1 /* $NetBSD: vchiq_kmod_netbsd.c,v 1.14 2024/11/07 09:51:00 rin Exp $ */
2
3 /*-
4 * Copyright (c) 2013 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jared D. McNeill
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: vchiq_kmod_netbsd.c,v 1.14 2024/11/07 09:51:00 rin Exp $");
34
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/device.h>
38 #include <sys/kernel.h>
39 #include <sys/bus.h>
40 #include <sys/sysctl.h>
41
42 #include <arm/broadcom/bcm2835reg.h>
43 #include <arm/broadcom/bcm2835_intr.h>
44
45 #include "vchiq_arm.h"
46 #include "vchiq_2835.h"
47 #include "vchiq_netbsd.h"
48
49 extern VCHIQ_STATE_T g_state;
50
51 static struct vchiq_softc *vchiq_softc = NULL;
52
53 #define VCHIQ_DOORBELL0 0x0
54 #define VCHIQ_DOORBELL1 0x4
55 #define VCHIQ_DOORBELL2 0x8
56 #define VCHIQ_DOORBELL3 0xC
57
58 void
vchiq_set_softc(struct vchiq_softc * sc)59 vchiq_set_softc(struct vchiq_softc *sc)
60 {
61 vchiq_softc = sc;
62 }
63
64 int
vchiq_intr(void * priv)65 vchiq_intr(void *priv)
66 {
67 struct vchiq_softc *sc = priv;
68 uint32_t status;
69
70 bus_space_barrier(sc->sc_iot, sc->sc_ioh,
71 VCHIQ_DOORBELL0, 4, BUS_SPACE_BARRIER_READ);
72
73 rmb();
74 status = bus_space_read_4(sc->sc_iot, sc->sc_ioh, VCHIQ_DOORBELL0);
75 if (status & 0x4) {
76 remote_event_pollall(&g_state);
77 return 1;
78 }
79
80 return 0;
81 }
82
83 int
vchiq_print(void * aux,const char * pnp)84 vchiq_print(void *aux, const char *pnp)
85 {
86 struct vchiq_attach_args *vaa = aux;
87
88 if (pnp)
89 aprint_normal("%s at %s", vaa->vaa_name, pnp);
90
91 return UNCONF;
92 }
93
94 void
remote_event_signal(REMOTE_EVENT_T * event)95 remote_event_signal(REMOTE_EVENT_T *event)
96 {
97 wmb();
98
99 event->fired = 1;
100
101 dsb(sy); /* data barrier operation */
102
103 if (event->armed) {
104 bus_space_write_4(vchiq_softc->sc_iot, vchiq_softc->sc_ioh,
105 VCHIQ_DOORBELL2, 0);
106 bus_space_barrier(vchiq_softc->sc_iot, vchiq_softc->sc_ioh,
107 VCHIQ_DOORBELL2, 4, BUS_SPACE_BARRIER_WRITE);
108 }
109 }
110
111 SYSCTL_SETUP(sysctl_hw_vchiq_setup, "sysctl hw.vchiq setup")
112 {
113 const struct sysctlnode *rnode = NULL;
114 const struct sysctlnode *cnode = NULL;
115
116 sysctl_createv(clog, 0, NULL, &rnode,
117 CTLFLAG_PERMANENT, CTLTYPE_NODE, "vchiq",
118 NULL, NULL, 0,
119 NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL);
120
121 sysctl_createv(clog, 0, &rnode, &cnode,
122 CTLFLAG_PERMANENT, CTLTYPE_NODE, "loglevel",
123 NULL, NULL, 0,
124 NULL, 0, CTL_CREATE, CTL_EOL);
125
126 sysctl_createv(clog, 0, &cnode, NULL,
127 CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT, "core",
128 SYSCTL_DESCR("VChiq Core Loglevel"), NULL, 0,
129 &vchiq_core_log_level, 0, CTL_CREATE, CTL_EOL);
130
131 sysctl_createv(clog, 0, &cnode, NULL,
132 CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT, "coremsg",
133 SYSCTL_DESCR("VChiq Core Message Loglevel"), NULL, 0,
134 &vchiq_core_msg_log_level, 0, CTL_CREATE, CTL_EOL);
135
136 sysctl_createv(clog, 0, &cnode, NULL,
137 CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT, "sync",
138 SYSCTL_DESCR("VChiq Sync Loglevel"), NULL, 0,
139 &vchiq_sync_log_level, 0, CTL_CREATE, CTL_EOL);
140 }
141