-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bsp][cvitek] add dcache opration functions for cache coherence
- Loading branch information
1 parent
9afe6a5
commit a181fb4
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (c) 2006-2024, RT-Thread Development Team | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Change Logs: | ||
* Date Author Notes | ||
* 2024/11/26 zdtyuiop4444 The first version | ||
*/ | ||
|
||
#include "cache.h" | ||
|
||
inline void rt_hw_cpu_dcache_enable(void) | ||
{ | ||
asm volatile("csrs mhcr, %0;" ::"rI"(0x2)); | ||
} | ||
|
||
inline void rt_hw_cpu_dcache_disable(void) | ||
{ | ||
asm volatile("csrc mhcr, %0;" ::"rI"(0x2)); | ||
} | ||
|
||
inline void rt_hw_cpu_dcache_ops(int ops, void* addr, int size) | ||
{ | ||
switch (ops) | ||
{ | ||
case RT_HW_CACHE_FLUSH: | ||
CACHE_OP_RANGE(DCACHE_CIPA_A0, start, size); | ||
break; | ||
case RT_HW_CACHE_INVALIDATE: | ||
CACHE_OP_RANGE(DCACHE_IPA_A0, start, size); | ||
break; | ||
default: | ||
break; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (c) 2006-2024, RT-Thread Development Team | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Change Logs: | ||
* Date Author Notes | ||
* 2024/11/26 zdtyuiop4444 The first version | ||
*/ | ||
|
||
#ifndef __CACHE_H__ | ||
#define __CACHE_H__ | ||
|
||
#include <rthw.h> | ||
|
||
#define L1_CACHE_BYTES 64 | ||
#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) | ||
|
||
/* | ||
* dcache.ipa rs1 (invalidate) | ||
* | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 | | ||
* 0000001 01010 rs1 000 00000 0001011 | ||
* | ||
* dcache.cpa rs1 (clean) | ||
* | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 | | ||
* 0000001 01001 rs1 000 00000 0001011 | ||
* | ||
* dcache.cipa rs1 (clean then invalidate) | ||
* | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 | | ||
* 0000001 01011 rs1 000 00000 0001011 | ||
* | ||
* sync.s | ||
* | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 | | ||
* 0000000 11001 00000 000 00000 0001011 | ||
*/ | ||
#define DCACHE_IPA_A0 ".long 0x02a5000b" | ||
#define DCACHE_CPA_A0 ".long 0x0295000b" | ||
#define DCACHE_CIPA_A0 ".long 0x02b5000b" | ||
|
||
#define SYNC_S ".long 0x0190000b" | ||
|
||
#define CACHE_OP_RANGE(OP, start, size) \ | ||
register unsigned long i asm("a0") = start & ~(L1_CACHE_BYTES - 1); \ | ||
for (; i < ALIGN(start + size, L1_CACHE_BYTES); i += L1_CACHE_BYTES) \ | ||
__asm__ __volatile__(OP); \ | ||
__asm__ __volatile__(SYNC_S) | ||
|
||
#endif /* __CACHE_H__ */ |