Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * include/asm/irqflags.h
0004  *
0005  * IRQ flags handling
0006  *
0007  * This file gets included from lowlevel asm headers too, to provide
0008  * wrapped versions of the local_irq_*() APIs, based on the
0009  * arch_local_irq_*() functions from the lowlevel headers.
0010  */
0011 #ifndef _ASM_IRQFLAGS_H
0012 #define _ASM_IRQFLAGS_H
0013 
0014 #include <asm/pil.h>
0015 
0016 #ifndef __ASSEMBLY__
0017 
0018 static inline notrace unsigned long arch_local_save_flags(void)
0019 {
0020     unsigned long flags;
0021 
0022     __asm__ __volatile__(
0023         "rdpr   %%pil, %0"
0024         : "=r" (flags)
0025     );
0026 
0027     return flags;
0028 }
0029 
0030 static inline notrace void arch_local_irq_restore(unsigned long flags)
0031 {
0032     __asm__ __volatile__(
0033         "wrpr   %0, %%pil"
0034         : /* no output */
0035         : "r" (flags)
0036         : "memory"
0037     );
0038 }
0039 
0040 static inline notrace void arch_local_irq_disable(void)
0041 {
0042     __asm__ __volatile__(
0043         "wrpr   %0, %%pil"
0044         : /* no outputs */
0045         : "i" (PIL_NORMAL_MAX)
0046         : "memory"
0047     );
0048 }
0049 
0050 static inline notrace void arch_local_irq_enable(void)
0051 {
0052     __asm__ __volatile__(
0053         "wrpr   0, %%pil"
0054         : /* no outputs */
0055         : /* no inputs */
0056         : "memory"
0057     );
0058 }
0059 
0060 static inline notrace int arch_irqs_disabled_flags(unsigned long flags)
0061 {
0062     return (flags > 0);
0063 }
0064 
0065 static inline notrace int arch_irqs_disabled(void)
0066 {
0067     return arch_irqs_disabled_flags(arch_local_save_flags());
0068 }
0069 
0070 static inline notrace unsigned long arch_local_irq_save(void)
0071 {
0072     unsigned long flags, tmp;
0073 
0074     /* Disable interrupts to PIL_NORMAL_MAX unless we already
0075      * are using PIL_NMI, in which case PIL_NMI is retained.
0076      *
0077      * The only values we ever program into the %pil are 0,
0078      * PIL_NORMAL_MAX and PIL_NMI.
0079      *
0080      * Since PIL_NMI is the largest %pil value and all bits are
0081      * set in it (0xf), it doesn't matter what PIL_NORMAL_MAX
0082      * actually is.
0083      */
0084     __asm__ __volatile__(
0085         "rdpr   %%pil, %0\n\t"
0086         "or %0, %2, %1\n\t"
0087         "wrpr   %1, 0x0, %%pil"
0088         : "=r" (flags), "=r" (tmp)
0089         : "i" (PIL_NORMAL_MAX)
0090         : "memory"
0091     );
0092 
0093     return flags;
0094 }
0095 
0096 #endif /* (__ASSEMBLY__) */
0097 
0098 #endif /* !(_ASM_IRQFLAGS_H) */