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:
To complete this step, call the KnRegisterPhyMem() function. If the same MMIO memory region needs to be registered multiple times, the MMIO_U_SHARED flag must be specified in the flags parameter during each registration of this region. If the registered MMIO memory region is used by the kernel code, the MMIO_K_SHARED flag must be specified. If these flags are not specified, only the code that requests this access first (this can be either the kernel code or the code that is executed in user mode) will have access to the MMIO memory region. All subsequent registration attempts by calling the KnRegisterPhyMem() function will end with the rcAlreadyExists error, and messages regarding the problem with shared access to the MMIO memory region will be added to the diagnostic output. If the kernel fails to access the MMIO memory region because this region is already registered by the code being executed in user mode, a message regarding the problem with shared access to the MMIO memory region will also be added to the diagnostic output.
The handle of an MMIO memory region can be transferred to another process via IPC.
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.
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() and IoWriteMmReg8|16|32() functions.
The API includes the auxiliary functions named KnIoMemHandlesClear() and KnIoMemHandlesClose(). The KnIoMemHandlesClear() function initializes the structure for storing the handles that are created at steps 1 and 2. The KnIoMemHandlesClose() function closes the handles stored in this structure (by calling the KnHandleClose() function from the handle_api.h API) and initializes it. When the KnIoMemHandlesClose() function is called, the absence of all or one handle in the structure does not result in an error, and the available handle will be closed. The KnIoMemHandlesClear() and KnIoMemHandlesClose() functions can be used as follows. Before performing step 1, initialize the structure for storing handles by calling the KnIoMemHandlesClear() function. Then store the handles in this structure when performing steps 1 and 2. This will allow you to subsequently close all created handles with a single call of the KnIoMemHandlesClose() function.
Deregistering an MMIO memory region
To deregister an MMIO memory region, complete the following steps:
KnIoMapMem() function was called.To perform this step, you must close the handle that was obtained when calling the KnIoMapMem() function.
You can use the KnIoMemHandlesClose() function to close the handles when performing these steps.
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 Additional information In the
|
|
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 Write an 8-, 16- or 32-bit word to an MMIO memory region. Parameters
Returned values N/A |
|
Purpose Initializes a structure for storing the handles of resources allocated for MMIO provisioning. Parameters
Returned values N/A Additional information After initialization, the structure fields take the |
|
Purpose Closes the handles of resources allocated for MMIO provisioning and initializes the structure in which these handles were stored. Parameters
Returned values If successful, the function returns Additional information After initialization, the structure fields take the |