summaryrefslogtreecommitdiff
path: root/chip/stm32/usb-stream.c
diff options
context:
space:
mode:
authorAnton Staaf <robotboy@chromium.org>2015-04-08 10:44:40 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-04-13 20:00:58 +0000
commit8c0cef260727ba125def62cfd0ef9c09fc9c2172 (patch)
tree15e9e12056e60a51c360bb939d60c327aec69010 /chip/stm32/usb-stream.c
parent0016de8250807601f46fb3736f93518155eca95f (diff)
downloadchrome-ec-8c0cef260727ba125def62cfd0ef9c09fc9c2172.tar.gz
USB: Fix memcpy routines
The memcpy like routines for moving to and from usb packet RAM couldn't deal with all unaligned uses, this fixes their behavior. In particular, a previous caller might assume that the packet RAM addresses were contiguous and attempt to break up a call into two separate chunks (as the queue insertion/removal code does). But this can lead to invalid pointers passed to these memcpy routines. A much cleaner solution is to make the packet RAM address space contiguous. To do so the memcpy routines take packet RAM addresses instead of AHB address space mapped addresses and __usb_ram_start needed to change to be of type usb_uint so that pointer arithmatic on it worked correctly on all platforms, this also allowed the usb_sram_addr macro to be simplified. Signed-off-by: Anton Staaf <robotboy@chromium.org> BRANCH=None BUG=None TEST=make buildall -j Verify that USB still works on Ryu and discovery-stm32f072 Change-Id: I479461f07a3203f1e6e0cf9705f512a5a43c4646 Reviewed-on: https://chromium-review.googlesource.com/264764 Trybot-Ready: Anton Staaf <robotboy@chromium.org> Tested-by: Anton Staaf <robotboy@chromium.org> Reviewed-by: Anton Staaf <robotboy@chromium.org> Commit-Queue: Anton Staaf <robotboy@chromium.org>
Diffstat (limited to 'chip/stm32/usb-stream.c')
-rw-r--r--chip/stm32/usb-stream.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/chip/stm32/usb-stream.c b/chip/stm32/usb-stream.c
index f5487372bb..2b3fe35e8f 100644
--- a/chip/stm32/usb-stream.c
+++ b/chip/stm32/usb-stream.c
@@ -17,7 +17,8 @@
static size_t rx_read(struct usb_stream_config const *config)
{
- size_t count = btable_ep[config->endpoint].rx_count & 0x3ff;
+ uintptr_t address = btable_ep[config->endpoint].rx_addr;
+ size_t count = btable_ep[config->endpoint].rx_count & 0x3ff;
/*
* Only read the received USB packet if there is enough space in the
@@ -27,17 +28,18 @@ static size_t rx_read(struct usb_stream_config const *config)
return 0;
return producer_write_memcpy(&config->producer,
- config->rx_ram,
+ (void *) address,
count,
memcpy_from_usbram);
}
static size_t tx_write(struct usb_stream_config const *config)
{
- size_t count = consumer_read_memcpy(&config->consumer,
- config->tx_ram,
- config->tx_size,
- memcpy_to_usbram);
+ uintptr_t address = btable_ep[config->endpoint].tx_addr;
+ size_t count = consumer_read_memcpy(&config->consumer,
+ (void *) address,
+ config->tx_size,
+ memcpy_to_usbram);
btable_ep[config->endpoint].tx_count = count;