Skip to content

Commit df67bc7

Browse files
committed
lib: open-amp: support resource table relocation
There are some remote processing scenarios where the resource table needs to be moved to another location. This can be either because there is no way to exchange the location of the resource table between the two processors and they have to agree on a fixed predefined location, or because the memory segment where the current resource table resides is not is accessible/writable by the remote processor. A real example of such a case can be found in the Linux rproc driver for i.MX SoCs. A memory area containing the resource table can be specified there in the device tree. Since this feature is application dependent, it can optionally be configured in the device tree along with the other open-amp related nodes. This device tree snippet is intended to illustrate a possible use case: [..] chosen { zephyr,ipc_shm = &ipc_shm; zephyr,rsc_table = &rsc_table; zephyr,ipc = &mailbox0; }; reserved-memory { #address-cells = <1>; #size-cells = <1>; ranges; ipc_shm: memory@55000000 { reg = <0x55000000 0x500000>; }; rsc_table: rsc-table@550ff000 { reg = <0x550ff000 0x1000>; }; }; [..] Signed-off-by: Matthias Fend <[email protected]>
1 parent 70c4841 commit df67bc7

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

doc/build/dts/api/api.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,9 @@ device.
421421
- Used by the OpenThread to specify UART device for Spinel protocol
422422
* - zephyr,pcie-controller
423423
- The node corresponding to the PCIe Controller
424+
* - zephyr,rsc_table
425+
- The resource table is copied to the "reserved memory" area specified
426+
by the ``zephyr,rsc_table`` node
424427
* - zephyr,settings-partition
425428
- Fixed partition node. If defined this selects the partition used
426429
by the NVS and FCB settings backends.

lib/open-amp/resource_table.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,33 @@ static struct fw_resource_table __resource resource_table = {
7272
#endif
7373
};
7474

75+
#if DT_HAS_CHOSEN(zephyr_rsc_table)
76+
77+
#define RSC_TABLE_RELOC DT_CHOSEN(zephyr_rsc_table)
78+
#define RSC_TABLE_RELOC_START DT_REG_ADDR(RSC_TABLE_RELOC)
79+
#define RSC_TABLE_RELOC_SIZE DT_REG_SIZE(RSC_TABLE_RELOC)
80+
81+
BUILD_ASSERT(sizeof(resource_table) <= RSC_TABLE_RELOC_SIZE,
82+
"Resource table does not fit in the relocation area");
83+
84+
#endif
85+
7586
void rsc_table_get(void **table_ptr, int *length)
7687
{
88+
#if defined(RSC_TABLE_RELOC)
89+
const size_t cmp_size = offsetof(struct fw_resource_table, offset) + sizeof(((struct fw_resource_table *)0)->offset);
90+
91+
*table_ptr = (void *)RSC_TABLE_RELOC_START;
92+
*length = sizeof(resource_table);
93+
94+
/*
95+
* Do not copy the resource table if it has already been installed from the remote host.
96+
* Because the remote host may have already initialized some fields, only the guaranteed constant bytes can be compared.
97+
*/
98+
if(memcmp(&resource_table, *table_ptr, cmp_size))
99+
memcpy(*table_ptr, (void *)&resource_table, *length);
100+
#else
77101
*table_ptr = (void *)&resource_table;
78102
*length = sizeof(resource_table);
103+
#endif
79104
}

0 commit comments

Comments
 (0)