system.h 5.47 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1 2 3 4 5 6 7 8
#ifndef __ASM_SH_SYSTEM_H
#define __ASM_SH_SYSTEM_H

/*
 * Copyright (C) 1999, 2000  Niibe Yutaka  &  Kaz Kojima
 * Copyright (C) 2002 Paul Mundt
 */

9
#include <linux/irqflags.h>
10
#include <linux/compiler.h>
11
#include <linux/linkage.h>
Tom Rini's avatar
Tom Rini committed
12
#include <asm/types.h>
Paul Mundt's avatar
Paul Mundt committed
13
#include <asm/ptrace.h>
Linus Torvalds's avatar
Linus Torvalds committed
14

15
#define AT_VECTOR_SIZE_ARCH 1 /* entries in ARCH_DLINFO */
Linus Torvalds's avatar
Linus Torvalds committed
16

17
#if defined(CONFIG_CPU_SH4A) || defined(CONFIG_CPU_SH5)
18 19 20 21 22 23 24 25 26 27
#define __icbi()			\
{					\
	unsigned long __addr;		\
	__addr = 0xa8000000;		\
	__asm__ __volatile__(		\
		"icbi   %0\n\t"		\
		: /* no output */	\
		: "m" (__m(__addr)));	\
}
#endif
Linus Torvalds's avatar
Linus Torvalds committed
28

29 30 31 32 33 34 35 36 37 38 39 40 41 42
/*
 * A brief note on ctrl_barrier(), the control register write barrier.
 *
 * Legacy SH cores typically require a sequence of 8 nops after
 * modification of a control register in order for the changes to take
 * effect. On newer cores (like the sh4a and sh5) this is accomplished
 * with icbi.
 *
 * Also note that on sh4a in the icbi case we can forego a synco for the
 * write barrier, as it's not necessary for control registers.
 *
 * Historically we have only done this type of barrier for the MMUCR, but
 * it's also necessary for the CCR, so we make it generic here instead.
 */
43
#if defined(CONFIG_CPU_SH4A) || defined(CONFIG_CPU_SH5)
44 45 46 47
#define mb()		__asm__ __volatile__ ("synco": : :"memory")
#define rmb()		mb()
#define wmb()		__asm__ __volatile__ ("synco": : :"memory")
#define ctrl_barrier()	__icbi()
48 49
#define read_barrier_depends()	do { } while(0)
#else
50 51 52 53
#define mb()		__asm__ __volatile__ ("": : :"memory")
#define rmb()		mb()
#define wmb()		__asm__ __volatile__ ("": : :"memory")
#define ctrl_barrier()	__asm__ __volatile__ ("nop;nop;nop;nop;nop;nop;nop;nop")
Linus Torvalds's avatar
Linus Torvalds committed
54
#define read_barrier_depends()	do { } while(0)
55
#endif
Linus Torvalds's avatar
Linus Torvalds committed
56 57 58 59 60 61 62 63 64 65 66 67 68

#ifdef CONFIG_SMP
#define smp_mb()	mb()
#define smp_rmb()	rmb()
#define smp_wmb()	wmb()
#define smp_read_barrier_depends()	read_barrier_depends()
#else
#define smp_mb()	barrier()
#define smp_rmb()	barrier()
#define smp_wmb()	barrier()
#define smp_read_barrier_depends()	do { } while(0)
#endif

69
#define set_mb(var, value) do { (void)xchg(&var, value); } while (0)
Linus Torvalds's avatar
Linus Torvalds committed
70

71
static inline unsigned long xchg_u32(volatile u32 *m, unsigned long val)
Linus Torvalds's avatar
Linus Torvalds committed
72 73 74 75 76 77 78 79 80 81
{
	unsigned long flags, retval;

	local_irq_save(flags);
	retval = *m;
	*m = val;
	local_irq_restore(flags);
	return retval;
}

82
static inline unsigned long xchg_u8(volatile u8 *m, unsigned long val)
Linus Torvalds's avatar
Linus Torvalds committed
83 84 85 86 87 88 89 90 91 92
{
	unsigned long flags, retval;

	local_irq_save(flags);
	retval = *m;
	*m = val & 0xff;
	local_irq_restore(flags);
	return retval;
}

93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
extern void __xchg_called_with_bad_pointer(void);

