1 /* 2 * Copyright (c) 2020 STMicroelectronics 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 /* 8 * In addition to the standard ELF segments, most remote processors would 9 * also include a special section which we call "the resource table". 10 * 11 * The resource table contains system resources that the remote processor 12 * requires before it should be powered on, such as allocation of physically 13 * contiguous memory, or iommu mapping of certain on-chip peripherals. 14 15 * In addition to system resources, the resource table may also contain 16 * resource entries that publish the existence of supported features 17 * or configurations by the remote processor, such as trace buffers and 18 * supported virtio devices (and their configurations). 19 20 * Dependencies: 21 * to be compliant with Linux kernel OS the resource table must be linked in a 22 * specific section named ".resource_table". 23 24 * Related documentation: 25 * https://www.kernel.org/doc/Documentation/remoteproc.txt 26 * https://github.com/OpenAMP/open-amp/wiki/OpenAMP-Life-Cycle-Management 27 */ 28 29 #include <zephyr/kernel.h> 30 #include <resource_table.h> 31 32 #ifdef CONFIG_OPENAMP_COPY_RSC_TABLE 33 #define RSC_TABLE_ADDR DT_REG_ADDR(DT_CHOSEN(zephyr_ipc_rsc_table)) 34 #define RSC_TABLE_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_ipc_rsc_table)) 35 BUILD_ASSERT(sizeof(struct fw_resource_table) <= RSC_TABLE_SIZE); 36 #endif 37 38 extern char ram_console_buf[]; 39 40 #define __resource Z_GENERIC_SECTION(.resource_table) 41 42 static struct fw_resource_table __resource resource_table = RESOURCE_TABLE_INIT; 43 rsc_table_get(void ** table_ptr,int * length)44void rsc_table_get(void **table_ptr, int *length) 45 { 46 *length = sizeof(resource_table); 47 #ifdef CONFIG_OPENAMP_COPY_RSC_TABLE 48 *table_ptr = (void *)RSC_TABLE_ADDR; 49 memcpy(*table_ptr, &resource_table, *length); 50 #else 51 *table_ptr = &resource_table; 52 #endif 53 } 54 55 #if (CONFIG_OPENAMP_RSC_TABLE_NUM_RPMSG_BUFF > 0) 56 rsc_table_to_vdev(void * rsc_table)57struct fw_rsc_vdev *rsc_table_to_vdev(void *rsc_table) 58 { 59 return &((struct fw_resource_table *)rsc_table)->vdev; 60 } 61 rsc_table_get_vring0(void * rsc_table)62struct fw_rsc_vdev_vring *rsc_table_get_vring0(void *rsc_table) 63 { 64 return &((struct fw_resource_table *)rsc_table)->vring0; 65 } 66 rsc_table_get_vring1(void * rsc_table)67struct fw_rsc_vdev_vring *rsc_table_get_vring1(void *rsc_table) 68 { 69 return &((struct fw_resource_table *)rsc_table)->vring1; 70 } 71 72 #endif 73