bha_pci.c revision 1.15 1 /* $NetBSD: bha_pci.c,v 1.15 1998/06/08 06:55:54 thorpej 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 <dev/scsipi/scsi_all.h>
41 #include <dev/scsipi/scsipi_all.h>
42 #include <dev/scsipi/scsiconf.h>
43
44 #include <dev/pci/pcivar.h>
45 #include <dev/pci/pcidevs.h>
46
47 #include <dev/ic/bhareg.h>
48 #include <dev/ic/bhavar.h>
49
50 #define PCI_CBIO 0x10
51
52 int bha_pci_match __P((struct device *, struct cfdata *, void *));
53 void bha_pci_attach __P((struct device *, struct device *, void *));
54
55 struct cfattach bha_pci_ca = {
56 sizeof(struct bha_softc), bha_pci_match, bha_pci_attach
57 };
58
59 /*
60 * Check the slots looking for a board we recognise
61 * If we find one, note it's address (slot) and call
62 * the actual probe routine to check it out.
63 */
64 int
65 bha_pci_match(parent, match, aux)
66 struct device *parent;
67 struct cfdata *match;
68 void *aux;
69 {
70 struct pci_attach_args *pa = aux;
71 bus_space_tag_t iot;
72 bus_space_handle_t ioh;
73 bus_size_t iosize;
74 int rv;
75
76 if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_BUSLOGIC)
77 return (0);
78
79 if (PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_BUSLOGIC_MULTIMASTER_NC &&
80 PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_BUSLOGIC_MULTIMASTER)
81 return (0);
82
83 if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0, &iot, &ioh,
84 NULL, &iosize))
85 return (0);
86
87 rv = bha_find(iot, ioh, NULL);
88
89 bus_space_unmap(iot, ioh, iosize);
90
91 return (rv);
92 }
93
94 /*
95 * Attach all the sub-devices we can find
96 */
97 void
98 bha_pci_attach(parent, self, aux)
99 struct device *parent, *self;
100 void *aux;
101 {
102 struct pci_attach_args *pa = aux;
103 struct bha_softc *sc = (void *)self;
104 bus_space_tag_t iot;
105 bus_space_handle_t ioh;
106 struct bha_probe_data bpd;
107 pci_chipset_tag_t pc = pa->pa_pc;
108 pci_intr_handle_t ih;
109 pcireg_t csr;
110 const char *model, *intrstr;
111
112 if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_BUSLOGIC_MULTIMASTER_NC)
113 model = "BusLogic 9xxC SCSI";
114 else if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_BUSLOGIC_MULTIMASTER)
115 model = "BusLogic 9xxC SCSI";
116 else
117 model = "unknown model!";
118 printf(": %s\n", model);
119
120 if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0, &iot, &ioh,
121 NULL, NULL)) {
122 printf("%s: unable to map device registers\n",
123 sc->sc_dev.dv_xname);
124 return;
125 }
126
127 sc->sc_iot = iot;
128 sc->sc_ioh = ioh;
129 sc->sc_dmat = pa->pa_dmat;
130 if (!bha_find(iot, ioh, &bpd))
131 panic("bha_pci_attach: bha_find failed");
132
133 sc->sc_dmaflags = 0;
134
135 csr = pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
136 pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
137 csr | PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_IO_ENABLE);
138
139 if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
140 pa->pa_intrline, &ih)) {
141 printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
142 return;
143 }
144 intrstr = pci_intr_string(pc, ih);
145 sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, bha_intr, sc);
146 if (sc->sc_ih == NULL) {
147 printf("%s: couldn't establish interrupt",
148 sc->sc_dev.dv_xname);
149 if (intrstr != NULL)
150 printf(" at %s", intrstr);
151 printf("\n");
152 return;
153 }
154 printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
155
156 bha_attach(sc, &bpd);
157
158 bha_disable_isacompat(sc);
159 }
160