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