Re: [PATCH v2 0/4] hpet: convert from ACPI to PNP driver

Previous thread: [PATCH] scripts/bootgraph.pl: ignore times until the clock is running by Aaro Koskinen on Thursday, March 18, 2010 - 10:49 am. (3 messages)

Next thread: Loan Offre by lo on Thursday, March 18, 2010 - 11:10 am. (1 message)
From: Bjorn Helgaas
Date: Thursday, March 18, 2010 - 10:59 am

The HPET driver parses ACPI _CRS data manually, but PNPACPI already does
that, and it does a more complete job, so we can simplify the HPET driver
quite a bit by taking advantage of that.

Clemens, if you like these, will you take care of merging them, or do
I need to shepherd them through some other path?

Changes from v1 to v2:
    - Wrap PNP code in "#ifdef CONFIG_PNP" (Venki)
    - Fix leak when hpet_alloc() fails (Venki)

---

Bjorn Helgaas (4):
      hpet: convert from ACPI to PNP driver
      hpet: pass physical address, not entire hpet_data, to hpet_is_known()
      hpet: clean up io mapping when hpet_alloc() fails
      MAINTAINERS: remove obsolete HPET ACPI entry


 MAINTAINERS         |    5 --
 drivers/char/hpet.c |  119 ++++++++++++++++-----------------------------------
 2 files changed, 38 insertions(+), 86 deletions(-)
--

From: Bjorn Helgaas
Date: Thursday, March 18, 2010 - 10:59 am

PNPACPI already parses _CRS, and does a more complete job than we did here,
so let's just take advantage of that.

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

 drivers/char/hpet.c |  109 +++++++++++++++------------------------------------
 1 files changed, 33 insertions(+), 76 deletions(-)


diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
index e481c59..5cb05ed 100644
--- a/drivers/char/hpet.c
+++ b/drivers/char/hpet.c
@@ -31,6 +31,7 @@
 #include <linux/seq_file.h>
 #include <linux/bitops.h>
 #include <linux/clocksource.h>
+#include <linux/pnp.h>
 
 #include <asm/current.h>
 #include <asm/uaccess.h>
@@ -40,7 +41,6 @@
 #include <asm/div64.h>
 
 #include <linux/acpi.h>
-#include <acpi/acpi_bus.h>
 #include <linux/hpet.h>
 
 /*
@@ -899,101 +899,56 @@ int hpet_alloc(struct hpet_data *hdp)
 	return 0;
 }
 
-static acpi_status hpet_resources(struct acpi_resource *res, void *data)
+#ifdef CONFIG_PNP
+static int hpet_pnp_add(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
 {
-	struct hpet_data *hdp;
-	acpi_status status;
-	struct acpi_resource_address64 addr;
-
-	hdp = data;
-
-	status = acpi_resource_to_address64(res, &addr);
-
-	if (ACPI_SUCCESS(status)) {
-		hdp->hd_phys_address = addr.minimum;
-		hdp->hd_address = ioremap(addr.minimum, addr.address_length);
-
-		if (hpet_is_known(hdp)) {
-			iounmap(hdp->hd_address);
-			return AE_ALREADY_EXISTS;
-		}
-	} else if (res->type == ACPI_RESOURCE_TYPE_FIXED_MEMORY32) {
-		struct acpi_resource_fixed_memory32 *fixmem32;
-
-		fixmem32 = &res->data.fixed_memory32;
-		if (!fixmem32)
-			return AE_NO_MEMORY;
-
-		hdp->hd_phys_address = fixmem32->address;
-		hdp->hd_address = ioremap(fixmem32->address,
-						HPET_RANGE_SIZE);
-
-		if (hpet_is_known(hdp)) {
-			iounmap(hdp->hd_address);
-			return AE_ALREADY_EXISTS;
-		}
-	} else if (res->type == ACPI_RESOURCE_TYPE_EXTENDED_IRQ) {
-		struct acpi_resource_extended_irq *irqp;
-		int i, irq;
-
-		irqp = ...
From: Venkatesh Pallipadi
Date: Thursday, March 18, 2010 - 12:26 pm

Acked-by: Venkatesh Pallipadi <venki@google.com>

--

From: Bjorn Helgaas
Date: Thursday, March 18, 2010 - 10:59 am

No functional change; hpet_is_known() only needs the physical address,
so supplying that instead of the whole struct hpet_data makes the callers
a little simpler.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-by: Clemens Ladisch <clemens@ladisch.de>
---

 drivers/char/hpet.c |   14 +++++---------
 1 files changed, 5 insertions(+), 9 deletions(-)


diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
index 5cb05ed..d132fef 100644
--- a/drivers/char/hpet.c
+++ b/drivers/char/hpet.c
@@ -662,12 +662,12 @@ static const struct file_operations hpet_fops = {
 	.mmap = hpet_mmap,
 };
 
-static int hpet_is_known(struct hpet_data *hdp)
+static int hpet_is_known(unsigned long phys_address)
 {
 	struct hpets *hpetp;
 
 	for (hpetp = hpets; hpetp; hpetp = hpetp->hp_next)
-		if (hpetp->hp_hpet_phys == hdp->hd_phys_address)
+		if (hpetp->hp_hpet_phys == phys_address)
 			return 1;
 
 	return 0;
@@ -788,7 +788,7 @@ int hpet_alloc(struct hpet_data *hdp)
 	 * If platform dependent code has allocated the hpet that
 	 * ACPI has also reported, then we catch it here.
 	 */
