summaryrefslogtreecommitdiffstats
path: root/sys/arch/powerpc64/dev/xics.c
blob: 9483b6661375a084eff0850de202aac6664e7d42 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*	$OpenBSD: xics.c,v 1.3 2020/09/21 11:14:28 kettenis Exp $	*/
/*
 * Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/evcount.h>
#include <sys/malloc.h>
#include <sys/queue.h>

#include <machine/bus.h>
#include <machine/fdt.h>
#include <machine/opal.h>

#include <dev/ofw/openfirm.h>
#include <dev/ofw/fdt.h>

struct xics_softc {
	struct device		sc_dev;

	struct interrupt_controller sc_ic;
};

int	xics_match(struct device *, void *, void *);
void	xics_attach(struct device *, struct device *, void *);

struct cfattach	xics_ca = {
	sizeof (struct xics_softc), xics_match, xics_attach
};

struct cfdriver xics_cd = {
	NULL, "xics", DV_DULL
};

void	*xics_intr_establish(void *, int *, int,
	    struct cpu_info *, int (*)(void *), void *, char *);
void	xics_intr_send_ipi(void *);

int
xics_match(struct device *parent, void *match, void *aux)
{
	struct fdt_attach_args *faa = aux;

	return OF_is_compatible(faa->fa_node, "ibm,opal-xive-vc");
}

void
xics_attach(struct device *parent, struct device *self, void *aux)
{
	struct xics_softc *sc = (struct xics_softc *)self;
	struct fdt_attach_args *faa = aux;

	printf("\n");

	sc->sc_ic.ic_node = faa->fa_node;
	sc->sc_ic.ic_cookie = self;
	sc->sc_ic.ic_establish = xics_intr_establish;
	sc->sc_ic.ic_send_ipi = xics_intr_send_ipi;
	interrupt_controller_register(&sc->sc_ic);
}

void *
xics_intr_establish(void *cookie, int *cell, int level,
    struct cpu_info *ci, int (*func)(void *), void *arg, char *name)
{
	uint32_t girq = cell[0];
	int type = cell[1];

	return _intr_establish(girq, type, level, ci, func, arg, name);
}

void
xics_intr_send_ipi(void *cookie)
{
	return _intr_send_ipi(cookie);
}