Skip to contentSkip to conversation

staging/vchi: Start on 64-bit cleanup, TODO file.

PATCH In review Eric Anholt 3 participants 13 messages Oct 17, 2016 – Oct 25, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover staging/vchi: Start on 64-bit cleanup, TODO file.

Here's a little cleanup of VCHI this morning, working toward building on aarch64 (not there yet) and adding some notes on what I think we need to do with the driver.

Eric Anholt (5):
staging/vchi: Fix build error in debugfs ops on aarch64. staging/vchi: Fix build warnings when formatting pointers on aarch64. staging/vchi: Fix some pointer math for 64-bit. staging/vchi: Add a TODO file of things I know we need to deal with.
MAINTAINERS: Add the staging vchiq driver as a bcm2835 responsibility.

 MAINTAINERS                                        |   1 +
 drivers/staging/vc04_services/interface/vchi/TODO  |  50 ++++++
 .../interface/vchiq_arm/vchiq_2835_arm.c           |  15 +-
 .../vc04_services/interface/vchiq_arm/vchiq_arm.c  |  32 ++--
 .../vc04_services/interface/vchiq_arm/vchiq_core.c | 183 +++++++++++----------
 .../interface/vchiq_arm/vchiq_debugfs.c            |   4 +-
 6 files changed, 168 insertions(+), 117 deletions(-)
 create mode 100644 drivers/staging/vc04_services/interface/vchi/TODO
Signature · 1 line
2.9.3
#1 lore raw

PATCH 1/5 staging/vchi: Fix build error in debugfs ops on aarch64.

file_operations.write returns a ssize_t, which worked out fine on 32 bit but errors out on 64 bit.

---
 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_debugfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_debugfs.c +2 -2
index 7e032130d967..f07cd4448ddf 100644
@@ -120,7 +120,7 @@ static int debugfs_log_open(struct inode *inode, struct file *file)
 	return single_open(file, debugfs_log_show, inode->i_private);
 }
 
-static int debugfs_log_write(struct file *file,
+static ssize_t debugfs_log_write(struct file *file,
 	const char __user *buffer,
 	size_t count, loff_t *ppos)
 {
@@ -229,7 +229,7 @@ static int debugfs_trace_open(struct inode *inode, struct file *file)
 	return single_open(file, debugfs_trace_show, inode->i_private);
 }
 
-static int debugfs_trace_write(struct file *file,
+static ssize_t debugfs_trace_write(struct file *file,
 	const char __user *buffer,
 	size_t count, loff_t *ppos)
 {
Signature · 1 line
2.9.3
#2 lore raw

Re: [PATCH 1/5] staging/vchi: Fix build error in debugfs ops on aarch64.

Quoted 7 lines · Eric Anholt

file_operations.write returns a ssize_t, which worked out fine on 32 bit but errors out on 64 bit.

---
 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_debugfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

I also have already fixed this one :)

#3 lore raw

PATCH 2/5 staging/vchi: Fix build warnings when formatting pointers on aarch64.

In reply to Eric Anholt

The code was generally using "%x" to print and "(unsigned int)" to cast the pointers, but we have %p for printing pointers in the same format without any broken casts.

---
 .../interface/vchiq_arm/vchiq_2835_arm.c           |   9 +-
 .../vc04_services/interface/vchiq_arm/vchiq_arm.c  |  32 ++--
 .../vc04_services/interface/vchiq_arm/vchiq_core.c | 178 ++++++++++-----------
 3 files changed, 109 insertions(+), 110 deletions(-)
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c +4 -5
index 4cb5bff23728..c5255bc6c589 100644
@@ -174,8 +174,8 @@ int vchiq_platform_init(struct platform_device *pdev, VCHIQ_STATE_T *state)
 	}
 
 	vchiq_log_info(vchiq_arm_log_level,
-		"vchiq_init - done (slots %x, phys %pad)",
-		(unsigned int)vchiq_slot_zero, &slot_phys);
+		"vchiq_init - done (slots %p, phys %pad)",
+		vchiq_slot_zero, &slot_phys);
 
 	vchiq_call_connected_callbacks();
 
