| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: machdep.c,v 1.64 2021/03/30 01:33:50 rin Exp $ */ | | 1 | /* $NetBSD: machdep.c,v 1.65 2021/03/30 02:04:44 rin Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright 2001, 2002 Wasabi Systems, Inc. | | 4 | * Copyright 2001, 2002 Wasabi Systems, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc. | | 7 | * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc. |
8 | * | | 8 | * |
9 | * Redistribution and use in source and binary forms, with or without | | 9 | * Redistribution and use in source and binary forms, with or without |
10 | * modification, are permitted provided that the following conditions | | 10 | * modification, are permitted provided that the following conditions |
11 | * are met: | | 11 | * are met: |
12 | * 1. Redistributions of source code must retain the above copyright | | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * 2. Redistributions in binary form must reproduce the above copyright | | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
| @@ -57,27 +57,27 @@ | | | @@ -57,27 +57,27 @@ |
57 | * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR | | 57 | * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR |
58 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 58 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
59 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 59 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
60 | * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | | 60 | * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
61 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | | 61 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
62 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | | 62 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
63 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | | 63 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
64 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | | 64 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
65 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | | 65 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
66 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 66 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
67 | */ | | 67 | */ |
68 | | | 68 | |
69 | #include <sys/cdefs.h> | | 69 | #include <sys/cdefs.h> |
70 | __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.64 2021/03/30 01:33:50 rin Exp $"); | | 70 | __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.65 2021/03/30 02:04:44 rin Exp $"); |
71 | | | 71 | |
72 | #include "opt_compat_netbsd.h" | | 72 | #include "opt_compat_netbsd.h" |
73 | #include "opt_ddb.h" | | 73 | #include "opt_ddb.h" |
74 | | | 74 | |
75 | #include <sys/param.h> | | 75 | #include <sys/param.h> |
76 | #include <sys/boot_flag.h> | | 76 | #include <sys/boot_flag.h> |
77 | #include <sys/buf.h> | | 77 | #include <sys/buf.h> |
78 | #include <sys/bus.h> | | 78 | #include <sys/bus.h> |
79 | #include <sys/cpu.h> | | 79 | #include <sys/cpu.h> |
80 | #include <sys/device.h> | | 80 | #include <sys/device.h> |
81 | #include <sys/exec.h> | | 81 | #include <sys/exec.h> |
82 | #include <sys/kernel.h> | | 82 | #include <sys/kernel.h> |
83 | #include <sys/ksyms.h> | | 83 | #include <sys/ksyms.h> |
| @@ -98,26 +98,28 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v | | | @@ -98,26 +98,28 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v |
98 | | | 98 | |
99 | #include <machine/powerpc.h> | | 99 | #include <machine/powerpc.h> |
100 | #include <machine/walnut.h> | | 100 | #include <machine/walnut.h> |
101 | | | 101 | |
102 | #include <powerpc/trap.h> | | 102 | #include <powerpc/trap.h> |
103 | #include <powerpc/pcb.h> | | 103 | #include <powerpc/pcb.h> |
104 | | | 104 | |
105 | #include <powerpc/spr.h> | | 105 | #include <powerpc/spr.h> |
106 | #include <powerpc/ibm4xx/spr.h> | | 106 | #include <powerpc/ibm4xx/spr.h> |
107 | #include <powerpc/ibm4xx/cpu.h> | | 107 | #include <powerpc/ibm4xx/cpu.h> |
108 | #include <powerpc/ibm4xx/dcr4xx.h> | | 108 | #include <powerpc/ibm4xx/dcr4xx.h> |
109 | #include <powerpc/ibm4xx/ibm405gp.h> | | 109 | #include <powerpc/ibm4xx/ibm405gp.h> |
110 | | | 110 | |
| | | 111 | #include <powerpc/ibm4xx/openbios.h> |
| | | 112 | |
111 | #include <powerpc/ibm4xx/pci_machdep.h> | | 113 | #include <powerpc/ibm4xx/pci_machdep.h> |
112 | | | 114 | |
113 | #include <powerpc/pic/picvar.h> | | 115 | #include <powerpc/pic/picvar.h> |
114 | | | 116 | |
115 | #include <dev/cons.h> | | 117 | #include <dev/cons.h> |
116 | #include <dev/pci/pcivar.h> | | 118 | #include <dev/pci/pcivar.h> |
117 | #include <dev/pci/pciconf.h> | | 119 | #include <dev/pci/pciconf.h> |
118 | | | 120 | |
119 | #include "ksyms.h" | | 121 | #include "ksyms.h" |
120 | | | 122 | |
121 | #if defined(DDB) | | 123 | #if defined(DDB) |
122 | #include <powerpc/db_machdep.h> | | 124 | #include <powerpc/db_machdep.h> |
123 | #include <ddb/db_extern.h> | | 125 | #include <ddb/db_extern.h> |
| @@ -129,127 +131,78 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v | | | @@ -129,127 +131,78 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v |
129 | /* | | 131 | /* |
130 | * Global variables used here and there | | 132 | * Global variables used here and there |
131 | */ | | 133 | */ |
132 | struct vm_map *phys_map = NULL; | | 134 | struct vm_map *phys_map = NULL; |
133 | | | 135 | |
134 | /* | | 136 | /* |
135 | * This should probably be in autoconf! XXX | | 137 | * This should probably be in autoconf! XXX |
136 | */ | | 138 | */ |
137 | char machine[] = MACHINE; /* from <machine/param.h> */ | | 139 | char machine[] = MACHINE; /* from <machine/param.h> */ |
138 | char machine_arch[] = MACHINE_ARCH; /* from <machine/param.h> */ | | 140 | char machine_arch[] = MACHINE_ARCH; /* from <machine/param.h> */ |
139 | | | 141 | |
140 | void initppc(vaddr_t, vaddr_t, char *, void *); | | 142 | void initppc(vaddr_t, vaddr_t, char *, void *); |
141 | | | 143 | |
142 | struct board_cfg_data board_data; | | | |
143 | | | | |
144 | void | | 144 | void |
145 | initppc(vaddr_t startkernel, vaddr_t endkernel, char *args, void *info_block) | | 145 | initppc(vaddr_t startkernel, vaddr_t endkernel, char *args, void *info_block) |
146 | { | | 146 | { |
| | | 147 | u_int memsize; |
| | | 148 | |
147 | /* Disable all external interrupts */ | | 149 | /* Disable all external interrupts */ |
148 | mtdcr(DCR_UIC0_BASE + DCR_UIC_ER, 0); | | 150 | mtdcr(DCR_UIC0_BASE + DCR_UIC_ER, 0); |
149 | | | 151 | |
150 | /* Initialize cache info for memcpy, etc. */ | | 152 | /* Setup board from OpenBIOS */ |
151 | cpu_probe_cache(); | | 153 | openbios_board_init(info_block); |
152 | | | 154 | memsize = openbios_board_memsize_get(); |
153 | /* Save info block */ | | | |
154 | memcpy(&board_data, info_block, sizeof(board_data)); | | | |
155 | | | | |
156 | ibm40x_memsize_init(board_data.mem_size, startkernel); | | | |
157 | | | 155 | |
158 | /* Linear map kernel memory */ | | 156 | /* Linear map kernel memory */ |
159 | for (vaddr_t va = 0; va < endkernel; va += TLB_PG_SIZE) { | | 157 | for (vaddr_t va = 0; va < endkernel; va += TLB_PG_SIZE) { |
160 | ppc4xx_tlb_reserve(va, va, TLB_PG_SIZE, TLB_EX); | | 158 | ppc4xx_tlb_reserve(va, va, TLB_PG_SIZE, TLB_EX); |
161 | } | | 159 | } |
162 | | | 160 | |
163 | /* Map console after physmem (see pmap_tlbmiss()) */ | | 161 | /* Map console after physmem (see pmap_tlbmiss()) */ |
164 | ppc4xx_tlb_reserve(IBM405GP_UART0_BASE, | | 162 | ppc4xx_tlb_reserve(IBM405GP_UART0_BASE, roundup(memsize, TLB_PG_SIZE), |
165 | roundup(board_data.mem_size, TLB_PG_SIZE), | | | |
166 | TLB_PG_SIZE, TLB_I | TLB_G); | | 163 | TLB_PG_SIZE, TLB_I | TLB_G); |
167 | | | 164 | |
168 | mtspr(SPR_TCR, 0); /* disable all timers */ | | 165 | mtspr(SPR_TCR, 0); /* disable all timers */ |
169 | | | 166 | |
| | | 167 | ibm40x_memsize_init(memsize, startkernel); |
170 | ibm4xx_init(startkernel, endkernel, pic_ext_intr); | | 168 | ibm4xx_init(startkernel, endkernel, pic_ext_intr); |
171 | | | 169 | |
172 | #ifdef DEBUG | | 170 | #ifdef DEBUG |
173 | printf("Board config data:\n"); | | 171 | openbios_board_print(); |
174 | printf(" usr_config_ver = %s\n", board_data.usr_config_ver); | | | |
175 | printf(" rom_sw_ver = %s\n", board_data.rom_sw_ver); | | | |
176 | printf(" mem_size = %u\n", board_data.mem_size); | | | |
177 | printf(" mac_address_local = %02x:%02x:%02x:%02x:%02x:%02x\n", | | | |
178 | board_data.mac_address_local[0], board_data.mac_address_local[1], | | | |
179 | board_data.mac_address_local[2], board_data.mac_address_local[3], | | | |
180 | board_data.mac_address_local[4], board_data.mac_address_local[5]); | | | |
181 | printf(" mac_address_pci = %02x:%02x:%02x:%02x:%02x:%02x\n", | | | |
182 | board_data.mac_address_pci[0], board_data.mac_address_pci[1], | | | |
183 | board_data.mac_address_pci[2], board_data.mac_address_pci[3], | | | |
184 | board_data.mac_address_pci[4], board_data.mac_address_pci[5]); | | | |
185 | printf(" processor_speed = %u\n", board_data.processor_speed); | | | |
186 | printf(" plb_speed = %u\n", board_data.plb_speed); | | | |
187 | printf(" pci_speed = %u\n", board_data.pci_speed); | | | |
188 | #endif | | 172 | #endif |
189 | | | 173 | |
190 | #ifdef DDB | | 174 | #ifdef DDB |
191 | if (boothowto & RB_KDB) | | 175 | if (boothowto & RB_KDB) |
192 | Debugger(); | | 176 | Debugger(); |
193 | #endif | | 177 | #endif |
194 | | | 178 | |
195 | /* | | 179 | /* |
196 | * Look for the ibm4xx modules in the right place. | | 180 | * Look for the ibm4xx modules in the right place. |
197 | */ | | 181 | */ |
198 | module_machine = module_machine_ibm4xx; | | 182 | module_machine = module_machine_ibm4xx; |
199 | } | | 183 | } |
200 | | | 184 | |
201 | /* | | 185 | /* |
202 | * Machine dependent startup code. | | 186 | * Machine dependent startup code. |
203 | */ | | 187 | */ |
204 | | | 188 | |
205 | void | | 189 | void |
206 | cpu_startup(void) | | 190 | cpu_startup(void) |
207 | { | | 191 | { |
208 | prop_number_t pn; | | | |
209 | prop_data_t pd; | | | |
210 | | | 192 | |
211 | ibm4xx_cpu_startup("Walnut PowerPC 405GP Evaluation Board"); | | 193 | ibm4xx_cpu_startup("Walnut PowerPC 405GP Evaluation Board"); |
212 | | | 194 | |
213 | board_info_init(); | | 195 | openbios_board_info_set(); |
214 | | | | |
215 | pn = prop_number_create_integer(board_data.mem_size); | | | |
216 | KASSERT(pn != NULL); | | | |
217 | if (prop_dictionary_set(board_properties, "mem-size", pn) == false) | | | |
218 | panic("setting mem-size"); | | | |
219 | prop_object_release(pn); | | | |
220 | | | | |
221 | pd = prop_data_create_data_nocopy(board_data.mac_address_local, | | | |
222 | sizeof(board_data.mac_address_local)); | | | |
223 | KASSERT(pd != NULL); | | | |
224 | if (prop_dictionary_set(board_properties, "emac0-mac-addr", | | | |
225 | pd) == false) | | | |
226 | panic("setting emac0-mac-addr"); | | | |
227 | prop_object_release(pd); | | | |
228 | | | | |
229 | pd = prop_data_create_data_nocopy(board_data.mac_address_pci, | | | |
230 | sizeof(board_data.mac_address_pci)); | | | |
231 | KASSERT(pd != NULL); | | | |
232 | if (prop_dictionary_set(board_properties, "sip0-mac-addr", | | | |
233 | pd) == false) | | | |
234 | panic("setting sip0-mac-addr"); | | | |
235 | prop_object_release(pd); | | | |
236 | | | | |
237 | pn = prop_number_create_integer(board_data.processor_speed); | | | |
238 | KASSERT(pn != NULL); | | | |
239 | if (prop_dictionary_set(board_properties, "processor-frequency", | | | |
240 | pn) == false) | | | |
241 | panic("setting processor-frequency"); | | | |
242 | prop_object_release(pn); | | | |
243 | | | 196 | |
244 | /* | | 197 | /* |
245 | * Now that we have VM, malloc()s are OK in bus_space. | | 198 | * Now that we have VM, malloc()s are OK in bus_space. |
246 | */ | | 199 | */ |
247 | bus_space_mallocok(); | | 200 | bus_space_mallocok(); |
248 | fake_mapiodev = 0; | | 201 | fake_mapiodev = 0; |
249 | } | | 202 | } |
250 | | | 203 | |
251 | int | | 204 | int |
252 | ibm4xx_pci_bus_maxdevs(void *v, int busno) | | 205 | ibm4xx_pci_bus_maxdevs(void *v, int busno) |
253 | { | | 206 | { |
254 | | | 207 | |
255 | /* | | 208 | /* |