Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@
/kernel/ @andrewboie @andyross
/lib/fnmatch/ @carlescufi
/lib/gui/ @vanwinkeljan
/lib/open-amp/ @arnopo
/lib/os/ @andrewboie @andyross
/lib/posix/ @pfalcon
/lib/cmsis_rtos_v2/ @nashif
Expand Down
2 changes: 1 addition & 1 deletion dts/arm/st/mp1/stm32mp157.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
mcusram: memory1@10000000 {
device_type = "memory";
compatible = "mmio-sram";
reg = <0x10000000 DT_SIZE_K(256)>;
reg = <0x10000000 DT_SIZE_K(320)>;
};

soc {
Expand Down
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ add_subdirectory_ifdef(CONFIG_FNMATCH fnmatch)
add_subdirectory(gui)
add_subdirectory(os)
add_subdirectory_ifdef(CONFIG_UPDATEHUB updatehub)
add_subdirectory_ifdef(CONFIG_OPENAMP open-amp)
2 changes: 2 additions & 0 deletions lib/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ source "lib/posix/Kconfig"

source "lib/updatehub/Kconfig"

source "lib/open-amp/Kconfig"

endmenu
8 changes: 8 additions & 0 deletions lib/open-amp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#
# Copyright (c) 2020, STMicroelectronics
#
# SPDX-License-Identifier: Apache-2.0
#

zephyr_include_directories_ifdef(CONFIG_OPENAMP_RSC_TABLE .)
zephyr_sources_ifdef(CONFIG_OPENAMP_RSC_TABLE resource_table.c)
20 changes: 20 additions & 0 deletions lib/open-amp/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# Copyright (c) 2020, STMicroelectronics
#
# SPDX-License-Identifier: Apache-2.0
#

config OPENAMP_RSC_TABLE
bool "coprocessor resource table"
imply OPENAMP
help
add the resource table in the generated binary. This table is
compatible with linux remote proc framework and OpenAMP library.

config OPENAMP_RSC_TABLE_NUM_RPMSG_BUFF
int "Resource table number of rpmsg buffers"
default 0
depends on OPENAMP_RSC_TABLE
help
This option specifies the number of buffer used in a Vring for
interprocessor communication
82 changes: 82 additions & 0 deletions lib/open-amp/resource_table.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright (c) 2020 STMicroelectronics
*
* SPDX-License-Identifier: Apache-2.0
*/

/*
* In addition to the standard ELF segments, most remote processors would
* also include a special section which we call "the resource table".
*
* The resource table contains system resources that the remote processor
* requires before it should be powered on, such as allocation of physically
* contiguous memory, or iommu mapping of certain on-chip peripherals.

* In addition to system resources, 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
* supported virtio devices (and their configurations).

* Dependencies:
* to be compliant with Linux kernel OS the resource table must be linked in a
* specific section named ".resource_table".

* Related documentation:
* https://www.kernel.org/doc/Documentation/remoteproc.txt
* https://github.com/OpenAMP/open-amp/wiki/OpenAMP-Life-Cycle-Management
*/

#include <zephyr.h>
#include <resource_table.h>

extern char ram_console[];

#define __resource Z_GENERIC_SECTION(.resource_table)

#if (CONFIG_OPENAMP_RSC_TABLE_NUM_RPMSG_BUFF > 0) || defined(CONFIG_RAM_CONSOLE)

static struct fw_resource_table __resource resource_table = {
.ver = 1,
.num = RSC_TABLE_NUM_ENTRY,
.offset = {

#if (CONFIG_OPENAMP_RSC_TABLE_NUM_RPMSG_BUFF > 0)
offsetof(struct fw_resource_table, vdev),
#endif

#if defined(CONFIG_RAM_CONSOLE)
offsetof(struct fw_resource_table, cm_trace),
#endif
},

#if (CONFIG_OPENAMP_RSC_TABLE_NUM_RPMSG_BUFF > 0)
/* Virtio device entry */
.vdev = {
RSC_VDEV, VIRTIO_ID_RPMSG, 0, RPMSG_IPU_C0_FEATURES, 0, 0, 0,
VRING_COUNT, {0, 0},
},

/* Vring rsc entry - part of vdev rsc entry */
.vring0 = {VRING_TX_ADDRESS, VRING_ALIGNMENT,
CONFIG_OPENAMP_RSC_TABLE_NUM_RPMSG_BUFF,
VRING0_ID, 0},
.vring1 = {VRING_RX_ADDRESS, VRING_ALIGNMENT,
CONFIG_OPENAMP_RSC_TABLE_NUM_RPMSG_BUFF,
VRING1_ID, 0},
#endif

#if defined(CONFIG_RAM_CONSOLE)
.cm_trace = {
RSC_TRACE,
(uint32_t)ram_console, CONFIG_RAM_CONSOLE_BUFFER_SIZE + 1, 0,
"Zephyr_log",
},
#endif
};

void rsc_table_get(void **table_ptr, int *length)
{
*table_ptr = (void *)&resource_table;
*length = sizeof(resource_table);
}
#endif
72 changes: 72 additions & 0 deletions lib/open-amp/resource_table.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (c) 2020 STMicroelectronics
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef RESOURCE_TABLE_H__
#define RESOURCE_TABLE_H__

#include <openamp/remoteproc.h>
#include <openamp/virtio.h>

#if (CONFIG_OPENAMP_RSC_TABLE_NUM_RPMSG_BUFF > 0)

#define VDEV_ID 0xFF
#define VRING0_ID 0 /* (master to remote) fixed to 0 for Linux compatibility */
#define VRING1_ID 1 /* (remote to master) fixed to 1 for Linux compatibility */

#define VRING_COUNT 2
#define RPMSG_IPU_C0_FEATURES 1

#define VRING_RX_ADDRESS -1 /* allocated by Master processor */
#define VRING_TX_ADDRESS -1 /* allocated by Master processor */
#define VRING_BUFF_ADDRESS -1 /* allocated by Master processor */
#define VRING_ALIGNMENT 16 /* fixed to match with Linux constraint */

#endif

enum rsc_table_entries {
#if (CONFIG_OPENAMP_RSC_TABLE_NUM_RPMSG_BUFF > 0)
RSC_TABLE_VDEV_ENTRY,
#endif
#if defined(CONFIG_RAM_CONSOLE)
RSC_TABLE_TRACE_ENTRY,
#endif
RSC_TABLE_NUM_ENTRY
};

struct fw_resource_table {
unsigned int ver;
unsigned int num;
unsigned int reserved[2];
unsigned int offset[RSC_TABLE_NUM_ENTRY];

struct fw_rsc_vdev vdev;
struct fw_rsc_vdev_vring vring0;
struct fw_rsc_vdev_vring vring1;

#if defined(CONFIG_RAM_CONSOLE)
/* rpmsg trace entry */
struct fw_rsc_trace cm_trace;
#endif
} METAL_PACKED_END;

void rsc_table_get(void **table_ptr, int *length);

inline struct fw_rsc_vdev *rsc_table_to_vdev(void *rsc_table)
{
return &((struct fw_resource_table *)rsc_table)->vdev;
}

inline struct fw_rsc_vdev_vring *rsc_table_get_vring0(void *rsc_table)
{
return &((struct fw_resource_table *)rsc_table)->vring0;
}

inline struct fw_rsc_vdev_vring *rsc_table_get_vring1(void *rsc_table)
{
return &((struct fw_resource_table *)rsc_table)->vring1;
}

#endif
19 changes: 19 additions & 0 deletions samples/subsys/ipc/openamp_rsc_table/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.13.1)
# Copyright (c) 2020 STMicroelectronics
#
# SPDX-License-Identifier: Apache-2.0
#

