>From a20f186ed0fe52ea6dac0ea4901654deb8b41863 Mon Sep 17 00:00:00 2001
From: Tadas Slotkus <devtadas@gmail.com>
Date: Sun, 21 Aug 2011 16:11:26 +0300
Subject: [carFl mem 58/65] Move flashbase and programmer_may_write to globals

>From now these variables reside in globals structure.

Signed-off-by: Tadas Slotkus <devtadas@gmail.com>
---
 chipset_enable.c   |    4 ++--
 flash.h            |    6 ++++++
 flashrom.c         |   14 ++++----------
 processor_enable.c |    2 +-
 programmer.h       |    2 --
 sb600spi.c         |    2 +-
 6 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/chipset_enable.c b/chipset_enable.c
index ecbe739..0992af3 100644
--- a/chipset_enable.c
+++ b/chipset_enable.c
@@ -1028,10 +1028,10 @@ static int get_flashbase_sc520(globals *g, struct pci_dev *dev, const char *name
 	if (bootcs_found) {
 		if (parx & (1 << 25)) {
 			parx &= (1 << 14) - 1; /* Mask [13:0] */
-			flashbase = parx << 16;
+			g->flashbase = parx << 16;
 		} else {
 			parx &= (1 << 18) - 1; /* Mask [17:0] */
-			flashbase = parx << 12;
+			g->flashbase = parx << 12;
 		}
 	} else {
 		msg_pinfo("AMD Elan SC520 detected, but no BOOTCS. "
diff --git a/flash.h b/flash.h
index d226551..29282c0 100644
--- a/flash.h
+++ b/flash.h
@@ -308,6 +308,12 @@ struct globals {
 	int superio_count;
 	uint32_t ichspi_bbar;
 	struct pci_access *pacc;
+
+	/* If nonzero, used as the start address of bottom-aligned flash. */
+	unsigned long flashbase;
+
+	/* Is writing allowed with this programmer? */
+	int programmer_may_write;
 };
 void init_globals(globals *g);
 
diff --git a/flashrom.c b/flashrom.c
index 5f477ac..725a6d4 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -72,12 +72,6 @@ static char *programmer_param = NULL;
  */
 struct decode_sizes max_rom_decode;
 
-/* If nonzero, used as the start address of bottom-aligned flash. */
-unsigned long flashbase;
-
-/* Is writing allowed with this programmer? */
-int programmer_may_write;
-
 const struct programmer_entry programmer_table[] = {
 #if CONFIG_INTERNAL == 1
 	{
@@ -461,11 +455,11 @@ int programmer_init(globals *g, char *param)
 	};
 	g->buses_supported = BUS_NONE;
 	/* Default to top aligned flash at 4 GB. */
-	flashbase = 0;
+	g->flashbase = 0;
 	/* Registering shutdown functions is now allowed. */
 	may_register_shutdown = 1;
 	/* Default to allowing writes. Broken programmers set this to 0. */
-	programmer_may_write = 1;
+	g->programmer_may_write = 1;
 
 	programmer_param = param;
 	msg_pdbg("Initializing %s programmer\n",
@@ -1112,7 +1106,7 @@ int probe_flash(globals *g, int startchip, struct flashchip *fill_flash, int for
 		/* Start filling in the dynamic data. */
 		*fill_flash = *flash;
 
-		base = flashbase ? flashbase : (0xffffffff - size + 1);
+		base = g->flashbase ? g->flashbase : (0xffffffff - size + 1);
 		fill_flash->virtual_memory = (chipaddr)programmer_map_flash_region(g, "flash chip", base, size);
 
 		if (force)
@@ -1775,7 +1769,7 @@ int main(int argc, char *argv[])
  */
 int chip_safety_check(globals *g, struct flashchip *flash, int force, int read_it, int write_it)
 {
-	if (!programmer_may_write && (write_it)) {
+	if (!g->programmer_may_write && (write_it)) {
 		msg_perr("Write/erase is not working yet on your programmer in "
 			 "its current configuration.\n");
 		/* --force is the wrong approach, but it's the best we can do
diff --git a/processor_enable.c b/processor_enable.c
index d8bea52..ee16ead 100644
--- a/processor_enable.c
+++ b/processor_enable.c
@@ -86,7 +86,7 @@ int processor_flash_enable(globals *g)
 	/* FIXME: detect loongson on FreeBSD and OpenBSD as well.  */
 #if defined (__MIPSEL__) && defined (__linux)
 	if (is_loongson()) {
-		flashbase = 0x1fc00000;
+		g->flashbase = 0x1fc00000;
 		return 0;
 	}
 #endif
diff --git a/programmer.h b/programmer.h
index 1b7b750..cf84a00 100644
--- a/programmer.h
+++ b/programmer.h
@@ -429,8 +429,6 @@ struct decode_sizes {
 	uint32_t spi;
 };
 extern struct decode_sizes max_rom_decode;
-extern int programmer_may_write;
-extern unsigned long flashbase;
 void check_chip_supported(const struct flashchip *flash);
 int check_max_decode(globals *g, enum chipbustype buses, uint32_t size);
 char *extract_programmer_param(globals *g, const char *param_name);
diff --git a/sb600spi.c b/sb600spi.c
index f487b58..c5b2b90 100644
--- a/sb600spi.c
+++ b/sb600spi.c
@@ -308,7 +308,7 @@ int sb600_probe_spi(globals *g, struct pci_dev *dev)
 		/* FIXME: Should we only disable SPI writes, or will the lockup
 		 * affect LPC/FWH chips as well?
 		 */
-		programmer_may_write = 0;
+		g->programmer_may_write = 0;
 	}
 
 	/* Bring the FIFO to a clean state. */
-- 
1.7.6

