From 3bb2b68bc84b9cb11aae7b46eeec3c5eb3363f54 Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Fri, 2 May 2014 21:33:01 +0200 Subject: i386: add io_map_cached io_map_cached is like io_map, but reuses the old mapping if it is applicable. * i386/i386/io_map.c: Add io_map_cached. --- i386/i386/io_map.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/i386/i386/io_map.c b/i386/i386/io_map.c index 74e0b47..03d7152 100644 --- a/i386/i386/io_map.c +++ b/i386/i386/io_map.c @@ -58,3 +58,32 @@ io_map( VM_PROT_READ|VM_PROT_WRITE); return (start); } + +/* + * Allocate and map memory for devices that may need to be mapped before + * Mach VM is running. + * + * This maps the all pages containing [PHYS_ADDR:PHYS_ADDR + SIZE]. + * For contiguous requests to those pages will reuse the previously + * established mapping. + */ +vm_offset_t +io_map_cached( + vm_offset_t phys_addr, + vm_size_t size) +{ + static vm_offset_t base; + static vm_size_t length; + static vm_offset_t map; + + if (! map + || (phys_addr < base) + || (base + length < phys_addr + size)) + { + base = trunc_page(phys_addr); + length = round_page(phys_addr - base + size); + map = io_map(base, length); + } + + return map + (phys_addr - base); +} -- cgit v1.2.3