find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})

project(openamp_rsc_table_remote)

# METAL_MAX_DEVICE_REGIONS is used to give the number of memory regions shared
# between processors. By default only one region is defined for the vrings
# and rpmsg buffers. The METAL_MAX_DEVICE_REGIONS has to be redifined to add a
# second region for the resource table.
zephyr_compile_definitions(METAL_MAX_DEVICE_REGIONS=2)

target_include_directories(app PRIVATE ${LIBMETAL_INCLUDE_DIR} ${OPENAMP_INCLUDE_DIR} ${PLATFORM_DIR})

target_sources(app PRIVATE src/main_remote.c)
15 changes: 15 additions & 0 deletions samples/subsys/ipc/openamp_rsc_table/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Private config options for openamp sample app

# Copyright (c) 2020 STMicroelectronics
# SPDX-License-Identifier: Apache-2.0

# Workaround for not being able to have commas in macro arguments
DT_CHOSEN_Z_IPC := zephyr,ipc

config OPENAMP_IPC_DEV_NAME
string
default "$(dt_chosen_label,$(DT_CHOSEN_Z_IPC))"
help
This option specifies the device name for the IPC device to be used

source "Kconfig.zephyr"
72 changes: 72 additions & 0 deletions samples/subsys/ipc/openamp_rsc_table/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
.. _openAMP_rsc_table_sample:

