system.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. #ifndef __ALPHA_SYSTEM_H
  2. #define __ALPHA_SYSTEM_H
  3. #include <linux/config.h>
  4. #include <asm/pal.h>
  5. #include <asm/page.h>
  6. /*
  7. * System defines.. Note that this is included both from .c and .S
  8. * files, so it does only defines, not any C code.
  9. */
  10. /*
  11. * We leave one page for the initial stack page, and one page for
  12. * the initial process structure. Also, the console eats 3 MB for
  13. * the initial bootloader (one of which we can reclaim later).
  14. */
  15. #define BOOT_PCB 0x20000000
  16. #define BOOT_ADDR 0x20000000
  17. /* Remove when official MILO sources have ELF support: */
  18. #define BOOT_SIZE (16*1024)
  19. #ifdef CONFIG_ALPHA_LEGACY_START_ADDRESS
  20. #define KERNEL_START_PHYS 0x300000 /* Old bootloaders hardcoded this. */
  21. #else
  22. #define KERNEL_START_PHYS 0x1000000 /* required: Wildfire/Titan/Marvel */
  23. #endif
  24. #define KERNEL_START (PAGE_OFFSET+KERNEL_START_PHYS)
  25. #define SWAPPER_PGD KERNEL_START
  26. #define INIT_STACK (PAGE_OFFSET+KERNEL_START_PHYS+0x02000)
  27. #define EMPTY_PGT (PAGE_OFFSET+KERNEL_START_PHYS+0x04000)
  28. #define EMPTY_PGE (PAGE_OFFSET+KERNEL_START_PHYS+0x08000)
  29. #define ZERO_PGE (PAGE_OFFSET+KERNEL_START_PHYS+0x0A000)
  30. #define START_ADDR (PAGE_OFFSET+KERNEL_START_PHYS+0x10000)
  31. /*
  32. * This is setup by the secondary bootstrap loader. Because
  33. * the zero page is zeroed out as soon as the vm system is
  34. * initialized, we need to copy things out into a more permanent
  35. * place.
  36. */
  37. #define PARAM ZERO_PGE
  38. #define COMMAND_LINE ((char*)(PARAM + 0x0000))
  39. #define INITRD_START (*(unsigned long *) (PARAM+0x100))
  40. #define INITRD_SIZE (*(unsigned long *) (PARAM+0x108))
  41. #ifndef __ASSEMBLY__
  42. #include <linux/kernel.h>
  43. /*
  44. * This is the logout header that should be common to all platforms
  45. * (assuming they are running OSF/1 PALcode, I guess).
  46. */
  47. struct el_common {
  48. unsigned int size; /* size in bytes of logout area */
  49. unsigned int sbz1 : 30; /* should be zero */
  50. unsigned int err2 : 1; /* second error */
  51. unsigned int retry : 1; /* retry flag */
  52. unsigned int proc_offset; /* processor-specific offset */
  53. unsigned int sys_offset; /* system-specific offset */
  54. unsigned int code; /* machine check code */
  55. unsigned int frame_rev; /* frame revision */
  56. };
  57. /* Machine Check Frame for uncorrectable errors (Large format)
  58. * --- This is used to log uncorrectable errors such as
  59. * double bit ECC errors.
  60. * --- These errors are detected by both processor and systems.
  61. */
  62. struct el_common_EV5_uncorrectable_mcheck {
  63. unsigned long shadow[8]; /* Shadow reg. 8-14, 25 */
  64. unsigned long paltemp[24]; /* PAL TEMP REGS. */
  65. unsigned long exc_addr; /* Address of excepting instruction*/
  66. unsigned long exc_sum; /* Summary of arithmetic traps. */
  67. unsigned long exc_mask; /* Exception mask (from exc_sum). */
  68. unsigned long pal_base; /* Base address for PALcode. */
  69. unsigned long isr; /* Interrupt Status Reg. */
  70. unsigned long icsr; /* CURRENT SETUP OF EV5 IBOX */
  71. unsigned long ic_perr_stat; /* I-CACHE Reg. <11> set Data parity
  72. <12> set TAG parity*/
  73. unsigned long dc_perr_stat; /* D-CACHE error Reg. Bits set to 1:
  74. <2> Data error in bank 0
  75. <3> Data error in bank 1
  76. <4> Tag error in bank 0
  77. <5> Tag error in bank 1 */
  78. unsigned long va; /* Effective VA of fault or miss. */
  79. unsigned long mm_stat; /* Holds the reason for D-stream
  80. fault or D-cache parity errors */
  81. unsigned long sc_addr; /* Address that was being accessed
  82. when EV5 detected Secondary cache
  83. failure. */
  84. unsigned long sc_stat; /* Helps determine if the error was
  85. TAG/Data parity(Secondary Cache)*/
  86. unsigned long bc_tag_addr; /* Contents of EV5 BC_TAG_ADDR */
  87. unsigned long ei_addr; /* Physical address of any transfer
  88. that is logged in EV5 EI_STAT */
  89. unsigned long fill_syndrome; /* For correcting ECC errors. */
  90. unsigned long ei_stat; /* Helps identify reason of any
  91. processor uncorrectable error
  92. at its external interface. */
  93. unsigned long ld_lock; /* Contents of EV5 LD_LOCK register*/
  94. };
  95. struct el_common_EV6_mcheck {
  96. unsigned int FrameSize; /* Bytes, including this field */
  97. unsigned int FrameFlags; /* <31> = Retry, <30> = Second Error */
  98. unsigned int CpuOffset; /* Offset to CPU-specific info */
  99. unsigned int SystemOffset; /* Offset to system-specific info */
  100. unsigned int MCHK_Code;
  101. unsigned int MCHK_Frame_Rev;
  102. unsigned long I_STAT; /* EV6 Internal Processor Registers */
  103. unsigned long DC_STAT; /* (See the 21264 Spec) */
  104. unsigned long C_ADDR;
  105. unsigned long DC1_SYNDROME;
  106. unsigned long DC0_SYNDROME;
  107. unsigned long C_STAT;
  108. unsigned long C_STS;
  109. unsigned long MM_STAT;
  110. unsigned long EXC_ADDR;
  111. unsigned long IER_CM;
  112. unsigned long ISUM;
  113. unsigned long RESERVED0;
  114. unsigned long PAL_BASE;
  115. unsigned long I_CTL;
  116. unsigned long PCTX;
  117. };
  118. extern void halt(void) __attribute__((noreturn));
  119. #define __halt() __asm__ __volatile__ ("call_pal %0 #halt" : : "i" (PAL_halt))
  120. #define switch_to(P,N,L) \
  121. do { \
  122. (L) = alpha_switch_to(virt_to_phys(&(N)->thread_info->pcb), (P)); \
  123. check_mmu_context(); \
  124. } while (0)
  125. struct task_struct;
  126. extern struct task_struct *alpha_switch_to(unsigned long, struct task_struct*);
  127. #define mb() \
  128. __asm__ __volatile__("mb": : :"memory")
  129. #define rmb() \
  130. __asm__ __volatile__("mb": : :"memory")
  131. #define wmb() \
  132. __asm__ __volatile__("wmb": : :"memory")
  133. #define read_barrier_depends() \
  134. __asm__ __volatile__("mb": : :"memory")
  135. #ifdef CONFIG_SMP
  136. #define smp_mb() mb()
  137. #define smp_rmb() rmb()
  138. #define smp_wmb() wmb()
  139. #define smp_read_barrier_depends() read_barrier_depends()
  140. #else
  141. #define smp_mb() barrier()
  142. #define smp_rmb() barrier()
  143. #define smp_wmb() barrier()
  144. #define smp_read_barrier_depends() barrier()
  145. #endif
  146. #define set_mb(var, value) \
  147. do { var = value; mb(); } while (0)
  148. #define set_wmb(var, value) \
  149. do { var = value; wmb(); } while (0)
  150. #define imb() \
  151. __asm__ __volatile__ ("call_pal %0 #imb" : : "i" (PAL_imb) : "memory")
  152. #define draina() \
  153. __asm__ __volatile__ ("call_pal %0 #draina" : : "i" (PAL_draina) : "memory")
  154. enum implver_enum {
  155. IMPLVER_EV4,
  156. IMPLVER_EV5,
  157. IMPLVER_EV6
  158. };
  159. #ifdef CONFIG_ALPHA_GENERIC
  160. #define implver() \
  161. ({ unsigned long __implver; \
  162. __asm__ ("implver %0" : "=r"(__implver)); \
  163. (enum implver_enum) __implver; })
  164. #else
  165. /* Try to eliminate some dead code. */
  166. #ifdef CONFIG_ALPHA_EV4
  167. #define implver() IMPLVER_EV4
  168. #endif
  169. #ifdef CONFIG_ALPHA_EV5
  170. #define implver() IMPLVER_EV5
  171. #endif
  172. #if defined(CONFIG_ALPHA_EV6)
  173. #define implver() IMPLVER_EV6
  174. #endif
  175. #endif
  176. enum amask_enum {
  177. AMASK_BWX = (1UL << 0),
  178. AMASK_FIX = (1UL << 1),
  179. AMASK_CIX = (1UL << 2),
  180. AMASK_MAX = (1UL << 8),
  181. AMASK_PRECISE_TRAP = (1UL << 9),
  182. };
  183. #define amask(mask) \
  184. ({ unsigned long __amask, __input = (mask); \
  185. __asm__ ("amask %1,%0" : "=r"(__amask) : "rI"(__input)); \
  186. __amask; })
  187. #define __CALL_PAL_R0(NAME, TYPE) \
  188. static inline TYPE NAME(void) \
  189. { \
  190. register TYPE __r0 __asm__("$0"); \
  191. __asm__ __volatile__( \
  192. "call_pal %1 # " #NAME \
  193. :"=r" (__r0) \
  194. :"i" (PAL_ ## NAME) \
  195. :"$1", "$16", "$22", "$23", "$24", "$25"); \
  196. return __r0; \
  197. }
  198. #define __CALL_PAL_W1(NAME, TYPE0) \
  199. static inline void NAME(TYPE0 arg0) \
  200. { \
  201. register TYPE0 __r16 __asm__("$16") = arg0; \
  202. __asm__ __volatile__( \
  203. "call_pal %1 # "#NAME \
  204. : "=r"(__r16) \
  205. : "i"(PAL_ ## NAME), "0"(__r16) \
  206. : "$1", "$22", "$23", "$24", "$25"); \
  207. }
  208. #define __CALL_PAL_W2(NAME, TYPE0, TYPE1) \
  209. static inline void NAME(TYPE0 arg0, TYPE1 arg1) \
  210. { \
  211. register TYPE0 __r16 __asm__("$16") = arg0; \
  212. register TYPE1 __r17 __asm__("$17") = arg1; \
  213. __asm__ __volatile__( \
  214. "call_pal %2 # "#NAME \
  215. : "=r"(__r16), "=r"(__r17) \
  216. : "i"(PAL_ ## NAME), "0"(__r16), "1"(__r17) \
  217. : "$1", "$22", "$23", "$24", "$25"); \
  218. }
  219. #define __CALL_PAL_RW1(NAME, RTYPE, TYPE0) \
  220. static inline RTYPE NAME(TYPE0 arg0) \
  221. { \
  222. register RTYPE __r0 __asm__("$0"); \
  223. register TYPE0 __r16 __asm__("$16") = arg0; \
  224. __asm__ __volatile__( \
  225. "call_pal %2 # "#NAME \
  226. : "=r"(__r16), "=r"(__r0) \
  227. : "i"(PAL_ ## NAME), "0"(__r16) \
  228. : "$1", "$22", "$23", "$24", "$25"); \
  229. return __r0; \
  230. }
  231. #define __CALL_PAL_RW2(NAME, RTYPE, TYPE0, TYPE1) \
  232. static inline RTYPE NAME(TYPE0 arg0, TYPE1 arg1) \
  233. { \
  234. register RTYPE __r0 __asm__("$0"); \
  235. register TYPE0 __r16 __asm__("$16") = arg0; \
  236. register TYPE1 __r17 __asm__("$17") = arg1; \
  237. __asm__ __volatile__( \
  238. "call_pal %3 # "#NAME \
  239. : "=r"(__r16), "=r"(__r17), "=r"(__r0) \
  240. : "i"(PAL_ ## NAME), "0"(__r16), "1"(__r17) \
  241. : "$1", "$22", "$23", "$24", "$25"); \
  242. return __r0; \
  243. }
  244. __CALL_PAL_W1(cflush, unsigned long);
  245. __CALL_PAL_R0(rdmces, unsigned long);
  246. __CALL_PAL_R0(rdps, unsigned long);
  247. __CALL_PAL_R0(rdusp, unsigned long);
  248. __CALL_PAL_RW1(swpipl, unsigned long, unsigned long);
  249. __CALL_PAL_R0(whami, unsigned long);
  250. __CALL_PAL_W2(wrent, void*, unsigned long);
  251. __CALL_PAL_W1(wripir, unsigned long);
  252. __CALL_PAL_W1(wrkgp, unsigned long);
  253. __CALL_PAL_W1(wrmces, unsigned long);
  254. __CALL_PAL_RW2(wrperfmon, unsigned long, unsigned long, unsigned long);
  255. __CALL_PAL_W1(wrusp, unsigned long);
  256. __CALL_PAL_W1(wrvptptr, unsigned long);
  257. #define IPL_MIN 0
  258. #define IPL_SW0 1
  259. #define IPL_SW1 2
  260. #define IPL_DEV0 3
  261. #define IPL_DEV1 4
  262. #define IPL_TIMER 5
  263. #define IPL_PERF 6
  264. #define IPL_POWERFAIL 6
  265. #define IPL_MCHECK 7
  266. #define IPL_MAX 7
  267. #ifdef CONFIG_ALPHA_BROKEN_IRQ_MASK
  268. #undef IPL_MIN
  269. #define IPL_MIN __min_ipl
  270. extern int __min_ipl;
  271. #endif
  272. #define getipl() (rdps() & 7)
  273. #define setipl(ipl) ((void) swpipl(ipl))
  274. #define local_irq_disable() do { setipl(IPL_MAX); barrier(); } while(0)
  275. #define local_irq_enable() do { barrier(); setipl(IPL_MIN); } while(0)
  276. #define local_save_flags(flags) ((flags) = rdps())
  277. #define local_irq_save(flags) do { (flags) = swpipl(IPL_MAX); barrier(); } while(0)
  278. #define local_irq_restore(flags) do { barrier(); setipl(flags); barrier(); } while(0)
  279. #define irqs_disabled() (getipl() == IPL_MAX)
  280. /*
  281. * TB routines..
  282. */
  283. #define __tbi(nr,arg,arg1...) \
  284. ({ \
  285. register unsigned long __r16 __asm__("$16") = (nr); \
  286. register unsigned long __r17 __asm__("$17"); arg; \
  287. __asm__ __volatile__( \
  288. "call_pal %3 #__tbi" \
  289. :"=r" (__r16),"=r" (__r17) \
  290. :"0" (__r16),"i" (PAL_tbi) ,##arg1 \
  291. :"$0", "$1", "$22", "$23", "$24", "$25"); \
  292. })
  293. #define tbi(x,y) __tbi(x,__r17=(y),"1" (__r17))
  294. #define tbisi(x) __tbi(1,__r17=(x),"1" (__r17))
  295. #define tbisd(x) __tbi(2,__r17=(x),"1" (__r17))
  296. #define tbis(x) __tbi(3,__r17=(x),"1" (__r17))
  297. #define tbiap() __tbi(-1, /* no second argument */)
  298. #define tbia() __tbi(-2, /* no second argument */)
  299. /*
  300. * Atomic exchange.
  301. * Since it can be used to implement critical sections
  302. * it must clobber "memory" (also for interrupts in UP).
  303. */
  304. static inline unsigned long
  305. __xchg_u8(volatile char *m, unsigned long val)
  306. {
  307. unsigned long ret, tmp, addr64;
  308. __asm__ __volatile__(
  309. " andnot %4,7,%3\n"
  310. " insbl %1,%4,%1\n"
  311. "1: ldq_l %2,0(%3)\n"
  312. " extbl %2,%4,%0\n"
  313. " mskbl %2,%4,%2\n"
  314. " or %1,%2,%2\n"
  315. " stq_c %2,0(%3)\n"
  316. " beq %2,2f\n"
  317. #ifdef CONFIG_SMP
  318. " mb\n"
  319. #endif
  320. ".subsection 2\n"
  321. "2: br 1b\n"
  322. ".previous"
  323. : "=&r" (ret), "=&r" (val), "=&r" (tmp), "=&r" (addr64)
  324. : "r" ((long)m), "1" (val) : "memory");
  325. return ret;
  326. }
  327. static inline unsigned long
  328. __xchg_u16(volatile short *m, unsigned long val)
  329. {
  330. unsigned long ret, tmp, addr64;
  331. __asm__ __volatile__(
  332. " andnot %4,7,%3\n"
  333. " inswl %1,%4,%1\n"
  334. "1: ldq_l %2,0(%3)\n"
  335. " extwl %2,%4,%0\n"
  336. " mskwl %2,%4,%2\n"
  337. " or %1,%2,%2\n"
  338. " stq_c %2,0(%3)\n"
  339. " beq %2,2f\n"
  340. #ifdef CONFIG_SMP
  341. " mb\n"
  342. #endif
  343. ".subsection 2\n"
  344. "2: br 1b\n"
  345. ".previous"
  346. : "=&r" (ret), "=&r" (val), "=&r" (tmp), "=&r" (addr64)
  347. : "r" ((long)m), "1" (val) : "memory");
  348. return ret;
  349. }
  350. static inline unsigned long
  351. __xchg_u32(volatile int *m, unsigned long val)
  352. {
  353. unsigned long dummy;
  354. __asm__ __volatile__(
  355. "1: ldl_l %0,%4\n"
  356. " bis $31,%3,%1\n"
  357. " stl_c %1,%2\n"
  358. " beq %1,2f\n"
  359. #ifdef CONFIG_SMP
  360. " mb\n"
  361. #endif
  362. ".subsection 2\n"
  363. "2: br 1b\n"
  364. ".previous"
  365. : "=&r" (val), "=&r" (dummy), "=m" (*m)
  366. : "rI" (val), "m" (*m) : "memory");
  367. return val;
  368. }
  369. static inline unsigned long
  370. __xchg_u64(volatile long *m, unsigned long val)
  371. {
  372. unsigned long dummy;
  373. __asm__ __volatile__(
  374. "1: ldq_l %0,%4\n"
  375. " bis $31,%3,%1\n"
  376. " stq_c %1,%2\n"
  377. " beq %1,2f\n"
  378. #ifdef CONFIG_SMP
  379. " mb\n"
  380. #endif
  381. ".subsection 2\n"
  382. "2: br 1b\n"
  383. ".previous"
  384. : "=&r" (val), "=&r" (dummy), "=m" (*m)
  385. : "rI" (val), "m" (*m) : "memory");
  386. return val;
  387. }
  388. /* This function doesn't exist, so you'll get a linker error
  389. if something tries to do an invalid xchg(). */
  390. extern void __xchg_called_with_bad_pointer(void);
  391. #define __xchg(ptr, x, size) \
  392. ({ \
  393. unsigned long __xchg__res; \
  394. volatile void *__xchg__ptr = (ptr); \
  395. switch (size) { \
  396. case 1: __xchg__res = __xchg_u8(__xchg__ptr, x); break; \
  397. case 2: __xchg__res = __xchg_u16(__xchg__ptr, x); break; \
  398. case 4: __xchg__res = __xchg_u32(__xchg__ptr, x); break; \
  399. case 8: __xchg__res = __xchg_u64(__xchg__ptr, x); break; \
  400. default: __xchg_called_with_bad_pointer(); __xchg__res = x; \
  401. } \
  402. __xchg__res; \
  403. })
  404. #define xchg(ptr,x) \
  405. ({ \
  406. __typeof__(*(ptr)) _x_ = (x); \
  407. (__typeof__(*(ptr))) __xchg((ptr), (unsigned long)_x_, sizeof(*(ptr))); \
  408. })
  409. #define tas(ptr) (xchg((ptr),1))
  410. /*
  411. * Atomic compare and exchange. Compare OLD with MEM, if identical,
  412. * store NEW in MEM. Return the initial value in MEM. Success is
  413. * indicated by comparing RETURN with OLD.
  414. *
  415. * The memory barrier should be placed in SMP only when we actually
  416. * make the change. If we don't change anything (so if the returned
  417. * prev is equal to old) then we aren't acquiring anything new and
  418. * we don't need any memory barrier as far I can tell.
  419. */
  420. #define __HAVE_ARCH_CMPXCHG 1
  421. static inline unsigned long
  422. __cmpxchg_u8(volatile char *m, long old, long new)
  423. {
  424. unsigned long prev, tmp, cmp, addr64;
  425. __asm__ __volatile__(
  426. " andnot %5,7,%4\n"
  427. " insbl %1,%5,%1\n"
  428. "1: ldq_l %2,0(%4)\n"
  429. " extbl %2,%5,%0\n"
  430. " cmpeq %0,%6,%3\n"
  431. " beq %3,2f\n"
  432. " mskbl %2,%5,%2\n"
  433. " or %1,%2,%2\n"
  434. " stq_c %2,0(%4)\n"
  435. " beq %2,3f\n"
  436. #ifdef CONFIG_SMP
  437. " mb\n"
  438. #endif
  439. "2:\n"
  440. ".subsection 2\n"
  441. "3: br 1b\n"
  442. ".previous"
  443. : "=&r" (prev), "=&r" (new), "=&r" (tmp), "=&r" (cmp), "=&r" (addr64)
  444. : "r" ((long)m), "Ir" (old), "1" (new) : "memory");
  445. return prev;
  446. }
  447. static inline unsigned long
  448. __cmpxchg_u16(volatile short *m, long old, long new)
  449. {
  450. unsigned long prev, tmp, cmp, addr64;
  451. __asm__ __volatile__(
  452. " andnot %5,7,%4\n"
  453. " inswl %1,%5,%1\n"
  454. "1: ldq_l %2,0(%4)\n"
  455. " extwl %2,%5,%0\n"
  456. " cmpeq %0,%6,%3\n"
  457. " beq %3,2f\n"
  458. " mskwl %2,%5,%2\n"
  459. " or %1,%2,%2\n"
  460. " stq_c %2,0(%4)\n"
  461. " beq %2,3f\n"
  462. #ifdef CONFIG_SMP
  463. " mb\n"
  464. #endif
  465. "2:\n"
  466. ".subsection 2\n"
  467. "3: br 1b\n"
  468. ".previous"
  469. : "=&r" (prev), "=&r" (new), "=&r" (tmp), "=&r" (cmp), "=&r" (addr64)
  470. : "r" ((long)m), "Ir" (old), "1" (new) : "memory");
  471. return prev;
  472. }
  473. static inline unsigned long
  474. __cmpxchg_u32(volatile int *m, int old, int new)
  475. {
  476. unsigned long prev, cmp;
  477. __asm__ __volatile__(
  478. "1: ldl_l %0,%5\n"
  479. " cmpeq %0,%3,%1\n"
  480. " beq %1,2f\n"
  481. " mov %4,%1\n"
  482. " stl_c %1,%2\n"
  483. " beq %1,3f\n"
  484. #ifdef CONFIG_SMP
  485. " mb\n"
  486. #endif
  487. "2:\n"
  488. ".subsection 2\n"
  489. "3: br 1b\n"
  490. ".previous"
  491. : "=&r"(prev), "=&r"(cmp), "=m"(*m)
  492. : "r"((long) old), "r"(new), "m"(*m) : "memory");
  493. return prev;
  494. }
  495. static inline unsigned long
  496. __cmpxchg_u64(volatile long *m, unsigned long old, unsigned long new)
  497. {
  498. unsigned long prev, cmp;
  499. __asm__ __volatile__(
  500. "1: ldq_l %0,%5\n"
  501. " cmpeq %0,%3,%1\n"
  502. " beq %1,2f\n"
  503. " mov %4,%1\n"
  504. " stq_c %1,%2\n"
  505. " beq %1,3f\n"
  506. #ifdef CONFIG_SMP
  507. " mb\n"
  508. #endif
  509. "2:\n"
  510. ".subsection 2\n"
  511. "3: br 1b\n"
  512. ".previous"
  513. : "=&r"(prev), "=&r"(cmp), "=m"(*m)
  514. : "r"((long) old), "r"(new), "m"(*m) : "memory");
  515. return prev;
  516. }
  517. /* This function doesn't exist, so you'll get a linker error
  518. if something tries to do an invalid cmpxchg(). */
  519. extern void __cmpxchg_called_with_bad_pointer(void);
  520. static inline unsigned long
  521. __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
  522. {
  523. switch (size) {
  524. case 1:
  525. return __cmpxchg_u8(ptr, old, new);
  526. case 2:
  527. return __cmpxchg_u16(ptr, old, new);
  528. case 4:
  529. return __cmpxchg_u32(ptr, old, new);
  530. case 8:
  531. return __cmpxchg_u64(ptr, old, new);
  532. }
  533. __cmpxchg_called_with_bad_pointer();
  534. return old;
  535. }
  536. #define cmpxchg(ptr,o,n) \
  537. ({ \
  538. __typeof__(*(ptr)) _o_ = (o); \
  539. __typeof__(*(ptr)) _n_ = (n); \
  540. (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
  541. (unsigned long)_n_, sizeof(*(ptr))); \
  542. })
  543. #endif /* __ASSEMBLY__ */
  544. #define arch_align_stack(x) (x)
  545. #endif