Replace ENV mutex with the libmetal mutex
authorWendy Liang <jliang@xilinx.com>
Wed, 10 Aug 2016 19:27:53 +0000 (12:27 -0700)
committerWendy Liang <jliang@xilinx.com>
Thu, 13 Oct 2016 05:01:41 +0000 (22:01 -0700)
This patch is to replace the OpoenAMP env mutex with
the libmetal mutex.

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

index 1c31ecdc4aed6a77188c0455e5b6e379bdfbc340..9f33264dee412cee9389bab718252078a1d5655b 100644 (file)
@@ -88,11 +88,7 @@ struct sh_mem_pool *sh_mem_create_pool(void *start_addr, unsigned int size,
        if (mem_pool) {
                /* Initialize pool parameters */
                env_memset(mem_pool, 0x00, pool_size);
-               status = env_create_mutex(&mem_pool->lock, 1);
-               if (status) {
-                       env_free_memory(mem_pool);
-                       return NULL;
-               }
+               metal_mutex_init(&mem_pool->lock);
                mem_pool->start_addr = start_addr;
                mem_pool->buff_size = buff_size;
                mem_pool->bmp_size = bmp_size;
@@ -120,10 +116,10 @@ void *sh_mem_get_buffer(struct sh_mem_pool *pool)
        if (!pool)
                return NULL;
 
-       env_lock_mutex(pool->lock);
+       metal_mutex_acquire(&pool->lock);
 
        if (pool->used_buffs >= pool->total_buffs) {
-               env_unlock_mutex(pool->lock);
+               metal_mutex_release(&pool->lock);
                return NULL;
        }
 
@@ -146,7 +142,7 @@ void *sh_mem_get_buffer(struct sh_mem_pool *pool)
                }
        }
 
-       env_unlock_mutex(pool->lock);
+       metal_mutex_release(&pool->lock);
 
        return buff;
 }
@@ -170,7 +166,7 @@ void sh_mem_free_buffer(void *buff, struct sh_mem_pool *pool)
                return;
 
        /* Acquire the pool lock */
-       env_lock_mutex(pool->lock);
+       metal_mutex_acquire(&pool->lock);
 
        /* Map the buffer address to its index. */
        buff_idx = ((char *)buff - (char *)pool->start_addr) / pool->buff_size;
@@ -186,7 +182,7 @@ void sh_mem_free_buffer(void *buff, struct sh_mem_pool *pool)
        pool->used_buffs--;
 
        /* Release the pool lock. */
-       env_unlock_mutex(pool->lock);
+       metal_mutex_release(&pool->lock);
 
 }
 
@@ -203,7 +199,7 @@ void sh_mem_delete_pool(struct sh_mem_pool *pool)
 {
 
        if (pool) {
-               env_delete_mutex(pool->lock);
+               metal_mutex_deinit(&pool->lock);
                env_free_memory(pool);
        }
 }
index 60d7fdb78c16051f7be49c447ce1a77788865375..7ee62ba73cdca10c5012134c11069dcd09b1424a 100644 (file)
@@ -37,6 +37,7 @@
 #include "openamp/sh_mem.h"
 #include "openamp/llist.h"
 #include "openamp/rpmsg.h"
+#include "metal/mutex.h"
 
 /* Configurable parameters */
 #define RPMSG_BUFFER_SIZE                       512
