dpt_eisa.c revision 49860
1/*
2 *       Copyright (c) 1997 by Matthew N. Dodd <winter@jurai.net>
3 *       All Rights Reserved
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions, and the following disclaimer,
10 *    without modification, immediately at the beginning of the file.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 *    derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30/*
31 * Credits:  Based on and part of the DPT driver for FreeBSD written and
32 *           maintained by Simon Shapiro <shimon@simon-shapiro.org>
33 */
34
35/*
36 * $Id: dpt_eisa.c,v 1.7 1999/08/01 22:57:09 mdodd Exp $
37 */
38
39#include "eisa.h"
40#if NEISA > 0
41#include "opt_dpt.h"
42
43#include <sys/param.h>
44#include <sys/systm.h>
45#include <sys/malloc.h>
46#include <sys/buf.h>
47#include <sys/proc.h>
48#include <sys/kernel.h>
49#include <sys/module.h>
50#include <sys/bus.h>
51
52#include <machine/bus_pio.h>
53#include <machine/bus.h>
54#include <machine/resource.h>
55#include <sys/rman.h>
56
57#include <cam/scsi/scsi_all.h>
58
59#include <dev/dpt/dpt.h>
60
61#include <i386/eisa/eisaconf.h>
62#include <i386/eisa/dpt_eisa.h>
63
64#include <machine/clock.h>
65
66#include <vm/vm.h>
67#include <vm/vm_param.h>
68#include <vm/pmap.h>
69
70/* Function Prototypes */
71
72static const char	*dpt_eisa_match(eisa_id_t);
73
74static int
75dpt_eisa_probe(device_t dev)
76{
77	const char	    *desc;
78	u_int32_t	    io_base;
79	u_int		    intdef;
80	u_int		    irq;
81	int	 	    shared;
82
83	desc = dpt_eisa_match(eisa_get_id(dev));
84	if (!desc)
85		return (ENXIO);
86	device_set_desc(dev, desc);
87
88	io_base = (eisa_get_slot(dev) * EISA_SLOT_SIZE)
89	    + DPT_EISA_SLOT_OFFSET;
90
91	eisa_add_iospace(dev, io_base, DPT_EISA_IOSIZE, RESVADDR_NONE);
92
93	outb((DPT_EISA_CFENABLE + io_base), 0xf8);
94
95	intdef = inb(DPT_EISA_INTDEF + io_base);
96
97	irq = intdef & DPT_EISA_INT_NUM_MASK;
98	shared = (intdef & DPT_EISA_INT_LEVEL)
99			? EISA_TRIGGER_LEVEL : EISA_TRIGGER_EDGE;
100	switch (irq) {
101	case DPT_EISA_INT_NUM_11:
102	    irq = 11;
103	    break;
104	case DPT_EISA_INT_NUM_15:
105	    irq = 15;
106	    break;
107	case DPT_EISA_INT_NUM_14:
108	    irq = 14;
109	    break;
110	default:
111	    device_printf(dev, "dpt at slot %d: illegal irq setting %d\n",
112		   eisa_get_slot(dev), irq);
113	    irq = 0;
114	    break;
115	}
116	if (irq == 0)
117	    return (ENXIO);
118
119	eisa_add_intr(dev, irq, shared);
120
121	return 0;
122}
123
124static int
125dpt_eisa_attach(device_t dev)
126{
127	dpt_softc_t	*dpt;
128	struct resource *io = 0;
129	struct resource *irq = 0;
130        int		unit = device_get_unit(dev);
131	int		s;
132	int		rid;
133	void		*ih;
134
135	rid = 0;
136	io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
137				0, ~0, 1, RF_ACTIVE);
138	if (!io) {
139		device_printf(dev, "No I/O space?!\n");
140		return ENOMEM;
141	}
142
143	dpt = dpt_alloc(unit, rman_get_bustag(io),
144			rman_get_bushandle(io) + DPT_EISA_EATA_REG_OFFSET);
145	if (dpt == NULL)
146		goto bad;
147
148	/* Allocate a dmatag representing the capabilities of this attachment */
149	/* XXX Should be a child of the EISA bus dma tag */
150	if (bus_dma_tag_create(/*parent*/NULL, /*alignemnt*/1, /*boundary*/0,
151			       /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
152			       /*highaddr*/BUS_SPACE_MAXADDR,
153			       /*filter*/NULL, /*filterarg*/NULL,
154			       /*maxsize*/BUS_SPACE_MAXSIZE_32BIT,
155			       /*nsegments*/BUS_SPACE_UNRESTRICTED,
156			       /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT,
157			       /*flags*/0, &dpt->parent_dmat) != 0) {
158		dpt_free(dpt);
159		goto bad;
160	}
161
162	rid = 0;
163	irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid,
164				 0, ~0, 1, RF_ACTIVE);
165	if (!irq) {
166		device_printf(dev, "No irq?!\n");
167		goto bad;
168	}
169
170	s = splcam();
171	if (dpt_init(dpt) != 0) {
172		dpt_free(dpt);
173		goto bad;
174	}
175
176	/* Register with the XPT */
177	dpt_attach(dpt);
178	bus_setup_intr(dev, irq, INTR_TYPE_CAM, dpt_intr, dpt, &ih);
179
180	splx(s);
181
182	return 0;
183
184 bad:
185	if (io)
186		bus_release_resource(dev, SYS_RES_IOPORT, 0, io);
187	if (irq)
188		bus_release_resource(dev, SYS_RES_IRQ, 0, irq);
189	return -1;
190}
191
192static const char	*
193dpt_eisa_match(type)
194	eisa_id_t	type;
195{
196	switch (type) {
197		case DPT_EISA_DPT2402 :
198			return ("DPT PM2012A/9X");
199			break;
200		case DPT_EISA_DPTA401 :
201			return ("DPT PM2012B/9X");
202			break;
203		case DPT_EISA_DPTA402 :
204			return ("DPT PM2012B2/9X");
205			break;
206		case DPT_EISA_DPTA410 :
207			return ("DPT PM2x22A/9X");
208			break;
209		case DPT_EISA_DPTA411 :
210			return ("DPT Spectre");
211			break;
212		case DPT_EISA_DPTA412 :
213			return ("DPT PM2021A/9X");
214			break;
215		case DPT_EISA_DPTA420 :
216			return ("DPT Smart Cache IV (PM2042)");
217			break;
218		case DPT_EISA_DPTA501 :
219			return ("DPT PM2012B1/9X");
220			break;
221		case DPT_EISA_DPTA502 :
222			return ("DPT PM2012Bx/9X");
223			break;
224		case DPT_EISA_DPTA701 :
225			return ("DPT PM2011B1/9X");
226			break;
227		case DPT_EISA_DPTBC01 :
228			return ("DPT PM3011/7X ESDI");
229			break;
230		case DPT_EISA_NEC8200 :
231			return ("NEC EATA SCSI");
232			break;
233		case DPT_EISA_ATT2408 :
234			return ("ATT EATA SCSI");
235			break;
236		default:
237			break;
238	}
239
240	return (NULL);
241}
242
243static device_method_t dpt_eisa_methods[] = {
244	/* Device interface */
245	DEVMETHOD(device_probe,		dpt_eisa_probe),
246	DEVMETHOD(device_attach,	dpt_eisa_attach),
247
248	{ 0, 0 }
249};
250
251static driver_t dpt_eisa_driver = {
252	"dpt",
253	dpt_eisa_methods,
254	1,			/* unused */
255};
256
257static devclass_t dpt_devclass;
258
259DRIVER_MODULE(dpt, eisa, dpt_eisa_driver, dpt_devclass, 0, 0);
260
261#endif /* NEISA > 0 */
262