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