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