mmap(D2DK) —
.IX \f4mmap\fP(D2DK)
NAME
mmap − check virtual mapping for memory-mapped device
SYNOPSIS
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/vm.h>
int prefixmmap(dev_t dev, off_t off, int prot);
ARGUMENTS
devDevice whose memory is to be mapped.
offOffset within device memory at which mapping begins.
protProtection flags from mman.h. Valid flags are:
PROT_READ page can be read.
PROT_WRITE page can be written.
PROT_EXEC page can be executed.
PROT_USER page is accessible from user-level.
PROT_ALL all of the above.
DESCRIPTION
The mmap entry point provides a way to support character drivers for memory-mapped devices. A memory-mapped device has memory that can be mapped into a process’s address space. The mmap(2) system call, when applied to a character special file, allows this device memory to be mapped into user space for direct access by the user application (no kernel buffering overhead is incurred.)
The mmap routine checks if the offset is within the range of pages supported by the device. For example, a device that has 512 bytes of memory that can be mapped into user space should not support offsets greater than, or equal to, 512. If the offset does not exist, then NOPAGE is returned. If the offset does exist, the mmap routine returns the physical page ID for the page at offset off in the device’s memory.
A physical page ID is a machine-specific token that uniquely identifies a page of physical memory in the system (either system memory or device memory.) No assumptions should be made about the format of a physical page ID. The functions kvtoppid(D3DK) and phystoppid(D3DK) can be used to get a physical page ID for a given address, depending on whether the address is virtual or physical.
NOTES
This entry point is optional. The driver’s mmap routine has user context and can sleep. The driver mmap routine should only be supported for memory-mapped devices or pseudo-devices.
RETURN VALUE
If the protection and offset are valid for the device, the driver should return the physical page ID. Otherwise, NOPAGE should be returned.
SEE ALSO
kvtoppid(D3DK), phystoppid(D3DK) mmap(2)
DDI/DKI