cvmx-fpa.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2020 Marvell International Ltd.
  4. *
  5. * Interface to the hardware Free Pool Allocator.
  6. */
  7. #ifndef __CVMX_FPA_H__
  8. #define __CVMX_FPA_H__
  9. #include "cvmx-scratch.h"
  10. #include "cvmx-fpa-defs.h"
  11. #include "cvmx-fpa1.h"
  12. #include "cvmx-fpa3.h"
  13. #define CVMX_FPA_MIN_BLOCK_SIZE 128
  14. #define CVMX_FPA_ALIGNMENT 128
  15. #define CVMX_FPA_POOL_NAME_LEN 16
  16. /* On CN78XX in backward-compatible mode, pool is mapped to AURA */
  17. #define CVMX_FPA_NUM_POOLS \
  18. (octeon_has_feature(OCTEON_FEATURE_FPA3) ? cvmx_fpa3_num_auras() : CVMX_FPA1_NUM_POOLS)
  19. /**
  20. * Structure to store FPA pool configuration parameters.
  21. */
  22. struct cvmx_fpa_pool_config {
  23. s64 pool_num;
  24. u64 buffer_size;
  25. u64 buffer_count;
  26. };
  27. typedef struct cvmx_fpa_pool_config cvmx_fpa_pool_config_t;
  28. /**
  29. * Return the name of the pool
  30. *
  31. * @param pool_num Pool to get the name of
  32. * Return: The name
  33. */
  34. const char *cvmx_fpa_get_name(int pool_num);
  35. /**
  36. * Initialize FPA per node
  37. */
  38. int cvmx_fpa_global_init_node(int node);
  39. /**
  40. * Enable the FPA
  41. */
  42. static inline void cvmx_fpa_enable(void)
  43. {
  44. if (!octeon_has_feature(OCTEON_FEATURE_FPA3))
  45. cvmx_fpa1_enable();
  46. else
  47. cvmx_fpa_global_init_node(cvmx_get_node_num());
  48. }
  49. /**
  50. * Disable the FPA
  51. */
  52. static inline void cvmx_fpa_disable(void)
  53. {
  54. if (!octeon_has_feature(OCTEON_FEATURE_FPA3))
  55. cvmx_fpa1_disable();
  56. /* FPA3 does not have a disable function */
  57. }
  58. /**
  59. * @INTERNAL
  60. * @deprecated OBSOLETE
  61. *
  62. * Kept for transition assistance only
  63. */
  64. static inline void cvmx_fpa_global_initialize(void)
  65. {
  66. cvmx_fpa_global_init_node(cvmx_get_node_num());
  67. }
  68. /**
  69. * @INTERNAL
  70. *
  71. * Convert FPA1 style POOL into FPA3 AURA in
  72. * backward compatibility mode.
  73. */
  74. static inline cvmx_fpa3_gaura_t cvmx_fpa1_pool_to_fpa3_aura(cvmx_fpa1_pool_t pool)
  75. {
  76. if ((octeon_has_feature(OCTEON_FEATURE_FPA3))) {
  77. unsigned int node = cvmx_get_node_num();
  78. cvmx_fpa3_gaura_t aura = __cvmx_fpa3_gaura(node, pool);
  79. return aura;
  80. }
  81. return CVMX_FPA3_INVALID_GAURA;
  82. }
  83. /**
  84. * Get a new block from the FPA
  85. *
  86. * @param pool Pool to get the block from
  87. * Return: Pointer to the block or NULL on failure
  88. */
  89. static inline void *cvmx_fpa_alloc(u64 pool)
  90. {
  91. /* FPA3 is handled differently */
  92. if ((octeon_has_feature(OCTEON_FEATURE_FPA3))) {
  93. return cvmx_fpa3_alloc(cvmx_fpa1_pool_to_fpa3_aura(pool));
  94. } else
  95. return cvmx_fpa1_alloc(pool);
  96. }
  97. /**
  98. * Asynchronously get a new block from the FPA
  99. *
  100. * The result of cvmx_fpa_async_alloc() may be retrieved using
  101. * cvmx_fpa_async_alloc_finish().
  102. *
  103. * @param scr_addr Local scratch address to put response in. This is a byte
  104. * address but must be 8 byte aligned.
  105. * @param pool Pool to get the block from
  106. */
  107. static inline void cvmx_fpa_async_alloc(u64 scr_addr, u64 pool)
  108. {
  109. if ((octeon_has_feature(OCTEON_FEATURE_FPA3))) {
  110. return cvmx_fpa3_async_alloc(scr_addr, cvmx_fpa1_pool_to_fpa3_aura(pool));
  111. } else
  112. return cvmx_fpa1_async_alloc(scr_addr, pool);
  113. }
  114. /**
  115. * Retrieve the result of cvmx_fpa_async_alloc
  116. *
  117. * @param scr_addr The Local scratch address. Must be the same value
  118. * passed to cvmx_fpa_async_alloc().
  119. *
  120. * @param pool Pool the block came from. Must be the same value
  121. * passed to cvmx_fpa_async_alloc.
  122. *
  123. * Return: Pointer to the block or NULL on failure
  124. */
  125. static inline void *cvmx_fpa_async_alloc_finish(u64 scr_addr, u64 pool)
  126. {
  127. if ((octeon_has_feature(OCTEON_FEATURE_FPA3)))
  128. return cvmx_fpa3_async_alloc_finish(scr_addr, cvmx_fpa1_pool_to_fpa3_aura(pool));
  129. else
  130. return cvmx_fpa1_async_alloc_finish(scr_addr, pool);
  131. }
  132. /**
  133. * Free a block allocated with a FPA pool.
  134. * Does NOT provide memory ordering in cases where the memory block was
  135. * modified by the core.
  136. *
  137. * @param ptr Block to free
  138. * @param pool Pool to put it in
  139. * @param num_cache_lines
  140. * Cache lines to invalidate
  141. */
  142. static inline void cvmx_fpa_free_nosync(void *ptr, u64 pool, u64 num_cache_lines)
  143. {
  144. /* FPA3 is handled differently */
  145. if ((octeon_has_feature(OCTEON_FEATURE_FPA3)))
  146. cvmx_fpa3_free_nosync(ptr, cvmx_fpa1_pool_to_fpa3_aura(pool), num_cache_lines);
  147. else
  148. cvmx_fpa1_free_nosync(ptr, pool, num_cache_lines);
  149. }
  150. /**
  151. * Free a block allocated with a FPA pool. Provides required memory
  152. * ordering in cases where memory block was modified by core.
  153. *
  154. * @param ptr Block to free
  155. * @param pool Pool to put it in
  156. * @param num_cache_lines
  157. * Cache lines to invalidate
  158. */
  159. static inline void cvmx_fpa_free(void *ptr, u64 pool, u64 num_cache_lines)
  160. {
  161. if ((octeon_has_feature(OCTEON_FEATURE_FPA3)))
  162. cvmx_fpa3_free(ptr, cvmx_fpa1_pool_to_fpa3_aura(pool), num_cache_lines);
  163. else
  164. cvmx_fpa1_free(ptr, pool, num_cache_lines);
  165. }
  166. /**
  167. * Setup a FPA pool to control a new block of memory.
  168. * This can only be called once per pool. Make sure proper
  169. * locking enforces this.
  170. *
  171. * @param pool Pool to initialize
  172. * @param name Constant character string to name this pool.
  173. * String is not copied.
  174. * @param buffer Pointer to the block of memory to use. This must be
  175. * accessible by all processors and external hardware.
  176. * @param block_size Size for each block controlled by the FPA
  177. * @param num_blocks Number of blocks
  178. *
  179. * Return: the pool number on Success,
  180. * -1 on failure
  181. */
  182. int cvmx_fpa_setup_pool(int pool, const char *name, void *buffer, u64 block_size, u64 num_blocks);
  183. int cvmx_fpa_shutdown_pool(int pool);
  184. /**
  185. * Gets the block size of buffer in specified pool
  186. * @param pool Pool to get the block size from
  187. * Return: Size of buffer in specified pool
  188. */
  189. unsigned int cvmx_fpa_get_block_size(int pool);
  190. int cvmx_fpa_is_pool_available(int pool_num);
  191. u64 cvmx_fpa_get_pool_owner(int pool_num);
  192. int cvmx_fpa_get_max_pools(void);
  193. int cvmx_fpa_get_current_count(int pool_num);
  194. int cvmx_fpa_validate_pool(int pool);
  195. #endif /* __CVM_FPA_H__ */