diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-11-02 18:58:13 +0200 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-11-02 18:58:13 +0200 |
| commit | 5890df7bf838a5a912465a1bba02e5d8cf34e33c (patch) | |
| tree | 48c17acfc5ed2b44bff817b00123288098273ecc /arch/riscv64/kernel/pte.h | |
| parent | 5531e2eaaa2fd1dd282dba2fb5bc10e09dfec5e0 (diff) | |
| download | kmi-5890df7bf838a5a912465a1bba02e5d8cf34e33c.tar.gz kmi-5890df7bf838a5a912465a1bba02e5d8cf34e33c.zip | |
allow skipping some cache flushes in proc
Diffstat (limited to 'arch/riscv64/kernel/pte.h')
| -rw-r--r-- | arch/riscv64/kernel/pte.h | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/arch/riscv64/kernel/pte.h b/arch/riscv64/kernel/pte.h new file mode 100644 index 0000000..03c3d05 --- /dev/null +++ b/arch/riscv64/kernel/pte.h @@ -0,0 +1,78 @@ +#ifndef KMI_RISCV_PTE_H +#define KMI_RISCV_PTE_H + +/** + * Get page table entry physical page number. + * + * @param pte Page table entry. + * @return Corresponding physical page number. + */ +#define pte_ppn(pte) (((pm_t)(pte)) >> 10) + +/** + * Get page table entry flags. + * + * @param pte Page table entry. + * @return Corresponding flags. + */ +#define pte_flags(pte) (((pm_t)(pte)) & 0xff) + +/** + * Convert physical memory address to page table entry. + * + * @param p Physical memory address. + * @param f Flags to use. + * @return Corresponding page table entry. + */ +#define to_pte(p, f) ((((p) >> page_shift()) << 10) | (f)) + +/** + * Get physical address in page table entry. + * + * @param pte Page table entry. + * @return Corresponding physical address. + */ +#define pte_paddr(pte) (pte_ppn(pte) << page_shift()) + +/** + * Get virtual address in page table entry. + * + * @param pte Page table entry. + * @return Corresponding virtual address. + */ +#define pte_addr(pte) __va(pte_paddr(pte)) + +/** + * Virtual memory address to page order index. + * + * @param a Virtual address. + * @param o Order of page. + * @return Corresponding page index. + */ +#define vm_to_index(a, o) (pm_to_index(a, o)) + +/** + * Check if page table entry is active. + * + * @param pte Page table entry. + * @return \c 0 if entry is not active, non-zero otherwise. + */ +#define is_active(pte) (pte_flags(pte) &VM_V) + +/** + * Check if page table entry is a leaf. + * + * @param pte Page table entry. + * @return \c 0 if entry is not leaf, non-zero otherwise. + */ +#define is_leaf(pte) (is_active(pte) && (pte_flags(pte) & ~VM_V)) + +/** + * Check if page table entry is a branch. + * + * @param pte Page table entry. + * @return \c 0 if entry is not branch, non-zero otherwise. + */ +#define is_branch(pte) (is_active(pte) && !(pte_flags(pte) & ~VM_V)) + +#endif /* KMI_RISCV_PTE_H */ |
