diff mbox

[v2,3/4] PCI/quirks: Extract the size detection logic of PIIX4 ACPI io and mem

Message ID 1380929453-15428-4-git-send-email-dengcheng.zhu@imgtec.com (mailing list archive)
State New, archived
Delegated to: Bjorn Helgaas
Headers show

Commit Message

Deng-Cheng Zhu Oct. 4, 2013, 11:30 p.m. UTC
From: Deng-Cheng Zhu <dengcheng.zhu@imgtec.com>

Put the same algorithm in piix4_acpi_[io|mem]_quirk into a dedicated
function for size detection.

Signed-off-by: Deng-Cheng Zhu <dengcheng.zhu@imgtec.com>
Reviewed-by: James Hogan <james.hogan@imgtec.com>
---
 drivers/pci/quirks.c |   30 ++++++++++++++++--------------
 1 files changed, 16 insertions(+), 14 deletions(-)
diff mbox

Patch

diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index a2b66c3..06762a8 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -380,6 +380,20 @@  static void quirk_ali7101_acpi(struct pci_dev *dev)
 }
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL,	PCI_DEVICE_ID_AL_M7101,		quirk_ali7101_acpi);
 
+static inline u32 piix4_acpi_quirk_size(u32 max, u32 mask)
+{
+	u32 size = max;
+
+	for (;;) {
+		unsigned bit = size >> 1;
+		if ((bit & mask) == bit)
+			break;
+		size = bit;
+	}
+
+	return size;
+}
+
 static void piix4_acpi_io_quirk(struct pci_dev *dev, const char *name,
 				unsigned int port, unsigned int enable)
 {
@@ -391,13 +405,7 @@  static void piix4_acpi_io_quirk(struct pci_dev *dev, const char *name,
 		return;
 	mask = (devres >> 16) & 15;
 	base = devres & 0xffff;
-	size = 16;
-	for (;;) {
-		unsigned bit = size >> 1;
-		if ((bit & mask) == bit)
-			break;
-		size = bit;
-	}
+	size = piix4_acpi_quirk_size(16, mask);
 	/*
 	 * For now we only print it out. Eventually we'll want to
 	 * reserve it (at least if it's in the 0x1000+ range), but
@@ -418,13 +426,7 @@  static void piix4_acpi_mem_quirk(struct pci_dev *dev, const char *name,
 		return;
 	base = devres & 0xffff8000;
 	mask = (devres & 0x7f) << 15;
-	size = 128 << 15;
-	for (;;) {
-		unsigned bit = size >> 1;
-		if ((bit & mask) == bit)
-			break;
-		size = bit;
-	}
+	size = piix4_acpi_quirk_size(128 << 15, mask);
 	/*
 	 * For now we only print it out. Eventually we'll want to
 	 * reserve it, but let's get enough confirmation reports first.