[Skiboot] [PATCH] core: Add test for PCI quirks
Andrew Jeffery
andrew at aj.id.au
Mon Jun 4 15:00:16 AEST 2018
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 at aj.id.au>
---
core/pci-quirk.c | 10 ++++--
core/test/Makefile.check | 3 +-
core/test/run-pci-quirk.c | 66 +++++++++++++++++++++++++++++++++++++++
3 files changed, 75 insertions(+), 4 deletions(-)
create mode 100644 core/test/run-pci-quirk.c
diff --git a/core/pci-quirk.c b/core/pci-quirk.c
index 04cbf8e2cfd0..1b60e921db72 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 355405042a7a..11857ca616ce 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 000000000000..b9db68096f77
--- /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;
+}
--
2.17.0
More information about the Skiboot
mailing list