[PATCH V2 2/3] staging: vc04_services: Add vchi_queue_user_message function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The vchi_msg_queue function which is used by other drivers
to queue a message is difficult to understand and overly
generic.

Add a new function which is a wrapper on top of vchi_msg_queue
that is specifically for queuing a message located in user
address space.

int
vchi_queue_user_message(VCHI_SERVICE_HANDLE_T handle,
                        void __user *data,
                        unsigned int size)

Signed-off-by: Michael Zoran <mzoran@xxxxxxxxxxxx>
---
 .../staging/vc04_services/interface/vchi/vchi.h    |  6 ++++
 .../vc04_services/interface/vchiq_arm/vchiq_shim.c | 34 ++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/drivers/staging/vc04_services/interface/vchi/vchi.h b/drivers/staging/vc04_services/interface/vchi/vchi.h
index 7ab74f76f2f8..1a401f04d03f 100644
--- a/drivers/staging/vc04_services/interface/vchi/vchi.h
+++ b/drivers/staging/vc04_services/interface/vchi/vchi.h
@@ -233,6 +233,12 @@ vchi_queue_kernel_message(VCHI_SERVICE_HANDLE_T handle,
 			  void *data,
 			  unsigned int size);
 
+/* Routine to send a message from user memory across a service */
+extern int
+vchi_queue_user_message(VCHI_SERVICE_HANDLE_T handle,
+			void __user *data,
+			unsigned int size);
+
 // Routine to receive a msg from a service
 // Dequeue is equivalent to hold, copy into client buffer, release
 extern int32_t vchi_msg_dequeue( VCHI_SERVICE_HANDLE_T handle,
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_shim.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_shim.c
index 26edd6e69dcd..8987c4ad3653 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_shim.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_shim.c
@@ -210,6 +210,40 @@ vchi_queue_kernel_message(VCHI_SERVICE_HANDLE_T handle,
 }
 EXPORT_SYMBOL(vchi_queue_kernel_message);
 
+struct vchi_queue_user_message_context {
+	void __user *data;
+};
+
+static ssize_t
+vchi_queue_user_message_callback(void *context,
+				 void *dest,
+				 size_t offset,
+				 size_t maxsize)
+{
+	struct vchi_queue_user_message_context *copycontext = context;
+
+	if (copy_from_user(dest, copycontext->data + offset, maxsize))
+		return -EFAULT;
+
+	return maxsize;
+}
+
+int
+vchi_queue_user_message(VCHI_SERVICE_HANDLE_T handle,
+			void __user *data,
+			unsigned int size)
+{
+	struct vchi_queue_user_message_context copycontext = {
+		.data = data
+	};
+
+	return vchi_msg_queue(handle,
+			      vchi_queue_user_message_callback,
+			      &copycontext,
+			      size);
+}
+EXPORT_SYMBOL(vchi_queue_user_message);
+
 /***********************************************************
  * Name: vchi_bulk_queue_receive
  *
-- 
2.11.0

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux