2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright 2003 by Peter Grehan. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/module.h>
39 #include <sys/kernel.h>
41 #include <dev/ofw/ofw_bus.h>
42 #include <dev/ofw/ofw_bus_subr.h>
43 #include <dev/ofw/openfirm.h>
45 #include <machine/bus.h>
46 #include <machine/intr_machdep.h>
47 #include <machine/md_var.h>
48 #include <machine/pio.h>
49 #include <machine/resource.h>
56 #include <machine/openpicreg.h>
57 #include <machine/openpicvar.h>
64 static int openpic_ofw_probe(device_t);
65 static int openpic_ofw_attach(device_t);
67 static void openpic_ofw_translate_code(device_t, u_int irq, int code,
68 enum intr_trigger *trig, enum intr_polarity *pol);
70 static device_method_t openpic_ofw_methods[] = {
71 /* Device interface */
72 DEVMETHOD(device_probe, openpic_ofw_probe),
73 DEVMETHOD(device_attach, openpic_ofw_attach),
74 DEVMETHOD(device_suspend, openpic_suspend),
75 DEVMETHOD(device_resume, openpic_resume),
78 DEVMETHOD(pic_bind, openpic_bind),
79 DEVMETHOD(pic_config, openpic_config),
80 DEVMETHOD(pic_dispatch, openpic_dispatch),
81 DEVMETHOD(pic_enable, openpic_enable),
82 DEVMETHOD(pic_eoi, openpic_eoi),
83 DEVMETHOD(pic_ipi, openpic_ipi),
84 DEVMETHOD(pic_mask, openpic_mask),
85 DEVMETHOD(pic_unmask, openpic_unmask),
87 DEVMETHOD(pic_translate_code, openpic_ofw_translate_code),
92 static driver_t openpic_ofw_driver = {
95 sizeof(struct openpic_softc),
98 EARLY_DRIVER_MODULE(openpic, ofwbus, openpic_ofw_driver, openpic_devclass,
99 0, 0, BUS_PASS_INTERRUPT);
100 EARLY_DRIVER_MODULE(openpic, simplebus, openpic_ofw_driver, openpic_devclass,
101 0, 0, BUS_PASS_INTERRUPT);
102 EARLY_DRIVER_MODULE(openpic, macio, openpic_ofw_driver, openpic_devclass, 0, 0,
106 openpic_ofw_probe(device_t dev)
108 const char *type = ofw_bus_get_type(dev);
113 if (!ofw_bus_is_compatible(dev, "chrp,open-pic") &&
114 strcmp(type, "open-pic") != 0)
118 * On some U4 systems, there is a phantom MPIC in the mac-io cell.
119 * The uninorth driver will pick up the real PIC, so ignore it here.
121 if (OF_finddevice("/u4") != (phandle_t)-1)
124 device_set_desc(dev, OPENPIC_DEVSTR);
129 openpic_ofw_attach(device_t dev)
131 struct openpic_softc *sc;
132 phandle_t xref, node;
134 node = ofw_bus_get_node(dev);
135 sc = device_get_softc(dev);
137 if (OF_getencprop(node, "phandle", &xref, sizeof(xref)) == -1 &&
138 OF_getencprop(node, "ibm,phandle", &xref, sizeof(xref)) == -1 &&
139 OF_getencprop(node, "linux,phandle", &xref, sizeof(xref)) == -1)
142 if (ofw_bus_is_compatible(dev, "fsl,mpic")) {
143 sc->sc_quirks = OPENPIC_QUIRK_SINGLE_BIND;
144 sc->sc_quirks |= OPENPIC_QUIRK_HIDDEN_IRQS;
147 return (openpic_common_attach(dev, xref));
151 openpic_ofw_translate_code(device_t dev, u_int irq, int code,
152 enum intr_trigger *trig, enum intr_polarity *pol)
157 *trig = INTR_TRIGGER_EDGE;
158 *pol = INTR_POLARITY_HIGH;
162 *trig = INTR_TRIGGER_LEVEL;
163 *pol = INTR_POLARITY_LOW;
167 *trig = INTR_TRIGGER_LEVEL;
168 *pol = INTR_POLARITY_HIGH;
172 *trig = INTR_TRIGGER_EDGE;
173 *pol = INTR_POLARITY_LOW;
176 *trig = INTR_TRIGGER_CONFORM;
177 *pol = INTR_POLARITY_CONFORM;