Libmetal provides common user APIs to access devices, handle device interrupts and request memory across the following operating environments:
- Linux user space (based on UIO and VFIO support in the kernel)
- RTOS (with and without virtual memory)
- Bare-metal environments
The following subsections give an overview of interfaces provided by libmetal.
These interfaces do not need to be ported across to new operating systems.
The libmetal I/O region abstraction provides access to memory mapped I/O and shared memory regions. This includes:
- primitives to read and write memory with ordering constraints, and
- ability to translate between physical and virtual addressing on systems that support virtual memory.
The libmetal logging interface is used to plug log messages generated by libmetal into application specific logging mechanisms (e.g. syslog). This also provides basic message prioritization and filtering mechanisms.
This is a simple doubly linked list implementation used internally within libmetal, and also available for application use.
The following utilities are provided in lib/utilities.h:
- Min/max, round up/down, etc.
- Bitmap operations
- Helper to compute container structure pointers
- ... and more ...
The libmetal version interface allows user to get the version of the library.
This is used in Linux shared memory implementation today, but will be removed in the future.
The users will need to call two top level interfaces to use libmetal APIs:
- metal_init - initialize the libmetal resource
- metal_finish - release libmetal resource
Each system needs to have their own implementation inside libmetal for these two APIs to call:
- metal_sys_init
- metal_sys_finish
For the current release, libmetal provides Linux userspace and bare-metal implementation for metal_sys_init and metal_sys_finish.
For Linux userspace, metal_sys_init sets up a table for available shared pages, checks whether UIO/VFIO drivers are avail, and starts interrupt handling thread.
For bare-metal, metal_sys_init and metal_sys_finish just returns.
The libmetal atomic operations API is consistent with the C11/C++11 stdatomics interface. The stdatomics interface is commonly provided by recent toolchains including GCC and LLVM/Clang. When porting to a different toolchain, it may be necessary to provide an stdatomic compatible implementation if the toolchain does not already provide one.
libmetal has a generic mutex implementation which is a busy wait. It is recommended to have OS specific implementation for mutex.
The Linux userspace mutex implementation uses futex to wait for the lock and wakeup a waiter.
libmetal has a generic static shared memory implementation. If your OS has a global shared memory allocation, you will need to port it for the OS.
The Linux userspace shmem implementation uses libhugetlbfs to support huge page sizes.
libmetal has a static generic implementation. If your OS has a driver model implementation, you will need to port it for the OS.
The Linux userspace abstraction binds the devices to UIO or VFIO driver. The user applications specify which device to use, e.g. bus "platform" bus, device "f8000000.slcr", and then the abstraction will check if platform UIO driver or platform VFIO driver is there. If platform VFIO driver exists, it will bind the device to the platform VFIO driver, otherwise, if UIO driver exists, it will bind the device to the platform UIO driver.
The VFIO support is not yet implemented.
This API is not in the current release yet. The interrupt API implementation will be OS specific or platform specific.
libmetal provides APIs to register an interrupt, disable interrupts and restore interrupts.
The Linux userspace implementation will use a thread to call select() function to listen to the file descriptors of the devices to see if there is an interrupt triggered. If there is an interrupt triggered, it will call the interrupt handler registered by the user application.
This API is for compiler dependent functions. For this release, there is only a GCC implementation, and compiler specific code is limited to atomic operations.