>From b13ab4ae0542ca4f4b1b2804a45eb1fa3561ab8b Mon Sep 17 00:00:00 2001
From: Tadas Slotkus <devtadas@gmail.com>
Date: Sun, 21 Aug 2011 17:55:26 +0300
Subject: [carFl mem 60/65] Move max_rom_decode to globals

Move this variable to globals structure.
Also move structure type to flash.h.

Signed-off-by: Tadas Slotkus <devtadas@gmail.com>
---
 board_enable.c   |   10 +++++-----
 chipset_enable.c |   12 ++++++------
 flash.h          |   13 +++++++++++++
 flashrom.c       |   24 +++++++++---------------
 programmer.h     |    7 -------
 wbsio_spi.c      |    2 +-
 6 files changed, 34 insertions(+), 34 deletions(-)

diff --git a/board_enable.c b/board_enable.c
index d1e6a21..76e7642 100644
--- a/board_enable.c
+++ b/board_enable.c
@@ -431,7 +431,7 @@ int it8705f_write_enable(globals *g, uint8_t port)
 		msg_pdbg("Enabling IT8705F flash ROM interface write.\n");
 		if (tmp & 0x02) {
 			/* The data sheet contradicts itself about max size. */
-			max_rom_decode.parallel = 1024 * 1024;
+			g->max_rom_decode.parallel = 1024 * 1024;
 			msg_pinfo("IT8705F with very unusual settings. Please "
 				  "send the output of \"flashrom -V\" to \n"
 				  "flashrom@flashrom.org with "
@@ -440,9 +440,9 @@ int it8705f_write_enable(globals *g, uint8_t port)
 				  "support for your Super I/O. Thanks.\n");
 			ret = 1;
 		} else if (tmp & 0x08) {
-			max_rom_decode.parallel = 512 * 1024;
+			g->max_rom_decode.parallel = 512 * 1024;
 		} else {
-			max_rom_decode.parallel = 256 * 1024;
+			g->max_rom_decode.parallel = 256 * 1024;
 		}
 		/* Safety checks. The data sheet is unclear here: Segments 1+3
 		 * overlap, no segment seems to cover top - 1MB to top - 512kB.
@@ -486,7 +486,7 @@ int it8705f_write_enable(globals *g, uint8_t port)
 			ret = 1;
 		}
 		msg_pdbg("Maximum IT8705F parallel flash decode size is %u.\n",
-			max_rom_decode.parallel);
+			g->max_rom_decode.parallel);
 		if (ret) {
 			msg_pinfo("Not enabling IT8705F flash write.\n");
 		} else {
@@ -2272,7 +2272,7 @@ int board_flash_enable(globals *g, const char *vendor, const char *part)
 
 	if (board) {
 		if (board->max_rom_decode_parallel)
-			max_rom_decode.parallel =
+			g->max_rom_decode.parallel =
 				board->max_rom_decode_parallel * 1024;
 
 		if (board->enable != NULL) {
diff --git a/chipset_enable.c b/chipset_enable.c
index 0992af3..d240205 100644
--- a/chipset_enable.c
+++ b/chipset_enable.c
@@ -409,8 +409,8 @@ idsel_garbage_out:
 			contiguous = 0;
 		}
 	}
-	max_rom_decode.fwh = min(max_decode_fwh_idsel, max_decode_fwh_decode);
-	msg_pdbg("\nMaximum FWH chip size: 0x%x bytes", max_rom_decode.fwh);
+	g->max_rom_decode.fwh = min(max_decode_fwh_idsel, max_decode_fwh_decode);
+	msg_pdbg("\nMaximum FWH chip size: 0x%x bytes", g->max_rom_decode.fwh);
 
 	/* If we're called by enable_flash_ich_dc_spi, it will override
 	 * buses_supported anyway.
@@ -610,18 +610,18 @@ static int enable_flash_cs5530(globals *g, struct pci_dev *dev, const char *name
 	reg8 = pci_read_byte(dev, CS5530_RESET_CONTROL_REG);
 	if (reg8 & CS5530_ISA_MASTER) {
 		/* We have A0-A23 available. */
-		max_rom_decode.parallel = 16 * 1024 * 1024;
+		g->max_rom_decode.parallel = 16 * 1024 * 1024;
 	} else {
 		reg8 = pci_read_byte(dev, CS5530_USB_SHADOW_REG);
 		if (reg8 & CS5530_ENABLE_SA2320) {
 			/* We have A0-19, A20-A23 available. */
-			max_rom_decode.parallel = 16 * 1024 * 1024;
+			g->max_rom_decode.parallel = 16 * 1024 * 1024;
 		} else if (reg8 & CS5530_ENABLE_SA20) {
 			/* We have A0-19, A20 available. */
-			max_rom_decode.parallel = 2 * 1024 * 1024;
+			g->max_rom_decode.parallel = 2 * 1024 * 1024;
 		} else {
 			/* A20 and above are not active. */
-			max_rom_decode.parallel = 1024 * 1024;
+			g->max_rom_decode.parallel = 1024 * 1024;
 		}
 	}
 
diff --git a/flash.h b/flash.h
index c1fa60c..a3d3372 100644
--- a/flash.h
+++ b/flash.h
@@ -292,6 +292,13 @@ struct superio {
 	uint16_t model;
 };
 
