xref: /openbsd/sys/arch/powerpc64/include/intr.h (revision 4bdff4be)
1 /*	$OpenBSD: intr.h,v 1.14 2021/05/30 15:06:53 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 #include <sys/queue.h>
23 
24 struct cpu_info;
25 struct trapframe;
26 
27 #define IPL_NONE	0
28 #define IPL_SOFT	1
29 #define IPL_SOFTCLOCK	2
30 #define IPL_SOFTNET	3
31 #define IPL_SOFTTTY	4
32 #define IPL_BIO		5
33 #define IPL_NET		6
34 #define IPL_TTY		7
35 #define IPL_VM		IPL_TTY
36 #define IPL_AUDIO	8
37 #define IPL_CLOCK	9
38 #define IPL_STATCLOCK	IPL_CLOCK
39 #define IPL_SCHED	IPL_CLOCK
40 #define IPL_HIGH	IPL_CLOCK
41 #define IPL_IPI		10
42 #define NIPL		11
43 
44 #define	IPL_MPFLOOR	IPL_TTY
45 /* Interrupt priority 'flags'. */
46 #define	IPL_IRQMASK	0xf	/* priority only */
47 #define	IPL_FLAGMASK	0xf00	/* flags only*/
48 #define	IPL_MPSAFE	0x100	/* 'mpsafe' interrupt, no kernel lock */
49 
50 int	splraise(int);
51 int	spllower(int);
52 void	splx(int);
53 
54 #define spl0()		spllower(IPL_NONE)
55 #define splsoftclock()	splraise(IPL_SOFTCLOCK)
56 #define splsoftnet()	splraise(IPL_SOFTNET)
57 #define splsofttty()	splraise(IPL_SOFTTTY)
58 #define splbio()	splraise(IPL_BIO)
59 #define splnet()	splraise(IPL_NET)
60 #define spltty()	splraise(IPL_TTY)
61 #define splvm()		splraise(IPL_VM)
62 #define splclock()	splraise(IPL_CLOCK)
63 #define splstatclock()	splraise(IPL_STATCLOCK)
64 #define splsched()	splraise(IPL_SCHED)
65 #define splhigh()	splraise(IPL_HIGH)
66 
67 #ifdef DIAGNOSTIC
68 /*
69  * Although this function is implemented in MI code, it must be in this MD
70  * header because we don't want this header to include MI includes.
71  */
72 void splassert_fail(int, int, const char *);
73 extern int splassert_ctl;
74 void splassert_check(int, const char *);
75 #define splassert(__wantipl) do {			\
76 	if (splassert_ctl > 0) {			\
77 		splassert_check(__wantipl, __func__);	\
78 	}						\
79 } while (0)
80 #define	splsoftassert(wantipl)	splassert(wantipl)
81 #else
82 #define	splassert(wantipl)	do { /* nothing */ } while (0)
83 #define	splsoftassert(wantipl)	do { /* nothing */ } while (0)
84 #endif
85 
86 void	intr_init(void);
87 
88 #define intr_barrier(x)
89 
90 #define IST_EDGE	0
91 #define IST_LEVEL	1
92 
93 void	*intr_establish(uint32_t, int, int, struct cpu_info *,
94 	    int (*)(void *), void *, const char *);
95 
96 #define IPI_NOP		0
97 #define IPI_DDB		(1 << 0)
98 #define IPI_SETPERF	(1 << 1)
99 
100 void	intr_send_ipi(struct cpu_info *, int);
101 
102 extern void (*_exi)(struct trapframe *);
103 extern void (*_hvi)(struct trapframe *);
104 extern void *(*_intr_establish)(uint32_t, int, int, struct cpu_info *,
105 	    int (*)(void *), void *, const char *);
106 extern void (*_intr_send_ipi)(void *);
107 extern void (*_setipl)(int);
108 
109 #include <machine/softintr.h>
110 
111 struct interrupt_controller {
112 	int	ic_node;
113 	void	*ic_cookie;
114 	void	*(*ic_establish)(void *, int *, int, struct cpu_info *,
115 		    int (*)(void *), void *, char *);
116 	void	(*ic_send_ipi)(void *);
117 
118 	LIST_ENTRY(interrupt_controller) ic_list;
119 	uint32_t ic_phandle;
120 	uint32_t ic_cells;
121 };
122 
123 void	interrupt_controller_register(struct interrupt_controller *);
124 
125 void	*fdt_intr_establish_idx_cpu(int, int, int, struct cpu_info *,
126 	    int (*)(void *), void *, char *);
127 void	*fdt_intr_establish_imap(int, int *, int, int, int (*)(void *),
128 	    void *, char *);
129 void	*fdt_intr_establish_imap_cpu(int, int *, int, int,
130 	    struct cpu_info *, int (*)(void *), void *, char *);
131 
132 #endif /* _MACHINE_INTR_H_ */
133