diff options
author | Andrey Petrov <andrey.petrov@intel.com> | 2015-06-25 19:03:50 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-07-01 03:49:24 +0000 |
commit | 1f941e867437b03761f3777bb575cad55c21c811 (patch) | |
tree | 51edbc24fe5fc5bb6a6203280c5d5dc0ab3ab2c8 | |
parent | ae834fa50a44887ea7e26939cd344514a5e16ad9 (diff) | |
download | chrome-ec-1f941e867437b03761f3777bb575cad55c21c811.tar.gz |
mec1322: protect spi_transcation() with mutex
Concurrent SPI transactions are not possible, however in case of external SPI
and flashrom update scenario both host command and vhash trigger transactions.
This adds mutex for the SPI transcation
BRANCH=None
BUG=chrome-os-partner:38103
TEST=on Cyan, run hundreds of flashrom cycles to make sure there are no read,
erase or write errors
Change-Id: If346ebe635387d477dcea5f406a5c31579142e2d
Signed-off-by: Andrey Petrov <andrey.petrov@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/282113
Reviewed-by: Shawn N <shawnn@chromium.org>
Commit-Queue: Bernie Thompson <bhthompson@chromium.org>
Tested-by: Bernie Thompson <bhthompson@chromium.org>
-rw-r--r-- | chip/mec1322/build.mk | 2 | ||||
-rw-r--r-- | chip/mec1322/spi.c | 17 |
2 files changed, 17 insertions, 2 deletions
diff --git a/chip/mec1322/build.mk b/chip/mec1322/build.mk index 109bb05dd2..3b7352fda0 100644 --- a/chip/mec1322/build.mk +++ b/chip/mec1322/build.mk @@ -53,7 +53,7 @@ objs_lfw += $(out)/common/version.o dirs-y+=chip/$(CHIP)/lfw # objs with -lfw suffix are to include lfw's gpio -$(out)/%-lfw.o: private CC+=-Iboard/$(BOARD)/lfw +$(out)/%-lfw.o: private CC+=-Iboard/$(BOARD)/lfw -DLFW $(out)/%-lfw.o: %.c $(call quiet,c_to_o,CC ) diff --git a/chip/mec1322/spi.c b/chip/mec1322/spi.c index b624e04863..bbd6e36a34 100644 --- a/chip/mec1322/spi.c +++ b/chip/mec1322/spi.c @@ -14,6 +14,7 @@ #include "timer.h" #include "util.h" #include "hooks.h" +#include "task.h" #define CPUTS(outstr) cputs(CC_SPI, outstr) #define CPRINTS(format, args...) cprints(CC_SPI, format, ## args) @@ -23,6 +24,12 @@ #define SPI_DMA_CHANNEL (MEC1322_DMAC_SPI0_RX + CONFIG_SPI_PORT * 2) +/* only regular image needs mutex, LFW does not have scheduling */ +/* TODO: Move SPI locking to common code */ +#ifndef LFW +static struct mutex spi_mutex; +#endif + static const struct dma_option spi_rx_option = { SPI_DMA_CHANNEL, (void *)&MEC1322_SPI_RD(CONFIG_SPI_PORT), MEC1322_DMA_XFER_SIZE(1) @@ -115,10 +122,18 @@ int spi_transaction(const uint8_t *txdata, int txlen, { int ret; +#ifndef LFW + mutex_lock(&spi_mutex); +#endif ret = spi_transaction_async(txdata, txlen, rxdata, rxlen); if (ret) return ret; - return spi_transaction_flush(); + ret = spi_transaction_flush(); + +#ifndef LFW + mutex_unlock(&spi_mutex); +#endif + return ret; } int spi_enable(int enable) |