>From d940a795a5449bbf165154636b655d61bcf35cb0 Mon Sep 17 00:00:00 2001
From: Tadas Slotkus <devtadas@gmail.com>
Date: Wed, 17 Aug 2011 15:21:26 +0300
Subject: [carFl mem 17/21] Move more vars + fix struct superio declaration

Move has_dmi_support, superio_count, superio array to globals.
Move struct superio type to flash.h

Signed-off-by: Tadas Slotkus <devtadas@gmail.com>
---
 board_enable.c |    2 +-
 dmi.c          |    8 +++-----
 flash.h        |   13 +++++++++++++
 flashrom.c     |    2 ++
 internal.c     |    9 ++-------
 it87spi.c      |   14 +++++++-------
 programmer.h   |    8 --------
 7 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/board_enable.c b/board_enable.c
index 8503ac7..90a4d1d 100644
--- a/board_enable.c
+++ b/board_enable.c
@@ -2190,7 +2190,7 @@ const static struct board_pciid_enable *board_match_pci_card_ids(
 		}
 
 		if (board->dmi_pattern) {
-			if (!has_dmi_support) {
+			if (!g->has_dmi_support) {
 				msg_perr("WARNING: Can't autodetect %s %s,"
 					 " DMI info unavailable.\n",
 					 board->vendor_name, board->board_name);
diff --git a/dmi.c b/dmi.c
index a17e7d7..0503af1 100644
--- a/dmi.c
+++ b/dmi.c
@@ -32,8 +32,6 @@ void sync_globals9(void)
 	g = get_globals();
 }
 
-int has_dmi_support = 0;
-
 #if STANDALONE
 
 /* Stub to indicate missing DMI functionality.
@@ -158,11 +156,11 @@ void dmi_init(void)
 	int i;
 	char *chassis_type;
 
-	has_dmi_support = 1;
+	g->has_dmi_support = 1;
 	for (i = 0; i < ARRAY_SIZE(dmidecode_names); i++) {
 		dmistrings[i] = get_dmi_string(dmidecode_names[i]);
 		if (!dmistrings[i]) {
-			has_dmi_support = 0;
+			g->has_dmi_support = 0;
 			return;
 		}
 	}
@@ -241,7 +239,7 @@ int dmi_match(const char *pattern)
 {
 	int i;
 
-	if (!has_dmi_support)
+	if (!g->has_dmi_support)
 		return 0;
 
 	for (i = 0; i < ARRAY_SIZE(dmidecode_names); i++)
diff --git a/flash.h b/flash.h
index 36bf1f2..253e5d9 100644
--- a/flash.h
+++ b/flash.h
@@ -286,6 +286,12 @@ enum programmer {
 	PROGRAMMER_INVALID /* This must always be the last entry. */
 };
 
+struct superio {
+	uint16_t vendor;
+	uint16_t port;
+	uint16_t model;
+};
+
 struct globals {
 	/* Supported buses for the current programmer. */
 	enum chipbustype buses_supported;
@@ -297,6 +303,13 @@ struct globals {
 
 	struct pci_access *pacc;
 	enum programmer programmer;
+
+	/* dmi.c */
+	int has_dmi_support;
+
+#define SUPERIO_MAX_COUNT 3
+	struct superio superios[SUPERIO_MAX_COUNT];
+	int superio_count;
 };
 globals *get_globals(void);
 
diff --git a/flashrom.c b/flashrom.c
index 4aee7bf..ba19a47 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -104,6 +104,8 @@ static void init_globals(void)
 
 	g.lb_part = NULL, g.lb_vendor = NULL;
 	g.partvendor_from_cbtable = 0;
+	g.has_dmi_support = 0;
+	g.superio_count = 0;
 	sync_all_globals();
 }
 
diff --git a/internal.c b/internal.c
index 3beff81..883f515 100644
--- a/internal.c
+++ b/internal.c
@@ -116,16 +116,11 @@ void probe_superio(void)
 #endif
 }
 
-int superio_count = 0;
-#define SUPERIO_MAX_COUNT 3
-
-struct superio superios[SUPERIO_MAX_COUNT];
-
 int register_superio(struct superio s)
 {
-	if (superio_count == SUPERIO_MAX_COUNT)
+	if (g->superio_count == SUPERIO_MAX_COUNT)
 		return 1;
-	superios[superio_count++] = s;
+	g->superios[g->superio_count++] = s;
 	return 0;
 }
 
diff --git a/it87spi.c b/it87spi.c
index 494f70e..a84fdfc 100644
--- a/it87spi.c
+++ b/it87spi.c
@@ -212,11 +212,11 @@ int init_superio_ite(void)
 {
 	int i, ret = 0;
 
-	for (i = 0; i < superio_count; i++) {
-		if (superios[i].vendor != SUPERIO_VENDOR_ITE)
+	for (i = 0; i < g->superio_count; i++) {
+		if (g->superios[i].vendor != SUPERIO_VENDOR_ITE)
 			continue;
 
-		switch (superios[i].model) {
+		switch (g->superios[i].model) {
 		case 0x8500:
 		case 0x8502:
 		case 0x8510:
@@ -227,20 +227,20 @@ int init_superio_ite(void)
 			 * which can go wrong if the EC firmware does not
 			 * implement the interface we want.
 			 */
-			//it85xx_spi_init(superios[i]);
+			//it85xx_spi_init(g->superios[i]);
 			break;
 		case 0x8705:
-			ret |= it8705f_write_enable(superios[i].port);
+			ret |= it8705f_write_enable(g->superios[i].port);
 			break;
 		case 0x8716:
 		case 0x8718:
 		case 0x8720:
-			ret |= it87spi_probe(superios[i].port);
+			ret |= it87spi_probe(g->superios[i].port);
 			break;
 		default:
 			msg_pdbg("Super I/O ID 0x%04hx is not on the list of "
 				 "flash capable controllers.\n",
-				 superios[i].model);
+				 g->superios[i].model);
 		}
 	}
 	return ret;
diff --git a/programmer.h b/programmer.h
index 157a8f7..e5d3b6f 100644
--- a/programmer.h
+++ b/programmer.h
@@ -209,18 +209,10 @@ void lb_vendor_dev_from_string(char *boardstring);
 int coreboot_init(void);
 
 /* dmi.c */
-extern int has_dmi_support;
 void dmi_init(void);
 int dmi_match(const char *pattern);
 
 /* internal.c */
-struct superio {
-	uint16_t vendor;
-	uint16_t port;
-	uint16_t model;
-};
-extern struct superio superios[];
-extern int superio_count;
 #define SUPERIO_VENDOR_NONE	0x0
 #define SUPERIO_VENDOR_ITE	0x1
 #endif
-- 
1.7.6

