>From 0fdfab543634cedf1803cb3b1b782f8516b4abf6 Mon Sep 17 00:00:00 2001
From: Tadas Slotkus <devtadas@gmail.com>
Date: Tue, 16 Aug 2011 19:45:17 +0300
Subject: [carFl mem 11/21] Provide massive globals sync mechanism

Now all pointers to globals structure are initialised on startup

Signed-off-by: Tadas Slotkus <devtadas@gmail.com>
---
 82802ab.c          |    7 +++++++
 a25.c              |    7 +++++++
 at25.c             |    7 +++++++
 bitbang_spi.c      |    7 +++++++
 board_enable.c     |    7 +++++++
 cbtable.c          |    7 +++++++
 chipset_enable.c   |    7 +++++++
 cli_classic.c      |    7 +++++++
 cli_output.c       |    7 +++++++
 dmi.c              |    7 +++++++
 dummyflasher.c     |    7 +++++++
 flash.h            |   39 +++++++++++++++++++++++++++++++++++++++
 flashrom.c         |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 hwaccess.c         |    7 +++++++
 ichspi.c           |    7 +++++++
 internal.c         |    7 +++++++
 it85spi.c          |    7 +++++++
 it87spi.c          |    7 +++++++
 jedec.c            |    7 +++++++
 layout.c           |    7 +++++++
 m29f400bt.c        |    7 +++++++
 mcp6x_spi.c        |    7 +++++++
 pcidev.c           |    7 +++++++
 physmap.c          |    7 +++++++
 pm49fl00x.c        |    7 +++++++
 print.c            |    7 +++++++
 processor_enable.c |    6 ++++++
 programmer.c       |    7 +++++++
 sb600spi.c         |    7 +++++++
 sharplhf00l04.c    |    7 +++++++
 spi.c              |    6 ++++++
 spi25.c            |    7 +++++++
 sst28sf040.c       |    7 +++++++
 sst49lfxxxc.c      |    7 +++++++
 sst_fwhub.c        |    7 +++++++
 stm50flw0x0x.c     |    7 +++++++
 udelay.c           |    7 +++++++
 w29ee011.c         |    7 +++++++
 w39.c              |    7 +++++++
 wbsio_spi.c        |    7 +++++++
 40 files changed, 351 insertions(+), 0 deletions(-)

diff --git a/82802ab.c b/82802ab.c
index cd59c07..7da1d3f 100644
--- a/82802ab.c
+++ b/82802ab.c
@@ -29,6 +29,13 @@
 #include "flash.h"
 #include "chipdrivers.h"
 
