blob: ad3d2a6361309af0d318b243663d0ba498e4fdf3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#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 Mundtafbfb522006-12-04 18:17:28 +09009#include <linux/irqflags.h>
Paul Mundt310f7962007-03-28 17:26:19 +090010#include <linux/compiler.h>
Paul Mundte08f4572007-05-14 12:52:56 +090011#include <linux/linkage.h>
Tom Rinie4e3b5c2006-09-27 11:28:20 +090012#include <asm/types.h>
Paul Mundt3a2e1172007-05-01 16:33:10 +090013#include <asm/ptrace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
Olaf Hering4f9a58d2007-10-16 23:30:12 -070015#define AT_VECTOR_SIZE_ARCH 1 /* entries in ARCH_DLINFO */
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Paul Mundta62a3862007-11-10 19:46:31 +090017#if defined(CONFIG_CPU_SH4A) || defined(CONFIG_CPU_SH5)
Paul Mundt29847622006-09-27 14:57:44 +090018#define __icbi() \
19{ \
20 unsigned long __addr; \
21 __addr = 0xa8000000; \
22 __asm__ __volatile__( \
23 "icbi %0\n\t" \
24 : /* no output */ \
25 : "m" (__m(__addr))); \
26}
27#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Paul Mundt29847622006-09-27 14:57:44 +090029/*
30 * A brief note on ctrl_barrier(), the control register write barrier.
31 *
32 * Legacy SH cores typically require a sequence of 8 nops after
33 * modification of a control register in order for the changes to take
34 * effect. On newer cores (like the sh4a and sh5) this is accomplished
35 * with icbi.
36 *
37 * Also note that on sh4a in the icbi case we can forego a synco for the
38 * write barrier, as it's not necessary for control registers.
39 *
40 * Historically we have only done this type of barrier for the MMUCR, but
41 * it's also necessary for the CCR, so we make it generic here instead.
42 */
Paul Mundta62a3862007-11-10 19:46:31 +090043#if defined(CONFIG_CPU_SH4A) || defined(CONFIG_CPU_SH5)
Paul Mundt29847622006-09-27 14:57:44 +090044#define mb() __asm__ __volatile__ ("synco": : :"memory")
45#define rmb() mb()
46#define wmb() __asm__ __volatile__ ("synco": : :"memory")
47#define ctrl_barrier() __icbi()
Paul Mundtfdfc74f2006-09-27 14:05:52 +090048#define read_barrier_depends() do { } while(0)
49#else
Paul Mundt29847622006-09-27 14:57:44 +090050#define mb() __asm__ __volatile__ ("": : :"memory")
51#define rmb() mb()
52#define wmb() __asm__ __volatile__ ("": : :"memory")
53#define ctrl_barrier() __asm__ __volatile__ ("nop;nop;nop;nop;nop;nop;nop;nop")
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#define read_barrier_depends() do { } while(0)
Paul Mundtfdfc74f2006-09-27 14:05:52 +090055#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57#ifdef CONFIG_SMP
58#define smp_mb() mb()
59#define smp_rmb() rmb()
60#define smp_wmb() wmb()
61#define smp_read_barrier_depends() read_barrier_depends()
62#else
63#define smp_mb() barrier()
64#define smp_rmb() barrier()
65#define smp_wmb() barrier()
66#define smp_read_barrier_depends() do { } while(0)
67#endif
68
Paul Mundt357d5942007-06-11 15:32:07 +090069#define set_mb(var, value) do { (void)xchg(&var, value); } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Paul Mundt00b3aa32006-09-27 16:05:56 +090071static inline unsigned long xchg_u32(volatile u32 *m, unsigned long val)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072{
73 unsigned long flags, retval;
74
75 local_irq_save(flags);
76 retval = *m;
77 *m = val;
78 local_irq_restore(flags);
79 return retval;
80}
81
Paul Mundt00b3aa32006-09-27 16:05:56 +090082static inline unsigned long xchg_u8(volatile u8 *m, unsigned long val)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
84 unsigned long flags, retval;
85
86 local_irq_save(flags);
87 retval = *m;
88 *m = val & 0xff;
89 local_irq_restore(flags);
90 return retval;
91}
92
Paul Mundt00b3aa32006-09-27 16:05:56 +090093extern void __xchg_called_with_bad_pointer(void);
94
95#define __xchg(ptr, x, size) \
96({ \
97 unsigned long __xchg__res; \
98 volatile void *__xchg_ptr = (ptr); \
99 switch (size) { \
100 case 4: \
101 __xchg__res = xchg_u32(__xchg_ptr, x); \
102 break; \
103 case 1: \
104 __xchg__res = xchg_u8(__xchg_ptr, x); \
105 break; \
106 default: \
107 __xchg_called_with_bad_pointer(); \
108 __xchg__res = x; \
109 break; \
110 } \
111 \
112 __xchg__res; \
113})
114
115#define xchg(ptr,x) \
116 ((__typeof__(*(ptr)))__xchg((ptr),(unsigned long)(x), sizeof(*(ptr))))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Tom Rinie4e3b5c2006-09-27 11:28:20 +0900118static inline unsigned long __cmpxchg_u32(volatile int * m, unsigned long old,
119 unsigned long new)
120{
121 __u32 retval;
122 unsigned long flags;
123
124 local_irq_save(flags);
125 retval = *m;
126 if (retval == old)
127 *m = new;
128 local_irq_restore(flags); /* implies memory barrier */
129 return retval;
130}
131
132/* This function doesn't exist, so you'll get a linker error
133 * if something tries to do an invalid cmpxchg(). */
134extern void __cmpxchg_called_with_bad_pointer(void);
135
136#define __HAVE_ARCH_CMPXCHG 1
137
138static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old,
139 unsigned long new, int size)
140{
141 switch (size) {
142 case 4:
143 return __cmpxchg_u32(ptr, old, new);
144 }
145 __cmpxchg_called_with_bad_pointer();
146 return old;
147}
148
149#define cmpxchg(ptr,o,n) \
150 ({ \
151 __typeof__(*(ptr)) _o_ = (o); \
152 __typeof__(*(ptr)) _n_ = (n); \
153 (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
154 (unsigned long)_n_, sizeof(*(ptr))); \
155 })
156
Paul Mundt3a2e1172007-05-01 16:33:10 +0900157extern void die(const char *str, struct pt_regs *regs, long err) __attribute__ ((noreturn));
158
Paul Mundt1f666582006-10-19 16:20:25 +0900159extern void *set_exception_table_vec(unsigned int vec, void *handler);
160
161static inline void *set_exception_table_evt(unsigned int evt, void *handler)
162{
163 return set_exception_table_vec(evt >> 5, handler);
164}
165
Paul Mundtbd079992007-05-08 14:50:59 +0900166/*
167 * SH-2A has both 16 and 32-bit opcodes, do lame encoding checks.
168 */
169#ifdef CONFIG_CPU_SH2A
170extern unsigned int instruction_size(unsigned int insn);
Paul Mundt0fa70ef2007-11-08 19:08:28 +0900171#elif defined(CONFIG_SUPERH32)
Paul Mundtbd079992007-05-08 14:50:59 +0900172#define instruction_size(insn) (2)
Paul Mundt0fa70ef2007-11-08 19:08:28 +0900173#else
174#define instruction_size(insn) (4)
Paul Mundtbd079992007-05-08 14:50:59 +0900175#endif
176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177/* XXX
178 * disable hlt during certain critical i/o operations
179 */
180#define HAVE_DISABLE_HLT
181void disable_hlt(void);
182void enable_hlt(void);
183
Paul Mundte08f4572007-05-14 12:52:56 +0900184void default_idle(void);
Paul Mundtaba10302007-09-21 18:32:32 +0900185void per_cpu_trap_init(void);
Paul Mundte08f4572007-05-14 12:52:56 +0900186
187asmlinkage void break_point_trap(void);
Paul Mundt5a4f7c62007-11-20 18:08:06 +0900188
189#ifdef CONFIG_SUPERH32
190#define BUILD_TRAP_HANDLER(name) \
191asmlinkage void name##_trap_handler(unsigned long r4, unsigned long r5, \
192 unsigned long r6, unsigned long r7, \
193 struct pt_regs __regs)
194
195#define TRAP_HANDLER_DECL \
196 struct pt_regs *regs = RELOC_HIDE(&__regs, 0); \
Paul Mundtb0006592007-11-23 14:02:20 +0900197 unsigned int vec = regs->tra; \
198 (void)vec;
Paul Mundt5a4f7c62007-11-20 18:08:06 +0900199#else
200#define BUILD_TRAP_HANDLER(name) \
201asmlinkage void name##_trap_handler(unsigned int vec, struct pt_regs *regs)
202#define TRAP_HANDLER_DECL
203#endif
204
205BUILD_TRAP_HANDLER(address_error);
206BUILD_TRAP_HANDLER(debug);
207BUILD_TRAP_HANDLER(bug);
Paul Mundt74d99a52007-11-26 20:38:36 +0900208BUILD_TRAP_HANDLER(fpu_error);
209BUILD_TRAP_HANDLER(fpu_state_restore);
Paul Mundte08f4572007-05-14 12:52:56 +0900210
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211#define arch_align_stack(x) (x)
212
Paul Mundta62a3862007-11-10 19:46:31 +0900213#ifdef CONFIG_SUPERH32
214# include "system_32.h"
215#else
216# include "system_64.h"
217#endif
218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219#endif