coreboot-kgpe-d16/payloads/libpayload/drivers/usb
Julius Werner 509c37e750 libpayload: Make EHCI driver cache-aware
This patch makes the EHCI driver work on ARM platforms which usually do
not support automatic cache snooping. It uses the new DMA memory
mechanism (which needs to be correctly set up in the Coreboot mainboard
code) to allocate all EHCI-internal communication structures in
cache-coherent memory, and cleans/invalidates the externally supplied
transfer buffers in Bulk and Control functions with explicit calls as
necessary.

Old-Change-Id: Ie8a62545d905b7a4fdd2a56b9405774be69779e5
Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/167339
(cherry picked from commit 322338934add36a5372ffe7d2a45e61a4fdd4a54)

libpayload: ehci: Cache management is hard, let's go copying...

It turns out that my previous commit to make the EHCI stack cache aware
on ARM devices wasn't quite correct, and the problem is actually much
trickier than I thought. After having some fun with more weird transfer
problems that appear/disappear based on stack alignment, this is my
current worst-case threat model that any cache managing implementation
would need to handle correctly:

Some upper layer calls ehci_bulk() with a transfer buffer on its stack.
Due to stack alignment, it happens to start just at the top of a cache
line, so up to 64 - 4 bytes of ehci_bulk's stack will share that line.
ehci_bulk() calls dcache_clean() and initializes the USB transfer.
Between that point and the call to dcache_invalidate() at the end of
ehci_bulk(), any access to the stack variables in that cache line (even
a speculative prefetch) will refetch the line into the cache. Afterwards
any other access to a random memory location that just happens to get
aliased to the same cache line may evict it again, causing the processor
to write out stale data to the transfer buffer and possibly overwrite
data that has already been received over USB.

In short, any dcache_clean/dcache_invalidate-based implementation that
preserves correctness while allowing any arbitrary (non cache-aligned)
memory location as a transfer buffer is presumed to be impossible.
Instead, this patch causes all transfer data to be copied to/from a
cache-coherent bounce buffer. It will still transfer directly if the
supplied buffer is already cache-coherent, which can be used by callers
to optimize their transfers (and is true by default on x86).

Old-Change-Id: I112908410bdbc8ca028d44f2f5d388c529f8057f
Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/169231
Reviewed-by: Stefan Reinauer <reinauer@chromium.org>
(cherry picked from commit 702dc50f1d56fe206442079fa443437f4336daed)

Squashed the initial commit and a follow up fix.

Change-Id: Idf7e5aa855b4f0221f82fa380a76049f273e4c88
Signed-off-by: Isaac Christensen <isaac.christensen@se-eng.com>
Reviewed-on: http://review.coreboot.org/6633
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2014-08-14 23:40:25 +02:00
..
TODO Since some people disapprove of white space cleanups mixed in regular commits 2010-04-27 06:56:47 +00:00
ehci.c libpayload: Make EHCI driver cache-aware 2014-08-14 23:40:25 +02:00
ehci.h libpayload: Use unsigned long for BARs in *hci_init() 2014-07-10 20:55:41 +02:00
ehci_private.h libpayload: Make EHCI driver cache-aware 2014-08-14 23:40:25 +02:00
ehci_rh.c libpayload: Add USB support for non-PCI controllers 2013-11-25 23:31:52 +01:00
generic_hub.c libpayload: Add a generic driver for usb hubs 2013-06-13 22:17:42 +02:00
generic_hub.h libpayload: Add a generic driver for usb hubs 2013-06-13 22:17:42 +02:00
ohci.c libpayload: Make USB transfer functions return amount of bytes 2014-08-12 22:03:28 +02:00
ohci.h libpayload: Use unsigned long for BARs in *hci_init() 2014-07-10 20:55:41 +02:00
ohci_private.h libpayload: Add USB support for non-PCI controllers 2013-11-25 23:31:52 +01:00
ohci_rh.c libpayload: Rework connection state detection for OHCI 2012-11-24 08:46:34 +01:00
quirks.c libpayload: Turn the "debug" #define into the usb_debug static inline function. 2012-11-07 18:38:37 +01:00
uhci.c libpayload: Make USB transfer functions return amount of bytes 2014-08-12 22:03:28 +02:00
uhci.h libpayload: Add USB support for non-PCI controllers 2013-11-25 23:31:52 +01:00
uhci_private.h libpayload: Remove bitfield use from UHCI data structures 2012-01-10 00:02:54 +01:00
uhci_rh.c libpayload: Turn the "debug" #define into the usb_debug static inline function. 2012-11-07 18:38:37 +01:00
usb.c libpayload: Make USB transfer functions return amount of bytes 2014-08-12 22:03:28 +02:00
usb_dev.c Fix the USB code to find the headers after they were moved. 2008-09-11 17:29:00 +00:00
usbhid.c libpayload: Change CONFIG_* to CONFIG_LP_* in the kconfig. 2014-08-05 18:44:08 +02:00
usbhub.c libpayload: usbhub: Don't clear PSC unless it was set 2014-08-12 23:19:42 +02:00
usbinit.c libpayload: Change CONFIG_* to CONFIG_LP_* in the kconfig. 2014-08-05 18:44:08 +02:00
usbmsc.c libpayload: Add in a missing "static". 2014-08-14 22:23:27 +02:00
xhci.c libpayload: Make USB transfer functions return amount of bytes 2014-08-12 22:03:28 +02:00
xhci.h libpayload: Use unsigned long for BARs in *hci_init() 2014-07-10 20:55:41 +02:00
xhci_commands.c libpayload: Fill gaps in the xHCI driver 2013-06-13 22:21:20 +02:00
xhci_debug.c libpayload: Fill gaps in the xHCI driver 2013-06-13 22:21:20 +02:00
xhci_devconf.c libpayload: Fill gaps in the xHCI driver 2013-06-13 22:21:20 +02:00
xhci_events.c libpayload: Make USB transfer functions return amount of bytes 2014-08-12 22:03:28 +02:00
xhci_private.h libpayload: xhci: Use Event Data TRBs for transfer event generation 2014-08-11 18:26:00 +02:00
xhci_rh.c libpayload: Fill gaps in the xHCI driver 2013-06-13 22:21:20 +02:00