+static globals *g;
+
+void sync_globals0(void)
+{
+	g = get_globals();
+}
+
 void print_status_82802ab(uint8_t status)
 {
 	msg_cdbg("%s", status & 0x80 ? "Ready:" : "Busy:");
diff --git a/a25.c b/a25.c
index 5791c46..f028ee5 100644
--- a/a25.c
+++ b/a25.c
@@ -21,6 +21,13 @@
 #include "chipdrivers.h"
 #include "spi.h"
 
+static globals *g;
+
+void sync_globals1(void)
+{
+	g = get_globals();
+}
+
 /* Prettyprint the status register. Works for AMIC A25L series. */
 
 static void spi_prettyprint_status_register_amic_a25_srwd(uint8_t status)
diff --git a/at25.c b/at25.c
index e55b007..f090391 100644
--- a/at25.c
+++ b/at25.c
@@ -21,6 +21,13 @@
 #include "chipdrivers.h"
 #include "spi.h"
 
+static globals *g;
+
+void sync_globals2(void)
+{
+	g = get_globals();
+}
+
 /* Prettyprint the status register. Works for Atmel A25/A26 series. */
 
 static void spi_prettyprint_status_register_atmel_at25_srpl(uint8_t status)
diff --git a/bitbang_spi.c b/bitbang_spi.c
index 4219a62..243dc40 100644
--- a/bitbang_spi.c
+++ b/bitbang_spi.c
@@ -26,6 +26,13 @@
 #include "programmer.h"
 #include "spi.h"
 
+static globals *g;
+
+void sync_globals3(void)
+{
+	g = get_globals();
+}
+
 /* Length of half a clock period in usecs. */
 static int bitbang_spi_half_period;
 
diff --git a/board_enable.c b/board_enable.c
index aba6f38..94019b6 100644
--- a/board_enable.c
+++ b/board_enable.c
@@ -28,6 +28,13 @@
 #include "flash.h"
 #include "programmer.h"
 
+static globals *g;
+
+void sync_globals4(void)
+{
+	g = get_globals();
+}
+
 #if defined(__i386__) || defined(__x86_64__)
 /*
  * Helper functions for many Winbond Super I/Os of the W836xx range.
diff --git a/cbtable.c b/cbtable.c
index ea8964a..a413e50 100644
--- a/cbtable.c
+++ b/cbtable.c
@@ -30,6 +30,13 @@
 #include "programmer.h"
 #include "coreboot_tables.h"
 
+static globals *g;
+
+void sync_globals5(void)
+{
+	g = get_globals();
+}
+
 char *lb_part = NULL, *lb_vendor = NULL;
 int partvendor_from_cbtable = 0;
 
diff --git a/chipset_enable.c b/chipset_enable.c
index b4ec96b..41aca70 100644
--- a/chipset_enable.c
+++ b/chipset_enable.c
@@ -35,6 +35,13 @@
 #include "flash.h"
 #include "programmer.h"
 
+static globals *g;
+
+void sync_globals6(void)
+{
+	g = get_globals();
+}
+
 #define NOT_DONE_YET 1
 
 #if defined(__i386__) || defined(__x86_64__)
diff --git a/cli_classic.c b/cli_classic.c
index 086bd86..2f3aa8e 100644
--- a/cli_classic.c
+++ b/cli_classic.c
@@ -31,6 +31,13 @@
 #include "flashchips.h"
 #include "programmer.h"
 
+static globals *g;
+
+void sync_globals7(void)
+{
+	g = get_globals();
+}
+
 static void cli_classic_usage(const char *name)
 {
 	printf("Usage: flashrom [-n] [-V] [-f] [-h|-R|-L|"
diff --git a/cli_output.c b/cli_output.c
index 2a67bea..65bd33d 100644
--- a/cli_output.c
+++ b/cli_output.c
@@ -22,6 +22,13 @@
 #include <stdarg.h>
 #include "flash.h"
 
+static globals *g;
+
+void sync_globals8(void)
+{
+	g = get_globals();
+}
+
 int print(int type, const char *fmt, ...)
 {
 	va_list ap;
diff --git a/dmi.c b/dmi.c
index 4f36245..a17e7d7 100644
--- a/dmi.c
+++ b/dmi.c
@@ -25,6 +25,13 @@
 #include "flash.h"
 #include "programmer.h"
 
+static globals *g;
+
+void sync_globals9(void)
+{
+	g = get_globals();
+}
+
 int has_dmi_support = 0;
 
 #if STANDALONE
diff --git a/dummyflasher.c b/dummyflasher.c
index be8f552..3886e06 100644
--- a/dummyflasher.c
+++ b/dummyflasher.c
@@ -23,6 +23,13 @@
 #include "chipdrivers.h"
 #include "programmer.h"
 
+static globals *g;
+
+void sync_globals10(void)
+{
+	g = get_globals();
+}
+
 /* Remove the #define below if you don't want SPI flash chip emulation. */
 #define EMULATE_SPI_CHIP 1
 
diff --git a/flash.h b/flash.h
index 14ca85a..a2521a5 100644
--- a/flash.h
+++ b/flash.h
@@ -284,4 +284,43 @@ struct globals {
 };
 globals *get_globals(void);
 
+void sync_globals0(void);
+void sync_globals1(void);
+void sync_globals2(void);
+void sync_globals3(void);
+void sync_globals4(void);
+void sync_globals5(void);
+void sync_globals6(void);
+void sync_globals7(void);
+void sync_globals8(void);
+void sync_globals9(void);
+void sync_globals10(void);
+void sync_globals11(void);
+void sync_globals12(void);
+void sync_globals13(void);
+void sync_globals14(void);
+void sync_globals15(void);
+void sync_globals16(void);
+void sync_globals17(void);
+void sync_globals18(void);
+void sync_globals19(void);
+void sync_globals20(void);
+void sync_globals21(void);
+void sync_globals22(void);
+void sync_globals23(void);
+void sync_globals24(void);
+void sync_globals25(void);
+void sync_globals26(void);
+void sync_globals27(void);
+void sync_globals28(void);
+void sync_globals29(void);
+void sync_globals30(void);
+void sync_globals31(void);
+void sync_globals32(void);
+void sync_globals33(void);
+void sync_globals34(void);
+void sync_globals35(void);
+void sync_globals36(void);
+void sync_globals37(void);
+
 #endif				/* !__FLASH_H__ */
diff --git a/flashrom.c b/flashrom.c
index f171182..5504d01 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -49,6 +49,53 @@ globals *get_globals(void)
 	return &g;
 }
 