-	if (hpet_is_known(hdp)) {
+	if (hpet_is_known(hdp->hd_phys_address)) {
 		printk(KERN_DEBUG "%s: duplicate HPET ignored\n",
 			__func__);
 		return 0;
@@ -909,12 +909,7 @@ static int hpet_pnp_add(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
 	memset(&data, 0, sizeof(data));
 
 	mem = pnp_get_resource(dev, IORESOURCE_MEM, 0);
-	if (!mem)
-		return -ENODEV;
-
-	data.hd_phys_address = mem->start;
-
-	if (hpet_is_known(&data))
+	if (!mem || hpet_is_known(mem->start))
 		return -ENODEV;
 
 	i = 0;
@@ -926,6 +921,7 @@ static int hpet_pnp_add(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
 	if (!data.hd_nirqs)
 		return -ENODEV;
 
+	data.hd_phys_address = mem->start;
 	data.hd_address = ioremap(mem->start, resource_size(mem));
 
 	return hpet_alloc(&data);

--

From: Venkatesh Pallipadi
Date: Thursday, March 18, 2010 - 12:25 pm

Acked-by: Venkatesh Pallipadi <venki@google.com>

--

From: Bjorn Helgaas
Date: Thursday, March 18, 2010 - 10:59 am

When hpet_alloc() fails, we should iounmap() the timer so we don't leak
the mapping.

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

 drivers/char/hpet.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)


diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
index d132fef..8961985 100644
--- a/drivers/char/hpet.c
+++ b/drivers/char/hpet.c
@@ -904,7 +904,7 @@ static int hpet_pnp_add(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
 {
 	struct hpet_data data;
 	struct resource *mem, *irq;
-	int i;
+	int i, ret;
 
 	memset(&data, 0, sizeof(data));
 
@@ -924,7 +924,11 @@ static int hpet_pnp_add(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
 	data.hd_phys_address = mem->start;
 	data.hd_address = ioremap(mem->start, resource_size(mem));
 
-	return hpet_alloc(&data);
+	ret = hpet_alloc(&data);
+	if (ret)
+		iounmap(data.hd_address);
+
+	return ret;
 }
 
 static void hpet_pnp_remove(struct pnp_dev *dev)

--

From: Venkatesh Pallipadi
Date: Thursday, March 18, 2010 - 12:25 pm

Acked-by: Venkatesh Pallipadi <venki@google.com>

--

From: Bjorn Helgaas
Date: Thursday, March 18, 2010 - 10:59 am

Bob Picco is no longer at HP.

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

 MAINTAINERS |    5 -----
 1 files changed, 0 insertions(+), 5 deletions(-)


diff --git a/MAINTAINERS b/MAINTAINERS
index 47cc449..30ba4e9 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2664,11 +2664,6 @@ HPET:	x86_64
 M:	Vojtech Pavlik <vojtech@suse.cz>
 S:	Maintained
 
-HPET:	ACPI
-M:	Bob Picco <bob.picco@hp.com>
-S:	Maintained
-F:	drivers/char/hpet.c
-
 HPFS FILESYSTEM
 M:	Mikulas Patocka <mikulas@artax.karlin.mff.cuni.cz>
 W:	http://artax.karlin.mff.cuni.cz/~mikulas/vyplody/hpfs/index-e.cgi

--

From: Clemens Ladisch
Date: Friday, March 19, 2010 - 1:28 am

I don't have a tree for this; HPET patches are usually picked up by akpm.


Regards,
Clemens
--

From: Bjorn Helgaas
Date: Friday, March 19, 2010 - 8:58 am

Andrew, did you see these?  Can you put them in -mm or whatever your
normal path for HPET patches is?

Thanks,
  Bjorn



--

Previous thread: [PATCH] scripts/bootgraph.pl: ignore times until the clock is running by Aaro Koskinen on Thursday, March 18, 2010 - 10:49 am. (3 messages)

Next thread: Loan Offre by lo on Thursday, March 18, 2010 - 11:10 am. (1 message)