From patchwork Thu Apr 27 14:35:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 9702997 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1E6D1601D3 for ; Thu, 27 Apr 2017 14:48:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 09B7228645 for ; Thu, 27 Apr 2017 14:48:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1B962865A; Thu, 27 Apr 2017 14:48:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F2D7C28645 for ; Thu, 27 Apr 2017 14:48:02 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d3kg5-0003GH-LR; Thu, 27 Apr 2017 14:45:53 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d3kg4-0003G4-5e for xen-devel@lists.xenproject.org; Thu, 27 Apr 2017 14:45:52 +0000 Received: from [85.158.139.211] by server-2.bemta-5.messagelabs.com id D8/7A-02006-F1402095; Thu, 27 Apr 2017 14:45:51 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprDIsWRWlGSWpSXmKPExsXitHSDva48C1O kwbMdjBbft0xmcmD0OPzhCksAYxRrZl5SfkUCa0bjoy2sBX+UKk63bmdsYJwl3cXIwSEh4C9x +INjFyMnB5uAjsTFuTvZQMIiAioSt/cadDFycTALnGCUaF+1hQ2kRlggWGL7tX2sIDaLgKrE6 64dYDavgKXE0g2LWUBsCQE9ibcTXzCC2JwCVhLvXl8Gs4WAaibPfcgEUS8ocXLmE7B6ZgFNid btv9khbHmJ5q2zmSHqFSX65z1gm8DINwtJyywkLbOQtCxgZF7FqFGcWlSWWqRraKiXVJSZnlG Sm5iZo2toYKqXm1pcnJiempOYVKyXnJ+7iREYagxAsINxZbvzIUZJDiYlUV7Zg4yRQnxJ+SmV GYnFGfFFpTmpxYcYZTg4lCR4y5mZIoUEi1LTUyvSMnOAQQ+TluDgURLhVQRJ8xYXJOYWZ6ZDp E4xKkqJ8waCJARAEhmleXBtsEi7xCgrJczLCHSIEE9BalFuZgmq/CtGcQ5GJWHeF0xAU3gy80 rgpr8CWswEtJjFhQFkcUkiQkqqgVGrwcjUMrj3TujKh99Olf/X4mK3M/y3aMen3f/du06ydrI 4rvquyhS6eeqvzX3P7q4P4PzmuPyJ0nOrw9uvcIuKKPOeTS2rrlucmbGwMNxidQHT2reHXv84 cM2EJ/QmY+Edxzwr+8aNbOeun/6/lvmUf0mk0KvHz897xGxQKWB8Kya97Gz9m1olluKMREMt5 qLiRAB4MXrdrwIAAA== X-Env-Sender: prvs=283fe5697=roger.pau@citrix.com X-Msg-Ref: server-16.tower-206.messagelabs.com!1493304349!79531122!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 22354 invoked from network); 27 Apr 2017 14:45:50 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-16.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 27 Apr 2017 14:45:50 -0000 X-IronPort-AV: E=Sophos;i="5.37,384,1488844800"; d="scan'208";a="430029184" From: Roger Pau Monne To: Date: Thu, 27 Apr 2017 15:35:44 +0100 Message-ID: <20170427143546.14662-8-roger.pau@citrix.com> X-Mailer: git-send-email 2.11.0 (Apple Git-81) In-Reply-To: <20170427143546.14662-1-roger.pau@citrix.com> References: <20170427143546.14662-1-roger.pau@citrix.com> MIME-Version: 1.0 Cc: Andrew Cooper , julien.grall@arm.com, Jan Beulich , boris.ostrovsky@oracle.com, Roger Pau Monne Subject: [Xen-devel] [PATCH v3 7/9] vpci: add a priority field to the vPCI register initializer X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP And mark the capability and header vPCI register initializers as high priority, so that they are initialized first. This is needed for MSI-X, since MSI-X needs to know the position of the BARs in order to perform it's initialization, and in order to mask or enable the MSI/MSI-X functionality on demand. Signed-off-by: Roger Pau Monné --- Cc: Jan Beulich Cc: Andrew Cooper --- tools/tests/vpci/Makefile | 4 ++-- xen/drivers/vpci/capabilities.c | 2 +- xen/drivers/vpci/header.c | 2 +- xen/drivers/vpci/vpci.c | 14 ++++++++++++-- xen/include/xen/vpci.h | 13 +++++++++++-- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/tools/tests/vpci/Makefile b/tools/tests/vpci/Makefile index 7969fcbd82..e5edc4f512 100644 --- a/tools/tests/vpci/Makefile +++ b/tools/tests/vpci/Makefile @@ -31,8 +31,8 @@ vpci.c: $(XEN_ROOT)/xen/drivers/vpci/vpci.c # Trick the compiler so it doesn't complain about missing symbols sed -e '/#include/d' \ -e '1s;^;#include "emul.h"\ - const vpci_register_init_t __start_vpci_array[1]\;\ - const vpci_register_init_t __end_vpci_array[1]\;\ + const struct vpci_register_init __start_vpci_array[1]\;\ + const struct vpci_register_init __end_vpci_array[1]\;\ ;' <$< >$@ rbtree.h: $(XEN_ROOT)/xen/include/xen/rbtree.h diff --git a/xen/drivers/vpci/capabilities.c b/xen/drivers/vpci/capabilities.c index b2a3326aa7..204355e673 100644 --- a/xen/drivers/vpci/capabilities.c +++ b/xen/drivers/vpci/capabilities.c @@ -145,7 +145,7 @@ static int vpci_capabilities_init(struct pci_dev *pdev) return 0; } -REGISTER_VPCI_INIT(vpci_capabilities_init); +REGISTER_VPCI_INIT(vpci_capabilities_init, true); /* * Local variables: diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index a401cf6915..3deec53efd 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -278,7 +278,7 @@ static int vpci_init_bars(struct pci_dev *pdev) return 0; } -REGISTER_VPCI_INIT(vpci_init_bars); +REGISTER_VPCI_INIT(vpci_init_bars, true); /* * Local variables: diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index b159f0db80..e6154b742e 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -20,7 +20,7 @@ #include #include -extern const vpci_register_init_t __start_vpci_array[], __end_vpci_array[]; +extern const struct vpci_register_init __start_vpci_array[], __end_vpci_array[]; #define NUM_VPCI_INIT (__end_vpci_array - __start_vpci_array) #define vpci_init __start_vpci_array @@ -37,6 +37,7 @@ struct vpci_register { int xen_vpci_add_handlers(struct pci_dev *pdev) { int i, rc = 0; + bool priority = true; if ( !has_vpci(pdev->domain) ) return 0; @@ -47,9 +48,13 @@ int xen_vpci_add_handlers(struct pci_dev *pdev) pdev->vpci->handlers = RB_ROOT; + again: for ( i = 0; i < NUM_VPCI_INIT; i++ ) { - rc = vpci_init[i](pdev); + if ( priority != vpci_init[i].priority ) + continue; + + rc = vpci_init[i].init(pdev); if ( rc ) break; } @@ -69,6 +74,11 @@ int xen_vpci_add_handlers(struct pci_dev *pdev) } xfree(pdev->vpci); } + else if ( priority ) + { + priority = false; + goto again; + } return rc; } diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h index d41277f39b..2bf61d6c15 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -29,8 +29,17 @@ typedef int (*vpci_write_t)(struct pci_dev *pdev, unsigned int reg, typedef int (*vpci_register_init_t)(struct pci_dev *dev); -#define REGISTER_VPCI_INIT(x) \ - static const vpci_register_init_t x##_entry __used_section(".data.vpci") = x +struct vpci_register_init { + vpci_register_init_t init; + bool priority; +}; + +#define REGISTER_VPCI_INIT(f, p) \ + static const struct vpci_register_init \ + x##_entry __used_section(".data.vpci") = { \ + .init = f, \ + .priority = p, \ +} /* Add vPCI handlers to device. */ int xen_vpci_add_handlers(struct pci_dev *dev);