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