From patchwork Mon Jun 4 05:00:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jeffery X-Patchwork-Id: 924818 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40zjTq1ncPz9s02 for ; Mon, 4 Jun 2018 15:02:07 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=aj.id.au Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=aj.id.au header.i=@aj.id.au header.b="gW0MG/0U"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="GnYLG3Kv"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 40zjTp6rRBzF0pl for ; Mon, 4 Jun 2018 15:02:06 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=aj.id.au Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=aj.id.au header.i=@aj.id.au header.b="gW0MG/0U"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="GnYLG3Kv"; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=aj.id.au (client-ip=66.111.4.25; helo=out1-smtp.messagingengine.com; envelope-from=andrew@aj.id.au; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=aj.id.au Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=aj.id.au header.i=@aj.id.au header.b="gW0MG/0U"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="GnYLG3Kv"; dkim-atps=neutral Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 40zjSk6Z1mzF0pl for ; Mon, 4 Jun 2018 15:01:10 +1000 (AEST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 7562D21C0D; Mon, 4 Jun 2018 01:01:08 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 04 Jun 2018 01:01:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aj.id.au; h=cc :date:from:message-id:subject:to:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=CY6xvNkebSePDmBNsBpKEJxn/KdBK23ovb1zA9nN8 hs=; b=gW0MG/0UoJ79SlM3xORMD/pwWfxMZih7PueCHAVj7oGHph1Dx4m5FC4uq Zc1zVhK/d25qWuL3oP3YEV9ZmYA26mzZ72Vksm8YvqAAw7hxiQEaLCe6++Ihugy8 Hqzj7tAPv8wCHn3BCREkS3BL+rN2QWzZ1RqU0xgd4BsJ+3u47n6NfCMvrmvKK4xn SP+fL2oYkG20Kmy2vNbQ4zjE8J60aVAJBQSbdzVkEj7THrqoiCoc3A7uyC13OIRK E1RaKsj2l0qfBjY5q7j8uttkvDvf0DJ7X5jyYgHcy0sboQMtV+MtxhxOTbiuMYN2 8ewNDBsTgHdRSi8TbFxcZcKpAC11w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:message-id:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=CY6xvNkebSePDmBNs BpKEJxn/KdBK23ovb1zA9nN8hs=; b=GnYLG3KvCJonsV6XdcmQ/k3BEzu15i2gK 5/kEjtWwIw4dTTILYeQrxe5oet28020bF/IqPd8YE4zE65wG6EYp/KNrKbdPQBmk cCq+ew96wOtlvEaP0cvm68i6PtWtGTgx/EGp7yzrgMPYShnNdrq2/k1lH3bnaLaO kmBA6DrOiTpvHRvOsCFyAebmoHTBS0ztjEidm/F6MSBB6MW+buOSTmx9PCzgahag BKz5SRkdj9QfZD1cXb1z7iBGI0F67m3XnyCnJbjKb1r9zp8eFJs5BxSbgdylrzNo TXPWM2KngXnqjyO6ywkodcSDyZtTqD1GH0NB3euwGAIEiqW2Tn8kg== X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Sender: Received: from dave.aj.id.au (unknown [118.211.115.117]) by mail.messagingengine.com (Postfix) with ESMTPA id DBA26E46C1; Mon, 4 Jun 2018 01:01:06 -0400 (EDT) From: Andrew Jeffery To: skiboot@lists.ozlabs.org Date: Mon, 4 Jun 2018 14:30:16 +0930 Message-Id: <20180604050016.13071-1-andrew@aj.id.au> X-Mailer: git-send-email 2.17.0 Subject: [Skiboot] [PATCH] core: Add test for PCI quirks X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jeffery MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" 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 --- 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 +#include +#include + +/* 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; +}