>From 8c72c763e84c5d78bbabded35fca2984f45033b6 Mon Sep 17 00:00:00 2001
From: Tadas Slotkus <devtadas@gmail.com>
Date: Sat, 20 Aug 2011 21:03:22 +0300
Subject: [carFl mem 46/65] Globalisation pass 3: flashrom.c...

This invades globals to extract_programmer_param. Buffer in globals
will be used for temporary storage later.

Also chip_safety_check, check_max_decode and laptop stuff use globals
struct in their signature.

Also does nothing just passes globals forth
acros funcion calls.

This commit might broke compilation as I have squashed, fixed
"Globalisation pass 3" a lot of times going back and forth and changes
might appear not in right order. Last commit of "Globalisation pass 3"
should fix compilation since there all stuff are "in".

Signed-off-by: Tadas Slotkus <devtadas@gmail.com>
---
 board_enable.c   |   14 +++++++-------
 chipset_enable.c |    2 +-
 cli_classic.c    |    4 ++--
 dmi.c            |    8 ++++----
 dummyflasher.c   |    8 ++++----
 flash.h          |    4 ++--
 flashrom.c       |   18 +++++++++---------
 internal.c       |   16 ++++++++--------
 it87spi.c        |    8 ++++----
 programmer.h     |   16 ++++++++--------
 spi.c            |    4 ++--
 spi25.c          |    4 ++--
 12 files changed, 53 insertions(+), 53 deletions(-)

