fwohci_pci.c revision 1.1 1 1.1 matt /*-
2 1.1 matt * Copyright (c) 2000 The NetBSD Foundation, Inc.
3 1.1 matt * All rights reserved.
4 1.1 matt *
5 1.1 matt * This code is derived from software contributed to The NetBSD Foundation
6 1.1 matt * by Matt Thomas of 3am Software Foundry.
7 1.1 matt *
8 1.1 matt * Redistribution and use in source and binary forms, with or without
9 1.1 matt * modification, are permitted provided that the following conditions
10 1.1 matt * are met:
11 1.1 matt * 1. Redistributions of source code must retain the above copyright
12 1.1 matt * notice, this list of conditions and the following disclaimer.
13 1.1 matt * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 matt * notice, this list of conditions and the following disclaimer in the
15 1.1 matt * documentation and/or other materials provided with the distribution.
16 1.1 matt * 3. All advertising materials mentioning features or use of this software
17 1.1 matt * must display the following acknowledgement:
18 1.1 matt * This product includes software developed by the NetBSD
19 1.1 matt * Foundation, Inc. and its contributors.
20 1.1 matt * 4. Neither the name of The NetBSD Foundation nor the names of its
21 1.1 matt * contributors may be used to endorse or promote products derived
22 1.1 matt * from this software without specific prior written permission.
23 1.1 matt *
24 1.1 matt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
25 1.1 matt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 1.1 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 1.1 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
28 1.1 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 1.1 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 1.1 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 1.1 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 1.1 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 1.1 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 1.1 matt * POSSIBILITY OF SUCH DAMAGE.
35 1.1 matt */
36 1.1 matt
37 1.1 matt #include <sys/param.h>
38 1.1 matt #include <sys/types.h>
39 1.1 matt #include <sys/socket.h>
40 1.1 matt #include <sys/device.h>
41 1.1 matt
42 1.1 matt #include <machine/bus.h>
43 1.1 matt #include <machine/intr.h>
44 1.1 matt
45 1.1 matt #include <dev/pci/pcireg.h>
46 1.1 matt #include <dev/pci/pcivar.h>
47 1.1 matt #include <dev/ieee1394/ieee1394reg.h>
48 1.1 matt #include <dev/ieee1394/ieee1394var.h>
49 1.1 matt #include <dev/ieee1394/fwohcireg.h>
50 1.1 matt #include <dev/ieee1394/fwohcivar.h>
51 1.1 matt
52 1.1 matt struct fwohci_pci_softc {
53 1.1 matt struct fwohci_softc psc_sc;
54 1.1 matt pci_chipset_tag_t psc_pc;
55 1.1 matt void *psc_ih;
56 1.1 matt };
57 1.1 matt
58 1.1 matt static int fwohci_pci_match __P((struct device *, struct cfdata *, void *));
59 1.1 matt static void fwohci_pci_attach __P((struct device *, struct device *, void *));
60 1.1 matt
61 1.1 matt struct cfattach fwohci_pci_ca = {
62 1.1 matt sizeof(struct fwohci_pci_softc), fwohci_pci_match, fwohci_pci_attach,
63 1.1 matt #if 0
64 1.1 matt fwohci_pci_detach, fwohci_activate
65 1.1 matt #endif
66 1.1 matt };
67 1.1 matt
68 1.1 matt static int
69 1.1 matt fwohci_pci_match(struct device *parent, struct cfdata *match, void *aux)
70 1.1 matt {
71 1.1 matt struct pci_attach_args *pa = (struct pci_attach_args *) aux;
72 1.1 matt
73 1.1 matt if (PCI_CLASS(pa->pa_class) == PCI_CLASS_SERIALBUS &&
74 1.1 matt PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_SERIALBUS_FIREWIRE &&
75 1.1 matt PCI_INTERFACE(pa->pa_class) == PCI_INTERFACE_OHCI)
76 1.1 matt return 1;
77 1.1 matt
78 1.1 matt return 0;
79 1.1 matt }
80 1.1 matt
81 1.1 matt static void
82 1.1 matt fwohci_pci_attach(struct device *parent, struct device *self, void *aux)
83 1.1 matt {
84 1.1 matt struct pci_attach_args *pa = (struct pci_attach_args *) aux;
85 1.1 matt struct fwohci_pci_softc *psc = (struct fwohci_pci_softc *) self;
86 1.1 matt char devinfo[256];
87 1.1 matt char const *intrstr;
88 1.1 matt pci_intr_handle_t ih;
89 1.1 matt u_int32_t csr;
90 1.1 matt
91 1.1 matt pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
92 1.1 matt printf(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class));
93 1.1 matt
94 1.1 matt psc->psc_sc.sc_dmat = pa->pa_dmat;
95 1.1 matt psc->psc_pc = pa->pa_pc;
96 1.1 matt
97 1.1 matt /* Map I/O registers */
98 1.1 matt if (pci_mapreg_map(pa, PCI_OHCI_MAP_REGISTER, PCI_MAPREG_TYPE_MEM, 0,
99 1.1 matt &psc->psc_sc.sc_memt, &psc->psc_sc.sc_memh,
100 1.1 matt NULL, &psc->psc_sc.sc_memsize)) {
101 1.1 matt printf("%s: can't map OCHI register space\n", self->dv_xname);
102 1.1 matt return;
103 1.1 matt }
104 1.1 matt
105 1.1 matt /* Disable interrupts, so we don't get any spurious ones. */
106 1.1 matt OHCI_CSR_WRITE(&psc->psc_sc, OHCI_REG_IntEventClear, OHCI_Int_MasterEnable);
107 1.1 matt
108 1.1 matt /* Enable the device. */
109 1.1 matt csr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
110 1.1 matt pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
111 1.1 matt csr | PCI_COMMAND_MASTER_ENABLE);
112 1.1 matt
113 1.1 matt /* Map and establish the interrupt. */
114 1.1 matt if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin,
115 1.1 matt pa->pa_intrline, &ih)) {
116 1.1 matt printf("%s: couldn't map interrupt\n", self->dv_xname);
117 1.1 matt return;
118 1.1 matt }
119 1.1 matt intrstr = pci_intr_string(pa->pa_pc, ih);
120 1.1 matt psc->psc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO, fwohci_intr, &psc->psc_sc);
121 1.1 matt if (psc->psc_ih == NULL) {
122 1.1 matt printf("%s: couldn't establish interrupt", self->dv_xname);
123 1.1 matt if (intrstr != NULL)
124 1.1 matt printf(" at %s", intrstr);
125 1.1 matt printf("\n");
126 1.1 matt return;
127 1.1 matt }
128 1.1 matt printf("%s: interrupting at %s\n", self->dv_xname, intrstr);
129 1.1 matt
130 1.1 matt fwohci_init(&psc->psc_sc);
131 1.1 matt }
132