From nobody Thu Nov 6 13:23:17 2025 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 14901786008041017.7450153677211; Wed, 22 Mar 2017 03:30:00 -0700 (PDT) Received: from localhost ([::1]:49957 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqdWh-0003WO-6C for importer@patchew.org; Wed, 22 Mar 2017 06:29:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43347) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqdV6-0002O7-SB for qemu-devel@nongnu.org; Wed, 22 Mar 2017 06:28:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cqdV5-0007Lh-P0 for qemu-devel@nongnu.org; Wed, 22 Mar 2017 06:28:20 -0400 Received: from [59.151.112.132] (port=15553 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqdV5-0007L5-4o for qemu-devel@nongnu.org; Wed, 22 Mar 2017 06:28:19 -0400 Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 22 Mar 2017 18:28:17 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id 0080F47B0CB5; Wed, 22 Mar 2017 18:28:16 +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; Wed, 22 Mar 2017 18:28:15 +0800 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="16863505" From: Cao jin To: Date: Wed, 22 Mar 2017 18:36:51 +0800 Message-ID: <1490179012-14990-3-git-send-email-caoj.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1490179012-14990-1-git-send-email-caoj.fnst@cn.fujitsu.com> References: <1490179012-14990-1-git-send-email-caoj.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.69] X-yoursite-MailScanner-ID: 0080F47B0CB5.A9815 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 v2 2/3] vfio pci: new function to init AER capability 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: izumi.taku@jp.fujitsu.com, alex.williamson@redhat.com, Dou Liyang , mst@redhat.com 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" Signed-off-by: Dou Liyang Signed-off-by: Cao jin --- hw/vfio/pci.c | 41 ++++++++++++++++++++++++++++++++++++----- hw/vfio/pci.h | 1 + 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 332f41d..3d0d005 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -1855,18 +1855,42 @@ out: return 0; } =20 -static void vfio_add_ext_cap(VFIOPCIDevice *vdev) +static int vfio_setup_aer(VFIOPCIDevice *vdev, uint8_t cap_ver, + int pos, uint16_t size, Error **errp) +{ + PCIDevice *pdev =3D &vdev->pdev; + uint32_t errcap; + + errcap =3D vfio_pci_read_config(pdev, pos + PCI_ERR_CAP, 4); + /* + * The ability to record multiple headers is depending on + * the state of the Multiple Header Recording Capable bit and + * enabled by the Multiple Header Recording Enable bit. + */ + if ((errcap & PCI_ERR_CAP_MHRC) && + (errcap & PCI_ERR_CAP_MHRE)) { + pdev->exp.aer_log.log_max =3D PCIE_AER_LOG_MAX_DEFAULT; + } else { + pdev->exp.aer_log.log_max =3D 0; + } + + pcie_cap_deverr_init(pdev); + return pcie_aer_init(pdev, cap_ver, pos, size, errp); +} + +static int vfio_add_ext_cap(VFIOPCIDevice *vdev, Error **errp) { PCIDevice *pdev =3D &vdev->pdev; uint32_t header; uint16_t cap_id, next, size; uint8_t cap_ver; uint8_t *config; + int ret =3D 0; =20 /* Only add extended caps if we have them and the guest can see them */ if (!pci_is_express(pdev) || !pci_bus_is_express(pdev->bus) || !pci_get_long(pdev->config + PCI_CONFIG_SPACE_SIZE)) { - return; + return 0; } =20 /* @@ -1915,6 +1939,9 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev) PCI_EXT_CAP_NEXT_MASK); =20 switch (cap_id) { + case PCI_EXT_CAP_ID_ERR: + ret =3D vfio_setup_aer(vdev, cap_ver, next, size, errp); + break; case PCI_EXT_CAP_ID_SRIOV: /* Read-only VF BARs confuse OVMF */ case PCI_EXT_CAP_ID_ARI: /* XXX Needs next function virtualization= */ trace_vfio_add_ext_cap_dropped(vdev->vbasedev.name, cap_id, ne= xt); @@ -1923,6 +1950,9 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev) pcie_add_capability(pdev, cap_id, cap_ver, next, size); } =20 + if (ret) { + goto out; + } } =20 /* Cleanup chain head ID if necessary */ @@ -1930,8 +1960,9 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev) pci_set_word(pdev->config + PCI_CONFIG_SPACE_SIZE, 0); } =20 +out: g_free(config); - return; + return ret; } =20 static int vfio_add_capabilities(VFIOPCIDevice *vdev, Error **errp) @@ -1949,8 +1980,8 @@ static int vfio_add_capabilities(VFIOPCIDevice *vdev,= Error **errp) return ret; } =20 - vfio_add_ext_cap(vdev); - return 0; + ret =3D vfio_add_ext_cap(vdev, errp); + return ret; } =20 static void vfio_pci_pre_reset(VFIOPCIDevice *vdev) diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index a8366bb..34e8b04 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -15,6 +15,7 @@ #include "qemu-common.h" #include "exec/memory.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_bridge.h" #include "hw/vfio/vfio-common.h" #include "qemu/event_notifier.h" #include "qemu/queue.h" --=20 1.8.3.1