1 /* $OpenBSD: stp_sbus.c,v 1.11 2020/02/18 12:13:39 mpi 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/device.h> 46 47 #include <dev/pcmcia/pcmciareg.h> 48 #include <dev/pcmcia/pcmciavar.h> 49 #include <dev/pcmcia/pcmciachip.h> 50 51 #include <machine/bus.h> 52 #include <machine/intr.h> 53 54 #include <dev/sbus/sbusvar.h> 55 #include <dev/sbus/stp4020reg.h> 56 #include <dev/sbus/stp4020var.h> 57 58 struct stp4020_sbus_softc { 59 struct stp4020_softc stp; 60 struct sparc_bus_space_tag *sc_bustag_le; 61 }; 62 63 int stpmatch(struct device *, void *, void *); 64 void stpattach(struct device *, struct device *, void *); 65 66 struct cfattach stp_sbus_ca = { 67 sizeof(struct stp4020_sbus_softc), stpmatch, stpattach 68 }; 69 70 int 71 stpmatch(parent, match, aux) 72 struct device *parent; 73 void *match; 74 void *aux; 75 { 76 struct sbus_attach_args *sa = aux; 77 78 return (strcmp("SUNW,pcmcia", sa->sa_name) == 0); 79 } 80 81 /* 82 * Attach all the sub-devices we can find 83 */ 84 void 85 stpattach(parent, self, aux) 86 struct device *parent, *self; 87 void *aux; 88 { 89 struct sbus_attach_args *sa = aux; 90 struct stp4020_sbus_softc *ssc = (void *)self; 91 struct stp4020_softc *sc = (void *)self; 92 int node; 93 int i; 94 bus_space_tag_t bt; 95 bus_space_handle_t bh; 96 97 node = sa->sa_node; 98 99 /* Allocate little-endian bus tag */ 100 ssc->sc_bustag_le = malloc(sizeof(*sa->sa_bustag), M_DEVBUF, M_NOWAIT); 101 if (ssc->sc_bustag_le == NULL) 102 panic("could not allocate stp bus tag"); 103 *ssc->sc_bustag_le = *sa->sa_bustag; 104 ssc->sc_bustag_le->asi = ASI_PRIMARY_LITTLE; 105 106 /* Transfer bus tags */ 107 sc->sc_bustag = sa->sa_bustag; 108 109 /* Set up per-socket static initialization */ 110 sc->sc_socks[0].sc = sc->sc_socks[1].sc = sc; 111 sc->sc_socks[0].tag = sc->sc_socks[1].tag = sa->sa_bustag; 112 113 if (sa->sa_nreg < 8) { 114 printf(": only %d register sets\n", sa->sa_nreg); 115 return; 116 } 117 118 if (sa->sa_nintr != 2) { 119 printf(": expect 2 interrupt SBus levels; got %d\n", 120 sa->sa_nintr); 121 return; 122 } 123 124 #define STP4020_BANK_PROM 0 125 #define STP4020_BANK_CTRL 4 126 for (i = 0; i < 8; i++) { 127 128 /* 129 * STP4020 Register address map: 130 * bank 0: Forth PROM 131 * banks 1-3: socket 0, windows 0-2 132 * bank 4: control registers 133 * banks 5-7: socket 1, windows 0-2 134 */ 135 136 if (i == STP4020_BANK_PROM) 137 /* Skip the PROM */ 138 continue; 139 140 if (i == STP4020_BANK_CTRL) 141 bt = sc->sc_bustag; 142 else 143 bt = ssc->sc_bustag_le; 144 145 if (sbus_bus_map(bt, sa->sa_reg[i].sbr_slot, 146 sa->sa_reg[i].sbr_offset, sa->sa_reg[i].sbr_size, 0, 0, 147 &bh) != 0) { 148 printf(": attach: cannot map registers\n"); 149 return; 150 } 151 152 if (i == STP4020_BANK_CTRL) { 153 /* 154 * Copy tag and handle to both socket structures 155 * for easy access in control/status IO functions. 156 */ 157 sc->sc_socks[0].regs = sc->sc_socks[1].regs = bh; 158 } else if (i < STP4020_BANK_CTRL) { 159 /* banks 1-3 */ 160 sc->sc_socks[0].windows[i-1].winaddr = bh; 161 sc->sc_socks[0].wintag = bt; 162 } else { 163 /* banks 5-7 */ 164 sc->sc_socks[1].windows[i-5].winaddr = bh; 165 sc->sc_socks[1].wintag = bt; 166 } 167 } 168 169 /* 170 * We get to use two SBus interrupt levels. 171 * The higher level we use for status change interrupts; 172 * the lower level for PC card I/O. 173 */ 174 bus_intr_establish(sa->sa_bustag, sa->sa_intr[1].sbi_pri, 175 IPL_NONE, 0, stp4020_statintr, sc, self->dv_xname); 176 177 bus_intr_establish(sa->sa_bustag, sa->sa_intr[0].sbi_pri, 178 IPL_NONE, 0, stp4020_iointr, sc, self->dv_xname); 179 180 stpattach_common(sc, sa->sa_frequency); 181 } 182