1 /* $NetBSD: obs200_machdep.c,v 1.25 2021/09/04 13:36:07 rin Exp $ */ 2 /* Original: machdep.c,v 1.3 2005/01/17 17:24:09 shige Exp */ 3 4 /* 5 * Copyright 2001, 2002 Wasabi Systems, Inc. 6 * All rights reserved. 7 * 8 * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed for the NetBSD Project by 21 * Wasabi Systems, Inc. 22 * 4. The name of Wasabi Systems, Inc. may not be used to endorse 23 * or promote products derived from this software without specific prior 24 * written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 /* 40 * Copyright (C) 1995, 1996 Wolfgang Solfrank. 41 * Copyright (C) 1995, 1996 TooLs GmbH. 42 * All rights reserved. 43 * 44 * Redistribution and use in source and binary forms, with or without 45 * modification, are permitted provided that the following conditions 46 * are met: 47 * 1. Redistributions of source code must retain the above copyright 48 * notice, this list of conditions and the following disclaimer. 49 * 2. Redistributions in binary form must reproduce the above copyright 50 * notice, this list of conditions and the following disclaimer in the 51 * documentation and/or other materials provided with the distribution. 52 * 3. All advertising materials mentioning features or use of this software 53 * must display the following acknowledgement: 54 * This product includes software developed by TooLs GmbH. 55 * 4. The name of TooLs GmbH may not be used to endorse or promote products 56 * derived from this software without specific prior written permission. 57 * 58 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 59 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 60 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 61 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 62 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 63 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 64 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 65 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 66 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 67 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 68 */ 69 70 #include <sys/cdefs.h> 71 __KERNEL_RCSID(0, "$NetBSD: obs200_machdep.c,v 1.25 2021/09/04 13:36:07 rin Exp $"); 72 73 #include "opt_ddb.h" 74 75 #include <sys/param.h> 76 #include <sys/bus.h> 77 #include <sys/device.h> 78 #include <sys/kernel.h> 79 #include <sys/module.h> 80 #include <sys/reboot.h> 81 #include <sys/systm.h> 82 83 #include <machine/obs200.h> 84 #include <machine/century_bios.h> 85 86 #include <powerpc/spr.h> 87 #include <powerpc/ibm4xx/spr.h> 88 89 #include <powerpc/ibm4xx/cpu.h> 90 #include <powerpc/ibm4xx/dcr4xx.h> 91 #include <powerpc/ibm4xx/ibm405gp.h> 92 #include <powerpc/ibm4xx/tlb.h> 93 94 #include <powerpc/ibm4xx/pci_machdep.h> 95 #include <dev/pci/pciconf.h> 96 #include <dev/pci/pcivar.h> 97 98 #include "com.h" 99 #if (NCOM > 0) 100 #include <sys/termios.h> 101 #include <powerpc/ibm4xx/dev/comopbvar.h> 102 #include <dev/ic/comreg.h> 103 104 #ifndef CONADDR 105 #define CONADDR IBM405GP_UART0_BASE 106 #endif 107 #ifndef CONSPEED 108 #define CONSPEED B9600 109 #endif 110 #ifndef CONMODE 111 /* 8N1 */ 112 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) 113 #endif 114 #endif /* NCOM */ 115 116 #define TLB_PG_SIZE (16*1024*1024) 117 118 void initppc(vaddr_t, vaddr_t, char *, void *); 119 120 void 121 initppc(vaddr_t startkernel, vaddr_t endkernel, char *args, void *info_block) 122 { 123 u_int32_t pllmode __debugused; 124 u_int32_t psr __debugused; 125 vaddr_t va; 126 u_int memsize; 127 128 /* Disable all external interrupts */ 129 mtdcr(DCR_UIC0_BASE + DCR_UIC_ER, 0); 130 pllmode = mfdcr(DCR_CPC0_PLLMR); 131 psr = mfdcr(DCR_CPC0_PSR); 132 133 /* Setup board from BIOS */ 134 bios_board_init(info_block, startkernel); 135 memsize = bios_board_memsize_get(); 136 137 /* Linear map kernel memory. */ 138 for (va = 0; va < endkernel; va += TLB_PG_SIZE) 139 ppc4xx_tlb_reserve(va, va, TLB_PG_SIZE, TLB_EX); 140 141 /* Map console after physmem (see pmap_tlbmiss()). */ 142 ppc4xx_tlb_reserve(CONADDR, roundup(memsize, TLB_PG_SIZE), TLB_PG_SIZE, 143 TLB_I | TLB_G); 144 145 /* Initialize IBM405GPr CPU */ 146 ibm40x_memsize_init(memsize, startkernel); 147 ibm4xx_init(startkernel, endkernel, pic_ext_intr); 148 149 #ifdef DEBUG 150 bios_board_print(); 151 printf(" PLL Mode Register = 0x%08x\n", pllmode); 152 printf(" Chip Pin Strapping Register = 0x%08x\n", psr); 153 #endif 154 155 #ifdef DDB 156 if (boothowto & RB_KDB) 157 Debugger(); 158 #endif 159 } 160 161 void 162 consinit(void) 163 { 164 165 #if (NCOM > 0) 166 com_opb_cnattach(OBS200_COM_FREQ, CONADDR, CONSPEED, CONMODE); 167 #endif 168 } 169 170 /* 171 * Machine dependent startup code. 172 */ 173 void 174 cpu_startup(void) 175 { 176 177 /* 178 * cpu common startup 179 */ 180 ibm4xx_cpu_startup("OpenBlockS S/R IBM PowerPC 405GP Board"); 181 182 /* 183 * Set up the board properties database. 184 */ 185 bios_board_info_set(); 186 187 /* 188 * Now that we have VM, malloc()s are OK in bus_space. 189 */ 190 bus_space_mallocok(); 191 192 /* 193 * no fake mapiodev 194 */ 195 fake_mapiodev = 0; 196 } 197 198 int 199 ibm4xx_pci_bus_maxdevs(void *v, int busno) 200 { 201 202 /* 203 * Bus number is irrelevant. Configuration Mechanism 1 is in 204 * use, can have devices 0-32 (i.e. the `normal' range). 205 */ 206 return 31; 207 } 208 209 int 210 ibm4xx_pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp) 211 { 212 /* 213 * We need to map the interrupt pin to the interrupt bit 214 * in the UIC associated with it. 215 * 216 * This platform has 4 PCI devices. 217 * 218 # External IRQ Mappings: 219 * dev 7 (Ext IRQ3): Realtek 8139 Ethernet 220 * dev 8 (Ext IRQ0): PCI Connector 221 */ 222 static const int irqmap[15/*device*/][4/*pin*/] = { 223 { -1, -1, -1, -1 }, /* 1: none */ 224 { -1, -1, -1, -1 }, /* 2: none */ 225 { -1, -1, -1, -1 }, /* 3: none */ 226 { -1, -1, -1, -1 }, /* 4: none */ 227 { -1, -1, -1, -1 }, /* 5: none */ 228 { -1, -1, -1, -1 }, /* 6: none */ 229 { 3, -1, -1, -1 }, /* 7: none */ 230 { 0, -1, -1, -1 }, /* 8: none */ 231 { -1, -1, -1, -1 }, /* 9: none */ 232 { -1, -1, -1, -1 }, /* 10: none */ 233 { -1, -1, -1, -1 }, /* 11: none */ 234 { -1, -1, -1, -1 }, /* 12: none */ 235 { -1, -1, -1, -1 }, /* 13: none */ 236 { -1, -1, -1, -1 }, /* 14: none */ 237 { -1, -1, -1, -1 }, /* 15: none */ 238 }; 239 240 int pin, dev, irq; 241 242 pin = pa->pa_intrpin; 243 dev = pa->pa_device; 244 *ihp = -1; 245 246 /* if interrupt pin not used... */ 247 if (pin == 0) 248 return 1; 249 250 if (pin > 4) { 251 printf("pci_intr_map: bad interrupt pin %d\n", pin); 252 return 1; 253 } 254 255 if ((dev < 1) || (dev > 15)) { 256 printf("pci_intr_map: bad device %d\n", dev); 257 return 1; 258 } 259 260 261 if ((irq = irqmap[dev - 1][pin - 1]) == -1) { 262 printf("pci_intr_map: no IRQ routing for device %d pin %d\n", 263 dev, pin); 264 return 1; 265 } 266 267 *ihp = irq + 25; 268 return 0; 269 } 270 271 void 272 ibm4xx_pci_conf_interrupt(void *v, int bus, int dev, int pin, int swiz, 273 int *iline) 274 { 275 static const int ilinemap[15/*device*/] = { 276 -1, -1, -1, -1, /* device 1 - 4 */ 277 -1, -1, 28, 25, /* device 5 - 8 */ 278 -1, -1, -1, -1, /* device 9 - 12 */ 279 -1, -1, -1, /* device 13 - 15 */ 280 }; 281 282 if (bus == 0) { 283 if ((dev < 1) || (dev > 15)) { 284 printf("pci_intr_map: bad device %d\n", dev); 285 *iline = 0; 286 return; 287 } 288 *iline = ilinemap[dev - 1]; 289 } else 290 *iline = 19 + ((swiz + dev + 1) & 3); 291 } 292