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