isa_machdep.c revision 1.27
11.27Sthorpej/* $NetBSD: isa_machdep.c,v 1.27 2002/10/02 05:26:49 thorpej Exp $ */ 21.1Stakemura 31.16Such/*- 41.16Such * Copyright (c) 1999 The NetBSD Foundation, Inc. 51.1Stakemura * All rights reserved. 61.1Stakemura * 71.16Such * This code is derived from software contributed to The NetBSD Foundation 81.16Such * by UCHIYAMA Yasushi. 91.16Such * 101.1Stakemura * Redistribution and use in source and binary forms, with or without 111.1Stakemura * modification, are permitted provided that the following conditions 121.1Stakemura * are met: 131.1Stakemura * 1. Redistributions of source code must retain the above copyright 141.1Stakemura * notice, this list of conditions and the following disclaimer. 151.16Such * 2. Redistributions in binary form must reproduce the above copyright 161.16Such * notice, this list of conditions and the following disclaimer in the 171.16Such * documentation and/or other materials provided with the distribution. 181.16Such * 3. All advertising materials mentioning features or use of this software 191.16Such * must display the following acknowledgement: 201.16Such * This product includes software developed by the NetBSD 211.16Such * Foundation, Inc. and its contributors. 221.16Such * 4. Neither the name of The NetBSD Foundation nor the names of its 231.16Such * contributors may be used to endorse or promote products derived 241.16Such * from this software without specific prior written permission. 251.1Stakemura * 261.16Such * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 271.16Such * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 281.16Such * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 291.16Such * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 301.16Such * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 311.16Such * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 321.16Such * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 331.16Such * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 341.16Such * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 351.16Such * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 361.16Such * POSSIBILITY OF SUCH DAMAGE. 371.1Stakemura */ 381.16Such 391.16Such#include "opt_vr41xx.h" 401.16Such 411.1Stakemura#include <sys/param.h> 421.1Stakemura#include <sys/systm.h> 431.10Ssato#include <sys/reboot.h> 441.1Stakemura 451.1Stakemura#include <dev/isa/isavar.h> 461.1Stakemura#include <dev/isa/isareg.h> 471.1Stakemura 481.1Stakemura#include <machine/platid.h> 491.1Stakemura#include <machine/platid_mask.h> 501.18Stakemura#include <machine/bus.h> 511.18Stakemura#include <machine/bus_space_hpcmips.h> 521.23Such#include <machine/debug.h> 531.1Stakemura 541.13Stakemura#include <dev/hpc/hpciovar.h> 551.13Stakemura 561.22Stakemura#include <hpcmips/vr/vripif.h> 571.1Stakemura 581.1Stakemura#include "locators.h" 591.1Stakemura 601.4Ssato#define VRISADEBUG 611.4Ssato 621.4Ssato#ifdef VRISADEBUG 631.4Ssato#ifndef VRISADEBUG_CONF 641.4Ssato#define VRISADEBUG_CONF 0 651.4Ssato#endif /* VRISADEBUG_CONF */ 661.4Ssatoint vrisa_debug = VRISADEBUG_CONF; 671.4Ssato#define DPRINTF(arg) if (vrisa_debug) printf arg; 681.23Such#define DBITDISP(mask) if (vrisa_debug) dbg_bit_print(mask); 691.8Sjdolecek#define VPRINTF(arg) if (bootverbose || vrisa_debug) printf arg; 701.4Ssato#else /* VRISADEBUG */ 711.4Ssato#define DPRINTF(arg) 721.23Such#define DBITDISP(mask) 731.8Sjdolecek#define VPRINTF(arg) if (bootverbose) printf arg; 741.4Ssato#endif /* VRISADEBUG */ 751.4Ssato 761.13Stakemura/* 771.13Stakemura * intrrupt no. encoding: 781.13Stakemura * 791.13Stakemura * 0x0000000f ISA IRQ# 801.13Stakemura * 0x00ff0000 GPIO port# 811.13Stakemura * 0x01000000 interrupt signal hold/through (1:hold/0:though) 821.13Stakemura * 0x02000000 interrupt detection level (1:low /0:high ) 831.13Stakemura * 0x04000000 interrupt detection trigger (1:edge/0:level ) 841.13Stakemura */ 851.13Stakemura#define INTR_IRQ(i) (((i)>> 0) & 0x0f) 861.13Stakemura#define INTR_PORT(i) (((i)>>16) & 0xff) 871.13Stakemura#define INTR_MODE(i) (((i)>>24) & 0x07) 881.13Stakemura#define INTR_NIRQS 16 891.13Stakemura 901.16Suchint vrisabprint(void *, const char *); 911.16Suchint vrisabmatch(struct device *, struct cfdata *, void *); 921.16Suchvoid vrisabattach(struct device *, struct device *, void *); 931.1Stakemura 941.1Stakemurastruct vrisab_softc { 951.1Stakemura struct device sc_dev; 961.13Stakemura hpcio_chip_t sc_hc; 971.13Stakemura int sc_intr_map[INTR_NIRQS]; /* ISA <-> GIU inerrupt line mapping */ 981.3Stakemura struct hpcmips_isa_chipset sc_isa_ic; 991.1Stakemura}; 1001.1Stakemura 1011.27SthorpejCFATTACH_DECL(vrisab, sizeof(struct vrisab_softc), 1021.27Sthorpej vrisabmatch, vrisabattach, NULL, NULL); 1031.1Stakemura 1041.1Stakemura#ifdef DEBUG_FIND_PCIC 1051.1Stakemura#include <mips/cpuregs.h> 1061.1Stakemura#warning DEBUG_FIND_PCIC 1071.16Suchstatic void __find_pcic(void); 1081.1Stakemura#endif 1091.1Stakemura 1101.11Ssato#ifdef DEBUG_FIND_COMPORT 1111.11Ssato#include <mips/cpuregs.h> 1121.11Ssato#include <dev/ic/ns16550reg.h> 1131.11Ssato#include <dev/ic/comreg.h> 1141.11Ssato#warning DEBUG_FIND_COMPORT 1151.16Suchstatic void __find_comport(void); 1161.11Ssato#endif 1171.11Ssato 1181.1Stakemuraint 1191.16Suchvrisabmatch(struct device *parent, struct cfdata *match, void *aux) 1201.1Stakemura{ 1211.13Stakemura struct hpcio_attach_args *haa = aux; 1221.1Stakemura platid_mask_t mask; 1231.20Stakemura int n; 1241.20Stakemura 1251.25Sthorpej if (strcmp(haa->haa_busname, match->cf_name)) 1261.16Such return (0); 1271.16Such 1281.13Stakemura if (match->cf_loc[HPCIOIFCF_PLATFORM] == HPCIOIFCF_PLATFORM_DEFAULT) 1291.16Such return (1); 1301.16Such 1311.13Stakemura mask = PLATID_DEREF(match->cf_loc[HPCIOIFCF_PLATFORM]); 1321.20Stakemura if ((n = platid_match(&platid, &mask)) != 0) 1331.20Stakemura return (n + 2); 1341.16Such 1351.16Such return (0); 1361.1Stakemura} 1371.1Stakemura 1381.1Stakemuravoid 1391.16Suchvrisabattach(struct device *parent, struct device *self, void *aux) 1401.1Stakemura{ 1411.13Stakemura struct hpcio_attach_args *haa = aux; 1421.1Stakemura struct vrisab_softc *sc = (void*)self; 1431.1Stakemura struct isabus_attach_args iba; 1441.18Stakemura struct bus_space_tag_hpcmips *iot, *memt; 1451.1Stakemura bus_addr_t offset; 1461.1Stakemura int i; 1471.1Stakemura 1481.13Stakemura sc->sc_hc = (*haa->haa_getchip)(haa->haa_sc, VRIP_IOCHIP_VRGIU); 1491.3Stakemura sc->sc_isa_ic.ic_sc = sc; 1501.1Stakemura 1511.1Stakemura iba.iba_busname = "isa"; 1521.3Stakemura iba.iba_ic = &sc->sc_isa_ic; 1531.1Stakemura iba.iba_dmat = 0; /* XXX not yet */ 1541.1Stakemura 1551.1Stakemura /* Allocate ISA memory space */ 1561.19Stakemura memt = hpcmips_alloc_bus_space_tag(); 1571.1Stakemura offset = sc->sc_dev.dv_cfdata->cf_loc[VRISABIFCF_ISAMEMOFFSET]; 1581.19Stakemura hpcmips_init_bus_space(memt, 1591.19Stakemura (struct bus_space_tag_hpcmips *)haa->haa_iot, "ISA mem", 1601.18Stakemura VR_ISA_MEM_BASE + offset, VR_ISA_MEM_SIZE - offset); 1611.19Stakemura iba.iba_memt = &memt->bst; 1621.1Stakemura 1631.1Stakemura /* Allocate ISA port space */ 1641.19Stakemura iot = hpcmips_alloc_bus_space_tag(); 1651.1Stakemura offset = sc->sc_dev.dv_cfdata->cf_loc[VRISABIFCF_ISAPORTOFFSET]; 1661.19Stakemura hpcmips_init_bus_space(iot, 1671.19Stakemura (struct bus_space_tag_hpcmips *)haa->haa_iot, "ISA port", 1681.18Stakemura VR_ISA_PORT_BASE + offset, VR_ISA_PORT_SIZE - offset); 1691.19Stakemura iba.iba_iot = &iot->bst; 1701.1Stakemura 1711.1Stakemura#ifdef DEBUG_FIND_PCIC 1721.1Stakemura#warning DEBUG_FIND_PCIC 1731.1Stakemura __find_pcic(); 1741.1Stakemura#else 1751.1Stakemura /* Initialize ISA IRQ <-> GPIO mapping */ 1761.13Stakemura for (i = 0; i < INTR_NIRQS; i++) 1771.1Stakemura sc->sc_intr_map[i] = -1; 1781.15Senami printf(": ISA port %#x-%#x mem %#x-%#x\n", 1791.18Stakemura iot->base, iot->base + iot->size, 1801.18Stakemura memt->base, memt->base + memt->size); 1811.1Stakemura config_found(self, &iba, vrisabprint); 1821.1Stakemura#endif 1831.11Ssato 1841.11Ssato#ifdef DEBUG_FIND_COMPORT 1851.11Ssato#warning DEBUG_FIND_COMPORT 1861.11Ssato __find_comport(); 1871.11Ssato#endif 1881.1Stakemura} 1891.1Stakemura 1901.1Stakemuraint 1911.16Suchvrisabprint(void *aux, const char *pnp) 1921.1Stakemura{ 1931.1Stakemura if (pnp) 1941.1Stakemura return (QUIET); 1951.16Such 1961.1Stakemura return (UNCONF); 1971.1Stakemura} 1981.1Stakemura 1991.1Stakemuravoid 2001.16Suchisa_attach_hook(struct device *parent, struct device *self, 2011.16Such struct isabus_attach_args *iba) 2021.1Stakemura{ 2031.16Such 2041.6Scgd} 2051.6Scgd 2061.6Scgdconst struct evcnt * 2071.6Scgdisa_intr_evcnt(isa_chipset_tag_t ic, int irq) 2081.6Scgd{ 2091.6Scgd 2101.6Scgd /* XXX for now, no evcnt parent reported */ 2111.16Such return (NULL); 2121.1Stakemura} 2131.1Stakemura 2141.1Stakemuravoid * 2151.16Suchisa_intr_establish(isa_chipset_tag_t ic, int intr, int type, int level, 2161.16Such int (*ih_fun)(void*), void *ih_arg) 2171.1Stakemura{ 2181.3Stakemura struct vrisab_softc *sc = ic->ic_sc; 2191.3Stakemura int port, irq, mode; 2201.2Stakemura 2211.2Stakemura static int intr_modes[8] = { 2221.13Stakemura HPCIO_INTR_LEVEL_HIGH_THROUGH, 2231.13Stakemura HPCIO_INTR_LEVEL_HIGH_HOLD, 2241.13Stakemura HPCIO_INTR_LEVEL_LOW_THROUGH, 2251.13Stakemura HPCIO_INTR_LEVEL_LOW_HOLD, 2261.13Stakemura HPCIO_INTR_EDGE_THROUGH, 2271.13Stakemura HPCIO_INTR_EDGE_HOLD, 2281.13Stakemura HPCIO_INTR_EDGE_THROUGH, 2291.13Stakemura HPCIO_INTR_EDGE_HOLD, 2301.2Stakemura }; 2311.4Ssato#ifdef VRISADEBUG 2321.2Stakemura static char* intr_mode_names[8] = { 2331.2Stakemura "level high through", 2341.2Stakemura "level high hold", 2351.2Stakemura "level low through", 2361.2Stakemura "level low hold", 2371.2Stakemura "edge through", 2381.2Stakemura "edge hold", 2391.2Stakemura "edge through", 2401.2Stakemura "edge hold", 2411.2Stakemura }; 2421.4Ssato#endif /* VRISADEBUG */ 2431.1Stakemura /* 2441.1Stakemura * ISA IRQ <-> GPIO port mapping 2451.1Stakemura */ 2461.2Stakemura irq = INTR_IRQ(intr); 2471.3Stakemura if (sc->sc_intr_map[irq] != -1) { 2481.3Stakemura /* already mapped */ 2491.3Stakemura intr = sc->sc_intr_map[irq]; 2501.2Stakemura } else { 2511.3Stakemura /* not mapped yet */ 2521.3Stakemura sc->sc_intr_map[irq] = intr; /* Register it */ 2531.1Stakemura } 2541.3Stakemura mode = INTR_MODE(intr); 2551.3Stakemura port = INTR_PORT(intr); 2561.3Stakemura 2571.14Stakemura VPRINTF(("ISA IRQ %d -> %s port %d, %s\n", 2581.16Such irq, sc->sc_hc->hc_name, port, intr_mode_names[mode])); 2591.3Stakemura 2601.1Stakemura /* Call Vr routine */ 2611.16Such return (hpcio_intr_establish(sc->sc_hc, port, intr_modes[mode], 2621.16Such ih_fun, ih_arg)); 2631.1Stakemura} 2641.1Stakemura 2651.1Stakemuravoid 2661.1Stakemuraisa_intr_disestablish(ic, arg) 2671.1Stakemura isa_chipset_tag_t ic; 2681.1Stakemura void *arg; 2691.1Stakemura{ 2701.3Stakemura struct vrisab_softc *sc = ic->ic_sc; 2711.1Stakemura /* Call Vr routine */ 2721.13Stakemura hpcio_intr_disestablish(sc->sc_hc, arg); 2731.1Stakemura} 2741.1Stakemura 2751.1Stakemuraint 2761.16Suchisa_intr_alloc(isa_chipset_tag_t ic, int mask, int type, int *irq) 2771.1Stakemura{ 2781.1Stakemura /* XXX not coded yet. this is temporary XXX */ 2791.4Ssato DPRINTF(("isa_intr_alloc:")); 2801.23Such DBITDISP(mask); 2811.3Stakemura *irq = (ffs(mask) -1); /* XXX */ 2821.16Such 2831.16Such return (0); 2841.1Stakemura} 2851.1Stakemura 2861.1Stakemura#ifdef DEBUG_FIND_PCIC 2871.1Stakemura#warning DEBUG_FIND_PCIC 2881.1Stakemurastatic void 2891.1Stakemura__find_pcic(void) 2901.1Stakemura{ 2911.1Stakemura int i, j, step, found; 2921.1Stakemura u_int32_t addr; 2931.1Stakemura u_int8_t reg; 2941.1Stakemura int __read_revid (u_int32_t port) 2951.16Such { 2961.16Such addr = MIPS_PHYS_TO_KSEG1(i + port); 2971.16Such printf("%#x\r", i); 2981.16Such for (found = 0, j = 0; j < 0x100; j += 0x40) { 2991.16Such *((volatile u_int8_t *)addr) = j; 3001.16Such reg = *((volatile u_int8_t *)(addr + 1)); 3011.1Stakemura#ifdef DEBUG_FIND_PCIC_I82365SL_ONLY 3021.16Such if (reg == 0x82 || reg == 0x83) { 3031.1Stakemura#else 3041.17Sshin if ((reg & 0xc0) == 0x80) { 3051.1Stakemura#endif 3061.16Such found++; 3071.16Such } 3081.16Such if (found) 3091.16Such printf("\nfound %d socket at %#x" 3101.16Such "(base from %#x)\n", found, addr, 3111.16Such i + port - VR_ISA_PORT_BASE); 3121.17Sshin } 3131.16Such } 3141.1Stakemura step = 0x1000000; 3151.1Stakemura printf("\nFinding PCIC. Trying ISA port %#x-%#x step %#x\n", 3161.16Such VR_ISA_PORT_BASE, VR_ISA_PORT_BASE + VR_ISA_PORT_SIZE, step); 3171.16Such for (i = VR_ISA_PORT_BASE; i < VR_ISA_PORT_BASE+VR_ISA_PORT_SIZE; 3181.16Such i+= step) { 3191.1Stakemura __read_revid (0x3e0); 3201.1Stakemura __read_revid (0x3e2); 3211.11Ssato } 3221.11Ssato} 3231.16Such#endif /* DEBUG_FIND_PCIC */ 3241.11Ssato 3251.11Ssato 3261.11Ssato#ifdef DEBUG_FIND_COMPORT 3271.11Ssato#warning DEBUG_FIND_COMPORT 3281.11Ssato 3291.16Suchstatic int probe_com(u_int32_t); 3301.11Ssato 3311.16Suchstatic int 3321.16Suchprobe_com(u_int32_t port_addr) 3331.11Ssato{ 3341.16Such u_int32_t addr; 3351.16Such u_int8_t ubtmp1, ubtmp2; 3361.11Ssato 3371.16Such addr = MIPS_PHYS_TO_KSEG1(port_addr); 3381.11Ssato 3391.16Such *((volatile u_int8_t *)(addr + com_cfcr)) = LCR_8BITS; 3401.16Such *((volatile u_int8_t *)(addr + com_iir)) = 0; 3411.11Ssato 3421.16Such ubtmp1 = *((volatile u_int8_t *)(addr + com_cfcr)); 3431.16Such ubtmp2 = *((volatile u_int8_t *)(addr + com_iir)); 3441.11Ssato 3451.16Such if ((ubtmp1 != LCR_8BITS) || ((ubtmp2 & 0x38) != 0)) { 3461.16Such return (0); 3471.11Ssato } 3481.11Ssato 3491.16Such return (1); 3501.11Ssato} 3511.11Ssato 3521.11Ssatostatic void 3531.16Such__find_comport() 3541.11Ssato{ 3551.16Such int found; 3561.16Such u_int32_t port, step; 3571.11Ssato 3581.11Ssato found = 0; 3591.11Ssato step = 0x08; 3601.11Ssato 3611.11Ssato printf("Searching COM port. Trying ISA port %#x-%#x step %#x\n", 3621.16Such VR_ISA_PORT_BASE, VR_ISA_PORT_BASE + VR_ISA_PORT_SIZE - 1, step ); 3631.11Ssato 3641.16Such for (port = VR_ISA_PORT_BASE; 3651.16Such port < (VR_ISA_PORT_BASE + VR_ISA_PORT_SIZE); port += step){ 3661.16Such if (probe_com(port)) { 3671.11Ssato found++; 3681.16Such printf("found %d at %#x\n", found, port); 3691.11Ssato } 3701.1Stakemura } 3711.1Stakemura} 3721.16Such#endif /* DEBUG_FIND_COMPORT */ 373