cvmx-l2c.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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. * Interface to the Level 2 Cache (L2C) control, measurement, and debugging
  30. * facilities.
  31. */
  32. #ifndef __CVMX_L2C_H__
  33. #define __CVMX_L2C_H__
  34. /* Deprecated macro, use function */
  35. #define CVMX_L2_ASSOC cvmx_l2c_get_num_assoc()
  36. /* Deprecated macro, use function */
  37. #define CVMX_L2_SET_BITS cvmx_l2c_get_set_bits()
  38. /* Deprecated macro, use function */
  39. #define CVMX_L2_SETS cvmx_l2c_get_num_sets()
  40. #define CVMX_L2C_IDX_ADDR_SHIFT 7 /* based on 128 byte cache line size */
  41. #define CVMX_L2C_IDX_MASK (cvmx_l2c_get_num_sets() - 1)
  42. /* Defines for index aliasing computations */
  43. #define CVMX_L2C_TAG_ADDR_ALIAS_SHIFT \
  44. (CVMX_L2C_IDX_ADDR_SHIFT + cvmx_l2c_get_set_bits())
  45. #define CVMX_L2C_ALIAS_MASK \
  46. (CVMX_L2C_IDX_MASK << CVMX_L2C_TAG_ADDR_ALIAS_SHIFT)
  47. union cvmx_l2c_tag {
  48. uint64_t u64;
  49. struct {
  50. uint64_t reserved:28;
  51. uint64_t V:1; /* Line valid */
  52. uint64_t D:1; /* Line dirty */
  53. uint64_t L:1; /* Line locked */
  54. uint64_t U:1; /* Use, LRU eviction */
  55. uint64_t addr:32; /* Phys mem (not all bits valid) */
  56. } s;
  57. };
  58. /* L2C Performance Counter events. */
  59. enum cvmx_l2c_event {
  60. CVMX_L2C_EVENT_CYCLES = 0,
  61. CVMX_L2C_EVENT_INSTRUCTION_MISS = 1,
  62. CVMX_L2C_EVENT_INSTRUCTION_HIT = 2,
  63. CVMX_L2C_EVENT_DATA_MISS = 3,
  64. CVMX_L2C_EVENT_DATA_HIT = 4,
  65. CVMX_L2C_EVENT_MISS = 5,
  66. CVMX_L2C_EVENT_HIT = 6,
  67. CVMX_L2C_EVENT_VICTIM_HIT = 7,
  68. CVMX_L2C_EVENT_INDEX_CONFLICT = 8,
  69. CVMX_L2C_EVENT_TAG_PROBE = 9,
  70. CVMX_L2C_EVENT_TAG_UPDATE = 10,
  71. CVMX_L2C_EVENT_TAG_COMPLETE = 11,
  72. CVMX_L2C_EVENT_TAG_DIRTY = 12,
  73. CVMX_L2C_EVENT_DATA_STORE_NOP = 13,
  74. CVMX_L2C_EVENT_DATA_STORE_READ = 14,
  75. CVMX_L2C_EVENT_DATA_STORE_WRITE = 15,
  76. CVMX_L2C_EVENT_FILL_DATA_VALID = 16,
  77. CVMX_L2C_EVENT_WRITE_REQUEST = 17,
  78. CVMX_L2C_EVENT_READ_REQUEST = 18,
  79. CVMX_L2C_EVENT_WRITE_DATA_VALID = 19,
  80. CVMX_L2C_EVENT_XMC_NOP = 20,
  81. CVMX_L2C_EVENT_XMC_LDT = 21,
  82. CVMX_L2C_EVENT_XMC_LDI = 22,
  83. CVMX_L2C_EVENT_XMC_LDD = 23,
  84. CVMX_L2C_EVENT_XMC_STF = 24,
  85. CVMX_L2C_EVENT_XMC_STT = 25,
  86. CVMX_L2C_EVENT_XMC_STP = 26,
  87. CVMX_L2C_EVENT_XMC_STC = 27,
  88. CVMX_L2C_EVENT_XMC_DWB = 28,
  89. CVMX_L2C_EVENT_XMC_PL2 = 29,
  90. CVMX_L2C_EVENT_XMC_PSL1 = 30,
  91. CVMX_L2C_EVENT_XMC_IOBLD = 31,
  92. CVMX_L2C_EVENT_XMC_IOBST = 32,
  93. CVMX_L2C_EVENT_XMC_IOBDMA = 33,
  94. CVMX_L2C_EVENT_XMC_IOBRSP = 34,
  95. CVMX_L2C_EVENT_XMC_BUS_VALID = 35,
  96. CVMX_L2C_EVENT_XMC_MEM_DATA = 36,
  97. CVMX_L2C_EVENT_XMC_REFL_DATA = 37,
  98. CVMX_L2C_EVENT_XMC_IOBRSP_DATA = 38,
  99. CVMX_L2C_EVENT_RSC_NOP = 39,
  100. CVMX_L2C_EVENT_RSC_STDN = 40,
  101. CVMX_L2C_EVENT_RSC_FILL = 41,
  102. CVMX_L2C_EVENT_RSC_REFL = 42,
  103. CVMX_L2C_EVENT_RSC_STIN = 43,
  104. CVMX_L2C_EVENT_RSC_SCIN = 44,
  105. CVMX_L2C_EVENT_RSC_SCFL = 45,
  106. CVMX_L2C_EVENT_RSC_SCDN = 46,
  107. CVMX_L2C_EVENT_RSC_DATA_VALID = 47,
  108. CVMX_L2C_EVENT_RSC_VALID_FILL = 48,
  109. CVMX_L2C_EVENT_RSC_VALID_STRSP = 49,
  110. CVMX_L2C_EVENT_RSC_VALID_REFL = 50,
  111. CVMX_L2C_EVENT_LRF_REQ = 51,
  112. CVMX_L2C_EVENT_DT_RD_ALLOC = 52,
  113. CVMX_L2C_EVENT_DT_WR_INVAL = 53
  114. };
  115. /**
  116. * Configure one of the four L2 Cache performance counters to capture event
  117. * occurences.
  118. *
  119. * @counter: The counter to configure. Range 0..3.
  120. * @event: The type of L2 Cache event occurrence to count.
  121. * @clear_on_read: When asserted, any read of the performance counter
  122. * clears the counter.
  123. *
  124. * The routine does not clear the counter.
  125. */
  126. void cvmx_l2c_config_perf(uint32_t counter,
  127. enum cvmx_l2c_event event, uint32_t clear_on_read);
  128. /**
  129. * Read the given L2 Cache performance counter. The counter must be configured
  130. * before reading, but this routine does not enforce this requirement.
  131. *
  132. * @counter: The counter to configure. Range 0..3.
  133. *
  134. * Returns The current counter value.
  135. */
  136. uint64_t cvmx_l2c_read_perf(uint32_t counter);
  137. /**
  138. * Return the L2 Cache way partitioning for a given core.
  139. *
  140. * @core: The core processor of interest.
  141. *
  142. * Returns The mask specifying the partitioning. 0 bits in mask indicates
  143. * the cache 'ways' that a core can evict from.
  144. * -1 on error
  145. */
  146. int cvmx_l2c_get_core_way_partition(uint32_t core);
  147. /**
  148. * Partitions the L2 cache for a core
  149. *
  150. * @core: The core that the partitioning applies to.
  151. *
  152. * @mask: The partitioning of the ways expressed as a binary mask. A 0
  153. * bit allows the core to evict cache lines from a way, while a
  154. * 1 bit blocks the core from evicting any lines from that
  155. * way. There must be at least one allowed way (0 bit) in the
  156. * mask.
  157. *
  158. * If any ways are blocked for all cores and the HW blocks, then those
  159. * ways will never have any cache lines evicted from them. All cores
  160. * and the hardware blocks are free to read from all ways regardless
  161. * of the partitioning.
  162. */
  163. int cvmx_l2c_set_core_way_partition(uint32_t core, uint32_t mask);
  164. /**
  165. * Return the L2 Cache way partitioning for the hw blocks.
  166. *
  167. * Returns The mask specifying the reserved way. 0 bits in mask indicates
  168. * the cache 'ways' that a core can evict from.
  169. * -1 on error
  170. */
  171. int cvmx_l2c_get_hw_way_partition(void);
  172. /**
  173. * Partitions the L2 cache for the hardware blocks.
  174. *
  175. * @mask: The partitioning of the ways expressed as a binary mask. A 0
  176. * bit allows the core to evict cache lines from a way, while a
  177. * 1 bit blocks the core from evicting any lines from that
  178. * way. There must be at least one allowed way (0 bit) in the
  179. * mask.
  180. *
  181. * If any ways are blocked for all cores and the HW blocks, then those
  182. * ways will never have any cache lines evicted from them. All cores
  183. * and the hardware blocks are free to read from all ways regardless
  184. * of the partitioning.
  185. */
  186. int cvmx_l2c_set_hw_way_partition(uint32_t mask);
  187. /**
  188. * Locks a line in the L2 cache at the specified physical address
  189. *
  190. * @addr: physical address of line to lock
  191. *
  192. * Returns 0 on success,
  193. * 1 if line not locked.
  194. */
  195. int cvmx_l2c_lock_line(uint64_t addr);
  196. /**
  197. * Locks a specified memory region in the L2 cache.
  198. *
  199. * Note that if not all lines can be locked, that means that all
  200. * but one of the ways (associations) available to the locking
  201. * core are locked. Having only 1 association available for
  202. * normal caching may have a significant adverse affect on performance.
  203. * Care should be taken to ensure that enough of the L2 cache is left
  204. * unlocked to allow for normal caching of DRAM.
  205. *
  206. * @start: Physical address of the start of the region to lock
  207. * @len: Length (in bytes) of region to lock
  208. *
  209. * Returns Number of requested lines that where not locked.
  210. * 0 on success (all locked)
  211. */
  212. int cvmx_l2c_lock_mem_region(uint64_t start, uint64_t len);
  213. /**
  214. * Unlock and flush a cache line from the L2 cache.
  215. * IMPORTANT: Must only be run by one core at a time due to use
  216. * of L2C debug features.
  217. * Note that this function will flush a matching but unlocked cache line.
  218. * (If address is not in L2, no lines are flushed.)
  219. *
  220. * @address: Physical address to unlock
  221. *
  222. * Returns 0: line not unlocked
  223. * 1: line unlocked
  224. */
  225. int cvmx_l2c_unlock_line(uint64_t address);
  226. /**
  227. * Unlocks a region of memory that is locked in the L2 cache
  228. *
  229. * @start: start physical address
  230. * @len: length (in bytes) to unlock
  231. *
  232. * Returns Number of locked lines that the call unlocked
  233. */
  234. int cvmx_l2c_unlock_mem_region(uint64_t start, uint64_t len);
  235. /**
  236. * Read the L2 controller tag for a given location in L2
  237. *
  238. * @association:
  239. * Which association to read line from
  240. * @index: Which way to read from.
  241. *
  242. * Returns l2c tag structure for line requested.
  243. */
  244. union cvmx_l2c_tag cvmx_l2c_get_tag(uint32_t association, uint32_t index);
  245. /* Wrapper around deprecated old function name */
  246. static inline union cvmx_l2c_tag cvmx_get_l2c_tag(uint32_t association,
  247. uint32_t index)
  248. {
  249. return cvmx_l2c_get_tag(association, index);
  250. }
  251. /**
  252. * Returns the cache index for a given physical address
  253. *
  254. * @addr: physical address
  255. *
  256. * Returns L2 cache index
  257. */
  258. uint32_t cvmx_l2c_address_to_index(uint64_t addr);
  259. /**
  260. * Flushes (and unlocks) the entire L2 cache.
  261. * IMPORTANT: Must only be run by one core at a time due to use
  262. * of L2C debug features.
  263. */
  264. void cvmx_l2c_flush(void);
  265. /**
  266. *
  267. * Returns Returns the size of the L2 cache in bytes,
  268. * -1 on error (unrecognized model)
  269. */
  270. int cvmx_l2c_get_cache_size_bytes(void);
  271. /**
  272. * Return the number of sets in the L2 Cache
  273. *
  274. * Returns
  275. */
  276. int cvmx_l2c_get_num_sets(void);
  277. /**
  278. * Return log base 2 of the number of sets in the L2 cache
  279. * Returns
  280. */
  281. int cvmx_l2c_get_set_bits(void);
  282. /**
  283. * Return the number of associations in the L2 Cache
  284. *
  285. * Returns
  286. */
  287. int cvmx_l2c_get_num_assoc(void);
  288. /**
  289. * Flush a line from the L2 cache
  290. * This should only be called from one core at a time, as this routine
  291. * sets the core to the 'debug' core in order to flush the line.
  292. *
  293. * @assoc: Association (or way) to flush
  294. * @index: Index to flush
  295. */
  296. void cvmx_l2c_flush_line(uint32_t assoc, uint32_t index);
  297. #endif /* __CVMX_L2C_H__ */