Rename almost all occurences of LinuxBIOS to coreboot.
[coreboot.git] / src / cpu / ppc / ppc7xx / ppc7xx.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 <ppc750.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
50         /* 
51          * Disable dcache and MMU, so we're in a known state
52          */   
53         li      r0, 0
54         sync
55         mtspr   HID0, r0
56         sync
57         mtmsr   r0 
58         isync
59
60         /*
61          * Invalidate D & I BATS
62          */
63         mtibatu 0, r0
64         mtibatu 1, r0
65         mtibatu 2, r0
66         mtibatu 3, r0
67         isync
68         mtdbatu 0, r0
69         mtdbatu 1, r0
70         mtdbatu 2, r0
71         mtdbatu 3, r0
72         isync
73
74         /*
75          * Clear segment registers (coreboot doesn't use these)
76          */
77         li      r3, 15
78 1:      mtsrin  r3, r0
79         subic.  r3, r3, 1
80         bge     1b
81         isync
82
83         /*
84          * Set up DBATs 
85          *
86          * DBAT0 covers RAM (0 -> 0x0FFFFFFF) (256Mb)
87          * DBAT1 covers PCI memory and ROM (0xFD000000 -> 0xFFFFFFFF) (64Mb)
88          * DBAT2 covers PCI memory (0x80000000 -> 0x8FFFFFFF) (256Mb)
89          * DBAT3 is not used
90          */
91         lis     r2, 0@h
92         ori     r3, r2, BAT_BL_256M | BAT_VALID_SUPERVISOR | BAT_VALID_USER
93         ori     r2, r2, BAT_READ_WRITE | BAT_GUARDED
94         mtdbatu 0, r3
95         mtdbatl 0, r2
96         isync
97
98         lis     r2, BSP_IOREGION2@h
99         ori     r3, r2, BAT_BL_64M | BAT_VALID_SUPERVISOR | BAT_VALID_USER
100         ori     r2, r2, BAT_CACHE_INHIBITED | BAT_GUARDED | BAT_READ_WRITE
101         mtdbatu 1, r3
102         mtdbatl 1, r2
103         isync
104
105         lis     r2, BSP_IOREGION1@h
106         ori     r3, r2, BAT_BL_256M | BAT_VALID_SUPERVISOR | BAT_VALID_USER
107         ori     r2, r2, BAT_CACHE_INHIBITED | BAT_GUARDED | BAT_READ_WRITE
108         mtdbatu 2, r3
109         mtdbatl 2, r2
110         isync
111
112         /*
113          * IBATS
114          *
115          * IBAT0 covers RAM (0 -> 256Mb)
116          * IBAT1 covers ROM (_ROMBASE -> _ROMBASE+ROM_SIZE)
117          */
118         lis     r2, 0@h
119         ori     r3, r2, BAT_BL_256M | BAT_VALID_SUPERVISOR | BAT_VALID_USER
120         ori     r2, r2, BAT_READ_WRITE
121         mtibatu 0, r3
122         mtibatl 0, r2
123         isync
124
125         lis     r2, _ROMBASE@h
126 #if ROM_SIZE > 1048576
127         ori     r3, r2, BAT_BL_16M | BAT_VALID_SUPERVISOR | BAT_VALID_USER
128 #else
129         ori     r3, r2, BAT_BL_1M | BAT_VALID_SUPERVISOR | BAT_VALID_USER
130 #endif
131         ori     r2, r2, BAT_READ_ONLY
132         mtibatu 1, r3
133         mtibatl 1, r2
134         isync
135
136         /*
137          * Enable MMU 
138          */
139         mfmsr   r2
140         ori     r2, r2, MSR_DR | MSR_IR
141         mtmsr   r2
142         isync
143         sync
144
145         /*
146          * Enable and invalidate the L1 icache 
147          */
148         mfspr   r2, HID0
149         ori     r2, r2, HID0_ICE | HID0_ICFI
150         isync
151         mtspr   HID0, r2
152         /*
153          * Enable and invalidate the L1 dcache 
154          */
155         mfspr   r2, HID0
156         ori     r2, r2, HID0_DCE | HID0_DCFI
157         sync
158         mtspr   HID0, r2
159
160         /*
161          * Initialize data cache blocks 
162          * (assumes cache block size of 32 bytes)
163          */
164         lis     r1, DCACHE_RAM_BASE@h
165         ori     r1, r1, DCACHE_RAM_BASE@l
166         li      r3, (DCACHE_RAM_SIZE / 32)
167         mtctr   r3
168 0:      dcbz    r0, r1
169         addi    r1, r1, 32
170         bdnz    0b