Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef __ASM_SH_SYSTEM_H |
| 2 | #define __ASM_SH_SYSTEM_H |
| 3 | |
| 4 | /* |
| 5 | * Copyright (C) 1999, 2000 Niibe Yutaka & Kaz Kojima |
| 6 | * Copyright (C) 2002 Paul Mundt |
| 7 | */ |
| 8 | |
Paul Mundt | afbfb52 | 2006-12-04 18:17:28 +0900 | [diff] [blame] | 9 | #include <linux/irqflags.h> |
Paul Mundt | 310f796 | 2007-03-28 17:26:19 +0900 | [diff] [blame] | 10 | #include <linux/compiler.h> |
Paul Mundt | e08f457 | 2007-05-14 12:52:56 +0900 | [diff] [blame] | 11 | #include <linux/linkage.h> |
Tom Rini | e4e3b5c | 2006-09-27 11:28:20 +0900 | [diff] [blame] | 12 | #include <asm/types.h> |
Paul Mundt | 3a2e117 | 2007-05-01 16:33:10 +0900 | [diff] [blame] | 13 | #include <asm/ptrace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | |
Paul Mundt | 98c4ecd | 2007-12-10 16:21:57 +0900 | [diff] [blame] | 15 | #define AT_VECTOR_SIZE_ARCH 5 /* entries in ARCH_DLINFO */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
Paul Mundt | 2984762 | 2006-09-27 14:57:44 +0900 | [diff] [blame] | 17 | /* |
| 18 | * A brief note on ctrl_barrier(), the control register write barrier. |
| 19 | * |
| 20 | * Legacy SH cores typically require a sequence of 8 nops after |
| 21 | * modification of a control register in order for the changes to take |
| 22 | * effect. On newer cores (like the sh4a and sh5) this is accomplished |
| 23 | * with icbi. |
| 24 | * |
| 25 | * Also note that on sh4a in the icbi case we can forego a synco for the |
| 26 | * write barrier, as it's not necessary for control registers. |
| 27 | * |
| 28 | * Historically we have only done this type of barrier for the MMUCR, but |
| 29 | * it's also necessary for the CCR, so we make it generic here instead. |
| 30 | */ |
Paul Mundt | a62a386 | 2007-11-10 19:46:31 +0900 | [diff] [blame] | 31 | #if defined(CONFIG_CPU_SH4A) || defined(CONFIG_CPU_SH5) |
Paul Mundt | 2984762 | 2006-09-27 14:57:44 +0900 | [diff] [blame] | 32 | #define mb() __asm__ __volatile__ ("synco": : :"memory") |
| 33 | #define rmb() mb() |
| 34 | #define wmb() __asm__ __volatile__ ("synco": : :"memory") |
Matt Fleming | 6430a59 | 2010-01-13 12:59:24 +0900 | [diff] [blame^] | 35 | #define ctrl_barrier() __icbi(PAGE_OFFSET) |
Paul Mundt | fdfc74f | 2006-09-27 14:05:52 +0900 | [diff] [blame] | 36 | #define read_barrier_depends() do { } while(0) |
| 37 | #else |
Paul Mundt | 2984762 | 2006-09-27 14:57:44 +0900 | [diff] [blame] | 38 | #define mb() __asm__ __volatile__ ("": : :"memory") |
| 39 | #define rmb() mb() |
| 40 | #define wmb() __asm__ __volatile__ ("": : :"memory") |
| 41 | #define ctrl_barrier() __asm__ __volatile__ ("nop;nop;nop;nop;nop;nop;nop;nop") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #define read_barrier_depends() do { } while(0) |
Paul Mundt | fdfc74f | 2006-09-27 14:05:52 +0900 | [diff] [blame] | 43 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
| 45 | #ifdef CONFIG_SMP |
| 46 | #define smp_mb() mb() |
| 47 | #define smp_rmb() rmb() |
| 48 | #define smp_wmb() wmb() |
| 49 | #define smp_read_barrier_depends() read_barrier_depends() |
| 50 | #else |
| 51 | #define smp_mb() barrier() |
| 52 | #define smp_rmb() barrier() |
| 53 | #define smp_wmb() barrier() |
| 54 | #define smp_read_barrier_depends() do { } while(0) |
| 55 | #endif |
| 56 | |
Paul Mundt | 357d594 | 2007-06-11 15:32:07 +0900 | [diff] [blame] | 57 | #define set_mb(var, value) do { (void)xchg(&var, value); } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Stuart Menefy | 1efe4ce | 2007-11-30 16:12:36 +0900 | [diff] [blame] | 59 | #ifdef CONFIG_GUSA_RB |
| 60 | #include <asm/cmpxchg-grb.h> |
Paul Mundt | ee43a84 | 2008-08-07 18:01:43 +0900 | [diff] [blame] | 61 | #elif defined(CONFIG_CPU_SH4A) |
| 62 | #include <asm/cmpxchg-llsc.h> |
Stuart Menefy | 1efe4ce | 2007-11-30 16:12:36 +0900 | [diff] [blame] | 63 | #else |
| 64 | #include <asm/cmpxchg-irq.h> |
| 65 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Paul Mundt | 00b3aa3 | 2006-09-27 16:05:56 +0900 | [diff] [blame] | 67 | extern void __xchg_called_with_bad_pointer(void); |
| 68 | |
| 69 | #define __xchg(ptr, x, size) \ |
| 70 | ({ \ |
| 71 | unsigned long __xchg__res; \ |
| 72 | volatile void *__xchg_ptr = (ptr); \ |
| 73 | switch (size) { \ |
| 74 | case 4: \ |
| 75 | __xchg__res = xchg_u32(__xchg_ptr, x); \ |
| 76 | break; \ |
| 77 | case 1: \ |
| 78 | __xchg__res = xchg_u8(__xchg_ptr, x); \ |
| 79 | break; \ |
| 80 | default: \ |
| 81 | __xchg_called_with_bad_pointer(); \ |
| 82 | __xchg__res = x; \ |
| 83 | break; \ |
| 84 | } \ |
| 85 | \ |
| 86 | __xchg__res; \ |
| 87 | }) |
| 88 | |
| 89 | #define xchg(ptr,x) \ |
| 90 | ((__typeof__(*(ptr)))__xchg((ptr),(unsigned long)(x), sizeof(*(ptr)))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Tom Rini | e4e3b5c | 2006-09-27 11:28:20 +0900 | [diff] [blame] | 92 | /* This function doesn't exist, so you'll get a linker error |
| 93 | * if something tries to do an invalid cmpxchg(). */ |
| 94 | extern void __cmpxchg_called_with_bad_pointer(void); |
| 95 | |
| 96 | #define __HAVE_ARCH_CMPXCHG 1 |
| 97 | |
| 98 | static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old, |
| 99 | unsigned long new, int size) |
| 100 | { |
| 101 | switch (size) { |
| 102 | case 4: |
| 103 | return __cmpxchg_u32(ptr, old, new); |
| 104 | } |
| 105 | __cmpxchg_called_with_bad_pointer(); |
| 106 | return old; |
| 107 | } |
| 108 | |
| 109 | #define cmpxchg(ptr,o,n) \ |
| 110 | ({ \ |
| 111 | __typeof__(*(ptr)) _o_ = (o); \ |
| 112 | __typeof__(*(ptr)) _n_ = (n); \ |
| 113 | (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \ |
| 114 | (unsigned long)_n_, sizeof(*(ptr))); \ |
| 115 | }) |
| 116 | |
Paul Mundt | 3a2e117 | 2007-05-01 16:33:10 +0900 | [diff] [blame] | 117 | extern void die(const char *str, struct pt_regs *regs, long err) __attribute__ ((noreturn)); |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 118 | void free_initmem(void); |
| 119 | void free_initrd_mem(unsigned long start, unsigned long end); |
Paul Mundt | 3a2e117 | 2007-05-01 16:33:10 +0900 | [diff] [blame] | 120 | |
Paul Mundt | 1f66658 | 2006-10-19 16:20:25 +0900 | [diff] [blame] | 121 | extern void *set_exception_table_vec(unsigned int vec, void *handler); |
| 122 | |
| 123 | static inline void *set_exception_table_evt(unsigned int evt, void *handler) |
| 124 | { |
| 125 | return set_exception_table_vec(evt >> 5, handler); |
| 126 | } |
| 127 | |
Paul Mundt | bd07999 | 2007-05-08 14:50:59 +0900 | [diff] [blame] | 128 | /* |
| 129 | * SH-2A has both 16 and 32-bit opcodes, do lame encoding checks. |
| 130 | */ |
| 131 | #ifdef CONFIG_CPU_SH2A |
| 132 | extern unsigned int instruction_size(unsigned int insn); |
Paul Mundt | 0fa70ef | 2007-11-08 19:08:28 +0900 | [diff] [blame] | 133 | #elif defined(CONFIG_SUPERH32) |
Paul Mundt | bd07999 | 2007-05-08 14:50:59 +0900 | [diff] [blame] | 134 | #define instruction_size(insn) (2) |
Paul Mundt | 0fa70ef | 2007-11-08 19:08:28 +0900 | [diff] [blame] | 135 | #else |
| 136 | #define instruction_size(insn) (4) |
Paul Mundt | bd07999 | 2007-05-08 14:50:59 +0900 | [diff] [blame] | 137 | #endif |
| 138 | |
Stuart Menefy | cbaa118 | 2007-11-30 17:06:36 +0900 | [diff] [blame] | 139 | extern unsigned long cached_to_uncached; |
| 140 | |
Paul Mundt | b9e393c | 2008-03-07 17:19:58 +0900 | [diff] [blame] | 141 | extern struct dentry *sh_debugfs_root; |
| 142 | |
Paul Mundt | aba1030 | 2007-09-21 18:32:32 +0900 | [diff] [blame] | 143 | void per_cpu_trap_init(void); |
Paul Mundt | e869a90 | 2009-04-02 13:08:31 +0900 | [diff] [blame] | 144 | void default_idle(void); |
Paul Mundt | 2e046b9 | 2009-06-19 14:40:51 +0900 | [diff] [blame] | 145 | void cpu_idle_wait(void); |
Paul Mundt | e08f457 | 2007-05-14 12:52:56 +0900 | [diff] [blame] | 146 | |
| 147 | asmlinkage void break_point_trap(void); |
Paul Mundt | 5a4f7c6 | 2007-11-20 18:08:06 +0900 | [diff] [blame] | 148 | |
| 149 | #ifdef CONFIG_SUPERH32 |
| 150 | #define BUILD_TRAP_HANDLER(name) \ |
| 151 | asmlinkage void name##_trap_handler(unsigned long r4, unsigned long r5, \ |
| 152 | unsigned long r6, unsigned long r7, \ |
| 153 | struct pt_regs __regs) |
| 154 | |
| 155 | #define TRAP_HANDLER_DECL \ |
| 156 | struct pt_regs *regs = RELOC_HIDE(&__regs, 0); \ |
Paul Mundt | b000659 | 2007-11-23 14:02:20 +0900 | [diff] [blame] | 157 | unsigned int vec = regs->tra; \ |
| 158 | (void)vec; |
Paul Mundt | 5a4f7c6 | 2007-11-20 18:08:06 +0900 | [diff] [blame] | 159 | #else |
| 160 | #define BUILD_TRAP_HANDLER(name) \ |
| 161 | asmlinkage void name##_trap_handler(unsigned int vec, struct pt_regs *regs) |
| 162 | #define TRAP_HANDLER_DECL |
| 163 | #endif |
| 164 | |
| 165 | BUILD_TRAP_HANDLER(address_error); |
| 166 | BUILD_TRAP_HANDLER(debug); |
| 167 | BUILD_TRAP_HANDLER(bug); |
Paul Mundt | ab6e570 | 2008-12-11 18:46:46 +0900 | [diff] [blame] | 168 | BUILD_TRAP_HANDLER(breakpoint); |
| 169 | BUILD_TRAP_HANDLER(singlestep); |
Paul Mundt | 74d99a5 | 2007-11-26 20:38:36 +0900 | [diff] [blame] | 170 | BUILD_TRAP_HANDLER(fpu_error); |
| 171 | BUILD_TRAP_HANDLER(fpu_state_restore); |
Paul Mundt | 1e1030d | 2009-09-01 17:38:32 +0900 | [diff] [blame] | 172 | BUILD_TRAP_HANDLER(nmi); |
Matt Fleming | b344e24a | 2009-08-16 21:54:48 +0100 | [diff] [blame] | 173 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | #define arch_align_stack(x) (x) |
| 175 | |
Magnus Damm | e7cc9a7 | 2008-02-07 20:18:21 +0900 | [diff] [blame] | 176 | struct mem_access { |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 177 | unsigned long (*from)(void *dst, const void __user *src, unsigned long cnt); |
| 178 | unsigned long (*to)(void __user *dst, const void *src, unsigned long cnt); |
Magnus Damm | e7cc9a7 | 2008-02-07 20:18:21 +0900 | [diff] [blame] | 179 | }; |
| 180 | |
Paul Mundt | a62a386 | 2007-11-10 19:46:31 +0900 | [diff] [blame] | 181 | #ifdef CONFIG_SUPERH32 |
| 182 | # include "system_32.h" |
| 183 | #else |
| 184 | # include "system_64.h" |
| 185 | #endif |
| 186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | #endif |