1 /* $NetBSD: intr.h,v 1.2 2022/02/26 03:02:25 macallan Exp $ */ 2 /* $OpenBSD: intr.h,v 1.26 2009/12/29 13:11:40 jsing Exp $ */ 3 4 /*- 5 * Copyright (c) 1998, 2001, 2002 The NetBSD Foundation, Inc. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to The NetBSD Foundation 9 * by Charles M. Hannum, and by Jason R. Thorpe, and by Matthew Fredette. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 #ifndef _HPPA_INTR_H_ 34 #define _HPPA_INTR_H_ 35 36 #include <machine/psl.h> 37 #include <machine/intrdefs.h> 38 39 #include <sys/evcnt.h> 40 41 #ifndef _LOCORE 42 43 #ifdef _KERNEL 44 45 struct cpu_info; 46 47 /* 48 * The maximum number of bits in a cpl value/spl mask, the maximum number of 49 * bits in an interrupt request register, and the maximum number of interrupt 50 * registers. 51 */ 52 #define HPPA_INTERRUPT_BITS (32) 53 #define CPU_NINTS HPPA_INTERRUPT_BITS /* Use this one */ 54 55 /* 56 * This describes one HPPA interrupt register. 57 */ 58 struct hppa_interrupt_register { 59 bool ir_iscpu; 60 const char *ir_name; /* name for this intr reg */ 61 struct cpu_info *ir_ci; /* cpu this intr reg */ 62 63 /* 64 * The virtual address of the mask, request and level 65 * registers. 66 */ 67 volatile int *ir_mask; 68 volatile int *ir_req; 69 volatile int *ir_level; 70 71 /* 72 * This array has one entry for each bit in the interrupt request 73 * register. 74 * 75 * If the 24 most significant bits are set, the low 8 bits are the 76 * index of the hppa_interrupt_register that this interrupt bit leads 77 * to, with zero meaning that the interrupt bit is unused. 78 * 79 * Otherwise these bits correspond to hppa_interrupt_bits. That is, 80 * these bits are ORed to ipending_new in hppa_intr_ipending() when 81 * an interrupt happens. 82 * 83 * Note that this array is indexed by HP bit number, *not* by "normal" 84 * bit number. In other words, the least significant bit in the inter- 85 * rupt register corresponds to array index 31. 86 */ 87 88 unsigned int ir_bits_map[HPPA_INTERRUPT_BITS]; 89 90 #define IR_BIT_MASK 0xffffff00 91 #define IR_BIT_REG(x) (IR_BIT_MASK | (x)) 92 #define IR_BIT_UNUSED IR_BIT_REG(0) 93 #define IR_BIT_USED_P(x) (((x) & IR_BIT_MASK) != IR_BIT_MASK) 94 #define IR_BIT_NESTED_P(x) (((x) & IR_BIT_MASK) == IR_BIT_MASK) 95 /* true if not used for interrupt or nested interrupt register */ 96 #define IR_BIT_UNUSED_P(x) ((x) == IR_BIT_MASK) 97 98 int ir_bits; /* mask of allocatable bit numbers */ 99 int ir_rbits; /* mask of reserved (for lasi/asp) bit numbers */ 100 }; 101 102 struct hppa_interrupt_bit { 103 104 /* 105 * The interrupt register this bit is in. Some handlers, e.g 106 * apic_intr, don't make use of an hppa_interrupt_register, but are 107 * nested. 108 */ 109 struct hppa_interrupt_register *ib_reg; 110 111 /* 112 * The priority level associated with this bit, e.g, IPL_BIO, IPL_NET, 113 * etc. 114 */ 115 int ib_ipl; 116 117 /* 118 * The spl mask for this bit. This starts out as the spl bit assigned 119 * to this particular interrupt, and later gets fleshed out by the mask 120 * calculator to be the full mask that we need to raise spl to when we 121 * get this interrupt. 122 */ 123 int ib_spl; 124 125 /* The interrupt name. */ 126 char ib_name[16]; 127 128 /* The interrupt event count. */ 129 struct evcnt ib_evcnt; 130 131 /* 132 * The interrupt handler and argument for this bit. If the argument is 133 * NULL, the handler gets the trapframe. 134 */ 135 int (*ib_handler)(void *); 136 void *ib_arg; 137 138 }; 139 140 void hppa_intr_bootstrap(void); 141 void hppa_intr_initialise(struct cpu_info *); 142 void hppa_interrupt_register_establish(struct cpu_info *, 143 struct hppa_interrupt_register *); 144 void * hppa_intr_establish(int, int (*)(void *), void *, 145 struct hppa_interrupt_register *, int); 146 int hppa_intr_allocate_bit(struct hppa_interrupt_register *, int); 147 void hppa_intr_enable(void); 148 149 /* splraise()/spllower() are in locore.S */ 150 int splraise(int); 151 void spllower(int); 152 153 /* 154 * Miscellaneous 155 */ 156 #define spl0() spllower(0) 157 #define splx(x) spllower(x) 158 159 typedef int ipl_t; 160 typedef struct { 161 ipl_t _ipl; 162 } ipl_cookie_t; 163 164 static inline ipl_cookie_t 165 makeiplcookie(ipl_t ipl) 166 { 167 168 return (ipl_cookie_t){._ipl = ipl}; 169 } 170 171 static inline int 172 splraiseipl(ipl_cookie_t icookie) 173 { 174 175 return splraise(icookie._ipl); 176 } 177 178 #include <sys/spl.h> 179 #endif 180 181 #define setsoftast(l) ((l)->l_md.md_astpending = 1) 182 183 #ifdef MULTIPROCESSOR 184 185 struct cpu_info; 186 187 void hppa_ipi_init(struct cpu_info *); 188 int hppa_ipi_intr(void *arg); 189 int hppa_ipi_send(struct cpu_info *, u_long); 190 int hppa_ipi_broadcast(u_long); 191 #endif 192 193 #endif /* !_LOCORE */ 194 195 #endif /* !_HPPA_INTR_H_ */ 196