Skip to content

Commit

Permalink
rpmsg: Introduce indirection table for rpmsg_device operations
Browse files Browse the repository at this point in the history
To allow for multiple backend implementations add an indireection table
for rpmsg_device related operations and move the virtio implementation
behind this table.

Signed-off-by: Bjorn Andersson <[email protected]>
  • Loading branch information
andersson committed Sep 9, 2016
1 parent 92e1de5 commit 36b72c7
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 6 deletions.
48 changes: 42 additions & 6 deletions drivers/rpmsg/virtio_rpmsg_bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,18 @@ struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_device *rpdev,
rpmsg_rx_cb_t cb, void *priv,
struct rpmsg_channel_info chinfo)
{
return __rpmsg_create_ept(rpdev->vrp, rpdev, cb, priv, chinfo.src);
return rpdev->ops->create_ept(rpdev, cb, priv, chinfo);
}
EXPORT_SYMBOL(rpmsg_create_ept);

static struct rpmsg_endpoint *virtio_rpmsg_create_ept(struct rpmsg_device *rpdev,
rpmsg_rx_cb_t cb,
void *priv,
struct rpmsg_channel_info chinfo)
{
return __rpmsg_create_ept(rpdev->vrp, rpdev, cb, priv, chinfo.src);
}

/**
* __rpmsg_destroy_ept() - destroy an existing rpmsg endpoint
* @vrp: virtproc which owns this ept
Expand Down Expand Up @@ -341,7 +349,6 @@ static int rpmsg_dev_probe(struct device *dev)
{
struct rpmsg_device *rpdev = to_rpmsg_device(dev);
struct rpmsg_driver *rpdrv = to_rpmsg_driver(rpdev->dev.driver);
struct virtproc_info *vrp = rpdev->vrp;
struct rpmsg_channel_info chinfo = {};
struct rpmsg_endpoint *ept;
int err;
Expand All @@ -367,6 +374,18 @@ static int rpmsg_dev_probe(struct device *dev)
goto out;
}

if (rpdev->ops->announce_create)
err = rpdev->ops->announce_create(rpdev);
out:
return err;
}

static int virtio_rpmsg_announce_create(struct rpmsg_device *rpdev)
{
struct virtproc_info *vrp = rpdev->vrp;
struct device *dev = &rpdev->dev;
int err = 0;

/* need to tell remote processor's name service about this channel ? */
if (rpdev->announce &&
virtio_has_feature(vrp->vdev, VIRTIO_RPMSG_F_NS)) {
Expand All @@ -381,15 +400,13 @@ static int rpmsg_dev_probe(struct device *dev)
dev_err(dev, "failed to announce service %d\n", err);
}

out:
return err;
}

static int rpmsg_dev_remove(struct device *dev)
static int virtio_rpmsg_announce_destroy(struct rpmsg_device *rpdev)
{
struct rpmsg_device *rpdev = to_rpmsg_device(dev);
struct rpmsg_driver *rpdrv = to_rpmsg_driver(rpdev->dev.driver);
struct virtproc_info *vrp = rpdev->vrp;
struct device *dev = &rpdev->dev;
int err = 0;

/* tell remote processor's name service we're removing this channel */
Expand All @@ -406,6 +423,18 @@ static int rpmsg_dev_remove(struct device *dev)
dev_err(dev, "failed to announce service %d\n", err);
}

return err;
}

static int rpmsg_dev_remove(struct device *dev)
{
struct rpmsg_device *rpdev = to_rpmsg_device(dev);
struct rpmsg_driver *rpdrv = to_rpmsg_driver(rpdev->dev.driver);
int err = 0;

if (rpdev->ops->announce_destroy)
err = rpdev->ops->announce_destroy(rpdev);

rpdrv->remove(rpdev);

rpmsg_destroy_ept(rpdev->ept);
Expand Down Expand Up @@ -479,6 +508,12 @@ static int rpmsg_device_match(struct device *dev, void *data)
return 1;
}

static const struct rpmsg_device_ops virtio_rpmsg_ops = {
.create_ept = virtio_rpmsg_create_ept,
.announce_create = virtio_rpmsg_announce_create,
.announce_destroy = virtio_rpmsg_announce_destroy,
};

/*
* create an rpmsg channel using its name and address info.
* this function will be used to create both static and dynamic
Expand Down Expand Up @@ -508,6 +543,7 @@ static struct rpmsg_device *rpmsg_create_channel(struct virtproc_info *vrp,
rpdev->vrp = vrp;
rpdev->src = chinfo->src;
rpdev->dst = chinfo->dst;
rpdev->ops = &virtio_rpmsg_ops;

/*
* rpmsg server channels has predefined local address (for now),
Expand Down
23 changes: 23 additions & 0 deletions include/linux/rpmsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ enum rpmsg_ns_flags {
#define RPMSG_ADDR_ANY 0xFFFFFFFF

struct virtproc_info;
struct rpmsg_endpoint;
struct rpmsg_device_ops;

/**
* struct rpmsg_channel_info - channel info representation
Expand Down Expand Up @@ -127,10 +129,31 @@ struct rpmsg_device {
u32 dst;
struct rpmsg_endpoint *ept;
bool announce;

const struct rpmsg_device_ops *ops;
};

typedef void (*rpmsg_rx_cb_t)(struct rpmsg_device *, void *, int, void *, u32);

/**
* struct rpmsg_device_ops - indirection table for the rpmsg_device operations
* @create_ept: create backend-specific endpoint, requried
* @announce_create: announce presence of new channel, optional
* @announce_destroy: announce destruction of channel, optional
*
* Indirection table for the operations that a rpmsg backend should implement.
* @announce_create and @announce_destroy are optional as the backend might
* advertise new channels implicitly by creating the endpoints.
*/
struct rpmsg_device_ops {
struct rpmsg_endpoint *(*create_ept)(struct rpmsg_device *rpdev,
rpmsg_rx_cb_t cb, void *priv,
struct rpmsg_channel_info chinfo);

int (*announce_create)(struct rpmsg_device *ept);
int (*announce_destroy)(struct rpmsg_device *ept);
};

/**
* struct rpmsg_endpoint - binds a local rpmsg address to its user
* @rpdev: rpmsg channel device
Expand Down

0 comments on commit 36b72c7

Please sign in to comment.