1 #ifndef __ALPHA_SYSTEM_H
2 #define __ALPHA_SYSTEM_H
4 #include <linux/config.h>
9 * System defines.. Note that this is included both from .c and .S
10 * files, so it does only defines, not any C code.
14 * We leave one page for the initial stack page, and one page for
15 * the initial process structure. Also, the console eats 3 MB for
16 * the initial bootloader (one of which we can reclaim later).
18 #define BOOT_PCB 0x20000000
19 #define BOOT_ADDR 0x20000000
20 /* Remove when official MILO sources have ELF support: */
21 #define BOOT_SIZE (16*1024)
23 #ifdef CONFIG_ALPHA_LEGACY_START_ADDRESS
24 #define KERNEL_START_PHYS 0x300000 /* Old bootloaders hardcoded this. */
26 #define KERNEL_START_PHYS 0x1000000 /* required: Wildfire/Titan/Marvel */
29 #define KERNEL_START (PAGE_OFFSET+KERNEL_START_PHYS)
30 #define SWAPPER_PGD KERNEL_START
31 #define INIT_STACK (PAGE_OFFSET+KERNEL_START_PHYS+0x02000)
32 #define EMPTY_PGT (PAGE_OFFSET+KERNEL_START_PHYS+0x04000)
33 #define EMPTY_PGE (PAGE_OFFSET+KERNEL_START_PHYS+0x08000)
34 #define ZERO_PGE (PAGE_OFFSET+KERNEL_START_PHYS+0x0A000)
36 #define START_ADDR (PAGE_OFFSET+KERNEL_START_PHYS+0x10000)
39 * This is setup by the secondary bootstrap loader. Because
40 * the zero page is zeroed out as soon as the vm system is
41 * initialized, we need to copy things out into a more permanent
44 #define PARAM ZERO_PGE
45 #define COMMAND_LINE ((char*)(PARAM + 0x0000))
46 #define INITRD_START (*(unsigned long *) (PARAM+0x100))
47 #define INITRD_SIZE (*(unsigned long *) (PARAM+0x108))
50 #include <linux/kernel.h>
53 * This is the logout header that should be common to all platforms
54 * (assuming they are running OSF/1 PALcode, I guess).
57 unsigned int size
; /* size in bytes of logout area */
58 unsigned int sbz1
: 30; /* should be zero */
59 unsigned int err2
: 1; /* second error */
60 unsigned int retry
: 1; /* retry flag */
61 unsigned int proc_offset
; /* processor-specific offset */
62 unsigned int sys_offset
; /* system-specific offset */
63 unsigned int code
; /* machine check code */
64 unsigned int frame_rev
; /* frame revision */
67 /* Machine Check Frame for uncorrectable errors (Large format)
68 * --- This is used to log uncorrectable errors such as
69 * double bit ECC errors.
70 * --- These errors are detected by both processor and systems.
72 struct el_common_EV5_uncorrectable_mcheck
{
73 unsigned long shadow
[8]; /* Shadow reg. 8-14, 25 */
74 unsigned long paltemp
[24]; /* PAL TEMP REGS. */
75 unsigned long exc_addr
; /* Address of excepting instruction*/
76 unsigned long exc_sum
; /* Summary of arithmetic traps. */
77 unsigned long exc_mask
; /* Exception mask (from exc_sum). */
78 unsigned long pal_base
; /* Base address for PALcode. */
79 unsigned long isr
; /* Interrupt Status Reg. */
80 unsigned long icsr
; /* CURRENT SETUP OF EV5 IBOX */
81 unsigned long ic_perr_stat
; /* I-CACHE Reg. <11> set Data parity
83 unsigned long dc_perr_stat
; /* D-CACHE error Reg. Bits set to 1:
84 <2> Data error in bank 0
85 <3> Data error in bank 1
86 <4> Tag error in bank 0
87 <5> Tag error in bank 1 */
88 unsigned long va
; /* Effective VA of fault or miss. */
89 unsigned long mm_stat
; /* Holds the reason for D-stream
90 fault or D-cache parity errors */
91 unsigned long sc_addr
; /* Address that was being accessed
92 when EV5 detected Secondary cache
94 unsigned long sc_stat
; /* Helps determine if the error was
95 TAG/Data parity(Secondary Cache)*/
96 unsigned long bc_tag_addr
; /* Contents of EV5 BC_TAG_ADDR */
97 unsigned long ei_addr
; /* Physical address of any transfer
98 that is logged in EV5 EI_STAT */
99 unsigned long fill_syndrome
; /* For correcting ECC errors. */
100 unsigned long ei_stat
; /* Helps identify reason of any
101 processor uncorrectable error
102 at its external interface. */
103 unsigned long ld_lock
; /* Contents of EV5 LD_LOCK register*/
106 struct el_common_EV6_mcheck
{
107 unsigned int FrameSize
; /* Bytes, including this field */
108 unsigned int FrameFlags
; /* <31> = Retry, <30> = Second Error */
109 unsigned int CpuOffset
; /* Offset to CPU-specific info */
110 unsigned int SystemOffset
; /* Offset to system-specific info */
111 unsigned int MCHK_Code
;
112 unsigned int MCHK_Frame_Rev
;
113 unsigned long I_STAT
; /* EV6 Internal Processor Registers */
114 unsigned long DC_STAT
; /* (See the 21264 Spec) */
115 unsigned long C_ADDR
;
116 unsigned long DC1_SYNDROME
;
117 unsigned long DC0_SYNDROME
;
118 unsigned long C_STAT
;
120 unsigned long MM_STAT
;
121 unsigned long EXC_ADDR
;
122 unsigned long IER_CM
;
124 unsigned long RESERVED0
;
125 unsigned long PAL_BASE
;
130 extern void halt(void) __attribute__((noreturn
));
131 #define __halt() __asm__ __volatile__ ("call_pal %0 #halt" : : "i" (PAL_halt))
133 #define switch_to(P,N,L) \
135 (L) = alpha_switch_to(virt_to_phys(&(N)->thread_info->pcb), (P)); \
136 check_mmu_context(); \
140 extern struct task_struct
*alpha_switch_to(unsigned long, struct task_struct
*);
143 __asm__ __volatile__("mb": : :"memory")
146 __asm__ __volatile__("mb": : :"memory")
149 __asm__ __volatile__("wmb": : :"memory")
151 #define read_barrier_depends() \
152 __asm__ __volatile__("mb": : :"memory")
155 #define smp_mb() mb()
156 #define smp_rmb() rmb()
157 #define smp_wmb() wmb()
158 #define smp_read_barrier_depends() read_barrier_depends()
160 #define smp_mb() barrier()
161 #define smp_rmb() barrier()
162 #define smp_wmb() barrier()
163 #define smp_read_barrier_depends() barrier()
166 #define set_mb(var, value) \
167 do { var = value; mb(); } while (0)
169 #define set_wmb(var, value) \
170 do { var = value; wmb(); } while (0)
173 __asm__ __volatile__ ("call_pal %0 #imb" : : "i" (PAL_imb) : "memory")
176 __asm__ __volatile__ ("call_pal %0 #draina" : : "i" (PAL_draina) : "memory")
184 #ifdef CONFIG_ALPHA_GENERIC
186 ({ unsigned long __implver; \
187 __asm__ ("implver %0" : "=r"(__implver)); \
188 (enum implver_enum) __implver; })
190 /* Try to eliminate some dead code. */
191 #ifdef CONFIG_ALPHA_EV4
192 #define implver() IMPLVER_EV4
194 #ifdef CONFIG_ALPHA_EV5
195 #define implver() IMPLVER_EV5
197 #if defined(CONFIG_ALPHA_EV6)
198 #define implver() IMPLVER_EV6
203 AMASK_BWX
= (1UL << 0),
204 AMASK_FIX
= (1UL << 1),
205 AMASK_CIX
= (1UL << 2),
206 AMASK_MAX
= (1UL << 8),
207 AMASK_PRECISE_TRAP
= (1UL << 9),
210 #define amask(mask) \
211 ({ unsigned long __amask, __input = (mask); \
212 __asm__ ("amask %1,%0" : "=r"(__amask) : "rI"(__input)); \
215 #define __CALL_PAL_R0(NAME, TYPE) \
216 static inline TYPE NAME(void) \
218 register TYPE __r0 __asm__("$0"); \
219 __asm__ __volatile__( \
220 "call_pal %1 # " #NAME \
222 :"i" (PAL_ ## NAME) \
223 :"$1", "$16", "$22", "$23", "$24", "$25"); \
227 #define __CALL_PAL_W1(NAME, TYPE0) \
228 static inline void NAME(TYPE0 arg0) \
230 register TYPE0 __r16 __asm__("$16") = arg0; \
231 __asm__ __volatile__( \
232 "call_pal %1 # "#NAME \
234 : "i"(PAL_ ## NAME), "0"(__r16) \
235 : "$1", "$22", "$23", "$24", "$25"); \
238 #define __CALL_PAL_W2(NAME, TYPE0, TYPE1) \
239 static inline void NAME(TYPE0 arg0, TYPE1 arg1) \
241 register TYPE0 __r16 __asm__("$16") = arg0; \
242 register TYPE1 __r17 __asm__("$17") = arg1; \
243 __asm__ __volatile__( \
244 "call_pal %2 # "#NAME \
245 : "=r"(__r16), "=r"(__r17) \
246 : "i"(PAL_ ## NAME), "0"(__r16), "1"(__r17) \
247 : "$1", "$22", "$23", "$24", "$25"); \
250 #define __CALL_PAL_RW1(NAME, RTYPE, TYPE0) \
251 static inline RTYPE NAME(TYPE0 arg0) \
253 register RTYPE __r0 __asm__("$0"); \
254 register TYPE0 __r16 __asm__("$16") = arg0; \
255 __asm__ __volatile__( \
256 "call_pal %2 # "#NAME \
257 : "=r"(__r16), "=r"(__r0) \
258 : "i"(PAL_ ## NAME), "0"(__r16) \
259 : "$1", "$22", "$23", "$24", "$25"); \
263 #define __CALL_PAL_RW2(NAME, RTYPE, TYPE0, TYPE1) \
264 static inline RTYPE NAME(TYPE0 arg0, TYPE1 arg1) \
266 register RTYPE __r0 __asm__("$0"); \
267 register TYPE0 __r16 __asm__("$16") = arg0; \
268 register TYPE1 __r17 __asm__("$17") = arg1; \
269 __asm__ __volatile__( \
270 "call_pal %3 # "#NAME \
271 : "=r"(__r16), "=r"(__r17), "=r"(__r0) \
272 : "i"(PAL_ ## NAME), "0"(__r16), "1"(__r17) \
273 : "$1", "$22", "$23", "$24", "$25"); \
277 __CALL_PAL_W1(cflush
, unsigned long);
278 __CALL_PAL_R0(rdmces
, unsigned long);
279 __CALL_PAL_R0(rdps
, unsigned long);
280 __CALL_PAL_R0(rdusp
, unsigned long);
281 __CALL_PAL_RW1(swpipl
, unsigned long, unsigned long);
282 __CALL_PAL_R0(whami
, unsigned long);
283 __CALL_PAL_W2(wrent
, void*, unsigned long);
284 __CALL_PAL_W1(wripir
, unsigned long);
285 __CALL_PAL_W1(wrkgp
, unsigned long);
286 __CALL_PAL_W1(wrmces
, unsigned long);
287 __CALL_PAL_RW2(wrperfmon
, unsigned long, unsigned long, unsigned long);
288 __CALL_PAL_W1(wrusp
, unsigned long);
289 __CALL_PAL_W1(wrvptptr
, unsigned long);
298 #define IPL_POWERFAIL 6
302 #ifdef CONFIG_ALPHA_BROKEN_IRQ_MASK
304 #define IPL_MIN __min_ipl
305 extern int __min_ipl
;
308 #define getipl() (rdps() & 7)
309 #define setipl(ipl) ((void) swpipl(ipl))
311 #define local_irq_disable() do { setipl(IPL_MAX); barrier(); } while(0)
312 #define local_irq_enable() do { barrier(); setipl(IPL_MIN); } while(0)
313 #define local_save_flags(flags) ((flags) = rdps())
314 #define local_irq_save(flags) do { (flags) = swpipl(IPL_MAX); barrier(); } while(0)
315 #define local_irq_restore(flags) do { barrier(); setipl(flags); barrier(); } while(0)
317 #define irqs_disabled() (getipl() == IPL_MAX)
322 #define __tbi(nr,arg,arg1...) \
324 register unsigned long __r16 __asm__("$16") = (nr); \
325 register unsigned long __r17 __asm__("$17"); arg; \
326 __asm__ __volatile__( \
327 "call_pal %3 #__tbi" \
328 :"=r" (__r16),"=r" (__r17) \
329 :"0" (__r16),"i" (PAL_tbi) ,##arg1 \
330 :"$0", "$1", "$22", "$23", "$24", "$25"); \
333 #define tbi(x,y) __tbi(x,__r17=(y),"1" (__r17))
334 #define tbisi(x) __tbi(1,__r17=(x),"1" (__r17))
335 #define tbisd(x) __tbi(2,__r17=(x),"1" (__r17))
336 #define tbis(x) __tbi(3,__r17=(x),"1" (__r17))
337 #define tbiap() __tbi(-1, /* no second argument */)
338 #define tbia() __tbi(-2, /* no second argument */)
342 * Since it can be used to implement critical sections
343 * it must clobber "memory" (also for interrupts in UP).
346 static inline unsigned long
347 __xchg_u8(volatile char *m
, unsigned long val
)
349 unsigned long ret
, tmp
, addr64
;
351 __asm__
__volatile__(
354 "1: ldq_l %2,0(%3)\n"
366 : "=&r" (ret
), "=&r" (val
), "=&r" (tmp
), "=&r" (addr64
)
367 : "r" ((long)m
), "1" (val
) : "memory");
372 static inline unsigned long
373 __xchg_u16(volatile short *m
, unsigned long val
)
375 unsigned long ret
, tmp
, addr64
;
377 __asm__
__volatile__(
380 "1: ldq_l %2,0(%3)\n"
392 : "=&r" (ret
), "=&r" (val
), "=&r" (tmp
), "=&r" (addr64
)
393 : "r" ((long)m
), "1" (val
) : "memory");
398 static inline unsigned long
399 __xchg_u32(volatile int *m
, unsigned long val
)
403 __asm__
__volatile__(
414 : "=&r" (val
), "=&r" (dummy
), "=m" (*m
)
415 : "rI" (val
), "m" (*m
) : "memory");
420 static inline unsigned long
421 __xchg_u64(volatile long *m
, unsigned long val
)
425 __asm__
__volatile__(
436 : "=&r" (val
), "=&r" (dummy
), "=m" (*m
)
437 : "rI" (val
), "m" (*m
) : "memory");
442 /* This function doesn't exist, so you'll get a linker error
443 if something tries to do an invalid xchg(). */
444 extern void __xchg_called_with_bad_pointer(void);
446 static inline unsigned long
447 __xchg(volatile void *ptr
, unsigned long x
, int size
)
451 return __xchg_u8(ptr
, x
);
453 return __xchg_u16(ptr
, x
);
455 return __xchg_u32(ptr
, x
);
457 return __xchg_u64(ptr
, x
);
459 __xchg_called_with_bad_pointer();
463 #define xchg(ptr,x) \
465 __typeof__(*(ptr)) _x_ = (x); \
466 (__typeof__(*(ptr))) __xchg((ptr), (unsigned long)_x_, sizeof(*(ptr))); \
469 #define tas(ptr) (xchg((ptr),1))
473 * Atomic compare and exchange. Compare OLD with MEM, if identical,
474 * store NEW in MEM. Return the initial value in MEM. Success is
475 * indicated by comparing RETURN with OLD.
477 * The memory barrier should be placed in SMP only when we actually
478 * make the change. If we don't change anything (so if the returned
479 * prev is equal to old) then we aren't acquiring anything new and
480 * we don't need any memory barrier as far I can tell.
483 #define __HAVE_ARCH_CMPXCHG 1
485 static inline unsigned long
486 __cmpxchg_u8(volatile char *m
, long old
, long new)
488 unsigned long prev
, tmp
, cmp
, addr64
;
490 __asm__
__volatile__(
493 "1: ldq_l %2,0(%4)\n"
508 : "=&r" (prev
), "=&r" (new), "=&r" (tmp
), "=&r" (cmp
), "=&r" (addr64
)
509 : "r" ((long)m
), "Ir" (old
), "1" (new) : "memory");
514 static inline unsigned long
515 __cmpxchg_u16(volatile short *m
, long old
, long new)
517 unsigned long prev
, tmp
, cmp
, addr64
;
519 __asm__
__volatile__(
522 "1: ldq_l %2,0(%4)\n"
537 : "=&r" (prev
), "=&r" (new), "=&r" (tmp
), "=&r" (cmp
), "=&r" (addr64
)
538 : "r" ((long)m
), "Ir" (old
), "1" (new) : "memory");
543 static inline unsigned long
544 __cmpxchg_u32(volatile int *m
, int old
, int new)
546 unsigned long prev
, cmp
;
548 __asm__
__volatile__(
562 : "=&r"(prev
), "=&r"(cmp
), "=m"(*m
)
563 : "r"((long) old
), "r"(new), "m"(*m
) : "memory");
568 static inline unsigned long
569 __cmpxchg_u64(volatile long *m
, unsigned long old
, unsigned long new)
571 unsigned long prev
, cmp
;
573 __asm__
__volatile__(
587 : "=&r"(prev
), "=&r"(cmp
), "=m"(*m
)
588 : "r"((long) old
), "r"(new), "m"(*m
) : "memory");
593 /* This function doesn't exist, so you'll get a linker error
594 if something tries to do an invalid cmpxchg(). */
595 extern void __cmpxchg_called_with_bad_pointer(void);
597 static inline unsigned long
598 __cmpxchg(volatile void *ptr
, unsigned long old
, unsigned long new, int size
)
602 return __cmpxchg_u8(ptr
, old
, new);
604 return __cmpxchg_u16(ptr
, old
, new);
606 return __cmpxchg_u32(ptr
, old
, new);
608 return __cmpxchg_u64(ptr
, old
, new);
610 __cmpxchg_called_with_bad_pointer();
614 #define cmpxchg(ptr,o,n) \
616 __typeof__(*(ptr)) _o_ = (o); \
617 __typeof__(*(ptr)) _n_ = (n); \
618 (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
619 (unsigned long)_n_, sizeof(*(ptr))); \
622 #endif /* __ASSEMBLY__ */
624 #define arch_align_stack(x) (x)