cvmx-scratch.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /***********************license start***************
  2. * Author: Cavium Networks
  3. *
  4. * Contact: support@caviumnetworks.com
  5. * This file is part of the OCTEON SDK
  6. *
  7. * Copyright (c) 2003-2008 Cavium Networks
  8. *
  9. * This file is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License, Version 2, as
  11. * published by the Free Software Foundation.
  12. *
  13. * This file is distributed in the hope that it will be useful, but
  14. * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
  15. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
  16. * NONINFRINGEMENT. See the GNU General Public License for more
  17. * details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this file; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  22. * or visit http://www.gnu.org/licenses/.
  23. *
  24. * This file may also be available under a different license from Cavium.
  25. * Contact Cavium Networks for more information
  26. ***********************license end**************************************/
  27. /**
  28. *
  29. * This file provides support for the processor local scratch memory.
  30. * Scratch memory is byte addressable - all addresses are byte addresses.
  31. *
  32. */
  33. #ifndef __CVMX_SCRATCH_H__
  34. #define __CVMX_SCRATCH_H__
  35. /*
  36. * Note: This define must be a long, not a long long in order to
  37. * compile without warnings for both 32bit and 64bit.
  38. */
  39. #define CVMX_SCRATCH_BASE (-32768l) /* 0xffffffffffff8000 */
  40. /**
  41. * Reads an 8 bit value from the processor local scratchpad memory.
  42. *
  43. * @address: byte address to read from
  44. *
  45. * Returns value read
  46. */
  47. static inline uint8_t cvmx_scratch_read8(uint64_t address)
  48. {
  49. return *CASTPTR(volatile uint8_t, CVMX_SCRATCH_BASE + address);
  50. }
  51. /**
  52. * Reads a 16 bit value from the processor local scratchpad memory.
  53. *
  54. * @address: byte address to read from
  55. *
  56. * Returns value read
  57. */
  58. static inline uint16_t cvmx_scratch_read16(uint64_t address)
  59. {
  60. return *CASTPTR(volatile uint16_t, CVMX_SCRATCH_BASE + address);
  61. }
  62. /**
  63. * Reads a 32 bit value from the processor local scratchpad memory.
  64. *
  65. * @address: byte address to read from
  66. *
  67. * Returns value read
  68. */
  69. static inline uint32_t cvmx_scratch_read32(uint64_t address)
  70. {
  71. return *CASTPTR(volatile uint32_t, CVMX_SCRATCH_BASE + address);
  72. }
  73. /**
  74. * Reads a 64 bit value from the processor local scratchpad memory.
  75. *
  76. * @address: byte address to read from
  77. *
  78. * Returns value read
  79. */
  80. static inline uint64_t cvmx_scratch_read64(uint64_t address)
  81. {
  82. return *CASTPTR(volatile uint64_t, CVMX_SCRATCH_BASE + address);
  83. }
  84. /**
  85. * Writes an 8 bit value to the processor local scratchpad memory.
  86. *
  87. * @address: byte address to write to
  88. * @value: value to write
  89. */
  90. static inline void cvmx_scratch_write8(uint64_t address, uint64_t value)
  91. {
  92. *CASTPTR(volatile uint8_t, CVMX_SCRATCH_BASE + address) =
  93. (uint8_t) value;
  94. }
  95. /**
  96. * Writes a 32 bit value to the processor local scratchpad memory.
  97. *
  98. * @address: byte address to write to
  99. * @value: value to write
  100. */
  101. static inline void cvmx_scratch_write16(uint64_t address, uint64_t value)
  102. {
  103. *CASTPTR(volatile uint16_t, CVMX_SCRATCH_BASE + address) =
  104. (uint16_t) value;
  105. }
  106. /**
  107. * Writes a 16 bit value to the processor local scratchpad memory.
  108. *
  109. * @address: byte address to write to
  110. * @value: value to write
  111. */
  112. static inline void cvmx_scratch_write32(uint64_t address, uint64_t value)
  113. {
  114. *CASTPTR(volatile uint32_t, CVMX_SCRATCH_BASE + address) =
  115. (uint32_t) value;
  116. }
  117. /**
  118. * Writes a 64 bit value to the processor local scratchpad memory.
  119. *
  120. * @address: byte address to write to
  121. * @value: value to write
  122. */
  123. static inline void cvmx_scratch_write64(uint64_t address, uint64_t value)
  124. {
  125. *CASTPTR(volatile uint64_t, CVMX_SCRATCH_BASE + address) = value;
  126. }
  127. #endif /* __CVMX_SCRATCH_H__ */