+static void sync_all_globals(void)
+{
+	sync_globals0();
+	sync_globals1();
+	sync_globals2();
+	sync_globals3();
+	sync_globals4();
+	sync_globals5();
+	sync_globals6();
+	sync_globals7();
+	sync_globals8();
+	sync_globals9();
+	sync_globals10();
+	sync_globals11();
+	sync_globals12();
+	sync_globals13();
+	sync_globals14();
+	sync_globals15();
+	sync_globals16();
+	sync_globals17();
+	sync_globals18();
+	sync_globals19();
+	sync_globals20();
+	sync_globals21();
+	sync_globals22();
+	sync_globals23();
+	sync_globals24();
+	sync_globals25();
+	sync_globals26();
+	sync_globals27();
+	sync_globals28();
+	sync_globals29();
+	sync_globals30();
+	sync_globals31();
+	sync_globals32();
+	sync_globals33();
+	sync_globals34();
+	sync_globals35();
+	sync_globals36();
+	sync_globals37();
+}
+
+static void init_globals(void)
+{
+	sync_all_globals();
+}
+
 #if CONFIG_INTERNAL == 1
 enum programmer programmer = PROGRAMMER_INTERNAL;
 #elif CONFIG_DUMMY == 1
@@ -1816,6 +1863,7 @@ void check_chip_supported(const struct flashchip *flash)
 
 int main(int argc, char *argv[])
 {
+	init_globals();
 	return cli_classic(argc, argv);
 }
 
diff --git a/hwaccess.c b/hwaccess.c
index 8c89925..e9d1864 100644
--- a/hwaccess.c
+++ b/hwaccess.c
@@ -31,6 +31,13 @@
 #endif
 #include "flash.h"
 
+static globals *g;
+
+void sync_globals11(void)
+{
+	g = get_globals();
+}
+
 #if defined(__i386__) || defined(__x86_64__)
 
 /* sync primitive is not needed because x86 uses uncached accesses
diff --git a/ichspi.c b/ichspi.c
index 34f0891..d7617d2 100644
--- a/ichspi.c
+++ b/ichspi.c
@@ -31,6 +31,13 @@
 #include "programmer.h"
 #include "spi.h"
 
+static globals *g;
+
+void sync_globals12(void)
+{
+	g = get_globals();
+}
+
 /* ICH9 controller register definition */
 #define ICH9_REG_HSFS		0x04	/* 16 Bits Hardware Sequencing Flash Status */
 #define HSFS_FDONE_OFF		0	/* 0: Flash Cycle Done */
diff --git a/internal.c b/internal.c
index 846cf1e..2e094bc 100644
--- a/internal.c
+++ b/internal.c
@@ -23,6 +23,13 @@
 #include "flash.h"
 #include "programmer.h"
 
