Exemple #1
0
/**
 * _rpmsg_virtio_get_buffer_size
 *
 * Returns buffer size available for sending messages.
 *
 * @param rvdev - pointer to rpmsg device
 *
 * @return - buffer size
 *
 */
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) {
		/*
		 * If device role is Master then buffers are provided by us,
		 * so just provide the macro.
		 */
		length = RPMSG_BUFFER_SIZE - sizeof(struct rpmsg_hdr);
	}
#endif /*!VIRTIO_SLAVE_ONLY*/

#ifndef VIRTIO_MASTER_ONLY
	if (role == RPMSG_REMOTE) {
		/*
		 * If other core is Master then buffers are provided by it,
		 * so get the buffer size from the virtqueue.
		 */
		length =
		    (int)virtqueue_get_desc_size(rvdev->svq) -
		    sizeof(struct rpmsg_hdr);
		if (length < 0) {
			length = 0;
		}
	}
#endif /*!VIRTIO_MASTER_ONLY*/

	return length;
}
Exemple #2
0
/**
 * rpmsg_get_buffer_size
 *
 * Returns buffer size available for sending messages.
 *
 * @param channel - pointer to rpmsg channel
 *
 * @return - buffer size
 *
 */
int rpmsg_get_buffer_size(struct rpmsg_channel *rp_chnl) {
    struct remote_device *rdev;
    int length;

    if (!rp_chnl) {
        return RPMSG_ERR_PARAM;
    }

    /* Get associated remote device for channel. */
    rdev = rp_chnl->rdev;

    /* Validate device state */
    if (rp_chnl->state != RPMSG_CHNL_STATE_ACTIVE
                    || rdev->state != RPMSG_DEV_STATE_ACTIVE) {
        return RPMSG_ERR_DEV_STATE;
    }

    env_lock_mutex(rdev->lock);

    if (rdev->role == RPMSG_REMOTE) {
        /*
         * If device role is Remote then buffers are provided by us
         * (RPMSG Master), so just provide the macro.
         */
        length = RPMSG_BUFFER_SIZE - sizeof(struct rpmsg_hdr);
    } else {
        /*
         * If other core is Master then buffers are provided by it,
         * so get the buffer size from the virtqueue.
         */
        length = (int) virtqueue_get_desc_size(rdev->tvq) - sizeof(struct rpmsg_hdr);
    }

    env_unlock_mutex(rdev->lock);

    return length;
}