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