1 /* $NetBSD: oioc.c,v 1.1 2009/02/10 06:04:56 rumble Exp $ */ 2 3 /* 4 * Copyright (c) 2009 Stephen M. Rumble 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. The name of the author may not be used to endorse or promote products 13 * derived from this software without specific prior written permission. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 /* 28 * IOC1/IOC2 chips on IP4 and IP6/IP10 machines. This interfaces the SCSI 29 * and Ethernet controllers, performs DMA for the former, and does address 30 * space translation for the latter (maps the lance memory space to physical 31 * pages). 32 * 33 * 'I/O Controller' is a sufficiently generic name that SGI created another 34 * one for IP24, which basically stuffed a bunch of miscellany on an ASIC. 35 * So, we'll call ourselves 'Old IOC' and hope that there wasn't an even older 36 * one. 37 */ 38 39 #include <sys/cdefs.h> 40 __KERNEL_RCSID(0, "$NetBSD: oioc.c,v 1.1 2009/02/10 06:04:56 rumble Exp $"); 41 42 #include <sys/param.h> 43 #include <sys/device.h> 44 45 #define _SGIMIPS_BUS_DMA_PRIVATE 46 #include <machine/cpu.h> 47 #include <machine/locore.h> 48 #include <machine/autoconf.h> 49 #include <machine/bus.h> 50 #include <machine/machtype.h> 51 #include <machine/sysconf.h> 52 53 #include <sgimips/ioc/oiocreg.h> 54 #include <sgimips/ioc/oiocvar.h> 55 56 #include "locators.h" 57 58 struct oioc_softc { 59 struct device sc_dev; 60 61 int sc_burst_dma; 62 63 bus_space_tag_t sc_iot; 64 bus_space_handle_t sc_ioh; 65 }; 66 67 static int oioc_match(struct device *, struct cfdata *, void *); 68 static void oioc_attach(struct device *, struct device *, void *); 69 static int oioc_print(void *, const char *); 70 71 CFATTACH_DECL(oioc, sizeof(struct oioc_softc), 72 oioc_match, oioc_attach, NULL, NULL); 73 74 struct oioc_device { 75 const char *od_name; 76 int od_irq; 77 } oioc_devices[] = { 78 { "oiocsc", 4 }, 79 { "le", 5 }, 80 { NULL, 0 } 81 }; 82 83 static int 84 oioc_match(struct device * parent, struct cfdata * match, void *aux) 85 { 86 87 switch(mach_type) { 88 case MACH_SGI_IP4: 89 case MACH_SGI_IP6 | MACH_SGI_IP10: 90 return (1); 91 } 92 93 return (0); 94 } 95 96 static void 97 oioc_attach(struct device * parent, struct device * self, void *aux) 98 { 99 struct oioc_softc *sc = (struct oioc_softc *)self; 100 struct mainbus_attach_args *ma = aux; 101 uint32_t reg1, reg2; 102 int oiocrev, i; 103 104 sc->sc_iot = SGIMIPS_BUS_SPACE_NORMAL; 105 if (bus_space_map(sc->sc_iot, ma->ma_addr, 0, 106 BUS_SPACE_MAP_LINEAR, &sc->sc_ioh)) 107 panic("oioc_attach: could not allocate memory\n"); 108 109 if (platform.badaddr((void *)MIPS_PHYS_TO_KSEG1(ma->ma_addr + 110 OIOC2_CONFIG), 4)) 111 oiocrev = 1; 112 else 113 oiocrev = 2; 114 115 printf("\noioc0: Old SGI IOC%d\n", oiocrev); 116 117 if (oiocrev == 2) { 118 char buf[64]; 119 120 /* Try to enable burst mode. If we can't, we can't... */ 121 reg1 = 12 << OIOC2_CONFIG_HIWAT_SHFT; 122 reg1 |= OIOC2_CONFIG_BURST_MASK; 123 bus_space_write_4(sc->sc_iot, sc->sc_ioh, OIOC2_CONFIG, reg1); 124 DELAY(1000); 125 reg2 = bus_space_read_4(sc->sc_iot, sc->sc_ioh, OIOC2_CONFIG); 126 if ((reg2 & (reg1 | OIOC2_CONFIG_NOSYNC_MASK)) == reg1) 127 sc->sc_burst_dma = 1; 128 129 snprintb(buf, sizeof(buf), 130 "\177\020" 131 "f\0\4HIWAT\0" 132 "f\4\2ID\0" 133 "b\6NOSYNC\0" 134 "b\7BURST\0" 135 "f\x8\7COUNT\0" 136 "f\x10\6SCP\0" 137 "f\x1c\4IOP\0\0", 138 (u_quad_t)reg2 & 0xffffffff); 139 printf("oioc0: %s\n", buf); 140 } 141 142 printf("oioc0: Burst DMA %ssupported\n", 143 (sc->sc_burst_dma) ? "" : "not "); 144 145 for (i = 0; oioc_devices[i].od_name != NULL; i++) { 146 struct oioc_attach_args oa; 147 148 oa.oa_name = oioc_devices[i].od_name; 149 oa.oa_irq = oioc_devices[i].od_irq; 150 oa.oa_burst_dma = sc->sc_burst_dma; 151 oa.oa_st = SGIMIPS_BUS_SPACE_NORMAL; 152 oa.oa_sh = sc->sc_ioh; 153 oa.oa_dmat = &sgimips_default_bus_dma_tag; 154 config_found_ia(self, "oioc", &oa, oioc_print); 155 } 156 } 157 158 static int 159 oioc_print(void *aux, const char *pnp) 160 { 161 struct oioc_attach_args *oa = aux; 162 163 if (pnp) 164 printf("%s at %s", oa->oa_name, pnp); 165 166 return (UNCONF); 167 } 168