Shared Memory - 2022.1 English

Libmetal and OpenAMP User Guide (UG1186)

Document ID
Release Date
2022.1 English

Libmetal provides a way to access and interact with a memory device. However the memory type is user-defined.

In the Linux userspace, libmetal uses the UIO (Userspace I/O) driver so interaction is limited to treating the memory as device memory.

Libmetal provides I/O region abstraction that gives access to memory mapped I/O and shared memory regions. This includes primitives to read and write memory with ordering constraints and the ability to translate between physical and virtual addressing on systems that support virtual memory.

Following is an example to statically define, open, read and write from a shared memory device. This example shows a shared memory libmetal device with static definition for baremetal/FreeRTOS:

static struct metal_device shm_dev = { /* shared memory device */

.name = “3ed80000.shm”, /* device name */

.bus = NULL, /* device bus */

.num_regions = 1, /* number of regions on device */



.virt = (void*) 0x3ED80000, /* virtual address */

.physmap = 0x3ED80000, /* physical address */

.size = 0x800000, /* size of region */

.page_shift = (sizeof(metal_phys_addr_t) << 3), /* page shift */

.page_mask = (unsigned long)(-1), /* page mask */

.mem_flags = NORM_SHARED_NCACHE | PRIV_RW_USER_RW, /* memory flags */

.ops = {NULL}, /* user defined memory operations */



.node = {NULL}, /* node to point to device in list of nodes on bus */

.irq_num = 0, /* Number of IRQs per device. This is 0 because there are no interrupts we want to use for this device.*/

.irq_info = NULL, /* IRQ info. This is NULL because we are not using this device for interrupts. */


* Open the shared memory device, use the shared memory device as follows:

/* Open the shared memory device */

ret = metal_device_open(“platform”, “3ed80000.shm”, &dev); /* the first argument, bus name, is ‘platform’ for generic platform. */

/* get shared memory device IO region */

io = metal_device_io_region(device, 0);

/* read data from the shared memory*/

metal_io_block_read(io, READ_OFFSET, destination, data_length);

/* write data to the shared memory*/

ret = metal_io_block_write(io, WRITE_OFFSET, source, data_length);