Sort out the IRQ flag handling naming
Subsystems (5)
RFC PATCH 1/1 Sort out the IRQ flag handling naming
Sort out the IRQ flag handling naming. In linux/irqflags.h under one configuration, it maps:
local_irq_enable() -> raw_local_irq_enable() local_irq_disable() -> raw_local_irq_disable() local_irq_save() -> raw_local_irq_save() ...
and under the other configuration, it maps:
raw_local_irq_enable() -> local_irq_enable() raw_local_irq_disable() -> local_irq_disable() raw_local_irq_save() -> local_irq_save() ...
This is quite confusing. There should be one set of names expected of the arch, and this should be wrapped to give another set of names that are expected by users of this facility.
Change this to have the arch provide:
flags = arch_local_save_flags()
flags = arch_local_irq_save()
arch_local_irq_restore(flags)
arch_local_irq_disable()
arch_local_irq_enable()
arch_irqs_disabled_flags(flags)
arch_irqs_disabled()
arch_safe_halt()
in asm/irqflags.h. Then linux/irqflags.h wraps this to provide:
raw_local_save_flags(flags) raw_local_irq_save(flags) raw_local_irq_restore(flags) raw_local_irq_disable() raw_local_irq_enable() raw_irqs_disabled_flags(flags) raw_irqs_disabled() raw_safe_halt()
with type checking on the flags 'arguments', and then wraps those to provide:
local_save_flags(flags) local_irq_save(flags) local_irq_restore(flags) local_irq_disable() local_irq_enable() irqs_disabled_flags(flags) irqs_disabled() safe_halt()
with tracing included if enabled.
The arch functions can now all be inline functions rather than some of them having to be macros.
[Note that this patch only alters x86, FRV and MN10300 at the moment. The
other arches will need altering too as part of this patch].
---
arch/frv/include/asm/irqflags.h | 158 +++++++++++++++++++++++++++++++++++ arch/frv/include/asm/system.h | 136 ------------------------------ arch/mn10300/include/asm/irqflags.h | 123 +++++++++++++++++++++++++++ arch/mn10300/include/asm/system.h | 109 ------------------------ arch/mn10300/kernel/entry.S | 1 arch/x86/include/asm/irqflags.h | 32 +++---- arch/x86/include/asm/paravirt.h | 16 ++-- include/asm-generic/atomic.h | 3 - include/asm-generic/cmpxchg-local.h | 9 +- include/asm-generic/irqflags.h | 52 +++++------- include/linux/irqflags.h | 107 ++++++++++++++---------- include/linux/spinlock.h | 1 12 files changed, 398 insertions(+), 349 deletions(-) create mode 100644 arch/frv/include/asm/irqflags.h create mode 100644 arch/mn10300/include/asm/irqflags.h
arch/frv/include/asm/irqflags.h new file +158 -0
@@ -0,0 +1,158 @@ +/* FR-V interrupt handling +* +* Copyright (C) 2010 Red Hat, Inc. All Rights Reserved. +* Written by David Howells ([email protected]) +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public Licence +* as published by the Free Software Foundation; either version +* 2 of the Licence, or (at your option) any later version. +*/ + +#ifndef _ASM_IRQFLAGS_H +#define _ASM_IRQFLAGS_H + +/* +* interrupt flag manipulation +* - use virtual interrupt management since touching the PSR is slow +* - ICC2.Z: T if interrupts virtually disabled +* - ICC2.C: F if interrupts really disabled +* - if Z==1 upon interrupt: +* - C is set to 0 +* - interrupts are really disabled +* - entry.S returns immediately +* - uses TIHI (TRAP if Z==0 && C==0) #2 to really reenable interrupts +* - if taken, the trap: +* - sets ICC2.C +* - enables interrupts +*/ +static inline void arch_local_irq_disable (void ) +{ +/* set Z flag, but don't change the C flag */ + asmvolatile (" andcc gr0,gr0,gr0,icc2 \n" + : + : + :"memory" ,"icc2" + ); +} + +static inline void arch_local_irq_enable (void ) +{ +/* clear Z flag and then test the C flag */ + asmvolatile (" oricc gr0,#1,gr0,icc2 \n" +" tihi icc2,gr0,#2 \n" + : + : + :"memory" ,"icc2" + ); +} + +static inline unsigned long arch_local_save_flags (void ) +{ +unsigned long flags; + + asmvolatile ("movsg ccr,%0" + :"=r" (flags) + : + :"memory" ); + +/* shift ICC2.Z to bit 0 */ + flags >>=26 ; + +/* make flags 1 if interrupts disabled, 0 otherwise */ +return flags &1UL ; + +} + +static inline unsigned long arch_local_irq_save (void ) +{ +unsigned long flags =arch_local_save_flags (); +arch_local_irq_disable (); +return flags; +} + +static inline void arch_local_irq_restore (unsigned long flags) +{ +/* load the Z flag by turning 1 if disabled into 0 if disabled +* and thus setting the Z flag but not the C flag */ + asmvolatile (" xoricc %0,#1,gr0,icc2 \n" +/* then trap if Z=0 and C=0 */ +" tihi icc2,gr0,#2 \n" + : + :"r" (flags) + :"memory" ,"icc2" + ); + +} + +static inline bool arch_irqs_disabled_flags (unsigned long flags) +{ +return flags; +} + +static inline bool arch_irqs_disabled (void ) +{ +return arch_irqs_disabled_flags (arch_local_save_flags ()); +} + +/* +* real interrupt flag manipulation +*/ +#define __arch_local_irq_disable () \ +do { \ + unsigned long psr; \ + asm volatile(" movsg psr,%0 \n" \ + " andi %0,%2,%0 \n" \ + " ori %0,%1,%0 \n" \ + " movgs %0,psr \n" \ + : "=r"(psr) \ + : "i" (PSR_PIL_14), "i" (~PSR_PIL) \ + : "memory"); \ +} while(0) + +#define __arch_local_irq_enable () \ +do { \ + unsigned long psr; \ + asm volatile(" movsg psr,%0 \n" \ + " andi %0,%1,%0 \n" \ + " movgs %0,psr \n" \ + : "=r"(psr) \ + : "i" (~PSR_PIL) \ + : "memory"); \ +} while(0) + +#define __arch_local_save_flags (flags) \ +do { \ + typecheck(unsigned long, flags); \ + asm("movsg psr,%0" \ + : "=r"(flags) \ + : \ + : "memory"); \ +} while(0) + +#define __arch_local_irq_save (flags) \ +do { \ + unsigned long npsr; \ + typecheck(unsigned long, flags); \ + asm volatile(" movsg psr,%0 \n" \ + " andi %0,%3,%1 \n" \ + " ori %1,%2,%1 \n" \ + " movgs %1,psr \n" \ + : "=r"(flags), "=r"(npsr) \ + : "i" (PSR_PIL_14), "i" (~PSR_PIL) \ + : "memory"); \ +} while(0) + +#define __arch_local_irq_restore (flags) \ +do { \ + typecheck(unsigned long, flags); \ + asm volatile(" movgs %0,psr \n" \ + : \ + : "r" (flags) \ + : "memory"); \ +} while(0) + +#define __arch_irqs_disabled () \ + ((__get_PSR() & PSR_PIL) >= PSR_PIL_14) + +#endif /* _ASM_IRQFLAGS_H */
arch/frv/include/asm/system.h +0 -136
142 lines not on this page · raw message
arch/mn10300/include/asm/irqflags.h new file +123 -0
123 lines not on this page · raw message
arch/mn10300/include/asm/system.h +1 -108
121 lines not on this page · raw message
arch/mn10300/kernel/entry.S +1 -0
@@ -16,6 +16,7 @@ #include <linux/linkage.h> #include <asm/smp.h> #include <asm/system.h> +#include <asm/irqflags.h> #include <asm/thread_info.h> #include <asm/intctl-regs.h> #include <asm/busctl-regs.h>
arch/x86/include/asm/irqflags.h +12 -20
@@ -61,22 +61,22 @@ static inline void native_halt(void)#else #ifndef __ASSEMBLY__ -static inline unsigned long __raw_local_save_flags (void ) +static inline unsigned long arch_local_save_flags (void ) {return native_save_fl (); } -static inline void raw_local_irq_restore (unsigned long flags) +static inline void arch_local_irq_restore (unsigned long flags) {native_restore_fl (flags); } -static inline void raw_local_irq_disable (void ) +static inline void arch_local_irq_disable (void ) {native_irq_disable (); } -static inline void raw_local_irq_enable (void ) +static inline void arch_local_irq_enable (void ) {native_irq_enable (); }
@@ -85,7 +85,7 @@ static inline void raw_local_irq_enable(void)* Used in the idle loop; sti takes one instruction cycle * to complete: */ -static inline void raw_safe_halt (void ) +static inline void arch_safe_halt (void ) {native_safe_halt (); }
@@ -102,12 +102,10 @@ static inline void halt(void)/* * For spinlocks, etc: */ -static inline unsigned long __raw_local_irq_save (void ) +static inline unsigned long arch_local_irq_save (void ) { -unsigned long flags =__raw_local_save_flags (); - -raw_local_irq_disable (); - +unsigned long flags =arch_local_save_flags (); +arch_local_irq_disable ();return flags; }#else
@@ -153,22 +151,16 @@ static inline unsigned long __raw_local_irq_save(void)#endif /* CONFIG_PARAVIRT */ #ifndef __ASSEMBLY__ -#define raw_local_save_flags (flags) \ - do { (flags) = __raw_local_save_flags(); } while (0) - -#define raw_local_irq_save (flags) \ - do { (flags) = __raw_local_irq_save(); } while (0) - -static inline int raw_irqs_disabled_flags (unsigned long flags) +static inline int arch_irqs_disabled_flags (unsigned long flags) {return !(flags &X86_EFLAGS_IF ); } -static inline int raw_irqs_disabled (void ) +static inline int arch_irqs_disabled (void ) { -unsigned long flags =__raw_local_save_flags (); +unsigned long flags =arch_local_save_flags (); -return raw_irqs_disabled_flags (flags); +return arch_irqs_disabled_flags (flags); }#else
arch/x86/include/asm/paravirt.h +8 -8
@@ -105,7 +105,7 @@ static inline void write_cr8(unsigned long x) }#endif -static inline void raw_safe_halt (void ) +static inline void arch_safe_halt (void ) {PVOP_VCALL0 (pv_irq_ops.safe_halt); }
@@ -829,32 +829,32 @@ static __always_inline void arch_spin_unlock(struct arch_spinlock *lock)#define __PV_IS_CALLEE_SAVE (func) \ ((struct paravirt_callee_save) { func }) -static inline unsigned long __raw_local_save_flags (void ) +static inline unsigned long arch_local_save_flags (void ) { return PVOP_CALLEE0(unsigned long, pv_irq_ops.save_fl); } -static inline void raw_local_irq_restore (unsigned long f) +static inline void arch_local_irq_restore (unsigned long f) {PVOP_VCALLEE1 (pv_irq_ops.restore_fl, f); } -static inline void raw_local_irq_disable (void ) +static inline void arch_local_irq_disable (void ) {PVOP_VCALLEE0 (pv_irq_ops.irq_disable); } -static inline void raw_local_irq_enable (void ) +static inline void arch_local_irq_enable (void ) {PVOP_VCALLEE0 (pv_irq_ops.irq_enable); } -static inline unsigned long __raw_local_irq_save (void ) +static inline unsigned long arch_local_irq_save (void ) {unsigned long f; - f =__raw_local_save_flags (); -raw_local_irq_disable (); + f =arch_local_save_flags (); +arch_local_irq_disable ();return f; }
include/asm-generic/atomic.h +2 -1
@@ -43,6 +43,7 @@*/ #define atomic_set (v, i) (((v)->counter) = (i)) +#include <asm/irqflags.h> #include <asm/system.h> /**
@@ -57,7 +58,7 @@ static inline int atomic_add_return(int i, atomic_t *v)unsigned long flags;int temp; -raw_local_irq_save (flags);/* Don't trace it in a irqsoff handler */ +raw_local_irq_save (flags);/* Don't trace it in an irqsoff handler */ temp = v->counter; temp += i; v->counter = temp;
include/asm-generic/cmpxchg-local.h +5 -4
@@ -2,6 +2,7 @@#define __ASM_GENERIC_CMPXCHG_LOCAL_H#include <linux/types.h> +#include <linux/irqflags.h> extern unsigned long wrong_size_cmpxchg (volatile void *ptr);
@@ -20,7 +21,7 @@ static inline unsigned long __cmpxchg_local_generic(volatile void *ptr,if (size ==8 &&sizeof (unsigned long ) !=8 )wrong_size_cmpxchg (ptr); -local_irq_save (flags); +raw_local_irq_save (flags);switch (size) {case 1 : prev = *(u8 *)ptr;if (prev == old)
@@ -41,7 +42,7 @@ static inline unsigned long __cmpxchg_local_generic(volatile void *ptr,default :wrong_size_cmpxchg (ptr); } -local_irq_restore (flags); +raw_local_irq_restore (flags);return prev; }
@@ -54,11 +55,11 @@ static inline u64 __cmpxchg64_local_generic(volatile void *ptr,u64 prev;unsigned long flags; -local_irq_save (flags); +raw_local_irq_save (flags); prev = *(u64 *)ptr;if (prev == old) *(u64 *)ptr = new; -local_irq_restore (flags); +raw_local_irq_restore (flags);return prev; }
include/asm-generic/irqflags.h +23 -29
91 lines not on this page · raw message
include/linux/irqflags.h +64 -43
145 lines not on this page · raw message
include/linux/spinlock.h +1 -0
@@ -50,6 +50,7 @@#include <linux/preempt.h> #include <linux/linkage.h> #include <linux/compiler.h> +#include <linux/irqflags.h> #include <linux/thread_info.h> #include <linux/kernel.h> #include <linux/stringify.h>