OpenAMP Sample Application using resource table
###############################################

Overview
********

This application demonstrates how to use OpenAMP with Zephyr based on a resource
table. It is designed to respond to the `Linux rpmsg client sample <https://elixir.bootlin.com/linux/latest/source/samples/rpmsg/rpmsg_client_sample.c>`_.
This sample implementation is compatible with platforms that embed
a Linux kernel OS on the main processor and a Zephyr application on
the co-processor.

Building the application
*************************

Zephyr
-------

.. zephyr-app-commands::
:zephyr-app: samples/subsys/ipc/openamp_rsc_table
:goals: test

Linux
------

Enable SAMPLE_RPMSG_CLIENT configuration to build and install
the rpmsg_client_sample.ko module on the target.

Running the sample
*******************

Zephyr console
---------------

Open a serial terminal (minicom, putty, etc.) and connect the board with the
following settings:

- Speed: 115200
- Data: 8 bits
- Parity: None
- Stop bits: 1

Reset the board.

Linux console
---------------

Open a Linux shell (minicom, ssh, etc.) and insert a module into the Linux Kernel

.. code-block:: console

root@linuxshell: insmod rpmsg_client_sample.ko

Result on Zephyr console
-------------------------

The following message will appear on the corresponding Zephyr console:

.. code-block:: console

***** Booting Zephyr OS v#.##.#-####-g########## *****
Starting application thread!

OpenAMP demo started
Remote core received message 1: hello world!
Remote core received message 2: hello world!
Remote core received message 3: hello world!
...
Remote core received message 100: hello world!
OpenAMP demo ended.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2020, STMICROLECTRONICS
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
chosen {
/*
* shared memory reserved for the inter-processor communication
*/
zephyr,ipc_shm = &mcusram3;
zephyr,ipc = &mailbox;
};

mcusram3: memory1@10040000 {
compatible = "mmio-sram";
reg = <0x10040000 DT_SIZE_K(64)>;
};
};

&mcusram {
reg = <0x10000000 DT_SIZE_K(256)>;
};
11 changes: 11 additions & 0 deletions samples/subsys/ipc/openamp_rsc_table/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CONFIG_KERNEL_BIN_NAME="zephyr_openamp_rsc_table"
CONFIG_PRINTK=n
CONFIG_IPM=y
CONFIG_IPM_MCUX=y
CONFIG_PLATFORM_SPECIFIC_INIT=n
CONFIG_MAIN_STACK_SIZE=1024
CONFIG_HEAP_MEM_POOL_SIZE=1024
CONFIG_OPENAMP=y
CONFIG_OPENAMP_RSC_TABLE_NUM_RPMSG_BUFF=8
CONFIG_OPENAMP_RSC_TABLE=y
CONFIG_OPENAMP_MASTER=n
9 changes: 9 additions & 0 deletions samples/subsys/ipc/openamp_rsc_table/sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sample:
description: This app provides an example of how to integrate OpenAMP
with Zephyr in cluding a esource table.
name: OpenAMP with resource table example integration
tests:
sample.subsys.ipc.openamp_rs_table:
build_only: true
platform_whitelist: stm32mp157c_dk2
tags: ipm
Loading