From nobody Mon Apr 29 20:19:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488874825744716.4621955802972; Tue, 7 Mar 2017 00:20:25 -0800 (PST) Received: from localhost ([::1]:48176 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clAM1-0000XR-JR for importer@patchew.org; Tue, 07 Mar 2017 03:20:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57863) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clALV-0000XK-Es for qemu-devel@nongnu.org; Tue, 07 Mar 2017 03:19:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clALS-0004qT-9P for qemu-devel@nongnu.org; Tue, 07 Mar 2017 03:19:49 -0500 Received: from [59.151.112.132] (port=22791 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clALR-0004p6-5w for qemu-devel@nongnu.org; Tue, 07 Mar 2017 03:19:46 -0500 Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 07 Mar 2017 16:19:36 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id 4852748A2940; Tue, 7 Mar 2017 16:19:33 +0800 (CST) Received: from G08FNSTD140223.g08.fujitsu.local (10.167.226.69) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 7 Mar 2017 16:19:33 +0800 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="16285520" From: Cao jin To: Date: Tue, 7 Mar 2017 16:27:37 +0800 Message-ID: <1488875257-7870-1-git-send-email-caoj.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1488011202-32121-2-git-send-email-caoj.fnst@cn.fujitsu.com> References: <1488011202-32121-2-git-send-email-caoj.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.69] X-yoursite-MailScanner-ID: 4852748A2940.AC02A X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: caoj.fnst@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Subject: [Qemu-devel] [PATCH v10] msix: rename and create a wrapper X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marcel Apfelbaum , Alex Williamson , Markus Armbruster , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Rename msix_init to msix_validate_and_init which doesn't assert; New a wrapper msix_init to assert programming error. CC: Alex Williamson CC: Markus Armbruster CC: Marcel Apfelbaum CC: Michael S. Tsirkin Signed-off-by: Cao jin --- revert the modification in msix_init_exclusive_bar() hw/pci/msix.c | 23 ++++++++++++++++++----- hw/vfio/pci.c | 12 ++++++------ include/hw/pci/msix.h | 5 +++++ 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/hw/pci/msix.c b/hw/pci/msix.c index bb54e8b0ac37..02697de32dfc 100644 --- a/hw/pci/msix.c +++ b/hw/pci/msix.c @@ -239,6 +239,19 @@ static void msix_mask_all(struct PCIDevice *dev, unsig= ned nentries) } } =20 +/* Just a wrapper to check the return value */ +int msix_init(struct PCIDevice *dev, unsigned short nentries, + MemoryRegion *table_bar, uint8_t table_bar_nr, + unsigned table_offset, MemoryRegion *pba_bar, + uint8_t pba_bar_nr, unsigned pba_offset, uint8_t cap_pos, + Error **errp) +{ + int ret =3D msix_validate_and_init(dev, nentries, table_bar, table_bar= _nr, + table_offset, pba_bar, pba_bar_nr, pba_offset, cap_pos, errp); + + assert(ret !=3D -EINVAL); + return ret; +} /* * Make PCI device @dev MSI-X capable * @nentries is the max number of MSI-X vectors that the device support. @@ -259,11 +272,11 @@ static void msix_mask_all(struct PCIDevice *dev, unsi= gned nentries) * also means a programming error, except device assignment, which can che= ck * if a real HW is broken. */ -int msix_init(struct PCIDevice *dev, unsigned short nentries, - MemoryRegion *table_bar, uint8_t table_bar_nr, - unsigned table_offset, MemoryRegion *pba_bar, - uint8_t pba_bar_nr, unsigned pba_offset, uint8_t cap_pos, - Error **errp) +int msix_validate_and_init(struct PCIDevice *dev, unsigned short nentries, + MemoryRegion *table_bar, uint8_t table_bar_nr, + unsigned table_offset, MemoryRegion *pba_bar, + uint8_t pba_bar_nr, unsigned pba_offset, + uint8_t cap_pos, Error **errp) { int cap; unsigned table_size, pba_size; diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 332f41d6627f..06828b537a75 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -1436,12 +1436,12 @@ static int vfio_msix_setup(VFIOPCIDevice *vdev, int= pos, Error **errp) =20 vdev->msix->pending =3D g_malloc0(BITS_TO_LONGS(vdev->msix->entries) * sizeof(unsigned long)); - ret =3D msix_init(&vdev->pdev, vdev->msix->entries, - vdev->bars[vdev->msix->table_bar].region.mem, - vdev->msix->table_bar, vdev->msix->table_offset, - vdev->bars[vdev->msix->pba_bar].region.mem, - vdev->msix->pba_bar, vdev->msix->pba_offset, pos, - &err); + ret =3D msix_validate_and_init(&vdev->pdev, vdev->msix->entries, + vdev->bars[vdev->msix->table_bar].region.mem, + vdev->msix->table_bar, vdev->msix->table_offs= et, + vdev->bars[vdev->msix->pba_bar].region.mem, + vdev->msix->pba_bar, vdev->msix->pba_offset, = pos, + &err); if (ret < 0) { if (ret =3D=3D -ENOTSUP) { error_report_err(err); diff --git a/include/hw/pci/msix.h b/include/hw/pci/msix.h index 1f27658d352f..815e59bc96f3 100644 --- a/include/hw/pci/msix.h +++ b/include/hw/pci/msix.h @@ -11,6 +11,11 @@ int msix_init(PCIDevice *dev, unsigned short nentries, unsigned table_offset, MemoryRegion *pba_bar, uint8_t pba_bar_nr, unsigned pba_offset, uint8_t cap_pos, Error **errp); +int msix_validate_and_init(PCIDevice *dev, unsigned short nentries, + MemoryRegion *table_bar, uint8_t table_bar_nr, + unsigned table_offset, MemoryRegion *pba_bar, + uint8_t pba_bar_nr, unsigned pba_offset, + uint8_t cap_pos, Error **errp); int msix_init_exclusive_bar(PCIDevice *dev, unsigned short nentries, uint8_t bar_nr, Error **errp); =20 --=20 2.1.0