cvmx-scratch.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2020 Marvell International Ltd.
  4. *
  5. * This file provides support for the processor local scratch memory.
  6. * Scratch memory is byte addressable - all addresses are byte addresses.
  7. */
  8. #ifndef __CVMX_SCRATCH_H__
  9. #define __CVMX_SCRATCH_H__
  10. /* Note: This define must be a long, not a long long in order to compile
  11. without warnings for both 32bit and 64bit. */
  12. #define CVMX_SCRATCH_BASE (-32768l) /* 0xffffffffffff8000 */
  13. /* Scratch line for LMTST/LMTDMA on Octeon3 models */
  14. #ifdef CVMX_CAVIUM_OCTEON3
  15. #define CVMX_PKO_LMTLINE 2ull
  16. #endif
  17. /**
  18. * Reads an 8 bit value from the processor local scratchpad memory.
  19. *
  20. * @param address byte address to read from
  21. *
  22. * Return: value read
  23. */
  24. static inline u8 cvmx_scratch_read8(u64 address)
  25. {
  26. return *CASTPTR(volatile u8, CVMX_SCRATCH_BASE + address);
  27. }
  28. /**
  29. * Reads a 16 bit value from the processor local scratchpad memory.
  30. *
  31. * @param address byte address to read from
  32. *
  33. * Return: value read
  34. */
  35. static inline u16 cvmx_scratch_read16(u64 address)
  36. {
  37. return *CASTPTR(volatile u16, CVMX_SCRATCH_BASE + address);
  38. }
  39. /**
  40. * Reads a 32 bit value from the processor local scratchpad memory.
  41. *
  42. * @param address byte address to read from
  43. *
  44. * Return: value read
  45. */
  46. static inline u32 cvmx_scratch_read32(u64 address)
  47. {
  48. return *CASTPTR(volatile u32, CVMX_SCRATCH_BASE + address);
  49. }
  50. /**
  51. * Reads a 64 bit value from the processor local scratchpad memory.
  52. *
  53. * @param address byte address to read from
  54. *
  55. * Return: value read
  56. */
  57. static inline u64 cvmx_scratch_read64(u64 address)
  58. {
  59. return *CASTPTR(volatile u64, CVMX_SCRATCH_BASE + address);
  60. }
  61. /**
  62. * Writes an 8 bit value to the processor local scratchpad memory.
  63. *
  64. * @param address byte address to write to
  65. * @param value value to write
  66. */
  67. static inline void cvmx_scratch_write8(u64 address, u64 value)
  68. {
  69. *CASTPTR(volatile u8, CVMX_SCRATCH_BASE + address) = (u8)value;
  70. }
  71. /**
  72. * Writes a 32 bit value to the processor local scratchpad memory.
  73. *
  74. * @param address byte address to write to
  75. * @param value value to write
  76. */
  77. static inline void cvmx_scratch_write16(u64 address, u64 value)
  78. {
  79. *CASTPTR(volatile u16, CVMX_SCRATCH_BASE + address) = (u16)value;
  80. }
  81. /**
  82. * Writes a 16 bit value to the processor local scratchpad memory.
  83. *
  84. * @param address byte address to write to
  85. * @param value value to write
  86. */
  87. static inline void cvmx_scratch_write32(u64 address, u64 value)
  88. {
  89. *CASTPTR(volatile u32, CVMX_SCRATCH_BASE + address) = (u32)value;
  90. }
  91. /**
  92. * Writes a 64 bit value to the processor local scratchpad memory.
  93. *
  94. * @param address byte address to write to
  95. * @param value value to write
  96. */
  97. static inline void cvmx_scratch_write64(u64 address, u64 value)
  98. {
  99. *CASTPTR(volatile u64, CVMX_SCRATCH_BASE + address) = value;
  100. }
  101. #endif /* __CVMX_SCRATCH_H__ */