Skip to contentSkip to conversation

usb: musb: use the new %pa format specifier for dma_addr_t

PATCH Superseded Emil Goode 3 participants 9 messages Jun 1, 2013 – Jun 2, 2013

Subsystems (6)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Emil Goode

author
#0 lore raw

PATCH 1/1 usb: musb: use the new %pa format specifier for dma_addr_t

This patch makes use of the new format specifier %pa that was introduced by the following commit.

7d7992108d02aa92ad4c77e5d9ce14088c942e75 ("lib/vsprintf.c: add %pa format specifier for phys_addr_t types")

The addition of urb->transfer_dma and urb->actual_length is also done a few lines below. I have moved this code up and pass the variable buf to dev_dbg.

---
I also added braces to the else statement for consistency. (Didn't want to send a separate patch for that)

 drivers/usb/musb/musb_host.c |   12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/usb/musb/musb_host.c +5 -7
index a9695f5..701f668 100644
@@ -1756,12 +1756,11 @@ void musb_host_rx(struct musb *musb, u8 epnum)
 			dma_addr_t		buf;
 
 			rx_count = musb_readw(epio, MUSB_RXCOUNT);
+			buf = urb->transfer_dma + urb->actual_length;
 
-			dev_dbg(musb->controller, "RX%d count %d, buffer 0x%llx len %d/%d\n",
+			dev_dbg(musb->controller, "RX%d count %d, buffer 0x%pa len %d/%d\n",
 					epnum, rx_count,
-					(unsigned long long) urb->transfer_dma
-					+ urb->actual_length,
-					qh->offset,
+					&buf, qh->offset,
 					urb->transfer_buffer_length);
 
 			c = musb->dma_controller;
@@ -1785,14 +1784,13 @@ void musb_host_rx(struct musb *musb, u8 epnum)
 					    rx_count, d->length);
 
 					length = d->length;
-				} else
+				} else {
 					length = rx_count;
+				}
 				d->status = d_status;
 				buf = urb->transfer_dma + d->offset;
 			} else {
 				length = rx_count;
-				buf = urb->transfer_dma +
-						urb->actual_length;
 			}
 
 			dma->desired_mode = 0;
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 5 lines · Emil Goode

This patch makes use of the new format specifier %pa that was introduced by the following commit.

7d7992108d02aa92ad4c77e5d9ce14088c942e75 ("lib/vsprintf.c: add %pa format specifier for phys_addr_t types")

[]

drivers/usb/musb/musb_host.c

Quoted 1 line
drivers/usb/musb/musb_host.c +0 -0

[]

drivers/usb/musb/musb_host.c void musb_host_rx(struct musb *musb, u8 epnum)

Quoted 1 line
drivers/usb/musb/musb_host.c +0 -0
@@ -1756,12 +1756,11 @@ void musb_host_rx(struct musb *musb, u8 epnum)

[]

drivers/usb/musb/musb_host.c void musb_host_rx(struct musb *musb, u8 epnum) · line 1761

