system.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. /*
  2. * Copyright (C) 1999 Cort Dougan <cort@cs.nmt.edu>
  3. */
  4. #ifndef _ASM_POWERPC_SYSTEM_H
  5. #define _ASM_POWERPC_SYSTEM_H
  6. #include <linux/kernel.h>
  7. #include <linux/irqflags.h>
  8. #include <asm/hw_irq.h>
  9. /*
  10. * Memory barrier.
  11. * The sync instruction guarantees that all memory accesses initiated
  12. * by this processor have been performed (with respect to all other
  13. * mechanisms that access memory). The eieio instruction is a barrier
  14. * providing an ordering (separately) for (a) cacheable stores and (b)
  15. * loads and stores to non-cacheable memory (e.g. I/O devices).
  16. *
  17. * mb() prevents loads and stores being reordered across this point.
  18. * rmb() prevents loads being reordered across this point.
  19. * wmb() prevents stores being reordered across this point.
  20. * read_barrier_depends() prevents data-dependent loads being reordered
  21. * across this point (nop on PPC).
  22. *
  23. * We have to use the sync instructions for mb(), since lwsync doesn't
  24. * order loads with respect to previous stores. Lwsync is fine for
  25. * rmb(), though. Note that rmb() actually uses a sync on 32-bit
  26. * architectures.
  27. *
  28. * For wmb(), we use sync since wmb is used in drivers to order
  29. * stores to system memory with respect to writes to the device.
  30. * However, smp_wmb() can be a lighter-weight lwsync or eieio barrier
  31. * on SMP since it is only used to order updates to system memory.
  32. */
  33. #define mb() __asm__ __volatile__ ("sync" : : : "memory")
  34. #define rmb() __asm__ __volatile__ ("sync" : : : "memory")
  35. #define wmb() __asm__ __volatile__ ("sync" : : : "memory")
  36. #define read_barrier_depends() do { } while(0)
  37. #define set_mb(var, value) do { var = value; mb(); } while (0)
  38. #ifdef __KERNEL__
  39. #define AT_VECTOR_SIZE_ARCH 6 /* entries in ARCH_DLINFO */
  40. #ifdef CONFIG_SMP
  41. #ifdef __SUBARCH_HAS_LWSYNC
  42. # define SMPWMB lwsync
  43. #else
  44. # define SMPWMB eieio
  45. #endif
  46. #define smp_mb() mb()
  47. #define smp_rmb() rmb()
  48. #define smp_wmb() __asm__ __volatile__ (__stringify(SMPWMB) : : :"memory")
  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 /* CONFIG_SMP */
  56. /*
  57. * This is a barrier which prevents following instructions from being
  58. * started until the value of the argument x is known. For example, if
  59. * x is a variable loaded from memory, this prevents following
  60. * instructions from being executed until the load has been performed.
  61. */
  62. #define data_barrier(x) \
  63. asm volatile("twi 0,%0,0; isync" : : "r" (x) : "memory");
  64. struct task_struct;
  65. struct pt_regs;
  66. #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC)
  67. extern int (*__debugger)(struct pt_regs *regs);
  68. extern int (*__debugger_ipi)(struct pt_regs *regs);
  69. extern int (*__debugger_bpt)(struct pt_regs *regs);
  70. extern int (*__debugger_sstep)(struct pt_regs *regs);
  71. extern int (*__debugger_iabr_match)(struct pt_regs *regs);
  72. extern int (*__debugger_dabr_match)(struct pt_regs *regs);
  73. extern int (*__debugger_fault_handler)(struct pt_regs *regs);
  74. #define DEBUGGER_BOILERPLATE(__NAME) \
  75. static inline int __NAME(struct pt_regs *regs) \
  76. { \
  77. if (unlikely(__ ## __NAME)) \
  78. return __ ## __NAME(regs); \
  79. return 0; \
  80. }
  81. DEBUGGER_BOILERPLATE(debugger)
  82. DEBUGGER_BOILERPLATE(debugger_ipi)
  83. DEBUGGER_BOILERPLATE(debugger_bpt)
  84. DEBUGGER_BOILERPLATE(debugger_sstep)
  85. DEBUGGER_BOILERPLATE(debugger_iabr_match)
  86. DEBUGGER_BOILERPLATE(debugger_dabr_match)
  87. DEBUGGER_BOILERPLATE(debugger_fault_handler)
  88. #else
  89. static inline int debugger(struct pt_regs *regs) { return 0; }
  90. static inline int debugger_ipi(struct pt_regs *regs) { return 0; }
  91. static inline int debugger_bpt(struct pt_regs *regs) { return 0; }
  92. static inline int debugger_sstep(struct pt_regs *regs) { return 0; }
  93. static inline int debugger_iabr_match(struct pt_regs *regs) { return 0; }
  94. static inline int debugger_dabr_match(struct pt_regs *regs) { return 0; }
  95. static inline int debugger_fault_handler(struct pt_regs *regs) { return 0; }
  96. #endif
  97. extern int set_dabr(unsigned long dabr);
  98. extern void do_dabr(struct pt_regs *regs, unsigned long address,
  99. unsigned long error_code);
  100. extern void print_backtrace(unsigned long *);
  101. extern void show_regs(struct pt_regs * regs);
  102. extern void flush_instruction_cache(void);
  103. extern void hard_reset_now(void);
  104. extern void poweroff_now(void);
  105. #ifdef CONFIG_6xx
  106. extern long _get_L2CR(void);
  107. extern long _get_L3CR(void);
  108. extern void _set_L2CR(unsigned long);
  109. extern void _set_L3CR(unsigned long);
  110. #else
  111. #define _get_L2CR() 0L
  112. #define _get_L3CR() 0L
  113. #define _set_L2CR(val) do { } while(0)
  114. #define _set_L3CR(val) do { } while(0)
  115. #endif
  116. extern void via_cuda_init(void);
  117. extern void read_rtc_time(void);
  118. extern void pmac_find_display(void);
  119. extern void giveup_fpu(struct task_struct *);
  120. extern void disable_kernel_fp(void);
  121. extern void enable_kernel_fp(void);
  122. extern void flush_fp_to_thread(struct task_struct *);
  123. extern void enable_kernel_altivec(void);
  124. extern void giveup_altivec(struct task_struct *);
  125. extern void load_up_altivec(struct task_struct *);
  126. extern int emulate_altivec(struct pt_regs *);
  127. extern void __giveup_vsx(struct task_struct *);
  128. extern void giveup_vsx(struct task_struct *);
  129. extern void enable_kernel_spe(void);
  130. extern void giveup_spe(struct task_struct *);
  131. extern void load_up_spe(struct task_struct *);
  132. extern int fix_alignment(struct pt_regs *);
  133. extern void cvt_fd(float *from, double *to, struct thread_struct *thread);
  134. extern void cvt_df(double *from, float *to, struct thread_struct *thread);
  135. #ifndef CONFIG_SMP
  136. extern void discard_lazy_cpu_state(void);
  137. #else
  138. static inline void discard_lazy_cpu_state(void)
  139. {
  140. }
  141. #endif
  142. #ifdef CONFIG_ALTIVEC
  143. extern void flush_altivec_to_thread(struct task_struct *);
  144. #else
  145. static inline void flush_altivec_to_thread(struct task_struct *t)
  146. {
  147. }
  148. #endif
  149. #ifdef CONFIG_VSX
  150. extern void flush_vsx_to_thread(struct task_struct *);
  151. #else
  152. static inline void flush_vsx_to_thread(struct task_struct *t)
  153. {
  154. }
  155. #endif
  156. #ifdef CONFIG_SPE
  157. extern void flush_spe_to_thread(struct task_struct *);
  158. #else
  159. static inline void flush_spe_to_thread(struct task_struct *t)
  160. {
  161. }
  162. #endif
  163. extern int call_rtas(const char *, int, int, unsigned long *, ...);
  164. extern void cacheable_memzero(void *p, unsigned int nb);
  165. extern void *cacheable_memcpy(void *, const void *, unsigned int);
  166. extern int do_page_fault(struct pt_regs *, unsigned long, unsigned long);
  167. extern void bad_page_fault(struct pt_regs *, unsigned long, int);
  168. extern int die(const char *, struct pt_regs *, long);
  169. extern void _exception(int, struct pt_regs *, int, unsigned long);
  170. extern void _nmask_and_or_msr(unsigned long nmask, unsigned long or_val);
  171. #ifdef CONFIG_BOOKE_WDT
  172. extern u32 booke_wdt_enabled;
  173. extern u32 booke_wdt_period;
  174. #endif /* CONFIG_BOOKE_WDT */
  175. struct device_node;
  176. extern void note_scsi_host(struct device_node *, void *);
  177. extern struct task_struct *__switch_to(struct task_struct *,
  178. struct task_struct *);
  179. #define switch_to(prev, next, last) ((last) = __switch_to((prev), (next)))
  180. struct thread_struct;
  181. extern struct task_struct *_switch(struct thread_struct *prev,
  182. struct thread_struct *next);
  183. extern unsigned int rtas_data;
  184. extern int mem_init_done; /* set on boot once kmalloc can be called */
  185. extern int init_bootmem_done; /* set on !NUMA once bootmem is available */
  186. extern unsigned long memory_limit;
  187. extern unsigned long klimit;
  188. extern void *alloc_maybe_bootmem(size_t size, gfp_t mask);
  189. extern void *zalloc_maybe_bootmem(size_t size, gfp_t mask);
  190. extern int powersave_nap; /* set if nap mode can be used in idle loop */
  191. /*
  192. * Atomic exchange
  193. *
  194. * Changes the memory location '*ptr' to be val and returns
  195. * the previous value stored there.
  196. */
  197. static __always_inline unsigned long
  198. __xchg_u32(volatile void *p, unsigned long val)
  199. {
  200. unsigned long prev;
  201. __asm__ __volatile__(
  202. LWSYNC_ON_SMP
  203. "1: lwarx %0,0,%2 \n"
  204. PPC405_ERR77(0,%2)
  205. " stwcx. %3,0,%2 \n\
  206. bne- 1b"
  207. ISYNC_ON_SMP
  208. : "=&r" (prev), "+m" (*(volatile unsigned int *)p)
  209. : "r" (p), "r" (val)
  210. : "cc", "memory");
  211. return prev;
  212. }
  213. /*
  214. * Atomic exchange
  215. *
  216. * Changes the memory location '*ptr' to be val and returns
  217. * the previous value stored there.
  218. */
  219. static __always_inline unsigned long
  220. __xchg_u32_local(volatile void *p, unsigned long val)
  221. {
  222. unsigned long prev;
  223. __asm__ __volatile__(
  224. "1: lwarx %0,0,%2 \n"
  225. PPC405_ERR77(0,%2)
  226. " stwcx. %3,0,%2 \n\
  227. bne- 1b"
  228. : "=&r" (prev), "+m" (*(volatile unsigned int *)p)
  229. : "r" (p), "r" (val)
  230. : "cc", "memory");
  231. return prev;
  232. }
  233. #ifdef CONFIG_PPC64
  234. static __always_inline unsigned long
  235. __xchg_u64(volatile void *p, unsigned long val)
  236. {
  237. unsigned long prev;
  238. __asm__ __volatile__(
  239. LWSYNC_ON_SMP
  240. "1: ldarx %0,0,%2 \n"
  241. PPC405_ERR77(0,%2)
  242. " stdcx. %3,0,%2 \n\
  243. bne- 1b"
  244. ISYNC_ON_SMP
  245. : "=&r" (prev), "+m" (*(volatile unsigned long *)p)
  246. : "r" (p), "r" (val)
  247. : "cc", "memory");
  248. return prev;
  249. }
  250. static __always_inline unsigned long
  251. __xchg_u64_local(volatile void *p, unsigned long val)
  252. {
  253. unsigned long prev;
  254. __asm__ __volatile__(
  255. "1: ldarx %0,0,%2 \n"
  256. PPC405_ERR77(0,%2)
  257. " stdcx. %3,0,%2 \n\
  258. bne- 1b"
  259. : "=&r" (prev), "+m" (*(volatile unsigned long *)p)
  260. : "r" (p), "r" (val)
  261. : "cc", "memory");
  262. return prev;
  263. }
  264. #endif
  265. /*
  266. * This function doesn't exist, so you'll get a linker error
  267. * if something tries to do an invalid xchg().
  268. */
  269. extern void __xchg_called_with_bad_pointer(void);
  270. static __always_inline unsigned long
  271. __xchg(volatile void *ptr, unsigned long x, unsigned int size)
  272. {
  273. switch (size) {
  274. case 4:
  275. return __xchg_u32(ptr, x);
  276. #ifdef CONFIG_PPC64
  277. case 8:
  278. return __xchg_u64(ptr, x);
  279. #endif
  280. }
  281. __xchg_called_with_bad_pointer();
  282. return x;
  283. }
  284. static __always_inline unsigned long
  285. __xchg_local(volatile void *ptr, unsigned long x, unsigned int size)
  286. {
  287. switch (size) {
  288. case 4:
  289. return __xchg_u32_local(ptr, x);
  290. #ifdef CONFIG_PPC64
  291. case 8:
  292. return __xchg_u64_local(ptr, x);
  293. #endif
  294. }
  295. __xchg_called_with_bad_pointer();
  296. return x;
  297. }
  298. #define xchg(ptr,x) \
  299. ({ \
  300. __typeof__(*(ptr)) _x_ = (x); \
  301. (__typeof__(*(ptr))) __xchg((ptr), (unsigned long)_x_, sizeof(*(ptr))); \
  302. })
  303. #define xchg_local(ptr,x) \
  304. ({ \
  305. __typeof__(*(ptr)) _x_ = (x); \
  306. (__typeof__(*(ptr))) __xchg_local((ptr), \
  307. (unsigned long)_x_, sizeof(*(ptr))); \
  308. })
  309. /*
  310. * Compare and exchange - if *p == old, set it to new,
  311. * and return the old value of *p.
  312. */
  313. #define __HAVE_ARCH_CMPXCHG 1
  314. static __always_inline unsigned long
  315. __cmpxchg_u32(volatile unsigned int *p, unsigned long old, unsigned long new)
  316. {
  317. unsigned int prev;
  318. __asm__ __volatile__ (
  319. LWSYNC_ON_SMP
  320. "1: lwarx %0,0,%2 # __cmpxchg_u32\n\
  321. cmpw 0,%0,%3\n\
  322. bne- 2f\n"
  323. PPC405_ERR77(0,%2)
  324. " stwcx. %4,0,%2\n\
  325. bne- 1b"
  326. ISYNC_ON_SMP
  327. "\n\
  328. 2:"
  329. : "=&r" (prev), "+m" (*p)
  330. : "r" (p), "r" (old), "r" (new)
  331. : "cc", "memory");
  332. return prev;
  333. }
  334. static __always_inline unsigned long
  335. __cmpxchg_u32_local(volatile unsigned int *p, unsigned long old,
  336. unsigned long new)
  337. {
  338. unsigned int prev;
  339. __asm__ __volatile__ (
  340. "1: lwarx %0,0,%2 # __cmpxchg_u32\n\
  341. cmpw 0,%0,%3\n\
  342. bne- 2f\n"
  343. PPC405_ERR77(0,%2)
  344. " stwcx. %4,0,%2\n\
  345. bne- 1b"
  346. "\n\
  347. 2:"
  348. : "=&r" (prev), "+m" (*p)
  349. : "r" (p), "r" (old), "r" (new)
  350. : "cc", "memory");
  351. return prev;
  352. }
  353. #ifdef CONFIG_PPC64
  354. static __always_inline unsigned long
  355. __cmpxchg_u64(volatile unsigned long *p, unsigned long old, unsigned long new)
  356. {
  357. unsigned long prev;
  358. __asm__ __volatile__ (
  359. LWSYNC_ON_SMP
  360. "1: ldarx %0,0,%2 # __cmpxchg_u64\n\
  361. cmpd 0,%0,%3\n\
  362. bne- 2f\n\
  363. stdcx. %4,0,%2\n\
  364. bne- 1b"
  365. ISYNC_ON_SMP
  366. "\n\
  367. 2:"
  368. : "=&r" (prev), "+m" (*p)
  369. : "r" (p), "r" (old), "r" (new)
  370. : "cc", "memory");
  371. return prev;
  372. }
  373. static __always_inline unsigned long
  374. __cmpxchg_u64_local(volatile unsigned long *p, unsigned long old,
  375. unsigned long new)
  376. {
  377. unsigned long prev;
  378. __asm__ __volatile__ (
  379. "1: ldarx %0,0,%2 # __cmpxchg_u64\n\
  380. cmpd 0,%0,%3\n\
  381. bne- 2f\n\
  382. stdcx. %4,0,%2\n\
  383. bne- 1b"
  384. "\n\
  385. 2:"
  386. : "=&r" (prev), "+m" (*p)
  387. : "r" (p), "r" (old), "r" (new)
  388. : "cc", "memory");
  389. return prev;
  390. }
  391. #endif
  392. /* This function doesn't exist, so you'll get a linker error
  393. if something tries to do an invalid cmpxchg(). */
  394. extern void __cmpxchg_called_with_bad_pointer(void);
  395. static __always_inline unsigned long
  396. __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new,
  397. unsigned int size)
  398. {
  399. switch (size) {
  400. case 4:
  401. return __cmpxchg_u32(ptr, old, new);
  402. #ifdef CONFIG_PPC64
  403. case 8:
  404. return __cmpxchg_u64(ptr, old, new);
  405. #endif
  406. }
  407. __cmpxchg_called_with_bad_pointer();
  408. return old;
  409. }
  410. static __always_inline unsigned long
  411. __cmpxchg_local(volatile void *ptr, unsigned long old, unsigned long new,
  412. unsigned int size)
  413. {
  414. switch (size) {
  415. case 4:
  416. return __cmpxchg_u32_local(ptr, old, new);
  417. #ifdef CONFIG_PPC64
  418. case 8:
  419. return __cmpxchg_u64_local(ptr, old, new);
  420. #endif
  421. }
  422. __cmpxchg_called_with_bad_pointer();
  423. return old;
  424. }
  425. #define cmpxchg(ptr, o, n) \
  426. ({ \
  427. __typeof__(*(ptr)) _o_ = (o); \
  428. __typeof__(*(ptr)) _n_ = (n); \
  429. (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
  430. (unsigned long)_n_, sizeof(*(ptr))); \
  431. })
  432. #define cmpxchg_local(ptr, o, n) \
  433. ({ \
  434. __typeof__(*(ptr)) _o_ = (o); \
  435. __typeof__(*(ptr)) _n_ = (n); \
  436. (__typeof__(*(ptr))) __cmpxchg_local((ptr), (unsigned long)_o_, \
  437. (unsigned long)_n_, sizeof(*(ptr))); \
  438. })
  439. #ifdef CONFIG_PPC64
  440. /*
  441. * We handle most unaligned accesses in hardware. On the other hand
  442. * unaligned DMA can be very expensive on some ppc64 IO chips (it does
  443. * powers of 2 writes until it reaches sufficient alignment).
  444. *
  445. * Based on this we disable the IP header alignment in network drivers.
  446. * We also modify NET_SKB_PAD to be a cacheline in size, thus maintaining
  447. * cacheline alignment of buffers.
  448. */
  449. #define NET_IP_ALIGN 0
  450. #define NET_SKB_PAD L1_CACHE_BYTES
  451. #define cmpxchg64(ptr, o, n) \
  452. ({ \
  453. BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
  454. cmpxchg((ptr), (o), (n)); \
  455. })
  456. #define cmpxchg64_local(ptr, o, n) \
  457. ({ \
  458. BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
  459. cmpxchg_local((ptr), (o), (n)); \
  460. })
  461. #else
  462. #include <asm-generic/cmpxchg-local.h>
  463. #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
  464. #endif
  465. #define arch_align_stack(x) (x)
  466. /* Used in very early kernel initialization. */
  467. extern unsigned long reloc_offset(void);
  468. extern unsigned long add_reloc_offset(unsigned long);
  469. extern void reloc_got2(unsigned long);
  470. #define PTRRELOC(x) ((typeof(x)) add_reloc_offset((unsigned long)(x)))
  471. #ifdef CONFIG_VIRT_CPU_ACCOUNTING
  472. extern void account_system_vtime(struct task_struct *);
  473. #endif
  474. extern struct dentry *powerpc_debugfs_root;
  475. #endif /* __KERNEL__ */
  476. #endif /* _ASM_POWERPC_SYSTEM_H */