#define __xchg(ptr, x, size)				\
({							\
	unsigned long __xchg__res;			\
	volatile void *__xchg_ptr = (ptr);		\
	switch (size) {					\
	case 4:						\
		__xchg__res = xchg_u32(__xchg_ptr, x);	\
		break;					\
	case 1:						\
		__xchg__res = xchg_u8(__xchg_ptr, x);	\
		break;					\
	default:					\
		__xchg_called_with_bad_pointer();	\
		__xchg__res = x;			\
		break;					\
	}						\
							\
	__xchg__res;					\
})

#define xchg(ptr,x)	\
	((__typeof__(*(ptr)))__xchg((ptr),(unsigned long)(x), sizeof(*(ptr))))
Linus Torvalds's avatar
Linus Torvalds committed
117

Tom Rini's avatar
Tom Rini committed
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
static inline unsigned long __cmpxchg_u32(volatile int * m, unsigned long old,
	unsigned long new)
{
	__u32 retval;
	unsigned long flags;

	local_irq_save(flags);
	retval = *m;
	if (retval == old)
		*m = new;
	local_irq_restore(flags);       /* implies memory barrier  */
	return retval;
}

/* This function doesn't exist, so you'll get a linker error
 * if something tries to do an invalid cmpxchg(). */
extern void __cmpxchg_called_with_bad_pointer(void);

#define __HAVE_ARCH_CMPXCHG 1

static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old,
		unsigned long new, int size)
{
	switch (size) {
	case 4:
		return __cmpxchg_u32(ptr, old, new);
	}
	__cmpxchg_called_with_bad_pointer();
	return old;
}

#define cmpxchg(ptr,o,n)						 \
  ({									 \
     __typeof__(*(ptr)) _o_ = (o);					 \
     __typeof__(*(ptr)) _n_ = (n);					 \
     (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_,		 \
				    (unsigned long)_n_, sizeof(*(ptr))); \
  })

Paul Mundt's avatar
Paul Mundt committed
157 158
extern void die(const char *str, struct pt_regs *regs, long err) __attribute__ ((noreturn));

159 160 161 162 163 164 165
extern void *set_exception_table_vec(unsigned int vec, void *handler);

static inline void *set_exception_table_evt(unsigned int evt, void *handler)
{
	return set_exception_table_vec(evt >> 5, handler);
}

166 167 168 169 170
/*
 * SH-2A has both 16 and 32-bit opcodes, do lame encoding checks.
 */
#ifdef CONFIG_CPU_SH2A
extern unsigned int instruction_size(unsigned int insn);
171
#elif defined(CONFIG_SUPERH32)
172
#define instruction_size(insn)	(2)
173 174
#else
#define instruction_size(insn)	(4)
175 176
#endif

Linus Torvalds's avatar
Linus Torvalds committed
177 178 179 180 181 182 183
/* XXX
 * disable hlt during certain critical i/o operations
 */
#define HAVE_DISABLE_HLT
void disable_hlt(void);
void enable_hlt(void);

184
void default_idle(void);
185
void per_cpu_trap_init(void);
186 187

asmlinkage void break_point_trap(void);
188 189 190 191 192 193 194 195 196

#ifdef CONFIG_SUPERH32
#define BUILD_TRAP_HANDLER(name)					\
asmlinkage void name##_trap_handler(unsigned long r4, unsigned long r5,	\
				    unsigned long r6, unsigned long r7,	\
				    struct pt_regs __regs)

#define TRAP_HANDLER_DECL				\
	struct pt_regs *regs = RELOC_HIDE(&__regs, 0);	\
197 198
	unsigned int vec = regs->tra;			\
	(void)vec;
199 200 201 202 203 204 205 206 207
#else
#define BUILD_TRAP_HANDLER(name)	\
asmlinkage void name##_trap_handler(unsigned int vec, struct pt_regs *regs)
#define TRAP_HANDLER_DECL
#endif

BUILD_TRAP_HANDLER(address_error);
BUILD_TRAP_HANDLER(debug);
BUILD_TRAP_HANDLER(bug);
Paul Mundt's avatar
Paul Mundt committed
208 209
BUILD_TRAP_HANDLER(fpu_error);
BUILD_TRAP_HANDLER(fpu_state_restore);
210

Linus Torvalds's avatar
Linus Torvalds committed
211 212
#define arch_align_stack(x) (x)

213 214 215 216 217 218
#ifdef CONFIG_SUPERH32
# include "system_32.h"
#else
# include "system_64.h"
#endif

Linus Torvalds's avatar
Linus Torvalds committed
219
#endif