1/* $OpenBSD: intr.h,v 1.16 2025/04/26 11:10:28 visa Exp $ */
2
3/*
4 * Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19#ifndef _MACHINE_INTR_H_
20#define _MACHINE_INTR_H_
21
22#define __USE_MI_SOFTINTR
23
24#include <sys/queue.h>
25#include <sys/softintr.h>
26
27struct cpu_info;
28struct trapframe;
29
30#define IPL_NONE 0
31#define IPL_SOFTCLOCK 2
32#define IPL_SOFTNET 3
33#define IPL_SOFTTTY 4
34#define IPL_BIO 5
35#define IPL_NET 6
36#define IPL_TTY 7
37#define IPL_VM IPL_TTY
38#define IPL_AUDIO 8
39#define IPL_CLOCK 9
40#define IPL_STATCLOCK IPL_CLOCK
41#define IPL_SCHED IPL_CLOCK
42#define IPL_HIGH IPL_CLOCK
43#define IPL_IPI 10
44#define NIPL 11
45
46#define IPL_MPFLOOR IPL_TTY
47/* Interrupt priority 'flags'. */
48#define IPL_IRQMASK 0xf /* priority only */
49#define IPL_FLAGMASK 0xf00 /* flags only*/
50#define IPL_MPSAFE 0x100 /* 'mpsafe' interrupt, no kernel lock */
51
52int splraise(int);
53int spllower(int);
54void splx(int);
55
56void softintr(int);
57
58#define spl0() spllower(IPL_NONE)
59#define splsoftclock() splraise(IPL_SOFTCLOCK)
60#define splsoftnet() splraise(IPL_SOFTNET)
61#define splsofttty() splraise(IPL_SOFTTTY)
62#define splbio() splraise(IPL_BIO)
63#define splnet() splraise(IPL_NET)
64#define spltty() splraise(IPL_TTY)
65#define splvm() splraise(IPL_VM)
66#define splclock() splraise(IPL_CLOCK)
67#define splstatclock() splraise(IPL_STATCLOCK)
68#define splsched() splraise(IPL_SCHED)
69#define splhigh() splraise(IPL_HIGH)
70
71#ifdef DIAGNOSTIC
72/*
73 * Although this function is implemented in MI code, it must be in this MD
74 * header because we don't want this header to include MI includes.
75 */
76void splassert_fail(int, int, const char *);
77extern int splassert_ctl;
78void splassert_check(int, const char *);
79#define splassert(__wantipl) do { \
80 if (splassert_ctl > 0) { \
81 splassert_check(__wantipl, __func__); \
82 } \
83} while (0)
84#define splsoftassert(wantipl) splassert(wantipl)
85#else
86#define splassert(wantipl) do { /* nothing */ } while (0)
87#define splsoftassert(wantipl) do { /* nothing */ } while (0)
88#endif
89
90void intr_init(void);
91
92#define intr_barrier(x)
93
94#define IST_EDGE 0
95#define IST_LEVEL 1
96
97void *intr_establish(uint32_t, int, int, struct cpu_info *,
98 int (*)(void *), void *, const char *);
99
100#define IPI_NOP 0
101#define IPI_DDB (1 << 0)
102#define IPI_SETPERF (1 << 1)
103
104void intr_send_ipi(struct cpu_info *, int);
105
106extern void (*_exi)(struct trapframe *);
107extern void (*_hvi)(struct trapframe *);
108extern void *(*_intr_establish)(uint32_t, int, int, struct cpu_info *,
109 int (*)(void *), void *, const char *);
110extern void (*_intr_send_ipi)(void *);
111extern void (*_setipl)(int);
112
113struct interrupt_controller {
114 int ic_node;
115 void *ic_cookie;
116 void *(*ic_establish)(void *, int *, int, struct cpu_info *,
117 int (*)(void *), void *, char *);
118 void (*ic_send_ipi)(void *);
119
120 LIST_ENTRY(interrupt_controller) ic_list;
121 uint32_t ic_phandle;
122 uint32_t ic_cells;
123};
124
125void interrupt_controller_register(struct interrupt_controller *);
126
127void *fdt_intr_establish_idx_cpu(int, int, int, struct cpu_info *,
128 int (*)(void *), void *, char *);
129void *fdt_intr_establish_imap(int, int *, int, int, int (*)(void *),
130 void *, char *);
131void *fdt_intr_establish_imap_cpu(int, int *, int, int,
132 struct cpu_info *, int (*)(void *), void *, char *);
133void fdt_intr_disestablish(void *);
134
135#endif /* _MACHINE_INTR_H_ */