ba2c0018d5ee1dd6eef2a6cc18cff777ef46484d
[coreboot.git] / src / cpu / ppc / mpc74xx / mpc74xx.inc
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2000 AG Electronics Ltd.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18  */
19
20 /*
21  * The aim of this code is to bring the machine from power-on to the point 
22  * where we can jump to the the main coreboot entry point hardwaremain()
23  * which is written in C.
24  *
25  * At power-on, we have no RAM, a memory-mapped I/O space, and we are executing
26  * out of ROM, generally at 0xfff00100.
27  *
28  * Before we jump to harwaremain() we want to do the following:
29  *
30  * - enable L1 I/D caches, otherwise performance will be slow
31  * - set up DBATs for the following regions:
32  *   - RAM (generally 0x00000000 -> 0x7fffffff)
33  *   - ROM (_ROMBASE -> _ROMBASE + ROM_SIZE)
34  *   - I/O (generally 0xfc000000 -> 0xfdffffff)
35  *   - the main purpose for setting up the DBATs is so the I/O region
36  *     can be marked cache inhibited/write through
37  * - set up IBATs for RAM and ROM
38  *
39  */
40
41 #include <ppc74xx.h>
42
43 #define BSP_IOREGION1   0x80000000
44 #define BSP_IOMASK1     BAT_BL_256M | BAT_VALID_SUPERVISOR | BAT_VALID_USER
45 #define BSP_IOREGION2   0xFD000000
46 #define BSP_IOMASK2     BAT_BL_64M | BAT_VALID_SUPERVISOR | BAT_VALID_USER
47
48         isync
49         sync
50
51         /* 
52          * Disable dcache and MMU
53          * Clear IR & DR
54          * Enable FP
55          */   
56         li      r0, 0
57         mtspr   HID0, r0
58         sync
59         mfmsr   r3
60         li      r4, 0x0030      /* IR & DR */
61         andc    r3, r3, r4
62         ori     r3, r3, 0x2000  /* FP */
63         mtmsr   r3
64         isync
65         sync
66
67         /*
68          * Invalidate D & I BATS
69          */
70         mtibatu 0, r0
71         mtibatu 1, r0
72         mtibatu 2, r0
73         mtibatu 3, r0
74         isync
75         mtdbatu 0, r0
76         mtdbatu 1, r0
77         mtdbatu 2, r0
78         mtdbatu 3, r0
79         isync
80
81         /*
82          * Clear segment registers (coreboot doesn't use these)
83          */
84         mtsr    0, r0
85         isync
86         mtsr    1, r0
87         isync
88         mtsr    2, r0
89         isync
90         mtsr    3, r0
91         isync
92         mtsr    4, r0
93         isync
94         mtsr    5, r0
95         isync
96         mtsr    6, r0
97         isync
98         mtsr    7, r0
99         isync
100         mtsr    8, r0
101         isync
102         mtsr    9, r0
103         isync
104         mtsr    10, r0
105         isync
106         mtsr    11, r0
107         isync
108         mtsr    12, r0
109         isync
110         mtsr    13, r0
111         isync
112         mtsr    14, r0
113         isync
114         mtsr    15, r0
115         isync
116
117         /*
118          * Set up DBATs 
119          *
120          * DBAT0 covers RAM (0 -> 0x0FFFFFFF) (256Mb)
121          * DBAT1 covers PCI memory and ROM (0xFD000000 -> 0xFFFFFFFF) (64Mb)
122          * DBAT2 covers PCI memory (0x80000000 -> 0x8FFFFFFF) (256Mb)
123          * DBAT3 is not used
124          */
125         lis     r2, 0@h
126         ori     r3, r2, BAT_BL_256M | BAT_VALID_SUPERVISOR | BAT_VALID_USER
127         ori     r2, r2, BAT_READ_WRITE | BAT_GUARDED
128         mtdbatu 0, r3
129         mtdbatl 0, r2
130         isync
131
132         lis     r2, BSP_IOREGION2@h
133         ori     r3, r2, BAT_BL_64M | BAT_VALID_SUPERVISOR | BAT_VALID_USER
134         ori     r2, r2, BAT_CACHE_INHIBITED | BAT_GUARDED | BAT_READ_WRITE
135         mtdbatu 1, r3
136         mtdbatl 1, r2
137         isync
138
139         lis     r2, BSP_IOREGION1@h
140         ori     r3, r2, BAT_BL_256M | BAT_VALID_SUPERVISOR | BAT_VALID_USER
141         ori     r2, r2, BAT_CACHE_INHIBITED | BAT_GUARDED | BAT_READ_WRITE
142         mtdbatu 2, r3
143         mtdbatl 2, r2
144         isync
145
146         /*
147          * IBATS
148          *
149          * IBAT0 covers RAM (0 -> 256Mb)
150          * IBAT1 covers ROM (_ROMBASE -> _ROMBASE+ROM_SIZE)
151          */
152         lis     r2, 0@h
153         ori     r3, r2, BAT_BL_256M | BAT_VALID_SUPERVISOR | BAT_VALID_USER
154         ori     r2, r2, BAT_READ_WRITE
155         mtibatu 0, r3
156         mtibatl 0, r2
157         isync
158
159         lis     r2, _ROMBASE@h
160 #if ROM_SIZE > 1048576
161         ori     r3, r2, BAT_BL_16M | BAT_VALID_SUPERVISOR | BAT_VALID_USER
162 #else
163         ori     r3, r2, BAT_BL_1M | BAT_VALID_SUPERVISOR | BAT_VALID_USER
164 #endif
165         ori     r2, r2, BAT_READ_ONLY
166         mtibatu 1, r3
167         mtibatl 1, r2
168         isync
169
170         /*
171          * Enable MMU 
172          */
173         mfmsr   r2
174         ori     r2, r2, MSR_DR | MSR_IR
175         mtmsr   r2
176         isync
177         sync
178
179         /*
180          * Enable and invalidate the L1 icache 
181          */
182         mfspr   r2, HID0
183         ori     r2, r2, HID0_ICE | HID0_ICFI
184         isync
185         mtspr   HID0, r2
186         /*
187          * Enable and invalidate the L1 dcache 
188          */
189         mfspr   r2, HID0
190         ori     r2, r2, HID0_DCE | HID0_DCFI
191         sync
192         mtspr   HID0, r2