1 /* $NetBSD: bha_eisa.c,v 1.38 2021/01/27 04:35:15 thorpej Exp $ */ 2 3 /*- 4 * Copyright (c) 1998 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Charles M. Hannum. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include <sys/cdefs.h> 33 __KERNEL_RCSID(0, "$NetBSD: bha_eisa.c,v 1.38 2021/01/27 04:35:15 thorpej Exp $"); 34 35 #include <sys/param.h> 36 #include <sys/systm.h> 37 #include <sys/device.h> 38 39 #include <sys/bus.h> 40 #include <sys/intr.h> 41 42 #include <dev/scsipi/scsipi_all.h> 43 #include <dev/scsipi/scsiconf.h> 44 45 #include <dev/eisa/eisavar.h> 46 #include <dev/eisa/eisadevs.h> 47 48 #include <dev/ic/bhareg.h> 49 #include <dev/ic/bhavar.h> 50 51 #define BHA_EISA_SLOT_OFFSET 0x0c80 52 #define BHA_EISA_IOSIZE 0x0010 53 #define BHA_ISA_IOSIZE 0x0004 54 55 #define BHA_EISA_IOCONF 0x0c 56 57 static int bha_eisa_address(bus_space_tag_t, bus_space_handle_t, int *); 58 static int bha_eisa_match(device_t, cfdata_t, void *); 59 static void bha_eisa_attach(device_t, device_t, void *); 60 61 CFATTACH_DECL_NEW(bha_eisa, sizeof(struct bha_softc), 62 bha_eisa_match, bha_eisa_attach, NULL, NULL); 63 64 static int 65 bha_eisa_address(bus_space_tag_t iot, bus_space_handle_t ioh, int *portp) 66 { 67 int port; 68 69 switch (bus_space_read_1(iot, ioh, BHA_EISA_IOCONF) & 0x07) { 70 case 0x00: 71 port = 0x330; 72 break; 73 case 0x01: 74 port = 0x334; 75 break; 76 case 0x02: 77 port = 0x230; 78 break; 79 case 0x03: 80 port = 0x234; 81 break; 82 case 0x04: 83 port = 0x130; 84 break; 85 case 0x05: 86 port = 0x134; 87 break; 88 default: 89 return (1); 90 } 91 92 *portp = port; 93 return (0); 94 } 95 96 static const struct device_compatible_entry compat_data[] = { 97 { .compat = "BUS4201", .data = EISA_PRODUCT_BUS4201 }, 98 { .compat = "BUS4202", .data = EISA_PRODUCT_BUS4202 }, 99 DEVICE_COMPAT_EOL 100 }; 101 102 /* 103 * Check the slots looking for a board we recognise 104 * If we find one, note its address (slot) and call 105 * the actual probe routine to check it out. 106 */ 107 static int 108 bha_eisa_match(device_t parent, cfdata_t match, void *aux) 109 { 110 struct eisa_attach_args *ea = aux; 111 bus_space_tag_t iot = ea->ea_iot; 112 bus_space_handle_t ioh, ioh2; 113 int port; 114 int rv; 115 116 if (!eisa_compatible_match(ea, compat_data)) 117 return (0); 118 119 if (bus_space_map(iot, 120 EISA_SLOT_ADDR(ea->ea_slot) + BHA_EISA_SLOT_OFFSET, BHA_EISA_IOSIZE, 121 0, &ioh)) 122 return (0); 123 124 if (bha_eisa_address(iot, ioh, &port) || 125 bus_space_map(iot, port, BHA_ISA_IOSIZE, 0, &ioh2)) { 126 bus_space_unmap(iot, ioh, BHA_EISA_IOSIZE); 127 return (0); 128 } 129 130 rv = bha_find(iot, ioh2); 131 132 bus_space_unmap(iot, ioh2, BHA_ISA_IOSIZE); 133 bus_space_unmap(iot, ioh, BHA_EISA_IOSIZE); 134 135 return (rv); 136 } 137 138 /* 139 * Attach all the sub-devices we can find 140 */ 141 static void 142 bha_eisa_attach(device_t parent, device_t self, void *aux) 143 { 144 struct eisa_attach_args *ea = aux; 145 struct bha_softc *sc = device_private(self); 146 const struct device_compatible_entry *dce; 147 bus_space_tag_t iot = ea->ea_iot; 148 bus_space_handle_t ioh, ioh2; 149 int port; 150 struct bha_probe_data bpd; 151 eisa_chipset_tag_t ec = ea->ea_ec; 152 eisa_intr_handle_t ih; 153 const char *intrstr; 154 char intrbuf[EISA_INTRSTR_LEN]; 155 156 sc->sc_dev = self; 157 158 dce = eisa_compatible_lookup(ea, compat_data); 159 KASSERT(dce != NULL); 160 161 printf(": %s\n", (const char *)dce->data); 162 163 if (bus_space_map(iot, 164 EISA_SLOT_ADDR(ea->ea_slot) + BHA_EISA_SLOT_OFFSET, BHA_EISA_IOSIZE, 165 0, &ioh)) 166 panic("bha_eisa_attach: could not map EISA slot"); 167 168 if (bha_eisa_address(iot, ioh, &port) || 169 bus_space_map(iot, port, BHA_ISA_IOSIZE, 0, &ioh2)) 170 panic("bha_eisa_attach: could not map ISA address"); 171 172 sc->sc_iot = iot; 173 sc->sc_ioh = ioh2; 174 sc->sc_dmat = ea->ea_dmat; 175 if (!bha_probe_inquiry(iot, ioh2, &bpd)) 176 panic("bha_eisa_attach failed"); 177 178 sc->sc_dmaflags = 0; 179 180 if (eisa_intr_map(ec, bpd.sc_irq, &ih)) { 181 aprint_error_dev(sc->sc_dev, "couldn't map interrupt (%d)\n", 182 bpd.sc_irq); 183 return; 184 } 185 intrstr = eisa_intr_string(ec, ih, intrbuf, sizeof(intrbuf)); 186 sc->sc_ih = eisa_intr_establish(ec, ih, IST_LEVEL, IPL_BIO, 187 bha_intr, sc); 188 if (sc->sc_ih == NULL) { 189 aprint_error_dev(sc->sc_dev, "couldn't establish interrupt"); 190 if (intrstr != NULL) 191 aprint_error(" at %s", intrstr); 192 aprint_error("\n"); 193 return; 194 } 195 aprint_normal_dev(sc->sc_dev, "interrupting at %s\n", intrstr); 196 197 bha_attach(sc); 198 } 199