1 /* $NetBSD: isa_machdep.c,v 1.27 2002/10/02 05:26:49 thorpej Exp $ */ 2 3 /*- 4 * Copyright (c) 1999 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by UCHIYAMA Yasushi. 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 by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND 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 THE FOUNDATION OR CONTRIBUTORS 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 #include "opt_vr41xx.h" 40 41 #include <sys/param.h> 42 #include <sys/systm.h> 43 #include <sys/reboot.h> 44 45 #include <dev/isa/isavar.h> 46 #include <dev/isa/isareg.h> 47 48 #include <machine/platid.h> 49 #include <machine/platid_mask.h> 50 #include <machine/bus.h> 51 #include <machine/bus_space_hpcmips.h> 52 #include <machine/debug.h> 53 54 #include <dev/hpc/hpciovar.h> 55 56 #include <hpcmips/vr/vripif.h> 57 58 #include "locators.h" 59 60 #define VRISADEBUG 61 62 #ifdef VRISADEBUG 63 #ifndef VRISADEBUG_CONF 64 #define VRISADEBUG_CONF 0 65 #endif /* VRISADEBUG_CONF */ 66 int vrisa_debug = VRISADEBUG_CONF; 67 #define DPRINTF(arg) if (vrisa_debug) printf arg; 68 #define DBITDISP(mask) if (vrisa_debug) dbg_bit_print(mask); 69 #define VPRINTF(arg) if (bootverbose || vrisa_debug) printf arg; 70 #else /* VRISADEBUG */ 71 #define DPRINTF(arg) 72 #define DBITDISP(mask) 73 #define VPRINTF(arg) if (bootverbose) printf arg; 74 #endif /* VRISADEBUG */ 75 76 /* 77 * intrrupt no. encoding: 78 * 79 * 0x0000000f ISA IRQ# 80 * 0x00ff0000 GPIO port# 81 * 0x01000000 interrupt signal hold/through (1:hold/0:though) 82 * 0x02000000 interrupt detection level (1:low /0:high ) 83 * 0x04000000 interrupt detection trigger (1:edge/0:level ) 84 */ 85 #define INTR_IRQ(i) (((i)>> 0) & 0x0f) 86 #define INTR_PORT(i) (((i)>>16) & 0xff) 87 #define INTR_MODE(i) (((i)>>24) & 0x07) 88 #define INTR_NIRQS 16 89 90 int vrisabprint(void *, const char *); 91 int vrisabmatch(struct device *, struct cfdata *, void *); 92 void vrisabattach(struct device *, struct device *, void *); 93 94 struct vrisab_softc { 95 struct device sc_dev; 96 hpcio_chip_t sc_hc; 97 int sc_intr_map[INTR_NIRQS]; /* ISA <-> GIU inerrupt line mapping */ 98 struct hpcmips_isa_chipset sc_isa_ic; 99 }; 100 101 CFATTACH_DECL(vrisab, sizeof(struct vrisab_softc), 102 vrisabmatch, vrisabattach, NULL, NULL); 103 104 #ifdef DEBUG_FIND_PCIC 105 #include <mips/cpuregs.h> 106 #warning DEBUG_FIND_PCIC 107 static void __find_pcic(void); 108 #endif 109 110 #ifdef DEBUG_FIND_COMPORT 111 #include <mips/cpuregs.h> 112 #include <dev/ic/ns16550reg.h> 113 #include <dev/ic/comreg.h> 114 #warning DEBUG_FIND_COMPORT 115 static void __find_comport(void); 116 #endif 117 118 int 119 vrisabmatch(struct device *parent, struct cfdata *match, void *aux) 120 { 121 struct hpcio_attach_args *haa = aux; 122 platid_mask_t mask; 123 int n; 124 125 if (strcmp(haa->haa_busname, match->cf_name)) 126 return (0); 127 128 if (match->cf_loc[HPCIOIFCF_PLATFORM] == HPCIOIFCF_PLATFORM_DEFAULT) 129 return (1); 130 131 mask = PLATID_DEREF(match->cf_loc[HPCIOIFCF_PLATFORM]); 132 if ((n = platid_match(&platid, &mask)) != 0) 133 return (n + 2); 134 135 return (0); 136 } 137 138 void 139 vrisabattach(struct device *parent, struct device *self, void *aux) 140 { 141 struct hpcio_attach_args *haa = aux; 142 struct vrisab_softc *sc = (void*)self; 143 struct isabus_attach_args iba; 144 struct bus_space_tag_hpcmips *iot, *memt; 145 bus_addr_t offset; 146 int i; 147 148 sc->sc_hc = (*haa->haa_getchip)(haa->haa_sc, VRIP_IOCHIP_VRGIU); 149 sc->sc_isa_ic.ic_sc = sc; 150 151 iba.iba_busname = "isa"; 152 iba.iba_ic = &sc->sc_isa_ic; 153 iba.iba_dmat = 0; /* XXX not yet */ 154 155 /* Allocate ISA memory space */ 156 memt = hpcmips_alloc_bus_space_tag(); 157 offset = sc->sc_dev.dv_cfdata->cf_loc[VRISABIFCF_ISAMEMOFFSET]; 158 hpcmips_init_bus_space(memt, 159 (struct bus_space_tag_hpcmips *)haa->haa_iot, "ISA mem", 160 VR_ISA_MEM_BASE + offset, VR_ISA_MEM_SIZE - offset); 161 iba.iba_memt = &memt->bst; 162 163 /* Allocate ISA port space */ 164 iot = hpcmips_alloc_bus_space_tag(); 165 offset = sc->sc_dev.dv_cfdata->cf_loc[VRISABIFCF_ISAPORTOFFSET]; 166 hpcmips_init_bus_space(iot, 167 (struct bus_space_tag_hpcmips *)haa->haa_iot, "ISA port", 168 VR_ISA_PORT_BASE + offset, VR_ISA_PORT_SIZE - offset); 169 iba.iba_iot = &iot->bst; 170 171 #ifdef DEBUG_FIND_PCIC 172 #warning DEBUG_FIND_PCIC 173 __find_pcic(); 174 #else 175 /* Initialize ISA IRQ <-> GPIO mapping */ 176 for (i = 0; i < INTR_NIRQS; i++) 177 sc->sc_intr_map[i] = -1; 178 printf(": ISA port %#x-%#x mem %#x-%#x\n", 179 iot->base, iot->base + iot->size, 180 memt->base, memt->base + memt->size); 181 config_found(self, &iba, vrisabprint); 182 #endif 183 184 #ifdef DEBUG_FIND_COMPORT 185 #warning DEBUG_FIND_COMPORT 186 __find_comport(); 187 #endif 188 } 189 190 int 191 vrisabprint(void *aux, const char *pnp) 192 { 193 if (pnp) 194 return (QUIET); 195 196 return (UNCONF); 197 } 198 199 void 200 isa_attach_hook(struct device *parent, struct device *self, 201 struct isabus_attach_args *iba) 202 { 203 204 } 205 206 const struct evcnt * 207 isa_intr_evcnt(isa_chipset_tag_t ic, int irq) 208 { 209 210 /* XXX for now, no evcnt parent reported */ 211 return (NULL); 212 } 213 214 void * 215 isa_intr_establish(isa_chipset_tag_t ic, int intr, int type, int level, 216 int (*ih_fun)(void*), void *ih_arg) 217 { 218 struct vrisab_softc *sc = ic->ic_sc; 219 int port, irq, mode; 220 221 static int intr_modes[8] = { 222 HPCIO_INTR_LEVEL_HIGH_THROUGH, 223 HPCIO_INTR_LEVEL_HIGH_HOLD, 224 HPCIO_INTR_LEVEL_LOW_THROUGH, 225 HPCIO_INTR_LEVEL_LOW_HOLD, 226 HPCIO_INTR_EDGE_THROUGH, 227 HPCIO_INTR_EDGE_HOLD, 228 HPCIO_INTR_EDGE_THROUGH, 229 HPCIO_INTR_EDGE_HOLD, 230 }; 231 #ifdef VRISADEBUG 232 static char* intr_mode_names[8] = { 233 "level high through", 234 "level high hold", 235 "level low through", 236 "level low hold", 237 "edge through", 238 "edge hold", 239 "edge through", 240 "edge hold", 241 }; 242 #endif /* VRISADEBUG */ 243 /* 244 * ISA IRQ <-> GPIO port mapping 245 */ 246 irq = INTR_IRQ(intr); 247 if (sc->sc_intr_map[irq] != -1) { 248 /* already mapped */ 249 intr = sc->sc_intr_map[irq]; 250 } else { 251 /* not mapped yet */ 252 sc->sc_intr_map[irq] = intr; /* Register it */ 253 } 254 mode = INTR_MODE(intr); 255 port = INTR_PORT(intr); 256 257 VPRINTF(("ISA IRQ %d -> %s port %d, %s\n", 258 irq, sc->sc_hc->hc_name, port, intr_mode_names[mode])); 259 260 /* Call Vr routine */ 261 return (hpcio_intr_establish(sc->sc_hc, port, intr_modes[mode], 262 ih_fun, ih_arg)); 263 } 264 265 void 266 isa_intr_disestablish(ic, arg) 267 isa_chipset_tag_t ic; 268 void *arg; 269 { 270 struct vrisab_softc *sc = ic->ic_sc; 271 /* Call Vr routine */ 272 hpcio_intr_disestablish(sc->sc_hc, arg); 273 } 274 275 int 276 isa_intr_alloc(isa_chipset_tag_t ic, int mask, int type, int *irq) 277 { 278 /* XXX not coded yet. this is temporary XXX */ 279 DPRINTF(("isa_intr_alloc:")); 280 DBITDISP(mask); 281 *irq = (ffs(mask) -1); /* XXX */ 282 283 return (0); 284 } 285 286 #ifdef DEBUG_FIND_PCIC 287 #warning DEBUG_FIND_PCIC 288 static void 289 __find_pcic(void) 290 { 291 int i, j, step, found; 292 u_int32_t addr; 293 u_int8_t reg; 294 int __read_revid (u_int32_t port) 295 { 296 addr = MIPS_PHYS_TO_KSEG1(i + port); 297 printf("%#x\r", i); 298 for (found = 0, j = 0; j < 0x100; j += 0x40) { 299 *((volatile u_int8_t *)addr) = j; 300 reg = *((volatile u_int8_t *)(addr + 1)); 301 #ifdef DEBUG_FIND_PCIC_I82365SL_ONLY 302 if (reg == 0x82 || reg == 0x83) { 303 #else 304 if ((reg & 0xc0) == 0x80) { 305 #endif 306 found++; 307 } 308 if (found) 309 printf("\nfound %d socket at %#x" 310 "(base from %#x)\n", found, addr, 311 i + port - VR_ISA_PORT_BASE); 312 } 313 } 314 step = 0x1000000; 315 printf("\nFinding PCIC. Trying ISA port %#x-%#x step %#x\n", 316 VR_ISA_PORT_BASE, VR_ISA_PORT_BASE + VR_ISA_PORT_SIZE, step); 317 for (i = VR_ISA_PORT_BASE; i < VR_ISA_PORT_BASE+VR_ISA_PORT_SIZE; 318 i+= step) { 319 __read_revid (0x3e0); 320 __read_revid (0x3e2); 321 } 322 } 323 #endif /* DEBUG_FIND_PCIC */ 324 325 326 #ifdef DEBUG_FIND_COMPORT 327 #warning DEBUG_FIND_COMPORT 328 329 static int probe_com(u_int32_t); 330 331 static int 332 probe_com(u_int32_t port_addr) 333 { 334 u_int32_t addr; 335 u_int8_t ubtmp1, ubtmp2; 336 337 addr = MIPS_PHYS_TO_KSEG1(port_addr); 338 339 *((volatile u_int8_t *)(addr + com_cfcr)) = LCR_8BITS; 340 *((volatile u_int8_t *)(addr + com_iir)) = 0; 341 342 ubtmp1 = *((volatile u_int8_t *)(addr + com_cfcr)); 343 ubtmp2 = *((volatile u_int8_t *)(addr + com_iir)); 344 345 if ((ubtmp1 != LCR_8BITS) || ((ubtmp2 & 0x38) != 0)) { 346 return (0); 347 } 348 349 return (1); 350 } 351 352 static void 353 __find_comport() 354 { 355 int found; 356 u_int32_t port, step; 357 358 found = 0; 359 step = 0x08; 360 361 printf("Searching COM port. Trying ISA port %#x-%#x step %#x\n", 362 VR_ISA_PORT_BASE, VR_ISA_PORT_BASE + VR_ISA_PORT_SIZE - 1, step ); 363 364 for (port = VR_ISA_PORT_BASE; 365 port < (VR_ISA_PORT_BASE + VR_ISA_PORT_SIZE); port += step){ 366 if (probe_com(port)) { 367 found++; 368 printf("found %d at %#x\n", found, port); 369 } 370 } 371 } 372 #endif /* DEBUG_FIND_COMPORT */ 373