cvmx-l2c.h 12 KB

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