Coprocessor resource table

Applicable for STM32MP15x lines

1 Role of the resource table[edit]

The resource table is a global variable declared as a structure in the coprocessor firmware. This table contains resources that the remote processor requires before being powered on, such as the allocation of a physically contiguous memory. In addition, the resource table may also contain resource entries that publish the existence of supported features or configurations by the remote processor, such as trace buffers and/or supported Virtio devices used for the IPC.

This table must be defined in a specific data section of the coprocessor firmware, parsed by the RemoteProc Linux® framework during the firmware load phase to:

  • Allocate memories defined in the resource table carveout section (not used in the ST Arm® Cortex®-M4 firmware).
  • Load the RPMsg and Virtio frameworks to support messaging services.
  • Provide a user sysfs interface to access coprocessor traces for debug.

2 How to define the resource table[edit]

The resource table must be part of the firmware’s ELF image, in order to be accessible by the Linux RemoteProc framework. This resource table can be a default table or customized depending on the enabled features.

In the STM32MCU cube firmware package, the resource table is defined in rsc_table.c

2.1 Default table[edit]

For the Cortex-M firmware that does not require interaction with the Linux OS, a default structure must be declared in the Cortex-M firmware

 struct remote_resource_table __resource __attribute__((used)) rproc_resource = {
 	.version = 1,
 	.num = 0,
 	.reserved = {0, 0},
 	.offset = { 0 },
 };

2.2 How to add trace for the log buffer[edit]

This feature allows to dump Cortex-M firmware traces on the linux side. For this a system_log_buf buffer defined in log.c file and declared in the resource table allows Linux to dump the associated memory area (under "__LOG_TRACE_IO_" preprocessor definition).

 1 const struct shared_resource_table __resource __attribute__((used)) resource_table = {
 2 	.version = 1,
 3 #if defined (__LOG_TRACE_IO_)
 4 	.num = 2,
 5 #else
 6 	.num = 1,
 7 #endif
 8 	.reserved = {0, 0},
 9 	.offset = {
10 		offsetof(struct shared_resource_table, vdev),
11 #if defined (__LOG_TRACE_IO_)
12 		offsetof(struct shared_resource_table, cm_trace),
13 #endif
14 	},
15         .......
16 #if defined (__LOG_TRACE_IO_)
17 	.cm_trace = {
18 		RSC_TRACE,
19 		(uint32_t)system_log_buf, SYSTEM_TRACE_BUF_SZ, 0, "cm4_log",
20 	},
21 #endif
22  };

These logs can be retrieved after a firmware crash: refer to How to retrieve Cortex-M4 logs after crash for more information.

2.3 How to add RPMsg inter-processor communication[edit]

The messaging service is enabled by declaring:

  • The rpmsg Virtio device for control,
  • The rpmsg Virtio ring buffers for message management.

These structures are used by the Linux RemoteProc framework. The Remoteproc framework is in charge of allocating buffers associated to Vring (for both direction) in the shared memory and of providing information in the rpmsg_vring structures.

 1 #define NUM_VRINGS                  0x02  /* number of Vring used , must be fixed to 2 (one for TX one for RX) */
 2 #define VRING_ALIGN                 0x1000 /* must be fixed to 0x1000 (Linux constraint) */
 3 #define VRING_TX                    -1  /* allocated by master processor */
 4 #define VRING_RX                    -1  /* allocated by master processor */
 5 #define VRING_SIZE                  8  /* number of 512 bytes buffers associated to a Vring: can be customized */
 6 
 7 struct remote_resource_table __resource __attribute__((used)) rproc_resource = {
 8  	.version = 1,
 9  	.num = 1,  /* rely to number of offsetof structures declared in .offset */
10  	.reserved = {0, 0},
11  	.offset = {
12  		offsetof(struct remote_resource_table, rpmsg_vdev),
13  	},
14  	/* Virtio device entry */
15 	.rpmsg_vdev= {
16 		RSC_VDEV, VIRTIO_ID_RPMSG_, 0, RPMSG_IPU_C0_FEATURES, 0, 0, 0,
17 		NUM_VRINGS, {0, 0},
18 	},
19 
20 	/* Vring rsc entry - part of vdev rsc entry */
21 	.rpmsg_vring0 = {VRING_TX, VRING_ALIGN, VRING_SIZE, 1, 0},
22 	.rpmsg_vring1 = {VRING_RX, VRING_ALIGN, VRING_SIZE, 2, 0},
23  };