+static globals *g;
+
+void sync_globals13(void)
+{
+	g = get_globals();
+}
+
 #if NEED_PCI == 1
 struct pci_dev *pci_dev_find_filter(struct pci_filter filter)
 {
diff --git a/it85spi.c b/it85spi.c
index 76e4861..709c92d 100644
--- a/it85spi.c
+++ b/it85spi.c
@@ -34,6 +34,13 @@
 #include "spi.h"
 #include "programmer.h"
 
+static globals *g;
+
+void sync_globals14(void)
+{
+	g = get_globals();
+}
+
 #define MAX_TIMEOUT 100000
 #define MAX_TRY 5
 
diff --git a/it87spi.c b/it87spi.c
index c24ba9b..77fbfcb 100644
--- a/it87spi.c
+++ b/it87spi.c
@@ -32,6 +32,13 @@
 #include "programmer.h"
 #include "spi.h"
 
+static globals *g;
+
+void sync_globals15(void)
+{
+	g = get_globals();
+}
+
 #define ITE_SUPERIO_PORT1	0x2e
 #define ITE_SUPERIO_PORT2	0x4e
 
diff --git a/jedec.c b/jedec.c
index b96f5fd..563428e 100644
--- a/jedec.c
+++ b/jedec.c
@@ -25,6 +25,13 @@
 #include "flash.h"
 #include "chipdrivers.h"
 
+static globals *g;
+
+void sync_globals16(void)
+{
+	g = get_globals();
+}
+
 #define MAX_REFLASH_TRIES 0x10
 #define MASK_FULL 0xffff
 #define MASK_2AA 0x7ff
diff --git a/layout.c b/layout.c
index d719a05..d387c3f 100644
--- a/layout.c
+++ b/layout.c
@@ -26,6 +26,13 @@
 #include "flash.h"
 #include "programmer.h"
 
+static globals *g;
+
+void sync_globals17(void)
+{
+	g = get_globals();
+}
+
 #if CONFIG_INTERNAL == 1
 char *mainboard_vendor = NULL;
 char *mainboard_part = NULL;
diff --git a/m29f400bt.c b/m29f400bt.c
index e0d41d4..dd89a67 100644
--- a/m29f400bt.c
+++ b/m29f400bt.c
@@ -21,6 +21,13 @@
 #include "flash.h"
 #include "chipdrivers.h"
 
+static globals *g;
+
+void sync_globals18(void)
+{
+	g = get_globals();
+}
+
 /* WARNING! 
    This chip uses the standard JEDEC Addresses in 16-bit mode as word
    addresses. In byte mode, 0xAAA has to be used instead of 0x555 and
diff --git a/mcp6x_spi.c b/mcp6x_spi.c
index d2c31be..082266d 100644
--- a/mcp6x_spi.c
+++ b/mcp6x_spi.c
@@ -30,6 +30,13 @@
 #include "flash.h"
 #include "programmer.h"
 
+static globals *g;
+
+void sync_globals19(void)
+{
+	g = get_globals();
+}
+
 /* Bit positions for each pin. */
 
 #define MCP6X_SPI_CS		1
diff --git a/pcidev.c b/pcidev.c
index e8b4dc1..649ca5e 100644
--- a/pcidev.c
+++ b/pcidev.c
@@ -24,6 +24,13 @@
 #include "flash.h"
 #include "programmer.h"
 
+static globals *g;
+
+void sync_globals20(void)
+{
+	g = get_globals();
+}
+
 uint32_t io_base_addr;
 struct pci_access *pacc;
 struct pci_dev *pcidev_dev = NULL;
diff --git a/physmap.c b/physmap.c
index cbab636..0c96302 100644
--- a/physmap.c
+++ b/physmap.c
@@ -33,6 +33,13 @@
 #include <errno.h>
 #endif
 
+static globals *g;
+
+void sync_globals21(void)
+{
+	g = get_globals();
+}
+
 #ifdef __DJGPP__
 #include <dpmi.h>
 #include <sys/nearptr.h>
diff --git a/pm49fl00x.c b/pm49fl00x.c
index 4136b17..f0ec567 100644
--- a/pm49fl00x.c
+++ b/pm49fl00x.c
@@ -23,6 +23,13 @@
 #include "flash.h"
 #include "chipdrivers.h"
 
+static globals *g;
+
+void sync_globals22(void)
+{
+	g = get_globals();
+}
+
 static void write_lockbits_49fl00x(chipaddr bios, int size,
 			    unsigned char bits, int block_size)
 {
diff --git a/print.c b/print.c
index 21b4570..d60db9f 100644
--- a/print.c
+++ b/print.c
@@ -26,6 +26,13 @@
 #include "flashchips.h"
 #include "programmer.h"
 
+static globals *g;
+
+void sync_globals23(void)
+{
+	g = get_globals();
+}
+
 /*
  * Return a string corresponding to the bustype parameter.
  * Memory is obtained with malloc() and must be freed with free() by the caller.
diff --git a/processor_enable.c b/processor_enable.c
index d680f97..7dab6ee 100644
--- a/processor_enable.c
+++ b/processor_enable.c
@@ -24,6 +24,12 @@
 #include "flash.h"
 #include "programmer.h"
 
+static globals *g;
+
+void sync_globals24(void)
+{
+	g = get_globals();
+}
 #if defined(__i386__) || defined(__x86_64__)
 
 int processor_flash_enable(void)
diff --git a/programmer.c b/programmer.c
index 5c1f963..7d77946 100644
--- a/programmer.c
+++ b/programmer.c
@@ -20,6 +20,13 @@
 
 #include "flash.h"
 
+static globals *g;
+
+void sync_globals25(void)
+{
+	g = get_globals();
+}
+
 /* No-op shutdown() for programmers which don't need special handling */
 int noop_shutdown(void)
 {
diff --git a/sb600spi.c b/sb600spi.c
index 37aac3b..ea7a8c2 100644
--- a/sb600spi.c
+++ b/sb600spi.c
@@ -28,6 +28,13 @@
 #include "programmer.h"
 #include "spi.h"
 
+static globals *g;
+
+void sync_globals26(void)
+{
+	g = get_globals();
+}
+
 /* This struct is unused, but helps visualize the SB600 SPI BAR layout.
  *struct sb600_spi_controller {
  *	unsigned int spi_cntrl0;	/ * 00h * /
diff --git a/sharplhf00l04.c b/sharplhf00l04.c
index 4865fc2..0d6b883 100644
--- a/sharplhf00l04.c
+++ b/sharplhf00l04.c
@@ -21,6 +21,13 @@
 #include "flash.h"
 #include "chipdrivers.h"
 
+static globals *g;
+
+void sync_globals27(void)
+{
+	g = get_globals();
+}
+
 /* FIXME: The datasheet is unclear whether we should use toggle_ready_jedec
  * or wait_82802ab.
  * FIXME: This file is unused.
diff --git a/spi.c b/spi.c
index f02f091..508ae7e 100644
--- a/spi.c
+++ b/spi.c
@@ -30,6 +30,12 @@
 #include "programmer.h"
 #include "spi.h"
 
+static globals *g;
+
+void sync_globals28(void)
+{
+	g = get_globals();
+}
 const struct spi_programmer spi_programmer_none = {
 	.type = SPI_CONTROLLER_NONE,
 	.max_data_read = MAX_DATA_UNSPECIFIED,
diff --git a/spi25.c b/spi25.c
index 937ee5d..68b40ba 100644
--- a/spi25.c
+++ b/spi25.c
@@ -29,6 +29,13 @@
 #include "programmer.h"
 #include "spi.h"
 
+static globals *g;
+
+void sync_globals29(void)
+{
+	g = get_globals();
+}
+
 static int spi_rdid(unsigned char *readarr, int bytes)
 {
 	static const unsigned char cmd[JEDEC_RDID_OUTSIZE] = { JEDEC_RDID };
diff --git a/sst28sf040.c b/sst28sf040.c
index d621cc7..ee0e8c8 100644
--- a/sst28sf040.c
+++ b/sst28sf040.c
@@ -23,6 +23,13 @@
 #include "flash.h"
 #include "chipdrivers.h"
 
+static globals *g;
+
+void sync_globals30(void)
+{
+	g = get_globals();
+}
+
 #define AUTO_PG_ERASE1		0x20
 #define AUTO_PG_ERASE2		0xD0
 #define AUTO_PGRM		0x10
diff --git a/sst49lfxxxc.c b/sst49lfxxxc.c
index 28f6cd0..e0bc430 100644
--- a/sst49lfxxxc.c
+++ b/sst49lfxxxc.c
@@ -23,6 +23,13 @@
 #include "flash.h"
 #include "chipdrivers.h"
 
+static globals *g;
+
+void sync_globals31(void)
+{
+	g = get_globals();
+}
+
 static int write_lockbits_block_49lfxxxc(struct flashchip *flash, unsigned long address, unsigned char bits)
 {
 	unsigned long lock = flash->virtual_registers + address + 2;
diff --git a/sst_fwhub.c b/sst_fwhub.c
index 65bd2b3..5069982 100644
--- a/sst_fwhub.c
+++ b/sst_fwhub.c
@@ -25,6 +25,13 @@
 #include "flash.h"
 #include "chipdrivers.h"
 
+static globals *g;
+
+void sync_globals32(void)
+{
+	g = get_globals();
+}
+
 static int check_sst_fwhub_block_lock(struct flashchip *flash, int offset)
 {
 	chipaddr registers = flash->virtual_registers;
diff --git a/stm50flw0x0x.c b/stm50flw0x0x.c
index f3fc4d8..19856ca 100644
--- a/stm50flw0x0x.c
+++ b/stm50flw0x0x.c
@@ -31,6 +31,13 @@
 #include "flashchips.h"
 #include "chipdrivers.h"
 
+static globals *g;
+
+void sync_globals33(void)
+{
+	g = get_globals();
+}
+
 /*
  * claus.gindhart@kontron.com
  * The ST M50FLW080B and STM50FLW080B chips have to be unlocked,
diff --git a/udelay.c b/udelay.c
index 5faa004..26f538a 100644
--- a/udelay.c
+++ b/udelay.c
@@ -27,6 +27,13 @@
 #include <limits.h>
 #include "flash.h"
 
+static globals *g;
+
+void sync_globals34(void)
+{
+	g = get_globals();
+}
+
 /* loops per microsecond */
 static unsigned long micro = 1;
 
diff --git a/w29ee011.c b/w29ee011.c
index 21fb6f2..e5a0707 100644
--- a/w29ee011.c
+++ b/w29ee011.c
@@ -22,6 +22,13 @@
 #include "flash.h"
 #include "chipdrivers.h"
 
+static globals *g;
+
+void sync_globals35(void)
+{
+	g = get_globals();
+}
+
 /* According to the Winbond W29EE011, W29EE012, W29C010M, W29C011A
  * datasheets this is the only valid probe function for those chips.
  */
diff --git a/w39.c b/w39.c
index 920a43f..3b74d9d 100644
--- a/w39.c
+++ b/w39.c
@@ -22,6 +22,13 @@
 #include "flash.h"
 #include "chipdrivers.h"
 
+static globals *g;
+
+void sync_globals36(void)
+{
+	g = get_globals();
+}
+
 static int printlock_w39_fwh_block(struct flashchip *flash, int offset)
 {
 	chipaddr wrprotect = flash->virtual_registers + offset + 2;
diff --git a/wbsio_spi.c b/wbsio_spi.c
index 851c87f..b300746 100644
--- a/wbsio_spi.c
+++ b/wbsio_spi.c
@@ -25,6 +25,13 @@
 #include "programmer.h"
 #include "spi.h"
 
+static globals *g;
+
+void sync_globals37(void)
+{
+	g = get_globals();
+}
+
 #define WBSIO_PORT1	0x2e
 #define WBSIO_PORT2	0x4e
 
-- 
1.7.6

