From 8d53544871e1f300c478224faca6be8384ab0d04 Mon Sep 17 00:00:00 2001 From: Carlo Caione Date: Fri, 29 Apr 2022 12:51:32 +0200 Subject: [PATCH] lib: update open-amp lib to release v2022.04.0 Origin: https://github.com/OpenAMP/open-amp Commit: 10dcceca63e5c699312ebc44eac87b63aeb58bf7 Status: merge open-amp new version after removing the apps dir. Release Description: https://github.com/OpenAMP/open-amp/releases/tag/v2022.04.0 Signed-off-by: Carlo Caione --- CMakeLists.txt | 8 +- README | 2 +- open-amp/CMakeLists.txt | 2 - open-amp/README.md | 6 +- open-amp/VERSION | 2 +- open-amp/cmake/collect.cmake | 2 - open-amp/cmake/depends.cmake | 2 - open-amp/cmake/options.cmake | 30 ++-- .../cmake/platforms/cross_generic_gcc.cmake | 2 - .../cmake/platforms/cross_linux_gcc.cmake | 2 - open-amp/cmake/platforms/zynq7_generic.cmake | 2 - open-amp/cmake/platforms/zynq7_linux.cmake | 2 - .../cmake/platforms/zynqmp_a53_generic.cmake | 2 - open-amp/cmake/platforms/zynqmp_linux.cmake | 2 - .../cmake/platforms/zynqmp_r5_generic.cmake | 4 +- open-amp/docs/apps/echo_test/README.md | 2 +- open-amp/docs/apps/matrix_multiply/README.md | 4 +- open-amp/docs/apps/rpc_demo/README.md | 2 +- open-amp/docs/data-structure.md | 22 +-- .../img-src/coprocessor-rpmsg-ns-dynamic.gv | 6 +- open-amp/docs/img-src/coprocessor-rpmsg-ns.gv | 6 +- .../img-src/coprocessor-rpmsg-static-ep.gv | 2 +- open-amp/docs/remoteproc-design.md | 10 +- open-amp/docs/rpmsg-design.md | 2 +- open-amp/lib/CMakeLists.txt | 2 - open-amp/lib/include/openamp/elf_loader.h | 2 +- open-amp/lib/include/openamp/remoteproc.h | 12 +- .../lib/include/openamp/remoteproc_virtio.h | 2 +- open-amp/lib/include/openamp/rpmsg_virtio.h | 76 ++++++++- open-amp/lib/include/openamp/virtio.h | 29 +++- open-amp/lib/remoteproc/elf_loader.c | 2 +- open-amp/lib/remoteproc/remoteproc.c | 28 ++-- open-amp/lib/remoteproc/remoteproc_virtio.c | 18 +- open-amp/lib/remoteproc/rsc_table_parser.c | 2 +- open-amp/lib/rpmsg/rpmsg.c | 17 +- open-amp/lib/rpmsg/rpmsg_internal.h | 33 +--- open-amp/lib/rpmsg/rpmsg_virtio.c | 155 +++++++++++------- open-amp/lib/virtio/virtio.c | 4 +- open-amp/lib/virtio/virtqueue.c | 112 ++++++------- 39 files changed, 361 insertions(+), 259 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 398bb1051a0..e2dc68026a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,14 +8,14 @@ if(CONFIG_OPENAMP) set(WITH_ZEPHYR 1) set(WITH_ZEPHYR_LIB 1) if (CONFIG_OPENAMP_MASTER) - set(WITH_VIRTIO_MASTER 1) + set(WITH_VIRTIO_DRIVER 1) else() - set(WITH_VIRTIO_MASTER OFF CACHE BOOL "" FORCE) + set(WITH_VIRTIO_DRIVER OFF CACHE BOOL "" FORCE) endif() if (CONFIG_OPENAMP_SLAVE) - set(WITH_VIRTIO_SLAVE 1) + set(WITH_VIRTIO_DEVICE 1) else() - set(WITH_VIRTIO_SLAVE OFF CACHE BOOL "" FORCE) + set(WITH_VIRTIO_DEVICE OFF CACHE BOOL "" FORCE) endif() set(WITH_LIBMETAL_FIND OFF CACHE BOOL "" FORCE) set(WITH_PROXY OFF CACHE BOOL "" FORCE) diff --git a/README b/README index 1f2f3cd4af3..f52e75c423b 100644 --- a/README +++ b/README @@ -39,7 +39,7 @@ URL: https://github.com/OpenAMP/open-amp/ commit: - 3c223735ea969199b3c9e2e2a85c9fa7c022b6c0 + 10dcceca63e5c699312ebc44eac87b63aeb58bf7 Maintained-by: External diff --git a/open-amp/CMakeLists.txt b/open-amp/CMakeLists.txt index 0c742b8f667..e77351bc574 100644 --- a/open-amp/CMakeLists.txt +++ b/open-amp/CMakeLists.txt @@ -35,5 +35,3 @@ add_subdirectory (lib) if (WITH_APPS) add_subdirectory (apps) endif (WITH_APPS) - -# vim: expandtab:ts=2:sw=2:smartindent diff --git a/open-amp/README.md b/open-amp/README.md index f983c365790..91d10ce3a72 100644 --- a/open-amp/README.md +++ b/open-amp/README.md @@ -82,10 +82,10 @@ library for it project: * **WITH_PROXY** (default OFF): Include proxy support in the library. * **WITH APPS** (default OFF): Build with sample applications. * **WITH_PROXY_APPS** (default OFF):Build with proxy sample applications. -* **WITH_VIRTIO_MASTER** (default ON): Build with virtio master enabled. +* **WITH_VIRTIO_DRIVER** (default ON): Build with virtio driver enabled. This option can be set to OFF if the only the remote mode is implemented. -* **WITH_VIRTIO_SLAVE** (default ON): Build with virtio slave enabled. - This option can be set to OFF if the only the master mode is implemented. +* **WITH_VIRTIO_DEVICE** (default ON): Build with virtio device enabled. + This option can be set to OFF if the only the driver mode is implemented. * **WITH_STATIC_LIB** (default ON): Build with a static library. * **WITH_SHARED_LIB** (default ON): Build with a shared library. * **WITH_ZEPHYR** (default OFF): Build open-amp as a zephyr library. This option diff --git a/open-amp/VERSION b/open-amp/VERSION index 61df8f44d67..f9c6daeab9f 100644 --- a/open-amp/VERSION +++ b/open-amp/VERSION @@ -1,3 +1,3 @@ VERSION_MAJOR = 1 -VERSION_MINOR = 1 +VERSION_MINOR = 2 VERSION_PATCH = 0 diff --git a/open-amp/cmake/collect.cmake b/open-amp/cmake/collect.cmake index d1bd17814cb..9c3e4956741 100644 --- a/open-amp/cmake/collect.cmake +++ b/open-amp/cmake/collect.cmake @@ -36,5 +36,3 @@ endfunction (collect) collector_create (PROJECT_INC_DIRS "") collector_create (PROJECT_LIB_DIRS "") collector_create (PROJECT_LIB_DEPS "") - -# vim: expandtab:ts=2:sw=2:smartindent diff --git a/open-amp/cmake/depends.cmake b/open-amp/cmake/depends.cmake index db27a60ee2c..c878d7154d2 100644 --- a/open-amp/cmake/depends.cmake +++ b/open-amp/cmake/depends.cmake @@ -19,5 +19,3 @@ endif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") if (NOT HAVE_FCNTL_H) unset (WITH_PROXY CACHE) endif (NOT HAVE_FCNTL_H) - -# vim: expandtab:ts=2:sw=2:smartindent diff --git a/open-amp/cmake/options.cmake b/open-amp/cmake/options.cmake index 269f179728d..0b1550d9f07 100644 --- a/open-amp/cmake/options.cmake +++ b/open-amp/cmake/options.cmake @@ -50,8 +50,8 @@ string (TOUPPER ${MACHINE} PROJECT_MACHINE_UPPER) # Select which components are in the openamp lib option (WITH_PROXY "Build with proxy(access device controlled by other processor)" ON) -option (WITH_APPS "Build with sample applicaitons" OFF) -option (WITH_PROXY_APPS "Build with proxy sample applicaitons" OFF) +option (WITH_APPS "Build with sample applications" OFF) +option (WITH_PROXY_APPS "Build with proxy sample applications" OFF) if (WITH_APPS) if (WITH_PROXY) set (WITH_PROXY_APPS ON) @@ -63,16 +63,25 @@ if (NOT ${MACHINE} STREQUAL "zynqmp_r5") set (WITH_LOAD_FW OFF) endif(NOT ${MACHINE} STREQUAL "zynqmp_r5") -option (WITH_VIRTIO_MASTER "Build with virtio master enabled" ON) -option (WITH_VIRTIO_SLAVE "Build with virtio slave enabled" ON) +option (WITH_VIRTIO_DRIVER "Build with virtio driver (front end) enabled" ON) +option (WITH_VIRTIO_DEVICE "Build with virtio device (back end) enabled" ON) +option (WITH_VIRTIO_MASTER "Build with virtio driver (front end) enabled" OFF) +option (WITH_VIRTIO_SLAVE "Build with virtio device (back end) enabled" OFF) -if (NOT WITH_VIRTIO_MASTER) - add_definitions(-DVIRTIO_SLAVE_ONLY) -endif (NOT WITH_VIRTIO_MASTER) +if (WITH_VIRTIO_MASTER) + message(DEPRECATION "deprecated cmake option replaced by WITH_VIRTIO_DRIVER" ...) +endif (WITH_VIRTIO_MASTER) +if (WITH_VIRTIO_SLAVE) + message(DEPRECATION "deprecated cmake option replaced by WITH_VIRTIO_DEVICE" ...) +endif (WITH_VIRTIO_SLAVE) -if (NOT WITH_VIRTIO_SLAVE) - add_definitions(-DVIRTIO_MASTER_ONLY) -endif (NOT WITH_VIRTIO_SLAVE) +if (NOT WITH_VIRTIO_DRIVER AND NOT WITH_VIRTIO_MASTER) + add_definitions(-DVIRTIO_DEVICE_ONLY) +endif (NOT WITH_VIRTIO_DRIVER AND NOT WITH_VIRTIO_MASTER) + +if (NOT WITH_VIRTIO_DEVICE AND NOT WITH_VIRTIO_SLAVE) + add_definitions(-DVIRTIO_DRIVER_ONLY) +endif (NOT WITH_VIRTIO_DEVICE AND NOT WITH_VIRTIO_SLAVE) option (WITH_DCACHE_VRINGS "Build with vrings cache operations enabled" OFF) @@ -106,4 +115,3 @@ if (DEFINED RPMSG_BUFFER_SIZE) endif (DEFINED RPMSG_BUFFER_SIZE) message ("-- C_FLAGS : ${CMAKE_C_FLAGS}") -# vim: expandtab:ts=2:sw=2:smartindent diff --git a/open-amp/cmake/platforms/cross_generic_gcc.cmake b/open-amp/cmake/platforms/cross_generic_gcc.cmake index 99a0d713c95..9e8a22c316f 100644 --- a/open-amp/cmake/platforms/cross_generic_gcc.cmake +++ b/open-amp/cmake/platforms/cross_generic_gcc.cmake @@ -8,5 +8,3 @@ CMAKE_FORCE_CXX_COMPILER ("${CROSS_PREFIX}g++" GNU) set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER CACHE STRING "") set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER CACHE STRING "") set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER CACHE STRING "") - -# vim: expandtab:ts=2:sw=2:smartindent diff --git a/open-amp/cmake/platforms/cross_linux_gcc.cmake b/open-amp/cmake/platforms/cross_linux_gcc.cmake index a7e2f6f8512..4d372d4e5dd 100644 --- a/open-amp/cmake/platforms/cross_linux_gcc.cmake +++ b/open-amp/cmake/platforms/cross_linux_gcc.cmake @@ -5,5 +5,3 @@ set (CMAKE_CXX_COMPILER "${CROSS_PREFIX}g++") set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER) set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER) - -# vim: expandtab:ts=2:sw=2:smartindent diff --git a/open-amp/cmake/platforms/zynq7_generic.cmake b/open-amp/cmake/platforms/zynq7_generic.cmake index a42219604ed..e526704cbdf 100644 --- a/open-amp/cmake/platforms/zynq7_generic.cmake +++ b/open-amp/cmake/platforms/zynq7_generic.cmake @@ -4,5 +4,3 @@ set (CROSS_PREFIX "arm-none-eabi-" CACHE STRING "") set (CMAKE_C_FLAGS "-mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard" CACHE STRING "") include (cross_generic_gcc) - -# vim: expandtab:ts=2:sw=2:smartindent diff --git a/open-amp/cmake/platforms/zynq7_linux.cmake b/open-amp/cmake/platforms/zynq7_linux.cmake index 9a69973c9cf..5986b56a6da 100644 --- a/open-amp/cmake/platforms/zynq7_linux.cmake +++ b/open-amp/cmake/platforms/zynq7_linux.cmake @@ -2,5 +2,3 @@ set (CMAKE_SYSTEM_PROCESSOR "arm") set (CROSS_PREFIX "arm-xilinx-linux-gnueabi-") include (cross-linux-gcc) - -# vim: expandtab:ts=2:sw=2:smartindent diff --git a/open-amp/cmake/platforms/zynqmp_a53_generic.cmake b/open-amp/cmake/platforms/zynqmp_a53_generic.cmake index 8ece0cc6a26..606a4dc1bca 100644 --- a/open-amp/cmake/platforms/zynqmp_a53_generic.cmake +++ b/open-amp/cmake/platforms/zynqmp_a53_generic.cmake @@ -2,5 +2,3 @@ set (CMAKE_SYSTEM_PROCESSOR "arm64") set (CROSS_PREFIX "aarch64-none-elf-") include (cross_generic_gcc) - -# vim: expandtab:ts=2:sw=2:smartindent diff --git a/open-amp/cmake/platforms/zynqmp_linux.cmake b/open-amp/cmake/platforms/zynqmp_linux.cmake index bed0928e835..03c60690ccf 100644 --- a/open-amp/cmake/platforms/zynqmp_linux.cmake +++ b/open-amp/cmake/platforms/zynqmp_linux.cmake @@ -3,5 +3,3 @@ set (CROSS_PREFIX "aarch64-linux-gnu-") set (MACHINE "zynqmp" CACHE STRING "") include (cross_linux_gcc) - -# vim: expandtab:ts=2:sw=2:smartindent diff --git a/open-amp/cmake/platforms/zynqmp_r5_generic.cmake b/open-amp/cmake/platforms/zynqmp_r5_generic.cmake index 5806a0dc503..4b856c6b8ff 100644 --- a/open-amp/cmake/platforms/zynqmp_r5_generic.cmake +++ b/open-amp/cmake/platforms/zynqmp_r5_generic.cmake @@ -2,9 +2,7 @@ set (CMAKE_SYSTEM_PROCESSOR "arm" CACHE STRING "") set (MACHINE "zynqmp_r5" CACHE STRING "") set (CROSS_PREFIX "armr5-none-eabi-" CACHE STRING "") -# Xilinx SDK version earlier than 2017.2 use mfloat-abi=soft by default to generat libxil +# Xilinx SDK version earlier than 2017.2 use mfloat-abi=soft by default to generate libxil set (CMAKE_C_FLAGS "-mfloat-abi=hard -mfpu=vfpv3-d16 -mcpu=cortex-r5" CACHE STRING "") include (cross_generic_gcc) - -# vim: expandtab:ts=2:sw=2:smartindent diff --git a/open-amp/docs/apps/echo_test/README.md b/open-amp/docs/apps/echo_test/README.md index a004bbfdf81..820e382526a 100644 --- a/open-amp/docs/apps/echo_test/README.md +++ b/open-amp/docs/apps/echo_test/README.md @@ -34,7 +34,7 @@ You will need to manually compile the following kernel modules with your Linux k ### Load the Demo After Linux boots, -* 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. +* Load the machine remoteproc. If Linux runs as remoteproc master, you will need to pass the other processor's echo_test binary as firmware argument to the remoteproc module. * 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. * If you run the userspace application demo, load the `rpmsg_user_dev_driver` module. * If you run the userspace application demo, you will see the similar output on the console: diff --git a/open-amp/docs/apps/matrix_multiply/README.md b/open-amp/docs/apps/matrix_multiply/README.md index ea4b08c5c91..93889bb7f96 100644 --- a/open-amp/docs/apps/matrix_multiply/README.md +++ b/open-amp/docs/apps/matrix_multiply/README.md @@ -1,7 +1,7 @@ # matrix_multiply This readme is about the OpenAMP matrix_multiply demo. -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. +The matrix_multiply is about one processor generates two matrices, and send them to the one, and the other one calculate the matrix multiplicaiton and return the result matrix. For now, it implements Linux generates the matrices, and the baremetal calculate the matrix mulitplication and send back the result. @@ -34,7 +34,7 @@ You will need to manually compile the following kernel modules with your Linux k ### Load the Demo After Linux boots, -* 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. +* Load the machine remoteproc. If Linux runs as remoteproc master, you will need to pass the other processor's matrix_multiply binary as firmware argument to the remoteproc module. * 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. * If you run the userspace application demo, load the `rpmsg_user_dev_driver` module. * If you run the userspace application demo `mat_mul_demo`, you will see the similar output on the console: diff --git a/open-amp/docs/apps/rpc_demo/README.md b/open-amp/docs/apps/rpc_demo/README.md index d3939188f58..54cf77938e7 100644 --- a/open-amp/docs/apps/rpc_demo/README.md +++ b/open-amp/docs/apps/rpc_demo/README.md @@ -3,7 +3,7 @@ This readme is about the OpenAMP rpc_demo demo. 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. -For now, It implements the processor running generic(baremetal) applicaiton access the devices on the Linux. +For now, It implements the processor running generic(baremetal) application access the devices on the Linux. ## Compilation diff --git a/open-amp/docs/data-structure.md b/open-amp/docs/data-structure.md index 4ea6197d7c6..2a493bb86c9 100644 --- a/open-amp/docs/data-structure.md +++ b/open-amp/docs/data-structure.md @@ -34,16 +34,16 @@ Remoteproc data struct =========================== ``` struct remoteproc { - struct metal_device dev; /**< Each remoteproc has a device, each device knows its memories regions */ - metal_mutex_t lock; /**< mutex lock */ - void *rsc_table; /**< pointer to resource table */ - size_t rsc_len; /**< length of the resoruce table */ - struct remoteproc_ops *ops; /**< pointer to remoteproc operation */ - metal_phys_addr_t bootaddr; /**< boot address */ - struct loader_ops *loader_ops; /**< image loader operation */ - unsigned int state; /**< remoteproc state */ - struct metal_list vdevs; /**< list of vdevs (can we limited to one for code size but linux and resource table supports multiple */ - void *priv; /**< remoteproc private data */ + struct metal_device dev; /**< Each remoteproc has a device, each device knows its memories regions */ + metal_mutex_t lock; /**< mutex lock */ + void *rsc_table; /**< pointer to resource table */ + size_t rsc_len; /**< length of the resource table */ + const struct remoteproc_ops *ops; /**< pointer to remoteproc operation */ + metal_phys_addr_t bootaddr; /**< boot address */ + const struct loader_ops *loader_ops; /**< image loader operation */ + unsigned int state; /**< remoteproc state */ + struct metal_list vdevs; /**< list of vdevs (can we limited to one for code size but linux and resource table supports multiple */ + void *priv; /**< remoteproc private data */ }; struct remoteproc_vdev { @@ -162,7 +162,7 @@ struct rpmsg_endpoint { uint32_t addr; /**< endpoint local address */ uint32_t dest_addr; /**< endpoint default target address */ int (*cb)(struct rpmsg_endpoint *ept, void *data, struct metal_io_region *io, size_t len, uint32_t addr); /**< endpoint callback */ - void (*destroy)(struct rpmsg_endpoint *ept); /**< user registerd endpoint destory callback */ + void (*destroy)(struct rpmsg_endpoint *ept); /**< user registered endpoint destroy callback */ /* Whether we need another callback for ack ns announcement? */ }; ``` diff --git a/open-amp/docs/img-src/coprocessor-rpmsg-ns-dynamic.gv b/open-amp/docs/img-src/coprocessor-rpmsg-ns-dynamic.gv index 6058f104692..b9bf8720aee 100644 --- a/open-amp/docs/img-src/coprocessor-rpmsg-ns-dynamic.gv +++ b/open-amp/docs/img-src/coprocessor-rpmsg-ns-dynamic.gv @@ -24,7 +24,7 @@ digraph G { node [shape="box"]; rank="same"; m_remoteproc_init [label="rproc = remoteproc_init(&remoteproc_ops, &arg);"] - m_remoteproc_load [label="calls remoteproc_load() to load applicaiton"]; + m_remoteproc_load [label="calls remoteproc_load() to load application"]; m_remoteproc_boot [shape="box", label="ret=remoteproc_boot(&rproc)"]; m_remoteproc_get_vdev [label="vdev=remoteproc_create_virtio(rproc, rpmsg_vdev_id, MASTER, NULL);"]; m_rpmsg_shmpool_init[label="rpmsg_virtio_init_shm_pool(shpool, shbuf, shbuf_pool_size);"]; @@ -75,8 +75,8 @@ digraph G { master -> m_remoteproc_init [dir="none"]; slave -> s_remoteproc_init [dir="none"]; - s_rpmsg_create_ep -> m_rpmsg_ns_cb [label="NS annoucement"]; - m_rpmsg_create_ep -> s_rpmsg_ns_cb [label="NS annoucement"]; + s_rpmsg_create_ep -> m_rpmsg_ns_cb [label="NS announcement"]; + m_rpmsg_create_ep -> s_rpmsg_ns_cb [label="NS announcement"]; m_rpmsg_send -> s_rpmsg_rx_cb [label="RPMsg data"]; s_rpmsg_send -> m_rpmsg_rx_cb [label="RPMsg data"]; m_rpmsg_destroy_ep -> s_rpmsg_ns_unbind_cb [label="Endpoint destroy NS"]; diff --git a/open-amp/docs/img-src/coprocessor-rpmsg-ns.gv b/open-amp/docs/img-src/coprocessor-rpmsg-ns.gv index 6c9e10f3b10..bf6671364ce 100644 --- a/open-amp/docs/img-src/coprocessor-rpmsg-ns.gv +++ b/open-amp/docs/img-src/coprocessor-rpmsg-ns.gv @@ -24,7 +24,7 @@ digraph G { node [shape="box"]; rank="same"; m_remoteproc_init [label="rproc = remoteproc_init(&remoteproc_ops, &arg);"] - m_remoteproc_load [label="calls remoteproc_load() to load applicaiton"]; + m_remoteproc_load [label="calls remoteproc_load() to load application"]; m_remoteproc_boot [shape="box", label="ret=remoteproc_boot(&rproc)"]; m_remoteproc_get_vdev [label="vdev=remoteproc_create_virtio(rproc, rpmsg_vdev_id, MASTER, NULL);"]; m_rpmsg_shmpool_init[label="rpmsg_virtio_init_shm_pool(shpool, shbuf, shbuf_pool_size);"]; @@ -73,8 +73,8 @@ digraph G { master -> m_remoteproc_init [dir="none"]; slave -> s_remoteproc_init [dir="none"]; - s_rpmsg_create_ep -> m_rpmsg_ns_cb [label="NS annoucement"]; - m_rpmsg_create_ep -> s_rpmsg_ns_cb [label="NS annoucement"]; + s_rpmsg_create_ep -> m_rpmsg_ns_cb [label="NS announcement"]; + m_rpmsg_create_ep -> s_rpmsg_ns_cb [label="NS announcement"]; m_rpmsg_send -> s_rpmsg_rx_cb [label="RPMsg data"]; s_rpmsg_send -> m_rpmsg_rx_cb [label="RPMsg data"]; m_rpmsg_destroy_ep -> s_rpmsg_ns_unbind_cb [label="Endpoint destroy NS"]; diff --git a/open-amp/docs/img-src/coprocessor-rpmsg-static-ep.gv b/open-amp/docs/img-src/coprocessor-rpmsg-static-ep.gv index ec95744ace2..44f4839c003 100644 --- a/open-amp/docs/img-src/coprocessor-rpmsg-static-ep.gv +++ b/open-amp/docs/img-src/coprocessor-rpmsg-static-ep.gv @@ -22,7 +22,7 @@ digraph G { node [shape="box"]; rank="same"; m_remoteproc_init [label="rproc = remoteproc_init(&remoteproc_ops, &arg);"]; - m_remoteproc_load [label="calls remoteproc_load() to load applicaiton"]; + m_remoteproc_load [label="calls remoteproc_load() to load application"]; m_remoteproc_boot [shape="box", label="ret=remoteproc_boot(&rproc)"]; m_remoteproc_get_vdev [label="vdev=remoteproc_create_virtio(rproc, rpmsg_vdev_id, MASTER, NULL);"]; m_rpmsg_shmpool_init[label="rpmsg_virtio_init_shm_pool(shpool, shbuf, shbuf_pool_size);"]; diff --git a/open-amp/docs/remoteproc-design.md b/open-amp/docs/remoteproc-design.md index e93f8d5c76c..ce99cd04c37 100644 --- a/open-amp/docs/remoteproc-design.md +++ b/open-amp/docs/remoteproc-design.md @@ -8,8 +8,8 @@ It will extend to crash detection, suspend and resume. | State | State Description | |:------|:------------------| | Offline | Initial state of a remoteproc instance. The remote presented by the remoteproc instance and its resource has been powered off. | -| Configured | The remote presented by the remoteproc instance has been configured. And ready to load applicaiton. | -| Ready | The remote presented by the remoteproc instance has applicaiton loaded, and ready to run. | +| Configured | The remote presented by the remoteproc instance has been configured. And ready to load application. | +| Ready | The remote presented by the remoteproc instance has application loaded, and ready to run. | | 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. | ![Rproc LCM States](img/rproc-lcm-state-machine.png) @@ -28,7 +28,7 @@ It will extend to crash detection, suspend and resume. * Initialize remoteproc instance: ``` struct remoteproc *remoteproc_init(struct remoteproc *rproc, - struct remoteproc_ops *ops, void *priv) + const struct remoteproc_ops *ops, void *priv) ``` * Release remoteproc instance: ``` @@ -64,7 +64,7 @@ It will extend to crash detection, suspend and resume. size_t rsc_size) ``` * Configure the remote presented by the remoteproc instance to make it able - to load applicaiton: + to load application: ``` int remoteproc_config(struct remoteproc *rproc, void *data) ``` @@ -72,7 +72,7 @@ It will extend to crash detection, suspend and resume. it ready to run: ``` int remoteproc_load(struct remoteproc *rproc, const char *path, - void *store, struct image_store_ops *store_ops, + void *store, const struct image_store_ops *store_ops, void **img_info) ``` * Run application on the remote presented by the remoteproc instance: diff --git a/open-amp/docs/rpmsg-design.md b/open-amp/docs/rpmsg-design.md index 206ee020ab3..1cfd468b97d 100644 --- a/open-amp/docs/rpmsg-design.md +++ b/open-amp/docs/rpmsg-design.md @@ -2,7 +2,7 @@ RPMsg is a framework to allow communication between two processors. RPMsg implementation in OpenAMP library is based on virtio. It complies the RPMsg Linux kernel implementation. It defines the handshaking on -setting up and tearing down the communication between applicaitons +setting up and tearing down the communication between applications running on two processors. ## RPMsg User API Flow Chats diff --git a/open-amp/lib/CMakeLists.txt b/open-amp/lib/CMakeLists.txt index 7962e9e9c5e..a363256899c 100644 --- a/open-amp/lib/CMakeLists.txt +++ b/open-amp/lib/CMakeLists.txt @@ -67,5 +67,3 @@ endif (WITH_ZEPHYR) install (DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/openamp" DESTINATION include) install (DIRECTORY "${PROJECT_BINARY_DIR}/include/generated/openamp" DESTINATION include) - -# vim: expandtab:ts=2:sw=2:smartindent diff --git a/open-amp/lib/include/openamp/elf_loader.h b/open-amp/lib/include/openamp/elf_loader.h index bc36b5c521e..e7dda74805c 100644 --- a/open-amp/lib/include/openamp/elf_loader.h +++ b/open-amp/lib/include/openamp/elf_loader.h @@ -308,7 +308,7 @@ struct elf64_info { #define ELF_STATE_MASK 0xFF00L #define ELF_NEXT_SEGMENT_MASK 0x00FFL -extern struct loader_ops elf_ops; +extern const struct loader_ops elf_ops; /** * elf_identify - check if it is an ELF file diff --git a/open-amp/lib/include/openamp/remoteproc.h b/open-amp/lib/include/openamp/remoteproc.h index f558846f933..41f5d574192 100644 --- a/open-amp/lib/include/openamp/remoteproc.h +++ b/open-amp/lib/include/openamp/remoteproc.h @@ -371,9 +371,9 @@ struct remoteproc { struct metal_list mems; struct metal_list vdevs; unsigned long bitmap; - struct remoteproc_ops *ops; + const struct remoteproc_ops *ops; metal_phys_addr_t bootaddr; - struct loader_ops *loader; + const struct loader_ops *loader; unsigned int state; void *priv; }; @@ -399,7 +399,7 @@ struct remoteproc { */ struct remoteproc_ops { struct remoteproc *(*init)(struct remoteproc *rproc, - struct remoteproc_ops *ops, void *arg); + const struct remoteproc_ops *ops, void *arg); void (*remove)(struct remoteproc *rproc); void *(*mmap)(struct remoteproc *rproc, metal_phys_addr_t *pa, metal_phys_addr_t *da, @@ -423,6 +423,7 @@ struct remoteproc_ops { * @da - device address * @va - virtual address * @size - memory size + * @buf - pointer to remoteproc_mem struct object to store result * * @returns remoteproc memory pointed by buf if success, otherwise NULL */ @@ -503,7 +504,8 @@ enum remoteproc_state { * @returns created remoteproc pointer */ struct remoteproc *remoteproc_init(struct remoteproc *rproc, - struct remoteproc_ops *ops, void *priv); + const struct remoteproc_ops *ops, + void *priv); /** * remoteproc_remove @@ -720,7 +722,7 @@ int remoteproc_shutdown(struct remoteproc *rproc); * return 0 for success and negative value for failure */ int remoteproc_load(struct remoteproc *rproc, const char *path, - void *store, struct image_store_ops *store_ops, + void *store, const struct image_store_ops *store_ops, void **img_info); /** diff --git a/open-amp/lib/include/openamp/remoteproc_virtio.h b/open-amp/lib/include/openamp/remoteproc_virtio.h index 1912f546c65..70cff9771cb 100644 --- a/open-amp/lib/include/openamp/remoteproc_virtio.h +++ b/open-amp/lib/include/openamp/remoteproc_virtio.h @@ -20,7 +20,7 @@ extern "C" { #endif -/* define vdev notification funciton user should implement */ +/* define vdev notification function user should implement */ typedef int (*rpvdev_notify_func)(void *priv, uint32_t id); /** diff --git a/open-amp/lib/include/openamp/rpmsg_virtio.h b/open-amp/lib/include/openamp/rpmsg_virtio.h index 12cb47fc862..ff1e1711928 100644 --- a/open-amp/lib/include/openamp/rpmsg_virtio.h +++ b/open-amp/lib/include/openamp/rpmsg_virtio.h @@ -41,9 +41,24 @@ struct rpmsg_virtio_shm_pool { size_t size; }; +/** + * struct rpmsg_virtio_config - configuration of rpmsg device based on virtio + * + * This structure is used by the rpmsg virtio host to configure the virtiio + * layer. + * + * @h2r_buf_size: the size of the buffer used to send data from host to remote + * @r2h_buf_size: the size of the buffer used to send data from remote to host + */ +struct rpmsg_virtio_config { + uint32_t h2r_buf_size; + uint32_t r2h_buf_size; +}; + /** * struct rpmsg_virtio_device - representation of a rpmsg device based on virtio * @rdev: rpmsg device, first property in the struct + * @config: structure containing virtio configuration * @vdev: pointer to the virtio device * @rvq: pointer to receive virtqueue * @svq: pointer to send virtqueue @@ -52,6 +67,7 @@ struct rpmsg_virtio_shm_pool { */ struct rpmsg_virtio_device { struct rpmsg_device rdev; + struct rpmsg_virtio_config config; struct virtio_device *vdev; struct virtqueue *rvq; struct virtqueue *svq; @@ -59,8 +75,23 @@ struct rpmsg_virtio_device { struct rpmsg_virtio_shm_pool *shpool; }; -#define RPMSG_REMOTE VIRTIO_DEV_SLAVE -#define RPMSG_MASTER VIRTIO_DEV_MASTER +#define RPMSG_REMOTE VIRTIO_DEV_DEVICE +#define RPMSG_HOST VIRTIO_DEV_DRIVER + +#define RPMSG_SLAVE deprecated_rpmsg_slave() +#define RPMSG_MASTER deprecated_rpmsg_master() + +__deprecated static inline int deprecated_rpmsg_master(void) +{ + /* "RPMSG_MASTER is deprecated, please use RPMSG_HOST" */ + return RPMSG_HOST; +} + +__deprecated static inline int deprecated_rpmsg_slave(void) +{ + /* "RPMSG_SLAVE is deprecated, please use RPMSG_REMOTE" */ + return RPMSG_REMOTE; +} static inline unsigned int rpmsg_virtio_get_role(struct rpmsg_virtio_device *rvdev) @@ -120,14 +151,14 @@ int rpmsg_virtio_get_buffer_size(struct rpmsg_device *rdev); /** * rpmsg_init_vdev - initialize rpmsg virtio device - * Master side: + * Host side: * Initialize RPMsg virtio queues and shared buffers, the address of shm can be * ANY. In this case, function will get shared memory from system shared memory - * pools. If the vdev has RPMsg name service feature, this API will create an + * pools. If the vdev has the RPMsg name service feature, this API will create a * name service endpoint. * - * Slave side: - * This API will not return until the driver ready is set by the master side. + * Remote side: + * This API will not return until the driver ready is set by the host side. * * @param rvdev - pointer to the rpmsg virtio device * @param vdev - pointer to the virtio device @@ -145,6 +176,39 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev, struct metal_io_region *shm_io, struct rpmsg_virtio_shm_pool *shpool); +/** + * rpmsg_init_vdev_with_config - initialize rpmsg virtio device with config + * Host side: + * Initialize RPMsg virtio queues and shared buffers, the address of shm can be + * ANY. In this case, function will get shared memory from system shared memory + * pools. If the vdev has the RPMsg name service feature, this API will create a + * name service endpoint. + * Sizes of virtio data buffers used by the initialized RPMsg instance are set + * to values read from the passed configuration structure. + * + * Remote side: + * This API will not return until the driver ready is set by the host side. + * Sizes of virtio data buffers are set by the host side. Values passed in the + * configuration structure have no effect. + * + * @param rvdev - pointer to the rpmsg virtio device + * @param vdev - pointer to the virtio device + * @param ns_bind_cb - callback handler for name service announcement without + * local endpoints waiting to bind. + * @param shm_io - pointer to the share memory I/O region. + * @param shpool - pointer to shared memory pool. rpmsg_virtio_init_shm_pool has + * to be called first to fill this structure. + * @param config - pointer to configuration structure + * + * @return - status of function execution + */ +int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev, + struct virtio_device *vdev, + rpmsg_ns_bind_cb ns_bind_cb, + struct metal_io_region *shm_io, + struct rpmsg_virtio_shm_pool *shpool, + const struct rpmsg_virtio_config *config); + /** * rpmsg_deinit_vdev - deinitialize rpmsg virtio device * diff --git a/open-amp/lib/include/openamp/virtio.h b/open-amp/lib/include/openamp/virtio.h index 55c8ea517bf..916132b47cf 100644 --- a/open-amp/lib/include/openamp/virtio.h +++ b/open-amp/lib/include/openamp/virtio.h @@ -34,8 +34,33 @@ extern "C" { #define VIRTIO_CONFIG_STATUS_FAILED 0x80 /* Virtio device role */ -#define VIRTIO_DEV_MASTER 0UL -#define VIRTIO_DEV_SLAVE 1UL +#define VIRTIO_DEV_DRIVER 0UL +#define VIRTIO_DEV_DEVICE 1UL + +#define VIRTIO_DEV_MASTER deprecated_virtio_dev_master() +#define VIRTIO_DEV_SLAVE deprecated_virtio_dev_slave() + +__deprecated static inline int deprecated_virtio_dev_master(void) +{ + /* "VIRTIO_DEV_MASTER is deprecated, please use VIRTIO_DEV_DRIVER" */ + return VIRTIO_DEV_DRIVER; +} + +__deprecated static inline int deprecated_virtio_dev_slave(void) +{ + /* "VIRTIO_DEV_SLAVE is deprecated, please use VIRTIO_DEV_DEVICE" */ + return VIRTIO_DEV_DEVICE; +} + +#ifdef VIRTIO_MASTER_ONLY +#define VIRTIO_DRIVER_ONLY +#warning "VIRTIO_MASTER_ONLY is deprecated, please use VIRTIO_DRIVER_ONLY" +#endif + +#ifdef VIRTIO_SLAVE_ONLY +#define VIRTIO_DEVICE_ONLY +#warning "VIRTIO_SLAVE_ONLY is deprecated, please use VIRTIO_DEVICE_ONLY" +#endif struct virtio_device_id { uint32_t device; diff --git a/open-amp/lib/remoteproc/elf_loader.c b/open-amp/lib/remoteproc/elf_loader.c index 057f465f882..c90b8d46b72 100644 --- a/open-amp/lib/remoteproc/elf_loader.c +++ b/open-amp/lib/remoteproc/elf_loader.c @@ -697,7 +697,7 @@ int elf_get_load_state(void *img_info) return *load_state; } -struct loader_ops elf_ops = { +const struct loader_ops elf_ops = { .load_header = elf_load_header, .load_data = elf_load, .locate_rsc_table = elf_locate_rsc_table, diff --git a/open-amp/lib/remoteproc/remoteproc.c b/open-amp/lib/remoteproc/remoteproc.c index f9cf5e9444a..9a0cf3e0144 100644 --- a/open-amp/lib/remoteproc/remoteproc.c +++ b/open-amp/lib/remoteproc/remoteproc.c @@ -18,7 +18,7 @@ /****************************************************************************** * static functions *****************************************************************************/ -static struct loader_ops * +static const struct loader_ops * remoteproc_check_fw_format(const void *img_data, size_t img_len) { if (img_len <= 0) @@ -48,21 +48,21 @@ remoteproc_get_mem(struct remoteproc *rproc, const char *name, metal_list_for_each(&rproc->mems, node) { mem = metal_container_of(node, struct remoteproc_mem, node); if (name) { - if (!strncmp(name, mem->name, strlen(name))) + if (!strncmp(name, mem->name, RPROC_MAX_NAME_LEN)) return mem; } else if (pa != METAL_BAD_PHYS) { metal_phys_addr_t pa_start, pa_end; pa_start = mem->pa; pa_end = pa_start + mem->size; - if (pa >= pa_start && (pa + size) <= pa_end) + if (pa >= pa_start && (pa + size) <= pa_end && pa < pa_end) return mem; } else if (da != METAL_BAD_PHYS) { metal_phys_addr_t da_start, da_end; da_start = mem->da; da_end = da_start + mem->size; - if (da >= da_start && (da + size) <= da_end) + if (da >= da_start && (da + size) <= da_end && da < da_end) return mem; } else if (va) { if (metal_io_virt_to_offset(mem->io, va) != @@ -100,7 +100,7 @@ remoteproc_patoda(struct remoteproc_mem *mem, metal_phys_addr_t pa) static void *remoteproc_get_rsc_table(struct remoteproc *rproc, void *store, - struct image_store_ops *store_ops, + const struct image_store_ops *store_ops, size_t offset, size_t len) { @@ -120,21 +120,20 @@ static void *remoteproc_get_rsc_table(struct remoteproc *rproc, if (ret < 0 || ret < (int)len || !img_data) { metal_log(METAL_LOG_ERROR, "get rsc failed: 0x%llx, 0x%llx\r\n", offset, len); - rsc_table = RPROC_ERR_PTR(-RPROC_EINVAL); + ret = -RPROC_EINVAL; goto error; } memcpy(rsc_table, img_data, len); ret = handle_rsc_table(rproc, rsc_table, len, NULL); if (ret < 0) { - rsc_table = RPROC_ERR_PTR(ret); goto error; } return rsc_table; error: metal_free_memory(rsc_table); - return rsc_table; + return RPROC_ERR_PTR(ret); } static int remoteproc_parse_rsc_table(struct remoteproc *rproc, @@ -167,7 +166,7 @@ int remoteproc_set_rsc_table(struct remoteproc *rproc, } struct remoteproc *remoteproc_init(struct remoteproc *rproc, - struct remoteproc_ops *ops, void *priv) + const struct remoteproc_ops *ops, void *priv) { if (rproc) { memset(rproc, 0, sizeof(*rproc)); @@ -390,11 +389,11 @@ void *remoteproc_mmap(struct remoteproc *rproc, } int remoteproc_load(struct remoteproc *rproc, const char *path, - void *store, struct image_store_ops *store_ops, + void *store, const struct image_store_ops *store_ops, void **img_info) { int ret; - struct loader_ops *loader; + const struct loader_ops *loader; const void *img_data; void *limg_info = NULL; size_t offset, noffset; @@ -668,7 +667,7 @@ int remoteproc_load_noblock(struct remoteproc *rproc, size_t *nmlen, unsigned char *padding) { int ret; - struct loader_ops *loader; + const struct loader_ops *loader; void *limg_info = NULL; int last_load_state; metal_phys_addr_t da, rsc_da; @@ -875,7 +874,10 @@ static int remoteproc_virtio_notify(void *priv, uint32_t id) { struct remoteproc *rproc = priv; - return rproc->ops->notify(rproc, id); + if (rproc->ops->notify) + return rproc->ops->notify(rproc, id); + + return 0; } struct virtio_device * diff --git a/open-amp/lib/remoteproc/remoteproc_virtio.c b/open-amp/lib/remoteproc/remoteproc_virtio.c index ed9f33cbcc5..cbfd966048f 100644 --- a/open-amp/lib/remoteproc/remoteproc_virtio.c +++ b/open-amp/lib/remoteproc/remoteproc_virtio.c @@ -45,7 +45,7 @@ static unsigned char rproc_virtio_get_status(struct virtio_device *vdev) return status; } -#ifndef VIRTIO_SLAVE_ONLY +#ifndef VIRTIO_DEVICE_ONLY static void rproc_virtio_set_status(struct virtio_device *vdev, unsigned char status) { @@ -97,7 +97,7 @@ static uint32_t rproc_virtio_get_features(struct virtio_device *vdev) return dfeatures & gfeatures; } -#ifndef VIRTIO_SLAVE_ONLY +#ifndef VIRTIO_DEVICE_ONLY static void rproc_virtio_set_features(struct virtio_device *vdev, uint32_t features) { @@ -144,7 +144,7 @@ static void rproc_virtio_read_config(struct virtio_device *vdev, dst, length); } -#ifndef VIRTIO_SLAVE_ONLY +#ifndef VIRTIO_DEVICE_ONLY static void rproc_virtio_write_config(struct virtio_device *vdev, uint32_t offset, void *src, int length) { @@ -168,7 +168,7 @@ static void rproc_virtio_write_config(struct virtio_device *vdev, static void rproc_virtio_reset_device(struct virtio_device *vdev) { - if (vdev->role == VIRTIO_DEV_MASTER) + if (vdev->role == VIRTIO_DEV_DRIVER) rproc_virtio_set_status(vdev, VIRTIO_CONFIG_STATUS_NEEDS_RESET); } @@ -179,7 +179,7 @@ static const struct virtio_dispatch remoteproc_virtio_dispatch_funcs = { .get_features = rproc_virtio_get_features, .read_config = rproc_virtio_read_config, .notify = rproc_virtio_virtqueue_notify, -#ifndef VIRTIO_SLAVE_ONLY +#ifndef VIRTIO_DEVICE_ONLY /* * We suppose here that the vdev is in a shared memory so that can * be access only by one core: the master. In this case salve core has @@ -223,7 +223,7 @@ rproc_virtio_create_vdev(unsigned int role, unsigned int notifyid, unsigned int num_extra_desc = 0; vring_rsc = &vdev_rsc->vring[i]; - if (role == VIRTIO_DEV_MASTER) { + if (role == VIRTIO_DEV_DRIVER) { num_extra_desc = vring_rsc->num; } vq = virtqueue_allocate(num_extra_desc); @@ -247,8 +247,8 @@ rproc_virtio_create_vdev(unsigned int role, unsigned int notifyid, vdev->vrings_num = num_vrings; vdev->func = &remoteproc_virtio_dispatch_funcs; -#ifndef VIRTIO_SLAVE_ONLY - if (role == VIRTIO_DEV_MASTER) { +#ifndef VIRTIO_DEVICE_ONLY + if (role == VIRTIO_DEV_DRIVER) { uint32_t dfeatures = rproc_virtio_get_dfeatures(vdev); /* Assume the master support all slave features */ rproc_virtio_negotiate_features(vdev, dfeatures); @@ -340,7 +340,7 @@ void rproc_virtio_wait_remote_ready(struct virtio_device *vdev) * slave action, we can return. Behavior should be updated * in future if a slave status is added. */ - if (vdev->role == VIRTIO_DEV_MASTER) + if (vdev->role == VIRTIO_DEV_DRIVER) return; while (1) { diff --git a/open-amp/lib/remoteproc/rsc_table_parser.c b/open-amp/lib/remoteproc/rsc_table_parser.c index e43fa729fe5..310bd2a988c 100644 --- a/open-amp/lib/remoteproc/rsc_table_parser.c +++ b/open-amp/lib/remoteproc/rsc_table_parser.c @@ -148,7 +148,7 @@ int handle_vdev_rsc(struct remoteproc *rproc, void *rsc) notifyid, notifyid + 1); if (notifyid != RSC_NOTIFY_ID_ANY) - vdev_rsc->notifyid = notifyid; + vring_rsc->notifyid = notifyid; } return 0; diff --git a/open-amp/lib/rpmsg/rpmsg.c b/open-amp/lib/rpmsg/rpmsg.c index 46c3691e9d4..214b2a98e44 100644 --- a/open-amp/lib/rpmsg/rpmsg.c +++ b/open-amp/lib/rpmsg/rpmsg.c @@ -217,9 +217,6 @@ struct rpmsg_endpoint *rpmsg_get_endpoint(struct rpmsg_device *rdev, /* try to get by local address only */ if (addr != RPMSG_ADDR_ANY && ept->addr == addr) return ept; - /* try to find match on local end remote address */ - if (addr == ept->addr && dest_addr == ept->dest_addr) - return ept; /* else use name service and destination address */ if (name) name_match = !strncmp(ept->name, name, @@ -250,8 +247,17 @@ static void rpmsg_unregister_endpoint(struct rpmsg_endpoint *ept) } void rpmsg_register_endpoint(struct rpmsg_device *rdev, - struct rpmsg_endpoint *ept) + struct rpmsg_endpoint *ept, + const char *name, + uint32_t src, uint32_t dest, + rpmsg_ept_cb cb, + rpmsg_ns_unbind_cb ns_unbind_cb) { + strncpy(ept->name, name ? name : "", sizeof(ept->name)); + ept->addr = src; + ept->dest_addr = dest; + ept->cb = cb; + ept->ns_unbind_cb = ns_unbind_cb; ept->rdev = rdev; metal_list_add_tail(&rdev->endpoints, &ept->node); } @@ -293,8 +299,7 @@ int rpmsg_create_ept(struct rpmsg_endpoint *ept, struct rpmsg_device *rdev, */ } - rpmsg_initialize_ept(ept, name, addr, dest, cb, unbind_cb); - rpmsg_register_endpoint(rdev, ept); + rpmsg_register_endpoint(rdev, ept, name, addr, dest, cb, unbind_cb); metal_mutex_release(&rdev->lock); /* Send NS announcement to remote processor */ diff --git a/open-amp/lib/rpmsg/rpmsg_internal.h b/open-amp/lib/rpmsg/rpmsg_internal.h index d4536d1bbe1..ab6e0f29442 100644 --- a/open-amp/lib/rpmsg/rpmsg_internal.h +++ b/open-amp/lib/rpmsg/rpmsg_internal.h @@ -85,40 +85,17 @@ struct rpmsg_ns_msg { uint32_t flags; } METAL_PACKED_END; -/** - * rpmsg_initialize_ept - initialize rpmsg endpoint - * - * Initialize an RPMsg endpoint with a name, source address, - * remoteproc address, endpoint callback, and destroy endpoint callback. - * - * @ept: pointer to rpmsg endpoint - * @name: service name associated to the endpoint - * @src: local address of the endpoint - * @dest: target address of the endpoint - * @cb: endpoint callback - * @ns_unbind_cb: end point service unbind callback, called when remote ept is - * destroyed. - */ -static inline void rpmsg_initialize_ept(struct rpmsg_endpoint *ept, - const char *name, - uint32_t src, uint32_t dest, - rpmsg_ept_cb cb, - rpmsg_ns_unbind_cb ns_unbind_cb) -{ - strncpy(ept->name, name ? name : "", sizeof(ept->name)); - ept->addr = src; - ept->dest_addr = dest; - ept->cb = cb; - ept->ns_unbind_cb = ns_unbind_cb; -} - int rpmsg_send_ns_message(struct rpmsg_endpoint *ept, unsigned long flags); struct rpmsg_endpoint *rpmsg_get_endpoint(struct rpmsg_device *rvdev, const char *name, uint32_t addr, uint32_t dest_addr); void rpmsg_register_endpoint(struct rpmsg_device *rdev, - struct rpmsg_endpoint *ept); + struct rpmsg_endpoint *ept, + const char *name, + uint32_t src, uint32_t dest, + rpmsg_ept_cb cb, + rpmsg_ns_unbind_cb ns_unbind_cb); static inline struct rpmsg_endpoint * rpmsg_get_ept_from_addr(struct rpmsg_device *rdev, uint32_t addr) diff --git a/open-amp/lib/rpmsg/rpmsg_virtio.c b/open-amp/lib/rpmsg/rpmsg_virtio.c index c7c578d6205..57a2083a49b 100644 --- a/open-amp/lib/rpmsg/rpmsg_virtio.c +++ b/open-amp/lib/rpmsg/rpmsg_virtio.c @@ -3,6 +3,7 @@ * All rights reserved. * Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved. * Copyright (c) 2018 Linaro, Inc. All rights reserved. + * Copyright (c) 2021 Nordic Semiconductor ASA * * SPDX-License-Identifier: BSD-3-Clause */ @@ -24,7 +25,19 @@ /* Time to wait - In multiple of 1 msecs. */ #define RPMSG_TICKS_PER_INTERVAL 1000 -#ifndef VIRTIO_SLAVE_ONLY + +/* Default configuration */ +#ifndef VIRTIO_DEVICE_ONLY +#define RPMSG_VIRTIO_DEFAULT_CONFIG \ + (&(const struct rpmsg_virtio_config) { \ + .h2r_buf_size = RPMSG_BUFFER_SIZE, \ + .r2h_buf_size = RPMSG_BUFFER_SIZE, \ + }) +#else +#define RPMSG_VIRTIO_DEFAULT_CONFIG NULL +#endif + +#ifndef VIRTIO_DEVICE_ONLY metal_weak void * rpmsg_virtio_shm_pool_get_buffer(struct rpmsg_virtio_shm_pool *shpool, size_t size) @@ -38,7 +51,7 @@ rpmsg_virtio_shm_pool_get_buffer(struct rpmsg_virtio_shm_pool *shpool, return buffer; } -#endif /*!VIRTIO_SLAVE_ONLY*/ +#endif /*!VIRTIO_DEVICE_ONLY*/ void rpmsg_virtio_init_shm_pool(struct rpmsg_virtio_shm_pool *shpool, void *shb, size_t size) @@ -66,8 +79,8 @@ static void rpmsg_virtio_return_buffer(struct rpmsg_virtio_device *rvdev, uint16_t idx) { unsigned int role = rpmsg_virtio_get_role(rvdev); -#ifndef VIRTIO_SLAVE_ONLY - if (role == RPMSG_MASTER) { +#ifndef VIRTIO_DEVICE_ONLY + if (role == RPMSG_HOST) { struct virtqueue_buf vqbuf; (void)idx; @@ -76,14 +89,14 @@ static void rpmsg_virtio_return_buffer(struct rpmsg_virtio_device *rvdev, vqbuf.len = len; virtqueue_add_buffer(rvdev->rvq, &vqbuf, 0, 1, buffer); } -#endif /*VIRTIO_SLAVE_ONLY*/ +#endif /*VIRTIO_DEVICE_ONLY*/ -#ifndef VIRTIO_MASTER_ONLY +#ifndef VIRTIO_DRIVER_ONLY if (role == RPMSG_REMOTE) { (void)buffer; virtqueue_add_consumed_buffer(rvdev->rvq, idx, len); } -#endif /*VIRTIO_MASTER_ONLY*/ +#endif /*VIRTIO_DRIVER_ONLY*/ } /** @@ -108,8 +121,8 @@ static int rpmsg_virtio_enqueue_buffer(struct rpmsg_virtio_device *rvdev, metal_cache_flush(buffer, len); #endif /* VIRTIO_CACHED_BUFFERS */ -#ifndef VIRTIO_SLAVE_ONLY - if (role == RPMSG_MASTER) { +#ifndef VIRTIO_DEVICE_ONLY + if (role == RPMSG_HOST) { struct virtqueue_buf vqbuf; (void)idx; @@ -118,14 +131,14 @@ static int rpmsg_virtio_enqueue_buffer(struct rpmsg_virtio_device *rvdev, vqbuf.len = len; return virtqueue_add_buffer(rvdev->svq, &vqbuf, 1, 0, buffer); } -#endif /*!VIRTIO_SLAVE_ONLY*/ +#endif /*!VIRTIO_DEVICE_ONLY*/ -#ifndef VIRTIO_MASTER_ONLY +#ifndef VIRTIO_DRIVER_ONLY if (role == RPMSG_REMOTE) { (void)buffer; return virtqueue_add_consumed_buffer(rvdev->svq, idx, len); } -#endif /*!VIRTIO_MASTER_ONLY*/ +#endif /*!VIRTIO_DRIVER_ONLY*/ return 0; } @@ -146,23 +159,23 @@ static void *rpmsg_virtio_get_tx_buffer(struct rpmsg_virtio_device *rvdev, unsigned int role = rpmsg_virtio_get_role(rvdev); void *data = NULL; -#ifndef VIRTIO_SLAVE_ONLY - if (role == RPMSG_MASTER) { +#ifndef VIRTIO_DEVICE_ONLY + if (role == RPMSG_HOST) { data = virtqueue_get_buffer(rvdev->svq, len, idx); if (!data && rvdev->svq->vq_free_cnt) { data = rpmsg_virtio_shm_pool_get_buffer(rvdev->shpool, - RPMSG_BUFFER_SIZE); - *len = RPMSG_BUFFER_SIZE; + rvdev->config.h2r_buf_size); + *len = rvdev->config.h2r_buf_size; *idx = 0; } } -#endif /*!VIRTIO_SLAVE_ONLY*/ +#endif /*!VIRTIO_DEVICE_ONLY*/ -#ifndef VIRTIO_MASTER_ONLY +#ifndef VIRTIO_DRIVER_ONLY if (role == RPMSG_REMOTE) { data = virtqueue_get_available_buffer(rvdev->svq, idx, len); } -#endif /*!VIRTIO_MASTER_ONLY*/ +#endif /*!VIRTIO_DRIVER_ONLY*/ return data; } @@ -185,18 +198,18 @@ static void *rpmsg_virtio_get_rx_buffer(struct rpmsg_virtio_device *rvdev, unsigned int role = rpmsg_virtio_get_role(rvdev); void *data = NULL; -#ifndef VIRTIO_SLAVE_ONLY - if (role == RPMSG_MASTER) { +#ifndef VIRTIO_DEVICE_ONLY + if (role == RPMSG_HOST) { data = virtqueue_get_buffer(rvdev->rvq, len, idx); } -#endif /*!VIRTIO_SLAVE_ONLY*/ +#endif /*!VIRTIO_DEVICE_ONLY*/ -#ifndef VIRTIO_MASTER_ONLY +#ifndef VIRTIO_DRIVER_ONLY if (role == RPMSG_REMOTE) { data = virtqueue_get_available_buffer(rvdev->rvq, idx, len); } -#endif /*!VIRTIO_MASTER_ONLY*/ +#endif /*!VIRTIO_DRIVER_ONLY*/ #ifdef VIRTIO_CACHED_BUFFERS /* Invalidate the buffer before returning it */ @@ -206,7 +219,7 @@ static void *rpmsg_virtio_get_rx_buffer(struct rpmsg_virtio_device *rvdev, return data; } -#ifndef VIRTIO_MASTER_ONLY +#ifndef VIRTIO_DRIVER_ONLY /** * check if the remote is ready to start RPMsg communication */ @@ -227,7 +240,7 @@ static int rpmsg_virtio_wait_remote_ready(struct rpmsg_virtio_device *rvdev) metal_cpu_yield(); } } -#endif /*!VIRTIO_MASTER_ONLY*/ +#endif /*!VIRTIO_DRIVER_ONLY*/ /** * _rpmsg_virtio_get_buffer_size @@ -244,17 +257,17 @@ static int _rpmsg_virtio_get_buffer_size(struct rpmsg_virtio_device *rvdev) unsigned int role = rpmsg_virtio_get_role(rvdev); int length = 0; -#ifndef VIRTIO_SLAVE_ONLY - if (role == RPMSG_MASTER) { +#ifndef VIRTIO_DEVICE_ONLY + if (role == RPMSG_HOST) { /* * If device role is Master then buffers are provided by us, * so just provide the macro. */ - length = RPMSG_BUFFER_SIZE - sizeof(struct rpmsg_hdr); + length = rvdev->config.h2r_buf_size - sizeof(struct rpmsg_hdr); } -#endif /*!VIRTIO_SLAVE_ONLY*/ +#endif /*!VIRTIO_DEVICE_ONLY*/ -#ifndef VIRTIO_MASTER_ONLY +#ifndef VIRTIO_DRIVER_ONLY if (role == RPMSG_REMOTE) { /* * If other core is Master then buffers are provided by it, @@ -263,11 +276,12 @@ static int _rpmsg_virtio_get_buffer_size(struct rpmsg_virtio_device *rvdev) length = (int)virtqueue_get_desc_size(rvdev->svq) - sizeof(struct rpmsg_hdr); - if (length < 0) { - length = 0; - } } -#endif /*!VIRTIO_MASTER_ONLY*/ +#endif /*!VIRTIO_DRIVER_ONLY*/ + + if (length <= 0) { + length = RPMSG_ERR_NO_BUFF; + } return length; } @@ -382,11 +396,11 @@ static int rpmsg_virtio_send_offchannel_nocopy(struct rpmsg_device *rdev, metal_mutex_acquire(&rdev->lock); -#ifndef VIRTIO_SLAVE_ONLY - if (rpmsg_virtio_get_role(rvdev) == RPMSG_MASTER) - buff_len = RPMSG_BUFFER_SIZE; +#ifndef VIRTIO_DEVICE_ONLY + if (rpmsg_virtio_get_role(rvdev) == RPMSG_HOST) + buff_len = rvdev->config.h2r_buf_size; else -#endif /*!VIRTIO_SLAVE_ONLY*/ +#endif /*!VIRTIO_DEVICE_ONLY*/ buff_len = virtqueue_get_buffer_length(rvdev->svq, idx); /* Enqueue buffer on virtqueue. */ @@ -610,6 +624,17 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev, rpmsg_ns_bind_cb ns_bind_cb, struct metal_io_region *shm_io, struct rpmsg_virtio_shm_pool *shpool) +{ + return rpmsg_init_vdev_with_config(rvdev, vdev, ns_bind_cb, shm_io, + shpool, RPMSG_VIRTIO_DEFAULT_CONFIG); +} + +int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev, + struct virtio_device *vdev, + rpmsg_ns_bind_cb ns_bind_cb, + struct metal_io_region *shm_io, + struct rpmsg_virtio_shm_pool *shpool, + const struct rpmsg_virtio_config *config) { struct rpmsg_device *rdev; const char *vq_names[RPMSG_NUM_VRINGS]; @@ -630,17 +655,34 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev, rdev->ops.send_offchannel_nocopy = rpmsg_virtio_send_offchannel_nocopy; role = rpmsg_virtio_get_role(rvdev); -#ifndef VIRTIO_MASTER_ONLY +#ifndef VIRTIO_DEVICE_ONLY + if (role == RPMSG_HOST) { + /* + * The virtio configuration contains only options applicable to + * a virtio driver, implying rpmsg host role. + */ + if (config == NULL) { + return RPMSG_ERR_PARAM; + } + rvdev->config = *config; + } +#else /*!VIRTIO_DEVICE_ONLY*/ + /* Ignore passed config in the virtio-device-only configuration. */ + (void)config; +#endif /*!VIRTIO_DEVICE_ONLY*/ + + +#ifndef VIRTIO_DRIVER_ONLY if (role == RPMSG_REMOTE) { /* wait synchro with the master */ rpmsg_virtio_wait_remote_ready(rvdev); } -#endif /*!VIRTIO_MASTER_ONLY*/ +#endif /*!VIRTIO_DRIVER_ONLY*/ vdev->features = rpmsg_virtio_get_features(rvdev); rdev->support_ns = !!(vdev->features & (1 << VIRTIO_RPMSG_F_NS)); -#ifndef VIRTIO_SLAVE_ONLY - if (role == RPMSG_MASTER) { +#ifndef VIRTIO_DEVICE_ONLY + if (role == RPMSG_HOST) { /* * Since device is RPMSG Remote so we need to manage the * shared buffers. Create shared memory pool to handle buffers. @@ -658,9 +700,9 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev, rvdev->rvq = vdev->vrings_info[0].vq; rvdev->svq = vdev->vrings_info[1].vq; } -#endif /*!VIRTIO_SLAVE_ONLY*/ +#endif /*!VIRTIO_DEVICE_ONLY*/ -#ifndef VIRTIO_MASTER_ONLY +#ifndef VIRTIO_DRIVER_ONLY (void)shpool; if (role == RPMSG_REMOTE) { vq_names[0] = "tx_vq"; @@ -670,7 +712,7 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev, rvdev->rvq = vdev->vrings_info[1].vq; rvdev->svq = vdev->vrings_info[0].vq; } -#endif /*!VIRTIO_MASTER_ONLY*/ +#endif /*!VIRTIO_DRIVER_ONLY*/ rvdev->shbuf_io = shm_io; /* Create virtqueues for remote device */ @@ -693,17 +735,17 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev, vq->shm_io = shm_io; } -#ifndef VIRTIO_SLAVE_ONLY - if (role == RPMSG_MASTER) { +#ifndef VIRTIO_DEVICE_ONLY + if (role == RPMSG_HOST) { struct virtqueue_buf vqbuf; unsigned int idx; void *buffer; - vqbuf.len = RPMSG_BUFFER_SIZE; + vqbuf.len = rvdev->config.r2h_buf_size; for (idx = 0; idx < rvdev->rvq->vq_nentries; idx++) { /* Initialize TX virtqueue buffers for remote device */ buffer = rpmsg_virtio_shm_pool_get_buffer(shpool, - RPMSG_BUFFER_SIZE); + rvdev->config.r2h_buf_size); if (!buffer) { return RPMSG_ERR_NO_BUFF; @@ -714,7 +756,7 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev, metal_io_block_set(shm_io, metal_io_virt_to_offset(shm_io, buffer), - 0x00, RPMSG_BUFFER_SIZE); + 0x00, rvdev->config.r2h_buf_size); status = virtqueue_add_buffer(rvdev->rvq, &vqbuf, 0, 1, buffer); @@ -724,7 +766,7 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev, } } } -#endif /*!VIRTIO_SLAVE_ONLY*/ +#endif /*!VIRTIO_DEVICE_ONLY*/ /* Initialize channels and endpoints list */ metal_list_init(&rdev->endpoints); @@ -734,16 +776,15 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev, * service announcement feature. */ if (rdev->support_ns) { - rpmsg_initialize_ept(&rdev->ns_ept, "NS", + rpmsg_register_endpoint(rdev, &rdev->ns_ept, "NS", RPMSG_NS_EPT_ADDR, RPMSG_NS_EPT_ADDR, rpmsg_virtio_ns_callback, NULL); - rpmsg_register_endpoint(rdev, &rdev->ns_ept); } -#ifndef VIRTIO_SLAVE_ONLY - if (role == RPMSG_MASTER) +#ifndef VIRTIO_DEVICE_ONLY + if (role == RPMSG_HOST) rpmsg_virtio_set_status(rvdev, VIRTIO_CONFIG_STATUS_DRIVER_OK); -#endif /*!VIRTIO_SLAVE_ONLY*/ +#endif /*!VIRTIO_DEVICE_ONLY*/ return status; } diff --git a/open-amp/lib/virtio/virtio.c b/open-amp/lib/virtio/virtio.c index c57985e6f80..d2057848764 100644 --- a/open-amp/lib/virtio/virtio.c +++ b/open-amp/lib/virtio/virtio.c @@ -101,8 +101,8 @@ int virtio_create_virtqueues(struct virtio_device *vdev, unsigned int flags, vring_info = &vdev->vrings_info[i]; vring_alloc = &vring_info->info; -#ifndef VIRTIO_SLAVE_ONLY - if (vdev->role == VIRTIO_DEV_MASTER) { +#ifndef VIRTIO_DEVICE_ONLY + if (vdev->role == VIRTIO_DEV_DRIVER) { size_t offset; struct metal_io_region *io = vring_info->io; diff --git a/open-amp/lib/virtio/virtqueue.c b/open-amp/lib/virtio/virtqueue.c index 889f5b6377c..d9895334d94 100644 --- a/open-amp/lib/virtio/virtqueue.c +++ b/open-amp/lib/virtio/virtqueue.c @@ -22,10 +22,10 @@ static int vq_ring_enable_interrupt(struct virtqueue *, uint16_t); static void vq_ring_free_chain(struct virtqueue *, uint16_t); static int vq_ring_must_notify(struct virtqueue *vq); static void vq_ring_notify(struct virtqueue *vq); -#ifndef VIRTIO_SLAVE_ONLY +#ifndef VIRTIO_DEVICE_ONLY static int virtqueue_nused(struct virtqueue *vq); #endif -#ifndef VIRTIO_MASTER_ONLY +#ifndef VIRTIO_DRIVER_ONLY static int virtqueue_navail(struct virtqueue *vq); #endif @@ -131,7 +131,7 @@ int virtqueue_add_buffer(struct virtqueue *vq, struct virtqueue_buf *buf_list, VQ_PARAM_CHK(vq == NULL, status, ERROR_VQUEUE_INVLD_PARAM); VQ_PARAM_CHK(needed < 1, status, ERROR_VQUEUE_INVLD_PARAM); - VQ_PARAM_CHK(vq->vq_free_cnt == 0, status, ERROR_VRING_FULL); + VQ_PARAM_CHK(vq->vq_free_cnt < needed, status, ERROR_VRING_FULL); VQUEUE_BUSY(vq); @@ -271,10 +271,10 @@ void *virtqueue_get_available_buffer(struct virtqueue *vq, uint16_t *avail_idx, VQUEUE_BUSY(vq); + head_idx = vq->vq_available_idx++ & (vq->vq_nentries - 1); + /* Avail.ring is updated by master, invalidate it */ VRING_INVALIDATE(vq->vq_ring.avail->ring[head_idx]); - - head_idx = vq->vq_available_idx++ & (vq->vq_nentries - 1); *avail_idx = vq->vq_ring.avail->ring[head_idx]; /* Invalidate the desc entry written by master before accessing it */ @@ -355,33 +355,33 @@ void virtqueue_disable_cb(struct virtqueue *vq) VQUEUE_BUSY(vq); if (vq->vq_dev->features & VIRTIO_RING_F_EVENT_IDX) { -#ifndef VIRTIO_SLAVE_ONLY - if (vq->vq_dev->role == VIRTIO_DEV_MASTER) { +#ifndef VIRTIO_DEVICE_ONLY + if (vq->vq_dev->role == VIRTIO_DEV_DRIVER) { vring_used_event(&vq->vq_ring) = vq->vq_used_cons_idx - vq->vq_nentries - 1; VRING_FLUSH(vring_used_event(&vq->vq_ring)); } -#endif /*VIRTIO_SLAVE_ONLY*/ -#ifndef VIRTIO_MASTER_ONLY - if (vq->vq_dev->role == VIRTIO_DEV_SLAVE) { +#endif /*VIRTIO_DEVICE_ONLY*/ +#ifndef VIRTIO_DRIVER_ONLY + if (vq->vq_dev->role == VIRTIO_DEV_DEVICE) { vring_avail_event(&vq->vq_ring) = vq->vq_available_idx - vq->vq_nentries - 1; VRING_FLUSH(vring_avail_event(&vq->vq_ring)); } -#endif /*VIRTIO_MASTER_ONLY*/ +#endif /*VIRTIO_DRIVER_ONLY*/ } else { -#ifndef VIRTIO_SLAVE_ONLY - if (vq->vq_dev->role == VIRTIO_DEV_MASTER) { +#ifndef VIRTIO_DEVICE_ONLY + if (vq->vq_dev->role == VIRTIO_DEV_DRIVER) { vq->vq_ring.avail->flags |= VRING_AVAIL_F_NO_INTERRUPT; VRING_FLUSH(vq->vq_ring.avail->flags); } -#endif /*VIRTIO_SLAVE_ONLY*/ -#ifndef VIRTIO_MASTER_ONLY - if (vq->vq_dev->role == VIRTIO_DEV_SLAVE) { +#endif /*VIRTIO_DEVICE_ONLY*/ +#ifndef VIRTIO_DRIVER_ONLY + if (vq->vq_dev->role == VIRTIO_DEV_DEVICE) { vq->vq_ring.used->flags |= VRING_USED_F_NO_NOTIFY; VRING_FLUSH(vq->vq_ring.used->flags); } -#endif /*VIRTIO_MASTER_ONLY*/ +#endif /*VIRTIO_DRIVER_ONLY*/ } VQUEUE_IDLE(vq); @@ -453,10 +453,10 @@ uint32_t virtqueue_get_desc_size(struct virtqueue *vq) VQUEUE_BUSY(vq); + head_idx = vq->vq_available_idx & (vq->vq_nentries - 1); + /* Avail.ring is updated by master, invalidate it */ VRING_INVALIDATE(vq->vq_ring.avail->ring[head_idx]); - - head_idx = vq->vq_available_idx & (vq->vq_nentries - 1); avail_idx = vq->vq_ring.avail->ring[head_idx]; /* Invalidate the desc entry written by master before accessing it */ @@ -581,15 +581,15 @@ static void vq_ring_init(struct virtqueue *vq, void *ring_mem, int alignment) vring_init(vr, size, ring_mem, alignment); -#ifndef VIRTIO_SLAVE_ONLY - if (vq->vq_dev->role == VIRTIO_DEV_MASTER) { +#ifndef VIRTIO_DEVICE_ONLY + if (vq->vq_dev->role == VIRTIO_DEV_DRIVER) { int i; for (i = 0; i < size - 1; i++) vr->desc[i].next = i + 1; vr->desc[i].next = VQ_RING_DESC_CHAIN_END; } -#endif /*VIRTIO_SLAVE_ONLY*/ +#endif /*VIRTIO_DEVICE_ONLY*/ } /** @@ -639,33 +639,33 @@ static int vq_ring_enable_interrupt(struct virtqueue *vq, uint16_t ndesc) * what's already been consumed. */ if (vq->vq_dev->features & VIRTIO_RING_F_EVENT_IDX) { -#ifndef VIRTIO_SLAVE_ONLY - if (vq->vq_dev->role == VIRTIO_DEV_MASTER) { +#ifndef VIRTIO_DEVICE_ONLY + if (vq->vq_dev->role == VIRTIO_DEV_DRIVER) { vring_used_event(&vq->vq_ring) = vq->vq_used_cons_idx + ndesc; VRING_FLUSH(vring_used_event(&vq->vq_ring)); } -#endif /*VIRTIO_SLAVE_ONLY*/ -#ifndef VIRTIO_MASTER_ONLY - if (vq->vq_dev->role == VIRTIO_DEV_SLAVE) { +#endif /*VIRTIO_DEVICE_ONLY*/ +#ifndef VIRTIO_DRIVER_ONLY + if (vq->vq_dev->role == VIRTIO_DEV_DEVICE) { vring_avail_event(&vq->vq_ring) = vq->vq_available_idx + ndesc; VRING_FLUSH(vring_avail_event(&vq->vq_ring)); } -#endif /*VIRTIO_MASTER_ONLY*/ +#endif /*VIRTIO_DRIVER_ONLY*/ } else { -#ifndef VIRTIO_SLAVE_ONLY - if (vq->vq_dev->role == VIRTIO_DEV_MASTER) { +#ifndef VIRTIO_DEVICE_ONLY + if (vq->vq_dev->role == VIRTIO_DEV_DRIVER) { vq->vq_ring.avail->flags &= ~VRING_AVAIL_F_NO_INTERRUPT; VRING_FLUSH(vq->vq_ring.avail->flags); } -#endif /*VIRTIO_SLAVE_ONLY*/ -#ifndef VIRTIO_MASTER_ONLY - if (vq->vq_dev->role == VIRTIO_DEV_SLAVE) { +#endif /*VIRTIO_DEVICE_ONLY*/ +#ifndef VIRTIO_DRIVER_ONLY + if (vq->vq_dev->role == VIRTIO_DEV_DEVICE) { vq->vq_ring.used->flags &= ~VRING_USED_F_NO_NOTIFY; VRING_FLUSH(vq->vq_ring.used->flags); } -#endif /*VIRTIO_MASTER_ONLY*/ +#endif /*VIRTIO_DRIVER_ONLY*/ } atomic_thread_fence(memory_order_seq_cst); @@ -675,20 +675,20 @@ static int vq_ring_enable_interrupt(struct virtqueue *vq, uint16_t ndesc) * since we last checked. Let our caller know so it processes the new * entries. */ -#ifndef VIRTIO_SLAVE_ONLY - if (vq->vq_dev->role == VIRTIO_DEV_MASTER) { +#ifndef VIRTIO_DEVICE_ONLY + if (vq->vq_dev->role == VIRTIO_DEV_DRIVER) { if (virtqueue_nused(vq) > ndesc) { return 1; } } -#endif /*VIRTIO_SLAVE_ONLY*/ -#ifndef VIRTIO_MASTER_ONLY - if (vq->vq_dev->role == VIRTIO_DEV_SLAVE) { +#endif /*VIRTIO_DEVICE_ONLY*/ +#ifndef VIRTIO_DRIVER_ONLY + if (vq->vq_dev->role == VIRTIO_DEV_DEVICE) { if (virtqueue_navail(vq) > ndesc) { return 1; } } -#endif /*VIRTIO_MASTER_ONLY*/ +#endif /*VIRTIO_DRIVER_ONLY*/ return 0; } @@ -715,8 +715,8 @@ static int vq_ring_must_notify(struct virtqueue *vq) uint16_t new_idx, prev_idx, event_idx; if (vq->vq_dev->features & VIRTIO_RING_F_EVENT_IDX) { -#ifndef VIRTIO_SLAVE_ONLY - if (vq->vq_dev->role == VIRTIO_DEV_MASTER) { +#ifndef VIRTIO_DEVICE_ONLY + if (vq->vq_dev->role == VIRTIO_DEV_DRIVER) { /* CACHE: no need to invalidate avail */ new_idx = vq->vq_ring.avail->idx; prev_idx = new_idx - vq->vq_queued_cnt; @@ -725,9 +725,9 @@ static int vq_ring_must_notify(struct virtqueue *vq) return vring_need_event(event_idx, new_idx, prev_idx) != 0; } -#endif /*VIRTIO_SLAVE_ONLY*/ -#ifndef VIRTIO_MASTER_ONLY - if (vq->vq_dev->role == VIRTIO_DEV_SLAVE) { +#endif /*VIRTIO_DEVICE_ONLY*/ +#ifndef VIRTIO_DRIVER_ONLY + if (vq->vq_dev->role == VIRTIO_DEV_DEVICE) { /* CACHE: no need to invalidate used */ new_idx = vq->vq_ring.used->idx; prev_idx = new_idx - vq->vq_queued_cnt; @@ -736,22 +736,22 @@ static int vq_ring_must_notify(struct virtqueue *vq) return vring_need_event(event_idx, new_idx, prev_idx) != 0; } -#endif /*VIRTIO_MASTER_ONLY*/ +#endif /*VIRTIO_DRIVER_ONLY*/ } else { -#ifndef VIRTIO_SLAVE_ONLY - if (vq->vq_dev->role == VIRTIO_DEV_MASTER) { +#ifndef VIRTIO_DEVICE_ONLY + if (vq->vq_dev->role == VIRTIO_DEV_DRIVER) { VRING_INVALIDATE(vq->vq_ring.used->flags); return (vq->vq_ring.used->flags & VRING_USED_F_NO_NOTIFY) == 0; } -#endif /*VIRTIO_SLAVE_ONLY*/ -#ifndef VIRTIO_MASTER_ONLY - if (vq->vq_dev->role == VIRTIO_DEV_SLAVE) { +#endif /*VIRTIO_DEVICE_ONLY*/ +#ifndef VIRTIO_DRIVER_ONLY + if (vq->vq_dev->role == VIRTIO_DEV_DEVICE) { VRING_INVALIDATE(vq->vq_ring.avail->flags); return (vq->vq_ring.avail->flags & VRING_AVAIL_F_NO_INTERRUPT) == 0; } -#endif /*VIRTIO_MASTER_ONLY*/ +#endif /*VIRTIO_DRIVER_ONLY*/ } return 0; @@ -773,7 +773,7 @@ static void vq_ring_notify(struct virtqueue *vq) * virtqueue_nused * */ -#ifndef VIRTIO_SLAVE_ONLY +#ifndef VIRTIO_DEVICE_ONLY static int virtqueue_nused(struct virtqueue *vq) { uint16_t used_idx, nused; @@ -787,14 +787,14 @@ static int virtqueue_nused(struct virtqueue *vq) return nused; } -#endif /*VIRTIO_SLAVE_ONLY*/ +#endif /*VIRTIO_DEVICE_ONLY*/ /** * * virtqueue_navail * */ -#ifndef VIRTIO_MASTER_ONLY +#ifndef VIRTIO_DRIVER_ONLY static int virtqueue_navail(struct virtqueue *vq) { uint16_t avail_idx, navail; @@ -809,4 +809,4 @@ static int virtqueue_navail(struct virtqueue *vq) return navail; } -#endif /*VIRTIO_MASTER_ONLY*/ +#endif /*VIRTIO_DRIVER_ONLY*/