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/*
30124469Sgrehan * The psim iobus attachment for the OpenPIC interrupt controller.
31124469Sgrehan */
32124469Sgrehan
33124469Sgrehan#include <sys/cdefs.h>
34124469Sgrehan__FBSDID("$FreeBSD$");
35124469Sgrehan
36124469Sgrehan#include <sys/param.h>
37124469Sgrehan#include <sys/systm.h>
38131102Sgrehan#include <sys/module.h>
39124469Sgrehan#include <sys/bus.h>
40124469Sgrehan#include <sys/conf.h>
41124469Sgrehan#include <sys/kernel.h>
42124469Sgrehan
43124469Sgrehan#include <dev/ofw/openfirm.h>
44124469Sgrehan
45124469Sgrehan#include <machine/bus.h>
46124469Sgrehan#include <machine/intr_machdep.h>
47124469Sgrehan#include <machine/md_var.h>
48124469Sgrehan#include <machine/pio.h>
49124469Sgrehan#include <machine/resource.h>
50124469Sgrehan
51124469Sgrehan#include <vm/vm.h>
52124469Sgrehan#include <vm/pmap.h>
53124469Sgrehan
54124469Sgrehan#include <sys/rman.h>
55124469Sgrehan
56259676Sjhibbits#include <machine/openpicreg.h>
57124469Sgrehan#include <machine/openpicvar.h>
58124469Sgrehan#include <powerpc/psim/iobusvar.h>
59124469Sgrehan
60124469Sgrehan#include "pic_if.h"
61124469Sgrehan
62124469Sgrehan/*
63171805Smarcel * PSIM IOBus interface
64124469Sgrehan */
65124469Sgrehanstatic int	openpic_iobus_probe(device_t);
66218075Smarcelstatic int	openpic_iobus_attach(device_t);
67124469Sgrehan
68171805Smarcelstatic device_method_t  openpic_iobus_methods[] = {
69124469Sgrehan	/* Device interface */
70171805Smarcel	DEVMETHOD(device_probe,		openpic_iobus_probe),
71218075Smarcel	DEVMETHOD(device_attach,	openpic_iobus_attach),
72124469Sgrehan
73124469Sgrehan	/* PIC interface */
74176918Smarcel	DEVMETHOD(pic_config,		openpic_config),
75171805Smarcel	DEVMETHOD(pic_dispatch,		openpic_dispatch),
76171805Smarcel	DEVMETHOD(pic_enable,		openpic_enable),
77171805Smarcel	DEVMETHOD(pic_eoi,		openpic_eoi),
78176208Smarcel	DEVMETHOD(pic_ipi,		openpic_ipi),
79171805Smarcel	DEVMETHOD(pic_mask,		openpic_mask),
80171805Smarcel	DEVMETHOD(pic_unmask,		openpic_unmask),
81124469Sgrehan
82124469Sgrehan	{ 0, 0 }
83124469Sgrehan};
84124469Sgrehan
85171805Smarcelstatic driver_t openpic_iobus_driver = {
86124469Sgrehan	"openpic",
87124469Sgrehan	openpic_iobus_methods,
88171805Smarcel	sizeof(struct openpic_softc)
89124469Sgrehan};
90124469Sgrehan
91171805SmarcelDRIVER_MODULE(openpic, iobus, openpic_iobus_driver, openpic_devclass, 0, 0);
92124469Sgrehan
93124469Sgrehanstatic int
94124469Sgrehanopenpic_iobus_probe(device_t dev)
95124469Sgrehan{
96177884Smarcel	struct openpic_softc *sc;
97124469Sgrehan	char *name;
98124469Sgrehan
99124469Sgrehan	name = iobus_get_name(dev);
100124469Sgrehan	if (strcmp(name, "interrupt-controller") != 0)
101171805Smarcel		return (ENXIO);
102124469Sgrehan
103124469Sgrehan	/*
104124469Sgrehan	 * The description was already printed out in the nexus
105124469Sgrehan	 * probe, so don't do it again here
106124469Sgrehan	 */
107171805Smarcel	device_set_desc(dev, OPENPIC_DEVSTR);
108177884Smarcel
109177884Smarcel	sc = device_get_softc(dev);
110177884Smarcel	sc->sc_psim = 1;
111177884Smarcel
112124469Sgrehan	return (0);
113124469Sgrehan}
114218075Smarcel
115218075Smarcelstatic int
116218075Smarcelopenpic_iobus_attach(device_t dev)
117218075Smarcel{
118218075Smarcel
119218075Smarcel	return (openpic_common_attach(dev, 0));
120218075Smarcel}
121