From 2de0e8762225265fcf5b72b9d2b9b291f57af50c Mon Sep 17 00:00:00 2001 From: Ashish Kumar Mishra Date: Wed, 24 Apr 2024 16:49:18 +0530 Subject: block/fast_spi: Use read32p/write32p for SPI RW The current fast_spi code uses memcpy for rw. The SPI flash read/write has 4 byte limit, due to which the current 64 bit memcpy doesn't work. Hence update rw ops to use read32p/write32p. BUG=b:242829490 TEST=Verified MRC cache working on MTL 64-bit, future 64 bit platforms and RPL(brox/skolas) 32-bit platforms. Change-Id: I317c7160bf192dd2aeacebf6029a809bc97f3420 Signed-off-by: Ashish Kumar Mishra Reviewed-on: https://review.coreboot.org/c/coreboot/+/82079 Tested-by: build bot (Jenkins) Reviewed-by: Subrata Banik Reviewed-by: Angel Pons --- .../intel/common/block/fast_spi/fast_spi_flash.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/soc/intel') diff --git a/src/soc/intel/common/block/fast_spi/fast_spi_flash.c b/src/soc/intel/common/block/fast_spi/fast_spi_flash.c index e9cfc230a4..a7762711fa 100644 --- a/src/soc/intel/common/block/fast_spi/fast_spi_flash.c +++ b/src/soc/intel/common/block/fast_spi/fast_spi_flash.c @@ -75,18 +75,28 @@ static uint32_t fast_spi_flash_read_sfdp(struct fast_spi_flash_ctx *ctx, /* Fill FDATAn FIFO in preparation for a write transaction. */ static void fill_xfer_fifo(struct fast_spi_flash_ctx *ctx, const void *data, - size_t len) + size_t len) { - /* YES! memcpy() works. FDATAn does not require 32-bit accesses. */ - memcpy((void *)(ctx->mmio_base + SPIBAR_FDATA(0)), data, len); + const uint32_t *data32 = (const uint32_t *)data; + for (size_t i = 0; i < len / sizeof(uint32_t); i++) + write32p(ctx->mmio_base + SPIBAR_FDATA(i), *data32++); + + const uint8_t *data8 = (const uint8_t *)data32; + for (size_t i = 0; i < len % sizeof(uint32_t); i++) + write8p(ctx->mmio_base + SPIBAR_FDATA(len / sizeof(uint32_t)) + i, *data8++); } /* Drain FDATAn FIFO after a read transaction populates data. */ -static void drain_xfer_fifo(struct fast_spi_flash_ctx *ctx, void *dest, +static void drain_xfer_fifo(struct fast_spi_flash_ctx *ctx, void *data, size_t len) { - /* YES! memcpy() works. FDATAn does not require 32-bit accesses. */ - memcpy(dest, (void *)(ctx->mmio_base + SPIBAR_FDATA(0)), len); + uint32_t *data32 = (uint32_t *)data; + for (size_t i = 0; i < len / sizeof(uint32_t); i++) + *data32++ = read32p(ctx->mmio_base + SPIBAR_FDATA(i)); + + uint8_t *data8 = (uint8_t *)data32; + for (size_t i = 0; i < len % sizeof(uint32_t); i++) + *data8++ = read8p(ctx->mmio_base + SPIBAR_FDATA(len / sizeof(uint32_t)) + i); } /* Fire up a transfer using the hardware sequencer. */ -- cgit v1.2.3