1 /* $OpenBSD: stp_sbus.c,v 1.10 2008/06/26 05:42:13 ray Exp $ */ 2 /* $NetBSD: stp4020.c,v 1.23 2002/06/01 23:51:03 lukem Exp $ */ 3 4 /*- 5 * Copyright (c) 1998 The NetBSD Foundation, Inc. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to The NetBSD Foundation 9 * by Paul Kranenburg. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 /* 34 * STP4020: SBus/PCMCIA bridge supporting one Type-3 PCMCIA card, or up to 35 * two Type-1 and Type-2 PCMCIA cards.. 36 */ 37 38 #include <sys/param.h> 39 #include <sys/systm.h> 40 #include <sys/errno.h> 41 #include <sys/malloc.h> 42 #include <sys/extent.h> 43 #include <sys/proc.h> 44 #include <sys/kernel.h> 45 #include <sys/kthread.h> 46 #include <sys/device.h> 47 48 #include <dev/pcmcia/pcmciareg.h> 49 #include <dev/pcmcia/pcmciavar.h> 50 #include <dev/pcmcia/pcmciachip.h> 51 52 #include <machine/bus.h> 53 #include <machine/intr.h> 54 55 #include <dev/sbus/sbusvar.h> 56 #include <dev/sbus/stp4020reg.h> 57 #include <dev/sbus/stp4020var.h> 58 59 struct stp4020_sbus_softc { 60 struct stp4020_softc stp; 61 struct sparc_bus_space_tag *sc_bustag_le; 62 }; 63 64 int stpmatch(struct device *, void *, void *); 65 void stpattach(struct device *, struct device *, void *); 66 67 struct cfattach stp_sbus_ca = { 68 sizeof(struct stp4020_sbus_softc), stpmatch, stpattach 69 }; 70 71 int 72 stpmatch(parent, match, aux) 73 struct device *parent; 74 void *match; 75 void *aux; 76 { 77 struct sbus_attach_args *sa = aux; 78 79 return (strcmp("SUNW,pcmcia", sa->sa_name) == 0); 80 } 81 82 /* 83 * Attach all the sub-devices we can find 84 */ 85 void 86 stpattach(parent, self, aux) 87 struct device *parent, *self; 88 void *aux; 89 { 90 struct sbus_attach_args *sa = aux; 91 struct stp4020_sbus_softc *ssc = (void *)self; 92 struct stp4020_softc *sc = (void *)self; 93 int node; 94 int i; 95 bus_space_tag_t bt; 96 bus_space_handle_t bh; 97 98 node = sa->sa_node; 99 100 /* Allocate little-endian bus tag */ 101 ssc->sc_bustag_le = malloc(sizeof(*sa->sa_bustag), M_DEVBUF, M_NOWAIT); 102 if (ssc->sc_bustag_le == NULL) 103 panic("could not allocate stp bus tag"); 104 *ssc->sc_bustag_le = *sa->sa_bustag; 105 ssc->sc_bustag_le->asi = ASI_PRIMARY_LITTLE; 106 107 /* Transfer bus tags */ 108 sc->sc_bustag = sa->sa_bustag; 109 110 /* Set up per-socket static initialization */ 111 sc->sc_socks[0].sc = sc->sc_socks[1].sc = sc; 112 sc->sc_socks[0].tag = sc->sc_socks[1].tag = sa->sa_bustag; 113 114 if (sa->sa_nreg < 8) { 115 printf(": only %d register sets\n", sa->sa_nreg); 116 return; 117 } 118 119 if (sa->sa_nintr != 2) { 120 printf(": expect 2 interrupt SBus levels; got %d\n", 121 sa->sa_nintr); 122 return; 123 } 124 125 #define STP4020_BANK_PROM 0 126 #define STP4020_BANK_CTRL 4 127 for (i = 0; i < 8; i++) { 128 129 /* 130 * STP4020 Register address map: 131 * bank 0: Forth PROM 132 * banks 1-3: socket 0, windows 0-2 133 * bank 4: control registers 134 * banks 5-7: socket 1, windows 0-2 135 */ 136 137 if (i == STP4020_BANK_PROM) 138 /* Skip the PROM */ 139 continue; 140 141 if (i == STP4020_BANK_CTRL) 142 bt = sc->sc_bustag; 143 else 144 bt = ssc->sc_bustag_le; 145 146 if (sbus_bus_map(bt, sa->sa_reg[i].sbr_slot, 147 sa->sa_reg[i].sbr_offset, sa->sa_reg[i].sbr_size, 0, 0, 148 &bh) != 0) { 149 printf(": attach: cannot map registers\n"); 150 return; 151 } 152 153 if (i == STP4020_BANK_CTRL) { 154 /* 155 * Copy tag and handle to both socket structures 156 * for easy access in control/status IO functions. 157 */ 158 sc->sc_socks[0].regs = sc->sc_socks[1].regs = bh; 159 } else if (i < STP4020_BANK_CTRL) { 160 /* banks 1-3 */ 161 sc->sc_socks[0].windows[i-1].winaddr = bh; 162 sc->sc_socks[0].wintag = bt; 163 } else { 164 /* banks 5-7 */ 165 sc->sc_socks[1].windows[i-5].winaddr = bh; 166 sc->sc_socks[1].wintag = bt; 167 } 168 } 169 170 /* 171 * We get to use two SBus interrupt levels. 172 * The higher level we use for status change interrupts; 173 * the lower level for PC card I/O. 174 */ 175 bus_intr_establish(sa->sa_bustag, sa->sa_intr[1].sbi_pri, 176 IPL_NONE, 0, stp4020_statintr, sc, self->dv_xname); 177 178 bus_intr_establish(sa->sa_bustag, sa->sa_intr[0].sbi_pri, 179 IPL_NONE, 0, stp4020_iointr, sc, self->dv_xname); 180 181 stpattach_common(sc, sa->sa_frequency); 182 } 183