1 /* $NetBSD: bha_pci.c,v 1.36 2009/05/12 08:23:00 cegger Exp $ */
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: bha_pci.c,v 1.36 2009/05/12 08:23:00 cegger Exp $");
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/device.h>
42 #include <dev/scsipi/scsipi_all.h>
43 #include <dev/scsipi/scsiconf.h>
45 #include <dev/pci/pcivar.h>
46 #include <dev/pci/pcidevs.h>
48 #include <dev/ic/bhareg.h>
49 #include <dev/ic/bhavar.h>
54 * Check the slots looking for a board we recognise
55 * If we find one, note it's address (slot) and call
56 * the actual probe routine to check it out.
59 bha_pci_match(device_t parent
, cfdata_t match
, void *aux
)
61 struct pci_attach_args
*pa
= aux
;
63 bus_space_handle_t ioh
;
67 if (PCI_VENDOR(pa
->pa_id
) != PCI_VENDOR_BUSLOGIC
)
70 if (PCI_PRODUCT(pa
->pa_id
) != PCI_PRODUCT_BUSLOGIC_MULTIMASTER_NC
&&
71 PCI_PRODUCT(pa
->pa_id
) != PCI_PRODUCT_BUSLOGIC_MULTIMASTER
)
74 if (pci_mapreg_map(pa
, PCI_CBIO
, PCI_MAPREG_TYPE_IO
, 0, &iot
, &ioh
,
78 rv
= bha_find(iot
, ioh
);
80 bus_space_unmap(iot
, ioh
, iosize
);
86 * Attach all the sub-devices we can find
89 bha_pci_attach(device_t parent
, device_t self
, void *aux
)
91 struct pci_attach_args
*pa
= aux
;
92 struct bha_softc
*sc
= device_private(self
);
94 bus_space_handle_t ioh
;
95 pci_chipset_tag_t pc
= pa
->pa_pc
;
98 const char *model
, *intrstr
;
100 aprint_naive(": SCSI controller\n");
102 if (PCI_PRODUCT(pa
->pa_id
) == PCI_PRODUCT_BUSLOGIC_MULTIMASTER_NC
)
103 model
= "BusLogic 9xxC SCSI";
104 else if (PCI_PRODUCT(pa
->pa_id
) == PCI_PRODUCT_BUSLOGIC_MULTIMASTER
)
105 model
= "BusLogic 9xxC SCSI";
107 model
= "unknown model!";
108 aprint_normal(": %s\n", model
);
110 if (pci_mapreg_map(pa
, PCI_CBIO
, PCI_MAPREG_TYPE_IO
, 0, &iot
, &ioh
,
112 aprint_error_dev(&sc
->sc_dev
, "unable to map device registers\n");
118 sc
->sc_dmat
= pa
->pa_dmat
;
119 if (!bha_find(iot
, ioh
))
120 panic("bha_pci_attach: bha_find failed");
124 csr
= pci_conf_read(pc
, pa
->pa_tag
, PCI_COMMAND_STATUS_REG
);
125 pci_conf_write(pc
, pa
->pa_tag
, PCI_COMMAND_STATUS_REG
,
126 csr
| PCI_COMMAND_MASTER_ENABLE
| PCI_COMMAND_IO_ENABLE
);
128 if (pci_intr_map(pa
, &ih
)) {
129 aprint_error_dev(&sc
->sc_dev
, "couldn't map interrupt\n");
132 intrstr
= pci_intr_string(pc
, ih
);
133 sc
->sc_ih
= pci_intr_establish(pc
, ih
, IPL_BIO
, bha_intr
, sc
);
134 if (sc
->sc_ih
== NULL
) {
135 aprint_error_dev(&sc
->sc_dev
, "couldn't establish interrupt");
137 aprint_error(" at %s", intrstr
);
141 aprint_normal_dev(&sc
->sc_dev
, "interrupting at %s\n", intrstr
);
145 bha_disable_isacompat(sc
);
148 CFATTACH_DECL(bha_pci
, sizeof(struct bha_softc
),
149 bha_pci_match
, bha_pci_attach
, NULL
, NULL
);