Quoted 2 lines
drivers/usb/musb/musb_host.c +1 -1
-			dev_dbg(musb->controller, "RX%d count %d, buffer 0x%llx len %d/%d\n",
+			dev_dbg(musb->controller, "RX%d count %d, buffer 0x%pa len %d/%d\n",

This would emit 0x0x<addr>

When you use %pa, don't add 0x

author
#2 lore raw

I see, will send a second version.

Thank's

Emil

Quoted 19 lines · Joe Perches
Quoted 5 lines · Emil Goode

This patch makes use of the new format specifier %pa that was introduced by the following commit.

7d7992108d02aa92ad4c77e5d9ce14088c942e75 ("lib/vsprintf.c: add %pa format specifier for phys_addr_t types")

[]

drivers/usb/musb/musb_host.c

Quoted 1 line
drivers/usb/musb/musb_host.c +0 -0

[]

drivers/usb/musb/musb_host.c void musb_host_rx(struct musb *musb, u8 epnum)

Quoted 1 line
drivers/usb/musb/musb_host.c +0 -0
@@ -1756,12 +1756,11 @@ void musb_host_rx(struct musb *musb, u8 epnum)

[]

drivers/usb/musb/musb_host.c void musb_host_rx(struct musb *musb, u8 epnum) · line 1761

Quoted 2 lines
drivers/usb/musb/musb_host.c +1 -1
-			dev_dbg(musb->controller, "RX%d count %d, buffer 0x%llx len %d/%d\n",
+			dev_dbg(musb->controller, "RX%d count %d, buffer 0x%pa len %d/%d\n",

This would emit 0x0x<addr>

When you use %pa, don't add 0x

#3 lore raw
Quoted 1 line · Emil Goode

I see, will send a second version.

Hey Emil.

I believe you can not use %pa with a dma_addr_t
because that could be a different size than a
phy_addr_t.

(the vsprintf cast and deref is to a phy_addr_t)

The definitions are: (types.h)

#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
typedef u64 dma_addr_t;
#else
typedef u32 dma_addr_t;
#endif /* dma_addr_t */

[]

#ifdef CONFIG_PHYS_ADDR_T_64BIT
typedef u64 phys_addr_t;
#else
typedef u32 phys_addr_t;
#endif

Quoted 15 lines · Joe Perches
Quoted 5 lines · Emil Goode

This patch makes use of the new format specifier %pa that was introduced by the following commit.

7d7992108d02aa92ad4c77e5d9ce14088c942e75 ("lib/vsprintf.c: add %pa format specifier for phys_addr_t types")

[]

drivers/usb/musb/musb_host.c

Quoted 1 line
drivers/usb/musb/musb_host.c +0 -0

[]

drivers/usb/musb/musb_host.c void musb_host_rx(struct musb *musb, u8 epnum)

Quoted 1 line
drivers/usb/musb/musb_host.c +0 -0
@@ -1756,12 +1756,11 @@ void musb_host_rx(struct musb *musb, u8 epnum)

[]

drivers/usb/musb/musb_host.c void musb_host_rx(struct musb *musb, u8 epnum) · line 1761

Quoted 2 lines
drivers/usb/musb/musb_host.c +1 -1
-                   dev_dbg(musb->controller, "RX%d count %d, buffer 0x%llx len %d/%d\n",
+                   dev_dbg(musb->controller, "RX%d count %d, buffer 0x%pa len %d/%d\n",

This would emit 0x0x<addr>

reviewer
#4 lore raw
Quoted 10 lines · Joe Perches
Quoted 1 line · Emil Goode

I see, will send a second version.

Hey Emil.

I believe you can not use %pa with a dma_addr_t
because that could be a different size than a
phy_addr_t.

(the vsprintf cast and deref is to a phy_addr_t)

Hi Joe,

Thank you for pointing that out. It's a bit of a shame that this comment was deleted from include/asm-generic/types.h in commit 3e50594e8e72932ad4cfcb0b3cbdf58fc3bce416:

-/*
- * DMA addresses may be very different from physical addresses
- * and pointers. i386 and powerpc may have 64 bit DMA on 32 bit
- * systems, while sparc64 uses 32 bit DMA addresses for 64 bit
- * physical addresses.
- * This default defines dma_addr_t to have the same size as
- * phys_addr_t, which is the most common way.
- * Do not define the dma64_addr_t type, which never really
- * worked.
- */

Quoted 32 lines

The definitions are: (types.h)

#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
typedef u64 dma_addr_t;
#else
typedef u32 dma_addr_t;
#endif /* dma_addr_t */

[]

#ifdef CONFIG_PHYS_ADDR_T_64BIT
typedef u64 phys_addr_t;
#else
typedef u32 phys_addr_t;
#endif

Quoted 15 lines · Joe Perches
Quoted 5 lines · Emil Goode

This patch makes use of the new format specifier %pa that was introduced by the following commit.

7d7992108d02aa92ad4c77e5d9ce14088c942e75 ("lib/vsprintf.c: add %pa format specifier for phys_addr_t types")

[]

drivers/usb/musb/musb_host.c

Quoted 1 line
drivers/usb/musb/musb_host.c +0 -0

[]

drivers/usb/musb/musb_host.c void musb_host_rx(struct musb *musb, u8 epnum)

Quoted 1 line
drivers/usb/musb/musb_host.c +0 -0
@@ -1756,12 +1756,11 @@ void musb_host_rx(struct musb *musb, u8 epnum)

[]

drivers/usb/musb/musb_host.c void musb_host_rx(struct musb *musb, u8 epnum) · line 1761

Quoted 2 lines
drivers/usb/musb/musb_host.c +1 -1
-                   dev_dbg(musb->controller, "RX%d count %d, buffer 0x%llx len %d/%d\n",
+                   dev_dbg(musb->controller, "RX%d count %d, buffer 0x%pa len %d/%d\n",

This would emit 0x0x<addr>

Signature · 1 line
~Randy
#5 lore raw
Quoted 4 lines · Randy Dunlap

It's a bit of a shame that this
comment was deleted from include/asm-generic/types.h in commit 3e50594e8e72932ad4cfcb0b3cbdf58fc3bce416:

Quoted 10 lines

-/*
- * DMA addresses may be very different from physical addresses
- * and pointers. i386 and powerpc may have 64 bit DMA on 32 bit
- * systems, while sparc64 uses 32 bit DMA addresses for 64 bit
- * physical addresses.
- * This default defines dma_addr_t to have the same size as
- * phys_addr_t, which is the most common way.
- * Do not define the dma64_addr_t type, which never really
- * worked.
- */

Hey Randy.

You could always put it back.

author
#6 lore raw

Hello Joe and Randy,

Maybe there should be another format specifier %da and Randy's clarifying comment
can be added there to the documentation?

Best regards,

Emil Goode

Quoted 21 lines · Joe Perches
Quoted 4 lines · Randy Dunlap

It's a bit of a shame that this
comment was deleted from include/asm-generic/types.h in commit 3e50594e8e72932ad4cfcb0b3cbdf58fc3bce416:

Quoted 10 lines

-/*
- * DMA addresses may be very different from physical addresses
- * and pointers. i386 and powerpc may have 64 bit DMA on 32 bit
- * systems, while sparc64 uses 32 bit DMA addresses for 64 bit
- * physical addresses.
- * This default defines dma_addr_t to have the same size as
- * phys_addr_t, which is the most common way.
- * Do not define the dma64_addr_t type, which never really
- * worked.
- */

Hey Randy.

You could always put it back.

#7 lore raw
Quoted 2 lines · Emil Goode

Maybe there should be another format specifier %da and Randy's clarifying comment

maybe %pad but I think the whole thing isn't much necessary. It seems there are a grand total of 3 uses of %pa today.

Maybe:

---
 Documentation/printk-formats.txt |  7 +++++++
 lib/vsprintf.c                   | 19 +++++++++++++++----
 2 files changed, 22 insertions(+), 4 deletions(-)
Documentation/printk-formats.txt +7 -0
index 3af5ae6..fa48403 100644
@@ -63,6 +63,13 @@ Physical addresses:
 	resource_size_t) which can vary based on build options, regardless of
 	the width of the CPU data path. Passed by reference.
 
+dma_addr_t addresses:
+
+	%pad	0x01234567 or 0x0123456789abcdef
+
+	For printing a dma_addr_t type which can vary based on build options,
+	regardless of the width of the CPU data path. Passed by reference.
+
 Raw buffer as a hex string:
 	%*ph	00 01 02  ...  3f
 	%*phC	00:01:02: ... :3f
lib/vsprintf.c +15 -4
index 7d84676..b6b8390 100644
@@ -1039,6 +1039,7 @@ int kptr_restrict __read_mostly;
  *            The maximum supported length is 64 bytes of the input. Consider
  *            to use print_hex_dump() for the larger input.
  * - 'a' For a phys_addr_t type and its derivative types (passed by reference)
+ * - 'ad' For a dma_addr_t type
  *
  * Note: The difference between 'S' and 'F' is that on ia64 and ppc64
  * function pointers are really function descriptors, which contain a
@@ -1129,12 +1130,22 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
 			return netdev_feature_string(buf, end, ptr, spec);
 		}
 		break;
-	case 'a':
+	case 'a': {
+		unsigned long long val;
 		spec.flags |= SPECIAL | SMALL | ZEROPAD;
-		spec.field_width = sizeof(phys_addr_t) * 2 + 2;
 		spec.base = 16;
-		return number(buf, end,
-			      (unsigned long long) *((phys_addr_t *)ptr), spec);
+		switch (fmt[1]) {
+		case 'd':
+			spec.field_width = sizeof(dma_addr_t) * 2 + 2;
+			val = (unsigned long long)*((dma_addr_t *)ptr);
+			break;
+		default:
+			spec.field_width = sizeof(phys_addr_t) * 2 + 2;
+			val = (unsigned long long)*((phys_addr_t *)ptr);
+			break;
+		}
+		return number(buf, end, val, spec);
+	}
 	}
 	spec.flags |= SMALL;
 	if (spec.field_width = -1) {
author
#8 lore raw

Maybe wait and see if %pa gets more usage and if the discussion comes up again.

Best regards,

Emil

Quoted 72 lines · Joe Perches
Quoted 2 lines · Emil Goode

Maybe there should be another format specifier %da and Randy's clarifying comment

maybe %pad but I think the whole thing isn't much necessary. It seems there are a grand total of 3 uses of %pa today.

Maybe:

---
 Documentation/printk-formats.txt |  7 +++++++
 lib/vsprintf.c                   | 19 +++++++++++++++----
 2 files changed, 22 insertions(+), 4 deletions(-)
Documentation/printk-formats.txt +7 -0
index 3af5ae6..fa48403 100644
@@ -63,6 +63,13 @@ Physical addresses:
 	resource_size_t) which can vary based on build options, regardless of
 	the width of the CPU data path. Passed by reference.
 
+dma_addr_t addresses:
+
+	%pad	0x01234567 or 0x0123456789abcdef
+
+	For printing a dma_addr_t type which can vary based on build options,
+	regardless of the width of the CPU data path. Passed by reference.
+
 Raw buffer as a hex string:
 	%*ph	00 01 02  ...  3f
 	%*phC	00:01:02: ... :3f
lib/vsprintf.c +15 -4
index 7d84676..b6b8390 100644
@@ -1039,6 +1039,7 @@ int kptr_restrict __read_mostly;
  *            The maximum supported length is 64 bytes of the input. Consider
  *            to use print_hex_dump() for the larger input.
  * - 'a' For a phys_addr_t type and its derivative types (passed by reference)
+ * - 'ad' For a dma_addr_t type
  *
  * Note: The difference between 'S' and 'F' is that on ia64 and ppc64
  * function pointers are really function descriptors, which contain a
@@ -1129,12 +1130,22 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
 			return netdev_feature_string(buf, end, ptr, spec);
 		}
 		break;
-	case 'a':
+	case 'a': {
+		unsigned long long val;
 		spec.flags |= SPECIAL | SMALL | ZEROPAD;
-		spec.field_width = sizeof(phys_addr_t) * 2 + 2;
 		spec.base = 16;
-		return number(buf, end,
-			      (unsigned long long) *((phys_addr_t *)ptr), spec);
+		switch (fmt[1]) {
+		case 'd':
+			spec.field_width = sizeof(dma_addr_t) * 2 + 2;
+			val = (unsigned long long)*((dma_addr_t *)ptr);
+			break;
+		default:
+			spec.field_width = sizeof(phys_addr_t) * 2 + 2;
+			val = (unsigned long long)*((phys_addr_t *)ptr);
+			break;
+		}
+		return number(buf, end, val, spec);
+	}
 	}
 	spec.flags |= SMALL;
 	if (spec.field_width = -1) {