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 <dev/aic7xxx/aic7xxx_osm.h>
42 #include <sys/limits.h> /* For CHAR_BIT*/
43 #include <isa/isavar.h> /* For ISA attach glue */
45 static struct aic7770_identity *ahc_isa_find_device(bus_space_tag_t tag,
46 bus_space_handle_t bsh);
47 static void ahc_isa_identify(driver_t *driver,
49 static int ahc_isa_probe(device_t dev);
50 static int ahc_isa_attach(device_t dev);
53 * Perform an EISA probe of the address with the addition
54 * of a "priming" step. The 284X requires priming (a write
55 * to offset 0x80, the first EISA ID register) to ensure it
56 * is not mistaken as an EISA card. Once we have the ID,
57 * lookup the controller in the aic7770 table of supported
60 static struct aic7770_identity *
61 ahc_isa_find_device(bus_space_tag_t tag, bus_space_handle_t bsh) {
68 for (i = 0; i < id_size; i++) {
69 bus_space_write_1(tag, bsh, 0x80, 0x80 + i);
70 id |= bus_space_read_1(tag, bsh, 0x80 + i)
71 << ((id_size - i - 1) * CHAR_BIT);
74 return (aic7770_find_device(id));
78 ahc_isa_identify(driver_t *driver, device_t parent)
84 for (slot = 0; slot <= max_slot; slot++) {
85 struct aic7770_identity *entry;
87 bus_space_handle_t bsh;
88 struct resource *regs;
93 iobase = (slot * AHC_EISA_SLOT_SIZE) + AHC_EISA_SLOT_OFFSET;
94 regs = bus_alloc_resource(parent, SYS_RES_IOPORT, &rid,
95 iobase, iobase, AHC_EISA_IOSIZE,
99 printf("ahc_isa_identify %d: ioport 0x%x "
100 "alloc failed\n", slot, iobase);
104 tag = rman_get_bustag(regs);
105 bsh = rman_get_bushandle(regs);
107 entry = ahc_isa_find_device(tag, bsh);
111 child = BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE,
114 device_set_driver(child, driver);
115 bus_set_resource(child, SYS_RES_IOPORT,
116 0, iobase, AHC_EISA_IOSIZE);
119 bus_release_resource(parent, SYS_RES_IOPORT, rid, regs);
124 ahc_isa_probe(device_t dev)
126 struct aic7770_identity *entry;
128 bus_space_handle_t bsh;
129 struct resource *regs;
130 struct resource *irq;
143 /* Skip probes for ISA PnP devices */
144 if (isa_get_logicalid(dev) != 0)
147 regs = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &zero, RF_ACTIVE);
149 device_printf(dev, "No resources allocated.\n");
153 iobase = rman_get_start(regs);
154 tag = rman_get_bustag(regs);
155 bsh = rman_get_bushandle(regs);
157 entry = ahc_isa_find_device(tag, bsh);
161 /* Pause the card preseving the IRQ type */
162 hcntrl = bus_space_read_1(tag, bsh, HCNTRL) & IRQMS;
163 bus_space_write_1(tag, bsh, HCNTRL, hcntrl | PAUSE);
164 while ((bus_space_read_1(tag, bsh, HCNTRL) & PAUSE) == 0)
167 /* Make sure we have a valid interrupt vector */
168 intdef = bus_space_read_1(tag, bsh, INTDEF);
169 irq_num = intdef & VECTOR;
179 device_printf(dev, "@0x%x: illegal irq setting %d\n",
184 if (bus_set_resource(dev, SYS_RES_IRQ, zero, irq_num, 1) != 0)
188 * The 284X only supports edge triggered interrupts,
189 * so do not claim RF_SHAREABLE.
191 irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &zero,
192 0 /*!(RF_ACTIVE|RF_SHAREABLE)*/);
195 device_set_desc(dev, entry->name);
197 device_printf(dev, "@0x%x: irq %d allocation failed\n",
202 bus_release_resource(dev, SYS_RES_IOPORT, zero, regs);
207 bus_release_resource(dev, SYS_RES_IRQ, zero, irq);
215 ahc_isa_attach(device_t dev)
217 struct aic7770_identity *entry;
219 bus_space_handle_t bsh;
220 struct resource *regs;
221 struct ahc_softc *ahc;
227 regs = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &zero, RF_ACTIVE);
231 tag = rman_get_bustag(regs);
232 bsh = rman_get_bushandle(regs);
233 entry = ahc_isa_find_device(tag, bsh);
234 bus_release_resource(dev, SYS_RES_IOPORT, zero, regs);
239 * Allocate a softc for this card and
240 * set it up for attachment by our
241 * common detect routine.
243 name = malloc(strlen(device_get_nameunit(dev)) + 1, M_DEVBUF, M_NOWAIT);
246 strcpy(name, device_get_nameunit(dev));
247 ahc = ahc_alloc(dev, name);
251 ahc_set_unit(ahc, device_get_unit(dev));
253 /* Allocate a dmatag for our SCB DMA maps */
254 error = aic_dma_tag_create(ahc, /*parent*/bus_get_dma_tag(dev),
255 /*alignment*/1, /*boundary*/0,
256 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
257 /*highaddr*/BUS_SPACE_MAXADDR,
258 /*filter*/NULL, /*filterarg*/NULL,
259 /*maxsize*/BUS_SPACE_MAXSIZE_32BIT,
260 /*nsegments*/AHC_NSEG,
261 /*maxsegsz*/AHC_MAXTRANSFER_SIZE,
266 printf("ahc_isa_attach: Could not allocate DMA tag "
267 "- error %d\n", error);
271 ahc->dev_softc = dev;
272 error = aic7770_config(ahc, entry, /*unused ioport arg*/0);
282 static device_method_t ahc_isa_device_methods[] = {
283 /* Device interface */
284 DEVMETHOD(device_identify, ahc_isa_identify),
285 DEVMETHOD(device_probe, ahc_isa_probe),
286 DEVMETHOD(device_attach, ahc_isa_attach),
287 DEVMETHOD(device_detach, ahc_detach),
291 static driver_t ahc_isa_driver = {
293 ahc_isa_device_methods,
294 sizeof(struct ahc_softc)
297 DRIVER_MODULE(ahc_isa, isa, ahc_isa_driver, 0, 0);
298 MODULE_DEPEND(ahc_isa, ahc, 1, 1, 1);
299 MODULE_VERSION(ahc_isa, 1);