xref: /openbsd/sys/arch/powerpc64/dev/xics.c (revision 3bef86f7)
1 /*	$OpenBSD: xics.c,v 1.4 2022/04/06 18:59:27 naddy Exp $	*/
2 /*
3  * Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #include <sys/param.h>
19 #include <sys/systm.h>
20 #include <sys/device.h>
21 #include <sys/evcount.h>
22 #include <sys/malloc.h>
23 #include <sys/queue.h>
24 
25 #include <machine/bus.h>
26 #include <machine/fdt.h>
27 #include <machine/opal.h>
28 
29 #include <dev/ofw/openfirm.h>
30 #include <dev/ofw/fdt.h>
31 
32 struct xics_softc {
33 	struct device		sc_dev;
34 
35 	struct interrupt_controller sc_ic;
36 };
37 
38 int	xics_match(struct device *, void *, void *);
39 void	xics_attach(struct device *, struct device *, void *);
40 
41 const struct cfattach xics_ca = {
42 	sizeof (struct xics_softc), xics_match, xics_attach
43 };
44 
45 struct cfdriver xics_cd = {
46 	NULL, "xics", DV_DULL
47 };
48 
49 void	*xics_intr_establish(void *, int *, int,
50 	    struct cpu_info *, int (*)(void *), void *, char *);
51 void	xics_intr_send_ipi(void *);
52 
53 int
54 xics_match(struct device *parent, void *match, void *aux)
55 {
56 	struct fdt_attach_args *faa = aux;
57 
58 	return OF_is_compatible(faa->fa_node, "ibm,opal-xive-vc");
59 }
60 
61 void
62 xics_attach(struct device *parent, struct device *self, void *aux)
63 {
64 	struct xics_softc *sc = (struct xics_softc *)self;
65 	struct fdt_attach_args *faa = aux;
66 
67 	printf("\n");
68 
69 	sc->sc_ic.ic_node = faa->fa_node;
70 	sc->sc_ic.ic_cookie = self;
71 	sc->sc_ic.ic_establish = xics_intr_establish;
72 	sc->sc_ic.ic_send_ipi = xics_intr_send_ipi;
73 	interrupt_controller_register(&sc->sc_ic);
74 }
75 
76 void *
77 xics_intr_establish(void *cookie, int *cell, int level,
78     struct cpu_info *ci, int (*func)(void *), void *arg, char *name)
79 {
80 	uint32_t girq = cell[0];
81 	int type = cell[1];
82 
83 	return _intr_establish(girq, type, level, ci, func, arg, name);
84 }
85 
86 void
87 xics_intr_send_ipi(void *cookie)
88 {
89 	return _intr_send_ipi(cookie);
90 }
91