2 * FreeBSD, VLB/ISA product support functions
4 * SPDX-License-Identifier: BSD-3-Clause
6 * Copyright (c) 2004 Justin T. Gibbs.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions, and the following disclaimer,
14 * without modification.
15 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
16 * substantially similar to the "NO WARRANTY" disclaimer below
17 * ("Disclaimer") and any redistribution must be conditioned upon
18 * including a substantially similar Disclaimer requirement for further
19 * binary redistribution.
20 * 3. Neither the names of the above-listed copyright holders nor the names
21 * of any contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
34 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGES.
40 #include <sys/cdefs.h>
41 __FBSDID("$FreeBSD$");
43 #include <dev/aic7xxx/aic7xxx_osm.h>
45 #include <sys/limits.h> /* For CHAR_BIT*/
46 #include <isa/isavar.h> /* For ISA attach glue */
49 static struct aic7770_identity *ahc_isa_find_device(bus_space_tag_t tag,
50 bus_space_handle_t bsh);
51 static void ahc_isa_identify(driver_t *driver,
53 static int ahc_isa_probe(device_t dev);
54 static int ahc_isa_attach(device_t dev);
57 * Perform an EISA probe of the address with the addition
58 * of a "priming" step. The 284X requires priming (a write
59 * to offset 0x80, the first EISA ID register) to ensure it
60 * is not mistaken as an EISA card. Once we have the ID,
61 * lookup the controller in the aic7770 table of supported
64 static struct aic7770_identity *
65 ahc_isa_find_device(bus_space_tag_t tag, bus_space_handle_t bsh) {
72 for (i = 0; i < id_size; i++) {
73 bus_space_write_1(tag, bsh, 0x80, 0x80 + i);
74 id |= bus_space_read_1(tag, bsh, 0x80 + i)
75 << ((id_size - i - 1) * CHAR_BIT);
78 return (aic7770_find_device(id));
82 ahc_isa_identify(driver_t *driver, device_t parent)
88 for (slot = 0; slot <= max_slot; slot++) {
89 struct aic7770_identity *entry;
91 bus_space_handle_t bsh;
92 struct resource *regs;
97 iobase = (slot * AHC_EISA_SLOT_SIZE) + AHC_EISA_SLOT_OFFSET;
98 regs = bus_alloc_resource(parent, SYS_RES_IOPORT, &rid,
99 iobase, iobase, AHC_EISA_IOSIZE,
103 printf("ahc_isa_identify %d: ioport 0x%x "
104 "alloc failed\n", slot, iobase);
108 tag = rman_get_bustag(regs);
109 bsh = rman_get_bushandle(regs);
111 entry = ahc_isa_find_device(tag, bsh);
115 child = BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE,
118 device_set_driver(child, driver);
119 bus_set_resource(child, SYS_RES_IOPORT,
120 0, iobase, AHC_EISA_IOSIZE);
123 bus_release_resource(parent, SYS_RES_IOPORT, rid, regs);
128 ahc_isa_probe(device_t dev)
130 struct aic7770_identity *entry;
132 bus_space_handle_t bsh;
133 struct resource *regs;
134 struct resource *irq;
147 /* Skip probes for ISA PnP devices */
148 if (isa_get_logicalid(dev) != 0)
151 regs = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &zero, RF_ACTIVE);
153 device_printf(dev, "No resources allocated.\n");
157 iobase = rman_get_start(regs);
158 tag = rman_get_bustag(regs);
159 bsh = rman_get_bushandle(regs);
161 entry = ahc_isa_find_device(tag, bsh);
165 /* Pause the card preseving the IRQ type */
166 hcntrl = bus_space_read_1(tag, bsh, HCNTRL) & IRQMS;
167 bus_space_write_1(tag, bsh, HCNTRL, hcntrl | PAUSE);
168 while ((bus_space_read_1(tag, bsh, HCNTRL) & PAUSE) == 0)
171 /* Make sure we have a valid interrupt vector */
172 intdef = bus_space_read_1(tag, bsh, INTDEF);
173 irq_num = intdef & VECTOR;
183 device_printf(dev, "@0x%x: illegal irq setting %d\n",
188 if (bus_set_resource(dev, SYS_RES_IRQ, zero, irq_num, 1) != 0)
192 * The 284X only supports edge triggered interrupts,
193 * so do not claim RF_SHAREABLE.
195 irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &zero,
196 0 /*!(RF_ACTIVE|RF_SHAREABLE)*/);
199 device_set_desc(dev, entry->name);
201 device_printf(dev, "@0x%x: irq %d allocation failed\n",
206 bus_release_resource(dev, SYS_RES_IOPORT, zero, regs);
211 bus_release_resource(dev, SYS_RES_IRQ, zero, irq);
219 ahc_isa_attach(device_t dev)
221 struct aic7770_identity *entry;
223 bus_space_handle_t bsh;
224 struct resource *regs;
225 struct ahc_softc *ahc;
231 regs = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &zero, RF_ACTIVE);
235 tag = rman_get_bustag(regs);
236 bsh = rman_get_bushandle(regs);
237 entry = ahc_isa_find_device(tag, bsh);
238 bus_release_resource(dev, SYS_RES_IOPORT, zero, regs);
243 * Allocate a softc for this card and
244 * set it up for attachment by our
245 * common detect routine.
247 name = malloc(strlen(device_get_nameunit(dev)) + 1, M_DEVBUF, M_NOWAIT);
250 strcpy(name, device_get_nameunit(dev));
251 ahc = ahc_alloc(dev, name);
255 ahc_set_unit(ahc, device_get_unit(dev));
257 /* Allocate a dmatag for our SCB DMA maps */
258 error = aic_dma_tag_create(ahc, /*parent*/bus_get_dma_tag(dev),
259 /*alignment*/1, /*boundary*/0,
260 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
261 /*highaddr*/BUS_SPACE_MAXADDR,
262 /*filter*/NULL, /*filterarg*/NULL,
263 /*maxsize*/BUS_SPACE_MAXSIZE_32BIT,
264 /*nsegments*/AHC_NSEG,
265 /*maxsegsz*/AHC_MAXTRANSFER_SIZE,
270 printf("ahc_isa_attach: Could not allocate DMA tag "
271 "- error %d\n", error);
275 ahc->dev_softc = dev;
276 error = aic7770_config(ahc, entry, /*unused ioport arg*/0);
286 static device_method_t ahc_isa_device_methods[] = {
287 /* Device interface */
288 DEVMETHOD(device_identify, ahc_isa_identify),
289 DEVMETHOD(device_probe, ahc_isa_probe),
290 DEVMETHOD(device_attach, ahc_isa_attach),
291 DEVMETHOD(device_detach, ahc_detach),
295 static driver_t ahc_isa_driver = {
297 ahc_isa_device_methods,
298 sizeof(struct ahc_softc)
301 DRIVER_MODULE(ahc_isa, isa, ahc_isa_driver, ahc_devclass, 0, 0);
302 MODULE_DEPEND(ahc_isa, ahc, 1, 1, 1);
303 MODULE_VERSION(ahc_isa, 1);