From ed098d62d66d91cf7330a37f9b83e303eb7f56d8 Mon Sep 17 00:00:00 2001 From: Nico Huber Date: Fri, 21 Apr 2017 23:47:08 +0200 Subject: spi: Move ICH BBAR quirk out of the way Get rid of the layering violations around ICH's BBAR. Move all the weird address handling into (surprise, surprise) `ichspi.c`. Might fix writes for the `BBAR != 0` case by accident. Background: Some ICHs have a BBAR (BIOS Base Address Configuration Register) that, if set, limits the valid address range to [BBAR, 2^24). Current code lifted addresses for REMS, RES and READ operations by BBAR, now we do it for all addresses in ichspi. Special care has to be taken if the BBAR is not aligned by the flash chip's size. In this case, the lower part of the chip (from BBAR aligned down, up to BBAR) is inacces- sible (this seems to be the original intend behind BBAR) and has to be left out in the address offset calculation. Change-Id: Icbac513c5339e8aff624870252133284ef85ab73 Signed-off-by: Nico Huber Reviewed-on: https://review.coreboot.org/22396 Reviewed-by: David Hendricks Tested-by: build bot (Jenkins) --- spi25.c | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) (limited to 'spi25.c') diff --git a/spi25.c b/spi25.c index c49f2512..dcc7641e 100644 --- a/spi25.c +++ b/spi25.c @@ -49,21 +49,10 @@ static int spi_rdid(struct flashctx *flash, unsigned char *readarr, int bytes) static int spi_rems(struct flashctx *flash, unsigned char *readarr) { - unsigned char cmd[JEDEC_REMS_OUTSIZE] = { JEDEC_REMS, 0, 0, 0 }; - uint32_t readaddr; + static const unsigned char cmd[JEDEC_REMS_OUTSIZE] = { JEDEC_REMS, }; int ret; - ret = spi_send_command(flash, sizeof(cmd), JEDEC_REMS_INSIZE, cmd, - readarr); - if (ret == SPI_INVALID_ADDRESS) { - /* Find the lowest even address allowed for reads. */ - readaddr = (spi_get_valid_read_addr(flash) + 1) & ~1; - cmd[1] = (readaddr >> 16) & 0xff, - cmd[2] = (readaddr >> 8) & 0xff, - cmd[3] = (readaddr >> 0) & 0xff, - ret = spi_send_command(flash, sizeof(cmd), JEDEC_REMS_INSIZE, - cmd, readarr); - } + ret = spi_send_command(flash, sizeof(cmd), JEDEC_REMS_INSIZE, cmd, readarr); if (ret) return ret; msg_cspew("REMS returned 0x%02x 0x%02x. ", readarr[0], readarr[1]); @@ -72,20 +61,11 @@ static int spi_rems(struct flashctx *flash, unsigned char *readarr) static int spi_res(struct flashctx *flash, unsigned char *readarr, int bytes) { - unsigned char cmd[JEDEC_RES_OUTSIZE] = { JEDEC_RES, 0, 0, 0 }; - uint32_t readaddr; + static const unsigned char cmd[JEDEC_RES_OUTSIZE] = { JEDEC_RES, }; int ret; int i; ret = spi_send_command(flash, sizeof(cmd), bytes, cmd, readarr); - if (ret == SPI_INVALID_ADDRESS) { - /* Find the lowest even address allowed for reads. */ - readaddr = (spi_get_valid_read_addr(flash) + 1) & ~1; - cmd[1] = (readaddr >> 16) & 0xff, - cmd[2] = (readaddr >> 8) & 0xff, - cmd[3] = (readaddr >> 0) & 0xff, - ret = spi_send_command(flash, sizeof(cmd), bytes, cmd, readarr); - } if (ret) return ret; msg_cspew("RES returned"); -- cgit v1.2.3