cvmx-l2c.h 11 KB

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