From patchwork Mon Mar 2 07:16:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenfan X-Patchwork-Id: 444944 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 636B914010F for ; Mon, 2 Mar 2015 18:26:19 +1100 (AEDT) Received: from localhost ([::1]:55420 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YSKk5-0008EH-Gy for incoming@patchwork.ozlabs.org; Mon, 02 Mar 2015 02:26:17 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58855) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YSKhF-0002tu-W3 for qemu-devel@nongnu.org; Mon, 02 Mar 2015 02:23:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YSKhC-0006uL-QY for qemu-devel@nongnu.org; Mon, 02 Mar 2015 02:23:21 -0500 Received: from [59.151.112.132] (port=48699 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YSKhC-0006qK-EV for qemu-devel@nongnu.org; Mon, 02 Mar 2015 02:23:18 -0500 X-IronPort-AV: E=Sophos;i="5.04,848,1406563200"; d="scan'208";a="61005056" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 02 Mar 2015 15:19:40 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t227MPrQ026544; Mon, 2 Mar 2015 15:22:25 +0800 Received: from G08FNSTD131468.g08.fujitsu.local (10.167.226.78) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Mon, 2 Mar 2015 15:23:20 +0800 From: Chen Fan To: Date: Mon, 2 Mar 2015 15:16:08 +0800 Message-ID: <585cc19614c259218afaa5a505618970f9559b13.1425280224.git.chen.fan.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.167.226.78] X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Cc: izumi.taku@jp.fujitsu.com, alex.williamson@redhat.com Subject: [Qemu-devel] [RFC v4 5/9] vfio: add aer support for vfio device X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Calling pcie_aer_init to initilize aer related registers for vfio device, then reload physical related registers to expose device capability. Signed-off-by: Chen Fan --- hw/vfio/pci.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 96cb52b..db4ba23 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2720,6 +2720,28 @@ static int vfio_add_std_cap(VFIOPCIDevice *vdev, uint8_t pos) return 0; } +static int vfio_setup_aer(VFIOPCIDevice *vdev, uint8_t cap_ver, + int pos, uint16_t size) +{ + PCIDevice *pdev = &vdev->pdev; + uint8_t *exp_cap = pdev->config + pdev->exp.exp_cap; + uint32_t severity; + int ret; + + pdev->exp.aer_log.log_max = PCIE_AER_LOG_MAX_DEFAULT; + ret = pcie_aer_init(pdev, cap_ver, pos, size); + if (ret) { + return ret; + } + + /* load physical registers */ + severity = vfio_pci_read_config(pdev, + pdev->exp.aer_cap + PCI_ERR_UNCOR_SEVER, 4); + pci_long_test_and_clear_mask(exp_cap + PCI_ERR_UNCOR_SEVER, ~severity); + + return 0; +} + static int vfio_add_ext_cap(VFIOPCIDevice *vdev, const uint8_t *config, uint16_t pos) { @@ -2742,7 +2764,18 @@ static int vfio_add_ext_cap(VFIOPCIDevice *vdev, const uint8_t *config, */ size = vfio_ext_cap_max_size(config, pos); - pcie_add_capability(pdev, cap_id, cap_ver, pos, size); + switch (cap_id) { + case PCI_EXT_CAP_ID_ERR: + ret = vfio_setup_aer(vdev, cap_ver, pos, size); + if (ret) { + return ret; + } + break; + default: + pcie_add_capability(pdev, cap_id, cap_ver, pos, size); + break; + } + if (pos == PCI_CONFIG_SPACE_SIZE) { /* Begin the rebuild, we should set the next offset zero. */ pci_set_long(pdev->config + pos, PCI_EXT_CAP(cap_id, cap_ver, 0));