+struct decode_sizes {
+	uint32_t parallel;
+	uint32_t lpc;
+	uint32_t fwh;
+	uint32_t spi;
+};
+
 #define TMP_BUF_SIZE 60
 
 struct globals {
@@ -323,6 +330,12 @@ struct globals {
 
 	#define SUPERIO_MAX_COUNT 3
 	struct superio superios[SUPERIO_MAX_COUNT];
+
+	/*
+	 * Programmers supporting multiple buses can have differing size limits on
+	 * each bus. Store the limits for each bus in a common struct.
+	 */
+	struct decode_sizes max_rom_decode;
 };
 void init_globals(globals *g);
 
diff --git a/flashrom.c b/flashrom.c
index 725a6d4..876db46 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -66,12 +66,6 @@ void init_globals(globals *g)
 
 static char *programmer_param = NULL;
 
-/*
- * Programmers supporting multiple buses can have differing size limits on
- * each bus. Store the limits for each bus in a common struct.
- */
-struct decode_sizes max_rom_decode;
-
 const struct programmer_entry programmer_table[] = {
 #if CONFIG_INTERNAL == 1
 	{
@@ -447,7 +441,7 @@ int programmer_init(globals *g, char *param)
 	int ret;
 	/* Initialize all programmer specific data. */
 	/* Default to unlimited decode sizes. */
-	max_rom_decode = (const struct decode_sizes) {
+	g->max_rom_decode = (const struct decode_sizes) {
 		.parallel	= 0xffffffff,
 		.lpc		= 0xffffffff,
 		.fwh		= 0xffffffff,
@@ -1021,37 +1015,37 @@ int check_max_decode(globals *g, enum chipbustype buses, uint32_t size)
 {
 	int limitexceeded = 0;
 
-	if ((buses & BUS_PARALLEL) && (max_rom_decode.parallel < size)) {
+	if ((buses & BUS_PARALLEL) && (g->max_rom_decode.parallel < size)) {
 		limitexceeded++;
 		msg_pdbg("Chip size %u kB is bigger than supported "
 			 "size %u kB of chipset/board/programmer "
 			 "for %s interface, "
 			 "probe/read/erase/write may fail. ", size / 1024,
-			 max_rom_decode.parallel / 1024, "Parallel");
+			 g->max_rom_decode.parallel / 1024, "Parallel");
 	}
-	if ((buses & BUS_LPC) && (max_rom_decode.lpc < size)) {
+	if ((buses & BUS_LPC) && (g->max_rom_decode.lpc < size)) {
 		limitexceeded++;
 		msg_pdbg("Chip size %u kB is bigger than supported "
 			 "size %u kB of chipset/board/programmer "
 			 "for %s interface, "
 			 "probe/read/erase/write may fail. ", size / 1024,
-			 max_rom_decode.lpc / 1024, "LPC");
+			 g->max_rom_decode.lpc / 1024, "LPC");
 	}
-	if ((buses & BUS_FWH) && (max_rom_decode.fwh < size)) {
+	if ((buses & BUS_FWH) && (g->max_rom_decode.fwh < size)) {
 		limitexceeded++;
 		msg_pdbg("Chip size %u kB is bigger than supported "
 			 "size %u kB of chipset/board/programmer "
 			 "for %s interface, "
 			 "probe/read/erase/write may fail. ", size / 1024,
-			 max_rom_decode.fwh / 1024, "FWH");
+			 g->max_rom_decode.fwh / 1024, "FWH");
 	}
-	if ((buses & BUS_SPI) && (max_rom_decode.spi < size)) {
+	if ((buses & BUS_SPI) && (g->max_rom_decode.spi < size)) {
 		limitexceeded++;
 		msg_pdbg("Chip size %u kB is bigger than supported "
 			 "size %u kB of chipset/board/programmer "
 			 "for %s interface, "
 			 "probe/read/erase/write may fail. ", size / 1024,
-			 max_rom_decode.spi / 1024, "SPI");
+			 g->max_rom_decode.spi / 1024, "SPI");
 	}
 	if (!limitexceeded)
 		return 0;
diff --git a/programmer.h b/programmer.h
index 8d87719..0a20014 100644
--- a/programmer.h
+++ b/programmer.h
@@ -416,13 +416,6 @@ int dediprog_init(void);
 #endif
 
 /* flashrom.c */
-struct decode_sizes {
-	uint32_t parallel;
-	uint32_t lpc;
-	uint32_t fwh;
-	uint32_t spi;
-};
-extern struct decode_sizes max_rom_decode;
 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/wbsio_spi.c b/wbsio_spi.c
index 9685f6c..f7ea33a 100644
--- a/wbsio_spi.c
+++ b/wbsio_spi.c
@@ -85,7 +85,7 @@ int wbsio_check_for_spi(globals *g)
 	register_spi_programmer(g, &spi_programmer_wbsio);
 	msg_pdbg("%s: Winbond saved on 4 register bits so max chip size is "
 		 "1024 kB!\n", __func__);
-	max_rom_decode.spi = 1024 * 1024;
+	g->max_rom_decode.spi = 1024 * 1024;
 
 	return 0;
 }
-- 
1.7.6

