From patchwork Thu Dec 24 13:27:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cao jin X-Patchwork-Id: 560939 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 B4B1F140C37 for ; Fri, 25 Dec 2015 00:26:05 +1100 (AEDT) Received: from localhost ([::1]:60127 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aC5u7-0004Cr-IP for incoming@patchwork.ozlabs.org; Thu, 24 Dec 2015 08:26:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43610) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aC5tr-0003uu-TH for qemu-devel@nongnu.org; Thu, 24 Dec 2015 08:25:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aC5to-0008I0-MS for qemu-devel@nongnu.org; Thu, 24 Dec 2015 08:25:47 -0500 Received: from [59.151.112.132] (port=27296 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aC5to-0008Ai-At for qemu-devel@nongnu.org; Thu, 24 Dec 2015 08:25:44 -0500 X-IronPort-AV: E=Sophos;i="5.20,346,1444665600"; d="scan'208";a="1946205" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 24 Dec 2015 21:25:08 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id B68E241887C9; Thu, 24 Dec 2015 21:24:58 +0800 (CST) Received: from G08FNSTD140223.g08.fujitsu.local (10.167.226.86) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Thu, 24 Dec 2015 21:28:19 +0800 From: Cao jin To: Date: Thu, 24 Dec 2015 21:27:27 +0800 Message-ID: <1450963647-11631-1-git-send-email-caoj.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.1.0 MIME-Version: 1.0 X-Originating-IP: [10.167.226.86] X-yoursite-MailScanner-ID: B68E241887C9.ACCB9 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 Cc: tiejun.chen@intel.com, mst@redhat.com, stefano.stabellini@eu.citrix.com Subject: [Qemu-devel] [PATCH v3] igd-passthrough-i440FX: convert to realize() 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 Bonus: fix a bug that will result in config space value error Signed-off-by: Cao jin --- hw/pci-host/piix.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c index 715208b..a37e93d 100644 --- a/hw/pci-host/piix.c +++ b/hw/pci-host/piix.c @@ -761,7 +761,7 @@ static const IGDHostInfo igd_host_bridge_infos[] = { {0xa8, 4}, /* SNB: base of GTT stolen memory */ }; -static int host_pci_config_read(int pos, int len, uint32_t val) +static void host_pci_config_read(int pos, int len, uint32_t *val, Error **errp) { char path[PATH_MAX]; int config_fd; @@ -769,50 +769,53 @@ static int host_pci_config_read(int pos, int len, uint32_t val) /* Access real host bridge. */ int rc = snprintf(path, size, "/sys/bus/pci/devices/%04x:%02x:%02x.%d/%s", 0, 0, 0, 0, "config"); - int ret = 0; if (rc >= size || rc < 0) { - return -ENODEV; + error_setg_errno(errp, errno, "snprintf err"); + return; } config_fd = open(path, O_RDWR); if (config_fd < 0) { - return -ENODEV; + error_setg_errno(errp, errno, "open err"); + return; } if (lseek(config_fd, pos, SEEK_SET) != pos) { - ret = -errno; + error_setg_errno(errp, errno, "lseek err"); goto out; } + do { - rc = read(config_fd, (uint8_t *)&val, len); + rc = read(config_fd, (uint8_t *)val, len); } while (rc < 0 && (errno == EINTR || errno == EAGAIN)); if (rc != len) { - ret = -errno; + error_setg_errno(errp, errno, "read err"); } + out: close(config_fd); - return ret; } -static int igd_pt_i440fx_initfn(struct PCIDevice *pci_dev) +static void igd_pt_i440fx_realize(struct PCIDevice *pci_dev, Error **errp) { uint32_t val = 0; - int rc, i, num; + int i, num; int pos, len; + Error *local_err = NULL; num = ARRAY_SIZE(igd_host_bridge_infos); for (i = 0; i < num; i++) { pos = igd_host_bridge_infos[i].offset; len = igd_host_bridge_infos[i].len; - rc = host_pci_config_read(pos, len, val); - if (rc) { - return -ENODEV; + host_pci_config_read(pos, len, &val, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; } - pci_default_write_config(pci_dev, pos, val, len); - } - return 0; + pci_default_write_config(pci_dev, pos, cpu_to_le32(val), len); + } } static void igd_passthrough_i440fx_class_init(ObjectClass *klass, void *data) @@ -820,7 +823,7 @@ static void igd_passthrough_i440fx_class_init(ObjectClass *klass, void *data) DeviceClass *dc = DEVICE_CLASS(klass); PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); - k->init = igd_pt_i440fx_initfn; + k->realize = igd_pt_i440fx_realize; dc->desc = "IGD Passthrough Host bridge"; }