cache.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. /*
  2. * SPDX-FileCopyrightText: 2020-2021 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. typedef enum {
  82. CACHE_PAGE_16KB = 0,
  83. CACHE_PAGE_32KB,
  84. CACHE_PAGE_64KB,
  85. } mmu_page_mode_t;
  86. struct cache_mode {
  87. uint32_t cache_size; /*!< cache size in byte */
  88. uint16_t cache_line_size; /*!< cache line size in byte */
  89. uint8_t cache_ways; /*!< cache ways, always 4 */
  90. uint8_t ibus; /*!< the cache index, 0 for dcache, 1 for icache */
  91. };
  92. struct icache_tag_item {
  93. uint32_t valid:1; /*!< the tag item is valid or not */
  94. uint32_t lock:1; /*!< the cache line is locked or not */
  95. uint32_t fifo_cnt:3; /*!< fifo cnt, 0 ~ 3 for 4 ways cache */
  96. 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 */
  97. uint32_t reserved:14;
  98. };
  99. struct autoload_config {
  100. uint8_t order; /*!< autoload step is positive or negative */
  101. uint8_t trigger; /*!< autoload trigger */
  102. uint8_t ena0; /*!< autoload region0 enable */
  103. uint8_t ena1; /*!< autoload region1 enable */
  104. uint32_t addr0; /*!< autoload region0 start address */
  105. uint32_t size0; /*!< autoload region0 size */
  106. uint32_t addr1; /*!< autoload region1 start address */
  107. uint32_t size1; /*!< autoload region1 size */
  108. };
  109. struct tag_group_info {
  110. struct cache_mode mode; /*!< cache and cache mode */
  111. uint32_t filter_addr; /*!< the address that used to generate the struct */
  112. uint32_t vaddr_offset; /*!< virtual address offset of the cache ways */
  113. uint32_t tag_addr[MAX_CACHE_WAYS]; /*!< tag memory address, only [0~mode.ways-1] is valid to use */
  114. uint32_t cache_memory_offset[MAX_CACHE_WAYS]; /*!< cache memory address, only [0~mode.ways-1] is valid to use */
  115. };
  116. struct lock_config {
  117. uint32_t addr; /*!< manual lock address*/
  118. uint16_t size; /*!< manual lock size*/
  119. uint16_t group; /*!< manual lock group, 0 or 1*/
  120. };
  121. struct cache_internal_stub_table {
  122. uint32_t (* icache_line_size)(void);
  123. uint32_t (* icache_addr)(uint32_t addr);
  124. uint32_t (* dcache_addr)(uint32_t addr);
  125. void (* invalidate_icache_items)(uint32_t addr, uint32_t items);
  126. void (* lock_icache_items)(uint32_t addr, uint32_t items);
  127. void (* unlock_icache_items)(uint32_t addr, uint32_t items);
  128. uint32_t (* suspend_icache_autoload)(void);
  129. void (* resume_icache_autoload)(uint32_t autoload);
  130. void (* freeze_icache_enable)(cache_freeze_mode_t mode);
  131. void (* freeze_icache_disable)(void);
  132. 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));
  133. };
  134. /* Defined in the interface file, default value is rom_default_cache_internal_table */
  135. extern const struct cache_internal_stub_table* rom_cache_internal_table_ptr;
  136. typedef void (* cache_op_start)(void);
  137. typedef void (* cache_op_end)(void);
  138. typedef struct {
  139. cache_op_start start;
  140. cache_op_end end;
  141. } cache_op_cb_t;
  142. /* Defined in the interface file, default value is NULL */
  143. extern const cache_op_cb_t* rom_cache_op_cb;
  144. #define ESP_ROM_ERR_INVALID_ARG 1
  145. #define MMU_SET_ADDR_ALIGNED_ERROR 2
  146. #define MMU_SET_PASE_SIZE_ERROR 3
  147. #define MMU_SET_VADDR_OUT_RANGE 4
  148. #define CACHE_OP_ICACHE_Y 1
  149. #define CACHE_OP_ICACHE_N 0
  150. /**
  151. * @brief Initialise cache mmu, mark all entries as invalid.
  152. * Please do not call this function in your SDK application.
  153. *
  154. * @param None
  155. *
  156. * @return None
  157. */
  158. void Cache_MMU_Init(void);
  159. /**
  160. * @brief Set ICache mmu mapping.
  161. * Please do not call this function in your SDK application.
  162. *
  163. * @param uint32_t ext_ram : DPORT_MMU_ACCESS_FLASH for flash, DPORT_MMU_INVALID for invalid. In
  164. * esp32c3, external memory is always flash
  165. *
  166. * @param uint32_t vaddr : virtual address in CPU address space.
  167. * Can be Iram0,Iram1,Irom0,Drom0 and AHB buses address.
  168. * Should be aligned by psize.
  169. *
  170. * @param uint32_t paddr : physical address in external memory.
  171. * Should be aligned by psize.
  172. *
  173. * @param uint32_t psize : page size of ICache, in kilobytes. Should be 64 here.
  174. *
  175. * @param uint32_t num : pages to be set.
  176. *
  177. * @param uint32_t fixed : 0 for physical pages grow with virtual pages, other for virtual pages map to same physical page.
  178. *
  179. * @return uint32_t: error status
  180. * 0 : mmu set success
  181. * 2 : vaddr or paddr is not aligned
  182. * 3 : psize error
  183. * 4 : vaddr is out of range
  184. */
  185. int Cache_Ibus_MMU_Set(uint32_t ext_ram, uint32_t vaddr, uint32_t paddr, uint32_t psize, uint32_t num, uint32_t fixed);
  186. /**
  187. * @brief Set DCache mmu mapping.
  188. * Please do not call this function in your SDK application.
  189. *
  190. * @param uint32_t ext_ram : DPORT_MMU_ACCESS_FLASH for flash, DPORT_MMU_INVALID for invalid. In
  191. * esp32c3, external memory is always flash
  192. *
  193. * @param uint32_t vaddr : virtual address in CPU address space.
  194. * Can be DRam0, DRam1, DRom0, DPort and AHB buses address.
  195. * Should be aligned by psize.
  196. *
  197. * @param uint32_t paddr : physical address in external memory.
  198. * Should be aligned by psize.
  199. *
  200. * @param uint32_t psize : page size of DCache, in kilobytes. Should be 64 here.
  201. *
  202. * @param uint32_t num : pages to be set.
  203. * @param uint32_t fixed : 0 for physical pages grow with virtual pages, other for virtual pages map to same physical page.
  204. *
  205. * @return uint32_t: error status
  206. * 0 : mmu set success
  207. * 2 : vaddr or paddr is not aligned
  208. * 3 : psize error
  209. * 4 : vaddr is out of range
  210. */
  211. int Cache_Dbus_MMU_Set(uint32_t ext_ram, uint32_t vaddr, uint32_t paddr, uint32_t psize, uint32_t num, uint32_t fixed);
  212. /**
  213. * @brief Count the pages in the bus room address which map to Flash.
  214. * Please do not call this function in your SDK application.
  215. *
  216. * @param uint32_t bus : the bus to count with.
  217. *
  218. * @param uint32_t * page0_mapped : value should be initial by user, 0 for not mapped, other for mapped count.
  219. *
  220. * return uint32_t : the number of pages which map to Flash.
  221. */
  222. uint32_t Cache_Count_Flash_Pages(uint32_t bus, uint32_t * page0_mapped);
  223. /**
  224. * @brief allocate memory to used by ICache.
  225. * Please do not call this function in your SDK application.
  226. *
  227. * @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
  228. *
  229. * return none
  230. */
  231. void Cache_Occupy_ICache_MEMORY(cache_array_t icache_low);
  232. /**
  233. * @brief Get cache mode of ICache or DCache.
  234. * Please do not call this function in your SDK application.
  235. *
  236. * @param struct cache_mode * mode : the pointer of cache mode struct, caller should set the icache field
  237. *
  238. * return none
  239. */
  240. void Cache_Get_Mode(struct cache_mode * mode);
  241. /**
  242. * @brief set ICache modes: cache size, associate ways and cache line size.
  243. * Please do not call this function in your SDK application.
  244. *
  245. * @param cache_size_t cache_size : the cache size, can be CACHE_SIZE_HALF and CACHE_SIZE_FULL
  246. *
  247. * @param cache_ways_t ways : the associate ways of cache, can be CACHE_4WAYS_ASSOC and CACHE_8WAYS_ASSOC
  248. *
  249. * @param cache_line_size_t cache_line_size : the cache line size, can be CACHE_LINE_SIZE_16B, CACHE_LINE_SIZE_32B and CACHE_LINE_SIZE_64B
  250. *
  251. * return none
  252. */
  253. void Cache_Set_ICache_Mode(cache_size_t cache_size, cache_ways_t ways, cache_line_size_t cache_line_size);
  254. /**
  255. * @brief set DCache modes: cache size, associate ways and cache line size.
  256. * Please do not call this function in your SDK application.
  257. *
  258. * @param cache_size_t cache_size : the cache size, can be CACHE_SIZE_8KB and CACHE_SIZE_16KB
  259. *
  260. * @param cache_ways_t ways : the associate ways of cache, can be CACHE_4WAYS_ASSOC and CACHE_8WAYS_ASSOC
  261. *
  262. * @param cache_line_size_t cache_line_size : the cache line size, can be CACHE_LINE_SIZE_16B, CACHE_LINE_SIZE_32B and CACHE_LINE_SIZE_64B
  263. *
  264. * return none
  265. */
  266. void Cache_Set_DCache_Mode(cache_size_t cache_size, cache_ways_t ways, cache_line_size_t cache_line_size);
  267. /**
  268. * @brief check if the address is accessed through ICache.
  269. * Please do not call this function in your SDK application.
  270. *
  271. * @param uint32_t addr : the address to check.
  272. *
  273. * @return 1 if the address is accessed through ICache, 0 if not.
  274. */
  275. uint32_t Cache_Address_Through_ICache(uint32_t addr);
  276. /**
  277. * @brief check if the address is accessed through DCache.
  278. * Please do not call this function in your SDK application.
  279. *
  280. * @param uint32_t addr : the address to check.
  281. *
  282. * @return 1 if the address is accessed through DCache, 0 if not.
  283. */
  284. uint32_t Cache_Address_Through_DCache(uint32_t addr);
  285. /**
  286. * @brief Init mmu owner register to make i/d cache use half mmu entries.
  287. *
  288. * @param None
  289. *
  290. * @return None
  291. */
  292. void Cache_Owner_Init(void);
  293. /**
  294. * @brief Invalidate the cache items for ICache.
  295. * Operation will be done CACHE_LINE_SIZE aligned.
  296. * If the region is not in ICache addr room, nothing will be done.
  297. * Please do not call this function in your SDK application.
  298. *
  299. * @param uint32_t addr: start address to invalidate
  300. *
  301. * @param uint32_t items: cache lines to invalidate, items * cache_line_size should not exceed the bus address size(16MB/32MB/64MB)
  302. *
  303. * @return None
  304. */
  305. void Cache_Invalidate_ICache_Items(uint32_t addr, uint32_t items);
  306. /**
  307. * @brief Invalidate the Cache items in the region from ICache or DCache.
  308. * If the region is not in Cache addr room, nothing will be done.
  309. * Please do not call this function in your SDK application.
  310. *
  311. * @param uint32_t addr : invalidated region start address.
  312. *
  313. * @param uint32_t size : invalidated region size.
  314. *
  315. * @return 0 for success
  316. * 1 for invalid argument
  317. */
  318. int Cache_Invalidate_Addr(uint32_t addr, uint32_t size);
  319. /**
  320. * @brief Invalidate all cache items in ICache.
  321. * Please do not call this function in your SDK application.
  322. *
  323. * @param None
  324. *
  325. * @return None
  326. */
  327. void Cache_Invalidate_ICache_All(void);
  328. /**
  329. * @brief Mask all buses through ICache and DCache.
  330. * Please do not call this function in your SDK application.
  331. *
  332. * @param None
  333. *
  334. * @return None
  335. */
  336. void Cache_Mask_All(void);
  337. /**
  338. * @brief Suspend ICache auto preload operation, then you can resume it after some ICache operations.
  339. * Please do not call this function in your SDK application.
  340. *
  341. * @param None
  342. *
  343. * @return uint32_t : 0 for ICache not auto preload before suspend.
  344. */
  345. uint32_t Cache_Suspend_ICache_Autoload(void);
  346. /**
  347. * @brief Resume ICache auto preload operation after some ICache operations.
  348. * Please do not call this function in your SDK application.
  349. *
  350. * @param uint32_t autoload : 0 for ICache not auto preload before suspend.
  351. *
  352. * @return None.
  353. */
  354. void Cache_Resume_ICache_Autoload(uint32_t autoload);
  355. /**
  356. * @brief Start an ICache manual preload, will suspend auto preload of ICache.
  357. * Please do not call this function in your SDK application.
  358. *
  359. * @param uint32_t addr : start address of the preload region.
  360. *
  361. * @param uint32_t size : size of the preload region, should not exceed the size of ICache.
  362. *
  363. * @param uint32_t order : the preload order, 0 for positive, other for negative
  364. *
  365. * @return uint32_t : 0 for ICache not auto preload before manual preload.
  366. */
  367. uint32_t Cache_Start_ICache_Preload(uint32_t addr, uint32_t size, uint32_t order);
  368. /**
  369. * @brief Return if the ICache manual preload done.
  370. * Please do not call this function in your SDK application.
  371. *
  372. * @param None
  373. *
  374. * @return uint32_t : 0 for ICache manual preload not done.
  375. */
  376. uint32_t Cache_ICache_Preload_Done(void);
  377. /**
  378. * @brief End the ICache manual preload to resume auto preload of ICache.
  379. * Please do not call this function in your SDK application.
  380. *
  381. * @param uint32_t autoload : 0 for ICache not auto preload before manual preload.
  382. *
  383. * @return None
  384. */
  385. void Cache_End_ICache_Preload(uint32_t autoload);
  386. /**
  387. * @brief Config autoload parameters of ICache.
  388. * Please do not call this function in your SDK application.
  389. *
  390. * @param struct autoload_config * config : autoload parameters.
  391. *
  392. * @return None
  393. */
  394. void Cache_Config_ICache_Autoload(const struct autoload_config * config);
  395. /**
  396. * @brief Enable auto preload for ICache.
  397. * Please do not call this function in your SDK application.
  398. *
  399. * @param None
  400. *
  401. * @return None
  402. */
  403. void Cache_Enable_ICache_Autoload(void);
  404. /**
  405. * @brief Disable auto preload for ICache.
  406. * Please do not call this function in your SDK application.
  407. *
  408. * @param None
  409. *
  410. * @return None
  411. */
  412. void Cache_Disable_ICache_Autoload(void);
  413. /**
  414. * @brief Config a group of prelock parameters of ICache.
  415. * Please do not call this function in your SDK application.
  416. *
  417. * @param struct lock_config * config : a group of lock parameters.
  418. *
  419. * @return None
  420. */
  421. void Cache_Enable_ICache_PreLock(const struct lock_config *config);
  422. /**
  423. * @brief Disable a group of prelock parameters for ICache.
  424. * However, the locked data will not be released.
  425. * Please do not call this function in your SDK application.
  426. *
  427. * @param uint16_t group : 0 for group0, 1 for group1.
  428. *
  429. * @return None
  430. */
  431. void Cache_Disable_ICache_PreLock(uint16_t group);
  432. /**
  433. * @brief Lock the cache items for ICache.
  434. * Operation will be done CACHE_LINE_SIZE aligned.
  435. * If the region is not in ICache addr room, nothing will be done.
  436. * Please do not call this function in your SDK application.
  437. *
  438. * @param uint32_t addr: start address to lock
  439. *
  440. * @param uint32_t items: cache lines to lock, items * cache_line_size should not exceed the bus address size(16MB/32MB/64MB)
  441. *
  442. * @return None
  443. */
  444. void Cache_Lock_ICache_Items(uint32_t addr, uint32_t items);
  445. /**
  446. * @brief Unlock the cache items for ICache.
  447. * Operation will be done CACHE_LINE_SIZE aligned.
  448. * If the region is not in ICache addr room, nothing will be done.
  449. * Please do not call this function in your SDK application.
  450. *
  451. * @param uint32_t addr: start address to unlock
  452. *
  453. * @param uint32_t items: cache lines to unlock, items * cache_line_size should not exceed the bus address size(16MB/32MB/64MB)
  454. *
  455. * @return None
  456. */
  457. void Cache_Unlock_ICache_Items(uint32_t addr, uint32_t items);
  458. /**
  459. * @brief Lock the cache items in tag memory for ICache or DCache.
  460. * Please do not call this function in your SDK application.
  461. *
  462. * @param uint32_t addr : start address of lock region.
  463. *
  464. * @param uint32_t size : size of lock region.
  465. *
  466. * @return 0 for success
  467. * 1 for invalid argument
  468. */
  469. int Cache_Lock_Addr(uint32_t addr, uint32_t size);
  470. /**
  471. * @brief Unlock the cache items in tag memory for ICache or DCache.
  472. * Please do not call this function in your SDK application.
  473. *
  474. * @param uint32_t addr : start address of unlock region.
  475. *
  476. * @param uint32_t size : size of unlock region.
  477. *
  478. * @return 0 for success
  479. * 1 for invalid argument
  480. */
  481. int Cache_Unlock_Addr(uint32_t addr, uint32_t size);
  482. /**
  483. * @brief Disable ICache access for the cpu.
  484. * This operation will make all ICache tag memory invalid, CPU can't access ICache, ICache will keep idle.
  485. * Please do not call this function in your SDK application.
  486. *
  487. * @return uint32_t : auto preload enabled before
  488. */
  489. uint32_t Cache_Disable_ICache(void);
  490. /**
  491. * @brief Enable ICache access for the cpu.
  492. * Please do not call this function in your SDK application.
  493. *
  494. * @param uint32_t autoload : ICache will preload then.
  495. *
  496. * @return None
  497. */
  498. void Cache_Enable_ICache(uint32_t autoload);
  499. /**
  500. * @brief Suspend ICache access for the cpu.
  501. * The ICache tag memory is still there, CPU can't access ICache, ICache will keep idle.
  502. * Please do not change MMU, cache mode or tag memory(tag memory can be changed in some special case).
  503. * Please do not call this function in your SDK application.
  504. *
  505. * @param None
  506. *
  507. * @return uint32_t : auto preload enabled before
  508. */
  509. uint32_t Cache_Suspend_ICache(void);
  510. /**
  511. * @brief Resume ICache access for the cpu.
  512. * Please do not call this function in your SDK application.
  513. *
  514. * @param uint32_t autoload : ICache will preload then.
  515. *
  516. * @return None
  517. */
  518. void Cache_Resume_ICache(uint32_t autoload);
  519. /**
  520. * @brief Get ICache cache line size
  521. *
  522. * @param None
  523. *
  524. * @return uint32_t: 16, 32, 64 Byte
  525. */
  526. uint32_t Cache_Get_ICache_Line_Size(void);
  527. /**
  528. * @brief Set default mode from boot, 8KB ICache, 16Byte cache line size.
  529. *
  530. * @param None
  531. *
  532. * @return None
  533. */
  534. void Cache_Set_Default_Mode(void);
  535. /**
  536. * @brief Set default mode from boot, 8KB ICache, 16Byte cache line size.
  537. *
  538. * @param None
  539. *
  540. * @return None
  541. */
  542. void Cache_Enable_Defalut_ICache_Mode(void);
  543. /**
  544. * @brief Set mmu page mode.
  545. *
  546. * @param mmu_page_mode_t
  547. *
  548. * @return None
  549. */
  550. void MMU_Set_Page_Mode(mmu_page_mode_t pg_mode);
  551. /**
  552. * @brief Get mmu page mode.
  553. *
  554. * @param None
  555. *
  556. * @return page mode
  557. */
  558. mmu_page_mode_t MMU_Get_Page_Mode(void);
  559. /**
  560. * @brief Enable freeze for ICache.
  561. * Any miss request will be rejected, including cpu miss and preload/autoload miss.
  562. * Please do not call this function in your SDK application.
  563. *
  564. * @param cache_freeze_mode_t mode : 0 for assert busy 1 for assert hit
  565. *
  566. * @return None
  567. */
  568. void Cache_Freeze_ICache_Enable(cache_freeze_mode_t mode);
  569. /**
  570. * @brief Disable freeze for ICache.
  571. * Please do not call this function in your SDK application.
  572. *
  573. * @return None
  574. */
  575. void Cache_Freeze_ICache_Disable(void);
  576. /**
  577. * @brief Travel tag memory to run a call back function.
  578. * ICache and DCache are suspend when doing this.
  579. * The callback will get the parameter tag_group_info, which will include a group of tag memory addresses and cache memory addresses.
  580. * Please do not call this function in your SDK application.
  581. *
  582. * @param struct cache_mode * mode : the cache to check and the cache mode.
  583. *
  584. * @param uint32_t filter_addr : only the cache lines which may include the filter_address will be returned to the call back function.
  585. * 0 for do not filter, all cache lines will be returned.
  586. *
  587. * @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.
  588. *
  589. * @return None
  590. */
  591. void Cache_Travel_Tag_Memory(struct cache_mode * mode, uint32_t filter_addr, void (* process)(struct tag_group_info *));
  592. /**
  593. * @brief Get the virtual address from cache mode, cache tag and the virtual address offset of cache ways.
  594. * Please do not call this function in your SDK application.
  595. *
  596. * @param struct cache_mode * mode : the cache to calculate the virtual address and the cache mode.
  597. *
  598. * @param uint32_t tag : the tag part fo a tag item, 12-14 bits.
  599. *
  600. * @param uint32_t addr_offset : the virtual address offset of the cache ways.
  601. *
  602. * @return uint32_t : the virtual address.
  603. */
  604. uint32_t Cache_Get_Virtual_Addr(struct cache_mode *mode, uint32_t tag, uint32_t vaddr_offset);
  605. /**
  606. * @brief Get cache memory block base address.
  607. * Please do not call this function in your SDK application.
  608. *
  609. * @param uint32_t icache : 0 for dcache, other for icache.
  610. *
  611. * @param uint32_t bank_no : 0 ~ 3 bank.
  612. *
  613. * @return uint32_t : the cache memory block base address, 0 if the block not used.
  614. */
  615. uint32_t Cache_Get_Memory_BaseAddr(uint32_t icache, uint32_t bank_no);
  616. /**
  617. * @brief Get the cache memory address from cache mode, cache memory offset and the virtual address offset of cache ways.
  618. * Please do not call this function in your SDK application.
  619. *
  620. * @param struct cache_mode * mode : the cache to calculate the virtual address and the cache mode.
  621. *
  622. * @param uint32_t cache_memory_offset : the cache memory offset of the whole cache (ICache or DCache) for the cache line.
  623. *
  624. * @param uint32_t addr_offset : the virtual address offset of the cache ways.
  625. *
  626. * @return uint32_t : the virtual address.
  627. */
  628. uint32_t Cache_Get_Memory_Addr(struct cache_mode *mode, uint32_t cache_memory_offset, uint32_t vaddr_offset);
  629. /**
  630. * @brief Get the cache memory value by DRAM address.
  631. * Please do not call this function in your SDK application.
  632. *
  633. * @param uint32_t cache_memory_addr : DRAM address for the cache memory, should be 4 byte aligned for IBus address.
  634. *
  635. * @return uint32_t : the word value of the address.
  636. */
  637. uint32_t Cache_Get_Memory_value(uint32_t cache_memory_addr);
  638. /**
  639. * @}
  640. */
  641. /**
  642. * @brief Get the cache MMU IROM end address.
  643. * Please do not call this function in your SDK application.
  644. *
  645. * @param void
  646. *
  647. * @return uint32_t : the word value of the address.
  648. */
  649. uint32_t Cache_Get_IROM_MMU_End(void);
  650. /**
  651. * @brief Get the cache MMU DROM end address.
  652. * Please do not call this function in your SDK application.
  653. *
  654. * @param void
  655. *
  656. * @return uint32_t : the word value of the address.
  657. */
  658. uint32_t Cache_Get_DROM_MMU_End(void);
  659. /**
  660. * @brief Lock the permission control section configuration. After lock, any
  661. * configuration modification will be bypass. Digital reset will clear the lock!
  662. * Please do not call this function in your SDK application.
  663. *
  664. * @param int ibus : 1 for lock ibus pms, 0 for lock dbus pms
  665. *
  666. * @return None
  667. */
  668. void Cache_Pms_Lock(int ibus);
  669. /**
  670. * @brief Set three ibus pms boundary address, which will determine pms reject section and section 1/2.
  671. * Please do not call this function in your SDK application.
  672. *
  673. * @param uint32_t ibus_boundary0_addr : vaddress for split line0
  674. *
  675. * @param uint32_t ibus_boundary1_addr : vaddress for split line1
  676. *
  677. * @param uint32_t ibus_boundary2_addr : vaddress for split line2
  678. *
  679. * @return int : ESP_ROM_ERR_INVALID_ARG for invalid address, 0 for success
  680. */
  681. int Cache_Ibus_Pms_Set_Addr(uint32_t ibus_boundary0_addr, uint32_t ibus_boundary1_addr, uint32_t ibus_boundary2_addr);
  682. /**
  683. * @brief Set three ibus pms attribute, which will determine pms in different section and world.
  684. * Please do not call this function in your SDK application.
  685. *
  686. * @param uint32_t ibus_pms_sct2_attr : attr for section2
  687. *
  688. * @param uint32_t ibus_pms_sct1_attr : attr for section1
  689. *
  690. * @return None
  691. */
  692. void Cache_Ibus_Pms_Set_Attr(uint32_t ibus_pms_sct2_attr, uint32_t ibus_pms_sct1_attr);
  693. /**
  694. * @brief Set three dbus pms boundary address, which will determine pms reject section and section 1/2.
  695. * Please do not call this function in your SDK application.
  696. *
  697. * @param uint32_t dbus_boundary0_addr : vaddress for split line0
  698. *
  699. * @param uint32_t dbus_boundary1_addr : vaddress for split line1
  700. *
  701. * @param uint32_t dbus_boundary2_addr : vaddress for split line2
  702. *
  703. * @return int : ESP_ROM_ERR_INVALID_ARG for invalid address, 0 for success
  704. */
  705. int Cache_Dbus_Pms_Set_Addr(uint32_t dbus_boundary0_addr, uint32_t dbus_boundary1_addr, uint32_t dbus_boundary2_addr);
  706. /**
  707. * @brief Set three dbus pms attribute, which will determine pms in different section and world.
  708. * Please do not call this function in your SDK application.
  709. *
  710. * @param uint32_t dbus_pms_sct2_attr : attr for section2
  711. *
  712. * @param uint32_t dbus_pms_sct1_attr : attr for section1
  713. *
  714. * @return None
  715. */
  716. void Cache_Dbus_Pms_Set_Attr(uint32_t dbus_pms_sct2_attr, uint32_t dbus_pms_sct1_attr);
  717. /**
  718. * @brief Used by SPI flash mmap
  719. *
  720. */
  721. uint32_t flash_instr_rodata_start_page(uint32_t bus);
  722. uint32_t flash_instr_rodata_end_page(uint32_t bus);
  723. #ifdef __cplusplus
  724. }
  725. #endif
  726. #endif /* _ROM_CACHE_H_ */