@@ -116,7 +117,7 @@ struct remote_device {
        rpmsg_chnl_cb_t channel_created;
        rpmsg_chnl_cb_t channel_destroyed;
        rpmsg_rx_cb_t default_cb;
-       LOCK *lock;
+       metal_mutex_t lock;
        unsigned int role;
        unsigned int state;
        int support_ns;
index 067cb51c8f1803d9bb6915f382cee7d573e06781..68c1323c0309bbad4921def47a4d094d39edc558 100644 (file)
@@ -1,4 +1,6 @@
 #include "openamp/open_amp.h"
+#include "metal/mutex.h"
+
 /* RPC response buffer size */
 #define RPC_BUFF_SIZE 512
 
@@ -20,7 +22,7 @@ typedef void (*rpc_shutdown_cb) (struct rpmsg_channel *);
 struct _rpc_data {
        struct rpmsg_channel *rpmsg_chnl;
        struct rpmsg_endpoint *rp_ept;
-       void *rpc_lock;
+       metal_mutex_t rpc_lock;
        void *sync_lock;
        struct _sys_rpc *rpc;
        struct _sys_rpc *rpc_response;
index 6aa4eba6261a209625166eec2346853d020087a7..20a1760ad807e28457f08f96c0b8c844bff6bcb4 100644 (file)
@@ -47,6 +47,7 @@
 #define SH_MEM_H_
 
 #include "openamp/env.h"
+#include "metal/mutex.h"
 
 /* Macros */
 #define BITMAP_WORD_SIZE         (sizeof(unsigned long) << 3)
@@ -72,7 +73,7 @@
 
 struct sh_mem_pool {
        void *start_addr;
-       LOCK *lock;
+       metal_mutex_t lock;
        int size;
        int buff_size;
        int total_buffs;
index c0e8cceb145bc127f62a538658c3b6707034ca2c..90eca716737d164cdcb906aba57aa0885de8d9d1 100644 (file)
@@ -50,7 +50,7 @@ int rpmsg_retarget_init(struct rpmsg_channel *rp_chnl, rpc_shutdown_cb cb)
            (struct _rpc_data *)env_allocate_memory(sizeof(struct _rpc_data));
 
        /* Create a mutex for synchronization */
-       status = env_create_mutex(&rpc_data->rpc_lock, 1);
+       metal_mutex_init(&rpc_data->rpc_lock);
 
        /* Create a mutex for synchronization */
        status = env_create_sync_lock(&rpc_data->sync_lock, LOCKED);
@@ -72,7 +72,7 @@ int rpmsg_retarget_deinit(struct rpmsg_channel *rp_chnl)
 
        env_free_memory(rpc_data->rpc);
        env_free_memory(rpc_data->rpc_response);
-       env_delete_mutex(rpc_data->rpc_lock);
+       metal_mutex_deinit(&rpc_data->rpc_lock);
        env_delete_sync_lock(rpc_data->sync_lock);
        rpmsg_destroy_ept(rpc_data->rp_ept);
        env_free_memory(rpc_data);
@@ -114,9 +114,9 @@ int _open(const char *filename, int flags, int mode)
        memcpy(&rpc_data->rpc->sys_call_args.data, filename, filename_len);
 
        /* Transmit rpc request */
-       env_lock_mutex(rpc_data->rpc_lock);
+       metal_mutex_acquire(&rpc_data->rpc_lock);
        send_rpc((void *)rpc_data->rpc, payload_size);
-       env_unlock_mutex(rpc_data->rpc_lock);
+       metal_mutex_release(&rpc_data->rpc_lock);
 
        /* Wait for response from proxy on master */
        env_acquire_sync_lock(rpc_data->sync_lock);
@@ -155,10 +155,10 @@ int _read(int fd, char *buffer, int buflen)
        rpc_data->rpc->sys_call_args.data_len = 0;      /*not used */
 
        /* Transmit rpc request */
-       env_lock_mutex(rpc_data->rpc_lock);
+       metal_mutex_acquire(&rpc_data->rpc_lock);
        get_response = 0;
        send_rpc((void *)rpc_data->rpc, payload_size);
-       env_unlock_mutex(rpc_data->rpc_lock);
+       metal_mutex_release(&rpc_data->rpc_lock);
 
        /* Wait for response from proxy on master */
        env_acquire_sync_lock(rpc_data->sync_lock);
@@ -208,9 +208,9 @@ int _write(int fd, const char *ptr, int len)
                    0;
        }
 
-       env_lock_mutex(rpc_data->rpc_lock);
+       metal_mutex_acquire(&rpc_data->rpc_lock);
        send_rpc((void *)rpc_data->rpc, payload_size);
-       env_unlock_mutex(rpc_data->rpc_lock);
+       metal_mutex_release(&rpc_data->rpc_lock);
 
        env_acquire_sync_lock(rpc_data->sync_lock);
 
@@ -243,9 +243,9 @@ int _close(int fd)
        rpc_data->rpc->sys_call_args.int_field2 = 0;    /*not used */
        rpc_data->rpc->sys_call_args.data_len = 0;      /*not used */
 
-       env_lock_mutex(rpc_data->rpc_lock);
+       metal_mutex_acquire(&rpc_data->rpc_lock);
        send_rpc((void *)rpc_data->rpc, payload_size);
-       env_unlock_mutex(rpc_data->rpc_lock);
+       metal_mutex_release(&rpc_data->rpc_lock);
 
        /* Wait for response from proxy on master */
        env_acquire_sync_lock(rpc_data->sync_lock);
index 5daf3b30958226caf0ca1eb323b039838673df0f..03c1fe4687c619f7002188e6cefd5dc5adb84ff1 100644 (file)
@@ -114,13 +114,7 @@ int rpmsg_rdev_init(struct remote_device **rdev, int dev_id, int role,
        }
 
        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;
-       }
+       metal_mutex_init(&rdev_loc->lock);
 
        rdev_loc->proc = proc;
        rdev_loc->role = role;
@@ -207,9 +201,9 @@ void rpmsg_rdev_deinit(struct remote_device *rdev)
 
        /* Delete name service endpoint */
 
-       env_lock_mutex(rdev->lock);
+       metal_mutex_acquire(&rdev->lock);
        node = rpmsg_rdev_get_endpoint_from_addr(rdev, RPMSG_NS_EPT_ADDR);
-       env_unlock_mutex(rdev->lock);
+       metal_mutex_release(&rdev->lock);
        if (node) {
                _destroy_endpoint(rdev, (struct rpmsg_endpoint *)node->data);
        }
@@ -223,9 +217,7 @@ void rpmsg_rdev_deinit(struct remote_device *rdev)
        if (rdev->mem_pool) {
                sh_mem_delete_pool(rdev->mem_pool);
        }
-       if (rdev->lock) {
-               env_delete_mutex(rdev->lock);
-       }
+       metal_mutex_deinit(&rdev->lock);
        if (rdev->proc) {
                hil_delete_proc(rdev->proc);
                rdev->proc = 0;
index 64a89037e4750d24011729152ce8d866e90ed36b..1cbb8aaa88b534195c415b9616229be689882444 100644 (file)
@@ -163,11 +163,11 @@ int rpmsg_send_offchannel_raw(struct rpmsg_channel *rp_chnl, uint32_t src,
        }
 
        /* Lock the device to enable exclusive access to virtqueues */
-       env_lock_mutex(rdev->lock);
+       metal_mutex_acquire(&rdev->lock);
        /* Get rpmsg buffer for sending message. */
        buffer = rpmsg_get_tx_buffer(rdev, &buff_len, &idx);
        /* Unlock the device */
-       env_unlock_mutex(rdev->lock);
+       metal_mutex_release(&rdev->lock);
 
        if (!buffer && !wait) {
                return RPMSG_ERR_NO_BUFF;
@@ -179,9 +179,9 @@ int rpmsg_send_offchannel_raw(struct rpmsg_channel *rp_chnl, uint32_t src,
                 * 15 secs as defined by the APIs.
                 */
                env_sleep_msec(RPMSG_TICKS_PER_INTERVAL);
-               env_lock_mutex(rdev->lock);
+               metal_mutex_acquire(&rdev->lock);
                buffer = rpmsg_get_tx_buffer(rdev, &buff_len, &idx);
-               env_unlock_mutex(rdev->lock);
+               metal_mutex_release(&rdev->lock);
                tick_count += RPMSG_TICKS_PER_INTERVAL;
                if (!buffer && (tick_count >=
                    (RPMSG_TICK_COUNT / RPMSG_TICKS_PER_INTERVAL))) {
@@ -199,7 +199,7 @@ int rpmsg_send_offchannel_raw(struct rpmsg_channel *rp_chnl, uint32_t src,
        /* Copy data to rpmsg buffer. */
        env_memcpy((void*)RPMSG_LOCATE_DATA(rp_hdr), data, size);
 
-       env_lock_mutex(rdev->lock);
+       metal_mutex_acquire(&rdev->lock);
 
        /* Enqueue buffer on virtqueue. */
        ret = rpmsg_enqueue_buffer(rdev, buffer, buff_len, idx);
@@ -207,7 +207,7 @@ int rpmsg_send_offchannel_raw(struct rpmsg_channel *rp_chnl, uint32_t src,
        /* Let the other side know that there is a job to process. */
        virtqueue_kick(rdev->tvq);
 
-       env_unlock_mutex(rdev->lock);
+       metal_mutex_release(&rdev->lock);
 
        return RPMSG_SUCCESS;
 }
@@ -230,7 +230,7 @@ int rpmsg_get_buffer_size(struct rpmsg_channel *rp_chnl)
        /* Get associated remote device for channel. */
        rdev = rp_chnl->rdev;
 
-       env_lock_mutex(rdev->lock);
+       metal_mutex_acquire(&rdev->lock);
 
        if (rdev->role == RPMSG_REMOTE) {
                /*
@@ -248,7 +248,7 @@ int rpmsg_get_buffer_size(struct rpmsg_channel *rp_chnl)
                    sizeof(struct rpmsg_hdr);
        }
 
-       env_unlock_mutex(rdev->lock);
+       metal_mutex_release(&rdev->lock);
 
        return length;
 }
index e17b61baba20eea5ca31c0ec838e793d1f42c021..81c2602e6c1be1a717983d58e8e5d01c5df649b9 100644 (file)
@@ -167,9 +167,9 @@ struct rpmsg_channel *_rpmsg_create_channel(struct remote_device *rdev,
                        return RPMSG_NULL;
                }
                node->data = rp_chnl;
-               env_lock_mutex(rdev->lock);
+               metal_mutex_acquire(&rdev->lock);
                add_to_list(&rdev->rp_channels, node);
-               env_unlock_mutex(rdev->lock);
+               metal_mutex_release(&rdev->lock);
        }
 
        return rp_chnl;
@@ -188,18 +188,18 @@ void _rpmsg_delete_channel(struct rpmsg_channel *rp_chnl)
 {
        struct llist *node;
        if (rp_chnl) {
-               env_lock_mutex(rp_chnl->rdev->lock);
+               metal_mutex_acquire(&rp_chnl->rdev->lock);
                node =
                    rpmsg_rdev_get_chnl_node_from_id(rp_chnl->rdev,
                                                     rp_chnl->name);
                if (node) {
                        remove_from_list(&rp_chnl->rdev->rp_channels, node);
-                       env_unlock_mutex(rp_chnl->rdev->lock);
+                       metal_mutex_release(&rp_chnl->rdev->lock);
                        /* free node and rp_chnl */
                        env_free_memory(node);
                        env_free_memory(rp_chnl);
                } else {
-                       env_unlock_mutex(rp_chnl->rdev->lock);
+                       metal_mutex_release(&rp_chnl->rdev->lock);
                }
        }
 }
@@ -238,7 +238,7 @@ struct rpmsg_endpoint *_create_endpoint(struct remote_device *rdev,
                return RPMSG_NULL;
        }
 
-       env_lock_mutex(rdev->lock);
+       metal_mutex_acquire(&rdev->lock);
 
        if (addr != RPMSG_ADDR_ANY) {
                /*
@@ -265,7 +265,7 @@ struct rpmsg_endpoint *_create_endpoint(struct remote_device *rdev,
        if (RPMSG_SUCCESS != status) {
                env_free_memory(node);
                env_free_memory(rp_ept);
-               env_unlock_mutex(rdev->lock);
+               metal_mutex_release(&rdev->lock);
                return RPMSG_NULL;
        }
 
@@ -276,7 +276,7 @@ struct rpmsg_endpoint *_create_endpoint(struct remote_device *rdev,
        node->data = rp_ept;
        add_to_list(&rdev->rp_endpoints, node);
 
-       env_unlock_mutex(rdev->lock);
+       metal_mutex_release(&rdev->lock);
 
        return rp_ept;
 }
@@ -294,18 +294,18 @@ void _destroy_endpoint(struct remote_device *rdev,
                       struct rpmsg_endpoint *rp_ept)
 {
        struct llist *node;
-       env_lock_mutex(rdev->lock);
+       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);
-               env_unlock_mutex(rdev->lock);
+               metal_mutex_release(&rdev->lock);
                /* free node and rp_ept */
                env_free_memory(node);
                env_free_memory(rp_ept);
        } else {
-               env_unlock_mutex(rdev->lock);
+               metal_mutex_release(&rdev->lock);
        }
 }
 
@@ -328,12 +328,12 @@ void rpmsg_send_ns_message(struct remote_device *rdev,
        unsigned short idx;
        unsigned long len;
 
-       env_lock_mutex(rdev->lock);
+       metal_mutex_acquire(&rdev->lock);
 
        /* Get Tx buffer. */
        rp_hdr = (struct rpmsg_hdr *)rpmsg_get_tx_buffer(rdev, &len, &idx);
        if (!rp_hdr) {
-               env_unlock_mutex(rdev->lock);
+               metal_mutex_release(&rdev->lock);
                return;
        }
 
@@ -351,7 +351,7 @@ void rpmsg_send_ns_message(struct remote_device *rdev,
        /* Notify the other side that it has data to process. */
        virtqueue_kick(rdev->tvq);
 
-       env_unlock_mutex(rdev->lock);
+       metal_mutex_release(&rdev->lock);
 }
 
 /**
@@ -582,19 +582,19 @@ void rpmsg_rx_callback(struct virtqueue *vq)
                }
        }
 
-       env_lock_mutex(rdev->lock);
+       metal_mutex_acquire(&rdev->lock);
 
        /* Process the received data from remote node */
        rp_hdr = (struct rpmsg_hdr *)rpmsg_get_rx_buffer(rdev, &len, &idx);
 
-       env_unlock_mutex(rdev->lock);
+       metal_mutex_release(&rdev->lock);
 
        while (rp_hdr) {
 
                /* Get the channel node from the remote device channels list. */
-               env_lock_mutex(rdev->lock);
+               metal_mutex_acquire(&rdev->lock);
                node = rpmsg_rdev_get_endpoint_from_addr(rdev, rp_hdr->dst);
-               env_unlock_mutex(rdev->lock);
+               metal_mutex_release(&rdev->lock);
 
                if (!node)
                        /* Fatal error no endpoint for the given dst addr. */
@@ -619,14 +619,14 @@ void rpmsg_rx_callback(struct virtqueue *vq)
                                   rp_ept->priv, rp_hdr->src);
                }
 
-               env_lock_mutex(rdev->lock);
+               metal_mutex_acquire(&rdev->lock);
 
                /* Return used buffers. */
                rpmsg_return_buffer(rdev, rp_hdr, len, idx);
 
                rp_hdr =
                    (struct rpmsg_hdr *)rpmsg_get_rx_buffer(rdev, &len, &idx);
-               env_unlock_mutex(rdev->lock);
+               metal_mutex_release(&rdev->lock);
        }
 }
 
@@ -665,9 +665,9 @@ void rpmsg_ns_callback(struct rpmsg_channel *server_chnl, void *data, int len,
        ns_msg->name[len - 1] = '\0';
 
        if (ns_msg->flags & RPMSG_NS_DESTROY) {
-               env_lock_mutex(rdev->lock);
+               metal_mutex_acquire(&rdev->lock);
                node = rpmsg_rdev_get_chnl_node_from_id(rdev, ns_msg->name);
-               env_unlock_mutex(rdev->lock);
+               metal_mutex_release(&rdev->lock);
                if (node) {
                        rp_chnl = (struct rpmsg_channel *)node->data;
                        if (rdev->channel_destroyed) {