2 * Device probe and attach routines for the following
3 * Advanced Systems Inc. SCSI controllers:
5 * ABP940UW - Bus-Master PCI Ultra-Wide (240 CDB)
7 * Copyright (c) 1998 Justin Gibbs.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions, and the following disclaimer,
15 * without modification, immediately at the beginning of the file.
16 * 2. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * $FreeBSD: src/sys/pci/adw_pci.c,v 1.8 1999/08/28 00:50:41 peter Exp $
32 * $DragonFly: src/sys/dev/disk/Attic/adw_pci.c,v 1.3 2003/08/07 21:16:50 dillon Exp $
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
39 #include <machine/bus_pio.h>
40 #include <machine/bus.h>
42 #include <bus/pci/pcireg.h>
43 #include <bus/pci/pcivar.h>
45 #include <bus/cam/cam.h>
46 #include <bus/cam/scsi/scsi_all.h>
48 #include <dev/advansys/adwvar.h>
49 #include <dev/advansys/adwlib.h>
50 #include <dev/advansys/adwmcode.h>
52 #define PCI_BASEADR0 PCI_MAP_REG_START /* I/O Address */
53 #define PCI_BASEADR1 PCI_MAP_REG_START + 4 /* Mem I/O Address */
55 #define PCI_DEVICE_ID_ADVANSYS_3550 0x230010CD
57 #define ADW_PCI_MAX_DMA_ADDR (0xFFFFFFFFUL)
58 #define ADW_PCI_MAX_DMA_COUNT (0xFFFFFFFFUL)
60 static const char* adwpciprobe(pcici_t tag, pcidi_t type);
61 static void adwpciattach(pcici_t config_id, int unit);
63 static struct pci_device adw_pci_driver = {
71 COMPAT_PCI_DRIVER (adw_pci, adw_pci_driver);
74 adwpciprobe(pcici_t tag, pcidi_t type)
77 case PCI_DEVICE_ID_ADVANSYS_3550:
78 return ("AdvanSys ASC3550 SCSI controller");
86 adwpciattach(pcici_t config_id, int unit)
91 #ifdef ADW_ALLOW_MEMIO
96 bus_space_handle_t bsh;
97 struct adw_softc *adw;
101 * Determine the chip version.
103 id = pci_cfgread(config_id, PCI_ID_REG, /*bytes*/4);
104 command = pci_cfgread(config_id, PCIR_COMMAND, /*bytes*/1);
107 * These cards do not allow memory mapped accesses, so we must
108 * ensure that I/O accesses are available or we won't be able
112 #ifdef ADW_ALLOW_MEMIO
113 if ((command & PCI_COMMAND_MEM_ENABLE) == 0
114 || (pci_map_mem(config_id, PCI_BASEADR1, &vaddr, &paddr)) == 0)
116 if ((command & PCI_COMMAND_IO_ENABLE) == 0
117 || (pci_map_port(config_id, PCI_BASEADR0, &io_port)) == 0)
120 /* XXX Should be passed in by parent bus */
121 /* XXX Why isn't the 0x10 offset incorporated into the reg defs? */
123 tag = I386_BUS_SPACE_MEM;
126 tag = I386_BUS_SPACE_IO;
131 if (adw_find_signature(tag, bsh) == 0)
134 adw = adw_alloc(unit, tag, bsh);
138 /* Allocate a dmatag for our transfer DMA maps */
139 /* XXX Should be a child of the PCI bus dma tag */
140 error = bus_dma_tag_create(/*parent*/NULL, /*alignment*/1,
142 /*lowaddr*/ADW_PCI_MAX_DMA_ADDR,
143 /*highaddr*/BUS_SPACE_MAXADDR,
144 /*filter*/NULL, /*filterarg*/NULL,
145 /*maxsize*/BUS_SPACE_MAXSIZE_32BIT,
146 /*nsegments*/BUS_SPACE_UNRESTRICTED,
147 /*maxsegsz*/ADW_PCI_MAX_DMA_COUNT,
154 printf("%s: Could not allocate DMA tag - error %d\n",
155 adw_name(adw), error);
162 if (adw_init(adw) != 0) {
168 * If the PCI Configuration Command Register "Parity Error Response
169 * Control" Bit was clear (0), then set the microcode variable
170 * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
171 * to ignore DMA parity errors.
173 if ((command & PCIM_CMD_PERRESPEN) == 0)
174 adw_lram_write_16(adw, ADW_MC_CONTROL_FLAG,
175 adw_lram_read_16(adw, ADW_MC_CONTROL_FLAG)
176 | ADW_MC_CONTROL_IGN_PERR);
178 if ((pci_map_int(config_id, adw_intr, (void *)adw, &cam_imask)) == 0) {