1 /* $NetBSD: machdep.c,v 1.68 2021/08/03 09:25: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.68 2021/08/03 09:25:44 rin Exp $");
71
72 #include "opt_ddb.h"
73
74 #include <sys/param.h>
75 #include <sys/bus.h>
76 #include <sys/device.h>
77 #include <sys/kernel.h>
78 #include <sys/module.h>
79 #include <sys/reboot.h>
80 #include <sys/systm.h>
81
82 #include <machine/walnut.h>
83
84 #include <powerpc/spr.h>
85 #include <powerpc/ibm4xx/spr.h>
86
87 #include <powerpc/ibm4xx/cpu.h>
88 #include <powerpc/ibm4xx/dcr4xx.h>
89 #include <powerpc/ibm4xx/ibm405gp.h>
90 #include <powerpc/ibm4xx/openbios.h>
91 #include <powerpc/ibm4xx/tlb.h>
92
93 #include <powerpc/ibm4xx/pci_machdep.h>
94 #include <dev/pci/pciconf.h>
95 #include <dev/pci/pcivar.h>
96
97 #define TLB_PG_SIZE (16*1024*1024)
98
99 void initppc(vaddr_t, vaddr_t, char *, void *);
100
101 void
initppc(vaddr_t startkernel,vaddr_t endkernel,char * args,void * info_block)102 initppc(vaddr_t startkernel, vaddr_t endkernel, char *args, void *info_block)
103 {
104 u_int memsize;
105
106 /* Disable all external interrupts */
107 mtdcr(DCR_UIC0_BASE + DCR_UIC_ER, 0);
108
109 /* Setup board from OpenBIOS */
110 openbios_board_init(info_block);
111 memsize = openbios_board_memsize_get();
112
113 /* Linear map kernel memory */
114 for (vaddr_t va = 0; va < endkernel; va += TLB_PG_SIZE) {
115 ppc4xx_tlb_reserve(va, va, TLB_PG_SIZE, TLB_EX);
116 }
117
118 /* Map console after physmem (see pmap_tlbmiss()) */
119 ppc4xx_tlb_reserve(IBM405GP_UART0_BASE, roundup(memsize, TLB_PG_SIZE),
120 TLB_PG_SIZE, TLB_I | TLB_G);
121
122 mtspr(SPR_TCR, 0); /* disable all timers */
123
124 ibm40x_memsize_init(memsize, startkernel);
125 ibm4xx_init(startkernel, endkernel, pic_ext_intr);
126
127 #ifdef DEBUG
128 openbios_board_print();
129 #endif
130
131 #ifdef DDB
132 if (boothowto & RB_KDB)
133 Debugger();
134 #endif
135 }
136
137 /*
138 * Machine dependent startup code.
139 */
140
141 void
cpu_startup(void)142 cpu_startup(void)
143 {
144
145 ibm4xx_cpu_startup("Walnut PowerPC 405GP Evaluation Board");
146
147 openbios_board_info_set();
148
149 /*
150 * Now that we have VM, malloc()s are OK in bus_space.
151 */
152 bus_space_mallocok();
153 fake_mapiodev = 0;
154 }
155
156 int
ibm4xx_pci_bus_maxdevs(void * v,int busno)157 ibm4xx_pci_bus_maxdevs(void *v, int busno)
158 {
159
160 /*
161 * Bus number is irrelevant. Configuration Mechanism 1 is in
162 * use, can have devices 0-32 (i.e. the `normal' range).
163 */
164 return 5;
165 }
166
167 int
ibm4xx_pci_intr_map(const struct pci_attach_args * pa,pci_intr_handle_t * ihp)168 ibm4xx_pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
169 {
170 int pin = pa->pa_intrpin;
171 int dev = pa->pa_device;
172
173 if (pin == 0)
174 /* No IRQ used. */
175 goto bad;
176
177 if (pin > 4) {
178 printf("%s: bad interrupt pin %d\n", __func__, pin);
179 goto bad;
180 }
181
182 /*
183 * We need to map the interrupt pin to the interrupt bit in the UIC
184 * associated with it. This is highly machine-dependent.
185 */
186 switch(dev) {
187 case 1:
188 case 2:
189 case 3:
190 case 4:
191 *ihp = 27 + dev;
192 break;
193 default:
194 printf("Hmm.. PCI device %d should not exist on this board\n",
195 dev);
196 goto bad;
197 }
198 return 0;
199
200 bad:
201 *ihp = -1;
202 return 1;
203 }
204
205 void
ibm4xx_pci_conf_interrupt(void * v,int bus,int dev,int pin,int swiz,int * iline)206 ibm4xx_pci_conf_interrupt(void *v, int bus, int dev, int pin, int swiz,
207 int *iline)
208 {
209
210 if (bus == 0) {
211 switch(dev) {
212 case 1:
213 case 2:
214 case 3:
215 case 4:
216 *iline = 31 - dev;
217 }
218 } else
219 *iline = 20 + ((swiz + dev + 1) & 3);
220 }
221