machdep.c revision 1.65 1 /* $NetBSD: machdep.c,v 1.65 2021/03/30 02:04:44 rin Exp $ */
2
3 /*
4 * Copyright 2001, 2002 Wasabi Systems, Inc.
5 * All rights reserved.
6 *
7 * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed for the NetBSD Project by
20 * Wasabi Systems, Inc.
21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 * or promote products derived from this software without specific prior
23 * written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38 /*
39 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
40 * Copyright (C) 1995, 1996 TooLs GmbH.
41 * All rights reserved.
42 *
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
45 * are met:
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 3. All advertising materials mentioning features or use of this software
52 * must display the following acknowledgement:
53 * This product includes software developed by TooLs GmbH.
54 * 4. The name of TooLs GmbH may not be used to endorse or promote products
55 * derived from this software without specific prior written permission.
56 *
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
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,
61 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
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,
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
66 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 */
68
69 #include <sys/cdefs.h>
70 __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.65 2021/03/30 02:04:44 rin Exp $");
71
72 #include "opt_compat_netbsd.h"
73 #include "opt_ddb.h"
74
75 #include <sys/param.h>
76 #include <sys/boot_flag.h>
77 #include <sys/buf.h>
78 #include <sys/bus.h>
79 #include <sys/cpu.h>
80 #include <sys/device.h>
81 #include <sys/exec.h>
82 #include <sys/kernel.h>
83 #include <sys/ksyms.h>
84 #include <sys/malloc.h>
85 #include <sys/mbuf.h>
86 #include <sys/module.h>
87 #include <sys/mount.h>
88 #include <sys/msgbuf.h>
89 #include <sys/proc.h>
90 #include <sys/reboot.h>
91 #include <sys/syscallargs.h>
92 #include <sys/syslog.h>
93 #include <sys/systm.h>
94
95 #include <uvm/uvm_extern.h>
96
97 #include <prop/proplib.h>
98
99 #include <machine/powerpc.h>
100 #include <machine/walnut.h>
101
102 #include <powerpc/trap.h>
103 #include <powerpc/pcb.h>
104
105 #include <powerpc/spr.h>
106 #include <powerpc/ibm4xx/spr.h>
107 #include <powerpc/ibm4xx/cpu.h>
108 #include <powerpc/ibm4xx/dcr4xx.h>
109 #include <powerpc/ibm4xx/ibm405gp.h>
110
111 #include <powerpc/ibm4xx/openbios.h>
112
113 #include <powerpc/ibm4xx/pci_machdep.h>
114
115 #include <powerpc/pic/picvar.h>
116
117 #include <dev/cons.h>
118 #include <dev/pci/pcivar.h>
119 #include <dev/pci/pciconf.h>
120
121 #include "ksyms.h"
122
123 #if defined(DDB)
124 #include <powerpc/db_machdep.h>
125 #include <ddb/db_extern.h>
126 #endif
127
128
129 #define TLB_PG_SIZE (16*1024*1024)
130
131 /*
132 * Global variables used here and there
133 */
134 struct vm_map *phys_map = NULL;
135
136 /*
137 * This should probably be in autoconf! XXX
138 */
139 char machine[] = MACHINE; /* from <machine/param.h> */
140 char machine_arch[] = MACHINE_ARCH; /* from <machine/param.h> */
141
142 void initppc(vaddr_t, vaddr_t, char *, void *);
143
144 void
145 initppc(vaddr_t startkernel, vaddr_t endkernel, char *args, void *info_block)
146 {
147 u_int memsize;
148
149 /* Disable all external interrupts */
150 mtdcr(DCR_UIC0_BASE + DCR_UIC_ER, 0);
151
152 /* Setup board from OpenBIOS */
153 openbios_board_init(info_block);
154 memsize = openbios_board_memsize_get();
155
156 /* Linear map kernel memory */
157 for (vaddr_t va = 0; va < endkernel; va += TLB_PG_SIZE) {
158 ppc4xx_tlb_reserve(va, va, TLB_PG_SIZE, TLB_EX);
159 }
160
161 /* Map console after physmem (see pmap_tlbmiss()) */
162 ppc4xx_tlb_reserve(IBM405GP_UART0_BASE, roundup(memsize, TLB_PG_SIZE),
163 TLB_PG_SIZE, TLB_I | TLB_G);
164
165 mtspr(SPR_TCR, 0); /* disable all timers */
166
167 ibm40x_memsize_init(memsize, startkernel);
168 ibm4xx_init(startkernel, endkernel, pic_ext_intr);
169
170 #ifdef DEBUG
171 openbios_board_print();
172 #endif
173
174 #ifdef DDB
175 if (boothowto & RB_KDB)
176 Debugger();
177 #endif
178
179 /*
180 * Look for the ibm4xx modules in the right place.
181 */
182 module_machine = module_machine_ibm4xx;
183 }
184
185 /*
186 * Machine dependent startup code.
187 */
188
189 void
190 cpu_startup(void)
191 {
192
193 ibm4xx_cpu_startup("Walnut PowerPC 405GP Evaluation Board");
194
195 openbios_board_info_set();
196
197 /*
198 * Now that we have VM, malloc()s are OK in bus_space.
199 */
200 bus_space_mallocok();
201 fake_mapiodev = 0;
202 }
203
204 int
205 ibm4xx_pci_bus_maxdevs(void *v, int busno)
206 {
207
208 /*
209 * Bus number is irrelevant. Configuration Mechanism 1 is in
210 * use, can have devices 0-32 (i.e. the `normal' range).
211 */
212 return 5;
213 }
214
215 int
216 ibm4xx_pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
217 {
218 int pin = pa->pa_intrpin;
219 int dev = pa->pa_device;
220
221 if (pin == 0)
222 /* No IRQ used. */
223 goto bad;
224
225 if (pin > 4) {
226 printf("%s: bad interrupt pin %d\n", __func__, pin);
227 goto bad;
228 }
229
230 /*
231 * We need to map the interrupt pin to the interrupt bit in the UIC
232 * associated with it. This is highly machine-dependent.
233 */
234 switch(dev) {
235 case 1:
236 case 2:
237 case 3:
238 case 4:
239 *ihp = 27 + dev;
240 break;
241 default:
242 printf("Hmm.. PCI device %d should not exist on this board\n",
243 dev);
244 goto bad;
245 }
246 return 0;
247
248 bad:
249 *ihp = -1;
250 return 1;
251 }
252
253 void
254 ibm4xx_pci_conf_interrupt(void *v, int bus, int dev, int pin, int swiz,
255 int *iline)
256 {
257
258 if (bus == 0) {
259 switch(dev) {
260 case 1:
261 case 2:
262 case 3:
263 case 4:
264 *iline = 31 - dev;
265 }
266 } else
267 *iline = 20 + ((swiz + dev + 1) & 3);
268 }
269