openpic_ofw.c revision 261513
128219Smsmith/*- 255939Snsouch * Copyright 2003 by Peter Grehan. All rights reserved. 328219Smsmith * 428219Smsmith * Redistribution and use in source and binary forms, with or without 528219Smsmith * modification, are permitted provided that the following conditions 628219Smsmith * are met: 728219Smsmith * 1. Redistributions of source code must retain the above copyright 828219Smsmith * notice, this list of conditions and the following disclaimer. 928219Smsmith * 2. Redistributions in binary form must reproduce the above copyright 1028219Smsmith * notice, this list of conditions and the following disclaimer in the 1128219Smsmith * documentation and/or other materials provided with the distribution. 1228219Smsmith * 3. The name of the author may not be used to endorse or promote products 1328219Smsmith * derived from this software without specific prior written permission. 1428219Smsmith * 1528219Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1628219Smsmith * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1728219Smsmith * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1828219Smsmith * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 1928219Smsmith * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 2028219Smsmith * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 2128219Smsmith * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 2228219Smsmith * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 2328219Smsmith * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2428219Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2528219Smsmith * SUCH DAMAGE. 2650477Speter * 2728219Smsmith */ 2828219Smsmith 2955939Snsouch#include <sys/cdefs.h> 3055939Snsouch__FBSDID("$FreeBSD: head/sys/powerpc/ofw/openpic_ofw.c 261513 2014-02-05 14:44:22Z nwhitehorn $"); 3128219Smsmith 3228219Smsmith#include <sys/param.h> 3355939Snsouch#include <sys/systm.h> 3455939Snsouch#include <sys/module.h> 3528219Smsmith#include <sys/bus.h> 3628219Smsmith#include <sys/conf.h> 3742475Snsouch#include <sys/kernel.h> 3832178Smsmith 3928219Smsmith#include <dev/ofw/ofw_bus.h> 4042475Snsouch#include <dev/ofw/ofw_bus_subr.h> 4155939Snsouch#include <dev/ofw/openfirm.h> 4255939Snsouch 4355939Snsouch#include <machine/bus.h> 4442475Snsouch#include <machine/intr_machdep.h> 4528219Smsmith#include <machine/md_var.h> 4642475Snsouch#include <machine/pio.h> 4742475Snsouch#include <machine/resource.h> 4842475Snsouch 4942475Snsouch#include <vm/vm.h> 5042475Snsouch#include <vm/pmap.h> 5142475Snsouch 5232178Smsmith#include <sys/rman.h> 5328219Smsmith 5455939Snsouch#include <machine/openpicreg.h> 5555939Snsouch#include <machine/openpicvar.h> 5655939Snsouch 5755939Snsouch#include "pic_if.h" 5842475Snsouch 5932178Smsmith/* 6028257Smsmith * OFW interface 6128257Smsmith */ 6232178Smsmithstatic int openpic_ofw_probe(device_t); 6332178Smsmithstatic int openpic_ofw_attach(device_t); 6432178Smsmith 6542475Snsouchstatic void openpic_ofw_translate_code(device_t, u_int irq, int code, 6628257Smsmith enum intr_trigger *trig, enum intr_polarity *pol); 6742475Snsouch 6842475Snsouchstatic device_method_t openpic_ofw_methods[] = { 6942475Snsouch /* Device interface */ 7042475Snsouch DEVMETHOD(device_probe, openpic_ofw_probe), 7155939Snsouch DEVMETHOD(device_attach, openpic_ofw_attach), 7255939Snsouch DEVMETHOD(device_suspend, openpic_suspend), 7328257Smsmith DEVMETHOD(device_resume, openpic_resume), 7428257Smsmith 7555939Snsouch /* PIC interface */ 7655939Snsouch DEVMETHOD(pic_bind, openpic_bind), 7755939Snsouch DEVMETHOD(pic_config, openpic_config), 7855939Snsouch DEVMETHOD(pic_dispatch, openpic_dispatch), 7955939Snsouch DEVMETHOD(pic_enable, openpic_enable), 8055939Snsouch DEVMETHOD(pic_eoi, openpic_eoi), 8128219Smsmith DEVMETHOD(pic_ipi, openpic_ipi), 8255939Snsouch DEVMETHOD(pic_mask, openpic_mask), 8328219Smsmith DEVMETHOD(pic_unmask, openpic_unmask), 8428219Smsmith 8528219Smsmith DEVMETHOD(pic_translate_code, openpic_ofw_translate_code), 8628219Smsmith 8742475Snsouch DEVMETHOD_END 8842475Snsouch}; 8928219Smsmith 9028261Smsmithstatic driver_t openpic_ofw_driver = { 9147625Sphk "openpic", 9247625Sphk openpic_ofw_methods, 9347625Sphk sizeof(struct openpic_softc), 9447625Sphk}; 9547625Sphk 9647625SphkDRIVER_MODULE(openpic, ofwbus, openpic_ofw_driver, openpic_devclass, 0, 0); 9747625SphkDRIVER_MODULE(openpic, simplebus, openpic_ofw_driver, openpic_devclass, 0, 0); 9847625SphkDRIVER_MODULE(openpic, macio, openpic_ofw_driver, openpic_devclass, 0, 0); 9947625Sphk 10047625Sphkstatic int 10147625Sphkopenpic_ofw_probe(device_t dev) 10247625Sphk{ 10347625Sphk const char *type = ofw_bus_get_type(dev); 10447625Sphk 10547625Sphk if (type == NULL) 10647625Sphk return (ENXIO); 10728219Smsmith 10842475Snsouch if (!ofw_bus_is_compatible(dev, "chrp,open-pic") && 10942475Snsouch strcmp(type, "open-pic") != 0) 11042475Snsouch return (ENXIO); 11155939Snsouch 11242475Snsouch /* 11342475Snsouch * On some U4 systems, there is a phantom MPIC in the mac-io cell. 11455939Snsouch * The uninorth driver will pick up the real PIC, so ignore it here. 11542475Snsouch */ 11655939Snsouch if (OF_finddevice("/u4") != (phandle_t)-1) 11755939Snsouch return (ENXIO); 11842475Snsouch 11942475Snsouch device_set_desc(dev, OPENPIC_DEVSTR); 12042475Snsouch return (0); 12142475Snsouch} 12242475Snsouch 12355939Snsouchstatic int 12442475Snsouchopenpic_ofw_attach(device_t dev) 12542475Snsouch{ 12655939Snsouch phandle_t xref, node; 12742475Snsouch 12855939Snsouch node = ofw_bus_get_node(dev); 12955939Snsouch 13042475Snsouch if (OF_getprop(node, "phandle", &xref, sizeof(xref)) == -1 && 13142475Snsouch OF_getprop(node, "ibm,phandle", &xref, sizeof(xref)) == -1 && 13242475Snsouch OF_getprop(node, "linux,phandle", &xref, sizeof(xref)) == -1) 13342475Snsouch xref = node; 13442475Snsouch 13542475Snsouch return (openpic_common_attach(dev, xref)); 13656455Speter} 13756455Speter 13856455Speterstatic void 13956455Speteropenpic_ofw_translate_code(device_t dev, u_int irq, int code, 14056455Speter enum intr_trigger *trig, enum intr_polarity *pol) 14156455Speter{ 14256455Speter switch (code) { 14328219Smsmith case 0: 14455939Snsouch /* L to H edge */ 14528219Smsmith *trig = INTR_TRIGGER_EDGE; 14655939Snsouch *pol = INTR_POLARITY_HIGH; 14755939Snsouch break; 14828219Smsmith case 1: 14928219Smsmith /* Active L level */ 15028219Smsmith *trig = INTR_TRIGGER_LEVEL; 15155939Snsouch *pol = INTR_POLARITY_LOW; 15255939Snsouch break; 15355939Snsouch case 2: 15455939Snsouch /* Active H level */ 15528219Smsmith *trig = INTR_TRIGGER_LEVEL; 15628219Smsmith *pol = INTR_POLARITY_HIGH; 15755939Snsouch break; 15855939Snsouch case 3: 15928219Smsmith /* H to L edge */ 16055939Snsouch *trig = INTR_TRIGGER_EDGE; 16155939Snsouch *pol = INTR_POLARITY_LOW; 16255939Snsouch break; 16355939Snsouch default: 16455939Snsouch *trig = INTR_TRIGGER_CONFORM; 16555939Snsouch *pol = INTR_POLARITY_CONFORM; 16655939Snsouch } 16755939Snsouch} 16855939Snsouch 16928219Smsmith