ThirdParty/sw_services/openamp/src/open-amp/lib/rpmsg/rpmsg_virtio.c
static int rpmsg_virtio_ns_callback(struct rpmsg_endpoint *ept, void *data,
				    size_t len, uint32_t src, void *priv)
{
	struct rpmsg_device *rdev = ept->rdev;
	struct rpmsg_virtio_device *rvdev = (struct rpmsg_virtio_device *)rdev;
	struct metal_io_region *io = rvdev->shbuf_io;
	struct rpmsg_endpoint *_ept;
	struct rpmsg_ns_msg *ns_msg;
	uint32_t dest;
	char name[RPMSG_NAME_SIZE];

	(void)priv;
	(void)src;

	ns_msg = data;
	if (len != sizeof(*ns_msg))
		/* Returns as the message is corrupted */
		return RPMSG_SUCCESS;
	metal_io_block_read(io,
			    metal_io_virt_to_offset(io, ns_msg->name),
			    &name, sizeof(name));
	dest = ns_msg->addr;

	/* check if a Ept has been locally registered */
	metal_mutex_acquire(&rdev->lock);
	_ept = rpmsg_get_endpoint(rdev, name, RPMSG_ADDR_ANY, dest);

	if (ns_msg->flags & RPMSG_NS_DESTROY) {
		if (_ept)
			_ept->dest_addr = RPMSG_ADDR_ANY;
		metal_mutex_release(&rdev->lock);
		if (_ept && _ept->ns_unbind_cb)
			_ept->ns_unbind_cb(ept);
	} else {
		if (!_ept) {
			/*
			 * send callback to application, that can
			 * - create the associated endpoints.
			 * - store information for future use.
			 * - just ignore the request as service not supported.
			 */
			metal_mutex_release(&rdev->lock);
			if (rdev->ns_bind_cb)
				rdev->ns_bind_cb(rdev, name, dest);
		} else {
			_ept->dest_addr = dest;
			metal_mutex_release(&rdev->lock);
		}
	}

	return RPMSG_SUCCESS;
}
/**
 * rpmsg_virtio_ns_callback
 *
 * This callback handles name service announcement from the remote device
 * and creates/deletes rpmsg channels.
 *
 * @param ept  - pointer to server channel control block.
 * @param data - pointer to received messages
 * @param len  - length of received data
 * @param priv - any private data
 * @param src  - source address
 *
 * @return - rpmag endpoint callback handled
 */
rpmsg_virtio_ns_callback
This callback handles name service announcement from the remote device
and creates/deletes rpmsg channels.

@param ept  - pointer to server channel control block.
@param data - pointer to received messages
@param len  - length of received data
@param priv - any private data
@param src  - source address

@return - rpmag endpoint callback handled
rpmsg_virtio_ns_callback This callback handles name service announcement from the remote device and creates / deletes rpmsg channels . @param ept - pointer to server channel control block . @param data - pointer to received messages @param len - length of received data @param priv - any private data @param src - source address @return - rpmag endpoint callback handled
static int rpmsg_virtio_ns_callback(struct rpmsg_endpoint *ept, void *data,
				    size_t len, uint32_t src, void *priv)
{
	struct rpmsg_device *rdev = ept->rdev;
	struct rpmsg_virtio_device *rvdev = (struct rpmsg_virtio_device *)rdev;
	struct metal_io_region *io = rvdev->shbuf_io;
	struct rpmsg_endpoint *_ept;
	struct rpmsg_ns_msg *ns_msg;
	uint32_t dest;
	char name[RPMSG_NAME_SIZE];
	(void)priv;
	(void)src;
	ns_msg = data;
	if (len != sizeof(*ns_msg))
		return RPMSG_SUCCESS;
	metal_io_block_read(io,
			    metal_io_virt_to_offset(io, ns_msg->name),
			    &name, sizeof(name));
	dest = ns_msg->addr;
	metal_mutex_acquire(&rdev->lock);
	_ept = rpmsg_get_endpoint(rdev, name, RPMSG_ADDR_ANY, dest);
	if (ns_msg->flags & RPMSG_NS_DESTROY) {
		if (_ept)
			_ept->dest_addr = RPMSG_ADDR_ANY;
		metal_mutex_release(&rdev->lock);
		if (_ept && _ept->ns_unbind_cb)
			_ept->ns_unbind_cb(ept);
	} else {
		if (!_ept) {
			metal_mutex_release(&rdev->lock);
			if (rdev->ns_bind_cb)
				rdev->ns_bind_cb(rdev, name, dest);
		} else {
			_ept->dest_addr = dest;
			metal_mutex_release(&rdev->lock);
		}
	}
	return RPMSG_SUCCESS;
}
static int rpmsg_virtio_ns_callback ( struct rpmsg_endpoint * ept , void * data , size_t len , uint32_t src , void * priv ) { struct rpmsg_device * rdev = ept -> rdev ; struct rpmsg_virtio_device * rvdev = ( struct rpmsg_virtio_device * ) rdev ; struct metal_io_region * io = rvdev -> shbuf_io ; struct rpmsg_endpoint * _ept ; struct rpmsg_ns_msg * ns_msg ; uint32_t dest ; char name [ RPMSG_NAME_SIZE ] ; ( void ) priv ; ( void ) src ; ns_msg = data ; if ( len != sizeof ( * ns_msg ) ) return RPMSG_SUCCESS ; metal_io_block_read ( io , metal_io_virt_to_offset ( io , ns_msg -> name ) , & name , sizeof ( name ) ) ; dest = ns_msg -> addr ; metal_mutex_acquire ( & rdev -> lock ) ; _ept = rpmsg_get_endpoint ( rdev , name , RPMSG_ADDR_ANY , dest ) ; if ( ns_msg -> flags & RPMSG_NS_DESTROY ) { if ( _ept ) _ept -> dest_addr = RPMSG_ADDR_ANY ; metal_mutex_release ( & rdev -> lock ) ; if ( _ept && _ept -> ns_unbind_cb ) _ept -> ns_unbind_cb ( ept ) ; } else { if ( ! _ept ) { metal_mutex_release ( & rdev -> lock ) ; if ( rdev -> ns_bind_cb ) rdev -> ns_bind_cb ( rdev , name , dest ) ; } else { _ept -> dest_addr = dest ; metal_mutex_release ( & rdev -> lock ) ; } } return RPMSG_SUCCESS ; }
rpmsg_virtio_ns_callback
 This callback handles name service announcement from the remote device
 and creates/deletes rpmsg channels.
rpmsg_virtio_ns_callback This callback handles name service announcement from the remote device and creates / deletes rpmsg channels .
/* Returns as the message is corrupted */ /* check if a Ept has been locally registered */ /*
			 * send callback to application, that can
			 * - create the associated endpoints.
			 * - store information for future use.
			 * - just ignore the request as service not supported.
			 */