xref: /netbsd-src/sys/dev/eisa/dpt_eisa.c (revision 5ce3f1d17010026525408cd8be9d30054cf6d8c2)
1 /*	$NetBSD: dpt_eisa.c,v 1.24 2021/01/27 04:35:15 thorpej Exp $	*/
2 
3 /*
4  * Copyright (c) 1999, 2000, 2001 Andrew Doran <ad@NetBSD.org>
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. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  */
29 
30 /*
31  * EISA front-end for DPT EATA SCSI driver.
32  */
33 
34 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: dpt_eisa.c,v 1.24 2021/01/27 04:35:15 thorpej Exp $");
36 
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/device.h>
40 #include <sys/queue.h>
41 
42 #include <sys/bus.h>
43 #include <sys/intr.h>
44 
45 #include <dev/scsipi/scsipi_all.h>
46 #include <dev/scsipi/scsiconf.h>
47 
48 #include <dev/eisa/eisavar.h>
49 
50 #include <dev/ic/dptreg.h>
51 #include <dev/ic/dptvar.h>
52 
53 #include <dev/i2o/dptivar.h>
54 
55 #define DPT_EISA_SLOT_OFFSET		0x0c00
56 #define DPT_EISA_IOSIZE			0x0100
57 #define DPT_EISA_IOCONF			0x90
58 #define DPT_EISA_EATA_REG_OFFSET	0x88
59 
60 static void	dpt_eisa_attach(device_t, device_t, void *);
61 static int	dpt_eisa_irq(bus_space_tag_t, bus_space_handle_t, int *);
62 static int	dpt_eisa_match(device_t, cfdata_t, void *);
63 
64 CFATTACH_DECL_NEW(dpt_eisa, sizeof(struct dpt_softc),
65     dpt_eisa_match, dpt_eisa_attach, NULL, NULL);
66 
67 static const struct device_compatible_entry compat_data[] = {
68 	{ .compat = "DPT2402" },
69 	{ .compat = "DPTA401" },
70 	{ .compat = "DPTA402" },
71 	{ .compat = "DPTA410" },
72 	{ .compat = "DPTA411" },
73 	{ .compat = "DPTA412" },
74 	{ .compat = "DPTA420" },
75 	{ .compat = "DPTA501" },
76 	{ .compat = "DPTA502" },
77 	{ .compat = "DPTA701" },
78 	{ .compat = "DPTBC01" },
79 	{ .compat = "NEC8200" },	/* OEM */
80 	{ .compat = "ATT2408" },	/* OEM */
81 	DEVICE_COMPAT_EOL
82 };
83 
84 static int
dpt_eisa_irq(bus_space_tag_t iot,bus_space_handle_t ioh,int * irq)85 dpt_eisa_irq(bus_space_tag_t iot, bus_space_handle_t ioh, int *irq)
86 {
87 
88 	switch (bus_space_read_1(iot, ioh, DPT_EISA_IOCONF) & 0x38) {
89 	case 0x08:
90 		*irq = 11;
91 		break;
92 	case 0x10:
93 		*irq = 15;
94 		break;
95 	case 0x20:
96 		*irq = 14;
97 		break;
98 	default:
99 		return (-1);
100 	}
101 
102 	return (0);
103 }
104 
105 static int
dpt_eisa_match(device_t parent,cfdata_t match,void * aux)106 dpt_eisa_match(device_t parent, cfdata_t match, void *aux)
107 {
108 	struct eisa_attach_args *ea = aux;
109 
110 	return eisa_compatible_match(ea, compat_data);
111 }
112 
113 static void
dpt_eisa_attach(device_t parent,device_t self,void * aux)114 dpt_eisa_attach(device_t parent, device_t self, void *aux)
115 {
116 	struct eisa_attach_args *ea;
117 	bus_space_handle_t ioh;
118 	eisa_chipset_tag_t ec;
119 	eisa_intr_handle_t ih;
120 	struct dpt_softc *sc;
121 	bus_space_tag_t iot;
122 	const char *intrstr;
123 	int irq;
124 	char intrbuf[EISA_INTRSTR_LEN];
125 
126 	ea = aux;
127 	sc = device_private(self);
128 	sc->sc_dev = self;
129 	iot = ea->ea_iot;
130 	ec = ea->ea_ec;
131 
132 	printf(": ");
133 
134 	if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
135 	    DPT_EISA_SLOT_OFFSET, DPT_EISA_IOSIZE, 0, &ioh)) {
136 		aprint_error("can't map i/o space\n");
137 		return;
138 	}
139 
140 	sc->sc_iot = iot;
141 	sc->sc_ioh = ioh;
142 	sc->sc_dmat = ea->ea_dmat;
143 
144 	/* Map and establish the interrupt. */
145 	if (dpt_eisa_irq(iot, ioh, &irq)) {
146 		aprint_error("HBA on invalid IRQ\n");
147 		return;
148 	}
149 
150 	if (eisa_intr_map(ec, irq, &ih)) {
151 		aprint_error("can't map interrupt (%d)\n", irq);
152 		return;
153 	}
154 
155 	intrstr = eisa_intr_string(ec, ih, intrbuf, sizeof(intrbuf));
156 	sc->sc_ih = eisa_intr_establish(ec, ih, IST_LEVEL, IPL_BIO,
157 	    dpt_intr, sc);
158 	if (sc->sc_ih == NULL) {
159 		aprint_error("can't establish interrupt");
160 		if (intrstr != NULL)
161 			aprint_error(" at %s", intrstr);
162 		aprint_error("\n");
163 		return;
164 	}
165 
166 	/* Read the EATA configuration. */
167 	if (dpt_readcfg(sc)) {
168 		aprint_error_dev(sc->sc_dev, "readcfg failed - see dpt(4)\n");
169 		return;
170 	}
171 
172 	sc->sc_bustype = SI_EISA_BUS;
173 	sc->sc_isaport =  EISA_SLOT_ADDR(ea->ea_slot) + DPT_EISA_SLOT_OFFSET;
174 	sc->sc_isairq = irq;
175 
176 	/* Now attach to the bus-independent code. */
177 	dpt_init(sc, intrstr);
178 }
179