/* invoked when a name service announcement arrives */
static void rpmsg_ns_cb(struct rpmsg_channel *rpdev, void *data, int len,
							void *priv, u32 src)
{
	struct rpmsg_ns_msg *msg = data;
	struct rpmsg_channel *newch;
	struct rpmsg_channel_info chinfo;
	struct virtproc_info *vrp = priv;
	struct device *dev = &vrp->vdev->dev;
	int ret;

#if 0
	print_hex_dump(KERN_DEBUG, "NS announcement: ",
			DUMP_PREFIX_NONE, 16, 1,
			data, len, true);
#endif

	if (len != sizeof(*msg)) {
		dev_err(dev, "malformed ns msg (%d)\n", len);
		return;
	}

	/*
	 * the name service ept does _not_ belong to a real rpmsg channel,
	 * and is handled by the rpmsg bus itself.
	 * for sanity reasons, make sure a valid rpdev has _not_ sneaked
	 * in somehow.
	 */
	if (rpdev) {
		dev_err(dev, "anomaly: ns ept has an rpdev handle\n");
		return;
	}

	/* don't trust the remote processor for null terminating the name */
	msg->name[RPMSG_NAME_SIZE - 1] = '\0';

	dev_info(dev, "%sing channel %s addr 0x%x\n",
			msg->flags & RPMSG_NS_DESTROY ? "destroy" : "creat",
			msg->name, msg->addr);

	strncpy(chinfo.name, msg->name, sizeof(chinfo.name));
	chinfo.src = RPMSG_ADDR_ANY;
	chinfo.dst = msg->addr;

	if (msg->flags & RPMSG_NS_DESTROY) {
		ret = __rpmsg_destroy_channel(vrp, &chinfo);
		if (ret)
			dev_err(dev, "__rpmsg_destroy_channel err: %d\n", ret);
	} else {
		newch = __rpmsg_create_channel(vrp, &chinfo);
		if (!newch)
			dev_err(dev, "__rpmsg_create_channel failed\n");
	}
}
Beispiel #2
0
struct rpmsg_channel *rpmsg_create_channel(int vrp_id, const char *name,
							int src, int dst)
{
	struct rpmsg_channel_info chinfo;
	struct virtproc_info *vrp;

	strncpy(chinfo.name, name, sizeof(chinfo.name));
	chinfo.src = src;
	chinfo.dst = dst;

	/* TODO we probably want radix tree and fw-induced id numbers ? */
	vrp = idr_find(&vprocs, vrp_id);
	if (!vrp)
		return NULL;

	return __rpmsg_create_channel(vrp, &chinfo);
}