1 | /* $NetBSD: iha_pci.c,v 1.19 2014/03/29 19:28:25 christos Exp $ */ |
2 | |
3 | /*- |
4 | * Copyright (c) 2001 Izumi Tsutsui. All rights reserved. |
5 | * |
6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions |
8 | * are met: |
9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * 2. Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
14 | * |
15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 | */ |
26 | |
27 | /*- |
28 | * Device driver for the INI-9XXXU/UW or INIC-940/950 PCI SCSI Controller. |
29 | * |
30 | * Written for 386bsd and FreeBSD by |
31 | * Winston Hung <winstonh@initio.com> |
32 | * |
33 | * Copyright (c) 1997-1999 Initio Corp. |
34 | * Copyright (c) 2000 Ken Westerback |
35 | * All rights reserved. |
36 | * |
37 | * Redistribution and use in source and binary forms, with or without |
38 | * modification, are permitted provided that the following conditions |
39 | * are met: |
40 | * 1. Redistributions of source code must retain the above copyright |
41 | * notice, this list of conditions and the following disclaimer, |
42 | * without modification, immediately at the beginning of the file. |
43 | * 2. The name of the author may not be used to endorse or promote products |
44 | * derived from this software without specific prior written permission. |
45 | * |
46 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
47 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
48 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
49 | * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, |
50 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
51 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
52 | * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
53 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
54 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
55 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
56 | * THE POSSIBILITY OF SUCH DAMAGE. |
57 | */ |
58 | |
59 | /* |
60 | * Ported to NetBSD by Izumi Tsutsui <tsutsui@NetBSD.org> from OpenBSD: |
61 | * $OpenBSD: iha_pci.c,v 1.2 2001/03/29 23:53:38 krw Exp $ |
62 | */ |
63 | |
64 | #include <sys/cdefs.h> |
65 | __KERNEL_RCSID(0, "$NetBSD: iha_pci.c,v 1.19 2014/03/29 19:28:25 christos Exp $" ); |
66 | |
67 | #include <sys/param.h> |
68 | #include <sys/systm.h> |
69 | #include <sys/device.h> |
70 | |
71 | #include <dev/pci/pcidevs.h> |
72 | #include <dev/pci/pcivar.h> |
73 | |
74 | #include <dev/scsipi/scsipi_all.h> |
75 | #include <dev/scsipi/scsi_all.h> |
76 | #include <dev/scsipi/scsiconf.h> |
77 | |
78 | #include <dev/ic/ihavar.h> |
79 | |
80 | static int iha_pci_match(device_t, cfdata_t, void *); |
81 | static void iha_pci_attach(device_t, device_t, void *); |
82 | |
83 | CFATTACH_DECL_NEW(iha_pci, sizeof(struct iha_softc), |
84 | iha_pci_match, iha_pci_attach, NULL, NULL); |
85 | |
86 | static int |
87 | iha_pci_match(device_t parent, cfdata_t cf, void *aux) |
88 | { |
89 | struct pci_attach_args *pa = aux; |
90 | |
91 | if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_INITIO) |
92 | return 0; |
93 | |
94 | switch (PCI_PRODUCT(pa->pa_id)) { |
95 | case PCI_PRODUCT_INITIO_I940: |
96 | case PCI_PRODUCT_INITIO_I950: |
97 | return 1; |
98 | } |
99 | |
100 | return 0; |
101 | } |
102 | |
103 | static void |
104 | iha_pci_attach(device_t parent, device_t self, void *aux) |
105 | { |
106 | struct iha_softc *sc = device_private(self); |
107 | struct pci_attach_args *pa = aux; |
108 | bus_space_tag_t iot; |
109 | bus_space_handle_t ioh; |
110 | pci_intr_handle_t ih; |
111 | const char *intrstr; |
112 | pcireg_t command; |
113 | int ioh_valid; |
114 | char intrbuf[PCI_INTRSTR_LEN]; |
115 | |
116 | sc->sc_dev = self; |
117 | |
118 | pci_aprint_devinfo(pa, NULL); |
119 | |
120 | command = pci_conf_read(pa->pa_pc,pa->pa_tag,PCI_COMMAND_STATUS_REG); |
121 | command |= PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_PARITY_ENABLE; |
122 | |
123 | pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, command); |
124 | |
125 | /* |
126 | * XXX - Tried memory mapping (using code from adw and ahc) |
127 | * rather that IO mapping, but it didn't work at all.. |
128 | */ |
129 | ioh_valid = pci_mapreg_map(pa, PCI_MAPREG_START, PCI_MAPREG_TYPE_IO, 0, |
130 | &iot, &ioh, NULL, NULL); |
131 | |
132 | if (ioh_valid != 0) { |
133 | aprint_error_dev(self, "unable to map registers\n" ); |
134 | return; |
135 | } |
136 | |
137 | sc->sc_iot = iot; |
138 | sc->sc_ioh = ioh; |
139 | sc->sc_dmat = pa->pa_dmat; |
140 | |
141 | if (pci_intr_map(pa, &ih)) { |
142 | aprint_error_dev(self, "couldn't map interrupt\n" ); |
143 | return; |
144 | } |
145 | intrstr = pci_intr_string(pa->pa_pc, ih, intrbuf, sizeof(intrbuf)); |
146 | |
147 | sc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO, iha_intr, sc); |
148 | |
149 | if (sc->sc_ih == NULL) { |
150 | aprint_error_dev(self, "couldn't establish interrupt" ); |
151 | if (intrstr != NULL) |
152 | aprint_error(" at %s" , intrstr); |
153 | aprint_error("\n" ); |
154 | return; |
155 | } |
156 | aprint_normal_dev(self, "interrupting at %s\n" , intrstr); |
157 | |
158 | iha_attach(sc); |
159 | } |
160 | |