-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[bsp][cvitek] add dcache opration functions for cache coherence #9696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,70 @@ | ||
| /* | ||
| * 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) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 是否也有icache操作?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 根据数据手册添加了icache相关操作,修改了config防止cache相关函数定义为空 |
||
| { | ||
| asm volatile("csrs mhcr, %0;" ::"rI"(0x2)); | ||
| } | ||
|
|
||
| inline void rt_hw_cpu_dcache_disable(void) | ||
| { | ||
| asm volatile("csrc mhcr, %0;" ::"rI"(0x2)); | ||
| } | ||
|
|
||
| inline void inv_dcache_range(uintptr_t start, size_t size) { | ||
| CACHE_OP_RANGE(DCACHE_IPA_A0, start, size); | ||
| } | ||
|
|
||
| inline void flush_dcache_range(uintptr_t start, size_t size) { | ||
| CACHE_OP_RANGE(DCACHE_CIPA_A0, start, size); | ||
| } | ||
|
|
||
| inline void rt_hw_cpu_dcache_ops(int ops, void* addr, int size) | ||
| { | ||
| switch (ops) | ||
| { | ||
| case RT_HW_CACHE_FLUSH: | ||
| flush_dcache_range(addr, size); | ||
| break; | ||
| case RT_HW_CACHE_INVALIDATE: | ||
| inv_dcache_range(addr, size); | ||
| break; | ||
| default: | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| inline void rt_hw_cpu_icache_enable(void) | ||
| { | ||
| asm volatile("csrs mhcr, %0;" ::"rI"(0x1)); | ||
| } | ||
|
|
||
| inline void rt_hw_cpu_icache_disable(void) | ||
| { | ||
| asm volatile("csrc mhcr, %0;" ::"rI"(0x1)); | ||
| } | ||
|
|
||
| inline void inv_icache_range(uintptr_t start, size_t size) { | ||
| CACHE_OP_RANGE(ICACHE_IPA_A0, start, size); | ||
| } | ||
|
|
||
| inline void rt_hw_cpu_icache_ops(int ops, void* addr, int size) | ||
| { | ||
| switch (ops) | ||
| { | ||
| case RT_HW_CACHE_INVALIDATE: | ||
| inv_icache_range(addr, size); | ||
| break; | ||
| default: | ||
| break; | ||
| } | ||
| } | ||
This file contains hidden or 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,54 @@ | ||
| /* | ||
| * 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 | ||
| * | ||
| * icache.ipa rs1 (invalidate) | ||
| * | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 | | ||
| * 0000001 11000 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 ICACHE_IPA_A0 ".long 0x0385000b" | ||
|
|
||
| #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__ */ |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
只要保留一条 change log 就好