2 * include/asm-microblaze/system.h -- Low-level interrupt/thread ops
4 * Copyright (C) 2003 John Williams (jwilliams@itee.uq.edu.au)
5 * based upon microblaze version
6 * Copyright (C) 2001 NEC Corporation
7 * Copyright (C) 2001 Miles Bader <miles@gnu.org>
9 * This file is subject to the terms and conditions of the GNU General
10 * Public License. See the file COPYING in the main directory of this
11 * archive for more details.
13 * Written by Miles Bader <miles@gnu.org>
14 * Microblaze port by John Williams
15 * Microblaze port by John Williams
18 #ifndef __MICROBLAZE_SYSTEM_H__
19 #define __MICROBLAZE_SYSTEM_H__
22 #include <linux/linkage.h>
24 #include <asm/ptrace.h>
26 #define prepare_to_switch() do { } while (0)
29 * switch_to(n) should switch tasks to task ptr, first checking that
30 * ptr isn't the current task, in which case it does nothing.
33 extern void *switch_thread (struct thread_struct *last,
34 struct thread_struct *next);
35 #define switch_to(prev,next,last) do { \
37 (last) = switch_thread (&prev->thread, &next->thread); \
42 /* Enable/disable interrupts. */
45 register unsigned tmp; \
46 __asm__ __volatile__ (" \
57 register unsigned tmp; \
58 __asm__ __volatile__ (" \
67 #define __save_flags(flags) \
68 __asm__ __volatile__ ("mfs %0, rmsr" : "=r" (flags))
69 #define __restore_flags(flags) \
70 __asm__ __volatile__ ("mts rmsr, %0" :: "r" (flags))
72 #define __save_flags_cli(flags) \
74 register unsigned tmp; \
75 __asm__ __volatile__ (" \
79 : "=r" (flags), "=r" (tmp) \
84 #define __save_flags_sti(flags) \
86 register unsigned tmp; \
87 __asm__ __volatile__ (" \
91 : "=r" (flags) ,"=r" (tmp) \
96 /* For spinlocks etc */
97 #define local_irq_save(flags) __save_flags_cli (flags)
98 #define local_irq_set(flags) __save_flags_sti (flags)
99 #define local_irq_restore(flags) __restore_flags (flags)
100 #define local_irq_disable() __cli ()
101 #define local_irq_enable() __sti ()
103 #define cli() __cli ()
104 #define sti() __sti ()
105 #define save_flags(flags) __save_flags (flags)
106 #define restore_flags(flags) __restore_flags (flags)
107 #define save_flags_cli(flags) __save_flags_cli (flags)
110 * Force strict CPU ordering.
111 * Not really required on microblaze...
113 #define nop() __asm__ __volatile__ ("nop")
114 #define mb() __asm__ __volatile__ ("nop" ::: "memory")
117 #define set_mb(var, value) do { var = value; mb(); } while (0)
118 #define set_wmb(var, value) do { var = value; wmb (); } while (0)
121 #define smp_mb() mb ()
122 #define smp_rmb() rmb ()
123 #define smp_wmb() wmb ()
125 #define smp_mb() barrier ()
126 #define smp_rmb() barrier ()
127 #define smp_wmb() barrier ()
130 #define xchg(ptr, with) \
131 ((__typeof__ (*(ptr)))__xchg ((unsigned long)(with), (ptr), sizeof (*(ptr))))
132 #define tas(ptr) (xchg ((ptr), 1))
134 extern inline unsigned long __xchg (unsigned long with,
135 __volatile__ void *ptr, int size)
137 unsigned long tmp, flags;
139 save_flags_cli (flags);
143 tmp = *(unsigned char *)ptr;
144 *(unsigned char *)ptr = with;
147 tmp = *(unsigned short *)ptr;
148 *(unsigned short *)ptr = with;
151 tmp = *(unsigned long *)ptr;
152 *(unsigned long *)ptr = with;
156 restore_flags (flags);
161 #endif /* __MICROBLAZE_SYSTEM_H__ */