cache.h 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609
  1. /*
  2. * SPDX-FileCopyrightText: 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 TAG_SIZE 4
  20. // L1 icache
  21. /* basic param
  22. */
  23. #define MAX_L1_ICACHE_SIZE (16 * 1024)
  24. #define MAX_L1_ICACHE_WAY 4
  25. #define MAX_L1_ICACHE_BANK_NUM 1
  26. #define MIN_L1_ICACHE_LINE_SIZE 64
  27. /* cal param
  28. */
  29. #define MAX_L1_ITAG_BANK_ITEMS (MAX_L1_ICACHE_SIZE / MAX_L1_ICACHE_BANK_NUM / MIN_L1_ICACHE_LINE_SIZE)
  30. #define MAX_L1_ITAG_BANK_WAY_ITEMS (MAX_L1_ITAG_BANK_ITEMS / MAX_L1_ICACHE_WAY)
  31. #define MAX_L1_ITAG_BANK_SIZE (MAX_L1_ITAG_BANK_ITEMS * TAG_SIZE)
  32. #define MAX_L1_ITAG_BANK_WAY_SIZE (MAX_L1_ITAG_BANK_WAY_ITEMS * TAG_SIZE)
  33. // L1 dcache
  34. /* basic param
  35. */
  36. #define MAX_L1_DCACHE_SIZE (64 * 1024)
  37. #define MAX_L1_DCACHE_WAY 2
  38. #define MAX_L1_DCACHE_BANK_NUM 4
  39. #define MIN_L1_DCACHE_LINE_SIZE 64
  40. /* cal param
  41. */
  42. #define MAX_L1_DTAG_BANK_ITEMS (MAX_L1_DCACHE_SIZE / MAX_L1_DCACHE_BANK_NUM / MIN_L1_DCACHE_LINE_SIZE)
  43. #define MAX_L1_DTAG_BANK_WAY_ITEMS (MAX_L1_DTAG_BANK_ITEMS / MAX_L1_DCACHE_WAY)
  44. #define MAX_L1_DTAG_BANK_SIZE (MAX_L1_DTAG_BANK_ITEMS * TAG_SIZE)
  45. #define MAX_L1_DTAG_BANK_WAY_SIZE (MAX_L1_DTAG_BANK_WAY_ITEMS * TAG_SIZE)
  46. // L2 cache
  47. /* basic param
  48. */
  49. #define MAX_L2_CACHE_SIZE (256 * 1024)
  50. #define MAX_L2_CACHE_WAY 8
  51. #define MAX_L2_CACHE_BANK_NUM 2
  52. // l2 cache line size only has 32/64B, 16 here used to calc tag in memory_access.c
  53. #define MIN_L2_CACHE_LINE_SIZE 64
  54. /* cal param
  55. */
  56. #define MAX_L2_TAG_BANK_ITEMS (MAX_L2_CACHE_SIZE / MAX_L2_CACHE_BANK_NUM / MIN_L2_CACHE_LINE_SIZE)
  57. #define MAX_L2_TAG_BANK_WAY_ITEMS (MAX_L2_TAG_BANK_ITEMS / MAX_L2_CACHE_WAY)
  58. #define MAX_L2_TAG_BANK_SIZE (MAX_L2_TAG_BANK_ITEMS * TAG_SIZE)
  59. #define MAX_L2_TAG_BANK_WAY_SIZE (MAX_L2_TAG_BANK_WAY_ITEMS * TAG_SIZE)
  60. /*
  61. * Simple MMU related defines
  62. */
  63. #define SMMU_GID_MIN 0
  64. #define SMMU_GID_MAX 15
  65. /*
  66. * GID = 0 is a special group id, when accessing l2 memory, all accesses are treated as GID=0
  67. * GID = 1...15, are used in MSPI
  68. */
  69. #define SMMU_GID_DEFAULT 0
  70. #define SMMU_ENTRY_INDEX_LOW 0
  71. // should NOT =
  72. #define SMMU_ENTRY_INDEX_HIGH 1024
  73. #define SMMU_ENTRY_NUM (SMMU_ENTRY_INDEX_HIGH - SMMU_ENTRY_INDEX_LOW)
  74. #define SMMU_SHARED_TBIT_INDEX 1024
  75. #define SMMU_GID_TBIT_NUM 16
  76. #define SMMU_GID_TBIT_INDEX_LOW 1025
  77. // should NOT =
  78. #define SMMU_GID_TBIT_INDEX_HIGH (SMMU_GID_TBIT_INDEX_LOW + SMMU_GID_TBIT_NUM)
  79. typedef enum {
  80. CACHE_L1_ICACHE0 = 0,
  81. CACHE_L1_ICACHE1 = 1,
  82. CACHE_L1_DCACHE = 4,
  83. CACHE_L2_CACHE = 5,
  84. } cache_t;
  85. typedef enum {
  86. CACHE_SIZE_128K = 9,
  87. CACHE_SIZE_256K = 10,
  88. CACHE_SIZE_512K = 11,
  89. } cache_size_t;
  90. typedef enum {
  91. CACHE_2WAYS_ASSOC = 0, /*!< 2 way associated cache */
  92. CACHE_4WAYS_ASSOC = 1, /*!< 4 way associated cache */
  93. CACHE_8WAYS_ASSOC = 2, /*!< 8 way associated cache */
  94. } cache_ways_t;
  95. typedef enum {
  96. CACHE_LINE_SIZE_64B = 3, /*!< 64 Byte cache line size */
  97. CACHE_LINE_SIZE_128B = 4, /*!< 128 Byte cache line size */
  98. } cache_line_size_t;
  99. typedef enum {
  100. CACHE_AUTOLOAD_POSITIVE = 0, /*!< cache autoload step is positive */
  101. CACHE_AUTOLOAD_NEGATIVE = 1, /*!< cache autoload step is negative */
  102. } cache_autoload_order_t;
  103. #define CACHE_AUTOLOAD_STEP(i) ((i)-1)
  104. typedef enum {
  105. CACHE_AUTOLOAD_MISS_TRIGGER = 0, /*!< autoload only triggered by cache miss */
  106. CACHE_AUTOLOAD_HIT_TRIGGER = 1, /*!< autoload only triggered by cache hit */
  107. CACHE_AUTOLOAD_BOTH_TRIGGER = 2, /*!< autoload triggered both by cache miss and hit */
  108. } cache_autoload_trigger_t;
  109. typedef enum {
  110. CACHE_FREEZE_ACK_BUSY = 0, /*!< in this mode, cache ack busy to CPU if a cache miss happens*/
  111. CACHE_FREEZE_ACK_ERROR = 1, /*!< in this mode, cache ack wrong data to CPU and trigger an error if a cache miss happens */
  112. } cache_freeze_mode_t;
  113. struct cache_mode {
  114. uint32_t cache_size; /*!< cache size in byte */
  115. uint16_t cache_line_size; /*!< cache line size in byte */
  116. uint8_t cache_ways; /*!< cache ways, always 4 */
  117. cache_t cache_type; /*!< the cache type indicated by cache_t*/
  118. };
  119. // l1 itag
  120. struct l1_itag_item {
  121. uint32_t valid : 1;
  122. uint32_t lock : 1;
  123. uint32_t tag : 16;
  124. uint32_t gid : 4;
  125. uint32_t replace : 2;
  126. uint32_t reserved : 8;
  127. };
  128. // l1 dtag
  129. struct l1_dtag_item {
  130. uint32_t dirty : 1;
  131. uint32_t valid : 1;
  132. uint32_t lock : 1;
  133. uint32_t tag : 13;
  134. uint32_t gid : 4;
  135. uint32_t replace : 1;
  136. uint32_t reserved : 11;
  137. };
  138. // l2 tag
  139. struct l2_tag_item {
  140. uint32_t dirty : 1;
  141. uint32_t valid : 1;
  142. uint32_t lock : 1;
  143. uint32_t tag : 14;
  144. uint32_t gid : 4;
  145. uint32_t replace : 1;
  146. uint32_t reserved : 10;
  147. };
  148. struct l1_icache_autoload_config {
  149. uint8_t gid;
  150. uint8_t order;
  151. uint8_t trigger;
  152. uint8_t ena0;
  153. uint8_t ena1;
  154. uint32_t addr0;
  155. uint32_t size0;
  156. uint32_t addr1;
  157. uint32_t size1;
  158. };
  159. // l1 dcache and l2 cache both have 4 autoload regions
  160. struct l1_dcache_l2_autoload_config {
  161. uint8_t gid;
  162. uint8_t order;
  163. uint8_t trigger;
  164. uint8_t ena0;
  165. uint8_t ena1;
  166. uint8_t ena2;
  167. uint8_t ena3;
  168. uint32_t addr0;
  169. uint32_t size0;
  170. uint32_t addr1;
  171. uint32_t size1;
  172. uint32_t addr2;
  173. uint32_t size2;
  174. uint32_t addr3;
  175. uint32_t size3;
  176. };
  177. struct tag_group_info {
  178. int use_legacy; /*!< 0 for new tag api, 1 for old tag api*/
  179. struct cache_mode mode;
  180. uint32_t filter_addr;
  181. uint32_t vaddr_offset;
  182. uint32_t tag_addr[MAX_L2_CACHE_WAY];
  183. };
  184. struct lock_config {
  185. uint32_t gid;
  186. uint32_t addr; /*!< manual lock address*/
  187. uint16_t size; /*!< manual lock size*/
  188. uint16_t group; /*!< manual lock group, 0 or 1*/
  189. };
  190. typedef enum {
  191. CACHE_LOCK_LOCK = BIT(0),
  192. CACHE_LOCK_UNLOCK = BIT(1),
  193. } cache_lock_t;
  194. typedef enum {
  195. CACHE_SYNC_INVALIDATE = BIT(0),
  196. CACHE_SYNC_CLEAN = BIT(1),
  197. CACHE_SYNC_WRITEBACK = BIT(2),
  198. CACHE_SYNC_WRITEBACK_INVALIDATE = BIT(3),
  199. } cache_sync_t;
  200. #define CACHE_MAP_L1_ICACHE_0 BIT(0)
  201. #define CACHE_MAP_L1_ICACHE_1 BIT(1)
  202. #define CACHE_MAP_L1_DCACHE BIT(4)
  203. #define CACHE_MAP_L2_CACHE BIT(5)
  204. #define CACHE_MAP_L1_ICACHE_MASK (CACHE_MAP_L1_ICACHE_0 | CACHE_MAP_L1_ICACHE_1)
  205. #define CACHE_MAP_MASK (CACHE_MAP_L1_ICACHE_MASK | CACHE_MAP_L1_DCACHE | CACHE_MAP_L2_CACHE)
  206. struct cache_internal_stub_table {
  207. uint32_t (*l1_icache_line_size)(void);
  208. uint32_t (*l1_dcache_line_size)(void);
  209. uint32_t (*l2_cache_line_size)(void);
  210. uint32_t (*cache_addr)(uint32_t addr);
  211. // sync, type: invalidate/clean/writeback map: l1i0~3/l1d/l2
  212. void (*sync_cache_items)(uint32_t gid, uint32_t type, uint32_t map, uint32_t addr, uint32_t bytes);
  213. // lock: 0 -> unlock op, 1 -> lock op
  214. void (*lock_cache_items)(uint32_t gid, uint32_t lock, uint32_t map, uint32_t addr, uint32_t bytes);
  215. //autoload
  216. uint32_t (*suspend_l1_icache0_autoload)(void);
  217. void (*resume_l1_icache0_autoload)(uint32_t autoload);
  218. uint32_t (*suspend_l1_icache1_autoload)(void);
  219. void (*resume_l1_icache1_autoload)(uint32_t autoload);
  220. uint32_t (*suspend_l1_dcache_autoload)(void);
  221. void (*resume_l1_dcache_autoload)(uint32_t autoload);
  222. uint32_t (*suspend_l2_cache_autoload)(void);
  223. void (*resume_l2_cache_autoload)(uint32_t autoload);
  224. // freeze
  225. void (*freeze_l1_icache0_enable)(cache_freeze_mode_t mode);
  226. void (*freeze_l1_icache0_disable)(void);
  227. void (*freeze_l1_icache1_enable)(cache_freeze_mode_t mode);
  228. void (*freeze_l1_icache1_disable)(void);
  229. void (*freeze_l1_dcache_enable)(cache_freeze_mode_t mode);
  230. void (*freeze_l1_dcache_disable)(void);
  231. void (*freeze_l2_cache_enable)(cache_freeze_mode_t mode);
  232. void (*freeze_l2_cache_disable)(void);
  233. // op
  234. int (*op_addr)(uint32_t gid,
  235. uint32_t op_type,
  236. uint32_t map,
  237. uint32_t start_addr,
  238. uint32_t size,
  239. uint32_t cache_line_size,
  240. uint32_t max_sync_num,
  241. void (*cache_op)(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t));
  242. };
  243. typedef void (*cache_op_start)(void);
  244. typedef void (*cache_op_end)(void);
  245. typedef struct {
  246. cache_op_start start;
  247. cache_op_end end;
  248. } cache_op_cb_t;
  249. extern const struct cache_internal_stub_table *rom_cache_internal_table_ptr;
  250. extern const cache_op_cb_t *rom_cache_op_cb;
  251. #define ESP_ROM_ERR_INVALID_ARG 1
  252. #define MMU_SET_ADDR_ALIGNED_ERROR 2
  253. #define MMU_SET_PASE_SIZE_ERROR 3
  254. #define MMU_SET_VADDR_OUT_RANGE 4
  255. /**
  256. * @brief Initialise cache mmu, mark all entries as invalid.
  257. * Please do not call this function in your SDK application.
  258. *
  259. * @param None
  260. *
  261. * @return None
  262. */
  263. void Cache_FLASH_MMU_Init(void);
  264. /**
  265. * @brief Initialise cache mmu, mark all entries as invalid.
  266. * Please do not call this function in your SDK application.
  267. *
  268. * @param None
  269. *
  270. * @return None
  271. */
  272. void Cache_PSRAM_MMU_Init(void);
  273. /**
  274. * @brief Set ICache mmu mapping.
  275. * Please do not call this function in your SDK application.
  276. *
  277. * @param uint32_t sensitive : Need encryption/ecc check for the page
  278. *
  279. * @param uint32_t vaddr : virtual address in CPU address space.
  280. * Can be Iram0,Iram1,Irom0,Drom0 and AHB buses address.
  281. * Should be aligned by psize.
  282. *
  283. * @param uint32_t paddr : physical address in external memory.
  284. * Should be aligned by psize.
  285. *
  286. * @param uint32_t psize : page size of ICache, in kilobytes. Should be 64 here.
  287. *
  288. * @param uint32_t num : pages to be set.
  289. *
  290. * @param uint32_t fixed : 0 for physical pages grow with virtual pages, other for virtual pages map to same physical page.
  291. *
  292. * @return uint32_t: error status
  293. * 0 : mmu set success
  294. * 2 : vaddr or paddr is not aligned
  295. * 3 : psize error
  296. * 4 : vaddr is out of range
  297. */
  298. int Cache_FLASH_MMU_Set(uint32_t sensitive, uint32_t vaddr, uint32_t paddr, uint32_t psize, uint32_t num, uint32_t fixed);
  299. /**
  300. * @brief Set Cache mmu mapping for dual_bank mspi.
  301. * Please do not call this function in your SDK application.
  302. *
  303. * @param uint32_t sensitive : Need encryption/ecc check for the page
  304. *
  305. * @param uint32_t vaddr : virtual address in CPU address space.
  306. * Can be Iram0,Iram1,Irom0,Drom0 and AHB buses address.
  307. * Should be aligned by psize.
  308. *
  309. * @param uint32_t paddr : physical address in external memory.
  310. * Should be aligned by psize.
  311. *
  312. * @param uint32_t psize : page size of ICache, in kilobytes. Should be 64 here.
  313. *
  314. * @param uint32_t num : pages to be set.
  315. *
  316. * @param uint32_t fixed : 0 for physical pages grow with virtual pages, other for virtual pages map to same physical page.
  317. *
  318. * @return uint32_t: error status
  319. * 0 : mmu set success
  320. * 2 : vaddr or paddr is not aligned
  321. * 3 : psize error
  322. * 4 : vaddr is out of range
  323. */
  324. int Cache_PSRAM_MMU_Set(uint32_t sensitive, uint32_t vaddr, uint32_t paddr, uint32_t psize, uint32_t num, uint32_t fixed);
  325. /**
  326. * @brief Wrapper for Cache_MSPI_MMU_Set, which sets the sensitive bit according to flash encryption efuse
  327. * Please do not call this function in your SDK application.
  328. *
  329. * @param uint32_t vaddr : virtual address in CPU address space.
  330. * Can be Iram0,Iram1,Irom0,Drom0 and AHB buses address.
  331. * Should be aligned by psize.
  332. *
  333. * @param uint32_t paddr : physical address in external memory.
  334. * Should be aligned by psize.
  335. *
  336. * @param uint32_t psize : page size of ICache, in kilobytes. Should be 64 here.
  337. *
  338. * @param uint32_t num : pages to be set.
  339. *
  340. * @param uint32_t fixed : 0 for physical pages grow with virtual pages, other for virtual pages map to same physical page.
  341. *
  342. * @return uint32_t: error status
  343. * 0 : mmu set success
  344. * 2 : vaddr or paddr is not aligned
  345. * 3 : psize error
  346. * 4 : vaddr is out of range
  347. */
  348. int Cache_FLASH_MMU_Set_Secure(uint32_t vaddr, uint32_t paddr, uint32_t psize, uint32_t num, uint32_t fixed);
  349. /**
  350. * @brief Wrapper for Cache_DB_MSPI_MMU_Set, which sets the sensitive bit according to flash encryption efuse
  351. * Please do not call this function in your SDK application.
  352. *
  353. * @param uint32_t ext_ram : MMU_MSPI_ACCESS_FLASH for flash, MMU_MSPI_ACCESS_SPIRAM for spiram, DPORT_MMU_INVALID for invalid.
  354. *
  355. * @param uint32_t vaddr : virtual address in CPU address space.
  356. * Can be Iram0,Iram1,Irom0,Drom0 and AHB buses address.
  357. * Should be aligned by psize.
  358. *
  359. * @param uint32_t paddr : physical address in external memory.
  360. * Should be aligned by psize.
  361. *
  362. * @param uint32_t psize : page size of ICache, in kilobytes. Should be 64 here.
  363. *
  364. * @param uint32_t num : pages to be set.
  365. *
  366. * @param uint32_t fixed : 0 for physical pages grow with virtual pages, other for virtual pages map to same physical page.
  367. *
  368. * @return uint32_t: error status
  369. * 0 : mmu set success
  370. * 2 : vaddr or paddr is not aligned
  371. * 3 : psize error
  372. * 4 : vaddr is out of range
  373. */
  374. int Cache_PSRAM_MMU_Set_Secure(uint32_t vaddr, uint32_t paddr, uint32_t psize, uint32_t num, uint32_t fixed);
  375. /**
  376. * @brief Count the pages in the bus room address which map to Flash.
  377. * Please do not call this function in your SDK application.
  378. *
  379. * @param uint32_t bus : the bus to count with.
  380. *
  381. * @param uint32_t * page0_mapped : value should be initial by user, 0 for not mapped, other for mapped count.
  382. *
  383. * return uint32_t : the number of pages which map to Flash.
  384. */
  385. uint32_t Cache_Count_Flash_Pages(uint32_t *page0_mapped);
  386. /**
  387. * @brief Copy Instruction or rodata from Flash to SPIRAM, and remap to SPIRAM.
  388. * Please do not call this function in your SDK application.
  389. *
  390. * @param uint32_t bus : the bus which need to copy to SPIRAM.
  391. *
  392. * @param uint32_t bus_start_addr : the start virtual address for the bus.
  393. *
  394. * @param uint32_t start_page : the start (64KB) page number in SPIRAM.
  395. *
  396. * @param uint32_t * page0_page : the flash page0 in SPIRAM page number, 0xffff for invalid.
  397. *
  398. * return uint32_t : the next start page number for SPIRAM not mapped.
  399. */
  400. uint32_t Cache_Flash_To_SPIRAM_Copy(uint32_t bus_start_addr, uint32_t start_page, uint32_t *page0_page);
  401. /**
  402. * @brief Get cache mode of L1 cache/L2 cache.
  403. * Please do not call this function in your SDK application.
  404. *
  405. * @param struct cache_mode * mode : the pointer of cache mode struct, caller should set the icache field
  406. *
  407. * return none
  408. */
  409. void Cache_Get_Mode(struct cache_mode *mode);
  410. /**
  411. * @brief set L2 Cache modes: cache size, associate ways and cache line size.
  412. * Please do not call this function in your SDK application.
  413. *
  414. * @param cache_size_t cache_size : the cache size, can be CACHE_SIZE_128K/CACHE_SIZE_256K
  415. *
  416. * @param cache_ways_t ways : the associate ways of cache, can be CACHE_4WAYS_ASSOC and CACHE_8WAYS_ASSOC
  417. *
  418. * @param cache_line_size_t cache_line_size : the cache line size, can be CACHE_LINE_SIZE_32B/CACHE_LINE_SIZE_64B
  419. *
  420. * return none
  421. */
  422. void Cache_Set_L2_Cache_Mode(cache_size_t cache_size, cache_ways_t ways, cache_line_size_t cache_line_size);
  423. /**
  424. * @brief check if the address is accessed through Cache.
  425. * Please do not call this function in your SDK application.
  426. *
  427. * @param uint32_t addr : the address to check.
  428. *
  429. * @return 1 if the address is accessed through ICache, 0 if not.
  430. */
  431. uint32_t Cache_Address_Through_Cache(uint32_t addr);
  432. /**
  433. * @brief Init l1 Cache in early time, used to speed up rom access time.
  434. *
  435. * @param None
  436. *
  437. * @return None
  438. */
  439. void ROM_L1_Cache_Init(void);
  440. /**
  441. * @brief Init Cache for ROM boot, including resetting the Dcache, initializing Owner, MMU, setting DCache mode, Enabling DCache, unmasking bus.
  442. *
  443. * @param None
  444. *
  445. * @return None
  446. */
  447. void ROM_Boot_Cache_Init(void);
  448. /**
  449. * @brief Init Cache for ROM direct boot, including resetting the I/Dcache, initializing Owner, MMU, setting I/DCache mode, Enabling I/DCache, unmasking bus.
  450. *
  451. * @param None
  452. *
  453. * @return None
  454. */
  455. void ROM_Direct_Boot_Cache_Init(void);
  456. /**
  457. * @brief Init MMU for ROM direct boot, including mapping all ibus region and dbus region
  458. *
  459. * @param None
  460. *
  461. * @return 0 if mmu map is sucessfully, others if not.
  462. */
  463. int ROM_Direct_Boot_MMU_Init(void);
  464. /**
  465. * @brief After cache reset (hw or sw), wait cache sync done until it can start work.
  466. *
  467. * @param None
  468. *
  469. * @return None
  470. */
  471. void Cache_Wait_Idle(void);
  472. /**
  473. * @brief Cache address operation wrapper for sync and lock operation.
  474. * Please do not call this function in your SDK application.
  475. *
  476. * @param uint32_t op_type: operation type
  477. *
  478. * @param uint32_t map: operation which cache
  479. *
  480. * @param uint32_t start_addr: operation start address
  481. *
  482. * @param uint32_t cache_line_size: corresponding cache line size to op_icache
  483. *
  484. * @param uint32_t max_sync_num: max sync cache line count in one operation. Can be CACHE_MAX_SYNC_NUM or CACHE_MAX_LOCK_NUM
  485. *
  486. * @param void(* cache_op)(uint32_t, uint32_t, uint32_t, uint32_t): cache operation hook
  487. *
  488. * @return 0 for success
  489. * 1 for invalid argument
  490. */
  491. int Cache_Op_Addr(uint32_t gid,
  492. uint32_t op_type,
  493. uint32_t map,
  494. uint32_t start_addr,
  495. uint32_t size,
  496. uint32_t cache_line_size,
  497. uint32_t max_sync_num,
  498. void (*cache_op)(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t));
  499. /**
  500. * @brief Invalidate the Cache items in the region from Cache.
  501. * If the region is not in Cache addr room, nothing will be done.
  502. * Please do not call this function in your SDK application.
  503. *
  504. * @param uint32_t map : operation which cache
  505. *
  506. * @param uint32_t addr : invalidated region start address.
  507. *
  508. * @param uint32_t size : invalidated region size.
  509. *
  510. * @return 0 for success
  511. * 1 for invalid argument
  512. */
  513. int Cache_Invalidate_Addr(uint32_t map, uint32_t addr, uint32_t size);
  514. /**
  515. * @brief Invalidate the Cache items in the region from Cache.
  516. * If the region is not in Cache addr room, nothing will be done.
  517. * Please do not call this function in your SDK application.
  518. *
  519. * @param uint32_t map : operation which cache
  520. *
  521. * @param uint32_t addr : invalidated region start address.
  522. *
  523. * @param uint32_t size : invalidated region size.
  524. *
  525. * @return 0 for success
  526. * 1 for invalid argument
  527. */
  528. int Cache_Invalidate_Addr_Gid(uint32_t gid, uint32_t map, uint32_t addr, uint32_t size);
  529. /**
  530. * @brief Clean the dirty bit of Cache items in the region from Cache.
  531. * If the region is not in Cache addr room, nothing will be done.
  532. * Please do not call this function in your SDK application.
  533. *
  534. * @param uint32_t map : operation which cache
  535. *
  536. * @param uint32_t addr : cleaned region start address.
  537. *
  538. * @param uint32_t size : cleaned region size.
  539. *
  540. * @return 0 for success
  541. * 1 for invalid argument
  542. */
  543. int Cache_Clean_Addr(uint32_t map, uint32_t addr, uint32_t size);
  544. /**
  545. * @brief Clean the dirty bit of Cache items in the region from Cache.
  546. * If the region is not in Cache addr room, nothing will be done.
  547. * Please do not call this function in your SDK application.
  548. *
  549. * @param uint32_t map : operation which cache
  550. *
  551. * @param uint32_t addr : cleaned region start address.
  552. *
  553. * @param uint32_t size : cleaned region size.
  554. *
  555. * @return 0 for success
  556. * 1 for invalid argument
  557. */
  558. int Cache_Clean_Addr_Gid(uint32_t gid, uint32_t map, uint32_t addr, uint32_t size);
  559. /**
  560. * @brief Writeback the Cache items(also clean the dirty bit) in the region from Cache.
  561. * If the region is not in Cache addr room, nothing will be done.
  562. * Please do not call this function in your SDK application.
  563. *
  564. * @param uint32_t map : operation which cache
  565. *
  566. * @param uint32_t addr : writeback region start address.
  567. *
  568. * @param uint32_t size : writeback region size.
  569. *
  570. * @return 0 for success
  571. * 1 for invalid argument
  572. */
  573. int Cache_WriteBack_Addr(uint32_t map, uint32_t addr, uint32_t size);
  574. /**
  575. * @brief Writeback the Cache items(also clean the dirty bit) in the region from Cache.
  576. * If the region is not in Cache addr room, nothing will be done.
  577. * Please do not call this function in your SDK application.
  578. *
  579. * @param uint32_t map : operation which cache
  580. *
  581. * @param uint32_t addr : writeback region start address.
  582. *
  583. * @param uint32_t size : writeback region size.
  584. *
  585. * @return 0 for success
  586. * 1 for invalid argument
  587. */
  588. int Cache_WriteBack_Addr_Gid(uint32_t gid, uint32_t map, uint32_t addr, uint32_t size);
  589. /**
  590. * @brief Writeback and invalidate the Cache items(also clean the dirty bit) in the region from Cache.
  591. * If the region is not in Cache addr room, nothing will be done.
  592. * Please do not call this function in your SDK application.
  593. *
  594. * @param uint32_t map : operation which cache
  595. *
  596. * @param uint32_t addr : writeback region start address.
  597. *
  598. * @param uint32_t size : writeback region size.
  599. *
  600. * @return 0 for success
  601. * 1 for invalid argument
  602. */
  603. int Cache_WriteBack_Invalidate_Addr(uint32_t map, uint32_t addr, uint32_t size);
  604. /**
  605. * @brief Writeback and invalidate the Cache items(also clean the dirty bit) in the region from Cache.
  606. * If the region is not in Cache addr room, nothing will be done.
  607. * Please do not call this function in your SDK application.
  608. *
  609. * @param uint32_t map : operation which cache
  610. *
  611. * @param uint32_t addr : writeback region start address.
  612. *
  613. * @param uint32_t size : writeback region size.
  614. *
  615. * @return 0 for success
  616. * 1 for invalid argument
  617. */
  618. int Cache_WriteBack_Invalidate_Addr_Gid(uint32_t gid, uint32_t map, uint32_t addr, uint32_t size);
  619. /**
  620. * @brief Invalidate all cache items in ICache.
  621. * Please do not call this function in your SDK application.
  622. *
  623. * @param uint32_t map : operation which cache
  624. *
  625. * @return 0 for success
  626. * 1 for invalid argument
  627. *
  628. * Note: ALAP to use this api in esp32p4, use *Cache_Invalidate_Addr* instead!
  629. */
  630. int Cache_Invalidate_All(uint32_t map);
  631. /**
  632. * @brief Invalidate all cache items in ICache.
  633. * Please do not call this function in your SDK application.
  634. *
  635. * @param uint32_t map : operation which cache
  636. *
  637. * @return 0 for success
  638. * 1 for invalid argument
  639. *
  640. * Note: ALAP to use this api in esp32p4, use *Cache_Invalidate_Addr* instead!
  641. */
  642. int Cache_Invalidate_All_Gid(uint32_t gid, uint32_t map);
  643. /**
  644. * @brief Clean the dirty bit of all cache items in DCache.
  645. * Please do not call this function in your SDK application.
  646. *
  647. * @param uint32_t map : operation which cache
  648. *
  649. * @return 0 for success
  650. * 1 for invalid argument
  651. */
  652. int Cache_Clean_All(uint32_t map);
  653. /**
  654. * @brief Clean the dirty bit of all cache items in DCache.
  655. * Please do not call this function in your SDK application.
  656. *
  657. * @param uint32_t map : operation which cache
  658. *
  659. * @return 0 for success
  660. * 1 for invalid argument
  661. */
  662. int Cache_Clean_All_Gid(uint32_t gid, uint32_t map);
  663. /**
  664. * @brief WriteBack all cache items in DCache.
  665. * Please do not call this function in your SDK application.
  666. *
  667. * @param uint32_t map : operation which cache
  668. *
  669. * @return 0 for success
  670. * 1 for invalid argument
  671. */
  672. int Cache_WriteBack_All(uint32_t map);
  673. /**
  674. * @brief WriteBack all cache items in DCache.
  675. * Please do not call this function in your SDK application.
  676. *
  677. * @param uint32_t map : operation which cache
  678. *
  679. * @return 0 for success
  680. * 1 for invalid argument
  681. */
  682. int Cache_WriteBack_All_Gid(uint32_t gid, uint32_t map);
  683. /**
  684. * @brief WriteBack all cache items in DCache during boot period.
  685. * Please do not call this function in your SDK application.
  686. *
  687. * @param None
  688. *
  689. * @return 0 for success
  690. * 1 for invalid argument
  691. */
  692. int ROM_Boot_Cache_WriteBack(void);
  693. /**
  694. * @brief WriteBack all cache items in DCache.
  695. * Please do not call this function in your SDK application.
  696. *
  697. * @param uint32_t map : operation which cache
  698. *
  699. * @return 0 for success
  700. * 1 for invalid argument
  701. */
  702. int Cache_WriteBack_Invalidate_All(uint32_t map);
  703. /**
  704. * @brief WriteBack all cache items in DCache.
  705. * Please do not call this function in your SDK application.
  706. *
  707. * @param uint32_t map : operation which cache
  708. *
  709. * @return 0 for success
  710. * 1 for invalid argument
  711. */
  712. int Cache_WriteBack_Invalidate_All_Gid(uint32_t gid, uint32_t map);
  713. /**
  714. * @brief Mask all buses through L1 Cache and L2 Cache.
  715. * Please do not call this function in your SDK application.
  716. *
  717. * @param None
  718. *
  719. * @return None
  720. */
  721. void Cache_Mask_All(void);
  722. /**
  723. * @brief Suspend L1 Core0 ICache auto preload operation, then you can resume it after some ICache operations.
  724. * Please do not call this function in your SDK application.
  725. *
  726. * @param None
  727. *
  728. * @return uint32_t : 0 for ICache not auto preload before suspend.
  729. */
  730. uint32_t Cache_Suspend_L1_CORE0_ICache_Autoload(void);
  731. /**
  732. * @brief Resume L1 Core0 ICache auto preload operation after some ICache operations.
  733. * Please do not call this function in your SDK application.
  734. *
  735. * @param uint32_t autoload : 0 for ICache not auto preload before suspend.
  736. *
  737. * @return None.
  738. */
  739. void Cache_Resume_L1_CORE0_ICache_Autoload(uint32_t autoload);
  740. /**
  741. * @brief Suspend L1 Core1 ICache auto preload operation, then you can resume it after some ICache operations.
  742. * Please do not call this function in your SDK application.
  743. *
  744. * @param None
  745. *
  746. * @return uint32_t : 0 for ICache not auto preload before suspend.
  747. */
  748. uint32_t Cache_Suspend_L1_CORE1_ICache_Autoload(void);
  749. /**
  750. * @brief Resume L1 Core0 ICache auto preload operation after some ICache operations.
  751. * Please do not call this function in your SDK application.
  752. *
  753. * @param uint32_t autoload : 0 for ICache not auto preload before suspend.
  754. *
  755. * @return None.
  756. */
  757. void Cache_Resume_L1_CORE1_ICache_Autoload(uint32_t autoload);
  758. /**
  759. * @brief Suspend L1 DCache auto preload operation, then you can resume it after some ICache operations.
  760. * Please do not call this function in your SDK application.
  761. *
  762. * @param None
  763. *
  764. * @return uint32_t : 0 for ICache not auto preload before suspend.
  765. */
  766. uint32_t Cache_Suspend_L1_DCache_Autoload(void);
  767. /**
  768. * @brief Resume L1 DCache auto preload operation after some ICache operations.
  769. * Please do not call this function in your SDK application.
  770. *
  771. * @param uint32_t autoload : 0 for ICache not auto preload before suspend.
  772. *
  773. * @return None.
  774. */
  775. void Cache_Resume_L1_DCache_Autoload(uint32_t autoload);
  776. /**
  777. * @brief Suspend L2 Cache auto preload operation, then you can resume it after some ICache operations.
  778. * Please do not call this function in your SDK application.
  779. *
  780. * @param None
  781. *
  782. * @return uint32_t : 0 for ICache not auto preload before suspend.
  783. */
  784. uint32_t Cache_Suspend_L2_Cache_Autoload(void);
  785. /**
  786. * @brief Resume L2 Cache auto preload operation after some ICache operations.
  787. * Please do not call this function in your SDK application.
  788. *
  789. * @param uint32_t autoload : 0 for ICache not auto preload before suspend.
  790. *
  791. * @return None.
  792. */
  793. void Cache_Resume_L2_Cache_Autoload(uint32_t autoload);
  794. /**
  795. * @brief Start an L1 Core0 ICache manual preload, will suspend auto preload of ICache.
  796. * Please do not call this function in your SDK application.
  797. *
  798. * @param uint32_t addr : start address of the preload region.
  799. *
  800. * @param uint32_t size : size of the preload region, should not exceed the size of ICache.
  801. *
  802. * @param uint32_t order : the preload order, 0 for positive, other for negative
  803. *
  804. * @return uint32_t : 0 for ICache not auto preload before manual preload.
  805. */
  806. uint32_t Cache_Start_L1_CORE0_ICache_Preload(uint32_t addr, uint32_t size, uint32_t order);
  807. /**
  808. * @brief Return if the ICache manual preload done.
  809. * Please do not call this function in your SDK application.
  810. *
  811. * @param None
  812. *
  813. * @return uint32_t : 0 for ICache manual preload not done.
  814. */
  815. uint32_t Cache_L1_CORE0_ICache_Preload_Done(void);
  816. /**
  817. * @brief End the ICache manual preload to resume auto preload of ICache.
  818. * Please do not call this function in your SDK application.
  819. *
  820. * @param uint32_t autoload : 0 for ICache not auto preload before manual preload.
  821. *
  822. * @return None
  823. */
  824. void Cache_End_L1_CORE0_ICache_Preload(uint32_t autoload);
  825. /**
  826. * @brief Start an L1 Core1 ICache manual preload, will suspend auto preload of DCache.
  827. * Please do not call this function in your SDK application.
  828. *
  829. * @param uint32_t addr : start address of the preload region.
  830. *
  831. * @param uint32_t size : size of the preload region, should not exceed the size of DCache.
  832. *
  833. * @param uint32_t order : the preload order, 0 for positive, other for negative
  834. *
  835. * @return uint32_t : 0 for DCache not auto preload before manual preload.
  836. */
  837. uint32_t Cache_Start_L1_CORE1_ICache_Preload(uint32_t addr, uint32_t size, uint32_t order);
  838. /**
  839. * @brief Return if the DCache manual preload done.
  840. * Please do not call this function in your SDK application.
  841. *
  842. * @param None
  843. *
  844. * @return uint32_t : 0 for DCache manual preload not done.
  845. */
  846. uint32_t Cache_L1_CORE1_ICache_Preload_Done(void);
  847. /**
  848. * @brief End the DCache manual preload to resume auto preload of DCache.
  849. * Please do not call this function in your SDK application.
  850. *
  851. * @param uint32_t autoload : 0 for DCache not auto preload before manual preload.
  852. *
  853. * @return None
  854. */
  855. void Cache_End_L1_CORE1_ICache_Preload(uint32_t autoload);
  856. /**
  857. * @brief Start an L1 DCache manual preload, will suspend auto preload of DCache.
  858. * Please do not call this function in your SDK application.
  859. *
  860. * @param uint32_t addr : start address of the preload region.
  861. *
  862. * @param uint32_t size : size of the preload region, should not exceed the size of DCache.
  863. *
  864. * @param uint32_t order : the preload order, 0 for positive, other for negative
  865. *
  866. * @return uint32_t : 0 for DCache not auto preload before manual preload.
  867. */
  868. uint32_t Cache_Start_L1_DCache_Preload(uint32_t addr, uint32_t size, uint32_t order);
  869. /**
  870. * @brief Return if the DCache manual preload done.
  871. * Please do not call this function in your SDK application.
  872. *
  873. * @param None
  874. *
  875. * @return uint32_t : 0 for DCache manual preload not done.
  876. */
  877. uint32_t Cache_L1_DCache_Preload_Done(void);
  878. /**
  879. * @brief End the DCache manual preload to resume auto preload of DCache.
  880. * Please do not call this function in your SDK application.
  881. *
  882. * @param uint32_t autoload : 0 for DCache not auto preload before manual preload.
  883. *
  884. * @return None
  885. */
  886. void Cache_End_L1_DCache_Preload(uint32_t autoload);
  887. /**
  888. * @brief Start an L2 Cache manual preload, will suspend auto preload of DCache.
  889. * Please do not call this function in your SDK application.
  890. *
  891. * @param uint32_t addr : start address of the preload region.
  892. *
  893. * @param uint32_t size : size of the preload region, should not exceed the size of DCache.
  894. *
  895. * @param uint32_t order : the preload order, 0 for positive, other for negative
  896. *
  897. * @return uint32_t : 0 for DCache not auto preload before manual preload.
  898. */
  899. uint32_t Cache_Start_L2_Cache_Preload(uint32_t addr, uint32_t size, uint32_t order);
  900. /**
  901. * @brief Return if the DCache manual preload done.
  902. * Please do not call this function in your SDK application.
  903. *
  904. * @param None
  905. *
  906. * @return uint32_t : 0 for DCache manual preload not done.
  907. */
  908. uint32_t Cache_L2_Cache_Preload_Done(void);
  909. /**
  910. * @brief End the DCache manual preload to resume auto preload of DCache.
  911. * Please do not call this function in your SDK application.
  912. *
  913. * @param uint32_t autoload : 0 for DCache not auto preload before manual preload.
  914. *
  915. * @return None
  916. */
  917. void Cache_End_L2_Cache_Preload(uint32_t autoload);
  918. /**
  919. * @brief Config autoload parameters of L1 Core0 ICache.
  920. * Please do not call this function in your SDK application.
  921. *
  922. * @param struct autoload_config * config : autoload parameters.
  923. *
  924. * @return ESP_ROM_ERR_INVALID_ARG : invalid param, 0 : success
  925. */
  926. void Cache_Config_L1_CORE0_ICache_Autoload(const struct l1_icache_autoload_config *config);
  927. /**
  928. * @brief Enable auto preload for L1 Core0 ICache.
  929. * Please do not call this function in your SDK application.
  930. *
  931. * @param None
  932. *
  933. * @return None
  934. */
  935. void Cache_Enable_L1_CORE0_ICache_Autoload(void);
  936. /**
  937. * @brief Disable auto preload for L1 Core0 ICache.
  938. * Please do not call this function in your SDK application.
  939. *
  940. * @param None
  941. *
  942. * @return None
  943. */
  944. void Cache_Disable_L1_CORE0_ICache_Autoload(void);
  945. /**
  946. * @brief Config autoload parameters of L1 Core1 ICache.
  947. * Please do not call this function in your SDK application.
  948. *
  949. * @param struct autoload_config * config : autoload parameters.
  950. *
  951. * @return ESP_ROM_ERR_INVALID_ARG : invalid param, 0 : success
  952. */
  953. void Cache_Config_L1_CORE1_ICache_Autoload(const struct l1_icache_autoload_config *config);
  954. /**
  955. * @brief Enable auto preload for L1 Core1 ICache.
  956. * Please do not call this function in your SDK application.
  957. *
  958. * @param None
  959. *
  960. * @return None
  961. */
  962. void Cache_Enable_L1_CORE1_ICache_Autoload(void);
  963. /**
  964. * @brief Disable auto preload for L1 Core1 ICache.
  965. * Please do not call this function in your SDK application.
  966. *
  967. * @param None
  968. *
  969. * @return None
  970. */
  971. void Cache_Disable_L1_CORE1_ICache_Autoload(void);
  972. /**
  973. * @brief Config autoload parameters of L1 DCache.
  974. * Please do not call this function in your SDK application.
  975. *
  976. * @param struct autoload_config * config : autoload parameters.
  977. *
  978. * @return ESP_ROM_ERR_INVALID_ARG : invalid param, 0 : success
  979. */
  980. void Cache_Config_L1_DCache_Autoload(const struct l1_dcache_l2_autoload_config *config);
  981. /**
  982. * @brief Enable auto preload for L1 DCache.
  983. * Please do not call this function in your SDK application.
  984. *
  985. * @param None
  986. *
  987. * @return None
  988. */
  989. void Cache_Enable_L1_DCache_Autoload(void);
  990. /**
  991. * @brief Disable auto preload for L1 DCache.
  992. * Please do not call this function in your SDK application.
  993. *
  994. * @param None
  995. *
  996. * @return None
  997. */
  998. void Cache_Disable_L1_DCache_Autoload(void);
  999. /**
  1000. * @brief Config autoload parameters of L2 Cache.
  1001. * Please do not call this function in your SDK application.
  1002. *
  1003. * @param struct autoload_config * config : autoload parameters.
  1004. *
  1005. * @return ESP_ROM_ERR_INVALID_ARG : invalid param, 0 : success
  1006. */
  1007. void Cache_Config_L2_Cache_Autoload(const struct l1_dcache_l2_autoload_config *config);
  1008. /**
  1009. * @brief Enable auto preload for L2 Cache.
  1010. * Please do not call this function in your SDK application.
  1011. *
  1012. * @param None
  1013. *
  1014. * @return None
  1015. */
  1016. void Cache_Enable_L2_Cache_Autoload(void);
  1017. /**
  1018. * @brief Disable auto preload for L2 Cache.
  1019. * Please do not call this function in your SDK application.
  1020. *
  1021. * @param None
  1022. *
  1023. * @return None
  1024. */
  1025. void Cache_Disable_L2_Cache_Autoload(void);
  1026. /**
  1027. * @brief Config a group of prelock parameters of L1 Core0 ICache.
  1028. * Please do not call this function in your SDK application.
  1029. *
  1030. * @param struct lock_config * config : a group of lock parameters.
  1031. *
  1032. * @return None
  1033. */
  1034. void Cache_Enable_L1_CORE0_ICache_PreLock(const struct lock_config *config);
  1035. /**
  1036. * @brief Disable a group of prelock parameters for L1 Core0 ICache.
  1037. * However, the locked data will not be released.
  1038. * Please do not call this function in your SDK application.
  1039. *
  1040. * @param uint16_t group : 0 for group0, 1 for group1.
  1041. *
  1042. * @return None
  1043. */
  1044. void Cache_Disable_L1_CORE0_ICache_PreLock(uint16_t group);
  1045. /**
  1046. * @brief Config a group of prelock parameters of L1 Core1 ICache.
  1047. * Please do not call this function in your SDK application.
  1048. *
  1049. * @param struct lock_config * config : a group of lock parameters.
  1050. *
  1051. * @return None
  1052. */
  1053. void Cache_Enable_L1_CORE1_ICache_PreLock(const struct lock_config *config);
  1054. /**
  1055. * @brief Disable a group of prelock parameters for L1 Core1 ICache.
  1056. * However, the locked data will not be released.
  1057. * Please do not call this function in your SDK application.
  1058. *
  1059. * @param uint16_t group : 0 for group0, 1 for group1.
  1060. *
  1061. * @return None
  1062. */
  1063. void Cache_Disable_L1_CORE1_ICache_PreLock(uint16_t group);
  1064. /**
  1065. * @brief Config a group of prelock parameters of L1 DCache.
  1066. * Please do not call this function in your SDK application.
  1067. *
  1068. * @param struct lock_config * config : a group of lock parameters.
  1069. *
  1070. * @return None
  1071. */
  1072. void Cache_Enable_L1_DCache_PreLock(const struct lock_config *config);
  1073. /**
  1074. * @brief Disable a group of prelock parameters for L1 DCache.
  1075. * However, the locked data will not be released.
  1076. * Please do not call this function in your SDK application.
  1077. *
  1078. * @param uint16_t group : 0 for group0, 1 for group1.
  1079. *
  1080. * @return None
  1081. */
  1082. void Cache_Disable_L1_DCache_PreLock(uint16_t group);
  1083. /**
  1084. * @brief Config a group of prelock parameters of L2 Cache.
  1085. * Please do not call this function in your SDK application.
  1086. *
  1087. * @param struct lock_config * config : a group of lock parameters.
  1088. *
  1089. * @return None
  1090. */
  1091. void Cache_Enable_L2_Cache_PreLock(const struct lock_config *config);
  1092. /**
  1093. * @brief Disable a group of prelock parameters for L2 Cache.
  1094. * However, the locked data will not be released.
  1095. * Please do not call this function in your SDK application.
  1096. *
  1097. * @param uint16_t group : 0 for group0, 1 for group1.
  1098. *
  1099. * @return None
  1100. */
  1101. void Cache_Disable_L2_Cache_PreLock(uint16_t group);
  1102. /**
  1103. * @brief Lock the cache items in tag memory for cache.
  1104. * Please do not call this function in your SDK application.
  1105. *
  1106. * @param uint32_t map : operation which cache
  1107. *
  1108. * @param uint32_t addr : start address of lock region.
  1109. *
  1110. * @param uint32_t size : size of lock region.
  1111. *
  1112. * @return 0 for success
  1113. * 1 for invalid argument
  1114. */
  1115. int Cache_Lock_Addr(uint32_t map, uint32_t addr, uint32_t size);
  1116. /**
  1117. * @brief Unlock the cache items in tag memory for cache.
  1118. * Please do not call this function in your SDK application.
  1119. *
  1120. * @param uint32_t map : operation which cache
  1121. *
  1122. * @param uint32_t addr : start address of unlock region.
  1123. *
  1124. * @param uint32_t size : size of unlock region.
  1125. *
  1126. * @return 0 for success
  1127. * 1 for invalid argument
  1128. */
  1129. int Cache_Unlock_Addr(uint32_t map, uint32_t addr, uint32_t size);
  1130. /**
  1131. * @brief Disable L1 Core0 ICache access for the cpu.
  1132. * This operation will make all ICache tag memory invalid, CPU can't access ICache, ICache will keep idle.
  1133. * Please do not call this function in your SDK application.
  1134. *
  1135. * @return uint32_t : auto preload enabled before
  1136. */
  1137. uint32_t Cache_Disable_L1_CORE0_ICache(void);
  1138. /**
  1139. * @brief Enable L1 Core0 ICache access for the cpu.
  1140. * Please do not call this function in your SDK application.
  1141. *
  1142. * @param uint32_t autoload : ICache will preload then.
  1143. *
  1144. * @return None
  1145. */
  1146. void Cache_Enable_L1_CORE0_ICache(uint32_t autoload);
  1147. /**
  1148. * @brief Suspend L1 Core0 ICache access for the cpu.
  1149. * This operation will make all ICache tag memory invalid, CPU can't access ICache, ICache will keep idle.
  1150. * Please do not call this function in your SDK application.
  1151. *
  1152. * @return uint32_t : auto preload enabled before
  1153. */
  1154. uint32_t Cache_Suspend_L1_CORE0_ICache(void);
  1155. /**
  1156. * @brief Enable L1 Core0 ICache access for the cpu.
  1157. * Please do not call this function in your SDK application.
  1158. *
  1159. * @param uint32_t autoload : ICache will preload then.
  1160. *
  1161. * @return None
  1162. */
  1163. void Cache_Resume_L1_CORE0_ICache(uint32_t autoload);
  1164. /**
  1165. * @brief Disable L1 Core1 ICache access for the cpu.
  1166. * This operation will make all ICache tag memory invalid, CPU can't access ICache, ICache will keep idle.
  1167. * Please do not call this function in your SDK application.
  1168. *
  1169. * @return uint32_t : auto preload enabled before
  1170. */
  1171. uint32_t Cache_Disable_L1_CORE1_ICache(void);
  1172. /**
  1173. * @brief Enable L1 Core1 ICache access for the cpu.
  1174. * Please do not call this function in your SDK application.
  1175. *
  1176. * @param uint32_t autoload : ICache will preload then.
  1177. *
  1178. * @return None
  1179. */
  1180. void Cache_Enable_L1_CORE1_ICache(uint32_t autoload);
  1181. /**
  1182. * @brief Suspend L1 Core1 ICache access for the cpu.
  1183. * This operation will make all ICache tag memory invalid, CPU can't access ICache, ICache will keep idle.
  1184. * Please do not call this function in your SDK application.
  1185. *
  1186. * @return uint32_t : auto preload enabled before
  1187. */
  1188. uint32_t Cache_Suspend_L1_CORE1_ICache(void);
  1189. /**
  1190. * @brief Enable L1 Core1 ICache access for the cpu.
  1191. * Please do not call this function in your SDK application.
  1192. *
  1193. * @param uint32_t autoload : ICache will preload then.
  1194. *
  1195. * @return None
  1196. */
  1197. void Cache_Resume_L1_CORE1_ICache(uint32_t autoload);
  1198. /**
  1199. * @brief Disable L1 DCache access for the cpu.
  1200. * This operation will make all ICache tag memory invalid, CPU can't access ICache, ICache will keep idle.
  1201. * Please do not call this function in your SDK application.
  1202. *
  1203. * @return uint32_t : auto preload enabled before
  1204. */
  1205. uint32_t Cache_Disable_L1_DCache(void);
  1206. /**
  1207. * @brief Enable L1 DCache access for the cpu.
  1208. * Please do not call this function in your SDK application.
  1209. *
  1210. * @param uint32_t autoload : ICache will preload then.
  1211. *
  1212. * @return None
  1213. */
  1214. void Cache_Enable_L1_DCache(uint32_t autoload);
  1215. /**
  1216. * @brief Suspend L1 DCache access for the cpu.
  1217. * This operation will make all ICache tag memory invalid, CPU can't access ICache, ICache will keep idle.
  1218. * Please do not call this function in your SDK application.
  1219. *
  1220. * @return uint32_t : auto preload enabled before
  1221. */
  1222. uint32_t Cache_Suspend_L1_DCache(void);
  1223. /**
  1224. * @brief Enable L1 DCache access for the cpu.
  1225. * Please do not call this function in your SDK application.
  1226. *
  1227. * @param uint32_t autoload : ICache will preload then.
  1228. *
  1229. * @return None
  1230. */
  1231. void Cache_Resume_L1_DCache(uint32_t autoload);
  1232. /**
  1233. * @brief Disable L2 Cache access for the cpu.
  1234. * This operation will make all ICache tag memory invalid, CPU can't access ICache, ICache will keep idle.
  1235. * Please do not call this function in your SDK application.
  1236. *
  1237. * @return uint32_t : auto preload enabled before
  1238. */
  1239. uint32_t Cache_Disable_L2_Cache(void);
  1240. /**
  1241. * @brief Enable L2 Cache access for the cpu.
  1242. * Please do not call this function in your SDK application.
  1243. *
  1244. * @param uint32_t autoload : ICache will preload then.
  1245. *
  1246. * @return None
  1247. */
  1248. void Cache_Enable_L2_Cache(uint32_t autoload);
  1249. /**
  1250. * @brief Suspend L2 Cache access for the cpu.
  1251. * This operation will make all ICache tag memory invalid, CPU can't access ICache, ICache will keep idle.
  1252. * Please do not call this function in your SDK application.
  1253. *
  1254. * @return uint32_t : auto preload enabled before
  1255. */
  1256. uint32_t Cache_Suspend_L2_Cache(void);
  1257. /**
  1258. * @brief Enable L2 Cache access for the cpu.
  1259. * Please do not call this function in your SDK application.
  1260. *
  1261. * @param uint32_t autoload : ICache will preload then.
  1262. *
  1263. * @return None
  1264. */
  1265. void Cache_Resume_L2_Cache(uint32_t autoload);
  1266. /**
  1267. * @brief Get L1 ICache cache line size
  1268. *
  1269. * @param None
  1270. *
  1271. * @return uint32_t: 16, 32, 64 Byte
  1272. */
  1273. uint32_t Cache_Get_L1_ICache_Line_Size(void);
  1274. /**
  1275. * @brief Get L1 DCache cache line size
  1276. *
  1277. * @param None
  1278. *
  1279. * @return uint32_t: 16, 32, 64 Byte
  1280. */
  1281. uint32_t Cache_Get_L1_DCache_Line_Size(void);
  1282. /**
  1283. * @brief Get L2 cache line size
  1284. *
  1285. * @param None
  1286. *
  1287. * @return uint32_t: 16, 32, 64 Byte
  1288. */
  1289. uint32_t Cache_Get_L2_Cache_Line_Size(void);
  1290. /**
  1291. * @brief Get DCache cache line size
  1292. *
  1293. * @param None
  1294. *
  1295. * @return uint32_t: 16, 32, 64 Byte
  1296. */
  1297. uint32_t Cache_Get_DCache_Line_Size(void);
  1298. /**
  1299. * @brief Freeze L1 core0 icache
  1300. *
  1301. * @param cache_freeze_mode_t : mode
  1302. *
  1303. * @return None
  1304. */
  1305. void Cache_Freeze_L1_ICache0_Enable(cache_freeze_mode_t mode);
  1306. /**
  1307. * @brief Disable L1 core0 icache freeze
  1308. *
  1309. * @param None
  1310. *
  1311. * @return None
  1312. */
  1313. void Cache_Freeze_L1_ICache0_Disable(void);
  1314. /**
  1315. * @brief Freeze L1 core1 icache
  1316. *
  1317. * @param cache_freeze_mode_t : mode
  1318. *
  1319. * @return None
  1320. */
  1321. void Cache_Freeze_L1_ICache1_Enable(cache_freeze_mode_t mode);
  1322. /**
  1323. * @brief Disable L1 core1 icache freeze
  1324. *
  1325. * @param None
  1326. *
  1327. * @return None
  1328. */
  1329. void Cache_Freeze_L1_ICache1_Disable(void);
  1330. /**
  1331. * @brief Freeze L1 dcache
  1332. *
  1333. * @param cache_freeze_mode_t : mode
  1334. *
  1335. * @return None
  1336. */
  1337. void Cache_Freeze_L1_DCache_Enable(cache_freeze_mode_t mode);
  1338. /**
  1339. * @brief Disable L1 dcache freeze
  1340. *
  1341. * @param None
  1342. *
  1343. * @return None
  1344. */
  1345. void Cache_Freeze_L1_DCache_Disable(void);
  1346. /**
  1347. * @brief Freeze L2 cache
  1348. *
  1349. * @param cache_freeze_mode_t : mode
  1350. *
  1351. * @return None
  1352. */
  1353. void Cache_Freeze_L2_Cache_Enable(cache_freeze_mode_t mode);
  1354. /**
  1355. * @brief Disable L2 cache freeze
  1356. *
  1357. * @param None
  1358. *
  1359. * @return None
  1360. */
  1361. void Cache_Freeze_L2_Cache_Disable(void);
  1362. /**
  1363. * @brief Travel tag memory to run a call back function using 1st tag api.
  1364. * ICache and DCache are suspend when doing this.
  1365. * The callback will get the parameter tag_group_info, which will include a group of tag memory addresses and cache memory addresses.
  1366. * Please do not call this function in your SDK application.
  1367. *
  1368. * @param struct cache_mode * mode : the cache to check and the cache mode.
  1369. *
  1370. * @param uint32_t filter_addr : only the cache lines which may include the filter_address will be returned to the call back function.
  1371. * 0 for do not filter, all cache lines will be returned.
  1372. *
  1373. * @param void (* process)(struct tag_group_info *, int res[]) : 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.
  1374. *
  1375. * @return None
  1376. */
  1377. void Cache_Travel_Tag_Memory(struct cache_mode *mode, uint32_t filter_addr, void (*process)(struct tag_group_info *, int res[]), int res[]);
  1378. /**
  1379. * @brief Travel tag memory to run a call back function using 2rd tag api.
  1380. * ICache and DCache are suspend when doing this.
  1381. * The callback will get the parameter tag_group_info, which will include a group of tag memory addresses and cache memory addresses.
  1382. * Please do not call this function in your SDK application.
  1383. *
  1384. * @param struct cache_mode * mode : the cache to check and the cache mode.
  1385. *
  1386. * @param uint32_t filter_addr : only the cache lines which may include the filter_address will be returned to the call back function.
  1387. * 0 for do not filter, all cache lines will be returned.
  1388. *
  1389. * @param void (* process)(struct tag_group_info *, int res[]) : 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.
  1390. *
  1391. * @return None
  1392. */
  1393. void Cache_Travel_Tag_Memory2(struct cache_mode *mode, uint32_t filter_addr, void (*process)(struct tag_group_info *, int res[]), int res[]);
  1394. /**
  1395. * @brief Get the virtual address from cache mode, cache tag and the virtual address offset of cache ways.
  1396. * Please do not call this function in your SDK application.
  1397. *
  1398. * @param struct cache_mode * mode : the cache to calculate the virtual address and the cache mode.
  1399. *
  1400. * @param uint32_t tag : the tag part fo a tag item, 12-14 bits.
  1401. *
  1402. * @param uint32_t addr_offset : the virtual address offset of the cache ways.
  1403. *
  1404. * @return uint32_t : the virtual address.
  1405. */
  1406. uint32_t Cache_Get_Virtual_Addr(struct cache_mode *mode, uint32_t tag, uint32_t vaddr_offset);
  1407. /**
  1408. * @}
  1409. */
  1410. /**
  1411. * @brief Get the cache MMU IROM end address.
  1412. * Please do not call this function in your SDK application.
  1413. *
  1414. * @param void
  1415. *
  1416. * @return uint32_t : the word value of the address.
  1417. */
  1418. uint32_t Cache_Get_IROM_MMU_End(void);
  1419. /**
  1420. * @brief Get the cache MMU DROM end address.
  1421. * Please do not call this function in your SDK application.
  1422. *
  1423. * @param void
  1424. *
  1425. * @return uint32_t : the word value of the address.
  1426. */
  1427. uint32_t Cache_Get_DROM_MMU_End(void);
  1428. /**
  1429. * @brief Configure cache MMU page size according to instruction and rodata size
  1430. *
  1431. * @param irom_size The instruction cache MMU page size
  1432. * @param drom_size The rodata data cache MMU page size
  1433. */
  1434. void Cache_Set_IDROM_MMU_Size(uint32_t irom_size, uint32_t drom_size);
  1435. /* MACRO for rom boot */
  1436. #define ROM_boot_Cache_Suspend() Cache_Suspend_L2_Cache()
  1437. #define ROM_boot_Cache_Invalidate_All() Cache_Invalidate_All(CACHE_MAP_L2_CACHE)
  1438. #define ROM_boot_Cache_Resume(preload) Cache_Resume_L2_Cache(preload)
  1439. #define Cache_Dbus_MMU_Set(ext_mem, vaddr, paddr, page_size, page, fix) \
  1440. Cache_MSPI_MMU_Set_Secure(ext_mem, vaddr, paddr, page_size, page, fix)
  1441. #define Cache_Ibus_MMU_Set(ext_mem, vaddr, paddr, page_size, page, fix) \
  1442. Cache_MSPI_MMU_Set_Secure(ext_mem, vaddr, paddr, page_size, page, fix)
  1443. #define Cache_MMU_Init() Cache_MSPI_MMU_Init()
  1444. /* MACRO for spi flash mmap */
  1445. #define SPI_FLASH_MMAP_INVALIDATE_CACHE_ADDR(addr, size) Cache_Invalidate_Addr(CACHE_MAP_L1_DCACHE | CACHE_MAP_L2_CACHE, addr, size)
  1446. /**
  1447. * @brief Used by SPI flash mmap
  1448. *
  1449. */
  1450. int flash2spiram_instruction_offset(void);
  1451. int flash2spiram_rodata_offset(void);
  1452. uint32_t flash_instr_rodata_start_page(uint32_t bus);
  1453. uint32_t flash_instr_rodata_end_page(uint32_t bus);
  1454. #ifdef __cplusplus
  1455. }
  1456. #endif
  1457. #endif /* _ROM_CACHE_H_ */