Sfoglia il codice sorgente

usb: do explicit unaligned accesses

usb_hub_descriptor has to be packed as it's used for
communication with the device. Member wHubCharacteristics
violates the natural alignment rules.

Use explicit unaligned access functions for this member.
Fixes ARMv7 traping while using USB.

v2: fix typo found by Thomas Langer

v3: rebased on top of u-boot-usb/master

Signed-off-by: Lucas Stach <dev@lynxeye.de>
Lucas Stach 12 anni fa
parent
commit
93ad908c43
2 ha cambiato i file con 14 aggiunte e 7 eliminazioni
  1. 9 5
      common/usb_hub.c
  2. 5 2
      drivers/usb/host/ehci-hcd.c

+ 9 - 5
common/usb_hub.c

@@ -43,6 +43,7 @@
 #include <common.h>
 #include <common.h>
 #include <command.h>
 #include <command.h>
 #include <asm/processor.h>
 #include <asm/processor.h>
+#include <asm/unaligned.h>
 #include <linux/ctype.h>
 #include <linux/ctype.h>
 #include <asm/byteorder.h>
 #include <asm/byteorder.h>
 #include <asm/unaligned.h>
 #include <asm/unaligned.h>
@@ -269,6 +270,7 @@ static int usb_hub_configure(struct usb_device *dev)
 	int i;
 	int i;
 	ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, USB_BUFSIZ);
 	ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, USB_BUFSIZ);
 	unsigned char *bitmap;
 	unsigned char *bitmap;
+	short hubCharacteristics;
 	struct usb_hub_descriptor *descriptor;
 	struct usb_hub_descriptor *descriptor;
 	struct usb_hub_device *hub;
 	struct usb_hub_device *hub;
 #ifdef USB_HUB_DEBUG
 #ifdef USB_HUB_DEBUG
@@ -304,8 +306,9 @@ static int usb_hub_configure(struct usb_device *dev)
 	}
 	}
 	memcpy((unsigned char *)&hub->desc, buffer, descriptor->bLength);
 	memcpy((unsigned char *)&hub->desc, buffer, descriptor->bLength);
 	/* adjust 16bit values */
 	/* adjust 16bit values */
-	hub->desc.wHubCharacteristics =
-				le16_to_cpu(descriptor->wHubCharacteristics);
+	put_unaligned(le16_to_cpu(get_unaligned(
+			&descriptor->wHubCharacteristics)),
+			&hub->desc.wHubCharacteristics);
 	/* set the bitmap */
 	/* set the bitmap */
 	bitmap = (unsigned char *)&hub->desc.DeviceRemovable[0];
 	bitmap = (unsigned char *)&hub->desc.DeviceRemovable[0];
 	/* devices not removable by default */
 	/* devices not removable by default */
@@ -322,7 +325,8 @@ static int usb_hub_configure(struct usb_device *dev)
 	dev->maxchild = descriptor->bNbrPorts;
 	dev->maxchild = descriptor->bNbrPorts;
 	USB_HUB_PRINTF("%d ports detected\n", dev->maxchild);
 	USB_HUB_PRINTF("%d ports detected\n", dev->maxchild);
 
 
-	switch (hub->desc.wHubCharacteristics & HUB_CHAR_LPSM) {
+	hubCharacteristics = get_unaligned(&hub->desc.wHubCharacteristics);
+	switch (hubCharacteristics & HUB_CHAR_LPSM) {
 	case 0x00:
 	case 0x00:
 		USB_HUB_PRINTF("ganged power switching\n");
 		USB_HUB_PRINTF("ganged power switching\n");
 		break;
 		break;
@@ -335,12 +339,12 @@ static int usb_hub_configure(struct usb_device *dev)
 		break;
 		break;
 	}
 	}
 
 
-	if (hub->desc.wHubCharacteristics & HUB_CHAR_COMPOUND)
+	if (hubCharacteristics & HUB_CHAR_COMPOUND)
 		USB_HUB_PRINTF("part of a compound device\n");
 		USB_HUB_PRINTF("part of a compound device\n");
 	else
 	else
 		USB_HUB_PRINTF("standalone hub\n");
 		USB_HUB_PRINTF("standalone hub\n");
 
 
-	switch (hub->desc.wHubCharacteristics & HUB_CHAR_OCPM) {
+	switch (hubCharacteristics & HUB_CHAR_OCPM) {
 	case 0x00:
 	case 0x00:
 		USB_HUB_PRINTF("global over-current protection\n");
 		USB_HUB_PRINTF("global over-current protection\n");
 		break;
 		break;

+ 5 - 2
drivers/usb/host/ehci-hcd.c

@@ -22,6 +22,7 @@
  */
  */
 #include <common.h>
 #include <common.h>
 #include <asm/byteorder.h>
 #include <asm/byteorder.h>
+#include <asm/unaligned.h>
 #include <usb.h>
 #include <usb.h>
 #include <asm/io.h>
 #include <asm/io.h>
 #include <malloc.h>
 #include <malloc.h>
@@ -866,10 +867,12 @@ int usb_lowlevel_init(void)
 	printf("Register %x NbrPorts %d\n", reg, descriptor.hub.bNbrPorts);
 	printf("Register %x NbrPorts %d\n", reg, descriptor.hub.bNbrPorts);
 	/* Port Indicators */
 	/* Port Indicators */
 	if (HCS_INDICATOR(reg))
 	if (HCS_INDICATOR(reg))
-		descriptor.hub.wHubCharacteristics |= 0x80;
+		put_unaligned(get_unaligned(&descriptor.hub.wHubCharacteristics)
+				| 0x80, &descriptor.hub.wHubCharacteristics);
 	/* Port Power Control */
 	/* Port Power Control */
 	if (HCS_PPC(reg))
 	if (HCS_PPC(reg))
-		descriptor.hub.wHubCharacteristics |= 0x01;
+		put_unaligned(get_unaligned(&descriptor.hub.wHubCharacteristics)
+				| 0x01, &descriptor.hub.wHubCharacteristics);
 
 
 	/* Start the host controller. */
 	/* Start the host controller. */
 	cmd = ehci_readl(&hcor->or_usbcmd);
 	cmd = ehci_readl(&hcor->or_usbcmd);