bha_pci.c revision 1.1 1 #include <sys/types.h>
2 #include <sys/param.h>
3 #include <sys/device.h>
4
5 #include <machine/bus.h>
6 #include <machine/intr.h>
7
8 #include <scsi/scsi_all.h>
9 #include <scsi/scsiconf.h>
10
11 #include <dev/pci/pcivar.h>
12 #include <dev/pci/pcidevs.h>
13
14 #include <dev/ic/bhareg.h>
15 #include <dev/ic/bhavar.h>
16
17 #define PCI_CBIO 0x10
18
19 int bha_pci_match __P((struct device *, void *, void *));
20 void bha_pci_attach __P((struct device *, struct device *, void *));
21
22 struct cfattach bha_pci_ca = {
23 sizeof(struct bha_softc), bha_pci_match, bha_pci_attach
24 };
25
26 /*
27 * Check the slots looking for a board we recognise
28 * If we find one, note it's address (slot) and call
29 * the actual probe routine to check it out.
30 */
31 int
32 bha_pci_match(parent, match, aux)
33 struct device *parent;
34 void *match, *aux;
35 {
36 struct pci_attach_args *pa = aux;
37 bus_chipset_tag_t bc = pa->pa_bc;
38 bus_io_addr_t iobase;
39 bus_io_size_t iosize;
40 bus_io_handle_t ioh;
41 pci_chipset_tag_t pc = pa->pa_pc;
42 int rv;
43
44 if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_BUSLOGIC)
45 return (0);
46
47 if (PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_BUSLOGIC_OLD946C &&
48 PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_BUSLOGIC_946C)
49 return (0);
50
51 if (pci_io_find(pc, pa->pa_tag, PCI_CBIO, &iobase, &iosize))
52 return (0);
53 if (bus_io_map(bc, iobase, iosize, &ioh))
54 return (0);
55
56 rv = bha_find(bc, ioh, NULL);
57
58 bus_io_unmap(bc, ioh, iosize);
59
60 return (rv);
61 }
62
63 /*
64 * Attach all the sub-devices we can find
65 */
66 void
67 bha_pci_attach(parent, self, aux)
68 struct device *parent, *self;
69 void *aux;
70 {
71 struct pci_attach_args *pa = aux;
72 struct bha_softc *sc = (void *)self;
73 bus_chipset_tag_t bc = pa->pa_bc;
74 bus_io_addr_t iobase;
75 bus_io_size_t iosize;
76 bus_io_handle_t ioh;
77 pci_chipset_tag_t pc = pa->pa_pc;
78 pci_intr_handle_t ih;
79 pcireg_t csr;
80 const char *model, *intrstr;
81
82 if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_BUSLOGIC_OLD946C)
83 model = "BusLogic 9xxC SCSI";
84 else if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_BUSLOGIC_946C)
85 model = "BusLogic 9xxC SCSI";
86 else
87 model = "unknown model!";
88 printf(": %s\n", model);
89
90 if (pci_io_find(pc, pa->pa_tag, PCI_CBIO, &iobase, &iosize))
91 panic("bha_attach: pci_io_find failed!");
92 if (bus_io_map(bc, iobase, iosize, &ioh))
93 panic("bha_attach: bus_io_map failed!");
94
95 sc->sc_bc = bc;
96 sc->sc_ioh = ioh;
97 if (!bha_find(bc, ioh, sc))
98 panic("bha_attach: bha_find failed!");
99
100 csr = pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
101 pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
102 csr | PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_IO_ENABLE);
103
104 if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
105 pa->pa_intrline, &ih)) {
106 printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
107 return;
108 }
109 intrstr = pci_intr_string(pc, ih);
110 sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, bha_intr, sc);
111 if (sc->sc_ih == NULL) {
112 printf("%s: couldn't establish interrupt",
113 sc->sc_dev.dv_xname);
114 if (intrstr != NULL)
115 printf(" at %s", intrstr);
116 printf("\n");
117 return;
118 }
119 printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
120
121 bha_attach(sc);
122 }
123