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