blob: 006e9487372dc2d188672f37e5731b6699f5fdc2 [file] [log] [blame]
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001/*
2 * Copyright (C) 2004-2006 Atmel Corporation
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#ifndef __ASM_AVR32_IRQFLAGS_H
9#define __ASM_AVR32_IRQFLAGS_H
10
David Howellsdf9ee292010-10-07 14:08:55 +010011#include <linux/types.h>
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070012#include <asm/sysreg.h>
13
David Howellsdf9ee292010-10-07 14:08:55 +010014static inline unsigned long arch_local_save_flags(void)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070015{
16 return sysreg_read(SR);
17}
18
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070019/*
20 * This will restore ALL status register flags, not only the interrupt
21 * mask flag.
22 *
23 * The empty asm statement informs the compiler of this fact while
24 * also serving as a barrier.
25 */
David Howellsdf9ee292010-10-07 14:08:55 +010026static inline void arch_local_irq_restore(unsigned long flags)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070027{
28 sysreg_write(SR, flags);
29 asm volatile("" : : : "memory", "cc");
30}
31
David Howellsdf9ee292010-10-07 14:08:55 +010032static inline void arch_local_irq_disable(void)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070033{
34 asm volatile("ssrf %0" : : "n"(SYSREG_GM_OFFSET) : "memory");
35}
36
David Howellsdf9ee292010-10-07 14:08:55 +010037static inline void arch_local_irq_enable(void)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070038{
39 asm volatile("csrf %0" : : "n"(SYSREG_GM_OFFSET) : "memory");
40}
41
David Howellsdf9ee292010-10-07 14:08:55 +010042static inline bool arch_irqs_disabled_flags(unsigned long flags)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070043{
44 return (flags & SYSREG_BIT(GM)) != 0;
45}
46
David Howellsdf9ee292010-10-07 14:08:55 +010047static inline bool arch_irqs_disabled(void)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070048{
David Howellsdf9ee292010-10-07 14:08:55 +010049 return arch_irqs_disabled_flags(arch_local_save_flags());
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070050}
51
David Howellsdf9ee292010-10-07 14:08:55 +010052static inline unsigned long arch_local_irq_save(void)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070053{
David Howellsdf9ee292010-10-07 14:08:55 +010054 unsigned long flags = arch_local_save_flags();
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070055
David Howellsdf9ee292010-10-07 14:08:55 +010056 arch_local_irq_disable();
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070057
58 return flags;
59}
60
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070061#endif /* __ASM_AVR32_IRQFLAGS_H */