iop_pci.c revision 1.6.4.2 1 1.6.4.2 he /* $NetBSD: iop_pci.c,v 1.6.4.2 2001/10/25 18:02:16 he Exp $ */
2 1.6.4.2 he
3 1.6.4.2 he /*-
4 1.6.4.2 he * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 1.6.4.2 he * All rights reserved.
6 1.6.4.2 he *
7 1.6.4.2 he * This code is derived from software contributed to The NetBSD Foundation
8 1.6.4.2 he * by Andrew Doran.
9 1.6.4.2 he *
10 1.6.4.2 he * Redistribution and use in source and binary forms, with or without
11 1.6.4.2 he * modification, are permitted provided that the following conditions
12 1.6.4.2 he * are met:
13 1.6.4.2 he * 1. Redistributions of source code must retain the above copyright
14 1.6.4.2 he * notice, this list of conditions and the following disclaimer.
15 1.6.4.2 he * 2. Redistributions in binary form must reproduce the above copyright
16 1.6.4.2 he * notice, this list of conditions and the following disclaimer in the
17 1.6.4.2 he * documentation and/or other materials provided with the distribution.
18 1.6.4.2 he * 3. All advertising materials mentioning features or use of this software
19 1.6.4.2 he * must display the following acknowledgement:
20 1.6.4.2 he * This product includes software developed by the NetBSD
21 1.6.4.2 he * Foundation, Inc. and its contributors.
22 1.6.4.2 he * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.6.4.2 he * contributors may be used to endorse or promote products derived
24 1.6.4.2 he * from this software without specific prior written permission.
25 1.6.4.2 he *
26 1.6.4.2 he * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.6.4.2 he * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.6.4.2 he * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.6.4.2 he * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.6.4.2 he * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.6.4.2 he * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.6.4.2 he * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.6.4.2 he * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.6.4.2 he * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.6.4.2 he * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.6.4.2 he * POSSIBILITY OF SUCH DAMAGE.
37 1.6.4.2 he */
38 1.6.4.2 he
39 1.6.4.2 he /*
40 1.6.4.2 he * PCI front-end for `iop' driver.
41 1.6.4.2 he */
42 1.6.4.2 he
43 1.6.4.2 he #include "opt_i2o.h"
44 1.6.4.2 he
45 1.6.4.2 he #include <sys/param.h>
46 1.6.4.2 he #include <sys/systm.h>
47 1.6.4.2 he #include <sys/kernel.h>
48 1.6.4.2 he #include <sys/device.h>
49 1.6.4.2 he #include <sys/queue.h>
50 1.6.4.2 he #include <sys/proc.h>
51 1.6.4.2 he
52 1.6.4.2 he #include <machine/endian.h>
53 1.6.4.2 he #include <machine/bus.h>
54 1.6.4.2 he
55 1.6.4.2 he #include <dev/pci/pcidevs.h>
56 1.6.4.2 he #include <dev/pci/pcivar.h>
57 1.6.4.2 he
58 1.6.4.2 he #include <dev/i2o/i2o.h>
59 1.6.4.2 he #include <dev/i2o/iopreg.h>
60 1.6.4.2 he #include <dev/i2o/iopio.h>
61 1.6.4.2 he #include <dev/i2o/iopvar.h>
62 1.6.4.2 he
63 1.6.4.2 he #define PCI_INTERFACE_I2O_POLLED 0x00
64 1.6.4.2 he #define PCI_INTERFACE_I2O_INTRDRIVEN 0x01
65 1.6.4.2 he
66 1.6.4.2 he static void iop_pci_attach(struct device *, struct device *, void *);
67 1.6.4.2 he static int iop_pci_match(struct device *, struct cfdata *, void *);
68 1.6.4.2 he
69 1.6.4.2 he struct cfattach iop_pci_ca = {
70 1.6.4.2 he sizeof(struct iop_softc), iop_pci_match, iop_pci_attach
71 1.6.4.2 he };
72 1.6.4.2 he
73 1.6.4.2 he static int
74 1.6.4.2 he iop_pci_match(struct device *parent, struct cfdata *match, void *aux)
75 1.6.4.2 he {
76 1.6.4.2 he struct pci_attach_args *pa;
77 1.6.4.2 he
78 1.6.4.2 he pa = aux;
79 1.6.4.2 he
80 1.6.4.2 he /*
81 1.6.4.2 he * Look for an "intelligent I/O processor" that adheres to the I2O
82 1.6.4.2 he * specification. Ignore the device if it doesn't support interrupt
83 1.6.4.2 he * driven operation.
84 1.6.4.2 he */
85 1.6.4.2 he if (PCI_CLASS(pa->pa_class) == PCI_CLASS_I2O &&
86 1.6.4.2 he PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_I2O_STANDARD &&
87 1.6.4.2 he PCI_INTERFACE(pa->pa_class) == PCI_INTERFACE_I2O_INTRDRIVEN)
88 1.6.4.2 he return (1);
89 1.6.4.2 he
90 1.6.4.2 he return (0);
91 1.6.4.2 he }
92 1.6.4.2 he
93 1.6.4.2 he static void
94 1.6.4.2 he iop_pci_attach(struct device *parent, struct device *self, void *aux)
95 1.6.4.2 he {
96 1.6.4.2 he struct pci_attach_args *pa;
97 1.6.4.2 he struct iop_softc *sc;
98 1.6.4.2 he pci_chipset_tag_t pc;
99 1.6.4.2 he pci_intr_handle_t ih;
100 1.6.4.2 he const char *intrstr;
101 1.6.4.2 he pcireg_t reg;
102 1.6.4.2 he int i;
103 1.6.4.2 he
104 1.6.4.2 he sc = (struct iop_softc *)self;
105 1.6.4.2 he pa = (struct pci_attach_args *)aux;
106 1.6.4.2 he pc = pa->pa_pc;
107 1.6.4.2 he printf(": ");
108 1.6.4.2 he
109 1.6.4.2 he /*
110 1.6.4.2 he * The kernel always uses the first memory mapping to communicate
111 1.6.4.2 he * with the IOP.
112 1.6.4.2 he */
113 1.6.4.2 he for (i = PCI_MAPREG_START; i < PCI_MAPREG_END; i += 4) {
114 1.6.4.2 he reg = pci_conf_read(pc, pa->pa_tag, i);
115 1.6.4.2 he if (PCI_MAPREG_TYPE(reg) == PCI_MAPREG_TYPE_MEM)
116 1.6.4.2 he break;
117 1.6.4.2 he }
118 1.6.4.2 he if (i == PCI_MAPREG_END) {
119 1.6.4.2 he printf("can't find mapping\n");
120 1.6.4.2 he return;
121 1.6.4.2 he }
122 1.6.4.2 he
123 1.6.4.2 he /* Map the register window. */
124 1.6.4.2 he if (pci_mapreg_map(pa, i, PCI_MAPREG_TYPE_MEM, 0, &sc->sc_iot,
125 1.6.4.2 he &sc->sc_ioh, NULL, NULL)) {
126 1.6.4.2 he printf("%s: can't map register window\n", sc->sc_dv.dv_xname);
127 1.6.4.2 he return;
128 1.6.4.2 he }
129 1.6.4.2 he
130 1.6.4.2 he sc->sc_dmat = pa->pa_dmat;
131 1.6.4.2 he sc->sc_bus_memt = pa->pa_memt;
132 1.6.4.2 he sc->sc_bus_iot = pa->pa_iot;
133 1.6.4.2 he
134 1.6.4.2 he /* Enable the device. */
135 1.6.4.2 he reg = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
136 1.6.4.2 he pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
137 1.6.4.2 he reg | PCI_COMMAND_MASTER_ENABLE);
138 1.6.4.2 he
139 1.6.4.2 he /* Map and establish the interrupt. XXX IPL_BIO. */
140 1.6.4.2 he if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin, pa->pa_intrline,
141 1.6.4.2 he &ih)) {
142 1.6.4.2 he printf("can't map interrupt\n");
143 1.6.4.2 he return;
144 1.6.4.2 he }
145 1.6.4.2 he intrstr = pci_intr_string(pc, ih);
146 1.6.4.2 he sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, iop_intr, sc);
147 1.6.4.2 he if (sc->sc_ih == NULL) {
148 1.6.4.2 he printf("can't establish interrupt");
149 1.6.4.2 he if (intrstr != NULL)
150 1.6.4.2 he printf(" at %s", intrstr);
151 1.6.4.2 he printf("\n");
152 1.6.4.2 he return;
153 1.6.4.2 he }
154 1.6.4.2 he
155 1.6.4.2 he /* Attach to the bus-independent code. */
156 1.6.4.2 he iop_init(sc, intrstr);
157 1.6.4.2 he }
158