bha_pci.c revision 1.10 1 /* $NetBSD: bha_pci.c,v 1.10 1997/03/28 23:47:16 mycroft 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 = pa->pa_iot;
79 bus_addr_t iobase;
80 bus_size_t iosize;
81 bus_space_handle_t ioh;
82 pci_chipset_tag_t pc = pa->pa_pc;
83 int rv;
84
85 if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_BUSLOGIC)
86 return (0);
87
88 if (PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_BUSLOGIC_MULTIMASTER_NC &&
89 PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_BUSLOGIC_MULTIMASTER)
90 return (0);
91
92 if (pci_io_find(pc, pa->pa_tag, PCI_CBIO, &iobase, &iosize))
93 return (0);
94 if (bus_space_map(iot, iobase, iosize, 0, &ioh))
95 return (0);
96
97 rv = bha_find(iot, ioh, NULL);
98
99 bus_space_unmap(iot, ioh, iosize);
100
101 return (rv);
102 }
103
104 /*
105 * Attach all the sub-devices we can find
106 */
107 void
108 bha_pci_attach(parent, self, aux)
109 struct device *parent, *self;
110 void *aux;
111 {
112 struct pci_attach_args *pa = aux;
113 struct bha_softc *sc = (void *)self;
114 bus_space_tag_t iot = pa->pa_iot;
115 bus_addr_t iobase;
116 bus_size_t iosize;
117 bus_space_handle_t ioh;
118 struct bha_probe_data bpd;
119 pci_chipset_tag_t pc = pa->pa_pc;
120 pci_intr_handle_t ih;
121 pcireg_t csr;
122 const char *model, *intrstr;
123
124 if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_BUSLOGIC_MULTIMASTER_NC)
125 model = "BusLogic 9xxC SCSI";
126 else if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_BUSLOGIC_MULTIMASTER)
127 model = "BusLogic 9xxC SCSI";
128 else
129 model = "unknown model!";
130 printf(": %s\n", model);
131
132 if (pci_io_find(pc, pa->pa_tag, PCI_CBIO, &iobase, &iosize))
133 panic("bha_pci_attach: pci_io_find failed");
134 if (bus_space_map(iot, iobase, iosize, 0, &ioh))
135 panic("bha_pci_attach: bus_space_map failed");
136
137 sc->sc_iot = iot;
138 sc->sc_ioh = ioh;
139 if (!bha_find(iot, ioh, &bpd))
140 panic("bha_pci_attach: bha_find failed");
141
142 csr = pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
143 pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
144 csr | PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_IO_ENABLE);
145
146 if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
147 pa->pa_intrline, &ih)) {
148 printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
149 return;
150 }
151 intrstr = pci_intr_string(pc, ih);
152 sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, bha_intr, sc);
153 if (sc->sc_ih == NULL) {
154 printf("%s: couldn't establish interrupt",
155 sc->sc_dev.dv_xname);
156 if (intrstr != NULL)
157 printf(" at %s", intrstr);
158 printf("\n");
159 return;
160 }
161 printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
162
163 bha_attach(sc, &bpd);
164
165 bha_disable_isacompat(sc);
166 }
167