spicache.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Copyright (c) 2017 Actions Semiconductor Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief SPICACHE profile interface for Actions SoC
  9. */
  10. #ifndef __SPICACHE_H__
  11. #define __SPICACHE_H__
  12. #include <zephyr/types.h>
  13. #define SPI0_BASE_ADDR 0x10000000
  14. #define SPI0_BASE_END_ADDR 0x14000000
  15. #define SPI0_UNCACHE_ADDR 0x14000000
  16. #define SPI0_UNCACHE_END_ADDR 0x18000000
  17. #define SPI1_BASE_ADDR 0x38000000
  18. #define SPI1_BASE_END_ADDR 0x3C000000
  19. #define SPI1_UNCACHE_ADDR 0x3C000000
  20. #define SPI1_UNCACHE_END_ADDR 0x40000000
  21. #define SPI1_CACHE_WT_WNA_ADDR 0x34000000
  22. #define SPI1_CACHE_WT_WNA_END_ADDR 0x38000000
  23. typedef enum __SPI_CACHE_OPS
  24. {
  25. SPI_CACHE_FLUSH = 0x01,
  26. SPI_CACHE_INVALIDATE = 0x02,
  27. SPI_WRITEBUF_FLUSH = 0x03,
  28. SPI_CACHE_FLUSH_ALL = 0x04,
  29. SPI_CACHE_INVALID_ALL = 0x05,
  30. SPI_CACHE_FLUSH_INVALID = 0x06,
  31. SPI_CACHE_FLUSH_INVALID_ALL = 0x07,
  32. }SPI_CACHE_OPS;
  33. typedef enum {
  34. SPI0_CACHE_MASTER_CPU, //always on
  35. SPI0_CACHE_MASTER_DMA,
  36. SPI0_CACHE_MASTER_SDMA,
  37. SPI0_CACHE_MASTER_DE,
  38. SPI1_CACHE_MASTER_CPU, //always on
  39. SPI1_CACHE_MASTER_GPU,
  40. SPI1_CACHE_MASTER_DMA,
  41. SPI1_CACHE_MASTER_SDMA,
  42. SPI1_CACHE_MASTER_DE,
  43. }SPI_CACHE_MASTER;
  44. typedef enum {
  45. SPI0_CACHE_PRIORITY_POLL = 0,
  46. SPI0_CACHE_PRIORITY_CACHEMISS_DMA_SDMA_DE,
  47. SPI0_CACHE_PRIORITY_SDMA_CACHEMISS_DMA_DE,
  48. SPI0_CACHE_PRIORITY_DE_SDMA_CACHEMISS_DMA,
  49. SPI1_CACHE_PRIORITY_POLL = 0x10,
  50. SPI1_CACHE_PRIORITY_SDMA_ICACHEMISS_DCACHEMISS_DMA_GPU_DER_DEW,
  51. SPI1_CACHE_PRIORITY_DMA_ICACHEMISS_DCACHEMISS_SDMA_GPU_DER_DEW,
  52. SPI1_CACHE_PRIORITY_DER_DEW_SDMA_GPU_DMA_ICACHEMISS_DCACHEMISS,
  53. SPI1_CACHE_PRIORITY_GPU_SDMA_DER_DEW_ICACHEMISS_DCACHEMISS_DMA,
  54. SPI1_CACHE_PRIORITY_DMA_DER_DEW_SDMA_GPU_ICACHEMISS_DCACHEMISS,
  55. }SPI_CACHE_PRIORITY;
  56. #ifdef CONFIG_SOC_SPICACHE_PROFILE
  57. struct spicache_profile {
  58. int spi_id;
  59. /* must aligned to 64-byte */
  60. uint32_t start_addr;
  61. uint32_t end_addr;
  62. uint32_t limit_addr;
  63. /* timestamp, ms */
  64. int64_t start_time;
  65. int64_t end_time;
  66. /* hit/miss in user address range */
  67. uint32_t hit_cnt;
  68. uint32_t miss_cnt;
  69. /* hit/miss in all address range */
  70. uint32_t total_hit_cnt;
  71. uint32_t total_miss_cnt;
  72. /* spi1 cache miss/hit count */
  73. uint32_t dma_hit_cnt;
  74. uint32_t dma_miss_cnt;
  75. };
  76. int spicache_profile_start(struct spicache_profile *profile);
  77. int spicache_profile_stop(struct spicache_profile *profile);
  78. int spicache_profile_get_data(struct spicache_profile *profile);
  79. #endif
  80. void spi1_cache_ops(SPI_CACHE_OPS ops, void* addr, int size);
  81. void spi1_cache_ops_wait_finshed(void);
  82. #define buf_is_psram(buf) (buf_is_psram_cache(buf) || buf_is_psram_wt_wna(buf))
  83. #define buf_is_psram_un(buf) ((((uint32_t)buf) >= SPI1_UNCACHE_ADDR) && (((uint32_t)buf) < SPI1_UNCACHE_END_ADDR))
  84. #define buf_is_psram_cache(buf) ((((uint32_t)buf) >= SPI1_BASE_ADDR) && (((uint32_t)buf) < SPI1_BASE_END_ADDR))
  85. #define buf_is_psram_wt_wna(buf) (((uint32_t)buf) >= SPI1_CACHE_WT_WNA_ADDR && (((uint32_t)buf) < SPI1_CACHE_WT_WNA_END_ADDR))
  86. #define buf_is_nor(buf) ((((uint32_t)buf) >= SPI0_BASE_ADDR) && (((uint32_t)buf) < SPI0_BASE_END_ADDR))
  87. #define buf_is_nor_un(buf) ((((uint32_t)buf) >= SPI0_UNCACHE_ADDR) && (((uint32_t)buf) < SPI0_UNCACHE_END_ADDR))
  88. extern void * cache_to_uncache(void *vaddr);
  89. extern void * cache_to_uncache_by_master(void *vaddr, SPI_CACHE_MASTER master_id);
  90. extern void * uncache_to_cache(void *paddr);
  91. extern void * uncache_to_cache_by_master(void *paddr, SPI_CACHE_MASTER master_id);
  92. extern void * uncache_to_wt_wna_cache(void *paddr);
  93. extern void * cache_to_wt_wna_cache(void *vaddr);
  94. extern void * wt_wna_cache_to_cache(void *vaddr);
  95. int spicache_master_enable(int spi_id, SPI_CACHE_MASTER master_id);
  96. int spicache_master_disable(int spi_id, SPI_CACHE_MASTER master_id);
  97. int spicache_set_priority(int spi_id, SPI_CACHE_PRIORITY priority);
  98. #endif /* __SPICACHE_H__ */