xref: /netbsd-src/sys/arch/arm/pic/picvar.h (revision a24ea6034e91a5a146b0069477432726f471d594)
1 /*	$NetBSD: picvar.h,v 1.38 2022/06/25 13:24:35 jmcneill Exp $	*/
2 /*-
3  * Copyright (c) 2008 The NetBSD Foundation, Inc.
4  * All rights reserved.
5  *
6  * This code is derived from software contributed to The NetBSD Foundation
7  * by Matt Thomas.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
30 #ifndef _ARM_PIC_PICVAR_H_
31 #define _ARM_PIC_PICVAR_H_
32 
33 #ifdef _KERNEL_OPT
34 #include "opt_multiprocessor.h"
35 #endif
36 
37 #ifdef MULTIPROCESSOR
38 #include <sys/kcpuset.h>
39 #endif
40 
41 typedef uint32_t	intr_handle_t;		/* for ACPI */
42 
43 int	_splraise(int);
44 int	_spllower(int);
45 void	splx(int);
46 
47 const char *
48 	intr_typename(int);
49 
50 struct pic_softc;
51 struct intrsource;
52 struct cpu_info;
53 
54 #define	IPI_AST			0	/* just get an interrupt */
55 #define	IPI_XCALL		1	/* xcall */
56 #define	IPI_NOP			2	/* just get an interrupt (armv6) */
57 #define	IPI_SHOOTDOWN		3	/* cause a tlb shootdown */
58 #define	IPI_DDB			4	/* enter DDB */
59 #define	IPI_GENERIC		5	/* generic IPI */
60 #ifdef __HAVE_PREEMPTION
61 #define	IPI_KPREEMPT		6	/* cause a preemption */
62 #define	NIPI			7
63 #else
64 #define	NIPI			6
65 #endif
66 
67 #if !defined(__HAVE_PIC_SET_PRIORITY)
68 #define __HAVE_PIC_PENDING_INTRS
69 #endif
70 
71 int	pic_handle_intr(void *);
72 #if defined(__HAVE_PIC_PENDING_INTRS)
73 void	pic_mark_pending(struct pic_softc *pic, int irq);
74 void	pic_mark_pending_source(struct pic_softc *pic, struct intrsource *is);
75 uint32_t pic_mark_pending_sources(struct pic_softc *pic, size_t irq_base,
76 	    uint32_t pending);
77 #endif /* __HAVE_PIC_PENDING_INTRS */
78 void	*pic_establish_intr(struct pic_softc *pic, int irq, int ipl, int type,
79 	    int (*func)(void *), void *arg, const char *);
80 int	pic_alloc_irq(struct pic_softc *pic);
81 void	pic_disestablish_source(struct intrsource *is);
82 #ifdef MULTIPROCESSOR
83 void	pic_distribute_source(struct intrsource *is, const kcpuset_t *,
84 	    kcpuset_t *);
85 #endif
86 void	pic_do_pending_ints(register_t psw, int newipl, void *frame);
87 void	pic_dispatch(struct intrsource *is, void *frame);
88 
89 void	*intr_establish(int irq, int ipl, int type, int (*func)(void *),
90 	    void *arg);
91 void	*intr_establish_xname(int irq, int ipl, int type, int (*func)(void *),
92 	    void *arg, const char *xname);
93 void	intr_disestablish(void *);
94 void	intr_mask(void *);
95 void	intr_unmask(void *);
96 const char *intr_string(intr_handle_t, char *, size_t);
97 #ifdef MULTIPROCESSOR
98 void	intr_cpu_init(struct cpu_info *);
99 void	intr_ipi_send(const kcpuset_t *, u_long ipi);
100 #endif
101 
102 #ifdef _INTR_PRIVATE
103 
104 #include "opt_arm_intr_impl.h"
105 
106 #include <sys/evcnt.h>
107 #include <sys/percpu.h>
108 
109 #ifndef PIC_MAXPICS
110 #define PIC_MAXPICS	32
111 #endif
112 #ifndef PIC_MAXSOURCES
113 #define	PIC_MAXSOURCES	64
114 #endif
115 #ifndef PIC_MAXMAXSOURCES
116 #define	PIC_MAXMAXSOURCES	128
117 #endif
118 
119 struct intrsource {
120 	int (*is_func)(void *);
121 	void *is_arg;
122 	struct pic_softc *is_pic;		/* owning PIC */
123 	uint8_t is_type;			/* IST_xxx */
124 	uint8_t is_ipl;				/* IPL_xxx */
125 	uint32_t is_irq;			/* local to pic */
126 	uint8_t is_iplidx;
127 	bool is_mpsafe;
128 	char is_source[16];
129 	char *is_xname;
130 	uint32_t is_mask_count;
131 	bool is_percpu;
132 };
133 
134 struct pic_percpu {
135 	struct evcnt *pcpu_evs;
136 	char *pcpu_name;
137 	uint32_t pcpu_magic;
138 };
139 
140 #define	PICPERCPU_MAGIC		0xfeedface
141 
142 struct pic_softc {
143 	const struct pic_ops *pic_ops;
144 	struct intrsource **pic_sources;
145 #ifdef __HAVE_PIC_PENDING_INTRS
146 	volatile uint32_t pic_pending_irqs[(PIC_MAXSOURCES + 31) / 32];
147 	volatile uint32_t pic_blocked_irqs[(PIC_MAXSOURCES + 31) / 32];
148 	volatile uint32_t pic_pending_ipls;
149 #endif
150 #ifdef MULTIPROCESSOR
151 	kcpuset_t *pic_cpus;
152 #endif
153 	size_t pic_maxsources;
154 	percpu_t *pic_percpu;
155 	uint8_t pic_id;
156 	int pic_irqbase;
157 	char pic_name[16];
158 };
159 
160 struct pic_ops {
161 	void (*pic_unblock_irqs)(struct pic_softc *, size_t, uint32_t);
162 	void (*pic_block_irqs)(struct pic_softc *, size_t, uint32_t);
163 	int (*pic_find_pending_irqs)(struct pic_softc *);
164 
165 	void (*pic_establish_irq)(struct pic_softc *, struct intrsource *);
166 	void (*pic_source_name)(struct pic_softc *, int, char *, size_t);
167 
168 #ifdef __HAVE_PIC_SET_PRIORITY
169 	void (*pic_set_priority)(struct pic_softc *, int);
170 #endif
171 #ifdef MULTIPROCESSOR
172 	void (*pic_cpu_init)(struct pic_softc *, struct cpu_info *);
173 	void (*pic_ipi_send)(struct pic_softc *, const kcpuset_t *, u_long);
174 	int (*pic_set_affinity)(struct pic_softc *, size_t, const kcpuset_t *);
175 	void (*pic_get_affinity)(struct pic_softc *, size_t, kcpuset_t *);
176 #endif
177 };
178 
179 #ifdef __HAVE_PIC_SET_PRIORITY
180 /*
181  * This is used to update a hardware pic with a value corresponding
182  * to the ipl being set.
183  */
184 struct cpu_info;
185 void	pic_set_priority(struct cpu_info *, int);
186 #else
187 /* Using an inline causes catch-22 problems with cpu.h */
188 #define	pic_set_priority(ci, newipl)	((void)((ci)->ci_cpl = (newipl)))
189 #endif
190 
191 #define	PIC_IRQBASE_ALLOC	(-2)
192 
193 int	pic_add(struct pic_softc *, int);
194 void	pic_do_pending_int(void);
195 #ifdef MULTIPROCESSOR
196 int	pic_ipi_ast(void *);
197 int	pic_ipi_nop(void *);
198 int	pic_ipi_xcall(void *);
199 int	pic_ipi_generic(void *);
200 int	pic_ipi_shootdown(void *);
201 int	pic_ipi_ddb(void *);
202 int	pic_ipi_kpreempt(void *);
203 #endif
204 #ifdef __HAVE_PIC_FAST_SOFTINTS
205 int	pic_handle_softint(void *);
206 #endif
207 
208 extern struct pic_softc * pic_list[PIC_MAXPICS];
209 #endif /* _INTR_PRIVATE */
210 
211 #endif /* _ARM_PIC_PICVAR_H_ */
212