diff --git a/openamp/0006-openamp-fix-scenario-case.patch b/openamp/0006-openamp-fix-scenario-case.patch index a9fa95f1bd..0134467825 100644 --- a/openamp/0006-openamp-fix-scenario-case.patch +++ b/openamp/0006-openamp-fix-scenario-case.patch @@ -1,7 +1,7 @@ -From d14f87ea5ff1371318acaf4539116b72986bae2c Mon Sep 17 00:00:00 2001 +From c2b9d18c72eebe558c6a013bf39818c47cffecc3 Mon Sep 17 00:00:00 2001 From: ligd Date: Thu, 18 Nov 2021 20:54:45 +0800 -Subject: [PATCH] openamp: fix scenario case +Subject: [PATCH 1/3] openamp: fix scenario case description: There are two CPUs use IPC. @@ -43,7 +43,6 @@ Resolve: add recursive call rpmsg_virtio_rx_callback() when get_tx_buffer() failed Signed-off-by: ligd -Change-Id: I60512c50327f180a0aba891e3ec847b211e172db --- lib/include/openamp/remoteproc.h | 10 +++ lib/include/openamp/rpmsg_virtio.h | 6 ++ @@ -53,7 +52,7 @@ Change-Id: I60512c50327f180a0aba891e3ec847b211e172db 5 files changed, 97 insertions(+), 66 deletions(-) diff --git a/lib/include/openamp/remoteproc.h open-amp/lib/include/openamp/remoteproc.h -index a71327b..222079e 100644 +index a71327b..328ec3f 100644 --- a/lib/include/openamp/remoteproc.h +++ open-amp/lib/include/openamp/remoteproc.h @@ -449,6 +449,16 @@ struct remoteproc_ops { @@ -61,56 +60,56 @@ index a71327b..222079e 100644 void *va, size_t size, struct remoteproc_mem *buf); + /** -+ * can_recursive ++ * wait_tx_buffer + * -+ * Check current vdev can do recursive rx_callabck or not ++ * Wait tx buffer available + * + * @rproc - pointer to remoteproc instance + * -+ * return true if can do recursive rx_callabck. ++ * return none + */ -+ int (*can_recursive)(struct remoteproc *rproc); ++ int (*wait_tx_buffer)(struct remoteproc *rproc); }; /* Remoteproc error codes */ diff --git a/lib/include/openamp/rpmsg_virtio.h open-amp/lib/include/openamp/rpmsg_virtio.h -index e552b96..fa556a2 100644 +index e552b96..ac155fb 100644 --- a/lib/include/openamp/rpmsg_virtio.h +++ open-amp/lib/include/openamp/rpmsg_virtio.h @@ -114,6 +114,12 @@ rpmsg_virtio_create_virtqueues(struct rpmsg_virtio_device *rvdev, callbacks); } -+static inline int rpmsg_virtio_can_recursive(struct rpmsg_virtio_device *rvdev) ++static inline int rpmsg_virtio_wait_tx_buffer(struct rpmsg_virtio_device *rvdev) +{ -+ return rvdev->vdev->func->can_recursive ? -+ rvdev->vdev->func->can_recursive(rvdev->vdev) : 0; ++ return rvdev->vdev->func->wait_tx_buffer ? ++ rvdev->vdev->func->wait_tx_buffer(rvdev->vdev) : -EAGAIN; +} + /** * rpmsg_virtio_get_buffer_size - get rpmsg virtio buffer size * diff --git a/lib/include/openamp/virtio.h open-amp/lib/include/openamp/virtio.h -index 55c8ea5..ce808cc 100644 +index 55c8ea5..34bccaa 100644 --- a/lib/include/openamp/virtio.h +++ open-amp/lib/include/openamp/virtio.h @@ -137,6 +137,7 @@ struct virtio_dispatch { void *src, int length); void (*reset_device)(struct virtio_device *dev); void (*notify)(struct virtqueue *vq); -+ int (*can_recursive)(struct virtio_device *dev); ++ int (*wait_tx_buffer)(struct virtio_device *dev); }; int virtio_create_virtqueues(struct virtio_device *vdev, unsigned int flags, diff --git a/lib/remoteproc/remoteproc_virtio.c open-amp/lib/remoteproc/remoteproc_virtio.c -index ed9f33c..937f294 100644 +index ed9f33c..0de31ee 100644 --- a/lib/remoteproc/remoteproc_virtio.c +++ open-amp/lib/remoteproc/remoteproc_virtio.c @@ -30,6 +30,17 @@ static void rproc_virtio_virtqueue_notify(struct virtqueue *vq) rpvdev->notify(rpvdev->priv, vring_info->notifyid); } -+static int rproc_virtio_can_recursive(struct virtio_device *vdev) ++static int rproc_virtio_wait_tx_buffer(struct virtio_device *vdev) +{ + struct remoteproc_virtio *rpvdev; + struct remoteproc *rproc; @@ -118,7 +117,7 @@ index ed9f33c..937f294 100644 + rpvdev = metal_container_of(vdev, struct remoteproc_virtio, vdev); + rproc = rpvdev->priv; + -+ return rproc->ops->can_recursive ? rproc->ops->can_recursive(rproc) : 0; ++ return rproc->ops->wait_tx_buffer ? rproc->ops->wait_tx_buffer(rproc) : -EAGAIN; +} + static unsigned char rproc_virtio_get_status(struct virtio_device *vdev) @@ -128,12 +127,12 @@ index ed9f33c..937f294 100644 .get_features = rproc_virtio_get_features, .read_config = rproc_virtio_read_config, .notify = rproc_virtio_virtqueue_notify, -+ .can_recursive = rproc_virtio_can_recursive, ++ .wait_tx_buffer = rproc_virtio_wait_tx_buffer, #ifndef VIRTIO_SLAVE_ONLY /* * We suppose here that the vdev is in a shared memory so that can diff --git a/lib/rpmsg/rpmsg_virtio.c open-amp/lib/rpmsg/rpmsg_virtio.c -index 2687320..a407be9 100644 +index 2687320..30c3ab3 100644 --- a/lib/rpmsg/rpmsg_virtio.c +++ open-amp/lib/rpmsg/rpmsg_virtio.c @@ -286,6 +286,72 @@ static void rpmsg_virtio_release_rx_buffer(struct rpmsg_device *rdev, @@ -213,8 +212,8 @@ index 2687320..a407be9 100644 metal_mutex_release(&rdev->lock); if (rp_hdr || !tick_count) break; -+ if (rpmsg_virtio_can_recursive(rvdev)) -+ rpmsg_virtio_rx_callback(rvdev->rvq); ++ if (rpmsg_virtio_wait_tx_buffer(rvdev) >= 0) ++ continue; metal_sleep_usec(RPMSG_TICKS_PER_INTERVAL); tick_count--; } diff --git a/openamp/0007-openamp-divide-shram-to-TX-shram-RX-shram.patch b/openamp/0007-openamp-divide-shram-to-TX-shram-RX-shram.patch new file mode 100644 index 0000000000..012b5ae626 --- /dev/null +++ b/openamp/0007-openamp-divide-shram-to-TX-shram-RX-shram.patch @@ -0,0 +1,130 @@ +From 0de084b8b7c65502a2339221b59aeaa60edbe8c5 Mon Sep 17 00:00:00 2001 +From: ligd +Date: Mon, 7 Feb 2022 20:36:25 +0800 +Subject: [PATCH 2/3] openamp: divide shram to TX shram & RX shram + +Add new API rpmsg_init_vdev_ext() + +Signed-off-by: ligd +Change-Id: I790cdcf27276ed12a633fab9cc8aefff7c7da830 +--- + lib/include/openamp/rpmsg_virtio.h | 30 +++++++++++++++++++++++++++++ + lib/rpmsg/rpmsg_virtio.c | 31 ++++++++++++++++++++---------- + 2 files changed, 51 insertions(+), 10 deletions(-) + +diff --git a/lib/include/openamp/rpmsg_virtio.h open-amp/lib/include/openamp/rpmsg_virtio.h +index ac155fb..9d6a16e 100644 +--- a/lib/include/openamp/rpmsg_virtio.h ++++ open-amp/lib/include/openamp/rpmsg_virtio.h +@@ -156,6 +156,36 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev, + struct metal_io_region *shm_io, + struct rpmsg_virtio_shm_pool *shpool); + ++/** ++ * rpmsg_init_vdev_ext - initialize rpmsg virtio device ++ * Master 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 ++ * name service endpoint. ++ * ++ * Slave side: ++ * This API will not return until the driver ready is set by the master side. ++ * ++ * @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 tx_shpool - pointer to tx shared memory pool. rpmsg_virtio_init_shm_pool ++ * has to be called first to fill this structure. ++ * @param rx_shpool - pointer to rx shared memory pool. rpmsg_virtio_init_shm_pool ++ * has to be called first to fill this structure. ++ * ++ * @return - status of function execution ++ */ ++int rpmsg_init_vdev_ext(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 *tx_shpool, ++ struct rpmsg_virtio_shm_pool *rx_shpool); ++ + /** + * rpmsg_deinit_vdev - deinitialize rpmsg virtio device + * +diff --git a/lib/rpmsg/rpmsg_virtio.c open-amp/lib/rpmsg/rpmsg_virtio.c +index 30c3ab3..8a2c795 100644 +--- a/lib/rpmsg/rpmsg_virtio.c ++++ open-amp/lib/rpmsg/rpmsg_virtio.c +@@ -604,11 +604,12 @@ int rpmsg_virtio_get_buffer_size(struct rpmsg_device *rdev) + return size; + } + +-int rpmsg_init_vdev(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) ++int rpmsg_init_vdev_ext(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 *tx_shpool, ++ struct rpmsg_virtio_shm_pool *rx_shpool) + { + struct rpmsg_device *rdev; + const char *vq_names[RPMSG_NUM_VRINGS]; +@@ -654,11 +655,11 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev, + * Since device is RPMSG Remote so we need to manage the + * shared buffers. Create shared memory pool to handle buffers. + */ +- if (!shpool) ++ if (!tx_shpool || !rx_shpool) + return RPMSG_ERR_PARAM; +- if (!shpool->size) ++ if (!tx_shpool->size || !rx_shpool->size) + return RPMSG_ERR_NO_BUFF; +- rvdev->shpool = shpool; ++ rvdev->shpool = tx_shpool; + + vq_names[0] = "rx_vq"; + vq_names[1] = "tx_vq"; +@@ -670,7 +671,8 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev, + #endif /*!VIRTIO_SLAVE_ONLY*/ + + #ifndef VIRTIO_MASTER_ONLY +- (void)shpool; ++ (void)tx_shpool; ++ (void)rx_shpool; + if (role == RPMSG_REMOTE) { + vq_names[0] = "tx_vq"; + vq_names[1] = "rx_vq"; +@@ -711,7 +713,7 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev, + vqbuf.len = rvdev->config.txbuf_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, ++ buffer = rpmsg_virtio_shm_pool_get_buffer(rx_shpool, + rvdev->config.txbuf_size); + + if (!buffer) { +@@ -757,6 +759,15 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev, + return status; + } + ++int rpmsg_init_vdev(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) ++{ ++ return rpmsg_init_vdev_ext(rvdev, vdev, ns_bind_cb, shm_io, shpool, shpool); ++} ++ + void rpmsg_deinit_vdev(struct rpmsg_virtio_device *rvdev) + { + struct metal_list *node; +-- +2.25.1 + diff --git a/openamp/0008-rpmsg_virtio-don-t-need-check-status-when-get_tx_pay.patch b/openamp/0008-rpmsg_virtio-don-t-need-check-status-when-get_tx_pay.patch new file mode 100644 index 0000000000..e003c769da --- /dev/null +++ b/openamp/0008-rpmsg_virtio-don-t-need-check-status-when-get_tx_pay.patch @@ -0,0 +1,34 @@ +From 0e2e59941d9694e060f8ac06fce6b8284d8e74ec Mon Sep 17 00:00:00 2001 +From: ligd +Date: Mon, 28 Feb 2022 16:31:54 +0800 +Subject: [PATCH 3/3] rpmsg_virtio: don't need check status when get_tx_payload + +Signed-off-by: ligd +--- + lib/rpmsg/rpmsg_virtio.c | 6 ------ + 1 file changed, 6 deletions(-) + +diff --git a/lib/rpmsg/rpmsg_virtio.c open-amp/lib/rpmsg/rpmsg_virtio.c +index 8a2c795..b95bf6d 100644 +--- a/lib/rpmsg/rpmsg_virtio.c ++++ open-amp/lib/rpmsg/rpmsg_virtio.c +@@ -359,16 +359,10 @@ static void *rpmsg_virtio_get_tx_payload_buffer(struct rpmsg_device *rdev, + struct rpmsg_hdr *rp_hdr; + uint16_t idx; + int tick_count; +- int status; + + /* Get the associated remote device for channel. */ + rvdev = metal_container_of(rdev, struct rpmsg_virtio_device, rdev); + +- /* Validate device state */ +- status = rpmsg_virtio_get_status(rvdev); +- if (!(status & VIRTIO_CONFIG_STATUS_DRIVER_OK)) +- return NULL; +- + if (wait) + tick_count = RPMSG_TICK_COUNT / RPMSG_TICKS_PER_INTERVAL; + else +-- +2.25.1 + diff --git a/openamp/open-amp.defs b/openamp/open-amp.defs index cf0dd8d28f..8c0053ce6c 100644 --- a/openamp/open-amp.defs +++ b/openamp/open-amp.defs @@ -39,6 +39,8 @@ open-amp.zip: $(Q) patch -p0 < 0004-openamp-add-ns_unbind_notify-support.patch $(Q) patch -p0 < 0005-rpmsg-notify-the-user-when-the-remote-address-is-rec.patch $(Q) patch -p0 < 0006-openamp-fix-scenario-case.patch + $(Q) patch -p0 < 0007-openamp-divide-shram-to-TX-shram-RX-shram.patch + $(Q) patch -p0 < 0008-rpmsg_virtio-don-t-need-check-status-when-get_tx_pay.patch .openamp_headers: open-amp.zip $(eval headers := $(wildcard open-amp/lib/include/openamp/*.h))