Memory-mapped I/O (mmio.h)
The API is defined in the header file sysroot-*-kos/include/coresrv/io/mmio.h
from the KasperskyOS SDK.
The API is intended for working with MMIO memory. MMIO memory consists of physical addresses that are mapped to registers and memory of devices. (Portions of one physical address space are used for physical memory addressing and access to registers and memory of devices.)
Information about API functions is provided in the table below.
Using the API
The standard scenario for API usage includes the following steps:
- The MMIO memory region corresponding to the relevant device is registered.
To complete this step, call the
KnRegisterPhyMem()
function.The handle of an MMIO memory region can be transferred to another process via IPC.
- Mapping the MMIO memory region to the memory of a process.
An MMIO memory region can only be mapped to one virtual memory region of only one process at one time. (However, an MMIO memory region may be mapped to the virtual memory of different processes that own the handle of this region at different times.) Mapping allows the process to receive read-and/or-write access to the MMIO memory region.
To reserve a virtual memory region and map the MMIO memory region to it, call the
KnIoMapMem()
function.A handle received when calling the
KnIoMapMem()
function cannot be transferred to another process via IPC. - Reading data from the MMIO memory region and writing data to it via process memory.
The 8-, 16- and 32-bit words that are read from the MMIO memory region or written to it are values of device registers or contents of device memory.
To complete this step, use the
IoReadMmReg8|16|32()
,IoReadMmBuffer8|16|32()
,IoWriteMmReg8|16|32()
, andIoWriteMmBuffer8|16|32()
functions.
Deregistering an MMIO memory region
To deregister an MMIO memory region, complete the following steps:
- Free the virtual memory region that was allocated when the
KnIoMapMem()
function was called.To complete this step, call the
KnHandleClose()
function and specify the handle that was received when theKnIoMapMem()
function was called. (TheKnHandleClose()
function is declared in the header filesysroot-*-kos/include/coresrv/handle/handle_api.h
from the KasperskyOS SDK.) - Close or revoke each MMIO memory region handle in all processes that own these handles.
To complete this step, use the
KnHandleClose()
and/orKnHandleRevoke()
functions that are declared in the header filesysroot-*-kos/include/coresrv/handle/handle_api.h
from the KasperskyOS SDK.
Information about API functions
mmio.h functions
Function(s) |
Information about the function(s) |
---|---|
|
Purpose Registers an MMIO memory region. Parameters
Returned values If successful, the function returns |
|
Purpose Reserves the virtual memory region and maps the MMIO memory region to it. Parameters
Returned values If successful, the function returns Additional information In the
In the
|
|
Purpose Get an 8-, 16- or 32-bit word from an MMIO memory region. Parameters
Returned values 8-, 16- or 32-bit word from the MMIO memory region. |
|
Purpose Save a sequence of 8-, 16- or 32-bit words from the MMIO memory region to the buffer. Parameters
Returned values N/A Additional information The functions can be used if the processor has an x86 or x86-64 architecture. |
|
Purpose Write an 8-, 16- or 32-bit word to an MMIO memory region. Parameters
Returned values N/A |
|
Purpose Write a sequence of 8-, 16- or 32-bit words from the buffer to an MMIO memory region. Parameters
Returned values N/A Additional information The functions can be used if the processor has an x86 or x86-64 architecture. |