Commit 93ad908c43ed5d8e3e546dd22fa08b668c5090d9

Authored by Lucas Stach
Committed by Marek Vasut
1 parent 81c1d7b605
Exists in master and in 57 other branches 8qm-imx_v2020.04_5.4.70_2.3.0, emb_lf-6.6.52-2.2.0, emb_lf_v2022.04, emb_lf_v2023.04, emb_lf_v2024.04, imx_v2015.04_4.1.15_1.0.0_ga, pitx_8mp_lf_v2020.04, smarc-8m-android-10.0.0_2.6.0, smarc-8m-android-11.0.0_2.0.0, smarc-8mp-android-11.0.0_2.0.0, smarc-emmc-imx_v2014.04_3.10.53_1.1.0_ga, smarc-emmc-imx_v2014.04_3.14.28_1.0.0_ga, smarc-imx-l5.0.0_1.0.0-ga, smarc-imx6_v2018.03_4.14.98_2.0.0_ga, smarc-imx7_v2017.03_4.9.11_1.0.0_ga, smarc-imx7_v2018.03_4.14.98_2.0.0_ga, smarc-imx_v2014.04_3.14.28_1.0.0_ga, smarc-imx_v2015.04_4.1.15_1.0.0_ga, smarc-imx_v2017.03_4.9.11_1.0.0_ga, smarc-imx_v2017.03_4.9.88_2.0.0_ga, smarc-imx_v2017.03_o8.1.0_1.3.0_8m, smarc-imx_v2018.03_4.14.78_1.0.0_ga, smarc-m6.0.1_2.1.0-ga, smarc-n7.1.2_2.0.0-ga, smarc-rel_imx_4.1.15_2.0.0_ga, smarc_8m-imx_v2018.03_4.14.98_2.0.0_ga, smarc_8m-imx_v2019.04_4.19.35_1.1.0, smarc_8m_00d0-imx_v2018.03_4.14.98_2.0.0_ga, smarc_8mm-imx_v2018.03_4.14.98_2.0.0_ga, smarc_8mm-imx_v2019.04_4.19.35_1.1.0, smarc_8mm-imx_v2020.04_5.4.24_2.1.0, smarc_8mp_lf_v2020.04, smarc_8mq-imx_v2020.04_5.4.24_2.1.0, smarc_8mq_lf_v2020.04, ti-u-boot-2015.07, u-boot-2013.01.y, v2013.10, v2013.10-smarct33, v2013.10-smartmen, v2014.01, v2014.04, v2014.04-smarct33, v2014.04-smarct33-emmc, v2014.04-smartmen, v2014.07, v2014.07-smarct33, v2014.07-smartmen, v2015.07-smarct33, v2015.07-smarct33-emmc, v2015.07-smarct4x, v2016.05-dlt, v2016.05-smarct3x, v2016.05-smarct3x-emmc, v2016.05-smarct4x, v2017.01-smarct3x, v2017.01-smarct3x-emmc, v2017.01-smarct4x

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>

Showing 2 changed files with 14 additions and 7 deletions Side-by-side Diff

... ... @@ -43,6 +43,7 @@
43 43 #include <common.h>
44 44 #include <command.h>
45 45 #include <asm/processor.h>
  46 +#include <asm/unaligned.h>
46 47 #include <linux/ctype.h>
47 48 #include <asm/byteorder.h>
48 49 #include <asm/unaligned.h>
... ... @@ -269,6 +270,7 @@
269 270 int i;
270 271 ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, USB_BUFSIZ);
271 272 unsigned char *bitmap;
  273 + short hubCharacteristics;
272 274 struct usb_hub_descriptor *descriptor;
273 275 struct usb_hub_device *hub;
274 276 #ifdef USB_HUB_DEBUG
... ... @@ -304,8 +306,9 @@
304 306 }
305 307 memcpy((unsigned char *)&hub->desc, buffer, descriptor->bLength);
306 308 /* adjust 16bit values */
307   - hub->desc.wHubCharacteristics =
308   - le16_to_cpu(descriptor->wHubCharacteristics);
  309 + put_unaligned(le16_to_cpu(get_unaligned(
  310 + &descriptor->wHubCharacteristics)),
  311 + &hub->desc.wHubCharacteristics);
309 312 /* set the bitmap */
310 313 bitmap = (unsigned char *)&hub->desc.DeviceRemovable[0];
311 314 /* devices not removable by default */
... ... @@ -322,7 +325,8 @@
322 325 dev->maxchild = descriptor->bNbrPorts;
323 326 USB_HUB_PRINTF("%d ports detected\n", dev->maxchild);
324 327  
325   - switch (hub->desc.wHubCharacteristics & HUB_CHAR_LPSM) {
  328 + hubCharacteristics = get_unaligned(&hub->desc.wHubCharacteristics);
  329 + switch (hubCharacteristics & HUB_CHAR_LPSM) {
326 330 case 0x00:
327 331 USB_HUB_PRINTF("ganged power switching\n");
328 332 break;
329 333  
... ... @@ -335,12 +339,12 @@
335 339 break;
336 340 }
337 341  
338   - if (hub->desc.wHubCharacteristics & HUB_CHAR_COMPOUND)
  342 + if (hubCharacteristics & HUB_CHAR_COMPOUND)
339 343 USB_HUB_PRINTF("part of a compound device\n");
340 344 else
341 345 USB_HUB_PRINTF("standalone hub\n");
342 346  
343   - switch (hub->desc.wHubCharacteristics & HUB_CHAR_OCPM) {
  347 + switch (hubCharacteristics & HUB_CHAR_OCPM) {
344 348 case 0x00:
345 349 USB_HUB_PRINTF("global over-current protection\n");
346 350 break;
drivers/usb/host/ehci-hcd.c
... ... @@ -22,6 +22,7 @@
22 22 */
23 23 #include <common.h>
24 24 #include <asm/byteorder.h>
  25 +#include <asm/unaligned.h>
25 26 #include <usb.h>
26 27 #include <asm/io.h>
27 28 #include <malloc.h>
28 29  
... ... @@ -866,10 +867,12 @@
866 867 printf("Register %x NbrPorts %d\n", reg, descriptor.hub.bNbrPorts);
867 868 /* Port Indicators */
868 869 if (HCS_INDICATOR(reg))
869   - descriptor.hub.wHubCharacteristics |= 0x80;
  870 + put_unaligned(get_unaligned(&descriptor.hub.wHubCharacteristics)
  871 + | 0x80, &descriptor.hub.wHubCharacteristics);
870 872 /* Port Power Control */
871 873 if (HCS_PPC(reg))
872   - descriptor.hub.wHubCharacteristics |= 0x01;
  874 + put_unaligned(get_unaligned(&descriptor.hub.wHubCharacteristics)
  875 + | 0x01, &descriptor.hub.wHubCharacteristics);
873 876  
874 877 /* Start the host controller. */
875 878 cmd = ehci_readl(&hcor->or_usbcmd);