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