diff mbox

[U-Boot,3/4] ehci-hcd.c: Add a new USB_DMA_MINALIGN define for cache alignment

Message ID 1339700507-26700-4-git-send-email-trini@ti.com
State Superseded, archived
Headers show

Commit Message

Tom Rini June 14, 2012, 7:01 p.m. UTC
The USB spec says that 32 bytes is the minimum required alignment.
However on some platforms we have a larger minimum requirement for cache
coherency.  In those cases, use that value rather than the USB spec
minimum.

Cc: Marek Vasut <marex@denx.de>
Signed-off-by: Tom Rini <trini@ti.com>
---
 drivers/usb/host/ehci-hcd.c |   23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

Comments

Marek Vasut June 14, 2012, 7:29 p.m. UTC | #1
Dear Tom Rini,

> The USB spec says that 32 bytes is the minimum required alignment.
> However on some platforms we have a larger minimum requirement for cache
> coherency.  In those cases, use that value rather than the USB spec
> minimum.
> 
> Cc: Marek Vasut <marex@denx.de>
> Signed-off-by: Tom Rini <trini@ti.com>
> ---
>  drivers/usb/host/ehci-hcd.c |   23 +++++++++++++++++------
>  1 file changed, 17 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
> index 04300be..45725f5 100644
> --- a/drivers/usb/host/ehci-hcd.c
> +++ b/drivers/usb/host/ehci-hcd.c
> @@ -29,12 +29,23 @@
> 
>  #include "ehci.h"
> 
> -int rootdev;
> -struct ehci_hccr *hccr;	/* R/O registers, not need for volatile */
> -volatile struct ehci_hcor *hcor;
> +/*
> + * The EHCI spec says that we must align to at least 32 bytes.  However,
> + * some platforms require larger alignment.
> + */
> +#if ARCH_DMA_MINALIGN > 32
> +#define USB_DMA_MINALIGN	ARCH_DMA_MINALIGN
> +#else
> +#define USB_DMA_MINALIGN	32
> +#endif

Don't we have some common header for these?

