From nobody Tue Oct 28 21:07:42 2025 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513610444856542.5538438445377; Mon, 18 Dec 2017 07:20:44 -0800 (PST) Received: from localhost ([::1]:47130 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eQxDR-0002tN-Gi for importer@patchew.org; Mon, 18 Dec 2017 10:20:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35192) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eQx7L-000636-GX for qemu-devel@nongnu.org; Mon, 18 Dec 2017 10:14:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eQx6F-0000qf-SI for qemu-devel@nongnu.org; Mon, 18 Dec 2017 10:14:11 -0500 Received: from mail-qk0-x241.google.com ([2607:f8b0:400d:c09::241]:44992) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eQx6E-0000p4-Nk; Mon, 18 Dec 2017 10:13:02 -0500 Received: by mail-qk0-x241.google.com with SMTP id h19so18705825qkj.11; Mon, 18 Dec 2017 07:13:02 -0800 (PST) Received: from x1.local ([138.117.48.211]) by smtp.gmail.com with ESMTPSA id y16sm8334022qta.48.2017.12.18.07.12.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Dec 2017 07:12:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XfLMLU+zTf2G+aDo7DUTmQjMimPvFT8MfZttUxwvOO4=; b=XfAjHAhFg+mqGxcQdpAkM1a0wyw4jgGJECaKWba6jTXK3pYqk22XUc9LQxcyhSWZv9 h/zLpXMXwuH3/mQvLMWlZWu0ysceN6WekJ6whINrihfshk+xr1GJS+3YfVWFbPJmz0gR Js84UfUK+GIKhCiPhhlhFjKekh6lhEy4C4Paey9R3YhOKLssCRqUwNi1Sr84wnjZ4S+k T8iWwjGqOLKfmb84/ug1xnob5Dp+2nJlLge4Pz82Yn7GH7lr+GStf0ilZojGSYEhDJFW 7rA7xcA2ehDe7Z2MLuc+HWFXTpmX2IAJ0oJo3eQaHFUmNQgDsNepognp+GMmHZkEhB0M 27ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=XfLMLU+zTf2G+aDo7DUTmQjMimPvFT8MfZttUxwvOO4=; b=T96myE2phaZZm0c+GiKKEzwr8S4VLuYiCbm7A4DIz56+e7vZ5VdIdHilOjkLG8AcEa a3FebpDlrQfMV0AwsAkv5DbR3iPOkUtbrmOJZrHlu3wJZ5sii8reLPJhl6CU2lYxWyKi QKr4RgLlDqT+GzToZMOUkRlXfb0gizjvBgpDp19339lxL5Xclo6TE0rwLih8qtR9zKTO JOMtlZXEqG/dU7V6mxGeCZ+kODAl7+WlN/07H8Vz8arUcOJ5a0rXa/a0r5QWSSA2JJTd ZR2loTbE68k7iYPjRIa8MQAHMXoWSOy/QwHE53H3xbTiI/rAqQ+CGlyOSNYrQmqSzDQK /Yuw== X-Gm-Message-State: AKGB3mLEEsV5a/EjwwFUmcyePMHrjiYkUpV+QLrZzf8twmJwtv8rmnKJ 2FrUGKJPCuAP476jhm0Z9GI= X-Google-Smtp-Source: ACJfBovVmfHrlZRDrrycyFgjJo2tQlhUvtE4uG0AYyGoqq0Ekvg/5nLhS3vaWIgwX9IWM8qP0vU6PA== X-Received: by 10.55.200.90 with SMTP id c87mr86173qkj.132.1513609979884; Mon, 18 Dec 2017 07:12:59 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: "Michael S. Tsirkin" , Marcel Apfelbaum , Eduardo Habkost , =?UTF-8?q?Herv=C3=A9=20Poussineau?= Date: Mon, 18 Dec 2017 12:12:42 -0300 Message-Id: <20171218151244.9975-3-f4bug@amsat.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171218151244.9975-1-f4bug@amsat.org> References: <20171218151244.9975-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c09::241 Subject: [Qemu-devel] [PATCH v2 2/4] hw/pci-host/piix: QOM'ify the IGD Passthrough host bridge 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: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-block@nongnu.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_6 Z_629925259 SPT_0 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Marcel Apfelbaum --- v2: use g_strdup_printf(), use 'pci_dev' variable. hw/pci-host/piix.c | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c index a684a7cca9..bb6560f815 100644 --- a/hw/pci-host/piix.c +++ b/hw/pci-host/piix.c @@ -804,60 +804,55 @@ static const IGDHostInfo igd_host_bridge_infos[] =3D { {0xa8, 4}, /* SNB: base of GTT stolen memory */ }; =20 -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; - ssize_t size =3D sizeof(path); + int rc, config_fd; /* Access real host bridge. */ - int rc =3D snprintf(path, size, "/sys/bus/pci/devices/%04x:%02x:%02x.%= d/%s", - 0, 0, 0, 0, "config"); - int ret =3D 0; - - if (rc >=3D size || rc < 0) { - return -ENODEV; - } + char *path =3D g_strdup_printf("/sys/bus/pci/devices/%04x:%02x:%02x.%d= /%s", + 0, 0, 0, 0, "config"); =20 config_fd =3D open(path, O_RDWR); if (config_fd < 0) { - return -ENODEV; + error_setg_errno(errp, errno, "Failed to open: %s", path); + goto out; } =20 if (lseek(config_fd, pos, SEEK_SET) !=3D pos) { - ret =3D -errno; - goto out; + error_setg_errno(errp, errno, "Failed to seek: %s", path); + goto out_close_fd; } =20 do { rc =3D read(config_fd, (uint8_t *)val, len); } while (rc < 0 && (errno =3D=3D EINTR || errno =3D=3D EAGAIN)); if (rc !=3D len) { - ret =3D -errno; + error_setg_errno(errp, errno, "Failed to read: %s", path); } =20 -out: +out_close_fd: close(config_fd); - return ret; +out: + g_free(path); } =20 -static int igd_pt_i440fx_initfn(struct PCIDevice *pci_dev) +static void igd_pt_i440fx_realize(PCIDevice *pci_dev, Error **errp) { uint32_t val =3D 0; - int rc, i, num; + int i, num; int pos, len; + Error *local_err =3D NULL; =20 num =3D ARRAY_SIZE(igd_host_bridge_infos); for (i =3D 0; i < num; i++) { pos =3D igd_host_bridge_infos[i].offset; len =3D igd_host_bridge_infos[i].len; - rc =3D 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; } =20 static void igd_passthrough_i440fx_class_init(ObjectClass *klass, void *da= ta) @@ -865,7 +860,7 @@ static void igd_passthrough_i440fx_class_init(ObjectCla= ss *klass, void *data) DeviceClass *dc =3D DEVICE_CLASS(klass); PCIDeviceClass *k =3D PCI_DEVICE_CLASS(klass); =20 - k->init =3D igd_pt_i440fx_initfn; + k->realize =3D igd_pt_i440fx_realize; dc->desc =3D "IGD Passthrough Host bridge"; } =20 --=20 2.15.1