rpmsg: run cache ops against cacheable buffers
authorWendy Liang <jliang@xilinx.com>
Tue, 2 Aug 2016 18:42:32 +0000 (11:42 -0700)
committerWendy Liang <jliang@xilinx.com>
Thu, 13 Oct 2016 05:01:46 +0000 (22:01 -0700)
If the shared buffers are cacheable, flush cache
before it enqueues the buffer to send, and invalidate
cache before it reads the buffer to receive.

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

index d389e8d2eb3f1d69666d6772eaf1c7e108c1e302..6245b3f64dfb32f1868923008caf8982c15be61c 100644 (file)
@@ -49,6 +49,8 @@
 #include <string.h>
 #include "openamp/rpmsg.h"
 #include "metal/utilities.h"
+#include "metal/io.h"
+#include "metal/cache.h"
 
 /* Internal functions */
 static void rpmsg_rx_callback(struct virtqueue *vq);
@@ -341,6 +343,7 @@ int rpmsg_enqueue_buffer(struct remote_device *rdev, void *buffer,
 {
        struct llist node;
        int status;
+       struct metal_io_region *io;
 
        /* Initialize buffer node */
        node.data = buffer;
@@ -348,6 +351,11 @@ int rpmsg_enqueue_buffer(struct remote_device *rdev, void *buffer,
        node.next = RPMSG_NULL;
        node.prev = RPMSG_NULL;
 
+       io = rdev->proc->sh_buff.io;
+       if (io) {
+               if (! (io->mem_flags & METAL_UNCACHED))
+                       metal_cache_flush(buffer, (unsigned int)len);
+       }
        if (rdev->role == RPMSG_REMOTE) {
                status = virtqueue_add_buffer(rdev->tvq, &node, 0, 1, buffer);
        } else {
@@ -440,6 +448,15 @@ void *rpmsg_get_rx_buffer(struct remote_device *rdev, unsigned long *len,
                    virtqueue_get_available_buffer(rdev->rvq, idx,
                                                   (uint32_t *) len);
        }
+       if (data) {
+               struct metal_io_region *io;
+               io = rdev->proc->sh_buff.io;
+               if (io) {
+                       if (! (io->mem_flags & METAL_UNCACHED))
+                               metal_cache_invalidate(data,
+                                       (unsigned int)(*len));
+               }
+       }
        return data;
 }