@@ -389,8 +389,7 @@ create_pagelist(char __user *buf, size_t count, unsigned short type,
                            (num_pages * sizeof(pages[0])),
                            GFP_KERNEL);
 
-	vchiq_log_trace(vchiq_arm_log_level,
-		"create_pagelist - %x", (unsigned int)pagelist);
+	vchiq_log_trace(vchiq_arm_log_level, "create_pagelist - %p", pagelist);
 	if (!pagelist)
 		return -ENOMEM;
 
@@ -515,7 +514,7 @@ free_pagelist(PAGELIST_T *pagelist, int actual)
 	unsigned int num_pages, i;
 
 	vchiq_log_trace(vchiq_arm_log_level,
-		"free_pagelist - %x, %d", (unsigned int)pagelist, actual);
+		"free_pagelist - %p, %d", pagelist, actual);
 
 	num_pages =
 		(pagelist->length + pagelist->offset + PAGE_SIZE - 1) /
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +16 -16
index 47df1af2219d..68ee5216f5bc 100644
@@ -418,8 +418,8 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 	DEBUG_INITIALISE(g_state.local)
 
 	vchiq_log_trace(vchiq_arm_log_level,
-		 "vchiq_ioctl - instance %x, cmd %s, arg %lx",
-		(unsigned int)instance,
+		 "vchiq_ioctl - instance %p, cmd %s, arg %lx",
+		instance,
 		((_IOC_TYPE(cmd) == VCHIQ_IOC_MAGIC) &&
 		(_IOC_NR(cmd) <= VCHIQ_IOC_MAX)) ?
 		ioctl_names[_IOC_NR(cmd)] : "<invalid>", arg);
@@ -713,8 +713,8 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 				break;
 			}
 			vchiq_log_info(vchiq_arm_log_level,
-				"found bulk_waiter %x for pid %d",
-				(unsigned int)waiter, current->pid);
+				"found bulk_waiter %p for pid %d",
+				waiter, current->pid);
 			args.userdata = &waiter->bulk_waiter;
 		}
 		status = vchiq_bulk_transfer
