dpt_eisa.c revision 56827
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 * $FreeBSD: head/sys/dev/dpt/dpt_eisa.c 56827 2000-01-29 14:31:57Z peter $
37 */
38
39#include "opt_dpt.h"
40
41#include <sys/param.h>
42#include <sys/systm.h>
43#include <sys/malloc.h>
44#include <sys/buf.h>
45#include <sys/proc.h>
46#include <sys/kernel.h>
47#include <sys/module.h>
48#include <sys/bus.h>
49
50#include <machine/bus_pio.h>
51#include <machine/bus.h>
52#include <machine/resource.h>
53#include <sys/rman.h>
54
55#include <cam/scsi/scsi_all.h>
56
57#include <dev/dpt/dpt.h>
58
59#include <dev/eisa/eisaconf.h>
60
61#include <machine/clock.h>
62
63#include <vm/vm.h>
64#include <vm/vm_param.h>
65#include <vm/pmap.h>
66
67#define DPT_EISA_IOSIZE			0x100
68#define DPT_EISA_SLOT_OFFSET		0x0c00
69#define DPT_EISA_EATA_REG_OFFSET	0x0088
70
71#define	DPT_EISA_DPT2402		0x12142402
72#define	DPT_EISA_DPTA401		0x1214A401
73#define	DPT_EISA_DPTA402		0x1214A402
74#define	DPT_EISA_DPTA410		0x1214A410
75#define	DPT_EISA_DPTA411		0x1214A411
76#define	DPT_EISA_DPTA412		0x1214A412
77#define	DPT_EISA_DPTA420		0x1214A420
78#define	DPT_EISA_DPTA501		0x1214A501
79#define	DPT_EISA_DPTA502		0x1214A502
80#define	DPT_EISA_DPTA701		0x1214A701
81#define	DPT_EISA_DPTBC01		0x1214BC01
82#define	DPT_EISA_NEC8200		0x12148200
83#define	DPT_EISA_ATT2408		0x12142408
84
85/* Function Prototypes */
86
87static const char	*dpt_eisa_match(eisa_id_t);
88
89static int
90dpt_eisa_probe(device_t dev)
91{
92	const char *	desc;
93	u_int32_t	io_base;
94	dpt_conf_t *	conf;
95
96	desc = dpt_eisa_match(eisa_get_id(dev));
97	if (!desc)
98		return (ENXIO);
99	device_set_desc(dev, desc);
100
101	io_base = (eisa_get_slot(dev) * EISA_SLOT_SIZE) + DPT_EISA_SLOT_OFFSET;
102
103	conf = dpt_pio_get_conf(io_base + DPT_EISA_EATA_REG_OFFSET);
104	if (!conf) {
105		printf("dpt: dpt_pio_get_conf() failed.\n");
106		return (ENXIO);
107	}
108
109	eisa_add_iospace(dev, io_base, DPT_EISA_IOSIZE, RESVADDR_NONE);
110	eisa_add_intr(dev, conf->IRQ,
111		      (conf->IRQ_TR ? EISA_TRIGGER_LEVEL : EISA_TRIGGER_EDGE));
112
113	return 0;
114}
115
116static int
117dpt_eisa_attach(device_t dev)
118{
119	dpt_softc_t	*dpt;
120	struct resource *io = 0;
121	struct resource *irq = 0;
122        int		unit = device_get_unit(dev);
123	int		s;
124	int		rid;
125	void		*ih;
126
127	rid = 0;
128	io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
129				0, ~0, 1, RF_ACTIVE);
130	if (!io) {
131		device_printf(dev, "No I/O space?!\n");
132		return ENOMEM;
133	}
134
135	dpt = dpt_alloc(unit, rman_get_bustag(io),
136			rman_get_bushandle(io) + DPT_EISA_EATA_REG_OFFSET);
137	if (dpt == NULL)
138		goto bad;
139
140	/* Allocate a dmatag representing the capabilities of this attachment */
141	/* XXX Should be a child of the EISA bus dma tag */
142	if (bus_dma_tag_create(/*parent*/NULL, /*alignemnt*/1, /*boundary*/0,
143			       /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
144			       /*highaddr*/BUS_SPACE_MAXADDR,
145			       /*filter*/NULL, /*filterarg*/NULL,
146			       /*maxsize*/BUS_SPACE_MAXSIZE_32BIT,
147			       /*nsegments*/BUS_SPACE_UNRESTRICTED,
148			       /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT,
149			       /*flags*/0, &dpt->parent_dmat) != 0) {
150		dpt_free(dpt);
151		goto bad;
152	}
153
154	rid = 0;
155	irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid,
156				 0, ~0, 1, RF_ACTIVE);
157	if (!irq) {
158		device_printf(dev, "No irq?!\n");
159		goto bad;
160	}
161
162	s = splcam();
163	if (dpt_init(dpt) != 0) {
164		dpt_free(dpt);
165		goto bad;
166	}
167
168	/* Register with the XPT */
169	dpt_attach(dpt);
170	bus_setup_intr(dev, irq, INTR_TYPE_CAM, dpt_intr, dpt, &ih);
171
172	splx(s);
173
174	return 0;
175
176 bad:
177	if (io)
178		bus_release_resource(dev, SYS_RES_IOPORT, 0, io);
179	if (irq)
180		bus_release_resource(dev, SYS_RES_IRQ, 0, irq);
181	return -1;
182}
183
184static const char	*
185dpt_eisa_match(type)
186	eisa_id_t	type;
187{
188	switch (type) {
189		case DPT_EISA_DPT2402 :
190			return ("DPT PM2012A/9X");
191			break;
192		case DPT_EISA_DPTA401 :
193			return ("DPT PM2012B/9X");
194			break;
195		case DPT_EISA_DPTA402 :
196			return ("DPT PM2012B2/9X");
197			break;
198		case DPT_EISA_DPTA410 :
199			return ("DPT PM2x22A/9X");
200			break;
201		case DPT_EISA_DPTA411 :
202			return ("DPT Spectre");
203			break;
204		case DPT_EISA_DPTA412 :
205			return ("DPT PM2021A/9X");
206			break;
207		case DPT_EISA_DPTA420 :
208			return ("DPT Smart Cache IV (PM2042)");
209			break;
210		case DPT_EISA_DPTA501 :
211			return ("DPT PM2012B1/9X");
212			break;
213		case DPT_EISA_DPTA502 :
214			return ("DPT PM2012Bx/9X");
215			break;
216		case DPT_EISA_DPTA701 :
217			return ("DPT PM2011B1/9X");
218			break;
219		case DPT_EISA_DPTBC01 :
220			return ("DPT PM3011/7X ESDI");
221			break;
222		case DPT_EISA_NEC8200 :
223			return ("NEC EATA SCSI");
224			break;
225		case DPT_EISA_ATT2408 :
226			return ("ATT EATA SCSI");
227			break;
228		default:
229			break;
230	}
231
232	return (NULL);
233}
234
235static device_method_t dpt_eisa_methods[] = {
236	/* Device interface */
237	DEVMETHOD(device_probe,		dpt_eisa_probe),
238	DEVMETHOD(device_attach,	dpt_eisa_attach),
239
240	{ 0, 0 }
241};
242
243static driver_t dpt_eisa_driver = {
244	"dpt",
245	dpt_eisa_methods,
246	1,			/* unused */
247};
248
249static devclass_t dpt_devclass;
250
251DRIVER_MODULE(dpt, eisa, dpt_eisa_driver, dpt_devclass, 0, 0);
252