system.h 15 KB

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