xref: /netbsd-src/sys/arch/virt68k/dev/gfpic_mainbus.c (revision f83db12ca6a74a01c1e9efb1a777cfaa84098ec6)
1*f83db12cSthorpej /*	$NetBSD: gfpic_mainbus.c,v 1.1 2024/01/02 07:40:59 thorpej Exp $	*/
2*f83db12cSthorpej 
3*f83db12cSthorpej /*-
4*f83db12cSthorpej  * Copyright (c) 2023 The NetBSD Foundation, Inc.
5*f83db12cSthorpej  * All rights reserved.
6*f83db12cSthorpej  *
7*f83db12cSthorpej  * This code is derived from software contributed to The NetBSD Foundation
8*f83db12cSthorpej  * by Jason R. Thorpe.
9*f83db12cSthorpej  *
10*f83db12cSthorpej  * Redistribution and use in source and binary forms, with or without
11*f83db12cSthorpej  * modification, are permitted provided that the following conditions
12*f83db12cSthorpej  * are met:
13*f83db12cSthorpej  * 1. Redistributions of source code must retain the above copyright
14*f83db12cSthorpej  *    notice, this list of conditions and the following disclaimer.
15*f83db12cSthorpej  * 2. Redistributions in binary form must reproduce the above copyright
16*f83db12cSthorpej  *    notice, this list of conditions and the following disclaimer in the
17*f83db12cSthorpej  *    documentation and/or other materials provided with the distribution.
18*f83db12cSthorpej  *
19*f83db12cSthorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*f83db12cSthorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*f83db12cSthorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*f83db12cSthorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*f83db12cSthorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*f83db12cSthorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*f83db12cSthorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*f83db12cSthorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*f83db12cSthorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*f83db12cSthorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*f83db12cSthorpej  * POSSIBILITY OF SUCH DAMAGE.
30*f83db12cSthorpej  */
31*f83db12cSthorpej 
32*f83db12cSthorpej #include <sys/cdefs.h>
33*f83db12cSthorpej __KERNEL_RCSID(0, "$NetBSD: gfpic_mainbus.c,v 1.1 2024/01/02 07:40:59 thorpej Exp $");
34*f83db12cSthorpej 
35*f83db12cSthorpej #include <sys/types.h>
36*f83db12cSthorpej #include <sys/bus.h>
37*f83db12cSthorpej #include <sys/device.h>
38*f83db12cSthorpej #include <sys/intr.h>
39*f83db12cSthorpej #include <sys/systm.h>
40*f83db12cSthorpej 
41*f83db12cSthorpej #include <virt68k/dev/mainbusvar.h>
42*f83db12cSthorpej 
43*f83db12cSthorpej #include <dev/goldfish/gfpicvar.h>
44*f83db12cSthorpej 
45*f83db12cSthorpej static const struct device_compatible_entry compat_data[] = {
46*f83db12cSthorpej 	{ .compat = "google,goldfish-pic" },
47*f83db12cSthorpej 	DEVICE_COMPAT_EOL
48*f83db12cSthorpej };
49*f83db12cSthorpej 
50*f83db12cSthorpej static int
gfpic_mainbus_match(device_t parent,cfdata_t cf,void * aux)51*f83db12cSthorpej gfpic_mainbus_match(device_t parent, cfdata_t cf, void *aux)
52*f83db12cSthorpej {
53*f83db12cSthorpej 	struct mainbus_attach_args * const ma = aux;
54*f83db12cSthorpej 
55*f83db12cSthorpej 	return mainbus_compatible_match(ma, compat_data);
56*f83db12cSthorpej }
57*f83db12cSthorpej 
58*f83db12cSthorpej static void
gfpic_mainbus_attach(device_t parent,device_t self,void * aux)59*f83db12cSthorpej gfpic_mainbus_attach(device_t parent, device_t self, void *aux)
60*f83db12cSthorpej {
61*f83db12cSthorpej 	struct gfpic_softc * const sc = device_private(self);
62*f83db12cSthorpej 	struct mainbus_attach_args * const ma = aux;
63*f83db12cSthorpej 
64*f83db12cSthorpej 	sc->sc_dev = self;
65*f83db12cSthorpej 	sc->sc_bst = ma->ma_st;
66*f83db12cSthorpej 	if (bus_space_map(sc->sc_bst, ma->ma_addr, ma->ma_size, 0,
67*f83db12cSthorpej 			  &sc->sc_bsh) != 0) {
68*f83db12cSthorpej 		aprint_error(": couldn't map registers\n");
69*f83db12cSthorpej 		return;
70*f83db12cSthorpej 	}
71*f83db12cSthorpej 
72*f83db12cSthorpej 	gfpic_attach(sc);
73*f83db12cSthorpej 
74*f83db12cSthorpej 	aprint_normal_dev(self, "interrupting at IPL %d\n", ma->ma_irq);
75*f83db12cSthorpej 	intr_register_pic(self, ma->ma_irq);
76*f83db12cSthorpej }
77*f83db12cSthorpej 
78*f83db12cSthorpej CFATTACH_DECL_NEW(gfpic_mainbus, sizeof(struct gfpic_softc),
79*f83db12cSthorpej 	gfpic_mainbus_match, gfpic_mainbus_attach, NULL, NULL);
80