linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch 00/53] PNP cleanup and convert to dynamic resources, v3
@ 2008-04-18 20:49 Bjorn Helgaas
  2008-04-18 20:49 ` [patch 01/53] ISAPNP: move config register addresses out of isapnp.h Bjorn Helgaas
                   ` (52 more replies)
  0 siblings, 53 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:49 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

This finally replaces the fixed-size pnp_resource_table
with something more dynamic so we can quit worrying about
table overflows.

Most of the patches here just lead up to the dynamic
resources patch by incrementally cleaning things up
and reducing the amount of code that knows about the
pnp_resource_table.

There are a *lot* of changes from v2, mostly to fix the
ISAPNP problem Rene pointed out (we need to track the
config register index so we write things back to the
same register we read them from).

Rene, you acked many of these patches previously, and
I noted those in the patches.  But where I made more than
trivial changes, I removed your ack.

Changes between v2 and v3:

  - several updates from Rene Herman's review:
	- tweak EISA ID conversion and keep high-order bit for ISAPNP
	- fix pnp_add_card_id() to bisection works better
	- fix some "x <= 0" tests when x is unsigned
	- make resource accessors inlines, not #defines
	- fix pnp_{port,mem,irq,dma}_valid() return int, not resource_size_t
	- fold isapnp_read_resources() back into isapnp_get_resources()
  - factored out pnp_init_resource() from pnp_{init,clean}_resource_table()
  - initialize generic pnp_dev fields earlier, to help dev_printk
  - add pnp_resource to hold ISAPNP register index
  - convert to resource management from table to list (finally)
  - remove pnp_dev->regs (only set by ISAPNP, never used)
  - in /sys/.../resources, don't sort resources by type

Changes between first post and v2:

  - export pnp_get_resource()
  - fix EISA ID conversion and make a common function for ISAPNP/PNPBIOS
  - fix typos in pnp_check_{port,mem,etc} that made resource assign fail

  - the following fixes should precede this series (they're in -mm already):
	- parport_pc: wrap PNP probe code in CONFIG_PNP
	- radio-cadet: wrap PNP probe code in CONFIG_PNP
	- smsc-ircc2: wrap PNP probe code in CONFIG_PNP
	- nsc-ircc: wrap PNP probe code in CONFIG_PNP

Bjorn

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 01/53] ISAPNP: move config register addresses out of isapnp.h
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
@ 2008-04-18 20:49 ` Bjorn Helgaas
  2008-04-18 20:49 ` [patch 02/53] PNPACPI: continue after _CRS and _PRS errors Bjorn Helgaas
                   ` (51 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:49 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, Rene Herman, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: isapnp-remove-register-addrs-from-header --]
[-- Type: text/plain, Size: 1549 bytes --]

These are used only in drivers/pnp/isapnp/core.c, so no need to
expose them to the world.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: Rene Herman <rene.herman@gmail.com>

Index: work7/drivers/pnp/isapnp/core.c
===================================================================
--- work7.orig/drivers/pnp/isapnp/core.c	2008-03-21 11:52:12.000000000 -0600
+++ work7/drivers/pnp/isapnp/core.c	2008-03-21 11:53:24.000000000 -0600
@@ -88,6 +88,14 @@
 #define _LTAG_MEM32RANGE	0x85
 #define _LTAG_FIXEDMEM32RANGE	0x86
 
+/* Logical device control and configuration registers */
+
+#define ISAPNP_CFG_ACTIVATE	0x30	/* byte */
+#define ISAPNP_CFG_MEM		0x40	/* 4 * dword */
+#define ISAPNP_CFG_PORT		0x60	/* 8 * word */
+#define ISAPNP_CFG_IRQ		0x70	/* 2 * word */
+#define ISAPNP_CFG_DMA		0x74	/* 2 * byte */
+
 /*
  * Sizes of ISAPNP logical device configuration register sets.
  * See PNP-ISA-v1.0a.pdf, Appendix A.
Index: work7/include/linux/isapnp.h
===================================================================
--- work7.orig/include/linux/isapnp.h	2008-03-21 11:45:41.000000000 -0600
+++ work7/include/linux/isapnp.h	2008-03-21 11:52:39.000000000 -0600
@@ -26,16 +26,6 @@
 #include <linux/pnp.h>
 
 /*
- *  Configuration registers (TODO: change by specification)
- */ 
-
-#define ISAPNP_CFG_ACTIVATE		0x30	/* byte */
-#define ISAPNP_CFG_MEM			0x40	/* 4 * dword */
-#define ISAPNP_CFG_PORT			0x60	/* 8 * word */
-#define ISAPNP_CFG_IRQ			0x70	/* 2 * word */
-#define ISAPNP_CFG_DMA			0x74	/* 2 * byte */
-
-/*
  *
  */
 

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 02/53] PNPACPI: continue after _CRS and _PRS errors
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
  2008-04-18 20:49 ` [patch 01/53] ISAPNP: move config register addresses out of isapnp.h Bjorn Helgaas
@ 2008-04-18 20:49 ` Bjorn Helgaas
  2008-04-18 20:49 ` [patch 03/53] PNP: make pnp_add_id() internal to PNP core Bjorn Helgaas
                   ` (50 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:49 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnpacpi-ignore-errors --]
[-- Type: text/plain, Size: 1230 bytes --]

Keep going and register the device even if we have trouble parsing
_CRS or _PRS.  A parsing problem might mean we ignore some resources
the device is using, or we might not be able to change its resources.
But we should still take note of anything we *could* parse correctly.

Also remove reference to dev_id because I plan to remove it soon.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>

Index: work7/drivers/pnp/pnpacpi/core.c
===================================================================
--- work7.orig/drivers/pnp/pnpacpi/core.c	2008-03-21 15:12:19.000000000 -0600
+++ work7/drivers/pnp/pnpacpi/core.c	2008-03-21 15:12:20.000000000 -0600
@@ -213,8 +213,7 @@
 							  &dev->res);
 		if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
 			pnp_err("PnPACPI: METHOD_NAME__CRS failure for %s",
-				dev_id->id);
-			goto err1;
+				acpi_device_hid(device));
 		}
 	}
 
@@ -223,8 +222,7 @@
 							    dev);
 		if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
 			pnp_err("PnPACPI: METHOD_NAME__PRS failure for %s",
-				dev_id->id);
-			goto err1;
+				acpi_device_hid(device));
 		}
 	}
 
@@ -252,8 +250,6 @@
 	num++;
 
 	return AE_OK;
-err1:
-	kfree(dev_id);
 err:
 	kfree(dev);
 	return -EINVAL;

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 03/53] PNP: make pnp_add_id() internal to PNP core
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
  2008-04-18 20:49 ` [patch 01/53] ISAPNP: move config register addresses out of isapnp.h Bjorn Helgaas
  2008-04-18 20:49 ` [patch 02/53] PNPACPI: continue after _CRS and _PRS errors Bjorn Helgaas
@ 2008-04-18 20:49 ` Bjorn Helgaas
  2008-04-18 20:49 ` [patch 04/53] PNP: change pnp_add_id() to allocate its own pnp_id structures Bjorn Helgaas
                   ` (49 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:49 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, Rene Herman, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-make-pnp_add_id-internal-to-core --]
[-- Type: text/plain, Size: 2507 bytes --]

pnp_add_id() doesn't need to be exposed outside the PNP core, so
move the declaration to an internal header file.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: Rene Herman <rene.herman@gmail.com>

Index: work7/include/linux/pnp.h
===================================================================
--- work7.orig/include/linux/pnp.h	2008-03-21 13:31:06.000000000 -0600
+++ work7/include/linux/pnp.h	2008-03-21 13:31:08.000000000 -0600
@@ -403,7 +403,6 @@
 /* protocol helpers */
 int pnp_is_active(struct pnp_dev *dev);
 int compare_pnp_id(struct pnp_id *pos, const char *id);
-int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev);
 int pnp_register_driver(struct pnp_driver *drv);
 void pnp_unregister_driver(struct pnp_driver *drv);
 
@@ -450,7 +449,6 @@
 /* protocol helpers */
 static inline int pnp_is_active(struct pnp_dev *dev) { return 0; }
 static inline int compare_pnp_id(struct pnp_id *pos, const char *id) { return -ENODEV; }
-static inline int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev) { return -ENODEV; }
 static inline int pnp_register_driver(struct pnp_driver *drv) { return -ENODEV; }
 static inline void pnp_unregister_driver(struct pnp_driver *drv) { }
 
Index: work7/drivers/pnp/base.h
===================================================================
--- work7.orig/drivers/pnp/base.h	2008-03-21 13:31:06.000000000 -0600
+++ work7/drivers/pnp/base.h	2008-03-21 13:31:39.000000000 -0600
@@ -1,5 +1,6 @@
 extern spinlock_t pnp_lock;
 void *pnp_alloc(long size);
+int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev);
 int pnp_interface_attach_device(struct pnp_dev *dev);
 void pnp_fixup_device(struct pnp_dev *dev);
 void pnp_free_option(struct pnp_option *option);
Index: work7/drivers/pnp/pnpacpi/core.c
===================================================================
--- work7.orig/drivers/pnp/pnpacpi/core.c	2008-03-21 13:31:06.000000000 -0600
+++ work7/drivers/pnp/pnpacpi/core.c	2008-03-21 13:31:08.000000000 -0600
@@ -25,6 +25,7 @@
 #include <acpi/acpi_bus.h>
 #include <acpi/actypes.h>
 
+#include "../base.h"
 #include "pnpacpi.h"
 
 static int num = 0;
Index: work7/drivers/pnp/pnpbios/core.c
===================================================================
--- work7.orig/drivers/pnp/pnpbios/core.c	2008-03-21 13:31:06.000000000 -0600
+++ work7/drivers/pnp/pnpbios/core.c	2008-03-21 13:31:08.000000000 -0600
@@ -69,6 +69,7 @@
 #include <asm/system.h>
 #include <asm/byteorder.h>
 
+#include "../base.h"
 #include "pnpbios.h"
 
 /*

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 04/53] PNP: change pnp_add_id() to allocate its own pnp_id structures
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (2 preceding siblings ...)
  2008-04-18 20:49 ` [patch 03/53] PNP: make pnp_add_id() internal to PNP core Bjorn Helgaas
@ 2008-04-18 20:49 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 05/53] PNP: add pnp_eisa_id_to_string() Bjorn Helgaas
                   ` (48 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:49 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, Rene Herman, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-move-allocation-into-pnp_add_id --]
[-- Type: text/plain, Size: 6484 bytes --]

This moves some of the pnp_id knowledge out of the backends and into
the PNP core.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: Rene Herman <rene.herman@gmail.com>

---
 drivers/pnp/base.h             |    2 +-
 drivers/pnp/driver.c           |   28 +++++++++++++++++++++-------
 drivers/pnp/isapnp/core.c      |   24 +++++++++++-------------
 drivers/pnp/pnpacpi/core.c     |   27 +++------------------------
 drivers/pnp/pnpbios/core.c     |   10 +---------
 drivers/pnp/pnpbios/rsparser.c |    7 +------
 6 files changed, 38 insertions(+), 60 deletions(-)

Index: work7/drivers/pnp/base.h
===================================================================
--- work7.orig/drivers/pnp/base.h	2008-03-26 10:50:27.000000000 -0600
+++ work7/drivers/pnp/base.h	2008-03-31 15:42:26.000000000 -0600
@@ -1,6 +1,6 @@
 extern spinlock_t pnp_lock;
 void *pnp_alloc(long size);
-int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev);
+struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id);
 int pnp_interface_attach_device(struct pnp_dev *dev);
 void pnp_fixup_device(struct pnp_dev *dev);
 void pnp_free_option(struct pnp_option *option);
Index: work7/drivers/pnp/driver.c
===================================================================
--- work7.orig/drivers/pnp/driver.c	2008-03-26 10:50:24.000000000 -0600
+++ work7/drivers/pnp/driver.c	2008-03-26 10:50:28.000000000 -0600
@@ -226,22 +226,36 @@
 
 /**
  * pnp_add_id - adds an EISA id to the specified device
- * @id: pointer to a pnp_id structure
  * @dev: pointer to the desired device
+ * @id: pointer to an EISA id string
  */
-int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev)
+struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id)
 {
-	struct pnp_id *ptr;
+	struct pnp_id *dev_id, *ptr;
 
-	id->next = NULL;
+	dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
+	if (!dev_id)
+		return NULL;
+
+	dev_id->id[0] = id[0];
+	dev_id->id[1] = id[1];
+	dev_id->id[2] = id[2];
+	dev_id->id[3] = tolower(id[3]);
+	dev_id->id[4] = tolower(id[4]);
+	dev_id->id[5] = tolower(id[5]);
+	dev_id->id[6] = tolower(id[6]);
+	dev_id->id[7] = '\0';
+
+	dev_id->next = NULL;
 	ptr = dev->id;
 	while (ptr && ptr->next)
 		ptr = ptr->next;
 	if (ptr)
-		ptr->next = id;
+		ptr->next = dev_id;
 	else
-		dev->id = id;
-	return 0;
+		dev->id = dev_id;
+
+	return dev_id;
 }
 
 EXPORT_SYMBOL(pnp_register_driver);
Index: work7/drivers/pnp/isapnp/core.c
===================================================================
--- work7.orig/drivers/pnp/isapnp/core.c	2008-03-26 10:50:25.000000000 -0600
+++ work7/drivers/pnp/isapnp/core.c	2008-03-31 15:46:38.000000000 -0600
@@ -44,6 +44,8 @@
 #include <linux/mutex.h>
 #include <asm/io.h>
 
+#include "../base.h"
+
 #if 0
 #define ISAPNP_REGION_OK
 #endif
@@ -401,20 +403,16 @@
 static void isapnp_parse_id(struct pnp_dev *dev, unsigned short vendor,
 			    unsigned short device)
 {
-	struct pnp_id *id;
+	char id[8];
 
-	if (!dev)
-		return;
-	id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
-	if (!id)
-		return;
-	sprintf(id->id, "%c%c%c%x%x%x%x",
+	sprintf(id, "%c%c%c%x%x%x%x",
 		'A' + ((vendor >> 2) & 0x3f) - 1,
 		'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1,
 		'A' + ((vendor >> 8) & 0x1f) - 1,
 		(device >> 4) & 0x0f,
 		device & 0x0f, (device >> 12) & 0x0f, (device >> 8) & 0x0f);
-	pnp_add_id(id, dev);
+
+	pnp_add_id(dev, id);
 }
 
 /*
Index: work7/drivers/pnp/pnpacpi/core.c
===================================================================
--- work7.orig/drivers/pnp/pnpacpi/core.c	2008-03-26 10:50:27.000000000 -0600
+++ work7/drivers/pnp/pnpacpi/core.c	2008-03-31 15:42:26.000000000 -0600
@@ -73,18 +73,6 @@
 	return 1;
 }
 
-static void __init pnpidacpi_to_pnpid(char *id, char *str)
-{
-	str[0] = id[0];
-	str[1] = id[1];
-	str[2] = id[2];
-	str[3] = tolower(id[3]);
-	str[4] = tolower(id[4]);
-	str[5] = tolower(id[5]);
-	str[6] = tolower(id[6]);
-	str[7] = '\0';
-}
-
 static int pnpacpi_get_resources(struct pnp_dev *dev,
 				 struct pnp_resource_table *res)
 {
@@ -201,12 +189,9 @@
 
 	dev->number = num;
 
-	/* set the initial values for the PnP device */
-	dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
+	dev_id = pnp_add_id(dev, acpi_device_hid(device));
 	if (!dev_id)
 		goto err;
-	pnpidacpi_to_pnpid(acpi_device_hid(device), dev_id->id);
-	pnp_add_id(dev_id, dev);
 
 	if (dev->active) {
 		/* parse allocated resource */
@@ -227,7 +212,6 @@
 		}
 	}
 
-	/* parse compatible ids */
 	if (device->flags.compatible_ids) {
 		struct acpi_compatible_id_list *cid_list = device->pnp.cid_list;
 		int i;
@@ -235,12 +219,7 @@
 		for (i = 0; i < cid_list->count; i++) {
 			if (!ispnpidacpi(cid_list->id[i].value))
 				continue;
-			dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
-			if (!dev_id)
-				continue;
-
-			pnpidacpi_to_pnpid(cid_list->id[i].value, dev_id->id);
-			pnp_add_id(dev_id, dev);
+			pnp_add_id(dev, cid_list->id[i].value);
 		}
 	}
 
Index: work7/drivers/pnp/pnpbios/core.c
===================================================================
--- work7.orig/drivers/pnp/pnpbios/core.c	2008-03-26 10:50:27.000000000 -0600
+++ work7/drivers/pnp/pnpbios/core.c	2008-03-31 15:42:26.000000000 -0600
@@ -332,16 +332,14 @@
 	if (!dev)
 		return -1;
 
-	dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
+	pnpid32_to_pnpid(node->eisa_id, id);
+	dev_id = pnp_add_id(dev, id);
 	if (!dev_id) {
 		kfree(dev);
 		return -1;
 	}
 
 	dev->number = node->handle;
-	pnpid32_to_pnpid(node->eisa_id, id);
-	memcpy(dev_id->id, id, 7);
-	pnp_add_id(dev_id, dev);
 	pnpbios_parse_data_stream(dev, node);
 	dev->active = pnp_is_active(dev);
 	dev->flags = node->flags;
Index: work7/drivers/pnp/pnpbios/rsparser.c
===================================================================
--- work7.orig/drivers/pnp/pnpbios/rsparser.c	2008-03-26 10:50:24.000000000 -0600
+++ work7/drivers/pnp/pnpbios/rsparser.c	2008-03-31 15:42:25.000000000 -0600
@@ -16,6 +16,7 @@
 }
 #endif				/* CONFIG_PCI */
 
+#include "../base.h"
 #include "pnpbios.h"
 
 /* standard resource tags */
@@ -548,13 +549,11 @@
 		case SMALL_TAG_COMPATDEVID:	/* compatible ID */
 			if (len != 4)
 				goto len_err;
-			dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
-			if (!dev_id)
-				return NULL;
 			pnpid32_to_pnpid(p[1] | p[2] << 8 | p[3] << 16 | p[4] <<
 					 24, id);
-			memcpy(&dev_id->id, id, 7);
-			pnp_add_id(dev_id, dev);
+			dev_id = pnp_add_id(dev, id);
+			if (!dev_id)
+				return NULL;
 			break;
 
 		case SMALL_TAG_END:

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 05/53] PNP: add pnp_eisa_id_to_string()
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (3 preceding siblings ...)
  2008-04-18 20:49 ` [patch 04/53] PNP: change pnp_add_id() to allocate its own pnp_id structures Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 06/53] PNP: add pnp_alloc_dev() Bjorn Helgaas
                   ` (47 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-common-eisa-id-parse --]
[-- Type: text/plain, Size: 6103 bytes --]

Converting the EISA ID to a string is messy and error-prone, and
we might as well use the same code for ISAPNP and PNPBIOS.

PNPACPI uses the conversion done by the ACPI core with
acpi_ex_eisa_id_to_string().

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>

---
 drivers/pnp/base.h             |    2 ++
 drivers/pnp/isapnp/core.c      |   32 +++++++++++---------------------
 drivers/pnp/pnpbios/core.c     |    2 +-
 drivers/pnp/pnpbios/rsparser.c |   26 +++-----------------------
 drivers/pnp/support.c          |   26 ++++++++++++++++++++++++++
 5 files changed, 43 insertions(+), 45 deletions(-)

Index: work7/drivers/pnp/base.h
===================================================================
--- work7.orig/drivers/pnp/base.h	2008-04-02 10:22:28.000000000 -0600
+++ work7/drivers/pnp/base.h	2008-04-02 14:59:50.000000000 -0600
@@ -1,5 +1,7 @@
 extern spinlock_t pnp_lock;
 void *pnp_alloc(long size);
+#define PNP_EISA_ID_MASK 0x7fffffff
+void pnp_eisa_id_to_string(u32 id, char *str);
 struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id);
 int pnp_interface_attach_device(struct pnp_dev *dev);
 void pnp_fixup_device(struct pnp_dev *dev);
Index: work7/drivers/pnp/isapnp/core.c
===================================================================
--- work7.orig/drivers/pnp/isapnp/core.c	2008-04-02 10:22:28.000000000 -0600
+++ work7/drivers/pnp/isapnp/core.c	2008-04-02 14:39:11.000000000 -0600
@@ -398,24 +398,6 @@
 }
 
 /*
- *  Parse EISA id.
- */
-static void isapnp_parse_id(struct pnp_dev *dev, unsigned short vendor,
-			    unsigned short device)
-{
-	char id[8];
-
-	sprintf(id, "%c%c%c%x%x%x%x",
-		'A' + ((vendor >> 2) & 0x3f) - 1,
-		'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1,
-		'A' + ((vendor >> 8) & 0x1f) - 1,
-		(device >> 4) & 0x0f,
-		device & 0x0f, (device >> 12) & 0x0f, (device >> 8) & 0x0f);
-
-	pnp_add_id(dev, id);
-}
-
-/*
  *  Parse logical device tag.
  */
 static struct pnp_dev *__init isapnp_parse_device(struct pnp_card *card,
@@ -423,13 +405,17 @@
 {
 	unsigned char tmp[6];
 	struct pnp_dev *dev;
+	u32 eisa_id;
+	char id[8];
 
 	isapnp_peek(tmp, size);
 	dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL);
 	if (!dev)
 		return NULL;
 	dev->number = number;
-	isapnp_parse_id(dev, (tmp[1] << 8) | tmp[0], (tmp[3] << 8) | tmp[2]);
+	eisa_id = tmp[0] | tmp[1] << 8 | tmp[2] << 16 | tmp[3] << 24;
+	pnp_eisa_id_to_string(eisa_id, id);
+	pnp_add_id(dev, id);
 	dev->regs = tmp[4];
 	dev->card = card;
 	if (size > 5)
@@ -619,6 +605,8 @@
 	unsigned char type, tmp[17];
 	struct pnp_option *option;
 	struct pnp_dev *dev;
+	u32 eisa_id;
+	char id[8];
 
 	if ((dev = isapnp_parse_device(card, size, number++)) == NULL)
 		return 1;
@@ -658,8 +646,10 @@
 		case _STAG_COMPATDEVID:
 			if (size == 4 && compat < DEVICE_COUNT_COMPATIBLE) {
 				isapnp_peek(tmp, 4);
-				isapnp_parse_id(dev, (tmp[1] << 8) | tmp[0],
-						(tmp[3] << 8) | tmp[2]);
+				eisa_id = tmp[0] | tmp[1] << 8 |
+					  tmp[2] << 16 | tmp[3] << 24;
+				pnp_eisa_id_to_string(eisa_id, id);
+				pnp_add_id(dev, id);
 				compat++;
 				size = 0;
 			}
Index: work7/drivers/pnp/pnpbios/core.c
===================================================================
--- work7.orig/drivers/pnp/pnpbios/core.c	2008-04-02 10:22:28.000000000 -0600
+++ work7/drivers/pnp/pnpbios/core.c	2008-04-02 14:58:58.000000000 -0600
@@ -332,7 +332,7 @@
 	if (!dev)
 		return -1;
 
-	pnpid32_to_pnpid(node->eisa_id, id);
+	pnp_eisa_id_to_string(node->eisa_id & PNP_EISA_ID_MASK, id);
 	dev_id = pnp_add_id(dev, id);
 	if (!dev_id) {
 		kfree(dev);
Index: work7/drivers/pnp/pnpbios/rsparser.c
===================================================================
--- work7.orig/drivers/pnp/pnpbios/rsparser.c	2008-04-02 10:22:28.000000000 -0600
+++ work7/drivers/pnp/pnpbios/rsparser.c	2008-04-02 14:59:13.000000000 -0600
@@ -494,32 +494,12 @@
  * Compatible Device IDs
  */
 
-#define HEX(id,a) hex[((id)>>a) & 15]
-#define CHAR(id,a) (0x40 + (((id)>>a) & 31))
-
-void pnpid32_to_pnpid(u32 id, char *str)
-{
-	const char *hex = "0123456789abcdef";
-
-	id = be32_to_cpu(id);
-	str[0] = CHAR(id, 26);
-	str[1] = CHAR(id, 21);
-	str[2] = CHAR(id, 16);
-	str[3] = HEX(id, 12);
-	str[4] = HEX(id, 8);
-	str[5] = HEX(id, 4);
-	str[6] = HEX(id, 0);
-	str[7] = '\0';
-}
-
-#undef CHAR
-#undef HEX
-
 static unsigned char *pnpbios_parse_compatible_ids(unsigned char *p,
 						   unsigned char *end,
 						   struct pnp_dev *dev)
 {
 	int len, tag;
+	u32 eisa_id;
 	char id[8];
 	struct pnp_id *dev_id;
 
@@ -549,8 +529,8 @@
 		case SMALL_TAG_COMPATDEVID:	/* compatible ID */
 			if (len != 4)
 				goto len_err;
-			pnpid32_to_pnpid(p[1] | p[2] << 8 | p[3] << 16 | p[4] <<
-					 24, id);
+			eisa_id = p[1] | p[2] << 8 | p[3] << 16 | p[4] << 24;
+			pnp_eisa_id_to_string(eisa_id & PNP_EISA_ID_MASK, id);
 			dev_id = pnp_add_id(dev, id);
 			if (!dev_id)
 				return NULL;
Index: work7/drivers/pnp/support.c
===================================================================
--- work7.orig/drivers/pnp/support.c	2008-04-02 10:22:28.000000000 -0600
+++ work7/drivers/pnp/support.c	2008-04-02 14:53:13.000000000 -0600
@@ -25,3 +25,29 @@
 }
 
 EXPORT_SYMBOL(pnp_is_active);
+
+/*
+ * Functionally similar to acpi_ex_eisa_id_to_string(), but that's
+ * buried in the ACPI CA, and we can't depend on it being present.
+ */
+void pnp_eisa_id_to_string(u32 id, char *str)
+{
+	id = be32_to_cpu(id);
+
+	/*
+	 * According to the specs, the first three characters are five-bit
+	 * compressed ASCII, and the left-over high order bit should be zero.
+	 * However, the Linux ISAPNP code historically used six bits for the
+	 * first character, and there seem to be IDs that depend on that,
+	 * e.g., "nEC8241" in the Linux 8250_pnp serial driver and the
+	 * FreeBSD sys/pc98/cbus/sio_cbus.c driver.
+	 */
+	str[0] = 'A' + ((id >> 26) & 0x3f) - 1;
+	str[1] = 'A' + ((id >> 21) & 0x1f) - 1;
+	str[2] = 'A' + ((id >> 16) & 0x1f) - 1;
+	str[3] = hex_asc((id >> 12) & 0xf);
+	str[4] = hex_asc((id >>  8) & 0xf);
+	str[5] = hex_asc((id >>  4) & 0xf);
+	str[6] = hex_asc((id >>  0) & 0xf);
+	str[7] = '\0';
+}

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 06/53] PNP: add pnp_alloc_dev()
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (4 preceding siblings ...)
  2008-04-18 20:50 ` [patch 05/53] PNP: add pnp_eisa_id_to_string() Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 07/53] PNP: make pnp_add_card_id() internal to PNP core Bjorn Helgaas
                   ` (46 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, Rene Herman, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-alloc-dev --]
[-- Type: text/plain, Size: 5794 bytes --]

Add pnp_alloc_dev() to allocate a struct pnp_dev and fill in the
protocol, instance number, and initial PNP ID.  Now it is always
valid to use dev_printk() on any pnp_dev pointer.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: Rene Herman <rene.herman@gmail.com>

---
 drivers/pnp/base.h         |    1 +
 drivers/pnp/core.c         |   28 +++++++++++++++++++++++++---
 drivers/pnp/isapnp/core.c  |   11 +++++------
 drivers/pnp/pnpacpi/core.c |   19 +++----------------
 drivers/pnp/pnpbios/core.c |   15 +++------------
 5 files changed, 37 insertions(+), 37 deletions(-)

Index: work7/drivers/pnp/base.h
===================================================================
--- work7.orig/drivers/pnp/base.h	2008-04-02 14:59:50.000000000 -0600
+++ work7/drivers/pnp/base.h	2008-04-02 15:17:49.000000000 -0600
@@ -2,6 +2,7 @@
 void *pnp_alloc(long size);
 #define PNP_EISA_ID_MASK 0x7fffffff
 void pnp_eisa_id_to_string(u32 id, char *str);
+struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *, int id, char *pnpid);
 struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id);
 int pnp_interface_attach_device(struct pnp_dev *dev);
 void pnp_fixup_device(struct pnp_dev *dev);
Index: work7/drivers/pnp/core.c
===================================================================
--- work7.orig/drivers/pnp/core.c	2008-04-02 14:39:11.000000000 -0600
+++ work7/drivers/pnp/core.c	2008-04-02 15:17:49.000000000 -0600
@@ -109,6 +109,31 @@
 	kfree(dev);
 }
 
+struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *protocol, int id, char *pnpid)
+{
+	struct pnp_dev *dev;
+	struct pnp_id *dev_id;
+
+	dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL);
+	if (!dev)
+		return NULL;
+
+	dev->protocol = protocol;
+	dev->number = id;
+
+	dev->dev.parent = &dev->protocol->dev;
+	sprintf(dev->dev.bus_id, "%02x:%02x", dev->protocol->number,
+		dev->number);
+
+	dev_id = pnp_add_id(dev, pnpid);
+	if (!dev_id) {
+		kfree(dev);
+		return NULL;
+	}
+
+	return dev;
+}
+
 int __pnp_add_device(struct pnp_dev *dev)
 {
 	int ret;
@@ -145,9 +170,6 @@
 	if (dev->card)
 		return -EINVAL;
 
-	dev->dev.parent = &dev->protocol->dev;
-	sprintf(dev->dev.bus_id, "%02x:%02x", dev->protocol->number,
-		dev->number);
 	ret = __pnp_add_device(dev);
 	if (ret)
 		return ret;
Index: work7/drivers/pnp/isapnp/core.c
===================================================================
--- work7.orig/drivers/pnp/isapnp/core.c	2008-04-02 14:39:11.000000000 -0600
+++ work7/drivers/pnp/isapnp/core.c	2008-04-02 15:17:49.000000000 -0600
@@ -409,18 +409,17 @@
 	char id[8];
 
 	isapnp_peek(tmp, size);
-	dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL);
-	if (!dev)
-		return NULL;
-	dev->number = number;
 	eisa_id = tmp[0] | tmp[1] << 8 | tmp[2] << 16 | tmp[3] << 24;
 	pnp_eisa_id_to_string(eisa_id, id);
-	pnp_add_id(dev, id);
+
+	dev = pnp_alloc_dev(&isapnp_protocol, number, id);
+	if (!dev)
+		return NULL;
+
 	dev->regs = tmp[4];
 	dev->card = card;
 	if (size > 5)
 		dev->regs |= tmp[5] << 8;
-	dev->protocol = &isapnp_protocol;
 	dev->capabilities |= PNP_CONFIGURABLE;
 	dev->capabilities |= PNP_READ;
 	dev->capabilities |= PNP_WRITE;
Index: work7/drivers/pnp/pnpacpi/core.c
===================================================================
--- work7.orig/drivers/pnp/pnpacpi/core.c	2008-04-02 14:39:11.000000000 -0600
+++ work7/drivers/pnp/pnpacpi/core.c	2008-04-02 15:17:49.000000000 -0600
@@ -152,7 +152,6 @@
 {
 	acpi_handle temp = NULL;
 	acpi_status status;
-	struct pnp_id *dev_id;
 	struct pnp_dev *dev;
 
 	status = acpi_get_handle(device->handle, "_CRS", &temp);
@@ -160,11 +159,10 @@
 	    is_exclusive_device(device))
 		return 0;
 
-	dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL);
-	if (!dev) {
-		pnp_err("Out of memory");
+	dev = pnp_alloc_dev(&pnpacpi_protocol, num, acpi_device_hid(device));
+	if (!dev)
 		return -ENOMEM;
-	}
+
 	dev->data = device->handle;
 	/* .enabled means the device can decode the resources */
 	dev->active = device->status.enabled;
@@ -180,19 +178,11 @@
 	if (ACPI_SUCCESS(status))
 		dev->capabilities |= PNP_DISABLE;
 
-	dev->protocol = &pnpacpi_protocol;
-
 	if (strlen(acpi_device_name(device)))
 		strncpy(dev->name, acpi_device_name(device), sizeof(dev->name));
 	else
 		strncpy(dev->name, acpi_device_bid(device), sizeof(dev->name));
 
-	dev->number = num;
-
-	dev_id = pnp_add_id(dev, acpi_device_hid(device));
-	if (!dev_id)
-		goto err;
-
 	if (dev->active) {
 		/* parse allocated resource */
 		status = pnpacpi_parse_allocated_resource(device->handle,
@@ -230,9 +220,6 @@
 	num++;
 
 	return AE_OK;
-err:
-	kfree(dev);
-	return -EINVAL;
 }
 
 static acpi_status __init pnpacpi_add_device_handler(acpi_handle handle,
Index: work7/drivers/pnp/pnpbios/core.c
===================================================================
--- work7.orig/drivers/pnp/pnpbios/core.c	2008-04-02 14:58:58.000000000 -0600
+++ work7/drivers/pnp/pnpbios/core.c	2008-04-02 15:18:46.000000000 -0600
@@ -318,7 +318,6 @@
 {
 	struct list_head *pos;
 	struct pnp_dev *dev;
-	struct pnp_id *dev_id;
 	char id[8];
 
 	/* check if the device is already added */
@@ -328,18 +327,11 @@
 			return -1;
 	}
 
-	dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL);
-	if (!dev)
-		return -1;
-
 	pnp_eisa_id_to_string(node->eisa_id & PNP_EISA_ID_MASK, id);
-	dev_id = pnp_add_id(dev, id);
-	if (!dev_id) {
-		kfree(dev);
+	dev = pnp_alloc_dev(&pnpbios_protocol, node->handle, id);
+	if (!dev)
 		return -1;
-	}
 
-	dev->number = node->handle;
 	pnpbios_parse_data_stream(dev, node);
 	dev->active = pnp_is_active(dev);
 	dev->flags = node->flags;
@@ -352,7 +344,6 @@
 		dev->capabilities |= PNP_WRITE;
 	if (dev->flags & PNPBIOS_REMOVABLE)
 		dev->capabilities |= PNP_REMOVABLE;
-	dev->protocol = &pnpbios_protocol;
 
 	/* clear out the damaged flags */
 	if (!dev->active)

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 07/53] PNP: make pnp_add_card_id() internal to PNP core
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (5 preceding siblings ...)
  2008-04-18 20:50 ` [patch 06/53] PNP: add pnp_alloc_dev() Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 08/53] PNP: change pnp_add_card_id() to allocate its own pnp_id structures Bjorn Helgaas
                   ` (45 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, Rene Herman, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-make-pnp_add_card_id-internal-to-core --]
[-- Type: text/plain, Size: 2180 bytes --]

pnp_add_card_id() doesn't need to be exposed outside the PNP core, so
move the declaration to an internal header file.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: Rene Herman <rene.herman@gmail.com>

Index: work7/drivers/pnp/base.h
===================================================================
--- work7.orig/drivers/pnp/base.h	2008-04-02 15:17:49.000000000 -0600
+++ work7/drivers/pnp/base.h	2008-04-02 15:19:07.000000000 -0600
@@ -4,6 +4,7 @@
 void pnp_eisa_id_to_string(u32 id, char *str);
 struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *, int id, char *pnpid);
 struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id);
+int pnp_add_card_id(struct pnp_id *id, struct pnp_card *card);
 int pnp_interface_attach_device(struct pnp_dev *dev);
 void pnp_fixup_device(struct pnp_dev *dev);
 void pnp_free_option(struct pnp_option *option);
Index: work7/include/linux/pnp.h
===================================================================
--- work7.orig/include/linux/pnp.h	2008-04-02 14:39:11.000000000 -0600
+++ work7/include/linux/pnp.h	2008-04-02 15:19:07.000000000 -0600
@@ -371,7 +371,6 @@
 void pnp_remove_card(struct pnp_card *card);
 int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev);
 void pnp_remove_card_device(struct pnp_dev *dev);
-int pnp_add_card_id(struct pnp_id *id, struct pnp_card *card);
 struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink,
 					const char *id, struct pnp_dev *from);
 void pnp_release_card_device(struct pnp_dev *dev);
@@ -423,7 +422,6 @@
 static inline void pnp_remove_card(struct pnp_card *card) { }
 static inline int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev) { return -ENODEV; }
 static inline void pnp_remove_card_device(struct pnp_dev *dev) { }
-static inline int pnp_add_card_id(struct pnp_id *id, struct pnp_card *card) { return -ENODEV; }
 static inline struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink, const char *id, struct pnp_dev *from) { return NULL; }
 static inline void pnp_release_card_device(struct pnp_dev *dev) { }
 static inline int pnp_register_card_driver(struct pnp_card_driver *drv) { return -ENODEV; }

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 08/53] PNP: change pnp_add_card_id() to allocate its own pnp_id structures
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (6 preceding siblings ...)
  2008-04-18 20:50 ` [patch 07/53] PNP: make pnp_add_card_id() internal to PNP core Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 09/53] ISAPNP: pull pnp_add_card_id() out of isapnp_parse_card_id() Bjorn Helgaas
                   ` (44 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, Rene Herman, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-move-allocation-into-pnp_add_card_id --]
[-- Type: text/plain, Size: 3343 bytes --]

This moves some of the pnp_id knowledge out of the backends and into
the PNP core.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: Rene Herman <rene.herman@gmail.com>

Index: work7/drivers/pnp/base.h
===================================================================
--- work7.orig/drivers/pnp/base.h	2008-04-02 15:19:07.000000000 -0600
+++ work7/drivers/pnp/base.h	2008-04-02 15:19:10.000000000 -0600
@@ -4,7 +4,7 @@
 void pnp_eisa_id_to_string(u32 id, char *str);
 struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *, int id, char *pnpid);
 struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id);
-int pnp_add_card_id(struct pnp_id *id, struct pnp_card *card);
+struct pnp_id *pnp_add_card_id(struct pnp_card *card, char *id);
 int pnp_interface_attach_device(struct pnp_dev *dev);
 void pnp_fixup_device(struct pnp_dev *dev);
 void pnp_free_option(struct pnp_option *option);
Index: work7/drivers/pnp/card.c
===================================================================
--- work7.orig/drivers/pnp/card.c	2008-04-02 14:39:11.000000000 -0600
+++ work7/drivers/pnp/card.c	2008-04-02 15:19:10.000000000 -0600
@@ -5,6 +5,7 @@
  */
 
 #include <linux/module.h>
+#include <linux/ctype.h>
 #include <linux/slab.h>
 #include <linux/pnp.h>
 #include "base.h"
@@ -100,19 +101,33 @@
  * @id: pointer to a pnp_id structure
  * @card: pointer to the desired card
  */
-int pnp_add_card_id(struct pnp_id *id, struct pnp_card *card)
+struct pnp_id *pnp_add_card_id(struct pnp_card *card, char *id)
 {
-	struct pnp_id *ptr;
+	struct pnp_id *dev_id, *ptr;
 
-	id->next = NULL;
+	dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
+	if (!dev_id)
+		return NULL;
+
+	dev_id->id[0] = id[0];
+	dev_id->id[1] = id[1];
+	dev_id->id[2] = id[2];
+	dev_id->id[3] = tolower(id[3]);
+	dev_id->id[4] = tolower(id[4]);
+	dev_id->id[5] = tolower(id[5]);
+	dev_id->id[6] = tolower(id[6]);
+	dev_id->id[7] = '\0';
+
+	dev_id->next = NULL;
 	ptr = card->id;
 	while (ptr && ptr->next)
 		ptr = ptr->next;
 	if (ptr)
-		ptr->next = id;
+		ptr->next = dev_id;
 	else
-		card->id = id;
-	return 0;
+		card->id = dev_id;
+
+	return dev_id;
 }
 
 static void pnp_free_card_ids(struct pnp_card *card)
Index: work7/drivers/pnp/isapnp/core.c
===================================================================
--- work7.orig/drivers/pnp/isapnp/core.c	2008-04-02 15:17:49.000000000 -0600
+++ work7/drivers/pnp/isapnp/core.c	2008-04-02 15:19:10.000000000 -0600
@@ -822,17 +822,18 @@
 static void isapnp_parse_card_id(struct pnp_card *card, unsigned short vendor,
 				 unsigned short device)
 {
-	struct pnp_id *id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
+	char id[8];
 
-	if (!id)
-		return;
-	sprintf(id->id, "%c%c%c%x%x%x%x",
-		'A' + ((vendor >> 2) & 0x3f) - 1,
-		'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1,
-		'A' + ((vendor >> 8) & 0x1f) - 1,
-		(device >> 4) & 0x0f,
-		device & 0x0f, (device >> 12) & 0x0f, (device >> 8) & 0x0f);
-	pnp_add_card_id(id, card);
+	id[0] = 'A' + ((vendor >> 2) & 0x3f) - 1;
+	id[1] = 'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1;
+	id[2] = 'A' + ((vendor >> 8) & 0x1f) - 1;
+	id[3] = hex_asc((device >> 4) & 0x0f);
+	id[4] = hex_asc(device & 0x0f);
+	id[5] = hex_asc((device >> 12) & 0x0f);
+	id[6] = hex_asc((device >> 8) & 0x0f);
+	id[7] = '\0';
+
+	pnp_add_card_id(card, id);
 }
 
 /*

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 09/53] ISAPNP: pull pnp_add_card_id() out of isapnp_parse_card_id()
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (7 preceding siblings ...)
  2008-04-18 20:50 ` [patch 08/53] PNP: change pnp_add_card_id() to allocate its own pnp_id structures Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 10/53] PNP: add pnp_alloc_card() Bjorn Helgaas
                   ` (43 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, Rene Herman, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: isapnp-restructure-parse-card-id --]
[-- Type: text/plain, Size: 1859 bytes --]

Split the pnp_add_card_id() part from the PNPID conversion part so we
can move the initial add_id() into the pnp_card allocation.

This makes the PNPID conversion generic so we can use the same
one for both devices and cards.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: Rene Herman <rene.herman@gmail.com>

Index: work7/drivers/pnp/isapnp/core.c
===================================================================
--- work7.orig/drivers/pnp/isapnp/core.c	2008-04-02 10:25:58.000000000 -0600
+++ work7/drivers/pnp/isapnp/core.c	2008-04-02 10:27:00.000000000 -0600
@@ -817,26 +817,6 @@
 }
 
 /*
- *  Parse EISA id for ISA PnP card.
- */
-static void isapnp_parse_card_id(struct pnp_card *card, unsigned short vendor,
-				 unsigned short device)
-{
-	char id[8];
-
-	id[0] = 'A' + ((vendor >> 2) & 0x3f) - 1;
-	id[1] = 'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1;
-	id[2] = 'A' + ((vendor >> 8) & 0x1f) - 1;
-	id[3] = hex_asc((device >> 4) & 0x0f);
-	id[4] = hex_asc(device & 0x0f);
-	id[5] = hex_asc((device >> 12) & 0x0f);
-	id[6] = hex_asc((device >> 8) & 0x0f);
-	id[7] = '\0';
-
-	pnp_add_card_id(card, id);
-}
-
-/*
  *  Build device list for all present ISA PnP devices.
  */
 static int __init isapnp_build_device_list(void)
@@ -844,6 +824,8 @@
 	int csn;
 	unsigned char header[9], checksum;
 	struct pnp_card *card;
+	u32 eisa_id;
+	char id[8];
 
 	isapnp_wait();
 	isapnp_key();
@@ -864,8 +846,10 @@
 
 		card->number = csn;
 		INIT_LIST_HEAD(&card->devices);
-		isapnp_parse_card_id(card, (header[1] << 8) | header[0],
-				     (header[3] << 8) | header[2]);
+		eisa_id = header[0] | header[1] << 8 |
+			  header[2] << 16 | header[3] << 24;
+		pnp_eisa_id_to_string(eisa_id, id);
+		pnp_add_card_id(card, id);
 		card->serial =
 		    (header[7] << 24) | (header[6] << 16) | (header[5] << 8) |
 		    header[4];

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 10/53] PNP: add pnp_alloc_card()
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (8 preceding siblings ...)
  2008-04-18 20:50 ` [patch 09/53] ISAPNP: pull pnp_add_card_id() out of isapnp_parse_card_id() Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 11/53] PNPACPI: pnpacpi_encode_ext_irq() wrongly set "irq" instead of "extended_irq" Bjorn Helgaas
                   ` (42 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, Rene Herman, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-alloc-card --]
[-- Type: text/plain, Size: 3519 bytes --]

Add pnp_alloc_card() to allocate a struct pnp_card and fill in the
protocol, instance number, and initial PNP ID.  Now it is always
valid to use dev_printk() on any pnp_card pointer.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: Rene Herman <rene.herman@gmail.com>

---
 drivers/pnp/base.h        |    1 +
 drivers/pnp/card.c        |   28 +++++++++++++++++++++++++---
 drivers/pnp/isapnp/core.c |   11 ++++-------
 3 files changed, 30 insertions(+), 10 deletions(-)

Index: work7/drivers/pnp/base.h
===================================================================
--- work7.orig/drivers/pnp/base.h	2008-04-02 15:19:10.000000000 -0600
+++ work7/drivers/pnp/base.h	2008-04-02 15:19:13.000000000 -0600
@@ -3,6 +3,7 @@
 #define PNP_EISA_ID_MASK 0x7fffffff
 void pnp_eisa_id_to_string(u32 id, char *str);
 struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *, int id, char *pnpid);
+struct pnp_card *pnp_alloc_card(struct pnp_protocol *, int id, char *pnpid);
 struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id);
 struct pnp_id *pnp_add_card_id(struct pnp_card *card, char *id);
 int pnp_interface_attach_device(struct pnp_dev *dev);
Index: work7/drivers/pnp/card.c
===================================================================
--- work7.orig/drivers/pnp/card.c	2008-04-02 15:19:10.000000000 -0600
+++ work7/drivers/pnp/card.c	2008-04-02 15:19:13.000000000 -0600
@@ -151,6 +151,31 @@
 	kfree(card);
 }
 
+struct pnp_card *pnp_alloc_card(struct pnp_protocol *protocol, int id, char *pnpid)
+{
+	struct pnp_card *card;
+	struct pnp_id *dev_id;
+
+	card = kzalloc(sizeof(struct pnp_card), GFP_KERNEL);
+	if (!card)
+		return NULL;
+
+	card->protocol = protocol;
+	card->number = id;
+
+	card->dev.parent = &card->protocol->dev;
+	sprintf(card->dev.bus_id, "%02x:%02x", card->protocol->number,
+		card->number);
+
+	dev_id = pnp_add_card_id(card, pnpid);
+	if (!dev_id) {
+		kfree(card);
+		return NULL;
+	}
+
+	return card;
+}
+
 static ssize_t pnp_show_card_name(struct device *dmdev,
 				  struct device_attribute *attr, char *buf)
 {
@@ -206,9 +231,6 @@
 	int error;
 	struct list_head *pos, *temp;
 
-	sprintf(card->dev.bus_id, "%02x:%02x", card->protocol->number,
-		card->number);
-	card->dev.parent = &card->protocol->dev;
 	card->dev.bus = NULL;
 	card->dev.release = &pnp_release_card;
 	error = device_register(&card->dev);
Index: work7/drivers/pnp/isapnp/core.c
===================================================================
--- work7.orig/drivers/pnp/isapnp/core.c	2008-04-02 15:19:11.000000000 -0600
+++ work7/drivers/pnp/isapnp/core.c	2008-04-02 15:19:13.000000000 -0600
@@ -840,16 +840,14 @@
 		       header[5], header[6], header[7], header[8]);
 		printk(KERN_DEBUG "checksum = 0x%x\n", checksum);
 #endif
-		if ((card =
-		     kzalloc(sizeof(struct pnp_card), GFP_KERNEL)) == NULL)
-			continue;
-
-		card->number = csn;
-		INIT_LIST_HEAD(&card->devices);
 		eisa_id = header[0] | header[1] << 8 |
 			  header[2] << 16 | header[3] << 24;
 		pnp_eisa_id_to_string(eisa_id, id);
-		pnp_add_card_id(card, id);
+		card = pnp_alloc_card(&isapnp_protocol, csn, id);
+		if (!card)
+			continue;
+
+		INIT_LIST_HEAD(&card->devices);
 		card->serial =
 		    (header[7] << 24) | (header[6] << 16) | (header[5] << 8) |
 		    header[4];
@@ -860,7 +858,6 @@
 			       "isapnp: checksum for device %i is not valid (0x%x)\n",
 			       csn, isapnp_checksum_value);
 		card->checksum = isapnp_checksum_value;
-		card->protocol = &isapnp_protocol;
 
 		pnp_add_card(card);
 	}

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 11/53] PNPACPI: pnpacpi_encode_ext_irq() wrongly set "irq" instead of "extended_irq"
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (9 preceding siblings ...)
  2008-04-18 20:50 ` [patch 10/53] PNP: add pnp_alloc_card() Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 12/53] PNPACPI: use temporaries to reduce repetition Bjorn Helgaas
                   ` (41 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnpacpi-fix-encode-extended-irq --]
[-- Type: text/plain, Size: 1016 bytes --]

pnpacpi_encode_ext_irq() should set resource->data.extended_irq, not
resource->data.irq.

This has been wrong since at least 2.6.12.  I haven't seen any bug
reports, but it's clearly incorrect.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>

Index: work8/drivers/pnp/pnpacpi/rsparser.c
===================================================================
--- work8.orig/drivers/pnp/pnpacpi/rsparser.c	2008-04-10 12:26:08.000000000 -0600
+++ work8/drivers/pnp/pnpacpi/rsparser.c	2008-04-10 13:26:19.000000000 -0600
@@ -818,9 +818,9 @@
 	resource->data.extended_irq.triggering = triggering;
 	resource->data.extended_irq.polarity = polarity;
 	if (triggering == ACPI_EDGE_SENSITIVE)
-		resource->data.irq.sharable = ACPI_EXCLUSIVE;
+		resource->data.extended_irq.sharable = ACPI_EXCLUSIVE;
 	else
-		resource->data.irq.sharable = ACPI_SHARED;
+		resource->data.extended_irq.sharable = ACPI_SHARED;
 	resource->data.extended_irq.interrupt_count = 1;
 	resource->data.extended_irq.interrupts[0] = p->start;
 }

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 12/53] PNPACPI: use temporaries to reduce repetition
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (10 preceding siblings ...)
  2008-04-18 20:50 ` [patch 11/53] PNPACPI: pnpacpi_encode_ext_irq() wrongly set "irq" instead of "extended_irq" Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 13/53] PNPACPI: hoist dma_flags() out of pnpacpi_parse_allocated_dmaresource() Bjorn Helgaas
                   ` (40 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, Rene Herman, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnpacpi-use-acpi-resource-temporaries --]
[-- Type: text/plain, Size: 10751 bytes --]

No functional change, just fewer words and fewer chances for
transcription errors.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: Rene Herman <rene.herman@gmail.com>

Index: work7/drivers/pnp/pnpacpi/rsparser.c
===================================================================
--- work7.orig/drivers/pnp/pnpacpi/rsparser.c	2008-03-20 12:07:31.000000000 -0600
+++ work7/drivers/pnp/pnpacpi/rsparser.c	2008-03-20 12:14:54.000000000 -0600
@@ -278,6 +278,14 @@
 					      void *data)
 {
 	struct pnp_resource_table *res_table = data;
+	struct acpi_resource_irq *irq;
+	struct acpi_resource_dma *dma;
+	struct acpi_resource_io *io;
+	struct acpi_resource_fixed_io *fixed_io;
+	struct acpi_resource_memory24 *memory24;
+	struct acpi_resource_memory32 *memory32;
+	struct acpi_resource_fixed_memory32 *fixed_memory32;
+	struct acpi_resource_extended_irq *extended_irq;
 	int i;
 
 	switch (res->type) {
@@ -286,29 +294,32 @@
 		 * Per spec, only one interrupt per descriptor is allowed in
 		 * _CRS, but some firmware violates this, so parse them all.
 		 */
-		for (i = 0; i < res->data.irq.interrupt_count; i++) {
+		irq = &res->data.irq;
+		for (i = 0; i < irq->interrupt_count; i++) {
 			pnpacpi_parse_allocated_irqresource(res_table,
-				res->data.irq.interrupts[i],
-				res->data.irq.triggering,
-				res->data.irq.polarity,
-				res->data.irq.sharable);
+				irq->interrupts[i],
+				irq->triggering,
+				irq->polarity,
+				irq->sharable);
 		}
 		break;
 
 	case ACPI_RESOURCE_TYPE_DMA:
-		if (res->data.dma.channel_count > 0)
+		dma = &res->data.dma;
+		if (dma->channel_count > 0)
 			pnpacpi_parse_allocated_dmaresource(res_table,
-				res->data.dma.channels[0],
-				res->data.dma.type,
-				res->data.dma.bus_master,
-				res->data.dma.transfer);
+				dma->channels[0],
+				dma->type,
+				dma->bus_master,
+				dma->transfer);
 		break;
 
 	case ACPI_RESOURCE_TYPE_IO:
+		io = &res->data.io;
 		pnpacpi_parse_allocated_ioresource(res_table,
-			res->data.io.minimum,
-			res->data.io.address_length,
-			res->data.io.io_decode);
+			io->minimum,
+			io->address_length,
+			io->io_decode);
 		break;
 
 	case ACPI_RESOURCE_TYPE_START_DEPENDENT:
@@ -316,9 +327,10 @@
 		break;
 
 	case ACPI_RESOURCE_TYPE_FIXED_IO:
+		fixed_io = &res->data.fixed_io;
 		pnpacpi_parse_allocated_ioresource(res_table,
-			res->data.fixed_io.address,
-			res->data.fixed_io.address_length,
+			fixed_io->address,
+			fixed_io->address_length,
 			ACPI_DECODE_10);
 		break;
 
@@ -329,22 +341,25 @@
 		break;
 
 	case ACPI_RESOURCE_TYPE_MEMORY24:
+		memory24 = &res->data.memory24;
 		pnpacpi_parse_allocated_memresource(res_table,
-			res->data.memory24.minimum,
-			res->data.memory24.address_length,
-			res->data.memory24.write_protect);
+			memory24->minimum,
+			memory24->address_length,
+			memory24->write_protect);
 		break;
 	case ACPI_RESOURCE_TYPE_MEMORY32:
+		memory32 = &res->data.memory32;
 		pnpacpi_parse_allocated_memresource(res_table,
-			res->data.memory32.minimum,
-			res->data.memory32.address_length,
-			res->data.memory32.write_protect);
+			memory32->minimum,
+			memory32->address_length,
+			memory32->write_protect);
 		break;
 	case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
+		fixed_memory32 = &res->data.fixed_memory32;
 		pnpacpi_parse_allocated_memresource(res_table,
-			res->data.fixed_memory32.address,
-			res->data.fixed_memory32.address_length,
-			res->data.fixed_memory32.write_protect);
+			fixed_memory32->address,
+			fixed_memory32->address_length,
+			fixed_memory32->write_protect);
 		break;
 	case ACPI_RESOURCE_TYPE_ADDRESS16:
 	case ACPI_RESOURCE_TYPE_ADDRESS32:
@@ -358,15 +373,16 @@
 		break;
 
 	case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
-		if (res->data.extended_irq.producer_consumer == ACPI_PRODUCER)
+		extended_irq = &res->data.extended_irq;
+		if (extended_irq->producer_consumer == ACPI_PRODUCER)
 			return AE_OK;
 
-		for (i = 0; i < res->data.extended_irq.interrupt_count; i++) {
+		for (i = 0; i < extended_irq->interrupt_count; i++) {
 			pnpacpi_parse_allocated_irqresource(res_table,
-				res->data.extended_irq.interrupts[i],
-				res->data.extended_irq.triggering,
-				res->data.extended_irq.polarity,
-				res->data.extended_irq.sharable);
+				extended_irq->interrupts[i],
+				extended_irq->triggering,
+				extended_irq->polarity,
+				extended_irq->sharable);
 		}
 		break;
 
@@ -795,122 +811,136 @@
 static void pnpacpi_encode_irq(struct acpi_resource *resource,
 			       struct resource *p)
 {
+	struct acpi_resource_irq *irq = &resource->data.irq;
 	int triggering, polarity;
 
 	decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity);
-	resource->data.irq.triggering = triggering;
-	resource->data.irq.polarity = polarity;
+	irq->triggering = triggering;
+	irq->polarity = polarity;
 	if (triggering == ACPI_EDGE_SENSITIVE)
-		resource->data.irq.sharable = ACPI_EXCLUSIVE;
+		irq->sharable = ACPI_EXCLUSIVE;
 	else
-		resource->data.irq.sharable = ACPI_SHARED;
-	resource->data.irq.interrupt_count = 1;
-	resource->data.irq.interrupts[0] = p->start;
+		irq->sharable = ACPI_SHARED;
+	irq->interrupt_count = 1;
+	irq->interrupts[0] = p->start;
 }
 
 static void pnpacpi_encode_ext_irq(struct acpi_resource *resource,
 				   struct resource *p)
 {
+	struct acpi_resource_extended_irq *extended_irq = &resource->data.extended_irq;
 	int triggering, polarity;
 
 	decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity);
-	resource->data.extended_irq.producer_consumer = ACPI_CONSUMER;
-	resource->data.extended_irq.triggering = triggering;
-	resource->data.extended_irq.polarity = polarity;
+	extended_irq->producer_consumer = ACPI_CONSUMER;
+	extended_irq->triggering = triggering;
+	extended_irq->polarity = polarity;
 	if (triggering == ACPI_EDGE_SENSITIVE)
-		resource->data.extended_irq.sharable = ACPI_EXCLUSIVE;
+		extended_irq->sharable = ACPI_EXCLUSIVE;
 	else
-		resource->data.extended_irq.sharable = ACPI_SHARED;
-	resource->data.extended_irq.interrupt_count = 1;
-	resource->data.extended_irq.interrupts[0] = p->start;
+		extended_irq->sharable = ACPI_SHARED;
+	extended_irq->interrupt_count = 1;
+	extended_irq->interrupts[0] = p->start;
 }
 
 static void pnpacpi_encode_dma(struct acpi_resource *resource,
 			       struct resource *p)
 {
+	struct acpi_resource_dma *dma = &resource->data.dma;
+
 	/* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
 	switch (p->flags & IORESOURCE_DMA_SPEED_MASK) {
 	case IORESOURCE_DMA_TYPEA:
-		resource->data.dma.type = ACPI_TYPE_A;
+		dma->type = ACPI_TYPE_A;
 		break;
 	case IORESOURCE_DMA_TYPEB:
-		resource->data.dma.type = ACPI_TYPE_B;
+		dma->type = ACPI_TYPE_B;
 		break;
 	case IORESOURCE_DMA_TYPEF:
-		resource->data.dma.type = ACPI_TYPE_F;
+		dma->type = ACPI_TYPE_F;
 		break;
 	default:
-		resource->data.dma.type = ACPI_COMPATIBILITY;
+		dma->type = ACPI_COMPATIBILITY;
 	}
 
 	switch (p->flags & IORESOURCE_DMA_TYPE_MASK) {
 	case IORESOURCE_DMA_8BIT:
-		resource->data.dma.transfer = ACPI_TRANSFER_8;
+		dma->transfer = ACPI_TRANSFER_8;
 		break;
 	case IORESOURCE_DMA_8AND16BIT:
-		resource->data.dma.transfer = ACPI_TRANSFER_8_16;
+		dma->transfer = ACPI_TRANSFER_8_16;
 		break;
 	default:
-		resource->data.dma.transfer = ACPI_TRANSFER_16;
+		dma->transfer = ACPI_TRANSFER_16;
 	}
 
-	resource->data.dma.bus_master = !!(p->flags & IORESOURCE_DMA_MASTER);
-	resource->data.dma.channel_count = 1;
-	resource->data.dma.channels[0] = p->start;
+	dma->bus_master = !!(p->flags & IORESOURCE_DMA_MASTER);
+	dma->channel_count = 1;
+	dma->channels[0] = p->start;
 }
 
 static void pnpacpi_encode_io(struct acpi_resource *resource,
 			      struct resource *p)
 {
+	struct acpi_resource_io *io = &resource->data.io;
+
 	/* Note: pnp_assign_port will copy pnp_port->flags into p->flags */
-	resource->data.io.io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR) ?
+	io->io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR) ?
 	    ACPI_DECODE_16 : ACPI_DECODE_10;
-	resource->data.io.minimum = p->start;
-	resource->data.io.maximum = p->end;
-	resource->data.io.alignment = 0;	/* Correct? */
-	resource->data.io.address_length = p->end - p->start + 1;
+	io->minimum = p->start;
+	io->maximum = p->end;
+	io->alignment = 0;	/* Correct? */
+	io->address_length = p->end - p->start + 1;
 }
 
 static void pnpacpi_encode_fixed_io(struct acpi_resource *resource,
 				    struct resource *p)
 {
-	resource->data.fixed_io.address = p->start;
-	resource->data.fixed_io.address_length = p->end - p->start + 1;
+	struct acpi_resource_fixed_io *fixed_io = &resource->data.fixed_io;
+
+	fixed_io->address = p->start;
+	fixed_io->address_length = p->end - p->start + 1;
 }
 
 static void pnpacpi_encode_mem24(struct acpi_resource *resource,
 				 struct resource *p)
 {
+	struct acpi_resource_memory24 *memory24 = &resource->data.memory24;
+
 	/* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */
-	resource->data.memory24.write_protect =
+	memory24->write_protect =
 	    (p->flags & IORESOURCE_MEM_WRITEABLE) ?
 	    ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
-	resource->data.memory24.minimum = p->start;
-	resource->data.memory24.maximum = p->end;
-	resource->data.memory24.alignment = 0;
-	resource->data.memory24.address_length = p->end - p->start + 1;
+	memory24->minimum = p->start;
+	memory24->maximum = p->end;
+	memory24->alignment = 0;
+	memory24->address_length = p->end - p->start + 1;
 }
 
 static void pnpacpi_encode_mem32(struct acpi_resource *resource,
 				 struct resource *p)
 {
-	resource->data.memory32.write_protect =
+	struct acpi_resource_memory32 *memory32 = &resource->data.memory32;
+
+	memory32->write_protect =
 	    (p->flags & IORESOURCE_MEM_WRITEABLE) ?
 	    ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
-	resource->data.memory32.minimum = p->start;
-	resource->data.memory32.maximum = p->end;
-	resource->data.memory32.alignment = 0;
-	resource->data.memory32.address_length = p->end - p->start + 1;
+	memory32->minimum = p->start;
+	memory32->maximum = p->end;
+	memory32->alignment = 0;
+	memory32->address_length = p->end - p->start + 1;
 }
 
 static void pnpacpi_encode_fixed_mem32(struct acpi_resource *resource,
 				       struct resource *p)
 {
-	resource->data.fixed_memory32.write_protect =
+	struct acpi_resource_fixed_memory32 *fixed_memory32 = &resource->data.fixed_memory32;
+
+	fixed_memory32->write_protect =
 	    (p->flags & IORESOURCE_MEM_WRITEABLE) ?
 	    ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
-	resource->data.fixed_memory32.address = p->start;
-	resource->data.fixed_memory32.address_length = p->end - p->start + 1;
+	fixed_memory32->address = p->start;
+	fixed_memory32->address_length = p->end - p->start + 1;
 }
 
 int pnpacpi_encode_resources(struct pnp_resource_table *res_table,

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 13/53] PNPACPI: hoist dma_flags() out of pnpacpi_parse_allocated_dmaresource()
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (11 preceding siblings ...)
  2008-04-18 20:50 ` [patch 12/53] PNPACPI: use temporaries to reduce repetition Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 14/53] PNPACPI: extend irq_flags() to set IORESOURCE_IRQ_SHAREABLE when appropriate Bjorn Helgaas
                   ` (39 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, Rene Herman, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnpacpi-hoist-dma-flags --]
[-- Type: text/plain, Size: 1432 bytes --]

Hoist dma_flags() out of pnpacpi_parse_allocated_dmaresource() into its
caller.  This makes pnpacpi_parse_allocated_dmaresource() more similar
to pnpbios_parse_allocated_dmaresource().

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: Rene Herman <rene.herman@gmail.com>

Index: work7/drivers/pnp/pnpacpi/rsparser.c
===================================================================
--- work7.orig/drivers/pnp/pnpacpi/rsparser.c	2008-03-21 15:08:36.000000000 -0600
+++ work7/drivers/pnp/pnpacpi/rsparser.c	2008-03-21 15:10:22.000000000 -0600
@@ -167,8 +167,7 @@
 }
 
 static void pnpacpi_parse_allocated_dmaresource(struct pnp_resource_table *res,
-						u32 dma, int type,
-						int bus_master, int transfer)
+						u32 dma, int flags)
 {
 	int i = 0;
 	static unsigned char warned;
@@ -178,8 +177,7 @@
 		i++;
 	if (i < PNP_MAX_DMA) {
 		res->dma_resource[i].flags = IORESOURCE_DMA;	// Also clears _UNSET flag
-		res->dma_resource[i].flags |=
-		    dma_flags(type, bus_master, transfer);
+		res->dma_resource[i].flags |= flags;
 		if (dma == -1) {
 			res->dma_resource[i].flags |= IORESOURCE_DISABLED;
 			return;
@@ -309,9 +307,8 @@
 		if (dma->channel_count > 0)
 			pnpacpi_parse_allocated_dmaresource(res_table,
 				dma->channels[0],
-				dma->type,
-				dma->bus_master,
-				dma->transfer);
+				dma_flags(dma->type, dma->bus_master,
+					  dma->transfer));
 		break;
 
 	case ACPI_RESOURCE_TYPE_IO:

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 14/53] PNPACPI: extend irq_flags() to set IORESOURCE_IRQ_SHAREABLE when appropriate
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (12 preceding siblings ...)
  2008-04-18 20:50 ` [patch 13/53] PNPACPI: hoist dma_flags() out of pnpacpi_parse_allocated_dmaresource() Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 15/53] PNPACPI: pass pnp_dev instead of acpi_handle Bjorn Helgaas
                   ` (38 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, Rene Herman, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnpacpi-add-shareability-to-irq-flags --]
[-- Type: text/plain, Size: 2560 bytes --]

This simplifies IRQ resource parsing slightly by computing all the
IORESOURCE_IRQ_* flags at the same time.

This also keeps track of shareability information when parsing options
from _PRS.  Previously we ignored shareability in _PRS.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: Rene Herman <rene.herman@gmail.com>

Index: work7/drivers/pnp/pnpacpi/rsparser.c
===================================================================
--- work7.orig/drivers/pnp/pnpacpi/rsparser.c	2008-03-21 15:10:22.000000000 -0600
+++ work7/drivers/pnp/pnpacpi/rsparser.c	2008-03-21 15:10:23.000000000 -0600
@@ -32,19 +32,26 @@
 /*
  * Allocated Resources
  */
-static int irq_flags(int triggering, int polarity)
+static int irq_flags(int triggering, int polarity, int shareable)
 {
+	int flags;
+
 	if (triggering == ACPI_LEVEL_SENSITIVE) {
 		if (polarity == ACPI_ACTIVE_LOW)
-			return IORESOURCE_IRQ_LOWLEVEL;
+			flags = IORESOURCE_IRQ_LOWLEVEL;
 		else
-			return IORESOURCE_IRQ_HIGHLEVEL;
+			flags = IORESOURCE_IRQ_HIGHLEVEL;
 	} else {
 		if (polarity == ACPI_ACTIVE_LOW)
-			return IORESOURCE_IRQ_LOWEDGE;
+			flags = IORESOURCE_IRQ_LOWEDGE;
 		else
-			return IORESOURCE_IRQ_HIGHEDGE;
+			flags = IORESOURCE_IRQ_HIGHEDGE;
 	}
+
+	if (shareable)
+		flags |= IORESOURCE_IRQ_SHAREABLE;
+
+	return flags;
 }
 
 static void decode_irq_flags(int flag, int *triggering, int *polarity)
@@ -108,16 +115,13 @@
 	}
 
 	res->irq_resource[i].flags = IORESOURCE_IRQ;	// Also clears _UNSET flag
-	res->irq_resource[i].flags |= irq_flags(triggering, polarity);
+	res->irq_resource[i].flags |= irq_flags(triggering, polarity, shareable);
 	irq = acpi_register_gsi(gsi, triggering, polarity);
 	if (irq < 0) {
 		res->irq_resource[i].flags |= IORESOURCE_DISABLED;
 		return;
 	}
 
-	if (shareable)
-		res->irq_resource[i].flags |= IORESOURCE_IRQ_SHAREABLE;
-
 	res->irq_resource[i].start = irq;
 	res->irq_resource[i].end = irq;
 	pcibios_penalize_isa_irq(irq, 1);
@@ -439,7 +443,7 @@
 	for (i = 0; i < p->interrupt_count; i++)
 		if (p->interrupts[i])
 			__set_bit(p->interrupts[i], irq->map);
-	irq->flags = irq_flags(p->triggering, p->polarity);
+	irq->flags = irq_flags(p->triggering, p->polarity, p->sharable);
 
 	pnp_register_irq_resource(option, irq);
 }
@@ -459,7 +463,7 @@
 	for (i = 0; i < p->interrupt_count; i++)
 		if (p->interrupts[i])
 			__set_bit(p->interrupts[i], irq->map);
-	irq->flags = irq_flags(p->triggering, p->polarity);
+	irq->flags = irq_flags(p->triggering, p->polarity, p->sharable);
 
 	pnp_register_irq_resource(option, irq);
 }

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 15/53] PNPACPI: pass pnp_dev instead of acpi_handle
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (13 preceding siblings ...)
  2008-04-18 20:50 ` [patch 14/53] PNPACPI: extend irq_flags() to set IORESOURCE_IRQ_SHAREABLE when appropriate Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 16/53] PNP: remove pnp_resource_table from internal get/set interfaces Bjorn Helgaas
                   ` (37 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, Rene Herman, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnpacpi-use-pnp_dev --]
[-- Type: text/plain, Size: 2103 bytes --]

Pass the pnp_dev pointer when possible instead of the acpi_handle.
This allows better error messages and reduces the chance of error
in the caller.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: Rene Herman <rene.herman@gmail.com>

Index: work7/drivers/pnp/pnpacpi/core.c
===================================================================
--- work7.orig/drivers/pnp/pnpacpi/core.c	2008-03-21 15:35:05.000000000 -0600
+++ work7/drivers/pnp/pnpacpi/core.c	2008-03-21 15:36:00.000000000 -0600
@@ -88,10 +88,10 @@
 {
 	acpi_handle handle = dev->data;
 	struct acpi_buffer buffer;
-	int ret = 0;
+	int ret;
 	acpi_status status;
 
-	ret = pnpacpi_build_resource_template(handle, &buffer);
+	ret = pnpacpi_build_resource_template(dev, &buffer);
 	if (ret)
 		return ret;
 	ret = pnpacpi_encode_resources(res, &buffer);
Index: work7/drivers/pnp/pnpacpi/pnpacpi.h
===================================================================
--- work7.orig/drivers/pnp/pnpacpi/pnpacpi.h	2008-03-21 15:28:07.000000000 -0600
+++ work7/drivers/pnp/pnpacpi/pnpacpi.h	2008-03-21 15:36:00.000000000 -0600
@@ -8,5 +8,5 @@
 acpi_status pnpacpi_parse_allocated_resource(acpi_handle, struct pnp_resource_table*);
 acpi_status pnpacpi_parse_resource_option_data(acpi_handle, struct pnp_dev*);
 int pnpacpi_encode_resources(struct pnp_resource_table *, struct acpi_buffer *);
-int pnpacpi_build_resource_template(acpi_handle, struct acpi_buffer*);
+int pnpacpi_build_resource_template(struct pnp_dev *, struct acpi_buffer *);
 #endif
Index: work7/drivers/pnp/pnpacpi/rsparser.c
===================================================================
--- work7.orig/drivers/pnp/pnpacpi/rsparser.c	2008-03-21 15:35:59.000000000 -0600
+++ work7/drivers/pnp/pnpacpi/rsparser.c	2008-03-21 15:36:00.000000000 -0600
@@ -775,9 +775,10 @@
 	return AE_OK;
 }
 
-int pnpacpi_build_resource_template(acpi_handle handle,
+int pnpacpi_build_resource_template(struct pnp_dev *dev,
 				    struct acpi_buffer *buffer)
 {
+	acpi_handle handle = dev->data;
 	struct acpi_resource *resource;
 	int res_cnt = 0;
 	acpi_status status;

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 16/53] PNP: remove pnp_resource_table from internal get/set interfaces
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (14 preceding siblings ...)
  2008-04-18 20:50 ` [patch 15/53] PNPACPI: pass pnp_dev instead of acpi_handle Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 17/53] PNP: remove more pnp_resource_table arguments Bjorn Helgaas
                   ` (36 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, Rene Herman, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-remove-pnp_resource_table-args-from-get-set --]
[-- Type: text/plain, Size: 5424 bytes --]

When we call protocol->get() and protocol->set() methods, we currently
supply pointers to both the pnp_dev and the pnp_resource_table even
though the pnp_resource_table should always be the one associated with
the pnp_dev.

This removes the pnp_resource_table arguments to make it clear that
these methods only operate on the specified pnp_dev.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: Rene Herman <rene.herman@gmail.com>

---
 include/linux/pnp.h        |    4 ++--
 drivers/pnp/interface.c    |    2 +-
 drivers/pnp/manager.c      |    2 +-
 drivers/pnp/isapnp/core.c  |   11 +++++------
 drivers/pnp/pnpacpi/core.c |    8 +++-----
 drivers/pnp/pnpbios/core.c |   10 ++++------
 6 files changed, 16 insertions(+), 21 deletions(-)

Index: work7/include/linux/pnp.h
===================================================================
--- work7.orig/include/linux/pnp.h	2008-03-31 17:07:19.000000000 -0600
+++ work7/include/linux/pnp.h	2008-03-31 17:10:39.000000000 -0600
@@ -328,8 +328,8 @@
 	char *name;
 
 	/* resource control functions */
-	int (*get) (struct pnp_dev *dev, struct pnp_resource_table *res);
-	int (*set) (struct pnp_dev *dev, struct pnp_resource_table *res);
+	int (*get) (struct pnp_dev *dev);
+	int (*set) (struct pnp_dev *dev);
 	int (*disable) (struct pnp_dev *dev);
 
 	/* protocol specific suspend/resume */
Index: work7/drivers/pnp/interface.c
===================================================================
--- work7.orig/drivers/pnp/interface.c	2008-03-31 16:59:07.000000000 -0600
+++ work7/drivers/pnp/interface.c	2008-03-31 17:10:39.000000000 -0600
@@ -364,7 +364,7 @@
 	if (!strnicmp(buf, "get", 3)) {
 		mutex_lock(&pnp_res_mutex);
 		if (pnp_can_read(dev))
-			dev->protocol->get(dev, &dev->res);
+			dev->protocol->get(dev);
 		mutex_unlock(&pnp_res_mutex);
 		goto done;
 	}
Index: work7/drivers/pnp/manager.c
===================================================================
--- work7.orig/drivers/pnp/manager.c	2008-03-31 16:59:07.000000000 -0600
+++ work7/drivers/pnp/manager.c	2008-03-31 17:10:39.000000000 -0600
@@ -473,7 +473,7 @@
 		return -EINVAL;
 	}
 
-	if (dev->protocol->set(dev, &dev->res) < 0) {
+	if (dev->protocol->set(dev) < 0) {
 		dev_err(&dev->dev, "activation failed\n");
 		return -EIO;
 	}
Index: work7/drivers/pnp/isapnp/core.c
===================================================================
--- work7.orig/drivers/pnp/isapnp/core.c	2008-03-31 17:10:26.000000000 -0600
+++ work7/drivers/pnp/isapnp/core.c	2008-03-31 17:10:39.000000000 -0600
@@ -968,21 +968,20 @@
 	return 0;
 }
 
-static int isapnp_get_resources(struct pnp_dev *dev,
-				struct pnp_resource_table *res)
+static int isapnp_get_resources(struct pnp_dev *dev)
 {
 	int ret;
 
-	pnp_init_resource_table(res);
+	pnp_init_resource_table(&dev->res);
 	isapnp_cfg_begin(dev->card->number, dev->number);
-	ret = isapnp_read_resources(dev, res);
+	ret = isapnp_read_resources(dev, &dev->res);
 	isapnp_cfg_end();
 	return ret;
 }
 
-static int isapnp_set_resources(struct pnp_dev *dev,
-				struct pnp_resource_table *res)
+static int isapnp_set_resources(struct pnp_dev *dev)
 {
+	struct pnp_resource_table *res = &dev->res;
 	int tmp;
 
 	isapnp_cfg_begin(dev->card->number, dev->number);
Index: work7/drivers/pnp/pnpacpi/core.c
===================================================================
--- work7.orig/drivers/pnp/pnpacpi/core.c	2008-03-31 17:10:38.000000000 -0600
+++ work7/drivers/pnp/pnpacpi/core.c	2008-03-31 17:10:39.000000000 -0600
@@ -73,8 +73,7 @@
 	return 1;
 }
 
-static int pnpacpi_get_resources(struct pnp_dev *dev,
-				 struct pnp_resource_table *res)
+static int pnpacpi_get_resources(struct pnp_dev *dev)
 {
 	acpi_status status;
 
@@ -83,8 +82,7 @@
 	return ACPI_FAILURE(status) ? -ENODEV : 0;
 }
 
-static int pnpacpi_set_resources(struct pnp_dev *dev,
-				 struct pnp_resource_table *res)
+static int pnpacpi_set_resources(struct pnp_dev *dev)
 {
 	acpi_handle handle = dev->data;
 	struct acpi_buffer buffer;
@@ -94,7 +92,7 @@
 	ret = pnpacpi_build_resource_template(dev, &buffer);
 	if (ret)
 		return ret;
-	ret = pnpacpi_encode_resources(res, &buffer);
+	ret = pnpacpi_encode_resources(&dev->res, &buffer);
 	if (ret) {
 		kfree(buffer.pointer);
 		return ret;
Index: work7/drivers/pnp/pnpbios/core.c
===================================================================
--- work7.orig/drivers/pnp/pnpbios/core.c	2008-03-31 17:05:32.000000000 -0600
+++ work7/drivers/pnp/pnpbios/core.c	2008-03-31 17:10:39.000000000 -0600
@@ -204,8 +204,7 @@
 
 #endif				/* CONFIG_HOTPLUG */
 
-static int pnpbios_get_resources(struct pnp_dev *dev,
-				 struct pnp_resource_table *res)
+static int pnpbios_get_resources(struct pnp_dev *dev)
 {
 	u8 nodenum = dev->number;
 	struct pnp_bios_node *node;
@@ -220,14 +219,13 @@
 		kfree(node);
 		return -ENODEV;
 	}
-	pnpbios_read_resources_from_node(res, node);
+	pnpbios_read_resources_from_node(&dev->res, node);
 	dev->active = pnp_is_active(dev);
 	kfree(node);
 	return 0;
 }
 
-static int pnpbios_set_resources(struct pnp_dev *dev,
-				 struct pnp_resource_table *res)
+static int pnpbios_set_resources(struct pnp_dev *dev)
 {
 	u8 nodenum = dev->number;
 	struct pnp_bios_node *node;
@@ -243,7 +241,7 @@
 		kfree(node);
 		return -ENODEV;
 	}
-	if (pnpbios_write_resources_to_node(res, node) < 0) {
+	if (pnpbios_write_resources_to_node(&dev->res, node) < 0) {
 		kfree(node);
 		return -1;
 	}

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 17/53] PNP: remove more pnp_resource_table arguments
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (15 preceding siblings ...)
  2008-04-18 20:50 ` [patch 16/53] PNP: remove pnp_resource_table from internal get/set interfaces Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 18/53] PNP: add pnp_init_resources(struct pnp_dev *) interface Bjorn Helgaas
                   ` (35 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, Rene Herman, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-remove-more-pnp_resource_table-args --]
[-- Type: text/plain, Size: 17537 bytes --]

Stop passing around struct pnp_resource_table pointers.  In most cases,
the caller doesn't need to know how the resources are stored inside
the struct pnp_dev.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: Rene Herman <rene.herman@gmail.com>

---
 drivers/pnp/isapnp/core.c      |    6 ++--
 drivers/pnp/pnpacpi/core.c     |   11 ++-----
 drivers/pnp/pnpacpi/pnpacpi.h  |    6 ++--
 drivers/pnp/pnpacpi/rsparser.c |   55 +++++++++++++++++++++-----------------
 drivers/pnp/pnpbios/core.c     |    4 +-
 drivers/pnp/pnpbios/pnpbios.h  |    4 +-
 drivers/pnp/pnpbios/rsparser.c |   58 ++++++++++++++++++++---------------------
 7 files changed, 73 insertions(+), 71 deletions(-)

Index: work7/drivers/pnp/isapnp/core.c
===================================================================
--- work7.orig/drivers/pnp/isapnp/core.c	2008-03-31 17:10:39.000000000 -0600
+++ work7/drivers/pnp/isapnp/core.c	2008-03-31 17:10:45.000000000 -0600
@@ -924,9 +924,9 @@
 EXPORT_SYMBOL(isapnp_cfg_end);
 EXPORT_SYMBOL(isapnp_write_byte);
 
-static int isapnp_read_resources(struct pnp_dev *dev,
-				 struct pnp_resource_table *res)
+static int isapnp_read_resources(struct pnp_dev *dev)
 {
+	struct pnp_resource_table *res = &dev->res;
 	int tmp, ret;
 
 	dev->active = isapnp_read_byte(ISAPNP_CFG_ACTIVATE);
@@ -974,7 +974,7 @@
 
 	pnp_init_resource_table(&dev->res);
 	isapnp_cfg_begin(dev->card->number, dev->number);
-	ret = isapnp_read_resources(dev, &dev->res);
+	ret = isapnp_read_resources(dev);
 	isapnp_cfg_end();
 	return ret;
 }
Index: work7/drivers/pnp/pnpacpi/core.c
===================================================================
--- work7.orig/drivers/pnp/pnpacpi/core.c	2008-03-31 17:10:39.000000000 -0600
+++ work7/drivers/pnp/pnpacpi/core.c	2008-03-31 17:10:45.000000000 -0600
@@ -77,8 +77,7 @@
 {
 	acpi_status status;
 
-	status = pnpacpi_parse_allocated_resource((acpi_handle) dev->data,
-						  &dev->res);
+	status = pnpacpi_parse_allocated_resource(dev);
 	return ACPI_FAILURE(status) ? -ENODEV : 0;
 }
 
@@ -92,7 +91,7 @@
 	ret = pnpacpi_build_resource_template(dev, &buffer);
 	if (ret)
 		return ret;
-	ret = pnpacpi_encode_resources(&dev->res, &buffer);
+	ret = pnpacpi_encode_resources(dev, &buffer);
 	if (ret) {
 		kfree(buffer.pointer);
 		return ret;
@@ -183,8 +182,7 @@
 
 	if (dev->active) {
 		/* parse allocated resource */
-		status = pnpacpi_parse_allocated_resource(device->handle,
-							  &dev->res);
+		status = pnpacpi_parse_allocated_resource(dev);
 		if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
 			pnp_err("PnPACPI: METHOD_NAME__CRS failure for %s",
 				acpi_device_hid(device));
@@ -192,8 +190,7 @@
 	}
 
 	if (dev->capabilities & PNP_CONFIGURABLE) {
-		status = pnpacpi_parse_resource_option_data(device->handle,
-							    dev);
+		status = pnpacpi_parse_resource_option_data(dev);
 		if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
 			pnp_err("PnPACPI: METHOD_NAME__PRS failure for %s",
 				acpi_device_hid(device));
Index: work7/drivers/pnp/pnpacpi/pnpacpi.h
===================================================================
--- work7.orig/drivers/pnp/pnpacpi/pnpacpi.h	2008-03-31 17:10:38.000000000 -0600
+++ work7/drivers/pnp/pnpacpi/pnpacpi.h	2008-03-31 17:10:45.000000000 -0600
@@ -5,8 +5,8 @@
 #include <linux/acpi.h>
 #include <linux/pnp.h>
 
-acpi_status pnpacpi_parse_allocated_resource(acpi_handle, struct pnp_resource_table*);
-acpi_status pnpacpi_parse_resource_option_data(acpi_handle, struct pnp_dev*);
-int pnpacpi_encode_resources(struct pnp_resource_table *, struct acpi_buffer *);
+acpi_status pnpacpi_parse_allocated_resource(struct pnp_dev *);
+acpi_status pnpacpi_parse_resource_option_data(struct pnp_dev *);
+int pnpacpi_encode_resources(struct pnp_dev *, struct acpi_buffer *);
 int pnpacpi_build_resource_template(struct pnp_dev *, struct acpi_buffer *);
 #endif
Index: work7/drivers/pnp/pnpacpi/rsparser.c
===================================================================
--- work7.orig/drivers/pnp/pnpacpi/rsparser.c	2008-03-31 17:10:38.000000000 -0600
+++ work7/drivers/pnp/pnpacpi/rsparser.c	2008-03-31 17:10:45.000000000 -0600
@@ -76,10 +76,11 @@
 	}
 }
 
-static void pnpacpi_parse_allocated_irqresource(struct pnp_resource_table *res,
+static void pnpacpi_parse_allocated_irqresource(struct pnp_dev *dev,
 						u32 gsi, int triggering,
 						int polarity, int shareable)
 {
+	struct pnp_resource_table *res = &dev->res;
 	int i = 0;
 	int irq;
 	int p, t;
@@ -170,9 +171,10 @@
 	return flags;
 }
 
-static void pnpacpi_parse_allocated_dmaresource(struct pnp_resource_table *res,
+static void pnpacpi_parse_allocated_dmaresource(struct pnp_dev *dev,
 						u32 dma, int flags)
 {
+	struct pnp_resource_table *res = &dev->res;
 	int i = 0;
 	static unsigned char warned;
 
@@ -195,9 +197,10 @@
 	}
 }
 
-static void pnpacpi_parse_allocated_ioresource(struct pnp_resource_table *res,
+static void pnpacpi_parse_allocated_ioresource(struct pnp_dev *dev,
 					       u64 io, u64 len, int io_decode)
 {
+	struct pnp_resource_table *res = &dev->res;
 	int i = 0;
 	static unsigned char warned;
 
@@ -221,10 +224,11 @@
 	}
 }
 
-static void pnpacpi_parse_allocated_memresource(struct pnp_resource_table *res,
+static void pnpacpi_parse_allocated_memresource(struct pnp_dev *dev,
 						u64 mem, u64 len,
 						int write_protect)
 {
+	struct pnp_resource_table *res = &dev->res;
 	int i = 0;
 	static unsigned char warned;
 
@@ -249,7 +253,7 @@
 	}
 }
 
-static void pnpacpi_parse_allocated_address_space(struct pnp_resource_table *res_table,
+static void pnpacpi_parse_allocated_address_space(struct pnp_dev *dev,
 						  struct acpi_resource *res)
 {
 	struct acpi_resource_address64 addr, *p = &addr;
@@ -266,11 +270,11 @@
 		return;
 
 	if (p->resource_type == ACPI_MEMORY_RANGE)
-		pnpacpi_parse_allocated_memresource(res_table,
+		pnpacpi_parse_allocated_memresource(dev,
 			p->minimum, p->address_length,
 			p->info.mem.write_protect);
 	else if (p->resource_type == ACPI_IO_RANGE)
-		pnpacpi_parse_allocated_ioresource(res_table,
+		pnpacpi_parse_allocated_ioresource(dev,
 			p->minimum, p->address_length,
 			p->granularity == 0xfff ? ACPI_DECODE_10 :
 				ACPI_DECODE_16);
@@ -279,7 +283,7 @@
 static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
 					      void *data)
 {
-	struct pnp_resource_table *res_table = data;
+	struct pnp_dev *dev = data;
 	struct acpi_resource_irq *irq;
 	struct acpi_resource_dma *dma;
 	struct acpi_resource_io *io;
@@ -298,7 +302,7 @@
 		 */
 		irq = &res->data.irq;
 		for (i = 0; i < irq->interrupt_count; i++) {
-			pnpacpi_parse_allocated_irqresource(res_table,
+			pnpacpi_parse_allocated_irqresource(dev,
 				irq->interrupts[i],
 				irq->triggering,
 				irq->polarity,
@@ -309,7 +313,7 @@
 	case ACPI_RESOURCE_TYPE_DMA:
 		dma = &res->data.dma;
 		if (dma->channel_count > 0)
-			pnpacpi_parse_allocated_dmaresource(res_table,
+			pnpacpi_parse_allocated_dmaresource(dev,
 				dma->channels[0],
 				dma_flags(dma->type, dma->bus_master,
 					  dma->transfer));
@@ -317,7 +321,7 @@
 
 	case ACPI_RESOURCE_TYPE_IO:
 		io = &res->data.io;
-		pnpacpi_parse_allocated_ioresource(res_table,
+		pnpacpi_parse_allocated_ioresource(dev,
 			io->minimum,
 			io->address_length,
 			io->io_decode);
@@ -329,7 +333,7 @@
 
 	case ACPI_RESOURCE_TYPE_FIXED_IO:
 		fixed_io = &res->data.fixed_io;
-		pnpacpi_parse_allocated_ioresource(res_table,
+		pnpacpi_parse_allocated_ioresource(dev,
 			fixed_io->address,
 			fixed_io->address_length,
 			ACPI_DECODE_10);
@@ -343,21 +347,21 @@
 
 	case ACPI_RESOURCE_TYPE_MEMORY24:
 		memory24 = &res->data.memory24;
-		pnpacpi_parse_allocated_memresource(res_table,
+		pnpacpi_parse_allocated_memresource(dev,
 			memory24->minimum,
 			memory24->address_length,
 			memory24->write_protect);
 		break;
 	case ACPI_RESOURCE_TYPE_MEMORY32:
 		memory32 = &res->data.memory32;
-		pnpacpi_parse_allocated_memresource(res_table,
+		pnpacpi_parse_allocated_memresource(dev,
 			memory32->minimum,
 			memory32->address_length,
 			memory32->write_protect);
 		break;
 	case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
 		fixed_memory32 = &res->data.fixed_memory32;
-		pnpacpi_parse_allocated_memresource(res_table,
+		pnpacpi_parse_allocated_memresource(dev,
 			fixed_memory32->address,
 			fixed_memory32->address_length,
 			fixed_memory32->write_protect);
@@ -365,7 +369,7 @@
 	case ACPI_RESOURCE_TYPE_ADDRESS16:
 	case ACPI_RESOURCE_TYPE_ADDRESS32:
 	case ACPI_RESOURCE_TYPE_ADDRESS64:
-		pnpacpi_parse_allocated_address_space(res_table, res);
+		pnpacpi_parse_allocated_address_space(dev, res);
 		break;
 
 	case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
@@ -379,7 +383,7 @@
 			return AE_OK;
 
 		for (i = 0; i < extended_irq->interrupt_count; i++) {
-			pnpacpi_parse_allocated_irqresource(res_table,
+			pnpacpi_parse_allocated_irqresource(dev,
 				extended_irq->interrupts[i],
 				extended_irq->triggering,
 				extended_irq->polarity,
@@ -398,14 +402,15 @@
 	return AE_OK;
 }
 
-acpi_status pnpacpi_parse_allocated_resource(acpi_handle handle,
-					     struct pnp_resource_table * res)
+acpi_status pnpacpi_parse_allocated_resource(struct pnp_dev *dev)
 {
+	acpi_handle handle = dev->data;
+
 	/* Blank the resource table values */
-	pnp_init_resource_table(res);
+	pnp_init_resource_table(&dev->res);
 
 	return acpi_walk_resources(handle, METHOD_NAME__CRS,
-				   pnpacpi_allocated_resource, res);
+				   pnpacpi_allocated_resource, dev);
 }
 
 static __init void pnpacpi_parse_dma_option(struct pnp_option *option,
@@ -713,9 +718,9 @@
 	return AE_OK;
 }
 
-acpi_status __init pnpacpi_parse_resource_option_data(acpi_handle handle,
-						      struct pnp_dev *dev)
+acpi_status __init pnpacpi_parse_resource_option_data(struct pnp_dev *dev)
 {
+	acpi_handle handle = dev->data;
 	acpi_status status;
 	struct acpipnp_parse_option_s parse_data;
 
@@ -945,9 +950,9 @@
 	fixed_memory32->address_length = p->end - p->start + 1;
 }
 
-int pnpacpi_encode_resources(struct pnp_resource_table *res_table,
-			     struct acpi_buffer *buffer)
+int pnpacpi_encode_resources(struct pnp_dev *dev, struct acpi_buffer *buffer)
 {
+	struct pnp_resource_table *res_table = &dev->res;
 	int i = 0;
 	/* pnpacpi_build_resource_template allocates extra mem */
 	int res_cnt = (buffer->length - 1) / sizeof(struct acpi_resource) - 1;
Index: work7/drivers/pnp/pnpbios/core.c
===================================================================
--- work7.orig/drivers/pnp/pnpbios/core.c	2008-03-31 17:10:39.000000000 -0600
+++ work7/drivers/pnp/pnpbios/core.c	2008-03-31 17:10:45.000000000 -0600
@@ -219,7 +219,7 @@
 		kfree(node);
 		return -ENODEV;
 	}
-	pnpbios_read_resources_from_node(&dev->res, node);
+	pnpbios_read_resources_from_node(dev, node);
 	dev->active = pnp_is_active(dev);
 	kfree(node);
 	return 0;
@@ -241,7 +241,7 @@
 		kfree(node);
 		return -ENODEV;
 	}
-	if (pnpbios_write_resources_to_node(&dev->res, node) < 0) {
+	if (pnpbios_write_resources_to_node(dev, node) < 0) {
 		kfree(node);
 		return -1;
 	}
Index: work7/drivers/pnp/pnpbios/pnpbios.h
===================================================================
--- work7.orig/drivers/pnp/pnpbios/pnpbios.h	2008-03-31 16:59:07.000000000 -0600
+++ work7/drivers/pnp/pnpbios/pnpbios.h	2008-03-31 17:10:45.000000000 -0600
@@ -28,8 +28,8 @@
 extern int  pnpbios_dont_use_current_config;
 
 extern int pnpbios_parse_data_stream(struct pnp_dev *dev, struct pnp_bios_node * node);
-extern int pnpbios_read_resources_from_node(struct pnp_resource_table *res, struct pnp_bios_node * node);
-extern int pnpbios_write_resources_to_node(struct pnp_resource_table *res, struct pnp_bios_node * node);
+extern int pnpbios_read_resources_from_node(struct pnp_dev *dev, struct pnp_bios_node *node);
+extern int pnpbios_write_resources_to_node(struct pnp_dev *dev, struct pnp_bios_node *node);
 extern void pnpid32_to_pnpid(u32 id, char *str);
 
 extern void pnpbios_print_status(const char * module, u16 status);
Index: work7/drivers/pnp/pnpbios/rsparser.c
===================================================================
--- work7.orig/drivers/pnp/pnpbios/rsparser.c	2008-03-31 16:59:07.000000000 -0600
+++ work7/drivers/pnp/pnpbios/rsparser.c	2008-03-31 17:10:45.000000000 -0600
@@ -54,9 +54,9 @@
  * Allocated Resources
  */
 
-static void pnpbios_parse_allocated_irqresource(struct pnp_resource_table *res,
-						int irq)
+static void pnpbios_parse_allocated_irqresource(struct pnp_dev *dev, int irq)
 {
+	struct pnp_resource_table *res = &dev->res;
 	int i = 0;
 
 	while (!(res->irq_resource[i].flags & IORESOURCE_UNSET)
@@ -74,9 +74,9 @@
 	}
 }
 
-static void pnpbios_parse_allocated_dmaresource(struct pnp_resource_table *res,
-						int dma)
+static void pnpbios_parse_allocated_dmaresource(struct pnp_dev *dev, int dma)
 {
+	struct pnp_resource_table *res = &dev->res;
 	int i = 0;
 
 	while (i < PNP_MAX_DMA &&
@@ -93,9 +93,10 @@
 	}
 }
 
-static void pnpbios_parse_allocated_ioresource(struct pnp_resource_table *res,
+static void pnpbios_parse_allocated_ioresource(struct pnp_dev *dev,
 					       int io, int len)
 {
+	struct pnp_resource_table *res = &dev->res;
 	int i = 0;
 
 	while (!(res->port_resource[i].flags & IORESOURCE_UNSET)
@@ -112,9 +113,10 @@
 	}
 }
 
-static void pnpbios_parse_allocated_memresource(struct pnp_resource_table *res,
+static void pnpbios_parse_allocated_memresource(struct pnp_dev *dev,
 						int mem, int len)
 {
+	struct pnp_resource_table *res = &dev->res;
 	int i = 0;
 
 	while (!(res->mem_resource[i].flags & IORESOURCE_UNSET)
@@ -131,11 +133,9 @@
 	}
 }
 
-static unsigned char *pnpbios_parse_allocated_resource_data(unsigned char *p,
-							    unsigned char *end,
-							    struct
-							    pnp_resource_table
-							    *res)
+static unsigned char *pnpbios_parse_allocated_resource_data(struct pnp_dev *dev,
+							    unsigned char *p,
+							    unsigned char *end)
 {
 	unsigned int len, tag;
 	int io, size, mask, i;
@@ -144,7 +144,7 @@
 		return NULL;
 
 	/* Blank the resource table values */
-	pnp_init_resource_table(res);
+	pnp_init_resource_table(&dev->res);
 
 	while ((char *)p < (char *)end) {
 
@@ -164,7 +164,7 @@
 				goto len_err;
 			io = *(short *)&p[4];
 			size = *(short *)&p[10];
-			pnpbios_parse_allocated_memresource(res, io, size);
+			pnpbios_parse_allocated_memresource(dev, io, size);
 			break;
 
 		case LARGE_TAG_ANSISTR:
@@ -180,7 +180,7 @@
 				goto len_err;
 			io = *(int *)&p[4];
 			size = *(int *)&p[16];
-			pnpbios_parse_allocated_memresource(res, io, size);
+			pnpbios_parse_allocated_memresource(dev, io, size);
 			break;
 
 		case LARGE_TAG_FIXEDMEM32:
@@ -188,7 +188,7 @@
 				goto len_err;
 			io = *(int *)&p[4];
 			size = *(int *)&p[8];
-			pnpbios_parse_allocated_memresource(res, io, size);
+			pnpbios_parse_allocated_memresource(dev, io, size);
 			break;
 
 		case SMALL_TAG_IRQ:
@@ -199,7 +199,7 @@
 			for (i = 0; i < 16; i++, mask = mask >> 1)
 				if (mask & 0x01)
 					io = i;
-			pnpbios_parse_allocated_irqresource(res, io);
+			pnpbios_parse_allocated_irqresource(dev, io);
 			break;
 
 		case SMALL_TAG_DMA:
@@ -210,7 +210,7 @@
 			for (i = 0; i < 8; i++, mask = mask >> 1)
 				if (mask & 0x01)
 					io = i;
-			pnpbios_parse_allocated_dmaresource(res, io);
+			pnpbios_parse_allocated_dmaresource(dev, io);
 			break;
 
 		case SMALL_TAG_PORT:
@@ -218,7 +218,7 @@
 				goto len_err;
 			io = p[2] + p[3] * 256;
 			size = p[7];
-			pnpbios_parse_allocated_ioresource(res, io, size);
+			pnpbios_parse_allocated_ioresource(dev, io, size);
 			break;
 
 		case SMALL_TAG_VENDOR:
@@ -230,7 +230,7 @@
 				goto len_err;
 			io = p[1] + p[2] * 256;
 			size = p[3];
-			pnpbios_parse_allocated_ioresource(res, io, size);
+			pnpbios_parse_allocated_ioresource(dev, io, size);
 			break;
 
 		case SMALL_TAG_END:
@@ -652,12 +652,12 @@
 	p[3] = len & 0xff;
 }
 
-static unsigned char *pnpbios_encode_allocated_resource_data(unsigned char *p,
-							     unsigned char *end,
-							     struct
-							     pnp_resource_table
-							     *res)
+static unsigned char *pnpbios_encode_allocated_resource_data(struct pnp_dev
+								*dev,
+							     unsigned char *p,
+							     unsigned char *end)
 {
+	struct pnp_resource_table *res = &dev->res;
 	unsigned int len, tag;
 	int port = 0, irq = 0, dma = 0, mem = 0;
 
@@ -766,7 +766,7 @@
 	unsigned char *p = (char *)node->data;
 	unsigned char *end = (char *)(node->data + node->size);
 
-	p = pnpbios_parse_allocated_resource_data(p, end, &dev->res);
+	p = pnpbios_parse_allocated_resource_data(dev, p, end);
 	if (!p)
 		return -EIO;
 	p = pnpbios_parse_resource_option_data(p, end, dev);
@@ -778,25 +778,25 @@
 	return 0;
 }
 
-int pnpbios_read_resources_from_node(struct pnp_resource_table *res,
+int pnpbios_read_resources_from_node(struct pnp_dev *dev,
 				     struct pnp_bios_node *node)
 {
 	unsigned char *p = (char *)node->data;
 	unsigned char *end = (char *)(node->data + node->size);
 
-	p = pnpbios_parse_allocated_resource_data(p, end, res);
+	p = pnpbios_parse_allocated_resource_data(dev, p, end);
 	if (!p)
 		return -EIO;
 	return 0;
 }
 
-int pnpbios_write_resources_to_node(struct pnp_resource_table *res,
+int pnpbios_write_resources_to_node(struct pnp_dev *dev,
 				    struct pnp_bios_node *node)
 {
 	unsigned char *p = (char *)node->data;
 	unsigned char *end = (char *)(node->data + node->size);
 
-	p = pnpbios_encode_allocated_resource_data(p, end, res);
+	p = pnpbios_encode_allocated_resource_data(dev, p, end);
 	if (!p)
 		return -EIO;
 	return 0;

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 18/53] PNP: add pnp_init_resources(struct pnp_dev *) interface
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (16 preceding siblings ...)
  2008-04-18 20:50 ` [patch 17/53] PNP: remove more pnp_resource_table arguments Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 19/53] PNP: remove pnp_resource_table from internal pnp_clean_resource_table interface Bjorn Helgaas
                   ` (34 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, Rene Herman, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-remove-pnp_resource_table-from-init --]
[-- Type: text/plain, Size: 6152 bytes --]

Add pnp_init_resources(struct pnp_dev *) to replace
pnp_init_resource_table(), which takes a pointer to the
pnp_resource_table itself.  Passing only the pnp_dev * reduces
the possibility for error in the caller and removes the
pnp_resource_table implementation detail from the interface.

Even though pnp_init_resource_table() is exported, I did not
export pnp_init_resources() because it is used only by the PNP
core.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: Rene Herman <rene.herman@gmail.com>

---
 drivers/pnp/interface.c        |    6 +++---
 drivers/pnp/isapnp/core.c      |    4 ++--
 drivers/pnp/manager.c          |    5 +++++
 drivers/pnp/pnpacpi/core.c     |    2 +-
 drivers/pnp/pnpacpi/rsparser.c |    3 +--
 drivers/pnp/pnpbios/core.c     |    2 +-
 drivers/pnp/pnpbios/rsparser.c |    3 +--
 include/linux/pnp.h            |    2 ++
 8 files changed, 16 insertions(+), 11 deletions(-)

Index: work7/include/linux/pnp.h
===================================================================
--- work7.orig/include/linux/pnp.h	2008-03-31 17:10:39.000000000 -0600
+++ work7/include/linux/pnp.h	2008-03-31 17:10:48.000000000 -0600
@@ -388,6 +388,7 @@
 			       struct pnp_port *data);
 int pnp_register_mem_resource(struct pnp_option *option, struct pnp_mem *data);
 void pnp_init_resource_table(struct pnp_resource_table *table);
+void pnp_init_resources(struct pnp_dev *dev);
 int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table *res,
 			  int mode);
 int pnp_auto_config_dev(struct pnp_dev *dev);
@@ -435,6 +436,7 @@
 static inline int pnp_register_port_resource(struct pnp_option *option, struct pnp_port *data) { return -ENODEV; }
 static inline int pnp_register_mem_resource(struct pnp_option *option, struct pnp_mem *data) { return -ENODEV; }
 static inline void pnp_init_resource_table(struct pnp_resource_table *table) { }
+static inline void pnp_init_resources(struct pnp_dev *dev) { }
 static inline int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table *res, int mode) { return -ENODEV; }
 static inline int pnp_auto_config_dev(struct pnp_dev *dev) { return -ENODEV; }
 static inline int pnp_validate_config(struct pnp_dev *dev) { return -ENODEV; }
Index: work7/drivers/pnp/manager.c
===================================================================
--- work7.orig/drivers/pnp/manager.c	2008-03-31 17:10:39.000000000 -0600
+++ work7/drivers/pnp/manager.c	2008-03-31 17:10:48.000000000 -0600
@@ -238,6 +238,11 @@
 	}
 }
 
+void pnp_init_resources(struct pnp_dev *dev)
+{
+	pnp_init_resource_table(&dev->res);
+}
+
 /**
  * pnp_clean_resources - clears resources that were not manually set
  * @res: the resources to clean
Index: work7/drivers/pnp/interface.c
===================================================================
--- work7.orig/drivers/pnp/interface.c	2008-03-31 17:10:39.000000000 -0600
+++ work7/drivers/pnp/interface.c	2008-03-31 17:10:48.000000000 -0600
@@ -351,14 +351,14 @@
 	if (!strnicmp(buf, "auto", 4)) {
 		if (dev->active)
 			goto done;
-		pnp_init_resource_table(&dev->res);
+		pnp_init_resources(dev);
 		retval = pnp_auto_config_dev(dev);
 		goto done;
 	}
 	if (!strnicmp(buf, "clear", 5)) {
 		if (dev->active)
 			goto done;
-		pnp_init_resource_table(&dev->res);
+		pnp_init_resources(dev);
 		goto done;
 	}
 	if (!strnicmp(buf, "get", 3)) {
@@ -373,7 +373,7 @@
 		if (dev->active)
 			goto done;
 		buf += 3;
-		pnp_init_resource_table(&dev->res);
+		pnp_init_resources(dev);
 		mutex_lock(&pnp_res_mutex);
 		while (1) {
 			while (isspace(*buf))
Index: work7/drivers/pnp/isapnp/core.c
===================================================================
--- work7.orig/drivers/pnp/isapnp/core.c	2008-03-31 17:10:45.000000000 -0600
+++ work7/drivers/pnp/isapnp/core.c	2008-03-31 17:10:48.000000000 -0600
@@ -424,7 +424,7 @@
 	dev->capabilities |= PNP_READ;
 	dev->capabilities |= PNP_WRITE;
 	dev->capabilities |= PNP_DISABLE;
-	pnp_init_resource_table(&dev->res);
+	pnp_init_resources(dev);
 	return dev;
 }
 
@@ -972,7 +972,7 @@
 {
 	int ret;
 
-	pnp_init_resource_table(&dev->res);
+	pnp_init_resources(dev);
 	isapnp_cfg_begin(dev->card->number, dev->number);
 	ret = isapnp_read_resources(dev);
 	isapnp_cfg_end();
Index: work7/drivers/pnp/pnpacpi/core.c
===================================================================
--- work7.orig/drivers/pnp/pnpacpi/core.c	2008-03-31 17:10:45.000000000 -0600
+++ work7/drivers/pnp/pnpacpi/core.c	2008-03-31 17:10:48.000000000 -0600
@@ -210,7 +210,7 @@
 
 	/* clear out the damaged flags */
 	if (!dev->active)
-		pnp_init_resource_table(&dev->res);
+		pnp_init_resources(dev);
 	pnp_add_device(dev);
 	num++;
 
Index: work7/drivers/pnp/pnpbios/core.c
===================================================================
--- work7.orig/drivers/pnp/pnpbios/core.c	2008-03-31 17:10:45.000000000 -0600
+++ work7/drivers/pnp/pnpbios/core.c	2008-03-31 17:10:48.000000000 -0600
@@ -345,7 +345,7 @@
 
 	/* clear out the damaged flags */
 	if (!dev->active)
-		pnp_init_resource_table(&dev->res);
+		pnp_init_resources(dev);
 
 	pnp_add_device(dev);
 	pnpbios_interface_attach_device(node);
Index: work7/drivers/pnp/pnpacpi/rsparser.c
===================================================================
--- work7.orig/drivers/pnp/pnpacpi/rsparser.c	2008-03-31 17:10:45.000000000 -0600
+++ work7/drivers/pnp/pnpacpi/rsparser.c	2008-03-31 17:10:48.000000000 -0600
@@ -406,8 +406,7 @@
 {
 	acpi_handle handle = dev->data;
 
-	/* Blank the resource table values */
-	pnp_init_resource_table(&dev->res);
+	pnp_init_resources(dev);
 
 	return acpi_walk_resources(handle, METHOD_NAME__CRS,
 				   pnpacpi_allocated_resource, dev);
Index: work7/drivers/pnp/pnpbios/rsparser.c
===================================================================
--- work7.orig/drivers/pnp/pnpbios/rsparser.c	2008-03-31 17:10:45.000000000 -0600
+++ work7/drivers/pnp/pnpbios/rsparser.c	2008-03-31 17:10:48.000000000 -0600
@@ -143,8 +143,7 @@
 	if (!p)
 		return NULL;
 
-	/* Blank the resource table values */
-	pnp_init_resource_table(&dev->res);
+	pnp_init_resources(dev);
 
 	while ((char *)p < (char *)end) {
 

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 19/53] PNP: remove pnp_resource_table from internal pnp_clean_resource_table interface
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (17 preceding siblings ...)
  2008-04-18 20:50 ` [patch 18/53] PNP: add pnp_init_resources(struct pnp_dev *) interface Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 20/53] PNP: remove unused interfaces using pnp_resource_table Bjorn Helgaas
                   ` (33 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, Rene Herman, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-remove-pnp_resource_table-from-clean --]
[-- Type: text/plain, Size: 1584 bytes --]

This changes pnp_clean_resource_table() to take a pnp_dev pointer
rather than a pnp_resource_table pointer.  This reduces the visibility
of pnp_resource_table and removes an opportunity for error in the
caller.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: Rene Herman <rene.herman@gmail.com>

Index: work7/drivers/pnp/manager.c
===================================================================
--- work7.orig/drivers/pnp/manager.c	2008-03-25 11:03:59.000000000 -0600
+++ work7/drivers/pnp/manager.c	2008-03-25 11:04:52.000000000 -0600
@@ -247,8 +247,9 @@
  * pnp_clean_resources - clears resources that were not manually set
  * @res: the resources to clean
  */
-static void pnp_clean_resource_table(struct pnp_resource_table *res)
+static void pnp_clean_resource_table(struct pnp_dev *dev)
 {
+	struct pnp_resource_table *res = &dev->res;
 	int idx;
 
 	for (idx = 0; idx < PNP_MAX_IRQ; idx++) {
@@ -304,7 +305,7 @@
 		return -ENODEV;
 
 	mutex_lock(&pnp_res_mutex);
-	pnp_clean_resource_table(&dev->res);	/* start with a fresh slate */
+	pnp_clean_resource_table(dev);
 	if (dev->independent) {
 		port = dev->independent->port;
 		mem = dev->independent->mem;
@@ -376,7 +377,7 @@
 	return 1;
 
 fail:
-	pnp_clean_resource_table(&dev->res);
+	pnp_clean_resource_table(dev);
 	mutex_unlock(&pnp_res_mutex);
 	return 0;
 }
@@ -554,7 +555,7 @@
 
 	/* release the resources so that other devices can use them */
 	mutex_lock(&pnp_res_mutex);
-	pnp_clean_resource_table(&dev->res);
+	pnp_clean_resource_table(dev);
 	mutex_unlock(&pnp_res_mutex);
 
 	return 0;

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 20/53] PNP: remove unused interfaces using pnp_resource_table
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (18 preceding siblings ...)
  2008-04-18 20:50 ` [patch 19/53] PNP: remove pnp_resource_table from internal pnp_clean_resource_table interface Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 21/53] PNP: use dev_printk when possible Bjorn Helgaas
                   ` (32 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, Rene Herman, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-remove-unused-interfaces --]
[-- Type: text/plain, Size: 6189 bytes --]

Rene Herman <rene.herman@gmail.com> recently removed the only in-tree
driver uses of:

    pnp_init_resource_table()
    pnp_manual_config_dev()
    pnp_resource_change()

in this change:

    http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=109c53f840e551d6e99ecfd8b0131a968332c89f

These are no longer used in the PNP core either, so we can just remove
them completely.

It's possible that there are out-of-tree drivers that use these
interfaces.  They should be changed to either (1) use PNP quirks
to work around broken hardware or firmware, or (2) use the sysfs
interfaces to control resource usage from userspace.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: Rene Herman <rene.herman@gmail.com>

---
 drivers/pnp/manager.c |   78 +-------------------------------------------------
 include/linux/pnp.h   |    9 -----
 2 files changed, 3 insertions(+), 84 deletions(-)

Index: work8/include/linux/pnp.h
===================================================================
--- work8.orig/include/linux/pnp.h	2008-04-10 16:47:25.000000000 -0600
+++ work8/include/linux/pnp.h	2008-04-10 16:48:34.000000000 -0600
@@ -387,18 +387,14 @@
 int pnp_register_port_resource(struct pnp_option *option,
 			       struct pnp_port *data);
 int pnp_register_mem_resource(struct pnp_option *option, struct pnp_mem *data);
-void pnp_init_resource_table(struct pnp_resource_table *table);
 void pnp_init_resources(struct pnp_dev *dev);
-int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table *res,
-			  int mode);
 int pnp_auto_config_dev(struct pnp_dev *dev);
 int pnp_validate_config(struct pnp_dev *dev);
 int pnp_start_dev(struct pnp_dev *dev);
 int pnp_stop_dev(struct pnp_dev *dev);
 int pnp_activate_dev(struct pnp_dev *dev);
 int pnp_disable_dev(struct pnp_dev *dev);
-void pnp_resource_change(struct resource *resource, resource_size_t start,
-			 resource_size_t size);
+
 
 /* protocol helpers */
 int pnp_is_active(struct pnp_dev *dev);
@@ -435,16 +431,13 @@
 static inline int pnp_register_dma_resource(struct pnp_option *option, struct pnp_dma *data) { return -ENODEV; }
 static inline int pnp_register_port_resource(struct pnp_option *option, struct pnp_port *data) { return -ENODEV; }
 static inline int pnp_register_mem_resource(struct pnp_option *option, struct pnp_mem *data) { return -ENODEV; }
-static inline void pnp_init_resource_table(struct pnp_resource_table *table) { }
 static inline void pnp_init_resources(struct pnp_dev *dev) { }
-static inline int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table *res, int mode) { return -ENODEV; }
 static inline int pnp_auto_config_dev(struct pnp_dev *dev) { return -ENODEV; }
 static inline int pnp_validate_config(struct pnp_dev *dev) { return -ENODEV; }
 static inline int pnp_start_dev(struct pnp_dev *dev) { return -ENODEV; }
 static inline int pnp_stop_dev(struct pnp_dev *dev) { return -ENODEV; }
 static inline int pnp_activate_dev(struct pnp_dev *dev) { return -ENODEV; }
 static inline int pnp_disable_dev(struct pnp_dev *dev) { return -ENODEV; }
-static inline void pnp_resource_change(struct resource *resource, resource_size_t start, resource_size_t size) { }
 
 /* protocol helpers */
 static inline int pnp_is_active(struct pnp_dev *dev) { return 0; }
Index: work8/drivers/pnp/manager.c
===================================================================
--- work8.orig/drivers/pnp/manager.c	2008-04-10 16:47:29.000000000 -0600
+++ work8/drivers/pnp/manager.c	2008-04-10 16:48:34.000000000 -0600
@@ -204,8 +204,9 @@
  * pnp_init_resources - Resets a resource table to default values.
  * @table: pointer to the desired resource table
  */
-void pnp_init_resource_table(struct pnp_resource_table *table)
+void pnp_init_resources(struct pnp_dev *dev)
 {
+	struct pnp_resource_table *table = &dev->res;
 	int idx;
 
 	for (idx = 0; idx < PNP_MAX_IRQ; idx++) {
@@ -238,11 +239,6 @@
 	}
 }
 
-void pnp_init_resources(struct pnp_dev *dev)
-{
-	pnp_init_resource_table(&dev->res);
-}
-
 /**
  * pnp_clean_resources - clears resources that were not manually set
  * @res: the resources to clean
@@ -383,59 +379,6 @@
 }
 
 /**
- * pnp_manual_config_dev - Disables Auto Config and Manually sets the resource table
- * @dev: pointer to the desired device
- * @res: pointer to the new resource config
- * @mode: 0 or PNP_CONFIG_FORCE
- *
- * This function can be used by drivers that want to manually set thier resources.
- */
-int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table *res,
-			  int mode)
-{
-	int i;
-	struct pnp_resource_table *bak;
-
-	if (!pnp_can_configure(dev))
-		return -ENODEV;
-	bak = pnp_alloc(sizeof(struct pnp_resource_table));
-	if (!bak)
-		return -ENOMEM;
-	*bak = dev->res;
-
-	mutex_lock(&pnp_res_mutex);
-	dev->res = *res;
-	if (!(mode & PNP_CONFIG_FORCE)) {
-		for (i = 0; i < PNP_MAX_PORT; i++) {
-			if (!pnp_check_port(dev, i))
-				goto fail;
-		}
-		for (i = 0; i < PNP_MAX_MEM; i++) {
-			if (!pnp_check_mem(dev, i))
-				goto fail;
-		}
-		for (i = 0; i < PNP_MAX_IRQ; i++) {
-			if (!pnp_check_irq(dev, i))
-				goto fail;
-		}
-		for (i = 0; i < PNP_MAX_DMA; i++) {
-			if (!pnp_check_dma(dev, i))
-				goto fail;
-		}
-	}
-	mutex_unlock(&pnp_res_mutex);
-
-	kfree(bak);
-	return 0;
-
-fail:
-	dev->res = *bak;
-	mutex_unlock(&pnp_res_mutex);
-	kfree(bak);
-	return -EINVAL;
-}
-
-/**
  * pnp_auto_config_dev - automatically assigns resources to a device
  * @dev: pointer to the desired device
  */
@@ -561,24 +504,7 @@
 	return 0;
 }
 
-/**
- * pnp_resource_change - change one resource
- * @resource: pointer to resource to be changed
- * @start: start of region
- * @size: size of region
- */
-void pnp_resource_change(struct resource *resource, resource_size_t start,
-			 resource_size_t size)
-{
-	resource->flags &= ~(IORESOURCE_AUTO | IORESOURCE_UNSET);
-	resource->start = start;
-	resource->end = start + size - 1;
-}
-
-EXPORT_SYMBOL(pnp_manual_config_dev);
 EXPORT_SYMBOL(pnp_start_dev);
 EXPORT_SYMBOL(pnp_stop_dev);
 EXPORT_SYMBOL(pnp_activate_dev);
 EXPORT_SYMBOL(pnp_disable_dev);
-EXPORT_SYMBOL(pnp_resource_change);
-EXPORT_SYMBOL(pnp_init_resource_table);

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 21/53] PNP: use dev_printk when possible
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (19 preceding siblings ...)
  2008-04-18 20:50 ` [patch 20/53] PNP: remove unused interfaces using pnp_resource_table Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 22/53] PNP: factor pnp_init_resource_table() and pnp_clean_resource_table() Bjorn Helgaas
                   ` (31 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, Rene Herman, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-dev_printk --]
[-- Type: text/plain, Size: 8252 bytes --]

Use dev_printk() when possible for more informative error messages.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: Rene Herman <rene.herman@gmail.com>

---
 drivers/pnp/isapnp/core.c      |   38 ++++++++++++++++++--------------------
 drivers/pnp/pnpacpi/rsparser.c |   20 ++++++++++++--------
 drivers/pnp/pnpbios/rsparser.c |   36 ++++++++++++++----------------------
 3 files changed, 44 insertions(+), 50 deletions(-)

Index: work8/drivers/pnp/isapnp/core.c
===================================================================
--- work8.orig/drivers/pnp/isapnp/core.c	2008-04-10 13:28:45.000000000 -0600
+++ work8/drivers/pnp/isapnp/core.c	2008-04-10 13:35:11.000000000 -0600
@@ -729,9 +729,8 @@
 				isapnp_skip_bytes(size);
 			return 1;
 		default:
-			printk(KERN_ERR
-			       "isapnp: unexpected or unknown tag type 0x%x for logical device %i (device %i), ignored\n",
-			       type, dev->number, card->number);
+			dev_err(&dev->dev, "unknown tag 0x%x (card %i), "
+				"ignored\n", type, card->number);
 		}
 __skip:
 		if (size > 0)
@@ -784,9 +783,8 @@
 				isapnp_skip_bytes(size);
 			return;
 		default:
-			printk(KERN_ERR
-			       "isapnp: unexpected or unknown tag type 0x%x for device %i, ignored\n",
-			       type, card->number);
+			dev_err(&card->dev, "unknown tag 0x%x, ignored\n",
+			       type);
 		}
 __skip:
 		if (size > 0)
@@ -833,13 +831,6 @@
 		isapnp_wake(csn);
 		isapnp_peek(header, 9);
 		checksum = isapnp_checksum(header);
-#if 0
-		printk(KERN_DEBUG
-		       "vendor: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
-		       header[0], header[1], header[2], header[3], header[4],
-		       header[5], header[6], header[7], header[8]);
-		printk(KERN_DEBUG "checksum = 0x%x\n", checksum);
-#endif
 		eisa_id = header[0] | header[1] << 8 |
 			  header[2] << 16 | header[3] << 24;
 		pnp_eisa_id_to_string(eisa_id, id);
@@ -847,6 +838,13 @@
 		if (!card)
 			continue;
 
+#if 0
+		dev_info(&card->dev,
+		       "vendor: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
+		       header[0], header[1], header[2], header[3], header[4],
+		       header[5], header[6], header[7], header[8]);
+		dev_info(&card->dev, "checksum = 0x%x\n", checksum);
+#endif
 		INIT_LIST_HEAD(&card->devices);
 		card->serial =
 		    (header[7] << 24) | (header[6] << 16) | (header[5] << 8) |
@@ -854,9 +852,8 @@
 		isapnp_checksum_value = 0x00;
 		isapnp_parse_resource_map(card);
 		if (isapnp_checksum_value != 0x00)
-			printk(KERN_ERR
-			       "isapnp: checksum for device %i is not valid (0x%x)\n",
-			       csn, isapnp_checksum_value);
+			dev_err(&card->dev, "invalid checksum 0x%x\n",
+				isapnp_checksum_value);
 		card->checksum = isapnp_checksum_value;
 
 		pnp_add_card(card);
@@ -1114,13 +1111,13 @@
 	protocol_for_each_card(&isapnp_protocol, card) {
 		cards++;
 		if (isapnp_verbose) {
-			printk(KERN_INFO "isapnp: Card '%s'\n",
-			       card->name[0] ? card->name : "Unknown");
+			dev_info(&card->dev, "card '%s'\n",
+			       card->name[0] ? card->name : "unknown");
 			if (isapnp_verbose < 2)
 				continue;
 			card_for_each_dev(card, dev) {
-				printk(KERN_INFO "isapnp:   Device '%s'\n",
-				       dev->name[0] ? dev->name : "Unknown");
+				dev_info(&card->dev, "device '%s'\n",
+				       dev->name[0] ? dev->name : "unknown");
 			}
 		}
 	}
Index: work8/drivers/pnp/pnpacpi/rsparser.c
===================================================================
--- work8.orig/drivers/pnp/pnpacpi/rsparser.c	2008-04-10 13:28:45.000000000 -0600
+++ work8/drivers/pnp/pnpacpi/rsparser.c	2008-04-10 13:35:11.000000000 -0600
@@ -108,7 +108,7 @@
 		p = p ? ACPI_ACTIVE_LOW : ACPI_ACTIVE_HIGH;
 
 		if (triggering != t || polarity != p) {
-			pnp_warn("IRQ %d override to %s, %s",
+			dev_warn(&dev->dev, "IRQ %d override to %s, %s\n",
 				gsi, t ? "edge":"level", p ? "low":"high");
 			triggering = t;
 			polarity = p;
@@ -261,7 +261,7 @@
 
 	status = acpi_resource_to_address64(res, p);
 	if (!ACPI_SUCCESS(status)) {
-		pnp_warn("PnPACPI: failed to convert resource type %d",
+		dev_warn(&dev->dev, "failed to convert resource type %d\n",
 			 res->type);
 		return;
 	}
@@ -395,7 +395,8 @@
 		break;
 
 	default:
-		pnp_warn("PnPACPI: unknown resource type %d", res->type);
+		dev_warn(&dev->dev, "unknown resource type %d in _CRS\n",
+			 res->type);
 		return AE_ERROR;
 	}
 
@@ -661,7 +662,8 @@
 	case ACPI_RESOURCE_TYPE_END_DEPENDENT:
 		/*only one EndDependentFn is allowed */
 		if (!parse_data->option_independent) {
-			pnp_warn("PnPACPI: more than one EndDependentFn");
+			dev_warn(&dev->dev, "more than one EndDependentFn "
+				 "in _PRS\n");
 			return AE_ERROR;
 		}
 		parse_data->option = parse_data->option_independent;
@@ -710,7 +712,8 @@
 		break;
 
 	default:
-		pnp_warn("PnPACPI: unknown resource type %d", res->type);
+		dev_warn(&dev->dev, "unknown resource type %d in _PRS\n",
+			 res->type);
 		return AE_ERROR;
 	}
 
@@ -790,7 +793,7 @@
 	status = acpi_walk_resources(handle, METHOD_NAME__CRS,
 				     pnpacpi_count_resources, &res_cnt);
 	if (ACPI_FAILURE(status)) {
-		pnp_err("Evaluate _CRS failed");
+		dev_err(&dev->dev, "can't evaluate _CRS\n");
 		return -EINVAL;
 	}
 	if (!res_cnt)
@@ -805,7 +808,7 @@
 				     pnpacpi_type_resources, &resource);
 	if (ACPI_FAILURE(status)) {
 		kfree(buffer->pointer);
-		pnp_err("Evaluate _CRS failed");
+		dev_err(&dev->dev, "can't evaluate _CRS\n");
 		return -EINVAL;
 	}
 	/* resource will pointer the end resource now */
@@ -1022,7 +1025,8 @@
 		case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
 		case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
 		default:	/* other type */
-			pnp_warn("unknown resource type %d", resource->type);
+			dev_warn(&dev->dev, "can't encode unknown resource "
+				 "type %d\n", resource->type);
 			return -EINVAL;
 		}
 		resource++;
Index: work8/drivers/pnp/pnpbios/rsparser.c
===================================================================
--- work8.orig/drivers/pnp/pnpbios/rsparser.c	2008-04-10 13:28:45.000000000 -0600
+++ work8/drivers/pnp/pnpbios/rsparser.c	2008-04-10 13:35:11.000000000 -0600
@@ -239,9 +239,8 @@
 
 		default:	/* an unkown tag */
 len_err:
-			printk(KERN_ERR
-			       "PnPBIOS: Unknown tag '0x%x', length '%d'.\n",
-			       tag, len);
+			dev_err(&dev->dev, "unknown tag 0x%x length %d\n",
+				tag, len);
 			break;
 		}
 
@@ -252,8 +251,7 @@
 			p += len + 1;
 	}
 
-	printk(KERN_ERR
-	       "PnPBIOS: Resource structure does not contain an end tag.\n");
+	dev_err(&dev->dev, "no end tag in resource structure\n");
 
 	return NULL;
 }
@@ -460,8 +458,8 @@
 			if (len != 0)
 				goto len_err;
 			if (option_independent == option)
-				printk(KERN_WARNING
-				       "PnPBIOS: Missing SMALL_TAG_STARTDEP tag\n");
+				dev_warn(&dev->dev, "missing "
+					 "SMALL_TAG_STARTDEP tag\n");
 			option = option_independent;
 			break;
 
@@ -470,9 +468,8 @@
 
 		default:	/* an unkown tag */
 len_err:
-			printk(KERN_ERR
-			       "PnPBIOS: Unknown tag '0x%x', length '%d'.\n",
-			       tag, len);
+			dev_err(&dev->dev, "unknown tag 0x%x length %d\n",
+				tag, len);
 			break;
 		}
 
@@ -483,8 +480,7 @@
 			p += len + 1;
 	}
 
-	printk(KERN_ERR
-	       "PnPBIOS: Resource structure does not contain an end tag.\n");
+	dev_err(&dev->dev, "no end tag in resource structure\n");
 
 	return NULL;
 }
@@ -542,9 +538,8 @@
 
 		default:	/* an unkown tag */
 len_err:
-			printk(KERN_ERR
-			       "PnPBIOS: Unknown tag '0x%x', length '%d'.\n",
-			       tag, len);
+			dev_err(&dev->dev, "unknown tag 0x%x length %d\n",
+				tag, len);
 			break;
 		}
 
@@ -555,8 +550,7 @@
 			p += len + 1;
 	}
 
-	printk(KERN_ERR
-	       "PnPBIOS: Resource structure does not contain an end tag.\n");
+	dev_err(&dev->dev, "no end tag in resource structure\n");
 
 	return NULL;
 }
@@ -736,9 +730,8 @@
 
 		default:	/* an unkown tag */
 len_err:
-			printk(KERN_ERR
-			       "PnPBIOS: Unknown tag '0x%x', length '%d'.\n",
-			       tag, len);
+			dev_err(&dev->dev, "unknown tag 0x%x length %d\n",
+				tag, len);
 			break;
 		}
 
@@ -749,8 +742,7 @@
 			p += len + 1;
 	}
 
-	printk(KERN_ERR
-	       "PnPBIOS: Resource structure does not contain an end tag.\n");
+	dev_err(&dev->dev, "no end tag in resource structure\n");
 
 	return NULL;
 }

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 22/53] PNP: factor pnp_init_resource_table() and pnp_clean_resource_table()
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (20 preceding siblings ...)
  2008-04-18 20:50 ` [patch 21/53] PNP: use dev_printk when possible Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 22:29   ` Rene Herman
  2008-04-18 20:50 ` [patch 23/53] PNP: add pnp_get_resource() interface Bjorn Helgaas
                   ` (30 subsequent siblings)
  52 siblings, 1 reply; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-factor-init-resources --]
[-- Type: text/plain, Size: 5043 bytes --]

Move the common part of pnp_init_resource_table() and
pnp_clean_resource_table() into a new pnp_init_resource().
This reduces a little code duplication and will be
useful later to initialize an individual resource.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>

---
 drivers/pnp/base.h    |    2 +
 drivers/pnp/manager.c |   86 +++++++++++++++++++-------------------------------
 2 files changed, 36 insertions(+), 52 deletions(-)

Index: work8/drivers/pnp/base.h
===================================================================
--- work8.orig/drivers/pnp/base.h	2008-04-10 16:47:29.000000000 -0600
+++ work8/drivers/pnp/base.h	2008-04-10 16:48:43.000000000 -0600
@@ -16,3 +16,5 @@
 int pnp_check_mem(struct pnp_dev * dev, int idx);
 int pnp_check_irq(struct pnp_dev * dev, int idx);
 int pnp_check_dma(struct pnp_dev * dev, int idx);
+
+void pnp_init_resource(struct resource *res);
Index: work8/drivers/pnp/manager.c
===================================================================
--- work8.orig/drivers/pnp/manager.c	2008-04-10 16:48:34.000000000 -0600
+++ work8/drivers/pnp/manager.c	2008-04-10 16:48:43.000000000 -0600
@@ -200,6 +200,24 @@
 	*flags |= IORESOURCE_UNSET | IORESOURCE_DISABLED;
 }
 
+void pnp_init_resource(struct resource *res)
+{
+	unsigned long type;
+
+	type = res->flags & (IORESOURCE_IO  | IORESOURCE_MEM |
+			     IORESOURCE_IRQ | IORESOURCE_DMA);
+
+	res->name = NULL;
+	res->flags = type | IORESOURCE_AUTO | IORESOURCE_UNSET;
+	if (type == IORESOURCE_IRQ || type == IORESOURCE_DMA) {
+		res->start = -1;
+		res->end = -1;
+	} else {
+		res->start = 0;
+		res->end = 0;
+	}
+}
+
 /**
  * pnp_init_resources - Resets a resource table to default values.
  * @table: pointer to the desired resource table
@@ -209,34 +227,14 @@
 	struct pnp_resource_table *table = &dev->res;
 	int idx;
 
-	for (idx = 0; idx < PNP_MAX_IRQ; idx++) {
-		table->irq_resource[idx].name = NULL;
-		table->irq_resource[idx].start = -1;
-		table->irq_resource[idx].end = -1;
-		table->irq_resource[idx].flags =
-		    IORESOURCE_IRQ | IORESOURCE_AUTO | IORESOURCE_UNSET;
-	}
-	for (idx = 0; idx < PNP_MAX_DMA; idx++) {
-		table->dma_resource[idx].name = NULL;
-		table->dma_resource[idx].start = -1;
-		table->dma_resource[idx].end = -1;
-		table->dma_resource[idx].flags =
-		    IORESOURCE_DMA | IORESOURCE_AUTO | IORESOURCE_UNSET;
-	}
-	for (idx = 0; idx < PNP_MAX_PORT; idx++) {
-		table->port_resource[idx].name = NULL;
-		table->port_resource[idx].start = 0;
-		table->port_resource[idx].end = 0;
-		table->port_resource[idx].flags =
-		    IORESOURCE_IO | IORESOURCE_AUTO | IORESOURCE_UNSET;
-	}
-	for (idx = 0; idx < PNP_MAX_MEM; idx++) {
-		table->mem_resource[idx].name = NULL;
-		table->mem_resource[idx].start = 0;
-		table->mem_resource[idx].end = 0;
-		table->mem_resource[idx].flags =
-		    IORESOURCE_MEM | IORESOURCE_AUTO | IORESOURCE_UNSET;
-	}
+	for (idx = 0; idx < PNP_MAX_IRQ; idx++)
+		pnp_init_resource(&table->irq_resource[idx]);
+	for (idx = 0; idx < PNP_MAX_DMA; idx++)
+		pnp_init_resource(&table->dma_resource[idx]);
+	for (idx = 0; idx < PNP_MAX_PORT; idx++)
+		pnp_init_resource(&table->port_resource[idx]);
+	for (idx = 0; idx < PNP_MAX_MEM; idx++)
+		pnp_init_resource(&table->mem_resource[idx]);
 }
 
 /**
@@ -245,40 +243,24 @@
  */
 static void pnp_clean_resource_table(struct pnp_dev *dev)
 {
-	struct pnp_resource_table *res = &dev->res;
+	struct pnp_resource_table *table = &dev->res;
 	int idx;
 
 	for (idx = 0; idx < PNP_MAX_IRQ; idx++) {
-		if (!(res->irq_resource[idx].flags & IORESOURCE_AUTO))
-			continue;
-		res->irq_resource[idx].start = -1;
-		res->irq_resource[idx].end = -1;
-		res->irq_resource[idx].flags =
-		    IORESOURCE_IRQ | IORESOURCE_AUTO | IORESOURCE_UNSET;
+		if (table->irq_resource[idx].flags & IORESOURCE_AUTO)
+			pnp_init_resource(&table->irq_resource[idx]);
 	}
 	for (idx = 0; idx < PNP_MAX_DMA; idx++) {
-		if (!(res->dma_resource[idx].flags & IORESOURCE_AUTO))
-			continue;
-		res->dma_resource[idx].start = -1;
-		res->dma_resource[idx].end = -1;
-		res->dma_resource[idx].flags =
-		    IORESOURCE_DMA | IORESOURCE_AUTO | IORESOURCE_UNSET;
+		if (table->dma_resource[idx].flags & IORESOURCE_AUTO)
+			pnp_init_resource(&table->dma_resource[idx]);
 	}
 	for (idx = 0; idx < PNP_MAX_PORT; idx++) {
-		if (!(res->port_resource[idx].flags & IORESOURCE_AUTO))
-			continue;
-		res->port_resource[idx].start = 0;
-		res->port_resource[idx].end = 0;
-		res->port_resource[idx].flags =
-		    IORESOURCE_IO | IORESOURCE_AUTO | IORESOURCE_UNSET;
+		if (table->port_resource[idx].flags & IORESOURCE_AUTO)
+			pnp_init_resource(&table->port_resource[idx]);
 	}
 	for (idx = 0; idx < PNP_MAX_MEM; idx++) {
-		if (!(res->mem_resource[idx].flags & IORESOURCE_AUTO))
-			continue;
-		res->mem_resource[idx].start = 0;
-		res->mem_resource[idx].end = 0;
-		res->mem_resource[idx].flags =
-		    IORESOURCE_MEM | IORESOURCE_AUTO | IORESOURCE_UNSET;
+		if (table->mem_resource[idx].flags & IORESOURCE_AUTO)
+			pnp_init_resource(&table->mem_resource[idx]);
 	}
 }
 

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 23/53] PNP: add pnp_get_resource() interface
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (21 preceding siblings ...)
  2008-04-18 20:50 ` [patch 22/53] PNP: factor pnp_init_resource_table() and pnp_clean_resource_table() Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 24/53] PNP: remove pnp_mem_flags() as an lvalue Bjorn Helgaas
                   ` (29 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, Rene Herman, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-add-get-resource --]
[-- Type: text/plain, Size: 2010 bytes --]

This adds a pnp_get_resource() that works the same way as
platform_get_resource().  This will enable us to consolidate
many pnp_resource_table references in one place, which will
make it easier to make the table dynamic.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: Rene Herman <rene.herman@gmail.com>

---
 drivers/pnp/resource.c |   27 +++++++++++++++++++++++++++
 include/linux/pnp.h    |    1 +
 2 files changed, 28 insertions(+)

Index: work8/include/linux/pnp.h
===================================================================
--- work8.orig/include/linux/pnp.h	2008-04-10 13:28:45.000000000 -0600
+++ work8/include/linux/pnp.h	2008-04-10 13:31:52.000000000 -0600
@@ -25,6 +25,7 @@
 /*
  * Resource Management
  */
+struct resource *pnp_get_resource(struct pnp_dev *, unsigned int, unsigned int);
 
 /* Use these instead of directly reading pnp_dev to get resource information */
 #define pnp_port_start(dev,bar)   ((dev)->res.port_resource[(bar)].start)
Index: work8/drivers/pnp/resource.c
===================================================================
--- work8.orig/drivers/pnp/resource.c	2008-04-10 12:26:08.000000000 -0600
+++ work8/drivers/pnp/resource.c	2008-04-10 13:31:52.000000000 -0600
@@ -461,6 +461,33 @@
 #endif
 }
 
+struct resource *pnp_get_resource(struct pnp_dev *dev,
+				  unsigned int type, unsigned int num)
+{
+	struct pnp_resource_table *res = &dev->res;
+
+	switch (type) {
+	case IORESOURCE_IO:
+		if (num >= PNP_MAX_PORT)
+			return NULL;
+		return &res->port_resource[num];
+	case IORESOURCE_MEM:
+		if (num >= PNP_MAX_MEM)
+			return NULL;
+		return &res->mem_resource[num];
+	case IORESOURCE_IRQ:
+		if (num >= PNP_MAX_IRQ)
+			return NULL;
+		return &res->irq_resource[num];
+	case IORESOURCE_DMA:
+		if (num >= PNP_MAX_DMA)
+			return NULL;
+		return &res->dma_resource[num];
+	}
+	return NULL;
+}
+EXPORT_SYMBOL(pnp_get_resource);
+
 /* format is: pnp_reserve_irq=irq1[,irq2] .... */
 static int __init pnp_setup_reserve_irq(char *str)
 {

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 24/53] PNP: remove pnp_mem_flags() as an lvalue
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (22 preceding siblings ...)
  2008-04-18 20:50 ` [patch 23/53] PNP: add pnp_get_resource() interface Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 25/53] PNP: convert resource accessors to use pnp_get_resource(), not pnp_resource_table Bjorn Helgaas
                   ` (28 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-remove-accessor-lvalues --]
[-- Type: text/plain, Size: 896 bytes --]

A future change will change pnp_mem_flags() from a "#define that
simplifies to an lvalue" to "an inline function that returns the
flags value."

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>

Index: work7/drivers/pnp/quirks.c
===================================================================
--- work7.orig/drivers/pnp/quirks.c	2008-04-02 13:08:09.000000000 -0600
+++ work7/drivers/pnp/quirks.c	2008-04-02 13:10:34.000000000 -0600
@@ -114,6 +114,7 @@
 static void quirk_system_pci_resources(struct pnp_dev *dev)
 {
 	struct pci_dev *pdev = NULL;
+	struct resource *res;
 	resource_size_t pnp_start, pnp_end, pci_start, pci_end;
 	int i, j;
 
@@ -173,7 +174,8 @@
 					pci_name(pdev), i,
 					(unsigned long long) pci_start,
 					(unsigned long long) pci_end);
-				pnp_mem_flags(dev, j) = 0;
+				res = pnp_get_resource(dev, IORESOURCE_MEM, j);
+				res->flags = 0;
 			}
 		}
 	}

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 25/53] PNP: convert resource accessors to use pnp_get_resource(), not pnp_resource_table
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (23 preceding siblings ...)
  2008-04-18 20:50 ` [patch 24/53] PNP: remove pnp_mem_flags() as an lvalue Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 26/53] PNP: use conventional "i" for loop indices Bjorn Helgaas
                   ` (27 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-convert-accessors-to-pnp_get_resource --]
[-- Type: text/plain, Size: 5308 bytes --]

This removes more direct references to pnp_resource_table.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>

---
 include/linux/pnp.h |  148 +++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 108 insertions(+), 40 deletions(-)

Index: work7/include/linux/pnp.h
===================================================================
--- work7.orig/include/linux/pnp.h	2008-04-02 11:08:02.000000000 -0600
+++ work7/include/linux/pnp.h	2008-04-02 13:02:29.000000000 -0600
@@ -27,46 +27,114 @@
  */
 struct resource *pnp_get_resource(struct pnp_dev *, unsigned int, unsigned int);
 
-/* Use these instead of directly reading pnp_dev to get resource information */
-#define pnp_port_start(dev,bar)   ((dev)->res.port_resource[(bar)].start)
-#define pnp_port_end(dev,bar)     ((dev)->res.port_resource[(bar)].end)
-#define pnp_port_flags(dev,bar)   ((dev)->res.port_resource[(bar)].flags)
-#define pnp_port_valid(dev,bar) \
-	((pnp_port_flags((dev),(bar)) & (IORESOURCE_IO | IORESOURCE_UNSET)) \
-		== IORESOURCE_IO)
-#define pnp_port_len(dev,bar) \
-	((pnp_port_start((dev),(bar)) == 0 &&	\
-	  pnp_port_end((dev),(bar)) ==		\
-	  pnp_port_start((dev),(bar))) ? 0 :	\
-	  					\
-	 (pnp_port_end((dev),(bar)) -		\
-	  pnp_port_start((dev),(bar)) + 1))
-
-#define pnp_mem_start(dev,bar)   ((dev)->res.mem_resource[(bar)].start)
-#define pnp_mem_end(dev,bar)     ((dev)->res.mem_resource[(bar)].end)
-#define pnp_mem_flags(dev,bar)   ((dev)->res.mem_resource[(bar)].flags)
-#define pnp_mem_valid(dev,bar) \
-	((pnp_mem_flags((dev),(bar)) & (IORESOURCE_MEM | IORESOURCE_UNSET)) \
-		== IORESOURCE_MEM)
-#define pnp_mem_len(dev,bar) \
-	((pnp_mem_start((dev),(bar)) == 0 &&	\
-	  pnp_mem_end((dev),(bar)) ==		\
-	  pnp_mem_start((dev),(bar))) ? 0 :	\
-	  					\
-	 (pnp_mem_end((dev),(bar)) -		\
-	  pnp_mem_start((dev),(bar)) + 1))
-
-#define pnp_irq(dev,bar)	 ((dev)->res.irq_resource[(bar)].start)
-#define pnp_irq_flags(dev,bar)	 ((dev)->res.irq_resource[(bar)].flags)
-#define pnp_irq_valid(dev,bar) \
-	((pnp_irq_flags((dev),(bar)) & (IORESOURCE_IRQ | IORESOURCE_UNSET)) \
-		== IORESOURCE_IRQ)
-
-#define pnp_dma(dev,bar)	 ((dev)->res.dma_resource[(bar)].start)
-#define pnp_dma_flags(dev,bar)	 ((dev)->res.dma_resource[(bar)].flags)
-#define pnp_dma_valid(dev,bar) \
-	((pnp_dma_flags((dev),(bar)) & (IORESOURCE_DMA | IORESOURCE_UNSET)) \
-		== IORESOURCE_DMA)
+static inline int pnp_resource_valid(struct resource *res)
+{
+	if (res && !(res->flags & IORESOURCE_UNSET))
+		return 1;
+	return 0;
+}
+
+static inline resource_size_t pnp_resource_len(struct resource *res)
+{
+	if (res->start == 0 && res->end == 0)
+		return 0;
+	return res->end - res->start + 1;
+}
+
+
+static inline resource_size_t pnp_port_start(struct pnp_dev *dev,
+					     unsigned int bar)
+{
+	return pnp_get_resource(dev, IORESOURCE_IO, bar)->start;
+}
+
+static inline resource_size_t pnp_port_end(struct pnp_dev *dev,
+					   unsigned int bar)
+{
+	return pnp_get_resource(dev, IORESOURCE_IO, bar)->end;
+}
+
+static inline resource_size_t pnp_port_flags(struct pnp_dev *dev,
+					     unsigned int bar)
+{
+	return pnp_get_resource(dev, IORESOURCE_IO, bar)->flags;
+}
+
+static inline int pnp_port_valid(struct pnp_dev *dev, unsigned int bar)
+{
+	return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_IO, bar));
+}
+
+static inline resource_size_t pnp_port_len(struct pnp_dev *dev,
+					   unsigned int bar)
+{
+	return pnp_resource_len(pnp_get_resource(dev, IORESOURCE_IO, bar));
+}
+
+
+static inline resource_size_t pnp_mem_start(struct pnp_dev *dev,
+					    unsigned int bar)
+{
+	return pnp_get_resource(dev, IORESOURCE_MEM, bar)->start;
+}
+
+static inline resource_size_t pnp_mem_end(struct pnp_dev *dev,
+					  unsigned int bar)
+{
+	return pnp_get_resource(dev, IORESOURCE_MEM, bar)->end;
+}
+
+static inline resource_size_t pnp_mem_flags(struct pnp_dev *dev,
+					    unsigned int bar)
+{
+	return pnp_get_resource(dev, IORESOURCE_MEM, bar)->flags;
+}
+
+static inline int pnp_mem_valid(struct pnp_dev *dev, unsigned int bar)
+{
+	return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_MEM, bar));
+}
+
+static inline resource_size_t pnp_mem_len(struct pnp_dev *dev,
+					  unsigned int bar)
+{
+	return pnp_resource_len(pnp_get_resource(dev, IORESOURCE_MEM, bar));
+}
+
+
+static inline resource_size_t pnp_irq(struct pnp_dev *dev, unsigned int bar)
+{
+	return pnp_get_resource(dev, IORESOURCE_IRQ, bar)->start;
+}
+
+static inline resource_size_t pnp_irq_flags(struct pnp_dev *dev,
+					    unsigned int bar)
+{
+	return pnp_get_resource(dev, IORESOURCE_IRQ, bar)->flags;
+}
+
+static inline int pnp_irq_valid(struct pnp_dev *dev, unsigned int bar)
+{
+	return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_IRQ, bar));
+}
+
+
+static inline resource_size_t pnp_dma(struct pnp_dev *dev, unsigned int bar)
+{
+	return pnp_get_resource(dev, IORESOURCE_DMA, bar)->start;
+}
+
+static inline resource_size_t pnp_dma_flags(struct pnp_dev *dev,
+					    unsigned int bar)
+{
+	return pnp_get_resource(dev, IORESOURCE_DMA, bar)->flags;
+}
+
+static inline int pnp_dma_valid(struct pnp_dev *dev, unsigned int bar)
+{
+	return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_DMA, bar));
+}
+
 
 #define PNP_PORT_FLAG_16BITADDR	(1<<0)
 #define PNP_PORT_FLAG_FIXED	(1<<1)

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 26/53] PNP: use conventional "i" for loop indices
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (24 preceding siblings ...)
  2008-04-18 20:50 ` [patch 25/53] PNP: convert resource accessors to use pnp_get_resource(), not pnp_resource_table Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 27/53] PNP: convert resource checks to use pnp_get_resource(), not pnp_resource_table Bjorn Helgaas
                   ` (26 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, Rene Herman, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-rename-temps --]
[-- Type: text/plain, Size: 6636 bytes --]

Cosmetic only: just use "i" instead of "tmp".

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: Rene Herman <rene.herman@gmail.com>

Index: work7/drivers/pnp/resource.c
===================================================================
--- work7.orig/drivers/pnp/resource.c	2008-03-24 16:32:00.000000000 -0600
+++ work7/drivers/pnp/resource.c	2008-03-24 16:33:17.000000000 -0600
@@ -215,7 +215,7 @@
 
 int pnp_check_port(struct pnp_dev *dev, int idx)
 {
-	int tmp;
+	int i;
 	struct pnp_dev *tdev;
 	resource_size_t *port, *end, *tport, *tend;
 
@@ -234,18 +234,18 @@
 	}
 
 	/* check if the resource is reserved */
-	for (tmp = 0; tmp < 8; tmp++) {
-		int rport = pnp_reserve_io[tmp << 1];
-		int rend = pnp_reserve_io[(tmp << 1) + 1] + rport - 1;
+	for (i = 0; i < 8; i++) {
+		int rport = pnp_reserve_io[i << 1];
+		int rend = pnp_reserve_io[(i << 1) + 1] + rport - 1;
 		if (ranged_conflict(port, end, &rport, &rend))
 			return 0;
 	}
 
 	/* check for internal conflicts */
-	for (tmp = 0; tmp < PNP_MAX_PORT && tmp != idx; tmp++) {
-		if (dev->res.port_resource[tmp].flags & IORESOURCE_IO) {
-			tport = &dev->res.port_resource[tmp].start;
-			tend = &dev->res.port_resource[tmp].end;
+	for (i = 0; i < PNP_MAX_PORT && i != idx; i++) {
+		if (dev->res.port_resource[i].flags & IORESOURCE_IO) {
+			tport = &dev->res.port_resource[i].start;
+			tend = &dev->res.port_resource[i].end;
 			if (ranged_conflict(port, end, tport, tend))
 				return 0;
 		}
@@ -255,13 +255,13 @@
 	pnp_for_each_dev(tdev) {
 		if (tdev == dev)
 			continue;
-		for (tmp = 0; tmp < PNP_MAX_PORT; tmp++) {
-			if (tdev->res.port_resource[tmp].flags & IORESOURCE_IO) {
+		for (i = 0; i < PNP_MAX_PORT; i++) {
+			if (tdev->res.port_resource[i].flags & IORESOURCE_IO) {
 				if (cannot_compare
-				    (tdev->res.port_resource[tmp].flags))
+				    (tdev->res.port_resource[i].flags))
 					continue;
-				tport = &tdev->res.port_resource[tmp].start;
-				tend = &tdev->res.port_resource[tmp].end;
+				tport = &tdev->res.port_resource[i].start;
+				tend = &tdev->res.port_resource[i].end;
 				if (ranged_conflict(port, end, tport, tend))
 					return 0;
 			}
@@ -273,7 +273,7 @@
 
 int pnp_check_mem(struct pnp_dev *dev, int idx)
 {
-	int tmp;
+	int i;
 	struct pnp_dev *tdev;
 	resource_size_t *addr, *end, *taddr, *tend;
 
@@ -292,18 +292,18 @@
 	}
 
 	/* check if the resource is reserved */
-	for (tmp = 0; tmp < 8; tmp++) {
-		int raddr = pnp_reserve_mem[tmp << 1];
-		int rend = pnp_reserve_mem[(tmp << 1) + 1] + raddr - 1;
+	for (i = 0; i < 8; i++) {
+		int raddr = pnp_reserve_mem[i << 1];
+		int rend = pnp_reserve_mem[(i << 1) + 1] + raddr - 1;
 		if (ranged_conflict(addr, end, &raddr, &rend))
 			return 0;
 	}
 
 	/* check for internal conflicts */
-	for (tmp = 0; tmp < PNP_MAX_MEM && tmp != idx; tmp++) {
-		if (dev->res.mem_resource[tmp].flags & IORESOURCE_MEM) {
-			taddr = &dev->res.mem_resource[tmp].start;
-			tend = &dev->res.mem_resource[tmp].end;
+	for (i = 0; i < PNP_MAX_MEM && i != idx; i++) {
+		if (dev->res.mem_resource[i].flags & IORESOURCE_MEM) {
+			taddr = &dev->res.mem_resource[i].start;
+			tend = &dev->res.mem_resource[i].end;
 			if (ranged_conflict(addr, end, taddr, tend))
 				return 0;
 		}
@@ -313,13 +313,13 @@
 	pnp_for_each_dev(tdev) {
 		if (tdev == dev)
 			continue;
-		for (tmp = 0; tmp < PNP_MAX_MEM; tmp++) {
-			if (tdev->res.mem_resource[tmp].flags & IORESOURCE_MEM) {
+		for (i = 0; i < PNP_MAX_MEM; i++) {
+			if (tdev->res.mem_resource[i].flags & IORESOURCE_MEM) {
 				if (cannot_compare
-				    (tdev->res.mem_resource[tmp].flags))
+				    (tdev->res.mem_resource[i].flags))
 					continue;
-				taddr = &tdev->res.mem_resource[tmp].start;
-				tend = &tdev->res.mem_resource[tmp].end;
+				taddr = &tdev->res.mem_resource[i].start;
+				tend = &tdev->res.mem_resource[i].end;
 				if (ranged_conflict(addr, end, taddr, tend))
 					return 0;
 			}
@@ -336,7 +336,7 @@
 
 int pnp_check_irq(struct pnp_dev *dev, int idx)
 {
-	int tmp;
+	int i;
 	struct pnp_dev *tdev;
 	resource_size_t *irq = &dev->res.irq_resource[idx].start;
 
@@ -349,15 +349,15 @@
 		return 0;
 
 	/* check if the resource is reserved */
-	for (tmp = 0; tmp < 16; tmp++) {
-		if (pnp_reserve_irq[tmp] == *irq)
+	for (i = 0; i < 16; i++) {
+		if (pnp_reserve_irq[i] == *irq)
 			return 0;
 	}
 
 	/* check for internal conflicts */
-	for (tmp = 0; tmp < PNP_MAX_IRQ && tmp != idx; tmp++) {
-		if (dev->res.irq_resource[tmp].flags & IORESOURCE_IRQ) {
-			if (dev->res.irq_resource[tmp].start == *irq)
+	for (i = 0; i < PNP_MAX_IRQ && i != idx; i++) {
+		if (dev->res.irq_resource[i].flags & IORESOURCE_IRQ) {
+			if (dev->res.irq_resource[i].start == *irq)
 				return 0;
 		}
 	}
@@ -388,12 +388,12 @@
 	pnp_for_each_dev(tdev) {
 		if (tdev == dev)
 			continue;
-		for (tmp = 0; tmp < PNP_MAX_IRQ; tmp++) {
-			if (tdev->res.irq_resource[tmp].flags & IORESOURCE_IRQ) {
+		for (i = 0; i < PNP_MAX_IRQ; i++) {
+			if (tdev->res.irq_resource[i].flags & IORESOURCE_IRQ) {
 				if (cannot_compare
-				    (tdev->res.irq_resource[tmp].flags))
+				    (tdev->res.irq_resource[i].flags))
 					continue;
-				if ((tdev->res.irq_resource[tmp].start == *irq))
+				if ((tdev->res.irq_resource[i].start == *irq))
 					return 0;
 			}
 		}
@@ -405,7 +405,7 @@
 int pnp_check_dma(struct pnp_dev *dev, int idx)
 {
 #ifndef CONFIG_IA64
-	int tmp;
+	int i;
 	struct pnp_dev *tdev;
 	resource_size_t *dma = &dev->res.dma_resource[idx].start;
 
@@ -418,15 +418,15 @@
 		return 0;
 
 	/* check if the resource is reserved */
-	for (tmp = 0; tmp < 8; tmp++) {
-		if (pnp_reserve_dma[tmp] == *dma)
+	for (i = 0; i < 8; i++) {
+		if (pnp_reserve_dma[i] == *dma)
 			return 0;
 	}
 
 	/* check for internal conflicts */
-	for (tmp = 0; tmp < PNP_MAX_DMA && tmp != idx; tmp++) {
-		if (dev->res.dma_resource[tmp].flags & IORESOURCE_DMA) {
-			if (dev->res.dma_resource[tmp].start == *dma)
+	for (i = 0; i < PNP_MAX_DMA && i != idx; i++) {
+		if (dev->res.dma_resource[i].flags & IORESOURCE_DMA) {
+			if (dev->res.dma_resource[i].start == *dma)
 				return 0;
 		}
 	}
@@ -443,12 +443,12 @@
 	pnp_for_each_dev(tdev) {
 		if (tdev == dev)
 			continue;
-		for (tmp = 0; tmp < PNP_MAX_DMA; tmp++) {
-			if (tdev->res.dma_resource[tmp].flags & IORESOURCE_DMA) {
+		for (i = 0; i < PNP_MAX_DMA; i++) {
+			if (tdev->res.dma_resource[i].flags & IORESOURCE_DMA) {
 				if (cannot_compare
-				    (tdev->res.dma_resource[tmp].flags))
+				    (tdev->res.dma_resource[i].flags))
 					continue;
-				if ((tdev->res.dma_resource[tmp].start == *dma))
+				if ((tdev->res.dma_resource[i].start == *dma))
 					return 0;
 			}
 		}

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 27/53] PNP: convert resource checks to use pnp_get_resource(), not pnp_resource_table
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (25 preceding siblings ...)
  2008-04-18 20:50 ` [patch 26/53] PNP: use conventional "i" for loop indices Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 28/53] PNP: convert resource assign functions " Bjorn Helgaas
                   ` (25 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-convert-checks-to-pnp_get_resource --]
[-- Type: text/plain, Size: 6810 bytes --]

This removes more direct references to pnp_resource_table.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>

---
 drivers/pnp/resource.c |   96 +++++++++++++++++++++++++++++--------------------
 1 file changed, 58 insertions(+), 38 deletions(-)

Index: work8/drivers/pnp/resource.c
===================================================================
--- work8.orig/drivers/pnp/resource.c	2008-04-10 13:59:17.000000000 -0600
+++ work8/drivers/pnp/resource.c	2008-04-10 15:23:34.000000000 -0600
@@ -216,16 +216,19 @@
 int pnp_check_port(struct pnp_dev *dev, int idx)
 {
 	int i;
+	struct resource *res, *tres;
 	struct pnp_dev *tdev;
 	resource_size_t *port, *end, *tport, *tend;
 
-	port = &dev->res.port_resource[idx].start;
-	end = &dev->res.port_resource[idx].end;
+	res = pnp_get_resource(dev, IORESOURCE_IO, idx);
 
 	/* if the resource doesn't exist, don't complain about it */
-	if (cannot_compare(dev->res.port_resource[idx].flags))
+	if (!res || cannot_compare(res->flags))
 		return 1;
 
+	port = &res->start;
+	end = &res->end;
+
 	/* check if the resource is already in use, skip if the
 	 * device is active because it itself may be in use */
 	if (!dev->active) {
@@ -243,9 +246,10 @@
 
 	/* check for internal conflicts */
 	for (i = 0; i < PNP_MAX_PORT && i != idx; i++) {
-		if (dev->res.port_resource[i].flags & IORESOURCE_IO) {
-			tport = &dev->res.port_resource[i].start;
-			tend = &dev->res.port_resource[i].end;
+		tres = pnp_get_resource(dev, IORESOURCE_IO, i);
+		if (tres && tres->flags & IORESOURCE_IO) {
+			tport = &tres->start;
+			tend = &tres->end;
 			if (ranged_conflict(port, end, tport, tend))
 				return 0;
 		}
@@ -256,12 +260,12 @@
 		if (tdev == dev)
 			continue;
 		for (i = 0; i < PNP_MAX_PORT; i++) {
-			if (tdev->res.port_resource[i].flags & IORESOURCE_IO) {
-				if (cannot_compare
-				    (tdev->res.port_resource[i].flags))
+			tres = pnp_get_resource(tdev, IORESOURCE_IO, i);
+			if (tres && tres->flags & IORESOURCE_IO) {
+				if (cannot_compare(tres->flags))
 					continue;
-				tport = &tdev->res.port_resource[i].start;
-				tend = &tdev->res.port_resource[i].end;
+				tport = &tres->start;
+				tend = &tres->end;
 				if (ranged_conflict(port, end, tport, tend))
 					return 0;
 			}
@@ -274,16 +278,19 @@
 int pnp_check_mem(struct pnp_dev *dev, int idx)
 {
 	int i;
+	struct resource *res, *tres;
 	struct pnp_dev *tdev;
 	resource_size_t *addr, *end, *taddr, *tend;
 
-	addr = &dev->res.mem_resource[idx].start;
-	end = &dev->res.mem_resource[idx].end;
+	res = pnp_get_resource(dev, IORESOURCE_MEM, idx);
 
 	/* if the resource doesn't exist, don't complain about it */
-	if (cannot_compare(dev->res.mem_resource[idx].flags))
+	if (!res || cannot_compare(res->flags))
 		return 1;
 
+	addr = &res->start;
+	end = &res->end;
+
 	/* check if the resource is already in use, skip if the
 	 * device is active because it itself may be in use */
 	if (!dev->active) {
@@ -301,9 +308,10 @@
 
 	/* check for internal conflicts */
 	for (i = 0; i < PNP_MAX_MEM && i != idx; i++) {
-		if (dev->res.mem_resource[i].flags & IORESOURCE_MEM) {
-			taddr = &dev->res.mem_resource[i].start;
-			tend = &dev->res.mem_resource[i].end;
+		tres = pnp_get_resource(dev, IORESOURCE_MEM, i);
+		if (tres && tres->flags & IORESOURCE_MEM) {
+			taddr = &tres->start;
+			tend = &tres->end;
 			if (ranged_conflict(addr, end, taddr, tend))
 				return 0;
 		}
@@ -314,12 +322,12 @@
 		if (tdev == dev)
 			continue;
 		for (i = 0; i < PNP_MAX_MEM; i++) {
-			if (tdev->res.mem_resource[i].flags & IORESOURCE_MEM) {
-				if (cannot_compare
-				    (tdev->res.mem_resource[i].flags))
+			tres = pnp_get_resource(tdev, IORESOURCE_MEM, i);
+			if (tres && tres->flags & IORESOURCE_MEM) {
+				if (cannot_compare(tres->flags))
 					continue;
-				taddr = &tdev->res.mem_resource[i].start;
-				tend = &tdev->res.mem_resource[i].end;
+				taddr = &tres->start;
+				tend = &tres->end;
 				if (ranged_conflict(addr, end, taddr, tend))
 					return 0;
 			}
@@ -337,13 +345,18 @@
 int pnp_check_irq(struct pnp_dev *dev, int idx)
 {
 	int i;
+	struct resource *res, *tres;
 	struct pnp_dev *tdev;
-	resource_size_t *irq = &dev->res.irq_resource[idx].start;
+	resource_size_t *irq;
+
+	res = pnp_get_resource(dev, IORESOURCE_IRQ, idx);
 
 	/* if the resource doesn't exist, don't complain about it */
-	if (cannot_compare(dev->res.irq_resource[idx].flags))
+	if (!res || cannot_compare(res->flags))
 		return 1;
 
+	irq = &res->start;
+
 	/* check if the resource is valid */
 	if (*irq < 0 || *irq > 15)
 		return 0;
@@ -356,8 +369,9 @@
 
 	/* check for internal conflicts */
 	for (i = 0; i < PNP_MAX_IRQ && i != idx; i++) {
-		if (dev->res.irq_resource[i].flags & IORESOURCE_IRQ) {
-			if (dev->res.irq_resource[i].start == *irq)
+		tres = pnp_get_resource(dev, IORESOURCE_IRQ, i);
+		if (tres && tres->flags & IORESOURCE_IRQ) {
+			if (tres->start == *irq)
 				return 0;
 		}
 	}
@@ -389,11 +403,11 @@
 		if (tdev == dev)
 			continue;
 		for (i = 0; i < PNP_MAX_IRQ; i++) {
-			if (tdev->res.irq_resource[i].flags & IORESOURCE_IRQ) {
-				if (cannot_compare
-				    (tdev->res.irq_resource[i].flags))
+			tres = pnp_get_resource(tdev, IORESOURCE_IRQ, i);
+			if (tres && tres->flags & IORESOURCE_IRQ) {
+				if (cannot_compare(tres->flags))
 					continue;
-				if ((tdev->res.irq_resource[i].start == *irq))
+				if (tres->start == *irq)
 					return 0;
 			}
 		}
@@ -406,13 +420,18 @@
 {
 #ifndef CONFIG_IA64
 	int i;
+	struct resource *res, *tres;
 	struct pnp_dev *tdev;
-	resource_size_t *dma = &dev->res.dma_resource[idx].start;
+	resource_size_t *dma;
+
+	res = pnp_get_resource(dev, IORESOURCE_DMA, idx);
 
 	/* if the resource doesn't exist, don't complain about it */
-	if (cannot_compare(dev->res.dma_resource[idx].flags))
+	if (!res || cannot_compare(res->flags))
 		return 1;
 
+	dma = &res->start;
+
 	/* check if the resource is valid */
 	if (*dma < 0 || *dma == 4 || *dma > 7)
 		return 0;
@@ -425,8 +444,9 @@
 
 	/* check for internal conflicts */
 	for (i = 0; i < PNP_MAX_DMA && i != idx; i++) {
-		if (dev->res.dma_resource[i].flags & IORESOURCE_DMA) {
-			if (dev->res.dma_resource[i].start == *dma)
+		tres = pnp_get_resource(dev, IORESOURCE_DMA, i);
+		if (tres && tres->flags & IORESOURCE_DMA) {
+			if (tres->start == *dma)
 				return 0;
 		}
 	}
@@ -444,11 +464,11 @@
 		if (tdev == dev)
 			continue;
 		for (i = 0; i < PNP_MAX_DMA; i++) {
-			if (tdev->res.dma_resource[i].flags & IORESOURCE_DMA) {
-				if (cannot_compare
-				    (tdev->res.dma_resource[i].flags))
+			tres = pnp_get_resource(tdev, IORESOURCE_DMA, i);
+			if (tres && tres->flags & IORESOURCE_DMA) {
+				if (cannot_compare(tres->flags))
 					continue;
-				if ((tdev->res.dma_resource[i].start == *dma))
+				if (tres->start == *dma)
 					return 0;
 			}
 		}

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 28/53] PNP: convert resource assign functions to use pnp_get_resource(), not pnp_resource_table
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (26 preceding siblings ...)
  2008-04-18 20:50 ` [patch 27/53] PNP: convert resource checks to use pnp_get_resource(), not pnp_resource_table Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 29/53] PNP: convert sysfs interface " Bjorn Helgaas
                   ` (24 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, Rene Herman, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-convert-assign-to-pnp_get_resource --]
[-- Type: text/plain, Size: 4004 bytes --]

This removes more direct references to pnp_resource_table.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: Rene Herman <rene.herman@gmail.com>

Index: work8/drivers/pnp/manager.c
===================================================================
--- work8.orig/drivers/pnp/manager.c	2008-04-10 15:20:30.000000000 -0600
+++ work8/drivers/pnp/manager.c	2008-04-10 15:36:06.000000000 -0600
@@ -19,22 +19,24 @@
 
 static int pnp_assign_port(struct pnp_dev *dev, struct pnp_port *rule, int idx)
 {
+	struct resource *res;
 	resource_size_t *start, *end;
 	unsigned long *flags;
 
-	if (idx >= PNP_MAX_PORT) {
+	res = pnp_get_resource(dev, IORESOURCE_IO, idx);
+	if (!res) {
 		dev_err(&dev->dev, "too many I/O port resources\n");
 		/* pretend we were successful so at least the manager won't try again */
 		return 1;
 	}
 
 	/* check if this resource has been manually set, if so skip */
-	if (!(dev->res.port_resource[idx].flags & IORESOURCE_AUTO))
+	if (!(res->flags & IORESOURCE_AUTO))
 		return 1;
 
-	start = &dev->res.port_resource[idx].start;
-	end = &dev->res.port_resource[idx].end;
-	flags = &dev->res.port_resource[idx].flags;
+	start = &res->start;
+	end = &res->end;
+	flags = &res->flags;
 
 	/* set the initial values */
 	*flags |= rule->flags | IORESOURCE_IO;
@@ -60,22 +62,24 @@
 
 static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx)
 {
+	struct resource *res;
 	resource_size_t *start, *end;
 	unsigned long *flags;
 
-	if (idx >= PNP_MAX_MEM) {
+	res = pnp_get_resource(dev, IORESOURCE_MEM, idx);
+	if (!res) {
 		dev_err(&dev->dev, "too many memory resources\n");
 		/* pretend we were successful so at least the manager won't try again */
 		return 1;
 	}
 
 	/* check if this resource has been manually set, if so skip */
-	if (!(dev->res.mem_resource[idx].flags & IORESOURCE_AUTO))
+	if (!(res->flags & IORESOURCE_AUTO))
 		return 1;
 
-	start = &dev->res.mem_resource[idx].start;
-	end = &dev->res.mem_resource[idx].end;
-	flags = &dev->res.mem_resource[idx].flags;
+	start = &res->start;
+	end = &res->end;
+	flags = &res->flags;
 
 	/* set the initial values */
 	*flags |= rule->flags | IORESOURCE_MEM;
@@ -111,6 +115,7 @@
 
 static int pnp_assign_irq(struct pnp_dev *dev, struct pnp_irq *rule, int idx)
 {
+	struct resource *res;
 	resource_size_t *start, *end;
 	unsigned long *flags;
 	int i;
@@ -120,19 +125,20 @@
 		5, 10, 11, 12, 9, 14, 15, 7, 3, 4, 13, 0, 1, 6, 8, 2
 	};
 
-	if (idx >= PNP_MAX_IRQ) {
+	res = pnp_get_resource(dev, IORESOURCE_IRQ, idx);
+	if (!res) {
 		dev_err(&dev->dev, "too many IRQ resources\n");
 		/* pretend we were successful so at least the manager won't try again */
 		return 1;
 	}
 
 	/* check if this resource has been manually set, if so skip */
-	if (!(dev->res.irq_resource[idx].flags & IORESOURCE_AUTO))
+	if (!(res->flags & IORESOURCE_AUTO))
 		return 1;
 
-	start = &dev->res.irq_resource[idx].start;
-	end = &dev->res.irq_resource[idx].end;
-	flags = &dev->res.irq_resource[idx].flags;
+	start = &res->start;
+	end = &res->end;
+	flags = &res->flags;
 
 	/* set the initial values */
 	*flags |= rule->flags | IORESOURCE_IRQ;
@@ -161,6 +167,7 @@
 
 static void pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx)
 {
+	struct resource *res;
 	resource_size_t *start, *end;
 	unsigned long *flags;
 	int i;
@@ -170,18 +177,19 @@
 		1, 3, 5, 6, 7, 0, 2, 4
 	};
 
-	if (idx >= PNP_MAX_DMA) {
+	res = pnp_get_resource(dev, IORESOURCE_DMA, idx);
+	if (!res) {
 		dev_err(&dev->dev, "too many DMA resources\n");
 		return;
 	}
 
 	/* check if this resource has been manually set, if so skip */
-	if (!(dev->res.dma_resource[idx].flags & IORESOURCE_AUTO))
+	if (!(res->flags & IORESOURCE_AUTO))
 		return;
 
-	start = &dev->res.dma_resource[idx].start;
-	end = &dev->res.dma_resource[idx].end;
-	flags = &dev->res.dma_resource[idx].flags;
+	start = &res->start;
+	end = &res->end;
+	flags = &res->flags;
 
 	/* set the initial values */
 	*flags |= rule->flags | IORESOURCE_DMA;

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 29/53] PNP: convert sysfs interface to use pnp_get_resource(), not pnp_resource_table
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (27 preceding siblings ...)
  2008-04-18 20:50 ` [patch 28/53] PNP: convert resource assign functions " Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 30/53] PNP: convert resource initializers " Bjorn Helgaas
                   ` (23 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-convert-proc-to-pnp_get_resource --]
[-- Type: text/plain, Size: 3618 bytes --]

This removes more direct references to pnp_resource_table.

Note that this does not allow adding new resources beyond the
preallocated ones, so even though it does not reference
pnp_resource_table directly, it is still limited to the
fixed size of that table.  When the preallocation is removed,
we'll have to change this so it can add new resources.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>

Index: work8/drivers/pnp/interface.c
===================================================================
--- work8.orig/drivers/pnp/interface.c	2008-04-10 16:09:39.000000000 -0600
+++ work8/drivers/pnp/interface.c	2008-04-10 16:15:48.000000000 -0600
@@ -323,6 +323,7 @@
 			  const char *ubuf, size_t count)
 {
 	struct pnp_dev *dev = to_pnp_dev(dmdev);
+	struct resource *res;
 	char *buf = (void *)ubuf;
 	int retval = 0;
 
@@ -382,76 +383,72 @@
 				buf += 2;
 				while (isspace(*buf))
 					++buf;
-				dev->res.port_resource[nport].start =
-				    simple_strtoul(buf, &buf, 0);
+				res = pnp_get_resource(dev, IORESOURCE_IO,
+						       nport);
+				if (!res)
+					break;
+				res->start = simple_strtoul(buf, &buf, 0);
 				while (isspace(*buf))
 					++buf;
 				if (*buf == '-') {
 					buf += 1;
 					while (isspace(*buf))
 						++buf;
-					dev->res.port_resource[nport].end =
-					    simple_strtoul(buf, &buf, 0);
+					res->end = simple_strtoul(buf, &buf, 0);
 				} else
-					dev->res.port_resource[nport].end =
-					    dev->res.port_resource[nport].start;
-				dev->res.port_resource[nport].flags =
-				    IORESOURCE_IO;
+					res->end = res->start;
+				res->flags = IORESOURCE_IO;
 				nport++;
-				if (nport >= PNP_MAX_PORT)
-					break;
 				continue;
 			}
 			if (!strnicmp(buf, "mem", 3)) {
 				buf += 3;
 				while (isspace(*buf))
 					++buf;
-				dev->res.mem_resource[nmem].start =
-				    simple_strtoul(buf, &buf, 0);
+				res = pnp_get_resource(dev, IORESOURCE_MEM,
+						       nmem);
+				if (!res)
+					break;
+				res->start = simple_strtoul(buf, &buf, 0);
 				while (isspace(*buf))
 					++buf;
 				if (*buf == '-') {
 					buf += 1;
 					while (isspace(*buf))
 						++buf;
-					dev->res.mem_resource[nmem].end =
-					    simple_strtoul(buf, &buf, 0);
+					res->end = simple_strtoul(buf, &buf, 0);
 				} else
-					dev->res.mem_resource[nmem].end =
-					    dev->res.mem_resource[nmem].start;
-				dev->res.mem_resource[nmem].flags =
-				    IORESOURCE_MEM;
+					res->end = res->start;
+				res->flags = IORESOURCE_MEM;
 				nmem++;
-				if (nmem >= PNP_MAX_MEM)
-					break;
 				continue;
 			}
 			if (!strnicmp(buf, "irq", 3)) {
 				buf += 3;
 				while (isspace(*buf))
 					++buf;
-				dev->res.irq_resource[nirq].start =
-				    dev->res.irq_resource[nirq].end =
+				res = pnp_get_resource(dev, IORESOURCE_IRQ,
+						       nirq);
+				if (!res)
+					break;
+				res->start = res->end =
 				    simple_strtoul(buf, &buf, 0);
-				dev->res.irq_resource[nirq].flags =
-				    IORESOURCE_IRQ;
+				res->flags = IORESOURCE_IRQ;
 				nirq++;
-				if (nirq >= PNP_MAX_IRQ)
-					break;
 				continue;
 			}
 			if (!strnicmp(buf, "dma", 3)) {
 				buf += 3;
 				while (isspace(*buf))
 					++buf;
-				dev->res.dma_resource[ndma].start =
-				    dev->res.dma_resource[ndma].end =
+				res = pnp_get_resource(dev, IORESOURCE_DMA,
+						       ndma);
+				if (!res)
+					break;
+				res->start = res->end =
 				    simple_strtoul(buf, &buf, 0);
-				dev->res.dma_resource[ndma].flags =
-				    IORESOURCE_DMA;
+				res->flags = IORESOURCE_DMA;
 				ndma++;
-				if (ndma >= PNP_MAX_DMA)
-					break;
 				continue;
 			}
 			break;

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 30/53] PNP: convert resource initializers to use pnp_get_resource(), not pnp_resource_table
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (28 preceding siblings ...)
  2008-04-18 20:50 ` [patch 29/53] PNP: convert sysfs interface " Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 31/53] PNP: convert encoders " Bjorn Helgaas
                   ` (22 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-convert-inits-to-pnp_get_resource --]
[-- Type: text/plain, Size: 2657 bytes --]

This removes more direct references to pnp_resource_table.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>

Index: work8/drivers/pnp/manager.c
===================================================================
--- work8.orig/drivers/pnp/manager.c	2008-04-10 16:50:03.000000000 -0600
+++ work8/drivers/pnp/manager.c	2008-04-10 16:59:08.000000000 -0600
@@ -232,17 +232,17 @@
  */
 void pnp_init_resources(struct pnp_dev *dev)
 {
-	struct pnp_resource_table *table = &dev->res;
-	int idx;
+	struct resource *res;
+	int i;
 
-	for (idx = 0; idx < PNP_MAX_IRQ; idx++)
-		pnp_init_resource(&table->irq_resource[idx]);
-	for (idx = 0; idx < PNP_MAX_DMA; idx++)
-		pnp_init_resource(&table->dma_resource[idx]);
-	for (idx = 0; idx < PNP_MAX_PORT; idx++)
-		pnp_init_resource(&table->port_resource[idx]);
-	for (idx = 0; idx < PNP_MAX_MEM; idx++)
-		pnp_init_resource(&table->mem_resource[idx]);
+	for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IRQ, i)); i++)
+		pnp_init_resource(res);
+	for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_DMA, i)); i++)
+		pnp_init_resource(res);
+	for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IO, i)); i++)
+		pnp_init_resource(res);
+	for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++)
+		pnp_init_resource(res);
 }
 
 /**
@@ -251,24 +251,24 @@
  */
 static void pnp_clean_resource_table(struct pnp_dev *dev)
 {
-	struct pnp_resource_table *table = &dev->res;
-	int idx;
+	struct resource *res;
+	int i;
 
-	for (idx = 0; idx < PNP_MAX_IRQ; idx++) {
-		if (table->irq_resource[idx].flags & IORESOURCE_AUTO)
-			pnp_init_resource(&table->irq_resource[idx]);
-	}
-	for (idx = 0; idx < PNP_MAX_DMA; idx++) {
-		if (table->dma_resource[idx].flags & IORESOURCE_AUTO)
-			pnp_init_resource(&table->dma_resource[idx]);
-	}
-	for (idx = 0; idx < PNP_MAX_PORT; idx++) {
-		if (table->port_resource[idx].flags & IORESOURCE_AUTO)
-			pnp_init_resource(&table->port_resource[idx]);
-	}
-	for (idx = 0; idx < PNP_MAX_MEM; idx++) {
-		if (table->mem_resource[idx].flags & IORESOURCE_AUTO)
-			pnp_init_resource(&table->mem_resource[idx]);
+	for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IRQ, i)); i++) {
+		if (res->flags & IORESOURCE_AUTO)
+			pnp_init_resource(res);
+	}
+	for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_DMA, i)); i++) {
+		if (res->flags & IORESOURCE_AUTO)
+			pnp_init_resource(res);
+	}
+	for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IO, i)); i++) {
+		if (res->flags & IORESOURCE_AUTO)
+			pnp_init_resource(res);
+	}
+	for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) {
+		if (res->flags & IORESOURCE_AUTO)
+			pnp_init_resource(res);
 	}
 }
 

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 31/53] PNP: convert encoders to use pnp_get_resource(), not pnp_resource_table
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (29 preceding siblings ...)
  2008-04-18 20:50 ` [patch 30/53] PNP: convert resource initializers " Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 32/53] PNP: remove PNP_MAX_* uses Bjorn Helgaas
                   ` (21 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-convert-encoders-to-pnp_get_resource --]
[-- Type: text/plain, Size: 4761 bytes --]

This removes more direct references to pnp_resource_table.  This
path is used when telling a device what resources it should use.

This doesn't convert ISAPNP because ISA needs to know the config
register index in addition to the resource itself.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>

Index: work8/drivers/pnp/pnpacpi/rsparser.c
===================================================================
--- work8.orig/drivers/pnp/pnpacpi/rsparser.c	2008-04-17 14:51:52.000000000 -0600
+++ work8/drivers/pnp/pnpacpi/rsparser.c	2008-04-17 14:54:45.000000000 -0600
@@ -954,7 +954,6 @@
 
 int pnpacpi_encode_resources(struct pnp_dev *dev, struct acpi_buffer *buffer)
 {
-	struct pnp_resource_table *res_table = &dev->res;
 	int i = 0;
 	/* pnpacpi_build_resource_template allocates extra mem */
 	int res_cnt = (buffer->length - 1) / sizeof(struct acpi_resource) - 1;
@@ -967,52 +966,50 @@
 		case ACPI_RESOURCE_TYPE_IRQ:
 			pnp_dbg("Encode irq");
 			pnpacpi_encode_irq(resource,
-					   &res_table->irq_resource[irq]);
+				pnp_get_resource(dev, IORESOURCE_IRQ, irq));
 			irq++;
 			break;
 
 		case ACPI_RESOURCE_TYPE_DMA:
 			pnp_dbg("Encode dma");
 			pnpacpi_encode_dma(resource,
-					   &res_table->dma_resource[dma]);
+				pnp_get_resource(dev, IORESOURCE_DMA, dma));
 			dma++;
 			break;
 		case ACPI_RESOURCE_TYPE_IO:
 			pnp_dbg("Encode io");
 			pnpacpi_encode_io(resource,
-					  &res_table->port_resource[port]);
+				pnp_get_resource(dev, IORESOURCE_IO, port));
 			port++;
 			break;
 		case ACPI_RESOURCE_TYPE_FIXED_IO:
 			pnp_dbg("Encode fixed io");
 			pnpacpi_encode_fixed_io(resource,
-						&res_table->
-						port_resource[port]);
+				pnp_get_resource(dev, IORESOURCE_IO, port));
 			port++;
 			break;
 		case ACPI_RESOURCE_TYPE_MEMORY24:
 			pnp_dbg("Encode mem24");
 			pnpacpi_encode_mem24(resource,
-					     &res_table->mem_resource[mem]);
+				pnp_get_resource(dev, IORESOURCE_MEM, mem));
 			mem++;
 			break;
 		case ACPI_RESOURCE_TYPE_MEMORY32:
 			pnp_dbg("Encode mem32");
 			pnpacpi_encode_mem32(resource,
-					     &res_table->mem_resource[mem]);
+				pnp_get_resource(dev, IORESOURCE_MEM, mem));
 			mem++;
 			break;
 		case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
 			pnp_dbg("Encode fixed mem32");
 			pnpacpi_encode_fixed_mem32(resource,
-						   &res_table->
-						   mem_resource[mem]);
+				pnp_get_resource(dev, IORESOURCE_MEM, mem));
 			mem++;
 			break;
 		case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
 			pnp_dbg("Encode ext irq");
 			pnpacpi_encode_ext_irq(resource,
-					       &res_table->irq_resource[irq]);
+				pnp_get_resource(dev, IORESOURCE_IRQ, irq));
 			irq++;
 			break;
 		case ACPI_RESOURCE_TYPE_START_DEPENDENT:
Index: work8/drivers/pnp/pnpbios/rsparser.c
===================================================================
--- work8.orig/drivers/pnp/pnpbios/rsparser.c	2008-04-17 14:51:52.000000000 -0600
+++ work8/drivers/pnp/pnpbios/rsparser.c	2008-04-17 14:53:00.000000000 -0600
@@ -650,7 +650,6 @@
 							     unsigned char *p,
 							     unsigned char *end)
 {
-	struct pnp_resource_table *res = &dev->res;
 	unsigned int len, tag;
 	int port = 0, irq = 0, dma = 0, mem = 0;
 
@@ -673,42 +672,48 @@
 		case LARGE_TAG_MEM:
 			if (len != 9)
 				goto len_err;
-			pnpbios_encode_mem(p, &res->mem_resource[mem]);
+			pnpbios_encode_mem(p,
+				pnp_get_resource(dev, IORESOURCE_MEM, mem));
 			mem++;
 			break;
 
 		case LARGE_TAG_MEM32:
 			if (len != 17)
 				goto len_err;
-			pnpbios_encode_mem32(p, &res->mem_resource[mem]);
+			pnpbios_encode_mem32(p,
+				pnp_get_resource(dev, IORESOURCE_MEM, mem));
 			mem++;
 			break;
 
 		case LARGE_TAG_FIXEDMEM32:
 			if (len != 9)
 				goto len_err;
-			pnpbios_encode_fixed_mem32(p, &res->mem_resource[mem]);
+			pnpbios_encode_fixed_mem32(p,
+				pnp_get_resource(dev, IORESOURCE_MEM, mem));
 			mem++;
 			break;
 
 		case SMALL_TAG_IRQ:
 			if (len < 2 || len > 3)
 				goto len_err;
-			pnpbios_encode_irq(p, &res->irq_resource[irq]);
+			pnpbios_encode_irq(p,
+				pnp_get_resource(dev, IORESOURCE_IRQ, irq));
 			irq++;
 			break;
 
 		case SMALL_TAG_DMA:
 			if (len != 2)
 				goto len_err;
-			pnpbios_encode_dma(p, &res->dma_resource[dma]);
+			pnpbios_encode_dma(p,
+				pnp_get_resource(dev, IORESOURCE_DMA, dma));
 			dma++;
 			break;
 
 		case SMALL_TAG_PORT:
 			if (len != 7)
 				goto len_err;
-			pnpbios_encode_port(p, &res->port_resource[port]);
+			pnpbios_encode_port(p,
+				pnp_get_resource(dev, IORESOURCE_IO, port));
 			port++;
 			break;
 
@@ -719,7 +724,8 @@
 		case SMALL_TAG_FIXEDPORT:
 			if (len != 3)
 				goto len_err;
-			pnpbios_encode_fixed_port(p, &res->port_resource[port]);
+			pnpbios_encode_fixed_port(p,
+				pnp_get_resource(dev, IORESOURCE_IO, port));
 			port++;
 			break;
 

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 32/53] PNP: remove PNP_MAX_* uses
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (30 preceding siblings ...)
  2008-04-18 20:50 ` [patch 31/53] PNP: convert encoders " Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 33/53] rtc: dont reference pnp_resource_table directly Bjorn Helgaas
                   ` (20 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, Rene Herman, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-remove-max-uses --]
[-- Type: text/plain, Size: 9636 bytes --]

Remove some PNP_MAX_* uses.  The pnp_resource_table isn't
dynamic yet, but with pnp_get_resource(), we can start moving
away from the table size constants.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: Rene Herman <rene.herman@gmail.com>

---
 drivers/pnp/interface.c |   43 ++++++++++++++++++------------------
 drivers/pnp/quirks.c    |   13 ++++++-----
 drivers/pnp/resource.c  |   56 +++++++++++++++++++++++++++---------------------
 drivers/pnp/system.c    |   21 ++++++++----------
 4 files changed, 70 insertions(+), 63 deletions(-)

Index: work8/drivers/pnp/interface.c
===================================================================
--- work8.orig/drivers/pnp/interface.c	2008-04-10 16:21:52.000000000 -0600
+++ work8/drivers/pnp/interface.c	2008-04-10 16:28:56.000000000 -0600
@@ -243,11 +243,14 @@
 
 static DEVICE_ATTR(options, S_IRUGO, pnp_show_options, NULL);
 
+#define set(flags)      ((flags & IORESOURCE_UNSET) == 0)
+
 static ssize_t pnp_show_current_resources(struct device *dmdev,
 					  struct device_attribute *attr,
 					  char *buf)
 {
 	struct pnp_dev *dev = to_pnp_dev(dmdev);
+	struct resource *res;
 	int i, ret;
 	pnp_info_buffer_t *buffer;
 
@@ -267,50 +270,46 @@
 	else
 		pnp_printf(buffer, "disabled\n");
 
-	for (i = 0; i < PNP_MAX_PORT; i++) {
-		if (pnp_port_valid(dev, i)) {
+	for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IO, i)); i++) {
+		if (set(res->flags)) {
 			pnp_printf(buffer, "io");
-			if (pnp_port_flags(dev, i) & IORESOURCE_DISABLED)
+			if (res->flags & IORESOURCE_DISABLED)
 				pnp_printf(buffer, " disabled\n");
 			else
 				pnp_printf(buffer, " 0x%llx-0x%llx\n",
-					   (unsigned long long)
-					   pnp_port_start(dev, i),
-					   (unsigned long long)pnp_port_end(dev,
-									    i));
+					   (unsigned long long) res->start,
+					   (unsigned long long) res->end);
 		}
 	}
-	for (i = 0; i < PNP_MAX_MEM; i++) {
-		if (pnp_mem_valid(dev, i)) {
+	for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) {
+		if (set(res->flags)) {
 			pnp_printf(buffer, "mem");
-			if (pnp_mem_flags(dev, i) & IORESOURCE_DISABLED)
+			if (res->flags & IORESOURCE_DISABLED)
 				pnp_printf(buffer, " disabled\n");
 			else
 				pnp_printf(buffer, " 0x%llx-0x%llx\n",
-					   (unsigned long long)
-					   pnp_mem_start(dev, i),
-					   (unsigned long long)pnp_mem_end(dev,
-									   i));
+					   (unsigned long long) res->start,
+					   (unsigned long long) res->end);
 		}
 	}
-	for (i = 0; i < PNP_MAX_IRQ; i++) {
-		if (pnp_irq_valid(dev, i)) {
+	for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IRQ, i)); i++) {
+		if (set(res->flags)) {
 			pnp_printf(buffer, "irq");
-			if (pnp_irq_flags(dev, i) & IORESOURCE_DISABLED)
+			if (res->flags & IORESOURCE_DISABLED)
 				pnp_printf(buffer, " disabled\n");
 			else
 				pnp_printf(buffer, " %lld\n",
-					   (unsigned long long)pnp_irq(dev, i));
+					   (unsigned long long) res->start);
 		}
 	}
-	for (i = 0; i < PNP_MAX_DMA; i++) {
-		if (pnp_dma_valid(dev, i)) {
+	for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_DMA, i)); i++) {
+		if (set(res->flags)) {
 			pnp_printf(buffer, "dma");
-			if (pnp_dma_flags(dev, i) & IORESOURCE_DISABLED)
+			if (res->flags & IORESOURCE_DISABLED)
 				pnp_printf(buffer, " disabled\n");
 			else
 				pnp_printf(buffer, " %lld\n",
-					   (unsigned long long)pnp_dma(dev, i));
+					   (unsigned long long) res->start);
 		}
 	}
 	ret = (buffer->curr - buf);
Index: work8/drivers/pnp/quirks.c
===================================================================
--- work8.orig/drivers/pnp/quirks.c	2008-04-10 16:21:52.000000000 -0600
+++ work8/drivers/pnp/quirks.c	2008-04-10 16:22:08.000000000 -0600
@@ -135,13 +135,15 @@
 
 			pci_start = pci_resource_start(pdev, i);
 			pci_end = pci_resource_end(pdev, i);
-			for (j = 0; j < PNP_MAX_MEM; j++) {
-				if (!pnp_mem_valid(dev, j) ||
-				    pnp_mem_len(dev, j) == 0)
+			for (j = 0;
+			     (res = pnp_get_resource(dev, IORESOURCE_MEM, j));
+			     j++) {
+				if (res->flags & IORESOURCE_UNSET ||
+				    (res->start == 0 && res->end == 0))
 					continue;
 
-				pnp_start = pnp_mem_start(dev, j);
-				pnp_end = pnp_mem_end(dev, j);
+				pnp_start = res->start;
+				pnp_end = res->end;
 
 				/*
 				 * If the PNP region doesn't overlap the PCI
@@ -174,7 +176,6 @@
 					pci_name(pdev), i,
 					(unsigned long long) pci_start,
 					(unsigned long long) pci_end);
-				res = pnp_get_resource(dev, IORESOURCE_MEM, j);
 				res->flags = 0;
 			}
 		}
Index: work8/drivers/pnp/resource.c
===================================================================
--- work8.orig/drivers/pnp/resource.c	2008-04-10 16:21:52.000000000 -0600
+++ work8/drivers/pnp/resource.c	2008-04-10 16:43:37.000000000 -0600
@@ -245,9 +245,10 @@
 	}
 
 	/* check for internal conflicts */
-	for (i = 0; i < PNP_MAX_PORT && i != idx; i++) {
-		tres = pnp_get_resource(dev, IORESOURCE_IO, i);
-		if (tres && tres->flags & IORESOURCE_IO) {
+	for (i = 0;
+	     i != idx && (tres = pnp_get_resource(dev, IORESOURCE_IO, i));
+	     i++) {
+		if (tres->flags & IORESOURCE_IO) {
 			tport = &tres->start;
 			tend = &tres->end;
 			if (ranged_conflict(port, end, tport, tend))
@@ -259,9 +260,10 @@
 	pnp_for_each_dev(tdev) {
 		if (tdev == dev)
 			continue;
-		for (i = 0; i < PNP_MAX_PORT; i++) {
-			tres = pnp_get_resource(tdev, IORESOURCE_IO, i);
-			if (tres && tres->flags & IORESOURCE_IO) {
+		for (i = 0;
+		     (tres = pnp_get_resource(tdev, IORESOURCE_IO, i));
+		     i++) {
+			if (tres->flags & IORESOURCE_IO) {
 				if (cannot_compare(tres->flags))
 					continue;
 				tport = &tres->start;
@@ -307,9 +309,10 @@
 	}
 
 	/* check for internal conflicts */
-	for (i = 0; i < PNP_MAX_MEM && i != idx; i++) {
-		tres = pnp_get_resource(dev, IORESOURCE_MEM, i);
-		if (tres && tres->flags & IORESOURCE_MEM) {
+	for (i = 0;
+	     i != idx && (tres = pnp_get_resource(dev, IORESOURCE_MEM, i));
+	     i++) {
+		if (tres->flags & IORESOURCE_MEM) {
 			taddr = &tres->start;
 			tend = &tres->end;
 			if (ranged_conflict(addr, end, taddr, tend))
@@ -321,9 +324,10 @@
 	pnp_for_each_dev(tdev) {
 		if (tdev == dev)
 			continue;
-		for (i = 0; i < PNP_MAX_MEM; i++) {
-			tres = pnp_get_resource(tdev, IORESOURCE_MEM, i);
-			if (tres && tres->flags & IORESOURCE_MEM) {
+		for (i = 0;
+		     (tres = pnp_get_resource(tdev, IORESOURCE_MEM, i));
+		     i++) {
+			if (tres->flags & IORESOURCE_MEM) {
 				if (cannot_compare(tres->flags))
 					continue;
 				taddr = &tres->start;
@@ -368,9 +372,10 @@
 	}
 
 	/* check for internal conflicts */
-	for (i = 0; i < PNP_MAX_IRQ && i != idx; i++) {
-		tres = pnp_get_resource(dev, IORESOURCE_IRQ, i);
-		if (tres && tres->flags & IORESOURCE_IRQ) {
+	for (i = 0;
+	     i != idx && (tres = pnp_get_resource(dev, IORESOURCE_IRQ, i));
+	     i++) {
+		if (tres->flags & IORESOURCE_IRQ) {
 			if (tres->start == *irq)
 				return 0;
 		}
@@ -402,9 +407,10 @@
 	pnp_for_each_dev(tdev) {
 		if (tdev == dev)
 			continue;
-		for (i = 0; i < PNP_MAX_IRQ; i++) {
-			tres = pnp_get_resource(tdev, IORESOURCE_IRQ, i);
-			if (tres && tres->flags & IORESOURCE_IRQ) {
+		for (i = 0;
+		     (tres = pnp_get_resource(tdev, IORESOURCE_IRQ, i));
+		     i++) {
+			if (tres->flags & IORESOURCE_IRQ) {
 				if (cannot_compare(tres->flags))
 					continue;
 				if (tres->start == *irq)
@@ -443,9 +449,10 @@
 	}
 
 	/* check for internal conflicts */
-	for (i = 0; i < PNP_MAX_DMA && i != idx; i++) {
-		tres = pnp_get_resource(dev, IORESOURCE_DMA, i);
-		if (tres && tres->flags & IORESOURCE_DMA) {
+	for (i = 0;
+	     i != idx && (tres = pnp_get_resource(dev, IORESOURCE_DMA, i));
+	     i++) {
+		if (tres->flags & IORESOURCE_DMA) {
 			if (tres->start == *dma)
 				return 0;
 		}
@@ -463,9 +470,10 @@
 	pnp_for_each_dev(tdev) {
 		if (tdev == dev)
 			continue;
-		for (i = 0; i < PNP_MAX_DMA; i++) {
-			tres = pnp_get_resource(tdev, IORESOURCE_DMA, i);
-			if (tres && tres->flags & IORESOURCE_DMA) {
+		for (i = 0;
+		     (tres = pnp_get_resource(tdev, IORESOURCE_DMA, i));
+		     i++) {
+			if (tres->flags & IORESOURCE_DMA) {
 				if (cannot_compare(tres->flags))
 					continue;
 				if (tres->start == *dma)
Index: work8/drivers/pnp/system.c
===================================================================
--- work8.orig/drivers/pnp/system.c	2008-04-10 16:21:52.000000000 -0600
+++ work8/drivers/pnp/system.c	2008-04-10 16:22:08.000000000 -0600
@@ -56,14 +56,15 @@
 
 static void reserve_resources_of_dev(struct pnp_dev *dev)
 {
+	struct resource *res;
 	int i;
 
-	for (i = 0; i < PNP_MAX_PORT; i++) {
-		if (!pnp_port_valid(dev, i))
+	for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IO, i)); i++) {
+		if (res->flags & IORESOURCE_UNSET)
 			continue;
-		if (pnp_port_start(dev, i) == 0)
+		if (res->start == 0)
 			continue;	/* disabled */
-		if (pnp_port_start(dev, i) < 0x100)
+		if (res->start < 0x100)
 			/*
 			 * Below 0x100 is only standard PC hardware
 			 * (pics, kbd, timer, dma, ...)
@@ -73,19 +74,17 @@
 			 * So, do nothing
 			 */
 			continue;
-		if (pnp_port_end(dev, i) < pnp_port_start(dev, i))
+		if (res->end < res->start)
 			continue;	/* invalid */
 
-		reserve_range(dev, pnp_port_start(dev, i),
-			      pnp_port_end(dev, i), 1);
+		reserve_range(dev, res->start, res->end, 1);
 	}
 
-	for (i = 0; i < PNP_MAX_MEM; i++) {
-		if (!pnp_mem_valid(dev, i))
+	for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) {
+		if (res->flags & IORESOURCE_UNSET)
 			continue;
 
-		reserve_range(dev, pnp_mem_start(dev, i),
-			      pnp_mem_end(dev, i), 0);
+		reserve_range(dev, res->start, res->end, 0);
 	}
 }
 

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 33/53] rtc: dont reference pnp_resource_table directly
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (31 preceding siblings ...)
  2008-04-18 20:50 ` [patch 32/53] PNP: remove PNP_MAX_* uses Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 34/53] PNP: make pnp_resource_table private to PNP core Bjorn Helgaas
                   ` (19 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, Rene Herman, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: rtc-remove-pnp_resource_table-use --]
[-- Type: text/plain, Size: 966 bytes --]

pnp_resource_table is going away soon, so use the more
generic public interfaces instead.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: Rene Herman <rene.herman@gmail.com>

Index: work9/drivers/rtc/rtc-cmos.c
===================================================================
--- work9.orig/drivers/rtc/rtc-cmos.c	2008-04-18 12:47:21.000000000 -0600
+++ work9/drivers/rtc/rtc-cmos.c	2008-04-18 12:52:19.000000000 -0600
@@ -854,11 +854,12 @@
 		 * don't define the IRQ. It should always be safe to
 		 * hardcode it in these cases
 		 */
-		return cmos_do_probe(&pnp->dev, &pnp->res.port_resource[0], 8);
+		return cmos_do_probe(&pnp->dev,
+				pnp_get_resource(pnp, IORESOURCE_IO, 0), 8);
 	else
 		return cmos_do_probe(&pnp->dev,
-				     &pnp->res.port_resource[0],
-				     pnp->res.irq_resource[0].start);
+				pnp_get_resource(pnp, IORESOURCE_IO, 0),
+				pnp_irq(pnp, 0));
 }
 
 static void __exit cmos_pnp_remove(struct pnp_dev *pnp)

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 34/53] PNP: make pnp_resource_table private to PNP core
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (32 preceding siblings ...)
  2008-04-18 20:50 ` [patch 33/53] rtc: dont reference pnp_resource_table directly Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 35/53] PNP: remove pnp_resource_table references from resource decoders Bjorn Helgaas
                   ` (18 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-private-resource-table --]
[-- Type: text/plain, Size: 7203 bytes --]

There are no remaining references to the PNP_MAX_* constants or
the pnp_resource_table structure outside of the PNP core.  Make
them private to the PNP core.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>

---
 include/linux/pnp.h            |   14 ++------------
 drivers/pnp/base.h             |   12 ++++++++++++
 drivers/pnp/core.c             |    8 ++++++++
 drivers/pnp/isapnp/core.c      |    4 ++--
 drivers/pnp/pnpacpi/rsparser.c |   10 ++++++----
 drivers/pnp/pnpbios/rsparser.c |    8 ++++----
 drivers/pnp/resource.c         |    2 +-
 7 files changed, 35 insertions(+), 23 deletions(-)

Index: work8/include/linux/pnp.h
===================================================================
--- work8.orig/include/linux/pnp.h	2008-04-17 14:51:52.000000000 -0600
+++ work8/include/linux/pnp.h	2008-04-17 14:57:25.000000000 -0600
@@ -13,14 +13,11 @@
 #include <linux/errno.h>
 #include <linux/mod_devicetable.h>
 
-#define PNP_MAX_PORT		40
-#define PNP_MAX_MEM		24
-#define PNP_MAX_IRQ		2
-#define PNP_MAX_DMA		2
 #define PNP_NAME_LEN		50
 
 struct pnp_protocol;
 struct pnp_dev;
+struct pnp_resource_table;
 
 /*
  * Resource Management
@@ -187,13 +184,6 @@
 	struct pnp_option *next;	/* used to chain dependent resources */
 };
 
-struct pnp_resource_table {
-	struct resource port_resource[PNP_MAX_PORT];
-	struct resource mem_resource[PNP_MAX_MEM];
-	struct resource dma_resource[PNP_MAX_DMA];
-	struct resource irq_resource[PNP_MAX_IRQ];
-};
-
 /*
  * Device Management
  */
@@ -263,7 +253,7 @@
 	int capabilities;
 	struct pnp_option *independent;
 	struct pnp_option *dependent;
-	struct pnp_resource_table res;
+	struct pnp_resource_table *res;
 
 	char name[PNP_NAME_LEN];	/* contains a human-readable name */
 	unsigned short regs;		/* ISAPnP: supported registers */
Index: work8/drivers/pnp/base.h
===================================================================
--- work8.orig/drivers/pnp/base.h	2008-04-17 14:51:52.000000000 -0600
+++ work8/drivers/pnp/base.h	2008-04-17 14:57:25.000000000 -0600
@@ -18,3 +18,15 @@
 int pnp_check_dma(struct pnp_dev * dev, int idx);
 
 void pnp_init_resource(struct resource *res);
+
+#define PNP_MAX_PORT		40
+#define PNP_MAX_MEM		24
+#define PNP_MAX_IRQ		 2
+#define PNP_MAX_DMA		 2
+
+struct pnp_resource_table {
+	struct resource port_resource[PNP_MAX_PORT];
+	struct resource mem_resource[PNP_MAX_MEM];
+	struct resource dma_resource[PNP_MAX_DMA];
+	struct resource irq_resource[PNP_MAX_IRQ];
+};
Index: work8/drivers/pnp/core.c
===================================================================
--- work8.orig/drivers/pnp/core.c	2008-04-17 14:51:52.000000000 -0600
+++ work8/drivers/pnp/core.c	2008-04-17 14:57:25.000000000 -0600
@@ -106,6 +106,7 @@
 	pnp_free_option(dev->independent);
 	pnp_free_option(dev->dependent);
 	pnp_free_ids(dev);
+	kfree(dev->res);
 	kfree(dev);
 }
 
@@ -118,6 +119,12 @@
 	if (!dev)
 		return NULL;
 
+	dev->res = kzalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
+	if (!dev->res) {
+		kfree(dev);
+		return NULL;
+	}
+
 	dev->protocol = protocol;
 	dev->number = id;
 
@@ -127,6 +134,7 @@
 
 	dev_id = pnp_add_id(dev, pnpid);
 	if (!dev_id) {
+		kfree(dev->res);
 		kfree(dev);
 		return NULL;
 	}
Index: work8/drivers/pnp/isapnp/core.c
===================================================================
--- work8.orig/drivers/pnp/isapnp/core.c	2008-04-17 14:51:52.000000000 -0600
+++ work8/drivers/pnp/isapnp/core.c	2008-04-17 14:57:25.000000000 -0600
@@ -923,7 +923,7 @@
 
 static int isapnp_read_resources(struct pnp_dev *dev)
 {
-	struct pnp_resource_table *res = &dev->res;
+	struct pnp_resource_table *res = dev->res;
 	int tmp, ret;
 
 	dev->active = isapnp_read_byte(ISAPNP_CFG_ACTIVATE);
@@ -978,7 +978,7 @@
 
 static int isapnp_set_resources(struct pnp_dev *dev)
 {
-	struct pnp_resource_table *res = &dev->res;
+	struct pnp_resource_table *res = dev->res;
 	int tmp;
 
 	isapnp_cfg_begin(dev->card->number, dev->number);
Index: work8/drivers/pnp/pnpacpi/rsparser.c
===================================================================
--- work8.orig/drivers/pnp/pnpacpi/rsparser.c	2008-04-17 14:54:45.000000000 -0600
+++ work8/drivers/pnp/pnpacpi/rsparser.c	2008-04-17 14:57:25.000000000 -0600
@@ -21,6 +21,8 @@
 #include <linux/kernel.h>
 #include <linux/acpi.h>
 #include <linux/pci.h>
+#include <linux/pnp.h>
+#include "../base.h"
 #include "pnpacpi.h"
 
 #ifdef CONFIG_IA64
@@ -80,7 +82,7 @@
 						u32 gsi, int triggering,
 						int polarity, int shareable)
 {
-	struct pnp_resource_table *res = &dev->res;
+	struct pnp_resource_table *res = dev->res;
 	int i = 0;
 	int irq;
 	int p, t;
@@ -174,7 +176,7 @@
 static void pnpacpi_parse_allocated_dmaresource(struct pnp_dev *dev,
 						u32 dma, int flags)
 {
-	struct pnp_resource_table *res = &dev->res;
+	struct pnp_resource_table *res = dev->res;
 	int i = 0;
 	static unsigned char warned;
 
@@ -200,7 +202,7 @@
 static void pnpacpi_parse_allocated_ioresource(struct pnp_dev *dev,
 					       u64 io, u64 len, int io_decode)
 {
-	struct pnp_resource_table *res = &dev->res;
+	struct pnp_resource_table *res = dev->res;
 	int i = 0;
 	static unsigned char warned;
 
@@ -228,7 +230,7 @@
 						u64 mem, u64 len,
 						int write_protect)
 {
-	struct pnp_resource_table *res = &dev->res;
+	struct pnp_resource_table *res = dev->res;
 	int i = 0;
 	static unsigned char warned;
 
Index: work8/drivers/pnp/pnpbios/rsparser.c
===================================================================
--- work8.orig/drivers/pnp/pnpbios/rsparser.c	2008-04-17 14:53:00.000000000 -0600
+++ work8/drivers/pnp/pnpbios/rsparser.c	2008-04-17 14:57:25.000000000 -0600
@@ -56,7 +56,7 @@
 
 static void pnpbios_parse_allocated_irqresource(struct pnp_dev *dev, int irq)
 {
-	struct pnp_resource_table *res = &dev->res;
+	struct pnp_resource_table *res = dev->res;
 	int i = 0;
 
 	while (!(res->irq_resource[i].flags & IORESOURCE_UNSET)
@@ -76,7 +76,7 @@
 
 static void pnpbios_parse_allocated_dmaresource(struct pnp_dev *dev, int dma)
 {
-	struct pnp_resource_table *res = &dev->res;
+	struct pnp_resource_table *res = dev->res;
 	int i = 0;
 
 	while (i < PNP_MAX_DMA &&
@@ -96,7 +96,7 @@
 static void pnpbios_parse_allocated_ioresource(struct pnp_dev *dev,
 					       int io, int len)
 {
-	struct pnp_resource_table *res = &dev->res;
+	struct pnp_resource_table *res = dev->res;
 	int i = 0;
 
 	while (!(res->port_resource[i].flags & IORESOURCE_UNSET)
@@ -116,7 +116,7 @@
 static void pnpbios_parse_allocated_memresource(struct pnp_dev *dev,
 						int mem, int len)
 {
-	struct pnp_resource_table *res = &dev->res;
+	struct pnp_resource_table *res = dev->res;
 	int i = 0;
 
 	while (!(res->mem_resource[i].flags & IORESOURCE_UNSET)
Index: work8/drivers/pnp/resource.c
===================================================================
--- work8.orig/drivers/pnp/resource.c	2008-04-17 14:56:51.000000000 -0600
+++ work8/drivers/pnp/resource.c	2008-04-17 14:57:25.000000000 -0600
@@ -492,7 +492,7 @@
 struct resource *pnp_get_resource(struct pnp_dev *dev,
 				  unsigned int type, unsigned int num)
 {
-	struct pnp_resource_table *res = &dev->res;
+	struct pnp_resource_table *res = dev->res;
 
 	switch (type) {
 	case IORESOURCE_IO:

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 35/53] PNP: remove pnp_resource_table references from resource decoders
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (33 preceding siblings ...)
  2008-04-18 20:50 ` [patch 34/53] PNP: make pnp_resource_table private to PNP core Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 36/53] PNP: add struct pnp_resource Bjorn Helgaas
                   ` (17 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-remove-pnp_resource_table-from-decoders --]
[-- Type: text/plain, Size: 13535 bytes --]

This removes a few more references to the pnp_resource_table.
No functional change.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>

---
 drivers/pnp/isapnp/core.c      |   87 ++++++++++++++++++++--------------------
 drivers/pnp/pnpacpi/rsparser.c |   88 ++++++++++++++++++++++-------------------
 drivers/pnp/pnpbios/rsparser.c |   82 +++++++++++++++++++++-----------------
 3 files changed, 138 insertions(+), 119 deletions(-)

Index: work8/drivers/pnp/isapnp/core.c
===================================================================
--- work8.orig/drivers/pnp/isapnp/core.c	2008-04-17 15:00:51.000000000 -0600
+++ work8/drivers/pnp/isapnp/core.c	2008-04-17 15:02:30.000000000 -0600
@@ -923,7 +923,7 @@
 
 static int isapnp_read_resources(struct pnp_dev *dev)
 {
-	struct pnp_resource_table *res = dev->res;
+	struct resource *res;
 	int tmp, ret;
 
 	dev->active = isapnp_read_byte(ISAPNP_CFG_ACTIVATE);
@@ -932,16 +932,18 @@
 			ret = isapnp_read_word(ISAPNP_CFG_PORT + (tmp << 1));
 			if (!ret)
 				continue;
-			res->port_resource[tmp].start = ret;
-			res->port_resource[tmp].flags = IORESOURCE_IO;
+			res = &dev->res->port_resource[tmp];
+			res->start = ret;
+			res->flags = IORESOURCE_IO;
 		}
 		for (tmp = 0; tmp < ISAPNP_MAX_MEM; tmp++) {
 			ret =
 			    isapnp_read_word(ISAPNP_CFG_MEM + (tmp << 3)) << 8;
 			if (!ret)
 				continue;
-			res->mem_resource[tmp].start = ret;
-			res->mem_resource[tmp].flags = IORESOURCE_MEM;
+			res = &dev->res->mem_resource[tmp];
+			res->start = ret;
+			res->flags = IORESOURCE_MEM;
 		}
 		for (tmp = 0; tmp < ISAPNP_MAX_IRQ; tmp++) {
 			ret =
@@ -949,17 +951,17 @@
 			     8);
 			if (!ret)
 				continue;
-			res->irq_resource[tmp].start =
-			    res->irq_resource[tmp].end = ret;
-			res->irq_resource[tmp].flags = IORESOURCE_IRQ;
+			res = &dev->res->irq_resource[tmp];
+			res->start = res->end = ret;
+			res->flags = IORESOURCE_IRQ;
 		}
 		for (tmp = 0; tmp < ISAPNP_MAX_DMA; tmp++) {
 			ret = isapnp_read_byte(ISAPNP_CFG_DMA + tmp);
 			if (ret == 4)
 				continue;
-			res->dma_resource[tmp].start =
-			    res->dma_resource[tmp].end = ret;
-			res->dma_resource[tmp].flags = IORESOURCE_DMA;
+			res = &dev->res->dma_resource[tmp];
+			res->start = res->end = ret;
+			res->flags = IORESOURCE_DMA;
 		}
 	}
 	return 0;
@@ -978,42 +980,41 @@
 
 static int isapnp_set_resources(struct pnp_dev *dev)
 {
-	struct pnp_resource_table *res = dev->res;
+	struct resource *res;
 	int tmp;
 
 	isapnp_cfg_begin(dev->card->number, dev->number);
 	dev->active = 1;
-	for (tmp = 0;
-	     tmp < ISAPNP_MAX_PORT
-	     && (res->port_resource[tmp].
-		 flags & (IORESOURCE_IO | IORESOURCE_UNSET)) == IORESOURCE_IO;
-	     tmp++)
-		isapnp_write_word(ISAPNP_CFG_PORT + (tmp << 1),
-				  res->port_resource[tmp].start);
-	for (tmp = 0;
-	     tmp < ISAPNP_MAX_IRQ
-	     && (res->irq_resource[tmp].
-		 flags & (IORESOURCE_IRQ | IORESOURCE_UNSET)) == IORESOURCE_IRQ;
-	     tmp++) {
-		int irq = res->irq_resource[tmp].start;
-		if (irq == 2)
-			irq = 9;
-		isapnp_write_byte(ISAPNP_CFG_IRQ + (tmp << 1), irq);
-	}
-	for (tmp = 0;
-	     tmp < ISAPNP_MAX_DMA
-	     && (res->dma_resource[tmp].
-		 flags & (IORESOURCE_DMA | IORESOURCE_UNSET)) == IORESOURCE_DMA;
-	     tmp++)
-		isapnp_write_byte(ISAPNP_CFG_DMA + tmp,
-				  res->dma_resource[tmp].start);
-	for (tmp = 0;
-	     tmp < ISAPNP_MAX_MEM
-	     && (res->mem_resource[tmp].
-		 flags & (IORESOURCE_MEM | IORESOURCE_UNSET)) == IORESOURCE_MEM;
-	     tmp++)
-		isapnp_write_word(ISAPNP_CFG_MEM + (tmp << 3),
-				  (res->mem_resource[tmp].start >> 8) & 0xffff);
+	for (tmp = 0; tmp < ISAPNP_MAX_PORT; tmp++) {
+		res = &dev->res->port_resource[tmp];
+		if ((res->flags & (IORESOURCE_IO | IORESOURCE_UNSET)) ==
+				IORESOURCE_IO)
+			isapnp_write_word(ISAPNP_CFG_PORT + (tmp << 1),
+					  res->start);
+	}
+	for (tmp = 0; tmp < ISAPNP_MAX_IRQ; tmp++) {
+		res = &dev->res->irq_resource[tmp];
+		if ((res->flags & (IORESOURCE_IRQ | IORESOURCE_UNSET)) ==
+				IORESOURCE_IRQ) {
+			int irq = res->start;
+			if (irq == 2)
+				irq = 9;
+			isapnp_write_byte(ISAPNP_CFG_IRQ + (tmp << 1), irq);
+		}
+	}
+	for (tmp = 0; tmp < ISAPNP_MAX_DMA; tmp++) {
+		res = &dev->res->dma_resource[tmp];
+		if ((res->flags & (IORESOURCE_DMA | IORESOURCE_UNSET)) ==
+				IORESOURCE_DMA)
+			isapnp_write_byte(ISAPNP_CFG_DMA + tmp, res->start);
+	}
+	for (tmp = 0; tmp < ISAPNP_MAX_MEM; tmp++) {
+		res = &dev->res->mem_resource[tmp];
+		if ((res->flags & (IORESOURCE_MEM | IORESOURCE_UNSET)) ==
+				IORESOURCE_MEM)
+			isapnp_write_word(ISAPNP_CFG_MEM + (tmp << 3),
+				  (res->start >> 8) & 0xffff);
+	}
 	/* FIXME: We aren't handling 32bit mems properly here */
 	isapnp_activate(dev->number);
 	isapnp_cfg_end();
Index: work8/drivers/pnp/pnpacpi/rsparser.c
===================================================================
--- work8.orig/drivers/pnp/pnpacpi/rsparser.c	2008-04-17 15:00:51.000000000 -0600
+++ work8/drivers/pnp/pnpacpi/rsparser.c	2008-04-17 15:02:30.000000000 -0600
@@ -82,8 +82,8 @@
 						u32 gsi, int triggering,
 						int polarity, int shareable)
 {
-	struct pnp_resource_table *res = dev->res;
-	int i = 0;
+	struct resource *res;
+	int i;
 	int irq;
 	int p, t;
 	static unsigned char warned;
@@ -91,9 +91,11 @@
 	if (!valid_IRQ(gsi))
 		return;
 
-	while (!(res->irq_resource[i].flags & IORESOURCE_UNSET) &&
-	       i < PNP_MAX_IRQ)
-		i++;
+	for (i = 0; i < PNP_MAX_IRQ; i++) {
+		res = &dev->res->irq_resource[i];
+		if (res->flags & IORESOURCE_UNSET)
+			break;
+	}
 	if (i >= PNP_MAX_IRQ && !warned) {
 		printk(KERN_WARNING "pnpacpi: exceeded the max number of IRQ "
 				"resources: %d \n", PNP_MAX_IRQ);
@@ -117,16 +119,16 @@
 		}
 	}
 
-	res->irq_resource[i].flags = IORESOURCE_IRQ;	// Also clears _UNSET flag
-	res->irq_resource[i].flags |= irq_flags(triggering, polarity, shareable);
+	res->flags = IORESOURCE_IRQ;	// Also clears _UNSET flag
+	res->flags |= irq_flags(triggering, polarity, shareable);
 	irq = acpi_register_gsi(gsi, triggering, polarity);
 	if (irq < 0) {
-		res->irq_resource[i].flags |= IORESOURCE_DISABLED;
+		res->flags |= IORESOURCE_DISABLED;
 		return;
 	}
 
-	res->irq_resource[i].start = irq;
-	res->irq_resource[i].end = irq;
+	res->start = irq;
+	res->end = irq;
 	pcibios_penalize_isa_irq(irq, 1);
 }
 
@@ -176,22 +178,24 @@
 static void pnpacpi_parse_allocated_dmaresource(struct pnp_dev *dev,
 						u32 dma, int flags)
 {
-	struct pnp_resource_table *res = dev->res;
-	int i = 0;
+	struct resource *res;
+	int i;
 	static unsigned char warned;
 
-	while (i < PNP_MAX_DMA &&
-	       !(res->dma_resource[i].flags & IORESOURCE_UNSET))
-		i++;
+	for (i = 0; i < PNP_MAX_DMA; i++) {
+		res = &dev->res->dma_resource[i];
+		if (res->flags & IORESOURCE_UNSET)
+			break;
+	}
 	if (i < PNP_MAX_DMA) {
-		res->dma_resource[i].flags = IORESOURCE_DMA;	// Also clears _UNSET flag
-		res->dma_resource[i].flags |= flags;
+		res->flags = IORESOURCE_DMA;	// Also clears _UNSET flag
+		res->flags |= flags;
 		if (dma == -1) {
-			res->dma_resource[i].flags |= IORESOURCE_DISABLED;
+			res->flags |= IORESOURCE_DISABLED;
 			return;
 		}
-		res->dma_resource[i].start = dma;
-		res->dma_resource[i].end = dma;
+		res->start = dma;
+		res->end = dma;
 	} else if (!warned) {
 		printk(KERN_WARNING "pnpacpi: exceeded the max number of DMA "
 				"resources: %d \n", PNP_MAX_DMA);
@@ -202,23 +206,25 @@
 static void pnpacpi_parse_allocated_ioresource(struct pnp_dev *dev,
 					       u64 io, u64 len, int io_decode)
 {
-	struct pnp_resource_table *res = dev->res;
-	int i = 0;
+	struct resource *res;
+	int i;
 	static unsigned char warned;
 
-	while (!(res->port_resource[i].flags & IORESOURCE_UNSET) &&
-	       i < PNP_MAX_PORT)
-		i++;
+	for (i = 0; i < PNP_MAX_PORT; i++) {
+		res = &dev->res->port_resource[i];
+		if (res->flags & IORESOURCE_UNSET)
+			break;
+	}
 	if (i < PNP_MAX_PORT) {
-		res->port_resource[i].flags = IORESOURCE_IO;	// Also clears _UNSET flag
+		res->flags = IORESOURCE_IO;	// Also clears _UNSET flag
 		if (io_decode == ACPI_DECODE_16)
-			res->port_resource[i].flags |= PNP_PORT_FLAG_16BITADDR;
+			res->flags |= PNP_PORT_FLAG_16BITADDR;
 		if (len <= 0 || (io + len - 1) >= 0x10003) {
-			res->port_resource[i].flags |= IORESOURCE_DISABLED;
+			res->flags |= IORESOURCE_DISABLED;
 			return;
 		}
-		res->port_resource[i].start = io;
-		res->port_resource[i].end = io + len - 1;
+		res->start = io;
+		res->end = io + len - 1;
 	} else if (!warned) {
 		printk(KERN_WARNING "pnpacpi: exceeded the max number of IO "
 				"resources: %d \n", PNP_MAX_PORT);
@@ -230,24 +236,26 @@
 						u64 mem, u64 len,
 						int write_protect)
 {
-	struct pnp_resource_table *res = dev->res;
-	int i = 0;
+	struct resource *res;
+	int i;
 	static unsigned char warned;
 
-	while (!(res->mem_resource[i].flags & IORESOURCE_UNSET) &&
-	       (i < PNP_MAX_MEM))
-		i++;
+	for (i = 0; i < PNP_MAX_MEM; i++) {
+		res = &dev->res->mem_resource[i];
+		if (res->flags & IORESOURCE_UNSET)
+			break;
+	}
 	if (i < PNP_MAX_MEM) {
-		res->mem_resource[i].flags = IORESOURCE_MEM;	// Also clears _UNSET flag
+		res->flags = IORESOURCE_MEM;	// Also clears _UNSET flag
 		if (len <= 0) {
-			res->mem_resource[i].flags |= IORESOURCE_DISABLED;
+			res->flags |= IORESOURCE_DISABLED;
 			return;
 		}
 		if (write_protect == ACPI_READ_WRITE_MEMORY)
-			res->mem_resource[i].flags |= IORESOURCE_MEM_WRITEABLE;
+			res->flags |= IORESOURCE_MEM_WRITEABLE;
 
-		res->mem_resource[i].start = mem;
-		res->mem_resource[i].end = mem + len - 1;
+		res->start = mem;
+		res->end = mem + len - 1;
 	} else if (!warned) {
 		printk(KERN_WARNING "pnpacpi: exceeded the max number of mem "
 				"resources: %d\n", PNP_MAX_MEM);
Index: work8/drivers/pnp/pnpbios/rsparser.c
===================================================================
--- work8.orig/drivers/pnp/pnpbios/rsparser.c	2008-04-17 15:00:51.000000000 -0600
+++ work8/drivers/pnp/pnpbios/rsparser.c	2008-04-17 15:02:30.000000000 -0600
@@ -56,80 +56,90 @@
 
 static void pnpbios_parse_allocated_irqresource(struct pnp_dev *dev, int irq)
 {
-	struct pnp_resource_table *res = dev->res;
-	int i = 0;
+	struct resource *res;
+	int i;
+
+	for (i = 0; i < PNP_MAX_IRQ; i++) {
+		res = &dev->res->irq_resource[i];
+		if (res->flags & IORESOURCE_UNSET)
+			break;
+	}
 
-	while (!(res->irq_resource[i].flags & IORESOURCE_UNSET)
-	       && i < PNP_MAX_IRQ)
-		i++;
 	if (i < PNP_MAX_IRQ) {
-		res->irq_resource[i].flags = IORESOURCE_IRQ;	// Also clears _UNSET flag
+		res->flags = IORESOURCE_IRQ;	// Also clears _UNSET flag
 		if (irq == -1) {
-			res->irq_resource[i].flags |= IORESOURCE_DISABLED;
+			res->flags |= IORESOURCE_DISABLED;
 			return;
 		}
-		res->irq_resource[i].start =
-		    res->irq_resource[i].end = (unsigned long)irq;
+		res->start = res->end = (unsigned long)irq;
 		pcibios_penalize_isa_irq(irq, 1);
 	}
 }
 
 static void pnpbios_parse_allocated_dmaresource(struct pnp_dev *dev, int dma)
 {
-	struct pnp_resource_table *res = dev->res;
-	int i = 0;
+	struct resource *res;
+	int i;
+
+	for (i = 0; i < PNP_MAX_DMA; i++) {
+		res = &dev->res->dma_resource[i];
+		if (res->flags & IORESOURCE_UNSET)
+			break;
+	}
 
-	while (i < PNP_MAX_DMA &&
-	       !(res->dma_resource[i].flags & IORESOURCE_UNSET))
-		i++;
 	if (i < PNP_MAX_DMA) {
-		res->dma_resource[i].flags = IORESOURCE_DMA;	// Also clears _UNSET flag
+		res->flags = IORESOURCE_DMA;	// Also clears _UNSET flag
 		if (dma == -1) {
-			res->dma_resource[i].flags |= IORESOURCE_DISABLED;
+			res->flags |= IORESOURCE_DISABLED;
 			return;
 		}
-		res->dma_resource[i].start =
-		    res->dma_resource[i].end = (unsigned long)dma;
+		res->start = res->end = (unsigned long)dma;
 	}
 }
 
 static void pnpbios_parse_allocated_ioresource(struct pnp_dev *dev,
 					       int io, int len)
 {
-	struct pnp_resource_table *res = dev->res;
-	int i = 0;
+	struct resource *res;
+	int i;
+
+	for (i = 0; i < PNP_MAX_PORT; i++) {
+		res = &dev->res->port_resource[i];
+		if (res->flags & IORESOURCE_UNSET)
+			break;
+	}
 
-	while (!(res->port_resource[i].flags & IORESOURCE_UNSET)
-	       && i < PNP_MAX_PORT)
-		i++;
 	if (i < PNP_MAX_PORT) {
-		res->port_resource[i].flags = IORESOURCE_IO;	// Also clears _UNSET flag
+		res->flags = IORESOURCE_IO;	// Also clears _UNSET flag
 		if (len <= 0 || (io + len - 1) >= 0x10003) {
-			res->port_resource[i].flags |= IORESOURCE_DISABLED;
+			res->flags |= IORESOURCE_DISABLED;
 			return;
 		}
-		res->port_resource[i].start = (unsigned long)io;
-		res->port_resource[i].end = (unsigned long)(io + len - 1);
+		res->start = (unsigned long)io;
+		res->end = (unsigned long)(io + len - 1);
 	}
 }
 
 static void pnpbios_parse_allocated_memresource(struct pnp_dev *dev,
 						int mem, int len)
 {
-	struct pnp_resource_table *res = dev->res;
-	int i = 0;
+	struct resource *res;
+	int i;
+
+	for (i = 0; i < PNP_MAX_MEM; i++) {
+		res = &dev->res->mem_resource[i];
+		if (res->flags & IORESOURCE_UNSET)
+			break;
+	}
 
-	while (!(res->mem_resource[i].flags & IORESOURCE_UNSET)
-	       && i < PNP_MAX_MEM)
-		i++;
 	if (i < PNP_MAX_MEM) {
-		res->mem_resource[i].flags = IORESOURCE_MEM;	// Also clears _UNSET flag
+		res->flags = IORESOURCE_MEM;	// Also clears _UNSET flag
 		if (len <= 0) {
-			res->mem_resource[i].flags |= IORESOURCE_DISABLED;
+			res->flags |= IORESOURCE_DISABLED;
 			return;
 		}
-		res->mem_resource[i].start = (unsigned long)mem;
-		res->mem_resource[i].end = (unsigned long)(mem + len - 1);
+		res->start = (unsigned long)mem;
+		res->end = (unsigned long)(mem + len - 1);
 	}
 }
 

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 36/53] PNP: add struct pnp_resource
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (34 preceding siblings ...)
  2008-04-18 20:50 ` [patch 35/53] PNP: remove pnp_resource_table references from resource decoders Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 37/53] PNP: add pnp_resource index for ISAPNP Bjorn Helgaas
                   ` (16 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-add-struct-pnp_resource --]
[-- Type: text/plain, Size: 7016 bytes --]

This struct currently contains only a struct resource, but we will
soon need additional PNP-specific information.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>

---
 drivers/pnp/base.h             |   12 ++++++++----
 drivers/pnp/isapnp/core.c      |   26 ++++++++++++++++++--------
 drivers/pnp/pnpacpi/rsparser.c |    8 ++++----
 drivers/pnp/pnpbios/rsparser.c |    8 ++++----
 drivers/pnp/resource.c         |    8 ++++----
 5 files changed, 38 insertions(+), 24 deletions(-)

Index: work8/drivers/pnp/base.h
===================================================================
--- work8.orig/drivers/pnp/base.h	2008-04-17 14:57:25.000000000 -0600
+++ work8/drivers/pnp/base.h	2008-04-17 15:04:41.000000000 -0600
@@ -24,9 +24,13 @@
 #define PNP_MAX_IRQ		 2
 #define PNP_MAX_DMA		 2
 
+struct pnp_resource {
+	struct resource res;
+};
+
 struct pnp_resource_table {
-	struct resource port_resource[PNP_MAX_PORT];
-	struct resource mem_resource[PNP_MAX_MEM];
-	struct resource dma_resource[PNP_MAX_DMA];
-	struct resource irq_resource[PNP_MAX_IRQ];
+	struct pnp_resource port[PNP_MAX_PORT];
+	struct pnp_resource mem[PNP_MAX_MEM];
+	struct pnp_resource dma[PNP_MAX_DMA];
+	struct pnp_resource irq[PNP_MAX_IRQ];
 };
Index: work8/drivers/pnp/isapnp/core.c
===================================================================
--- work8.orig/drivers/pnp/isapnp/core.c	2008-04-17 15:02:30.000000000 -0600
+++ work8/drivers/pnp/isapnp/core.c	2008-04-17 15:04:41.000000000 -0600
@@ -923,6 +923,7 @@
 
 static int isapnp_read_resources(struct pnp_dev *dev)
 {
+	struct pnp_resource *pnp_res;
 	struct resource *res;
 	int tmp, ret;
 
@@ -932,7 +933,8 @@
 			ret = isapnp_read_word(ISAPNP_CFG_PORT + (tmp << 1));
 			if (!ret)
 				continue;
-			res = &dev->res->port_resource[tmp];
+			pnp_res = &dev->res->port[tmp];
+			res = &pnp_res->res;
 			res->start = ret;
 			res->flags = IORESOURCE_IO;
 		}
@@ -941,7 +943,8 @@
 			    isapnp_read_word(ISAPNP_CFG_MEM + (tmp << 3)) << 8;
 			if (!ret)
 				continue;
-			res = &dev->res->mem_resource[tmp];
+			pnp_res = &dev->res->mem[tmp];
+			res = &pnp_res->res;
 			res->start = ret;
 			res->flags = IORESOURCE_MEM;
 		}
@@ -951,7 +954,8 @@
 			     8);
 			if (!ret)
 				continue;
-			res = &dev->res->irq_resource[tmp];
+			pnp_res = &dev->res->irq[tmp];
+			res = &pnp_res->res;
 			res->start = res->end = ret;
 			res->flags = IORESOURCE_IRQ;
 		}
@@ -959,7 +963,8 @@
 			ret = isapnp_read_byte(ISAPNP_CFG_DMA + tmp);
 			if (ret == 4)
 				continue;
-			res = &dev->res->dma_resource[tmp];
+			pnp_res = &dev->res->dma[tmp];
+			res = &pnp_res->res;
 			res->start = res->end = ret;
 			res->flags = IORESOURCE_DMA;
 		}
@@ -980,20 +985,23 @@
 
 static int isapnp_set_resources(struct pnp_dev *dev)
 {
+	struct pnp_resource *pnp_res;
 	struct resource *res;
 	int tmp;
 
 	isapnp_cfg_begin(dev->card->number, dev->number);
 	dev->active = 1;
 	for (tmp = 0; tmp < ISAPNP_MAX_PORT; tmp++) {
-		res = &dev->res->port_resource[tmp];
+		pnp_res = &dev->res->port[tmp];
+		res = &pnp_res->res;
 		if ((res->flags & (IORESOURCE_IO | IORESOURCE_UNSET)) ==
 				IORESOURCE_IO)
 			isapnp_write_word(ISAPNP_CFG_PORT + (tmp << 1),
 					  res->start);
 	}
 	for (tmp = 0; tmp < ISAPNP_MAX_IRQ; tmp++) {
-		res = &dev->res->irq_resource[tmp];
+		pnp_res = &dev->res->irq[tmp];
+		res = &pnp_res->res;
 		if ((res->flags & (IORESOURCE_IRQ | IORESOURCE_UNSET)) ==
 				IORESOURCE_IRQ) {
 			int irq = res->start;
@@ -1003,13 +1011,15 @@
 		}
 	}
 	for (tmp = 0; tmp < ISAPNP_MAX_DMA; tmp++) {
-		res = &dev->res->dma_resource[tmp];
+		pnp_res = &dev->res->dma[tmp];
+		res = &pnp_res->res;
 		if ((res->flags & (IORESOURCE_DMA | IORESOURCE_UNSET)) ==
 				IORESOURCE_DMA)
 			isapnp_write_byte(ISAPNP_CFG_DMA + tmp, res->start);
 	}
 	for (tmp = 0; tmp < ISAPNP_MAX_MEM; tmp++) {
-		res = &dev->res->mem_resource[tmp];
+		pnp_res = &dev->res->mem[tmp];
+		res = &pnp_res->res;
 		if ((res->flags & (IORESOURCE_MEM | IORESOURCE_UNSET)) ==
 				IORESOURCE_MEM)
 			isapnp_write_word(ISAPNP_CFG_MEM + (tmp << 3),
Index: work8/drivers/pnp/pnpacpi/rsparser.c
===================================================================
--- work8.orig/drivers/pnp/pnpacpi/rsparser.c	2008-04-17 15:02:30.000000000 -0600
+++ work8/drivers/pnp/pnpacpi/rsparser.c	2008-04-17 15:04:41.000000000 -0600
@@ -92,7 +92,7 @@
 		return;
 
 	for (i = 0; i < PNP_MAX_IRQ; i++) {
-		res = &dev->res->irq_resource[i];
+		res = &dev->res->irq[i].res;
 		if (res->flags & IORESOURCE_UNSET)
 			break;
 	}
@@ -183,7 +183,7 @@
 	static unsigned char warned;
 
 	for (i = 0; i < PNP_MAX_DMA; i++) {
-		res = &dev->res->dma_resource[i];
+		res = &dev->res->dma[i].res;
 		if (res->flags & IORESOURCE_UNSET)
 			break;
 	}
@@ -211,7 +211,7 @@
 	static unsigned char warned;
 
 	for (i = 0; i < PNP_MAX_PORT; i++) {
-		res = &dev->res->port_resource[i];
+		res = &dev->res->port[i].res;
 		if (res->flags & IORESOURCE_UNSET)
 			break;
 	}
@@ -241,7 +241,7 @@
 	static unsigned char warned;
 
 	for (i = 0; i < PNP_MAX_MEM; i++) {
-		res = &dev->res->mem_resource[i];
+		res = &dev->res->mem[i].res;
 		if (res->flags & IORESOURCE_UNSET)
 			break;
 	}
Index: work8/drivers/pnp/pnpbios/rsparser.c
===================================================================
--- work8.orig/drivers/pnp/pnpbios/rsparser.c	2008-04-17 15:02:30.000000000 -0600
+++ work8/drivers/pnp/pnpbios/rsparser.c	2008-04-17 15:04:41.000000000 -0600
@@ -60,7 +60,7 @@
 	int i;
 
 	for (i = 0; i < PNP_MAX_IRQ; i++) {
-		res = &dev->res->irq_resource[i];
+		res = &dev->res->irq[i].res;
 		if (res->flags & IORESOURCE_UNSET)
 			break;
 	}
@@ -82,7 +82,7 @@
 	int i;
 
 	for (i = 0; i < PNP_MAX_DMA; i++) {
-		res = &dev->res->dma_resource[i];
+		res = &dev->res->dma[i].res;
 		if (res->flags & IORESOURCE_UNSET)
 			break;
 	}
@@ -104,7 +104,7 @@
 	int i;
 
 	for (i = 0; i < PNP_MAX_PORT; i++) {
-		res = &dev->res->port_resource[i];
+		res = &dev->res->port[i].res;
 		if (res->flags & IORESOURCE_UNSET)
 			break;
 	}
@@ -127,7 +127,7 @@
 	int i;
 
 	for (i = 0; i < PNP_MAX_MEM; i++) {
-		res = &dev->res->mem_resource[i];
+		res = &dev->res->mem[i].res;
 		if (res->flags & IORESOURCE_UNSET)
 			break;
 	}
Index: work8/drivers/pnp/resource.c
===================================================================
--- work8.orig/drivers/pnp/resource.c	2008-04-17 14:57:25.000000000 -0600
+++ work8/drivers/pnp/resource.c	2008-04-17 15:04:41.000000000 -0600
@@ -498,19 +498,19 @@
 	case IORESOURCE_IO:
 		if (num >= PNP_MAX_PORT)
 			return NULL;
-		return &res->port_resource[num];
+		return &res->port[num].res;
 	case IORESOURCE_MEM:
 		if (num >= PNP_MAX_MEM)
 			return NULL;
-		return &res->mem_resource[num];
+		return &res->mem[num].res;
 	case IORESOURCE_IRQ:
 		if (num >= PNP_MAX_IRQ)
 			return NULL;
-		return &res->irq_resource[num];
+		return &res->irq[num].res;
 	case IORESOURCE_DMA:
 		if (num >= PNP_MAX_DMA)
 			return NULL;
-		return &res->dma_resource[num];
+		return &res->dma[num].res;
 	}
 	return NULL;
 }

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 37/53] PNP: add pnp_resource index for ISAPNP
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (35 preceding siblings ...)
  2008-04-18 20:50 ` [patch 36/53] PNP: add struct pnp_resource Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 38/53] PNP: add pnp_new_resource() to find a new unset pnp_resource Bjorn Helgaas
                   ` (15 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-add-pnp_resource-index --]
[-- Type: text/plain, Size: 3902 bytes --]

Save the ISAPNP config register index in the struct pnp_resource.

We need this because it is important to write ISAPNP configuration
back to the same registers we read it from.  For example, if we
read valid regions from memory descriptors 0, 1, and 3, we'd
better write them back to the same registers, without compressing
them to descriptors 0, 1, and 2.

This was previously guaranteed by using the index into the
pnp_resource_table array as the ISAPNP config register index.
However, I am removing those fixed-size arrays, so we need to
save the ISAPNP register index elsewhere.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>

---
 drivers/pnp/base.h        |    1 +
 drivers/pnp/isapnp/core.c |   18 +++++++++++++-----
 2 files changed, 14 insertions(+), 5 deletions(-)

Index: work8/drivers/pnp/base.h
===================================================================
--- work8.orig/drivers/pnp/base.h	2008-04-16 11:20:08.000000000 -0600
+++ work8/drivers/pnp/base.h	2008-04-16 11:20:45.000000000 -0600
@@ -26,6 +26,7 @@
 
 struct pnp_resource {
 	struct resource res;
+	unsigned int index;		/* ISAPNP config register index */
 };
 
 struct pnp_resource_table {
Index: work8/drivers/pnp/isapnp/core.c
===================================================================
--- work8.orig/drivers/pnp/isapnp/core.c	2008-04-16 11:21:05.000000000 -0600
+++ work8/drivers/pnp/isapnp/core.c	2008-04-16 11:22:57.000000000 -0600
@@ -934,6 +934,7 @@
 			if (!ret)
 				continue;
 			pnp_res = &dev->res->port[tmp];
+			pnp_res->index = tmp;
 			res = &pnp_res->res;
 			res->start = ret;
 			res->flags = IORESOURCE_IO;
@@ -944,6 +945,7 @@
 			if (!ret)
 				continue;
 			pnp_res = &dev->res->mem[tmp];
+			pnp_res->index = tmp;
 			res = &pnp_res->res;
 			res->start = ret;
 			res->flags = IORESOURCE_MEM;
@@ -955,6 +957,7 @@
 			if (!ret)
 				continue;
 			pnp_res = &dev->res->irq[tmp];
+			pnp_res->index = tmp;
 			res = &pnp_res->res;
 			res->start = res->end = ret;
 			res->flags = IORESOURCE_IRQ;
@@ -964,6 +967,7 @@
 			if (ret == 4)
 				continue;
 			pnp_res = &dev->res->dma[tmp];
+			pnp_res->index = tmp;
 			res = &pnp_res->res;
 			res->start = res->end = ret;
 			res->flags = IORESOURCE_DMA;
@@ -987,42 +991,46 @@
 {
 	struct pnp_resource *pnp_res;
 	struct resource *res;
-	int tmp;
+	int tmp, index;
 
 	isapnp_cfg_begin(dev->card->number, dev->number);
 	dev->active = 1;
 	for (tmp = 0; tmp < ISAPNP_MAX_PORT; tmp++) {
 		pnp_res = &dev->res->port[tmp];
+		index = pnp_res->index;
 		res = &pnp_res->res;
 		if ((res->flags & (IORESOURCE_IO | IORESOURCE_UNSET)) ==
 				IORESOURCE_IO)
-			isapnp_write_word(ISAPNP_CFG_PORT + (tmp << 1),
+			isapnp_write_word(ISAPNP_CFG_PORT + (index << 1),
 					  res->start);
 	}
 	for (tmp = 0; tmp < ISAPNP_MAX_IRQ; tmp++) {
 		pnp_res = &dev->res->irq[tmp];
+		index = pnp_res->index;
 		res = &pnp_res->res;
 		if ((res->flags & (IORESOURCE_IRQ | IORESOURCE_UNSET)) ==
 				IORESOURCE_IRQ) {
 			int irq = res->start;
 			if (irq == 2)
 				irq = 9;
-			isapnp_write_byte(ISAPNP_CFG_IRQ + (tmp << 1), irq);
+			isapnp_write_byte(ISAPNP_CFG_IRQ + (index << 1), irq);
 		}
 	}
 	for (tmp = 0; tmp < ISAPNP_MAX_DMA; tmp++) {
 		pnp_res = &dev->res->dma[tmp];
+		index = pnp_res->index;
 		res = &pnp_res->res;
 		if ((res->flags & (IORESOURCE_DMA | IORESOURCE_UNSET)) ==
 				IORESOURCE_DMA)
-			isapnp_write_byte(ISAPNP_CFG_DMA + tmp, res->start);
+			isapnp_write_byte(ISAPNP_CFG_DMA + index, res->start);
 	}
 	for (tmp = 0; tmp < ISAPNP_MAX_MEM; tmp++) {
 		pnp_res = &dev->res->mem[tmp];
+		index = pnp_res->index;
 		res = &pnp_res->res;
 		if ((res->flags & (IORESOURCE_MEM | IORESOURCE_UNSET)) ==
 				IORESOURCE_MEM)
-			isapnp_write_word(ISAPNP_CFG_MEM + (tmp << 3),
+			isapnp_write_word(ISAPNP_CFG_MEM + (index << 3),
 				  (res->start >> 8) & 0xffff);
 	}
 	/* FIXME: We aren't handling 32bit mems properly here */

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 38/53] PNP: add pnp_new_resource() to find a new unset pnp_resource
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (36 preceding siblings ...)
  2008-04-18 20:50 ` [patch 37/53] PNP: add pnp_resource index for ISAPNP Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 39/53] PNP: make generic pnp_add_irq_resource() Bjorn Helgaas
                   ` (14 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-add-pnp_new_resource --]
[-- Type: text/plain, Size: 1625 bytes --]

This encapsulates the code to locate a new pnp_resource of the
desired type.  Currently this uses the pnp_resource_table, but
it will soon change to find a resource in a linked list.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>

Index: work8/drivers/pnp/resource.c
===================================================================
--- work8.orig/drivers/pnp/resource.c	2008-04-17 15:04:41.000000000 -0600
+++ work8/drivers/pnp/resource.c	2008-04-18 11:08:33.000000000 -0600
@@ -516,6 +516,49 @@
 }
 EXPORT_SYMBOL(pnp_get_resource);
 
+static struct pnp_resource *pnp_new_resource(struct pnp_dev *dev, int type)
+{
+	struct pnp_resource *pnp_res;
+	struct resource *res;
+	int i;
+
+	switch (type) {
+	case IORESOURCE_IO:
+		for (i = 0; i < PNP_MAX_PORT; i++) {
+			pnp_res = &dev->res->port[i];
+			res = &pnp_res->res;
+			if (res->flags & IORESOURCE_UNSET)
+				return pnp_res;
+		}
+		break;
+	case IORESOURCE_MEM:
+		for (i = 0; i < PNP_MAX_MEM; i++) {
+			pnp_res = &dev->res->mem[i];
+			res = &pnp_res->res;
+			if (res->flags & IORESOURCE_UNSET)
+				return pnp_res;
+		}
+		break;
+	case IORESOURCE_IRQ:
+		for (i = 0; i < PNP_MAX_IRQ; i++) {
+			pnp_res = &dev->res->irq[i];
+			res = &pnp_res->res;
+			if (res->flags & IORESOURCE_UNSET)
+				return pnp_res;
+		}
+		break;
+	case IORESOURCE_DMA:
+		for (i = 0; i < PNP_MAX_DMA; i++) {
+			pnp_res = &dev->res->dma[i];
+			res = &pnp_res->res;
+			if (res->flags & IORESOURCE_UNSET)
+				return pnp_res;
+		}
+		break;
+	}
+	return NULL;
+}
+
 /* format is: pnp_reserve_irq=irq1[,irq2] .... */
 static int __init pnp_setup_reserve_irq(char *str)
 {

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 39/53] PNP: make generic pnp_add_irq_resource()
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (37 preceding siblings ...)
  2008-04-18 20:50 ` [patch 38/53] PNP: add pnp_new_resource() to find a new unset pnp_resource Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 40/53] PNP: make generic pnp_add_dma_resource() Bjorn Helgaas
                   ` (13 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-common-add-irq-resource --]
[-- Type: text/plain, Size: 6689 bytes --]

Add a pnp_add_irq_resource() that can be used by all the PNP
backends.  This consolidates a little more pnp_resource_table
knowledge into one place.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>

---
 drivers/pnp/base.h             |    3 +++
 drivers/pnp/resource.c         |   24 ++++++++++++++++++++++++
 drivers/pnp/interface.c        |   14 ++++++--------
 drivers/pnp/isapnp/core.c      |    8 +++-----
 drivers/pnp/pnpacpi/rsparser.c |   31 +++++++------------------------
 drivers/pnp/pnpbios/rsparser.c |   31 +++++++------------------------
 6 files changed, 50 insertions(+), 61 deletions(-)

Index: work8/drivers/pnp/base.h
===================================================================
--- work8.orig/drivers/pnp/base.h	2008-04-17 15:05:12.000000000 -0600
+++ work8/drivers/pnp/base.h	2008-04-18 11:00:36.000000000 -0600
@@ -35,3 +35,6 @@
 	struct pnp_resource dma[PNP_MAX_DMA];
 	struct pnp_resource irq[PNP_MAX_IRQ];
 };
+
+struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq,
+					  int flags);
Index: work8/drivers/pnp/resource.c
===================================================================
--- work8.orig/drivers/pnp/resource.c	2008-04-17 15:05:13.000000000 -0600
+++ work8/drivers/pnp/resource.c	2008-04-18 11:00:36.000000000 -0600
@@ -559,6 +559,30 @@
 	return NULL;
 }
 
+struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq,
+					  int flags)
+{
+	struct pnp_resource *pnp_res;
+	struct resource *res;
+	static unsigned char warned;
+
+	pnp_res = pnp_new_resource(dev, IORESOURCE_IRQ);
+	if (!pnp_res) {
+		if (!warned) {
+			dev_err(&dev->dev, "can't add resource for IRQ %d\n",
+				irq);
+			warned = 1;
+		}
+		return NULL;
+	}
+
+	res = &pnp_res->res;
+	res->flags = IORESOURCE_IRQ | flags;
+	res->start = irq;
+	res->end = irq;
+	return pnp_res;
+}
+
 /* format is: pnp_reserve_irq=irq1[,irq2] .... */
 static int __init pnp_setup_reserve_irq(char *str)
 {
Index: work8/drivers/pnp/interface.c
===================================================================
--- work8.orig/drivers/pnp/interface.c	2008-04-17 14:56:51.000000000 -0600
+++ work8/drivers/pnp/interface.c	2008-04-18 11:02:06.000000000 -0600
@@ -322,9 +322,11 @@
 			  const char *ubuf, size_t count)
 {
 	struct pnp_dev *dev = to_pnp_dev(dmdev);
+	struct pnp_resource *pnp_res;
 	struct resource *res;
 	char *buf = (void *)ubuf;
 	int retval = 0;
+	resource_size_t start;
 
 	if (dev->status & PNP_ATTACHED) {
 		retval = -EBUSY;
@@ -426,14 +428,10 @@
 				buf += 3;
 				while (isspace(*buf))
 					++buf;
-				res = pnp_get_resource(dev, IORESOURCE_IRQ,
-						       nirq);
-				if (!res)
-					break;
-				res->start = res->end =
-				    simple_strtoul(buf, &buf, 0);
-				res->flags = IORESOURCE_IRQ;
-				nirq++;
+				start = simple_strtoul(buf, &buf, 0);
+				pnp_res = pnp_add_irq_resource(dev, start, 0);
+				if (pnp_res)
+					pnp_res->index = nirq++;
 				continue;
 			}
 			if (!strnicmp(buf, "dma", 3)) {
Index: work8/drivers/pnp/isapnp/core.c
===================================================================
--- work8.orig/drivers/pnp/isapnp/core.c	2008-04-17 15:05:12.000000000 -0600
+++ work8/drivers/pnp/isapnp/core.c	2008-04-18 11:00:36.000000000 -0600
@@ -956,11 +956,9 @@
 			     8);
 			if (!ret)
 				continue;
-			pnp_res = &dev->res->irq[tmp];
-			pnp_res->index = tmp;
-			res = &pnp_res->res;
-			res->start = res->end = ret;
-			res->flags = IORESOURCE_IRQ;
+			pnp_res = pnp_add_irq_resource(dev, ret, 0);
+			if (pnp_res)
+				pnp_res->index = tmp;
 		}
 		for (tmp = 0; tmp < ISAPNP_MAX_DMA; tmp++) {
 			ret = isapnp_read_byte(ISAPNP_CFG_DMA + tmp);
Index: work8/drivers/pnp/pnpacpi/rsparser.c
===================================================================
--- work8.orig/drivers/pnp/pnpacpi/rsparser.c	2008-04-17 15:04:41.000000000 -0600
+++ work8/drivers/pnp/pnpacpi/rsparser.c	2008-04-18 11:00:36.000000000 -0600
@@ -82,26 +82,12 @@
 						u32 gsi, int triggering,
 						int polarity, int shareable)
 {
-	struct resource *res;
-	int i;
-	int irq;
+	int irq, flags;
 	int p, t;
-	static unsigned char warned;
 
 	if (!valid_IRQ(gsi))
 		return;
 
-	for (i = 0; i < PNP_MAX_IRQ; i++) {
-		res = &dev->res->irq[i].res;
-		if (res->flags & IORESOURCE_UNSET)
-			break;
-	}
-	if (i >= PNP_MAX_IRQ && !warned) {
-		printk(KERN_WARNING "pnpacpi: exceeded the max number of IRQ "
-				"resources: %d \n", PNP_MAX_IRQ);
-		warned = 1;
-		return;
-	}
 	/*
 	 * in IO-APIC mode, use overrided attribute. Two reasons:
 	 * 1. BIOS bug in DSDT
@@ -119,17 +105,14 @@
 		}
 	}
 
-	res->flags = IORESOURCE_IRQ;	// Also clears _UNSET flag
-	res->flags |= irq_flags(triggering, polarity, shareable);
+	flags = irq_flags(triggering, polarity, shareable);
 	irq = acpi_register_gsi(gsi, triggering, polarity);
-	if (irq < 0) {
-		res->flags |= IORESOURCE_DISABLED;
-		return;
-	}
+	if (irq >= 0)
+		pcibios_penalize_isa_irq(irq, 1);
+	else
+		flags |= IORESOURCE_DISABLED;
 
-	res->start = irq;
-	res->end = irq;
-	pcibios_penalize_isa_irq(irq, 1);
+	pnp_add_irq_resource(dev, irq, flags);
 }
 
 static int dma_flags(int type, int bus_master, int transfer)
Index: work8/drivers/pnp/pnpbios/rsparser.c
===================================================================
--- work8.orig/drivers/pnp/pnpbios/rsparser.c	2008-04-17 15:04:41.000000000 -0600
+++ work8/drivers/pnp/pnpbios/rsparser.c	2008-04-18 11:00:36.000000000 -0600
@@ -54,28 +54,6 @@
  * Allocated Resources
  */
 
-static void pnpbios_parse_allocated_irqresource(struct pnp_dev *dev, int irq)
-{
-	struct resource *res;
-	int i;
-
-	for (i = 0; i < PNP_MAX_IRQ; i++) {
-		res = &dev->res->irq[i].res;
-		if (res->flags & IORESOURCE_UNSET)
-			break;
-	}
-
-	if (i < PNP_MAX_IRQ) {
-		res->flags = IORESOURCE_IRQ;	// Also clears _UNSET flag
-		if (irq == -1) {
-			res->flags |= IORESOURCE_DISABLED;
-			return;
-		}
-		res->start = res->end = (unsigned long)irq;
-		pcibios_penalize_isa_irq(irq, 1);
-	}
-}
-
 static void pnpbios_parse_allocated_dmaresource(struct pnp_dev *dev, int dma)
 {
 	struct resource *res;
@@ -148,7 +126,7 @@
 							    unsigned char *end)
 {
 	unsigned int len, tag;
-	int io, size, mask, i;
+	int io, size, mask, i, flags;
 
 	if (!p)
 		return NULL;
@@ -203,12 +181,17 @@
 		case SMALL_TAG_IRQ:
 			if (len < 2 || len > 3)
 				goto len_err;
+			flags = 0;
 			io = -1;
 			mask = p[1] + p[2] * 256;
 			for (i = 0; i < 16; i++, mask = mask >> 1)
 				if (mask & 0x01)
 					io = i;
-			pnpbios_parse_allocated_irqresource(dev, io);
+			if (io != -1)
+				pcibios_penalize_isa_irq(io, 1);
+			else
+				flags = IORESOURCE_DISABLED;
+			pnp_add_irq_resource(dev, io, flags);
 			break;
 
 		case SMALL_TAG_DMA:

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 40/53] PNP: make generic pnp_add_dma_resource()
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (38 preceding siblings ...)
  2008-04-18 20:50 ` [patch 39/53] PNP: make generic pnp_add_irq_resource() Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 41/53] PNP: make generic pnp_add_io_resource() Bjorn Helgaas
                   ` (12 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-common-add-dma-resource --]
[-- Type: text/plain, Size: 6446 bytes --]

Add a pnp_add_dma_resource() that can be used by all the PNP
backends.  This consolidates a little more pnp_resource_table
knowledge into one place.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>

---
 drivers/pnp/base.h             |    2 +
 drivers/pnp/resource.c         |   24 +++++++++++++++++++++++
 drivers/pnp/interface.c        |   12 +++--------
 drivers/pnp/isapnp/core.c      |    8 ++-----
 drivers/pnp/pnpacpi/rsparser.c |   42 +++++++----------------------------------
 drivers/pnp/pnpbios/rsparser.c |   26 +++----------------------
 6 files changed, 45 insertions(+), 69 deletions(-)

Index: work8/drivers/pnp/base.h
===================================================================
--- work8.orig/drivers/pnp/base.h	2008-04-18 11:00:36.000000000 -0600
+++ work8/drivers/pnp/base.h	2008-04-18 11:03:34.000000000 -0600
@@ -38,3 +38,5 @@
 
 struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq,
 					  int flags);
+struct pnp_resource *pnp_add_dma_resource(struct pnp_dev *dev, int dma,
+					  int flags);
Index: work8/drivers/pnp/resource.c
===================================================================
--- work8.orig/drivers/pnp/resource.c	2008-04-18 11:00:36.000000000 -0600
+++ work8/drivers/pnp/resource.c	2008-04-18 11:03:34.000000000 -0600
@@ -583,6 +583,30 @@
 	return pnp_res;
 }
 
+struct pnp_resource *pnp_add_dma_resource(struct pnp_dev *dev, int dma,
+					  int flags)
+{
+	struct pnp_resource *pnp_res;
+	struct resource *res;
+	static unsigned char warned;
+
+	pnp_res = pnp_new_resource(dev, IORESOURCE_DMA);
+	if (!pnp_res) {
+		if (!warned) {
+			dev_err(&dev->dev, "can't add resource for DMA %d\n",
+				dma);
+			warned = 1;
+		}
+		return NULL;
+	}
+
+	res = &pnp_res->res;
+	res->flags = IORESOURCE_DMA | flags;
+	res->start = dma;
+	res->end = dma;
+	return pnp_res;
+}
+
 /* format is: pnp_reserve_irq=irq1[,irq2] .... */
 static int __init pnp_setup_reserve_irq(char *str)
 {
Index: work8/drivers/pnp/interface.c
===================================================================
--- work8.orig/drivers/pnp/interface.c	2008-04-18 11:02:06.000000000 -0600
+++ work8/drivers/pnp/interface.c	2008-04-18 11:04:17.000000000 -0600
@@ -438,14 +438,10 @@
 				buf += 3;
 				while (isspace(*buf))
 					++buf;
-				res = pnp_get_resource(dev, IORESOURCE_DMA,
-						       ndma);
-				if (!res)
-					break;
-				res->start = res->end =
-				    simple_strtoul(buf, &buf, 0);
-				res->flags = IORESOURCE_DMA;
-				ndma++;
+				start = simple_strtoul(buf, &buf, 0);
+				pnp_res = pnp_add_dma_resource(dev, start, 0);
+				if (pnp_res)
+					pnp_res->index = ndma++;
 				continue;
 			}
 			break;
Index: work8/drivers/pnp/isapnp/core.c
===================================================================
--- work8.orig/drivers/pnp/isapnp/core.c	2008-04-18 11:00:36.000000000 -0600
+++ work8/drivers/pnp/isapnp/core.c	2008-04-18 11:03:34.000000000 -0600
@@ -964,11 +964,9 @@
 			ret = isapnp_read_byte(ISAPNP_CFG_DMA + tmp);
 			if (ret == 4)
 				continue;
-			pnp_res = &dev->res->dma[tmp];
-			pnp_res->index = tmp;
-			res = &pnp_res->res;
-			res->start = res->end = ret;
-			res->flags = IORESOURCE_DMA;
+			pnp_res = pnp_add_dma_resource(dev, ret, 0);
+			if  (pnp_res)
+				pnp_res->index = tmp;
 		}
 	}
 	return 0;
Index: work8/drivers/pnp/pnpacpi/rsparser.c
===================================================================
--- work8.orig/drivers/pnp/pnpacpi/rsparser.c	2008-04-18 11:00:36.000000000 -0600
+++ work8/drivers/pnp/pnpacpi/rsparser.c	2008-04-18 11:03:34.000000000 -0600
@@ -158,34 +158,6 @@
 	return flags;
 }
 
-static void pnpacpi_parse_allocated_dmaresource(struct pnp_dev *dev,
-						u32 dma, int flags)
-{
-	struct resource *res;
-	int i;
-	static unsigned char warned;
-
-	for (i = 0; i < PNP_MAX_DMA; i++) {
-		res = &dev->res->dma[i].res;
-		if (res->flags & IORESOURCE_UNSET)
-			break;
-	}
-	if (i < PNP_MAX_DMA) {
-		res->flags = IORESOURCE_DMA;	// Also clears _UNSET flag
-		res->flags |= flags;
-		if (dma == -1) {
-			res->flags |= IORESOURCE_DISABLED;
-			return;
-		}
-		res->start = dma;
-		res->end = dma;
-	} else if (!warned) {
-		printk(KERN_WARNING "pnpacpi: exceeded the max number of DMA "
-				"resources: %d \n", PNP_MAX_DMA);
-		warned = 1;
-	}
-}
-
 static void pnpacpi_parse_allocated_ioresource(struct pnp_dev *dev,
 					       u64 io, u64 len, int io_decode)
 {
@@ -285,7 +257,7 @@
 	struct acpi_resource_memory32 *memory32;
 	struct acpi_resource_fixed_memory32 *fixed_memory32;
 	struct acpi_resource_extended_irq *extended_irq;
-	int i;
+	int i, flags;
 
 	switch (res->type) {
 	case ACPI_RESOURCE_TYPE_IRQ:
@@ -305,11 +277,13 @@
 
 	case ACPI_RESOURCE_TYPE_DMA:
 		dma = &res->data.dma;
-		if (dma->channel_count > 0)
-			pnpacpi_parse_allocated_dmaresource(dev,
-				dma->channels[0],
-				dma_flags(dma->type, dma->bus_master,
-					  dma->transfer));
+		if (dma->channel_count > 0) {
+			flags = dma_flags(dma->type, dma->bus_master,
+					  dma->transfer);
+			if (dma->channels[0] == (u8) -1)
+				flags |= IORESOURCE_DISABLED;
+			pnp_add_dma_resource(dev, dma->channels[0], flags);
+		}
 		break;
 
 	case ACPI_RESOURCE_TYPE_IO:
Index: work8/drivers/pnp/pnpbios/rsparser.c
===================================================================
--- work8.orig/drivers/pnp/pnpbios/rsparser.c	2008-04-18 11:00:36.000000000 -0600
+++ work8/drivers/pnp/pnpbios/rsparser.c	2008-04-18 11:03:34.000000000 -0600
@@ -54,27 +54,6 @@
  * Allocated Resources
  */
 
-static void pnpbios_parse_allocated_dmaresource(struct pnp_dev *dev, int dma)
-{
-	struct resource *res;
-	int i;
-
-	for (i = 0; i < PNP_MAX_DMA; i++) {
-		res = &dev->res->dma[i].res;
-		if (res->flags & IORESOURCE_UNSET)
-			break;
-	}
-
-	if (i < PNP_MAX_DMA) {
-		res->flags = IORESOURCE_DMA;	// Also clears _UNSET flag
-		if (dma == -1) {
-			res->flags |= IORESOURCE_DISABLED;
-			return;
-		}
-		res->start = res->end = (unsigned long)dma;
-	}
-}
-
 static void pnpbios_parse_allocated_ioresource(struct pnp_dev *dev,
 					       int io, int len)
 {
@@ -197,12 +176,15 @@
 		case SMALL_TAG_DMA:
 			if (len != 2)
 				goto len_err;
+			flags = 0;
 			io = -1;
 			mask = p[1];
 			for (i = 0; i < 8; i++, mask = mask >> 1)
 				if (mask & 0x01)
 					io = i;
-			pnpbios_parse_allocated_dmaresource(dev, io);
+			if (io == -1)
+				flags = IORESOURCE_DISABLED;
+			pnp_add_dma_resource(dev, io, flags);
 			break;
 
 		case SMALL_TAG_PORT:

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 41/53] PNP: make generic pnp_add_io_resource()
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (39 preceding siblings ...)
  2008-04-18 20:50 ` [patch 40/53] PNP: make generic pnp_add_dma_resource() Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 42/53] PNP: make generic pnp_add_mem_resource() Bjorn Helgaas
                   ` (11 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-common-add-io-resource --]
[-- Type: text/plain, Size: 6617 bytes --]

Add a pnp_add_io_resource() that can be used by all the PNP
backends.  This consolidates a little more pnp_resource_table
knowledge into one place.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>

---
 drivers/pnp/base.h             |    3 +++
 drivers/pnp/resource.c         |   26 ++++++++++++++++++++++++++
 drivers/pnp/interface.c        |   18 ++++++++----------
 drivers/pnp/isapnp/core.c      |    8 +++-----
 drivers/pnp/pnpacpi/rsparser.c |   35 ++++++++++-------------------------
 drivers/pnp/pnpbios/rsparser.c |   23 ++++++-----------------
 6 files changed, 56 insertions(+), 57 deletions(-)

Index: work8/drivers/pnp/base.h
===================================================================
--- work8.orig/drivers/pnp/base.h	2008-04-18 11:03:34.000000000 -0600
+++ work8/drivers/pnp/base.h	2008-04-18 11:05:06.000000000 -0600
@@ -40,3 +40,6 @@
 					  int flags);
 struct pnp_resource *pnp_add_dma_resource(struct pnp_dev *dev, int dma,
 					  int flags);
+struct pnp_resource *pnp_add_io_resource(struct pnp_dev *dev,
+					 resource_size_t start,
+					 resource_size_t end, int flags);
Index: work8/drivers/pnp/interface.c
===================================================================
--- work8.orig/drivers/pnp/interface.c	2008-04-18 11:04:17.000000000 -0600
+++ work8/drivers/pnp/interface.c	2008-04-18 11:05:47.000000000 -0600
@@ -326,7 +326,7 @@
 	struct resource *res;
 	char *buf = (void *)ubuf;
 	int retval = 0;
-	resource_size_t start;
+	resource_size_t start, end;
 
 	if (dev->status & PNP_ATTACHED) {
 		retval = -EBUSY;
@@ -384,22 +384,20 @@
 				buf += 2;
 				while (isspace(*buf))
 					++buf;
-				res = pnp_get_resource(dev, IORESOURCE_IO,
-						       nport);
-				if (!res)
-					break;
-				res->start = simple_strtoul(buf, &buf, 0);
+				start = simple_strtoul(buf, &buf, 0);
 				while (isspace(*buf))
 					++buf;
 				if (*buf == '-') {
 					buf += 1;
 					while (isspace(*buf))
 						++buf;
-					res->end = simple_strtoul(buf, &buf, 0);
+					end = simple_strtoul(buf, &buf, 0);
 				} else
-					res->end = res->start;
-				res->flags = IORESOURCE_IO;
-				nport++;
+					end = start;
+				pnp_res = pnp_add_io_resource(dev, start, end,
+							      0);
+				if (pnp_res)
+					pnp_res->index = nport++;
 				continue;
 			}
 			if (!strnicmp(buf, "mem", 3)) {
Index: work8/drivers/pnp/isapnp/core.c
===================================================================
--- work8.orig/drivers/pnp/isapnp/core.c	2008-04-18 11:03:34.000000000 -0600
+++ work8/drivers/pnp/isapnp/core.c	2008-04-18 11:05:06.000000000 -0600
@@ -933,11 +933,9 @@
 			ret = isapnp_read_word(ISAPNP_CFG_PORT + (tmp << 1));
 			if (!ret)
 				continue;
-			pnp_res = &dev->res->port[tmp];
-			pnp_res->index = tmp;
-			res = &pnp_res->res;
-			res->start = ret;
-			res->flags = IORESOURCE_IO;
+			pnp_res = pnp_add_io_resource(dev, ret, ret, 0);
+			if (pnp_res)
+				pnp_res->index = tmp;
 		}
 		for (tmp = 0; tmp < ISAPNP_MAX_MEM; tmp++) {
 			ret =
Index: work8/drivers/pnp/pnpacpi/rsparser.c
===================================================================
--- work8.orig/drivers/pnp/pnpacpi/rsparser.c	2008-04-18 11:03:34.000000000 -0600
+++ work8/drivers/pnp/pnpacpi/rsparser.c	2008-04-18 11:05:06.000000000 -0600
@@ -158,33 +158,18 @@
 	return flags;
 }
 
-static void pnpacpi_parse_allocated_ioresource(struct pnp_dev *dev,
-					       u64 io, u64 len, int io_decode)
+static void pnpacpi_parse_allocated_ioresource(struct pnp_dev *dev, u64 start,
+					       u64 len, int io_decode)
 {
-	struct resource *res;
-	int i;
-	static unsigned char warned;
+	int flags = 0;
+	u64 end = start + len - 1;
 
-	for (i = 0; i < PNP_MAX_PORT; i++) {
-		res = &dev->res->port[i].res;
-		if (res->flags & IORESOURCE_UNSET)
-			break;
-	}
-	if (i < PNP_MAX_PORT) {
-		res->flags = IORESOURCE_IO;	// Also clears _UNSET flag
-		if (io_decode == ACPI_DECODE_16)
-			res->flags |= PNP_PORT_FLAG_16BITADDR;
-		if (len <= 0 || (io + len - 1) >= 0x10003) {
-			res->flags |= IORESOURCE_DISABLED;
-			return;
-		}
-		res->start = io;
-		res->end = io + len - 1;
-	} else if (!warned) {
-		printk(KERN_WARNING "pnpacpi: exceeded the max number of IO "
-				"resources: %d \n", PNP_MAX_PORT);
-		warned = 1;
-	}
+	if (io_decode == ACPI_DECODE_16)
+		flags |= PNP_PORT_FLAG_16BITADDR;
+	if (len == 0 || end >= 0x10003)
+		flags |= IORESOURCE_DISABLED;
+
+	pnp_add_io_resource(dev, start, end, flags);
 }
 
 static void pnpacpi_parse_allocated_memresource(struct pnp_dev *dev,
Index: work8/drivers/pnp/pnpbios/rsparser.c
===================================================================
--- work8.orig/drivers/pnp/pnpbios/rsparser.c	2008-04-18 11:03:34.000000000 -0600
+++ work8/drivers/pnp/pnpbios/rsparser.c	2008-04-18 11:05:06.000000000 -0600
@@ -55,26 +55,15 @@
  */
 
 static void pnpbios_parse_allocated_ioresource(struct pnp_dev *dev,
-					       int io, int len)
+					       int start, int len)
 {
-	struct resource *res;
-	int i;
+	int flags = 0;
+	int end = start + len - 1;
 
-	for (i = 0; i < PNP_MAX_PORT; i++) {
-		res = &dev->res->port[i].res;
-		if (res->flags & IORESOURCE_UNSET)
-			break;
-	}
+	if (len <= 0 || end >= 0x10003)
+		flags |= IORESOURCE_DISABLED;
 
-	if (i < PNP_MAX_PORT) {
-		res->flags = IORESOURCE_IO;	// Also clears _UNSET flag
-		if (len <= 0 || (io + len - 1) >= 0x10003) {
-			res->flags |= IORESOURCE_DISABLED;
-			return;
-		}
-		res->start = (unsigned long)io;
-		res->end = (unsigned long)(io + len - 1);
-	}
+	pnp_add_io_resource(dev, start, end, flags);
 }
 
 static void pnpbios_parse_allocated_memresource(struct pnp_dev *dev,
Index: work8/drivers/pnp/resource.c
===================================================================
--- work8.orig/drivers/pnp/resource.c	2008-04-18 11:03:34.000000000 -0600
+++ work8/drivers/pnp/resource.c	2008-04-18 11:05:06.000000000 -0600
@@ -607,6 +607,32 @@
 	return pnp_res;
 }
 
+struct pnp_resource *pnp_add_io_resource(struct pnp_dev *dev,
+					 resource_size_t start,
+					 resource_size_t end, int flags)
+{
+	struct pnp_resource *pnp_res;
+	struct resource *res;
+	static unsigned char warned;
+
+	pnp_res = pnp_new_resource(dev, IORESOURCE_IO);
+	if (!pnp_res) {
+		if (!warned) {
+			dev_err(&dev->dev, "can't add resource for IO "
+				"0x%llx-0x%llx\n",(unsigned long long) start,
+				(unsigned long long) end);
+			warned = 1;
+		}
+		return NULL;
+	}
+
+	res = &pnp_res->res;
+	res->flags = IORESOURCE_IO | flags;
+	res->start = start;
+	res->end = end;
+	return pnp_res;
+}
+
 /* format is: pnp_reserve_irq=irq1[,irq2] .... */
 static int __init pnp_setup_reserve_irq(char *str)
 {

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 42/53] PNP: make generic pnp_add_mem_resource()
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (40 preceding siblings ...)
  2008-04-18 20:50 ` [patch 41/53] PNP: make generic pnp_add_io_resource() Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 43/53] ISAPNP: fold isapnp_read_resources() back into isapnp_get_resources() Bjorn Helgaas
                   ` (10 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-common-add-mem-resource --]
[-- Type: text/plain, Size: 6686 bytes --]

Add a pnp_add_mem_resource() that can be used by all the PNP
backends.  This consolidates a little more pnp_resource_table
knowledge into one place.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>

---
 drivers/pnp/base.h             |    3 +++
 drivers/pnp/resource.c         |   26 ++++++++++++++++++++++++++
 drivers/pnp/interface.c        |   17 +++++++----------
 drivers/pnp/isapnp/core.c      |    9 +++------
 drivers/pnp/pnpacpi/rsparser.c |   32 ++++++++------------------------
 drivers/pnp/pnpbios/rsparser.c |   23 ++++++-----------------
 6 files changed, 53 insertions(+), 57 deletions(-)

Index: work8/drivers/pnp/base.h
===================================================================
--- work8.orig/drivers/pnp/base.h	2008-04-18 11:05:06.000000000 -0600
+++ work8/drivers/pnp/base.h	2008-04-18 11:06:13.000000000 -0600
@@ -43,3 +43,6 @@
 struct pnp_resource *pnp_add_io_resource(struct pnp_dev *dev,
 					 resource_size_t start,
 					 resource_size_t end, int flags);
+struct pnp_resource *pnp_add_mem_resource(struct pnp_dev *dev,
+					  resource_size_t start,
+					  resource_size_t end, int flags);
Index: work8/drivers/pnp/resource.c
===================================================================
--- work8.orig/drivers/pnp/resource.c	2008-04-18 11:05:06.000000000 -0600
+++ work8/drivers/pnp/resource.c	2008-04-18 11:06:13.000000000 -0600
@@ -633,6 +633,32 @@
 	return pnp_res;
 }
 
+struct pnp_resource *pnp_add_mem_resource(struct pnp_dev *dev,
+					  resource_size_t start,
+					  resource_size_t end, int flags)
+{
+	struct pnp_resource *pnp_res;
+	struct resource *res;
+	static unsigned char warned;
+
+	pnp_res = pnp_new_resource(dev, IORESOURCE_MEM);
+	if (!pnp_res) {
+		if (!warned) {
+			dev_err(&dev->dev, "can't add resource for MEM "
+				"0x%llx-0x%llx\n",(unsigned long long) start,
+				(unsigned long long) end);
+			warned = 1;
+		}
+		return NULL;
+	}
+
+	res = &pnp_res->res;
+	res->flags = IORESOURCE_MEM | flags;
+	res->start = start;
+	res->end = end;
+	return pnp_res;
+}
+
 /* format is: pnp_reserve_irq=irq1[,irq2] .... */
 static int __init pnp_setup_reserve_irq(char *str)
 {
Index: work8/drivers/pnp/interface.c
===================================================================
--- work8.orig/drivers/pnp/interface.c	2008-04-18 11:05:47.000000000 -0600
+++ work8/drivers/pnp/interface.c	2008-04-18 11:06:50.000000000 -0600
@@ -323,7 +323,6 @@
 {
 	struct pnp_dev *dev = to_pnp_dev(dmdev);
 	struct pnp_resource *pnp_res;
-	struct resource *res;
 	char *buf = (void *)ubuf;
 	int retval = 0;
 	resource_size_t start, end;
@@ -404,22 +403,20 @@
 				buf += 3;
 				while (isspace(*buf))
 					++buf;
-				res = pnp_get_resource(dev, IORESOURCE_MEM,
-						       nmem);
-				if (!res)
-					break;
-				res->start = simple_strtoul(buf, &buf, 0);
+				start = simple_strtoul(buf, &buf, 0);
 				while (isspace(*buf))
 					++buf;
 				if (*buf == '-') {
 					buf += 1;
 					while (isspace(*buf))
 						++buf;
-					res->end = simple_strtoul(buf, &buf, 0);
+					end = simple_strtoul(buf, &buf, 0);
 				} else
-					res->end = res->start;
-				res->flags = IORESOURCE_MEM;
-				nmem++;
+					end = start;
+				pnp_res = pnp_add_mem_resource(dev, start, end,
+							       0);
+				if (pnp_res)
+					pnp_res->index = nmem++;
 				continue;
 			}
 			if (!strnicmp(buf, "irq", 3)) {
Index: work8/drivers/pnp/isapnp/core.c
===================================================================
--- work8.orig/drivers/pnp/isapnp/core.c	2008-04-18 11:05:06.000000000 -0600
+++ work8/drivers/pnp/isapnp/core.c	2008-04-18 11:06:13.000000000 -0600
@@ -924,7 +924,6 @@
 static int isapnp_read_resources(struct pnp_dev *dev)
 {
 	struct pnp_resource *pnp_res;
-	struct resource *res;
 	int tmp, ret;
 
 	dev->active = isapnp_read_byte(ISAPNP_CFG_ACTIVATE);
@@ -942,11 +941,9 @@
 			    isapnp_read_word(ISAPNP_CFG_MEM + (tmp << 3)) << 8;
 			if (!ret)
 				continue;
-			pnp_res = &dev->res->mem[tmp];
-			pnp_res->index = tmp;
-			res = &pnp_res->res;
-			res->start = ret;
-			res->flags = IORESOURCE_MEM;
+			pnp_res = pnp_add_mem_resource(dev, ret, ret, 0);
+			if (pnp_res)
+				pnp_res->index = tmp;
 		}
 		for (tmp = 0; tmp < ISAPNP_MAX_IRQ; tmp++) {
 			ret =
Index: work8/drivers/pnp/pnpacpi/rsparser.c
===================================================================
--- work8.orig/drivers/pnp/pnpacpi/rsparser.c	2008-04-18 11:05:06.000000000 -0600
+++ work8/drivers/pnp/pnpacpi/rsparser.c	2008-04-18 11:06:13.000000000 -0600
@@ -173,34 +173,18 @@
 }
 
 static void pnpacpi_parse_allocated_memresource(struct pnp_dev *dev,
-						u64 mem, u64 len,
+						u64 start, u64 len,
 						int write_protect)
 {
-	struct resource *res;
-	int i;
-	static unsigned char warned;
+	int flags = 0;
+	u64 end = start + len - 1;
 
-	for (i = 0; i < PNP_MAX_MEM; i++) {
-		res = &dev->res->mem[i].res;
-		if (res->flags & IORESOURCE_UNSET)
-			break;
-	}
-	if (i < PNP_MAX_MEM) {
-		res->flags = IORESOURCE_MEM;	// Also clears _UNSET flag
-		if (len <= 0) {
-			res->flags |= IORESOURCE_DISABLED;
-			return;
-		}
-		if (write_protect == ACPI_READ_WRITE_MEMORY)
-			res->flags |= IORESOURCE_MEM_WRITEABLE;
+	if (len == 0)
+		flags |= IORESOURCE_DISABLED;
+	if (write_protect == ACPI_READ_WRITE_MEMORY)
+		flags |= IORESOURCE_MEM_WRITEABLE;
 
-		res->start = mem;
-		res->end = mem + len - 1;
-	} else if (!warned) {
-		printk(KERN_WARNING "pnpacpi: exceeded the max number of mem "
-				"resources: %d\n", PNP_MAX_MEM);
-		warned = 1;
-	}
+	pnp_add_mem_resource(dev, start, end, flags);
 }
 
 static void pnpacpi_parse_allocated_address_space(struct pnp_dev *dev,
Index: work8/drivers/pnp/pnpbios/rsparser.c
===================================================================
--- work8.orig/drivers/pnp/pnpbios/rsparser.c	2008-04-18 11:05:06.000000000 -0600
+++ work8/drivers/pnp/pnpbios/rsparser.c	2008-04-18 11:06:13.000000000 -0600
@@ -67,26 +67,15 @@
 }
 
 static void pnpbios_parse_allocated_memresource(struct pnp_dev *dev,
-						int mem, int len)
+						int start, int len)
 {
-	struct resource *res;
-	int i;
+	int flags = 0;
+	int end = start + len - 1;
 
-	for (i = 0; i < PNP_MAX_MEM; i++) {
-		res = &dev->res->mem[i].res;
-		if (res->flags & IORESOURCE_UNSET)
-			break;
-	}
+	if (len <= 0)
+		flags |= IORESOURCE_DISABLED;
 
-	if (i < PNP_MAX_MEM) {
-		res->flags = IORESOURCE_MEM;	// Also clears _UNSET flag
-		if (len <= 0) {
-			res->flags |= IORESOURCE_DISABLED;
-			return;
-		}
-		res->start = (unsigned long)mem;
-		res->end = (unsigned long)(mem + len - 1);
-	}
+	pnp_add_mem_resource(dev, start, end, flags);
 }
 
 static unsigned char *pnpbios_parse_allocated_resource_data(struct pnp_dev *dev,

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 43/53] ISAPNP: fold isapnp_read_resources() back into isapnp_get_resources()
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (41 preceding siblings ...)
  2008-04-18 20:50 ` [patch 42/53] PNP: make generic pnp_add_mem_resource() Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 44/53] PNP: add pnp_resource_type() internal interface Bjorn Helgaas
                   ` (9 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: isapnp-fold-isapnp_read_resources --]
[-- Type: text/plain, Size: 2795 bytes --]

isapnp_get_resources() does very little besides call
isapnp_read_resources(), so just fold them back together.

Based on a patch by Rene Herman <rene.herman@gmail.com>

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>

Index: work8/drivers/pnp/isapnp/core.c
===================================================================
--- work8.orig/drivers/pnp/isapnp/core.c	2008-04-18 12:27:43.000000000 -0600
+++ work8/drivers/pnp/isapnp/core.c	2008-04-18 12:32:37.000000000 -0600
@@ -921,61 +921,53 @@
 EXPORT_SYMBOL(isapnp_cfg_end);
 EXPORT_SYMBOL(isapnp_write_byte);
 
-static int isapnp_read_resources(struct pnp_dev *dev)
+static int isapnp_get_resources(struct pnp_dev *dev)
 {
 	struct pnp_resource *pnp_res;
-	int tmp, ret;
+	int i, ret;
 
+	pnp_init_resources(dev);
+	isapnp_cfg_begin(dev->card->number, dev->number);
 	dev->active = isapnp_read_byte(ISAPNP_CFG_ACTIVATE);
-	if (dev->active) {
-		for (tmp = 0; tmp < ISAPNP_MAX_PORT; tmp++) {
-			ret = isapnp_read_word(ISAPNP_CFG_PORT + (tmp << 1));
-			if (!ret)
-				continue;
+	if (!dev->active)
+		goto __end;
+
+	for (i = 0; i < ISAPNP_MAX_PORT; i++) {
+		ret = isapnp_read_word(ISAPNP_CFG_PORT + (i << 1));
+		if (ret) {
 			pnp_res = pnp_add_io_resource(dev, ret, ret, 0);
 			if (pnp_res)
-				pnp_res->index = tmp;
+				pnp_res->index = i;
 		}
-		for (tmp = 0; tmp < ISAPNP_MAX_MEM; tmp++) {
-			ret =
-			    isapnp_read_word(ISAPNP_CFG_MEM + (tmp << 3)) << 8;
-			if (!ret)
-				continue;
+	}
+	for (i = 0; i < ISAPNP_MAX_MEM; i++) {
+		ret = isapnp_read_word(ISAPNP_CFG_MEM + (i << 3)) << 8;
+		if (ret) {
 			pnp_res = pnp_add_mem_resource(dev, ret, ret, 0);
 			if (pnp_res)
-				pnp_res->index = tmp;
+				pnp_res->index = i;
 		}
-		for (tmp = 0; tmp < ISAPNP_MAX_IRQ; tmp++) {
-			ret =
-			    (isapnp_read_word(ISAPNP_CFG_IRQ + (tmp << 1)) >>
-			     8);
-			if (!ret)
-				continue;
+	}
+	for (i = 0; i < ISAPNP_MAX_IRQ; i++) {
+		ret = (isapnp_read_word(ISAPNP_CFG_IRQ + (i << 1)) >> 8);
+		if (ret) {
 			pnp_res = pnp_add_irq_resource(dev, ret, 0);
 			if (pnp_res)
-				pnp_res->index = tmp;
+				pnp_res->index = i;
 		}
-		for (tmp = 0; tmp < ISAPNP_MAX_DMA; tmp++) {
-			ret = isapnp_read_byte(ISAPNP_CFG_DMA + tmp);
-			if (ret == 4)
-				continue;
+	}
+	for (i = 0; i < ISAPNP_MAX_DMA; i++) {
+		ret = isapnp_read_byte(ISAPNP_CFG_DMA + i);
+		if (ret != 4) {
 			pnp_res = pnp_add_dma_resource(dev, ret, 0);
 			if  (pnp_res)
-				pnp_res->index = tmp;
+				pnp_res->index = i;
 		}
 	}
-	return 0;
-}
-
-static int isapnp_get_resources(struct pnp_dev *dev)
-{
-	int ret;
 
-	pnp_init_resources(dev);
-	isapnp_cfg_begin(dev->card->number, dev->number);
-	ret = isapnp_read_resources(dev);
+__end:
 	isapnp_cfg_end();
-	return ret;
+	return 0;
 }
 
 static int isapnp_set_resources(struct pnp_dev *dev)

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 44/53] PNP: add pnp_resource_type() internal interface
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (42 preceding siblings ...)
  2008-04-18 20:50 ` [patch 43/53] ISAPNP: fold isapnp_read_resources() back into isapnp_get_resources() Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 45/53] PNP: replace pnp_resource_table with dynamically allocated resources Bjorn Helgaas
                   ` (8 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-add-pnp_resource_type --]
[-- Type: text/plain, Size: 1116 bytes --]

Given a struct resource, this returns the type (IO, MEM, IRQ, DMA).

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>

Index: work8/drivers/pnp/base.h
===================================================================
--- work8.orig/drivers/pnp/base.h	2008-04-17 14:07:25.000000000 -0600
+++ work8/drivers/pnp/base.h	2008-04-17 14:07:37.000000000 -0600
@@ -18,6 +18,7 @@
 int pnp_check_dma(struct pnp_dev * dev, int idx);
 
 void pnp_init_resource(struct resource *res);
+int pnp_resource_type(struct resource *res);
 
 #define PNP_MAX_PORT		40
 #define PNP_MAX_MEM		24
Index: work8/drivers/pnp/resource.c
===================================================================
--- work8.orig/drivers/pnp/resource.c	2008-04-17 14:07:48.000000000 -0600
+++ work8/drivers/pnp/resource.c	2008-04-17 14:09:25.000000000 -0600
@@ -489,6 +489,12 @@
 #endif
 }
 
+int pnp_resource_type(struct resource *res)
+{
+	return res->flags & (IORESOURCE_IO  | IORESOURCE_MEM |
+			     IORESOURCE_IRQ | IORESOURCE_DMA);
+}
+
 struct resource *pnp_get_resource(struct pnp_dev *dev,
 				  unsigned int type, unsigned int num)
 {

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 45/53] PNP: replace pnp_resource_table with dynamically allocated resources
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (43 preceding siblings ...)
  2008-04-18 20:50 ` [patch 44/53] PNP: add pnp_resource_type() internal interface Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 46/53] PNP: remove ratelimit on add resource failures Bjorn Helgaas
                   ` (7 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-make-resources-dynamic --]
[-- Type: text/plain, Size: 10612 bytes --]

PNP used to have a fixed-size pnp_resource_table for tracking the
resources used by a device.  This table often overflowed, so we've
had to increase the table size, which wastes memory because most
devices have very few resources.

This patch replaces the table with a linked list of resources where
the entries are allocated on demand.

This removes messages like these:

    pnpacpi: exceeded the max number of IO resources
    00:01: too many PORTs (max 40)

References:

    http://bugzilla.kernel.org/show_bug.cgi?id=9535
    http://bugzilla.kernel.org/show_bug.cgi?id=9740
    http://lkml.org/lkml/2007/11/30/110

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>

---
 drivers/pnp/base.h        |   13 --------
 drivers/pnp/core.c        |   20 +++++++-----
 drivers/pnp/isapnp/core.c |   56 ++++++++++++++--------------------
 drivers/pnp/manager.c     |   33 +++++---------------
 drivers/pnp/resource.c    |   74 +++++++++++++---------------------------------
 include/linux/pnp.h       |    3 -
 6 files changed, 68 insertions(+), 131 deletions(-)

Index: work8/drivers/pnp/base.h
===================================================================
--- work8.orig/drivers/pnp/base.h	2008-04-18 12:33:55.000000000 -0600
+++ work8/drivers/pnp/base.h	2008-04-18 12:33:56.000000000 -0600
@@ -20,23 +20,12 @@
 void pnp_init_resource(struct resource *res);
 int pnp_resource_type(struct resource *res);
 
-#define PNP_MAX_PORT		40
-#define PNP_MAX_MEM		24
-#define PNP_MAX_IRQ		 2
-#define PNP_MAX_DMA		 2
-
 struct pnp_resource {
+	struct list_head list;
 	struct resource res;
 	unsigned int index;		/* ISAPNP config register index */
 };
 
-struct pnp_resource_table {
-	struct pnp_resource port[PNP_MAX_PORT];
-	struct pnp_resource mem[PNP_MAX_MEM];
-	struct pnp_resource dma[PNP_MAX_DMA];
-	struct pnp_resource irq[PNP_MAX_IRQ];
-};
-
 struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq,
 					  int flags);
 struct pnp_resource *pnp_add_dma_resource(struct pnp_dev *dev, int dma,
Index: work8/drivers/pnp/core.c
===================================================================
--- work8.orig/drivers/pnp/core.c	2008-04-18 12:27:14.000000000 -0600
+++ work8/drivers/pnp/core.c	2008-04-18 12:33:56.000000000 -0600
@@ -99,6 +99,16 @@
 	}
 }
 
+static void pnp_free_resources(struct pnp_dev *dev)
+{
+	struct pnp_resource *pnp_res;
+
+	list_for_each_entry(pnp_res, &dev->resources, list) {
+		list_del(&pnp_res->list);
+		kfree(pnp_res);
+	}
+}
+
 static void pnp_release_device(struct device *dmdev)
 {
 	struct pnp_dev *dev = to_pnp_dev(dmdev);
@@ -106,7 +116,7 @@
 	pnp_free_option(dev->independent);
 	pnp_free_option(dev->dependent);
 	pnp_free_ids(dev);
-	kfree(dev->res);
+	pnp_free_resources(dev);
 	kfree(dev);
 }
 
@@ -119,12 +129,7 @@
 	if (!dev)
 		return NULL;
 
-	dev->res = kzalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
-	if (!dev->res) {
-		kfree(dev);
-		return NULL;
-	}
-
+	INIT_LIST_HEAD(&dev->resources);
 	dev->protocol = protocol;
 	dev->number = id;
 
@@ -134,7 +139,6 @@
 
 	dev_id = pnp_add_id(dev, pnpid);
 	if (!dev_id) {
-		kfree(dev->res);
 		kfree(dev);
 		return NULL;
 	}
Index: work8/drivers/pnp/isapnp/core.c
===================================================================
--- work8.orig/drivers/pnp/isapnp/core.c	2008-04-18 12:32:37.000000000 -0600
+++ work8/drivers/pnp/isapnp/core.c	2008-04-18 12:33:56.000000000 -0600
@@ -970,53 +970,45 @@
 	return 0;
 }
 
+#define set(flags)	((flags & IORESOURCE_UNSET) == 0)
+
 static int isapnp_set_resources(struct pnp_dev *dev)
 {
 	struct pnp_resource *pnp_res;
 	struct resource *res;
-	int tmp, index;
+	int index, irq;
 
 	isapnp_cfg_begin(dev->card->number, dev->number);
 	dev->active = 1;
-	for (tmp = 0; tmp < ISAPNP_MAX_PORT; tmp++) {
-		pnp_res = &dev->res->port[tmp];
-		index = pnp_res->index;
+
+	list_for_each_entry(pnp_res, &dev->resources, list) {
 		res = &pnp_res->res;
-		if ((res->flags & (IORESOURCE_IO | IORESOURCE_UNSET)) ==
-				IORESOURCE_IO)
+		if (res->flags & IORESOURCE_UNSET)
+			continue;
+
+		index = pnp_res->index;
+		switch (pnp_resource_type(res)) {
+		case IORESOURCE_IO:
 			isapnp_write_word(ISAPNP_CFG_PORT + (index << 1),
 					  res->start);
-	}
-	for (tmp = 0; tmp < ISAPNP_MAX_IRQ; tmp++) {
-		pnp_res = &dev->res->irq[tmp];
-		index = pnp_res->index;
-		res = &pnp_res->res;
-		if ((res->flags & (IORESOURCE_IRQ | IORESOURCE_UNSET)) ==
-				IORESOURCE_IRQ) {
-			int irq = res->start;
+			break;
+		case IORESOURCE_MEM:
+			/* FIXME: We aren't handling 32bit mems properly here */
+			isapnp_write_word(ISAPNP_CFG_MEM + (index << 3),
+					  (res->start >> 8) & 0xffff);
+			break;
+		case IORESOURCE_IRQ:
+			irq = res->start;
 			if (irq == 2)
 				irq = 9;
 			isapnp_write_byte(ISAPNP_CFG_IRQ + (index << 1), irq);
-		}
-	}
-	for (tmp = 0; tmp < ISAPNP_MAX_DMA; tmp++) {
-		pnp_res = &dev->res->dma[tmp];
-		index = pnp_res->index;
-		res = &pnp_res->res;
-		if ((res->flags & (IORESOURCE_DMA | IORESOURCE_UNSET)) ==
-				IORESOURCE_DMA)
+			break;
+		case IORESOURCE_DMA:
 			isapnp_write_byte(ISAPNP_CFG_DMA + index, res->start);
+			break;
+		}
 	}
-	for (tmp = 0; tmp < ISAPNP_MAX_MEM; tmp++) {
-		pnp_res = &dev->res->mem[tmp];
-		index = pnp_res->index;
-		res = &pnp_res->res;
-		if ((res->flags & (IORESOURCE_MEM | IORESOURCE_UNSET)) ==
-				IORESOURCE_MEM)
-			isapnp_write_word(ISAPNP_CFG_MEM + (index << 3),
-				  (res->start >> 8) & 0xffff);
-	}
-	/* FIXME: We aren't handling 32bit mems properly here */
+
 	isapnp_activate(dev->number);
 	isapnp_cfg_end();
 	return 0;
Index: work8/drivers/pnp/manager.c
===================================================================
--- work8.orig/drivers/pnp/manager.c	2008-04-18 12:27:14.000000000 -0600
+++ work8/drivers/pnp/manager.c	2008-04-18 12:33:56.000000000 -0600
@@ -228,45 +228,30 @@
 
 /**
  * pnp_init_resources - Resets a resource table to default values.
- * @table: pointer to the desired resource table
+ * @dev: pointer to the desired device
  */
 void pnp_init_resources(struct pnp_dev *dev)
 {
+	struct pnp_resource *pnp_res;
 	struct resource *res;
-	int i;
 
-	for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IRQ, i)); i++)
-		pnp_init_resource(res);
-	for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_DMA, i)); i++)
-		pnp_init_resource(res);
-	for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IO, i)); i++)
-		pnp_init_resource(res);
-	for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++)
+	list_for_each_entry(pnp_res, &dev->resources, list) {
+		res = &pnp_res->res;
 		pnp_init_resource(res);
+	}
 }
 
 /**
  * pnp_clean_resources - clears resources that were not manually set
- * @res: the resources to clean
+ * @dev: pointer to the desired device
  */
 static void pnp_clean_resource_table(struct pnp_dev *dev)
 {
+	struct pnp_resource *pnp_res;
 	struct resource *res;
-	int i;
 
-	for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IRQ, i)); i++) {
-		if (res->flags & IORESOURCE_AUTO)
-			pnp_init_resource(res);
-	}
-	for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_DMA, i)); i++) {
-		if (res->flags & IORESOURCE_AUTO)
-			pnp_init_resource(res);
-	}
-	for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IO, i)); i++) {
-		if (res->flags & IORESOURCE_AUTO)
-			pnp_init_resource(res);
-	}
-	for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) {
+	list_for_each_entry(pnp_res, &dev->resources, list) {
+		res = &pnp_res->res;
 		if (res->flags & IORESOURCE_AUTO)
 			pnp_init_resource(res);
 	}
Index: work8/drivers/pnp/resource.c
===================================================================
--- work8.orig/drivers/pnp/resource.c	2008-04-18 12:33:55.000000000 -0600
+++ work8/drivers/pnp/resource.c	2008-04-18 12:33:56.000000000 -0600
@@ -498,25 +498,13 @@
 struct resource *pnp_get_resource(struct pnp_dev *dev,
 				  unsigned int type, unsigned int num)
 {
-	struct pnp_resource_table *res = dev->res;
+	struct pnp_resource *pnp_res;
+	struct resource *res;
 
-	switch (type) {
-	case IORESOURCE_IO:
-		if (num >= PNP_MAX_PORT)
-			return NULL;
-		return &res->port[num].res;
-	case IORESOURCE_MEM:
-		if (num >= PNP_MAX_MEM)
-			return NULL;
-		return &res->mem[num].res;
-	case IORESOURCE_IRQ:
-		if (num >= PNP_MAX_IRQ)
-			return NULL;
-		return &res->irq[num].res;
-	case IORESOURCE_DMA:
-		if (num >= PNP_MAX_DMA)
-			return NULL;
-		return &res->dma[num].res;
+	list_for_each_entry(pnp_res, &dev->resources, list) {
+		res = &pnp_res->res;
+		if (pnp_resource_type(res) == type && num-- == 0)
+			return res;
 	}
 	return NULL;
 }
@@ -526,43 +514,23 @@
 {
 	struct pnp_resource *pnp_res;
 	struct resource *res;
-	int i;
 
-	switch (type) {
-	case IORESOURCE_IO:
-		for (i = 0; i < PNP_MAX_PORT; i++) {
-			pnp_res = &dev->res->port[i];
-			res = &pnp_res->res;
-			if (res->flags & IORESOURCE_UNSET)
-				return pnp_res;
-		}
-		break;
-	case IORESOURCE_MEM:
-		for (i = 0; i < PNP_MAX_MEM; i++) {
-			pnp_res = &dev->res->mem[i];
-			res = &pnp_res->res;
-			if (res->flags & IORESOURCE_UNSET)
-				return pnp_res;
-		}
-		break;
-	case IORESOURCE_IRQ:
-		for (i = 0; i < PNP_MAX_IRQ; i++) {
-			pnp_res = &dev->res->irq[i];
-			res = &pnp_res->res;
-			if (res->flags & IORESOURCE_UNSET)
-				return pnp_res;
-		}
-		break;
-	case IORESOURCE_DMA:
-		for (i = 0; i < PNP_MAX_DMA; i++) {
-			pnp_res = &dev->res->dma[i];
-			res = &pnp_res->res;
-			if (res->flags & IORESOURCE_UNSET)
-				return pnp_res;
-		}
-		break;
+	list_for_each_entry(pnp_res, &dev->resources, list) {
+		res = &pnp_res->res;
+		if (pnp_resource_type(res) == type &&
+		    res->flags & IORESOURCE_UNSET)
+			return pnp_res;
 	}
-	return NULL;
+
+	pnp_res = kzalloc(sizeof(struct pnp_resource), GFP_KERNEL);
+	if (!pnp_res)
+		return NULL;
+
+	res = &pnp_res->res;
+	res->flags = type;
+	pnp_init_resource(res);
+	list_add_tail(&pnp_res->list, &dev->resources);
+	return pnp_res;
 }
 
 struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq,
Index: work8/include/linux/pnp.h
===================================================================
--- work8.orig/include/linux/pnp.h	2008-04-18 12:27:14.000000000 -0600
+++ work8/include/linux/pnp.h	2008-04-18 12:33:56.000000000 -0600
@@ -17,7 +17,6 @@
 
 struct pnp_protocol;
 struct pnp_dev;
-struct pnp_resource_table;
 
 /*
  * Resource Management
@@ -253,7 +252,7 @@
 	int capabilities;
 	struct pnp_option *independent;
 	struct pnp_option *dependent;
-	struct pnp_resource_table *res;
+	struct list_head resources;
 
 	char name[PNP_NAME_LEN];	/* contains a human-readable name */
 	unsigned short regs;		/* ISAPnP: supported registers */

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 46/53] PNP: remove ratelimit on add resource failures
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (44 preceding siblings ...)
  2008-04-18 20:50 ` [patch 45/53] PNP: replace pnp_resource_table with dynamically allocated resources Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 47/53] PNPACPI: move _CRS/_PRS warnings closer to the action Bjorn Helgaas
                   ` (6 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-remove-warning-ratelimit --]
[-- Type: text/plain, Size: 2423 bytes --]

We used to have a fixed-size resource table.  If a device had
twenty resources when the table only had space for ten, we didn't
need ten warnings, so we added the ratelimit.

Now that we can dynamically allocate new resources, we should
only get failures if the allocation fails.  That should be
rare enough that we don't need to ratelimit the messages.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>

Index: work8/drivers/pnp/resource.c
===================================================================
--- work8.orig/drivers/pnp/resource.c	2008-04-17 14:39:12.000000000 -0600
+++ work8/drivers/pnp/resource.c	2008-04-17 14:40:09.000000000 -0600
@@ -538,15 +538,10 @@
 {
 	struct pnp_resource *pnp_res;
 	struct resource *res;
-	static unsigned char warned;
 
 	pnp_res = pnp_new_resource(dev, IORESOURCE_IRQ);
 	if (!pnp_res) {
-		if (!warned) {
-			dev_err(&dev->dev, "can't add resource for IRQ %d\n",
-				irq);
-			warned = 1;
-		}
+		dev_err(&dev->dev, "can't add resource for IRQ %d\n", irq);
 		return NULL;
 	}
 
@@ -562,15 +557,10 @@
 {
 	struct pnp_resource *pnp_res;
 	struct resource *res;
-	static unsigned char warned;
 
 	pnp_res = pnp_new_resource(dev, IORESOURCE_DMA);
 	if (!pnp_res) {
-		if (!warned) {
-			dev_err(&dev->dev, "can't add resource for DMA %d\n",
-				dma);
-			warned = 1;
-		}
+		dev_err(&dev->dev, "can't add resource for DMA %d\n", dma);
 		return NULL;
 	}
 
@@ -587,16 +577,11 @@
 {
 	struct pnp_resource *pnp_res;
 	struct resource *res;
-	static unsigned char warned;
 
 	pnp_res = pnp_new_resource(dev, IORESOURCE_IO);
 	if (!pnp_res) {
-		if (!warned) {
-			dev_err(&dev->dev, "can't add resource for IO "
-				"0x%llx-0x%llx\n",(unsigned long long) start,
-				(unsigned long long) end);
-			warned = 1;
-		}
+		dev_err(&dev->dev, "can't add resource for IO 0x%llx-0x%llx\n",
+			(unsigned long long) start, (unsigned long long) end);
 		return NULL;
 	}
 
@@ -613,16 +598,11 @@
 {
 	struct pnp_resource *pnp_res;
 	struct resource *res;
-	static unsigned char warned;
 
 	pnp_res = pnp_new_resource(dev, IORESOURCE_MEM);
 	if (!pnp_res) {
-		if (!warned) {
-			dev_err(&dev->dev, "can't add resource for MEM "
-				"0x%llx-0x%llx\n",(unsigned long long) start,
-				(unsigned long long) end);
-			warned = 1;
-		}
+		dev_err(&dev->dev, "can't add resource for MEM 0x%llx-0x%llx\n",
+			(unsigned long long) start, (unsigned long long) end);
 		return NULL;
 	}
 

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 47/53] PNPACPI: move _CRS/_PRS warnings closer to the action
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (45 preceding siblings ...)
  2008-04-18 20:50 ` [patch 46/53] PNP: remove ratelimit on add resource failures Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 48/53] PNPACPI: remove some pnp_dbg calls Bjorn Helgaas
                   ` (5 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnpacpi-cleanup-CRS-PRS-warnings --]
[-- Type: text/plain, Size: 4796 bytes --]

Move warnings about _CRS and _PRS problems to the place where we
actually make the ACPI calls.  Then we don't have to pass around
acpi_status values any more than necessary.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>

Index: work8/drivers/pnp/pnpacpi/pnpacpi.h
===================================================================
--- work8.orig/drivers/pnp/pnpacpi/pnpacpi.h	2008-04-17 15:58:17.000000000 -0600
+++ work8/drivers/pnp/pnpacpi/pnpacpi.h	2008-04-17 15:58:22.000000000 -0600
@@ -5,8 +5,8 @@
 #include <linux/acpi.h>
 #include <linux/pnp.h>
 
-acpi_status pnpacpi_parse_allocated_resource(struct pnp_dev *);
-acpi_status pnpacpi_parse_resource_option_data(struct pnp_dev *);
+int pnpacpi_parse_allocated_resource(struct pnp_dev *);
+int pnpacpi_parse_resource_option_data(struct pnp_dev *);
 int pnpacpi_encode_resources(struct pnp_dev *, struct acpi_buffer *);
 int pnpacpi_build_resource_template(struct pnp_dev *, struct acpi_buffer *);
 #endif
Index: work8/drivers/pnp/pnpacpi/core.c
===================================================================
--- work8.orig/drivers/pnp/pnpacpi/core.c	2008-04-17 16:00:00.000000000 -0600
+++ work8/drivers/pnp/pnpacpi/core.c	2008-04-17 16:04:22.000000000 -0600
@@ -75,10 +75,7 @@
 
 static int pnpacpi_get_resources(struct pnp_dev *dev)
 {
-	acpi_status status;
-
-	status = pnpacpi_parse_allocated_resource(dev);
-	return ACPI_FAILURE(status) ? -ENODEV : 0;
+	return pnpacpi_parse_allocated_resource(dev);
 }
 
 static int pnpacpi_set_resources(struct pnp_dev *dev)
@@ -180,22 +177,11 @@
 	else
 		strncpy(dev->name, acpi_device_bid(device), sizeof(dev->name));
 
-	if (dev->active) {
-		/* parse allocated resource */
-		status = pnpacpi_parse_allocated_resource(dev);
-		if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
-			pnp_err("PnPACPI: METHOD_NAME__CRS failure for %s",
-				acpi_device_hid(device));
-		}
-	}
+	if (dev->active)
+		pnpacpi_parse_allocated_resource(dev);
 
-	if (dev->capabilities & PNP_CONFIGURABLE) {
-		status = pnpacpi_parse_resource_option_data(dev);
-		if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
-			pnp_err("PnPACPI: METHOD_NAME__PRS failure for %s",
-				acpi_device_hid(device));
-		}
-	}
+	if (dev->capabilities & PNP_CONFIGURABLE)
+		pnpacpi_parse_resource_option_data(dev);
 
 	if (device->flags.compatible_ids) {
 		struct acpi_compatible_id_list *cid_list = device->pnp.cid_list;
Index: work8/drivers/pnp/pnpacpi/rsparser.c
===================================================================
--- work8.orig/drivers/pnp/pnpacpi/rsparser.c	2008-04-17 15:58:29.000000000 -0600
+++ work8/drivers/pnp/pnpacpi/rsparser.c	2008-04-17 16:17:08.000000000 -0600
@@ -339,14 +339,21 @@
 	return AE_OK;
 }
 
-acpi_status pnpacpi_parse_allocated_resource(struct pnp_dev *dev)
+int pnpacpi_parse_allocated_resource(struct pnp_dev *dev)
 {
 	acpi_handle handle = dev->data;
+	acpi_status status;
 
 	pnp_init_resources(dev);
 
-	return acpi_walk_resources(handle, METHOD_NAME__CRS,
-				   pnpacpi_allocated_resource, dev);
+	status = acpi_walk_resources(handle, METHOD_NAME__CRS,
+				     pnpacpi_allocated_resource, dev);
+	if (ACPI_FAILURE(status)) {
+		if (status != AE_NOT_FOUND)
+			dev_err(&dev->dev, "can't evaluate _CRS: %d", status);
+		return -EPERM;
+	}
+	return 0;
 }
 
 static __init void pnpacpi_parse_dma_option(struct pnp_option *option,
@@ -656,7 +663,7 @@
 	return AE_OK;
 }
 
-acpi_status __init pnpacpi_parse_resource_option_data(struct pnp_dev *dev)
+int __init pnpacpi_parse_resource_option_data(struct pnp_dev *dev)
 {
 	acpi_handle handle = dev->data;
 	acpi_status status;
@@ -664,13 +671,19 @@
 
 	parse_data.option = pnp_register_independent_option(dev);
 	if (!parse_data.option)
-		return AE_ERROR;
+		return -ENOMEM;
+
 	parse_data.option_independent = parse_data.option;
 	parse_data.dev = dev;
 	status = acpi_walk_resources(handle, METHOD_NAME__PRS,
 				     pnpacpi_option_resource, &parse_data);
 
-	return status;
+	if (ACPI_FAILURE(status)) {
+		if (status != AE_NOT_FOUND)
+			dev_err(&dev->dev, "can't evaluate _PRS: %d", status);
+		return -EPERM;
+	}
+	return 0;
 }
 
 static int pnpacpi_supported_resource(struct acpi_resource *res)
@@ -729,7 +742,7 @@
 	status = acpi_walk_resources(handle, METHOD_NAME__CRS,
 				     pnpacpi_count_resources, &res_cnt);
 	if (ACPI_FAILURE(status)) {
-		dev_err(&dev->dev, "can't evaluate _CRS\n");
+		dev_err(&dev->dev, "can't evaluate _CRS: %d\n", status);
 		return -EINVAL;
 	}
 	if (!res_cnt)
@@ -744,7 +757,7 @@
 				     pnpacpi_type_resources, &resource);
 	if (ACPI_FAILURE(status)) {
 		kfree(buffer->pointer);
-		dev_err(&dev->dev, "can't evaluate _CRS\n");
+		dev_err(&dev->dev, "can't evaluate _CRS: %d\n", status);
 		return -EINVAL;
 	}
 	/* resource will pointer the end resource now */

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 48/53] PNPACPI: remove some pnp_dbg calls
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (46 preceding siblings ...)
  2008-04-18 20:50 ` [patch 47/53] PNPACPI: move _CRS/_PRS warnings closer to the action Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 49/53] PNP: make interfaces private to the PNP core Bjorn Helgaas
                   ` (4 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, Rene Herman, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnpacpi-remove-debug-prints --]
[-- Type: text/plain, Size: 2440 bytes --]

These are turned off by default and don't print much useful information
anyway.  Anybody debugging this area will likely need to add his or her
own printks anyway.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: Rene Herman <rene.herman@gmail.com>

Index: work8/drivers/pnp/pnpacpi/rsparser.c
===================================================================
--- work8.orig/drivers/pnp/pnpacpi/rsparser.c	2008-04-17 16:13:37.000000000 -0600
+++ work8/drivers/pnp/pnpacpi/rsparser.c	2008-04-17 16:14:21.000000000 -0600
@@ -751,7 +751,6 @@
 	buffer->pointer = kzalloc(buffer->length - 1, GFP_KERNEL);
 	if (!buffer->pointer)
 		return -ENOMEM;
-	pnp_dbg("Res cnt %d", res_cnt);
 	resource = (struct acpi_resource *)buffer->pointer;
 	status = acpi_walk_resources(handle, METHOD_NAME__CRS,
 				     pnpacpi_type_resources, &resource);
@@ -909,54 +908,45 @@
 	struct acpi_resource *resource = buffer->pointer;
 	int port = 0, irq = 0, dma = 0, mem = 0;
 
-	pnp_dbg("res cnt %d", res_cnt);
 	while (i < res_cnt) {
 		switch (resource->type) {
 		case ACPI_RESOURCE_TYPE_IRQ:
-			pnp_dbg("Encode irq");
 			pnpacpi_encode_irq(resource,
 				pnp_get_resource(dev, IORESOURCE_IRQ, irq));
 			irq++;
 			break;
 
 		case ACPI_RESOURCE_TYPE_DMA:
-			pnp_dbg("Encode dma");
 			pnpacpi_encode_dma(resource,
 				pnp_get_resource(dev, IORESOURCE_DMA, dma));
 			dma++;
 			break;
 		case ACPI_RESOURCE_TYPE_IO:
-			pnp_dbg("Encode io");
 			pnpacpi_encode_io(resource,
 				pnp_get_resource(dev, IORESOURCE_IO, port));
 			port++;
 			break;
 		case ACPI_RESOURCE_TYPE_FIXED_IO:
-			pnp_dbg("Encode fixed io");
 			pnpacpi_encode_fixed_io(resource,
 				pnp_get_resource(dev, IORESOURCE_IO, port));
 			port++;
 			break;
 		case ACPI_RESOURCE_TYPE_MEMORY24:
-			pnp_dbg("Encode mem24");
 			pnpacpi_encode_mem24(resource,
 				pnp_get_resource(dev, IORESOURCE_MEM, mem));
 			mem++;
 			break;
 		case ACPI_RESOURCE_TYPE_MEMORY32:
-			pnp_dbg("Encode mem32");
 			pnpacpi_encode_mem32(resource,
 				pnp_get_resource(dev, IORESOURCE_MEM, mem));
 			mem++;
 			break;
 		case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
-			pnp_dbg("Encode fixed mem32");
 			pnpacpi_encode_fixed_mem32(resource,
 				pnp_get_resource(dev, IORESOURCE_MEM, mem));
 			mem++;
 			break;
 		case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
-			pnp_dbg("Encode ext irq");
 			pnpacpi_encode_ext_irq(resource,
 				pnp_get_resource(dev, IORESOURCE_IRQ, irq));
 			irq++;

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 49/53] PNP: make interfaces private to the PNP core
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (47 preceding siblings ...)
  2008-04-18 20:50 ` [patch 48/53] PNPACPI: remove some pnp_dbg calls Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 50/53] ISAPNP: remove unused pnp_dev->regs field Bjorn Helgaas
                   ` (3 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, Rene Herman, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-make-interfaces-private --]
[-- Type: text/plain, Size: 6791 bytes --]

The interfaces for registering protocols, devices, cards,
and resource options should only be used inside the PNP core.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: Rene Herman <rene.herman@gmail.com>

---
 drivers/pnp/base.h  |   24 +++++++++++++++++++++++-
 include/linux/pnp.h |   34 ----------------------------------
 2 files changed, 23 insertions(+), 35 deletions(-)

Index: work8/include/linux/pnp.h
===================================================================
--- work8.orig/include/linux/pnp.h	2008-04-17 15:05:18.000000000 -0600
+++ work8/include/linux/pnp.h	2008-04-17 16:19:05.000000000 -0600
@@ -416,19 +416,12 @@
 #if defined(CONFIG_PNP)
 
 /* device management */
-int pnp_register_protocol(struct pnp_protocol *protocol);
-void pnp_unregister_protocol(struct pnp_protocol *protocol);
-int pnp_add_device(struct pnp_dev *dev);
 int pnp_device_attach(struct pnp_dev *pnp_dev);
 void pnp_device_detach(struct pnp_dev *pnp_dev);
 extern struct list_head pnp_global;
 extern int pnp_platform_devices;
 
 /* multidevice card support */
-int pnp_add_card(struct pnp_card *card);
-void pnp_remove_card(struct pnp_card *card);
-int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev);
-void pnp_remove_card_device(struct pnp_dev *dev);
 struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink,
 					const char *id, struct pnp_dev *from);
 void pnp_release_card_device(struct pnp_dev *dev);
@@ -437,23 +430,12 @@
 extern struct list_head pnp_cards;
 
 /* resource management */
-struct pnp_option *pnp_register_independent_option(struct pnp_dev *dev);
-struct pnp_option *pnp_register_dependent_option(struct pnp_dev *dev,
-						 int priority);
-int pnp_register_irq_resource(struct pnp_option *option, struct pnp_irq *data);
-int pnp_register_dma_resource(struct pnp_option *option, struct pnp_dma *data);
-int pnp_register_port_resource(struct pnp_option *option,
-			       struct pnp_port *data);
-int pnp_register_mem_resource(struct pnp_option *option, struct pnp_mem *data);
-void pnp_init_resources(struct pnp_dev *dev);
 int pnp_auto_config_dev(struct pnp_dev *dev);
-int pnp_validate_config(struct pnp_dev *dev);
 int pnp_start_dev(struct pnp_dev *dev);
 int pnp_stop_dev(struct pnp_dev *dev);
 int pnp_activate_dev(struct pnp_dev *dev);
 int pnp_disable_dev(struct pnp_dev *dev);
 
-
 /* protocol helpers */
 int pnp_is_active(struct pnp_dev *dev);
 int compare_pnp_id(struct pnp_id *pos, const char *id);
@@ -463,35 +445,19 @@
 #else
 
 /* device management */
-static inline int pnp_register_protocol(struct pnp_protocol *protocol) { return -ENODEV; }
-static inline void pnp_unregister_protocol(struct pnp_protocol *protocol) { }
-static inline int pnp_init_device(struct pnp_dev *dev) { return -ENODEV; }
-static inline int pnp_add_device(struct pnp_dev *dev) { return -ENODEV; }
 static inline int pnp_device_attach(struct pnp_dev *pnp_dev) { return -ENODEV; }
 static inline void pnp_device_detach(struct pnp_dev *pnp_dev) { }
 
 #define pnp_platform_devices 0
 
 /* multidevice card support */
-static inline int pnp_add_card(struct pnp_card *card) { return -ENODEV; }
-static inline void pnp_remove_card(struct pnp_card *card) { }
-static inline int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev) { return -ENODEV; }
-static inline void pnp_remove_card_device(struct pnp_dev *dev) { }
 static inline struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink, const char *id, struct pnp_dev *from) { return NULL; }
 static inline void pnp_release_card_device(struct pnp_dev *dev) { }
 static inline int pnp_register_card_driver(struct pnp_card_driver *drv) { return -ENODEV; }
 static inline void pnp_unregister_card_driver(struct pnp_card_driver *drv) { }
 
 /* resource management */
-static inline struct pnp_option *pnp_register_independent_option(struct pnp_dev *dev) { return NULL; }
-static inline struct pnp_option *pnp_register_dependent_option(struct pnp_dev *dev, int priority) { return NULL; }
-static inline int pnp_register_irq_resource(struct pnp_option *option, struct pnp_irq *data) { return -ENODEV; }
-static inline int pnp_register_dma_resource(struct pnp_option *option, struct pnp_dma *data) { return -ENODEV; }
-static inline int pnp_register_port_resource(struct pnp_option *option, struct pnp_port *data) { return -ENODEV; }
-static inline int pnp_register_mem_resource(struct pnp_option *option, struct pnp_mem *data) { return -ENODEV; }
-static inline void pnp_init_resources(struct pnp_dev *dev) { }
 static inline int pnp_auto_config_dev(struct pnp_dev *dev) { return -ENODEV; }
-static inline int pnp_validate_config(struct pnp_dev *dev) { return -ENODEV; }
 static inline int pnp_start_dev(struct pnp_dev *dev) { return -ENODEV; }
 static inline int pnp_stop_dev(struct pnp_dev *dev) { return -ENODEV; }
 static inline int pnp_activate_dev(struct pnp_dev *dev) { return -ENODEV; }
Index: work8/drivers/pnp/base.h
===================================================================
--- work8.orig/drivers/pnp/base.h	2008-04-17 15:05:18.000000000 -0600
+++ work8/drivers/pnp/base.h	2008-04-17 16:19:05.000000000 -0600
@@ -1,12 +1,34 @@
 extern spinlock_t pnp_lock;
 void *pnp_alloc(long size);
+
+int pnp_register_protocol(struct pnp_protocol *protocol);
+void pnp_unregister_protocol(struct pnp_protocol *protocol);
+
 #define PNP_EISA_ID_MASK 0x7fffffff
 void pnp_eisa_id_to_string(u32 id, char *str);
 struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *, int id, char *pnpid);
 struct pnp_card *pnp_alloc_card(struct pnp_protocol *, int id, char *pnpid);
+
+int pnp_add_device(struct pnp_dev *dev);
 struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id);
-struct pnp_id *pnp_add_card_id(struct pnp_card *card, char *id);
 int pnp_interface_attach_device(struct pnp_dev *dev);
+
+int pnp_add_card(struct pnp_card *card);
+struct pnp_id *pnp_add_card_id(struct pnp_card *card, char *id);
+void pnp_remove_card(struct pnp_card *card);
+int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev);
+void pnp_remove_card_device(struct pnp_dev *dev);
+
+struct pnp_option *pnp_register_independent_option(struct pnp_dev *dev);
+struct pnp_option *pnp_register_dependent_option(struct pnp_dev *dev,
+						 int priority);
+int pnp_register_irq_resource(struct pnp_option *option, struct pnp_irq *data);
+int pnp_register_dma_resource(struct pnp_option *option, struct pnp_dma *data);
+int pnp_register_port_resource(struct pnp_option *option,
+			       struct pnp_port *data);
+int pnp_register_mem_resource(struct pnp_option *option, struct pnp_mem *data);
+void pnp_init_resources(struct pnp_dev *dev);
+
 void pnp_fixup_device(struct pnp_dev *dev);
 void pnp_free_option(struct pnp_option *option);
 int __pnp_add_device(struct pnp_dev *dev);

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 50/53] ISAPNP: remove unused pnp_dev->regs field
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (48 preceding siblings ...)
  2008-04-18 20:50 ` [patch 49/53] PNP: make interfaces private to the PNP core Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 51/53] PNPBIOS: remove include/linux/pnpbios.h Bjorn Helgaas
                   ` (2 subsequent siblings)
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: isapnp-remove-unused-pnp_dev-fields --]
[-- Type: text/plain, Size: 1171 bytes --]

The "regs" field in struct pnp_dev is set but never read, so remove it.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>

Index: work8/drivers/pnp/isapnp/core.c
===================================================================
--- work8.orig/drivers/pnp/isapnp/core.c	2008-04-18 11:15:16.000000000 -0600
+++ work8/drivers/pnp/isapnp/core.c	2008-04-18 11:19:49.000000000 -0600
@@ -416,10 +416,7 @@
 	if (!dev)
 		return NULL;
 
-	dev->regs = tmp[4];
 	dev->card = card;
-	if (size > 5)
-		dev->regs |= tmp[5] << 8;
 	dev->capabilities |= PNP_CONFIGURABLE;
 	dev->capabilities |= PNP_READ;
 	dev->capabilities |= PNP_WRITE;
Index: work8/include/linux/pnp.h
===================================================================
--- work8.orig/include/linux/pnp.h	2008-04-18 11:19:43.000000000 -0600
+++ work8/include/linux/pnp.h	2008-04-18 11:19:49.000000000 -0600
@@ -255,7 +255,6 @@
 	struct list_head resources;
 
 	char name[PNP_NAME_LEN];	/* contains a human-readable name */
-	unsigned short regs;		/* ISAPnP: supported registers */
 	int flags;			/* used by protocols */
 	struct proc_dir_entry *procent;	/* device entry in /proc/bus/isapnp */
 	void *data;

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 51/53] PNPBIOS: remove include/linux/pnpbios.h
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (49 preceding siblings ...)
  2008-04-18 20:50 ` [patch 50/53] ISAPNP: remove unused pnp_dev->regs field Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 52/53] PNP: fill in generic pnp_dev fields earlier Bjorn Helgaas
  2008-04-18 20:50 ` [patch 53/53] PNP: dont sort by type in /sys/.../resources Bjorn Helgaas
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnpbios-remove-public-header --]
[-- Type: text/plain, Size: 12188 bytes --]

The contents of include/linux/pnpbios.h are used only inside the PNPBIOS
backend, so this file doesn't need to be visible outside PNP.

This patch moves the contents into an existing PNPBIOS-specific file,
drivers/pnp/pnpbios/pnpbios.h.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>

---
 drivers/pnp/pnpbios/bioscalls.c |    1 
 drivers/pnp/pnpbios/core.c      |    1 
 drivers/pnp/pnpbios/pnpbios.h   |  136 ++++++++++++++++++++++++++++++++++++
 drivers/pnp/pnpbios/proc.c      |    2 
 drivers/pnp/pnpbios/rsparser.c  |    1 
 include/linux/pnpbios.h         |  151 ----------------------------------------
 6 files changed, 137 insertions(+), 155 deletions(-)

Index: work7/drivers/pnp/pnpbios/bioscalls.c
===================================================================
--- work7.orig/drivers/pnp/pnpbios/bioscalls.c	2008-04-04 14:44:01.000000000 -0600
+++ work7/drivers/pnp/pnpbios/bioscalls.c	2008-04-04 14:47:36.000000000 -0600
@@ -7,7 +7,6 @@
 #include <linux/init.h>
 #include <linux/linkage.h>
 #include <linux/kernel.h>
-#include <linux/pnpbios.h>
 #include <linux/device.h>
 #include <linux/pnp.h>
 #include <linux/mm.h>
Index: work7/drivers/pnp/pnpbios/core.c
===================================================================
--- work7.orig/drivers/pnp/pnpbios/core.c	2008-04-04 14:44:32.000000000 -0600
+++ work7/drivers/pnp/pnpbios/core.c	2008-04-04 14:44:45.000000000 -0600
@@ -50,7 +50,6 @@
 #include <linux/init.h>
 #include <linux/linkage.h>
 #include <linux/kernel.h>
-#include <linux/pnpbios.h>
 #include <linux/device.h>
 #include <linux/pnp.h>
 #include <linux/mm.h>
Index: work7/drivers/pnp/pnpbios/pnpbios.h
===================================================================
--- work7.orig/drivers/pnp/pnpbios/pnpbios.h	2008-04-04 14:34:16.000000000 -0600
+++ work7/drivers/pnp/pnpbios/pnpbios.h	2008-04-04 14:38:27.000000000 -0600
@@ -2,6 +2,142 @@
  * pnpbios.h - contains local definitions
  */
 
+/*
+ * Include file for the interface to a PnP BIOS
+ *
+ * Original BIOS code (C) 1998 Christian Schmidt (chr.schmidt@tu-bs.de)
+ * PnP handler parts (c) 1998 Tom Lees <tom@lpsg.demon.co.uk>
+ * Minor reorganizations by David Hinds <dahinds@users.sourceforge.net>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * Return codes
+ */
+#define PNP_SUCCESS                     0x00
+#define PNP_NOT_SET_STATICALLY          0x7f
+#define PNP_UNKNOWN_FUNCTION            0x81
+#define PNP_FUNCTION_NOT_SUPPORTED      0x82
+#define PNP_INVALID_HANDLE              0x83
+#define PNP_BAD_PARAMETER               0x84
+#define PNP_SET_FAILED                  0x85
+#define PNP_EVENTS_NOT_PENDING          0x86
+#define PNP_SYSTEM_NOT_DOCKED           0x87
+#define PNP_NO_ISA_PNP_CARDS            0x88
+#define PNP_UNABLE_TO_DETERMINE_DOCK_CAPABILITIES 0x89
+#define PNP_CONFIG_CHANGE_FAILED_NO_BATTERY 0x8a
+#define PNP_CONFIG_CHANGE_FAILED_RESOURCE_CONFLICT 0x8b
+#define PNP_BUFFER_TOO_SMALL            0x8c
+#define PNP_USE_ESCD_SUPPORT            0x8d
+#define PNP_MESSAGE_NOT_SUPPORTED       0x8e
+#define PNP_HARDWARE_ERROR              0x8f
+
+#define ESCD_SUCCESS                    0x00
+#define ESCD_IO_ERROR_READING           0x55
+#define ESCD_INVALID                    0x56
+#define ESCD_BUFFER_TOO_SMALL           0x59
+#define ESCD_NVRAM_TOO_SMALL            0x5a
+#define ESCD_FUNCTION_NOT_SUPPORTED     0x81
+
+/*
+ * Events that can be received by "get event"
+ */
+#define PNPEV_ABOUT_TO_CHANGE_CONFIG	0x0001
+#define PNPEV_DOCK_CHANGED		0x0002
+#define PNPEV_SYSTEM_DEVICE_CHANGED	0x0003
+#define PNPEV_CONFIG_CHANGED_FAILED	0x0004
+#define PNPEV_UNKNOWN_SYSTEM_EVENT	0xffff
+/* 0x8000 through 0xfffe are OEM defined */
+
+/*
+ * Messages that should be sent through "send message"
+ */
+#define PNPMSG_OK			0x00
+#define PNPMSG_ABORT			0x01
+#define PNPMSG_UNDOCK_DEFAULT_ACTION	0x40
+#define PNPMSG_POWER_OFF		0x41
+#define PNPMSG_PNP_OS_ACTIVE		0x42
+#define PNPMSG_PNP_OS_INACTIVE		0x43
+
+/*
+ * Plug and Play BIOS flags
+ */
+#define PNPBIOS_NO_DISABLE		0x0001
+#define PNPBIOS_NO_CONFIG		0x0002
+#define PNPBIOS_OUTPUT			0x0004
+#define PNPBIOS_INPUT			0x0008
+#define PNPBIOS_BOOTABLE		0x0010
+#define PNPBIOS_DOCK			0x0020
+#define PNPBIOS_REMOVABLE		0x0040
+#define pnpbios_is_static(x) (((x)->flags & 0x0100) == 0x0000)
+#define pnpbios_is_dynamic(x) ((x)->flags & 0x0080)
+
+/*
+ * Function Parameters
+ */
+#define PNPMODE_STATIC 1
+#define PNPMODE_DYNAMIC 0
+
+/* 0x8000 through 0xffff are OEM defined */
+
+#pragma pack(1)
+struct pnp_dev_node_info {
+	__u16 no_nodes;
+	__u16 max_node_size;
+};
+struct pnp_docking_station_info {
+	__u32 location_id;
+	__u32 serial;
+	__u16 capabilities;
+};
+struct pnp_isa_config_struc {
+	__u8 revision;
+	__u8 no_csns;
+	__u16 isa_rd_data_port;
+	__u16 reserved;
+};
+struct escd_info_struc {
+	__u16 min_escd_write_size;
+	__u16 escd_size;
+	__u32 nv_storage_base;
+};
+struct pnp_bios_node {
+	__u16 size;
+	__u8 handle;
+	__u32 eisa_id;
+	__u8 type_code[3];
+	__u16 flags;
+	__u8 data[0];
+};
+#pragma pack()
+
+/* non-exported */
+extern struct pnp_dev_node_info node_info;
+
+extern int pnp_bios_dev_node_info(struct pnp_dev_node_info *data);
+extern int pnp_bios_get_dev_node(u8 *nodenum, char config,
+				 struct pnp_bios_node *data);
+extern int pnp_bios_set_dev_node(u8 nodenum, char config,
+				 struct pnp_bios_node *data);
+extern int pnp_bios_get_stat_res(char *info);
+extern int pnp_bios_isapnp_config(struct pnp_isa_config_struc *data);
+extern int pnp_bios_escd_info(struct escd_info_struc *data);
+extern int pnp_bios_read_escd(char *data, u32 nvram_base);
+extern int pnp_bios_dock_station_info(struct pnp_docking_station_info *data);
+
 #pragma pack(1)
 union pnp_bios_install_struct {
 	struct {
Index: work7/drivers/pnp/pnpbios/proc.c
===================================================================
--- work7.orig/drivers/pnp/pnpbios/proc.c	2008-04-04 14:43:14.000000000 -0600
+++ work7/drivers/pnp/pnpbios/proc.c	2008-04-04 14:43:47.000000000 -0600
@@ -23,7 +23,7 @@
 #include <linux/slab.h>
 #include <linux/types.h>
 #include <linux/proc_fs.h>
-#include <linux/pnpbios.h>
+#include <linux/pnp.h>
 #include <linux/init.h>
 
 #include <asm/uaccess.h>
Index: work7/drivers/pnp/pnpbios/rsparser.c
===================================================================
--- work7.orig/drivers/pnp/pnpbios/rsparser.c	2008-04-04 14:44:50.000000000 -0600
+++ work7/drivers/pnp/pnpbios/rsparser.c	2008-04-04 14:44:55.000000000 -0600
@@ -4,7 +4,6 @@
 
 #include <linux/ctype.h>
 #include <linux/pnp.h>
-#include <linux/pnpbios.h>
 #include <linux/string.h>
 #include <linux/slab.h>
 
Index: work7/include/linux/pnpbios.h
===================================================================
--- work7.orig/include/linux/pnpbios.h	2008-04-04 14:33:53.000000000 -0600
+++ /dev/null	1970-01-01 00:00:00.000000000 +0000
@@ -1,151 +0,0 @@
-/*
- * Include file for the interface to a PnP BIOS
- *
- * Original BIOS code (C) 1998 Christian Schmidt (chr.schmidt@tu-bs.de)
- * PnP handler parts (c) 1998 Tom Lees <tom@lpsg.demon.co.uk>
- * Minor reorganizations by David Hinds <dahinds@users.sourceforge.net>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2, or (at your option) any
- * later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-#ifndef _LINUX_PNPBIOS_H
-#define _LINUX_PNPBIOS_H
-
-#ifdef __KERNEL__
-
-#include <linux/types.h>
-#include <linux/pnp.h>
-
-/*
- * Return codes
- */
-#define PNP_SUCCESS                     0x00
-#define PNP_NOT_SET_STATICALLY          0x7f
-#define PNP_UNKNOWN_FUNCTION            0x81
-#define PNP_FUNCTION_NOT_SUPPORTED      0x82
-#define PNP_INVALID_HANDLE              0x83
-#define PNP_BAD_PARAMETER               0x84
-#define PNP_SET_FAILED                  0x85
-#define PNP_EVENTS_NOT_PENDING          0x86
-#define PNP_SYSTEM_NOT_DOCKED           0x87
-#define PNP_NO_ISA_PNP_CARDS            0x88
-#define PNP_UNABLE_TO_DETERMINE_DOCK_CAPABILITIES 0x89
-#define PNP_CONFIG_CHANGE_FAILED_NO_BATTERY 0x8a
-#define PNP_CONFIG_CHANGE_FAILED_RESOURCE_CONFLICT 0x8b
-#define PNP_BUFFER_TOO_SMALL            0x8c
-#define PNP_USE_ESCD_SUPPORT            0x8d
-#define PNP_MESSAGE_NOT_SUPPORTED       0x8e
-#define PNP_HARDWARE_ERROR              0x8f
-
-#define ESCD_SUCCESS                    0x00
-#define ESCD_IO_ERROR_READING           0x55
-#define ESCD_INVALID                    0x56
-#define ESCD_BUFFER_TOO_SMALL           0x59
-#define ESCD_NVRAM_TOO_SMALL            0x5a
-#define ESCD_FUNCTION_NOT_SUPPORTED     0x81
-
-/*
- * Events that can be received by "get event"
- */
-#define PNPEV_ABOUT_TO_CHANGE_CONFIG	0x0001
-#define PNPEV_DOCK_CHANGED		0x0002
-#define PNPEV_SYSTEM_DEVICE_CHANGED	0x0003
-#define PNPEV_CONFIG_CHANGED_FAILED	0x0004
-#define PNPEV_UNKNOWN_SYSTEM_EVENT	0xffff
-/* 0x8000 through 0xfffe are OEM defined */
-
-/*
- * Messages that should be sent through "send message"
- */
-#define PNPMSG_OK			0x00
-#define PNPMSG_ABORT			0x01
-#define PNPMSG_UNDOCK_DEFAULT_ACTION	0x40
-#define PNPMSG_POWER_OFF		0x41
-#define PNPMSG_PNP_OS_ACTIVE		0x42
-#define PNPMSG_PNP_OS_INACTIVE		0x43
-
-/*
- * Plug and Play BIOS flags
- */
-#define PNPBIOS_NO_DISABLE		0x0001
-#define PNPBIOS_NO_CONFIG		0x0002
-#define PNPBIOS_OUTPUT			0x0004
-#define PNPBIOS_INPUT			0x0008
-#define PNPBIOS_BOOTABLE		0x0010
-#define PNPBIOS_DOCK			0x0020
-#define PNPBIOS_REMOVABLE		0x0040
-#define pnpbios_is_static(x) (((x)->flags & 0x0100) == 0x0000)
-#define pnpbios_is_dynamic(x) ((x)->flags & 0x0080)
-
-/*
- * Function Parameters
- */
-#define PNPMODE_STATIC 1
-#define PNPMODE_DYNAMIC 0
-
-/* 0x8000 through 0xffff are OEM defined */
-
-#pragma pack(1)
-struct pnp_dev_node_info {
-	__u16 no_nodes;
-	__u16 max_node_size;
-};
-struct pnp_docking_station_info {
-	__u32 location_id;
-	__u32 serial;
-	__u16 capabilities;
-};
-struct pnp_isa_config_struc {
-	__u8 revision;
-	__u8 no_csns;
-	__u16 isa_rd_data_port;
-	__u16 reserved;
-};
-struct escd_info_struc {
-	__u16 min_escd_write_size;
-	__u16 escd_size;
-	__u32 nv_storage_base;
-};
-struct pnp_bios_node {
-	__u16 size;
-	__u8 handle;
-	__u32 eisa_id;
-	__u8 type_code[3];
-	__u16 flags;
-	__u8 data[0];
-};
-#pragma pack()
-
-#ifdef CONFIG_PNPBIOS
-
-/* non-exported */
-extern struct pnp_dev_node_info node_info;
-
-extern int pnp_bios_dev_node_info(struct pnp_dev_node_info *data);
-extern int pnp_bios_get_dev_node(u8 *nodenum, char config,
-				 struct pnp_bios_node *data);
-extern int pnp_bios_set_dev_node(u8 nodenum, char config,
-				 struct pnp_bios_node *data);
-extern int pnp_bios_get_stat_res(char *info);
-extern int pnp_bios_isapnp_config(struct pnp_isa_config_struc *data);
-extern int pnp_bios_escd_info(struct escd_info_struc *data);
-extern int pnp_bios_read_escd(char *data, u32 nvram_base);
-extern int pnp_bios_dock_station_info(struct pnp_docking_station_info *data);
-
-#endif /* CONFIG_PNPBIOS */
-
-#endif /* __KERNEL__ */
-
-#endif /* _LINUX_PNPBIOS_H */

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 52/53] PNP: fill in generic pnp_dev fields earlier
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (50 preceding siblings ...)
  2008-04-18 20:50 ` [patch 51/53] PNPBIOS: remove include/linux/pnpbios.h Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  2008-04-18 20:50 ` [patch 53/53] PNP: dont sort by type in /sys/.../resources Bjorn Helgaas
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-init-pnp_dev-generic-stuff-earlier --]
[-- Type: text/plain, Size: 1119 bytes --]

This makes dev_printk() work better because we have a default driver.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>

Index: work8/drivers/pnp/core.c
===================================================================
--- work8.orig/drivers/pnp/core.c	2008-04-17 15:05:18.000000000 -0600
+++ work8/drivers/pnp/core.c	2008-04-17 17:13:12.000000000 -0600
@@ -132,8 +132,13 @@
 	INIT_LIST_HEAD(&dev->resources);
 	dev->protocol = protocol;
 	dev->number = id;
+	dev->dma_mask = DMA_24BIT_MASK;
 
 	dev->dev.parent = &dev->protocol->dev;
+	dev->dev.bus = &pnp_bus_type;
+	dev->dev.dma_mask = &dev->dma_mask;
+	dev->dev.coherent_dma_mask = dev->dma_mask;
+	dev->dev.release = &pnp_release_device;
 	sprintf(dev->dev.bus_id, "%02x:%02x", dev->protocol->number,
 		dev->number);
 
@@ -151,10 +156,6 @@
 	int ret;
 
 	pnp_fixup_device(dev);
-	dev->dev.bus = &pnp_bus_type;
-	dev->dev.dma_mask = &dev->dma_mask;
-	dev->dma_mask = dev->dev.coherent_dma_mask = DMA_24BIT_MASK;
-	dev->dev.release = &pnp_release_device;
 	dev->status = PNP_READY;
 	spin_lock(&pnp_lock);
 	list_add_tail(&dev->global_list, &pnp_global);

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* [patch 53/53] PNP: dont sort by type in /sys/.../resources
  2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
                   ` (51 preceding siblings ...)
  2008-04-18 20:50 ` [patch 52/53] PNP: fill in generic pnp_dev fields earlier Bjorn Helgaas
@ 2008-04-18 20:50 ` Bjorn Helgaas
  52 siblings, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-18 20:50 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Rene Herman, Jaroslav Kysela,
	Andrew Morton

[-- Attachment #1: pnp-unsort-proc-resources --]
[-- Type: text/plain, Size: 3914 bytes --]

Rather than stepping through all IO resources, then stepping through
all MMIO resources, etc. (and traversing the list every time), we
can just iterate over the resource list once directly.

This can change the order in /sys, e.g.,

    # cat /sys/devices/pnp0/00:07/resources     # OLD
    state = active
    io 0x3f8-0x3ff
    irq 4

    # cat /sys/devices/pnp0/00:07/resources     # NEW
    state = active
    irq 4
    io 0x3f8-0x3ff

The old code artificially sorted resources by type; the new code
just lists them in the order we found them.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>

Index: work8/drivers/pnp/interface.c
===================================================================
--- work8.orig/drivers/pnp/interface.c	2008-04-18 11:22:35.000000000 -0600
+++ work8/drivers/pnp/interface.c	2008-04-18 11:52:53.000000000 -0600
@@ -243,16 +243,30 @@
 
 static DEVICE_ATTR(options, S_IRUGO, pnp_show_options, NULL);
 
-#define set(flags)      ((flags & IORESOURCE_UNSET) == 0)
+static char *pnp_resource_type_name(struct resource *res)
+{
+	switch (pnp_resource_type(res)) {
+	case IORESOURCE_IO:
+		return "io";
+	case IORESOURCE_MEM:
+		return "mem";
+	case IORESOURCE_IRQ:
+		return "irq";
+	case IORESOURCE_DMA:
+		return "dma";
+	}
+	return NULL;
+}
 
 static ssize_t pnp_show_current_resources(struct device *dmdev,
 					  struct device_attribute *attr,
 					  char *buf)
 {
 	struct pnp_dev *dev = to_pnp_dev(dmdev);
+	struct pnp_resource *pnp_res;
 	struct resource *res;
-	int i, ret;
 	pnp_info_buffer_t *buffer;
+	int ret;
 
 	if (!dev)
 		return -EINVAL;
@@ -264,54 +278,36 @@
 	buffer->buffer = buf;
 	buffer->curr = buffer->buffer;
 
-	pnp_printf(buffer, "state = ");
-	if (dev->active)
-		pnp_printf(buffer, "active\n");
-	else
-		pnp_printf(buffer, "disabled\n");
-
-	for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IO, i)); i++) {
-		if (set(res->flags)) {
-			pnp_printf(buffer, "io");
-			if (res->flags & IORESOURCE_DISABLED)
-				pnp_printf(buffer, " disabled\n");
-			else
-				pnp_printf(buffer, " 0x%llx-0x%llx\n",
-					   (unsigned long long) res->start,
-					   (unsigned long long) res->end);
-		}
-	}
-	for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) {
-		if (set(res->flags)) {
-			pnp_printf(buffer, "mem");
-			if (res->flags & IORESOURCE_DISABLED)
-				pnp_printf(buffer, " disabled\n");
-			else
-				pnp_printf(buffer, " 0x%llx-0x%llx\n",
-					   (unsigned long long) res->start,
-					   (unsigned long long) res->end);
-		}
-	}
-	for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IRQ, i)); i++) {
-		if (set(res->flags)) {
-			pnp_printf(buffer, "irq");
-			if (res->flags & IORESOURCE_DISABLED)
-				pnp_printf(buffer, " disabled\n");
-			else
-				pnp_printf(buffer, " %lld\n",
-					   (unsigned long long) res->start);
+	pnp_printf(buffer, "state = %s\n", dev->active ? "active" : "disabled");
+
+	list_for_each_entry(pnp_res, &dev->resources, list) {
+		res = &pnp_res->res;
+		if (res->flags & IORESOURCE_UNSET)
+			continue;
+
+		pnp_printf(buffer, pnp_resource_type_name(res));
+
+		if (res->flags & IORESOURCE_DISABLED) {
+			pnp_printf(buffer, " disabled\n");
+			continue;
 		}
-	}
-	for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_DMA, i)); i++) {
-		if (set(res->flags)) {
-			pnp_printf(buffer, "dma");
-			if (res->flags & IORESOURCE_DISABLED)
-				pnp_printf(buffer, " disabled\n");
-			else
-				pnp_printf(buffer, " %lld\n",
-					   (unsigned long long) res->start);
+
+		switch (pnp_resource_type(res)) {
+		case IORESOURCE_IO:
+		case IORESOURCE_MEM:
+			pnp_printf(buffer, " 0x%llx-0x%llx\n",
+				   (unsigned long long) res->start,
+				   (unsigned long long) res->end);
+			break;
+		case IORESOURCE_IRQ:
+		case IORESOURCE_DMA:
+			pnp_printf(buffer, " %lld\n",
+				   (unsigned long long) res->start);
+			break;
 		}
+
 	}
+
 	ret = (buffer->curr - buf);
 	kfree(buffer);
 	return ret;

-- 

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [patch 22/53] PNP: factor pnp_init_resource_table() and pnp_clean_resource_table()
  2008-04-18 20:50 ` [patch 22/53] PNP: factor pnp_init_resource_table() and pnp_clean_resource_table() Bjorn Helgaas
@ 2008-04-18 22:29   ` Rene Herman
  2008-04-19  3:57     ` Bjorn Helgaas
  0 siblings, 1 reply; 65+ messages in thread
From: Rene Herman @ 2008-04-18 22:29 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Len Brown, linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Jaroslav Kysela,
	Andrew Morton

On 18-04-08 22:50, Bjorn Helgaas wrote:

> Move the common part of pnp_init_resource_table() and
> pnp_clean_resource_table() into a new pnp_init_resource().
> This reduces a little code duplication and will be
> useful later to initialize an individual resource.

This can't be right, can it? :

> +void pnp_init_resource(struct resource *res)
> +{
> +	unsigned long type;
> +
> +	type = res->flags & (IORESOURCE_IO  | IORESOURCE_MEM |
> +			     IORESOURCE_IRQ | IORESOURCE_DMA);
> +
> +	res->name = NULL;
> +	res->flags = type | IORESOURCE_AUTO | IORESOURCE_UNSET;
> +	if (type == IORESOURCE_IRQ || type == IORESOURCE_DMA) {
> +		res->start = -1;
> +		res->end = -1;
> +	} else {
> +		res->start = 0;
> +		res->end = 0;
> +	}
> +}

This depends on the type already being set in res->flags, yet:

>  /**
>   * pnp_init_resources - Resets a resource table to default values.
>   * @table: pointer to the desired resource table
> @@ -209,34 +227,14 @@
>  	struct pnp_resource_table *table = &dev->res;
>  	int idx;
>  
> -	for (idx = 0; idx < PNP_MAX_IRQ; idx++) {
> -		table->irq_resource[idx].name = NULL;
> -		table->irq_resource[idx].start = -1;
> -		table->irq_resource[idx].end = -1;
> -		table->irq_resource[idx].flags =
> -		    IORESOURCE_IRQ | IORESOURCE_AUTO | IORESOURCE_UNSET;
> -	}
> -	for (idx = 0; idx < PNP_MAX_DMA; idx++) {
> -		table->dma_resource[idx].name = NULL;
> -		table->dma_resource[idx].start = -1;
> -		table->dma_resource[idx].end = -1;
> -		table->dma_resource[idx].flags =
> -		    IORESOURCE_DMA | IORESOURCE_AUTO | IORESOURCE_UNSET;
> -	}
> -	for (idx = 0; idx < PNP_MAX_PORT; idx++) {
> -		table->port_resource[idx].name = NULL;
> -		table->port_resource[idx].start = 0;
> -		table->port_resource[idx].end = 0;
> -		table->port_resource[idx].flags =
> -		    IORESOURCE_IO | IORESOURCE_AUTO | IORESOURCE_UNSET;
> -	}
> -	for (idx = 0; idx < PNP_MAX_MEM; idx++) {
> -		table->mem_resource[idx].name = NULL;
> -		table->mem_resource[idx].start = 0;
> -		table->mem_resource[idx].end = 0;
> -		table->mem_resource[idx].flags =
> -		    IORESOURCE_MEM | IORESOURCE_AUTO | IORESOURCE_UNSET;
> -	}
> +	for (idx = 0; idx < PNP_MAX_IRQ; idx++)
> +		pnp_init_resource(&table->irq_resource[idx]);
> +	for (idx = 0; idx < PNP_MAX_DMA; idx++)
> +		pnp_init_resource(&table->dma_resource[idx]);
> +	for (idx = 0; idx < PNP_MAX_PORT; idx++)
> +		pnp_init_resource(&table->port_resource[idx]);
> +	for (idx = 0; idx < PNP_MAX_MEM; idx++)
> +		pnp_init_resource(&table->mem_resource[idx]);
>  }

... it's not being set.

Rene.

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [patch 22/53] PNP: factor pnp_init_resource_table() and pnp_clean_resource_table()
  2008-04-18 22:29   ` Rene Herman
@ 2008-04-19  3:57     ` Bjorn Helgaas
  2008-04-19  4:43       ` Rene Herman
  0 siblings, 1 reply; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-19  3:57 UTC (permalink / raw)
  To: Rene Herman
  Cc: Len Brown, linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Jaroslav Kysela,
	Andrew Morton

On Friday 18 April 2008 4:29:15 pm Rene Herman wrote:
> On 18-04-08 22:50, Bjorn Helgaas wrote:
> > Move the common part of pnp_init_resource_table() and
> > pnp_clean_resource_table() into a new pnp_init_resource().
> > This reduces a little code duplication and will be
> > useful later to initialize an individual resource.
>
> This can't be right, can it? :
> > +void pnp_init_resource(struct resource *res)
> > +{
> > +	unsigned long type;
> > +
> > +	type = res->flags & (IORESOURCE_IO  | IORESOURCE_MEM |
> > +			     IORESOURCE_IRQ | IORESOURCE_DMA);
> > +
> > +	res->name = NULL;
> > +	res->flags = type | IORESOURCE_AUTO | IORESOURCE_UNSET;
> > +	if (type == IORESOURCE_IRQ || type == IORESOURCE_DMA) {
> > +		res->start = -1;
> > +		res->end = -1;
> > +	} else {
> > +		res->start = 0;
> > +		res->end = 0;
> > +	}
> > +}
>
> This depends on the type already being set in res->flags, yet:

Yep, you're right.  I fixed it, but it requires changes to a couple
other patches down the line, so I'll wait to repost the series until
next week in case you find more problems.

I think this is only a problem for bisection.  By the time you
apply the whole series, we start with an empty resource list, and
every time we add one, we set the type in pnp_new_resource().

That makes me wonder whether pnp_init_resources() should just
free the whole list, so we just start again with an empty list.

Bjorn

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [patch 22/53] PNP: factor pnp_init_resource_table() and pnp_clean_resource_table()
  2008-04-19  3:57     ` Bjorn Helgaas
@ 2008-04-19  4:43       ` Rene Herman
  2008-04-19  4:46         ` Rene Herman
  2008-04-21 18:41         ` Rene Herman
  0 siblings, 2 replies; 65+ messages in thread
From: Rene Herman @ 2008-04-19  4:43 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Len Brown, linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Jaroslav Kysela,
	Andrew Morton

On 19-04-08 05:57, Bjorn Helgaas wrote:

> Yep, you're right.  I fixed it, but it requires changes to a couple
> other patches down the line, so I'll wait to repost the series until
> next week in case you find more problems.
> 
> I think this is only a problem for bisection.  By the time you
> apply the whole series, we start with an empty resource list, and
> every time we add one, we set the type in pnp_new_resource().
> 
> That makes me wonder whether pnp_init_resources() should just
> free the whole list, so we just start again with an empty list.

Probably. Just a quick heads up; if you don't beat me to it I'll look at it 
in more detail over the weekend but with the current series ISAPnP is quite 
decidedly broken. Forget the OOPS for now which seems just a symptom of the 
same thing as the "too many" warnings". Result of "modprobe snd-cs4236".

I believe it's pnp_assign_resources() which has all the pnp_assign_foo() 
helpers fail due to there not being any yet. I guess pnp_assign_mem() and 
friends should allocate upon not finding one available and not fail?

Don't get why isapnp_get_resources() didn't allocate though. As said, unless 
you beat me to it I'll look into it more tomorrow or sunday.

===
pnp: the driver 'cs4236_isapnp' has been registered
cs4236_isapnp 01:01.00: driver attached
cs4236_isapnp 01:01.02: driver attached
cs4236_isapnp 01:01.03: driver attached
cs4236_isapnp 01:01.00: too many I/O port resources
cs4236_isapnp 01:01.00: too many I/O port resources
cs4236_isapnp 01:01.00: too many I/O port resources
cs4236_isapnp 01:01.00: too many IRQ resources
cs4236_isapnp 01:01.00: too many DMA resources
cs4236_isapnp 01:01.00: too many DMA resources
cs4236_isapnp 01:01.00: activated
BUG: unable to handle kernel NULL pointer dereference at 00000000
IP: [<f0c604da>] :snd_cs4236:snd_cs423x_pnpc_detect+0x104/0x390
*pde = 00000000
Oops: 0000 [#1] PREEMPT
Modules linked in: snd_cs4236(+) snd_opl3_lib snd_hwdep snd_cs4236_lib 
snd_mpu401_uart snd_rawmidi snd_seq_device snd_cs4231_lib snd_pcm snd_timer 
snd soundcore snd_page_alloc nfsd lockd nfs_acl sunrpc exportfs

Pid: 1198, comm: modprobe Not tainted (2.6.25 #2)
EIP: 0060:[<f0c604da>] EFLAGS: 00010202 CPU: 0
EIP is at snd_cs423x_pnpc_detect+0x104/0x390 [snd_cs4236]
EAX: 00000000 EBX: ef868c00 ECX: ef868d6c EDX: 00000000
ESI: 00000000 EDI: f0c63004 EBP: ef84d600 ESP: eed4ce88
  DS: 007b ES: 007b FS: 0000 GS: 0033 SS: 0068
Process modprobe (pid: 1198, ti=eed4c000 task=eecf0aa0 task.ti=eed4c000)
Stack: ef312d40 ef84d7b8 ef843200 ef312d40 f0c63004 00000003 c10d981b f0c62720
        ef868a00 f0c62720 ef84391c f0cab090 f0c633c0 c10d9df7 00000001 0000002b
        f0c4802f f0c633c0 c102eb21 00018f20 c1050987 000226c4 00000000 00000690
Call Trace:
  [<c10d981b>] card_probe+0xba/0x107
  [<c10d9df7>] pnp_register_card_driver+0xa2/0xb2
  [<f0c4802f>] alsa_card_cs423x_init+0x2f/0x4f [snd_cs4236]
  [<c102eb21>] sys_init_module+0x149a/0x1604
  [<c1050987>] do_sync_read+0xbe/0xfd
  [<c1017be8>] __request_region+0x0/0x85
  [<c10513bd>] sys_read+0x3c/0x63
  [<c1003a62>] syscall_call+0x7/0xb
  =======================
Code: 89 d8 e8 93 ad 47 d0 85 c0 79 0a 68 5a 0a c6 f0 e9 30 01 00 00 31 c9 
ba 00 01 00 00 89 d8 e8 fc 9d 47 d0 83 3c b5 40 26 c6 f0 00 <8b> 00 89 04 b5 
a0 26 c6 f0 7e 1a b9 01 00 00 00 ba 00 01 00 00
EIP: [<f0c604da>] snd_cs423x_pnpc_detect+0x104/0x390 [snd_cs4236] SS:ESP 
0068:eed4ce88
---[ end trace 6704e77dc1a89be6 ]---
===

Rene


^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [patch 22/53] PNP: factor pnp_init_resource_table() and pnp_clean_resource_table()
  2008-04-19  4:43       ` Rene Herman
@ 2008-04-19  4:46         ` Rene Herman
  2008-04-21 18:41         ` Rene Herman
  1 sibling, 0 replies; 65+ messages in thread
From: Rene Herman @ 2008-04-19  4:46 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Len Brown, linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Jaroslav Kysela,
	Andrew Morton

On 19-04-08 06:43, Rene Herman wrote:

> pnp: the driver 'cs4236_isapnp' has been registered
> cs4236_isapnp 01:01.00: driver attached
> cs4236_isapnp 01:01.02: driver attached
> cs4236_isapnp 01:01.03: driver attached
> cs4236_isapnp 01:01.00: too many I/O port resources
> cs4236_isapnp 01:01.00: too many I/O port resources
> cs4236_isapnp 01:01.00: too many I/O port resources
> cs4236_isapnp 01:01.00: too many IRQ resources
> cs4236_isapnp 01:01.00: too many DMA resources
> cs4236_isapnp 01:01.00: too many DMA resources
> cs4236_isapnp 01:01.00: activated

Oh, yes, 01:01.00 has three port resources, 1 IRQ resource and 2 DMA resources.

Rene.

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [patch 22/53] PNP: factor pnp_init_resource_table() and pnp_clean_resource_table()
  2008-04-19  4:43       ` Rene Herman
  2008-04-19  4:46         ` Rene Herman
@ 2008-04-21 18:41         ` Rene Herman
  2008-04-21 23:10           ` Bjorn Helgaas
  1 sibling, 1 reply; 65+ messages in thread
From: Rene Herman @ 2008-04-21 18:41 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Len Brown, linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Jaroslav Kysela,
	Andrew Morton

On 19-04-08 06:43, Rene Herman wrote:

> Probably. Just a quick heads up; if you don't beat me to it I'll look at
> it in more detail over the weekend but with the current series ISAPnP is
> quite decidedly broken. Forget the OOPS for now which seems just a 
> symptom of the same thing as the "too many" warnings". Result of 
> "modprobe snd-cs4236".
> 
> I believe it's pnp_assign_resources() which has all the pnp_assign_foo()
>  helpers fail due to there not being any yet. I guess pnp_assign_mem() 
> and friends should allocate upon not finding one available and not fail?
> 
> Don't get why isapnp_get_resources() didn't allocate though. As said, 
> unless you beat me to it I'll look into it more tomorrow or sunday.

isapnp_get_resources didn't allocate simply since it hasn't been called yet; 
there's nothing to get from an inactive device. It is pnp_assign_resources 
which constructs the table which isapnp_set_resources then puts to the hardware.

Currently with the list, pnp_assign_resources doesn't construct anything. It 
finds an empty resource list and then fails all pnp_assign_foo() helpers. I 
can get things functional by making pnp_assign_foo do a pnp_add_foo_resource 
upon not finding one yet but that's a hack -- things are just not very right 
at the moment.

Getting things working also needs setting pnp_res->index (to nport, nmem, 
nirq, ndma in pnp_assign_resources) so that the isapnp_set_resources which 
follows sets to the correct hardware index, but at that point position in 
the list and the index are mixing together in unhealthy ways -- in the 
pnp_assign_foo helpers, pnp_get_resource(.., idx) just get the "idx-th" 
resource of the correct type in the list but it seems it really should be 
getting the resource of the correct type with its ->index set to "idx".

Just making it do that then again disagrees with pnpbios/acpi which do not 
set the index field, nor do I know if you'd want them to or want to keep the 
index totally isapnp specific.

Anyways, currently things really don't work though, due to

1) pnp_assign_resources needing to construct the list and
2) it needing to match resources by their index.

(do note that pnp_assign_foo are the only callers of pnp_check_foo and they 
could be either merged together or at least not communicate via "idx" but 
simply by passing the res/pnp_res).

Also note -- manually set resources are skipped in pnp_assign_resources, yet 
they also definitely need their index initialized for use by 
isapnp_set_resources.

No patches due to the huge series where I don't know where you want to take 
a different turn to end up right. Also many, many opportunities for more 
cleanup of drivers/pnp/manager.c in its post-series state but I suppose you 
want the series bisectably functional first. I'll wait for a next version 
for now I guess?

Rene.


^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [patch 22/53] PNP: factor pnp_init_resource_table() and pnp_clean_resource_table()
  2008-04-21 18:41         ` Rene Herman
@ 2008-04-21 23:10           ` Bjorn Helgaas
  2008-04-22 21:01             ` Rene Herman
  0 siblings, 1 reply; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-21 23:10 UTC (permalink / raw)
  To: Rene Herman
  Cc: Len Brown, linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Jaroslav Kysela,
	Andrew Morton

On Monday 21 April 2008 12:41:31 pm Rene Herman wrote:
> isapnp_get_resources didn't allocate simply since it hasn't been called yet; 
> there's nothing to get from an inactive device. It is pnp_assign_resources 
> which constructs the table which isapnp_set_resources then puts to the hardware.

Yes, right.  I reproduced this on an ACPI system where the BIOS leaves
a couple devices disabled.

> Getting things working also needs setting pnp_res->index (to nport, nmem, 
> nirq, ndma in pnp_assign_resources) so that the isapnp_set_resources which 
> follows sets to the correct hardware index, but at that point position in 
> the list and the index are mixing together in unhealthy ways -- in the 
> pnp_assign_foo helpers, pnp_get_resource(.., idx) just get the "idx-th" 
> resource of the correct type in the list but it seems it really should be 
> getting the resource of the correct type with its ->index set to "idx".

I don't mind setting pnp_res->index in the generic pnp_assign_* code.
We have to do that already in pnp_set_current_resources() (the /sys
interface), and I don't see a good way around it.

In pnp_assign_resources(), we currently assume that all independent
options appear before any dependent ones because we compute nport,
nmem, etc by iterating through the independent options first.  Then
we use those nport, nmem, etc values as the "index" (CSR index for
ISAPNP, nth resource type in the template for PNPBIOS and PNPACPI).
I don't know whether this assumption is in the spec, but at least
we've assumed it for a long time.

I'm trying to figure out the cases where pnp_assign_resources()
has to pay attention to pre-existing configuration.  It looks like
the common case is that we'll start with an empty resource list, and
we can just find non-conflicting values and use pnp_add_foo_resource().

But I'm concerned about all the IORESOURCE_AUTO stuff.  Seems like
we should only get to pnp_assign_foo() with !IORESOURCE_AUTO if
(a) we've used /sys to set some but not all resources, or (b) the
BIOS described fewer things in _CRS than in _PRS (which seems like
a BIOS bug).  But I'm not comfortable with this yet.

> Anyways, currently things really don't work though, due to
> 
> 1) pnp_assign_resources needing to construct the list and
> 2) it needing to match resources by their index.
> 
> (do note that pnp_assign_foo are the only callers of pnp_check_foo and they 
> could be either merged together or at least not communicate via "idx" but 
> simply by passing the res/pnp_res).

Yes, I'd like to do that.  But I think I'd better wait or I'll never
get anything finished :-)

> Also note -- manually set resources are skipped in pnp_assign_resources, yet 
> they also definitely need their index initialized for use by 
> isapnp_set_resources.

Yes.  "Manually set resources" includes ones from /sys and also the
resources we discover from active devices.  We should already be setting
those in the /sys and ISAPNP "read resources" paths.

Bjorn

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [patch 22/53] PNP: factor pnp_init_resource_table() and pnp_clean_resource_table()
  2008-04-21 23:10           ` Bjorn Helgaas
@ 2008-04-22 21:01             ` Rene Herman
  2008-04-23 23:08               ` Bjorn Helgaas
  2008-04-24 22:45               ` Bjorn Helgaas
  0 siblings, 2 replies; 65+ messages in thread
From: Rene Herman @ 2008-04-22 21:01 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Len Brown, linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Jaroslav Kysela,
	Andrew Morton

On 22-04-08 01:10, Bjorn Helgaas wrote:

> Yes, right.  I reproduced this on an ACPI system where the BIOS leaves
> a couple devices disabled.

Ah, good, not just  isapnp then. I was starting to feel lonely here, sitting 
atop my pile of ISA crap...

>> Getting things working also needs setting pnp_res->index (to nport, nmem, 
>> nirq, ndma in pnp_assign_resources) so that the isapnp_set_resources which 
>> follows sets to the correct hardware index, but at that point position in 
>> the list and the index are mixing together in unhealthy ways -- in the 
>> pnp_assign_foo helpers, pnp_get_resource(.., idx) just get the "idx-th" 
>> resource of the correct type in the list but it seems it really should be 
>> getting the resource of the correct type with its ->index set to "idx".
> 
> I don't mind setting pnp_res->index in the generic pnp_assign_* code.
> We have to do that already in pnp_set_current_resources() (the /sys
> interface), and I don't see a good way around it.
> 
> In pnp_assign_resources(), we currently assume that all independent
> options appear before any dependent ones because we compute nport,
> nmem, etc by iterating through the independent options first.  Then
> we use those nport, nmem, etc values as the "index" (CSR index for
> ISAPNP, nth resource type in the template for PNPBIOS and PNPACPI).
> I don't know whether this assumption is in the spec, but at least
> we've assumed it for a long time.

Did this just address my position/index worry above?

It seems you designed the list to be basically in any order, judging by 
things such as pnp_new_resource which'll happily reuse resources of the 
correct type at any position in the list. Yet, pnp_assign_foo() and friends 
retrieve resources (through pnp_get_resource) by position in the list and 
not by the index. I'm not overly sure of failure scenarios but isn't this 
mixing up position and index in a bad way?

> I'm trying to figure out the cases where pnp_assign_resources()
> has to pay attention to pre-existing configuration.  It looks like
> the common case is that we'll start with an empty resource list, and
> we can just find non-conflicting values and use pnp_add_foo_resource().

Yes...

> But I'm concerned about all the IORESOURCE_AUTO stuff.  Seems like
> we should only get to pnp_assign_foo() with !IORESOURCE_AUTO if
> (a) we've used /sys to set some but not all resources, or (b) the
> BIOS described fewer things in _CRS than in _PRS (which seems like
> a BIOS bug).  But I'm not comfortable with this yet.

Sounds right to me. Note that the /sys stuff is also not a corner case 
situation either, as it's the way to force at least ISAPnP hardware to 
manual settings.

>> (do note that pnp_assign_foo are the only callers of pnp_check_foo and they 
>> could be either merged together or at least not communicate via "idx" but 
>> simply by passing the res/pnp_res).
> 
> Yes, I'd like to do that.  But I think I'd better wait or I'll never
> get anything finished :-)

Well, the idea here was that getting rid of one "idx" here so that things 
communicate directly removes at least one possible ordering artifact...

>> Also note -- manually set resources are skipped in pnp_assign_resources, yet 
>> they also definitely need their index initialized for use by 
>> isapnp_set_resources.
> 
> Yes.  "Manually set resources" includes ones from /sys and also the
> resources we discover from active devices.  We should already be setting
> those in the /sys and ISAPNP "read resources" paths.

Hmm, yes, that sounds true...

Rene.

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [patch 22/53] PNP: factor pnp_init_resource_table() and pnp_clean_resource_table()
  2008-04-22 21:01             ` Rene Herman
@ 2008-04-23 23:08               ` Bjorn Helgaas
  2008-04-24  1:26                 ` Rene Herman
  2008-04-24 22:45               ` Bjorn Helgaas
  1 sibling, 1 reply; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-23 23:08 UTC (permalink / raw)
  To: Rene Herman
  Cc: Len Brown, linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Jaroslav Kysela,
	Andrew Morton

On Tuesday 22 April 2008 03:01:58 pm Rene Herman wrote:
> It seems you designed the list to be basically in any order, judging by 
> things such as pnp_new_resource which'll happily reuse resources of the 
> correct type at any position in the list. Yet, pnp_assign_foo() and friends 
> retrieve resources (through pnp_get_resource) by position in the list and 
> not by the index. I'm not overly sure of failure scenarios but isn't this 
> mixing up position and index in a bad way?

Yes, I think you're right.

My idea is that the list should end up in the same order as the
resource list from the BIOS, e.g., the _CRS and _PRS lists for
ACPI.  In the case of ISAPNP, it'll be in the order that we read
things from the hardware registers.

I think I should probably make pnp_new_resource() always allocate
a new resource and get rid of the idea of reusing something already
in the list.

> >> (do note that pnp_assign_foo are the only callers of pnp_check_foo and they 
> >> could be either merged together or at least not communicate via "idx" but 
> >> simply by passing the res/pnp_res).
> > 
> > Yes, I'd like to do that.  But I think I'd better wait or I'll never
> > get anything finished :-)
> 
> Well, the idea here was that getting rid of one "idx" here so that things 
> communicate directly removes at least one possible ordering artifact...

Yup.  I ended up doing this after all.

I updated the patches and my ACPI box with the inactive devices now
boots (it failed with the v3 patches).  I'll work on the
pnp_new_resource() thing tomorrow, but I'll send you the current
patches now in case you have a chance to try them on your ISA box.

Bjorn

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [patch 22/53] PNP: factor pnp_init_resource_table() and pnp_clean_resource_table()
  2008-04-23 23:08               ` Bjorn Helgaas
@ 2008-04-24  1:26                 ` Rene Herman
  2008-04-24  1:39                   ` Rene Herman
  0 siblings, 1 reply; 65+ messages in thread
From: Rene Herman @ 2008-04-24  1:26 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Len Brown, linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Jaroslav Kysela,
	Andrew Morton

On 24-04-08 01:08, Bjorn Helgaas wrote:

> My idea is that the list should end up in the same order as the
> resource list from the BIOS, e.g., the _CRS and _PRS lists for
> ACPI.  In the case of ISAPNP, it'll be in the order that we read
> things from the hardware registers.
> 
> I think I should probably make pnp_new_resource() always allocate
> a new resource and get rid of the idea of reusing something already
> in the list.

I'd agree.

> I updated the patches and my ACPI box with the inactive devices now boots
> (it failed with the v3 patches).  I'll work on the pnp_new_resource()
> thing tomorrow, but I'll send you the current patches now in case you
> have a chance to try them on your ISA box.

Could do a quick test and its cs4236 soundcard works fine with them. There 
are a few "current resources: after pnp_assign_resources (failed)" in there 
but they might be expected, I didn't yet look. There's a dmesg from booting 
it and "modprobe snd-cs4236" at:

http://members.home.nl/rene.herman/dmesg-2.6.25-pnpv3.9

Matching "options" files:

root@6bap:~# for OPTIONS in /sys/devices/pnp1/01\:01/01\:01.0?/options; do 
echo; echo $OPTIONS; echo; cat $OPTIONS; done

/sys/devices/pnp1/01:01/01:01.00/options

Dependent: 01 - Priority preferred
    port 0x534-0x534, align 0x3, size 0x4, 16-bit address decoding
    port 0x388-0x388, align 0x7, size 0x4, 16-bit address decoding
    port 0x220-0x220, align 0x1f, size 0x10, 16-bit address decoding
    irq 5 High-Edge
    dma 1 8-bit byte-count compatible
    dma 0,1 8-bit byte-count compatible
Dependent: 02 - Priority acceptable
    port 0x534-0xffc, align 0x3, size 0x4, 16-bit address decoding
    port 0x388-0x388, align 0x7, size 0x4, 16-bit address decoding
    port 0x220-0x260, align 0x1f, size 0x10, 16-bit address decoding
    irq 5,7,2/9,11,12,15 High-Edge
    dma 1,3 8-bit byte-count compatible
    dma 0,1,3 8-bit byte-count compatible
Dependent: 03 - Priority functional
    port 0x534-0xffc, align 0x3, size 0x4, 16-bit address decoding
    port 0x388-0x3f8, align 0x7, size 0x4, 16-bit address decoding
    port 0x220-0x300, align 0x1f, size 0x10, 16-bit address decoding
    irq 5,7,2/9,11,12,15 High-Edge
    dma 0,1,3 8-bit byte-count compatible

/sys/devices/pnp1/01:01/01:01.01/options

Dependent: 01 - Priority preferred
    port 0x200-0x200, align 0x7, size 0x8, 16-bit address decoding
Dependent: 02 - Priority acceptable
    port 0x208-0x208, align 0x7, size 0x8, 16-bit address decoding

/sys/devices/pnp1/01:01/01:01.02/options

port 0x120-0xff8, align 0x7, size 0x8, 16-bit address decoding

/sys/devices/pnp1/01:01/01:01.03/options

Dependent: 01 - Priority preferred
    port 0x330-0x330, align 0x7, size 0x2, 16-bit address decoding
    irq 2/9 High-Edge
Dependent: 02 - Priority acceptable
    port 0x330-0x360, align 0x7, size 0x2, 16-bit address decoding
    irq 2/9,11,12,15 High-Edge
Dependent: 03 - Priority functional
    port 0x330-0x3e0, align 0x7, size 0x2, 16-bit address decoding

/sys/devices/pnp1/01:01/01:01.04/options

Dependent: 01 - Priority acceptable
    port 0x1e8-0x1e8, align 0x0, size 0x8, 16-bit address decoding
    port 0x3ee-0x3ee, align 0x0, size 0x1, 16-bit address decoding
    irq 11,12 High-Edge
Dependent: 02 - Priority acceptable
    port 0x168-0x168, align 0x0, size 0x8, 16-bit address decoding
    port 0x36e-0x36e, align 0x0, size 0x1, 16-bit address decoding
    irq 2/9,11,12 High-Edge

Rene.

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [patch 22/53] PNP: factor pnp_init_resource_table() and pnp_clean_resource_table()
  2008-04-24  1:26                 ` Rene Herman
@ 2008-04-24  1:39                   ` Rene Herman
  0 siblings, 0 replies; 65+ messages in thread
From: Rene Herman @ 2008-04-24  1:39 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Len Brown, linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Jaroslav Kysela,
	Andrew Morton

On 24-04-08 03:26, Rene Herman wrote:

> Could do a quick test and its cs4236 soundcard works fine with them. 

Oh, this was on v2.6.25 vanilla + 0093cb1199ec551f179562ca9fbd6f64fb750645 
(only post 2.6.25 change to drivers/pnp).

Rene

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [patch 22/53] PNP: factor pnp_init_resource_table() and pnp_clean_resource_table()
  2008-04-22 21:01             ` Rene Herman
  2008-04-23 23:08               ` Bjorn Helgaas
@ 2008-04-24 22:45               ` Bjorn Helgaas
  1 sibling, 0 replies; 65+ messages in thread
From: Bjorn Helgaas @ 2008-04-24 22:45 UTC (permalink / raw)
  To: Rene Herman
  Cc: Len Brown, linux-acpi, linux-kernel, Adam Belay, Li Shaohua,
	Matthieu Castet, Thomas Renninger, Jaroslav Kysela,
	Andrew Morton

On Tuesday 22 April 2008 03:01:58 pm Rene Herman wrote:
> On 22-04-08 01:10, Bjorn Helgaas wrote:
> >> Getting things working also needs setting pnp_res->index (to nport, nmem, 
> >> nirq, ndma in pnp_assign_resources) so that the isapnp_set_resources which 
> >> follows sets to the correct hardware index, but at that point position in 
> >> the list and the index are mixing together in unhealthy ways -- in the 
> >> pnp_assign_foo helpers, pnp_get_resource(.., idx) just get the "idx-th" 
> >> resource of the correct type in the list but it seems it really should be 
> >> getting the resource of the correct type with its ->index set to "idx".
> > 
> > I don't mind setting pnp_res->index in the generic pnp_assign_* code.
> > We have to do that already in pnp_set_current_resources() (the /sys
> > interface), and I don't see a good way around it.
> > 
> > In pnp_assign_resources(), we currently assume that all independent
> > options appear before any dependent ones because we compute nport,
> > nmem, etc by iterating through the independent options first.  Then
> > we use those nport, nmem, etc values as the "index" (CSR index for
> > ISAPNP, nth resource type in the template for PNPBIOS and PNPACPI).
> > I don't know whether this assumption is in the spec, but at least
> > we've assumed it for a long time.
> 
> Did this just address my position/index worry above?

Here's something interesting.  I was mistaken about the ordering
of independent vs. dependent options coming from BIOS -- I have
several examples where the dependent ones come first, including
this one:

    pnp 00:0a: parse resource options
    pnp 00:0a: new independent option
    pnp 00:0a: new dependent option (priority 0x1)
    pnp 00:0a:   io  min 0x3f8 max 0x3f8 align 1 size 8 flags 0x1
    pnp 00:0a: new dependent option (priority 0x1)
    pnp 00:0a:   io  min 0x2e8 max 0x2e8 align 1 size 8 flags 0x1
    pnp 00:0a: new dependent option (priority 0x1)
    pnp 00:0a:   io  min 0x2f8 max 0x2f8 align 1 size 8 flags 0x1
    pnp 00:0a: new dependent option (priority 0x1)
    pnp 00:0a:   io  min 0x3e8 max 0x3e8 align 1 size 8 flags 0x1
    pnp 00:0a: end dependent options
    pnp 00:0a:   irq bitmask 00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000cf8 flags 0x1
    pnp 00:0a:   io  min 0x100 max 0x130 align 16 size 8 flags 0x1
    pnp 00:0a:   dma bitmask 0xe flags 0x2
    pnp 00:0a: Plug and Play ACPI device, IDs SMCf010 (disabled)

The interesting thing here is that this IRDA device comes up disabled,
and we use pnp_assign_resources() before enabling it.  But we
assign independent options first, so we end up reversing the order
of these IO regions:

    state = active
    io 0x100-0x107
    io 0x2e8-0x2ef
    irq 5
    dma 1

The driver for this device (smsc-ircc2.c) currently can't claim it
via PNP, but by long painful trial and error, I figured out last
summer that I could get the PNP claim code to work if I manually
swapped the IO regions!

I haven't done anything about this yet, but it sure looks to me like
we need to preserve the order of the independent/dependent options
as we get them from the BIOS.

Bjorn

^ permalink raw reply	[flat|nested] 65+ messages in thread

end of thread, other threads:[~2008-04-24 22:46 UTC | newest]

Thread overview: 65+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-18 20:49 [patch 00/53] PNP cleanup and convert to dynamic resources, v3 Bjorn Helgaas
2008-04-18 20:49 ` [patch 01/53] ISAPNP: move config register addresses out of isapnp.h Bjorn Helgaas
2008-04-18 20:49 ` [patch 02/53] PNPACPI: continue after _CRS and _PRS errors Bjorn Helgaas
2008-04-18 20:49 ` [patch 03/53] PNP: make pnp_add_id() internal to PNP core Bjorn Helgaas
2008-04-18 20:49 ` [patch 04/53] PNP: change pnp_add_id() to allocate its own pnp_id structures Bjorn Helgaas
2008-04-18 20:50 ` [patch 05/53] PNP: add pnp_eisa_id_to_string() Bjorn Helgaas
2008-04-18 20:50 ` [patch 06/53] PNP: add pnp_alloc_dev() Bjorn Helgaas
2008-04-18 20:50 ` [patch 07/53] PNP: make pnp_add_card_id() internal to PNP core Bjorn Helgaas
2008-04-18 20:50 ` [patch 08/53] PNP: change pnp_add_card_id() to allocate its own pnp_id structures Bjorn Helgaas
2008-04-18 20:50 ` [patch 09/53] ISAPNP: pull pnp_add_card_id() out of isapnp_parse_card_id() Bjorn Helgaas
2008-04-18 20:50 ` [patch 10/53] PNP: add pnp_alloc_card() Bjorn Helgaas
2008-04-18 20:50 ` [patch 11/53] PNPACPI: pnpacpi_encode_ext_irq() wrongly set "irq" instead of "extended_irq" Bjorn Helgaas
2008-04-18 20:50 ` [patch 12/53] PNPACPI: use temporaries to reduce repetition Bjorn Helgaas
2008-04-18 20:50 ` [patch 13/53] PNPACPI: hoist dma_flags() out of pnpacpi_parse_allocated_dmaresource() Bjorn Helgaas
2008-04-18 20:50 ` [patch 14/53] PNPACPI: extend irq_flags() to set IORESOURCE_IRQ_SHAREABLE when appropriate Bjorn Helgaas
2008-04-18 20:50 ` [patch 15/53] PNPACPI: pass pnp_dev instead of acpi_handle Bjorn Helgaas
2008-04-18 20:50 ` [patch 16/53] PNP: remove pnp_resource_table from internal get/set interfaces Bjorn Helgaas
2008-04-18 20:50 ` [patch 17/53] PNP: remove more pnp_resource_table arguments Bjorn Helgaas
2008-04-18 20:50 ` [patch 18/53] PNP: add pnp_init_resources(struct pnp_dev *) interface Bjorn Helgaas
2008-04-18 20:50 ` [patch 19/53] PNP: remove pnp_resource_table from internal pnp_clean_resource_table interface Bjorn Helgaas
2008-04-18 20:50 ` [patch 20/53] PNP: remove unused interfaces using pnp_resource_table Bjorn Helgaas
2008-04-18 20:50 ` [patch 21/53] PNP: use dev_printk when possible Bjorn Helgaas
2008-04-18 20:50 ` [patch 22/53] PNP: factor pnp_init_resource_table() and pnp_clean_resource_table() Bjorn Helgaas
2008-04-18 22:29   ` Rene Herman
2008-04-19  3:57     ` Bjorn Helgaas
2008-04-19  4:43       ` Rene Herman
2008-04-19  4:46         ` Rene Herman
2008-04-21 18:41         ` Rene Herman
2008-04-21 23:10           ` Bjorn Helgaas
2008-04-22 21:01             ` Rene Herman
2008-04-23 23:08               ` Bjorn Helgaas
2008-04-24  1:26                 ` Rene Herman
2008-04-24  1:39                   ` Rene Herman
2008-04-24 22:45               ` Bjorn Helgaas
2008-04-18 20:50 ` [patch 23/53] PNP: add pnp_get_resource() interface Bjorn Helgaas
2008-04-18 20:50 ` [patch 24/53] PNP: remove pnp_mem_flags() as an lvalue Bjorn Helgaas
2008-04-18 20:50 ` [patch 25/53] PNP: convert resource accessors to use pnp_get_resource(), not pnp_resource_table Bjorn Helgaas
2008-04-18 20:50 ` [patch 26/53] PNP: use conventional "i" for loop indices Bjorn Helgaas
2008-04-18 20:50 ` [patch 27/53] PNP: convert resource checks to use pnp_get_resource(), not pnp_resource_table Bjorn Helgaas
2008-04-18 20:50 ` [patch 28/53] PNP: convert resource assign functions " Bjorn Helgaas
2008-04-18 20:50 ` [patch 29/53] PNP: convert sysfs interface " Bjorn Helgaas
2008-04-18 20:50 ` [patch 30/53] PNP: convert resource initializers " Bjorn Helgaas
2008-04-18 20:50 ` [patch 31/53] PNP: convert encoders " Bjorn Helgaas
2008-04-18 20:50 ` [patch 32/53] PNP: remove PNP_MAX_* uses Bjorn Helgaas
2008-04-18 20:50 ` [patch 33/53] rtc: dont reference pnp_resource_table directly Bjorn Helgaas
2008-04-18 20:50 ` [patch 34/53] PNP: make pnp_resource_table private to PNP core Bjorn Helgaas
2008-04-18 20:50 ` [patch 35/53] PNP: remove pnp_resource_table references from resource decoders Bjorn Helgaas
2008-04-18 20:50 ` [patch 36/53] PNP: add struct pnp_resource Bjorn Helgaas
2008-04-18 20:50 ` [patch 37/53] PNP: add pnp_resource index for ISAPNP Bjorn Helgaas
2008-04-18 20:50 ` [patch 38/53] PNP: add pnp_new_resource() to find a new unset pnp_resource Bjorn Helgaas
2008-04-18 20:50 ` [patch 39/53] PNP: make generic pnp_add_irq_resource() Bjorn Helgaas
2008-04-18 20:50 ` [patch 40/53] PNP: make generic pnp_add_dma_resource() Bjorn Helgaas
2008-04-18 20:50 ` [patch 41/53] PNP: make generic pnp_add_io_resource() Bjorn Helgaas
2008-04-18 20:50 ` [patch 42/53] PNP: make generic pnp_add_mem_resource() Bjorn Helgaas
2008-04-18 20:50 ` [patch 43/53] ISAPNP: fold isapnp_read_resources() back into isapnp_get_resources() Bjorn Helgaas
2008-04-18 20:50 ` [patch 44/53] PNP: add pnp_resource_type() internal interface Bjorn Helgaas
2008-04-18 20:50 ` [patch 45/53] PNP: replace pnp_resource_table with dynamically allocated resources Bjorn Helgaas
2008-04-18 20:50 ` [patch 46/53] PNP: remove ratelimit on add resource failures Bjorn Helgaas
2008-04-18 20:50 ` [patch 47/53] PNPACPI: move _CRS/_PRS warnings closer to the action Bjorn Helgaas
2008-04-18 20:50 ` [patch 48/53] PNPACPI: remove some pnp_dbg calls Bjorn Helgaas
2008-04-18 20:50 ` [patch 49/53] PNP: make interfaces private to the PNP core Bjorn Helgaas
2008-04-18 20:50 ` [patch 50/53] ISAPNP: remove unused pnp_dev->regs field Bjorn Helgaas
2008-04-18 20:50 ` [patch 51/53] PNPBIOS: remove include/linux/pnpbios.h Bjorn Helgaas
2008-04-18 20:50 ` [patch 52/53] PNP: fill in generic pnp_dev fields earlier Bjorn Helgaas
2008-04-18 20:50 ` [patch 53/53] PNP: dont sort by type in /sys/.../resources Bjorn Helgaas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).