1 /* 2 * Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU) 3 * Licensed under the Mulan PSL v2. 4 * You can use this software according to the terms and conditions of the Mulan PSL v2. 5 * You may obtain a copy of Mulan PSL v2 at: 6 * http://license.coscl.org.cn/MulanPSL2 7 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR 8 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR 9 * PURPOSE. 10 * See the Mulan PSL v2 for more details. 11 */ 12 #ifndef MM_COMMON_PTE_H 13 #define MM_COMMON_PTE_H 14 15 #include <common/types.h> 16 #include <arch/mmu.h> 17 18 #define L0 (0) 19 #define L1 (1) 20 #define L2 (2) 21 #define L3 (3) 22 23 /** 24 * @brief Architecture-independent PTE structure, containing some useful 25 * information which is shared by all architectures. 26 * 27 * This struct can be used to write architecture-independent code to parse 28 * or manipulate PTEs. 29 */ 30 struct common_pte_t { 31 /** Physical Page Number */ 32 unsigned long ppn; 33 /** ChCore VMR permission, architecture-independent */ 34 vmr_prop_t perm; 35 unsigned char 36 /** This PTE is valid or not */ 37 valid : 1, 38 /** This PTE is accessed by hardware or not */ 39 access : 1, 40 /** This PTE is written by hardware or not */ 41 dirty : 1, _unused : 4; 42 }; 43 44 /** 45 * @brief Parse an architecture-specific to a common PTE. 46 * 47 * @param pte [In] pointer to an architecture-specific PTE 48 * @param level [In] The level in page table where the @pte reside. WARNING: 49 * Currently, the last level PTE is encoded as level 3, and the levels above 50 * it are encoded as level 2, 1, 0(if the architecture has 4-level page table, 51 * otherwise the smallest level is 1). But levels except 3 is not used in this 52 * function now. And if we would implement 5-level page tables in the future, 53 * we should change the encoding of levels. 54 * @param ret [Out] returning the parsed common PTE 55 */ 56 void parse_pte_to_common(pte_t *pte, unsigned int level, 57 struct common_pte_t *ret); 58 /** 59 * @brief Assign settings in the common PTE to an architecture-specific PTE. 60 * 61 * @param dest [In] pointer to an architecture-specific PTE 62 * @param level [In] The level in page table where the @dest reside. WARNING: 63 * Currently, the last level PTE is encoded as level 3, and the levels above 64 * it are encoded as level 2, 1, 0(if the architecture has 4-level page table, 65 * otherwise the smallest level is 1). But levels except 3 is not used in this 66 * function now. And if we would implement 5-level page tables in the future, 67 * we should change the encoding of levels. 68 * @param src [In] pointer to the common PTE 69 */ 70 void update_pte(pte_t *dest, unsigned int level, struct common_pte_t *src); 71 72 #endif /* MM_COMMON_PTE_H */