diff --git a/arch/x86/pagetables.c b/arch/x86/pagetables.c index 58761dc6..2cec2051 100644 --- a/arch/x86/pagetables.c +++ b/arch/x86/pagetables.c @@ -152,11 +152,11 @@ static mfn_t get_pgentry_mfn(mfn_t tab_mfn, pt_index_t index, unsigned long flag return mfn; } -void *vmap(void *va, mfn_t mfn, unsigned int order, +void *_vmap(cr3_t *cr3, void *va, mfn_t mfn, unsigned int order, #if defined(__x86_64__) - unsigned long l4_flags, + unsigned long l4_flags, #endif - unsigned long l3_flags, unsigned long l2_flags, unsigned long l1_flags) { + unsigned long l3_flags, unsigned long l2_flags, unsigned long l1_flags) { static spinlock_t lock = SPINLOCK_INIT; mfn_t l1t_mfn, l2t_mfn, l3t_mfn; pgentry_t *tab, *entry; @@ -169,9 +169,9 @@ void *vmap(void *va, mfn_t mfn, unsigned int order, spin_lock(&lock); #if defined(__x86_64__) - l3t_mfn = get_pgentry_mfn(get_cr3_mfn(&cr3), l4_table_index(va), l4_flags); + l3t_mfn = get_pgentry_mfn(get_cr3_mfn(cr3), l4_table_index(va), l4_flags); #else - l3t_mfn = get_cr3_mfn(&cr3); + l3t_mfn = get_cr3_mfn(cr3); #endif if (order == PAGE_ORDER_1G) { @@ -201,8 +201,14 @@ void *vmap(void *va, mfn_t mfn, unsigned int order, return va; } -void vunmap(void *va, unsigned int order) { - vmap(va, MFN_INVALID, order, PT_NO_FLAGS, PT_NO_FLAGS, PT_NO_FLAGS, PT_NO_FLAGS); +void *vmap_kern(void *va, mfn_t mfn, unsigned int order, +#if defined(__x86_64__) + unsigned long l4_flags, +#endif + unsigned long l3_flags, unsigned long l2_flags, unsigned long l1_flags) { + unsigned long _va = _ul(va) & PAGE_ORDER_TO_MASK(order); + + return _vmap(&cr3, _ptr(_va), mfn, order, l4_flags, l3_flags, l2_flags, l1_flags); } void init_pagetables(void) { diff --git a/common/setup.c b/common/setup.c index 4eb74006..42cbdaf9 100644 --- a/common/setup.c +++ b/common/setup.c @@ -105,7 +105,7 @@ void zap_boot_mappings(void) { memset(r->start, 0, r->end - r->start); for (mfn_t mfn = virt_to_mfn(r->start); mfn < virt_to_mfn(r->end); mfn++) { - vunmap(mfn_to_virt(mfn), PAGE_ORDER_4K); + vunmap_kern(mfn_to_virt(mfn), PAGE_ORDER_4K); reclaim_frame(mfn, PAGE_ORDER_4K); } } diff --git a/drivers/acpi/acpica/osl.c b/drivers/acpi/acpica/osl.c index 9d372a00..23511159 100644 --- a/drivers/acpi/acpica/osl.c +++ b/drivers/acpi/acpica/osl.c @@ -294,7 +294,8 @@ void *AcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS PhysicalAddress, ACPI_SIZE Length) { void *_va; if (!frame) { - _va = mmap_4k(mfn, L1_PROT); + _va = vmap_kern(mfn_to_virt_map(mfn), mfn, PAGE_ORDER_4K, L4_PROT, L3_PROT, + L2_PROT, L1_PROT); if (!_va) { spin_unlock(&map_lock); return NULL; @@ -327,7 +328,7 @@ void AcpiOsUnmapMemory(void *LogicalAddress, ACPI_SIZE Length) { if (--frame->refcount > 0) continue; - vunmap(mfn_to_virt_map(mfn), PAGE_ORDER_4K); + vunmap_kern(mfn_to_virt_map(mfn), PAGE_ORDER_4K); list_unlink(&frame->list); kfree(frame); } @@ -351,7 +352,6 @@ typedef struct osd_exec_cb_wrapper osd_exec_cb_wrapper_t; unsigned long _osd_exec_cb_wrapper(void *arg) { osd_exec_cb_wrapper_t *cb = arg; - cb->Function(cb->Context); return 0; } diff --git a/include/arch/x86/page.h b/include/arch/x86/page.h index c7bc16de..468234d6 100644 --- a/include/arch/x86/page.h +++ b/include/arch/x86/page.h @@ -159,13 +159,13 @@ typedef unsigned long mfn_t; /* External declarations */ -extern void *vmap(void *va, mfn_t mfn, unsigned int order, +extern void *vmap_kern(void *va, mfn_t mfn, unsigned int order, #if defined(__x86_64__) - unsigned long l4_flags, + unsigned long l4_flags, #endif - unsigned long l3_flags, unsigned long l2_flags, unsigned long l1_flags); + unsigned long l3_flags, unsigned long l2_flags, + unsigned long l1_flags); -extern void vunmap(void *va, unsigned int order); extern void pat_set_type(pat_field_t field, pat_memory_type_t type); extern pat_memory_type_t pat_get_type(pat_field_t field); @@ -227,68 +227,45 @@ static inline mfn_t virt_to_mfn(const void *va) { return paddr_to_mfn(virt_to_paddr(va)); } -static inline void *kmap(mfn_t mfn, unsigned int order, -#if defined(__x86_64__) - unsigned long l4_flags, -#endif - unsigned long l3_flags, unsigned long l2_flags, - unsigned long l1_flags) { - return vmap(mfn_to_virt_kern(mfn), mfn, order, -#if defined(__x86_64__) - l4_flags, -#endif - l3_flags, l2_flags, l1_flags); +static inline void vunmap_kern(void *va, unsigned int order) { + vmap_kern(va, MFN_INVALID, order, PT_NO_FLAGS, PT_NO_FLAGS, PT_NO_FLAGS, PT_NO_FLAGS); } -static inline void *mmap(mfn_t mfn, unsigned int order, +static inline void *kmap(mfn_t mfn, unsigned int order, #if defined(__x86_64__) unsigned long l4_flags, #endif unsigned long l3_flags, unsigned long l2_flags, unsigned long l1_flags) { - return vmap(mfn_to_virt_map(mfn), mfn, order, + return vmap_kern(mfn_to_virt_kern(mfn), mfn, order, #if defined(__x86_64__) - l4_flags, + l4_flags, #endif - l3_flags, l2_flags, l1_flags); + l3_flags, l2_flags, l1_flags); } static inline void *vmap_1g(void *va, mfn_t mfn, unsigned long l3_flags) { - return vmap(va, mfn, PAGE_ORDER_1G, L4_PROT_USER, l3_flags, PT_NO_FLAGS, PT_NO_FLAGS); + return vmap_kern(va, mfn, PAGE_ORDER_1G, L4_PROT, l3_flags, PT_NO_FLAGS, PT_NO_FLAGS); } static inline void *vmap_2m(void *va, mfn_t mfn, unsigned long l2_flags) { - return vmap(va, mfn, PAGE_ORDER_2M, L4_PROT_USER, L3_PROT_USER, l2_flags, - PT_NO_FLAGS); + return vmap_kern(va, mfn, PAGE_ORDER_2M, L4_PROT, L3_PROT, l2_flags, PT_NO_FLAGS); } static inline void *vmap_4k(void *va, mfn_t mfn, unsigned long l1_flags) { - return vmap(va, mfn, PAGE_ORDER_4K, L4_PROT_USER, L3_PROT_USER, L2_PROT_USER, - l1_flags); + return vmap_kern(va, mfn, PAGE_ORDER_4K, L4_PROT, L3_PROT, L2_PROT, l1_flags); } static inline void *kmap_1g(mfn_t mfn, unsigned long l3_flags) { - return kmap(mfn, PAGE_ORDER_1G, L4_PROT_USER, l3_flags, PT_NO_FLAGS, PT_NO_FLAGS); + return kmap(mfn, PAGE_ORDER_1G, L4_PROT, l3_flags, PT_NO_FLAGS, PT_NO_FLAGS); } static inline void *kmap_2m(mfn_t mfn, unsigned long l2_flags) { - return kmap(mfn, PAGE_ORDER_2M, L4_PROT_USER, L3_PROT_USER, l2_flags, PT_NO_FLAGS); + return kmap(mfn, PAGE_ORDER_2M, L4_PROT, L3_PROT, l2_flags, PT_NO_FLAGS); } static inline void *kmap_4k(mfn_t mfn, unsigned long l1_flags) { - return kmap(mfn, PAGE_ORDER_4K, L4_PROT_USER, L3_PROT_USER, L2_PROT_USER, l1_flags); -} - -static inline void *mmap_1g(mfn_t mfn, unsigned long l3_flags) { - return mmap(mfn, PAGE_ORDER_1G, L4_PROT_USER, l3_flags, PT_NO_FLAGS, PT_NO_FLAGS); -} - -static inline void *mmap_2m(mfn_t mfn, unsigned long l2_flags) { - return mmap(mfn, PAGE_ORDER_2M, L4_PROT_USER, L3_PROT_USER, l2_flags, PT_NO_FLAGS); -} - -static inline void *mmap_4k(mfn_t mfn, unsigned long l1_flags) { - return mmap(mfn, PAGE_ORDER_4K, L4_PROT_USER, L3_PROT_USER, L2_PROT_USER, l1_flags); + return kmap(mfn, PAGE_ORDER_4K, L4_PROT, L3_PROT, L2_PROT, l1_flags); } #endif /* __ASSEMBLY__ */ diff --git a/mm/vmm.c b/mm/vmm.c index 6d86b21d..2983275f 100644 --- a/mm/vmm.c +++ b/mm/vmm.c @@ -40,24 +40,31 @@ void *get_free_pages(unsigned int order, uint32_t flags) { if (!frame) return NULL; - mfn = frame->mfn; - if (flags & GFP_IDENT) - va = vmap(mfn_to_virt(mfn), mfn, order, L4_PROT, L3_PROT, L2_PROT, L1_PROT); - if (flags & GFP_USER) - va = vmap(mfn_to_virt_user(mfn), mfn, order, L4_PROT_USER, L3_PROT_USER, - L2_PROT_USER, L1_PROT_USER); - if (flags & GFP_KERNEL) + if (flags == GFP_USER) { + va = vmap_kern(mfn_to_virt_user(mfn), mfn, order, L4_PROT, L3_PROT, L2_PROT, + L1_PROT); + } + + if (flags & GFP_IDENT) { + va = vmap_kern(mfn_to_virt(mfn), mfn, order, L4_PROT, L3_PROT, L2_PROT, L1_PROT); + } + + if (flags & GFP_KERNEL) { va = kmap(mfn, order, L4_PROT, L3_PROT, L2_PROT, L1_PROT); - if (flags & GFP_KERNEL_MAP) - va = mmap(mfn, order, L4_PROT, L3_PROT, L2_PROT, L1_PROT); + } + + if (flags & GFP_KERNEL_MAP) { + va = vmap_kern(mfn_to_virt_map(mfn), mfn, order, L4_PROT, L3_PROT, L2_PROT, + L1_PROT); + } return va; } void put_pages(void *page, unsigned int order) { /* FIXME: unmap all mappings */ - vunmap(page, order); + vunmap_kern(page, order); put_free_frames(virt_to_mfn(page), order); }