├── CMakeLists.txt ├── LICENSE.md ├── MAINTAINERS.md ├── README.md ├── SConscript ├── apps ├── CMakeLists.txt ├── examples │ ├── CMakeLists.txt │ ├── echo │ │ ├── CMakeLists.txt │ │ ├── rpmsg-echo.c │ │ ├── rpmsg-echo.h │ │ └── rpmsg-ping.c │ ├── load_fw │ │ ├── CMakeLists.txt │ │ ├── common.h │ │ ├── common.h.orig │ │ ├── load_fw.c │ │ ├── lscript.ld │ │ ├── mem_image_store.c │ │ ├── mem_image_store.c.orig │ │ ├── platform_info.c │ │ ├── platform_info.h │ │ ├── virt_rv64_rproc_example.c │ │ ├── zynqmp_apu_lcm_rproc_example.c │ │ ├── zynqmp_r5_lcm_rproc_example.c │ │ └── zynqmp_rpu_lcm_rproc_example.c │ ├── matrix_multiply │ │ ├── CMakeLists.txt │ │ ├── matrix_multiply.c │ │ ├── matrix_multiply.h │ │ ├── matrix_multiplyd.c │ │ ├── matrix_multiplyd.c.orig │ │ ├── matrix_multiplyd.c.rej │ │ └── matrix_multiplyd.o │ ├── rpc_demo │ │ ├── CMakeLists.txt │ │ ├── rpc_demo.c │ │ ├── rpc_demod.c │ │ └── rpmsg-rpc-demo.h │ └── rpmsg_sample_echo │ │ ├── CMakeLists.txt │ │ ├── rpmsg-sample-echo.c │ │ ├── rpmsg-sample-echo.c.orig │ │ ├── rpmsg-sample-echo.o │ │ └── rpmsg-sample-ping.c ├── machine │ ├── CMakeLists.txt │ ├── zynq7 │ │ ├── CMakeLists.txt │ │ ├── platform_info.c │ │ ├── platform_info.h │ │ ├── platform_info_remoteproc_master.c │ │ ├── rsc_table.c │ │ ├── rsc_table.h │ │ └── zynq_a9_rproc.c │ ├── zynqmp │ │ ├── CMakeLists.txt │ │ ├── openamp-linux-userspace.dtsi │ │ ├── platform_info.c │ │ ├── platform_info.h │ │ └── zynqmp_linux_r5_proc.c │ └── zynqmp_r5 │ │ ├── CMakeLists.txt │ │ ├── platform_info.c │ │ ├── platform_info.h │ │ ├── rsc_table.c │ │ ├── rsc_table.h │ │ └── zynqmp_r5_a53_rproc.c ├── system │ ├── CMakeLists.txt │ ├── generic │ │ ├── CMakeLists.txt │ │ └── machine │ │ │ ├── CMakeLists.txt │ │ │ ├── rv64_virt │ │ │ ├── CMakeLists.txt │ │ │ ├── helper.c │ │ │ ├── helper.o │ │ │ ├── platform_info.c │ │ │ ├── platform_info.h │ │ │ ├── platform_info.o │ │ │ ├── rsc_table.c │ │ │ ├── rsc_table.h │ │ │ ├── rsc_table.o │ │ │ ├── virt_rv64_rproc.c │ │ │ └── virt_rv64_rproc.o │ │ │ ├── zynq7 │ │ │ ├── CMakeLists.txt │ │ │ ├── Xilinx.spec │ │ │ ├── helper.c │ │ │ ├── linker_master.ld │ │ │ └── linker_remote.ld │ │ │ └── zynqmp_r5 │ │ │ ├── CMakeLists.txt │ │ │ ├── helper.c │ │ │ ├── linker_large_text.ld │ │ │ └── linker_remote.ld │ └── linux │ │ ├── CMakeLists.txt │ │ └── machine │ │ ├── CMakeLists.txt │ │ ├── generic │ │ ├── CMakeLists.txt │ │ ├── helper.c │ │ ├── platform_info.c │ │ ├── platform_info.c.orig │ │ ├── platform_info.h │ │ ├── rsc_table.c │ │ └── rsc_table.h │ │ ├── rv64_virt │ │ ├── CMakeLists.txt │ │ ├── helper.c │ │ ├── platform_info.c │ │ ├── platform_info.h │ │ ├── rsc_table.c │ │ ├── rsc_table.h │ │ └── rv64_virt_linux_proc.c │ │ └── zynqmp │ │ ├── CMakeLists.txt │ │ └── helper.c └── tests │ ├── CMakeLists.txt │ └── msg │ ├── CMakeLists.txt │ ├── rpmsg-flood-ping.c │ ├── rpmsg-ping.c │ ├── rpmsg-ping.h │ ├── rpmsg-update.c │ ├── rpmsg-update.c.orig │ ├── rpmsg-update.c.rej │ └── rpmsg-update.o ├── cmake ├── collect.cmake ├── depends.cmake ├── modules │ └── FindLibmetal.cmake ├── options.cmake ├── platforms │ ├── cross_generic_gcc.cmake │ ├── cross_linux_gcc.cmake │ ├── zynq7_generic.cmake │ ├── zynq7_linux.cmake │ ├── zynqmp_a53_generic.cmake │ ├── zynqmp_linux.cmake │ └── zynqmp_r5_generic.cmake └── syscheck.cmake ├── docs ├── apps │ ├── echo_test │ │ └── README.md │ ├── matrix_multiply │ │ └── README.md │ └── rpc_demo │ │ └── README.md ├── data-structure.md ├── img-src │ ├── coprocessor-rpmsg-ns-dynamic.gv │ ├── coprocessor-rpmsg-ns.gv │ ├── coprocessor-rpmsg-static-ep.gv │ ├── gen-graph.py │ └── rproc-lcm-state-machine.gv ├── img │ ├── coprocessor-rpmsg-ns-dynamic.png │ ├── coprocessor-rpmsg-ns.png │ ├── coprocessor-rpmsg-static-ep.png │ ├── menuconfig_openamp.png │ ├── rproc-lcm-state-machine.png │ ├── select_openamp.png │ └── smpvsamp.png ├── remoteproc-design.md └── rpmsg-design.md ├── lib ├── CMakeLists.txt ├── include │ └── openamp │ │ ├── elf_loader.h │ │ ├── open_amp.h │ │ ├── remoteproc.h │ │ ├── remoteproc_loader.h │ │ ├── remoteproc_virtio.h │ │ ├── rpmsg.h │ │ ├── rpmsg_retarget.h │ │ ├── rpmsg_virtio.h │ │ ├── rsc_table_parser.h │ │ ├── virtio.h │ │ ├── virtio_ring.h │ │ └── virtqueue.h ├── proxy │ ├── CMakeLists.txt │ ├── rpmsg_retarget.c │ └── rpmsg_retarget.o ├── remoteproc │ ├── CMakeLists.txt │ ├── elf_loader.c │ ├── elf_loader.o │ ├── remoteproc.c │ ├── remoteproc.o │ ├── remoteproc_virtio.c │ ├── remoteproc_virtio.o │ ├── rsc_table_parser.c │ └── rsc_table_parser.o ├── rpmsg │ ├── CMakeLists.txt │ ├── rpmsg.c │ ├── rpmsg.o │ ├── rpmsg_internal.h │ ├── rpmsg_virtio.c │ └── rpmsg_virtio.o └── virtio │ ├── CMakeLists.txt │ ├── virtio.c │ ├── virtio.o │ ├── virtqueue.c │ └── virtqueue.o └── scripts ├── checkpatch.pl ├── do_checkpatch.sh ├── gitlint └── commit_rules.py └── spelling.txt /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 2.6) 2 | if (POLICY CMP0048) 3 | cmake_policy(SET CMP0048 NEW) 4 | endif() 5 | 6 | if (POLICY CMP0077) 7 | cmake_policy(SET CMP0077 NEW) 8 | endif() 9 | 10 | # The version number 11 | set (OPENAMP_VERSION_MAJOR 1) 12 | set (OPENAMP_VERSION_MINOR 0) 13 | 14 | list (APPEND CMAKE_MODULE_PATH 15 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake" 16 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" 17 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/platforms") 18 | 19 | include (syscheck) 20 | project (open_amp C) 21 | 22 | include (CheckIncludeFiles) 23 | include (CheckCSourceCompiles) 24 | include (collect) 25 | include (options) 26 | include (depends) 27 | enable_testing () 28 | 29 | set (OPENAMP_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}") 30 | set (OPENAMP_BIN_ROOT "${CMAKE_CURRENT_BINARY_DIR}") 31 | 32 | if (WITH_OBSOLETE) 33 | add_subdirectory (obsolete) 34 | endif (WITH_OBSOLETE) 35 | 36 | add_subdirectory (lib) 37 | 38 | if (WITH_APPS) 39 | add_subdirectory (apps) 40 | endif (WITH_APPS) 41 | 42 | # vim: expandtab:ts=2:sw=2:smartindent 43 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Software License Agreement (BSD 3-Clause License) 2 | ======================================== 3 | 4 | Copyright (c) 2014, Mentor Graphics Corporation. All rights reserved. 5 | Copyright (c) 2015 - 2016 Xilinx, Inc. All rights reserved. 6 | Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright notice, 12 | this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright notice, 15 | this list of conditions and the following disclaimer in the documentation 16 | and/or other materials provided with the distribution. 17 | 18 | 3. Neither the name of nor the names of its contributors 19 | may be used to endorse or promote products derived from this software 20 | without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | POSSIBILITY OF SUCH DAMAGE. 33 | 34 | BSD 2-Clause License 35 | ------------------------- 36 | 37 | Copyright (c) . All rights reserved. 38 | 39 | Redistribution and use in source and binary forms, with or without 40 | modification, are permitted provided that the following conditions are met: 41 | 42 | 1. Redistributions of source code must retain the above copyright notice, this 43 | list of conditions and the following disclaimer. 44 | 45 | 2. Redistributions in binary form must reproduce the above copyright notice, 46 | this list of conditions and the following disclaimer in the documentation 47 | and/or other materials provided with the distribution. 48 | 49 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 50 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 51 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 52 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 53 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 54 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 55 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 56 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 57 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 58 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 59 | 60 | Notes 61 | ========================================= 62 | Use the following tag instead of the full license text in the individual files: 63 | 64 | SPDX-License-Identifier: BSD-3-Clause 65 | SPDX-License-Identifier: BSD-2-Clause 66 | 67 | This enables machine processing of license information based on the SPDX 68 | License Identifiers that are here available: http://spdx.org/licenses/ 69 | 70 | -------------------------------------------------------------------------------- /MAINTAINERS.md: -------------------------------------------------------------------------------- 1 | # OpenAMP Maintainers 2 | 3 | OpenAMP project is maintained by the OpenAMP open source community. Everyone 4 | is encouraged to submit issues and changes to improve OpenAMP. 5 | 6 | The intention of this file is to provide a set of names that developers can 7 | consult when they have a question about OpenAMP and to provide a a set of 8 | names to be CC'd when submitting a patch. 9 | 10 | 11 | ## Project Administration 12 | Ed Mooring 13 | Arnaud Pouliquen 14 | 15 | ### All patches CC here 16 | openamp-rp@lists.openampproject.org 17 | 18 | ## Machines 19 | ### Xilinx Platform - Zynq-7000 20 | Ed Mooring 21 | 22 | ### Xilinx Platform - Zynq UltraScale+ MPSoC 23 | Ed Mooring 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # rt-thread OpenAMP软件包使用指南 2 | 3 | [toc] 4 | 5 | ## 1.什么是openamp 6 | 7 | openamp(Open Asymmetric Multi-Processing),旨在通过非对称式多处理(AMP)的开源解决方案来标准化异构嵌入式系统中操作环境之间的交互。 8 | 9 | SoC正在变得越来越异构化,一个芯片内可能有多个处理器,而非对称的处理器则需要能够在统一芯片上并排运行不同的操作系统环境,为这些环境之间的配置和交互开发标准需要进行统一。 10 | 11 | ![smpvsamp](docs/img/smpvsamp.png) 12 | 13 | OpenAMP 是一个框架,提供实现AMP系统软件应用程序开发所需的软件组件。它允许操作系统在各种复杂的同构异构架构之间进行交互,并允许非对称多处理应用程序利用多核配置提供的并行性。 14 | 15 | ## 2.RT-Thread上的OpenAMP使用 16 | 17 | 对于RT-Thread上的OpenAMP,首先需要通过menuconfig开启OpenAMP。 18 | 19 | ![menuconfig_openamp](docs/img/menuconfig_openamp.png) 20 | 21 | 接着选择最新版本即可。 22 | 23 | ![select_openamp](docs/img/select_openamp.png) 24 | 25 | 选择后在bsp目录下输入: 26 | 27 | ``` 28 | pkgs --update 29 | ``` 30 | 31 | 注意:在linux的环境下,需要输入`source ~/.env/env.sh`。 32 | 33 | 看到下面的命令表示成功。 34 | 35 | ## 3.当前软件包功能 36 | 37 | 当前已经在riscv64的qemu上运行测试。 38 | 39 | 当前已经实现的测试功能列表如下表格: 40 | 41 | | 功能 | 测试情况 | 42 | | --------------- | -------- | 43 | | shmem_demod | pass | 44 | | rpmsg-ping | pass | 45 | | flood-ping | pass | 46 | | echo | pass | 47 | | matrix_multiply | pass | 48 | 49 | ## 4.联系方式 & 感谢 50 | 51 | - 维护:bigmagic123 52 | - 主页:https://github.com/bigmagic123/openamp 53 | 54 | 55 | -------------------------------------------------------------------------------- /SConscript: -------------------------------------------------------------------------------- 1 | # RT-Thread building script for bridge 2 | 3 | import os 4 | from building import * 5 | 6 | cwd = GetCurrentDir() 7 | objs = [] 8 | list = os.listdir(cwd) 9 | include_path = [cwd + '/apps/system/generic/machine/rv64_virt'] 10 | include_path += [cwd + '/lib/rpmsg'] 11 | include_path += [cwd + '/lib/include/openamp'] 12 | include_path += [cwd + '/lib/include'] 13 | 14 | 15 | src = [cwd + '/apps/examples/rpmsg_sample_echo/rpmsg-sample-echo.c'] 16 | src += [cwd + '/apps/tests/msg/rpmsg-update.c'] 17 | src += [cwd + '/apps/examples/matrix_multiply/matrix_multiplyd.c'] 18 | src += [cwd + '/apps/system/generic/machine/rv64_virt/virt_rv64_rproc.c'] 19 | src += [cwd + '/apps/system/generic/machine/rv64_virt/helper.c'] 20 | src += [cwd + '/apps/system/generic/machine/rv64_virt/platform_info.c'] 21 | src += [cwd + '/apps/system/generic/machine/rv64_virt/rsc_table.c'] 22 | src += [cwd + '/lib/rpmsg/rpmsg.c'] 23 | src += [cwd + '/lib/rpmsg/rpmsg_virtio.c'] 24 | src += [cwd + '/lib/proxy/rpmsg_retarget.c'] 25 | src += [cwd + '/lib/remoteproc/rsc_table_parser.c'] 26 | src += [cwd + '/lib/remoteproc/remoteproc_virtio.c'] 27 | src += [cwd + '/lib/remoteproc/elf_loader.c'] 28 | src += [cwd + '/lib/remoteproc/remoteproc.c'] 29 | src += [cwd + '/lib/virtio/virtqueue.c'] 30 | src += [cwd + '/lib/virtio/virtio.c'] 31 | 32 | CPPDEFINES = [] 33 | CPPDEFINES += ['DEFAULT_LOGGER_ON'] 34 | CPPDEFINES += ['RPMSG_NO_IPI'] 35 | 36 | objs = DefineGroup('openamp', src, depend = ['PKG_USING_OPENAMP'], CPPPATH = include_path, CPPDEFINES = CPPDEFINES) 37 | 38 | Return('objs') 39 | -------------------------------------------------------------------------------- /apps/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | collector_create (APP_COMMON_SOURCES "") 2 | collector_create (APP_LIB_DIRS "") 3 | collector_create (APP_INC_DIRS "") 4 | collector_create (APP_LIB_DEPS "") 5 | 6 | collector_create (APP_EXTRA_C_FLAGS "") 7 | set (APPS_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}") 8 | 9 | set (APPS_SHARE_DIR "${CMAKE_CURRENT_BINARY_DIR}/share") 10 | 11 | add_subdirectory (machine) 12 | add_subdirectory (system) 13 | add_subdirectory (tests) 14 | add_subdirectory (examples) 15 | -------------------------------------------------------------------------------- /apps/examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | option (WITH_LOAD_FW "Include loading firmware example" OFF) 3 | 4 | add_subdirectory (echo) 5 | add_subdirectory (rpmsg_sample_echo) 6 | add_subdirectory (matrix_multiply) 7 | add_subdirectory (load_fw) 8 | if (WITH_PROXY_APPS) 9 | add_subdirectory (rpc_demo) 10 | endif (WITH_PROXY_APPS) 11 | -------------------------------------------------------------------------------- /apps/examples/echo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set (_cflags "${CMAKE_C_FLAGS} ${APP_EXTRA_C_FLAGS} -fdata-sections -ffunction-sections") 3 | set (_fw_dir "${APPS_SHARE_DIR}") 4 | 5 | collector_list (_list PROJECT_INC_DIRS) 6 | collector_list (_app_list APP_INC_DIRS) 7 | include_directories (${_list} ${_app_list} ${CMAKE_CURRENT_SOURCE_DIR}) 8 | 9 | collector_list (_list PROJECT_LIB_DIRS) 10 | collector_list (_app_list APP_LIB_DIRS) 11 | link_directories (${_list} ${_app_list}) 12 | 13 | get_property (_linker_opt GLOBAL PROPERTY APP_LINKER_OPT) 14 | collector_list (_deps PROJECT_LIB_DEPS) 15 | 16 | set (OPENAMP_LIB open_amp) 17 | 18 | foreach (_app rpmsg-echo-ping rpmsg-echo) 19 | collector_list (_sources APP_COMMON_SOURCES) 20 | if (${_app} STREQUAL "rpmsg-echo-ping") 21 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/rpmsg-ping.c") 22 | elseif (${_app} STREQUAL "rpmsg-echo") 23 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/rpmsg-echo.c") 24 | endif (${_app} STREQUAL "rpmsg-echo-ping") 25 | 26 | if (WITH_SHARED_LIB) 27 | add_executable (${_app}-shared ${_sources}) 28 | target_link_libraries (${_app}-shared ${OPENAMP_LIB}-shared ${_deps}) 29 | install (TARGETS ${_app}-shared RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 30 | endif (WITH_SHARED_LIB) 31 | 32 | if (WITH_STATIC_LIB) 33 | if (${PROJECT_SYSTEM} STREQUAL "linux") 34 | add_executable (${_app}-static ${_sources}) 35 | target_link_libraries (${_app}-static ${OPENAMP_LIB}-static ${_deps}) 36 | install (TARGETS ${_app}-static RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 37 | else (${PROJECT_SYSTEM}) 38 | add_executable (${_app}.out ${_sources}) 39 | set_source_files_properties(${_sources} PROPERTIES COMPILE_FLAGS "${_cflags}") 40 | 41 | target_link_libraries(${_app}.out -Wl,-Map=${_app}.map -Wl,--gc-sections ${_linker_opt} -Wl,--start-group ${OPENAMP_LIB}-static ${_deps} -Wl,--end-group) 42 | 43 | install (TARGETS ${_app}.out RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 44 | endif (${PROJECT_SYSTEM} STREQUAL "linux" ) 45 | endif (WITH_STATIC_LIB) 46 | endforeach(_app) 47 | -------------------------------------------------------------------------------- /apps/examples/echo/rpmsg-echo.c: -------------------------------------------------------------------------------- 1 | /* This is a sample demonstration application that showcases usage of rpmsg 2 | This application is meant to run on the remote CPU running baremetal code. 3 | This application echoes back data that was sent to it by the master core. */ 4 | 5 | #include 6 | #include 7 | #include 8 | #include "platform_info.h" 9 | #include "rpmsg-echo.h" 10 | 11 | #define SHUTDOWN_MSG 0xEF56A55A 12 | 13 | #define LPRINTF(format, ...) printf(format, ##__VA_ARGS__) 14 | //#define LPRINTF(format, ...) 15 | #define LPERROR(format, ...) LPRINTF("ERROR: " format, ##__VA_ARGS__) 16 | 17 | static struct rpmsg_endpoint lept; 18 | static int shutdown_req = 0; 19 | 20 | /*-----------------------------------------------------------------------------* 21 | * RPMSG endpoint callbacks 22 | *-----------------------------------------------------------------------------*/ 23 | static int rpmsg_endpoint_cb(struct rpmsg_endpoint *ept, void *data, size_t len, 24 | uint32_t src, void *priv) 25 | { 26 | (void)priv; 27 | (void)src; 28 | 29 | /* On reception of a shutdown we signal the application to terminate */ 30 | if ((*(unsigned int *)data) == SHUTDOWN_MSG) { 31 | LPRINTF("shutdown message is received.\r\n"); 32 | shutdown_req = 1; 33 | return RPMSG_SUCCESS; 34 | } 35 | 36 | /* Send data back to master */ 37 | if (rpmsg_send(ept, data, len) < 0) { 38 | LPERROR("rpmsg_send failed\r\n"); 39 | } 40 | return RPMSG_SUCCESS; 41 | } 42 | 43 | static void rpmsg_service_unbind(struct rpmsg_endpoint *ept) 44 | { 45 | (void)ept; 46 | LPRINTF("unexpected Remote endpoint destroy\r\n"); 47 | shutdown_req = 1; 48 | } 49 | 50 | /*-----------------------------------------------------------------------------* 51 | * Application 52 | *-----------------------------------------------------------------------------*/ 53 | int app(struct rpmsg_device *rdev, void *priv) 54 | { 55 | int ret; 56 | 57 | /* Initialize RPMSG framework */ 58 | LPRINTF("Try to create rpmsg endpoint.\r\n"); 59 | 60 | ret = rpmsg_create_ept(&lept, rdev, RPMSG_SERVICE_NAME, 61 | RPMSG_ADDR_ANY, RPMSG_ADDR_ANY, 62 | rpmsg_endpoint_cb, 63 | rpmsg_service_unbind); 64 | if (ret) { 65 | LPERROR("Failed to create endpoint.\r\n"); 66 | return -1; 67 | } 68 | 69 | LPRINTF("Successfully created rpmsg endpoint.\r\n"); 70 | while(1) { 71 | platform_poll(priv); 72 | /* we got a shutdown request, exit */ 73 | if (shutdown_req) { 74 | break; 75 | } 76 | } 77 | rpmsg_destroy_ept(&lept); 78 | 79 | return 0; 80 | } 81 | 82 | /*-----------------------------------------------------------------------------* 83 | * Application entry point 84 | *-----------------------------------------------------------------------------*/ 85 | int main(int argc, char *argv[]) 86 | { 87 | void *platform; 88 | struct rpmsg_device *rpdev; 89 | int ret; 90 | 91 | LPRINTF("Starting application...\r\n"); 92 | 93 | /* Initialize platform */ 94 | ret = platform_init(argc, argv, &platform); 95 | if (ret) { 96 | LPERROR("Failed to initialize platform.\r\n"); 97 | ret = -1; 98 | } else { 99 | rpdev = platform_create_rpmsg_vdev(platform, 0, 100 | VIRTIO_DEV_SLAVE, 101 | NULL, NULL); 102 | if (!rpdev) { 103 | LPERROR("Failed to create rpmsg virtio device.\r\n"); 104 | ret = -1; 105 | } else { 106 | app(rpdev, platform); 107 | platform_release_rpmsg_vdev(rpdev); 108 | ret = 0; 109 | } 110 | } 111 | 112 | LPRINTF("Stopping application...\r\n"); 113 | platform_cleanup(platform); 114 | 115 | return ret; 116 | } 117 | -------------------------------------------------------------------------------- /apps/examples/echo/rpmsg-echo.h: -------------------------------------------------------------------------------- 1 | #ifndef RPMSG_ECHO_H 2 | #define RPMSG_ECHO_H 3 | 4 | #define RPMSG_SERVICE_NAME "rpmsg-openamp-demo-channel" 5 | 6 | #endif /* RPMSG_ECHO_H */ 7 | -------------------------------------------------------------------------------- /apps/examples/load_fw/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | collector_list (_app_extra_c_flags APP_EXTRA_C_FLAGS) 2 | set (_cflags "${CMAKE_C_FLAGS} ${_app_extra_c_flags}") 3 | set (_fw_dir "${APPS_SHARE_DIR}") 4 | 5 | collector_list (_list PROJECT_INC_DIRS) 6 | collector_list (_app_list APP_INC_DIRS) 7 | include_directories (${_list} ${_app_list} ${CMAKE_CURRENT_SOURCE_DIR}) 8 | 9 | collector_list (_list PROJECT_LIB_DIRS) 10 | collector_list (_app_list APP_LIB_DIRS) 11 | link_directories (${_list} ${_app_list}) 12 | 13 | get_property (_linker_opt GLOBAL PROPERTY APP_LINKER_OPT) 14 | if (WITH_ZYNQMP) 15 | collect (PROJECT_LIB_DEPS xilpm) 16 | endif (WITH_ZYNQMP) 17 | collector_list (_deps PROJECT_LIB_DEPS) 18 | 19 | set (OPENAMP_LIB open_amp) 20 | 21 | if (WITH_WFI) 22 | add_definitions(-DWITH_WFI) 23 | endif (WITH_WFI) 24 | 25 | foreach (_app load_fw) 26 | collector_list (_sources APP_COMMON_SOURCES) 27 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/mem_image_store.c") 28 | if (WITH_ZYNQMP) 29 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/zynqmp_apu_lcm_rproc_example.c") 30 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/zynqmp_rpu_lcm_rproc_example.c") 31 | add_definitions(-DWITH_ZYNQMP) 32 | endif (WITH_ZYNQMP) 33 | if (WITH_RV64) 34 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/virt_rv64_rproc_example.c") 35 | add_definitions(-DWITH_RV64) 36 | endif (WITH_RV64) 37 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/platform_info.c") 38 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/${_app}.c") 39 | 40 | if (WITH_SHARED_LIB) 41 | add_executable (${_app}-shared ${_sources}) 42 | target_link_libraries (${_app}-shared ${OPENAMP_LIB}-shared ${_deps}) 43 | install (TARGETS ${_app}-shared RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 44 | endif (WITH_SHARED_LIB) 45 | if (WITH_STATIC_LIB) 46 | add_executable (${_app}.out ${_sources}) 47 | set_source_files_properties(${_sources} PROPERTIES COMPILE_FLAGS "${_cflags}") 48 | target_link_libraries(${_app}.out -Wl,-Map=${_app}.map -Wl,--gc-sections -T"${CMAKE_CURRENT_SOURCE_DIR}/lscript.ld" -Wl,--start-group ${OPENAMP_LIB}-static ${_deps} -Wl,--end-group) 49 | install (TARGETS ${_app}.out RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 50 | endif (WITH_STATIC_LIB) 51 | 52 | endforeach(_app) 53 | -------------------------------------------------------------------------------- /apps/examples/load_fw/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright(c) 2019 Xilinx Ltd. 3 | * All rights reserved. 4 | * 5 | * SPDX-License-Identifier: BSD-3-Clause 6 | */ 7 | 8 | #ifndef COMMON_H_ 9 | #define COMMON_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #ifdef WITH_ZYNQMP 20 | /* Xilinx headers */ 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #ifdef versal 27 | #include 28 | #include 29 | 30 | #ifndef NODE_APU_0 31 | #define NODE_APU_0 PM_DEV_ACPU_0 32 | #endif 33 | #ifndef NODE_APU_1 34 | #define NODE_APU_1 PM_DEV_ACPU_1 35 | #endif 36 | #ifndef NODE_RPU_0 37 | #define NODE_RPU_0 PM_DEV_RPU0_0 38 | #endif 39 | #ifndef NODE_RPU 40 | #define NODE_RPU PM_DEV_RPU0_0 41 | #endif 42 | 43 | #ifndef NODE_RPU_1 44 | #define NODE_RPU_1 PM_DEV_RPU0_1 45 | #endif 46 | 47 | #ifndef NODE_TCM_0_A 48 | #define NODE_TCM_0_A PM_DEV_TCM_0_A 49 | #endif 50 | #ifndef NODE_TCM_0_B 51 | #define NODE_TCM_0_B PM_DEV_TCM_0_B 52 | #endif 53 | #ifndef NODE_TCM_1_A 54 | #define NODE_TCM_1_A PM_DEV_TCM_1_A 55 | #endif 56 | #ifndef NODE_TCM_1_B 57 | #define NODE_TCM_1_B PM_DEV_TCM_1_B 58 | #endif 59 | 60 | #ifndef NODE_DDR 61 | #define NODE_DDR PM_DEV_DDR_0 62 | #endif 63 | 64 | #ifndef NODE_OCM_BANK_0 65 | #define NODE_OCM_BANK_0 PM_DEV_OCM_0 66 | #endif 67 | #ifndef NODE_OCM_BANK_1 68 | #define NODE_OCM_BANK_1 PM_DEV_OCM_1 69 | #endif 70 | #ifndef NODE_OCM_BANK_2 71 | #define NODE_OCM_BANK_2 PM_DEV_OCM_2 72 | #endif 73 | #ifndef NODE_OCM_BANK_3 74 | #define NODE_OCM_BANK_3 PM_DEV_OCM_3 75 | #endif 76 | 77 | /* Requirement limits */ 78 | #define XPM_MAX_CAPABILITY (PM_CAP_ACCESS | PM_CAP_CONTEXT | PM_CAP_WAKEUP) 79 | #define XPM_MAX_LATENCY (0xFFFFU) 80 | #define XPM_MAX_QOS (100) 81 | #define XPM_MIN_CAPABILITY (0) 82 | #define XPM_MIN_LATENCY (0) 83 | #define XPM_MIN_QOS (0) 84 | #define XPM_DEF_CAPABILITY XPM_MAX_CAPABILITY 85 | #define XPM_DEF_LATENCY XPM_MAX_LATENCY 86 | #define XPM_DEF_QOS XPM_MAX_QOS 87 | 88 | enum XPmRequestAck { 89 | REQUEST_ACK_NO = 1, 90 | REQUEST_ACK_BLOCKING, 91 | REQUEST_ACK_NON_BLOCKING, 92 | REQUEST_ACK_CB_CERROR, 93 | }; 94 | 95 | #elif zynqmp 96 | #include 97 | #define XPM_MAX_QOS MAX_QOS 98 | #define XPM_MIN_QOS (0) 99 | #endif /* versal */ 100 | 101 | #define LPRINTF(format, ...) xil_printf(format, ##__VA_ARGS__) 102 | //#define LPRINTF(format, ...) 103 | 104 | #endif /* #ifdef WITH_ZYNQMP */ 105 | 106 | #ifdef WITH_RV64 107 | 108 | #define RV_NODE_APU_0 (0) 109 | #define RV_NODE_APU_N (1) 110 | 111 | #define LPRINTF(format, ...) printf(format, ##__VA_ARGS__) 112 | //#define LPRINTF(format, ...) 113 | 114 | #endif /* #ifdef WITH_RV64 */ 115 | 116 | struct rproc_priv { 117 | struct remoteproc *rproc; 118 | int cpu_id; 119 | }; 120 | #define LPERROR(format, ...) LPRINTF("ERROR: " format, ##__VA_ARGS__) 121 | 122 | #endif /* COMMON_H_ */ 123 | -------------------------------------------------------------------------------- /apps/examples/load_fw/common.h.orig: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright(c) 2019 Xilinx Ltd. 3 | * All rights reserved. 4 | * 5 | * SPDX-License-Identifier: BSD-3-Clause 6 | */ 7 | 8 | #ifndef COMMON_H_ 9 | #define COMMON_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | /* Xilinx headers */ 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #ifdef versal 26 | #include 27 | #include 28 | 29 | #ifndef NODE_APU_0 30 | #define NODE_APU_0 PM_DEV_ACPU_0 31 | #endif 32 | #ifndef NODE_APU_1 33 | #define NODE_APU_1 PM_DEV_ACPU_1 34 | #endif 35 | #ifndef NODE_RPU_0 36 | #define NODE_RPU_0 PM_DEV_RPU0_0 37 | #endif 38 | #ifndef NODE_RPU 39 | #define NODE_RPU PM_DEV_RPU0_0 40 | #endif 41 | 42 | #ifndef NODE_RPU_1 43 | #define NODE_RPU_1 PM_DEV_RPU0_1 44 | #endif 45 | 46 | #ifndef NODE_TCM_0_A 47 | #define NODE_TCM_0_A PM_DEV_TCM_0_A 48 | #endif 49 | #ifndef NODE_TCM_0_B 50 | #define NODE_TCM_0_B PM_DEV_TCM_0_B 51 | #endif 52 | #ifndef NODE_TCM_1_A 53 | #define NODE_TCM_1_A PM_DEV_TCM_1_A 54 | #endif 55 | #ifndef NODE_TCM_1_B 56 | #define NODE_TCM_1_B PM_DEV_TCM_1_B 57 | #endif 58 | 59 | #ifndef NODE_DDR 60 | #define NODE_DDR PM_DEV_DDR_0 61 | #endif 62 | 63 | #ifndef NODE_OCM_BANK_0 64 | #define NODE_OCM_BANK_0 PM_DEV_OCM_0 65 | #endif 66 | #ifndef NODE_OCM_BANK_1 67 | #define NODE_OCM_BANK_1 PM_DEV_OCM_1 68 | #endif 69 | #ifndef NODE_OCM_BANK_2 70 | #define NODE_OCM_BANK_2 PM_DEV_OCM_2 71 | #endif 72 | #ifndef NODE_OCM_BANK_3 73 | #define NODE_OCM_BANK_3 PM_DEV_OCM_3 74 | #endif 75 | 76 | /* Requirement limits */ 77 | #define XPM_MAX_CAPABILITY (PM_CAP_ACCESS | PM_CAP_CONTEXT | PM_CAP_WAKEUP) 78 | #define XPM_MAX_LATENCY (0xFFFFU) 79 | #define XPM_MAX_QOS (100) 80 | #define XPM_MIN_CAPABILITY (0) 81 | #define XPM_MIN_LATENCY (0) 82 | #define XPM_MIN_QOS (0) 83 | #define XPM_DEF_CAPABILITY XPM_MAX_CAPABILITY 84 | #define XPM_DEF_LATENCY XPM_MAX_LATENCY 85 | #define XPM_DEF_QOS XPM_MAX_QOS 86 | 87 | enum XPmRequestAck { 88 | REQUEST_ACK_NO = 1, 89 | REQUEST_ACK_BLOCKING, 90 | REQUEST_ACK_NON_BLOCKING, 91 | REQUEST_ACK_CB_CERROR, 92 | }; 93 | 94 | #else /* zynqmp */ 95 | #include 96 | #define XPM_MAX_QOS MAX_QOS 97 | #define XPM_MIN_QOS (0) 98 | #endif /* versal */ 99 | 100 | #define LPRINTF(format, ...) xil_printf(format, ##__VA_ARGS__) 101 | //#define LPRINTF(format, ...) 102 | #define LPERROR(format, ...) LPRINTF("ERROR: " format, ##__VA_ARGS__) 103 | 104 | struct rproc_priv { 105 | struct remoteproc *rproc; 106 | int cpu_id; 107 | }; 108 | 109 | #endif /* COMMON_H_ */ 110 | -------------------------------------------------------------------------------- /apps/examples/load_fw/mem_image_store.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Memory based image store Operation 3 | * 4 | * Copyright(c) 2018 Xilinx Ltd. 5 | * All rights reserved. 6 | * 7 | * SPDX-License-Identifier: BSD-3-Clause 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | struct mem_file { 22 | const void *base; 23 | }; 24 | 25 | int mem_image_open(void *store, const char *path, const void **image_data) 26 | { 27 | struct mem_file *image = store; 28 | int fd = -1; 29 | struct stat file_stat; 30 | char *buf = NULL; 31 | int ret = -1; 32 | 33 | fd = open(path, O_RDONLY); 34 | if (fd < 0) 35 | return -1; 36 | 37 | memset(&file_stat, 0, sizeof(file_stat)); 38 | if (fstat(fd, &file_stat)) 39 | return -1; 40 | 41 | LPRINTF("file size %d\n", file_stat.st_size); 42 | buf = malloc(file_stat.st_size); 43 | if (!buf) 44 | return -1; 45 | 46 | ret = read(fd, buf, file_stat.st_size); 47 | if (ret > 0) { 48 | LPRINTF("%d read\n", ret); 49 | } else if (ret < 0) { 50 | LPRINTF("%s\n", strerror(errno)); 51 | return ret; 52 | } 53 | *image_data = buf; 54 | image->base = buf; 55 | return file_stat.st_size; 56 | } 57 | 58 | void mem_image_close(void *store) 59 | { 60 | //TODO 61 | /* The image is in memory, does nothing */ 62 | (void)store; 63 | } 64 | 65 | int mem_image_load(void *store, size_t offset, size_t size, 66 | const void **data, metal_phys_addr_t pa, 67 | struct metal_io_region *io, 68 | char is_blocking) 69 | { 70 | struct mem_file *image = store; 71 | const void *fw_base = image->base; 72 | 73 | (void)is_blocking; 74 | 75 | LPRINTF("%s: offset=0x%x, size=0x%x\n\r", 76 | __func__, offset, size); 77 | if (pa == METAL_BAD_PHYS) { 78 | if (data == NULL) { 79 | LPERROR("%s: data is NULL while pa is ANY\r\n", 80 | __func__); 81 | return -EINVAL; 82 | } 83 | *data = (const void *)((const char *)fw_base + offset); 84 | } else { 85 | void *va; 86 | 87 | if (io == NULL) { 88 | LPERROR("%s, io is NULL while pa is not ANY\r\n", 89 | __func__); 90 | return -EINVAL; 91 | } 92 | va = metal_io_phys_to_virt(io, pa); 93 | if (va == NULL) { 94 | LPERROR("%s: no va is found\r\n", __func__); 95 | return -EINVAL; 96 | } 97 | LPRINTF("Copy to %p (pa: %lx) with size 0x%lx\n", va, pa, size); 98 | memcpy(va, (const void *)((const char *)fw_base + offset), size); 99 | } 100 | 101 | return (int)size; 102 | } 103 | 104 | struct image_store_ops mem_image_store_ops = { 105 | .open = mem_image_open, 106 | .close = mem_image_close, 107 | .load = mem_image_load, 108 | .features = SUPPORT_SEEK, 109 | }; 110 | 111 | -------------------------------------------------------------------------------- /apps/examples/load_fw/mem_image_store.c.orig: -------------------------------------------------------------------------------- 1 | /* 2 | * Memory based image store Operation 3 | * 4 | * Copyright(c) 2018 Xilinx Ltd. 5 | * All rights reserved. 6 | * 7 | * SPDX-License-Identifier: BSD-3-Clause 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | struct mem_file { 22 | const void *base; 23 | }; 24 | 25 | int mem_image_open(void *store, const char *path, const void **image_data) 26 | { 27 | int fd = -1; 28 | struct stat file_stat; 29 | char *buf = NULL; 30 | int ret = -1; 31 | 32 | fd = open(path, O_RDONLY); 33 | if (fd < 0) 34 | return -1; 35 | 36 | memset(&file_stat, 0, sizeof(file_stat)); 37 | if (fstat(fd, &file_stat)) 38 | return -1; 39 | 40 | LPRINTF("file size %d\n", file_stat.st_size); 41 | buf = malloc(file_stat.st_size); 42 | if (!buf) 43 | return -1; 44 | 45 | ret = read(fd, buf, file_stat.st_size); 46 | if (ret > 0) { 47 | LPRINTF("%d read\n", ret); 48 | } else if (ret < 0) { 49 | LPRINTF("%s\n", strerror(errno)); 50 | return ret; 51 | } 52 | *image_data = buf; 53 | return file_stat.st_size; 54 | } 55 | 56 | void mem_image_close(void *store) 57 | { 58 | //TODO 59 | /* The image is in memory, does nothing */ 60 | (void)store; 61 | } 62 | 63 | int mem_image_load(void *store, size_t offset, size_t size, 64 | const void **data, metal_phys_addr_t pa, 65 | struct metal_io_region *io, 66 | char is_blocking) 67 | { 68 | struct mem_file *image = store; 69 | const void *fw_base = image->base; 70 | 71 | (void)is_blocking; 72 | 73 | LPRINTF("%s: offset=0x%x, size=0x%x\n\r", 74 | __func__, offset, size); 75 | if (pa == METAL_BAD_PHYS) { 76 | if (data == NULL) { 77 | LPERROR("%s: data is NULL while pa is ANY\r\n", 78 | __func__); 79 | return -EINVAL; 80 | } 81 | *data = (const void *)((const char *)fw_base + offset); 82 | } else { 83 | void *va; 84 | 85 | if (io == NULL) { 86 | LPERROR("%s, io is NULL while pa is not ANY\r\n", 87 | __func__); 88 | return -EINVAL; 89 | } 90 | va = metal_io_phys_to_virt(io, pa); 91 | if (va == NULL) { 92 | LPERROR("%s: no va is found\r\n", __func__); 93 | return -EINVAL; 94 | } 95 | memcpy(va, (const void *)((const char *)fw_base + offset), size); 96 | } 97 | 98 | return (int)size; 99 | } 100 | 101 | struct image_store_ops mem_image_store_ops = { 102 | .open = mem_image_open, 103 | .close = mem_image_close, 104 | .load = mem_image_load, 105 | .features = SUPPORT_SEEK, 106 | }; 107 | 108 | -------------------------------------------------------------------------------- /apps/examples/load_fw/platform_info.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright(c) 2019 Xilinx Ltd. 3 | * All rights reserved. 4 | * 5 | * SPDX-License-Identifier: BSD-3-Clause 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | #ifdef WITH_ZYNQMP 12 | extern struct remoteproc_ops zynqmp_apu_rproc_ops; 13 | extern struct remoteproc_ops zynqmp_rpu_rproc_ops; 14 | #endif /* #ifdef WITH_ZYNQMP */ 15 | #ifdef WITH_RV64 16 | extern struct remoteproc_ops virt_rv64_rproc_ops; 17 | #endif /* #ifdef WITH_RV64 */ 18 | 19 | static struct remoteproc rproc_inst; 20 | static struct remoteproc_ops ops; 21 | 22 | static struct remoteproc * platform_create_proc(unsigned int cpu_id) 23 | { 24 | struct remoteproc * rproc; 25 | 26 | #ifdef WITH_RV64 27 | ops = virt_rv64_rproc_ops; 28 | #elif defined(WITH_ZYNQMP) 29 | if (NODE_RPU_0 <= LOAD_FW_TARGET && LOAD_FW_TARGET <= NODE_RPU_1) 30 | ops = zynqmp_rpu_rproc_ops; 31 | else if (NODE_APU_0 <= LOAD_FW_TARGET && LOAD_FW_TARGET <= NODE_APU_1) 32 | ops = zynqmp_apu_rproc_ops; 33 | #else 34 | return NULL; 35 | #endif /* #ifdef WITH_ZYNQMP */ 36 | 37 | rproc = remoteproc_init(&rproc_inst, &ops, &cpu_id); 38 | if (!rproc) 39 | return NULL; 40 | return &rproc_inst; 41 | } 42 | 43 | static void app_log_handler(enum metal_log_level level, 44 | const char *format, ...) 45 | { 46 | char msg[1024]; 47 | va_list args; 48 | static const char *level_strs[] = { 49 | "metal: emergency: ", 50 | "metal: alert: ", 51 | "metal: critical: ", 52 | "metal: error: ", 53 | "metal: warning: ", 54 | "metal: notice: ", 55 | "metal: info: ", 56 | "metal: debug: ", 57 | }; 58 | 59 | va_start(args, format); 60 | vsnprintf(msg, sizeof(msg), format, args); 61 | va_end(args); 62 | 63 | if (level <= METAL_LOG_EMERGENCY || level > METAL_LOG_DEBUG) 64 | level = METAL_LOG_EMERGENCY; 65 | 66 | LPRINTF("%s%s", level_strs[level], msg); 67 | } 68 | 69 | #ifdef WITH_ZYNQMP 70 | static XIpiPsu IpiInst; 71 | 72 | static XStatus IpiConfigure(XIpiPsu *const IpiInstPtr) 73 | { 74 | XStatus Status; 75 | XIpiPsu_Config *IpiCfgPtr; 76 | 77 | /* Look Up the config data */ 78 | IpiCfgPtr = XIpiPsu_LookupConfig(XPAR_XIPIPSU_0_DEVICE_ID); 79 | if (NULL == IpiCfgPtr) { 80 | Status = XST_FAILURE; 81 | LPERROR("%s ERROR in getting CfgPtr\n", __func__); 82 | return Status; 83 | } 84 | 85 | /* Init with the Cfg Data */ 86 | Status = XIpiPsu_CfgInitialize(IpiInstPtr, IpiCfgPtr, 87 | IpiCfgPtr->BaseAddress); 88 | if (XST_SUCCESS != Status) { 89 | LPERROR("%s ERROR #%d in configuring IPI\n", __func__, Status); 90 | return Status; 91 | } 92 | return Status; 93 | } 94 | #endif /* #ifdef WITH_ZYNQMP */ 95 | 96 | struct remoteproc * app_init(unsigned int cpu_id){ 97 | struct metal_init_params metal_param = { 98 | .log_handler = app_log_handler, 99 | .log_level = METAL_LOG_DEBUG, 100 | }; 101 | metal_init(&metal_param); 102 | 103 | #ifdef WITH_ZYNQMP 104 | if (XST_SUCCESS != IpiConfigure(&IpiInst)) { 105 | LPERROR("Failed to config IPI instance\r\n"); 106 | return NULL; 107 | } 108 | 109 | if (XST_SUCCESS != XPm_InitXilpm(&IpiInst)) { 110 | LPERROR("Failed to initialize PM\r\n"); 111 | return NULL; 112 | } 113 | #endif /* #ifdef WITH_ZYNQMP */ 114 | 115 | return platform_create_proc(cpu_id); 116 | } 117 | -------------------------------------------------------------------------------- /apps/examples/load_fw/platform_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright(c) 2019 Xilinx Ltd. 3 | * All rights reserved. 4 | * 5 | * SPDX-License-Identifier: BSD-3-Clause 6 | */ 7 | #ifndef PLATFORM_INFO_H_ 8 | #define PLATFORM_INFO_H_ 9 | 10 | struct remoteproc * app_init(unsigned int cpu_id); 11 | #endif /* PLATFORM_INFO_H_ */ 12 | -------------------------------------------------------------------------------- /apps/examples/matrix_multiply/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (_cflags "${CMAKE_C_FLAGS} ${APP_EXTRA_C_FLAGS} -fdata-sections -ffunction-sections") 2 | set (_fw_dir "${APPS_SHARE_DIR}") 3 | 4 | collector_list (_list PROJECT_INC_DIRS) 5 | collector_list (_app_list APP_INC_DIRS) 6 | include_directories (${_list} ${_app_list} ${CMAKE_CURRENT_SOURCE_DIR}) 7 | 8 | collector_list (_list PROJECT_LIB_DIRS) 9 | collector_list (_app_list APP_LIB_DIRS) 10 | link_directories (${_list} ${_app_list}) 11 | 12 | get_property (_linker_opt GLOBAL PROPERTY APP_LINKER_OPT) 13 | collector_list (_deps PROJECT_LIB_DEPS) 14 | 15 | set (OPENAMP_LIB open_amp) 16 | foreach (_app matrix_multiply matrix_multiplyd) 17 | collector_list (_sources APP_COMMON_SOURCES) 18 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/${_app}.c") 19 | 20 | if (WITH_SHARED_LIB) 21 | add_executable (${_app}-shared ${_sources}) 22 | target_link_libraries (${_app}-shared ${OPENAMP_LIB}-shared ${_deps}) 23 | install (TARGETS ${_app}-shared RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 24 | endif (WITH_SHARED_LIB) 25 | 26 | if (WITH_STATIC_LIB) 27 | if (${PROJECT_SYSTEM} STREQUAL "linux") 28 | add_executable (${_app}-static ${_sources}) 29 | target_link_libraries (${_app}-static ${OPENAMP_LIB}-static ${_deps}) 30 | install (TARGETS ${_app}-static RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 31 | else (${PROJECT_SYSTEM}) 32 | add_executable (${_app}.out ${_sources}) 33 | set_source_files_properties(${_sources} PROPERTIES COMPILE_FLAGS "${_cflags}") 34 | 35 | target_link_libraries(${_app}.out -Wl,-Map=${_app}.map -Wl,--gc-sections ${_linker_opt} -Wl,--start-group ${OPENAMP_LIB}-static ${_deps} -Wl,--end-group) 36 | 37 | install (TARGETS ${_app}.out RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 38 | endif (${PROJECT_SYSTEM} STREQUAL "linux" ) 39 | endif (WITH_STATIC_LIB) 40 | endforeach(_app) 41 | 42 | -------------------------------------------------------------------------------- /apps/examples/matrix_multiply/matrix_multiply.h: -------------------------------------------------------------------------------- 1 | #ifndef MATRIX_MULTIPLY_H 2 | #define MATRIX_MULTIPLY_H 3 | 4 | #define RPMSG_SERVICE_NAME "rpmsg-openamp-demo-channel" 5 | 6 | #endif /* MATRIX_MULTIPLY_H */ 7 | -------------------------------------------------------------------------------- /apps/examples/matrix_multiply/matrix_multiplyd.c: -------------------------------------------------------------------------------- 1 | /* This is a sample demonstration application that showcases usage of remoteproc 2 | and rpmsg APIs on the remote core. This application is meant to run on the remote CPU 3 | running baremetal code. This applicationr receives two matrices from the master, 4 | multiplies them and returns the result to the master core. */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "matrix_multiply.h" 11 | #include "platform_info.h" 12 | 13 | #define MAX_SIZE 6 14 | #define NUM_MATRIX 2 15 | 16 | #define SHUTDOWN_MSG 0xEF56A55A 17 | 18 | #define LPRINTF(format, ...) printf(format, ##__VA_ARGS__) 19 | //#define LPRINTF(format, ...) 20 | #define LPERROR(format, ...) LPRINTF("ERROR: " format, ##__VA_ARGS__) 21 | 22 | typedef struct _matrix { 23 | unsigned int size; 24 | unsigned int elements[MAX_SIZE][MAX_SIZE]; 25 | } matrix; 26 | 27 | /* Local variables */ 28 | static struct rpmsg_endpoint lept; 29 | static int shutdown_req = 0; 30 | 31 | /*-----------------------------------------------------------------------------* 32 | * Calculate the Matrix 33 | *-----------------------------------------------------------------------------*/ 34 | static void Matrix_Multiply(const matrix *m, const matrix *n, matrix *r) 35 | { 36 | unsigned int i, j, k; 37 | 38 | memset(r, 0x0, sizeof(matrix)); 39 | r->size = m->size; 40 | 41 | for (i = 0; i < m->size; ++i) { 42 | for (j = 0; j < n->size; ++j) { 43 | for (k = 0; k < r->size; ++k) { 44 | r->elements[i][j] += 45 | m->elements[i][k] * n->elements[k][j]; 46 | } 47 | } 48 | } 49 | } 50 | 51 | /*-----------------------------------------------------------------------------* 52 | * RPMSG callbacks setup by remoteproc_resource_init() 53 | *-----------------------------------------------------------------------------*/ 54 | static int rpmsg_endpoint_cb(struct rpmsg_endpoint *ept, void *data, size_t len, 55 | uint32_t src, void *priv) 56 | { 57 | matrix matrix_array[NUM_MATRIX]; 58 | matrix matrix_result; 59 | 60 | (void)priv; 61 | (void)src; 62 | 63 | if ((*(unsigned int *)data) == SHUTDOWN_MSG) { 64 | LPRINTF("shutdown message is received.\r\n"); 65 | shutdown_req = 1; 66 | return RPMSG_SUCCESS; 67 | } 68 | 69 | memcpy(matrix_array, data, len); 70 | /* Process received data and multiple matrices. */ 71 | Matrix_Multiply(&matrix_array[0], &matrix_array[1], &matrix_result); 72 | 73 | /* Send the result of matrix multiplication back to master. */ 74 | if (rpmsg_send(ept, &matrix_result, sizeof(matrix)) < 0) { 75 | LPERROR("rpmsg_send failed\r\n"); 76 | } 77 | return RPMSG_SUCCESS; 78 | } 79 | 80 | static void rpmsg_service_unbind(struct rpmsg_endpoint *ept) 81 | { 82 | (void)ept; 83 | LPERROR("Endpoint is destroyed\r\n"); 84 | shutdown_req = 1; 85 | } 86 | 87 | /*-----------------------------------------------------------------------------* 88 | * Application 89 | *-----------------------------------------------------------------------------*/ 90 | int matrix_multiplyd_app(struct rpmsg_device *rdev, void *priv) 91 | { 92 | int ret; 93 | 94 | ret = rpmsg_create_ept(&lept, rdev, RPMSG_SERVICE_NAME, 95 | RPMSG_ADDR_ANY, RPMSG_ADDR_ANY, 96 | rpmsg_endpoint_cb, 97 | rpmsg_service_unbind); 98 | if (ret) { 99 | LPERROR("Failed to create endpoint.\r\n"); 100 | return -1; 101 | } 102 | 103 | LPRINTF("Waiting for events...\r\n"); 104 | while(1) { 105 | platform_poll(priv); 106 | /* we got a shutdown request, exit */ 107 | if (shutdown_req) { 108 | break; 109 | } 110 | } 111 | rpmsg_destroy_ept(&lept); 112 | 113 | return 0; 114 | } 115 | 116 | /*-----------------------------------------------------------------------------* 117 | * Application entry point 118 | *-----------------------------------------------------------------------------*/ 119 | #ifdef METAL_SYSTEM_RTTHREAD 120 | static int __matrix_multiplyd(int argc, char *argv[]); 121 | 122 | int matrix_multiplyd() 123 | { 124 | __matrix_multiplyd(1, NULL); 125 | } 126 | #ifdef RT_USING_FINSH 127 | FINSH_FUNCTION_EXPORT(matrix_multiplyd, rpmsg echo); 128 | #endif /* #ifdef RT_USING_FINSH */ 129 | #ifdef FINSH_USING_MSH 130 | MSH_CMD_EXPORT(matrix_multiplyd, rpmsg echo); 131 | #endif /* #ifdef FINSH_USING_MSH */ 132 | 133 | static int __matrix_multiplyd(int argc, char *argv[]) 134 | #else 135 | int main(int argc, char *argv[]) 136 | #endif /* #ifdef METAL_SYSTEM_RTTHREAD */ 137 | { 138 | void *platform; 139 | struct rpmsg_device *rpdev; 140 | int ret; 141 | 142 | LPRINTF("Starting application...\r\n"); 143 | #ifdef METAL_SYSTEM_RTTHREAD 144 | //Make rt-thread happy 145 | shutdown_req = 0; 146 | memset(&lept, 0, sizeof(lept)); 147 | #endif /* #ifdef FINSH_USING_MSH */ 148 | 149 | /* Initialize platform */ 150 | ret = platform_init(argc, argv, &platform); 151 | if (ret) { 152 | LPERROR("Failed to initialize platform.\r\n"); 153 | ret = -1; 154 | } else { 155 | rpdev = platform_create_rpmsg_vdev(platform, 0, 156 | VIRTIO_DEV_SLAVE, 157 | NULL, NULL); 158 | if (!rpdev) { 159 | LPERROR("Failed to create rpmsg virtio device.\r\n"); 160 | ret = -1; 161 | } else { 162 | app(rpdev, platform); 163 | platform_release_rpmsg_vdev(rpdev,0); 164 | ret = 0; 165 | } 166 | } 167 | 168 | LPRINTF("Stopping application...\r\n"); 169 | platform_cleanup(platform); 170 | 171 | return ret; 172 | } 173 | -------------------------------------------------------------------------------- /apps/examples/matrix_multiply/matrix_multiplyd.c.orig: -------------------------------------------------------------------------------- 1 | /* This is a sample demonstration application that showcases usage of remoteproc 2 | and rpmsg APIs on the remote core. This application is meant to run on the remote CPU 3 | running baremetal code. This applicationr receives two matrices from the master, 4 | multiplies them and returns the result to the master core. */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "matrix_multiply.h" 11 | #include "platform_info.h" 12 | 13 | #define MAX_SIZE 6 14 | #define NUM_MATRIX 2 15 | 16 | #define SHUTDOWN_MSG 0xEF56A55A 17 | 18 | #define LPRINTF(format, ...) printf(format, ##__VA_ARGS__) 19 | //#define LPRINTF(format, ...) 20 | #define LPERROR(format, ...) LPRINTF("ERROR: " format, ##__VA_ARGS__) 21 | 22 | typedef struct _matrix { 23 | unsigned int size; 24 | unsigned int elements[MAX_SIZE][MAX_SIZE]; 25 | } matrix; 26 | 27 | /* Local variables */ 28 | static struct rpmsg_endpoint lept; 29 | static int shutdown_req = 0; 30 | 31 | /*-----------------------------------------------------------------------------* 32 | * Calculate the Matrix 33 | *-----------------------------------------------------------------------------*/ 34 | static void Matrix_Multiply(const matrix *m, const matrix *n, matrix *r) 35 | { 36 | unsigned int i, j, k; 37 | 38 | memset(r, 0x0, sizeof(matrix)); 39 | r->size = m->size; 40 | 41 | for (i = 0; i < m->size; ++i) { 42 | for (j = 0; j < n->size; ++j) { 43 | for (k = 0; k < r->size; ++k) { 44 | r->elements[i][j] += 45 | m->elements[i][k] * n->elements[k][j]; 46 | } 47 | } 48 | } 49 | } 50 | 51 | /*-----------------------------------------------------------------------------* 52 | * RPMSG callbacks setup by remoteproc_resource_init() 53 | *-----------------------------------------------------------------------------*/ 54 | static int rpmsg_endpoint_cb(struct rpmsg_endpoint *ept, void *data, size_t len, 55 | uint32_t src, void *priv) 56 | { 57 | matrix matrix_array[NUM_MATRIX]; 58 | matrix matrix_result; 59 | 60 | (void)priv; 61 | (void)src; 62 | 63 | if ((*(unsigned int *)data) == SHUTDOWN_MSG) { 64 | LPRINTF("shutdown message is received.\r\n"); 65 | shutdown_req = 1; 66 | return RPMSG_SUCCESS; 67 | } 68 | 69 | memcpy(matrix_array, data, len); 70 | /* Process received data and multiple matrices. */ 71 | Matrix_Multiply(&matrix_array[0], &matrix_array[1], &matrix_result); 72 | 73 | /* Send the result of matrix multiplication back to master. */ 74 | if (rpmsg_send(ept, &matrix_result, sizeof(matrix)) < 0) { 75 | LPERROR("rpmsg_send failed\r\n"); 76 | } 77 | return RPMSG_SUCCESS; 78 | } 79 | 80 | static void rpmsg_service_unbind(struct rpmsg_endpoint *ept) 81 | { 82 | (void)ept; 83 | LPERROR("Endpoint is destroyed\r\n"); 84 | shutdown_req = 1; 85 | } 86 | 87 | /*-----------------------------------------------------------------------------* 88 | * Application 89 | *-----------------------------------------------------------------------------*/ 90 | int matrix_multiplyd_app(struct rpmsg_device *rdev, void *priv) 91 | { 92 | int ret; 93 | 94 | ret = rpmsg_create_ept(&lept, rdev, RPMSG_SERVICE_NAME, 95 | RPMSG_ADDR_ANY, RPMSG_ADDR_ANY, 96 | rpmsg_endpoint_cb, 97 | rpmsg_service_unbind); 98 | if (ret) { 99 | LPERROR("Failed to create endpoint.\r\n"); 100 | return -1; 101 | } 102 | 103 | LPRINTF("Waiting for events...\r\n"); 104 | while(1) { 105 | platform_poll(priv); 106 | /* we got a shutdown request, exit */ 107 | if (shutdown_req) { 108 | break; 109 | } 110 | } 111 | rpmsg_destroy_ept(&lept); 112 | 113 | return 0; 114 | } 115 | 116 | /*-----------------------------------------------------------------------------* 117 | * Application entry point 118 | *-----------------------------------------------------------------------------*/ 119 | #ifdef METAL_SYSTEM_RTTHREAD 120 | static int __matrix_multiplyd(int argc, char *argv[]); 121 | 122 | int matrix_multiplyd() 123 | { 124 | __matrix_multiplyd(1, NULL); 125 | } 126 | #ifdef RT_USING_FINSH 127 | FINSH_FUNCTION_EXPORT(matrix_multiplyd, rpmsg echo); 128 | #endif /* #ifdef RT_USING_FINSH */ 129 | #ifdef FINSH_USING_MSH 130 | MSH_CMD_EXPORT(matrix_multiplyd, rpmsg echo); 131 | #endif /* #ifdef FINSH_USING_MSH */ 132 | 133 | static int __matrix_multiplyd(int argc, char *argv[]) 134 | #else 135 | int main(int argc, char *argv[]) 136 | #endif /* #ifdef METAL_SYSTEM_RTTHREAD */ 137 | { 138 | void *platform; 139 | struct rpmsg_device *rpdev; 140 | int ret; 141 | 142 | LPRINTF("Starting application...\r\n"); 143 | 144 | /* Initialize platform */ 145 | ret = platform_init(argc, argv, &platform); 146 | if (ret) { 147 | LPERROR("Failed to initialize platform.\r\n"); 148 | ret = -1; 149 | } else { 150 | rpdev = platform_create_rpmsg_vdev(platform, 0, 151 | VIRTIO_DEV_SLAVE, 152 | NULL, NULL); 153 | if (!rpdev) { 154 | LPERROR("Failed to create rpmsg virtio device.\r\n"); 155 | ret = -1; 156 | } else { 157 | app(rpdev, platform); 158 | platform_release_rpmsg_vdev(rpdev); 159 | ret = 0; 160 | } 161 | } 162 | 163 | LPRINTF("Stopping application...\r\n"); 164 | platform_cleanup(platform); 165 | 166 | return ret; 167 | } 168 | -------------------------------------------------------------------------------- /apps/examples/matrix_multiply/matrix_multiplyd.c.rej: -------------------------------------------------------------------------------- 1 | --- apps/examples/matrix_multiply/matrix_multiplyd.c 2 | +++ apps/examples/matrix_multiply/matrix_multiplyd.c 3 | @@ -158,7 +175,7 @@ int main(int argc, char *argv[]) 4 | LPERROR("Failed to create rpmsg virtio device.\r\n"); 5 | ret = -1; 6 | } else { 7 | - app(rpdev, platform); 8 | + matrix_multiplyd_app(rpdev, platform); 9 | platform_release_rpmsg_vdev(rpdev, platform); 10 | ret = 0; 11 | } 12 | -------------------------------------------------------------------------------- /apps/examples/matrix_multiply/matrix_multiplyd.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigmagic123/openamp/f793a2503fbb9085df79d31bb5184157e3fc1470/apps/examples/matrix_multiply/matrix_multiplyd.o -------------------------------------------------------------------------------- /apps/examples/rpc_demo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (_cflags "${CMAKE_C_FLAGS} ${APP_EXTRA_C_FLAGS}") 2 | set (_fw_dir "${APPS_SHARE_DIR}") 3 | 4 | collector_list (_list PROJECT_INC_DIRS) 5 | collector_list (_app_list APP_INC_DIRS) 6 | include_directories (${_list} ${_app_list} ${CMAKE_CURRENT_SOURCE_DIR}) 7 | 8 | collector_list (_list PROJECT_LIB_DIRS) 9 | collector_list (_app_list APP_LIB_DIRS) 10 | link_directories (${_list} ${_app_list}) 11 | 12 | get_property (_linker_opt GLOBAL PROPERTY APP_LINKER_LARGE_TEXT_OPT) 13 | if (NOT _linker_opt) 14 | get_property (_linker_opt GLOBAL PROPERTY APP_LINKER_OPT) 15 | endif (NOT _linker_opt) 16 | collector_list (_deps PROJECT_LIB_DEPS) 17 | 18 | set (OPENAMP_LIB open_amp) 19 | 20 | if (${PROJECT_SYSTEM} STREQUAL "linux") 21 | set (app_list rpc_demod) 22 | else (${PROJECT_SYSTEM}) 23 | set (app_list rpc_demo) 24 | endif (${PROJECT_SYSTEM} STREQUAL "linux") 25 | 26 | foreach (_app ${app_list}) 27 | collector_list (_sources APP_COMMON_SOURCES) 28 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/${_app}.c") 29 | 30 | if (WITH_SHARED_LIB) 31 | add_executable (${_app}-shared ${_sources}) 32 | target_link_libraries (${_app}-shared ${OPENAMP_LIB}-shared ${_deps}) 33 | install (TARGETS ${_app}-shared RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 34 | endif (WITH_SHARED_LIB) 35 | 36 | if (WITH_STATIC_LIB) 37 | if (${PROJECT_SYSTEM} STREQUAL "linux") 38 | add_executable (${_app}-static ${_sources}) 39 | target_link_libraries (${_app}-static ${OPENAMP_LIB}-static ${_deps}) 40 | install (TARGETS ${_app}-static RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 41 | else (${PROJECT_SYSTEM}) 42 | add_executable (${_app}.out ${_sources}) 43 | set_source_files_properties(${_sources} PROPERTIES COMPILE_FLAGS "${_cflags}") 44 | 45 | target_link_libraries(${_app}.out -Wl,-Map=${_app}.map -Wl,--gc-sections ${_linker_opt} -Wl,--start-group ${OPENAMP_LIB}-static ${_deps} -Wl,--end-group) 46 | install (TARGETS ${_app}.out RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 47 | endif (${PROJECT_SYSTEM} STREQUAL "linux" ) 48 | endif (WITH_STATIC_LIB) 49 | endforeach(_app) 50 | -------------------------------------------------------------------------------- /apps/examples/rpc_demo/rpmsg-rpc-demo.h: -------------------------------------------------------------------------------- 1 | #ifndef RPMSG_RPC_DEMO_H 2 | #define RPMSG_RPC_DEMO_H 3 | 4 | #define RPMSG_SERVICE_NAME "rpmsg-openamp-demo-channel" 5 | 6 | #endif /* RPMSG_RPC_DEMO_H */ 7 | -------------------------------------------------------------------------------- /apps/examples/rpmsg_sample_echo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set (_cflags "${CMAKE_C_FLAGS} ${APP_EXTRA_C_FLAGS} -fdata-sections -ffunction-sections") 3 | set (_fw_dir "${APPS_SHARE_DIR}") 4 | 5 | collector_list (_list PROJECT_INC_DIRS) 6 | collector_list (_app_list APP_INC_DIRS) 7 | include_directories (${_list} ${_app_list} ${CMAKE_CURRENT_SOURCE_DIR}) 8 | 9 | collector_list (_list PROJECT_LIB_DIRS) 10 | collector_list (_app_list APP_LIB_DIRS) 11 | link_directories (${_list} ${_app_list}) 12 | 13 | get_property (_linker_opt GLOBAL PROPERTY APP_LINKER_OPT) 14 | collector_list (_deps PROJECT_LIB_DEPS) 15 | 16 | set (OPENAMP_LIB open_amp) 17 | 18 | foreach (_app rpmsg-sample-echo rpmsg-sample-ping) 19 | collector_list (_sources APP_COMMON_SOURCES) 20 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/${_app}.c") 21 | 22 | if (WITH_SHARED_LIB) 23 | add_executable (${_app}-shared ${_sources}) 24 | target_link_libraries (${_app}-shared ${OPENAMP_LIB}-shared ${_deps}) 25 | install (TARGETS ${_app}-shared RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 26 | endif (WITH_SHARED_LIB) 27 | 28 | if (WITH_STATIC_LIB) 29 | if (${PROJECT_SYSTEM} STREQUAL "linux") 30 | add_executable (${_app}-static ${_sources}) 31 | target_link_libraries (${_app}-static ${OPENAMP_LIB}-static ${_deps}) 32 | install (TARGETS ${_app}-static RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 33 | else (${PROJECT_SYSTEM}) 34 | add_executable (${_app}.out ${_sources}) 35 | set_source_files_properties(${_sources} PROPERTIES COMPILE_FLAGS "${_cflags}") 36 | 37 | target_link_libraries(${_app}.out -Wl,-Map=${_app}.map -Wl,--gc-sections ${_linker_opt} -Wl,--start-group ${OPENAMP_LIB}-static ${_deps} -Wl,--end-group) 38 | 39 | install (TARGETS ${_app}.out RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 40 | endif (${PROJECT_SYSTEM} STREQUAL "linux" ) 41 | endif (WITH_STATIC_LIB) 42 | endforeach(_app) 43 | -------------------------------------------------------------------------------- /apps/examples/rpmsg_sample_echo/rpmsg-sample-echo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a sample demonstration application that showcases usage of rpmsg 3 | * This application is meant to run on the remote CPU running baremetal code. 4 | * This application allows to check the compatibility with linux OS running on 5 | * the master CPU. For this it echo MSG_LIMIT time message sent by the rpmsg 6 | * sample client available in linux kernel distribution. 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "platform_info.h" 14 | 15 | #define LPRINTF(format, ...) printf(format, ##__VA_ARGS__) 16 | #define LPERROR(format, ...) LPRINTF("ERROR: " format, ##__VA_ARGS__) 17 | 18 | 19 | #define RPMSG_SERV_NAME "rpmsg-client-sample" 20 | #define MSG_LIMIT 100 21 | 22 | static struct rpmsg_endpoint lept; 23 | static int shutdown_req = 0; 24 | 25 | /*-----------------------------------------------------------------------------* 26 | * RPMSG endpoint callbacks 27 | *-----------------------------------------------------------------------------*/ 28 | static int rpmsg_endpoint_cb(struct rpmsg_endpoint *ept, void *data, size_t len, 29 | uint32_t src, void *priv) 30 | { 31 | (void)priv; 32 | (void)src; 33 | static uint32_t count = 0; 34 | char payload[RPMSG_BUFFER_SIZE]; 35 | 36 | /* Send data back MSG_LIMIT time to master */ 37 | memset(payload, 0, RPMSG_BUFFER_SIZE); 38 | memcpy(payload, data, len); 39 | if (++count <= MSG_LIMIT) { 40 | LPRINTF("echo message number %u: %s\r\n", 41 | (unsigned int)count, payload); 42 | if (rpmsg_send(ept, (char *)data, len) < 0) { 43 | LPERROR("rpmsg_send failed\r\n"); 44 | goto destroy_ept; 45 | } 46 | 47 | if (count == MSG_LIMIT) { 48 | LPRINTF("reach message limit, exit\r\n"); 49 | goto destroy_ept; 50 | } 51 | } 52 | return RPMSG_SUCCESS; 53 | 54 | destroy_ept: 55 | shutdown_req = 1; 56 | return RPMSG_SUCCESS; 57 | } 58 | 59 | static void rpmsg_service_unbind(struct rpmsg_endpoint *ept) 60 | { 61 | (void)ept; 62 | LPRINTF("unexpected Remote endpoint destroy\r\n"); 63 | shutdown_req = 1; 64 | } 65 | 66 | /*-----------------------------------------------------------------------------* 67 | * Application 68 | *-----------------------------------------------------------------------------*/ 69 | int app(struct rpmsg_device *rdev, void *priv) 70 | { 71 | int ret; 72 | 73 | /* Initialize RPMSG framework */ 74 | LPRINTF("Try to create rpmsg endpoint.\r\n"); 75 | 76 | ret = rpmsg_create_ept(&lept, rdev, RPMSG_SERV_NAME, 77 | RPMSG_ADDR_ANY, RPMSG_ADDR_ANY, 78 | rpmsg_endpoint_cb, rpmsg_service_unbind); 79 | if (ret) { 80 | LPERROR("Failed to create endpoint.\r\n"); 81 | return -1; 82 | } 83 | 84 | LPRINTF("Successfully created rpmsg endpoint.\r\n"); 85 | while (1) { 86 | platform_poll(priv); 87 | /* we got a shutdown request, exit */ 88 | if (shutdown_req) { 89 | break; 90 | } 91 | } 92 | rpmsg_destroy_ept(&lept); 93 | 94 | return 0; 95 | } 96 | 97 | /*-----------------------------------------------------------------------------* 98 | * Application entry point 99 | *-----------------------------------------------------------------------------*/ 100 | #ifdef METAL_SYSTEM_RTTHREAD 101 | static int rpmsg_sample_echo(int argc, char *argv[]); 102 | 103 | int rpmsg_echo() 104 | { 105 | rpmsg_sample_echo(1, NULL); 106 | } 107 | #ifdef RT_USING_FINSH 108 | FINSH_FUNCTION_EXPORT(rpmsg_echo, rpmsg echo); 109 | #endif /* #ifdef RT_USING_FINSH */ 110 | #ifdef FINSH_USING_MSH 111 | MSH_CMD_EXPORT(rpmsg_echo, rpmsg echo); 112 | #endif /* #ifdef FINSH_USING_MSH */ 113 | 114 | static int rpmsg_sample_echo(int argc, char *argv[]) 115 | #else 116 | int main(int argc, char *argv[]) 117 | #endif /* #ifdef METAL_SYSTEM_RTTHREAD */ 118 | { 119 | void *platform; 120 | struct rpmsg_device *rpdev; 121 | int ret; 122 | 123 | LPRINTF("Starting application...\r\n"); 124 | #ifdef METAL_SYSTEM_RTTHREAD 125 | //Make rt-thread happy 126 | shutdown_req = 0; 127 | memset(&lept, 0, sizeof(lept)); 128 | #endif /* #ifdef FINSH_USING_MSH */ 129 | 130 | /* Initialize platform */ 131 | ret = platform_init(argc, argv, &platform); 132 | if (ret) { 133 | LPERROR("Failed to initialize platform.\r\n"); 134 | ret = -1; 135 | } else { 136 | rpdev = platform_create_rpmsg_vdev(platform, 0, 137 | VIRTIO_DEV_SLAVE, 138 | NULL, NULL); 139 | if (!rpdev) { 140 | LPERROR("Failed to create rpmsg virtio device.\r\n"); 141 | ret = -1; 142 | } else { 143 | app(rpdev, platform); 144 | platform_release_rpmsg_vdev(rpdev,0); 145 | ret = 0; 146 | } 147 | } 148 | 149 | LPRINTF("Stopping application...\r\n"); 150 | platform_cleanup(platform); 151 | 152 | return ret; 153 | } 154 | -------------------------------------------------------------------------------- /apps/examples/rpmsg_sample_echo/rpmsg-sample-echo.c.orig: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a sample demonstration application that showcases usage of rpmsg 3 | * This application is meant to run on the remote CPU running baremetal code. 4 | * This application allows to check the compatibility with linux OS running on 5 | * the master CPU. For this it echo MSG_LIMIT time message sent by the rpmsg 6 | * sample client available in linux kernel distribution. 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "platform_info.h" 14 | 15 | #define LPRINTF(format, ...) printf(format, ##__VA_ARGS__) 16 | #define LPERROR(format, ...) LPRINTF("ERROR: " format, ##__VA_ARGS__) 17 | 18 | 19 | #define RPMSG_SERV_NAME "rpmsg-client-sample" 20 | #define MSG_LIMIT 100 21 | 22 | static struct rpmsg_endpoint lept; 23 | static int shutdown_req = 0; 24 | 25 | /*-----------------------------------------------------------------------------* 26 | * RPMSG endpoint callbacks 27 | *-----------------------------------------------------------------------------*/ 28 | static int rpmsg_endpoint_cb(struct rpmsg_endpoint *ept, void *data, size_t len, 29 | uint32_t src, void *priv) 30 | { 31 | (void)priv; 32 | (void)src; 33 | static uint32_t count = 0; 34 | char payload[RPMSG_BUFFER_SIZE]; 35 | 36 | /* Send data back MSG_LIMIT time to master */ 37 | memset(payload, 0, RPMSG_BUFFER_SIZE); 38 | memcpy(payload, data, len); 39 | if (++count <= MSG_LIMIT) { 40 | LPRINTF("echo message number %u: %s\r\n", 41 | (unsigned int)count, payload); 42 | if (rpmsg_send(ept, (char *)data, len) < 0) { 43 | LPERROR("rpmsg_send failed\r\n"); 44 | goto destroy_ept; 45 | } 46 | 47 | if (count == MSG_LIMIT) { 48 | goto destroy_ept; 49 | } 50 | } 51 | return RPMSG_SUCCESS; 52 | 53 | destroy_ept: 54 | shutdown_req = 1; 55 | return RPMSG_SUCCESS; 56 | } 57 | 58 | static void rpmsg_service_unbind(struct rpmsg_endpoint *ept) 59 | { 60 | (void)ept; 61 | LPRINTF("unexpected Remote endpoint destroy\r\n"); 62 | shutdown_req = 1; 63 | } 64 | 65 | /*-----------------------------------------------------------------------------* 66 | * Application 67 | *-----------------------------------------------------------------------------*/ 68 | int app(struct rpmsg_device *rdev, void *priv) 69 | { 70 | int ret; 71 | 72 | /* Initialize RPMSG framework */ 73 | LPRINTF("Try to create rpmsg endpoint.\r\n"); 74 | 75 | ret = rpmsg_create_ept(&lept, rdev, RPMSG_SERV_NAME, 76 | RPMSG_ADDR_ANY, RPMSG_ADDR_ANY, 77 | rpmsg_endpoint_cb, rpmsg_service_unbind); 78 | if (ret) { 79 | LPERROR("Failed to create endpoint.\r\n"); 80 | return -1; 81 | } 82 | 83 | LPRINTF("Successfully created rpmsg endpoint.\r\n"); 84 | while (1) { 85 | platform_poll(priv); 86 | /* we got a shutdown request, exit */ 87 | if (shutdown_req) { 88 | break; 89 | } 90 | } 91 | rpmsg_destroy_ept(&lept); 92 | 93 | return 0; 94 | } 95 | 96 | /*-----------------------------------------------------------------------------* 97 | * Application entry point 98 | *-----------------------------------------------------------------------------*/ 99 | #ifdef METAL_SYSTEM_RTTHREAD 100 | static int rpmsg_sample_echo(int argc, char *argv[]); 101 | 102 | int rpmsg_echo() 103 | { 104 | rpmsg_sample_echo(1, NULL); 105 | } 106 | #ifdef RT_USING_FINSH 107 | FINSH_FUNCTION_EXPORT(rpmsg_echo, rpmsg echo); 108 | #endif /* #ifdef RT_USING_FINSH */ 109 | #ifdef FINSH_USING_MSH 110 | MSH_CMD_EXPORT(rpmsg_echo, rpmsg echo); 111 | #endif /* #ifdef FINSH_USING_MSH */ 112 | 113 | static int rpmsg_sample_echo(int argc, char *argv[]) 114 | #else 115 | int main(int argc, char *argv[]) 116 | #endif /* #ifdef METAL_SYSTEM_RTTHREAD */ 117 | { 118 | void *platform; 119 | struct rpmsg_device *rpdev; 120 | int ret; 121 | 122 | LPRINTF("Starting application...\r\n"); 123 | 124 | /* Initialize platform */ 125 | ret = platform_init(argc, argv, &platform); 126 | if (ret) { 127 | LPERROR("Failed to initialize platform.\r\n"); 128 | ret = -1; 129 | } else { 130 | rpdev = platform_create_rpmsg_vdev(platform, 0, 131 | VIRTIO_DEV_SLAVE, 132 | NULL, NULL); 133 | if (!rpdev) { 134 | LPERROR("Failed to create rpmsg virtio device.\r\n"); 135 | ret = -1; 136 | } else { 137 | app(rpdev, platform); 138 | platform_release_rpmsg_vdev(rpdev); 139 | ret = 0; 140 | } 141 | } 142 | 143 | LPRINTF("Stopping application...\r\n"); 144 | platform_cleanup(platform); 145 | 146 | return ret; 147 | } 148 | -------------------------------------------------------------------------------- /apps/examples/rpmsg_sample_echo/rpmsg-sample-echo.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigmagic123/openamp/f793a2503fbb9085df79d31bb5184157e3fc1470/apps/examples/rpmsg_sample_echo/rpmsg-sample-echo.o -------------------------------------------------------------------------------- /apps/examples/rpmsg_sample_echo/rpmsg-sample-ping.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a sample demonstration application that showcases usage of rpmsg 3 | * This application is meant to run on the remote CPU running baremetal code. 4 | * This application simulate linux sample rpmsg driver. For this it echo 100 5 | * time message sent by the rpmsg sample client available in linux kernel 6 | * distribution. 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "platform_info.h" 16 | 17 | #define RPMSG_SERV_NAME "rpmsg-client-sample" 18 | 19 | #define HELLO_MSG "hello world!" 20 | #define BYE_MSG "goodbye!" 21 | #define MSG_LIMIT 100 22 | 23 | #define LPRINTF(format, ...) printf(format, ##__VA_ARGS__) 24 | #define LPERROR(format, ...) LPRINTF("ERROR: " format, ##__VA_ARGS__) 25 | 26 | static int err_cnt; 27 | 28 | 29 | /* Globals */ 30 | static struct rpmsg_endpoint lept; 31 | static int rnum = 0; 32 | static int err_cnt = 0; 33 | static int ept_deleted = 0; 34 | 35 | /*-----------------------------------------------------------------------------* 36 | * RPMSG endpoint callbacks 37 | *-----------------------------------------------------------------------------*/ 38 | static int rpmsg_endpoint_cb(struct rpmsg_endpoint *ept, void *data, size_t len, 39 | uint32_t src, void *priv) 40 | { 41 | char payload[RPMSG_BUFFER_SIZE]; 42 | char seed[20]; 43 | 44 | (void)ept; 45 | (void)src; 46 | (void)priv; 47 | 48 | memset(payload, 0, RPMSG_BUFFER_SIZE); 49 | memcpy(payload, data, len); 50 | LPRINTF("received message %d: %s of size %lu \r\n", 51 | rnum + 1, payload, (unsigned long)len); 52 | 53 | if (rnum == (MSG_LIMIT - 1)) 54 | sprintf (seed, "%s", BYE_MSG); 55 | else 56 | sprintf (seed, "%s", HELLO_MSG); 57 | 58 | LPRINTF(" seed %s: \r\n", seed); 59 | 60 | if (strncmp(payload, seed, len)) { 61 | LPERROR(" Invalid message is received.\r\n"); 62 | err_cnt++; 63 | return RPMSG_SUCCESS; 64 | } 65 | LPRINTF(" rnum %d: \r\n", rnum); 66 | rnum++; 67 | 68 | return RPMSG_SUCCESS; 69 | } 70 | 71 | static void rpmsg_service_unbind(struct rpmsg_endpoint *ept) 72 | { 73 | (void)ept; 74 | rpmsg_destroy_ept(&lept); 75 | LPRINTF("echo test: service is destroyed\r\n"); 76 | ept_deleted = 1; 77 | } 78 | 79 | static void rpmsg_name_service_bind_cb(struct rpmsg_device *rdev, 80 | const char *name, uint32_t dest) 81 | { 82 | LPRINTF("new endpoint notification is received.\r\n"); 83 | if (strcmp(name, RPMSG_SERV_NAME)) 84 | LPERROR("Unexpected name service %s.\r\n", name); 85 | else 86 | (void)rpmsg_create_ept(&lept, rdev, RPMSG_SERV_NAME, 87 | RPMSG_ADDR_ANY, dest, 88 | rpmsg_endpoint_cb, 89 | rpmsg_service_unbind); 90 | 91 | } 92 | 93 | /*-----------------------------------------------------------------------------* 94 | * Application 95 | *-----------------------------------------------------------------------------*/ 96 | int app(struct rpmsg_device *rdev, void *priv) 97 | { 98 | int ret; 99 | int i; 100 | 101 | LPRINTF(" 1 - Send data to remote core, retrieve the echo"); 102 | LPRINTF(" and validate its integrity ..\r\n"); 103 | 104 | /* Create RPMsg endpoint */ 105 | ret = rpmsg_create_ept(&lept, rdev, RPMSG_SERV_NAME, 106 | RPMSG_ADDR_ANY, RPMSG_ADDR_ANY, 107 | rpmsg_endpoint_cb, rpmsg_service_unbind); 108 | 109 | if (ret) { 110 | LPERROR("Failed to create RPMsg endpoint.\r\n"); 111 | return ret; 112 | } 113 | 114 | while (!is_rpmsg_ept_ready(&lept)) 115 | platform_poll(priv); 116 | 117 | LPRINTF("RPMSG endpoint is binded with remote.\r\n"); 118 | for (i = 1; i <= MSG_LIMIT; i++) { 119 | 120 | 121 | if (i < MSG_LIMIT) 122 | ret = rpmsg_send(&lept, HELLO_MSG, strlen(HELLO_MSG)); 123 | else 124 | ret = rpmsg_send(&lept, BYE_MSG, strlen(BYE_MSG)); 125 | 126 | if (ret < 0) { 127 | LPERROR("Failed to send data...\r\n"); 128 | break; 129 | } 130 | LPRINTF("rpmsg sample test: message %d sent\r\n", i); 131 | 132 | do { 133 | platform_poll(priv); 134 | } while ((rnum < i) && !err_cnt); 135 | 136 | } 137 | 138 | LPRINTF("**********************************\r\n"); 139 | LPRINTF(" Test Results: Error count = %d\r\n", err_cnt); 140 | LPRINTF("**********************************\r\n"); 141 | while (!ept_deleted) 142 | platform_poll(priv); 143 | LPRINTF("Quitting application .. rpmsg sample test end\r\n"); 144 | 145 | return 0; 146 | } 147 | 148 | int main(int argc, char *argv[]) 149 | { 150 | void *platform; 151 | struct rpmsg_device *rpdev; 152 | int ret; 153 | 154 | /* Initialize platform */ 155 | ret = platform_init(argc, argv, &platform); 156 | if (ret) { 157 | LPERROR("Failed to initialize platform.\r\n"); 158 | ret = -1; 159 | } else { 160 | rpdev = platform_create_rpmsg_vdev(platform, 0, 161 | VIRTIO_DEV_MASTER, 162 | NULL, 163 | rpmsg_name_service_bind_cb); 164 | if (!rpdev) { 165 | LPERROR("Failed to create rpmsg virtio device.\r\n"); 166 | ret = -1; 167 | } else { 168 | app(rpdev, platform); 169 | platform_release_rpmsg_vdev(rpdev); 170 | ret = 0; 171 | } 172 | } 173 | 174 | LPRINTF("Stopping application...\r\n"); 175 | platform_cleanup(platform); 176 | 177 | return ret; 178 | } 179 | 180 | -------------------------------------------------------------------------------- /apps/machine/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_MACHINE}/CMakeLists.txt") 2 | add_subdirectory (${PROJECT_MACHINE}) 3 | endif (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_MACHINE}/CMakeLists.txt") 4 | -------------------------------------------------------------------------------- /apps/machine/zynq7/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | collect (APP_INC_DIRS "${CMAKE_CURRENT_SOURCE_DIR}") 2 | 3 | collect (APP_COMMON_SOURCES platform_info.c) 4 | collect (APP_COMMON_SOURCES rsc_table.c) 5 | collect (APP_COMMON_SOURCES zynq_a9_rproc.c) 6 | 7 | -------------------------------------------------------------------------------- /apps/machine/zynq7/platform_info.h: -------------------------------------------------------------------------------- 1 | #ifndef PLATFORM_INFO_H_ 2 | #define PLATFORM_INFO_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #if defined __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | /* SGIs */ 13 | #define SGI_TO_NOTIFY 15 /* SGI to notify the remote */ 14 | #define SGI_NOTIFICATION 14 /* SGI from the remote */ 15 | 16 | /* Memory attributes */ 17 | #define NORM_NONCACHE 0x11DE2 /* Normal Non-cacheable */ 18 | #define STRONG_ORDERED 0xC02 /* Strongly ordered */ 19 | #define DEVICE_MEMORY 0xC06 /* Device memory */ 20 | #define RESERVED 0x0 /* reserved memory */ 21 | 22 | /* Shared memory */ 23 | #define SHARED_MEM_PA 0x3e800000UL 24 | #define SHARED_MEM_SIZE 0x80000UL 25 | #define SHARED_BUF_OFFSET 0x80000UL 26 | 27 | /* Zynq CPU ID mask */ 28 | #define ZYNQ_CPU_ID_MASK 0x1UL 29 | 30 | /* Remoteproc private data struct */ 31 | struct remoteproc_priv { 32 | const char *gic_name; /* SCUGIC device name */ 33 | const char *gic_bus_name; /* SCUGIC bus name */ 34 | struct metal_device *gic_dev; /* pointer to SCUGIC device */ 35 | struct metal_io_region *gic_io; /* pointer to SCUGIC i/o region */ 36 | unsigned int irq_to_notify; /* SCUGIC IRQ vector to notify the 37 | * other end. 38 | */ 39 | unsigned int irq_notification; /* SCUGIC IRQ vector received from 40 | * other end. 41 | */ 42 | unsigned int cpu_id; /* CPU ID */ 43 | atomic_int nokick; /* 0 for kick from other side */ 44 | }; 45 | 46 | /** 47 | * platform_init - initialize the platform 48 | * 49 | * It will initialize the platform. 50 | * 51 | * @argc: number of arguments 52 | * @argv: array of the input arguements 53 | * @platform: pointer to store the platform data pointer 54 | * 55 | * return 0 for success or negative value for failure 56 | */ 57 | int platform_init(int argc, char *argv[], void **platform); 58 | 59 | /** 60 | * platform_create_rpmsg_vdev - create rpmsg vdev 61 | * 62 | * It will create rpmsg virtio device, and returns the rpmsg virtio 63 | * device pointer. 64 | * 65 | * @platform: pointer to the private data 66 | * @vdev_index: index of the virtio device, there can more than one vdev 67 | * on the platform. 68 | * @role: virtio master or virtio slave of the vdev 69 | * @rst_cb: virtio device reset callback 70 | * @ns_bind_cb: rpmsg name service bind callback 71 | * 72 | * return pointer to the rpmsg virtio device 73 | */ 74 | struct rpmsg_device * 75 | platform_create_rpmsg_vdev(void *platform, unsigned int vdev_index, 76 | unsigned int role, 77 | void (*rst_cb)(struct virtio_device *vdev), 78 | rpmsg_ns_bind_cb ns_bind_cb); 79 | 80 | /** 81 | * platform_poll - platform poll function 82 | * 83 | * @platform: pointer to the platform 84 | * 85 | * return negative value for errors, otherwise 0. 86 | */ 87 | int platform_poll(void *platform); 88 | 89 | /** 90 | * platform_release_rpmsg_vdev - release rpmsg virtio device 91 | * 92 | * @rpdev: pointer to the rpmsg device 93 | */ 94 | void platform_release_rpmsg_vdev(struct rpmsg_device *rpdev); 95 | 96 | /** 97 | * platform_cleanup - clean up the platform resource 98 | * 99 | * @platform: pointer to the platform 100 | */ 101 | void platform_cleanup(void *platform); 102 | 103 | #if defined __cplusplus 104 | } 105 | #endif 106 | 107 | #endif /* PLATFORM_INFO_H_ */ 108 | -------------------------------------------------------------------------------- /apps/machine/zynq7/rsc_table.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Mentor Graphics Corporation 3 | * All rights reserved. 4 | * Copyright (c) 2015 Xilinx, Inc. All rights reserved. 5 | * 6 | * SPDX-License-Identifier: BSD-3-Clause 7 | */ 8 | 9 | /* This file populates resource table for BM remote 10 | * for use by the Linux Master */ 11 | 12 | #include 13 | #include "rsc_table.h" 14 | #include "platform_info.h" 15 | 16 | /* Place resource table in special ELF section */ 17 | /* Redefine __section for section name with token */ 18 | #define __section_t(S) __attribute__((__section__(#S))) 19 | #define __resource __section_t(.resource_table) 20 | 21 | #define RPMSG_IPU_C0_FEATURES 1 22 | 23 | /* VirtIO rpmsg device id */ 24 | #define VIRTIO_ID_RPMSG_ 7 25 | 26 | /* Remote supports Name Service announcement */ 27 | #define VIRTIO_RPMSG_F_NS 0 28 | 29 | /* Resource table entries */ 30 | #define NUM_VRINGS 0x02 31 | #define VRING_ALIGN 0x1000 32 | #define RING_TX FW_RSC_U32_ADDR_ANY 33 | #define RING_RX FW_RSC_U32_ADDR_ANY 34 | #define VRING_SIZE 256 35 | 36 | #define NUM_TABLE_ENTRIES 1 37 | 38 | 39 | struct remote_resource_table __resource resources = { 40 | /* Version */ 41 | 1, 42 | 43 | /* NUmber of table entries */ 44 | NUM_TABLE_ENTRIES, 45 | /* reserved fields */ 46 | {0, 0,}, 47 | 48 | /* Offsets of rsc entries */ 49 | { 50 | offsetof(struct remote_resource_table, rpmsg_vdev), 51 | }, 52 | 53 | /* Virtio device entry */ 54 | { 55 | RSC_VDEV, VIRTIO_ID_RPMSG_, 0, RPMSG_IPU_C0_FEATURES, 0, 0, 0, 56 | NUM_VRINGS, {0, 0}, 57 | }, 58 | 59 | /* Vring rsc entry - part of vdev rsc entry */ 60 | {RING_TX, VRING_ALIGN, VRING_SIZE, 1, 0}, 61 | {RING_RX, VRING_ALIGN, VRING_SIZE, 2, 0}, 62 | }; 63 | 64 | void *get_resource_table (int rsc_id, int *len) 65 | { 66 | (void) rsc_id; 67 | *len = sizeof(resources); 68 | return &resources; 69 | } 70 | -------------------------------------------------------------------------------- /apps/machine/zynq7/rsc_table.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Mentor Graphics Corporation 3 | * All rights reserved. 4 | * Copyright (c) 2015 Xilinx, Inc. All rights reserved. 5 | * 6 | * SPDX-License-Identifier: BSD-3-Clause 7 | */ 8 | 9 | /* This file populates resource table for BM remote 10 | * for use by the Linux Master */ 11 | 12 | #ifndef RSC_TABLE_H_ 13 | #define RSC_TABLE_H_ 14 | 15 | #include 16 | #include 17 | 18 | #if defined __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | #define NO_RESOURCE_ENTRIES 8 23 | 24 | /* Resource table for the given remote */ 25 | struct remote_resource_table { 26 | unsigned int version; 27 | unsigned int num; 28 | unsigned int reserved[2]; 29 | unsigned int offset[NO_RESOURCE_ENTRIES]; 30 | /* rpmsg vdev entry */ 31 | struct fw_rsc_vdev rpmsg_vdev; 32 | struct fw_rsc_vdev_vring rpmsg_vring0; 33 | struct fw_rsc_vdev_vring rpmsg_vring1; 34 | }__attribute__((packed, aligned(0x100000))); 35 | 36 | void *get_resource_table (int rsc_id, int *len); 37 | 38 | #if defined __cplusplus 39 | } 40 | #endif 41 | 42 | #endif /* RSC_TABLE_H_ */ 43 | -------------------------------------------------------------------------------- /apps/machine/zynq7/zynq_a9_rproc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Xilinx, Inc. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | /************************************************************************** 8 | * FILE NAME 9 | * 10 | * zynq_a9_rproc.c 11 | * 12 | * DESCRIPTION 13 | * 14 | * This file define Xilinx Zynq A9 platform specific remoteproc 15 | * implementation. 16 | * 17 | **************************************************************************/ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | /* SCUGIC macros */ 27 | #define GIC_DIST_SOFTINT 0xF00 28 | #define GIC_SFI_TRIG_CPU_MASK 0x00FF0000 29 | #define GIC_SFI_TRIG_SATT_MASK 0x00008000 30 | #define GIC_SFI_TRIG_INTID_MASK 0x0000000F 31 | #define GIC_CPU_ID_BASE (1 << 4) 32 | 33 | static int zynq_a9_proc_irq_handler(int vect_id, void *data) 34 | { 35 | struct remoteproc *rproc = data; 36 | struct remoteproc_priv *prproc; 37 | 38 | (void)vect_id; 39 | if (!rproc) 40 | return METAL_IRQ_NOT_HANDLED; 41 | prproc = rproc->priv; 42 | atomic_flag_clear(&prproc->nokick); 43 | return METAL_IRQ_HANDLED; 44 | } 45 | 46 | static struct remoteproc * 47 | zynq_a9_proc_init(struct remoteproc *rproc, 48 | struct remoteproc_ops *ops, void *arg) 49 | { 50 | struct remoteproc_priv *prproc = arg; 51 | struct metal_device *dev; 52 | unsigned int irq_vect; 53 | int ret; 54 | 55 | if (!rproc || !prproc || !ops) 56 | return NULL; 57 | ret = metal_device_open(prproc->gic_bus_name, prproc->gic_name, 58 | &dev); 59 | if (ret) { 60 | xil_printf("failed to open GIC device: %d.\r\n", ret); 61 | return NULL; 62 | } 63 | rproc->priv = prproc; 64 | prproc->gic_dev = dev; 65 | prproc->gic_io = metal_device_io_region(dev, 0); 66 | if (!prproc->gic_io) 67 | goto err1; 68 | rproc->ops = ops; 69 | atomic_flag_test_and_set(&prproc->nokick); 70 | 71 | /* Register interrupt handler and enable interrupt */ 72 | irq_vect = prproc->irq_notification; 73 | metal_irq_register(irq_vect, zynq_a9_proc_irq_handler, rproc); 74 | metal_irq_enable(irq_vect); 75 | xil_printf("Successfully intialize remoteproc.\r\n"); 76 | return rproc; 77 | err1: 78 | metal_device_close(dev); 79 | return NULL; 80 | } 81 | 82 | static void zynq_a9_proc_remove(struct remoteproc *rproc) 83 | { 84 | struct remoteproc_priv *prproc; 85 | struct metal_device *dev; 86 | 87 | if (!rproc) 88 | return; 89 | prproc = rproc->priv; 90 | metal_irq_disable(prproc->irq_to_notify); 91 | metal_irq_unregister(prproc->irq_to_notify); 92 | dev = prproc->gic_dev; 93 | if (dev) 94 | metal_device_close(dev); 95 | } 96 | 97 | static void * 98 | zynq_a9_proc_mmap(struct remoteproc *rproc, metal_phys_addr_t *pa, 99 | metal_phys_addr_t *da, size_t size, 100 | unsigned int attribute, struct metal_io_region **io) 101 | { 102 | struct remoteproc_mem *mem; 103 | metal_phys_addr_t lpa, lda; 104 | struct metal_io_region *tmpio; 105 | 106 | lpa = *pa; 107 | lda = *da; 108 | 109 | if (lpa == METAL_BAD_PHYS && lda == METAL_BAD_PHYS) 110 | return NULL; 111 | if (lpa == METAL_BAD_PHYS) 112 | lpa = lda; 113 | if (lda == METAL_BAD_PHYS) 114 | lda = lpa; 115 | 116 | if (!attribute) 117 | attribute = NORM_NONCACHE | STRONG_ORDERED; 118 | mem = metal_allocate_memory(sizeof(*mem)); 119 | if (!mem) 120 | return NULL; 121 | tmpio = metal_allocate_memory(sizeof(*tmpio)); 122 | if (!tmpio) { 123 | metal_free_memory(mem); 124 | return NULL; 125 | } 126 | remoteproc_init_mem(mem, NULL, lpa, lda, size, tmpio); 127 | /* va is the same as pa in this platform */ 128 | metal_io_init(tmpio, (void *)lpa, &mem->pa, size, 129 | sizeof(metal_phys_addr_t)<<3, attribute, NULL); 130 | remoteproc_add_mem(rproc, mem); 131 | *pa = lpa; 132 | *da = lda; 133 | if (io) 134 | *io = tmpio; 135 | return metal_io_phys_to_virt(tmpio, mem->pa); 136 | } 137 | 138 | static int zynq_a9_proc_notify(struct remoteproc *rproc, uint32_t id) 139 | { 140 | struct remoteproc_priv *prproc; 141 | unsigned long mask = 0; 142 | 143 | (void)id; 144 | if (!rproc) 145 | return -1; 146 | prproc = rproc->priv; 147 | if (!prproc->gic_io) 148 | return -1; 149 | 150 | mask = ((1 << (GIC_CPU_ID_BASE + prproc->cpu_id)) | 151 | (prproc->irq_to_notify)) 152 | & (GIC_SFI_TRIG_CPU_MASK | GIC_SFI_TRIG_INTID_MASK); 153 | /* Trigger IPI */ 154 | metal_io_write32(prproc->gic_io, GIC_DIST_SOFTINT, mask); 155 | return 0; 156 | } 157 | 158 | /* processor operations from r5 to a53. It defines 159 | * notification operation and remote processor managementi operations. */ 160 | struct remoteproc_ops zynq_a9_proc_ops = { 161 | .init = zynq_a9_proc_init, 162 | .remove = zynq_a9_proc_remove, 163 | .mmap = zynq_a9_proc_mmap, 164 | .notify = zynq_a9_proc_notify, 165 | .start = NULL, 166 | .stop = NULL, 167 | .shutdown = NULL, 168 | }; 169 | -------------------------------------------------------------------------------- /apps/machine/zynqmp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | collect (APP_COMMON_SOURCES platform_info.c) 2 | collect (APP_COMMON_SOURCES zynqmp_linux_r5_proc.c) 3 | collect (APP_INC_DIRS "${CMAKE_CURRENT_SOURCE_DIR}") 4 | -------------------------------------------------------------------------------- /apps/machine/zynqmp/openamp-linux-userspace.dtsi: -------------------------------------------------------------------------------- 1 | / { 2 | reserved-memory { 3 | #address-cells = <2>; 4 | #size-cells = <2>; 5 | ranges; 6 | rproc_0_reserved: rproc@3ed000000 { 7 | no-map; 8 | reg = <0x0 0x3ed00000 0x0 0x1000000>; 9 | }; 10 | }; 11 | 12 | amba { 13 | vring: vring@0 { 14 | compatible = "vring_uio"; 15 | reg = <0x0 0x3ed40000 0x0 0x40000>; 16 | }; 17 | shm0: shm@0 { 18 | compatible = "shm_uio"; 19 | reg = <0x0 0x3ed20000 0x0 0x0100000>; 20 | }; 21 | ipi0: ipi@0 { 22 | compatible = "ipi_uio"; 23 | reg = <0x0 0xff340000 0x0 0x1000>; 24 | interrupt-parent = <&gic>; 25 | interrupts = <0 29 4>; 26 | }; 27 | }; 28 | }; 29 | 30 | -------------------------------------------------------------------------------- /apps/machine/zynqmp/platform_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Xilinx, Inc. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | /* This file populates resource table for BM remote 8 | * for use by the Linux Master */ 9 | 10 | #ifndef PLATFORM_INFO_H_ 11 | #define PLATFORM_INFO_H_ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | #if defined __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | struct remoteproc_priv { 22 | const char *ipi_name; /**< IPI device name */ 23 | const char *ipi_bus_name; /**< IPI bus name */ 24 | const char *rsc_name; /**< rsc device name */ 25 | const char *rsc_bus_name; /**< rsc bus name */ 26 | const char *shm_name; /**< shared memory device name */ 27 | const char *shm_bus_name; /**< shared memory bus name */ 28 | struct metal_device *ipi_dev; /**< pointer to IPI device */ 29 | struct metal_io_region *ipi_io; /**< pointer to IPI i/o region */ 30 | struct metal_device *shm_dev; /**< pointer to shared memory device */ 31 | struct metal_io_region *shm_io; /**< pointer to sh mem i/o region */ 32 | 33 | struct remoteproc_mem shm_mem; /**< shared memory */ 34 | unsigned int ipi_chn_mask; /**< IPI channel mask */ 35 | atomic_int ipi_nokick; 36 | #ifdef RPMSG_NO_IPI 37 | const char *shm_poll_name; /**< shared memory device name */ 38 | const char *shm_poll_bus_name; /**< shared memory bus name */ 39 | struct metal_device *shm_poll_dev; /**< pointer to poll mem device */ 40 | struct metal_io_region *shm_poll_io; /**< pointer to poll mem i/o */ 41 | #endif /* RPMSG_NO_IPI */ 42 | 43 | }; 44 | 45 | 46 | /** 47 | * platform_init - initialize the platform 48 | * 49 | * It will initialize the platform. 50 | * 51 | * @argc: number of arguments 52 | * @argv: array of the input arguements 53 | * @platform: pointer to store the platform data pointer 54 | * 55 | * return 0 for success or negative value for failure 56 | */ 57 | int platform_init(int argc, char *argv[], void **platform); 58 | 59 | /** 60 | * platform_create_rpmsg_vdev - create rpmsg vdev 61 | * 62 | * It will create rpmsg virtio device, and returns the rpmsg virtio 63 | * device pointer. 64 | * 65 | * @platform: pointer to the private data 66 | * @vdev_index: index of the virtio device, there can more than one vdev 67 | * on the platform. 68 | * @role: virtio master or virtio slave of the vdev 69 | * @rst_cb: virtio device reset callback 70 | * @ns_bind_cb: rpmsg name service bind callback 71 | * 72 | * return pointer to the rpmsg virtio device 73 | */ 74 | struct rpmsg_device * 75 | platform_create_rpmsg_vdev(void *platform, unsigned int vdev_index, 76 | unsigned int role, 77 | void (*rst_cb)(struct virtio_device *vdev), 78 | rpmsg_ns_bind_cb ns_bind_cb); 79 | 80 | /** 81 | * platform_poll - platform poll function 82 | * 83 | * @platform: pointer to the platform 84 | * 85 | * return negative value for errors, otherwise 0. 86 | */ 87 | int platform_poll(void *platform); 88 | 89 | /** 90 | * platform_release_rpmsg_vdev - release rpmsg virtio device 91 | * 92 | * @rpdev: pointer to the rpmsg device 93 | */ 94 | void platform_release_rpmsg_vdev(struct rpmsg_device *rpdev); 95 | 96 | /** 97 | * platform_cleanup - clean up the platform resource 98 | * 99 | * @platform: pointer to the platform 100 | */ 101 | void platform_cleanup(void *platform); 102 | 103 | #if defined __cplusplus 104 | } 105 | #endif 106 | 107 | #endif /* PLATFORM_INFO_H_ */ 108 | 109 | -------------------------------------------------------------------------------- /apps/machine/zynqmp_r5/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | collect (APP_COMMON_SOURCES platform_info.c) 2 | collect (APP_COMMON_SOURCES rsc_table.c) 3 | collect (APP_COMMON_SOURCES zynqmp_r5_a53_rproc.c) 4 | collect (APP_INC_DIRS "${CMAKE_CURRENT_SOURCE_DIR}") 5 | 6 | -------------------------------------------------------------------------------- /apps/machine/zynqmp_r5/platform_info.h: -------------------------------------------------------------------------------- 1 | #ifndef PLATFORM_INFO_H_ 2 | #define PLATFORM_INFO_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #if defined __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | /* Cortex R5 memory attributes */ 13 | #define DEVICE_SHARED 0x00000001U /* device, shareable */ 14 | #define DEVICE_NONSHARED 0x00000010U /* device, non shareable */ 15 | #define NORM_NSHARED_NCACHE 0x00000008U /* Non cacheable non shareable */ 16 | #define NORM_SHARED_NCACHE 0x0000000CU /* Non cacheable shareable */ 17 | #define PRIV_RW_USER_RW (0x00000003U<<8U) /* Full Access */ 18 | 19 | /* Interrupt vectors */ 20 | #ifdef versal 21 | #define IPI_IRQ_VECT_ID 63 22 | #define POLL_BASE_ADDR 0xFF340000 /* IPI base address*/ 23 | #define IPI_CHN_BITMASK 0x0000020 /* IPI channel bit mask for IPI from/to 24 | APU */ 25 | #else 26 | #define IPI_IRQ_VECT_ID XPAR_XIPIPSU_0_INT_ID 27 | #define POLL_BASE_ADDR XPAR_XIPIPSU_0_BASE_ADDRESS 28 | #define IPI_CHN_BITMASK 0x01000000 29 | #endif /* versal */ 30 | 31 | #ifdef RPMSG_NO_IPI 32 | #undef POLL_BASE_ADDR 33 | #define POLL_BASE_ADDR 0x3EE40000 34 | #define POLL_STOP 0x1U 35 | #endif /* RPMSG_NO_IPI */ 36 | 37 | struct remoteproc_priv { 38 | const char *poll_dev_name; 39 | const char *poll_dev_bus_name; 40 | struct metal_device *poll_dev; 41 | struct metal_io_region *poll_io; 42 | #ifndef RPMSG_NO_IPI 43 | unsigned int ipi_chn_mask; /**< IPI channel mask */ 44 | atomic_int ipi_nokick; 45 | #endif /* !RPMSG_NO_IPI */ 46 | }; 47 | 48 | /** 49 | * platform_init - initialize the platform 50 | * 51 | * It will initialize the platform. 52 | * 53 | * @argc: number of arguments 54 | * @argv: array of the input arguements 55 | * @platform: pointer to store the platform data pointer 56 | * 57 | * return 0 for success or negative value for failure 58 | */ 59 | int platform_init(int argc, char *argv[], void **platform); 60 | 61 | /** 62 | * platform_create_rpmsg_vdev - create rpmsg vdev 63 | * 64 | * It will create rpmsg virtio device, and returns the rpmsg virtio 65 | * device pointer. 66 | * 67 | * @platform: pointer to the private data 68 | * @vdev_index: index of the virtio device, there can more than one vdev 69 | * on the platform. 70 | * @role: virtio master or virtio slave of the vdev 71 | * @rst_cb: virtio device reset callback 72 | * @ns_bind_cb: rpmsg name service bind callback 73 | * 74 | * return pointer to the rpmsg virtio device 75 | */ 76 | struct rpmsg_device * 77 | platform_create_rpmsg_vdev(void *platform, unsigned int vdev_index, 78 | unsigned int role, 79 | void (*rst_cb)(struct virtio_device *vdev), 80 | rpmsg_ns_bind_cb ns_bind_cb); 81 | 82 | /** 83 | * platform_poll - platform poll function 84 | * 85 | * @platform: pointer to the platform 86 | * 87 | * return negative value for errors, otherwise 0. 88 | */ 89 | int platform_poll(void *platform); 90 | 91 | /** 92 | * platform_release_rpmsg_vdev - release rpmsg virtio device 93 | * 94 | * @rpdev: pointer to the rpmsg device 95 | */ 96 | void platform_release_rpmsg_vdev(struct rpmsg_device *rpdev); 97 | 98 | /** 99 | * platform_cleanup - clean up the platform resource 100 | * 101 | * @platform: pointer to the platform 102 | */ 103 | void platform_cleanup(void *platform); 104 | 105 | #if defined __cplusplus 106 | } 107 | #endif 108 | 109 | #endif /* PLATFORM_INFO_H_ */ 110 | -------------------------------------------------------------------------------- /apps/machine/zynqmp_r5/rsc_table.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Mentor Graphics Corporation 3 | * All rights reserved. 4 | * Copyright (c) 2015 Xilinx, Inc. All rights reserved. 5 | * 6 | * SPDX-License-Identifier: BSD-3-Clause 7 | */ 8 | 9 | /* This file populates resource table for BM remote 10 | * for use by the Linux Master */ 11 | 12 | #include 13 | #include "rsc_table.h" 14 | 15 | /* Place resource table in special ELF section */ 16 | #define __section_t(S) __attribute__((__section__(#S))) 17 | #define __resource __section_t(.resource_table) 18 | 19 | #define RPMSG_IPU_C0_FEATURES 1 20 | 21 | /* VirtIO rpmsg device id */ 22 | #define VIRTIO_ID_RPMSG_ 7 23 | 24 | /* Remote supports Name Service announcement */ 25 | #define VIRTIO_RPMSG_F_NS 0 26 | 27 | #define NUM_VRINGS 0x02 28 | #define VRING_ALIGN 0x1000 29 | #define RING_TX FW_RSC_U32_ADDR_ANY 30 | #define RING_RX FW_RSC_U32_ADDR_ANY 31 | #define VRING_SIZE 256 32 | 33 | #define NUM_TABLE_ENTRIES 1 34 | 35 | struct remote_resource_table __resource resources = { 36 | /* Version */ 37 | 1, 38 | 39 | /* NUmber of table entries */ 40 | NUM_TABLE_ENTRIES, 41 | /* reserved fields */ 42 | {0, 0,}, 43 | 44 | /* Offsets of rsc entries */ 45 | { 46 | offsetof(struct remote_resource_table, rpmsg_vdev), 47 | }, 48 | 49 | /* Virtio device entry */ 50 | { 51 | RSC_VDEV, VIRTIO_ID_RPMSG_, 0, RPMSG_IPU_C0_FEATURES, 0, 0, 0, 52 | NUM_VRINGS, {0, 0}, 53 | }, 54 | 55 | /* Vring rsc entry - part of vdev rsc entry */ 56 | {RING_TX, VRING_ALIGN, VRING_SIZE, 1, 0}, 57 | {RING_RX, VRING_ALIGN, VRING_SIZE, 2, 0}, 58 | }; 59 | 60 | void *get_resource_table (int rsc_id, int *len) 61 | { 62 | (void) rsc_id; 63 | *len = sizeof(resources); 64 | return &resources; 65 | } 66 | 67 | -------------------------------------------------------------------------------- /apps/machine/zynqmp_r5/rsc_table.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Mentor Graphics Corporation 3 | * All rights reserved. 4 | * 5 | * Copyright (C) 2015 Xilinx, Inc. All rights reserved. 6 | * 7 | * SPDX-License-Identifier: BSD-3-Clause 8 | */ 9 | 10 | /* This file populates resource table for BM remote 11 | * for use by the Linux Master */ 12 | 13 | #ifndef RSC_TABLE_H_ 14 | #define RSC_TABLE_H_ 15 | 16 | #include 17 | #include 18 | 19 | #if defined __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #define NO_RESOURCE_ENTRIES 8 24 | 25 | /* Resource table for the given remote */ 26 | struct remote_resource_table { 27 | unsigned int version; 28 | unsigned int num; 29 | unsigned int reserved[2]; 30 | unsigned int offset[NO_RESOURCE_ENTRIES]; 31 | /* rpmsg vdev entry */ 32 | struct fw_rsc_vdev rpmsg_vdev; 33 | struct fw_rsc_vdev_vring rpmsg_vring0; 34 | struct fw_rsc_vdev_vring rpmsg_vring1; 35 | }__attribute__((packed, aligned(0x100))); 36 | 37 | void *get_resource_table (int rsc_id, int *len); 38 | 39 | #if defined __cplusplus 40 | } 41 | #endif 42 | 43 | #endif /* RSC_TABLE_H_ */ 44 | -------------------------------------------------------------------------------- /apps/system/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_SYSTEM}/CMakeLists.txt") 2 | add_subdirectory (${PROJECT_SYSTEM}) 3 | endif (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_SYSTEM}/CMakeLists.txt") 4 | -------------------------------------------------------------------------------- /apps/system/generic/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory (machine) 2 | -------------------------------------------------------------------------------- /apps/system/generic/machine/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_MACHINE}/CMakeLists.txt") 2 | add_subdirectory (${PROJECT_MACHINE}) 3 | endif (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_MACHINE}/CMakeLists.txt") 4 | -------------------------------------------------------------------------------- /apps/system/generic/machine/rv64_virt/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | collect (APP_COMMON_SOURCES platform_info.c) 2 | collect (APP_COMMON_SOURCES rv64_virt_linux_proc.c) 3 | collect (APP_COMMON_SOURCES helper.c) 4 | collect (APP_COMMON_SOURCES rsc_table.c) 5 | collect (APP_INC_DIRS "${CMAKE_CURRENT_SOURCE_DIR}") 6 | if (RPMSG_NO_IPI) 7 | add_definitions(-DRPMSG_NO_IPI) 8 | endif (RPMSG_NO_IPI) 9 | 10 | -------------------------------------------------------------------------------- /apps/system/generic/machine/rv64_virt/helper.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (c) 2014, Mentor Graphics Corporation 4 | * All rights reserved. 5 | * 6 | * Copyright (c) 2015 Xilinx, Inc. All rights reserved. 7 | * 8 | * SPDX-License-Identifier: BSD-3-Clause 9 | */ 10 | #include 11 | #include 12 | #include 13 | 14 | int init_system() 15 | { 16 | struct metal_init_params metal_param = METAL_INIT_DEFAULTS; 17 | 18 | metal_init(&metal_param); 19 | 20 | return 0; 21 | } 22 | 23 | void cleanup_system() 24 | { 25 | metal_finish(); 26 | } 27 | -------------------------------------------------------------------------------- /apps/system/generic/machine/rv64_virt/helper.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigmagic123/openamp/f793a2503fbb9085df79d31bb5184157e3fc1470/apps/system/generic/machine/rv64_virt/helper.o -------------------------------------------------------------------------------- /apps/system/generic/machine/rv64_virt/platform_info.h: -------------------------------------------------------------------------------- 1 | #ifndef PLATFORM_INFO_H_ 2 | #define PLATFORM_INFO_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #if defined __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | #define PRINT printf 13 | 14 | /* memory attributes */ 15 | 16 | /* Interrupt vectors */ 17 | 18 | /* POLL device */ 19 | #ifdef RPMSG_NO_IPI 20 | #undef POLL_BASE_ADDR 21 | //qemu virt_memmap hw/riscv/virt.c 22 | //[VIRT_SHM_IPI] = { 0x90000000, 0x00080000 }, 23 | #define POLL_BASE_ADDR 0x90000000UL 24 | #define POLL_STOP 0x1U 25 | #endif /* RPMSG_NO_IPI */ 26 | 27 | //TODO: move to common 28 | #define SHM_BASE 0x90100000UL 29 | 30 | #define RSC_MEM_PA SHM_BASE 31 | #define RSC_MEM_SIZE 0x00020000UL 32 | //shared buffer: 0x90120000--0x90160000 33 | #define SHARED_BUF_PA (SHM_BASE + RSC_MEM_SIZE) 34 | #define SHARED_BUF_SIZE 0x00040000UL 35 | //TODO: move to common end 36 | 37 | struct remoteproc_priv { 38 | const char *poll_dev_name; 39 | const char *poll_dev_bus_name; 40 | struct metal_device *poll_dev; 41 | struct metal_io_region *poll_io; 42 | #ifndef RPMSG_NO_IPI 43 | unsigned int ipi_chn_mask; /**< IPI channel mask */ 44 | atomic_int ipi_nokick; 45 | #endif /* !RPMSG_NO_IPI */ 46 | }; 47 | 48 | /** 49 | * platform_init - initialize the platform 50 | * 51 | * It will initialize the platform. 52 | * 53 | * @argc: number of arguments 54 | * @argv: array of the input arguements 55 | * @platform: pointer to store the platform data pointer 56 | * 57 | * return 0 for success or negative value for failure 58 | */ 59 | int platform_init(int argc, char *argv[], void **platform); 60 | 61 | /** 62 | * platform_create_rpmsg_vdev - create rpmsg vdev 63 | * 64 | * It will create rpmsg virtio device, and returns the rpmsg virtio 65 | * device pointer. 66 | * 67 | * @platform: pointer to the private data 68 | * @vdev_index: index of the virtio device, there can more than one vdev 69 | * on the platform. 70 | * @role: virtio master or virtio slave of the vdev 71 | * @rst_cb: virtio device reset callback 72 | * @ns_bind_cb: rpmsg name service bind callback 73 | * 74 | * return pointer to the rpmsg virtio device 75 | */ 76 | struct rpmsg_device * 77 | platform_create_rpmsg_vdev(void *platform, unsigned int vdev_index, 78 | unsigned int role, 79 | void (*rst_cb)(struct virtio_device *vdev), 80 | rpmsg_ns_bind_cb ns_bind_cb); 81 | 82 | /** 83 | * platform_poll - platform poll function 84 | * 85 | * @platform: pointer to the platform 86 | * 87 | * return negative value for errors, otherwise 0. 88 | */ 89 | int platform_poll(void *platform); 90 | 91 | /** 92 | * platform_release_rpmsg_vdev - release rpmsg virtio device 93 | * 94 | * @rpdev: pointer to the rpmsg device 95 | */ 96 | void platform_release_rpmsg_vdev(struct rpmsg_device *rpdev, void *platform); 97 | 98 | /** 99 | * platform_cleanup - clean up the platform resource 100 | * 101 | * @platform: pointer to the platform 102 | */ 103 | void platform_cleanup(void *platform); 104 | 105 | #if defined __cplusplus 106 | } 107 | #endif 108 | 109 | #endif /* PLATFORM_INFO_H_ */ 110 | -------------------------------------------------------------------------------- /apps/system/generic/machine/rv64_virt/platform_info.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigmagic123/openamp/f793a2503fbb9085df79d31bb5184157e3fc1470/apps/system/generic/machine/rv64_virt/platform_info.o -------------------------------------------------------------------------------- /apps/system/generic/machine/rv64_virt/rsc_table.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Mentor Graphics Corporation 3 | * All rights reserved. 4 | * Copyright (c) 2015 Xilinx, Inc. All rights reserved. 5 | * 6 | * SPDX-License-Identifier: BSD-3-Clause 7 | */ 8 | 9 | /* This file populates resource table for BM remote 10 | * for use by the Linux Master */ 11 | 12 | #include 13 | #include "rsc_table.h" 14 | 15 | /* Place resource table in special ELF section */ 16 | #define __section_t(S) __attribute__((__section__(#S))) 17 | #define __resource __section_t(.resource_table) 18 | 19 | #define RPMSG_IPU_C0_FEATURES 1 20 | 21 | /* VirtIO rpmsg device id */ 22 | #define VIRTIO_ID_RPMSG_ 7 23 | 24 | /* Remote supports Name Service announcement */ 25 | #define VIRTIO_RPMSG_F_NS 0 26 | 27 | #define NUM_VRINGS 0x02 28 | #define VRING_ALIGN 0x1000 29 | #define RING_TX FW_RSC_U32_ADDR_ANY 30 | #define RING_RX FW_RSC_U32_ADDR_ANY 31 | #define VRING_SIZE 256 32 | 33 | #define NUM_TABLE_ENTRIES 1 34 | 35 | struct remote_resource_table __resource resources = { 36 | /* Version */ 37 | 1, 38 | 39 | /* NUmber of table entries */ 40 | NUM_TABLE_ENTRIES, 41 | /* reserved fields */ 42 | {0, 0,}, 43 | 44 | /* Offsets of rsc entries */ 45 | { 46 | offsetof(struct remote_resource_table, rpmsg_vdev), 47 | }, 48 | 49 | /* Virtio device entry */ 50 | { 51 | RSC_VDEV, VIRTIO_ID_RPMSG_, 0, RPMSG_IPU_C0_FEATURES, 0, 0, 0, 52 | NUM_VRINGS, {0, 0}, 53 | }, 54 | 55 | /* Vring rsc entry - part of vdev rsc entry */ 56 | {RING_TX, VRING_ALIGN, VRING_SIZE, 1, 0}, 57 | {RING_RX, VRING_ALIGN, VRING_SIZE, 2, 0}, 58 | }; 59 | 60 | void *get_resource_table (int rsc_id, int *len) 61 | { 62 | (void) rsc_id; 63 | *len = sizeof(resources); 64 | return &resources; 65 | } 66 | 67 | -------------------------------------------------------------------------------- /apps/system/generic/machine/rv64_virt/rsc_table.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Mentor Graphics Corporation 3 | * All rights reserved. 4 | * 5 | * Copyright (C) 2015 Xilinx, Inc. All rights reserved. 6 | * 7 | * SPDX-License-Identifier: BSD-3-Clause 8 | */ 9 | 10 | /* This file populates resource table for BM remote 11 | * for use by the Linux Master */ 12 | 13 | #ifndef RSC_TABLE_H_ 14 | #define RSC_TABLE_H_ 15 | 16 | #include 17 | #include 18 | 19 | #if defined __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #define NO_RESOURCE_ENTRIES 8 24 | 25 | /* Resource table for the given remote */ 26 | struct remote_resource_table { 27 | unsigned int version; 28 | unsigned int num; 29 | unsigned int reserved[2]; 30 | unsigned int offset[NO_RESOURCE_ENTRIES]; 31 | /* rpmsg vdev entry */ 32 | struct fw_rsc_vdev rpmsg_vdev; 33 | struct fw_rsc_vdev_vring rpmsg_vring0; 34 | struct fw_rsc_vdev_vring rpmsg_vring1; 35 | }__attribute__((packed, aligned(0x100))); 36 | 37 | void *get_resource_table (int rsc_id, int *len); 38 | 39 | #if defined __cplusplus 40 | } 41 | #endif 42 | 43 | #endif /* RSC_TABLE_H_ */ 44 | -------------------------------------------------------------------------------- /apps/system/generic/machine/rv64_virt/rsc_table.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigmagic123/openamp/f793a2503fbb9085df79d31bb5184157e3fc1470/apps/system/generic/machine/rv64_virt/rsc_table.o -------------------------------------------------------------------------------- /apps/system/generic/machine/rv64_virt/virt_rv64_rproc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Mentor Graphics Corporation 3 | * All rights reserved. 4 | * Copyright (c) 2017 Xilinx, Inc. 5 | * 6 | * SPDX-License-Identifier: BSD-3-Clause 7 | */ 8 | 9 | /************************************************************************** 10 | * FILE NAME 11 | * 12 | * virt_rv64_rproc.c 13 | * 14 | * DESCRIPTION 15 | * 16 | * This file define Xilinx ZynqMP R5 to A53 platform specific 17 | * remoteproc implementation. 18 | * 19 | **************************************************************************/ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "platform_info.h" 28 | 29 | static struct remoteproc * 30 | virt_rv64_proc_init(struct remoteproc *rproc, 31 | struct remoteproc_ops *ops, void *arg) 32 | { 33 | struct remoteproc_priv *prproc = arg; 34 | struct metal_device *poll_dev; 35 | unsigned int irq_vect; 36 | int ret; 37 | 38 | if (!rproc || !prproc || !ops) 39 | return NULL; 40 | ret = metal_device_open(prproc->poll_dev_bus_name, 41 | prproc->poll_dev_name, 42 | &poll_dev); 43 | if (ret) { 44 | PRINT("failed to open polling device: %d.\r\n", ret); 45 | return NULL; 46 | } 47 | rproc->priv = prproc; 48 | prproc->poll_dev = poll_dev; 49 | prproc->poll_io = metal_device_io_region(poll_dev, 0); 50 | if (!prproc->poll_io) 51 | goto err1; 52 | #ifndef RPMSG_NO_IPI 53 | atomic_store(&prproc->ipi_nokick, 1); 54 | /* Register interrupt handler and enable interrupt */ 55 | irq_vect = (uintptr_t)ipi_dev->irq_info; 56 | metal_irq_register(irq_vect, virt_rv64_proc_irq_handler, rproc); 57 | metal_irq_enable(irq_vect); 58 | metal_io_write32(prproc->poll_io, IPI_IER_OFFSET, 59 | prproc->ipi_chn_mask); 60 | #else 61 | metal_io_write32(prproc->poll_io, 0, !POLL_STOP); 62 | #endif /* !RPMSG_NO_IPI */ 63 | rproc->ops = ops; 64 | 65 | return rproc; 66 | err1: 67 | metal_device_close(poll_dev); 68 | return NULL; 69 | } 70 | 71 | static void virt_rv64_proc_remove(struct remoteproc *rproc) 72 | { 73 | struct remoteproc_priv *prproc; 74 | struct metal_device *dev; 75 | 76 | if (!rproc) 77 | return; 78 | prproc = rproc->priv; 79 | #ifndef RPMSG_NO_IPI 80 | metal_io_write32(prproc->poll_io, IPI_IDR_OFFSET, 81 | prproc->ipi_chn_mask); 82 | dev = prproc->poll_dev; 83 | if (dev) { 84 | metal_irq_disable((uintptr_t)dev->irq_info); 85 | metal_irq_unregister((uintptr_t)dev->irq_info); 86 | } 87 | #endif /* !RPMSG_NO_IPI */ 88 | metal_device_close(prproc->poll_dev); 89 | } 90 | 91 | static void * 92 | virt_rv64_proc_mmap(struct remoteproc *rproc, metal_phys_addr_t *pa, 93 | metal_phys_addr_t *da, size_t size, 94 | unsigned int attribute, struct metal_io_region **io) 95 | { 96 | struct remoteproc_mem *mem; 97 | metal_phys_addr_t lpa, lda; 98 | struct metal_io_region *tmpio; 99 | 100 | lpa = *pa; 101 | lda = *da; 102 | 103 | if (lpa == METAL_BAD_PHYS && lda == METAL_BAD_PHYS) 104 | return NULL; 105 | if (lpa == METAL_BAD_PHYS) 106 | lpa = lda; 107 | if (lda == METAL_BAD_PHYS) 108 | lda = lpa; 109 | 110 | if (!attribute) 111 | attribute = 0; 112 | mem = metal_allocate_memory(sizeof(*mem)); 113 | if (!mem) 114 | return NULL; 115 | tmpio = metal_allocate_memory(sizeof(*tmpio)); 116 | if (!tmpio) { 117 | metal_free_memory(mem); 118 | return NULL; 119 | } 120 | remoteproc_init_mem(mem, NULL, lpa, lda, size, tmpio); 121 | /* va is the same as pa in this platform */ 122 | metal_io_init(tmpio, (void *)lpa, &mem->pa, size, 123 | sizeof(metal_phys_addr_t) << 3, attribute, NULL); 124 | remoteproc_add_mem(rproc, mem); 125 | *pa = lpa; 126 | *da = lda; 127 | if (io) 128 | *io = tmpio; 129 | return metal_io_phys_to_virt(tmpio, mem->pa); 130 | } 131 | 132 | static int virt_rv64_proc_notify(struct remoteproc *rproc, uint32_t id) 133 | { 134 | struct remoteproc_priv *prproc; 135 | 136 | (void)id; 137 | if (!rproc) 138 | return -1; 139 | prproc = rproc->priv; 140 | 141 | #ifdef RPMSG_NO_IPI 142 | metal_io_write32(prproc->poll_io, 0, POLL_STOP); 143 | #else 144 | metal_io_write32(prproc->poll_io, IPI_TRIG_OFFSET, 145 | prproc->ipi_chn_mask); 146 | #endif /* RPMSG_NO_IPI */ 147 | return 0; 148 | } 149 | 150 | /* processor operations from r5 to a53. It defines 151 | * notification operation and remote processor managementi operations. */ 152 | struct remoteproc_ops virt_rv64_proc_ops = { 153 | .init = virt_rv64_proc_init, 154 | .remove = virt_rv64_proc_remove, 155 | .mmap = virt_rv64_proc_mmap, 156 | .notify = virt_rv64_proc_notify, 157 | .start = NULL, 158 | .stop = NULL, 159 | .shutdown = NULL, 160 | }; 161 | -------------------------------------------------------------------------------- /apps/system/generic/machine/rv64_virt/virt_rv64_rproc.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigmagic123/openamp/f793a2503fbb9085df79d31bb5184157e3fc1470/apps/system/generic/machine/rv64_virt/virt_rv64_rproc.o -------------------------------------------------------------------------------- /apps/system/generic/machine/zynq7/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | collect (APP_COMMON_SOURCES helper.c) 2 | 3 | set (_linker_script "${CMAKE_CURRENT_SOURCE_DIR}/linker_remote.ld") 4 | 5 | set_property (GLOBAL PROPERTY APP_LINKER_OPT "-Wl,-build-id=none -specs=${CMAKE_CURRENT_SOURCE_DIR}/Xilinx.spec -T\"${_linker_script}\"") 6 | 7 | find_path(XIL_INCLUDE_DIR NAMES xparameters.h PATHS ${CMAKE_FIND_ROOT_PATH}) 8 | collect (PROJECT_INC_DIRS "${XIL_INCLUDE_DIR}") 9 | 10 | find_library(LIBXIL_LIB NAMES xil PATHS ${CMAKE_FIND_ROOT_PATH}) 11 | get_filename_component(LIBXIL_LIB_DIR ${LIBXIL_LIB} DIRECTORY) 12 | collect(PROJECT_LIB_DIRS ${LIBXIL_LIB_DIR}) 13 | 14 | collect(PROJECT_LIB_DEPS xil) 15 | collect(PROJECT_LIB_DEPS c) 16 | collect(PROJECT_LIB_DEPS m) 17 | -------------------------------------------------------------------------------- /apps/system/generic/machine/zynq7/Xilinx.spec: -------------------------------------------------------------------------------- 1 | *startfile: 2 | crti%O%s crtbegin%O%s 3 | -------------------------------------------------------------------------------- /apps/system/generic/machine/zynq7/helper.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Mentor Graphics Corporation 3 | * All rights reserved. 4 | * 5 | * Copyright (c) 2015 Xilinx, Inc. All rights reserved. 6 | * 7 | * SPDX-License-Identifier: BSD-3-Clause 8 | */ 9 | 10 | #include "xparameters.h" 11 | #include "xil_exception.h" 12 | #include "xil_printf.h" 13 | #include "xscugic.h" 14 | #include "xil_cache.h" 15 | #include 16 | #include 17 | #include "platform_info.h" 18 | 19 | 20 | #define INTC_DEVICE_ID XPAR_SCUGIC_0_DEVICE_ID 21 | 22 | static XScuGic xInterruptController; 23 | 24 | /* Interrupt Controller setup */ 25 | static int app_gic_initialize(void) 26 | { 27 | u32 Status; 28 | XScuGic_Config *IntcConfig; /* The configuration parameters of the interrupt controller */ 29 | 30 | Xil_ExceptionDisable(); 31 | 32 | /* 33 | * Initialize the interrupt controller driver 34 | */ 35 | IntcConfig = XScuGic_LookupConfig(INTC_DEVICE_ID); 36 | if (NULL == IntcConfig) { 37 | return XST_FAILURE; 38 | } 39 | 40 | Status = XScuGic_CfgInitialize(&xInterruptController, IntcConfig, 41 | IntcConfig->CpuBaseAddress); 42 | if (Status != XST_SUCCESS) { 43 | return XST_FAILURE; 44 | } 45 | 46 | /* 47 | * Register the interrupt handler to the hardware interrupt handling 48 | * logic in the ARM processor. 49 | */ 50 | Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_IRQ_INT, 51 | (Xil_ExceptionHandler)XScuGic_InterruptHandler, 52 | &xInterruptController); 53 | 54 | /* Disable the interrupt before enabling exception to avoid interrupts 55 | * received before exception is enabled. 56 | */ 57 | XScuGic_Disable(&xInterruptController, SGI_NOTIFICATION); 58 | 59 | Xil_ExceptionEnable(); 60 | 61 | /* Connect notificaiton interrupt ID with ISR */ 62 | XScuGic_Connect(&xInterruptController, SGI_NOTIFICATION, 63 | (Xil_ExceptionHandler)metal_xlnx_irq_isr, 64 | (void *)SGI_NOTIFICATION); 65 | 66 | return 0; 67 | } 68 | 69 | /* Main hw machinery initialization entry point, called from main()*/ 70 | /* return 0 on success */ 71 | int init_system(void) 72 | { 73 | int ret; 74 | struct metal_init_params metal_param = METAL_INIT_DEFAULTS; 75 | 76 | /* Low level abstraction layer for openamp initialization */ 77 | metal_init(&metal_param); 78 | 79 | /* configure the global interrupt controller */ 80 | app_gic_initialize(); 81 | 82 | /* Initialize metal Xilinx IRQ controller */ 83 | ret = metal_xlnx_irq_init(); 84 | if (ret) { 85 | xil_printf("%s: Xilinx metal IRQ controller init failed.\r\n", 86 | __func__); 87 | } 88 | 89 | return ret; 90 | } 91 | 92 | void cleanup_system() 93 | { 94 | metal_finish(); 95 | 96 | Xil_DCacheDisable(); 97 | Xil_ICacheDisable(); 98 | Xil_DCacheInvalidate(); 99 | Xil_ICacheInvalidate(); 100 | } 101 | -------------------------------------------------------------------------------- /apps/system/generic/machine/zynqmp_r5/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(CheckSymbolExists) 2 | 3 | collect (APP_COMMON_SOURCES helper.c) 4 | 5 | set (_linker_script "${CMAKE_CURRENT_SOURCE_DIR}/linker_remote.ld") 6 | set_property (GLOBAL PROPERTY APP_LINKER_OPT "-T\"${_linker_script}\"") 7 | set (_linker_large_text_script "${CMAKE_CURRENT_SOURCE_DIR}/linker_large_text.ld") 8 | set_property (GLOBAL PROPERTY APP_LINKER_LARGE_TEXT_OPT "-T\"${_linker_large_text_script}\"") 9 | 10 | find_path(XIL_INCLUDE_DIR NAMES xparameters.h PATHS ${CMAKE_FIND_ROOT_PATH}) 11 | collect (PROJECT_INC_DIRS "${XIL_INCLUDE_DIR}") 12 | 13 | find_library(LIBXIL_LIB NAMES xil PATHS ${CMAKE_FIND_ROOT_PATH}) 14 | get_filename_component(LIBXIL_LIB_DIR ${LIBXIL_LIB} DIRECTORY) 15 | collect(PROJECT_LIB_DIRS ${LIBXIL_LIB_DIR}) 16 | 17 | # check PM API for certain headers and set client version based 18 | CHECK_SYMBOL_EXISTS(XPAR_XILPM_ENABLED "xparameters.h" PM_FOUND) 19 | if(PM_FOUND) 20 | find_library(HAS_PM_LIB NAMES xilpm PATHS ${CMAKE_FIND_ROOT_PATH}) 21 | collect (PROJECT_LIB_DEPS xilpm) 22 | CHECK_SYMBOL_EXISTS(versal "xparameters.h" VERSION_2_PM_CLIENT) 23 | if (VERSION_2_PM_CLIENT) 24 | collect (APP_EXTRA_C_FLAGS " -DVERSION_2_PM_CLIENT ") 25 | else() 26 | collect (APP_EXTRA_C_FLAGS " -DVERSION_1_PM_CLIENT ") 27 | endif(VERSION_2_PM_CLIENT) 28 | endif(PM_FOUND) 29 | 30 | collect(PROJECT_LIB_DEPS xil) 31 | collect(PROJECT_LIB_DEPS c) 32 | collect(PROJECT_LIB_DEPS m) 33 | find_library(XILMEM_LIB NAMES xilmem PATHS ${CMAKE_FIND_ROOT_PATH}) 34 | if(XILMEM_LIB) 35 | collect (PROJECT_LIB_DEPS xilmem) 36 | endif(XILMEM_LIB) 37 | -------------------------------------------------------------------------------- /apps/system/generic/machine/zynqmp_r5/helper.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Mentor Graphics Corporation 3 | * All rights reserved. 4 | * 5 | * Copyright (c) 2015 Xilinx, Inc. All rights reserved. 6 | * 7 | * SPDX-License-Identifier: BSD-3-Clause 8 | */ 9 | 10 | #include "xparameters.h" 11 | #include "xil_exception.h" 12 | #include "xil_printf.h" 13 | #include "xscugic.h" 14 | #include "xil_cache.h" 15 | #include 16 | #include 17 | #include "platform_info.h" 18 | 19 | #define INTC_DEVICE_ID XPAR_SCUGIC_0_DEVICE_ID 20 | 21 | static XScuGic xInterruptController; 22 | 23 | /* Interrupt Controller setup */ 24 | static int app_gic_initialize(void) 25 | { 26 | uint32_t status; 27 | XScuGic_Config *int_ctrl_config; /* interrupt controller configuration params */ 28 | uint32_t int_id; 29 | uint32_t mask_cpu_id = ((u32)0x1 << XPAR_CPU_ID); 30 | uint32_t target_cpu; 31 | 32 | mask_cpu_id |= mask_cpu_id << 8U; 33 | mask_cpu_id |= mask_cpu_id << 16U; 34 | 35 | Xil_ExceptionDisable(); 36 | 37 | /* 38 | * Initialize the interrupt controller driver 39 | */ 40 | int_ctrl_config = XScuGic_LookupConfig(INTC_DEVICE_ID); 41 | if (NULL == int_ctrl_config) { 42 | return XST_FAILURE; 43 | } 44 | 45 | status = XScuGic_CfgInitialize(&xInterruptController, int_ctrl_config, 46 | int_ctrl_config->CpuBaseAddress); 47 | if (status != XST_SUCCESS) { 48 | return XST_FAILURE; 49 | } 50 | 51 | /* Only associate interrupt needed to this CPU */ 52 | for (int_id = 32U; int_id 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | int init_system() 19 | { 20 | struct metal_init_params metal_param = METAL_INIT_DEFAULTS; 21 | 22 | metal_param.log_level = LOG_DEBUG; 23 | metal_init(&metal_param); 24 | 25 | return 0; 26 | } 27 | 28 | void cleanup_system() 29 | { 30 | metal_finish(); 31 | } 32 | -------------------------------------------------------------------------------- /apps/system/linux/machine/generic/platform_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Xilinx, Inc. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | /* This file populates resource table for BM remote 8 | * for use by the Linux Master */ 9 | 10 | #ifndef PLATFORM_INFO_H 11 | #define PLATFORM_INFO_H 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | #if defined __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | struct remoteproc_priv { 22 | const char *ipi_name; /**< IPI device name */ 23 | const char *ipi_bus_name; /**< IPI bus name */ 24 | const char *rsc_name; /**< rsc device name */ 25 | const char *rsc_bus_name; /**< rsc bus name */ 26 | const char *shm_name; /**< shared memory device name */ 27 | const char *shm_bus_name; /**< shared memory bus name */ 28 | struct metal_device *ipi_dev; /**< pointer to IPI device */ 29 | struct metal_io_region *ipi_io; /**< pointer to IPI i/o region */ 30 | struct metal_device *shm_dev; /**< pointer to shared memory device */ 31 | struct metal_io_region *shm_io; /**< pointer to sh mem i/o region */ 32 | 33 | struct remoteproc_mem shm_mem; /**< shared memory */ 34 | unsigned int ipi_chn_mask; /**< IPI channel mask */ 35 | atomic_int ipi_nokick; 36 | #ifdef RPMSG_NO_IPI 37 | const char *shm_poll_name; /**< shared memory device name */ 38 | const char *shm_poll_bus_name; /**< shared memory bus name */ 39 | struct metal_device *shm_poll_dev; /**< pointer to poll mem device */ 40 | struct metal_io_region *shm_poll_io; /**< pointer to poll mem i/o */ 41 | #endif /* RPMSG_NO_IPI */ 42 | 43 | }; 44 | /** 45 | * platform_init - initialize the platform 46 | * 47 | * It will initialize the platform. 48 | * 49 | * @argc: number of arguments 50 | * @argv: array of the input arguements 51 | * @platform: pointer to store the platform data pointer 52 | * 53 | * return 0 for success or negative value for failure 54 | */ 55 | int platform_init(int argc, char *argv[], void **platform); 56 | 57 | /** 58 | * platform_create_rpmsg_vdev - create rpmsg vdev 59 | * 60 | * It will create rpmsg virtio device, and returns the rpmsg virtio 61 | * device pointer. 62 | * 63 | * @platform: pointer to the private data 64 | * @vdev_index: index of the virtio device, there can more than one vdev 65 | * on the platform. 66 | * @role: virtio master or virtio slave of the vdev 67 | * @rst_cb: virtio device reset callback 68 | * @ns_bind_cb: rpmsg name service bind callback 69 | * 70 | * return pointer to the rpmsg virtio device 71 | */ 72 | struct rpmsg_device * 73 | platform_create_rpmsg_vdev(void *platform, unsigned int vdev_index, 74 | unsigned int role, 75 | void (*rst_cb)(struct virtio_device *vdev), 76 | rpmsg_ns_bind_cb ns_bind_cb); 77 | 78 | /** 79 | * platform_poll - platform poll function 80 | * 81 | * @platform: pointer to the platform 82 | * 83 | * return negative value for errors, otherwise 0. 84 | */ 85 | int platform_poll(void *platform); 86 | 87 | /** 88 | * platform_release_rpmsg_vdev - release rpmsg virtio device 89 | * 90 | * @rpdev: pointer to the rpmsg device 91 | */ 92 | void platform_release_rpmsg_vdev(struct rpmsg_device *rpdev); 93 | 94 | /** 95 | * platform_cleanup - clean up the platform resource 96 | * 97 | * @platform: pointer to the platform 98 | */ 99 | void platform_cleanup(void *platform); 100 | 101 | #if defined __cplusplus 102 | } 103 | #endif 104 | 105 | #endif /* PLATFORM_INFO_H */ 106 | -------------------------------------------------------------------------------- /apps/system/linux/machine/generic/rsc_table.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Mentor Graphics Corporation 3 | * All rights reserved. 4 | * Copyright (c) 2016 Xilinx, Inc. All rights reserved. 5 | * 6 | * SPDX-License-Identifier: BSD-3-Clause 7 | */ 8 | 9 | /* This file populates resource table for BM remote 10 | * for use by the Linux Master */ 11 | 12 | #include 13 | #include "rsc_table.h" 14 | 15 | #define RPMSG_IPU_C0_FEATURES 1 16 | 17 | /* VirtIO rpmsg device id */ 18 | #define VIRTIO_ID_RPMSG_ 7 19 | 20 | /* Remote supports Name Service announcement */ 21 | #define VIRTIO_RPMSG_F_NS 0 22 | 23 | #define NUM_VRINGS 0x02 24 | #define VRING_ALIGN 0x1000 25 | #define RING_TX 0x00004000 26 | #define RING_RX 0x00008000 27 | #define VRING_SIZE 256 28 | 29 | #define NUM_TABLE_ENTRIES 1 30 | 31 | struct remote_resource_table resources = { 32 | /* Version */ 33 | 1, 34 | 35 | /* NUmber of table entries */ 36 | NUM_TABLE_ENTRIES, 37 | /* reserved fields */ 38 | {0, 0,}, 39 | 40 | /* Offsets of rsc entries */ 41 | { 42 | offsetof(struct remote_resource_table, rpmsg_vdev), 43 | }, 44 | 45 | /* Virtio device entry */ 46 | { 47 | RSC_VDEV, VIRTIO_ID_RPMSG_, 0, RPMSG_IPU_C0_FEATURES, 0, 0, 0, 48 | NUM_VRINGS, {0, 0}, 49 | }, 50 | 51 | /* Vring rsc entry - part of vdev rsc entry */ 52 | {RING_TX, VRING_ALIGN, VRING_SIZE, 1, 0}, 53 | {RING_RX, VRING_ALIGN, VRING_SIZE, 2, 0}, 54 | }; 55 | 56 | void *get_resource_table (int rsc_id, int *len) 57 | { 58 | (void) rsc_id; 59 | *len = sizeof(resources); 60 | return &resources; 61 | } 62 | -------------------------------------------------------------------------------- /apps/system/linux/machine/generic/rsc_table.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Mentor Graphics Corporation 3 | * All rights reserved. 4 | * Copyright (c) 2016 Xilinx, Inc. All rights reserved. 5 | * 6 | * SPDX-License-Identifier: BSD-3-Clause 7 | */ 8 | 9 | /* This file populates resource table for BM remote 10 | * for use by the Linux Master */ 11 | 12 | #ifndef RSC_TABLE_H_ 13 | #define RSC_TABLE_H_ 14 | 15 | #include 16 | #include 17 | 18 | #if defined __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | #define NO_RESOURCE_ENTRIES 1 23 | 24 | /* Resource table for the given remote */ 25 | struct remote_resource_table { 26 | unsigned int version; 27 | unsigned int num; 28 | unsigned int reserved[2]; 29 | unsigned int offset[NO_RESOURCE_ENTRIES]; 30 | /* rpmsg vdev entry */ 31 | struct fw_rsc_vdev rpmsg_vdev; 32 | struct fw_rsc_vdev_vring rpmsg_vring0; 33 | struct fw_rsc_vdev_vring rpmsg_vring1; 34 | }; 35 | 36 | void *get_resource_table (int rsc_id, int *len); 37 | 38 | #if defined __cplusplus 39 | } 40 | #endif 41 | 42 | #endif /* RSC_TABLE_H_ */ 43 | -------------------------------------------------------------------------------- /apps/system/linux/machine/rv64_virt/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | collect (APP_COMMON_SOURCES platform_info.c) 2 | collect (APP_COMMON_SOURCES rv64_virt_linux_proc.c) 3 | collect (APP_COMMON_SOURCES helper.c) 4 | collect (APP_COMMON_SOURCES rsc_table.c) 5 | collect (APP_INC_DIRS "${CMAKE_CURRENT_SOURCE_DIR}") 6 | if (RPMSG_NO_IPI) 7 | add_definitions(-DRPMSG_NO_IPI) 8 | endif (RPMSG_NO_IPI) 9 | 10 | -------------------------------------------------------------------------------- /apps/system/linux/machine/rv64_virt/helper.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (c) 2014, Mentor Graphics Corporation 4 | * All rights reserved. 5 | * 6 | * Copyright (c) 2015 Xilinx, Inc. All rights reserved. 7 | * 8 | * SPDX-License-Identifier: BSD-3-Clause 9 | */ 10 | #include 11 | #include 12 | #include 13 | 14 | int init_system() 15 | { 16 | struct metal_init_params metal_param = METAL_INIT_DEFAULTS; 17 | 18 | metal_init(&metal_param); 19 | 20 | return 0; 21 | } 22 | 23 | void cleanup_system() 24 | { 25 | metal_finish(); 26 | } 27 | -------------------------------------------------------------------------------- /apps/system/linux/machine/rv64_virt/platform_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Xilinx, Inc. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | /* This file populates resource table for BM remote 8 | * for use by the Linux Master */ 9 | 10 | #ifndef PLATFORM_INFO_H_ 11 | #define PLATFORM_INFO_H_ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | #if defined __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | #define RPMSG_NO_IPI 22 | #define RPU_CPU_ID 0 /* RPU remote CPU Index. We only talk to 23 | * one CPU in the exmaple. We set the CPU 24 | * index to 0. */ 25 | //#define IPI_CHN_BITMASK 0x08 /* IPI channel bit mask for IPI 26 | // * from/to RPU0 */ 27 | //#define IPI_DEV_NAME "ff360000.ipi" /* IPI device name */ 28 | #define DEV_BUS_NAME "platform" /* device bus name. "platform" bus 29 | * is used in Linux kernel for generic 30 | * devices */ 31 | /* libmetal devices names used in the examples. 32 | * They are platform devices, you find them in Linux sysfs 33 | * sys/bus/platform/devices */ 34 | #define SHM_DEV_NAME "90100000.shm" /* shared device name */ 35 | //TODO: move to common 36 | #define SHM_BASE 0x90100000UL 37 | 38 | #define RSC_MEM_PA SHM_BASE 39 | #define RSC_MEM_SIZE 0x00020000UL 40 | //shared buffer: 0x90120000--0x90160000 41 | #define SHARED_BUF_PA (SHM_BASE + RSC_MEM_SIZE) 42 | #define SHARED_BUF_SIZE 0x00040000UL 43 | //TODO: move to common end 44 | #define RING_SIZE 0x00004000UL 45 | //start: 0x90160000 46 | #define RING_TX (SHARED_BUF_PA + SHARED_BUF_SIZE) 47 | //start: 0x90164000 48 | #define RING_RX (RING_TX + RING_SIZE) 49 | 50 | #ifdef RPMSG_NO_IPI 51 | #define POLL_DEV_NAME "90000000.shm" /* shared device name */ 52 | #define POLL_STOP 0x1U 53 | #endif /* RPMSG_NO_IPI */ 54 | 55 | struct remoteproc_priv { 56 | const char *ipi_name; /**< IPI device name */ 57 | const char *ipi_bus_name; /**< IPI bus name */ 58 | const char *rsc_name; /**< rsc device name */ 59 | const char *rsc_bus_name; /**< rsc bus name */ 60 | const char *shm_name; /**< shared memory device name */ 61 | const char *shm_bus_name; /**< shared memory bus name */ 62 | struct metal_device *ipi_dev; /**< pointer to IPI device */ 63 | struct metal_io_region *ipi_io; /**< pointer to IPI i/o region */ 64 | struct metal_device *shm_dev; /**< pointer to shared memory device */ 65 | struct metal_io_region *shm_io; /**< pointer to sh mem i/o region */ 66 | 67 | struct remoteproc_mem shm_mem; /**< shared memory */ 68 | unsigned int ipi_chn_mask; /**< IPI channel mask */ 69 | atomic_int ipi_nokick; 70 | #ifdef RPMSG_NO_IPI 71 | const char *shm_poll_name; /**< shared memory device name */ 72 | const char *shm_poll_bus_name; /**< shared memory bus name */ 73 | struct metal_device *shm_poll_dev; /**< pointer to poll mem device */ 74 | struct metal_io_region *shm_poll_io; /**< pointer to poll mem i/o */ 75 | #endif /* RPMSG_NO_IPI */ 76 | 77 | }; 78 | 79 | 80 | /** 81 | * platform_init - initialize the platform 82 | * 83 | * It will initialize the platform. 84 | * 85 | * @argc: number of arguments 86 | * @argv: array of the input arguements 87 | * @platform: pointer to store the platform data pointer 88 | * 89 | * return 0 for success or negative value for failure 90 | */ 91 | int platform_init(int argc, char *argv[], void **platform); 92 | 93 | /** 94 | * platform_create_rpmsg_vdev - create rpmsg vdev 95 | * 96 | * It will create rpmsg virtio device, and returns the rpmsg virtio 97 | * device pointer. 98 | * 99 | * @platform: pointer to the private data 100 | * @vdev_index: index of the virtio device, there can more than one vdev 101 | * on the platform. 102 | * @role: virtio master or virtio slave of the vdev 103 | * @rst_cb: virtio device reset callback 104 | * @ns_bind_cb: rpmsg name service bind callback 105 | * 106 | * return pointer to the rpmsg virtio device 107 | */ 108 | struct rpmsg_device * 109 | platform_create_rpmsg_vdev(void *platform, unsigned int vdev_index, 110 | unsigned int role, 111 | void (*rst_cb)(struct virtio_device *vdev), 112 | rpmsg_ns_bind_cb ns_bind_cb); 113 | 114 | /** 115 | * platform_poll - platform poll function 116 | * 117 | * @platform: pointer to the platform 118 | * 119 | * return negative value for errors, otherwise 0. 120 | */ 121 | int platform_poll(void *platform); 122 | 123 | /** 124 | * platform_release_rpmsg_vdev - release rpmsg virtio device 125 | * 126 | * @rpdev: pointer to the rpmsg device 127 | */ 128 | void platform_release_rpmsg_vdev(struct rpmsg_device *rpdev, void *platform); 129 | 130 | /** 131 | * platform_cleanup - clean up the platform resource 132 | * 133 | * @platform: pointer to the platform 134 | */ 135 | void platform_cleanup(void *platform); 136 | 137 | #if defined __cplusplus 138 | } 139 | #endif 140 | 141 | #endif /* PLATFORM_INFO_H_ */ 142 | 143 | -------------------------------------------------------------------------------- /apps/system/linux/machine/rv64_virt/rsc_table.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Mentor Graphics Corporation 3 | * All rights reserved. 4 | * Copyright (c) 2016 Xilinx, Inc. All rights reserved. 5 | * Copyright (c) 2020 Bamvor Jian ZHANG. All rights reserved. 6 | * 7 | * SPDX-License-Identifier: BSD-3-Clause 8 | */ 9 | 10 | #include 11 | #include "platform_info.h" 12 | #include "rsc_table.h" 13 | 14 | #define RPMSG_IPU_C0_FEATURES 1 15 | 16 | /* VirtIO rpmsg device id */ 17 | #define VIRTIO_ID_RPMSG_ 7 18 | 19 | /* Remote supports Name Service announcement */ 20 | #define VIRTIO_RPMSG_F_NS 0 21 | 22 | #define NUM_VRINGS 0x02 23 | #define VRING_ALIGN 0x1000 24 | #define VRING_SIZE 256 25 | 26 | #define NUM_TABLE_ENTRIES 1 27 | 28 | struct remote_resource_table resources = { 29 | /* Version */ 30 | 1, 31 | 32 | /* NUmber of table entries */ 33 | NUM_TABLE_ENTRIES, 34 | /* reserved fields */ 35 | {0, 0,}, 36 | 37 | /* Offsets of rsc entries */ 38 | { 39 | offsetof(struct remote_resource_table, rpmsg_vdev), 40 | }, 41 | 42 | /* Virtio device entry */ 43 | { 44 | RSC_VDEV, VIRTIO_ID_RPMSG_, 0, RPMSG_IPU_C0_FEATURES, 0, 0, 0, 45 | NUM_VRINGS, {0, 0}, 46 | }, 47 | 48 | /* Vring rsc entry - part of vdev rsc entry */ 49 | {RING_TX, VRING_ALIGN, VRING_SIZE, 1, 0}, 50 | {RING_RX, VRING_ALIGN, VRING_SIZE, 2, 0}, 51 | }; 52 | 53 | void *get_resource_table (int rsc_id, int *len) 54 | { 55 | (void) rsc_id; 56 | *len = sizeof(resources); 57 | return &resources; 58 | } 59 | -------------------------------------------------------------------------------- /apps/system/linux/machine/rv64_virt/rsc_table.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Mentor Graphics Corporation 3 | * All rights reserved. 4 | * Copyright (c) 2016 Xilinx, Inc. All rights reserved. 5 | * 6 | * SPDX-License-Identifier: BSD-3-Clause 7 | */ 8 | 9 | /* This file populates resource table for BM remote 10 | * for use by the Linux Master */ 11 | 12 | #ifndef RSC_TABLE_H_ 13 | #define RSC_TABLE_H_ 14 | 15 | #include 16 | #include 17 | 18 | #if defined __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | #define NO_RESOURCE_ENTRIES 8 23 | 24 | /* Resource table for the given remote */ 25 | struct remote_resource_table { 26 | unsigned int version; 27 | unsigned int num; 28 | unsigned int reserved[2]; 29 | unsigned int offset[NO_RESOURCE_ENTRIES]; 30 | /* rpmsg vdev entry */ 31 | struct fw_rsc_vdev rpmsg_vdev; 32 | struct fw_rsc_vdev_vring rpmsg_vring0; 33 | struct fw_rsc_vdev_vring rpmsg_vring1; 34 | }; 35 | 36 | void *get_resource_table (int rsc_id, int *len); 37 | 38 | #if defined __cplusplus 39 | } 40 | #endif 41 | 42 | #endif /* RSC_TABLE_H_ */ 43 | -------------------------------------------------------------------------------- /apps/system/linux/machine/zynqmp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | collect (APP_COMMON_SOURCES helper.c) 2 | 3 | -------------------------------------------------------------------------------- /apps/system/linux/machine/zynqmp/helper.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (c) 2014, Mentor Graphics Corporation 4 | * All rights reserved. 5 | * 6 | * Copyright (c) 2015 Xilinx, Inc. All rights reserved. 7 | * 8 | * SPDX-License-Identifier: BSD-3-Clause 9 | */ 10 | #include 11 | #include 12 | #include 13 | 14 | int init_system() 15 | { 16 | struct metal_init_params metal_param = METAL_INIT_DEFAULTS; 17 | 18 | metal_init(&metal_param); 19 | 20 | return 0; 21 | } 22 | 23 | void cleanup_system() 24 | { 25 | metal_finish(); 26 | } 27 | -------------------------------------------------------------------------------- /apps/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_subdirectory (msg) 3 | -------------------------------------------------------------------------------- /apps/tests/msg/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set (_cflags "${CMAKE_C_FLAGS} ${APP_EXTRA_C_FLAGS} -fdata-sections -ffunction-sections") 3 | set (_fw_dir "${APPS_SHARE_DIR}") 4 | 5 | collector_list (_list PROJECT_INC_DIRS) 6 | collector_list (_app_list APP_INC_DIRS) 7 | include_directories (${_list} ${_app_list} ${CMAKE_CURRENT_SOURCE_DIR}) 8 | 9 | collector_list (_list PROJECT_LIB_DIRS) 10 | collector_list (_app_list APP_LIB_DIRS) 11 | link_directories (${_list} ${_app_list}) 12 | 13 | get_property (_linker_opt GLOBAL PROPERTY APP_LINKER_OPT) 14 | collector_list (_deps PROJECT_LIB_DEPS) 15 | 16 | set (OPENAMP_LIB open_amp) 17 | 18 | foreach (_app msg-test-rpmsg-ping msg-test-rpmsg-update msg-test-rpmsg-flood-ping) 19 | collector_list (_sources APP_COMMON_SOURCES) 20 | if (${_app} STREQUAL "msg-test-rpmsg-ping") 21 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/rpmsg-ping.c") 22 | elseif (${_app} STREQUAL "msg-test-rpmsg-update") 23 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/rpmsg-update.c") 24 | elseif (${_app} STREQUAL "msg-test-rpmsg-flood-ping") 25 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/rpmsg-flood-ping.c") 26 | endif (${_app} STREQUAL "msg-test-rpmsg-ping") 27 | 28 | if (WITH_SHARED_LIB) 29 | add_executable (${_app}-shared ${_sources}) 30 | target_link_libraries (${_app}-shared ${OPENAMP_LIB}-shared ${_deps}) 31 | install (TARGETS ${_app}-shared RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 32 | endif (WITH_SHARED_LIB) 33 | 34 | if (WITH_STATIC_LIB) 35 | if (${PROJECT_SYSTEM} STREQUAL "linux") 36 | add_executable (${_app}-static ${_sources}) 37 | target_link_libraries (${_app}-static ${OPENAMP_LIB}-static ${_deps}) 38 | install (TARGETS ${_app}-static RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 39 | else (${PROJECT_SYSTEM}) 40 | add_executable (${_app}.out ${_sources}) 41 | set_source_files_properties(${_sources} PROPERTIES COMPILE_FLAGS "${_cflags}") 42 | 43 | target_link_libraries(${_app}.out -Wl,-Map=${_app}.map -Wl,--gc-sections ${_linker_opt} -Wl,--start-group ${OPENAMP_LIB}-static ${_deps} -Wl,--end-group) 44 | 45 | install (TARGETS ${_app}.out RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 46 | endif (${PROJECT_SYSTEM} STREQUAL "linux" ) 47 | endif (WITH_STATIC_LIB) 48 | endforeach(_app) 49 | -------------------------------------------------------------------------------- /apps/tests/msg/rpmsg-ping.h: -------------------------------------------------------------------------------- 1 | #ifndef RPMSG_PING_H 2 | #define RPMSG_PING_H 3 | 4 | #define RPMSG_SERVICE_NAME "rpmsg-openamp-demo-channel" 5 | 6 | #endif /* RPMSG_PING_H */ 7 | -------------------------------------------------------------------------------- /apps/tests/msg/rpmsg-update.c: -------------------------------------------------------------------------------- 1 | /* This is a sample demonstration application that showcases usage of rpmsg 2 | This application is meant to run on the remote CPU running baremetal code. 3 | This application echoes back data that was sent to it by the master core. */ 4 | 5 | #include 6 | #include 7 | #include 8 | #include "platform_info.h" 9 | #include "rpmsg-ping.h" 10 | 11 | #define SHUTDOWN_MSG 0xEF56A55A 12 | 13 | #define LPRINTF(format, ...) printf(format, ##__VA_ARGS__) 14 | //#define LPRINTF(format, ...) 15 | #define LPERROR(format, ...) LPRINTF("ERROR: " format, ##__VA_ARGS__) 16 | 17 | static struct rpmsg_endpoint lept; 18 | static int shutdown_req = 0; 19 | 20 | /* External functions */ 21 | extern int init_system(void); 22 | extern void cleanup_system(void); 23 | 24 | /*-----------------------------------------------------------------------------* 25 | * RPMSG endpoint callbacks 26 | *-----------------------------------------------------------------------------*/ 27 | static int rpmsg_endpoint_cb(struct rpmsg_endpoint *ept, void *data, size_t len, 28 | uint32_t src, void *priv) 29 | { 30 | (void)priv; 31 | (void)src; 32 | 33 | /* On reception of a shutdown we signal the application to terminate */ 34 | if ((*(unsigned int *)data) == SHUTDOWN_MSG) { 35 | LPRINTF("shutdown message is received.\r\n"); 36 | shutdown_req = 1; 37 | return RPMSG_SUCCESS; 38 | } 39 | 40 | /* Send data back to master */ 41 | while (1) { 42 | int ret; 43 | 44 | ret = rpmsg_send(ept, data, len); 45 | if (ret == RPMSG_ERR_NO_BUFF) { 46 | LPRINTF("%s, wait for buffer\r\n", __func__); 47 | continue; 48 | } else { 49 | if (ret < 0) 50 | LPERROR("rpmsg_send, size %lu failed %d\r\n", 51 | (unsigned long)len, ret); 52 | break; 53 | } 54 | } 55 | return RPMSG_SUCCESS; 56 | } 57 | 58 | static void rpmsg_service_unbind(struct rpmsg_endpoint *ept) 59 | { 60 | (void)ept; 61 | LPRINTF("unexpected Remote endpoint destroy\r\n"); 62 | shutdown_req = 1; 63 | } 64 | 65 | /*-----------------------------------------------------------------------------* 66 | * Application 67 | *-----------------------------------------------------------------------------*/ 68 | int rpmsg_update_app(struct rpmsg_device *rdev, void *priv) 69 | { 70 | int ret; 71 | 72 | /* Initialize RPMSG framework */ 73 | LPRINTF("Try to create rpmsg endpoint.\r\n"); 74 | 75 | ret = rpmsg_create_ept(&lept, rdev, RPMSG_SERVICE_NAME, 76 | RPMSG_ADDR_ANY, RPMSG_ADDR_ANY, 77 | rpmsg_endpoint_cb, 78 | rpmsg_service_unbind); 79 | if (ret) { 80 | LPERROR("Failed to create endpoint.\r\n"); 81 | return -1; 82 | } 83 | 84 | LPRINTF("Successfully created rpmsg endpoint.\r\n"); 85 | while(1) { 86 | platform_poll(priv); 87 | /* we got a shutdown request, exit */ 88 | if (shutdown_req) { 89 | break; 90 | } 91 | } 92 | rpmsg_destroy_ept(&lept); 93 | 94 | return 0; 95 | } 96 | 97 | /*-----------------------------------------------------------------------------* 98 | * Application entry point 99 | *-----------------------------------------------------------------------------*/ 100 | #ifdef METAL_SYSTEM_RTTHREAD 101 | static int __rpmsg_update(int argc, char *argv[]); 102 | 103 | int rpmsg_update() 104 | { 105 | __rpmsg_update(1, NULL); 106 | } 107 | #ifdef RT_USING_FINSH 108 | FINSH_FUNCTION_EXPORT(rpmsg_update, rpmsg echo); 109 | #endif /* #ifdef RT_USING_FINSH */ 110 | #ifdef FINSH_USING_MSH 111 | MSH_CMD_EXPORT(rpmsg_update, rpmsg echo); 112 | #endif /* #ifdef FINSH_USING_MSH */ 113 | 114 | static int __rpmsg_update(int argc, char *argv[]) 115 | #else 116 | int main(int argc, char *argv[]) 117 | #endif /* #ifdef METAL_SYSTEM_RTTHREAD */ 118 | { 119 | void *platform; 120 | struct rpmsg_device *rpdev; 121 | int ret; 122 | 123 | LPRINTF("Starting application...\r\n"); 124 | #ifdef METAL_SYSTEM_RTTHREAD 125 | //Make rt-thread happy 126 | shutdown_req = 0; 127 | memset(&lept, 0, sizeof(lept)); 128 | #endif /* #ifdef FINSH_USING_MSH */ 129 | 130 | /* Initialize platform */ 131 | ret = platform_init(argc, argv, &platform); 132 | if (ret) { 133 | LPERROR("Failed to initialize platform.\r\n"); 134 | ret = -1; 135 | } else { 136 | rpdev = platform_create_rpmsg_vdev(platform, 0, 137 | VIRTIO_DEV_SLAVE, 138 | NULL, NULL); 139 | if (!rpdev) { 140 | LPERROR("Failed to create rpmsg virtio device.\r\n"); 141 | ret = -1; 142 | } else { 143 | app(rpdev, platform); 144 | platform_release_rpmsg_vdev(rpdev,0); 145 | ret = 0; 146 | } 147 | } 148 | 149 | LPRINTF("Stopping application...\r\n"); 150 | platform_cleanup(platform); 151 | 152 | return ret; 153 | } 154 | -------------------------------------------------------------------------------- /apps/tests/msg/rpmsg-update.c.orig: -------------------------------------------------------------------------------- 1 | /* This is a sample demonstration application that showcases usage of rpmsg 2 | This application is meant to run on the remote CPU running baremetal code. 3 | This application echoes back data that was sent to it by the master core. */ 4 | 5 | #include 6 | #include 7 | #include 8 | #include "platform_info.h" 9 | #include "rpmsg-ping.h" 10 | 11 | #define SHUTDOWN_MSG 0xEF56A55A 12 | 13 | #define LPRINTF(format, ...) printf(format, ##__VA_ARGS__) 14 | //#define LPRINTF(format, ...) 15 | #define LPERROR(format, ...) LPRINTF("ERROR: " format, ##__VA_ARGS__) 16 | 17 | static struct rpmsg_endpoint lept; 18 | static int shutdown_req = 0; 19 | 20 | /* External functions */ 21 | extern int init_system(void); 22 | extern void cleanup_system(void); 23 | 24 | /*-----------------------------------------------------------------------------* 25 | * RPMSG endpoint callbacks 26 | *-----------------------------------------------------------------------------*/ 27 | static int rpmsg_endpoint_cb(struct rpmsg_endpoint *ept, void *data, size_t len, 28 | uint32_t src, void *priv) 29 | { 30 | (void)priv; 31 | (void)src; 32 | 33 | /* On reception of a shutdown we signal the application to terminate */ 34 | if ((*(unsigned int *)data) == SHUTDOWN_MSG) { 35 | LPRINTF("shutdown message is received.\r\n"); 36 | shutdown_req = 1; 37 | return RPMSG_SUCCESS; 38 | } 39 | 40 | /* Send data back to master */ 41 | while (1) { 42 | int ret; 43 | 44 | ret = rpmsg_send(ept, data, len); 45 | if (ret == RPMSG_ERR_NO_BUFF) { 46 | LPRINTF("%s, wait for buffer\r\n", __func__); 47 | continue; 48 | } else { 49 | if (ret < 0) 50 | LPERROR("rpmsg_send, size %lu failed %d\r\n", 51 | (unsigned long)len, ret); 52 | break; 53 | } 54 | } 55 | return RPMSG_SUCCESS; 56 | } 57 | 58 | static void rpmsg_service_unbind(struct rpmsg_endpoint *ept) 59 | { 60 | (void)ept; 61 | LPRINTF("unexpected Remote endpoint destroy\r\n"); 62 | shutdown_req = 1; 63 | } 64 | 65 | /*-----------------------------------------------------------------------------* 66 | * Application 67 | *-----------------------------------------------------------------------------*/ 68 | int rpmsg_update_app(struct rpmsg_device *rdev, void *priv) 69 | { 70 | int ret; 71 | 72 | /* Initialize RPMSG framework */ 73 | LPRINTF("Try to create rpmsg endpoint.\r\n"); 74 | 75 | ret = rpmsg_create_ept(&lept, rdev, RPMSG_SERVICE_NAME, 76 | RPMSG_ADDR_ANY, RPMSG_ADDR_ANY, 77 | rpmsg_endpoint_cb, 78 | rpmsg_service_unbind); 79 | if (ret) { 80 | LPERROR("Failed to create endpoint.\r\n"); 81 | return -1; 82 | } 83 | 84 | LPRINTF("Successfully created rpmsg endpoint.\r\n"); 85 | while(1) { 86 | platform_poll(priv); 87 | /* we got a shutdown request, exit */ 88 | if (shutdown_req) { 89 | break; 90 | } 91 | } 92 | rpmsg_destroy_ept(&lept); 93 | 94 | return 0; 95 | } 96 | 97 | /*-----------------------------------------------------------------------------* 98 | * Application entry point 99 | *-----------------------------------------------------------------------------*/ 100 | #ifdef METAL_SYSTEM_RTTHREAD 101 | static int __rpmsg_update(int argc, char *argv[]); 102 | 103 | int rpmsg_update() 104 | { 105 | __rpmsg_update(1, NULL); 106 | } 107 | #ifdef RT_USING_FINSH 108 | FINSH_FUNCTION_EXPORT(rpmsg_update, rpmsg echo); 109 | #endif /* #ifdef RT_USING_FINSH */ 110 | #ifdef FINSH_USING_MSH 111 | MSH_CMD_EXPORT(rpmsg_update, rpmsg echo); 112 | #endif /* #ifdef FINSH_USING_MSH */ 113 | 114 | static int __rpmsg_update(int argc, char *argv[]) 115 | #else 116 | int main(int argc, char *argv[]) 117 | #endif /* #ifdef METAL_SYSTEM_RTTHREAD */ 118 | { 119 | void *platform; 120 | struct rpmsg_device *rpdev; 121 | int ret; 122 | 123 | LPRINTF("Starting application...\r\n"); 124 | 125 | /* Initialize platform */ 126 | ret = platform_init(argc, argv, &platform); 127 | if (ret) { 128 | LPERROR("Failed to initialize platform.\r\n"); 129 | ret = -1; 130 | } else { 131 | rpdev = platform_create_rpmsg_vdev(platform, 0, 132 | VIRTIO_DEV_SLAVE, 133 | NULL, NULL); 134 | if (!rpdev) { 135 | LPERROR("Failed to create rpmsg virtio device.\r\n"); 136 | ret = -1; 137 | } else { 138 | app(rpdev, platform); 139 | platform_release_rpmsg_vdev(rpdev); 140 | ret = 0; 141 | } 142 | } 143 | 144 | LPRINTF("Stopping application...\r\n"); 145 | platform_cleanup(platform); 146 | 147 | return ret; 148 | } 149 | -------------------------------------------------------------------------------- /apps/tests/msg/rpmsg-update.c.rej: -------------------------------------------------------------------------------- 1 | --- apps/tests/msg/rpmsg-update.c 2 | +++ apps/tests/msg/rpmsg-update.c 3 | @@ -139,7 +156,7 @@ int main(int argc, char *argv[]) 4 | LPERROR("Failed to create rpmsg virtio device.\r\n"); 5 | ret = -1; 6 | } else { 7 | - app(rpdev, platform); 8 | + rpmsg_update_app(rpdev, platform); 9 | platform_release_rpmsg_vdev(rpdev, platform); 10 | ret = 0; 11 | } 12 | -------------------------------------------------------------------------------- /apps/tests/msg/rpmsg-update.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigmagic123/openamp/f793a2503fbb9085df79d31bb5184157e3fc1470/apps/tests/msg/rpmsg-update.o -------------------------------------------------------------------------------- /cmake/collect.cmake: -------------------------------------------------------------------------------- 1 | function (collector_create name base) 2 | set_property (GLOBAL PROPERTY "COLLECT_${name}_LIST") 3 | set_property (GLOBAL PROPERTY "COLLECT_${name}_BASE" "${base}") 4 | endfunction (collector_create) 5 | 6 | function (collector_list var name) 7 | get_property (_list GLOBAL PROPERTY "COLLECT_${name}_LIST") 8 | set (${var} "${_list}" PARENT_SCOPE) 9 | endfunction (collector_list) 10 | 11 | function (collector_base var name) 12 | get_property (_base GLOBAL PROPERTY "COLLECT_${name}_BASE") 13 | set (${var} "${_base}" PARENT_SCOPE) 14 | endfunction (collector_base) 15 | 16 | function (collect name) 17 | collector_base (_base ${name}) 18 | string(COMPARE NOTEQUAL "${_base}" "" _is_rel) 19 | set (_list) 20 | foreach (s IN LISTS ARGN) 21 | if (_is_rel) 22 | get_filename_component (s "${s}" ABSOLUTE) 23 | file (RELATIVE_PATH s "${_base}" "${s}") 24 | else (_is_rel) 25 | get_filename_component (ts "${s}" ABSOLUTE) 26 | if (EXISTS "${ts}") 27 | set (s "${ts}") 28 | endif (EXISTS "${ts}") 29 | endif (_is_rel) 30 | list (APPEND _list "${s}") 31 | endforeach () 32 | set_property (GLOBAL APPEND PROPERTY "COLLECT_${name}_LIST" "${_list}") 33 | endfunction (collect) 34 | 35 | # Create global collectors 36 | collector_create (PROJECT_INC_DIRS "") 37 | collector_create (PROJECT_LIB_DIRS "") 38 | collector_create (PROJECT_LIB_DEPS "") 39 | 40 | # vim: expandtab:ts=2:sw=2:smartindent 41 | -------------------------------------------------------------------------------- /cmake/depends.cmake: -------------------------------------------------------------------------------- 1 | if (WITH_LIBMETAL_FIND) 2 | find_package (Libmetal REQUIRED) 3 | collect (PROJECT_INC_DIRS "${LIBMETAL_INCLUDE_DIR}") 4 | collect (PROJECT_LIB_DIRS "${LIBMETAL_LIB_DIR}") 5 | collect (PROJECT_LIB_DEPS "${LIBMETAL_LIB}") 6 | endif (WITH_LIBMETAL_FIND) 7 | 8 | if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") 9 | check_include_files (stdatomic.h HAVE_STDATOMIC_H) 10 | check_include_files (fcntl.h HAVE_FCNTL_H) 11 | else ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") 12 | set (_saved_cmake_required_flags ${CMAKE_REQUIRED_FLAGS}) 13 | set (CMAKE_REQUIRED_FLAGS "-c") 14 | check_include_files (stdatomic.h HAVE_STDATOMIC_H) 15 | check_include_files (fcntl.h HAVE_FCNTL_H) 16 | set (CMAKE_REQUIRED_FLAGS ${_saved_cmake_required_flags}) 17 | endif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") 18 | 19 | if (NOT HAVE_FCNTL_H) 20 | unset (WITH_PROXY CACHE) 21 | endif (NOT HAVE_FCNTL_H) 22 | 23 | # vim: expandtab:ts=2:sw=2:smartindent 24 | -------------------------------------------------------------------------------- /cmake/modules/FindLibmetal.cmake: -------------------------------------------------------------------------------- 1 | # FindLibmetal 2 | # -------- 3 | # 4 | # Find Libmetal 5 | # 6 | # Find the native Libmetal includes and library this module defines 7 | # 8 | # :: 9 | # 10 | # LIBMETAL_INCLUDE_DIR, where to find metal/sysfs.h, etc. 11 | # LIBSYSFS_LIB_DIR, where to find libmetal library. 12 | 13 | # FIX ME, CMAKE_FIND_ROOT_PATH doesn't work 14 | # even use the following 15 | # set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH) 16 | # set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH) 17 | # set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) 18 | find_path(LIBMETAL_INCLUDE_DIR NAMES metal/sys.h PATHS ${CMAKE_FIND_ROOT_PATH}) 19 | find_library(LIBMETAL_LIB NAMES metal PATHS ${CMAKE_FIND_ROOT_PATH}) 20 | get_filename_component(LIBMETAL_LIB_DIR ${LIBMETAL_LIB} DIRECTORY) 21 | 22 | # handle the QUIETLY and REQUIRED arguments and set HUGETLBFS_FOUND to TRUE if 23 | # all listed variables are TRUE 24 | include (FindPackageHandleStandardArgs) 25 | FIND_PACKAGE_HANDLE_STANDARD_ARGS (Libmetal DEFAULT_MSG LIBMETAL_LIB LIBMETAL_INCLUDE_DIR) 26 | 27 | if (LIBMETAL_FOUND) 28 | set (LIBMETAL_LIBS ${LIBMETAL_LIB}) 29 | endif (LIBMETAL_FOUND) 30 | 31 | mark_as_advanced (LIBMETAL_LIB LIBMETAL_INCLUDE_DIR LIBMETAL_LIB_DIR) 32 | -------------------------------------------------------------------------------- /cmake/options.cmake: -------------------------------------------------------------------------------- 1 | set (PROJECT_VER_MAJOR 0) 2 | set (PROJECT_VER_MINOR 1) 3 | set (PROJECT_VER_PATCH 0) 4 | set (PROJECT_VER 0.1.0) 5 | 6 | if (NOT DEFINED CMAKE_BUILD_TYPE) 7 | set (CMAKE_BUILD_TYPE Debug) 8 | endif (NOT DEFINED CMAKE_BUILD_TYPE) 9 | 10 | if (NOT CMAKE_INSTALL_LIBDIR) 11 | set (CMAKE_INSTALL_LIBDIR "lib") 12 | endif (NOT CMAKE_INSTALL_LIBDIR) 13 | 14 | if (NOT CMAKE_INSTALL_BINDIR) 15 | set (CMAKE_INSTALL_BINDIR "bin") 16 | endif (NOT CMAKE_INSTALL_BINDIR) 17 | 18 | set (_host "${CMAKE_HOST_SYSTEM_NAME}/${CMAKE_HOST_SYSTEM_PROCESSOR}") 19 | message ("-- Host: ${_host}") 20 | 21 | set (_target "${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR}") 22 | message ("-- Target: ${_target}") 23 | 24 | if (NOT DEFINED MACHINE) 25 | set (MACHINE "Generic") 26 | endif (NOT DEFINED MACHINE) 27 | message ("-- Machine: ${MACHINE}") 28 | 29 | string (TOLOWER ${CMAKE_SYSTEM_NAME} PROJECT_SYSTEM) 30 | string (TOUPPER ${CMAKE_SYSTEM_NAME} PROJECT_SYSTEM_UPPER) 31 | string (TOLOWER ${CMAKE_SYSTEM_PROCESSOR} PROJECT_PROCESSOR) 32 | string (TOUPPER ${CMAKE_SYSTEM_PROCESSOR} PROJECT_PROCESSOR_UPPER) 33 | string (TOLOWER ${MACHINE} PROJECT_MACHINE) 34 | string (TOUPPER ${MACHINE} PROJECT_MACHINE_UPPER) 35 | 36 | # Select which components are in the openamp lib 37 | option (WITH_PROXY "Build with proxy(access device controlled by other processor)" ON) 38 | option (WITH_APPS "Build with sample applicaitons" OFF) 39 | option (WITH_PROXY_APPS "Build with proxy sample applicaitons" OFF) 40 | if (WITH_APPS) 41 | if (WITH_PROXY) 42 | set (WITH_PROXY_APPS ON) 43 | endif (WITH_PROXY) 44 | endif (WITH_APPS) 45 | 46 | # LOAD_FW only allowed for R5, otherwise turn off 47 | if (NOT ${MACHINE} STREQUAL "zynqmp_r5") 48 | set (WITH_LOAD_FW OFF) 49 | endif(NOT ${MACHINE} STREQUAL "zynqmp_r5") 50 | 51 | option (WITH_VIRTIO_MASTER "Build with virtio master enabled" ON) 52 | option (WITH_VIRTIO_SLAVE "Build with virtio slave enabled" ON) 53 | 54 | if (NOT WITH_VIRTIO_MASTER) 55 | add_definitions(-DVIRTIO_SLAVE_ONLY) 56 | endif (NOT WITH_VIRTIO_MASTER) 57 | 58 | if (NOT WITH_VIRTIO_SLAVE) 59 | add_definitions(-DVIRTIO_MASTER_ONLY) 60 | endif (NOT WITH_VIRTIO_SLAVE) 61 | 62 | # Set the complication flags 63 | set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra") 64 | 65 | option (WITH_STATIC_LIB "Build with a static library" ON) 66 | 67 | if ("${PROJECT_SYSTEM}" STREQUAL "linux") 68 | option (WITH_SHARED_LIB "Build with a shared library" ON) 69 | endif ("${PROJECT_SYSTEM}" STREQUAL "linux") 70 | 71 | if (WITH_ZEPHYR) 72 | option (WITH_ZEPHYR_LIB "Build open-amp as a zephyr library" OFF) 73 | endif (WITH_ZEPHYR) 74 | 75 | option (WITH_LIBMETAL_FIND "Check Libmetal library can be found" ON) 76 | 77 | if (DEFINED RPMSG_BUFFER_SIZE) 78 | add_definitions( -DRPMSG_BUFFER_SIZE=${RPMSG_BUFFER_SIZE} ) 79 | endif (DEFINED RPMSG_BUFFER_SIZE) 80 | 81 | message ("-- C_FLAGS : ${CMAKE_C_FLAGS}") 82 | # vim: expandtab:ts=2:sw=2:smartindent 83 | -------------------------------------------------------------------------------- /cmake/platforms/cross_generic_gcc.cmake: -------------------------------------------------------------------------------- 1 | set (CMAKE_SYSTEM_NAME "Generic" CACHE STRING "") 2 | 3 | include (CMakeForceCompiler) 4 | 5 | CMAKE_FORCE_C_COMPILER ("${CROSS_PREFIX}gcc" GNU) 6 | CMAKE_FORCE_CXX_COMPILER ("${CROSS_PREFIX}g++" GNU) 7 | 8 | set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER CACHE STRING "") 9 | set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER CACHE STRING "") 10 | set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER CACHE STRING "") 11 | 12 | # vim: expandtab:ts=2:sw=2:smartindent 13 | -------------------------------------------------------------------------------- /cmake/platforms/cross_linux_gcc.cmake: -------------------------------------------------------------------------------- 1 | set (CMAKE_SYSTEM_NAME "Linux") 2 | set (CMAKE_C_COMPILER "${CROSS_PREFIX}gcc") 3 | set (CMAKE_CXX_COMPILER "${CROSS_PREFIX}g++") 4 | 5 | set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 6 | set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER) 7 | set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER) 8 | 9 | # vim: expandtab:ts=2:sw=2:smartindent 10 | -------------------------------------------------------------------------------- /cmake/platforms/zynq7_generic.cmake: -------------------------------------------------------------------------------- 1 | set (CMAKE_SYSTEM_PROCESSOR "arm" CACHE STRING "") 2 | set (MACHINE "zynq7" CACHE STRING "") 3 | set (CROSS_PREFIX "arm-none-eabi-" CACHE STRING "") 4 | set (CMAKE_C_FLAGS "-mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard" CACHE STRING "") 5 | 6 | include (cross_generic_gcc) 7 | 8 | # vim: expandtab:ts=2:sw=2:smartindent 9 | -------------------------------------------------------------------------------- /cmake/platforms/zynq7_linux.cmake: -------------------------------------------------------------------------------- 1 | set (CMAKE_SYSTEM_PROCESSOR "arm") 2 | set (CROSS_PREFIX "arm-xilinx-linux-gnueabi-") 3 | 4 | include (cross-linux-gcc) 5 | 6 | # vim: expandtab:ts=2:sw=2:smartindent 7 | -------------------------------------------------------------------------------- /cmake/platforms/zynqmp_a53_generic.cmake: -------------------------------------------------------------------------------- 1 | set (CMAKE_SYSTEM_PROCESSOR "arm64") 2 | set (CROSS_PREFIX "aarch64-none-elf-") 3 | 4 | include (cross_generic_gcc) 5 | 6 | # vim: expandtab:ts=2:sw=2:smartindent 7 | -------------------------------------------------------------------------------- /cmake/platforms/zynqmp_linux.cmake: -------------------------------------------------------------------------------- 1 | set (CMAKE_SYSTEM_PROCESSOR "arm64") 2 | set (CROSS_PREFIX "aarch64-linux-gnu-") 3 | set (MACHINE "zynqmp" CACHE STRING "") 4 | 5 | include (cross_linux_gcc) 6 | 7 | # vim: expandtab:ts=2:sw=2:smartindent 8 | -------------------------------------------------------------------------------- /cmake/platforms/zynqmp_r5_generic.cmake: -------------------------------------------------------------------------------- 1 | set (CMAKE_SYSTEM_PROCESSOR "arm" CACHE STRING "") 2 | set (MACHINE "zynqmp_r5" CACHE STRING "") 3 | set (CROSS_PREFIX "armr5-none-eabi-" CACHE STRING "") 4 | 5 | # Xilinx SDK version earlier than 2017.2 use mfloat-abi=soft by default to generat libxil 6 | set (CMAKE_C_FLAGS "-mfloat-abi=hard -mfpu=vfpv3-d16 -mcpu=cortex-r5" CACHE STRING "") 7 | 8 | include (cross_generic_gcc) 9 | 10 | # vim: expandtab:ts=2:sw=2:smartindent 11 | -------------------------------------------------------------------------------- /cmake/syscheck.cmake: -------------------------------------------------------------------------------- 1 | # use "Generic" as CMAKE_SYSTEM_NAME 2 | 3 | if (WITH_ZEPHYR) 4 | set (CMAKE_SYSTEM_NAME "Generic" CACHE STRING "") 5 | string (TOLOWER "Zephyr" PROJECT_SYSTEM) 6 | string (TOUPPER "Zephyr" PROJECT_SYSTEM_UPPER) 7 | if (NOT WITH_ZEPHYR_LIB) 8 | include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) 9 | endif () 10 | if (CONFIG_CPU_CORTEX_M) 11 | set (MACHINE "cortexm" CACHE STRING "") 12 | endif (CONFIG_CPU_CORTEX_M) 13 | endif (WITH_ZEPHYR) 14 | -------------------------------------------------------------------------------- /docs/apps/echo_test/README.md: -------------------------------------------------------------------------------- 1 | 2 | # echo_test 3 | This readme is about the OpenAMP echo_test demo. 4 | The echo_test is about one processor sends message to the other one, and the other one echo back the message. The processor which sends the message will verify the echo message. 5 | 6 | For now, it implements Linux sends the message, and the baremetal echos back. 7 | 8 | ## Compilation 9 | 10 | ### Baremetal Compilation 11 | Option `WITH_ECHO_TEST` is to control if the application will be built. 12 | By default this option is `ON` when `WITH_APPS` is on. 13 | 14 | Here is an example: 15 | 16 | ``` 17 | $ cmake ../open-amp -DCMAKE_TOOLCHAIN_FILE=zynq7_generic -DWITH_OBSOLETE=on -DWITH_APPS=ON 18 | ``` 19 | 20 | ### Linux Compilation 21 | 22 | #### Linux Kernel Compilation 23 | You will need to manually compile the following kernel modules with your Linux kernel (Please refer to Linux kernel documents for how to add kernel module): 24 | 25 | * Your machine's remoteproc kernel driver 26 | * `obsolete/apps/echo_test/system/linux/kernelspace/rpmsg_user_dev_driver` if you want to run the echo_test app in Linux user space. 27 | * `obsolete/system/linux/kernelspace/rpmsg_echo_test_kern_app` if you want to run the echo_test app in Linux kernel space. 28 | 29 | #### Linux Userspace Compliation 30 | * Compile `obsolete/apps/echo_test/system/linux/userspace/echo_test` into your Linux OS. 31 | * If you are running generic(baremetal) system as remoteproc slave, and Linux as remoteproc master, please also add the built generic `echo_test` executable to the firmware of your Linux OS. 32 | 33 | ## Run the Demo 34 | 35 | ### Load the Demo 36 | After Linux boots, 37 | * Load the machine remoteproc. If Linux runs as remoteproc master, you will need to pass the other processor's echo_test binary as firmware arguement to the remoteproc module. 38 | * If you run the Linux kernel application demo, load the `rpmsg_echo_test_kern_app` module. You will see the kernel application send the message to remote and the remote reply back and the kernel application will verify the result. 39 | * If you run the userspace application demo, load the `rpmsg_user_dev_driver` module. 40 | * If you run the userspace application demo, you will see the similar output on the console: 41 | ``` 42 | **************************************** 43 | Please enter command and press enter key 44 | **************************************** 45 | 1 - Send data to remote core, retrieve the echo and validate its integrity .. 46 | 2 - Quit this application .. 47 | CMD> 48 | ``` 49 | * Input `1` to send packages. 50 | * Input `2` to exit the application. 51 | 52 | After you run the demo, you will need to unload the kernel modules. 53 | 54 | ### Unload the Demo 55 | * If you run the userspace application demo, unload the `rpmsg_user_dev_driver` module. 56 | * If you run the kernelspace application demo, unload the `rpmsg_echo_test_kern_app` module. 57 | * Unload the machine remoteproc driver. 58 | 59 | -------------------------------------------------------------------------------- /docs/apps/matrix_multiply/README.md: -------------------------------------------------------------------------------- 1 | 2 | # matrix_multiply 3 | This readme is about the OpenAMP matrix_multiply demo. 4 | The matrix_multiply is about one processor generates two matrices, and send them to the one, and the other one calcuate the matrix multiplicaiton and return the result matrix. 5 | 6 | For now, it implements Linux generates the matrices, and the baremetal calculate the matrix mulitplication and send back the result. 7 | 8 | ## Compilation 9 | 10 | ### Baremetal Compilation 11 | Option `WITH_MATRIX_MULTIPLY` is to control if the application will be built. 12 | By default this option is `ON` when `WITH_APPS` is on. 13 | 14 | Here is an example: 15 | 16 | ``` 17 | $ cmake ../open-amp -DCMAKE_TOOLCHAIN_FILE=zynq7_generic -DWITH_OBSOLETE=on -DWITH_APPS=ON 18 | ``` 19 | 20 | ### Linux Compilation 21 | 22 | #### Linux Kernel Compilation 23 | You will need to manually compile the following kernel modules with your Linux kernel (Please refer to Linux kernel documents for how to add kernel module): 24 | 25 | * Your machine's remoteproc kernel driver 26 | * `obsolete/system/linux/kernelspace/rpmsg_user_dev_driver` if you want to run the matrix_multiply app in Linux user space. 27 | * `obsolete/apps/matrix_multiply/system/linux/kernelspace/rpmsg_mat_mul_kern_app` if you want to run the matrix_multiply app in Linux kernel space. 28 | 29 | #### Linux Userspace Compliation 30 | * Compile `obsolete/apps/matrix_multiply/system/linux/userspace/mat_mul_demo` into your Linux OS. 31 | * If you are running generic(baremetal) system as remoteproc slave, and Linux as remoteproc master, please also add the built generic `matrix_multiply` executable to the firmware of your Linux OS. 32 | 33 | ## Run the Demo 34 | 35 | ### Load the Demo 36 | After Linux boots, 37 | * Load the machine remoteproc. If Linux runs as remoteproc master, you will need to pass the other processor's matrix_multiply binary as firmware arguement to the remoteproc module. 38 | * If you run the Linux kernel application demo, load the `rpmsg_mat_mul_kern_app` module, you will see the kernel app will generate two matrices to the other processor, and output the result matrix returned by the other processor. 39 | * If you run the userspace application demo, load the `rpmsg_user_dev_driver` module. 40 | * If you run the userspace application demo `mat_mul_demo`, you will see the similar output on the console: 41 | ``` 42 | **************************************** 43 | Please enter command and press enter key 44 | **************************************** 45 | 1 - Generates random 6x6 matrices and transmits them to remote core over rpmsg 46 | .. 47 | 2 - Quit this application .. 48 | CMD> 49 | ``` 50 | * Input `1` to run the matrix multiplication. 51 | * Input `2` to exit the application. 52 | 53 | After you run the demo, you will need to unload the kernel modules. 54 | 55 | ### Unload the Demo 56 | * If you run the userspace application demo, unload the `rpmsg_user_dev_driver` module. 57 | * If you run the kernelspace application demo, unload the `rpmsg_mat_mul_kern_app` module. 58 | * Unload the machine remoteproc driver. 59 | 60 | -------------------------------------------------------------------------------- /docs/apps/rpc_demo/README.md: -------------------------------------------------------------------------------- 1 | 2 | # rpc_demo 3 | This readme is about the OpenAMP rpc_demo demo. 4 | The rpc_demo is about one processor uses the UART on the other processor and create file on the other processor's filesystem with file operations. 5 | 6 | For now, It implements the processor running generic(baremetal) applicaiton access the devices on the Linux. 7 | 8 | ## Compilation 9 | 10 | ### Baremetal Compilation 11 | Option `WITH_RPC_DEMO` is to control if the application will be built. 12 | By default this option is `ON` when `WITH_APPS` is on. 13 | 14 | Here is an example: 15 | 16 | ``` 17 | $ cmake ../open-amp -DCMAKE_TOOLCHAIN_FILE=zynq7_generic -DWITH_OBSOLETE=on -DWITH_APPS=ON 18 | ``` 19 | 20 | ### Linux Compilation 21 | 22 | #### Linux Kernel Compilation 23 | You will need to manually compile the following kernel modules with your Linux kernel (Please refer to Linux kernel documents for how to add kernel module): 24 | 25 | * Your machine's remoteproc kernel driver 26 | * `obsolete/apps/rpc_demo/system/linux/kernelspace/rpmsg_proxy_dev_driver` 27 | 28 | #### Linux Userspace Compliation 29 | * Compile `obsolete/apps/rpc_demo/system/linux/userspace/proxy_app` into your Linux OS. 30 | * Add the built generic `rpc_demo` executable to the firmware of your Linux OS. 31 | 32 | ## Run the Demo 33 | After Linux boots, run `proxy_app` as follows: 34 | ``` 35 | # proxy_app [-m REMOTEPROC_MODULE] [-f PATH_OF_THE_RPC_DEMO_FIRMWARE] 36 | ``` 37 | 38 | The demo application will load the remoteproc module, then the proxy rpmsg module, will output message sent from the other processor, send the console input back to the other processor. When the demo application exits, it will unload the kernel modules. 39 | -------------------------------------------------------------------------------- /docs/img-src/coprocessor-rpmsg-ns.gv: -------------------------------------------------------------------------------- 1 | // RPMsg dynamic endpoints binding 2 | 3 | digraph G { 4 | rankdir="LR"; 5 | 6 | subgraph roles { 7 | node [style="filled", fillcolor="lightblue"]; 8 | master [label="Master"]; 9 | slave [label="Slave"]; 10 | } 11 | 12 | subgraph m_comment_nodes { 13 | node [group=m_comment, shape="note", style="filled", fillcolor="yellow"]; 14 | rank="same"; 15 | m_remoteproc_init_comment [label="this is initialize rproc call"]; 16 | m_remoteproc_boot_comment [label="it will setup vdev before booting the remote"]; 17 | m_rpmsg_vdev_init_comment [label="\l* It will initialize vrings with the shared memory\l* As vdev doesn't support name service, it will not create name service endpoint;\l* it sets vdev status to DRVIER_READY, And will notify remote.\l"]; 18 | m_rpmsg_create_ep_comment [label="\lIf vdev supports name service,\lit will send out name service.\l"]; 19 | m_rpmsg_send_comment [label="\lIf endpoint hasn't binded, it fail\lreturn failure to indicate ep hasn't been binded.\l"]; 20 | 21 | } 22 | 23 | subgraph m_flow_nodes { 24 | node [shape="box"]; 25 | rank="same"; 26 | m_remoteproc_init [label="rproc = remoteproc_init(&remoteproc_ops, &arg);"] 27 | m_remoteproc_load [label="calls remoteproc_load() to load applicaiton"]; 28 | m_remoteproc_boot [shape="box", label="ret=remoteproc_boot(&rproc)"]; 29 | m_remoteproc_get_vdev [label="vdev=remoteproc_create_virtio(rproc, rpmsg_vdev_id, MASTER, NULL);"]; 30 | m_rpmsg_shmpool_init[label="rpmsg_virtio_init_shm_pool(shpool, shbuf, shbuf_pool_size);"]; 31 | m_rpmsg_vdev_init [label="rpdev=rpmsg_init_vdev(rpvdev, vdev, ns_bind_cb, &shm_io, shpool);"]; 32 | m_rpmsg_ns_cb [label="\lrpmsg_ns_callback() will see if there is a local ep registered.\lIf yes, bind the ep; otherwise, call ns_bind_cb.\l"]; 33 | m_rpmsg_create_ep [label="\lept=rpmsg_create_ept(ept, rdev, ept_name, ept_addr, dest_addr, \lendpoint_cb, ns_unbind_cb);\l"]; 34 | m_rpmsg_send [label="rpmsg_send(ept,data)"]; 35 | m_rpmsg_rx_cb [label="rpmsg_rx_callback()"]; 36 | m_ep_cb [label="endpoint_cb(ept, data, size, src_addr)"]; 37 | m_rpmsg_destroy_ep [label="rpmsg_destroy_endpoint(ept)"]; 38 | 39 | m_remoteproc_init -> m_remoteproc_load -> m_remoteproc_boot -> m_remoteproc_get_vdev -> 40 | m_rpmsg_shmpool_init -> m_rpmsg_vdev_init -> m_rpmsg_ns_cb -> m_rpmsg_create_ep -> m_rpmsg_send; 41 | m_rpmsg_send -> m_rpmsg_rx_cb -> m_ep_cb -> 42 | m_rpmsg_destroy_ep [dir="none", style="dashed"]; 43 | } 44 | 45 | subgraph s_flow_nodes { 46 | rank="same"; 47 | node [shape="box"]; 48 | s_remoteproc_init [label="rproc = remoteproc_init(&remoteproc_ops, &arg);"]; 49 | 50 | s_remoteproc_parse_rsc [label="ret = remoteproc_set_rsc_table(rproc, &rsc_table, rsc_size)"]; 51 | s_remoteproc_get_vdev [label="vdev=remoteproc_create_virtio(rproc, rpmsg_vdev_id, SLAVE, rst_cb);"]; 52 | s_rpmsg_vdev_init [label="rpdev=rpmsg_init_vdev(rpvdev, vdev, ns_bind_cb, &shm_io, NULL);"]; 53 | s_rpmsg_create_ep [label="\lept=rpmsg_create_ept(ept, rdev, ept_name, ept_addr, dest_addr, \lendpoint_cb, ns_unbind_cb);\l"]; 54 | s_rpmsg_ns_cb [label="\lrpmsg_ns_callback() will see if there is a local ep registered.\lIf yes, bind the ep; otherwise, call ns_binc_cb.\l"]; 55 | s_rpmsg_send [label="rpmsg_send(ept,data)"]; 56 | s_rpmsg_rx_cb [label="rpmsg_rx_callback()"]; 57 | s_ep_cb [label="endpoint_cb(ept, data, size, src_addr)"]; 58 | s_rpmsg_ns_unbind_cb [label="\lrpmsg_ns_callback() will call the previous\lregistered endpoint unbind callback\l"]; 59 | 60 | s_remoteproc_init -> s_remoteproc_parse_rsc -> s_remoteproc_get_vdev -> 61 | s_rpmsg_vdev_init -> s_rpmsg_create_ep; 62 | s_rpmsg_create_ep -> s_rpmsg_ns_cb -> s_rpmsg_rx_cb -> 63 | s_ep_cb -> s_rpmsg_send -> s_rpmsg_ns_unbind_cb [dir="none", style="dash"]; 64 | 65 | } 66 | 67 | subgraph s_comment_nodes { 68 | node [group=s_comment, shape="note", style="filled", fillcolor="yellow"]; 69 | rank="same"; 70 | s_rpmsg_vdev_init_comment [label="\l* If vdev supports name service, it will create name service endpoint;\l* It will not return until the master set status to DRIVER READY\l"]; 71 | s_rpmsg_rx_cb_comment [label="\l* It will look for the endpoint which matches the destination address.\lIf the two endpoints hasn't binded yet,\lit will set the local endpoint's destination address with the source address in the message\l"]; 72 | } 73 | 74 | master -> m_remoteproc_init [dir="none"]; 75 | slave -> s_remoteproc_init [dir="none"]; 76 | s_rpmsg_create_ep -> m_rpmsg_ns_cb [label="NS annoucement"]; 77 | m_rpmsg_create_ep -> s_rpmsg_ns_cb [label="NS annoucement"]; 78 | m_rpmsg_send -> s_rpmsg_rx_cb [label="RPMsg data"]; 79 | s_rpmsg_send -> m_rpmsg_rx_cb [label="RPMsg data"]; 80 | m_rpmsg_destroy_ep -> s_rpmsg_ns_unbind_cb [label="Endpoint destroy NS"]; 81 | 82 | m_remoteproc_init_comment -> m_remoteproc_init [dir="none"]; 83 | m_remoteproc_boot_comment -> m_remoteproc_boot [dir="none"]; 84 | m_rpmsg_vdev_init_comment -> m_rpmsg_vdev_init [dir="none"]; 85 | m_rpmsg_create_ep_comment -> m_rpmsg_create_ep [dir="none"]; 86 | m_rpmsg_send_comment -> m_rpmsg_send [dir="none"]; 87 | 88 | s_rpmsg_vdev_init -> s_rpmsg_vdev_init_comment [dir="none"]; 89 | s_rpmsg_rx_cb -> s_rpmsg_rx_cb_comment [dir="none"]; 90 | 91 | {rank=same; master; m_remoteproc_init} 92 | {rank=same; slave; s_remoteproc_init} 93 | 94 | } 95 | 96 | -------------------------------------------------------------------------------- /docs/img-src/coprocessor-rpmsg-static-ep.gv: -------------------------------------------------------------------------------- 1 | // RPMsg static endpoints 2 | 3 | digraph G { 4 | rankdir="LR"; 5 | 6 | subgraph roles { 7 | node [style="filled", fillcolor="lightblue"]; 8 | master [label="Master"]; 9 | slave [label="Slave"]; 10 | } 11 | 12 | subgraph m_comment_nodes { 13 | node [group=m_comment, shape="note", style="filled", fillcolor="yellow"]; 14 | rank="same"; 15 | m_remoteproc_init_comment [label="this is initialize rproc call"]; 16 | m_remoteproc_boot_comment [label="it will setup vdev before booting the remote"]; 17 | m_rpmsg_vdev_init_comment [label="\l* It will initialize vrings with the shared memory\l* As vdev doesn't support name service, it will not create name service endpoint;\l* it sets vdev status to DRVIER_READY, And will notify remote.\l"]; 18 | m_rpmsg_create_ep_comment [label="\lAs vdev doesn't supports name service,\lit will not send out name service.\l"]; 19 | } 20 | 21 | subgraph m_flow_nodes { 22 | node [shape="box"]; 23 | rank="same"; 24 | m_remoteproc_init [label="rproc = remoteproc_init(&remoteproc_ops, &arg);"]; 25 | m_remoteproc_load [label="calls remoteproc_load() to load applicaiton"]; 26 | m_remoteproc_boot [shape="box", label="ret=remoteproc_boot(&rproc)"]; 27 | m_remoteproc_get_vdev [label="vdev=remoteproc_create_virtio(rproc, rpmsg_vdev_id, MASTER, NULL);"]; 28 | m_rpmsg_shmpool_init[label="rpmsg_virtio_init_shm_pool(shpool, shbuf, shbuf_pool_size);"]; 29 | m_rpmsg_vdev_init [label="rpdev=rpmsg_init_vdev(rpvdev, vdev, ns_bind_cb, &shm_io, shpool);"]; 30 | m_rpmsg_create_ep [label="\lept=rpmsg_create_ept(ept, rdev, ept_name, ept_addr, dest_addr, \lendpoint_cb, ns_unbind_cb);\l"]; 31 | m_rpmsg_send [label="rpmsg_send(ept,data)"]; 32 | m_rpmsg_rx_cb [label="rpmsg_rx_callback()"]; 33 | m_ep_cb [label="endpoint_cb(ept, data, size, src_addr)"]; 34 | m_rpmsg_destroy_ep [label="rpmsg_destroy_endpoint(ept)"]; 35 | 36 | m_remoteproc_init -> m_remoteproc_load -> m_remoteproc_boot -> m_remoteproc_get_vdev -> 37 | m_rpmsg_shmpool_init -> m_rpmsg_vdev_init -> m_rpmsg_create_ep -> m_rpmsg_send; 38 | m_rpmsg_send -> m_rpmsg_rx_cb -> m_ep_cb -> 39 | m_rpmsg_destroy_ep [dir="none", style="dashed"]; 40 | } 41 | 42 | subgraph s_flow_nodes { 43 | rank="same"; 44 | node [shape="box"]; 45 | s_remoteproc_init [label="rproc = remoteproc_init(&remoteproc_ops, &arg);"]; 46 | 47 | s_remoteproc_parse_rsc [label="ret = remoteproc_set_rsc_table(rproc, &rsc_table, rsc_size)"]; 48 | s_remoteproc_get_vdev [label="vdev=remoteproc_create_virtio(rproc, rpmsg_vdev_id, SLAVE, rst_cb);"]; 49 | s_rpmsg_vdev_init [label="rpdev=rpmsg_init_vdev(rpvdev, vdev, ns_bind_cb, &shm_io, NULL);"]; 50 | s_rpmsg_create_ep [label="\lept=rpmsg_create_ept(ept, rdev, ept_name, ept_addr, dest_addr, \lendpoint_cb, ns_unbind_cb);\l"]; 51 | s_rpmsg_send [label="rpmsg_send(ept,data)"]; 52 | s_rpmsg_rx_cb [label="rpmsg_rx_callback()"]; 53 | s_ep_cb [label="endpoint_cb(ept, data, size, src_addr)"]; 54 | s_rpmsg_destroy_ep [label="rpmsg_destroy_endpoint(ept)"]; 55 | 56 | s_remoteproc_init -> s_remoteproc_parse_rsc -> s_remoteproc_get_vdev -> 57 | s_rpmsg_vdev_init -> s_rpmsg_create_ep; 58 | s_rpmsg_create_ep -> s_rpmsg_rx_cb -> 59 | s_ep_cb -> s_rpmsg_send -> s_rpmsg_destroy_ep [dir="none", style="dash"]; 60 | 61 | } 62 | 63 | subgraph s_comment_nodes { 64 | node [group=s_comment, shape="note", style="filled", fillcolor="yellow"]; 65 | rank="same"; 66 | s_rpmsg_vdev_init_comment [label="\l* As vdev doesn't support name service, it will not create name service endpoint;\l* It will not return until the master set status to DRIVER READY\l"]; 67 | s_rpmsg_rx_cb_comment [label="\l* It will look for the endpoint which matches the destination address.\lIf no endpoint has found, it will drop the message.\l"]; 68 | } 69 | 70 | master -> m_remoteproc_init [dir="none"]; 71 | slave -> s_remoteproc_init [dir="none"]; 72 | m_rpmsg_send -> s_rpmsg_rx_cb [label="RPMsg data"]; 73 | s_rpmsg_send -> m_rpmsg_rx_cb [label="RPMsg data"]; 74 | 75 | m_remoteproc_init_comment -> m_remoteproc_init [dir="none"]; 76 | m_remoteproc_boot_comment -> m_remoteproc_boot [dir="none"]; 77 | m_rpmsg_vdev_init_comment -> m_rpmsg_vdev_init [dir="none"]; 78 | m_rpmsg_create_ep_comment -> m_rpmsg_create_ep [dir="none"]; 79 | 80 | s_rpmsg_vdev_init -> s_rpmsg_vdev_init_comment [dir="none"]; 81 | s_rpmsg_rx_cb -> s_rpmsg_rx_cb_comment [dir="none"]; 82 | 83 | {rank=same; master; m_remoteproc_init} 84 | {rank=same; slave; s_remoteproc_init} 85 | 86 | } 87 | 88 | -------------------------------------------------------------------------------- /docs/img-src/gen-graph.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import os 3 | import pydot 4 | import sys 5 | import warnings 6 | 7 | def gen_graph_from_gv(ifile, odir, oformat="png"): 8 | (graph,) = pydot.graph_from_dot_file(ifile) 9 | gen_graph_func = getattr(graph, "write_" + oformat) 10 | filename = os.path.basename(ifile) 11 | ofile = odir + "/" + os.path.splitext(filename)[0] + "." + oformat 12 | gen_graph_func(ofile) 13 | 14 | parser = argparse.ArgumentParser(description='Process some integers.') 15 | parser.add_argument('-i', "--infile", action="append", 16 | help="graphviz file path") 17 | parser.add_argument('-o', '--outdir', 18 | help='sum the integers (default: find the max)') 19 | parser.add_argument('-f', '--outformat', default="png", 20 | help='output image format (default: png)') 21 | 22 | args = parser.parse_args() 23 | 24 | # Image source directory 25 | img_src_dir = os.path.dirname(os.path.realpath(sys.argv[0])) 26 | 27 | img_files = [] 28 | if args.infile: 29 | for f in args.infile: 30 | if not os.path.isfile(f): 31 | f = img_src_dir + "/" + f 32 | if not os.path.isfile(f): 33 | warnings.warn("Input file: " + f + " doesn't exist.") 34 | else: 35 | img_files.append(f) 36 | else: 37 | for f in os.listdir(img_src_dir): 38 | if f.endswith(".gv"): 39 | img_files.append(img_src_dir + "/" + f) 40 | 41 | if not img_files: 42 | sys.exit("ERROR: no found image files.") 43 | 44 | oformat = args.outformat 45 | 46 | if args.outdir: 47 | odir = args.outdir 48 | if not os.path.isdir(odir): 49 | sys.exit("--outdir " + odir + "doesn't exist") 50 | else: 51 | odir = os.path.dirname(img_src_dir) + "/img" 52 | 53 | for f in img_files: 54 | print("Generating " + oformat + " for " + f + " ...") 55 | gen_graph_from_gv(f, odir, oformat) 56 | -------------------------------------------------------------------------------- /docs/img-src/rproc-lcm-state-machine.gv: -------------------------------------------------------------------------------- 1 | // Remoteproc Life Cycle Management State Machine 2 | 3 | digraph G { 4 | rankdir="LR" 5 | st_offline [label="Offline"] 6 | st_configured [label="Configured"] 7 | st_ready [label="Ready"] 8 | st_running [label="Running"] 9 | st_stopped [label="Stopped"] 10 | 11 | st_offline -> st_configured 12 | st_configured -> st_ready 13 | st_ready -> st_running 14 | st_ready -> st_stopped 15 | st_stopped -> st_offline 16 | st_running -> st_stopped 17 | 18 | {rank=same; st_configured; st_ready; st_running} 19 | } 20 | -------------------------------------------------------------------------------- /docs/img/coprocessor-rpmsg-ns-dynamic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigmagic123/openamp/f793a2503fbb9085df79d31bb5184157e3fc1470/docs/img/coprocessor-rpmsg-ns-dynamic.png -------------------------------------------------------------------------------- /docs/img/coprocessor-rpmsg-ns.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigmagic123/openamp/f793a2503fbb9085df79d31bb5184157e3fc1470/docs/img/coprocessor-rpmsg-ns.png -------------------------------------------------------------------------------- /docs/img/coprocessor-rpmsg-static-ep.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigmagic123/openamp/f793a2503fbb9085df79d31bb5184157e3fc1470/docs/img/coprocessor-rpmsg-static-ep.png -------------------------------------------------------------------------------- /docs/img/menuconfig_openamp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigmagic123/openamp/f793a2503fbb9085df79d31bb5184157e3fc1470/docs/img/menuconfig_openamp.png -------------------------------------------------------------------------------- /docs/img/rproc-lcm-state-machine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigmagic123/openamp/f793a2503fbb9085df79d31bb5184157e3fc1470/docs/img/rproc-lcm-state-machine.png -------------------------------------------------------------------------------- /docs/img/select_openamp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigmagic123/openamp/f793a2503fbb9085df79d31bb5184157e3fc1470/docs/img/select_openamp.png -------------------------------------------------------------------------------- /docs/img/smpvsamp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigmagic123/openamp/f793a2503fbb9085df79d31bb5184157e3fc1470/docs/img/smpvsamp.png -------------------------------------------------------------------------------- /docs/remoteproc-design.md: -------------------------------------------------------------------------------- 1 | # Remoteproc Design Document 2 | Remoteproc provides abstraction to manage the life cycle of a remote 3 | application. For now, it only provides APIs on bringing up and 4 | tearing down the remote application, and parsing resource table. 5 | It will extend to crash detection, suspend and resume. 6 | 7 | ## Remoteproc LCM States 8 | | State | State Description | 9 | |:------|:------------------| 10 | | Offline | Initial state of a remoteproc instance. The remote presented by the remoteproc instance and its resource has been powered off. | 11 | | Configured | The remote presented by the remoteproc instance has been configured. And ready to load applicaiton. | 12 | | Ready | The remote presented by the remoteproc instance has applicaiton loaded, and ready to run. | 13 | | Stopped | The remote presented by the remoteproc instance has stopped from running. But the remote is still powered on. And the remote's resource hasn't been released. | 14 | 15 | ![Rproc LCM States](img/rproc-lcm-state-machine.png) 16 | 17 | ### State Transition 18 | | State Transition | Transition Trigger | 19 | |:-----------------|:-------------------| 20 | | Offline -> Configured | Configure the remote to make it able to load application;
`remoteproc_configure(&rproc, &config_data)`| 21 | | Configured -> Ready | load firmware ;
`remoteproc_load(&rproc, &path, &image_store, &image_store_ops, &image_info)` | 22 | | Ready -> Running | start the processor;
`remoteproc_start(&rproc)` | 23 | | Ready -> Stopped | stop the processor;
`remoteproc_stop(&rproc)`;
`remoteproc_shutdown(&rproc)`(Stopped is the intermediate state of shutdown operation) | 24 | | Running -> Stopped | stop the processor;
`remoteproc_stop(&rproc)`;
`remoteproc_shutdown(&rproc)` | 25 | | Stopped -> Offline | shutdown the processor;
`remoteproc_shutdown(&rproc)` | 26 | 27 | ## Remote User APIs 28 | * Initialize remoteproc instance: 29 | ``` 30 | struct remoteproc *remoteproc_init(struct remoteproc *rproc, 31 | struct remoteproc_ops *ops, void *priv) 32 | ``` 33 | * Release remoteproc instance: 34 | ``` 35 | int remoteproc_remove(struct remoteproc *rproc) 36 | ``` 37 | * Add memory to remoteproc: 38 | ``` 39 | void remoteproc_add_mem(struct remoteproc *rproc, struct remoteproc_mem *mem) 40 | ``` 41 | * Get memory libmetal I/O region from remoteproc specifying memory name: 42 | ``` 43 | struct metal_io_region *remoteproc_get_io_with_name(struct remoteproc *rproc, const char *name) 44 | ``` 45 | * Get memory libmetal I/O region from remoteproc specifying physical address: 46 | ``` 47 | struct metal_io_region *remoteproc_get_io_with_pa(struct remoteproc *rproc, metal_phys_addr_t pa); 48 | ``` 49 | * Get memory libmetal I/O region from remoteproc specifying virtual address: 50 | ``` 51 | struct metal_io_region *remoteproc_get_io_with_va(struct remoteproc *rproc, void *va); 52 | ``` 53 | * Map memory and add the memory to the remoteproc instance: 54 | ``` 55 | void *remoteproc_mmap(struct remoteproc *rproc, 56 | metal_phys_addr_t *pa, metal_phys_addr_t *da, 57 | size_t size, unsigned int attribute, 58 | struct metal_io_region **io); 59 | ``` 60 | * Set resource table to remoteproc: 61 | ``` 62 | int remoteproc_set_rsc_table(struct remoteproc *rproc, 63 | struct resource_table *rsc_table, 64 | size_t rsc_size) 65 | ``` 66 | * Configure the remote presented by the remoteproc instance to make it able 67 | to load applicaiton: 68 | ``` 69 | int remoteproc_config(struct remoteproc *rproc, void *data) 70 | ``` 71 | * Load application to the remote presented by the remoteproc instance to make 72 | it ready to run: 73 | ``` 74 | int remoteproc_load(struct remoteproc *rproc, const char *path, 75 | void *store, struct image_store_ops *store_ops, 76 | void **img_info) 77 | ``` 78 | * Run application on the remote presented by the remoteproc instance: 79 | ``` 80 | int remoteproc_start(struct remoteproc *rproc) 81 | ``` 82 | * Stop application on remote presented by the remoteproc instance: 83 | ``` 84 | int remoteproc_stop(struct remoteproc *rproc) 85 | ``` 86 | * Shutdown the remote presented by the remoteproc instance: 87 | ``` 88 | int remoteproc_shutdown(struct remoteproc *rproc) 89 | ``` 90 | * Create virtio device from the resource table vdev resource, and add it to the 91 | remoteproc instance: 92 | ``` 93 | struct virtio_device *remoteproc_create_virtio(struct remoteproc *rproc, 94 | int vdev_id, unsigned int role, 95 | void (*rst_cb)(struct virtio_device *vdev)) 96 | ``` 97 | * Remove virtio device from the remoteproc instance: 98 | ``` 99 | void remoteproc_remove_virtio(struct remoteproc *rproc, 100 | struct virtio_device *vdev) 101 | ``` 102 | 103 | 104 | -------------------------------------------------------------------------------- /docs/rpmsg-design.md: -------------------------------------------------------------------------------- 1 | # RPMsg Design Document 2 | RPMsg is a framework to allow communication between two processors. 3 | RPMsg implementation in OpenAMP library is based on virtio. It complies 4 | the RPMsg Linux kernel implementation. It defines the handshaking on 5 | setting up and tearing down the communication between applicaitons 6 | running on two processors. 7 | 8 | ## RPMsg User API Flow Chats 9 | ### RPMsg Static Endpoint 10 | ![Static Endpoint](img/coprocessor-rpmsg-static-ep.png) 11 | ### Binding Endpoint Dynamically with Name Service 12 | ![Binding Endpoint Dynamically with Name Service](img/coprocessor-rpmsg-ns.png) 13 | ### Creating Endpoint Dynamically with Name Service 14 | ![Creating Endpoint Dynamically with Name Service](img/coprocessor-rpmsg-ns-dynamic.png) 15 | 16 | ## RPMsg User APIs 17 | * RPMsg virtio master to initialize the shared buffers pool(RPMsg virtio slave 18 | doesn't need to use this API): 19 | ``` 20 | void rpmsg_virtio_init_shm_pool(struct rpmsg_virtio_shm_pool *shpool, 21 | void *shbuf, size_t size) 22 | ``` 23 | * Initialize RPMsg virtio device: 24 | ``` 25 | int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev, 26 | struct virtio_device *vdev, 27 | rpmsg_ns_bind_cb ns_bind_cb, 28 | struct metal_io_region *shm_io, 29 | struct rpmsg_virtio_shm_pool *shpool) 30 | ``` 31 | * Deinitialize RPMsg virtio device: 32 | ``` 33 | void rpmsg_deinit_vdev(struct rpmsg_virtio_device *rvdev)` 34 | ``` 35 | * Get RPMsg device from RPMsg virtio device: 36 | ``` 37 | struct rpmsg_device *rpmsg_virtio_get_rpmsg_device(struct rpmsg_virtio_device *rvdev) 38 | ``` 39 | * Create RPMsg endpoint: 40 | ``` 41 | int rpmsg_create_ept(struct rpmsg_endpoint *ept, 42 | struct rpmsg_device *rdev, 43 | const char *name, uint32_t src, uint32_t dest, 44 | rpmsg_ept_cb cb, rpmsg_ns_unbind_cb ns_unbind_cb) 45 | ``` 46 | * Destroy RPMsg endpoint: 47 | ``` 48 | void rpmsg_destroy_ept(struct rpsmg_endpoint *ept) 49 | ``` 50 | * Check if the local RPMsg endpoint is binded to the remote, and ready to send 51 | message: 52 | ``` 53 | int is_rpmsg_ept_ready(struct rpmsg_endpoint *ept) 54 | ``` 55 | * Send message with RPMsg endpoint default binding: 56 | ``` 57 | int rpmsg_send(struct rpmsg_endpoint *ept, const void *data, int len) 58 | ``` 59 | * Send message with RPMsg endpoint, specify destination address: 60 | ``` 61 | int rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len, 62 | uint32_t dst) 63 | ``` 64 | * Send message with RPMsg endpoint using explicit source and destination 65 | addresses: 66 | ``` 67 | int rpmsg_send_offchannel(struct rpmsg_endpoint *ept, 68 | uint32_t src, uint32_t dst, 69 | const void *data, int len) 70 | ``` 71 | * Try to send message with RPMsg endpoint default binding, if no buffer 72 | available, returns: 73 | ``` 74 | int rpmsg_trysend(struct rpmsg_endpoint *ept, const void *data, 75 | int len) 76 | ``` 77 | * Try to send message with RPMsg endpoint, specify destination address, 78 | if no buffer available, returns: 79 | ``` 80 | int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, int len, 81 | uint32_t dst) 82 | ``` 83 | * Try to send message with RPMsg endpoint using explicit source and destination 84 | addresses, if no buffer available, returns: 85 | ``` 86 | int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, 87 | uint32_t src, uint32_t dst, 88 | const void *data, int len)` 89 | ``` 90 | ## RPMsg User Defined Callbacks 91 | * RPMsg endpoint message received callback: 92 | ``` 93 | int (*rpmsg_ept_cb)(struct rpmsg_endpoint *ept, void *data, 94 | size_t len, uint32_t src, void *priv) 95 | ``` 96 | * RPMsg name service binding callback. If user defines such callback, when 97 | there is a name service announcement arrives, if there is no registered 98 | endpoint found to bind to this name service, it will call this callback. 99 | If this callback is not defined, it will drop this name service.: 100 | ``` 101 | void (*rpmsg_ns_bind_cb)(struct rpmsg_device *rdev, 102 | const char *name, uint32_t dest) 103 | ``` 104 | * RPMsg endpoint name service unbind callback. If user defines such callback, 105 | when there is name service destroy arrives, it will call this callback to 106 | notify the user application about the remote has destroyed the service.: 107 | ``` 108 | void (*rpmsg_ns_unbind_cb)(struct rpmsg_endpoint *ept) 109 | ``` 110 | -------------------------------------------------------------------------------- /lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set_property (GLOBAL PROPERTY "PROJECT_LIB_EXTRA_CFLAGS") 3 | 4 | collector_create (PROJECT_LIB_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}") 5 | collect (PROJECT_LIB_DIRS "${CMAKE_CURRENT_BINARY_DIR}") 6 | collect (PROJECT_INC_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include") 7 | 8 | 9 | add_subdirectory (virtio) 10 | add_subdirectory (rpmsg) 11 | add_subdirectory (remoteproc) 12 | 13 | if (WITH_PROXY) 14 | add_subdirectory (proxy) 15 | endif (WITH_PROXY) 16 | 17 | set (OPENAMP_LIB open_amp) 18 | 19 | if (NOT CMAKE_INSTALL_LIBDIR) 20 | set (CMAKE_INSTALL_LIBDIR "lib") 21 | endif (NOT CMAKE_INSTALL_LIBDIR) 22 | 23 | collector_list (_include PROJECT_INC_DIRS) 24 | include_directories (${_include}) 25 | 26 | collector_list (_deps PROJECT_LIB_DEPS) 27 | 28 | get_property (_ecflags GLOBAL PROPERTY "PROJECT_LIB_EXTRA_CFLAGS") 29 | 30 | collector_list (_sources PROJECT_LIB_SOURCES) 31 | set_property (SOURCE ${_sources} 32 | APPEND_STRING PROPERTY COMPILE_FLAGS " ${_ecflags}") 33 | 34 | # Build a shared library if so configured. 35 | if (WITH_ZEPHYR) 36 | zephyr_library_named(${OPENAMP_LIB}) 37 | add_dependencies(${ZEPHYR_CURRENT_LIBRARY} ${OFFSETS_H_TARGET}) 38 | zephyr_library_sources(${_sources}) 39 | zephyr_include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) 40 | else (WITH_ZEPHYR) 41 | if (WITH_SHARED_LIB) 42 | set (_lib ${OPENAMP_LIB}-shared) 43 | add_library (${_lib} SHARED ${_sources}) 44 | target_link_libraries (${_lib} ${_deps}) 45 | install (TARGETS ${_lib} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) 46 | set_target_properties (${_lib} PROPERTIES 47 | OUTPUT_NAME "${OPENAMP_LIB}" 48 | VERSION "${PROJECT_VER}" 49 | SOVERSION "${PROJECT_VER_MAJOR}" 50 | ) 51 | endif (WITH_SHARED_LIB) 52 | 53 | if (WITH_STATIC_LIB) 54 | set (_lib ${OPENAMP_LIB}-static) 55 | add_library (${_lib} STATIC ${_sources}) 56 | install (TARGETS ${_lib} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) 57 | set_target_properties (${_lib} PROPERTIES 58 | OUTPUT_NAME "${OPENAMP_LIB}" 59 | ) 60 | endif (WITH_STATIC_LIB) 61 | endif (WITH_ZEPHYR) 62 | 63 | install (DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/openamp" DESTINATION include) 64 | 65 | # vim: expandtab:ts=2:sw=2:smartindent 66 | -------------------------------------------------------------------------------- /lib/include/openamp/open_amp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Mentor Graphics Corporation 3 | * All rights reserved. 4 | * 5 | * SPDX-License-Identifier: BSD-3-Clause 6 | */ 7 | 8 | #ifndef OPEN_AMP_H_ 9 | #define OPEN_AMP_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #endif /* OPEN_AMP_H_ */ 17 | -------------------------------------------------------------------------------- /lib/include/openamp/remoteproc_loader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Mentor Graphics Corporation 3 | * All rights reserved. 4 | * 5 | * SPDX-License-Identifier: BSD-3-Clause 6 | */ 7 | 8 | /************************************************************************** 9 | * FILE NAME 10 | * 11 | * remoteproc_loader.h 12 | * 13 | * COMPONENT 14 | * 15 | * OpenAMP stack. 16 | * 17 | * DESCRIPTION 18 | * 19 | * This file provides definitions for remoteproc loader 20 | * 21 | * 22 | **************************************************************************/ 23 | #ifndef REMOTEPROC_LOADER_H_ 24 | #define REMOTEPROC_LOADER_H_ 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #if defined __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | /* Loader feature macros */ 36 | #define SUPPORT_SEEK 1UL 37 | 38 | /* Remoteproc loader any address */ 39 | #define RPROC_LOAD_ANYADDR ((metal_phys_addr_t)-1) 40 | 41 | /* Remoteproc loader Executable Image Parsing States */ 42 | /* Remoteproc loader parser initial state */ 43 | #define RPROC_LOADER_NOT_READY 0x0L 44 | /* Remoteproc loader ready to load, even it can be not finish parsing */ 45 | #define RPROC_LOADER_READY_TO_LOAD 0x10000L 46 | /* Remoteproc loader post data load */ 47 | #define RPROC_LOADER_POST_DATA_LOAD 0x20000L 48 | /* Remoteproc loader finished loading */ 49 | #define RPROC_LOADER_LOAD_COMPLETE 0x40000L 50 | /* Remoteproc loader state mask */ 51 | #define RPROC_LOADER_MASK 0x00FF0000L 52 | /* Remoteproc loader private mask */ 53 | #define RPROC_LOADER_PRIVATE_MASK 0x0000FFFFL 54 | /* Remoteproc loader reserved mask */ 55 | #define RPROC_LOADER_RESERVED_MASK 0x0F000000L 56 | 57 | /** 58 | * struct image_store_ops - user defined image store operations 59 | * @open: user defined callback to open the "firmware" to prepare loading 60 | * @close: user defined callback to close the "firmware" to clean up 61 | * after loading 62 | * @load: user defined callback to load the firmware contents to target 63 | * memory or local memory 64 | * @features: loader supported features. e.g. seek 65 | */ 66 | struct image_store_ops { 67 | int (*open)(void *store, const char *path, const void **img_data); 68 | void (*close)(void *store); 69 | int (*load)(void *store, size_t offset, size_t size, 70 | const void **data, 71 | metal_phys_addr_t pa, 72 | struct metal_io_region *io, char is_blocking); 73 | unsigned int features; 74 | }; 75 | 76 | /** 77 | * struct loader_ops - loader operations 78 | * @load_header: define how to get the executable headers 79 | * @load_data: define how to load the target data 80 | * @locate_rsc_table: define how to get the resource table target address, 81 | * offset to the ELF image file and size of the resource 82 | * table. 83 | * @release: define how to release the loader 84 | * @get_entry: get entry address 85 | * @get_load_state: get load state from the image information 86 | */ 87 | struct loader_ops { 88 | int (*load_header)(const void *img_data, size_t offset, size_t len, 89 | void **img_info, int last_state, 90 | size_t *noffset, size_t *nlen); 91 | int (*load_data)(struct remoteproc *rproc, 92 | const void *img_data, size_t offset, size_t len, 93 | void **img_info, int last_load_state, 94 | metal_phys_addr_t *da, 95 | size_t *noffset, size_t *nlen, 96 | unsigned char *padding, size_t *nmemsize); 97 | int (*locate_rsc_table)(void *img_info, metal_phys_addr_t *da, 98 | size_t *offset, size_t *size); 99 | void (*release)(void *img_info); 100 | metal_phys_addr_t (*get_entry)(void *img_info); 101 | int (*get_load_state)(void *img_info); 102 | }; 103 | 104 | #if defined __cplusplus 105 | } 106 | #endif 107 | 108 | #endif /* REMOTEPROC_LOADER_H_ */ 109 | -------------------------------------------------------------------------------- /lib/include/openamp/remoteproc_virtio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Remoteproc Virtio Framework 3 | * 4 | * Copyright(c) 2018 Xilinx Ltd. 5 | * Copyright(c) 2011 Texas Instruments, Inc. 6 | * Copyright(c) 2011 Google, Inc. 7 | * All rights reserved. 8 | * 9 | * SPDX-License-Identifier: BSD-3-Clause 10 | */ 11 | 12 | #ifndef REMOTEPROC_VIRTIO_H 13 | #define REMOTEPROC_VIRTIO_H 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #if defined __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | /* define vdev notification funciton user should implement */ 24 | typedef int (*rpvdev_notify_func)(void *priv, uint32_t id); 25 | 26 | /** 27 | * struct remoteproc_virtio 28 | * @priv pointer to private data 29 | * @vdev_rsc address of vdev resource 30 | * @vdev_rsc_io metal I/O region of vdev_info, can be NULL 31 | * @notify notification function 32 | * @vdev virtio device 33 | * @node list node 34 | */ 35 | struct remoteproc_virtio { 36 | void *priv; 37 | void *vdev_rsc; 38 | struct metal_io_region *vdev_rsc_io; 39 | rpvdev_notify_func notify; 40 | struct virtio_device vdev; 41 | struct metal_list node; 42 | }; 43 | 44 | /** 45 | * rproc_virtio_create_vdev 46 | * 47 | * Create rproc virtio vdev 48 | * 49 | * @role: 0 - virtio master, 1 - virtio slave 50 | * @notifyid: virtio device notification id 51 | * @rsc: pointer to the virtio device resource 52 | * @rsc_io: pointer to the virtio device resource I/O region 53 | * @priv: pointer to the private data 54 | * @notify: vdev and virtqueue notification function 55 | * @rst_cb: reset virtio device callback 56 | * 57 | * return pointer to the created virtio device for success, 58 | * NULL for failure. 59 | */ 60 | struct virtio_device * 61 | rproc_virtio_create_vdev(unsigned int role, unsigned int notifyid, 62 | void *rsc, struct metal_io_region *rsc_io, 63 | void *priv, 64 | rpvdev_notify_func notify, 65 | virtio_dev_reset_cb rst_cb); 66 | 67 | /** 68 | * rproc_virtio_remove_vdev 69 | * 70 | * Remove rproc virtio vdev 71 | * 72 | * @vdev - pointer to the virtio device 73 | */ 74 | void rproc_virtio_remove_vdev(struct virtio_device *vdev); 75 | 76 | /** 77 | * rproc_virtio_init_vring 78 | * 79 | * Initialize rproc virtio vring 80 | * 81 | * @vdev: pointer to the virtio device 82 | * @index: vring index in the virtio device 83 | * @notifyid: remoteproc vring notification id 84 | * @va: vring virtual address 85 | * @io: pointer to vring I/O region 86 | * @num_desc: number of descriptors 87 | * @align: vring alignment 88 | * 89 | * return 0 for success, negative value for failure. 90 | */ 91 | int rproc_virtio_init_vring(struct virtio_device *vdev, unsigned int index, 92 | unsigned int notifyid, void *va, 93 | struct metal_io_region *io, 94 | unsigned int num_descs, unsigned int align); 95 | 96 | /** 97 | * rproc_virtio_notified 98 | * 99 | * remoteproc virtio is got notified 100 | * 101 | * @vdev - pointer to the virtio device 102 | * @notifyid - notify id 103 | * 104 | * return 0 for successful, negative value for failure 105 | */ 106 | int rproc_virtio_notified(struct virtio_device *vdev, uint32_t notifyid); 107 | 108 | /** 109 | * rproc_virtio_wait_remote_ready 110 | * 111 | * Blocking function, waiting for the remote core is ready to start 112 | * communications. 113 | * 114 | * @vdev - pointer to the virtio device 115 | * 116 | * return true when remote processor is ready. 117 | */ 118 | void rproc_virtio_wait_remote_ready(struct virtio_device *vdev); 119 | 120 | #if defined __cplusplus 121 | } 122 | #endif 123 | 124 | #endif /* REMOTEPROC_VIRTIO_H */ 125 | -------------------------------------------------------------------------------- /lib/include/openamp/rpmsg_retarget.h: -------------------------------------------------------------------------------- 1 | #ifndef RPMSG_RETARGET_H 2 | #define RPMSG_RETARGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #if defined __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | /* File Operations System call definitions */ 13 | #define OPEN_SYSCALL_ID 0x1UL 14 | #define CLOSE_SYSCALL_ID 0x2UL 15 | #define WRITE_SYSCALL_ID 0x3UL 16 | #define READ_SYSCALL_ID 0x4UL 17 | #define ACK_STATUS_ID 0x5UL 18 | 19 | #define TERM_SYSCALL_ID 0x6UL 20 | 21 | #define DEFAULT_PROXY_ENDPOINT 0xFFUL 22 | 23 | struct rpmsg_rpc_data; 24 | 25 | typedef int (*rpmsg_rpc_poll)(void *arg); 26 | typedef void (*rpmsg_rpc_shutdown_cb)(struct rpmsg_rpc_data *rpc); 27 | 28 | struct rpmsg_rpc_syscall_header { 29 | int32_t int_field1; 30 | int32_t int_field2; 31 | uint32_t data_len; 32 | }; 33 | 34 | struct rpmsg_rpc_syscall { 35 | uint32_t id; 36 | struct rpmsg_rpc_syscall_header args; 37 | }; 38 | 39 | struct rpmsg_rpc_data { 40 | struct rpmsg_endpoint ept; 41 | int ept_destroyed; 42 | atomic_int nacked; 43 | void *respbuf; 44 | size_t respbuf_len; 45 | rpmsg_rpc_poll poll; 46 | void *poll_arg; 47 | rpmsg_rpc_shutdown_cb shutdown_cb; 48 | metal_mutex_t lock; 49 | struct metal_spinlock buflock; 50 | }; 51 | 52 | /** 53 | * rpmsg_rpc_init - initialize RPMsg remote procedure call 54 | * 55 | * This function is to initialize the remote procedure call 56 | * global data. RPMsg RPC will send request to remote and 57 | * wait for callback. 58 | * 59 | * @rpc: pointer to the global remote procedure call data 60 | * @rdev: pointer to the rpmsg device 61 | * @ept_name: name of the endpoint used by RPC 62 | * @ept_addr: address of the endpoint used by RPC 63 | * @ept_raddr: remote address of the endpoint used by RPC 64 | * @poll_arg: pointer to poll function argument 65 | * @poll: poll function 66 | * @shutdown_cb: shutdown callback function 67 | * 68 | * return 0 for success, and negative value for failure. 69 | */ 70 | int rpmsg_rpc_init(struct rpmsg_rpc_data *rpc, 71 | struct rpmsg_device *rdev, 72 | const char *ept_name, uint32_t ept_addr, 73 | uint32_t ept_raddr, 74 | void *poll_arg, rpmsg_rpc_poll poll, 75 | rpmsg_rpc_shutdown_cb shutdown_cb); 76 | 77 | /** 78 | * rpmsg_rpc_release - release RPMsg remote procedure call 79 | * 80 | * This function is to release remoteproc procedure call 81 | * global data. 82 | * 83 | * @rpc: pointer to the globacl remote procedure call 84 | */ 85 | void rpmsg_rpc_release(struct rpmsg_rpc_data *rpc); 86 | 87 | /** 88 | * rpmsg_rpc_send - Request RPMsg RPC call 89 | * 90 | * This function sends RPC request it will return with the length 91 | * of data and the response buffer. 92 | * 93 | * @rpc: pointer to remoteproc procedure call data struct 94 | * @req: pointer to request buffer 95 | * @len: length of the request data 96 | * @resp: pointer to where store the response buffer 97 | * @resp_len: length of the response buffer 98 | * 99 | * return length of the received response, negative value for failure. 100 | */ 101 | int rpmsg_rpc_send(struct rpmsg_rpc_data *rpc, 102 | void *req, size_t len, 103 | void *resp, size_t resp_len); 104 | 105 | /** 106 | * rpmsg_set_default_rpc - set default RPMsg RPC data 107 | * 108 | * The default RPC data is used to redirect standard C file operations 109 | * to RPMsg channels. 110 | * 111 | * @rpc: pointer to remoteproc procedure call data struct 112 | */ 113 | void rpmsg_set_default_rpc(struct rpmsg_rpc_data *rpc); 114 | 115 | #if defined __cplusplus 116 | } 117 | #endif 118 | 119 | #endif /* RPMSG_RETARGET_H */ 120 | -------------------------------------------------------------------------------- /lib/include/openamp/rsc_table_parser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Mentor Graphics Corporation 3 | * All rights reserved. 4 | * 5 | * SPDX-License-Identifier: BSD-3-Clause 6 | */ 7 | 8 | #ifndef RSC_TABLE_PARSER_H 9 | #define RSC_TABLE_PARSER_H 10 | 11 | #include 12 | 13 | #if defined __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #define RSC_TAB_SUPPORTED_VERSION 1 18 | 19 | /* Standard control request handling. */ 20 | typedef int (*rsc_handler)(struct remoteproc *rproc, void *rsc); 21 | 22 | /** 23 | * handle_rsc_table 24 | * 25 | * This function parses resource table. 26 | * 27 | * @param rproc - pointer to remote remoteproc 28 | * @param rsc_table - resource table to parse 29 | * @param len - size of rsc table 30 | * @param io - pointer to the resource table I/O region 31 | * It can be NULL if the resource table 32 | * is in the local memory. 33 | * 34 | * @returns - execution status 35 | * 36 | */ 37 | int handle_rsc_table(struct remoteproc *rproc, 38 | struct resource_table *rsc_table, size_t len, 39 | struct metal_io_region *io); 40 | int handle_carve_out_rsc(struct remoteproc *rproc, void *rsc); 41 | int handle_trace_rsc(struct remoteproc *rproc, void *rsc); 42 | int handle_vdev_rsc(struct remoteproc *rproc, void *rsc); 43 | int handle_vendor_rsc(struct remoteproc *rproc, void *rsc); 44 | 45 | /** 46 | * find_rsc 47 | * 48 | * find out location of a resource type in the resource table. 49 | * 50 | * @rsc_table - pointer to the resource table 51 | * @rsc_type - type of the resource 52 | * @index - index of the resource of the specified type 53 | * 54 | * return the offset to the resource on success, or 0 on failure 55 | */ 56 | size_t find_rsc(void *rsc_table, unsigned int rsc_type, unsigned int index); 57 | 58 | #if defined __cplusplus 59 | } 60 | #endif 61 | 62 | #endif /* RSC_TABLE_PARSER_H */ 63 | -------------------------------------------------------------------------------- /lib/include/openamp/virtio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-3-Clause 3 | * 4 | * $FreeBSD$ 5 | */ 6 | 7 | #ifndef _VIRTIO_H_ 8 | #define _VIRTIO_H_ 9 | 10 | #include 11 | #include 12 | 13 | #if defined __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | /* VirtIO device IDs. */ 18 | #define VIRTIO_ID_NETWORK 0x01UL 19 | #define VIRTIO_ID_BLOCK 0x02UL 20 | #define VIRTIO_ID_CONSOLE 0x03UL 21 | #define VIRTIO_ID_ENTROPY 0x04UL 22 | #define VIRTIO_ID_BALLOON 0x05UL 23 | #define VIRTIO_ID_IOMEMORY 0x06UL 24 | #define VIRTIO_ID_RPMSG 0x07UL /* remote processor messaging */ 25 | #define VIRTIO_ID_SCSI 0x08UL 26 | #define VIRTIO_ID_9P 0x09UL 27 | #define VIRTIO_DEV_ANY_ID (-1)UL 28 | 29 | /* Status byte for guest to report progress. */ 30 | #define VIRTIO_CONFIG_STATUS_ACK 0x01 31 | #define VIRTIO_CONFIG_STATUS_DRIVER 0x02 32 | #define VIRTIO_CONFIG_STATUS_DRIVER_OK 0x04 33 | #define VIRTIO_CONFIG_STATUS_NEEDS_RESET 0x40 34 | #define VIRTIO_CONFIG_STATUS_FAILED 0x80 35 | 36 | /* Virtio device role */ 37 | #define VIRTIO_DEV_MASTER 0UL 38 | #define VIRTIO_DEV_SLAVE 1UL 39 | 40 | struct virtio_device_id { 41 | uint32_t device; 42 | uint32_t vendor; 43 | }; 44 | 45 | /* 46 | * Generate interrupt when the virtqueue ring is 47 | * completely used, even if we've suppressed them. 48 | */ 49 | #define VIRTIO_F_NOTIFY_ON_EMPTY (1 << 24) 50 | 51 | /* 52 | * The guest should never negotiate this feature; it 53 | * is used to detect faulty drivers. 54 | */ 55 | #define VIRTIO_F_BAD_FEATURE (1 << 30) 56 | 57 | /* 58 | * Some VirtIO feature bits (currently bits 28 through 31) are 59 | * reserved for the transport being used (eg. virtio_ring), the 60 | * rest are per-device feature bits. 61 | */ 62 | #define VIRTIO_TRANSPORT_F_START 28 63 | #define VIRTIO_TRANSPORT_F_END 32 64 | 65 | typedef void (*virtio_dev_reset_cb)(struct virtio_device *vdev); 66 | 67 | struct virtio_dispatch; 68 | 69 | struct virtio_feature_desc { 70 | uint32_t vfd_val; 71 | const char *vfd_str; 72 | }; 73 | 74 | /** 75 | * struct virtio_vring_info 76 | * @vq virtio queue 77 | * @info vring alloc info 78 | * @notifyid vring notify id 79 | * @io metal I/O region of the vring memory, can be NULL 80 | */ 81 | struct virtio_vring_info { 82 | struct virtqueue *vq; 83 | struct vring_alloc_info info; 84 | uint32_t notifyid; 85 | struct metal_io_region *io; 86 | }; 87 | 88 | /* 89 | * Structure definition for virtio devices for use by the 90 | * applications/drivers 91 | */ 92 | 93 | struct virtio_device { 94 | uint32_t notifyid; /**< unique position on the virtio bus */ 95 | struct virtio_device_id id; /**< the device type identification 96 | * (used to match it with a driver 97 | */ 98 | uint64_t features; /**< the features supported by both ends. */ 99 | unsigned int role; /**< if it is virtio backend or front end. */ 100 | virtio_dev_reset_cb reset_cb; /**< user registered device callback */ 101 | const struct virtio_dispatch *func; /**< Virtio dispatch table */ 102 | void *priv; /**< TODO: remove pointer to virtio_device private data */ 103 | unsigned int vrings_num; /**< number of vrings */ 104 | struct virtio_vring_info *vrings_info; 105 | }; 106 | 107 | /* 108 | * Helper functions. 109 | */ 110 | const char *virtio_dev_name(uint16_t devid); 111 | void virtio_describe(struct virtio_device *dev, const char *msg, 112 | uint32_t features, 113 | struct virtio_feature_desc *feature_desc); 114 | 115 | /* 116 | * Functions for virtio device configuration as defined in Rusty Russell's 117 | * paper. 118 | * Drivers are expected to implement these functions in their respective codes. 119 | */ 120 | 121 | struct virtio_dispatch { 122 | uint8_t (*get_status)(struct virtio_device *dev); 123 | void (*set_status)(struct virtio_device *dev, uint8_t status); 124 | uint32_t (*get_features)(struct virtio_device *dev); 125 | void (*set_features)(struct virtio_device *dev, uint32_t feature); 126 | uint32_t (*negotiate_features)(struct virtio_device *dev, 127 | uint32_t features); 128 | 129 | /* 130 | * Read/write a variable amount from the device specific (ie, network) 131 | * configuration region. This region is encoded in the same endian as 132 | * the guest. 133 | */ 134 | void (*read_config)(struct virtio_device *dev, uint32_t offset, 135 | void *dst, int length); 136 | void (*write_config)(struct virtio_device *dev, uint32_t offset, 137 | void *src, int length); 138 | void (*reset_device)(struct virtio_device *dev); 139 | void (*notify)(struct virtqueue *vq); 140 | }; 141 | 142 | int virtio_create_virtqueues(struct virtio_device *vdev, unsigned int flags, 143 | unsigned int nvqs, const char *names[], 144 | vq_callback callbacks[]); 145 | 146 | #if defined __cplusplus 147 | } 148 | #endif 149 | 150 | #endif /* _VIRTIO_H_ */ 151 | -------------------------------------------------------------------------------- /lib/include/openamp/virtio_ring.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Rusty Russell IBM Corporation 2007. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | * 6 | * $FreeBSD$ 7 | */ 8 | 9 | #ifndef VIRTIO_RING_H 10 | #define VIRTIO_RING_H 11 | 12 | #include 13 | 14 | #if defined __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | /* This marks a buffer as continuing via the next field. */ 19 | #define VRING_DESC_F_NEXT 1 20 | /* This marks a buffer as write-only (otherwise read-only). */ 21 | #define VRING_DESC_F_WRITE 2 22 | /* This means the buffer contains a list of buffer descriptors. */ 23 | #define VRING_DESC_F_INDIRECT 4 24 | 25 | /* The Host uses this in used->flags to advise the Guest: don't kick me 26 | * when you add a buffer. It's unreliable, so it's simply an 27 | * optimization. Guest will still kick if it's out of buffers. 28 | */ 29 | #define VRING_USED_F_NO_NOTIFY 1 30 | /* The Guest uses this in avail->flags to advise the Host: don't 31 | * interrupt me when you consume a buffer. It's unreliable, so it's 32 | * simply an optimization. 33 | */ 34 | #define VRING_AVAIL_F_NO_INTERRUPT 1 35 | 36 | /* VirtIO ring descriptors: 16 bytes. 37 | * These can chain together via "next". 38 | */ 39 | METAL_PACKED_BEGIN 40 | struct vring_desc { 41 | /* Address (guest-physical). */ 42 | uint64_t addr; 43 | /* Length. */ 44 | uint32_t len; 45 | /* The flags as indicated above. */ 46 | uint16_t flags; 47 | /* We chain unused descriptors via this, too. */ 48 | uint16_t next; 49 | } METAL_PACKED_END; 50 | 51 | METAL_PACKED_BEGIN 52 | struct vring_avail { 53 | uint16_t flags; 54 | uint16_t idx; 55 | uint16_t ring[0]; 56 | } METAL_PACKED_END; 57 | 58 | /* uint32_t is used here for ids for padding reasons. */ 59 | METAL_PACKED_BEGIN 60 | struct vring_used_elem { 61 | union { 62 | uint16_t event; 63 | /* Index of start of used descriptor chain. */ 64 | uint32_t id; 65 | }; 66 | /* Total length of the descriptor chain which was written to. */ 67 | uint32_t len; 68 | } METAL_PACKED_END; 69 | 70 | METAL_PACKED_BEGIN 71 | struct vring_used { 72 | uint16_t flags; 73 | uint16_t idx; 74 | struct vring_used_elem ring[0]; 75 | } METAL_PACKED_END; 76 | 77 | struct vring { 78 | unsigned int num; 79 | 80 | struct vring_desc *desc; 81 | struct vring_avail *avail; 82 | struct vring_used *used; 83 | }; 84 | 85 | /* The standard layout for the ring is a continuous chunk of memory which 86 | * looks like this. We assume num is a power of 2. 87 | * 88 | * struct vring { 89 | * // The actual descriptors (16 bytes each) 90 | * struct vring_desc desc[num]; 91 | * 92 | * // A ring of available descriptor heads with free-running index. 93 | * __u16 avail_flags; 94 | * __u16 avail_idx; 95 | * __u16 available[num]; 96 | * __u16 used_event_idx; 97 | * 98 | * // Padding to the next align boundary. 99 | * char pad[]; 100 | * 101 | * // A ring of used descriptor heads with free-running index. 102 | * __u16 used_flags; 103 | * __u16 used_idx; 104 | * struct vring_used_elem used[num]; 105 | * __u16 avail_event_idx; 106 | * }; 107 | * 108 | * NOTE: for VirtIO PCI, align is 4096. 109 | */ 110 | 111 | /* 112 | * We publish the used event index at the end of the available ring, and vice 113 | * versa. They are at the end for backwards compatibility. 114 | */ 115 | #define vring_used_event(vr) ((vr)->avail->ring[(vr)->num]) 116 | #define vring_avail_event(vr) ((vr)->used->ring[(vr)->num].event) 117 | 118 | static inline int vring_size(unsigned int num, unsigned long align) 119 | { 120 | int size; 121 | 122 | size = num * sizeof(struct vring_desc); 123 | size += sizeof(struct vring_avail) + (num * sizeof(uint16_t)) + 124 | sizeof(uint16_t); 125 | size = (size + align - 1) & ~(align - 1); 126 | size += sizeof(struct vring_used) + 127 | (num * sizeof(struct vring_used_elem)) + sizeof(uint16_t); 128 | 129 | return size; 130 | } 131 | 132 | static inline void 133 | vring_init(struct vring *vr, unsigned int num, uint8_t *p, unsigned long align) 134 | { 135 | vr->num = num; 136 | vr->desc = (struct vring_desc *)p; 137 | vr->avail = (struct vring_avail *)(p + num * sizeof(struct vring_desc)); 138 | vr->used = (struct vring_used *) 139 | (((unsigned long)&vr->avail->ring[num] + sizeof(uint16_t) + 140 | align - 1) & ~(align - 1)); 141 | } 142 | 143 | /* 144 | * The following is used with VIRTIO_RING_F_EVENT_IDX. 145 | * 146 | * Assuming a given event_idx value from the other size, if we have 147 | * just incremented index from old to new_idx, should we trigger an 148 | * event? 149 | */ 150 | static inline int 151 | vring_need_event(uint16_t event_idx, uint16_t new_idx, uint16_t old) 152 | { 153 | return (uint16_t)(new_idx - event_idx - 1) < 154 | (uint16_t)(new_idx - old); 155 | } 156 | 157 | #if defined __cplusplus 158 | } 159 | #endif 160 | 161 | #endif /* VIRTIO_RING_H */ 162 | -------------------------------------------------------------------------------- /lib/proxy/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | collect (PROJECT_LIB_SOURCES rpmsg_retarget.c) 2 | -------------------------------------------------------------------------------- /lib/proxy/rpmsg_retarget.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigmagic123/openamp/f793a2503fbb9085df79d31bb5184157e3fc1470/lib/proxy/rpmsg_retarget.o -------------------------------------------------------------------------------- /lib/remoteproc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | collect (PROJECT_LIB_SOURCES elf_loader.c) 2 | collect (PROJECT_LIB_SOURCES remoteproc.c) 3 | collect (PROJECT_LIB_SOURCES remoteproc_virtio.c) 4 | collect (PROJECT_LIB_SOURCES rsc_table_parser.c) 5 | -------------------------------------------------------------------------------- /lib/remoteproc/elf_loader.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigmagic123/openamp/f793a2503fbb9085df79d31bb5184157e3fc1470/lib/remoteproc/elf_loader.o -------------------------------------------------------------------------------- /lib/remoteproc/remoteproc.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigmagic123/openamp/f793a2503fbb9085df79d31bb5184157e3fc1470/lib/remoteproc/remoteproc.o -------------------------------------------------------------------------------- /lib/remoteproc/remoteproc_virtio.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigmagic123/openamp/f793a2503fbb9085df79d31bb5184157e3fc1470/lib/remoteproc/remoteproc_virtio.o -------------------------------------------------------------------------------- /lib/remoteproc/rsc_table_parser.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigmagic123/openamp/f793a2503fbb9085df79d31bb5184157e3fc1470/lib/remoteproc/rsc_table_parser.o -------------------------------------------------------------------------------- /lib/rpmsg/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | collect (PROJECT_LIB_SOURCES rpmsg.c) 2 | collect (PROJECT_LIB_SOURCES rpmsg_virtio.c) 3 | -------------------------------------------------------------------------------- /lib/rpmsg/rpmsg.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigmagic123/openamp/f793a2503fbb9085df79d31bb5184157e3fc1470/lib/rpmsg/rpmsg.o -------------------------------------------------------------------------------- /lib/rpmsg/rpmsg_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-3-Clause 3 | * 4 | * $FreeBSD$ 5 | */ 6 | 7 | #ifndef _RPMSG_INTERNAL_H_ 8 | #define _RPMSG_INTERNAL_H_ 9 | 10 | #include 11 | #include 12 | 13 | #if defined __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #ifdef RPMSG_DEBUG 18 | #include 19 | 20 | #define RPMSG_ASSERT(_exp, _msg) do { \ 21 | if (!(_exp)) { \ 22 | metal_log(METAL_LOG_EMERGENCY, \ 23 | "FATAL: %s - "_msg, __func__); \ 24 | while (1) { \ 25 | ; \ 26 | } \ 27 | } \ 28 | } while (0) 29 | #else 30 | #define RPMSG_ASSERT(_exp, _msg) do { \ 31 | if (!(_exp)) \ 32 | while (1) { \ 33 | ; \ 34 | } \ 35 | } while (0) 36 | #endif 37 | 38 | #define RPMSG_LOCATE_DATA(p) ((unsigned char *)(p) + sizeof(struct rpmsg_hdr)) 39 | /** 40 | * enum rpmsg_ns_flags - dynamic name service announcement flags 41 | * 42 | * @RPMSG_NS_CREATE: a new remote service was just created 43 | * @RPMSG_NS_DESTROY: a known remote service was just destroyed 44 | * @RPMSG_NS_CREATE_WITH_ACK: a new remote service was just created waiting 45 | * acknowledgment. 46 | */ 47 | enum rpmsg_ns_flags { 48 | RPMSG_NS_CREATE = 0, 49 | RPMSG_NS_DESTROY = 1, 50 | }; 51 | 52 | /** 53 | * struct rpmsg_hdr - common header for all rpmsg messages 54 | * @src: source address 55 | * @dst: destination address 56 | * @reserved: reserved for future use 57 | * @len: length of payload (in bytes) 58 | * @flags: message flags 59 | * 60 | * Every message sent(/received) on the rpmsg bus begins with this header. 61 | */ 62 | METAL_PACKED_BEGIN 63 | struct rpmsg_hdr { 64 | uint32_t src; 65 | uint32_t dst; 66 | uint32_t reserved; 67 | uint16_t len; 68 | uint16_t flags; 69 | } METAL_PACKED_END; 70 | 71 | /** 72 | * struct rpmsg_ns_msg - dynamic name service announcement message 73 | * @name: name of remote service that is published 74 | * @addr: address of remote service that is published 75 | * @flags: indicates whether service is created or destroyed 76 | * 77 | * This message is sent across to publish a new service, or announce 78 | * about its removal. When we receive these messages, an appropriate 79 | * rpmsg channel (i.e device) is created/destroyed. In turn, the ->probe() 80 | * or ->remove() handler of the appropriate rpmsg driver will be invoked 81 | * (if/as-soon-as one is registered). 82 | */ 83 | METAL_PACKED_BEGIN 84 | struct rpmsg_ns_msg { 85 | char name[RPMSG_NAME_SIZE]; 86 | uint32_t addr; 87 | uint32_t flags; 88 | } METAL_PACKED_END; 89 | 90 | /** 91 | * rpmsg_initialize_ept - initialize rpmsg endpoint 92 | * 93 | * Initialize an RPMsg endpoint with a name, source address, 94 | * remoteproc address, endpoint callback, and destroy endpoint callback. 95 | * 96 | * @ept: pointer to rpmsg endpoint 97 | * @name: service name associated to the endpoint 98 | * @src: local address of the endpoint 99 | * @dest: target address of the endpoint 100 | * @cb: endpoint callback 101 | * @ns_unbind_cb: end point service unbind callback, called when remote ept is 102 | * destroyed. 103 | */ 104 | static inline void rpmsg_initialize_ept(struct rpmsg_endpoint *ept, 105 | const char *name, 106 | uint32_t src, uint32_t dest, 107 | rpmsg_ept_cb cb, 108 | rpmsg_ns_unbind_cb ns_unbind_cb) 109 | { 110 | strncpy(ept->name, name ? name : "", sizeof(ept->name)); 111 | ept->addr = src; 112 | ept->dest_addr = dest; 113 | ept->cb = cb; 114 | ept->ns_unbind_cb = ns_unbind_cb; 115 | } 116 | 117 | int rpmsg_send_ns_message(struct rpmsg_endpoint *ept, unsigned long flags); 118 | 119 | struct rpmsg_endpoint *rpmsg_get_endpoint(struct rpmsg_device *rvdev, 120 | const char *name, uint32_t addr, 121 | uint32_t dest_addr); 122 | void rpmsg_register_endpoint(struct rpmsg_device *rdev, 123 | struct rpmsg_endpoint *ept); 124 | 125 | static inline struct rpmsg_endpoint * 126 | rpmsg_get_ept_from_addr(struct rpmsg_device *rdev, uint32_t addr) 127 | { 128 | return rpmsg_get_endpoint(rdev, NULL, addr, RPMSG_ADDR_ANY); 129 | } 130 | 131 | #if defined __cplusplus 132 | } 133 | #endif 134 | 135 | #endif /* _RPMSG_INTERNAL_H_ */ 136 | -------------------------------------------------------------------------------- /lib/rpmsg/rpmsg_virtio.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigmagic123/openamp/f793a2503fbb9085df79d31bb5184157e3fc1470/lib/rpmsg/rpmsg_virtio.o -------------------------------------------------------------------------------- /lib/virtio/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | collect (PROJECT_LIB_SOURCES virtio.c) 2 | collect (PROJECT_LIB_SOURCES virtqueue.c) 3 | -------------------------------------------------------------------------------- /lib/virtio/virtio.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, Bryan Venteicher 3 | * All rights reserved. 4 | * 5 | * SPDX-License-Identifier: BSD-2-Clause 6 | */ 7 | #include 8 | 9 | static const char *virtio_feature_name(unsigned long feature, 10 | const struct virtio_feature_desc *); 11 | 12 | /* 13 | * TODO : 14 | * This structure may change depending on the types of devices we support. 15 | */ 16 | static const struct virtio_ident { 17 | unsigned short devid; 18 | const char *name; 19 | } virtio_ident_table[] = { 20 | { 21 | VIRTIO_ID_NETWORK, "Network"}, { 22 | VIRTIO_ID_BLOCK, "Block"}, { 23 | VIRTIO_ID_CONSOLE, "Console"}, { 24 | VIRTIO_ID_ENTROPY, "Entropy"}, { 25 | VIRTIO_ID_BALLOON, "Balloon"}, { 26 | VIRTIO_ID_IOMEMORY, "IOMemory"}, { 27 | VIRTIO_ID_SCSI, "SCSI"}, { 28 | VIRTIO_ID_9P, "9P Transport"}, { 29 | 0, NULL} 30 | }; 31 | 32 | /* Device independent features. */ 33 | static const struct virtio_feature_desc virtio_common_feature_desc[] = { 34 | {VIRTIO_F_NOTIFY_ON_EMPTY, "NotifyOnEmpty"}, 35 | {VIRTIO_RING_F_INDIRECT_DESC, "RingIndirect"}, 36 | {VIRTIO_RING_F_EVENT_IDX, "EventIdx"}, 37 | {VIRTIO_F_BAD_FEATURE, "BadFeature"}, 38 | 39 | {0, NULL} 40 | }; 41 | 42 | const char *virtio_dev_name(unsigned short devid) 43 | { 44 | const struct virtio_ident *ident; 45 | 46 | for (ident = virtio_ident_table; ident->name; ident++) { 47 | if (ident->devid == devid) 48 | return ident->name; 49 | } 50 | 51 | return NULL; 52 | } 53 | 54 | static const char *virtio_feature_name(unsigned long val, 55 | const struct virtio_feature_desc *desc) 56 | { 57 | int i, j; 58 | const struct virtio_feature_desc *descs[2] = { desc, 59 | virtio_common_feature_desc 60 | }; 61 | 62 | for (i = 0; i < 2; i++) { 63 | if (!descs[i]) 64 | continue; 65 | 66 | for (j = 0; descs[i][j].vfd_val != 0; j++) { 67 | if (val == descs[i][j].vfd_val) 68 | return descs[i][j].vfd_str; 69 | } 70 | } 71 | 72 | return NULL; 73 | } 74 | 75 | void virtio_describe(struct virtio_device *dev, const char *msg, 76 | uint32_t features, struct virtio_feature_desc *desc) 77 | { 78 | (void)dev; 79 | (void)msg; 80 | (void)features; 81 | 82 | /* TODO: Not used currently - keeping it for future use*/ 83 | virtio_feature_name(0, desc); 84 | } 85 | 86 | int virtio_create_virtqueues(struct virtio_device *vdev, unsigned int flags, 87 | unsigned int nvqs, const char *names[], 88 | vq_callback callbacks[]) 89 | { 90 | struct virtio_vring_info *vring_info; 91 | struct vring_alloc_info *vring_alloc; 92 | unsigned int num_vrings, i; 93 | int ret; 94 | (void)flags; 95 | 96 | num_vrings = vdev->vrings_num; 97 | if (nvqs > num_vrings) 98 | return ERROR_VQUEUE_INVLD_PARAM; 99 | /* Initialize virtqueue for each vring */ 100 | for (i = 0; i < nvqs; i++) { 101 | vring_info = &vdev->vrings_info[i]; 102 | 103 | vring_alloc = &vring_info->info; 104 | #ifndef VIRTIO_SLAVE_ONLY 105 | if (vdev->role == VIRTIO_DEV_MASTER) { 106 | size_t offset; 107 | struct metal_io_region *io = vring_info->io; 108 | 109 | offset = metal_io_virt_to_offset(io, 110 | vring_alloc->vaddr); 111 | metal_io_block_set(io, offset, 0, 112 | vring_size(vring_alloc->num_descs, 113 | vring_alloc->align)); 114 | } 115 | #endif 116 | ret = virtqueue_create(vdev, i, names[i], vring_alloc, 117 | callbacks[i], vdev->func->notify, 118 | vring_info->vq); 119 | if (ret) 120 | return ret; 121 | } 122 | return 0; 123 | } 124 | 125 | -------------------------------------------------------------------------------- /lib/virtio/virtio.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigmagic123/openamp/f793a2503fbb9085df79d31bb5184157e3fc1470/lib/virtio/virtio.o -------------------------------------------------------------------------------- /lib/virtio/virtqueue.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigmagic123/openamp/f793a2503fbb9085df79d31bb5184157e3fc1470/lib/virtio/virtqueue.o -------------------------------------------------------------------------------- /scripts/do_checkpatch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright (c) 2019 STMicroelectronics . 5 | # Copyright (c) 2015 Intel Corporation. 6 | # 7 | # SPDX-License-Identifier: Apache-2.0 8 | # 9 | 10 | res=$1 11 | [ -z "$res" ] && res="checkpatch_log" 12 | [ -f ${res} ] && rm ${res} 13 | [ -f ${res}_error.types ] && rm ${res}_error.types 14 | [ -f ${res}_warning.types ] && rm ${res}_warning.types 15 | 16 | dirs_to_check="lib" 17 | files=$(for d in ${dirs_to_check}; do find $d/ -type f -name '*.[ch]'; done) 18 | 19 | for i in $files; do 20 | ./scripts/checkpatch.pl --no-tree -f --emacs --summary-file --show-types --ignore BRACES,PRINTK_WITHOUT_KERN_LEVEL,SPLIT_STRING,PREFER_KERNEL_TYPES,NEW_TYPEDEFS --max-line-length=90 $i >> ${res} 21 | done 22 | grep ERROR: ${res} |cut -d : -f 3,4 |sort -u > ${res}_error.types 23 | grep WARNING: ${res} |cut -d : -f 3,4 |sort -u > ${res}_warning.types 24 | for i in `cat ${res}_error.types`; do 25 | echo -n $i ' '; grep $i ${res} | wc -l 26 | done 27 | for i in `cat ${res}_warning.types`; do 28 | echo -n $i ' '; grep $i ${res} | wc -l 29 | done 30 | --------------------------------------------------------------------------------