>From 0de8605577dc48af84a875f112463ee632e1f1ea Mon Sep 17 00:00:00 2001
From: Tadas Slotkus <devtadas@gmail.com>
Date: Wed, 17 Aug 2011 14:47:13 +0300
Subject: [carFl mem 15/21] Move pacc to globals

Move pointer to pci_access struct to globals.
Comment unneded variables for our makefile config.

Signed-off-by: Tadas Slotkus <devtadas@gmail.com>
---
 board_enable.c |    6 +++---
 flash.h        |    2 ++
 internal.c     |   14 +++++++-------
 pcidev.c       |   16 ++++++++--------
 programmer.h   |    5 ++---
 5 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/board_enable.c b/board_enable.c
index 1da2775..8503ac7 100644
--- a/board_enable.c
+++ b/board_enable.c
@@ -889,13 +889,13 @@ static int nvidia_mcp_gpio_set(int gpio, int raise)
 		}
 
 #if PCI_LIB_VERSION >= 0x020200
-		dev = pci_get_dev(pacc, dev->domain, dev->bus, dev->dev, 1);
+		dev = pci_get_dev(g->pacc, dev->domain, dev->bus, dev->dev, 1);
 #else
 		/* pciutils/libpci before version 2.2 is too old to support
 		 * PCI domains. Such old machines usually don't have domains
 		 * besides domain 0, so this is not a problem.
 		 */
-		dev = pci_get_dev(pacc, dev->bus, dev->dev, 1);
+		dev = pci_get_dev(g->pacc, dev->bus, dev->dev, 1);
 #endif
 		if (!dev) {
 			msg_perr("MCP SMBus controller could not be found\n");
@@ -1320,7 +1320,7 @@ static int intel_ich_gpio_set(int gpio, int raise)
 	int i, allowed;
 
 	/* First, look for a known LPC bridge */
-	for (dev = pacc->devices; dev; dev = dev->next) {
+	for (dev = g->pacc->devices; dev; dev = dev->next) {
 		uint16_t device_class;
 		/* libpci before version 2.2.4 does not store class info. */
 		device_class = pci_read_word(dev, PCI_CLASS_DEVICE);
diff --git a/flash.h b/flash.h
index b57f81e..84051f3 100644
--- a/flash.h
+++ b/flash.h
@@ -284,6 +284,8 @@ struct globals {
 
 	char *lb_part, *lb_vendor;
 	int partvendor_from_cbtable;
+
+	struct pci_access *pacc;
 };
 globals *get_globals(void);
 
diff --git a/internal.c b/internal.c
index 028a0cb..3beff81 100644
--- a/internal.c
+++ b/internal.c
@@ -35,7 +35,7 @@ struct pci_dev *pci_dev_find_filter(struct pci_filter filter)
 {
 	struct pci_dev *temp;
 
-	for (temp = pacc->devices; temp; temp = temp->next)
+	for (temp = g->pacc->devices; temp; temp = temp->next)
 		if (pci_filter_match(&filter, temp))
 			return temp;
 
@@ -51,7 +51,7 @@ struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t devclass)
 	pci_filter_init(NULL, &filter);
 	filter.vendor = vendor;
 
-	for (temp = pacc->devices; temp; temp = temp->next)
+	for (temp = g->pacc->devices; temp; temp = temp->next)
 		if (pci_filter_match(&filter, temp)) {
 			/* Read PCI class */
 			tmp2 = pci_read_word(temp, 0x0a);
@@ -71,7 +71,7 @@ struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device)
 	filter.vendor = vendor;
 	filter.device = device;
 
-	for (temp = pacc->devices; temp; temp = temp->next)
+	for (temp = g->pacc->devices; temp; temp = temp->next)
 		if (pci_filter_match(&filter, temp))
 			return temp;
 
@@ -88,7 +88,7 @@ struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
 	filter.vendor = vendor;
 	filter.device = device;
 
-	for (temp = pacc->devices; temp; temp = temp->next)
+	for (temp = g->pacc->devices; temp; temp = temp->next)
 		if (pci_filter_match(&filter, temp)) {
 			if ((card_vendor ==
 			     pci_read_word(temp, PCI_SUBSYSTEM_VENDOR_ID))
@@ -200,10 +200,10 @@ int internal_init(void)
 	g->buses_supported = BUS_NONSPI;
 
 	/* Initialize PCI access for flash enables */
-	pacc = pci_alloc();	/* Get the pci_access structure */
+	g->pacc = pci_alloc();	/* Get the pci_access structure */
 	/* Set all options you want -- here we stick with the defaults */
-	pci_init(pacc);		/* Initialize the PCI library */
-	pci_scan_bus(pacc);	/* We want to get the list of devices */
+	pci_init(g->pacc);		/* Initialize the PCI library */
+	pci_scan_bus(g->pacc);	/* We want to get the list of devices */
 
 	if (processor_flash_enable()) {
 		msg_perr("Processor detection/init failed.\n"
diff --git a/pcidev.c b/pcidev.c
index 649ca5e..3265ff4 100644
--- a/pcidev.c
+++ b/pcidev.c
@@ -31,9 +31,9 @@ void sync_globals20(void)
 	g = get_globals();
 }
 
-uint32_t io_base_addr;
-struct pci_access *pacc;
-struct pci_dev *pcidev_dev = NULL;
+//uint32_t io_base_addr;
+
+static struct pci_dev *pcidev_dev = NULL;
 
 enum pci_bartype {
 	TYPE_MEMBAR,
@@ -204,10 +204,10 @@ uintptr_t pcidev_init(int bar, const struct pcidev_status *devs)
 	int found = 0;
 	uintptr_t addr = 0, curaddr = 0;
 
-	pacc = pci_alloc();     /* Get the pci_access structure */
-	pci_init(pacc);         /* Initialize the PCI library */
-	pci_scan_bus(pacc);     /* We want to get the list of devices */
-	pci_filter_init(pacc, &filter);
+	g->pacc = pci_alloc();     /* Get the pci_access structure */
+	pci_init(g->pacc);         /* Initialize the PCI library */
+	pci_scan_bus(g->pacc);     /* We want to get the list of devices */
+	pci_filter_init(g->pacc, &filter);
 
 	/* Filter by bb:dd.f (if supplied by the user). */
 	pcidev_bdf = extract_programmer_param("pci");
@@ -219,7 +219,7 @@ uintptr_t pcidev_init(int bar, const struct pcidev_status *devs)
 	}
 	free(pcidev_bdf);
 
-	for (dev = pacc->devices; dev; dev = dev->next) {
+	for (dev = g->pacc->devices; dev; dev = dev->next) {
 		if (pci_filter_match(&filter, dev)) {
 			/* FIXME: We should count all matching devices, not
 			 * just those with a valid BAR.
diff --git a/programmer.h b/programmer.h
index 03fe007..9dcc6d2 100644
--- a/programmer.h
+++ b/programmer.h
@@ -213,9 +213,8 @@ void internal_delay(int usecs);
 
 #if NEED_PCI == 1
 /* pcidev.c */
-extern uint32_t io_base_addr;
-extern struct pci_access *pacc;
-extern struct pci_dev *pcidev_dev;
+//extern uint32_t io_base_addr;
+//extern struct pci_dev *pcidev_dev;
 struct pcidev_status {
 	uint16_t vendor_id;
 	uint16_t device_id;
-- 
1.7.6

