isa_machdep.c revision 1.18
1/* $NetBSD: isa_machdep.c,v 1.18 2001/11/18 08:19:40 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 53#include <dev/hpc/hpciovar.h> 54 55#include <hpcmips/hpcmips/machdep.h> 56#include <hpcmips/vr/vrcpudef.h> 57#include <hpcmips/vr/vripreg.h> 58#include <hpcmips/vr/vripvar.h> 59 60#include "locators.h" 61 62#define VRISADEBUG 63 64#ifdef VRISADEBUG 65#ifndef VRISADEBUG_CONF 66#define VRISADEBUG_CONF 0 67#endif /* VRISADEBUG_CONF */ 68int vrisa_debug = VRISADEBUG_CONF; 69#define DPRINTF(arg) if (vrisa_debug) printf arg; 70#define DBITDISP32(mask) if (vrisa_debug) bitdisp32(mask); 71#define VPRINTF(arg) if (bootverbose || vrisa_debug) printf arg; 72#else /* VRISADEBUG */ 73#define DPRINTF(arg) 74#define DBITDISP32(mask) 75#define VPRINTF(arg) if (bootverbose) printf arg; 76#endif /* VRISADEBUG */ 77 78/* 79 * intrrupt no. encoding: 80 * 81 * 0x0000000f ISA IRQ# 82 * 0x00ff0000 GPIO port# 83 * 0x01000000 interrupt signal hold/through (1:hold/0:though) 84 * 0x02000000 interrupt detection level (1:low /0:high ) 85 * 0x04000000 interrupt detection trigger (1:edge/0:level ) 86 */ 87#define INTR_IRQ(i) (((i)>> 0) & 0x0f) 88#define INTR_PORT(i) (((i)>>16) & 0xff) 89#define INTR_MODE(i) (((i)>>24) & 0x07) 90#define INTR_NIRQS 16 91 92int vrisabprint(void *, const char *); 93int vrisabmatch(struct device *, struct cfdata *, void *); 94void vrisabattach(struct device *, struct device *, void *); 95 96struct vrisab_softc { 97 struct device sc_dev; 98 hpcio_chip_t sc_hc; 99 int sc_intr_map[INTR_NIRQS]; /* ISA <-> GIU inerrupt line mapping */ 100 struct hpcmips_isa_chipset sc_isa_ic; 101}; 102 103struct cfattach vrisab_ca = { 104 sizeof(struct vrisab_softc), vrisabmatch, vrisabattach 105}; 106 107#ifdef DEBUG_FIND_PCIC 108#include <mips/cpuregs.h> 109#warning DEBUG_FIND_PCIC 110static void __find_pcic(void); 111#endif 112 113#ifdef DEBUG_FIND_COMPORT 114#include <mips/cpuregs.h> 115#include <dev/ic/ns16550reg.h> 116#include <dev/ic/comreg.h> 117#warning DEBUG_FIND_COMPORT 118static void __find_comport(void); 119#endif 120 121int 122vrisabmatch(struct device *parent, struct cfdata *match, void *aux) 123{ 124 struct hpcio_attach_args *haa = aux; 125 platid_mask_t mask; 126 127 if (strcmp(haa->haa_busname, match->cf_driver->cd_name)) 128 return (0); 129 130 if (match->cf_loc[HPCIOIFCF_PLATFORM] == HPCIOIFCF_PLATFORM_DEFAULT) 131 return (1); 132 133 mask = PLATID_DEREF(match->cf_loc[HPCIOIFCF_PLATFORM]); 134 if (platid_match(&platid, &mask)) 135 return (2); 136 137 return (0); 138} 139 140void 141vrisabattach(struct device *parent, struct device *self, void *aux) 142{ 143 struct hpcio_attach_args *haa = aux; 144 struct vrisab_softc *sc = (void*)self; 145 struct isabus_attach_args iba; 146 struct bus_space_tag_hpcmips *iot, *memt; 147 bus_addr_t offset; 148 int i; 149 150 sc->sc_hc = (*haa->haa_getchip)(haa->haa_sc, VRIP_IOCHIP_VRGIU); 151 sc->sc_isa_ic.ic_sc = sc; 152 153 iba.iba_busname = "isa"; 154 iba.iba_ic = &sc->sc_isa_ic; 155 iba.iba_dmat = 0; /* XXX not yet */ 156 157 /* Allocate ISA memory space */ 158 iba.iba_memt = hpcmips_alloc_bus_space_tag(); 159 offset = sc->sc_dev.dv_cfdata->cf_loc[VRISABIFCF_ISAMEMOFFSET]; 160 hpcmips_init_bus_space(iba.iba_memt, haa->haa_iot, "ISA mem", 161 VR_ISA_MEM_BASE + offset, VR_ISA_MEM_SIZE - offset); 162 163 /* Allocate ISA port space */ 164 iba.iba_iot = hpcmips_alloc_bus_space_tag(); 165 offset = sc->sc_dev.dv_cfdata->cf_loc[VRISABIFCF_ISAPORTOFFSET]; 166 hpcmips_init_bus_space(iba.iba_iot, haa->haa_iot, "ISA port", 167 VR_ISA_PORT_BASE + offset, VR_ISA_PORT_SIZE - offset); 168 169#ifdef DEBUG_FIND_PCIC 170#warning DEBUG_FIND_PCIC 171 __find_pcic(); 172#else 173 /* Initialize ISA IRQ <-> GPIO mapping */ 174 for (i = 0; i < INTR_NIRQS; i++) 175 sc->sc_intr_map[i] = -1; 176 iot = (struct bus_space_tag_hpcmips *)iba.iba_iot; 177 memt = (struct bus_space_tag_hpcmips *)iba.iba_memt; 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 190int 191vrisabprint(void *aux, const char *pnp) 192{ 193 if (pnp) 194 return (QUIET); 195 196 return (UNCONF); 197} 198 199void 200isa_attach_hook(struct device *parent, struct device *self, 201 struct isabus_attach_args *iba) 202{ 203 204} 205 206const struct evcnt * 207isa_intr_evcnt(isa_chipset_tag_t ic, int irq) 208{ 209 210 /* XXX for now, no evcnt parent reported */ 211 return (NULL); 212} 213 214void * 215isa_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 265void 266isa_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 275int 276isa_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 DBITDISP32(mask); 281 *irq = (ffs(mask) -1); /* XXX */ 282 283 return (0); 284} 285 286#ifdef DEBUG_FIND_PCIC 287#warning DEBUG_FIND_PCIC 288static 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 329static int probe_com(u_int32_t); 330 331static int 332probe_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 352static 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