aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Jeffery <andrew@aj.id.au>2018-06-04 14:30:16 +0930
committerStewart Smith <stewart@linux.ibm.com>2018-06-18 22:13:06 -0500
commitdc24a1fd61e0b3fbceb1027b2c458bde0257fb38 (patch)
tree68b9692887f652c0ee13a96055d835591a30e5e1
parent50dfd067835af53736ec8106b1f0e99339b54a81 (diff)
downloadskiboot-dc24a1fd61e0b3fbceb1027b2c458bde0257fb38.zip
skiboot-dc24a1fd61e0b3fbceb1027b2c458bde0257fb38.tar.gz
skiboot-dc24a1fd61e0b3fbceb1027b2c458bde0257fb38.tar.bz2
core: Add test for PCI quirks
Ensure that quirks are run (or not) for given PCI vendor and device IDs. This tests the quirk infrastructure and the PCI_VENDOR_ID() and PCI_DEVICE_ID() macros, the latter of which was recently found to be broken. Signed-off-by: Andrew Jeffery <andrew@aj.id.au> Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
-rw-r--r--core/pci-quirk.c10
-rw-r--r--core/test/Makefile.check3
-rw-r--r--core/test/run-pci-quirk.c66
3 files changed, 75 insertions, 4 deletions
diff --git a/core/pci-quirk.c b/core/pci-quirk.c
index 04cbf8e..1b60e92 100644
--- a/core/pci-quirk.c
+++ b/core/pci-quirk.c
@@ -70,10 +70,9 @@ static const struct pci_quirk quirk_table[] = {
{ NULL, 0, 0 }
};
-void pci_handle_quirk(struct phb *phb, struct pci_device *pd)
+static void __pci_handle_quirk(struct phb *phb, struct pci_device *pd,
+ const struct pci_quirk *quirks)
{
- const struct pci_quirk *quirks = quirk_table;
-
while (quirks->vendor_id) {
if (quirks->vendor_id == PCI_VENDOR_ID(pd->vdid) &&
(quirks->device_id == PCI_ANY_ID ||
@@ -82,3 +81,8 @@ void pci_handle_quirk(struct phb *phb, struct pci_device *pd)
quirks++;
}
}
+
+void pci_handle_quirk(struct phb *phb, struct pci_device *pd)
+{
+ __pci_handle_quirk(phb, pd, quirk_table);
+}
diff --git a/core/test/Makefile.check b/core/test/Makefile.check
index 3554050..11857ca 100644
--- a/core/test/Makefile.check
+++ b/core/test/Makefile.check
@@ -19,7 +19,8 @@ CORE_TEST := \
core/test/run-time-utils \
core/test/run-timebase \
core/test/run-timer \
- core/test/run-buddy
+ core/test/run-buddy \
+ core/test/run-pci-quirk
HOSTCFLAGS+=-I . -I include
diff --git a/core/test/run-pci-quirk.c b/core/test/run-pci-quirk.c
new file mode 100644
index 0000000..b9db680
--- /dev/null
+++ b/core/test/run-pci-quirk.c
@@ -0,0 +1,66 @@
+#include <assert.h>
+#include <stdint.h>
+#include <compiler.h>
+
+/* Stubs for quirk_astbmc_vga() */
+
+struct dt_property;
+struct dt_node;
+
+static uint32_t ast_ahb_readl(uint32_t reg)
+{
+ return reg;
+}
+
+static struct dt_property *__dt_add_property_cells(
+ struct dt_node *node __unused, const char *name __unused,
+ int count __unused, ...)
+{
+ return (void *)0;
+}
+
+#include "../pci-quirk.c"
+
+struct pci_device test_pd;
+int test_fixup_ran;
+
+static void test_fixup(struct phb *phb __unused, struct pci_device *pd __unused)
+{
+ assert(PCI_VENDOR_ID(pd->vdid) == 0x1a03);
+ assert(PCI_DEVICE_ID(pd->vdid) == 0x2000);
+ test_fixup_ran = 1;
+}
+
+/* Quirks are: {fixup function, vendor ID, (device ID or PCI_ANY_ID)} */
+static const struct pci_quirk test_quirk_table[] = {
+ /* ASPEED 2400 VGA device */
+ { &test_fixup, 0x1a03, 0x2000 },
+ { NULL, 0, 0 }
+};
+
+#define PCI_COMPOSE_VDID(vendor, device) (((device) << 16) | (vendor))
+
+int main(void)
+{
+ /* Unrecognised vendor and device ID */
+ test_pd.vdid = PCI_COMPOSE_VDID(0xabcd, 0xef01);
+ __pci_handle_quirk(NULL, &test_pd, test_quirk_table);
+ assert(test_fixup_ran == 0);
+
+ /* Unrecognised vendor ID, matching device ID */
+ test_pd.vdid = PCI_COMPOSE_VDID(0xabcd, 0x2000);
+ __pci_handle_quirk(NULL, &test_pd, test_quirk_table);
+ assert(test_fixup_ran == 0);
+
+ /* Matching vendor ID, unrecognised device ID */
+ test_pd.vdid = PCI_COMPOSE_VDID(0x1a03, 0xef01);
+ __pci_handle_quirk(NULL, &test_pd, test_quirk_table);
+ assert(test_fixup_ran == 0);
+
+ /* Matching vendor and device ID */
+ test_pd.vdid = PCI_COMPOSE_VDID(0x1a03, 0x2000);
+ __pci_handle_quirk(NULL, &test_pd, test_quirk_table);
+ assert(test_fixup_ran == 1);
+
+ return 0;
+}