bha_pci.c revision 1.12 1 /* $NetBSD: bha_pci.c,v 1.12 1997/04/13 20:14:22 cgd Exp $ */
2
3 /*
4 * Copyright (c) 1994, 1996, 1997 Charles M. Hannum. 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 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Charles M. Hannum.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/types.h>
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/device.h>
36
37 #include <machine/bus.h>
38 #include <machine/intr.h>
39
40 #include <scsi/scsi_all.h>
41 #include <scsi/scsiconf.h>
42
43 #include <dev/pci/pcivar.h>
44 #include <dev/pci/pcidevs.h>
45
46 #include <dev/ic/bhareg.h>
47 #include <dev/ic/bhavar.h>
48
49 #define PCI_CBIO 0x10
50
51 #ifdef __BROKEN_INDIRECT_CONFIG
52 int bha_pci_match __P((struct device *, void *, void *));
53 #else
54 int bha_pci_match __P((struct device *, struct cfdata *, void *));
55 #endif
56 void bha_pci_attach __P((struct device *, struct device *, void *));
57
58 struct cfattach bha_pci_ca = {
59 sizeof(struct bha_softc), bha_pci_match, bha_pci_attach
60 };
61
62 /*
63 * Check the slots looking for a board we recognise
64 * If we find one, note it's address (slot) and call
65 * the actual probe routine to check it out.
66 */
67 int
68 bha_pci_match(parent, match, aux)
69 struct device *parent;
70 #ifdef __BROKEN_INDIRECT_CONFIG
71 void *match;
72 #else
73 struct cfdata *match;
74 #endif
75 void *aux;
76 {
77 struct pci_attach_args *pa = aux;
78 bus_space_tag_t iot;
79 bus_space_handle_t ioh;
80 bus_size_t iosize;
81 int rv;
82
83 if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_BUSLOGIC)
84 return (0);
85
86 if (PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_BUSLOGIC_MULTIMASTER_NC &&
87 PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_BUSLOGIC_MULTIMASTER)
88 return (0);
89
90 if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0, &iot, &ioh,
91 NULL, &iosize))
92 return (0);
93
94 rv = bha_find(iot, ioh, NULL);
95
96 bus_space_unmap(iot, ioh, iosize);
97
98 return (rv);
99 }
100
101 /*
102 * Attach all the sub-devices we can find
103 */
104 void
105 bha_pci_attach(parent, self, aux)
106 struct device *parent, *self;
107 void *aux;
108 {
109 struct pci_attach_args *pa = aux;
110 struct bha_softc *sc = (void *)self;
111 bus_space_tag_t iot;
112 bus_space_handle_t ioh;
113 struct bha_probe_data bpd;
114 pci_chipset_tag_t pc = pa->pa_pc;
115 pci_intr_handle_t ih;
116 pcireg_t csr;
117 const char *model, *intrstr;
118
119 if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_BUSLOGIC_MULTIMASTER_NC)
120 model = "BusLogic 9xxC SCSI";
121 else if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_BUSLOGIC_MULTIMASTER)
122 model = "BusLogic 9xxC SCSI";
123 else
124 model = "unknown model!";
125 printf(": %s\n", model);
126
127 if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0, &iot, &ioh,
128 NULL, NULL)) {
129 printf("%s: unable to map device registers\n",
130 sc->sc_dev.dv_xname);
131 return;
132 }
133
134 sc->sc_iot = iot;
135 sc->sc_ioh = ioh;
136 if (!bha_find(iot, ioh, &bpd))
137 panic("bha_pci_attach: bha_find failed");
138
139 csr = pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
140 pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
141 csr | PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_IO_ENABLE);
142
143 if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
144 pa->pa_intrline, &ih)) {
145 printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
146 return;
147 }
148 intrstr = pci_intr_string(pc, ih);
149 sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, bha_intr, sc);
150 if (sc->sc_ih == NULL) {
151 printf("%s: couldn't establish interrupt",
152 sc->sc_dev.dv_xname);
153 if (intrstr != NULL)
154 printf(" at %s", intrstr);
155 printf("\n");
156 return;
157 }
158 printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
159
160 bha_attach(sc, &bpd);
161
162 bha_disable_isacompat(sc);
163 }
164