From f01e81ddc8548a02836f3c765d34a1fb4f7fcda9 Mon Sep 17 00:00:00 2001 From: David Hendricks Date: Tue, 14 Jun 2011 01:35:36 +0000 Subject: Use shutdown callback mechanism to shutdown programmers This patch attempts to resolve some programmer shutdown ordering issues by having the programmer init functions register shutdown callbacks explicitly wherever it makes most sense. Before, assumptions were made that could lead to the internal programmer's state changing before the external programmer could be shut down properly. Now, each programmer cleans up after itself and (hopefully) performs each operation in the correct order. As a side-effect, this patch gives us a better usage model for reverse operations such as rpci_* and rmmio_*. In the long-run, this should make reversing the initialization process easier to understand, less tedious, and less error-prone. In short, this patch does the following: - Registers a shutdown callback during initialization for each programmer. - Kills the .shutdown function pointer from programmer_entry struct. Also, make most shutdown functions static. - Adds a few minor clean-ups and corrections (e.g. missing physunmap() calls). TODO: Remove forward declaration of serprog_shutdown() (added to simplify diff) Corresponding to flashrom svn r1338. Signed-off-by: David Hendricks Acked-by: Carl-Daniel Hailfinger --- nicintel_spi.c | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'nicintel_spi.c') diff --git a/nicintel_spi.c b/nicintel_spi.c index 574735f..aacd68c 100644 --- a/nicintel_spi.c +++ b/nicintel_spi.c @@ -139,6 +139,25 @@ static const struct bitbang_spi_master bitbang_spi_master_nicintel = { .release_bus = nicintel_release_spibus, }; +static int nicintel_spi_shutdown(void *data) +{ + uint32_t tmp; + + /* Disable writes manually. See the comment about EECD in + * nicintel_spi_init() for details. + */ + tmp = pci_mmio_readl(nicintel_spibar + EECD); + tmp &= ~FLASH_WRITES_ENABLED; + tmp |= FLASH_WRITES_DISABLED; + pci_mmio_writel(tmp, nicintel_spibar + EECD); + + physunmap(nicintel_spibar, 4096); + pci_cleanup(pacc); + release_io_perms(); + + return 0; +} + int nicintel_spi_init(void) { uint32_t tmp; @@ -159,28 +178,12 @@ int nicintel_spi_init(void) tmp |= FLASH_WRITES_ENABLED; pci_mmio_writel(tmp, nicintel_spibar + EECD); + if (register_shutdown(nicintel_spi_shutdown, NULL)) + return 1; + /* 1 usec halfperiod delay for now. */ if (bitbang_spi_init(&bitbang_spi_master_nicintel, 1)) return 1; return 0; } - -int nicintel_spi_shutdown(void) -{ - uint32_t tmp; - - /* Disable writes manually. See the comment about EECD in - * nicintel_spi_init() for details. - */ - tmp = pci_mmio_readl(nicintel_spibar + EECD); - tmp &= ~FLASH_WRITES_ENABLED; - tmp |= FLASH_WRITES_DISABLED; - pci_mmio_writel(tmp, nicintel_spibar + EECD); - - physunmap(nicintel_spibar, 4096); - pci_cleanup(pacc); - release_io_perms(); - - return 0; -} -- cgit v1.1