openpic_ofw.c revision 265959
129088Smarkm/*-
229088Smarkm * Copyright 2003 by Peter Grehan. All rights reserved.
329088Smarkm *
429088Smarkm * Redistribution and use in source and binary forms, with or without
529088Smarkm * modification, are permitted provided that the following conditions
629088Smarkm * are met:
729088Smarkm * 1. Redistributions of source code must retain the above copyright
829088Smarkm *    notice, this list of conditions and the following disclaimer.
929088Smarkm * 2. Redistributions in binary form must reproduce the above copyright
1029088Smarkm *    notice, this list of conditions and the following disclaimer in the
1129088Smarkm *    documentation and/or other materials provided with the distribution.
1229088Smarkm * 3. The name of the author may not be used to endorse or promote products
1329088Smarkm *    derived from this software without specific prior written permission.
1429088Smarkm *
1529088Smarkm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1629088Smarkm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1729088Smarkm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1829088Smarkm * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1929088Smarkm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
2029088Smarkm * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2129088Smarkm * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
2229088Smarkm * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2329088Smarkm * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2429088Smarkm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2529088Smarkm * SUCH DAMAGE.
2629088Smarkm *
2729088Smarkm */
2829088Smarkm
2929088Smarkm#include <sys/cdefs.h>
3029088Smarkm__FBSDID("$FreeBSD: stable/10/sys/powerpc/ofw/openpic_ofw.c 265959 2014-05-13 17:12:07Z ian $");
3129088Smarkm
3229088Smarkm#include <sys/param.h>
3329088Smarkm#include <sys/systm.h>
3484305Smarkm#include <sys/module.h>
3587139Smarkm#include <sys/bus.h>
3684305Smarkm#include <sys/conf.h>
3784305Smarkm#include <sys/kernel.h>
3829088Smarkm
3929088Smarkm#include <dev/ofw/ofw_bus.h>
4029088Smarkm#include <dev/ofw/ofw_bus_subr.h>
4129088Smarkm#include <dev/ofw/openfirm.h>
4229088Smarkm
4329088Smarkm#include <machine/bus.h>
4429088Smarkm#include <machine/intr_machdep.h>
4529088Smarkm#include <machine/md_var.h>
4629088Smarkm#include <machine/pio.h>
4729088Smarkm#include <machine/resource.h>
4829088Smarkm
4929088Smarkm#include <vm/vm.h>
5029088Smarkm#include <vm/pmap.h>
5129088Smarkm
5229088Smarkm#include <sys/rman.h>
5329088Smarkm
5429088Smarkm#include <machine/openpicvar.h>
5529088Smarkm
5629088Smarkm#include "pic_if.h"
5729088Smarkm
5829088Smarkm/*
5929088Smarkm * OFW interface
6029088Smarkm */
6129088Smarkmstatic int	openpic_ofw_probe(device_t);
6229088Smarkmstatic int	openpic_ofw_attach(device_t);
6329088Smarkm
6429088Smarkmstatic device_method_t  openpic_ofw_methods[] = {
6529088Smarkm	/* Device interface */
6629088Smarkm	DEVMETHOD(device_probe,		openpic_ofw_probe),
6729088Smarkm	DEVMETHOD(device_attach,	openpic_ofw_attach),
6829088Smarkm
6929088Smarkm	/* PIC interface */
7029088Smarkm	DEVMETHOD(pic_bind,		openpic_bind),
7129088Smarkm	DEVMETHOD(pic_config,		openpic_config),
7229088Smarkm	DEVMETHOD(pic_dispatch,		openpic_dispatch),
7329088Smarkm	DEVMETHOD(pic_enable,		openpic_enable),
7429088Smarkm	DEVMETHOD(pic_eoi,		openpic_eoi),
7529088Smarkm	DEVMETHOD(pic_ipi,		openpic_ipi),
7629088Smarkm	DEVMETHOD(pic_mask,		openpic_mask),
7729088Smarkm	DEVMETHOD(pic_unmask,		openpic_unmask),
7829088Smarkm
7929088Smarkm	DEVMETHOD_END
8029088Smarkm};
8129088Smarkm
8229088Smarkmstatic driver_t openpic_ofw_driver = {
8329088Smarkm	"openpic",
8429088Smarkm	openpic_ofw_methods,
8529088Smarkm	sizeof(struct openpic_softc),
8629088Smarkm};
8729088Smarkm
8829088SmarkmDRIVER_MODULE(openpic, nexus, openpic_ofw_driver, openpic_devclass, 0, 0);
8929088SmarkmDRIVER_MODULE(openpic, simplebus, openpic_ofw_driver, openpic_devclass, 0, 0);
9029088SmarkmDRIVER_MODULE(openpic, macio, openpic_ofw_driver, openpic_devclass, 0, 0);
9129088Smarkm
9229088Smarkmstatic int
9329088Smarkmopenpic_ofw_probe(device_t dev)
9429088Smarkm{
9529088Smarkm	const char *type = ofw_bus_get_type(dev);
9629088Smarkm
9729088Smarkm	if (type == NULL)
9829088Smarkm                return (ENXIO);
9929088Smarkm
10029088Smarkm	if (!ofw_bus_is_compatible(dev, "chrp,open-pic") &&
10129088Smarkm	    strcmp(type, "open-pic") != 0)
10229088Smarkm                return (ENXIO);
10329088Smarkm
10429088Smarkm	/*
10529088Smarkm	 * On some U4 systems, there is a phantom MPIC in the mac-io cell.
10629088Smarkm	 * The uninorth driver will pick up the real PIC, so ignore it here.
10729088Smarkm	 */
10829088Smarkm	if (OF_finddevice("/u4") != (phandle_t)-1)
10929088Smarkm		return (ENXIO);
11029088Smarkm
11129088Smarkm	device_set_desc(dev, OPENPIC_DEVSTR);
11229088Smarkm	return (0);
11329088Smarkm}
11429088Smarkm
11529088Smarkmstatic int
11629088Smarkmopenpic_ofw_attach(device_t dev)
11729088Smarkm{
11829088Smarkm	phandle_t xref, node;
11929088Smarkm
12029088Smarkm	node = ofw_bus_get_node(dev);
12129088Smarkm
12229088Smarkm	if (OF_getprop(node, "phandle", &xref, sizeof(xref)) == -1 &&
12329088Smarkm	    OF_getprop(node, "ibm,phandle", &xref, sizeof(xref)) == -1 &&
12429088Smarkm	    OF_getprop(node, "linux,phandle", &xref, sizeof(xref)) == -1)
12529088Smarkm		xref = node;
12629088Smarkm
12729088Smarkm	return (openpic_common_attach(dev, xref));
12829088Smarkm}
12929088Smarkm
13029088Smarkm