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
56124469Sgrehan#include <machine/openpicvar.h>
57124469Sgrehan#include <powerpc/psim/iobusvar.h>
58124469Sgrehan
59124469Sgrehan#include "pic_if.h"
60124469Sgrehan
61124469Sgrehan/*
62171805Smarcel * PSIM IOBus interface
63124469Sgrehan */
64124469Sgrehanstatic int	openpic_iobus_probe(device_t);
65218075Smarcelstatic int	openpic_iobus_attach(device_t);
66124469Sgrehan
67171805Smarcelstatic device_method_t  openpic_iobus_methods[] = {
68124469Sgrehan	/* Device interface */
69171805Smarcel	DEVMETHOD(device_probe,		openpic_iobus_probe),
70218075Smarcel	DEVMETHOD(device_attach,	openpic_iobus_attach),
71124469Sgrehan
72124469Sgrehan	/* PIC interface */
73176918Smarcel	DEVMETHOD(pic_config,		openpic_config),
74171805Smarcel	DEVMETHOD(pic_dispatch,		openpic_dispatch),
75171805Smarcel	DEVMETHOD(pic_enable,		openpic_enable),
76171805Smarcel	DEVMETHOD(pic_eoi,		openpic_eoi),
77176208Smarcel	DEVMETHOD(pic_ipi,		openpic_ipi),
78171805Smarcel	DEVMETHOD(pic_mask,		openpic_mask),
79171805Smarcel	DEVMETHOD(pic_unmask,		openpic_unmask),
80124469Sgrehan
81124469Sgrehan	{ 0, 0 }
82124469Sgrehan};
83124469Sgrehan
84171805Smarcelstatic driver_t openpic_iobus_driver = {
85124469Sgrehan	"openpic",
86124469Sgrehan	openpic_iobus_methods,
87171805Smarcel	sizeof(struct openpic_softc)
88124469Sgrehan};
89124469Sgrehan
90171805SmarcelDRIVER_MODULE(openpic, iobus, openpic_iobus_driver, openpic_devclass, 0, 0);
91124469Sgrehan
92124469Sgrehanstatic int
93124469Sgrehanopenpic_iobus_probe(device_t dev)
94124469Sgrehan{
95177884Smarcel	struct openpic_softc *sc;
96124469Sgrehan	char *name;
97124469Sgrehan
98124469Sgrehan	name = iobus_get_name(dev);
99124469Sgrehan	if (strcmp(name, "interrupt-controller") != 0)
100171805Smarcel		return (ENXIO);
101124469Sgrehan
102124469Sgrehan	/*
103124469Sgrehan	 * The description was already printed out in the nexus
104124469Sgrehan	 * probe, so don't do it again here
105124469Sgrehan	 */
106171805Smarcel	device_set_desc(dev, OPENPIC_DEVSTR);
107177884Smarcel
108177884Smarcel	sc = device_get_softc(dev);
109177884Smarcel	sc->sc_psim = 1;
110177884Smarcel
111124469Sgrehan	return (0);
112124469Sgrehan}
113218075Smarcel
114218075Smarcelstatic int
115218075Smarcelopenpic_iobus_attach(device_t dev)
116218075Smarcel{
117218075Smarcel
118218075Smarcel	return (openpic_common_attach(dev, 0));
119218075Smarcel}
120