machdep.c revision 1.66 1 /* $NetBSD: machdep.c,v 1.66 2021/03/30 02:41:15 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.66 2021/03/30 02:41:15 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 void initppc(vaddr_t, vaddr_t, char *, void *);
132
133 void
134 initppc(vaddr_t startkernel, vaddr_t endkernel, char *args, void *info_block)
135 {
136 u_int memsize;
137
138 /* Disable all external interrupts */
139 mtdcr(DCR_UIC0_BASE + DCR_UIC_ER, 0);
140
141 /* Setup board from OpenBIOS */
142 openbios_board_init(info_block);
143 memsize = openbios_board_memsize_get();
144
145 /* Linear map kernel memory */
146 for (vaddr_t va = 0; va < endkernel; va += TLB_PG_SIZE) {
147 ppc4xx_tlb_reserve(va, va, TLB_PG_SIZE, TLB_EX);
148 }
149
150 /* Map console after physmem (see pmap_tlbmiss()) */
151 ppc4xx_tlb_reserve(IBM405GP_UART0_BASE, roundup(memsize, TLB_PG_SIZE),
152 TLB_PG_SIZE, TLB_I | TLB_G);
153
154 mtspr(SPR_TCR, 0); /* disable all timers */
155
156 ibm40x_memsize_init(memsize, startkernel);
157 ibm4xx_init(startkernel, endkernel, pic_ext_intr);
158
159 #ifdef DEBUG
160 openbios_board_print();
161 #endif
162
163 #ifdef DDB
164 if (boothowto & RB_KDB)
165 Debugger();
166 #endif
167
168 /*
169 * Look for the ibm4xx modules in the right place.
170 */
171 module_machine = module_machine_ibm4xx;
172 }
173
174 /*
175 * Machine dependent startup code.
176 */
177
178 void
179 cpu_startup(void)
180 {
181
182 ibm4xx_cpu_startup("Walnut PowerPC 405GP Evaluation Board");
183
184 openbios_board_info_set();
185
186 /*
187 * Now that we have VM, malloc()s are OK in bus_space.
188 */
189 bus_space_mallocok();
190 fake_mapiodev = 0;
191 }
192
193 int
194 ibm4xx_pci_bus_maxdevs(void *v, int busno)
195 {
196
197 /*
198 * Bus number is irrelevant. Configuration Mechanism 1 is in
199 * use, can have devices 0-32 (i.e. the `normal' range).
200 */
201 return 5;
202 }
203
204 int
205 ibm4xx_pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
206 {
207 int pin = pa->pa_intrpin;
208 int dev = pa->pa_device;
209
210 if (pin == 0)
211 /* No IRQ used. */
212 goto bad;
213
214 if (pin > 4) {
215 printf("%s: bad interrupt pin %d\n", __func__, pin);
216 goto bad;
217 }
218
219 /*
220 * We need to map the interrupt pin to the interrupt bit in the UIC
221 * associated with it. This is highly machine-dependent.
222 */
223 switch(dev) {
224 case 1:
225 case 2:
226 case 3:
227 case 4:
228 *ihp = 27 + dev;
229 break;
230 default:
231 printf("Hmm.. PCI device %d should not exist on this board\n",
232 dev);
233 goto bad;
234 }
235 return 0;
236
237 bad:
238 *ihp = -1;
239 return 1;
240 }
241
242 void
243 ibm4xx_pci_conf_interrupt(void *v, int bus, int dev, int pin, int swiz,
244 int *iline)
245 {
246
247 if (bus == 0) {
248 switch(dev) {
249 case 1:
250 case 2:
251 case 3:
252 case 4:
253 *iline = 31 - dev;
254 }
255 } else
256 *iline = 20 + ((swiz + dev + 1) & 3);
257 }
258