cache.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. /*
  2. * SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef _ROM_CACHE_H_
  7. #define _ROM_CACHE_H_
  8. #include <stdint.h>
  9. #include "esp_bit_defs.h"
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. /** \defgroup cache_apis, cache operation related apis
  14. * @brief cache apis
  15. */
  16. /** @addtogroup cache_apis
  17. * @{
  18. */
  19. #define MIN_ICACHE_SIZE 16384
  20. #define MAX_ICACHE_SIZE 16384
  21. #define MIN_ICACHE_WAYS 8
  22. #define MAX_ICACHE_WAYS 8
  23. #define MAX_CACHE_WAYS 8
  24. #define MIN_CACHE_LINE_SIZE 32
  25. #define TAG_SIZE 4
  26. #define MIN_ICACHE_BANK_NUM 1
  27. #define MAX_ICACHE_BANK_NUM 1
  28. #define CACHE_MEMORY_BANK_NUM 1
  29. #define CACHE_MEMORY_IBANK_SIZE 0x4000
  30. #define MAX_ITAG_BANK_ITEMS (MAX_ICACHE_SIZE / MAX_ICACHE_BANK_NUM / MIN_CACHE_LINE_SIZE)
  31. #define MAX_ITAG_BLOCK_ITEMS (MAX_ICACHE_SIZE / MAX_ICACHE_BANK_NUM / MAX_ICACHE_WAYS / MIN_CACHE_LINE_SIZE)
  32. #define MAX_ITAG_BANK_SIZE (MAX_ITAG_BANK_ITEMS * TAG_SIZE)
  33. #define MAX_ITAG_BLOCK_SIZE (MAX_ITAG_BLOCK_ITEMS * TAG_SIZE)
  34. typedef enum {
  35. CACHE_DCACHE = 0,
  36. CACHE_ICACHE0 = 1,
  37. CACHE_ICACHE1 = 2,
  38. } cache_t;
  39. typedef enum {
  40. CACHE_MEMORY_INVALID = 0,
  41. CACHE_MEMORY_IBANK0 = BIT(0),
  42. CACHE_MEMORY_IBANK1 = BIT(1),
  43. CACHE_MEMORY_IBANK2 = BIT(2),
  44. CACHE_MEMORY_IBANK3 = BIT(3),
  45. CACHE_MEMORY_DBANK0 = BIT(0),
  46. CACHE_MEMORY_DBANK1 = BIT(1),
  47. CACHE_MEMORY_DBANK2 = BIT(2),
  48. CACHE_MEMORY_DBANK3 = BIT(3),
  49. } cache_array_t;
  50. #define ICACHE_SIZE_16KB CACHE_SIZE_HALF
  51. #define ICACHE_SIZE_32KB CACHE_SIZE_FULL
  52. #define DCACHE_SIZE_32KB CACHE_SIZE_HALF
  53. #define DCACHE_SIZE_64KB CACHE_SIZE_FULL
  54. typedef enum {
  55. CACHE_SIZE_HALF = 0, /*!< 8KB for icache and dcache */
  56. CACHE_SIZE_FULL = 1, /*!< 16KB for icache and dcache */
  57. } cache_size_t;
  58. typedef enum {
  59. CACHE_4WAYS_ASSOC = 0, /*!< 4 way associated cache */
  60. CACHE_8WAYS_ASSOC = 1, /*!< 8 way associated cache */
  61. } cache_ways_t;
  62. typedef enum {
  63. CACHE_LINE_SIZE_16B = 0, /*!< 16 Byte cache line size */
  64. CACHE_LINE_SIZE_32B = 1, /*!< 32 Byte cache line size */
  65. CACHE_LINE_SIZE_64B = 2, /*!< 64 Byte cache line size */
  66. } cache_line_size_t;
  67. typedef enum {
  68. CACHE_AUTOLOAD_POSITIVE = 0, /*!< cache autoload step is positive */
  69. CACHE_AUTOLOAD_NEGATIVE = 1, /*!< cache autoload step is negative */
  70. } cache_autoload_order_t;
  71. #define CACHE_AUTOLOAD_STEP(i) ((i) - 1)
  72. typedef enum {
  73. CACHE_AUTOLOAD_MISS_TRIGGER = 0, /*!< autoload only triggered by cache miss */
  74. CACHE_AUTOLOAD_HIT_TRIGGER = 1, /*!< autoload only triggered by cache hit */
  75. CACHE_AUTOLOAD_BOTH_TRIGGER = 2, /*!< autoload triggered both by cache miss and hit */
  76. } cache_autoload_trigger_t;
  77. typedef enum {
  78. CACHE_FREEZE_ACK_BUSY = 0, /*!< in this mode, cache ack busy to CPU if a cache miss happens*/
  79. CACHE_FREEZE_ACK_ERROR = 1, /*!< in this mode, cache ack wrong data to CPU and trigger an error if a cache miss happens */
  80. } cache_freeze_mode_t;
  81. struct cache_mode {
  82. uint32_t cache_size; /*!< cache size in byte */
  83. uint16_t cache_line_size; /*!< cache line size in byte */
  84. uint8_t cache_ways; /*!< cache ways, always 4 */
  85. uint8_t ibus; /*!< the cache index, 0 for dcache, 1 for icache */
  86. };
  87. struct icache_tag_item {
  88. uint32_t valid:1; /*!< the tag item is valid or not */
  89. uint32_t lock:1; /*!< the cache line is locked or not */
  90. uint32_t fifo_cnt:3; /*!< fifo cnt, 0 ~ 3 for 4 ways cache */
  91. uint32_t tag:13; /*!< the tag is the high part of the cache address, however is only 16MB (8MB Ibus + 8MB Dbus) range, and without low part */
  92. uint32_t reserved:14;
  93. };
  94. struct autoload_config {
  95. uint8_t order; /*!< autoload step is positive or negative */
  96. uint8_t trigger; /*!< autoload trigger */
  97. uint8_t ena0; /*!< autoload region0 enable */
  98. uint8_t ena1; /*!< autoload region1 enable */
  99. uint32_t addr0; /*!< autoload region0 start address */
  100. uint32_t size0; /*!< autoload region0 size */
  101. uint32_t addr1; /*!< autoload region1 start address */
  102. uint32_t size1; /*!< autoload region1 size */
  103. };
  104. struct tag_group_info {
  105. struct cache_mode mode; /*!< cache and cache mode */
  106. uint32_t filter_addr; /*!< the address that used to generate the struct */
  107. uint32_t vaddr_offset; /*!< virtual address offset of the cache ways */
  108. uint32_t tag_addr[MAX_CACHE_WAYS]; /*!< tag memory address, only [0~mode.ways-1] is valid to use */
  109. uint32_t cache_memory_offset[MAX_CACHE_WAYS]; /*!< cache memory address, only [0~mode.ways-1] is valid to use */
  110. };
  111. struct lock_config {
  112. uint32_t addr; /*!< manual lock address*/
  113. uint16_t size; /*!< manual lock size*/
  114. uint16_t group; /*!< manual lock group, 0 or 1*/
  115. };
  116. struct cache_internal_stub_table {
  117. uint32_t (* icache_line_size)(void);
  118. uint32_t (* icache_addr)(uint32_t addr);
  119. uint32_t (* dcache_addr)(uint32_t addr);
  120. void (* invalidate_icache_items)(uint32_t addr, uint32_t items);
  121. void (* lock_icache_items)(uint32_t addr, uint32_t items);
  122. void (* unlock_icache_items)(uint32_t addr, uint32_t items);
  123. uint32_t (* suspend_icache_autoload)(void);
  124. void (* resume_icache_autoload)(uint32_t autoload);
  125. void (* freeze_icache_enable)(cache_freeze_mode_t mode);
  126. void (* freeze_icache_disable)(void);
  127. int (* op_addr)(uint32_t start_addr, uint32_t size, uint32_t cache_line_size, uint32_t max_sync_num, void(* cache_Iop)(uint32_t, uint32_t));
  128. };
  129. /* Defined in the interface file, default value is rom_default_cache_internal_table */
  130. extern const struct cache_internal_stub_table* rom_cache_internal_table_ptr;
  131. typedef void (* cache_op_start)(void);
  132. typedef void (* cache_op_end)(void);
  133. typedef struct {
  134. cache_op_start start;
  135. cache_op_end end;
  136. } cache_op_cb_t;
  137. /* Defined in the interface file, default value is NULL */
  138. extern const cache_op_cb_t* rom_cache_op_cb;
  139. #define ESP_ROM_ERR_INVALID_ARG 1
  140. #define MMU_SET_ADDR_ALIGNED_ERROR 2
  141. #define MMU_SET_PASE_SIZE_ERROR 3
  142. #define MMU_SET_VADDR_OUT_RANGE 4
  143. #define CACHE_OP_ICACHE_Y 1
  144. #define CACHE_OP_ICACHE_N 0
  145. /**
  146. * @brief Initialise cache mmu, mark all entries as invalid.
  147. * Please do not call this function in your SDK application.
  148. *
  149. * @param None
  150. *
  151. * @return None
  152. */
  153. void Cache_MMU_Init(void);
  154. /**
  155. * @brief Set ICache mmu mapping.
  156. * Please do not call this function in your SDK application.
  157. *
  158. * @param uint32_t ext_ram : DPORT_MMU_ACCESS_FLASH for flash, DPORT_MMU_INVALID for invalid. In
  159. * esp32c3, external memory is always flash
  160. *
  161. * @param uint32_t vaddr : virtual address in CPU address space.
  162. * Can be Iram0,Iram1,Irom0,Drom0 and AHB buses address.
  163. * Should be aligned by psize.
  164. *
  165. * @param uint32_t paddr : physical address in external memory.
  166. * Should be aligned by psize.
  167. *
  168. * @param uint32_t psize : page size of ICache, in kilobytes. Should be 64 here.
  169. *
  170. * @param uint32_t num : pages to be set.
  171. *
  172. * @param uint32_t fixed : 0 for physical pages grow with virtual pages, other for virtual pages map to same physical page.
  173. *
  174. * @return uint32_t: error status
  175. * 0 : mmu set success
  176. * 2 : vaddr or paddr is not aligned
  177. * 3 : psize error
  178. * 4 : vaddr is out of range
  179. */
  180. int Cache_Ibus_MMU_Set(uint32_t ext_ram, uint32_t vaddr, uint32_t paddr, uint32_t psize, uint32_t num, uint32_t fixed);
  181. /**
  182. * @brief Set DCache mmu mapping.
  183. * Please do not call this function in your SDK application.
  184. *
  185. * @param uint32_t ext_ram : DPORT_MMU_ACCESS_FLASH for flash, DPORT_MMU_INVALID for invalid. In
  186. * esp32c3, external memory is always flash
  187. *
  188. * @param uint32_t vaddr : virtual address in CPU address space.
  189. * Can be DRam0, DRam1, DRom0, DPort and AHB buses address.
  190. * Should be aligned by psize.
  191. *
  192. * @param uint32_t paddr : physical address in external memory.
  193. * Should be aligned by psize.
  194. *
  195. * @param uint32_t psize : page size of DCache, in kilobytes. Should be 64 here.
  196. *
  197. * @param uint32_t num : pages to be set.
  198. * @param uint32_t fixed : 0 for physical pages grow with virtual pages, other for virtual pages map to same physical page.
  199. *
  200. * @return uint32_t: error status
  201. * 0 : mmu set success
  202. * 2 : vaddr or paddr is not aligned
  203. * 3 : psize error
  204. * 4 : vaddr is out of range
  205. */
  206. int Cache_Dbus_MMU_Set(uint32_t ext_ram, uint32_t vaddr, uint32_t paddr, uint32_t psize, uint32_t num, uint32_t fixed);
  207. /**
  208. * @brief Count the pages in the bus room address which map to Flash.
  209. * Please do not call this function in your SDK application.
  210. *
  211. * @param uint32_t bus : the bus to count with.
  212. *
  213. * @param uint32_t * page0_mapped : value should be initial by user, 0 for not mapped, other for mapped count.
  214. *
  215. * return uint32_t : the number of pages which map to Flash.
  216. */
  217. uint32_t Cache_Count_Flash_Pages(uint32_t bus, uint32_t * page0_mapped);
  218. /**
  219. * @brief allocate memory to used by ICache.
  220. * Please do not call this function in your SDK application.
  221. *
  222. * @param cache_array_t icache_low : the data array bank used by icache low part. Due to timing constraint, can only be CACHE_MEMORY_INVALID, CACHE_MEMORY_IBANK0
  223. *
  224. * return none
  225. */
  226. void Cache_Occupy_ICache_MEMORY(cache_array_t icache_low);
  227. /**
  228. * @brief Get cache mode of ICache or DCache.
  229. * Please do not call this function in your SDK application.
  230. *
  231. * @param struct cache_mode * mode : the pointer of cache mode struct, caller should set the icache field
  232. *
  233. * return none
  234. */
  235. void Cache_Get_Mode(struct cache_mode * mode);
  236. /**
  237. * @brief Init Cache for ROM boot, including resetting the Icache, initializing Owner, MMU, setting ICache mode, Enabling ICache, unmasking bus.
  238. *
  239. * @param None
  240. *
  241. * @return None
  242. */
  243. void ROM_Boot_Cache_Init(void);
  244. /**
  245. * @brief Init mmu owner register to make i/d cache use half mmu entries.
  246. *
  247. * @param None
  248. *
  249. * @return None
  250. */
  251. void Cache_Owner_Init(void);
  252. /**
  253. * @brief Invalidate the cache items for ICache.
  254. * Operation will be done CACHE_LINE_SIZE aligned.
  255. * If the region is not in ICache addr room, nothing will be done.
  256. * Please do not call this function in your SDK application.
  257. *
  258. * @param uint32_t addr: start address to invalidate
  259. *
  260. * @param uint32_t items: cache lines to invalidate, items * cache_line_size should not exceed the bus address size(16MB/32MB/64MB)
  261. *
  262. * @return None
  263. */
  264. void Cache_Invalidate_ICache_Items(uint32_t addr, uint32_t items);
  265. /**
  266. * @brief Invalidate the Cache items in the region from ICache or DCache.
  267. * If the region is not in Cache addr room, nothing will be done.
  268. * Please do not call this function in your SDK application.
  269. *
  270. * @param uint32_t addr : invalidated region start address.
  271. *
  272. * @param uint32_t size : invalidated region size.
  273. *
  274. * @return 0 for success
  275. * 1 for invalid argument
  276. */
  277. int Cache_Invalidate_Addr(uint32_t addr, uint32_t size);
  278. /**
  279. * @brief Invalidate all cache items in ICache.
  280. * Please do not call this function in your SDK application.
  281. *
  282. * @param None
  283. *
  284. * @return None
  285. */
  286. void Cache_Invalidate_ICache_All(void);
  287. /**
  288. * @brief Mask all buses through ICache and DCache.
  289. * Please do not call this function in your SDK application.
  290. *
  291. * @param None
  292. *
  293. * @return None
  294. */
  295. void Cache_Mask_All(void);
  296. /**
  297. * @brief Suspend ICache auto preload operation, then you can resume it after some ICache operations.
  298. * Please do not call this function in your SDK application.
  299. *
  300. * @param None
  301. *
  302. * @return uint32_t : 0 for ICache not auto preload before suspend.
  303. */
  304. uint32_t Cache_Suspend_ICache_Autoload(void);
  305. /**
  306. * @brief Resume ICache auto preload operation after some ICache operations.
  307. * Please do not call this function in your SDK application.
  308. *
  309. * @param uint32_t autoload : 0 for ICache not auto preload before suspend.
  310. *
  311. * @return None.
  312. */
  313. void Cache_Resume_ICache_Autoload(uint32_t autoload);
  314. /**
  315. * @brief Start an ICache manual preload, will suspend auto preload of ICache.
  316. * Please do not call this function in your SDK application.
  317. *
  318. * @param uint32_t addr : start address of the preload region.
  319. *
  320. * @param uint32_t size : size of the preload region, should not exceed the size of ICache.
  321. *
  322. * @param uint32_t order : the preload order, 0 for positive, other for negative
  323. *
  324. * @return uint32_t : 0 for ICache not auto preload before manual preload.
  325. */
  326. uint32_t Cache_Start_ICache_Preload(uint32_t addr, uint32_t size, uint32_t order);
  327. /**
  328. * @brief Return if the ICache manual preload done.
  329. * Please do not call this function in your SDK application.
  330. *
  331. * @param None
  332. *
  333. * @return uint32_t : 0 for ICache manual preload not done.
  334. */
  335. uint32_t Cache_ICache_Preload_Done(void);
  336. /**
  337. * @brief End the ICache manual preload to resume auto preload of ICache.
  338. * Please do not call this function in your SDK application.
  339. *
  340. * @param uint32_t autoload : 0 for ICache not auto preload before manual preload.
  341. *
  342. * @return None
  343. */
  344. void Cache_End_ICache_Preload(uint32_t autoload);
  345. /**
  346. * @brief Config autoload parameters of ICache.
  347. * Please do not call this function in your SDK application.
  348. *
  349. * @param struct autoload_config * config : autoload parameters.
  350. *
  351. * @return None
  352. */
  353. void Cache_Config_ICache_Autoload(const struct autoload_config * config);
  354. /**
  355. * @brief Enable auto preload for ICache.
  356. * Please do not call this function in your SDK application.
  357. *
  358. * @param None
  359. *
  360. * @return None
  361. */
  362. void Cache_Enable_ICache_Autoload(void);
  363. /**
  364. * @brief Disable auto preload for ICache.
  365. * Please do not call this function in your SDK application.
  366. *
  367. * @param None
  368. *
  369. * @return None
  370. */
  371. void Cache_Disable_ICache_Autoload(void);
  372. /**
  373. * @brief Config a group of prelock parameters of ICache.
  374. * Please do not call this function in your SDK application.
  375. *
  376. * @param struct lock_config * config : a group of lock parameters.
  377. *
  378. * @return None
  379. */
  380. void Cache_Enable_ICache_PreLock(const struct lock_config *config);
  381. /**
  382. * @brief Disable a group of prelock parameters for ICache.
  383. * However, the locked data will not be released.
  384. * Please do not call this function in your SDK application.
  385. *
  386. * @param uint16_t group : 0 for group0, 1 for group1.
  387. *
  388. * @return None
  389. */
  390. void Cache_Disable_ICache_PreLock(uint16_t group);
  391. /**
  392. * @brief Lock the cache items for ICache.
  393. * Operation will be done CACHE_LINE_SIZE aligned.
  394. * If the region is not in ICache addr room, nothing will be done.
  395. * Please do not call this function in your SDK application.
  396. *
  397. * @param uint32_t addr: start address to lock
  398. *
  399. * @param uint32_t items: cache lines to lock, items * cache_line_size should not exceed the bus address size(16MB/32MB/64MB)
  400. *
  401. * @return None
  402. */
  403. void Cache_Lock_ICache_Items(uint32_t addr, uint32_t items);
  404. /**
  405. * @brief Unlock the cache items for ICache.
  406. * Operation will be done CACHE_LINE_SIZE aligned.
  407. * If the region is not in ICache addr room, nothing will be done.
  408. * Please do not call this function in your SDK application.
  409. *
  410. * @param uint32_t addr: start address to unlock
  411. *
  412. * @param uint32_t items: cache lines to unlock, items * cache_line_size should not exceed the bus address size(16MB/32MB/64MB)
  413. *
  414. * @return None
  415. */
  416. void Cache_Unlock_ICache_Items(uint32_t addr, uint32_t items);
  417. /**
  418. * @brief Lock the cache items in tag memory for ICache or DCache.
  419. * Please do not call this function in your SDK application.
  420. *
  421. * @param uint32_t addr : start address of lock region.
  422. *
  423. * @param uint32_t size : size of lock region.
  424. *
  425. * @return 0 for success
  426. * 1 for invalid argument
  427. */
  428. int Cache_Lock_Addr(uint32_t addr, uint32_t size);
  429. /**
  430. * @brief Unlock the cache items in tag memory for ICache or DCache.
  431. * Please do not call this function in your SDK application.
  432. *
  433. * @param uint32_t addr : start address of unlock region.
  434. *
  435. * @param uint32_t size : size of unlock region.
  436. *
  437. * @return 0 for success
  438. * 1 for invalid argument
  439. */
  440. int Cache_Unlock_Addr(uint32_t addr, uint32_t size);
  441. /**
  442. * @brief Disable ICache access for the cpu.
  443. * This operation will make all ICache tag memory invalid, CPU can't access ICache, ICache will keep idle.
  444. * Please do not call this function in your SDK application.
  445. *
  446. * @return uint32_t : auto preload enabled before
  447. */
  448. uint32_t Cache_Disable_ICache(void);
  449. /**
  450. * @brief Enable ICache access for the cpu.
  451. * Please do not call this function in your SDK application.
  452. *
  453. * @param uint32_t autoload : ICache will preload then.
  454. *
  455. * @return None
  456. */
  457. void Cache_Enable_ICache(uint32_t autoload);
  458. /**
  459. * @brief Suspend ICache access for the cpu.
  460. * The ICache tag memory is still there, CPU can't access ICache, ICache will keep idle.
  461. * Please do not change MMU, cache mode or tag memory(tag memory can be changed in some special case).
  462. * Please do not call this function in your SDK application.
  463. *
  464. * @param None
  465. *
  466. * @return uint32_t : auto preload enabled before
  467. */
  468. uint32_t Cache_Suspend_ICache(void);
  469. /**
  470. * @brief Resume ICache access for the cpu.
  471. * Please do not call this function in your SDK application.
  472. *
  473. * @param uint32_t autoload : ICache will preload then.
  474. *
  475. * @return None
  476. */
  477. void Cache_Resume_ICache(uint32_t autoload);
  478. /**
  479. * @brief Get ICache cache line size
  480. *
  481. * @param None
  482. *
  483. * @return uint32_t: 16, 32, 64 Byte
  484. */
  485. uint32_t Cache_Get_ICache_Line_Size(void);
  486. /**
  487. * @brief Set default mode from boot, 8KB ICache, 16Byte cache line size.
  488. *
  489. * @param None
  490. *
  491. * @return None
  492. */
  493. void Cache_Set_Default_Mode(void);
  494. /**
  495. * @brief Set default mode from boot, 8KB ICache, 16Byte cache line size.
  496. *
  497. * @param None
  498. *
  499. * @return None
  500. */
  501. void Cache_Enable_Defalut_ICache_Mode(void);
  502. /**
  503. * @brief Enable freeze for ICache.
  504. * Any miss request will be rejected, including cpu miss and preload/autoload miss.
  505. * Please do not call this function in your SDK application.
  506. *
  507. * @param cache_freeze_mode_t mode : 0 for assert busy 1 for assert hit
  508. *
  509. * @return None
  510. */
  511. void Cache_Freeze_ICache_Enable(cache_freeze_mode_t mode);
  512. /**
  513. * @brief Disable freeze for ICache.
  514. * Please do not call this function in your SDK application.
  515. *
  516. * @return None
  517. */
  518. void Cache_Freeze_ICache_Disable(void);
  519. /**
  520. * @brief Travel tag memory to run a call back function.
  521. * ICache and DCache are suspend when doing this.
  522. * The callback will get the parameter tag_group_info, which will include a group of tag memory addresses and cache memory addresses.
  523. * Please do not call this function in your SDK application.
  524. *
  525. * @param struct cache_mode * mode : the cache to check and the cache mode.
  526. *
  527. * @param uint32_t filter_addr : only the cache lines which may include the filter_address will be returned to the call back function.
  528. * 0 for do not filter, all cache lines will be returned.
  529. *
  530. * @param void (* process)(struct tag_group_info *) : call back function, which may be called many times, a group(the addresses in the group are in the same position in the cache ways) a time.
  531. *
  532. * @return None
  533. */
  534. void Cache_Travel_Tag_Memory(struct cache_mode * mode, uint32_t filter_addr, void (* process)(struct tag_group_info *));
  535. /**
  536. * @brief Get the virtual address from cache mode, cache tag and the virtual address offset of cache ways.
  537. * Please do not call this function in your SDK application.
  538. *
  539. * @param struct cache_mode * mode : the cache to calculate the virtual address and the cache mode.
  540. *
  541. * @param uint32_t tag : the tag part fo a tag item, 12-14 bits.
  542. *
  543. * @param uint32_t addr_offset : the virtual address offset of the cache ways.
  544. *
  545. * @return uint32_t : the virtual address.
  546. */
  547. uint32_t Cache_Get_Virtual_Addr(struct cache_mode *mode, uint32_t tag, uint32_t vaddr_offset);
  548. /**
  549. * @brief Get cache memory block base address.
  550. * Please do not call this function in your SDK application.
  551. *
  552. * @param uint32_t icache : 0 for dcache, other for icache.
  553. *
  554. * @param uint32_t bank_no : 0 ~ 3 bank.
  555. *
  556. * @return uint32_t : the cache memory block base address, 0 if the block not used.
  557. */
  558. uint32_t Cache_Get_Memory_BaseAddr(uint32_t icache, uint32_t bank_no);
  559. /**
  560. * @brief Get the cache memory address from cache mode, cache memory offset and the virtual address offset of cache ways.
  561. * Please do not call this function in your SDK application.
  562. *
  563. * @param struct cache_mode * mode : the cache to calculate the virtual address and the cache mode.
  564. *
  565. * @param uint32_t cache_memory_offset : the cache memory offset of the whole cache (ICache or DCache) for the cache line.
  566. *
  567. * @param uint32_t addr_offset : the virtual address offset of the cache ways.
  568. *
  569. * @return uint32_t : the virtual address.
  570. */
  571. uint32_t Cache_Get_Memory_Addr(struct cache_mode *mode, uint32_t cache_memory_offset, uint32_t vaddr_offset);
  572. /**
  573. * @brief Get the cache memory value by DRAM address.
  574. * Please do not call this function in your SDK application.
  575. *
  576. * @param uint32_t cache_memory_addr : DRAM address for the cache memory, should be 4 byte aligned for IBus address.
  577. *
  578. * @return uint32_t : the word value of the address.
  579. */
  580. uint32_t Cache_Get_Memory_value(uint32_t cache_memory_addr);
  581. /**
  582. * @}
  583. */
  584. /**
  585. * @brief Get the cache MMU IROM end address.
  586. * Please do not call this function in your SDK application.
  587. *
  588. * @param void
  589. *
  590. * @return uint32_t : the word value of the address.
  591. */
  592. uint32_t Cache_Get_IROM_MMU_End(void);
  593. /**
  594. * @brief Get the cache MMU DROM end address.
  595. * Please do not call this function in your SDK application.
  596. *
  597. * @param void
  598. *
  599. * @return uint32_t : the word value of the address.
  600. */
  601. uint32_t Cache_Get_DROM_MMU_End(void);
  602. /**
  603. * @brief Configure cache MMU page size according to instruction and rodata size
  604. *
  605. * @param irom_size The instruction cache MMU page size
  606. * @param drom_size The rodata data cache MMU page size
  607. */
  608. void Cache_Set_IDROM_MMU_Size(uint32_t irom_size, uint32_t drom_size);
  609. /**
  610. * @brief Lock the permission control section configuration. After lock, any
  611. * configuration modification will be bypass. Digital reset will clear the lock!
  612. * Please do not call this function in your SDK application.
  613. *
  614. * @param int ibus : 1 for lock ibus pms, 0 for lock dbus pms
  615. *
  616. * @return None
  617. */
  618. void Cache_Pms_Lock(int ibus);
  619. /**
  620. * @brief Set three ibus pms boundary address, which will determine pms reject section and section 1/2.
  621. * Please do not call this function in your SDK application.
  622. *
  623. * @param uint32_t ibus_boundary0_addr : vaddress for split line0
  624. *
  625. * @param uint32_t ibus_boundary1_addr : vaddress for split line1
  626. *
  627. * @param uint32_t ibus_boundary2_addr : vaddress for split line2
  628. *
  629. * @return int : ESP_ROM_ERR_INVALID_ARG for invalid address, 0 for success
  630. */
  631. int Cache_Ibus_Pms_Set_Addr(uint32_t ibus_boundary0_addr, uint32_t ibus_boundary1_addr, uint32_t ibus_boundary2_addr);
  632. /**
  633. * @brief Set three ibus pms attribute, which will determine pms in different section and world.
  634. * Please do not call this function in your SDK application.
  635. *
  636. * @param uint32_t ibus_pms_sct2_attr : attr for section2
  637. *
  638. * @param uint32_t ibus_pms_sct1_attr : attr for section1
  639. *
  640. * @return None
  641. */
  642. void Cache_Ibus_Pms_Set_Attr(uint32_t ibus_pms_sct2_attr, uint32_t ibus_pms_sct1_attr);
  643. /**
  644. * @brief Set three dbus pms boundary address, which will determine pms reject section and section 1/2.
  645. * Please do not call this function in your SDK application.
  646. *
  647. * @param uint32_t dbus_boundary0_addr : vaddress for split line0
  648. *
  649. * @param uint32_t dbus_boundary1_addr : vaddress for split line1
  650. *
  651. * @param uint32_t dbus_boundary2_addr : vaddress for split line2
  652. *
  653. * @return int : ESP_ROM_ERR_INVALID_ARG for invalid address, 0 for success
  654. */
  655. int Cache_Dbus_Pms_Set_Addr(uint32_t dbus_boundary0_addr, uint32_t dbus_boundary1_addr, uint32_t dbus_boundary2_addr);
  656. /**
  657. * @brief Set three dbus pms attribute, which will determine pms in different section and world.
  658. * Please do not call this function in your SDK application.
  659. *
  660. * @param uint32_t dbus_pms_sct2_attr : attr for section2
  661. *
  662. * @param uint32_t dbus_pms_sct1_attr : attr for section1
  663. *
  664. * @return None
  665. */
  666. void Cache_Dbus_Pms_Set_Attr(uint32_t dbus_pms_sct2_attr, uint32_t dbus_pms_sct1_attr);
  667. #ifdef __cplusplus
  668. }
  669. #endif
  670. #endif /* _ROM_CACHE_H_ */