summaryrefslogtreecommitdiffstats
path: root/sys/dev/aha/aha_isa.c
blob: f7183305babad344aeb675a7b9906174716fdfa9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*
 * Product specific probe and attach routines for:
 *      Adaptec 154x.
 *
 * Derived from code written by:
 *
 * Copyright (c) 1998 Justin T. Gibbs
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions, and the following disclaimer,
 *    without modification, immediately at the beginning of the file.
 * 2. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	$Id: aha_isa.c,v 1.4 1998/10/12 18:53:33 imp Exp $
 */

#include <sys/param.h>
#include <sys/systm.h>

#include <machine/bus_pio.h>
#include <machine/bus.h>

#include <i386/isa/isa_device.h>
#include <dev/aha/ahareg.h>

#include <cam/scsi/scsi_all.h>

static	int aha_isa_probe __P((struct isa_device *dev));
static	int aha_isa_attach __P((struct isa_device *dev));
static	void aha_isa_intr __P((void *unit));

struct isa_driver ahadriver =
{
    aha_isa_probe,
    aha_isa_attach,
    "aha"
};

/*
 * Check if the device can be found at the port given
 * and if so, set it up ready for further work
 * as an argument, takes the isa_device structure from
 * autoconf.c
 */
static int
aha_isa_probe(dev)
	struct isa_device *dev;
{
	/*
	 * find unit and check we have that many defined
	 */
	struct	aha_softc *aha;
	int	port_index;
	int	max_port_index;

	/*
	 * We ignore the unit number assigned by config to allow
	 * consistant numbering between PCI/EISA/ISA devices.
	 * This is a total kludge until we have a configuration
	 * manager.
	 */
	dev->id_unit = aha_unit;

	aha = NULL;

	/*
	 * Bound our board search if the user has
	 * specified an exact port.
	 */
	aha_find_probe_range(dev->id_iobase, &port_index, &max_port_index);

	if (port_index < 0)
		return 0;

	/* Attempt to find an adapter */
	for (;port_index <= max_port_index; port_index++) {
		config_data_t config_data;
		u_int ioport;
		int error;

		ioport = aha_iop_from_bio(port_index);

		/*
		 * Ensure this port has not already been claimed already
		 * by a PCI, EISA or ISA adapter.
		 */
		if (aha_check_probed_iop(ioport) != 0)
			continue;
		dev->id_iobase = ioport;
		if (haveseen_isadev(dev, CC_IOADDR | CC_QUIET))
			continue;

		/* Allocate a softc for use during probing */
		aha = aha_alloc(dev->id_unit, I386_BUS_SPACE_IO, ioport);

		if (aha == NULL)
			break;

		/* We're going to attempt to probe it now, so mark it probed */
		aha_mark_probed_bio(port_index);

		/* See if there is really a card present */
		if (aha_probe(aha) || aha_fetch_adapter_info(aha)) {
			aha_free(aha);
			continue;
		}

		/*
		 * Determine our IRQ, and DMA settings and
		 * export them to the configuration system.
		 */
		error = aha_cmd(aha, AOP_INQUIRE_CONFIG, NULL, /*parmlen*/0,
			       (u_int8_t*)&config_data, sizeof(config_data),
			       DEFAULT_CMD_TIMEOUT);
		if (error != 0) {
			printf("aha_isa_probe: Could not determine IRQ or DMA "
			       "settings for adapter at 0x%x.  Failing probe\n",
			       ioport);
			aha_free(aha);
			continue;
		}

		switch (config_data.dma_chan) {
		case DMA_CHAN_5:
			dev->id_drq = 5;
			break;
		case DMA_CHAN_6:
			dev->id_drq = 6;
			break;
		case DMA_CHAN_7:
			dev->id_drq = 7;
			break;
		default:
			printf("aha_isa_probe: Invalid DMA setting "
				"detected for adapter at 0x%x.  "
				"Failing probe\n", ioport);
			return (0);
		}
		dev->id_irq = (config_data.irq << 9);
		dev->id_intr = aha_isa_intr;
		aha_unit++;
		return (AHA_NREGS);
	}

	return (0);
}

/*
 * Attach all the sub-devices we can find
 */
static int
aha_isa_attach(dev)
	struct isa_device *dev;
{
	struct	aha_softc *aha;
	bus_dma_filter_t *filter;
	void		 *filter_arg;
	bus_addr_t	 lowaddr;

	aha = aha_softcs[dev->id_unit];
	if (dev->id_drq != -1)
		isa_dmacascade(dev->id_drq);

	/* Allocate our parent dmatag */
	filter = NULL;
	filter_arg = NULL;
	lowaddr = BUS_SPACE_MAXADDR_24BIT;

	if (bus_dma_tag_create(/*parent*/NULL, /*alignemnt*/0, /*boundary*/0,
                               lowaddr, /*highaddr*/BUS_SPACE_MAXADDR,
                               filter, filter_arg,
                               /*maxsize*/BUS_SPACE_MAXSIZE_24BIT,
                               /*nsegments*/BUS_SPACE_UNRESTRICTED,
                               /*maxsegsz*/BUS_SPACE_MAXSIZE_24BIT,
                               /*flags*/0, &aha->parent_dmat) != 0) {
                aha_free(aha);
                return (-1);
        }                              

        if (aha_init(aha)) {
		printf("aha init failed\n");
                aha_free(aha);
                return (-1);
        }

	return (aha_attach(aha));
}

/*
 * Handle an ISA interrupt.
 * XXX should go away as soon as ISA interrupt handlers
 * take a (void *) arg.
 */
static void
aha_isa_intr(void *unit)
{
	struct aha_softc* arg = aha_softcs[(int)unit];
	aha_intr((void *)arg);
}
OpenPOWER on IntegriCloud