Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / pci / bha_pci.c
blob8d792fa5ab2da9a9dd07f9019348fb9e76494435
1 /* $NetBSD: bha_pci.c,v 1.36 2009/05/12 08:23:00 cegger Exp $ */
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
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
12 * are met:
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>
39 #include <sys/bus.h>
40 #include <sys/intr.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>
51 #define PCI_CBIO 0x10
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.
58 static int
59 bha_pci_match(device_t parent, cfdata_t match, void *aux)
61 struct pci_attach_args *pa = aux;
62 bus_space_tag_t iot;
63 bus_space_handle_t ioh;
64 bus_size_t iosize;
65 int rv;
67 if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_BUSLOGIC)
68 return (0);
70 if (PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_BUSLOGIC_MULTIMASTER_NC &&
71 PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_BUSLOGIC_MULTIMASTER)
72 return (0);
74 if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0, &iot, &ioh,
75 NULL, &iosize))
76 return (0);
78 rv = bha_find(iot, ioh);
80 bus_space_unmap(iot, ioh, iosize);
82 return (rv);
86 * Attach all the sub-devices we can find
88 static void
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);
93 bus_space_tag_t iot;
94 bus_space_handle_t ioh;
95 pci_chipset_tag_t pc = pa->pa_pc;
96 pci_intr_handle_t ih;
97 pcireg_t csr;
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";
106 else
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,
111 NULL, NULL)) {
112 aprint_error_dev(&sc->sc_dev, "unable to map device registers\n");
113 return;
116 sc->sc_iot = iot;
117 sc->sc_ioh = ioh;
118 sc->sc_dmat = pa->pa_dmat;
119 if (!bha_find(iot, ioh))
120 panic("bha_pci_attach: bha_find failed");
122 sc->sc_dmaflags = 0;
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");
130 return;
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");
136 if (intrstr != NULL)
137 aprint_error(" at %s", intrstr);
138 aprint_error("\n");
139 return;
141 aprint_normal_dev(&sc->sc_dev, "interrupting at %s\n", intrstr);
143 bha_attach(sc);
145 bha_disable_isacompat(sc);
148 CFATTACH_DECL(bha_pci, sizeof(struct bha_softc),
149 bha_pci_match, bha_pci_attach, NULL, NULL);