vmap. vmappat – physical to virtual mapping


#include "fns.h"
enum {
PATUC           = 0,        /* uncachable */
PATWC           = 1,        /* use write–combining buffers */
PATWT           = 4,        /* write–through */
PATWP           = 5,        /* write protect */
PATWB           = 6,        /* write back */
PATUCMINUS       = 7,        /* UC–; strongly uncacheable */
void* vmap(uintmem base, usize size)
void* vmappat(uintmem base, usize size, uint pattype)
void    vunmap(void*)
int     vmapsync(uintmem addr)


Vmap creates and returns a virtual address for the physical address base on the local processor. The most common use for this is to map PCI BARs.
The actual map may be larger than the requested size if the base is not smallest page–aligned or the size is not a multiple of the smallest page size. It is an error to map the same region of memory twice, but overlap is calculated before rounding to smallest page size. It is also an error to map an unknown region. The default memory type is uncachable memory, or PATUC. But vmappat allows the memory type to be user–selected.
If the new map is accessed on another processor it will fault. Fault can restore the mapping with vmapsync, which returns 0 if a matching map is found and restored, and –1 otherwise.






Vmap and Vmappat return nil on failure. Vmapsync returns –1 if no map is found.


PAT is x86– and x86–64–specific.