From patchwork Mon Dec 18 15:12:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 850124 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="XfAjHAhF"; dkim-atps=neutral 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 3z0l874B4zz9s82 for ; Tue, 19 Dec 2017 02:19:51 +1100 (AEDT) Received: from localhost ([::1]:46945 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eQxCn-000215-Ee for incoming@patchwork.ozlabs.org; Mon, 18 Dec 2017 10:19:49 -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) 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) 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) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: "Michael S. Tsirkin" , Marcel Apfelbaum , Eduardo Habkost , =?utf-8?q?Herv=C3=A9_Poussinea?= =?utf-8?q?u?= 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 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_Mathieu-Daud=C3=A9?= , qemu-block@nongnu.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Philippe Mathieu-Daudé 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[] = { {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; - ssize_t size = sizeof(path); + int rc, config_fd; /* 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; - } + char *path = g_strdup_printf("/sys/bus/pci/devices/%04x:%02x:%02x.%d/%s", + 0, 0, 0, 0, "config"); config_fd = open(path, O_RDWR); if (config_fd < 0) { - return -ENODEV; + error_setg_errno(errp, errno, "Failed to open: %s", path); + goto out; } if (lseek(config_fd, pos, SEEK_SET) != pos) { - ret = -errno; - goto out; + error_setg_errno(errp, errno, "Failed to seek: %s", path); + goto out_close_fd; } do { 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, "Failed to read: %s", path); } -out: +out_close_fd: close(config_fd); - return ret; +out: + g_free(path); } -static int igd_pt_i440fx_initfn(struct PCIDevice *pci_dev) +static void igd_pt_i440fx_realize(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; } static void igd_passthrough_i440fx_class_init(ObjectClass *klass, void *data) @@ -865,7 +860,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"; }