ldcw.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __PARISC_LDCW_H
  3. #define __PARISC_LDCW_H
  4. /* Because kmalloc only guarantees 8-byte alignment for kmalloc'd data,
  5. and GCC only guarantees 8-byte alignment for stack locals, we can't
  6. be assured of 16-byte alignment for atomic lock data even if we
  7. specify "__attribute ((aligned(16)))" in the type declaration. So,
  8. we use a struct containing an array of four ints for the atomic lock
  9. type and dynamically select the 16-byte aligned int from the array
  10. for the semaphore. */
  11. /* From: "Jim Hull" <jim.hull of hp.com>
  12. I've attached a summary of the change, but basically, for PA 2.0, as
  13. long as the ",CO" (coherent operation) completer is implemented, then the
  14. 16-byte alignment requirement for ldcw and ldcd is relaxed, and instead
  15. they only require "natural" alignment (4-byte for ldcw, 8-byte for
  16. ldcd).
  17. Although the cache control hint is accepted by all PA 2.0 processors,
  18. it is only implemented on PA8800/PA8900 CPUs. Prior PA8X00 CPUs still
  19. require 16-byte alignment. If the address is unaligned, the operation
  20. of the instruction is undefined. The ldcw instruction does not generate
  21. unaligned data reference traps so misaligned accesses are not detected.
  22. This hid the problem for years. So, restore the 16-byte alignment dropped
  23. by Kyle McMartin in "Remove __ldcw_align for PA-RISC 2.0 processors". */
  24. #define __PA_LDCW_ALIGNMENT 16
  25. #define __PA_LDCW_ALIGN_ORDER 4
  26. #define __ldcw_align(a) ({ \
  27. unsigned long __ret = (unsigned long) &(a)->lock[0]; \
  28. __ret = (__ret + __PA_LDCW_ALIGNMENT - 1) \
  29. & ~(__PA_LDCW_ALIGNMENT - 1); \
  30. (volatile unsigned int *) __ret; \
  31. })
  32. #ifdef CONFIG_PA20
  33. #define __LDCW "ldcw,co"
  34. #else
  35. #define __LDCW "ldcw"
  36. #endif
  37. /* LDCW, the only atomic read-write operation PA-RISC has. *sigh*.
  38. We don't explicitly expose that "*a" may be written as reload
  39. fails to find a register in class R1_REGS when "a" needs to be
  40. reloaded when generating 64-bit PIC code. Instead, we clobber
  41. memory to indicate to the compiler that the assembly code reads
  42. or writes to items other than those listed in the input and output
  43. operands. This may pessimize the code somewhat but __ldcw is
  44. usually used within code blocks surrounded by memory barriers. */
  45. #define __ldcw(a) ({ \
  46. unsigned __ret; \
  47. __asm__ __volatile__(__LDCW " 0(%1),%0" \
  48. : "=r" (__ret) : "r" (a) : "memory"); \
  49. __ret; \
  50. })
  51. #ifdef CONFIG_SMP
  52. # define __lock_aligned __section(".data..lock_aligned") __aligned(16)
  53. #endif
  54. #endif /* __PARISC_LDCW_H */