diff --git a/cmake/options.cmake b/cmake/options.cmake index 62dc7d25..ead1446c 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -139,5 +139,10 @@ if (DEFINED RPMSG_BUFFER_SIZE) endif (DEFINED RPMSG_BUFFER_SIZE) option (WITH_DOC "Build with documentation" OFF) +option (WITH_RPMSG_TRACE "Enable Rpmsg Device Trace" OFF) + +if (WITH_RPMSG_TRACE) + add_definitions(-DRPMSG_TRACE) +endif (WITH_RPMSG_TRACE) message ("-- C_FLAGS : ${CMAKE_C_FLAGS}") diff --git a/lib/include/openamp/rpmsg.h b/lib/include/openamp/rpmsg.h index 8871cfef..1cb6345b 100644 --- a/lib/include/openamp/rpmsg.h +++ b/lib/include/openamp/rpmsg.h @@ -129,6 +129,19 @@ struct rpmsg_device_ops { int (*get_tx_buffer_size)(struct rpmsg_device *rdev); }; +/** + * struct rpmsg_device_trace - trace operation for debugging + * + * This structure is used by the rpmsg device to trace the various events. + * + * @get_tx_buffer: trace callback, called when get a tx buffer + * @release_tx_buffer: trace callback, called when release a tx buffer + */ +struct rpmsg_device_trace { + void (*get_tx_buffer)(struct rpmsg_device *rvdev, void *hdr); + void (*release_tx_buffer)(struct rpmsg_device *rvdev, void *hdr); +}; + /** @brief Representation of a RPMsg device */ struct rpmsg_device { /** List of endpoints */ @@ -153,6 +166,8 @@ struct rpmsg_device { /** RPMsg device operations */ struct rpmsg_device_ops ops; + struct rpmsg_device_trace trace; + /** Create/destroy namespace message */ bool support_ns; }; diff --git a/lib/rpmsg/rpmsg_internal.h b/lib/rpmsg/rpmsg_internal.h index 27b0f0d1..3fd1c76e 100644 --- a/lib/rpmsg/rpmsg_internal.h +++ b/lib/rpmsg/rpmsg_internal.h @@ -133,6 +133,47 @@ void rpmsg_ept_incref(struct rpmsg_endpoint *ept); */ void rpmsg_ept_decref(struct rpmsg_endpoint *ept); +#ifdef RPMSG_TRACE +/** + * @internal + * + * @brief Trace the get tx buffer process + * + * This function is used to trace the get tx buffer process + * + * @param rdev pointer to rpmsg endpoint + * @param hdr pointer to rpmsg header + * + */ +static inline void +rpmsg_device_trace_get_tx_buffer(struct rpmsg_device *rdev, void *hdr) +{ + if (rdev->trace.get_tx_buffer && hdr) + rdev->trace.get_tx_buffer(rdev, hdr); +} + +/** + * @internal + * + * @brief Trace the release tx buffer process + * + * This function is used to trace the release tx buffer process + * + * @param rdev pointer to rpmsg endpoint + * @param hdr pointer to rpmsg header + * + */ +static inline void +rpmsg_device_trace_release_tx_buffer(struct rpmsg_device *rdev, void *hdr) +{ + if (rdev->trace.release_tx_buffer && hdr) + rdev->trace.release_tx_buffer(rdev, hdr); +} +#else +#define rpmsg_device_trace_get_tx_buffer(rdev, hdr) +#define rpmsg_device_trace_release_tx_buffer(rdev, hdr) +#endif + #if defined __cplusplus } #endif diff --git a/lib/rpmsg/rpmsg_virtio.c b/lib/rpmsg/rpmsg_virtio.c index ac75c836..6477a71a 100644 --- a/lib/rpmsg/rpmsg_virtio.c +++ b/lib/rpmsg/rpmsg_virtio.c @@ -148,6 +148,7 @@ static int rpmsg_virtio_enqueue_buffer(struct rpmsg_virtio_device *rvdev, void *buffer, uint32_t len, uint16_t idx) { + int ret; BUFFER_FLUSH(buffer, len); if (VIRTIO_ROLE_IS_DRIVER(rvdev->vdev)) { @@ -157,12 +158,17 @@ static int rpmsg_virtio_enqueue_buffer(struct rpmsg_virtio_device *rvdev, /* Initialize buffer node */ vqbuf.buf = buffer; vqbuf.len = len; - return virtqueue_add_buffer(rvdev->svq, &vqbuf, 1, 0, buffer); + + ret = virtqueue_add_buffer(rvdev->svq, &vqbuf, 1, 0, buffer); + rpmsg_device_trace_release_tx_buffer(&rvdev->rdev, buffer); + return ret; } if (VIRTIO_ROLE_IS_DEVICE(rvdev->vdev)) { (void)buffer; - return virtqueue_add_consumed_buffer(rvdev->svq, idx, len); + ret = virtqueue_add_consumed_buffer(rvdev->svq, idx, len); + rpmsg_device_trace_release_tx_buffer(&rvdev->rdev, buffer); + return ret; } return 0; @@ -210,6 +216,8 @@ static void *rpmsg_virtio_get_tx_buffer(struct rpmsg_virtio_device *rvdev, data = virtqueue_get_available_buffer(rvdev->svq, idx, len); } + rpmsg_device_trace_get_tx_buffer(&rvdev->rdev, data); + return data; } @@ -482,6 +490,7 @@ static int rpmsg_virtio_release_tx_buffer(struct rpmsg_device *rdev, void *txbuf */ r_desc->idx = RPMSG_BUF_INDEX(rp_hdr); metal_list_add_tail(&rvdev->reclaimer, &r_desc->node); + rpmsg_device_trace_release_tx_buffer(&rvdev->rdev, rp_hdr); } metal_mutex_release(&rdev->lock);