@@ -743,8 +743,8 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 			list_add(&waiter->list, &instance->bulk_waiter_list);
 			mutex_unlock(&instance->bulk_waiter_list_mutex);
 			vchiq_log_info(vchiq_arm_log_level,
-				"saved bulk_waiter %x for pid %d",
-				(unsigned int)waiter, current->pid);
+				"saved bulk_waiter %p for pid %d",
+				waiter, current->pid);
 
 			if (copy_to_user((void __user *)
 				&(((VCHIQ_QUEUE_BULK_TRANSFER_T __user *)
@@ -826,9 +826,9 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 					if (args.msgbufsize < msglen) {
 						vchiq_log_error(
 							vchiq_arm_log_level,
-							"header %x: msgbufsize"
+							"header %p: msgbufsize"
 							" %x < msglen %x",
-							(unsigned int)header,
+							header,
 							args.msgbufsize,
 							msglen);
 						WARN(1, "invalid message "
@@ -980,8 +980,8 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 				ret = -EFAULT;
 		} else {
 			vchiq_log_error(vchiq_arm_log_level,
-				"header %x: bufsize %x < size %x",
-				(unsigned int)header, args.bufsize,
+				"header %p: bufsize %x < size %x",
+				header, args.bufsize,
 				header->size);
 			WARN(1, "invalid size\n");
 			ret = -EMSGSIZE;
@@ -1284,9 +1284,9 @@ vchiq_release(struct inode *inode, struct file *file)
 					list);
 				list_del(pos);
 				vchiq_log_info(vchiq_arm_log_level,
-					"bulk_waiter - cleaned up %x "
+					"bulk_waiter - cleaned up %p "
 					"for pid %d",
-					(unsigned int)waiter, waiter->pid);
+					waiter, waiter->pid);
 				kfree(waiter);
 			}
 		}
@@ -1385,9 +1385,9 @@ vchiq_dump_platform_instances(void *dump_context)
 			instance = service->instance;
 			if (instance && !instance->mark) {
 				len = snprintf(buf, sizeof(buf),
-					"Instance %x: pid %d,%s completions "
+					"Instance %p: pid %d,%s completions "
 						"%d/%d",
-					(unsigned int)instance, instance->pid,
+					instance, instance->pid,
 					instance->connected ? " connected, " :
 						"",
 					instance->completion_insert -
@@ -1415,8 +1415,8 @@ vchiq_dump_platform_service_state(void *dump_context, VCHIQ_SERVICE_T *service)
 	char buf[80];
 	int len;
 
-	len = snprintf(buf, sizeof(buf), "  instance %x",
-		(unsigned int)service->instance);
+	len = snprintf(buf, sizeof(buf), "  instance %p",
+		       service->instance);
 
 	if ((service->base.callback == service_callback) &&
 		user_service->is_vchi) {
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c +89 -89

472 lines not on this page · raw message

Signature · 1 line
2.9.3
#4 lore raw

Re: [PATCH 2/5] staging/vchi: Fix build warnings when formatting pointers on aarch64.

Quoted 3 lines · Eric Anholt

The code was generally using "%x" to print and "(unsigned int)" to cast the pointers, but we have %p for printing pointers in the same format without any broken casts.

I already did this work, it's all checked into my tree, and is in linux-next now. You were cc:ed on the patches as well.

Also, please use "%pK" for kernel pointers, you never want to print an address to userspace unless debugging is enabled, as it is a security leak.

thanks,

greg k-h

#5 lore raw

Re: [PATCH 2/5] staging/vchi: Fix build warnings when formatting pointers on aarch64.

Quoted 7 lines · Greg Kroah-Hartman
Quoted 3 lines · Eric Anholt

The code was generally using "%x" to print and "(unsigned int)" to cast the pointers, but we have %p for printing pointers in the same format without any broken casts.

I already did this work, it's all checked into my tree, and is in linux-next now. You were cc:ed on the patches as well.

I actually haven't seen any of those messages about the patches. It looks like it's actually that notmuch is still failing to parse some mails (they apparently disagree with postfix on how maildir files should be formatted, so they just drop some mail on the floor).

I did check the staging-testing branch before I started, since that's
where things were last I knew, and didn't know it had moved to -next.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 800 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20161017/c79885f6/attachment.sig>

#6 lore raw

Re: [PATCH 2/5] staging/vchi: Fix build warnings when formatting pointers on aarch64.

Quoted 10 lines · Eric Anholt
Quoted 7 lines · Greg Kroah-Hartman
Quoted 3 lines · Eric Anholt

The code was generally using "%x" to print and "(unsigned int)" to cast the pointers, but we have %p for printing pointers in the same format without any broken casts.

I already did this work, it's all checked into my tree, and is in linux-next now. You were cc:ed on the patches as well.

Quoted 7 lines

I actually haven't seen any of those messages about the patches. It looks like it's actually that notmuch is still failing to parse some mails (they apparently disagree with postfix on how maildir files should be formatted, so they just drop some mail on the floor).

I did check the staging-testing branch before I started, since that's where things were last I knew, and didn't know it had moved to -next.

But staging-testing has those fixes in it (it gets pulled into -next). So I don't see how we got out of sync here...

thanks,

greg k-h

#7 lore raw

PATCH 3/5 staging/vchi: Fix some pointer math for 64-bit.

In reply to Eric Anholt

These were throwing warnings on aarch64, and all are trivially converted to longs.

---
 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c | 6 +++---
 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c     | 5 +++--
 2 files changed, 6 insertions(+), 5 deletions(-)
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c +3 -3
index c5255bc6c589..3c7165b34dab 100644
@@ -121,7 +121,7 @@ int vchiq_platform_init(struct platform_device *pdev, VCHIQ_STATE_T *state)
 		return -ENOMEM;
 	}
 
-	WARN_ON(((int)slot_mem & (PAGE_SIZE - 1)) != 0);
+	WARN_ON(((unsigned long)slot_mem & (PAGE_SIZE - 1)) != 0);
 
 	vchiq_slot_zero = vchiq_init_slots(slot_mem, slot_mem_size);
 	if (!vchiq_slot_zero)
@@ -222,7 +222,7 @@ remote_event_signal(REMOTE_EVENT_T *event)
 int
 vchiq_copy_from_user(void *dst, const void *src, int size)
 {
-	if ((uint32_t)src < TASK_SIZE) {
+	if ((unsigned long)src < TASK_SIZE) {
 		return copy_from_user(dst, src, size);
 	} else {
 		memcpy(dst, src, size);
@@ -375,7 +375,7 @@ create_pagelist(char __user *buf, size_t count, unsigned short type,
 	int run, addridx, actual_pages;
         unsigned long *need_release;
 
-	offset = (unsigned int)buf & (PAGE_SIZE - 1);
+	offset = (unsigned long)buf & (PAGE_SIZE - 1);
 	num_pages = (count + offset + PAGE_SIZE - 1) / PAGE_SIZE;
 
 	*ppagelist = NULL;
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c +3 -2
index 93a6ac75791f..6862cbc0d7a9 100644
@@ -1723,7 +1723,7 @@ parse_rx_slots(VCHIQ_STATE_T *state)
 					min(64, size));
 		}
 
-		if (((unsigned int)header & VCHIQ_SLOT_MASK) + calc_stride(size)
+		if (((unsigned long)header & VCHIQ_SLOT_MASK) + calc_stride(size)
 			> VCHIQ_SLOT_SIZE) {
 			vchiq_log_error(vchiq_core_log_level,
 				"header %p (msgid %x) - size %x too big for "
@@ -2268,7 +2268,8 @@ get_conn_state_name(VCHIQ_CONNSTATE_T conn_state)
 VCHIQ_SLOT_ZERO_T *
 vchiq_init_slots(void *mem_base, int mem_size)
 {
-	int mem_align = (VCHIQ_SLOT_SIZE - (int)mem_base) & VCHIQ_SLOT_MASK;
+	int mem_align = (VCHIQ_SLOT_SIZE -
+			 (unsigned long)mem_base) & VCHIQ_SLOT_MASK;
 	VCHIQ_SLOT_ZERO_T *slot_zero =
 		(VCHIQ_SLOT_ZERO_T *)((char *)mem_base + mem_align);
 	int num_slots = (mem_size - mem_align)/VCHIQ_SLOT_SIZE;
Signature · 1 line
2.9.3
#8 lore raw

Re: [PATCH 3/5] staging/vchi: Fix some pointer math for 64-bit.

Quoted 8 lines · Eric Anholt

These were throwing warnings on aarch64, and all are trivially converted to longs.

---
 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c | 6 +++---
 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c     | 5 +++--
 2 files changed, 6 insertions(+), 5 deletions(-)

This didnt apply anymore as I think I took the other fixups, sorry.

greg k-h

#9 lore raw

Re: [PATCH 3/5] staging/vchi: Fix some pointer math for 64-bit.

Quoted 11 lines · Greg Kroah-Hartman
Quoted 8 lines · Eric Anholt

These were throwing warnings on aarch64, and all are trivially converted to longs.

---
 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c | 6 +++---
 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c     | 5 +++--
 2 files changed, 6 insertions(+), 5 deletions(-)

This didnt apply anymore as I think I took the other fixups, sorry.

No problem, I'm happy to see Michael's stuff getting merged.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 800 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20161025/36d2d692/attachment-0001.sig>

#10 lore raw

PATCH 4/5 staging/vchi: Add a TODO file of things I know we need to deal with.

In reply to Eric Anholt

I've left out the downstream HDMI audio driver from the "to be imported" section, as we'll want to handle it natively in vc4. The downstream kernel will likely continue to use that driver for a while due to using the interim "vc4 firmware KMS" mode while vc4 gets its featureset (such as HDMI audio!) completed.

I've also left out VC-CMA, which appears to be about having Linux manage a CMA area that the firmware gets to make allocations out of. I'm not clear on if this is useful (the firmware's need for memory drops massively with vc4 present, and may drop even more depending on how we resolve dmabuf handling for camera and video decode)

---
 drivers/staging/vc04_services/interface/vchi/TODO | 50 +++++++++++++++++++++++
 1 file changed, 50 insertions(+)
 create mode 100644 drivers/staging/vc04_services/interface/vchi/TODO
drivers/staging/vc04_services/interface/vchi/TODO new file +50 -0
new file mode 100644
index 000000000000..03aa65183b25
@@ -0,0 +1,50 @@
+1) Port to aarch64
+
+This driver won't be very useful unless we also have it working on
+Raspberry Pi 3.  This requires, at least:
+
+  - Figure out an alternative to the dmac_map_area() hack.
+
+  - Decide what to use instead of dsb().
+
+  - Do something about (int) cast of bulk->data in
+    vchiq_bulk_transfer().
+
+    bulk->data is a bus address going across to the firmware.  We know
+    our bus addresses are <32bit.
+
+2) Write a DT binding doc and get the corresponding DT node merged to
+   bcm2835.
+
+This will let the driver probe when enabled.
+
+3) Import drivers using VCHI.
+
+VCHI is just a tool to let drivers talk to the firmware.  Here are
+some of the ones we want:
+
+  - vc_mem (https://github.com/raspberrypi/linux/blob/rpi-4.4.y/drivers/char/broadcom/vc_mem.c)
+
+  This driver is what the vcdbg userspace program uses to set up its
+  requests to the firmware, which are transmitted across VCHIQ.  vcdbg
+  is really useful for debugging firmware interactions.
+
+  - bcm2835-camera (https://github.com/raspberrypi/linux/tree/rpi-4.4.y/drivers/media/platform/bcm2835)
+
+  This driver will let us get images from the camera using the MMAL
+  protocol over VCHI.
+
+  - VCSM (https://github.com/raspberrypi/linux/tree/rpi-4.4.y/drivers/char/broadcom/vc_sm)
+
+  This driver is used for talking about regions of VC memory across
+  firmware protocols including VCHI.  We'll want to extend this driver
+  to manage these buffers as dmabufs so that we can zero-copy import
+  camera images into vc4 for rendering/display.
+
+4) Garbage-collect unused code
+
+One of the reasons this driver wasn't upstreamed previously was that
+there's a lot code that got built that's probably unnecessary these
+days.  Once we have the set of VCHI-using drivers we want in tree, we
+should be able to do a sweep of the code to see what's left that's
+unused.
Signature · 1 line
2.9.3
#11 lore raw

Re: [PATCH 4/5] staging/vchi: Add a TODO file of things I know we need to deal with.

Quoted 6 lines · Eric Anholt

I've also left out VC-CMA, which appears to be about having Linux manage a CMA area that the firmware gets to make allocations out of. I'm not clear on if this is useful (the firmware's need for memory drops massively with vc4 present, and may drop even more depending on how we resolve dmabuf handling for camera and video decode)

VC-CMA allows unused memory from the gpu to be used as CMA on the linux side in a dynamic way.
However it has always had some issues, so is not enabled by default.

The main reason for wanting the gpu side to have significant memory is for textures used
by the gpu side 3D driver. In the vc4-kms-v3d driver world the requirement for significant amounts
of gpu memory goes away.

For most camera and video decode usage, the default gpu_mem=64M is sufficient.

As such, I'd ignore VC-CMA upstream, and assume it will disappear downstream eventually.

vc_mem is used by vcdbg to get gpu side addresses for debug features (e.g. extracting gpu debug log and viewing its memory heaps and vchiq state).

vcsm is currently used for allocating arm accessible memory from the gpu. It is used by mmal when in zero copy mode (typically enabled) and as Eric says, is likely to be used for dmabuf allocation.

#12 lore raw

PATCH 5/5 MAINTAINERS: Add the staging vchiq driver as a bcm2835 responsibility.

In reply to Eric Anholt

It's being merged to support firmware communication on the Raspberry Pi, so we should probably send its patches to linux-rpi-kernel.

---

Greg, I'd be pulling this one through broadcom trees.

 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
index 1cd38a7e0064..8ed85a51d9c1 100644
@@ -2586,6 +2586,7 @@ L:	linux-arm-kernel at lists.infradead.org (moderated for non-subscribers)
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/rpi/linux-rpi.git
 S:	Maintained
 N:	bcm2835
+F:	drivers/staging/vc04_services
 
 BROADCOM BCM47XX MIPS ARCHITECTURE
 M:	Hauke Mehrtens <[email protected]>
Signature · 1 line
2.9.3