cache.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef _ROM_CACHE_H_
  14. #define _ROM_CACHE_H_
  15. #include "esp_bit_defs.h"
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /** \defgroup cache_apis, cache operation related apis
  20. * @brief cache apis
  21. */
  22. /** @addtogroup cache_apis
  23. * @{
  24. */
  25. #define MIN_CACHE_SIZE 8192
  26. #define MAX_CACHE_SIZE 16384
  27. #define MIN_CACHE_WAYS 4
  28. #define MAX_CACHE_WAYS 8
  29. #define MIN_CACHE_LINE_SIZE 16
  30. #define MAX_CACHE_LINE_SIZE 64
  31. //normally should be (MAX_CACHE_SIZE / MIN_CACHE_WAYS / MIN_CACHE_LINE_SIZE), however, the items not all in one tag memory block.
  32. #define MAX_TAG_BLOCK_ITEMS (MAX_CACHE_SIZE / MAX_CACHE_WAYS / MIN_CACHE_LINE_SIZE)
  33. #define TAG_SIZE 4
  34. #define MAX_TAG_BLOCK_SIZE (MAX_TAG_BLOCK_ITEMS * TAG_SIZE)
  35. #define ESP_CACHE_TEMP_ADDR DROM0_ADDRESS_LOW
  36. #define CACHE_MAX_OPERATION_SIZE BUS_ADDR_SIZE
  37. typedef enum {
  38. CACHE_MEMORY_INVALID = 0,
  39. CACHE_MEMORY_ICACHE_LOW = BIT(0),
  40. CACHE_MEMORY_ICACHE_HIGH = BIT(1),
  41. CACHE_MEMORY_DCACHE_LOW = BIT(2),
  42. CACHE_MEMORY_DCACHE_HIGH = BIT(3),
  43. } cache_layout_t;
  44. typedef enum {
  45. CACHE_SIZE_8KB = 0,
  46. CACHE_SIZE_16KB = 1,
  47. } cache_size_t;
  48. typedef enum {
  49. CACHE_4WAYS_ASSOC = 0,
  50. CACHE_8WAYS_ASSOC = 1,
  51. } cache_ways_t;
  52. typedef enum {
  53. CACHE_LINE_SIZE_16B = 0,
  54. CACHE_LINE_SIZE_32B = 1,
  55. CACHE_LINE_SIZE_64B = 2,
  56. } cache_line_size_t;
  57. typedef enum {
  58. CACHE_AUTOLOAD_NORMAL_MODE = 0, /*!< normal mode will autoload anytime if enabled */
  59. CACHE_AUTOLOAD_REGION_MODE = 1, /*!< region mode only autoload if access the memory in regions */
  60. } cache_autoload_mode_t;
  61. typedef enum {
  62. CACHE_AUTOLOAD_POSITIVE = 0, /*!< cache autoload step is positive */
  63. CACHE_AUTOLOAD_NEGATIVE = 1, /*!< cache autoload step is negative */
  64. } cache_autoload_order_t;
  65. #define CACHE_AUTOLOAD_STEP(i) ((i) - 1)
  66. typedef enum {
  67. CACHE_AUTOLOAD_MISS_TRIGGER = 0, /*!< autoload only triggered by cache miss */
  68. CACHE_AUTOLOAD_HIT_TRIGGER = 1, /*!< autoload only triggered by cache hit */
  69. CACHE_AUTOLOAD_BOTH_TRIGGER = 2, /*!< autoload triggered both by cache miss and hit */
  70. } cache_autoload_trigger_t;
  71. struct cache_mode {
  72. uint32_t cache_size;
  73. uint16_t cache_line_size;
  74. uint8_t cache_ways;
  75. uint8_t icache;
  76. };
  77. struct tag_item {
  78. uint32_t dirty:1; /*!< the cache line value is dirty or not */
  79. uint32_t tag:14; /*!< the tag is the high part of the cache address, however is only 16MB range, and with out low part */
  80. uint32_t valid:1; /*!< the tag item is valid or not */
  81. uint32_t fifo_cnt:3; /*!< fifo cnt, 0 ~ 3 for 4 ways cache, 0 ~ 7 for 8 ways cache */
  82. uint32_t lock:1; /*!< the cache line is locked or not */
  83. uint32_t attr:3; /*!< the attribute of the external memory physical address */
  84. uint32_t access:1; /*!< software accessable, used by hardware */
  85. uint32_t reserved:8;
  86. };
  87. struct autoload_config {
  88. uint8_t mode; /*!< autoload mode */
  89. uint8_t order; /*!< autoload step is positive or negative */
  90. uint8_t step; /*!< autoload step */
  91. uint8_t trigger; /*!< autoload trigger */
  92. uint32_t autoload_size; /*!< autoload size */
  93. uint32_t addr0; /*!< autoload region0 start address */
  94. uint32_t size0; /*!< autoload region0 size */
  95. uint32_t addr1; /*!< autoload region1 start address */
  96. uint32_t size1; /*!< autoload region1 size */
  97. };
  98. struct tag_group_info {
  99. struct cache_mode mode; /*!< cache and cache mode */
  100. uint32_t vaddr_offset; /*!< virtual address offset of the cache ways */
  101. uint32_t tag_addr[MAX_CACHE_WAYS]; /*!< tag memory address, only [0~mode.ways-1] is valid to use */
  102. uint32_t cache_memory_offset[MAX_CACHE_WAYS]; /*!< cache memory address, only [0~mode.ways-1] is valid to use */
  103. };
  104. struct lock_config {
  105. uint32_t addr; /*!< manual lock address*/
  106. uint16_t size; /*!< manual lock size*/
  107. uint16_t group; /*!< manual lock group, 0 or 1*/
  108. };
  109. #define MMU_SET_ADDR_ALIGNED_ERROR 1
  110. #define MMU_SET_PASE_SIZE_ERROR 3
  111. #define MMU_SET_VADDR_OUT_RANGE 5
  112. /**
  113. * @brief Initialise cache mmu, mark all entries as invalid.
  114. * Please do not call this function in your SDK application.
  115. *
  116. * @param None
  117. *
  118. * @return None
  119. */
  120. void Cache_MMU_Init(void);
  121. /**
  122. * @brief Set ICache mmu mapping.
  123. * Please do not call this function in your SDK application.
  124. *
  125. * @param uint32_t ext_ram : DPORT_MMU_ACCESS_FLASH for flash, DPORT_MMU_ACCESS_SPIRAM for spiram, DPORT_MMU_INVALID for invalid.
  126. *
  127. * @param uint32_t vaddr : virtual address in CPU address space.
  128. * Can be Iram0,Iram1,Irom0,Drom0 and AHB buses address.
  129. * Should be aligned by psize.
  130. *
  131. * @param uint32_t paddr : physical address in external memory.
  132. * Should be aligned by psize.
  133. *
  134. * @param uint32_t psize : page size of ICache, in kilobytes. Should be 64 here.
  135. *
  136. * @param uint32_t num : pages to be set.
  137. *
  138. * @param uint32_t fixed : 0 for physical pages grow with virtual pages, other for virtual pages map to same physical page.
  139. *
  140. * @return uint32_t: error status
  141. * 0 : mmu set success
  142. * 1 : vaddr or paddr is not aligned
  143. * 3 : psize error
  144. * 5 : vaddr is out of range
  145. */
  146. int Cache_Ibus_MMU_Set(uint32_t ext_ram, uint32_t vaddr, uint32_t paddr, uint32_t psize, uint32_t num, uint32_t fixed);
  147. /**
  148. * @brief Set DCache mmu mapping.
  149. * Please do not call this function in your SDK application.
  150. *
  151. * @param uint32_t ext_ram : DPORT_MMU_ACCESS_FLASH for flash, DPORT_MMU_ACCESS_SPIRAM for spiram, DPORT_MMU_INVALID for invalid.
  152. *
  153. * @param uint32_t vaddr : virtual address in CPU address space.
  154. * Can be DRam0, DRam1, DRom0, DPort and AHB buses address.
  155. * Should be aligned by psize.
  156. *
  157. * @param uint32_t paddr : physical address in external memory.
  158. * Should be aligned by psize.
  159. *
  160. * @param uint32_t psize : page size of DCache, in kilobytes. Should be 64 here.
  161. *
  162. * @param uint32_t num : pages to be set.
  163. * @param uint32_t fixed : 0 for physical pages grow with virtual pages, other for virtual pages map to same physical page.
  164. *
  165. * @return uint32_t: error status
  166. * 0 : mmu set success
  167. * 1 : vaddr or paddr is not aligned
  168. * 3 : psize error
  169. * 5 : vaddr is out of range
  170. */
  171. int Cache_Dbus_MMU_Set(uint32_t ext_ram, uint32_t vaddr, uint32_t paddr, uint32_t psize, uint32_t num, uint32_t fixed);
  172. /**
  173. * @brief Copy DRom0 ICache MMU to DCache MMU.
  174. * Please do not call this function in your SDK application.
  175. *
  176. * @param None
  177. *
  178. * @return None
  179. */
  180. void MMU_Drom0_I2D_Copy(void);
  181. /**
  182. * @brief Unmap DRom0 ICache MMU.
  183. * Please do not call this function in your SDK application.
  184. *
  185. * @param None
  186. *
  187. * @return None
  188. */
  189. void MMU_Drom_ICache_Unmap(void);
  190. /**
  191. * @brief Count the pages in the bus room address which map to Flash.
  192. * Please do not call this function in your SDK application.
  193. *
  194. * @param uint32_t bus : the bus to count with.
  195. *
  196. * @param uint32_t * page0_mapped : value should be initial by user, 0 for not mapped, other for mapped count.
  197. *
  198. * return uint32_t : the number of pages which map to Flash.
  199. */
  200. uint32_t Cache_Count_Flash_Pages(uint32_t bus, uint32_t * page0_mapped);
  201. /**
  202. * @brief Copy Instruction or rodata from Flash to SPIRAM, and remap to SPIRAM.
  203. * Please do not call this function in your SDK application.
  204. *
  205. * @param uint32_t bus : the bus which need to copy to SPIRAM.
  206. *
  207. * @param uint32_t bus_start_addr : the start virtual address for the bus.
  208. *
  209. * @param uint32_t start_page : the start (64KB) page number in SPIRAM.
  210. *
  211. * @param uint32_t * page0_page : the flash page0 in SPIRAM page number, 0xffff for invalid.
  212. *
  213. * return uint32_t : the next start page number for SPIRAM not mapped.
  214. */
  215. uint32_t Cache_Flash_To_SPIRAM_Copy(uint32_t bus, uint32_t bus_start_addr, uint32_t start_page, uint32_t * page0_page);
  216. /**
  217. * @brief allocate memory to used by ICache and DCache.
  218. * Please do not call this function in your SDK application.
  219. *
  220. * @param cache_layout_t sram0_layout : the usage of first 8KB internal memory block, can be CACHE_MEMORY_INVALID, CACHE_MEMORY_ICACHE_LOW, CACHE_MEMORY_ICACHE_HIGH, CACHE_MEMORY_DCACHE_LOW and CACHE_MEMORY_DCACHE_HIGH
  221. *
  222. * @param cache_layout_t sram1_layout : the usage of second 8KB internal memory block
  223. *
  224. * @param cache_layout_t sram2_layout : the usage of third 8KB internal memory block
  225. *
  226. * @param cache_layout_t sram3_layout : the usage of forth 8KB internal memory block
  227. *
  228. * return none
  229. */
  230. void Cache_Allocate_SRAM(cache_layout_t sram0_layout, cache_layout_t sram1_layout, cache_layout_t sram2_layout, cache_layout_t sram3_layout);
  231. /**
  232. * @brief Get cache mode of ICache or DCache.
  233. * Please do not call this function in your SDK application.
  234. *
  235. * @param struct cache_mode * mode : the pointer of cache mode struct
  236. *
  237. * return none
  238. */
  239. void Cache_Get_Mode(struct cache_mode * mode);
  240. /**
  241. * @brief set ICache modes: cache size, associate ways and cache line size.
  242. * Please do not call this function in your SDK application.
  243. *
  244. * @param cache_size_t cache_size : the cache size, can be CACHE_SIZE_8KB and CACHE_SIZE_16KB
  245. *
  246. * @param cache_ways_t ways : the associate ways of cache, cane be CACHE_4WAYS_ASSOC and CACHE_8WAYS_ASSOC
  247. *
  248. * @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
  249. *
  250. * @param cache_layout_t sram3_layout : the usage of forth 8KB internal memory block
  251. *
  252. * return none
  253. */
  254. void Cache_Set_ICache_Mode(cache_size_t cache_size, cache_ways_t ways, cache_line_size_t cache_line_size);
  255. /**
  256. * @brief set DCache modes: cache size, associate ways and cache line size.
  257. * Please do not call this function in your SDK application.
  258. *
  259. * @param cache_size_t cache_size : the cache size, can be CACHE_SIZE_8KB and CACHE_SIZE_16KB
  260. *
  261. * @param cache_ways_t ways : the associate ways of cache, cane be CACHE_4WAYS_ASSOC and CACHE_8WAYS_ASSOC
  262. *
  263. * @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
  264. *
  265. * @param cache_layout_t sram3_layout : the usage of forth 8KB internal memory block
  266. *
  267. * return none
  268. */
  269. void Cache_Set_DCache_Mode(cache_size_t cache_size, cache_ways_t ways, cache_line_size_t cache_line_size);
  270. /**
  271. * @brief check if the address is accessed through ICache.
  272. * Please do not call this function in your SDK application.
  273. *
  274. * @param uint32_t addr : the address to check.
  275. *
  276. * @return 1 if the address is accessed through ICache, 0 if not.
  277. */
  278. uint32_t Cache_Address_Through_ICache(uint32_t addr);
  279. /**
  280. * @brief check if the address is accessed through DCache.
  281. * Please do not call this function in your SDK application.
  282. *
  283. * @param uint32_t addr : the address to check.
  284. *
  285. * @return 1 if the address is accessed through DCache, 0 if not.
  286. */
  287. uint32_t Cache_Address_Through_DCache(uint32_t addr);
  288. /**
  289. * @brief Invalidate the cache items for ICache.
  290. * Operation will be done CACHE_LINE_SIZE aligned.
  291. * If the addr is not in our addr room, we will Flush all Cache.
  292. * Please do not call this function in your SDK application.
  293. *
  294. * @param uint32_t addr: start address to invalidate
  295. *
  296. * @param uint32_t size: size to invalidate, should <= 4MB
  297. *
  298. * @return None
  299. */
  300. void Cache_Invalidate_ICache_Items(uint32_t addr, uint32_t size);
  301. /**
  302. * @brief Invalidate the cache items for DCache.
  303. * Operation will be done CACHE_LINE_SIZE aligned.
  304. * If the addr is not in our addr room, we will Flush all Cache.
  305. * Please do not call this function in your SDK application.
  306. *
  307. * @param uint32_t addr: start address to invalidate
  308. *
  309. * @param uint32_t size: size to invalidate, should <= 4MB
  310. *
  311. * @return None
  312. */
  313. void Cache_Invalidate_DCache_Items(uint32_t addr, uint32_t size);
  314. /**
  315. * @brief Clean the dirty bit of cache Items of DCache.
  316. * Operation will be done CACHE_LINE_SIZE aligned.
  317. * Please do not call this function in your SDK application.
  318. *
  319. * @param uint32_t addr: start address to Clean
  320. *
  321. * @param uint32_t size: size to Clean, should <= 4MB
  322. *
  323. * @return None
  324. */
  325. void Cache_Clean_Items(uint32_t addr, uint32_t size);
  326. /**
  327. * @brief Write back the cache items of DCache.
  328. * Operation will be done CACHE_LINE_SIZE aligned.
  329. * Please do not call this function in your SDK application.
  330. *
  331. * @param uint32_t addr: start address to write back
  332. *
  333. * @param uint32_t size: size to write back, should <= 4MB
  334. *
  335. * @return None
  336. */
  337. void Cache_WriteBack_Items(uint32_t addr, uint32_t size);
  338. /**
  339. * @brief Invalidate the Cache items in the region from ICache or DCache.
  340. * Please do not call this function in your SDK application.
  341. *
  342. * @param uint32_t addr : invalidated region start address.
  343. *
  344. * @param uint32_t size : invalidated region size.
  345. *
  346. * @return None
  347. */
  348. void Cache_Invalidate_Addr(uint32_t addr, uint32_t size);
  349. /**
  350. * @brief Clean the dirty bit of Cache items in the region from DCache.
  351. * Please do not call this function in your SDK application.
  352. *
  353. * @param uint32_t addr : cleaned region start address.
  354. *
  355. * @param uint32_t size : cleaned region size.
  356. *
  357. * @return None
  358. */
  359. void Cache_Clean_Addr(uint32_t addr, uint32_t size);
  360. /**
  361. * @brief Writeback the Cache items(also clean the dirty bit) in the region from DCache.
  362. * Please do not call this function in your SDK application.
  363. *
  364. * @param uint32_t addr : writeback region start address.
  365. *
  366. * @param uint32_t size : writeback region size.
  367. *
  368. * @return None
  369. */
  370. void Cache_WriteBack_Addr(uint32_t addr, uint32_t size);
  371. /**
  372. * @brief Invalidate all cache items in ICache.
  373. * Please do not call this function in your SDK application.
  374. *
  375. * @param None
  376. *
  377. * @return None
  378. */
  379. void Cache_Invalidate_ICache_All(void);
  380. /**
  381. * @brief Invalidate all cache items in DCache.
  382. * Please do not call this function in your SDK application.
  383. *
  384. * @param None
  385. *
  386. * @return None
  387. */
  388. void Cache_Invalidate_DCache_All(void);
  389. /**
  390. * @brief Clean the dirty bit of all cache items in DCache.
  391. * Please do not call this function in your SDK application.
  392. *
  393. * @param None
  394. *
  395. * @return None
  396. */
  397. void Cache_Clean_All(void);
  398. /**
  399. * @brief WriteBack all cache items in DCache.
  400. * Please do not call this function in your SDK application.
  401. *
  402. * @param None
  403. *
  404. * @return None
  405. */
  406. void Cache_WriteBack_All(void);
  407. /**
  408. * @brief Mask all buses through ICache and DCache.
  409. * Please do not call this function in your SDK application.
  410. *
  411. * @param None
  412. *
  413. * @return None
  414. */
  415. void Cache_Mask_All(void);
  416. /**
  417. * @brief UnMask DRom0 bus through ICache or DCache.
  418. * Please do not call this function in your SDK application.
  419. *
  420. * @param None
  421. *
  422. * @return None
  423. */
  424. void Cache_UnMask_Drom0(void);
  425. /**
  426. * @brief Suspend ICache auto preload operation, then you can resume it after some ICache operations.
  427. * Please do not call this function in your SDK application.
  428. *
  429. * @param None
  430. *
  431. * @return uint32_t : 0 for ICache not auto preload before suspend.
  432. */
  433. uint32_t Cache_Suspend_ICache_Autoload(void);
  434. /**
  435. * @brief Resume ICache auto preload operation after some ICache operations.
  436. * Please do not call this function in your SDK application.
  437. *
  438. * @param uint32_t autoload : 0 for ICache not auto preload before suspend.
  439. *
  440. * @return None.
  441. */
  442. void Cache_Resume_ICache_Autoload(uint32_t autoload);
  443. /**
  444. * @brief Suspend DCache auto preload operation, then you can resume it after some DCache operations.
  445. * Please do not call this function in your SDK application.
  446. *
  447. * @param None
  448. *
  449. * @return uint32_t : 0 for DCache not auto preload before suspend.
  450. */
  451. uint32_t Cache_Suspend_DCache_Autoload(void);
  452. /**
  453. * @brief Resume DCache auto preload operation after some DCache operations.
  454. * Please do not call this function in your SDK application.
  455. *
  456. * @param uint32_t autoload : 0 for DCache not auto preload before suspend.
  457. *
  458. * @return None.
  459. */
  460. void Cache_Resume_DCache_Autoload(uint32_t autoload);
  461. /**
  462. * @brief Start an ICache manual preload, will suspend auto preload of ICache.
  463. * Please do not call this function in your SDK application.
  464. *
  465. * @param uint32_t addr : start address of the preload region.
  466. *
  467. * @param uint32_t size : size of the preload region, should not exceed the size of ICache.
  468. *
  469. * @param uint32_t order : the preload order, 0 for positive, other for negative
  470. *
  471. * @return uint32_t : 0 for ICache not auto preload before manual preload.
  472. */
  473. uint32_t Cache_Start_ICache_Preload(uint32_t addr, uint32_t size, uint32_t order);
  474. /**
  475. * @brief Return if the ICache manual preload done.
  476. * Please do not call this function in your SDK application.
  477. *
  478. * @param None
  479. *
  480. * @return uint32_t : 0 for ICache manual preload not done.
  481. */
  482. uint32_t Cache_ICache_Preload_Done(void);
  483. /**
  484. * @brief End the ICache manual preload to resume auto preload of ICache.
  485. * Please do not call this function in your SDK application.
  486. *
  487. * @param uint32_t autoload : 0 for ICache not auto preload before manual preload.
  488. *
  489. * @return None
  490. */
  491. void Cache_End_ICache_Preload(uint32_t autoload);
  492. /**
  493. * @brief Start an DCache manual preload, will suspend auto preload of DCache.
  494. * Please do not call this function in your SDK application.
  495. *
  496. * @param uint32_t addr : start address of the preload region.
  497. *
  498. * @param uint32_t size : size of the preload region, should not exceed the size of DCache.
  499. *
  500. * @param uint32_t order : the preload order, 0 for positive, other for negative
  501. *
  502. * @return uint32_t : 0 for DCache not auto preload before manual preload.
  503. */
  504. uint32_t Cache_Start_DCache_Preload(uint32_t addr, uint32_t size, uint32_t order);
  505. /**
  506. * @brief Return if the DCache manual preload done.
  507. * Please do not call this function in your SDK application.
  508. *
  509. * @param None
  510. *
  511. * @return uint32_t : 0 for DCache manual preload not done.
  512. */
  513. uint32_t Cache_DCache_Preload_Done(void);
  514. /**
  515. * @brief End the DCache manual preload to resume auto preload of DCache.
  516. * Please do not call this function in your SDK application.
  517. *
  518. * @param uint32_t autoload : 0 for DCache not auto preload before manual preload.
  519. *
  520. * @return None
  521. */
  522. void Cache_End_DCache_Preload(uint32_t autoload);
  523. /**
  524. * @brief Config autoload parameters of ICache.
  525. * Please do not call this function in your SDK application.
  526. *
  527. * @param struct autoload_config * config : autoload parameters.
  528. *
  529. * @return None
  530. */
  531. void Cache_Config_ICache_Autoload(const struct autoload_config * config);
  532. /**
  533. * @brief Enable auto preload for ICache.
  534. * Please do not call this function in your SDK application.
  535. *
  536. * @param None
  537. *
  538. * @return None
  539. */
  540. void Cache_Enable_ICache_Autoload(void);
  541. /**
  542. * @brief Disable auto preload for ICache.
  543. * Please do not call this function in your SDK application.
  544. *
  545. * @param None
  546. *
  547. * @return None
  548. */
  549. void Cache_Disable_ICache_Autoload(void);
  550. /**
  551. * @brief Config autoload parameters of DCache.
  552. * Please do not call this function in your SDK application.
  553. *
  554. * @param struct autoload_config * config : autoload parameters.
  555. *
  556. * @return None
  557. */
  558. void Cache_Config_DCache_Autoload(const struct autoload_config * config);
  559. /**
  560. * @brief Enable auto preload for DCache.
  561. * Please do not call this function in your SDK application.
  562. *
  563. * @param None
  564. *
  565. * @return None
  566. */
  567. void Cache_Enable_DCache_Autoload(void);
  568. /**
  569. * @brief Disable auto preload for DCache.
  570. * Please do not call this function in your SDK application.
  571. *
  572. * @param None
  573. *
  574. * @return None
  575. */
  576. void Cache_Disable_DCache_Autoload(void);
  577. /**
  578. * @brief Config a group of lock parameters of ICache.
  579. * Please do not call this function in your SDK application.
  580. *
  581. * @param struct lock_config * config : a group of lock parameters.
  582. *
  583. * @return None
  584. */
  585. void Cache_Enable_ICache_Lock(const struct lock_config *config);
  586. /**
  587. * @brief Disable a group of lock parameters for ICache.
  588. * However, the locked data will not be released.
  589. * Please do not call this function in your SDK application.
  590. *
  591. * @param uint16_t group : 0 for group0, 1 for group1.
  592. *
  593. * @return None
  594. */
  595. void Cache_Disable_ICache_Lock(uint16_t group);
  596. /**
  597. * @brief Unlock the cache items in tag memory for ICache.
  598. * Please do not call this function in your SDK application.
  599. *
  600. * @param uint32_t addr : start address of unlock region.
  601. *
  602. * @param uint32_t size : size of unlock region.
  603. *
  604. * @return None
  605. */
  606. void Cache_Unlock_ICache(uint32_t addr, uint32_t size);
  607. /**
  608. * @brief Config a group of lock parameters of DCache.
  609. * Please do not call this function in your SDK application.
  610. *
  611. * @param struct lock_config * config : a group of lock parameters.
  612. *
  613. * @return None
  614. */
  615. void Cache_Enable_DCache_Lock(const struct lock_config *config);
  616. /**
  617. * @brief Disable a group of lock parameters for DCache.
  618. * However, the locked data will not be released.
  619. * Please do not call this function in your SDK application.
  620. *
  621. * @param uint16_t group : 0 for group0, 1 for group1.
  622. *
  623. * @return None
  624. */
  625. void Cache_Disable_DCache_Lock(uint16_t group);
  626. /**
  627. * @brief Unlock the cache items in tag memory for DCache.
  628. * Please do not call this function in your SDK application.
  629. *
  630. * @param uint32_t addr : start address of unlock region.
  631. *
  632. * @param uint32_t size : size of unlock region.
  633. *
  634. * @return None
  635. */
  636. void Cache_Unlock_DCache(uint32_t addr, uint32_t size);
  637. /**
  638. * @brief Disable ICache access for the cpu.
  639. * This operation will make all ICache tag memory invalid, CPU can't access ICache, ICache will keep idle.
  640. * Please do not call this function in your SDK application.
  641. *
  642. * @return uint32_t : auto preload enabled before
  643. */
  644. uint32_t Cache_Disable_ICache(void);
  645. /**
  646. * @brief Enable ICache access for the cpu.
  647. * Please do not call this function in your SDK application.
  648. *
  649. * @param uint32_t autoload : ICache will preload then.
  650. *
  651. * @return None
  652. */
  653. void Cache_Enable_ICache(uint32_t autoload);
  654. /**
  655. * @brief Disable DCache access for the cpu.
  656. * This operation will make all DCache tag memory invalid, CPU can't access DCache, DCache will keep idle
  657. * Please do not call this function in your SDK application.
  658. *
  659. * @return uint32_t : auto preload enabled before
  660. */
  661. uint32_t Cache_Disable_DCache(void);
  662. /**
  663. * @brief Enable DCache access for the cpu.
  664. * Please do not call this function in your SDK application.
  665. *
  666. * @param uint32_t autoload : DCache will preload then.
  667. *
  668. * @return None
  669. */
  670. void Cache_Enable_DCache(uint32_t autoload);
  671. /**
  672. * @brief Suspend ICache access for the cpu.
  673. * The ICache tag memory is still there, CPU can't access ICache, ICache will keep idle.
  674. * Please do not change MMU, cache mode or tag memory(tag memory can be changed in some special case).
  675. * Please do not call this function in your SDK application.
  676. *
  677. * @param None
  678. *
  679. * @return uint32_t : auto preload enabled before
  680. */
  681. uint32_t Cache_Suspend_ICache(void);
  682. /**
  683. * @brief Resume ICache access for the cpu.
  684. * Please do not call this function in your SDK application.
  685. *
  686. * @param uint32_t autoload : ICache will preload then.
  687. *
  688. * @return None
  689. */
  690. void Cache_Resume_ICache(uint32_t autoload);
  691. /**
  692. * @brief Suspend DCache access for the cpu.
  693. * The ICache tag memory is still there, CPU can't access DCache, DCache will keep idle.
  694. × Please do not change MMU, cache mode or tag memory(tag memory can be changed in some special case).
  695. * Please do not call this function in your SDK application.
  696. *
  697. * @param None
  698. *
  699. * @return uint32_t : auto preload enabled before
  700. */
  701. uint32_t Cache_Suspend_DCache(void);
  702. /**
  703. * @brief Resume DCache access for the cpu.
  704. * Please do not call this function in your SDK application.
  705. *
  706. * @param uint32_t autoload : DCache will preload then.
  707. *
  708. * @return None
  709. */
  710. void Cache_Resume_DCache(uint32_t autoload);
  711. /**
  712. * @brief Make Drom0 bus access from ICache.
  713. *
  714. * @param None
  715. *
  716. * @return None
  717. */
  718. void Cache_Drom0_Source_ICache(void);
  719. /**
  720. * @brief Make Drom0 bus access from DCache.
  721. *
  722. * @param None
  723. *
  724. * @return None
  725. */
  726. void Cache_Drom0_Source_DCache(void);
  727. /**
  728. * @brief Return if Drom0 bus access from ICache.
  729. *
  730. * @param None
  731. *
  732. * @return uint32_t: 0 for no, other for yes
  733. */
  734. uint32_t Cache_Drom0_Using_ICache(void);
  735. /**
  736. * @brief Return if Drom0 bus access from DCache.
  737. *
  738. * @param None
  739. *
  740. * @return uint32_t: 0 for no, other for yes
  741. */
  742. uint32_t Cache_Drom0_Using_DCache(void);
  743. /**
  744. * @brief Get ICache cache line size
  745. *
  746. * @param None
  747. *
  748. * @return uint32_t: 16, 32, 64 Byte
  749. */
  750. uint32_t Cache_Get_ICache_Line_Size(void);
  751. /**
  752. * @brief Get DCache cache line size
  753. *
  754. * @param None
  755. *
  756. * @return uint32_t: 16, 32, 64 Byte
  757. */
  758. uint32_t Cache_Get_DCache_Line_Size(void);
  759. /**
  760. * @brief Set default mode from boot.
  761. *
  762. * @param None
  763. *
  764. * @return None
  765. */
  766. void Cache_Set_Default_Mode(void);
  767. /**
  768. * @brief Travel tag memory to run a call back function.
  769. * ICache and DCache are suspend when doing this.
  770. * The callback will get the parameter tag_group_info, which will include a group of tag memory addresses and cache memory addresses.
  771. * Please do not call this function in your SDK application.
  772. *
  773. * @param struct cache_mode * mode : the cache to check and the cache mode.
  774. *
  775. * @param uint32_t filter_addr : only the cache lines which may include the filter_address will be returned to the call back function.
  776. * 0 for do not filter, all cache lines will be returned.
  777. *
  778. * @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.
  779. *
  780. * @return None
  781. */
  782. void Cache_Travel_Tag_Memory(struct cache_mode * mode, uint32_t filter_addr, void (* process)(struct tag_group_info *));
  783. /**
  784. * @brief Get the virtual address from cache mode, cache tag and the virtual address offset of cache ways.
  785. * Please do not call this function in your SDK application.
  786. *
  787. * @param struct cache_mode * mode : the cache to calculate the virtual address and the cache mode.
  788. *
  789. * @param uint32_t tag : the tag part fo a tag item, 12-14 bits.
  790. *
  791. * @param uint32_t addr_offset : the virtual address offset of the cache ways.
  792. *
  793. * @return uint32_t : the virtual address.
  794. */
  795. uint32_t Cache_Get_Virtual_Addr(struct cache_mode *mode, uint32_t tag, uint32_t vaddr_offset);
  796. /**
  797. * @brief Get cache memory block base address.
  798. * Please do not call this function in your SDK application.
  799. *
  800. * @param uint32_t icache : 0 for dcache, other for icache.
  801. *
  802. * @param uint32_t high : 0 for low part block, 1 for high part block.
  803. *
  804. * @return uint32_t : the cache memory block base address, 0 if the block not used.
  805. */
  806. uint32_t Cache_Get_Memory_BaseAddr(uint32_t icache, uint32_t high);
  807. /**
  808. * @brief Get the cache memory address from cache mode, cache memory offset and the virtual address offset of cache ways.
  809. * Please do not call this function in your SDK application.
  810. *
  811. * @param struct cache_mode * mode : the cache to calculate the virtual address and the cache mode.
  812. *
  813. * @param uint32_t cache_memory_offset : the cache memory offset of the whole cache (ICache or DCache) for the cache line.
  814. *
  815. * @param uint32_t addr_offset : the virtual address offset of the cache ways.
  816. *
  817. * @return uint32_t : the virtual address.
  818. */
  819. uint32_t Cache_Get_Memory_Addr(struct cache_mode *mode, uint32_t cache_memory_offset, uint32_t vaddr_offset);
  820. /**
  821. * @brief Get the cache memory value by DRAM address.
  822. * Please do not call this function in your SDK application.
  823. *
  824. * @param uint32_t cache_memory_addr : DRAM address for the cache memory.
  825. *
  826. * @return uint32_t : the word value of the address.
  827. */
  828. uint32_t Cache_Get_Memory_value(uint32_t cache_memory_addr);
  829. /**
  830. * @}
  831. */
  832. #ifdef __cplusplus
  833. }
  834. #endif
  835. #endif /* _ROM_CACHE_H_ */