From nobody Tue Feb 10 10:04:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1615543911; cv=none; d=zohomail.com; s=zohoarc; b=Te9QPUEPyBBuqdMHihw4+xF6FOtWmSnIzP9Dd4BLWHB+gR5y4XcQTq//v9emGz7fRp6YqYjxbwujJi2o/7vf613i1y1XqyGNsTAire2+gxDFrgDYbS9vo4jOPRTSmBoAZW5W+KafEC11dtCKK9tJh/DeY5/59LO/KiPxCbw0ji8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615543911; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uH8FQtcVOWObNnSx2E/9vhaDLZ8kg5cN31rmkw7boNc=; b=hktAFS8rOEL+xrudilWQ0rJit2bCDHRjNeYWEFRYwYohpCc+QYZo2akox6AKvhTwR/E8Lz66muFEjaKGPIf2+bSUo0p0Sfv4SJlIetNm5TFxlpkpEyYTUCq3bSm8uS8bk5jhSiOai06ATK4p3L6bfQO5Xh83BDJt7RFBqQpZOiA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16155439119621020.7985669246775; Fri, 12 Mar 2021 02:11:51 -0800 (PST) Received: from localhost ([::1]:53594 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lKelq-0004bN-Rz for importer@patchew.org; Fri, 12 Mar 2021 05:11:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34792) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lKedf-0000JU-BC for qemu-devel@nongnu.org; Fri, 12 Mar 2021 05:03:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:28966) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lKedd-000377-3C for qemu-devel@nongnu.org; Fri, 12 Mar 2021 05:03:23 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-575-tIHfrqK2Me27yROFljUEMw-1; Fri, 12 Mar 2021 05:03:17 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ABBC183DD21 for ; Fri, 12 Mar 2021 10:03:16 +0000 (UTC) Received: from localhost (unknown [10.36.110.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id F13CF18B5E; Fri, 12 Mar 2021 10:03:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615543400; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uH8FQtcVOWObNnSx2E/9vhaDLZ8kg5cN31rmkw7boNc=; b=LJ/voJYXrwmnEQMVUw1byZUesYq3khcqO56Oswvxp5/yiXwfbV7f7GV/uX2qPMAOYIt1/Q IW9AX3uWTgoMCAhTJABYCj4k7f+E7sH9Lo1rL409+9Pv/ioIqqyaHmXSICng9pt4QOYA8K ABE1tZ0pbmq9KPmMHU5fmvojQ12UFus= X-MC-Unique: tIHfrqK2Me27yROFljUEMw-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PATCH 12/27] ui: move qemu_spice_fill_device_address to ui/util.c Date: Fri, 12 Mar 2021 14:00:53 +0400 Message-Id: <20210312100108.2706195-13-marcandre.lureau@redhat.com> In-Reply-To: <20210312100108.2706195-1-marcandre.lureau@redhat.com> References: <20210312100108.2706195-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.25, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Marc-Andr=C3=A9 Lureau Other backends can use it. Signed-off-by: Marc-Andr=C3=A9 Lureau --- include/ui/console.h | 6 +++ include/ui/spice-display.h | 4 -- hw/display/qxl.c | 5 ++- ui/spice-core.c | 50 ------------------------- ui/spice-display.c | 5 ++- ui/util.c | 75 ++++++++++++++++++++++++++++++++++++++ ui/meson.build | 1 + 7 files changed, 90 insertions(+), 56 deletions(-) create mode 100644 ui/util.c diff --git a/include/ui/console.h b/include/ui/console.h index b271bb1c51..793f4c09ee 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -489,4 +489,10 @@ int vnc_init_func(void *opaque, QemuOpts *opts, Error = **errp); /* input.c */ int index_from_key(const char *key, size_t key_length); =20 +/* util.c */ +bool qemu_console_fill_device_address(QemuConsole *con, + char *device_address, + size_t size, + Error **errp); + #endif diff --git a/include/ui/spice-display.h b/include/ui/spice-display.h index a2fbf62c52..e271e011da 100644 --- a/include/ui/spice-display.h +++ b/include/ui/spice-display.h @@ -184,8 +184,4 @@ void qemu_spice_display_start(void); void qemu_spice_display_stop(void); int qemu_spice_display_is_running(SimpleSpiceDisplay *ssd); =20 -bool qemu_spice_fill_device_address(QemuConsole *con, - char *device_address, - size_t size); - #endif diff --git a/hw/display/qxl.c b/hw/display/qxl.c index 6784d32920..ac56aeeff4 100644 --- a/hw/display/qxl.c +++ b/hw/display/qxl.c @@ -2202,12 +2202,15 @@ static void qxl_realize_common(PCIQXLDevice *qxl, E= rror **errp) } =20 #if SPICE_SERVER_VERSION >=3D 0x000e02 /* release 0.14.2 */ + Error *err =3D NULL; char device_address[256] =3D ""; - if (qemu_spice_fill_device_address(qxl->vga.con, device_address, 256))= { + if (qemu_console_fill_device_address(qxl->vga.con, device_address, 256= , &err)) { spice_qxl_set_device_info(&qxl->ssd.qxl, device_address, 0, qxl->max_outputs); + } else { + error_report_err(err); } #endif =20 diff --git a/ui/spice-core.c b/ui/spice-core.c index beee932f55..2c21d923c8 100644 --- a/ui/spice-core.c +++ b/ui/spice-core.c @@ -861,56 +861,6 @@ bool qemu_spice_have_display_interface(QemuConsole *co= n) return false; } =20 -/* - * Recursively (in reverse order) appends addresses of PCI devices as it m= oves - * up in the PCI hierarchy. - * - * @returns true on success, false when the buffer wasn't large enough - */ -static bool append_pci_address(char *buf, size_t buf_size, const PCIDevice= *pci) -{ - PCIBus *bus =3D pci_get_bus(pci); - /* - * equivalent to if (!pci_bus_is_root(bus)), but the function is not b= uilt - * with PCI_CONFIG=3Dn, avoid using an #ifdef by checking directly - */ - if (bus->parent_dev !=3D NULL) { - append_pci_address(buf, buf_size, bus->parent_dev); - } - - size_t len =3D strlen(buf); - ssize_t written =3D snprintf(buf + len, buf_size - len, "/%02x.%x", - PCI_SLOT(pci->devfn), PCI_FUNC(pci->devfn)); - - return written > 0 && written < buf_size - len; -} - -bool qemu_spice_fill_device_address(QemuConsole *con, - char *device_address, - size_t size) -{ - DeviceState *dev =3D DEVICE(object_property_get_link(OBJECT(con), - "device", - &error_abort)); - PCIDevice *pci =3D (PCIDevice *) object_dynamic_cast(OBJECT(dev), - TYPE_PCI_DEVICE); - - if (pci =3D=3D NULL) { - warn_report("Setting device address of a display device to SPICE: " - "Not a PCI device."); - return false; - } - - strncpy(device_address, "pci/0000", size); - if (!append_pci_address(device_address, size, pci)) { - warn_report("Setting device address of a display device to SPICE: " - "Too many PCI devices in the chain."); - return false; - } - - return true; -} - int qemu_spice_add_display_interface(QXLInstance *qxlin, QemuConsole *con) { if (g_slist_find(spice_consoles, con)) { diff --git a/ui/spice-display.c b/ui/spice-display.c index 0b787d12df..278a11b1d5 100644 --- a/ui/spice-display.c +++ b/ui/spice-display.c @@ -1144,12 +1144,15 @@ static void qemu_spice_display_init_one(QemuConsole= *con) qemu_spice_add_display_interface(&ssd->qxl, con); =20 #if SPICE_SERVER_VERSION >=3D 0x000e02 /* release 0.14.2 */ + Error *err =3D NULL; char device_address[256] =3D ""; - if (qemu_spice_fill_device_address(con, device_address, 256)) { + if (qemu_console_fill_device_address(con, device_address, 256, &err)) { spice_qxl_set_device_info(&ssd->qxl, device_address, qemu_console_get_head(con), 1); + } else { + error_report_err(err); } #endif =20 diff --git a/ui/util.c b/ui/util.c new file mode 100644 index 0000000000..7e8fc1ea53 --- /dev/null +++ b/ui/util.c @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2021 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 or + * (at your option) version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" + +#include "hw/pci/pci.h" +#include "hw/pci/pci_bus.h" +#include "qapi/error.h" +#include "ui/console.h" + +/* + * Recursively (in reverse order) appends addresses of PCI devices as it m= oves + * up in the PCI hierarchy. + * + * @returns true on success, false when the buffer wasn't large enough + */ +static bool append_pci_address(char *buf, size_t buf_size, const PCIDevice= *pci) +{ + PCIBus *bus =3D pci_get_bus(pci); + /* + * equivalent to if (!pci_bus_is_root(bus)), but the function is not b= uilt + * with PCI_CONFIG=3Dn, avoid using an #ifdef by checking directly + */ + if (bus->parent_dev !=3D NULL) { + append_pci_address(buf, buf_size, bus->parent_dev); + } + + size_t len =3D strlen(buf); + ssize_t written =3D snprintf(buf + len, buf_size - len, "/%02x.%x", + PCI_SLOT(pci->devfn), PCI_FUNC(pci->devfn)); + + return written > 0 && written < buf_size - len; +} + +bool qemu_console_fill_device_address(QemuConsole *con, + char *device_address, + size_t size, + Error **errp) +{ + ERRP_GUARD(); + DeviceState *dev =3D DEVICE(object_property_get_link(OBJECT(con), + "device", + &error_abort)); + PCIDevice *pci =3D (PCIDevice *) object_dynamic_cast(OBJECT(dev), + TYPE_PCI_DEVICE); + + if (pci =3D=3D NULL) { + error_setg(errp, "Setting device address of a display device: " + "Not a PCI device."); + return false; + } + + strncpy(device_address, "pci/0000", size); + if (!append_pci_address(device_address, size, pci)) { + error_setg(errp, "Setting device address of a display device: " + "Too many PCI devices in the chain."); + return false; + } + + return true; +} diff --git a/ui/meson.build b/ui/meson.build index e8d3ff41b9..97cdd58856 100644 --- a/ui/meson.build +++ b/ui/meson.build @@ -11,6 +11,7 @@ softmmu_ss.add(files( 'kbd-state.c', 'keymaps.c', 'qemu-pixman.c', + 'util.c', )) softmmu_ss.add([spice_headers, files('spice-module.c')]) =20 --=20 2.29.0