From 768a7d4a989d95e22e1249c36c57655665975918 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Wed, 16 Feb 2022 23:36:18 +0100 Subject: io_map: Fix using physical addresses --- i386/i386/io_map.c | 10 +++++----- include/mach/vm_param.h | 4 ++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/i386/i386/io_map.c b/i386/i386/io_map.c index 2c2aa720..96062243 100644 --- a/i386/i386/io_map.c +++ b/i386/i386/io_map.c @@ -38,7 +38,7 @@ extern vm_offset_t kernel_virtual_start; */ vm_offset_t io_map( - vm_offset_t phys_addr, + phys_addr_t phys_addr, vm_size_t size) { vm_offset_t start; @@ -72,10 +72,10 @@ io_map( */ vm_offset_t io_map_cached( - vm_offset_t phys_addr, + phys_addr_t phys_addr, vm_size_t size) { - static vm_offset_t base; + static phys_addr_t base; static vm_size_t length; static vm_offset_t map; @@ -83,8 +83,8 @@ io_map_cached( || (phys_addr < base) || (base + length < phys_addr + size)) { - base = trunc_page(phys_addr); - length = round_page(phys_addr - base + size); + base = trunc_phys(phys_addr); + length = round_phys(phys_addr - base + size); map = io_map(base, length); } diff --git a/include/mach/vm_param.h b/include/mach/vm_param.h index cdccce82..4cbd0eca 100644 --- a/include/mach/vm_param.h +++ b/include/mach/vm_param.h @@ -88,11 +88,15 @@ #define round_page(x) ((vm_offset_t)((((vm_offset_t)(x)) + PAGE_MASK) & ~PAGE_MASK)) #define trunc_page(x) ((vm_offset_t)(((vm_offset_t)(x)) & ~PAGE_MASK)) +#define round_phys(x) ((phys_addr_t)((((phys_addr_t)(x)) + PAGE_MASK) & ~PAGE_MASK)) +#define trunc_phys(x) ((phys_addr_t)(((phys_addr_t)(x)) & ~PAGE_MASK)) + /* * Determine whether an address is page-aligned, or a count is * an exact page multiple. */ #define page_aligned(x) ((((vm_offset_t) (x)) & PAGE_MASK) == 0) +#define phys_aligned(x) ((((phys_addr_t) (x)) & PAGE_MASK) == 0) #endif /* _MACH_VM_PARAM_H_ */ -- cgit v1.2.3