1 /* $OpenBSD: intr.h,v 1.37 2011/01/14 13:20:06 jsing Exp $ */ 2 3 /* 4 * Copyright (c) 2002-2004 Michael Shalayeff 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, 20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 26 * THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #ifndef _MACHINE_INTR_H_ 30 #define _MACHINE_INTR_H_ 31 32 #include <machine/psl.h> 33 34 #define CPU_NINTS 32 35 #define NIPL 17 36 37 #define IPL_NONE 0 38 #define IPL_SOFTCLOCK 1 39 #define IPL_SOFTNET 2 40 #define IPL_BIO 3 41 #define IPL_NET 4 42 #define IPL_SOFTTTY 5 43 #define IPL_TTY 6 44 #define IPL_VM 7 45 #define IPL_AUDIO 8 46 #define IPL_CLOCK 9 47 #define IPL_STATCLOCK 10 48 #define IPL_SCHED 10 49 #define IPL_HIGH 10 50 #define IPL_IPI 11 51 #define IPL_NESTED 12 /* pseudo-level for sub-tables */ 52 53 #define IST_NONE 0 54 #define IST_PULSE 1 55 #define IST_EDGE 2 56 #define IST_LEVEL 3 57 58 #ifdef MULTIPROCESSOR 59 #define HPPA_IPI_NOP 0 60 #define HPPA_IPI_HALT 1 61 #define HPPA_IPI_FPU_SAVE 2 62 #define HPPA_IPI_FPU_FLUSH 3 63 #define HPPA_NIPI 4 64 #endif 65 66 #if !defined(_LOCORE) && defined(_KERNEL) 67 68 extern volatile u_long imask[NIPL]; 69 70 #ifdef DIAGNOSTIC 71 void splassert_fail(int, int, const char *); 72 extern int splassert_ctl; 73 void splassert_check(int, const char *); 74 #define splassert(__wantipl) do { \ 75 if (splassert_ctl > 0) { \ 76 splassert_check(__wantipl, __func__); \ 77 } \ 78 } while (0) 79 #define splsoftassert(__wantipl) splassert(__wantipl) 80 #else 81 #define splassert(__wantipl) do { /* nada */ } while (0) 82 #define splsoftassert(__wantipl) do { /* nada */ } while (0) 83 #endif /* DIAGNOSTIC */ 84 85 void cpu_intr_init(void); 86 void cpu_intr(void *); 87 88 static __inline int 89 spllower(int ncpl) 90 { 91 register int ocpl asm("r28") = ncpl; 92 __asm __volatile("copy %0, %%arg0\n\tbreak %1, %2" 93 : "+r" (ocpl) : "i" (HPPA_BREAK_KERNEL), "i" (HPPA_BREAK_SPLLOWER) 94 : "r26", "memory"); 95 return (ocpl); 96 } 97 98 static __inline int 99 splraise(int ncpl) 100 { 101 struct cpu_info *ci = curcpu(); 102 int ocpl = ci->ci_cpl; 103 104 if (ocpl < ncpl) 105 ci->ci_cpl = ncpl; 106 __asm __volatile ("sync" : "+r" (ci->ci_cpl)); 107 108 return (ocpl); 109 } 110 111 static __inline void 112 splx(int ncpl) 113 { 114 (void)spllower(ncpl); 115 } 116 117 static __inline register_t 118 hppa_intr_disable(void) 119 { 120 register_t eiem; 121 122 __asm __volatile("mfctl %%cr15, %0": "=r" (eiem)); 123 __asm __volatile("mtctl %r0, %cr15"); 124 125 return eiem; 126 } 127 128 static __inline void 129 hppa_intr_enable(register_t eiem) 130 { 131 __asm __volatile("mtctl %0, %%cr15":: "r" (eiem)); 132 } 133 134 #define splsoftclock() splraise(IPL_SOFTCLOCK) 135 #define splsoftnet() splraise(IPL_SOFTNET) 136 #define splbio() splraise(IPL_BIO) 137 #define splnet() splraise(IPL_NET) 138 #define splsofttty() splraise(IPL_SOFTTTY) 139 #define spltty() splraise(IPL_TTY) 140 #define splvm() splraise(IPL_VM) 141 #define splaudio() splraise(IPL_AUDIO) 142 #define splclock() splraise(IPL_CLOCK) 143 #define splsched() splraise(IPL_SCHED) 144 #define splstatclock() splraise(IPL_STATCLOCK) 145 #define splhigh() splraise(IPL_HIGH) 146 #define splipi() splraise(IPL_IPI) 147 #define spl0() spllower(IPL_NONE) 148 149 #define softintr(mask) atomic_setbits_long(&curcpu()->ci_ipending, mask) 150 151 #define SOFTINT_MASK ((1 << (IPL_SOFTCLOCK - 1)) | \ 152 (1 << (IPL_SOFTNET - 1)) | (1 << (IPL_SOFTTTY - 1))) 153 154 #ifdef MULTIPROCESSOR 155 void hppa_ipi_init(struct cpu_info *); 156 int hppa_ipi_send(struct cpu_info *, u_long); 157 int hppa_ipi_broadcast(u_long); 158 #endif 159 160 #define setsoftast(p) (p->p_md.md_astpending = 1) 161 162 void *softintr_establish(int, void (*)(void *), void *); 163 void softintr_disestablish(void *); 164 void softintr_schedule(void *); 165 166 #ifdef MULTIPROCESSOR 167 void hppa_ipi_init(struct cpu_info *); 168 int hppa_ipi_intr(void *arg); 169 int hppa_ipi_send(struct cpu_info *, u_long); 170 #endif 171 172 #endif /* !_LOCORE && _KERNEL */ 173 #endif /* _MACHINE_INTR_H_ */ 174