1 /* $OpenBSD: if_ti_sbus.c,v 1.1 2009/09/01 14:45:44 kettenis Exp $ */ 2 /* 3 * Copyright (c) 2009 Mark Kettenis 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 #include <sys/param.h> 19 #include <sys/device.h> 20 #include <sys/socket.h> 21 #include <sys/systm.h> 22 23 #include <net/if.h> 24 #include <net/if_dl.h> 25 #include <net/if_media.h> 26 27 #ifdef INET 28 #include <netinet/in.h> 29 #include <netinet/in_systm.h> 30 #include <netinet/in_var.h> 31 #include <netinet/ip.h> 32 #include <netinet/if_ether.h> 33 #endif 34 35 #include <machine/bus.h> 36 #include <machine/intr.h> 37 #include <machine/autoconf.h> 38 39 #include <dev/sbus/sbusvar.h> 40 41 #include <dev/pci/pcireg.h> 42 43 #include <dev/ic/tireg.h> 44 #include <dev/ic/tivar.h> 45 46 struct ti_sbus_softc { 47 struct ti_softc tsc_sc; 48 }; 49 50 int ti_sbus_match(struct device *, void *, void *); 51 void ti_sbus_attach(struct device *, struct device *, void *); 52 53 struct cfattach ti_sbus_ca = { 54 sizeof(struct ti_sbus_softc), ti_sbus_match, ti_sbus_attach 55 }; 56 57 int 58 ti_sbus_match(struct device *parent, void *match, void *aux) 59 { 60 struct sbus_attach_args *sa = aux; 61 62 return (strcmp("SUNW,vge", sa->sa_name) == 0); 63 } 64 65 void 66 ti_sbus_attach(struct device *parent, struct device *self, void *aux) 67 { 68 struct sbus_attach_args *sa = aux; 69 struct ti_sbus_softc *tsc = (void *)self; 70 struct ti_softc *sc = &tsc->tsc_sc; 71 bus_space_handle_t ioh; 72 73 /* Pass on the bus tags */ 74 sc->ti_btag = sa->sa_bustag; 75 sc->sc_dmatag = sa->sa_dmatag; 76 77 if (sa->sa_nintr < 1) { 78 printf(": no interrupt\n"); 79 return; 80 } 81 82 if (sa->sa_nreg < 2) { 83 printf(": only %d register sets\n", sa->sa_nreg); 84 return; 85 } 86 87 if (sbus_bus_map(sa->sa_bustag, sa->sa_reg[1].sbr_slot, 88 sa->sa_reg[1].sbr_offset, sa->sa_reg[1].sbr_size, 89 0, 0, &sc->ti_bhandle)) { 90 printf(": can't map registers\n"); 91 return; 92 } 93 94 if (sbus_bus_map(sa->sa_bustag, sa->sa_reg[0].sbr_slot, 95 sa->sa_reg[0].sbr_offset, sa->sa_reg[0].sbr_size, 96 0, 0, &ioh)) { 97 printf(": can't map registers\n"); 98 goto unmap; 99 } 100 101 bus_intr_establish(sa->sa_bustag, sa->sa_pri, IPL_NET, 0, ti_intr, 102 sc, self->dv_xname); 103 104 bus_space_write_4(sa->sa_bustag, ioh, TI_PCI_CMDSTAT, 0x02000006); 105 bus_space_write_4(sa->sa_bustag, ioh, TI_PCI_BIST, 0xffffffff); 106 bus_space_write_4(sa->sa_bustag, ioh, TI_PCI_LOMEM, 0x00000400); 107 108 bus_space_unmap(sa->sa_bustag, ioh, sa->sa_reg[0].sbr_size); 109 110 sc->ti_sbus = 1; 111 if (ti_attach(sc) == 0) 112 return; 113 114 unmap: 115 bus_space_unmap(sa->sa_bustag, sc->ti_bhandle, 116 sa->sa_reg[1].sbr_size); 117 } 118