bha_pci.c revision 1.2 1 /* $NetBSD: bha_pci.c,v 1.2 1996/09/01 00:20:25 mycroft 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/device.h>
35
36 #include <machine/bus.h>
37 #include <machine/intr.h>
38
39 #include <scsi/scsi_all.h>
40 #include <scsi/scsiconf.h>
41
42 #include <dev/pci/pcivar.h>
43 #include <dev/pci/pcidevs.h>
44
45 #include <dev/ic/bhareg.h>
46 #include <dev/ic/bhavar.h>
47
48 #define PCI_CBIO 0x10
49
50 int bha_pci_match __P((struct device *, void *, void *));
51 void bha_pci_attach __P((struct device *, struct device *, void *));
52
53 struct cfattach bha_pci_ca = {
54 sizeof(struct bha_softc), bha_pci_match, bha_pci_attach
55 };
56
57 /*
58 * Check the slots looking for a board we recognise
59 * If we find one, note it's address (slot) and call
60 * the actual probe routine to check it out.
61 */
62 int
63 bha_pci_match(parent, match, aux)
64 struct device *parent;
65 void *match, *aux;
66 {
67 struct pci_attach_args *pa = aux;
68 bus_chipset_tag_t bc = pa->pa_bc;
69 bus_io_addr_t iobase;
70 bus_io_size_t iosize;
71 bus_io_handle_t ioh;
72 pci_chipset_tag_t pc = pa->pa_pc;
73 int rv;
74
75 if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_BUSLOGIC)
76 return (0);
77
78 if (PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_BUSLOGIC_OLD946C &&
79 PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_BUSLOGIC_946C)
80 return (0);
81
82 if (pci_io_find(pc, pa->pa_tag, PCI_CBIO, &iobase, &iosize))
83 return (0);
84 if (bus_io_map(bc, iobase, iosize, &ioh))
85 return (0);
86
87 rv = bha_find(bc, ioh, NULL);
88
89 bus_io_unmap(bc, 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_chipset_tag_t bc = pa->pa_bc;
105 bus_io_addr_t iobase;
106 bus_io_size_t iosize;
107 bus_io_handle_t ioh;
108 pci_chipset_tag_t pc = pa->pa_pc;
109 pci_intr_handle_t ih;
110 pcireg_t csr;
111 const char *model, *intrstr;
112
113 if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_BUSLOGIC_OLD946C)
114 model = "BusLogic 9xxC SCSI";
115 else if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_BUSLOGIC_946C)
116 model = "BusLogic 9xxC SCSI";
117 else
118 model = "unknown model!";
119 printf(": %s\n", model);
120
121 if (pci_io_find(pc, pa->pa_tag, PCI_CBIO, &iobase, &iosize))
122 panic("bha_attach: pci_io_find failed!");
123 if (bus_io_map(bc, iobase, iosize, &ioh))
124 panic("bha_attach: bus_io_map failed!");
125
126 sc->sc_bc = bc;
127 sc->sc_ioh = ioh;
128 if (!bha_find(bc, ioh, sc))
129 panic("bha_attach: bha_find failed!");
130
131 csr = pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
132 pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
133 csr | PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_IO_ENABLE);
134
135 if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
136 pa->pa_intrline, &ih)) {
137 printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
138 return;
139 }
140 intrstr = pci_intr_string(pc, ih);
141 sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, bha_intr, sc);
142 if (sc->sc_ih == NULL) {
143 printf("%s: couldn't establish interrupt",
144 sc->sc_dev.dv_xname);
145 if (intrstr != NULL)
146 printf(" at %s", intrstr);
147 printf("\n");
148 return;
149 }
150 printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
151
152 bha_attach(sc);
153 }
154