> +
> +int rootdev __attribute__((aligned(USB_DMA_MINALIGN)));
> +/* R/O registers, not need for volatile */
> +struct ehci_hccr *hccr __attribute__((aligned(USB_DMA_MINALIGN)));
> +volatile struct ehci_hcor *hcor
> __attribute__((aligned(USB_DMA_MINALIGN)));
> 
>  static uint16_t portreset;
> -static struct QH qh_list __attribute__((aligned(32)));
> +static struct QH qh_list __attribute__((aligned(USB_DMA_MINALIGN)));
> 
>  static struct descriptor {
>  	struct usb_hub_descriptor hub;
> @@ -207,8 +218,8 @@ static int
>  ehci_submit_async(struct usb_device *dev, unsigned long pipe, void
> *buffer, int length, struct devrequest *req)
>  {
> -	static struct QH qh __attribute__((aligned(32)));
> -	static struct qTD qtd[3] __attribute__((aligned (32)));
> +	static struct QH qh __attribute__((aligned(USB_DMA_MINALIGN)));
> +	static struct qTD qtd[3] __attribute__((aligned(USB_DMA_MINALIGN)));
>  	int qtd_counter = 0;
> 
>  	volatile struct qTD *vtd;

Best regards,
Marek Vasut
Tom Rini June 14, 2012, 7:30 p.m. UTC | #2
On 06/14/2012 12:29 PM, Marek Vasut wrote:
> Dear Tom Rini,
> 
>> The USB spec says that 32 bytes is the minimum required alignment.
>> However on some platforms we have a larger minimum requirement for cache
>> coherency.  In those cases, use that value rather than the USB spec
>> minimum.
>>
>> Cc: Marek Vasut <marex@denx.de>
>> Signed-off-by: Tom Rini <trini@ti.com>
>> ---
>>  drivers/usb/host/ehci-hcd.c |   23 +++++++++++++++++------
>>  1 file changed, 17 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
>> index 04300be..45725f5 100644
>> --- a/drivers/usb/host/ehci-hcd.c
>> +++ b/drivers/usb/host/ehci-hcd.c
>> @@ -29,12 +29,23 @@
>>
>>  #include "ehci.h"
>>
>> -int rootdev;
>> -struct ehci_hccr *hccr;	/* R/O registers, not need for volatile */
>> -volatile struct ehci_hcor *hcor;
>> +/*
>> + * The EHCI spec says that we must align to at least 32 bytes.  However,
>> + * some platforms require larger alignment.
>> + */
>> +#if ARCH_DMA_MINALIGN > 32
>> +#define USB_DMA_MINALIGN	ARCH_DMA_MINALIGN
>> +#else
>> +#define USB_DMA_MINALIGN	32
>> +#endif
> 
> Don't we have some common header for these?

For ECHI and musb?  I did not spot one unless we go all the way up to
common.h or similar.
Marek Vasut June 14, 2012, 7:41 p.m. UTC | #3
Dear Tom Rini,

> On 06/14/2012 12:29 PM, Marek Vasut wrote:
> > Dear Tom Rini,
> > 
> >> The USB spec says that 32 bytes is the minimum required alignment.
> >> However on some platforms we have a larger minimum requirement for cache
> >> coherency.  In those cases, use that value rather than the USB spec
> >> minimum.
> >> 
> >> Cc: Marek Vasut <marex@denx.de>
> >> Signed-off-by: Tom Rini <trini@ti.com>
> >> ---
> >> 
> >>  drivers/usb/host/ehci-hcd.c |   23 +++++++++++++++++------
> >>  1 file changed, 17 insertions(+), 6 deletions(-)
> >> 
> >> diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
> >> index 04300be..45725f5 100644
> >> --- a/drivers/usb/host/ehci-hcd.c
> >> +++ b/drivers/usb/host/ehci-hcd.c
> >> @@ -29,12 +29,23 @@
> >> 
> >>  #include "ehci.h"
> >> 
> >> -int rootdev;
> >> -struct ehci_hccr *hccr;	/* R/O registers, not need for volatile */
> >> -volatile struct ehci_hcor *hcor;
> >> +/*
> >> + * The EHCI spec says that we must align to at least 32 bytes. 
> >> However, + * some platforms require larger alignment.
> >> + */
> >> +#if ARCH_DMA_MINALIGN > 32
> >> +#define USB_DMA_MINALIGN	ARCH_DMA_MINALIGN
> >> +#else
> >> +#define USB_DMA_MINALIGN	32
> >> +#endif
> > 
> > Don't we have some common header for these?
> 
> For ECHI and musb?  I did not spot one unless we go all the way up to
> common.h or similar.

Ok, that's crappy :-/

Don't we have ehci.h or usb.h? Is musb ehci or not?

Best regards,
Marek Vasut
Tom Rini June 14, 2012, 7:54 p.m. UTC | #4
On 06/14/2012 12:41 PM, Marek Vasut wrote:
> Dear Tom Rini,
> 
>> On 06/14/2012 12:29 PM, Marek Vasut wrote:
>>> Dear Tom Rini,
>>>
>>>> The USB spec says that 32 bytes is the minimum required alignment.
>>>> However on some platforms we have a larger minimum requirement for cache
>>>> coherency.  In those cases, use that value rather than the USB spec
>>>> minimum.
>>>>
>>>> Cc: Marek Vasut <marex@denx.de>
>>>> Signed-off-by: Tom Rini <trini@ti.com>
>>>> ---
>>>>
>>>>  drivers/usb/host/ehci-hcd.c |   23 +++++++++++++++++------
>>>>  1 file changed, 17 insertions(+), 6 deletions(-)
>>>>
>>>> diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
>>>> index 04300be..45725f5 100644
>>>> --- a/drivers/usb/host/ehci-hcd.c
>>>> +++ b/drivers/usb/host/ehci-hcd.c
>>>> @@ -29,12 +29,23 @@
>>>>
>>>>  #include "ehci.h"
>>>>
>>>> -int rootdev;
>>>> -struct ehci_hccr *hccr;	/* R/O registers, not need for volatile */
>>>> -volatile struct ehci_hcor *hcor;
>>>> +/*
>>>> + * The EHCI spec says that we must align to at least 32 bytes. 
>>>> However, + * some platforms require larger alignment.
>>>> + */
>>>> +#if ARCH_DMA_MINALIGN > 32
>>>> +#define USB_DMA_MINALIGN	ARCH_DMA_MINALIGN
>>>> +#else
>>>> +#define USB_DMA_MINALIGN	32
>>>> +#endif
>>>
>>> Don't we have some common header for these?
>>
>> For ECHI and musb?  I did not spot one unless we go all the way up to
>> common.h or similar.
> 
> Ok, that's crappy :-/
> 
> Don't we have ehci.h or usb.h? Is musb ehci or not?

MUSB is Mentor USB.  But, good spotting, include/usb.h is in both
ehci-hcd.c (and other places) and musb_core.h, moving there.
Marek Vasut June 14, 2012, 8:02 p.m. UTC | #5
Dear Tom Rini,

> On 06/14/2012 12:41 PM, Marek Vasut wrote:
> > Dear Tom Rini,
> > 
> >> On 06/14/2012 12:29 PM, Marek Vasut wrote:
> >>> Dear Tom Rini,
> >>> 
> >>>> The USB spec says that 32 bytes is the minimum required alignment.
> >>>> However on some platforms we have a larger minimum requirement for
> >>>> cache coherency.  In those cases, use that value rather than the USB
> >>>> spec minimum.
> >>>> 
> >>>> Cc: Marek Vasut <marex@denx.de>
> >>>> Signed-off-by: Tom Rini <trini@ti.com>
> >>>> ---
> >>>> 
> >>>>  drivers/usb/host/ehci-hcd.c |   23 +++++++++++++++++------
> >>>>  1 file changed, 17 insertions(+), 6 deletions(-)
> >>>> 
> >>>> diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
> >>>> index 04300be..45725f5 100644
> >>>> --- a/drivers/usb/host/ehci-hcd.c
> >>>> +++ b/drivers/usb/host/ehci-hcd.c
> >>>> @@ -29,12 +29,23 @@
> >>>> 
> >>>>  #include "ehci.h"
> >>>> 
> >>>> -int rootdev;
> >>>> -struct ehci_hccr *hccr;	/* R/O registers, not need for volatile */
> >>>> -volatile struct ehci_hcor *hcor;
> >>>> +/*
> >>>> + * The EHCI spec says that we must align to at least 32 bytes.
> >>>> However, + * some platforms require larger alignment.
> >>>> + */
> >>>> +#if ARCH_DMA_MINALIGN > 32
> >>>> +#define USB_DMA_MINALIGN	ARCH_DMA_MINALIGN
> >>>> +#else
> >>>> +#define USB_DMA_MINALIGN	32
> >>>> +#endif
> >>> 
> >>> Don't we have some common header for these?
> >> 
> >> For ECHI and musb?  I did not spot one unless we go all the way up to
> >> common.h or similar.
> > 
> > Ok, that's crappy :-/
> > 
> > Don't we have ehci.h or usb.h? Is musb ehci or not?
> 
> MUSB is Mentor USB.  But, good spotting, include/usb.h is in both
> ehci-hcd.c (and other places) and musb_core.h, moving there.

Heh, my clairvoiance can now do git-grep-alike actions without touching the repo 
... I have to praise myself :-)

Best regards,
Marek Vasut
diff mbox

Patch

diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 04300be..45725f5 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -29,12 +29,23 @@ 
 
 #include "ehci.h"
 
-int rootdev;
-struct ehci_hccr *hccr;	/* R/O registers, not need for volatile */
-volatile struct ehci_hcor *hcor;
+/*
+ * The EHCI spec says that we must align to at least 32 bytes.  However,
+ * some platforms require larger alignment.
+ */
+#if ARCH_DMA_MINALIGN > 32
+#define USB_DMA_MINALIGN	ARCH_DMA_MINALIGN
+#else
+#define USB_DMA_MINALIGN	32
+#endif
+
+int rootdev __attribute__((aligned(USB_DMA_MINALIGN)));
+/* R/O registers, not need for volatile */
+struct ehci_hccr *hccr __attribute__((aligned(USB_DMA_MINALIGN)));
+volatile struct ehci_hcor *hcor __attribute__((aligned(USB_DMA_MINALIGN)));
 
 static uint16_t portreset;
-static struct QH qh_list __attribute__((aligned(32)));
+static struct QH qh_list __attribute__((aligned(USB_DMA_MINALIGN)));
 
 static struct descriptor {
 	struct usb_hub_descriptor hub;
@@ -207,8 +218,8 @@  static int
 ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer,
 		   int length, struct devrequest *req)
 {
-	static struct QH qh __attribute__((aligned(32)));
-	static struct qTD qtd[3] __attribute__((aligned (32)));
+	static struct QH qh __attribute__((aligned(USB_DMA_MINALIGN)));
+	static struct qTD qtd[3] __attribute__((aligned(USB_DMA_MINALIGN)));
 	int qtd_counter = 0;
 
 	volatile struct qTD *vtd;