Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef __ASM_SH64_SYSTEM_H |
| 2 | #define __ASM_SH64_SYSTEM_H |
| 3 | |
| 4 | /* |
| 5 | * This file is subject to the terms and conditions of the GNU General Public |
| 6 | * License. See the file "COPYING" in the main directory of this archive |
| 7 | * for more details. |
| 8 | * |
| 9 | * include/asm-sh64/system.h |
| 10 | * |
| 11 | * Copyright (C) 2000, 2001 Paolo Alberelli |
| 12 | * Copyright (C) 2003 Paul Mundt |
| 13 | * Copyright (C) 2004 Richard Curnow |
| 14 | * |
| 15 | */ |
| 16 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <asm/registers.h> |
| 18 | #include <asm/processor.h> |
| 19 | |
| 20 | /* |
| 21 | * switch_to() should switch tasks to task nr n, first |
| 22 | */ |
| 23 | |
| 24 | typedef struct { |
| 25 | unsigned long seg; |
| 26 | } mm_segment_t; |
| 27 | |
| 28 | extern struct task_struct *sh64_switch_to(struct task_struct *prev, |
| 29 | struct thread_struct *prev_thread, |
| 30 | struct task_struct *next, |
| 31 | struct thread_struct *next_thread); |
| 32 | |
| 33 | #define switch_to(prev,next,last) \ |
| 34 | do {\ |
| 35 | if (last_task_used_math != next) {\ |
| 36 | struct pt_regs *regs = next->thread.uregs;\ |
| 37 | if (regs) regs->sr |= SR_FD;\ |
| 38 | }\ |
| 39 | last = sh64_switch_to(prev, &prev->thread, next, &next->thread);\ |
| 40 | } while(0) |
| 41 | |
| 42 | #define nop() __asm__ __volatile__ ("nop") |
| 43 | |
| 44 | #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr)))) |
| 45 | |
| 46 | #define tas(ptr) (xchg((ptr), 1)) |
| 47 | |
| 48 | extern void __xchg_called_with_bad_pointer(void); |
| 49 | |
| 50 | #define mb() __asm__ __volatile__ ("synco": : :"memory") |
| 51 | #define rmb() mb() |
| 52 | #define wmb() __asm__ __volatile__ ("synco": : :"memory") |
| 53 | #define read_barrier_depends() do { } while (0) |
| 54 | |
| 55 | #ifdef CONFIG_SMP |
| 56 | #define smp_mb() mb() |
| 57 | #define smp_rmb() rmb() |
| 58 | #define smp_wmb() wmb() |
| 59 | #define smp_read_barrier_depends() read_barrier_depends() |
| 60 | #else |
| 61 | #define smp_mb() barrier() |
| 62 | #define smp_rmb() barrier() |
| 63 | #define smp_wmb() barrier() |
| 64 | #define smp_read_barrier_depends() do { } while (0) |
| 65 | #endif /* CONFIG_SMP */ |
| 66 | |
| 67 | #define set_rmb(var, value) do { xchg(&var, value); } while (0) |
| 68 | #define set_mb(var, value) set_rmb(var, value) |
| 69 | #define set_wmb(var, value) do { var = value; wmb(); } while (0) |
| 70 | |
| 71 | /* Interrupt Control */ |
| 72 | #ifndef HARD_CLI |
| 73 | #define SR_MASK_L 0x000000f0L |
| 74 | #define SR_MASK_LL 0x00000000000000f0LL |
| 75 | #else |
| 76 | #define SR_MASK_L 0x10000000L |
| 77 | #define SR_MASK_LL 0x0000000010000000LL |
| 78 | #endif |
| 79 | |
| 80 | static __inline__ void local_irq_enable(void) |
| 81 | { |
| 82 | /* cli/sti based on SR.BL */ |
| 83 | unsigned long long __dummy0, __dummy1=~SR_MASK_LL; |
| 84 | |
| 85 | __asm__ __volatile__("getcon " __SR ", %0\n\t" |
| 86 | "and %0, %1, %0\n\t" |
| 87 | "putcon %0, " __SR "\n\t" |
| 88 | : "=&r" (__dummy0) |
| 89 | : "r" (__dummy1)); |
| 90 | } |
| 91 | |
| 92 | static __inline__ void local_irq_disable(void) |
| 93 | { |
| 94 | /* cli/sti based on SR.BL */ |
| 95 | unsigned long long __dummy0, __dummy1=SR_MASK_LL; |
| 96 | __asm__ __volatile__("getcon " __SR ", %0\n\t" |
| 97 | "or %0, %1, %0\n\t" |
| 98 | "putcon %0, " __SR "\n\t" |
| 99 | : "=&r" (__dummy0) |
| 100 | : "r" (__dummy1)); |
| 101 | } |
| 102 | |
| 103 | #define local_save_flags(x) \ |
| 104 | (__extension__ ({ unsigned long long __dummy=SR_MASK_LL; \ |
| 105 | __asm__ __volatile__( \ |
| 106 | "getcon " __SR ", %0\n\t" \ |
| 107 | "and %0, %1, %0" \ |
| 108 | : "=&r" (x) \ |
| 109 | : "r" (__dummy));})) |
| 110 | |
| 111 | #define local_irq_save(x) \ |
| 112 | (__extension__ ({ unsigned long long __d2=SR_MASK_LL, __d1; \ |
| 113 | __asm__ __volatile__( \ |
| 114 | "getcon " __SR ", %1\n\t" \ |
| 115 | "or %1, r63, %0\n\t" \ |
| 116 | "or %1, %2, %1\n\t" \ |
| 117 | "putcon %1, " __SR "\n\t" \ |
| 118 | "and %0, %2, %0" \ |
| 119 | : "=&r" (x), "=&r" (__d1) \ |
| 120 | : "r" (__d2));})); |
| 121 | |
| 122 | #define local_irq_restore(x) do { \ |
| 123 | if ( ((x) & SR_MASK_L) == 0 ) /* dropping to 0 ? */ \ |
| 124 | local_irq_enable(); /* yes...re-enable */ \ |
| 125 | } while (0) |
| 126 | |
| 127 | #define irqs_disabled() \ |
| 128 | ({ \ |
| 129 | unsigned long flags; \ |
| 130 | local_save_flags(flags); \ |
| 131 | (flags != 0); \ |
| 132 | }) |
| 133 | |
Adrian Bunk | ca5ed2f | 2006-01-09 20:54:47 -0800 | [diff] [blame] | 134 | static inline unsigned long xchg_u32(volatile int * m, unsigned long val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | { |
| 136 | unsigned long flags, retval; |
| 137 | |
| 138 | local_irq_save(flags); |
| 139 | retval = *m; |
| 140 | *m = val; |
| 141 | local_irq_restore(flags); |
| 142 | return retval; |
| 143 | } |
| 144 | |
Adrian Bunk | ca5ed2f | 2006-01-09 20:54:47 -0800 | [diff] [blame] | 145 | static inline unsigned long xchg_u8(volatile unsigned char * m, unsigned long val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | { |
| 147 | unsigned long flags, retval; |
| 148 | |
| 149 | local_irq_save(flags); |
| 150 | retval = *m; |
| 151 | *m = val & 0xff; |
| 152 | local_irq_restore(flags); |
| 153 | return retval; |
| 154 | } |
| 155 | |
| 156 | static __inline__ unsigned long __xchg(unsigned long x, volatile void * ptr, int size) |
| 157 | { |
| 158 | switch (size) { |
| 159 | case 4: |
| 160 | return xchg_u32(ptr, x); |
| 161 | break; |
| 162 | case 1: |
| 163 | return xchg_u8(ptr, x); |
| 164 | break; |
| 165 | } |
| 166 | __xchg_called_with_bad_pointer(); |
| 167 | return x; |
| 168 | } |
| 169 | |
| 170 | /* XXX |
| 171 | * disable hlt during certain critical i/o operations |
| 172 | */ |
| 173 | #define HAVE_DISABLE_HLT |
| 174 | void disable_hlt(void); |
| 175 | void enable_hlt(void); |
| 176 | |
| 177 | |
| 178 | #define smp_mb() barrier() |
| 179 | #define smp_rmb() barrier() |
| 180 | #define smp_wmb() barrier() |
| 181 | |
| 182 | #ifdef CONFIG_SH_ALPHANUMERIC |
| 183 | /* This is only used for debugging. */ |
| 184 | extern void print_seg(char *file,int line); |
| 185 | #define PLS() print_seg(__FILE__,__LINE__) |
| 186 | #else /* CONFIG_SH_ALPHANUMERIC */ |
| 187 | #define PLS() |
| 188 | #endif /* CONFIG_SH_ALPHANUMERIC */ |
| 189 | |
| 190 | #define PL() printk("@ <%s,%s:%d>\n",__FILE__,__FUNCTION__,__LINE__) |
| 191 | |
| 192 | #define arch_align_stack(x) (x) |
| 193 | |
| 194 | #endif /* __ASM_SH64_SYSTEM_H */ |