xref: /freebsd-src/sys/powerpc/psim/openpic_iobus.c (revision fdafd315ad0d0f28a11b9fb4476a9ab059c62b92)
160727d8bSWarner Losh /*-
271e3c308SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
371e3c308SPedro F. Giffuni  *
4739af9bcSPeter Grehan  * Copyright 2003 by Peter Grehan. All rights reserved.
5739af9bcSPeter Grehan  *
6739af9bcSPeter Grehan  * Redistribution and use in source and binary forms, with or without
7739af9bcSPeter Grehan  * modification, are permitted provided that the following conditions
8739af9bcSPeter Grehan  * are met:
9739af9bcSPeter Grehan  * 1. Redistributions of source code must retain the above copyright
10739af9bcSPeter Grehan  *    notice, this list of conditions and the following disclaimer.
11739af9bcSPeter Grehan  * 2. Redistributions in binary form must reproduce the above copyright
12739af9bcSPeter Grehan  *    notice, this list of conditions and the following disclaimer in the
13739af9bcSPeter Grehan  *    documentation and/or other materials provided with the distribution.
14739af9bcSPeter Grehan  * 3. The name of the author may not be used to endorse or promote products
15739af9bcSPeter Grehan  *    derived from this software without specific prior written permission.
16739af9bcSPeter Grehan  *
17739af9bcSPeter Grehan  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18739af9bcSPeter Grehan  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19739af9bcSPeter Grehan  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20739af9bcSPeter Grehan  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21739af9bcSPeter Grehan  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22739af9bcSPeter Grehan  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23739af9bcSPeter Grehan  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24739af9bcSPeter Grehan  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25739af9bcSPeter Grehan  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26739af9bcSPeter Grehan  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27739af9bcSPeter Grehan  * SUCH DAMAGE.
28739af9bcSPeter Grehan  *
29739af9bcSPeter Grehan  */
30739af9bcSPeter Grehan 
31739af9bcSPeter Grehan /*
32739af9bcSPeter Grehan  * The psim iobus attachment for the OpenPIC interrupt controller.
33739af9bcSPeter Grehan  */
34739af9bcSPeter Grehan 
35739af9bcSPeter Grehan #include <sys/param.h>
36739af9bcSPeter Grehan #include <sys/systm.h>
3740cdee9dSPeter Grehan #include <sys/module.h>
38739af9bcSPeter Grehan #include <sys/bus.h>
39739af9bcSPeter Grehan #include <sys/conf.h>
40739af9bcSPeter Grehan #include <sys/kernel.h>
41739af9bcSPeter Grehan 
42739af9bcSPeter Grehan #include <dev/ofw/openfirm.h>
43739af9bcSPeter Grehan 
44739af9bcSPeter Grehan #include <machine/bus.h>
45739af9bcSPeter Grehan #include <machine/intr_machdep.h>
46739af9bcSPeter Grehan #include <machine/md_var.h>
47739af9bcSPeter Grehan #include <machine/pio.h>
48739af9bcSPeter Grehan #include <machine/resource.h>
49739af9bcSPeter Grehan 
50739af9bcSPeter Grehan #include <vm/vm.h>
51739af9bcSPeter Grehan #include <vm/pmap.h>
52739af9bcSPeter Grehan 
53739af9bcSPeter Grehan #include <sys/rman.h>
54739af9bcSPeter Grehan 
559a2edf01SJustin Hibbits #include <machine/openpicreg.h>
56739af9bcSPeter Grehan #include <machine/openpicvar.h>
57739af9bcSPeter Grehan #include <powerpc/psim/iobusvar.h>
58739af9bcSPeter Grehan 
59739af9bcSPeter Grehan #include "pic_if.h"
60739af9bcSPeter Grehan 
61739af9bcSPeter Grehan /*
6277d40ffdSMarcel Moolenaar  * PSIM IOBus interface
63739af9bcSPeter Grehan  */
64739af9bcSPeter Grehan static int	openpic_iobus_probe(device_t);
656d2d7b8cSMarcel Moolenaar static int	openpic_iobus_attach(device_t);
66739af9bcSPeter Grehan 
6777d40ffdSMarcel Moolenaar static device_method_t  openpic_iobus_methods[] = {
68739af9bcSPeter Grehan 	/* Device interface */
6977d40ffdSMarcel Moolenaar 	DEVMETHOD(device_probe,		openpic_iobus_probe),
706d2d7b8cSMarcel Moolenaar 	DEVMETHOD(device_attach,	openpic_iobus_attach),
71739af9bcSPeter Grehan 
72739af9bcSPeter Grehan 	/* PIC interface */
73d6f59297SMarcel Moolenaar 	DEVMETHOD(pic_config,		openpic_config),
7477d40ffdSMarcel Moolenaar 	DEVMETHOD(pic_dispatch,		openpic_dispatch),
7577d40ffdSMarcel Moolenaar 	DEVMETHOD(pic_enable,		openpic_enable),
7677d40ffdSMarcel Moolenaar 	DEVMETHOD(pic_eoi,		openpic_eoi),
7705c62b81SMarcel Moolenaar 	DEVMETHOD(pic_ipi,		openpic_ipi),
7877d40ffdSMarcel Moolenaar 	DEVMETHOD(pic_mask,		openpic_mask),
7977d40ffdSMarcel Moolenaar 	DEVMETHOD(pic_unmask,		openpic_unmask),
80739af9bcSPeter Grehan 	{ 0, 0 }
81739af9bcSPeter Grehan };
82739af9bcSPeter Grehan 
83739af9bcSPeter Grehan static driver_t openpic_iobus_driver = {
8477d40ffdSMarcel Moolenaar 	"openpic",
85739af9bcSPeter Grehan 	openpic_iobus_methods,
8677d40ffdSMarcel Moolenaar 	sizeof(struct openpic_softc)
87739af9bcSPeter Grehan };
88739af9bcSPeter Grehan 
89*52ed569bSJohn Baldwin DRIVER_MODULE(openpic, iobus, openpic_iobus_driver, 0, 0);
90739af9bcSPeter Grehan 
91739af9bcSPeter Grehan static int
openpic_iobus_probe(device_t dev)92739af9bcSPeter Grehan openpic_iobus_probe(device_t dev)
93739af9bcSPeter Grehan {
9466821a4cSMarcel Moolenaar 	struct openpic_softc *sc;
95739af9bcSPeter Grehan 	char *name;
96739af9bcSPeter Grehan 
97739af9bcSPeter Grehan 	name = iobus_get_name(dev);
98739af9bcSPeter Grehan 	if (strcmp(name, "interrupt-controller") != 0)
99739af9bcSPeter Grehan 		return (ENXIO);
100739af9bcSPeter Grehan 
101739af9bcSPeter Grehan 	/*
102739af9bcSPeter Grehan 	 * The description was already printed out in the nexus
103739af9bcSPeter Grehan 	 * probe, so don't do it again here
104739af9bcSPeter Grehan 	 */
10577d40ffdSMarcel Moolenaar 	device_set_desc(dev, OPENPIC_DEVSTR);
10666821a4cSMarcel Moolenaar 
10766821a4cSMarcel Moolenaar 	sc = device_get_softc(dev);
10866821a4cSMarcel Moolenaar 	sc->sc_psim = 1;
10966821a4cSMarcel Moolenaar 
110739af9bcSPeter Grehan 	return (0);
111739af9bcSPeter Grehan }
1126d2d7b8cSMarcel Moolenaar 
1136d2d7b8cSMarcel Moolenaar static int
openpic_iobus_attach(device_t dev)1146d2d7b8cSMarcel Moolenaar openpic_iobus_attach(device_t dev)
1156d2d7b8cSMarcel Moolenaar {
1166d2d7b8cSMarcel Moolenaar 
1176d2d7b8cSMarcel Moolenaar 	return (openpic_common_attach(dev, 0));
1186d2d7b8cSMarcel Moolenaar }
119