Replace llist with metal_list for rpmsg endpoint
authorWendy Liang <jliang@xilinx.com>
Fri, 27 May 2016 23:23:59 +0000 (16:23 -0700)
committerWendy Liang <jliang@xilinx.com>
Thu, 13 Oct 2016 05:01:43 +0000 (22:01 -0700)
Use metal_list to keep rpmsg endpoints

Signed-off-by: Wendy Liang <jliang@xilinx.com>
lib/include/openamp/rpmsg.h
lib/include/openamp/rpmsg_core.h
lib/rpmsg/remote_device.c
lib/rpmsg/rpmsg_core.c

index 8bd56d50ac9961ba176b3831bbcd282aa740cae2..1230f6b35b4be5a2daed7a7fe26b8072bdd366d5 100644 (file)
@@ -153,6 +153,7 @@ struct rpmsg_endpoint {
        rpmsg_rx_cb_t cb;
        uint32_t addr;
        void *priv;
+       struct metal_list node;
 };
 
 struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_channel *rp_chnl,
index d75ef27d0a5fa6d5f3d143a9ba27f17a6f9c4f72..f2e814a35199ac49ef60a456f60e83ead62406cb 100644 (file)
@@ -120,7 +120,7 @@ struct remote_device {
        struct virtqueue *tvq;
        struct hil_proc *proc;
        struct metal_list rp_channels;
-       struct llist *rp_endpoints;
+       struct metal_list rp_endpoints;
        struct sh_mem_pool *mem_pool;
        unsigned long bitmap[RPMSG_ADDR_BMP_SIZE];
        rpmsg_chnl_cb_t channel_created;
@@ -170,8 +170,9 @@ int rpmsg_rdev_init(struct remote_device **rdev, int dev_id, int role,
 void rpmsg_rdev_deinit(struct remote_device *rdev);
 struct rpmsg_channel *rpmsg_rdev_get_chnl_from_id(struct remote_device *rdev,
                                               char *rp_chnl_id);
-struct llist *rpmsg_rdev_get_endpoint_from_addr(struct remote_device *rdev,
-                                               unsigned long addr);
+struct rpmsg_endpoint *rpmsg_rdev_get_endpoint_from_addr(
+                                       struct remote_device *rdev,
+                                       unsigned long addr);
 int rpmsg_rdev_notify(struct remote_device *rdev);
 int rpmsg_rdev_create_virtqueues(struct virtio_device *dev, int flags, int nvqs,
                                 const char *names[], vq_callback * callbacks[],
index d808db0f5da03a940644b2d557cc9d772f8e07ca..3dcb55069f66bbaed608065a0454f160f0199940 100644 (file)
@@ -150,6 +150,9 @@ int rpmsg_rdev_init(struct remote_device **rdev, int dev_id, int role,
                }
        }
 
+       /* Initialize endpoints list */
+       metal_list_init(&rdev_loc->rp_endpoints);
+
        /* Initialize channels for RPMSG Remote */
        status = rpmsg_rdev_init_channels(rdev_loc);
 
@@ -174,14 +177,14 @@ int rpmsg_rdev_init(struct remote_device **rdev, int dev_id, int role,
  */
 void rpmsg_rdev_deinit(struct remote_device *rdev)
 {
-       struct llist *node;
-       struct metal_list *chnode;
+       struct metal_list *node;
        struct rpmsg_channel *rp_chnl;
+       struct rpmsg_endpoint *rp_ept;
 
 
        while(!metal_list_is_empty(&rdev->rp_channels)) {
-               chnode = rdev->rp_channels.next;
-               rp_chnl = metal_container_of(chnode, struct rpmsg_channel, node);
+               node = rdev->rp_channels.next;
+               rp_chnl = metal_container_of(node, struct rpmsg_channel, node);
 
                if (rdev->channel_destroyed) {
                        rdev->channel_destroyed(rp_chnl);
@@ -200,12 +203,11 @@ void rpmsg_rdev_deinit(struct remote_device *rdev)
        }
 
        /* Delete name service endpoint */
-
        metal_mutex_acquire(&rdev->lock);
-       node = rpmsg_rdev_get_endpoint_from_addr(rdev, RPMSG_NS_EPT_ADDR);
+       rp_ept = rpmsg_rdev_get_endpoint_from_addr(rdev, RPMSG_NS_EPT_ADDR);
        metal_mutex_release(&rdev->lock);
-       if (node) {
-               _destroy_endpoint(rdev, (struct rpmsg_endpoint *)node->data);
+       if (rp_ept) {
+               _destroy_endpoint(rdev, rp_ept);
        }
 
        if (rdev->rvq) {
@@ -265,23 +267,21 @@ struct rpmsg_channel *rpmsg_rdev_get_chnl_from_id(struct remote_device *rdev,
  * @param rdev - pointer remote device control block
  * @param addr - src address
  *
- * @return - endpoint node
+ * @return - rpmsg endpoint
  *
  */
-struct llist *rpmsg_rdev_get_endpoint_from_addr(struct remote_device *rdev,
+struct rpmsg_endpoint *rpmsg_rdev_get_endpoint_from_addr(struct remote_device *rdev,
                                                unsigned long addr)
 {
-       struct llist *rp_ept_lut_head;
-
-       rp_ept_lut_head = rdev->rp_endpoints;
+       struct rpmsg_endpoint *rp_ept;
+       struct metal_list *node;
 
-       while (rp_ept_lut_head) {
-               struct rpmsg_endpoint *rp_ept =
-                   (struct rpmsg_endpoint *)rp_ept_lut_head->data;
+       metal_list_for_each(&rdev->rp_endpoints, node) {
+               rp_ept = metal_container_of(node,
+                               struct rpmsg_endpoint, node);
                if (rp_ept->addr == addr) {
-                       return rp_ept_lut_head;
+                       return rp_ept;
                }
-               rp_ept_lut_head = rp_ept_lut_head->next;
        }
 
        return RPMSG_NULL;
index 6456382d466aeeb5853b8a046f1cb2482a7f8da3..d282763543841ccb39131f3fed82a7111c49b0a5 100644 (file)
@@ -208,7 +208,6 @@ struct rpmsg_endpoint *_create_endpoint(struct remote_device *rdev,
 {
 
        struct rpmsg_endpoint *rp_ept;
-       struct llist *node;
        int status = RPMSG_SUCCESS;
 
        rp_ept = env_allocate_memory(sizeof(struct rpmsg_endpoint));
@@ -217,12 +216,6 @@ struct rpmsg_endpoint *_create_endpoint(struct remote_device *rdev,
        }
        memset(rp_ept, 0x00, sizeof(struct rpmsg_endpoint));
 
-       node = env_allocate_memory(sizeof(struct llist));
-       if (!node) {
-               env_free_memory(rp_ept);
-               return RPMSG_NULL;
-       }
-
        metal_mutex_acquire(&rdev->lock);
 
        if (addr != RPMSG_ADDR_ANY) {
@@ -248,7 +241,6 @@ struct rpmsg_endpoint *_create_endpoint(struct remote_device *rdev,
 
        /* Do cleanup in case of error and return */
        if (RPMSG_SUCCESS != status) {
-               env_free_memory(node);
                env_free_memory(rp_ept);
                metal_mutex_release(&rdev->lock);
                return RPMSG_NULL;
@@ -258,8 +250,7 @@ struct rpmsg_endpoint *_create_endpoint(struct remote_device *rdev,
        rp_ept->cb = cb;
        rp_ept->priv = priv;
 
-       node->data = rp_ept;
-       add_to_list(&rdev->rp_endpoints, node);
+       metal_list_add_tail(&rdev->rp_endpoints, &rp_ept->node);
 
        metal_mutex_release(&rdev->lock);
 
@@ -278,20 +269,13 @@ struct rpmsg_endpoint *_create_endpoint(struct remote_device *rdev,
 void _destroy_endpoint(struct remote_device *rdev,
                       struct rpmsg_endpoint *rp_ept)
 {
-       struct llist *node;
        metal_mutex_acquire(&rdev->lock);
-       node = rpmsg_rdev_get_endpoint_from_addr(rdev, rp_ept->addr);
-       if (node) {
-               rpmsg_release_address(rdev->bitmap, RPMSG_ADDR_BMP_SIZE,
-                                     rp_ept->addr);
-               remove_from_list(&rdev->rp_endpoints, node);
-               metal_mutex_release(&rdev->lock);
-               /* free node and rp_ept */
-               env_free_memory(node);
-               env_free_memory(rp_ept);
-       } else {
-               metal_mutex_release(&rdev->lock);
-       }
+       rpmsg_release_address(rdev->bitmap, RPMSG_ADDR_BMP_SIZE,
+                             rp_ept->addr);
+       metal_list_del(&rp_ept->node);
+       metal_mutex_release(&rdev->lock);
+       /* free node and rp_ept */
+       env_free_memory(rp_ept);
 }
 
 /**
@@ -543,8 +527,7 @@ void rpmsg_rx_callback(struct virtqueue *vq)
        struct rpmsg_channel *rp_chnl;
        struct rpmsg_endpoint *rp_ept;
        struct rpmsg_hdr *rp_hdr;
-       struct llist *node;
-       struct metal_list *chnode;
+       struct metal_list *node;
        unsigned long len;
        unsigned short idx;
 
@@ -552,8 +535,8 @@ void rpmsg_rx_callback(struct virtqueue *vq)
        rdev = (struct remote_device *)vdev;
 
        if (rdev->role == RPMSG_MASTER) {
-               metal_list_for_each(&rdev->rp_channels, chnode) {
-                       rp_chnl = metal_container_of(chnode,
+               metal_list_for_each(&rdev->rp_channels, node) {
+                       rp_chnl = metal_container_of(node,
                                struct rpmsg_channel, node);
                        if (rp_chnl->state == RPMSG_CHNL_STATE_IDLE) {
                                if (rdev->support_ns) {
@@ -579,15 +562,13 @@ void rpmsg_rx_callback(struct virtqueue *vq)
 
                /* Get the channel node from the remote device channels list. */
                metal_mutex_acquire(&rdev->lock);
-               node = rpmsg_rdev_get_endpoint_from_addr(rdev, rp_hdr->dst);
+               rp_ept = rpmsg_rdev_get_endpoint_from_addr(rdev, rp_hdr->dst);
                metal_mutex_release(&rdev->lock);
 
-               if (!node)
+               if (!rp_ept)
                        /* Fatal error no endpoint for the given dst addr. */
                        return;
 
-               rp_ept = (struct rpmsg_endpoint *)node->data;
-
                rp_chnl = rp_ept->rp_chnl;
 
                if ((rp_chnl) && (rp_chnl->state == RPMSG_CHNL_STATE_NS)) {