Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / sys / dev / disk / adw_pci.c
1 /*
2  * Device probe and attach routines for the following
3  * Advanced Systems Inc. SCSI controllers:
4  *
5  *      ABP940UW - Bus-Master PCI Ultra-Wide (240 CDB)
6  *
7  * Copyright (c) 1998 Justin Gibbs.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
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.
18  *
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
29  * SUCH DAMAGE.
30  *
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.2 2003/06/17 04:28:55 dillon Exp $
33  */
34
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
38
39 #include <machine/bus_pio.h>
40 #include <machine/bus.h>
41
42 #include <pci/pcireg.h>
43 #include <pci/pcivar.h>
44
45 #include <cam/cam.h>
46 #include <cam/scsi/scsi_all.h>
47
48 #include <dev/advansys/adwvar.h>
49 #include <dev/advansys/adwlib.h>
50 #include <dev/advansys/adwmcode.h>
51
52 #define PCI_BASEADR0    PCI_MAP_REG_START       /* I/O Address */
53 #define PCI_BASEADR1    PCI_MAP_REG_START + 4   /* Mem I/O Address */
54
55 #define PCI_DEVICE_ID_ADVANSYS_3550     0x230010CD
56
57 #define ADW_PCI_MAX_DMA_ADDR    (0xFFFFFFFFUL)
58 #define ADW_PCI_MAX_DMA_COUNT   (0xFFFFFFFFUL)
59
60 static const char* adwpciprobe(pcici_t tag, pcidi_t type);
61 static void adwpciattach(pcici_t config_id, int unit);
62
63 static struct  pci_device adw_pci_driver = {
64         "adw",
65         adwpciprobe,
66         adwpciattach,
67         &adw_unit,
68         NULL
69 };
70
71 COMPAT_PCI_DRIVER (adw_pci, adw_pci_driver);
72
73 static const char*
74 adwpciprobe(pcici_t tag, pcidi_t type)
75 {
76         switch (type) {
77         case PCI_DEVICE_ID_ADVANSYS_3550:
78                 return ("AdvanSys ASC3550 SCSI controller");
79         default:
80                 break;
81         }
82         return (NULL);
83 }
84
85 static void
86 adwpciattach(pcici_t config_id, int unit)
87 {
88         u_int32_t          id;
89         u_int32_t          command;
90         vm_offset_t        vaddr;
91 #ifdef ADW_ALLOW_MEMIO
92         vm_offset_t        paddr;
93 #endif
94         u_int16_t          io_port;
95         bus_space_tag_t    tag;
96         bus_space_handle_t bsh;
97         struct adw_softc  *adw;
98         int                error;
99  
100         /*
101          * Determine the chip version.
102          */
103         id = pci_cfgread(config_id, PCI_ID_REG, /*bytes*/4);
104         command = pci_cfgread(config_id, PCIR_COMMAND, /*bytes*/1);
105
106         /*
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
109          * to talk to them.
110          */
111         vaddr = 0;
112 #ifdef ADW_ALLOW_MEMIO
113         if ((command & PCI_COMMAND_MEM_ENABLE) == 0
114          || (pci_map_mem(config_id, PCI_BASEADR1, &vaddr, &paddr)) == 0)
115 #endif
116                 if ((command & PCI_COMMAND_IO_ENABLE) == 0
117                  || (pci_map_port(config_id, PCI_BASEADR0, &io_port)) == 0)
118                         return;
119
120         /* XXX Should be passed in by parent bus */
121         /* XXX Why isn't the 0x10 offset incorporated into the reg defs? */
122         if (vaddr != 0) {
123                 tag = I386_BUS_SPACE_MEM;
124                 bsh = vaddr;
125         } else {
126                 tag = I386_BUS_SPACE_IO;
127                 bsh = io_port;
128         }
129
130
131         if (adw_find_signature(tag, bsh) == 0)
132                 return;
133
134         adw = adw_alloc(unit, tag, bsh);
135         if (adw == NULL)
136                 return;
137
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,
141                                    /*boundary*/0,
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,
148                                    /*flags*/0,
149                                    &adw->parent_dmat);
150
151         adw->init_level++;
152  
153         if (error != 0) {
154                 printf("%s: Could not allocate DMA tag - error %d\n",
155                        adw_name(adw), error);
156                 adw_free(adw);
157                 return;
158         }
159
160         adw->init_level++;
161
162         if (adw_init(adw) != 0) {
163                 adw_free(adw);
164                 return;
165         }
166
167         /*
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.
172          */
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);
177
178         if ((pci_map_int(config_id, adw_intr, (void *)adw, &cam_imask)) == 0) {
179                 adw_free(adw);
180                 return;
181         }
182         
183         adw_attach(adw);
184 }