system.h 15 KB

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