obio.c revision 1.23
11.23Schs/* $NetBSD: obio.c,v 1.23 2005/01/22 15:36:11 chs Exp $ */ 21.1Sgwr 31.1Sgwr/*- 41.1Sgwr * Copyright (c) 1996 The NetBSD Foundation, Inc. 51.1Sgwr * All rights reserved. 61.1Sgwr * 71.1Sgwr * This code is derived from software contributed to The NetBSD Foundation 81.1Sgwr * by Adam Glass and Gordon W. Ross. 91.1Sgwr * 101.1Sgwr * Redistribution and use in source and binary forms, with or without 111.1Sgwr * modification, are permitted provided that the following conditions 121.1Sgwr * are met: 131.1Sgwr * 1. Redistributions of source code must retain the above copyright 141.1Sgwr * notice, this list of conditions and the following disclaimer. 151.1Sgwr * 2. Redistributions in binary form must reproduce the above copyright 161.1Sgwr * notice, this list of conditions and the following disclaimer in the 171.1Sgwr * documentation and/or other materials provided with the distribution. 181.1Sgwr * 3. All advertising materials mentioning features or use of this software 191.1Sgwr * must display the following acknowledgement: 201.1Sgwr * This product includes software developed by the NetBSD 211.1Sgwr * Foundation, Inc. and its contributors. 221.1Sgwr * 4. Neither the name of The NetBSD Foundation nor the names of its 231.1Sgwr * contributors may be used to endorse or promote products derived 241.1Sgwr * from this software without specific prior written permission. 251.1Sgwr * 261.1Sgwr * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 271.1Sgwr * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 281.1Sgwr * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 291.1Sgwr * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 301.1Sgwr * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 311.1Sgwr * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 321.1Sgwr * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 331.1Sgwr * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 341.1Sgwr * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 351.1Sgwr * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 361.1Sgwr * POSSIBILITY OF SUCH DAMAGE. 371.1Sgwr */ 381.22Slukem 391.22Slukem#include <sys/cdefs.h> 401.23Schs__KERNEL_RCSID(0, "$NetBSD: obio.c,v 1.23 2005/01/22 15:36:11 chs Exp $"); 411.1Sgwr 421.1Sgwr#include <sys/param.h> 431.1Sgwr#include <sys/systm.h> 441.1Sgwr#include <sys/device.h> 451.1Sgwr 461.21Sthorpej#include <uvm/uvm_extern.h> 471.21Sthorpej 481.1Sgwr#include <machine/autoconf.h> 491.1Sgwr#include <machine/mon.h> 501.3Sgwr#include <machine/pte.h> 511.2Sgwr 521.9Sgwr#include <sun3/sun3/machdep.h> 531.9Sgwr#include <sun3/sun3x/obio.h> 541.1Sgwr 551.23Schsstatic int obio_match(struct device *, struct cfdata *, void *); 561.23Schsstatic void obio_attach(struct device *, struct device *, void *); 571.23Schsstatic int obio_print(void *, const char *); 581.23Schsstatic int obio_submatch(struct device *, struct cfdata *, void *); 591.1Sgwr 601.19SthorpejCFATTACH_DECL(obio, sizeof(struct device), 611.20Sthorpej obio_match, obio_attach, NULL, NULL); 621.1Sgwr 631.23Schsstatic int 641.23Schsobio_match(struct device *parent, struct cfdata *cf, void *aux) 651.1Sgwr{ 661.1Sgwr struct confargs *ca = aux; 671.1Sgwr 681.1Sgwr if (ca->ca_bustype != BUS_OBIO) 691.1Sgwr return (0); 701.1Sgwr return(1); 711.1Sgwr} 721.1Sgwr 731.1Sgwr/* 741.10Sgwr * We need control over the order of attachment on OBIO, 751.10Sgwr * so do "direct" style autoconfiguration with addresses 761.10Sgwr * from the list below. OBIO addresses are fixed forever. 771.5Sgwr * 781.5Sgwr * Warning: This whole list is very carefully ordered! 791.5Sgwr * In general, anything not already shown here should 801.5Sgwr * be added at or near the end. 811.1Sgwr */ 821.1Sgwrstatic int obio_alist[] = { 831.5Sgwr 841.10Sgwr /* This is used by the Ethernet and SCSI drivers. */ 851.10Sgwr OBIO_IOMMU, 861.10Sgwr 871.5Sgwr /* Misc. registers - needed by many things */ 881.5Sgwr OBIO_ENABLEREG, 891.5Sgwr OBIO_BUSERRREG, 901.5Sgwr OBIO_DIAGREG, /* leds.c */ 911.5Sgwr OBIO_IDPROM1, /* idprom.c (3/470) */ 921.5Sgwr OBIO_MEMREG, /* memerr.c */ 931.5Sgwr OBIO_INTERREG, /* intreg.c */ 941.5Sgwr 951.5Sgwr /* Zilog UARTs */ 961.1Sgwr OBIO_ZS_KBD_MS, 971.1Sgwr OBIO_ZS_TTY_AB, 981.1Sgwr 991.5Sgwr /* eeprom.c */ 1001.5Sgwr OBIO_EEPROM, 1011.1Sgwr 1021.5Sgwr /* Note: This must come after OBIO_IDPROM1. */ 1031.5Sgwr OBIO_IDPROM2, /* idprom.c (3/80) */ 1041.1Sgwr 1051.5Sgwr /* Note: Must probe for the Intersil first! */ 1061.5Sgwr OBIO_CLOCK1, /* clock.c (3/470) */ 1071.5Sgwr OBIO_CLOCK2, /* clock.c (3/80) */ 1081.4Sgwr 1091.1Sgwr OBIO_INTEL_ETHER, 1101.1Sgwr OBIO_LANCE_ETHER, 1111.1Sgwr 1121.11Sgwr /* Need esp DMA before SCSI. */ 1131.11Sgwr OBIO_EMULEX_DMA, /* 3/80 only */ 1141.4Sgwr OBIO_EMULEX_SCSI, /* 3/80 only */ 1151.4Sgwr 1161.10Sgwr /* Memory subsystem */ 1171.10Sgwr OBIO_PCACHE_TAGS, 1181.10Sgwr OBIO_ECCPARREG, 1191.10Sgwr OBIO_IOC_TAGS, 1201.10Sgwr OBIO_IOC_FLUSH, 1211.10Sgwr 1221.10Sgwr OBIO_FDC, /* floppy disk (3/80) */ 1231.12Stsutsui OBIO_PRINTER_PORT, /* printer port (3/80) */ 1241.1Sgwr}; 1251.4Sgwr#define OBIO_ALIST_LEN (sizeof(obio_alist) / \ 1261.4Sgwr sizeof(obio_alist[0])) 1271.1Sgwr 1281.23Schsstatic void 1291.23Schsobio_attach(struct device *parent, struct device *self, void *aux) 1301.1Sgwr{ 1311.1Sgwr struct confargs *ca = aux; 1321.1Sgwr int i; 1331.1Sgwr 1341.1Sgwr printf("\n"); 1351.1Sgwr 1361.5Sgwr /* Configure these in the order listed above. */ 1371.1Sgwr for (i = 0; i < OBIO_ALIST_LEN; i++) { 1381.5Sgwr /* Our parent set ca->ca_bustype already. */ 1391.1Sgwr ca->ca_paddr = obio_alist[i]; 1401.5Sgwr /* These are filled-in by obio_submatch. */ 1411.1Sgwr ca->ca_intpri = -1; 1421.1Sgwr ca->ca_intvec = -1; 1431.1Sgwr (void) config_found_sm(self, ca, obio_print, obio_submatch); 1441.1Sgwr } 1451.1Sgwr} 1461.1Sgwr 1471.1Sgwr/* 1481.1Sgwr * Print out the confargs. The (parent) name is non-NULL 1491.1Sgwr * when there was no match found by config_found(). 1501.1Sgwr */ 1511.23Schsstatic int 1521.23Schsobio_print(void *args, const char *name) 1531.1Sgwr{ 1541.1Sgwr 1551.1Sgwr /* Be quiet about empty OBIO locations. */ 1561.1Sgwr if (name) 1571.1Sgwr return(QUIET); 1581.1Sgwr 1591.5Sgwr /* Otherwise do the usual. */ 1601.5Sgwr return(bus_print(args, name)); 1611.1Sgwr} 1621.1Sgwr 1631.23Schsint 1641.23Schsobio_submatch(struct device *parent, struct cfdata *cf, void *aux) 1651.1Sgwr{ 1661.1Sgwr struct confargs *ca = aux; 1671.1Sgwr 1681.1Sgwr /* 1691.5Sgwr * Note that a defaulted address locator can never match 1701.5Sgwr * the value of ca->ca_paddr set by the obio_attach loop. 1711.5Sgwr * Without this diagnostic, any device with a defaulted 1721.5Sgwr * address locator would always be silently unmatched. 1731.5Sgwr * Therefore, just disallow default addresses on OBIO. 1741.1Sgwr */ 1751.1Sgwr#ifdef DIAGNOSTIC 1761.1Sgwr if (cf->cf_paddr == -1) 1771.17Sprovos panic("obio_submatch: invalid address for: %s%d", 1781.15Sthorpej cf->cf_name, cf->cf_unit); 1791.1Sgwr#endif 1801.1Sgwr 1811.5Sgwr /* 1821.5Sgwr * Note that obio_attach calls config_found_sm() with 1831.5Sgwr * this function as the "submatch" and ca->ca_paddr 1841.5Sgwr * set to each of the possible OBIO locations, so we 1851.5Sgwr * want to reject any unmatched address here. 1861.5Sgwr */ 1871.1Sgwr if (cf->cf_paddr != ca->ca_paddr) 1881.1Sgwr return 0; 1891.1Sgwr 1901.5Sgwr /* 1911.5Sgwr * Copy the locators into our confargs for the child. 1921.5Sgwr * Note: ca->ca_bustype was set by our parent driver 1931.5Sgwr * (mainbus) and ca->ca_paddr was set by obio_attach. 1941.5Sgwr */ 1951.5Sgwr ca->ca_intpri = cf->cf_intpri; 1961.5Sgwr ca->ca_intvec = cf->cf_intvec; 1971.5Sgwr 1981.1Sgwr /* Now call the match function of the potential child. */ 1991.16Sthorpej return (config_match(parent, cf, aux)); 2001.1Sgwr} 2011.1Sgwr 2021.1Sgwr 2031.1Sgwr/*****************************************************************/ 2041.1Sgwr 2051.1Sgwr/* 2061.1Sgwr * This is our record of "interesting" OBIO mappings that 2071.1Sgwr * the PROM has left in the virtual space reserved for it. 2081.10Sgwr * Each row of the array holds a virtual address and the 2091.10Sgwr * physical address it maps to (if found). 2101.1Sgwr */ 2111.1Sgwrstatic struct prom_map { 2121.13Stsutsui paddr_t pa; 2131.13Stsutsui vaddr_t va; 2141.1Sgwr} prom_mappings[] = { 2151.5Sgwr { OBIO_ENABLEREG, 0 }, /* regs: Sys ENA, Bus ERR, etc. */ 2161.1Sgwr { OBIO_ZS_KBD_MS, 0 }, /* Keyboard and Mouse */ 2171.1Sgwr { OBIO_ZS_TTY_AB, 0 }, /* Serial Ports */ 2181.1Sgwr { OBIO_EEPROM, 0 }, /* EEPROM/IDPROM/clock */ 2191.1Sgwr}; 2201.1Sgwr#define PROM_MAP_CNT (sizeof(prom_mappings) / \ 2211.1Sgwr sizeof(prom_mappings[0])) 2221.1Sgwr 2231.1Sgwr/* 2241.1Sgwr * Find a virtual address for a device at physical address 'pa'. 2251.1Sgwr * If one is found among the mappings already made by the PROM 2261.1Sgwr * at power-up time, use it. Otherwise return 0 as a sign that 2271.1Sgwr * a mapping will have to be created. 2281.1Sgwr */ 2291.1Sgwrcaddr_t 2301.14Stsutsuiobio_find_mapping(paddr_t pa, psize_t sz) 2311.1Sgwr{ 2321.14Stsutsui int i; 2331.14Stsutsui vsize_t off; 2341.1Sgwr 2351.1Sgwr off = pa & PGOFSET; 2361.1Sgwr pa -= off; 2371.10Sgwr sz += off; 2381.10Sgwr 2391.10Sgwr /* The saved mappings are all one page long. */ 2401.21Sthorpej if (sz > PAGE_SIZE) 2411.10Sgwr return (caddr_t)0; 2421.1Sgwr 2431.10Sgwr /* Linear search for it. The list is short. */ 2441.1Sgwr for (i = 0; i < PROM_MAP_CNT; i++) { 2451.1Sgwr if (pa == prom_mappings[i].pa) { 2461.1Sgwr return ((caddr_t)(prom_mappings[i].va + off)); 2471.1Sgwr } 2481.1Sgwr } 2491.1Sgwr return (caddr_t)0; 2501.1Sgwr} 2511.1Sgwr 2521.1Sgwr/* 2531.1Sgwr * Search the PROM page tables for OBIO mappings that 2541.1Sgwr * we would like to borrow. 2551.1Sgwr */ 2561.1Sgwrstatic void 2571.23Schssave_prom_mappings(void) 2581.1Sgwr{ 2591.1Sgwr int *mon_pte; 2601.13Stsutsui vaddr_t va; 2611.13Stsutsui paddr_t pa; 2621.1Sgwr int i; 2631.1Sgwr 2641.9Sgwr /* Note: mon_ctbl[0] maps SUN3X_MON_KDB_BASE */ 2651.1Sgwr mon_pte = *romVectorPtr->monptaddr; 2661.1Sgwr 2671.9Sgwr for (va = SUN3X_MON_KDB_BASE; va < SUN3X_MONEND; 2681.21Sthorpej va += PAGE_SIZE, mon_pte++) 2691.1Sgwr { 2701.1Sgwr /* Is this a valid mapping to OBIO? */ 2711.1Sgwr /* XXX - Some macros would be nice... */ 2721.1Sgwr if ((*mon_pte & 0xF0000003) != 0x60000001) 2731.1Sgwr continue; 2741.1Sgwr 2751.1Sgwr /* Yes it is. Is this a mapping we want? */ 2761.1Sgwr pa = *mon_pte & MMU_SHORT_PTE_BASEADDR; 2771.1Sgwr for (i = 0; i < PROM_MAP_CNT; i++) { 2781.1Sgwr if (pa != prom_mappings[i].pa) 2791.1Sgwr continue; 2801.1Sgwr /* Yes, we want it. Save the va? */ 2811.1Sgwr if (prom_mappings[i].va == 0) { 2821.1Sgwr prom_mappings[i].va = va; 2831.1Sgwr } 2841.1Sgwr } 2851.1Sgwr } 2861.1Sgwr 2871.1Sgwr} 2881.1Sgwr 2891.1Sgwr/* 2901.1Sgwr * These are all the OBIO address that are required early in 2911.1Sgwr * the life of the kernel. All are less than one page long. 2921.1Sgwr * This function should make any required mappings that we 2931.1Sgwr * were not able to find among the PROM monitor's mappings. 2941.1Sgwr */ 2951.1Sgwrstatic void 2961.23Schsmake_required_mappings(void) 2971.1Sgwr{ 2981.1Sgwr int i; 2991.1Sgwr 3001.1Sgwr for (i = 0; i < PROM_MAP_CNT; i++) { 3011.1Sgwr if (prom_mappings[i].va == 0) { 3021.1Sgwr /* 3031.1Sgwr * Actually, the PROM always has all the 3041.1Sgwr * "required" mappings we need, (smile) 3051.1Sgwr * but this makes sure that is true. 3061.1Sgwr */ 3071.2Sgwr mon_printf("obio: no mapping for pa=0x%x\n", 3081.1Sgwr prom_mappings[i].pa); 3091.2Sgwr sunmon_abort(); /* Ancient PROM? */ 3101.1Sgwr } 3111.1Sgwr } 3121.1Sgwr} 3131.1Sgwr 3141.1Sgwr 3151.1Sgwr/* 3161.1Sgwr * Find mappings for devices that are needed before autoconfiguration. 3171.1Sgwr * We first look for and record any useful PROM mappings, then call 3181.1Sgwr * the "init" functions for drivers that we need to use before the 3191.1Sgwr * normal autoconfiguration calls configure(). Warning: this is 3201.1Sgwr * called before pmap_bootstrap, so no allocation allowed! 3211.1Sgwr */ 3221.23Schsvoid 3231.23Schsobio_init(void) 3241.1Sgwr{ 3251.1Sgwr save_prom_mappings(); 3261.1Sgwr make_required_mappings(); 3271.1Sgwr 3281.9Sgwr enable_init(); 3291.1Sgwr 3301.5Sgwr /* 3311.5Sgwr * Find the interrupt reg mapping and turn off the 3321.5Sgwr * interrupts, otherwise the PROM clock interrupt 3331.5Sgwr * would poll the zs and toggle some LEDs... 3341.5Sgwr */ 3351.1Sgwr intreg_init(); 3361.1Sgwr} 337