2013-06-01 18:03:08

by Emil Goode

[permalink] [raw]
Subject: [PATCH] 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.

Signed-off-by: Emil Goode <[email protected]>
---
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(-)

diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index a9695f5..701f668 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -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;
--
1.7.10.4


2013-06-01 18:29:16

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH] usb: musb: use the new %pa format specifier for dma_addr_t

On Sat, 2013-06-01 at 20:02 +0200, Emil Goode wrote:
> 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")
[]
> diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
[]
> @@ -1756,12 +1756,11 @@ void musb_host_rx(struct musb *musb, u8 epnum)
[]
> - 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

2013-06-01 19:09:51

by Emil Goode

[permalink] [raw]
Subject: Re: [PATCH] usb: musb: use the new %pa format specifier for dma_addr_t

I see, will send a second version.

Thank's

Emil


On Sat, Jun 01, 2013 at 11:29:10AM -0700, Joe Perches wrote:
> On Sat, 2013-06-01 at 20:02 +0200, Emil Goode wrote:
> > 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")
> []
> > diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
> []
> > @@ -1756,12 +1756,11 @@ void musb_host_rx(struct musb *musb, u8 epnum)
> []
> > - 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
>
>

2013-06-01 20:31:28

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH] usb: musb: use the new %pa format specifier for dma_addr_t

On Sat, 2013-06-01 at 21:09 +0200, Emil Goode wrote:
> 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

On Sat, Jun 01, 2013 at 11:29:10AM -0700, Joe Perches wrote:
> On Sat, 2013-06-01 at 20:02 +0200, Emil Goode wrote:
> > 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")
> []
> > diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
> []
> > @@ -1756,12 +1756,11 @@ void musb_host_rx(struct musb *musb, u8 epnum)
> []
> > - 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>

2013-06-01 21:57:57

by Randy Dunlap

[permalink] [raw]
Subject: Re: [PATCH] usb: musb: use the new %pa format specifier for dma_addr_t

On 06/01/13 13:31, Joe Perches wrote:
> On Sat, 2013-06-01 at 21:09 +0200, Emil Goode wrote:
>> 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.
- */


> 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
>
> On Sat, Jun 01, 2013 at 11:29:10AM -0700, Joe Perches wrote:
>> On Sat, 2013-06-01 at 20:02 +0200, Emil Goode wrote:
>>> 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")
>> []
>>> diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
>> []
>>> @@ -1756,12 +1756,11 @@ void musb_host_rx(struct musb *musb, u8 epnum)
>> []
>>> - 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>


--
~Randy

2013-06-01 22:16:03

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH] usb: musb: use the new %pa format specifier for dma_addr_t

On Sat, 2013-06-01 at 14:56 -0700, Randy Dunlap wrote:
> 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.
> - */

Hey Randy.

You could always put it back.

2013-06-01 23:06:15

by Emil Goode

[permalink] [raw]
Subject: Re: [PATCH] usb: musb: use the new %pa format specifier for dma_addr_t

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

On Sat, Jun 01, 2013 at 03:16:00PM -0700, Joe Perches wrote:
> On Sat, 2013-06-01 at 14:56 -0700, Randy Dunlap wrote:
> > 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.
> > - */
>
> Hey Randy.
>
> You could always put it back.
>
>

2013-06-01 23:22:21

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH] usb: musb: use the new %pa format specifier for dma_addr_t

On Sun, 2013-06-02 at 01:06 +0200, Emil Goode wrote:
> 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(-)

diff --git a/Documentation/printk-formats.txt b/Documentation/printk-formats.txt
index 3af5ae6..fa48403 100644
--- a/Documentation/printk-formats.txt
+++ b/Documentation/printk-formats.txt
@@ -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
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 7d84676..b6b8390 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -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) {

2013-06-02 13:33:21

by Emil Goode

[permalink] [raw]
Subject: Re: [PATCH] usb: musb: use the new %pa format specifier for dma_addr_t

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

Best regards,

Emil

On Sat, Jun 01, 2013 at 04:22:18PM -0700, Joe Perches wrote:
> On Sun, 2013-06-02 at 01:06 +0200, Emil Goode wrote:
> > 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(-)
>
> diff --git a/Documentation/printk-formats.txt b/Documentation/printk-formats.txt
> index 3af5ae6..fa48403 100644
> --- a/Documentation/printk-formats.txt
> +++ b/Documentation/printk-formats.txt
> @@ -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
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index 7d84676..b6b8390 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -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) {
>
>