obio.c revision 1.5
11.5Sgwr/* $NetBSD: obio.c,v 1.5 1997/04/25 15:35:27 gwr 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.1Sgwr 391.1Sgwr#include <sys/param.h> 401.1Sgwr#include <sys/systm.h> 411.1Sgwr#include <sys/device.h> 421.1Sgwr 431.1Sgwr#include <machine/autoconf.h> 441.3Sgwr#include <machine/machdep.h> 451.1Sgwr#include <machine/mon.h> 461.1Sgwr#include <machine/obio.h> 471.3Sgwr#include <machine/pte.h> 481.2Sgwr 491.1Sgwrshort *enable_reg; 501.1Sgwr 511.1Sgwrstatic int obio_match __P((struct device *, struct cfdata *, void *)); 521.1Sgwrstatic void obio_attach __P((struct device *, struct device *, void *)); 531.1Sgwrstatic int obio_print __P((void *, const char *parentname)); 541.1Sgwrstatic int obio_submatch __P((struct device *, struct cfdata *, void *)); 551.1Sgwr 561.1Sgwrstruct cfattach obio_ca = { 571.1Sgwr sizeof(struct device), obio_match, obio_attach 581.1Sgwr}; 591.1Sgwr 601.1Sgwrstruct cfdriver obio_cd = { 611.1Sgwr NULL, "obio", DV_DULL 621.1Sgwr}; 631.1Sgwr 641.1Sgwrstatic int 651.1Sgwrobio_match(parent, cf, aux) 661.1Sgwr struct device *parent; 671.1Sgwr struct cfdata *cf; 681.1Sgwr void *aux; 691.1Sgwr{ 701.1Sgwr struct confargs *ca = aux; 711.1Sgwr 721.1Sgwr if (ca->ca_bustype != BUS_OBIO) 731.1Sgwr return (0); 741.1Sgwr return(1); 751.1Sgwr} 761.1Sgwr 771.1Sgwr/* 781.1Sgwr * We need some control over the order of attachment on OBIO, 791.1Sgwr * and all OBIO device addresses are known and fixed foerver. 801.1Sgwr * Therefore, this uses a list of addresses to attach. 811.1Sgwr * XXX - Any other way to control search/attach order? 821.5Sgwr * 831.5Sgwr * Warning: This whole list is very carefully ordered! 841.5Sgwr * In general, anything not already shown here should 851.5Sgwr * be added at or near the end. 861.1Sgwr */ 871.1Sgwrstatic int obio_alist[] = { 881.5Sgwr 891.5Sgwr /* Misc. registers - needed by many things */ 901.5Sgwr OBIO_ENABLEREG, 911.5Sgwr OBIO_BUSERRREG, 921.5Sgwr OBIO_DIAGREG, /* leds.c */ 931.5Sgwr OBIO_IDPROM1, /* idprom.c (3/470) */ 941.5Sgwr OBIO_MEMREG, /* memerr.c */ 951.5Sgwr OBIO_INTERREG, /* intreg.c */ 961.5Sgwr 971.5Sgwr /* Zilog UARTs */ 981.1Sgwr OBIO_ZS_KBD_MS, 991.1Sgwr OBIO_ZS_TTY_AB, 1001.1Sgwr 1011.5Sgwr /* eeprom.c */ 1021.5Sgwr OBIO_EEPROM, 1031.1Sgwr 1041.5Sgwr /* Note: This must come after OBIO_IDPROM1. */ 1051.5Sgwr OBIO_IDPROM2, /* idprom.c (3/80) */ 1061.1Sgwr 1071.5Sgwr /* Note: Must probe for the Intersil first! */ 1081.5Sgwr OBIO_CLOCK1, /* clock.c (3/470) */ 1091.5Sgwr OBIO_CLOCK2, /* clock.c (3/80) */ 1101.4Sgwr 1111.4Sgwr /* This is used by the Ethernet and SCSI drivers. */ 1121.1Sgwr OBIO_IOMMU, 1131.1Sgwr 1141.1Sgwr OBIO_INTEL_ETHER, 1151.1Sgwr OBIO_LANCE_ETHER, 1161.1Sgwr 1171.4Sgwr OBIO_EMULEX_SCSI, /* 3/80 only */ 1181.4Sgwr 1191.1Sgwr /* ...todo... */ 1201.1Sgwr OBIO_FDC, 1211.1Sgwr OBIO_PRINTER_PORT, 1221.1Sgwr}; 1231.4Sgwr#define OBIO_ALIST_LEN (sizeof(obio_alist) / \ 1241.4Sgwr sizeof(obio_alist[0])) 1251.1Sgwr 1261.1Sgwrstatic void 1271.1Sgwrobio_attach(parent, self, aux) 1281.1Sgwr struct device *parent; 1291.1Sgwr struct device *self; 1301.1Sgwr void *aux; 1311.1Sgwr{ 1321.1Sgwr struct confargs *ca = aux; 1331.1Sgwr int i; 1341.1Sgwr 1351.1Sgwr printf("\n"); 1361.1Sgwr 1371.5Sgwr /* Configure these in the order listed above. */ 1381.1Sgwr for (i = 0; i < OBIO_ALIST_LEN; i++) { 1391.5Sgwr /* Our parent set ca->ca_bustype already. */ 1401.1Sgwr ca->ca_paddr = obio_alist[i]; 1411.5Sgwr /* These are filled-in by obio_submatch. */ 1421.1Sgwr ca->ca_intpri = -1; 1431.1Sgwr ca->ca_intvec = -1; 1441.1Sgwr (void) config_found_sm(self, ca, obio_print, obio_submatch); 1451.1Sgwr } 1461.1Sgwr} 1471.1Sgwr 1481.1Sgwr/* 1491.1Sgwr * Print out the confargs. The (parent) name is non-NULL 1501.1Sgwr * when there was no match found by config_found(). 1511.1Sgwr */ 1521.1Sgwrstatic int 1531.1Sgwrobio_print(args, name) 1541.1Sgwr void *args; 1551.1Sgwr const char *name; 1561.1Sgwr{ 1571.1Sgwr 1581.1Sgwr /* Be quiet about empty OBIO locations. */ 1591.1Sgwr if (name) 1601.1Sgwr return(QUIET); 1611.1Sgwr 1621.5Sgwr /* Otherwise do the usual. */ 1631.5Sgwr return(bus_print(args, name)); 1641.1Sgwr} 1651.1Sgwr 1661.1Sgwrint 1671.1Sgwrobio_submatch(parent, cf, aux) 1681.1Sgwr struct device *parent; 1691.1Sgwr struct cfdata *cf; 1701.1Sgwr void *aux; 1711.1Sgwr{ 1721.1Sgwr struct confargs *ca = aux; 1731.1Sgwr cfmatch_t submatch; 1741.1Sgwr 1751.1Sgwr /* 1761.5Sgwr * Note that a defaulted address locator can never match 1771.5Sgwr * the value of ca->ca_paddr set by the obio_attach loop. 1781.5Sgwr * Without this diagnostic, any device with a defaulted 1791.5Sgwr * address locator would always be silently unmatched. 1801.5Sgwr * Therefore, just disallow default addresses on OBIO. 1811.1Sgwr */ 1821.1Sgwr#ifdef DIAGNOSTIC 1831.1Sgwr if (cf->cf_paddr == -1) 1841.1Sgwr panic("obio_submatch: invalid address for: %s%d\n", 1851.1Sgwr cf->cf_driver->cd_name, cf->cf_unit); 1861.1Sgwr#endif 1871.1Sgwr 1881.5Sgwr /* 1891.5Sgwr * Note that obio_attach calls config_found_sm() with 1901.5Sgwr * this function as the "submatch" and ca->ca_paddr 1911.5Sgwr * set to each of the possible OBIO locations, so we 1921.5Sgwr * want to reject any unmatched address here. 1931.5Sgwr */ 1941.1Sgwr if (cf->cf_paddr != ca->ca_paddr) 1951.1Sgwr return 0; 1961.1Sgwr 1971.5Sgwr /* 1981.5Sgwr * Copy the locators into our confargs for the child. 1991.5Sgwr * Note: ca->ca_bustype was set by our parent driver 2001.5Sgwr * (mainbus) and ca->ca_paddr was set by obio_attach. 2011.5Sgwr */ 2021.5Sgwr ca->ca_intpri = cf->cf_intpri; 2031.5Sgwr ca->ca_intvec = cf->cf_intvec; 2041.5Sgwr 2051.1Sgwr /* Now call the match function of the potential child. */ 2061.1Sgwr submatch = cf->cf_attach->ca_match; 2071.1Sgwr if (submatch == NULL) 2081.1Sgwr panic("obio_submatch: no match function for: %s\n", 2091.1Sgwr cf->cf_driver->cd_name); 2101.1Sgwr 2111.1Sgwr return ((*submatch)(parent, cf, aux)); 2121.1Sgwr} 2131.1Sgwr 2141.1Sgwr 2151.1Sgwr/*****************************************************************/ 2161.1Sgwr 2171.1Sgwr/* 2181.1Sgwr * This is our record of "interesting" OBIO mappings that 2191.1Sgwr * the PROM has left in the virtual space reserved for it. 2201.1Sgwr * Each non-null array element holds the virtual address 2211.1Sgwr * of an OBIO mapping where the OBIO address mapped is: 2221.1Sgwr * (array_index * SAVE_INCR) 2231.1Sgwr * and the length of the mapping is one page. 2241.1Sgwr */ 2251.1Sgwrstatic struct prom_map { 2261.1Sgwr vm_offset_t pa, va; 2271.1Sgwr} prom_mappings[] = { 2281.5Sgwr { OBIO_ENABLEREG, 0 }, /* regs: Sys ENA, Bus ERR, etc. */ 2291.1Sgwr { OBIO_ZS_KBD_MS, 0 }, /* Keyboard and Mouse */ 2301.1Sgwr { OBIO_ZS_TTY_AB, 0 }, /* Serial Ports */ 2311.1Sgwr { OBIO_EEPROM, 0 }, /* EEPROM/IDPROM/clock */ 2321.1Sgwr}; 2331.1Sgwr#define PROM_MAP_CNT (sizeof(prom_mappings) / \ 2341.1Sgwr sizeof(prom_mappings[0])) 2351.1Sgwr 2361.1Sgwr/* 2371.1Sgwr * Find a virtual address for a device at physical address 'pa'. 2381.1Sgwr * If one is found among the mappings already made by the PROM 2391.1Sgwr * at power-up time, use it. Otherwise return 0 as a sign that 2401.1Sgwr * a mapping will have to be created. 2411.1Sgwr */ 2421.1Sgwrcaddr_t 2431.1Sgwrobio_find_mapping(int pa, int size) 2441.1Sgwr{ 2451.1Sgwr int i, off; 2461.1Sgwr 2471.1Sgwr if (size >= NBPG) 2481.1Sgwr return (caddr_t)0; 2491.1Sgwr 2501.1Sgwr off = pa & PGOFSET; 2511.1Sgwr pa -= off; 2521.1Sgwr 2531.1Sgwr for (i = 0; i < PROM_MAP_CNT; i++) { 2541.1Sgwr if (pa == prom_mappings[i].pa) { 2551.1Sgwr return ((caddr_t)(prom_mappings[i].va + off)); 2561.1Sgwr } 2571.1Sgwr } 2581.1Sgwr return (caddr_t)0; 2591.1Sgwr} 2601.1Sgwr 2611.1Sgwr/* 2621.1Sgwr * Search the PROM page tables for OBIO mappings that 2631.1Sgwr * we would like to borrow. 2641.1Sgwr */ 2651.1Sgwrstatic void 2661.1Sgwrsave_prom_mappings __P((void)) 2671.1Sgwr{ 2681.1Sgwr int *mon_pte; 2691.1Sgwr vm_offset_t va, pa; 2701.1Sgwr int i; 2711.1Sgwr 2721.1Sgwr /* Note: mon_ctbl[0] maps MON_KDB_START */ 2731.1Sgwr mon_pte = *romVectorPtr->monptaddr; 2741.1Sgwr 2751.1Sgwr for (va = MON_KDB_START; va < MONEND; 2761.1Sgwr va += NBPG, mon_pte++) 2771.1Sgwr { 2781.1Sgwr /* Is this a valid mapping to OBIO? */ 2791.1Sgwr /* XXX - Some macros would be nice... */ 2801.1Sgwr if ((*mon_pte & 0xF0000003) != 0x60000001) 2811.1Sgwr continue; 2821.1Sgwr 2831.1Sgwr /* Yes it is. Is this a mapping we want? */ 2841.1Sgwr pa = *mon_pte & MMU_SHORT_PTE_BASEADDR; 2851.1Sgwr for (i = 0; i < PROM_MAP_CNT; i++) { 2861.1Sgwr if (pa != prom_mappings[i].pa) 2871.1Sgwr continue; 2881.1Sgwr /* Yes, we want it. Save the va? */ 2891.1Sgwr if (prom_mappings[i].va == 0) { 2901.1Sgwr prom_mappings[i].va = va; 2911.1Sgwr } 2921.1Sgwr } 2931.1Sgwr } 2941.1Sgwr 2951.1Sgwr} 2961.1Sgwr 2971.1Sgwr/* 2981.1Sgwr * These are all the OBIO address that are required early in 2991.1Sgwr * the life of the kernel. All are less than one page long. 3001.1Sgwr * This function should make any required mappings that we 3011.1Sgwr * were not able to find among the PROM monitor's mappings. 3021.1Sgwr */ 3031.1Sgwrstatic void 3041.1Sgwrmake_required_mappings __P((void)) 3051.1Sgwr{ 3061.1Sgwr int i; 3071.1Sgwr 3081.1Sgwr for (i = 0; i < PROM_MAP_CNT; i++) { 3091.1Sgwr if (prom_mappings[i].va == 0) { 3101.1Sgwr /* 3111.1Sgwr * Actually, the PROM always has all the 3121.1Sgwr * "required" mappings we need, (smile) 3131.1Sgwr * but this makes sure that is true. 3141.1Sgwr */ 3151.2Sgwr mon_printf("obio: no mapping for pa=0x%x\n", 3161.1Sgwr prom_mappings[i].pa); 3171.2Sgwr sunmon_abort(); /* Ancient PROM? */ 3181.1Sgwr } 3191.1Sgwr } 3201.1Sgwr} 3211.1Sgwr 3221.1Sgwr 3231.1Sgwr/* 3241.1Sgwr * Find mappings for devices that are needed before autoconfiguration. 3251.1Sgwr * We first look for and record any useful PROM mappings, then call 3261.1Sgwr * the "init" functions for drivers that we need to use before the 3271.1Sgwr * normal autoconfiguration calls configure(). Warning: this is 3281.1Sgwr * called before pmap_bootstrap, so no allocation allowed! 3291.1Sgwr */ 3301.1Sgwrvoid 3311.1Sgwrobio_init() 3321.1Sgwr{ 3331.1Sgwr save_prom_mappings(); 3341.1Sgwr make_required_mappings(); 3351.1Sgwr 3361.5Sgwr enable_reg = (short*) obio_find_mapping(OBIO_ENABLEREG, 2); 3371.1Sgwr 3381.5Sgwr /* 3391.5Sgwr * Find the interrupt reg mapping and turn off the 3401.5Sgwr * interrupts, otherwise the PROM clock interrupt 3411.5Sgwr * would poll the zs and toggle some LEDs... 3421.5Sgwr */ 3431.1Sgwr intreg_init(); 3441.5Sgwr 3451.5Sgwr /* Turn on the LEDs so we know power is on. */ 3461.5Sgwr leds_init(); 3471.5Sgwr 3481.5Sgwr /* Make the zs driver ready for console duty. */ 3491.5Sgwr zs_init(); 3501.5Sgwr cninit(); 3511.1Sgwr} 3521.1Sgwr 3531.1Sgwrcaddr_t 3541.5Sgwrobio_mapin(obio_addr, obio_size) 3551.1Sgwr int obio_addr, obio_size; 3561.1Sgwr{ 3571.1Sgwr caddr_t cp; 3581.1Sgwr 3591.1Sgwr cp = obio_find_mapping((vm_offset_t)obio_addr, obio_size); 3601.5Sgwr if (cp) 3611.5Sgwr return (cp); 3621.1Sgwr 3631.1Sgwr cp = bus_mapin(BUS_OBIO, obio_addr, obio_size); 3641.1Sgwr return (cp); 3651.1Sgwr} 366