blob: 1f1af5afff0374537f989911d4e98f51078a9c1e [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
Paul Mundt98c4ecd2007-12-10 16:21:57 +090014#define AT_VECTOR_SIZE_ARCH 5 /* entries in ARCH_DLINFO */
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Paul Mundt29847622006-09-27 14:57:44 +090016/*
17 * A brief note on ctrl_barrier(), the control register write barrier.
18 *
19 * Legacy SH cores typically require a sequence of 8 nops after
20 * modification of a control register in order for the changes to take
21 * effect. On newer cores (like the sh4a and sh5) this is accomplished
22 * with icbi.
23 *
24 * Also note that on sh4a in the icbi case we can forego a synco for the
25 * write barrier, as it's not necessary for control registers.
26 *
27 * Historically we have only done this type of barrier for the MMUCR, but
28 * it's also necessary for the CCR, so we make it generic here instead.
29 */
Paul Mundta62a3862007-11-10 19:46:31 +090030#if defined(CONFIG_CPU_SH4A) || defined(CONFIG_CPU_SH5)
Paul Mundt29847622006-09-27 14:57:44 +090031#define mb() __asm__ __volatile__ ("synco": : :"memory")
32#define rmb() mb()
33#define wmb() __asm__ __volatile__ ("synco": : :"memory")
Matt Fleming6430a592010-01-13 12:59:24 +090034#define ctrl_barrier() __icbi(PAGE_OFFSET)
Paul Mundtfdfc74f2006-09-27 14:05:52 +090035#define read_barrier_depends() do { } while(0)
36#else
Paul Mundt29847622006-09-27 14:57:44 +090037#define mb() __asm__ __volatile__ ("": : :"memory")
38#define rmb() mb()
39#define wmb() __asm__ __volatile__ ("": : :"memory")
40#define ctrl_barrier() __asm__ __volatile__ ("nop;nop;nop;nop;nop;nop;nop;nop")
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#define read_barrier_depends() do { } while(0)
Paul Mundtfdfc74f2006-09-27 14:05:52 +090042#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44#ifdef CONFIG_SMP
45#define smp_mb() mb()
46#define smp_rmb() rmb()
47#define smp_wmb() wmb()
48#define smp_read_barrier_depends() read_barrier_depends()
49#else
50#define smp_mb() barrier()
51#define smp_rmb() barrier()
52#define smp_wmb() barrier()
53#define smp_read_barrier_depends() do { } while(0)
54#endif
55
Paul Mundt357d5942007-06-11 15:32:07 +090056#define set_mb(var, value) do { (void)xchg(&var, value); } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Stuart Menefy1efe4ce2007-11-30 16:12:36 +090058#ifdef CONFIG_GUSA_RB
59#include <asm/cmpxchg-grb.h>
Paul Mundtee43a842008-08-07 18:01:43 +090060#elif defined(CONFIG_CPU_SH4A)
61#include <asm/cmpxchg-llsc.h>
Stuart Menefy1efe4ce2007-11-30 16:12:36 +090062#else
63#include <asm/cmpxchg-irq.h>
64#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Paul Mundt00b3aa32006-09-27 16:05:56 +090066extern void __xchg_called_with_bad_pointer(void);
67
68#define __xchg(ptr, x, size) \
69({ \
70 unsigned long __xchg__res; \
71 volatile void *__xchg_ptr = (ptr); \
72 switch (size) { \
73 case 4: \
74 __xchg__res = xchg_u32(__xchg_ptr, x); \
75 break; \
76 case 1: \
77 __xchg__res = xchg_u8(__xchg_ptr, x); \
78 break; \
79 default: \
80 __xchg_called_with_bad_pointer(); \
81 __xchg__res = x; \
82 break; \
83 } \
84 \
85 __xchg__res; \
86})
87
88#define xchg(ptr,x) \
89 ((__typeof__(*(ptr)))__xchg((ptr),(unsigned long)(x), sizeof(*(ptr))))
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Tom Rinie4e3b5c2006-09-27 11:28:20 +090091/* This function doesn't exist, so you'll get a linker error
92 * if something tries to do an invalid cmpxchg(). */
93extern void __cmpxchg_called_with_bad_pointer(void);
94
95#define __HAVE_ARCH_CMPXCHG 1
96
97static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old,
98 unsigned long new, int size)
99{
100 switch (size) {
101 case 4:
102 return __cmpxchg_u32(ptr, old, new);
103 }
104 __cmpxchg_called_with_bad_pointer();
105 return old;
106}
107
108#define cmpxchg(ptr,o,n) \
109 ({ \
110 __typeof__(*(ptr)) _o_ = (o); \
111 __typeof__(*(ptr)) _n_ = (n); \
112 (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
113 (unsigned long)_n_, sizeof(*(ptr))); \
114 })
115
Paul Mundtb0f3ae02010-02-12 15:40:00 +0900116struct pt_regs;
117
Paul Mundt3a2e1172007-05-01 16:33:10 +0900118extern void die(const char *str, struct pt_regs *regs, long err) __attribute__ ((noreturn));
Paul Mundtfa439722008-09-04 18:53:58 +0900119void free_initmem(void);
120void free_initrd_mem(unsigned long start, unsigned long end);
Paul Mundt3a2e1172007-05-01 16:33:10 +0900121
Paul Mundt1f666582006-10-19 16:20:25 +0900122extern void *set_exception_table_vec(unsigned int vec, void *handler);
123
124static inline void *set_exception_table_evt(unsigned int evt, void *handler)
125{
126 return set_exception_table_vec(evt >> 5, handler);
127}
128
Paul Mundtbd079992007-05-08 14:50:59 +0900129/*
130 * SH-2A has both 16 and 32-bit opcodes, do lame encoding checks.
131 */
132#ifdef CONFIG_CPU_SH2A
133extern unsigned int instruction_size(unsigned int insn);
Paul Mundt0fa70ef2007-11-08 19:08:28 +0900134#elif defined(CONFIG_SUPERH32)
Paul Mundtbd079992007-05-08 14:50:59 +0900135#define instruction_size(insn) (2)
Paul Mundt0fa70ef2007-11-08 19:08:28 +0900136#else
137#define instruction_size(insn) (4)
Paul Mundtbd079992007-05-08 14:50:59 +0900138#endif
139
Stuart Menefycbaa1182007-11-30 17:06:36 +0900140extern unsigned long cached_to_uncached;
Paul Mundt3125ee72010-01-21 15:54:31 +0900141extern unsigned long uncached_size;
Stuart Menefycbaa1182007-11-30 17:06:36 +0900142
Paul Mundtaba10302007-09-21 18:32:32 +0900143void per_cpu_trap_init(void);
Paul Mundte869a902009-04-02 13:08:31 +0900144void default_idle(void);
Paul Mundt2e046b92009-06-19 14:40:51 +0900145void cpu_idle_wait(void);
Paul Mundtfbb82b02010-01-20 16:42:52 +0900146void stop_this_cpu(void *);
Paul Mundte08f4572007-05-14 12:52:56 +0900147
Paul Mundt5a4f7c62007-11-20 18:08:06 +0900148#ifdef CONFIG_SUPERH32
149#define BUILD_TRAP_HANDLER(name) \
150asmlinkage void name##_trap_handler(unsigned long r4, unsigned long r5, \
151 unsigned long r6, unsigned long r7, \
152 struct pt_regs __regs)
153
154#define TRAP_HANDLER_DECL \
155 struct pt_regs *regs = RELOC_HIDE(&__regs, 0); \
Paul Mundtb0006592007-11-23 14:02:20 +0900156 unsigned int vec = regs->tra; \
157 (void)vec;
Paul Mundt5a4f7c62007-11-20 18:08:06 +0900158#else
159#define BUILD_TRAP_HANDLER(name) \
160asmlinkage void name##_trap_handler(unsigned int vec, struct pt_regs *regs)
161#define TRAP_HANDLER_DECL
162#endif
163
164BUILD_TRAP_HANDLER(address_error);
165BUILD_TRAP_HANDLER(debug);
166BUILD_TRAP_HANDLER(bug);
Paul Mundtab6e5702008-12-11 18:46:46 +0900167BUILD_TRAP_HANDLER(breakpoint);
168BUILD_TRAP_HANDLER(singlestep);
Paul Mundt74d99a52007-11-26 20:38:36 +0900169BUILD_TRAP_HANDLER(fpu_error);
170BUILD_TRAP_HANDLER(fpu_state_restore);
Paul Mundt1e1030d2009-09-01 17:38:32 +0900171BUILD_TRAP_HANDLER(nmi);
Matt Flemingb344e24a2009-08-16 21:54:48 +0100172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173#define arch_align_stack(x) (x)
174
Magnus Damme7cc9a72008-02-07 20:18:21 +0900175struct mem_access {
Paul Mundtfa439722008-09-04 18:53:58 +0900176 unsigned long (*from)(void *dst, const void __user *src, unsigned long cnt);
177 unsigned long (*to)(void __user *dst, const void *src, unsigned long cnt);
Magnus Damme7cc9a72008-02-07 20:18:21 +0900178};
179
Paul Mundta62a3862007-11-10 19:46:31 +0900180#ifdef CONFIG_SUPERH32
181# include "system_32.h"
182#else
183# include "system_64.h"
184#endif
185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186#endif