From fccc7dea2459f313476c32437493285779e2f814 Mon Sep 17 00:00:00 2001 From: David Hendricks Date: Fri, 12 Dec 2014 14:07:08 -0800 Subject: [PATCH] spi: do not use malloc in Gigadevice driver This allows us to use the driver before ramstage. BRANCH=none BUG=none TEST=built and booted on Pinky Change-Id: I0700388b0e4e0562e3c0a52863c8357097bfd8d6 Signed-off-by: Patrick Georgi Original-Commit-Id: cd57587dab74de509d5c50cfc1ad337d765af6c8 Original-Signed-off-by: David Hendricks Original-Change-Id: I0ce901331e401274254b8889484ffb41359119fa Original-Reviewed-on: https://chromium-review.googlesource.com/235864 Original-Reviewed-by: Julius Werner Reviewed-on: http://review.coreboot.org/8774 Tested-by: build bot (Jenkins) Reviewed-by: David Hendricks Reviewed-by: Paul Menzel --- src/drivers/spi/gigadevice.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/src/drivers/spi/gigadevice.c b/src/drivers/spi/gigadevice.c index 68b487efca..0f0d7b7432 100644 --- a/src/drivers/spi/gigadevice.c +++ b/src/drivers/spi/gigadevice.c @@ -189,11 +189,12 @@ static int gigadevice_erase(struct spi_flash *flash, u32 offset, size_t len) return spi_flash_cmd_erase(flash, CMD_GD25_SE, offset, len); } +static struct gigadevice_spi_flash stm; + struct spi_flash *spi_flash_probe_gigadevice(struct spi_slave *spi, u8 *idcode) { const struct gigadevice_spi_flash_params *params; unsigned page_size; - struct gigadevice_spi_flash *stm; unsigned int i; for (i = 0; i < ARRAY_SIZE(gigadevice_spi_flash_table); i++) { @@ -209,32 +210,25 @@ struct spi_flash *spi_flash_probe_gigadevice(struct spi_slave *spi, u8 *idcode) return NULL; } - stm = malloc(sizeof(struct gigadevice_spi_flash)); - if (!stm) { - printk(BIOS_WARNING, - "SF gigadevice.c: Failed to allocate memory\n"); - return NULL; - } - - stm->params = params; - stm->flash.spi = spi; - stm->flash.name = params->name; + stm.params = params; + stm.flash.spi = spi; + stm.flash.name = params->name; /* Assuming power-of-two page size initially. */ page_size = 1 << params->l2_page_size; - stm->flash.write = gigadevice_write; - stm->flash.erase = gigadevice_erase; + stm.flash.write = gigadevice_write; + stm.flash.erase = gigadevice_erase; #if CONFIG_SPI_FLASH_NO_FAST_READ - stm->flash.read = spi_flash_cmd_read_slow; + stm.flash.read = spi_flash_cmd_read_slow; #else - stm->flash.read = spi_flash_cmd_read_fast; + stm.flash.read = spi_flash_cmd_read_fast; #endif - stm->flash.sector_size = (1 << stm->params->l2_page_size) * - stm->params->pages_per_sector; - stm->flash.size = page_size * params->pages_per_sector + stm.flash.sector_size = (1 << stm.params->l2_page_size) * + stm.params->pages_per_sector; + stm.flash.size = page_size * params->pages_per_sector * params->sectors_per_block * params->nr_blocks; - return &stm->flash; + return &stm.flash; }