Vineet Gupta | 820970a | 2015-03-06 14:08:20 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014-15 Synopsys, Inc. (www.synopsys.com) |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | */ |
| 8 | |
| 9 | #ifndef __ASM_IRQFLAGS_ARCV2_H |
| 10 | #define __ASM_IRQFLAGS_ARCV2_H |
| 11 | |
| 12 | #include <asm/arcregs.h> |
| 13 | |
| 14 | /* status32 Bits */ |
| 15 | #define STATUS_AD_BIT 19 /* Disable Align chk: core supports non-aligned */ |
| 16 | #define STATUS_IE_BIT 31 |
| 17 | |
| 18 | #define STATUS_AD_MASK (1<<STATUS_AD_BIT) |
| 19 | #define STATUS_IE_MASK (1<<STATUS_IE_BIT) |
| 20 | |
| 21 | #define AUX_USER_SP 0x00D |
| 22 | #define AUX_IRQ_CTRL 0x00E |
| 23 | #define AUX_IRQ_ACT 0x043 /* Active Intr across all levels */ |
| 24 | #define AUX_IRQ_LVL_PEND 0x200 /* Pending Intr across all levels */ |
| 25 | #define AUX_IRQ_PRIORITY 0x206 |
| 26 | #define ICAUSE 0x40a |
| 27 | #define AUX_IRQ_SELECT 0x40b |
| 28 | #define AUX_IRQ_ENABLE 0x40c |
| 29 | |
Vineet Gupta | 1f6ccff | 2013-05-13 18:30:41 +0530 | [diff] [blame] | 30 | /* Was Intr taken in User Mode */ |
| 31 | #define AUX_IRQ_ACT_BIT_U 31 |
| 32 | |
Vineet Gupta | dec2b28 | 2016-02-07 12:54:35 +0530 | [diff] [blame] | 33 | /* |
| 34 | * User space should be interruptable even by lowest prio interrupt |
| 35 | * Safe even if actual interrupt priorities is fewer or even one |
| 36 | */ |
| 37 | #define ARCV2_IRQ_DEF_PRIO 15 |
Vineet Gupta | 820970a | 2015-03-06 14:08:20 +0530 | [diff] [blame] | 38 | |
| 39 | /* seed value for status register */ |
| 40 | #define ISA_INIT_STATUS_BITS (STATUS_IE_MASK | STATUS_AD_MASK | \ |
| 41 | (ARCV2_IRQ_DEF_PRIO << 1)) |
| 42 | |
Vineet Gupta | b8628f3 | 2015-06-17 17:03:18 +0530 | [diff] [blame] | 43 | /* SLEEP needs default irq priority (<=) which can interrupt the doze */ |
| 44 | #define ISA_SLEEP_ARG (0x10 | ARCV2_IRQ_DEF_PRIO) |
Vineet Gupta | 512b5b8 | 2015-11-16 13:52:07 +0530 | [diff] [blame] | 45 | |
Vineet Gupta | 820970a | 2015-03-06 14:08:20 +0530 | [diff] [blame] | 46 | #ifndef __ASSEMBLY__ |
| 47 | |
| 48 | /* |
| 49 | * Save IRQ state and disable IRQs |
| 50 | */ |
| 51 | static inline long arch_local_irq_save(void) |
| 52 | { |
| 53 | unsigned long flags; |
| 54 | |
| 55 | __asm__ __volatile__(" clri %0 \n" : "=r" (flags) : : "memory"); |
| 56 | |
| 57 | return flags; |
| 58 | } |
| 59 | |
| 60 | /* |
| 61 | * restore saved IRQ state |
| 62 | */ |
| 63 | static inline void arch_local_irq_restore(unsigned long flags) |
| 64 | { |
| 65 | __asm__ __volatile__(" seti %0 \n" : : "r" (flags) : "memory"); |
| 66 | } |
| 67 | |
| 68 | /* |
| 69 | * Unconditionally Enable IRQs |
| 70 | */ |
| 71 | static inline void arch_local_irq_enable(void) |
| 72 | { |
Vineet Gupta | 4de0e52 | 2014-11-15 17:00:08 +0530 | [diff] [blame] | 73 | unsigned int irqact = read_aux_reg(AUX_IRQ_ACT); |
| 74 | |
| 75 | if (irqact & 0xffff) |
| 76 | write_aux_reg(AUX_IRQ_ACT, irqact & ~0xffff); |
| 77 | |
Vineet Gupta | 820970a | 2015-03-06 14:08:20 +0530 | [diff] [blame] | 78 | __asm__ __volatile__(" seti \n" : : : "memory"); |
| 79 | } |
| 80 | |
| 81 | /* |
| 82 | * Unconditionally Disable IRQs |
| 83 | */ |
| 84 | static inline void arch_local_irq_disable(void) |
| 85 | { |
| 86 | __asm__ __volatile__(" clri \n" : : : "memory"); |
| 87 | } |
| 88 | |
| 89 | /* |
| 90 | * save IRQ state |
| 91 | */ |
| 92 | static inline long arch_local_save_flags(void) |
| 93 | { |
| 94 | unsigned long temp; |
| 95 | |
| 96 | __asm__ __volatile__( |
| 97 | " lr %0, [status32] \n" |
| 98 | : "=&r"(temp) |
| 99 | : |
| 100 | : "memory"); |
| 101 | |
| 102 | return temp; |
| 103 | } |
| 104 | |
| 105 | /* |
| 106 | * Query IRQ state |
| 107 | */ |
| 108 | static inline int arch_irqs_disabled_flags(unsigned long flags) |
| 109 | { |
| 110 | return !(flags & (STATUS_IE_MASK)); |
| 111 | } |
| 112 | |
| 113 | static inline int arch_irqs_disabled(void) |
| 114 | { |
| 115 | return arch_irqs_disabled_flags(arch_local_save_flags()); |
| 116 | } |
| 117 | |
| 118 | #else |
| 119 | |
| 120 | .macro IRQ_DISABLE scratch |
| 121 | clri |
| 122 | .endm |
| 123 | |
| 124 | .macro IRQ_ENABLE scratch |
| 125 | seti |
| 126 | .endm |
| 127 | |
| 128 | #endif /* __ASSEMBLY__ */ |
| 129 | |
| 130 | #endif |