Skip to content

Latest commit

 

History

History
130 lines (88 loc) · 4.36 KB

README.md

File metadata and controls

130 lines (88 loc) · 4.36 KB

libmetal

Overview

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

Interfaces

The following subsections give an overview of interfaces provided by libmetal.

Platform and OS Independent Utilities

These interfaces do not need to be ported across to new operating systems.

I/O

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.

Log

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.

List

This is a simple doubly linked list implementation used internally within libmetal, and also available for application use.

Other Utilities

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 ...

Version

The libmetal version interface allows user to get the version of the library.

Domain

This is used in Linux shared memory implementation today, but will be removed in the future.

Top Level Interfaces

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.

Atomics

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.

Mutex

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.

Shmem

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.

Bus and Device Abstraction

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.

Interrupt

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.

Compiler

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.