Example #1
0
int rpmsg_retarget_init(struct rpmsg_channel *rp_chnl, rpc_shutdown_cb cb) {
	int status;

	/* Allocate memory for rpc control block */
	rpc_data = (struct _rpc_data*) env_allocate_memory(
				sizeof(struct _rpc_data));

	/* Create a mutex for synchronization */
	status = env_create_mutex(&rpc_data->rpc_lock, 1);

	/* Create a mutex for synchronization */
	status = env_create_sync_lock(&rpc_data->sync_lock, LOCKED);

	/* Create a endpoint to handle rpc response from master */
	rpc_data->rpmsg_chnl = rp_chnl;
	rpc_data->rp_ept = rpmsg_create_ept(rpc_data->rpmsg_chnl, rpc_cb,
						RPMSG_NULL, PROXY_ENDPOINT);
	rpc_data->rpc = env_allocate_memory(RPC_BUFF_SIZE);
	rpc_data->rpc_response = env_allocate_memory(RPC_BUFF_SIZE);
	rpc_data->shutdown_cb = cb;

	return status;
}
Example #2
0
/**
 * rpmsg_rdev_init
 *
 * This function creates and initializes the remote device. The remote device
 * encapsulates virtio device.
 *
 * @param rdev              - pointer to newly created remote device
 * @param dev-id            - ID of device to create , remote cpu id
 * @param role              - role of the other device, Master or Remote
 * @param channel_created   - callback function for channel creation
 * @param channel_destroyed - callback function for channel deletion
 * @param default_cb        - default callback for channel
 *
 * @return - status of function execution
 *
 */
int rpmsg_rdev_init(struct remote_device **rdev, int dev_id, int role,
		    rpmsg_chnl_cb_t channel_created,
		    rpmsg_chnl_cb_t channel_destroyed, rpmsg_rx_cb_t default_cb)
{

	struct remote_device *rdev_loc;
	struct virtio_device *virt_dev;
	struct hil_proc *proc;
	struct proc_shm *shm;
	int status;

	/* Initialize HIL data structures for given device */
	proc = hil_create_proc(dev_id);

	if (!proc) {
		return RPMSG_ERR_DEV_ID;
	}

	/* Create software representation of remote processor. */
	rdev_loc =
	    (struct remote_device *)
	    env_allocate_memory(sizeof(struct remote_device));

	if (!rdev_loc) {
		return RPMSG_ERR_NO_MEM;
	}

	env_memset(rdev_loc, 0x00, sizeof(struct remote_device));
	status = env_create_mutex(&rdev_loc->lock, 1);

	if (status != RPMSG_SUCCESS) {

		/* Cleanup required in case of error is performed by caller */
		return status;
	}

	rdev_loc->proc = proc;
	rdev_loc->role = role;
	rdev_loc->channel_created = channel_created;
	rdev_loc->channel_destroyed = channel_destroyed;
	rdev_loc->default_cb = default_cb;

	/* Restrict the ept address - zero address can't be assigned */
	rdev_loc->bitmap[0] = 1;

	/* Initialize the virtio device */
	virt_dev = &rdev_loc->virt_dev;
	virt_dev->device = proc;
	virt_dev->func = &rpmsg_rdev_config_ops;
	if (virt_dev->func->set_features != RPMSG_NULL) {
		virt_dev->func->set_features(virt_dev, proc->vdev.dfeatures);
	}

	if (rdev_loc->role == RPMSG_REMOTE) {
		/*
		 * Since device is RPMSG Remote so we need to manage the
		 * shared buffers. Create shared memory pool to handle buffers.
		 */
		shm = hil_get_shm_info(proc);
		rdev_loc->mem_pool =
		    sh_mem_create_pool(shm->start_addr, shm->size,
				       RPMSG_BUFFER_SIZE);

		if (!rdev_loc->mem_pool) {
			return RPMSG_ERR_NO_MEM;
		}
	}

	/* Initialize channels for RPMSG Remote */
	status = rpmsg_rdev_init_channels(rdev_loc);

	if (status != RPMSG_SUCCESS) {
		return status;
	}

	*rdev = rdev_loc;

	return RPMSG_SUCCESS;
}