openpic_ofw.c revision 218075
1139825Simp/*-
2124469Sgrehan * Copyright 2003 by Peter Grehan. All rights reserved.
3124469Sgrehan *
4124469Sgrehan * Redistribution and use in source and binary forms, with or without
5124469Sgrehan * modification, are permitted provided that the following conditions
6124469Sgrehan * are met:
7124469Sgrehan * 1. Redistributions of source code must retain the above copyright
8124469Sgrehan *    notice, this list of conditions and the following disclaimer.
9124469Sgrehan * 2. Redistributions in binary form must reproduce the above copyright
10124469Sgrehan *    notice, this list of conditions and the following disclaimer in the
11124469Sgrehan *    documentation and/or other materials provided with the distribution.
12124469Sgrehan * 3. The name of the author may not be used to endorse or promote products
13124469Sgrehan *    derived from this software without specific prior written permission.
14124469Sgrehan *
15124469Sgrehan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16124469Sgrehan * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17124469Sgrehan * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18124469Sgrehan * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19124469Sgrehan * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20124469Sgrehan * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21124469Sgrehan * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
22124469Sgrehan * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23124469Sgrehan * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24124469Sgrehan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25124469Sgrehan * SUCH DAMAGE.
26124469Sgrehan *
27124469Sgrehan */
28124469Sgrehan
29124469Sgrehan#include <sys/cdefs.h>
30124469Sgrehan__FBSDID("$FreeBSD: head/sys/powerpc/powermac/openpic_macio.c 218075 2011-01-29 20:58:38Z marcel $");
31124469Sgrehan
32124469Sgrehan#include <sys/param.h>
33124469Sgrehan#include <sys/systm.h>
34131102Sgrehan#include <sys/module.h>
35124469Sgrehan#include <sys/bus.h>
36124469Sgrehan#include <sys/conf.h>
37124469Sgrehan#include <sys/kernel.h>
38124469Sgrehan
39133589Smarius#include <dev/ofw/ofw_bus.h>
40124469Sgrehan#include <dev/ofw/openfirm.h>
41124469Sgrehan
42124469Sgrehan#include <machine/bus.h>
43124469Sgrehan#include <machine/intr_machdep.h>
44124469Sgrehan#include <machine/md_var.h>
45124469Sgrehan#include <machine/pio.h>
46124469Sgrehan#include <machine/resource.h>
47124469Sgrehan
48124469Sgrehan#include <vm/vm.h>
49124469Sgrehan#include <vm/pmap.h>
50124469Sgrehan
51124469Sgrehan#include <sys/rman.h>
52124469Sgrehan
53124469Sgrehan#include <machine/openpicvar.h>
54124469Sgrehan
55124469Sgrehan#include "pic_if.h"
56124469Sgrehan
57124469Sgrehan/*
58124469Sgrehan * MacIO interface
59124469Sgrehan */
60124469Sgrehanstatic int	openpic_macio_probe(device_t);
61218075Smarcelstatic int	openpic_macio_attach(device_t);
62124469Sgrehan
63171805Smarcelstatic device_method_t  openpic_macio_methods[] = {
64124469Sgrehan	/* Device interface */
65171805Smarcel	DEVMETHOD(device_probe,		openpic_macio_probe),
66218075Smarcel	DEVMETHOD(device_attach,	openpic_macio_attach),
67124469Sgrehan
68124469Sgrehan	/* PIC interface */
69209486Snwhitehorn	DEVMETHOD(pic_bind,		openpic_bind),
70176918Smarcel	DEVMETHOD(pic_config,		openpic_config),
71171805Smarcel	DEVMETHOD(pic_dispatch,		openpic_dispatch),
72171805Smarcel	DEVMETHOD(pic_enable,		openpic_enable),
73171805Smarcel	DEVMETHOD(pic_eoi,		openpic_eoi),
74176208Smarcel	DEVMETHOD(pic_ipi,		openpic_ipi),
75171805Smarcel	DEVMETHOD(pic_mask,		openpic_mask),
76171805Smarcel	DEVMETHOD(pic_unmask,		openpic_unmask),
77124469Sgrehan
78124469Sgrehan	{ 0, 0 },
79124469Sgrehan};
80124469Sgrehan
81124469Sgrehanstatic driver_t openpic_macio_driver = {
82171805Smarcel	"openpic",
83124469Sgrehan	openpic_macio_methods,
84171805Smarcel	sizeof(struct openpic_softc),
85124469Sgrehan};
86124469Sgrehan
87171805SmarcelDRIVER_MODULE(openpic, macio, openpic_macio_driver, openpic_devclass, 0, 0);
88124469Sgrehan
89124469Sgrehanstatic int
90124469Sgrehanopenpic_macio_probe(device_t dev)
91124469Sgrehan{
92133589Smarius	const char *type = ofw_bus_get_type(dev);
93124469Sgrehan
94124469Sgrehan	if (strcmp(type, "open-pic") != 0)
95124469Sgrehan                return (ENXIO);
96124469Sgrehan
97171805Smarcel	device_set_desc(dev, OPENPIC_DEVSTR);
98124469Sgrehan	return (0);
99124469Sgrehan}
100209298Snwhitehorn
101218075Smarcelstatic int
102218075Smarcelopenpic_macio_attach(device_t dev)
103209298Snwhitehorn{
104218075Smarcel
105218075Smarcel	return (openpic_common_attach(dev, ofw_bus_get_node(dev)));
106209298Snwhitehorn}
107