Skip to content

Commit da701d6

Browse files
committed
添加dcache invalidate/dcache clean&invalidate接口
1 parent c77ddf4 commit da701d6

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

libcpu/arm/cortex-a/cache.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,37 @@ void rt_hw_cpu_dcache_invalidate(void *addr, int size)
5858
asm volatile ("dsb":::"memory");
5959
}
6060

61+
void rt_hw_cpu_dcache_inv_range(void *addr, int size)
62+
{
63+
rt_uint32_t line_size = rt_cpu_dcache_line_size();
64+
rt_uint32_t start_addr = (rt_uint32_t)addr;
65+
rt_uint32_t end_addr = (rt_uint32_t)addr + size;
66+
67+
asm volatile ("dmb":::"memory");
68+
69+
if ((start_addr & (line_size - 1)) != 0)
70+
{
71+
start_addr &= ~(line_size - 1);
72+
asm volatile ("mcr p15, 0, %0, c7, c14, 1" :: "r"(start_addr));
73+
start_addr += line_size;
74+
asm volatile ("dsb":::"memory");
75+
}
76+
77+
if ((end_addr & (line_size - 1)) != 0)
78+
{
79+
end_addr &= ~(line_size - 1);
80+
asm volatile ("mcr p15, 0, %0, c7, c14, 1" :: "r"(end_addr));
81+
asm volatile ("dsb":::"memory");
82+
}
83+
84+
while (start_addr < end_addr)
85+
{
86+
asm volatile ("mcr p15, 0, %0, c7, c6, 1" :: "r"(start_addr)); /* dcimvac */
87+
start_addr += line_size;
88+
}
89+
asm volatile ("dsb":::"memory");
90+
}
91+
6192
void rt_hw_cpu_dcache_clean(void *addr, int size)
6293
{
6394
rt_uint32_t line_size = rt_cpu_dcache_line_size();
@@ -75,6 +106,23 @@ void rt_hw_cpu_dcache_clean(void *addr, int size)
75106
asm volatile ("dsb":::"memory");
76107
}
77108

109+
void rt_hw_cpu_dcache_clean_inv(void *addr, int size)
110+
{
111+
rt_uint32_t line_size = rt_cpu_dcache_line_size();
112+
rt_uint32_t start_addr = (rt_uint32_t)addr;
113+
rt_uint32_t end_addr = (rt_uint32_t) addr + size + line_size - 1;
114+
115+
asm volatile ("dmb":::"memory");
116+
start_addr &= ~(line_size-1);
117+
end_addr &= ~(line_size-1);
118+
while (start_addr < end_addr)
119+
{
120+
asm volatile ("mcr p15, 0, %0, c7, c14, 1" :: "r"(start_addr));
121+
start_addr += line_size;
122+
}
123+
asm volatile ("dsb":::"memory");
124+
}
125+
78126
void rt_hw_cpu_icache_ops(int ops, void *addr, int size)
79127
{
80128
if (ops == RT_HW_CACHE_INVALIDATE)

0 commit comments

Comments
 (0)