diff --git a/board_enable.c b/board_enable.c
index aba6f38..e798bf4 100644
--- a/board_enable.c
+++ b/board_enable.c
@@ -2151,7 +2151,7 @@ static const struct board_pciid_enable *board_match_coreboot_name(
  * Match boards on PCI IDs and subsystem IDs.
  * Second set of IDs can be main only or missing completely.
  */
-const static struct board_pciid_enable *board_match_pci_card_ids(
+const static struct board_pciid_enable *board_match_pci_card_ids(globals *g,
 						enum board_match_phase phase)
 {
 	const struct board_pciid_enable *board = board_pciid_enables;
@@ -2189,7 +2189,7 @@ const static struct board_pciid_enable *board_match_pci_card_ids(
 					 board->vendor_name, board->board_name);
 				continue;
 			} else {
-				if (!dmi_match(board->dmi_pattern))
+				if (!dmi_match(g, board->dmi_pattern))
 					continue;
 			}
 		}
@@ -2200,7 +2200,7 @@ const static struct board_pciid_enable *board_match_pci_card_ids(
 	return NULL;
 }
 
-static int unsafe_board_handler(const struct board_pciid_enable *board)
+static int unsafe_board_handler(globals *g, const struct board_pciid_enable *board)
 {
 	if (!board)
 		return 1;
@@ -2229,9 +2229,9 @@ static int board_handle_phase(enum board_match_phase phase)
 {
 	const struct board_pciid_enable *board = NULL;
 
-	board = board_match_pci_card_ids(phase);
+	board = board_match_pci_card_ids(g, phase);
 
-	if (unsafe_board_handler(board))
+	if (unsafe_board_handler(g, board))
 		board = NULL;
 
 	if (!board)
@@ -2265,9 +2265,9 @@ int board_flash_enable(const char *vendor, const char *part)
 		board = board_match_coreboot_name(vendor, part);
 
 	if (!board)
-		board = board_match_pci_card_ids(P3);
+		board = board_match_pci_card_ids(g, P3);
 
-	if (unsafe_board_handler(board))
+	if (unsafe_board_handler(g, board))
 		board = NULL;
 
 	if (board) {
diff --git a/chipset_enable.c b/chipset_enable.c
index cd6ad28..f6b1a71 100644
--- a/chipset_enable.c
+++ b/chipset_enable.c
@@ -313,7 +313,7 @@ static int enable_flash_ich_dc(globals *g, struct pci_dev *dev, const char *name
 	int i, tmp, max_decode_fwh_idsel = 0, max_decode_fwh_decode = 0;
 	int contiguous = 1;
 
-	idsel = extract_programmer_param("fwh_idsel");
+	idsel = extract_programmer_param(g, "fwh_idsel");
 	if (idsel && strlen(idsel)) {
 		uint64_t fwh_idsel_old, fwh_idsel;
 		errno = 0;
diff --git a/cli_classic.c b/cli_classic.c
index 1544d5e..fa961cc 100644
--- a/cli_classic.c
+++ b/cli_classic.c
@@ -410,7 +410,7 @@ int cli_classic(globals *g, int argc, char *argv[])
 	check_chip_supported(fill_flash);
 
 	size = fill_flash->total_size * 1024;
-	if (check_max_decode((buses_supported & fill_flash->bustype), size) &&
+	if (check_max_decode(g, (buses_supported & fill_flash->bustype), size) &&
 	    (!force)) {
 		fprintf(stderr, "Chip is too big for this programmer "
 			"(-V gives details). Use --force to override.\n");
@@ -441,6 +441,6 @@ int cli_classic(globals *g, int argc, char *argv[])
 	return doit(g, fill_flash, force, filename, read_it, write_it);
 
 out_shutdown:
-	programmer_shutdown();
+	programmer_shutdown(g);
 	return ret;
 }
diff --git a/dmi.c b/dmi.c
index 4f36245..5ab64f0 100644
--- a/dmi.c
+++ b/dmi.c
@@ -34,11 +34,11 @@ int has_dmi_support = 0;
  * Because dmidecode is not available on all systems, the goal is to implement
  * the DMI subset we need directly in this file.
  */
-void dmi_init(void)
+void dmi_init(globals *g)
 {
 }
 
-int dmi_match(const char *pattern)
+int dmi_match(globals *g, const char *pattern)
 {
 	return 0;
 }
@@ -146,7 +146,7 @@ static char *get_dmi_string(const char *string_name)
 	return result;
 }
 
-void dmi_init(void)
+void dmi_init(globals *g)
 {
 	int i;
 	char *chassis_type;
@@ -230,7 +230,7 @@ static int dmi_compare(const char *value, const char *pattern)
 		return strstr(value, pattern) != NULL;
 }
 
-int dmi_match(const char *pattern)
+int dmi_match(globals *g, const char *pattern)
 {
 	int i;
 
diff --git a/dummyflasher.c b/dummyflasher.c
index b7e88ef..f9caaeb 100644
--- a/dummyflasher.c
+++ b/dummyflasher.c
@@ -101,7 +101,7 @@ int dummy_init(globals *g)
 
 	msg_pspew("%s\n", __func__);
 
-	bustext = extract_programmer_param("bus");
+	bustext = extract_programmer_param(g, "bus");
 	msg_pdbg("Requested buses are: %s\n", bustext ? bustext : "default");
 	if (!bustext)
 		bustext = strdup("parallel+lpc+fwh+spi");
@@ -129,7 +129,7 @@ int dummy_init(globals *g)
 		msg_pdbg("Support for all flash bus types disabled.\n");
 	free(bustext);
 
-	tmp = extract_programmer_param("spi_write_256_chunksize");
+	tmp = extract_programmer_param(g, "spi_write_256_chunksize");
 	if (tmp) {
 		spi_write_256_chunksize = atoi(tmp);
 		free(tmp);
@@ -140,7 +140,7 @@ int dummy_init(globals *g)
 	}
 
 #if EMULATE_CHIP
-	tmp = extract_programmer_param("emulate");
+	tmp = extract_programmer_param(g, "emulate");
 	if (!tmp) {
 		msg_pdbg("Not emulating any flash chip.\n");
 		/* Nothing else to do. */
@@ -202,7 +202,7 @@ int dummy_init(globals *g)
 	msg_pdbg("Filling fake flash chip with 0xff, size %i\n", emu_chip_size);
 	memset(flashchip_contents, 0xff, emu_chip_size);
 
-	emu_persistent_image = extract_programmer_param("image");
+	emu_persistent_image = extract_programmer_param(g, "image");
 	if (!emu_persistent_image) {
 		/* Nothing else to do. */
 		goto dummy_init_out;
diff --git a/flash.h b/flash.h
index 41dbf0c..b98f40b 100644
--- a/flash.h
+++ b/flash.h
@@ -217,7 +217,7 @@ int read_flash_to_file(globals *g, struct flashchip *flash, const char *filename
 int min(int a, int b);
 int max(int a, int b);
 void tolower_string(char *str);
-char *extract_param(char **haystack, const char *needle, const char *delim);
+char *extract_param(globals *g, char **haystack, const char *needle, const char *delim);
 int verify_range(globals *g, struct flashchip *flash, uint8_t *cmpbuf, int start, int len, const char *message);
 int need_erase(uint8_t *have, uint8_t *want, int len, enum write_granularity gran);
 char *strcat_realloc(char *dest, const char *src);
@@ -277,7 +277,7 @@ struct spi_command {
 int spi_send_command(globals *g, unsigned int writecnt, unsigned int readcnt,
 		const unsigned char *writearr, unsigned char *readarr);
 int spi_send_multicommand(globals *g, struct spi_command *cmds);
-uint32_t spi_get_valid_read_addr(void);
+uint32_t spi_get_valid_read_addr(globals *g);
 
 enum programmer {
 #if CONFIG_INTERNAL == 1
diff --git a/flashrom.c b/flashrom.c
index 6c50566..7a0b238 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -472,7 +472,7 @@ int programmer_init(globals *g, char *param)
 	return ret;
 }
 
-int programmer_shutdown(void)
+int programmer_shutdown(globals *g)
 {
 	int ret = 0;
 
@@ -599,7 +599,7 @@ char *strcat_realloc(char *dest, const char *src)
  * needle and remove everything from the first occurrence of needle to the next
  * delimiter from haystack.
  */
-char *extract_param(char **haystack, const char *needle, const char *delim)
+char *extract_param(globals *g, char **haystack, const char *needle, const char *delim)
 {
 	char *param_pos, *opt_pos, *rest;
 	char *opt = NULL;
@@ -656,9 +656,9 @@ char *extract_param(char **haystack, const char *needle, const char *delim)
 	return opt;
 }
 
-char *extract_programmer_param(const char *param_name)
+char *extract_programmer_param(globals *g, const char *param_name)
 {
-	return extract_param(&programmer_param, param_name, ",");
+	return extract_param(g, &programmer_param, param_name, ",");
 }
 
 /* Returns the number of well-defined erasers for a chip. */
@@ -1016,7 +1016,7 @@ int generate_testpattern(uint8_t *buf, uint32_t size, int variant)
 	return 0;
 }
 
-int check_max_decode(enum chipbustype buses, uint32_t size)
+int check_max_decode(globals *g, enum chipbustype buses, uint32_t size)
 {
 	int limitexceeded = 0;
 
@@ -1100,7 +1100,7 @@ int probe_flash(globals *g, int startchip, struct flashchip *fill_flash, int for
 		}
 
 		size = flash->total_size * 1024;
-		check_max_decode(buses_common, size);
+		check_max_decode(g, buses_common, size);
 
 		/* Start filling in the dynamic data. */
 		*fill_flash = *flash;
@@ -1766,7 +1766,7 @@ int main(int argc, char *argv[])
 /* FIXME: This function signature needs to be improved once doit() has a better
  * function signature.
  */
-int chip_safety_check(struct flashchip *flash, int force, int read_it, int write_it)
+int chip_safety_check(globals *g, struct flashchip *flash, int force, int read_it, int write_it)
 {
 	if (!programmer_may_write && (write_it)) {
 		msg_perr("Write/erase is not working yet on your programmer in "
@@ -1833,7 +1833,7 @@ int doit(globals *g, struct flashchip *flash, int force, const char *filename, i
 	uint8_t newcontents[BUF_SIZE];
 	int ret = 0;
 
-	if (chip_safety_check(flash, force, read_it, write_it)) {
+	if (chip_safety_check(g, flash, force, read_it, write_it)) {
 		msg_cerr("Aborting.\n");
 		ret = 1;
 		goto out_nofree;
@@ -1860,6 +1860,6 @@ int doit(globals *g, struct flashchip *flash, int force, const char *filename, i
 
 out:
 out_nofree:
-	programmer_shutdown();
+	programmer_shutdown(g);
 	return ret;
 }
diff --git a/internal.c b/internal.c
index 4d9e416..b2ca5e4 100644
--- a/internal.c
+++ b/internal.c
@@ -99,9 +99,9 @@ int force_boardenable = 0;
 int force_boardmismatch = 0;
 
 #if defined(__i386__) || defined(__x86_64__)
-void probe_superio(void)
+void probe_superio(globals *g)
 {
-	probe_superio_ite();
+	probe_superio_ite(g);
 #if 0
 	/* Winbond Super I/O code is not yet available. */
 	if (superio.vendor == SUPERIO_VENDOR_NONE)
@@ -114,7 +114,7 @@ int superio_count = 0;
 
 struct superio superios[SUPERIO_MAX_COUNT];
 
-int register_superio(struct superio s)
+int register_superio(globals *g, struct superio s)
 {
 	if (superio_count == SUPERIO_MAX_COUNT)
 		return 1;
@@ -141,7 +141,7 @@ int internal_init(globals *g)
 	int force_laptop = 0;
 	char *arg;
 
-	arg = extract_programmer_param("boardenable");
+	arg = extract_programmer_param(g, "boardenable");
 	if (arg && !strcmp(arg,"force")) {
 		force_boardenable = 1;
 	} else if (arg && !strlen(arg)) {
@@ -155,7 +155,7 @@ int internal_init(globals *g)
 	}
 	free(arg);
 
-	arg = extract_programmer_param("boardmismatch");
+	arg = extract_programmer_param(g, "boardmismatch");
 	if (arg && !strcmp(arg,"force")) {
 		force_boardmismatch = 1;
 	} else if (arg && !strlen(arg)) {
@@ -169,7 +169,7 @@ int internal_init(globals *g)
 	}
 	free(arg);
 
-	arg = extract_programmer_param("laptop");
+	arg = extract_programmer_param(g, "laptop");
 	if (arg && !strcmp(arg,"force_I_want_a_brick")) {
 		force_laptop = 1;
 	} else if (arg && !strlen(arg)) {
@@ -210,13 +210,13 @@ int internal_init(globals *g)
 	 */
 	coreboot_init();
 
-	dmi_init();
+	dmi_init(g);
 
 	/* In case Super I/O probing would cause pretty explosions. */
 	board_handle_before_superio();
 
 	/* Probe for the Super I/O chip and fill global struct superio. */
-	probe_superio();
+	probe_superio(g);
 #else
 	/* FIXME: Enable cbtable searching on all non-x86 platforms supported
 	 *        by coreboot.
diff --git a/it87spi.c b/it87spi.c
index 3c01bcb..2770e3a 100644
--- a/it87spi.c
+++ b/it87spi.c
@@ -71,7 +71,7 @@ uint16_t probe_id_ite(uint16_t port)
 	return id;
 }
 
-void probe_superio_ite(void)
+void probe_superio_ite(globals *g)
 {
 	struct superio s = {};
 	uint16_t ite_ports[] = {ITE_SUPERIO_PORT1, ITE_SUPERIO_PORT2, 0};
@@ -88,14 +88,14 @@ void probe_superio_ite(void)
 			/* FIXME: Print revision for all models? */
 			msg_pdbg("Found ITE Super I/O, ID 0x%04hx on port "
 				 "0x%x\n", s.model, s.port);
-			register_superio(s);
+			register_superio(g, s);
 			break;
 		case 0x85:
 			msg_pdbg("Found ITE EC, ID 0x%04hx,"
 			         "Rev 0x%02x on port 0x%x.\n",
 			         s.model, sio_read(s.port, CHIP_VER_REG),
 			         s.port);
-			register_superio(s);
+			register_superio(g, s);
 			break;
 		}
 	}
@@ -164,7 +164,7 @@ static uint16_t it87spi_probe(globals *g, uint16_t port)
 	flashport |= sio_read(port, 0x65);
 	msg_pdbg("Serial flash port 0x%04x\n", flashport);
 	/* Non-default port requested? */
-	portpos = extract_programmer_param("it87spiport");
+	portpos = extract_programmer_param(g, "it87spiport");
 	if (portpos) {
 		char *endptr = NULL;
 		unsigned long forced_flashport;
diff --git a/programmer.h b/programmer.h
index 1882e46..441cf19 100644
--- a/programmer.h
+++ b/programmer.h
@@ -48,7 +48,7 @@ struct programmer_entry {
 extern const struct programmer_entry programmer_table[];
 
 int programmer_init(globals *g, char *param);
-int programmer_shutdown(void);
+int programmer_shutdown(globals *g);
 
 enum bitbang_spi_master_type {
 	BITBANG_SPI_INVALID	= 0, /* This must always be the first entry. */
@@ -212,8 +212,8 @@ extern int partvendor_from_cbtable;
 
 /* dmi.c */
 extern int has_dmi_support;
-void dmi_init(void);
-int dmi_match(const char *pattern);
+void dmi_init(globals *g);
+int dmi_match(globals *g, const char *pattern);
 
 /* internal.c */
 struct superio {
@@ -240,8 +240,8 @@ extern int is_laptop;
 extern int laptop_ok;
 extern int force_boardenable;
 extern int force_boardmismatch;
-void probe_superio(void);
-int register_superio(struct superio s);
+void probe_superio(globals *g);
+int register_superio(globals *g, struct superio s);
 int internal_init(globals *g);
 void internal_chip_writeb(uint8_t val, chipaddr addr);
 void internal_chip_writew(uint16_t val, chipaddr addr);
@@ -443,8 +443,8 @@ 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(enum chipbustype buses, uint32_t size);
-char *extract_programmer_param(const char *param_name);
+int check_max_decode(globals *g, enum chipbustype buses, uint32_t size);
+char *extract_programmer_param(globals *g, const char *param_name);
 
 /* layout.c */
 int show_id(uint8_t *bios, int size, int force);
@@ -518,7 +518,7 @@ int it85xx_spi_init(globals *g, struct superio s);
 /* it87spi.c */
 void enter_conf_mode_ite(uint16_t port);
 void exit_conf_mode_ite(uint16_t port);
-void probe_superio_ite(void);
+void probe_superio_ite(globals *g);
 int init_superio_ite(globals *g);
 
 /* mcp6x_spi.c */
diff --git a/spi.c b/spi.c
index 72b1192..5125279 100644
--- a/spi.c
+++ b/spi.c
@@ -135,7 +135,7 @@ int spi_chip_read(globals *g, struct flashchip *flash, uint8_t *buf, int start,
 	 * address. Highest possible address with the current SPI implementation
 	 * means 0xffffff, the highest unsigned 24bit number.
 	 */
-	addrbase = spi_get_valid_read_addr();
+	addrbase = spi_get_valid_read_addr(g);
 	if (addrbase + flash->total_size * 1024 > (1 << 24)) {
 		msg_perr("Flash chip size exceeds the allowed access window. ");
 		msg_perr("Read will probably fail.\n");
@@ -177,7 +177,7 @@ int spi_chip_write_256(globals *g, struct flashchip *flash, uint8_t *buf, int st
  * be the lowest allowed address for all commands which take an address.
  * This is a programmer limitation.
  */
-uint32_t spi_get_valid_read_addr(void)
+uint32_t spi_get_valid_read_addr(globals *g)
 {
 	switch (spi_programmer->type) {
 #if CONFIG_INTERNAL == 1
diff --git a/spi25.c b/spi25.c
index 69c3487..0535eec 100644
--- a/spi25.c
+++ b/spi25.c
@@ -54,7 +54,7 @@ static int spi_rems(globals *g, unsigned char *readarr)
 	ret = spi_send_command(g, sizeof(cmd), JEDEC_REMS_INSIZE, cmd, readarr);
 	if (ret == SPI_INVALID_ADDRESS) {
 		/* Find the lowest even address allowed for reads. */
-		readaddr = (spi_get_valid_read_addr() + 1) & ~1;
+		readaddr = (spi_get_valid_read_addr(g) + 1) & ~1;
 		cmd[1] = (readaddr >> 16) & 0xff,
 		cmd[2] = (readaddr >> 8) & 0xff,
 		cmd[3] = (readaddr >> 0) & 0xff,
@@ -76,7 +76,7 @@ static int spi_res(globals *g, unsigned char *readarr, int bytes)
 	ret = spi_send_command(g, sizeof(cmd), bytes, cmd, readarr);
 	if (ret == SPI_INVALID_ADDRESS) {
 		/* Find the lowest even address allowed for reads. */
-		readaddr = (spi_get_valid_read_addr() + 1) & ~1;
+		readaddr = (spi_get_valid_read_addr(g) + 1) & ~1;
 		cmd[1] = (readaddr >> 16) & 0xff,
 		cmd[2] = (readaddr >> 8) & 0xff,
 		cmd[3] = (readaddr >> 0) & 0xff,
-- 
1.7.6

