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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Deng-Cheng Zhu <dengcheng.zhu@xxxxxxxxxx>

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@xxxxxxxxxx>
Reviewed-by: James Hogan <james.hogan@xxxxxxxxxx>
---
 drivers/pci/quirks.c |   30 ++++++++++++++++--------------
 1 files changed, 16 insertions(+), 14 deletions(-)

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. 
-- 
1.7.1


--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux