1 /*
2  * Copyright (c) 2006-2022, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2022-12-12     WangXiaoyao  the first version
9  */
10 #ifndef __TLB_H__
11 #define __TLB_H__
12 
13 #include "mm_aspace.h"
14 #include <rtthread.h>
15 #include <stddef.h>
16 #include <stdint.h>
17 
18 #define dsb(scope)      __asm__ volatile("dsb " #scope : : : "memory")
19 #define isb()           __asm__ volatile("isb" : : : "memory")
20 #define STORE_CP32(r, name...) "mcr " RT_STRINGIFY(CP32(%r, name)) ";"
21 
22 #define WRITE_CP32(v, name...) do {                             \
23     register uint32_t _r = (v);                                 \
24     asm volatile(STORE_CP32(0, name) : : "r" (_r));             \
25 } while (0)
26 
rt_hw_tlb_invalidate_all(void)27 static inline void rt_hw_tlb_invalidate_all(void)
28 {
29     asm volatile ("mcr p15, 0, r0, c8, c7, 0\ndsb\nisb" ::: "memory");
30 }
31 
rt_hw_tlb_invalidate_all_local(void)32 static inline void rt_hw_tlb_invalidate_all_local(void)
33 {
34     rt_hw_tlb_invalidate_all();
35 }
36 
rt_hw_tlb_invalidate_aspace(rt_aspace_t aspace)37 static inline void rt_hw_tlb_invalidate_aspace(rt_aspace_t aspace)
38 {
39     rt_hw_tlb_invalidate_all();
40 }
41 
rt_hw_tlb_invalidate_range(rt_aspace_t aspace,void * start,size_t size,size_t stride)42 static inline void rt_hw_tlb_invalidate_range(rt_aspace_t aspace, void *start,
43                                               size_t size, size_t stride)
44 {
45     rt_hw_tlb_invalidate_all();
46 }
47 
48 #endif /* __TLB_H__ */
49