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 */
48 static struct aic7770_identity *ahc_isa_find_device(bus_space_tag_t tag,
49 bus_space_handle_t bsh);
50 static void ahc_isa_identify(driver_t *driver,
52 static int ahc_isa_probe(device_t dev);
53 static int ahc_isa_attach(device_t dev);
56 * Perform an EISA probe of the address with the addition
57 * of a "priming" step. The 284X requires priming (a write
58 * to offset 0x80, the first EISA ID register) to ensure it
59 * is not mistaken as an EISA card. Once we have the ID,
60 * lookup the controller in the aic7770 table of supported
63 static struct aic7770_identity *
64 ahc_isa_find_device(bus_space_tag_t tag, bus_space_handle_t bsh) {
71 for (i = 0; i < id_size; i++) {
72 bus_space_write_1(tag, bsh, 0x80, 0x80 + i);
73 id |= bus_space_read_1(tag, bsh, 0x80 + i)
74 << ((id_size - i - 1) * CHAR_BIT);
77 return (aic7770_find_device(id));
81 ahc_isa_identify(driver_t *driver, device_t parent)
87 for (slot = 0; slot <= max_slot; slot++) {
88 struct aic7770_identity *entry;
90 bus_space_handle_t bsh;
91 struct resource *regs;
96 iobase = (slot * AHC_EISA_SLOT_SIZE) + AHC_EISA_SLOT_OFFSET;
97 regs = bus_alloc_resource(parent, SYS_RES_IOPORT, &rid,
98 iobase, iobase, AHC_EISA_IOSIZE,
102 printf("ahc_isa_identify %d: ioport 0x%x "
103 "alloc failed\n", slot, iobase);
107 tag = rman_get_bustag(regs);
108 bsh = rman_get_bushandle(regs);
110 entry = ahc_isa_find_device(tag, bsh);
114 child = BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE,
117 device_set_driver(child, driver);
118 bus_set_resource(child, SYS_RES_IOPORT,
119 0, iobase, AHC_EISA_IOSIZE);
122 bus_release_resource(parent, SYS_RES_IOPORT, rid, regs);
127 ahc_isa_probe(device_t dev)
129 struct aic7770_identity *entry;
131 bus_space_handle_t bsh;
132 struct resource *regs;
133 struct resource *irq;
146 /* Skip probes for ISA PnP devices */
147 if (isa_get_logicalid(dev) != 0)
150 regs = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &zero, RF_ACTIVE);
152 device_printf(dev, "No resources allocated.\n");
156 iobase = rman_get_start(regs);
157 tag = rman_get_bustag(regs);
158 bsh = rman_get_bushandle(regs);
160 entry = ahc_isa_find_device(tag, bsh);
164 /* Pause the card preseving the IRQ type */
165 hcntrl = bus_space_read_1(tag, bsh, HCNTRL) & IRQMS;
166 bus_space_write_1(tag, bsh, HCNTRL, hcntrl | PAUSE);
167 while ((bus_space_read_1(tag, bsh, HCNTRL) & PAUSE) == 0)
170 /* Make sure we have a valid interrupt vector */
171 intdef = bus_space_read_1(tag, bsh, INTDEF);
172 irq_num = intdef & VECTOR;
182 device_printf(dev, "@0x%x: illegal irq setting %d\n",
187 if (bus_set_resource(dev, SYS_RES_IRQ, zero, irq_num, 1) != 0)
191 * The 284X only supports edge triggered interrupts,
192 * so do not claim RF_SHAREABLE.
194 irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &zero,
195 0 /*!(RF_ACTIVE|RF_SHAREABLE)*/);
198 device_set_desc(dev, entry->name);
200 device_printf(dev, "@0x%x: irq %d allocation failed\n",
205 bus_release_resource(dev, SYS_RES_IOPORT, zero, regs);
210 bus_release_resource(dev, SYS_RES_IRQ, zero, irq);
218 ahc_isa_attach(device_t dev)
220 struct aic7770_identity *entry;
222 bus_space_handle_t bsh;
223 struct resource *regs;
224 struct ahc_softc *ahc;
230 regs = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &zero, RF_ACTIVE);
234 tag = rman_get_bustag(regs);
235 bsh = rman_get_bushandle(regs);
236 entry = ahc_isa_find_device(tag, bsh);
237 bus_release_resource(dev, SYS_RES_IOPORT, zero, regs);
242 * Allocate a softc for this card and
243 * set it up for attachment by our
244 * common detect routine.
246 name = malloc(strlen(device_get_nameunit(dev)) + 1, M_DEVBUF, M_NOWAIT);
249 strcpy(name, device_get_nameunit(dev));
250 ahc = ahc_alloc(dev, name);
254 ahc_set_unit(ahc, device_get_unit(dev));
256 /* Allocate a dmatag for our SCB DMA maps */
257 error = aic_dma_tag_create(ahc, /*parent*/bus_get_dma_tag(dev),
258 /*alignment*/1, /*boundary*/0,
259 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
260 /*highaddr*/BUS_SPACE_MAXADDR,
261 /*filter*/NULL, /*filterarg*/NULL,
262 /*maxsize*/BUS_SPACE_MAXSIZE_32BIT,
263 /*nsegments*/AHC_NSEG,
264 /*maxsegsz*/AHC_MAXTRANSFER_SIZE,
269 printf("ahc_isa_attach: Could not allocate DMA tag "
270 "- error %d\n", error);
274 ahc->dev_softc = dev;
275 error = aic7770_config(ahc, entry, /*unused ioport arg*/0);
285 static device_method_t ahc_isa_device_methods[] = {
286 /* Device interface */
287 DEVMETHOD(device_identify, ahc_isa_identify),
288 DEVMETHOD(device_probe, ahc_isa_probe),
289 DEVMETHOD(device_attach, ahc_isa_attach),
290 DEVMETHOD(device_detach, ahc_detach),
294 static driver_t ahc_isa_driver = {
296 ahc_isa_device_methods,
297 sizeof(struct ahc_softc)
300 DRIVER_MODULE(ahc_isa, isa, ahc_isa_driver, ahc_devclass, 0, 0);
301 MODULE_DEPEND(ahc_isa, ahc, 1, 1, 1);
302 MODULE_VERSION(ahc_isa, 1);