From nobody Mon May 13 23:06:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1671465184; cv=none; d=zohomail.com; s=zohoarc; b=HhSnHpO7UYATU4YL3mV5SIGduSfuKaHyUfLbghr7HPMPjWvR+9qUkdYNeO4OA9zwlbyXaMSBObz4nuFnOg0hiPkuHof7WXBcis6Ltbl5dMA7FqhOBqvfQ+YA2/vkSaDRNVKCfveBS+mCQzf0zVpmq8WEiuMOJMKP0PJbuNGYwrM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671465184; 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=7mNAZMVGKhkXnvNBCGHt9IbwV3LsRKkwsbsubKDR2Ec=; b=NxXpAGxyOJDHDCqA8BqUlHuBWCSV2FSPjW82sZjDiHj/B8ksXSwtWv1/KlFXK0pRXnsb3yPmbt7BAQR9fNp+8c29X7qi2ys7ok7qETh8uFhsXzr0NLdGBk7ur85VNZkMwrUufMl7OQ5b2nTRkr+p/lP4s412/fCH60UMAUO64yk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1671465184168529.8450750772496; Mon, 19 Dec 2022 07:53:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p7IQW-0002hk-Du; Mon, 19 Dec 2022 10:51:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7IQK-0002Xo-AM for qemu-devel@nongnu.org; Mon, 19 Dec 2022 10:51:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7IQH-0000Zd-Jn for qemu-devel@nongnu.org; Mon, 19 Dec 2022 10:51:28 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-395-ZZ060WMnPmyPcF2uCgBBEQ-1; Mon, 19 Dec 2022 10:51:22 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B65DB3813F50; Mon, 19 Dec 2022 15:51:21 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.195.91]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 869E714152F4; Mon, 19 Dec 2022 15:51:21 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5539021E6891; Mon, 19 Dec 2022 16:51:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671465084; 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=7mNAZMVGKhkXnvNBCGHt9IbwV3LsRKkwsbsubKDR2Ec=; b=U2TUD3TZW132XIQJQgtCrv2DQz566vcnuSErgpjq4QOuCug6H2Img9Zd3NsWhlRNHzZkoQ QYOa7p38Vs5bKFxuGT6/d+vGQkXv9xbbPozH/QkbIMr8grDEkxRsn/uCNfrO9DfIe+V037 E/XJDctALkXI92bckHiSylf0VuFKJEs= X-MC-Unique: ZZ060WMnPmyPcF2uCgBBEQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, "Michael S . Tsirkin" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 01/13] pci: Clean up a few things checkpatch.pl would flag later on Date: Mon, 19 Dec 2022 16:51:08 +0100 Message-Id: <20221219155120.2273041-2-armbru@redhat.com> In-Reply-To: <20221219155120.2273041-1-armbru@redhat.com> References: <20221219155120.2273041-1-armbru@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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=170.10.129.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1671465185807100003 Fix a few style violations so that checkpatch.pl won't complain when I move this code. Signed-off-by: Markus Armbruster Reviewed-by: Michael S. Tsirkin Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20221201121133.3813857-2-armbru@redhat.com> --- hw/pci/pci.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index c61348dca0..d70a567490 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -1851,10 +1851,12 @@ static PciBridgeInfo *qmp_query_pci_bridge(PCIDevic= e *dev, PCIBus *bus, range->limit =3D pci_bridge_get_limit(dev, PCI_BASE_ADDRESS_MEM_PREFET= CH); =20 if (dev->config[PCI_SECONDARY_BUS] !=3D 0) { - PCIBus *child_bus =3D pci_find_bus_nr(bus, dev->config[PCI_SECONDA= RY_BUS]); + PCIBus *child_bus =3D pci_find_bus_nr(bus, + dev->config[PCI_SECONDARY_BUS]= ); if (child_bus) { info->has_devices =3D true; - info->devices =3D qmp_query_pci_devices(child_bus, dev->config= [PCI_SECONDARY_BUS]); + info->devices =3D qmp_query_pci_devices(child_bus, + dev->config[PCI_SECONDARY_BUS]= ); } } =20 @@ -2610,8 +2612,9 @@ static void pcibus_dev_print(Monitor *mon, DeviceStat= e *dev, int indent) pci_get_word(d->config + PCI_SUBSYSTEM_ID)); for (i =3D 0; i < PCI_NUM_REGIONS; i++) { r =3D &d->io_regions[i]; - if (!r->size) + if (!r->size) { continue; + } monitor_printf(mon, "%*sbar %d: %s at 0x%"FMT_PCIBUS " [0x%"FMT_PCIBUS"]\n", indent, "", --=20 2.37.3 From nobody Mon May 13 23:06:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1671465217; cv=none; d=zohomail.com; s=zohoarc; b=kGsdWFZrHL7PGXk2dnyY9G3I0TYrpSJJzO75Xas5yAu2wd4fMDSSkQDGAOgLBMw0GqhTGQCFfq0o34d3faOQBQMLVsI9uA2WPCdTzwKIPwyanWLivGk6KrJA1jO/i/gNJrMhWkV8mA4O1TteIAMKT3qA316zKLk2NfZJIpXVfKE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671465217; 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=XekOz1xQDuh/VQxIQM5JfgtIYvE5R1or89l9uEcg3o4=; b=bYcNVxg0fqOL+04x+i4PQwAJtpr6WmbCTdP4z0ByhEwQbnSQulxi0QutFrfq5oRpDHcBI1IH4XGDqmBnqsQuhYyAATRb3oajtxTmlxB+C0jJMUtmkX0lzhtvUA5UKAUhd/4HV/x8QnzU2ZJvQeqecCAQRCAQheMbpLnNUNNz8+Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1671465217225198.5868824425795; Mon, 19 Dec 2022 07:53:37 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p7IQW-0002i1-FH; Mon, 19 Dec 2022 10:51:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7IQN-0002at-3d for qemu-devel@nongnu.org; Mon, 19 Dec 2022 10:51:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7IQI-0000Zq-OP for qemu-devel@nongnu.org; Mon, 19 Dec 2022 10:51:29 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-638-56dp-S0BMwmhsnXqbRvrbg-1; Mon, 19 Dec 2022 10:51:22 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 056B5185A794; Mon, 19 Dec 2022 15:51:22 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.195.91]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 867F71121314; Mon, 19 Dec 2022 15:51:21 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 57C1F21E68BD; Mon, 19 Dec 2022 16:51:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671465086; 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=XekOz1xQDuh/VQxIQM5JfgtIYvE5R1or89l9uEcg3o4=; b=BD4dR4zZ8Sm9z6fZ29DEJSPtH7bB0I+eU7sGSgeSTtu9JM0WosIVUo8qnRJN89B5x0dwqA FJgAfD3o0eYnexOPbuNGLqmmBMYqlbznIo7y9e6dTQ5yWm9Kby9GvxKDWw6o+KgQxghSXv r9ME49vRARNVNpK2Opu2Sk+iPv3dH3Y= X-MC-Unique: 56dp-S0BMwmhsnXqbRvrbg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, "Michael S . Tsirkin" Subject: [PULL 02/13] pci: Move QMP commands to new hw/pci/pci-qmp-cmds.c Date: Mon, 19 Dec 2022 16:51:09 +0100 Message-Id: <20221219155120.2273041-3-armbru@redhat.com> In-Reply-To: <20221219155120.2273041-1-armbru@redhat.com> References: <20221219155120.2273041-1-armbru@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1671465217998100003 Content-Type: text/plain; charset="utf-8" This moves these commands from MAINTAINERS section "QMP" to "PCI". Signed-off-by: Markus Armbruster Reviewed-by: Michael S. Tsirkin Message-Id: <20221201121133.3813857-3-armbru@redhat.com> [Commit message improved] --- hw/pci/pci-internal.h | 20 +++++ hw/pci/pci-qmp-cmds.c | 199 ++++++++++++++++++++++++++++++++++++++++++ hw/pci/pci.c | 186 +-------------------------------------- hw/pci/meson.build | 1 + 4 files changed, 224 insertions(+), 182 deletions(-) create mode 100644 hw/pci/pci-internal.h create mode 100644 hw/pci/pci-qmp-cmds.c diff --git a/hw/pci/pci-internal.h b/hw/pci/pci-internal.h new file mode 100644 index 0000000000..4903a26cbf --- /dev/null +++ b/hw/pci/pci-internal.h @@ -0,0 +1,20 @@ +#ifndef HW_PCI_PCI_INTERNAL_H +#define HW_PCI_PCI_INTERNAL_H + +#include "qemu/queue.h" + +typedef struct { + uint16_t class; + const char *desc; + const char *fw_name; + uint16_t fw_ign_bits; +} pci_class_desc; + +typedef QLIST_HEAD(, PCIHostState) PCIHostStateList; + +extern PCIHostStateList pci_host_bridges; + +const pci_class_desc *get_class_desc(int class); +PCIBus *pci_find_bus_nr(PCIBus *bus, int bus_num); + +#endif diff --git a/hw/pci/pci-qmp-cmds.c b/hw/pci/pci-qmp-cmds.c new file mode 100644 index 0000000000..5d9f4817f5 --- /dev/null +++ b/hw/pci/pci-qmp-cmds.c @@ -0,0 +1,199 @@ +/* + * QMP commands related to PCI + * + * Copyright (c) 2004 Fabrice Bellard + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "hw/pci/pci.h" +#include "hw/pci/pci_bridge.h" +#include "pci-internal.h" +#include "qapi/qapi-commands-pci.h" + +static PciDeviceInfoList *qmp_query_pci_devices(PCIBus *bus, int bus_num); + +static PciMemoryRegionList *qmp_query_pci_regions(const PCIDevice *dev) +{ + PciMemoryRegionList *head =3D NULL, **tail =3D &head; + int i; + + for (i =3D 0; i < PCI_NUM_REGIONS; i++) { + const PCIIORegion *r =3D &dev->io_regions[i]; + PciMemoryRegion *region; + + if (!r->size) { + continue; + } + + region =3D g_malloc0(sizeof(*region)); + + if (r->type & PCI_BASE_ADDRESS_SPACE_IO) { + region->type =3D g_strdup("io"); + } else { + region->type =3D g_strdup("memory"); + region->has_prefetch =3D true; + region->prefetch =3D !!(r->type & PCI_BASE_ADDRESS_MEM_PREFETC= H); + region->has_mem_type_64 =3D true; + region->mem_type_64 =3D !!(r->type & PCI_BASE_ADDRESS_MEM_TYPE= _64); + } + + region->bar =3D i; + region->address =3D r->addr; + region->size =3D r->size; + + QAPI_LIST_APPEND(tail, region); + } + + return head; +} + +static PciBridgeInfo *qmp_query_pci_bridge(PCIDevice *dev, PCIBus *bus, + int bus_num) +{ + PciBridgeInfo *info; + PciMemoryRange *range; + + info =3D g_new0(PciBridgeInfo, 1); + + info->bus =3D g_new0(PciBusInfo, 1); + info->bus->number =3D dev->config[PCI_PRIMARY_BUS]; + info->bus->secondary =3D dev->config[PCI_SECONDARY_BUS]; + info->bus->subordinate =3D dev->config[PCI_SUBORDINATE_BUS]; + + range =3D info->bus->io_range =3D g_new0(PciMemoryRange, 1); + range->base =3D pci_bridge_get_base(dev, PCI_BASE_ADDRESS_SPACE_IO); + range->limit =3D pci_bridge_get_limit(dev, PCI_BASE_ADDRESS_SPACE_IO); + + range =3D info->bus->memory_range =3D g_new0(PciMemoryRange, 1); + range->base =3D pci_bridge_get_base(dev, PCI_BASE_ADDRESS_SPACE_MEMORY= ); + range->limit =3D pci_bridge_get_limit(dev, PCI_BASE_ADDRESS_SPACE_MEMO= RY); + + range =3D info->bus->prefetchable_range =3D g_new0(PciMemoryRange, 1); + range->base =3D pci_bridge_get_base(dev, PCI_BASE_ADDRESS_MEM_PREFETCH= ); + range->limit =3D pci_bridge_get_limit(dev, PCI_BASE_ADDRESS_MEM_PREFET= CH); + + if (dev->config[PCI_SECONDARY_BUS] !=3D 0) { + PCIBus *child_bus =3D pci_find_bus_nr(bus, + dev->config[PCI_SECONDARY_BUS]= ); + if (child_bus) { + info->has_devices =3D true; + info->devices =3D qmp_query_pci_devices(child_bus, + dev->config[PCI_SECONDARY_BUS]= ); + } + } + + return info; +} + +static PciDeviceInfo *qmp_query_pci_device(PCIDevice *dev, PCIBus *bus, + int bus_num) +{ + const pci_class_desc *desc; + PciDeviceInfo *info; + uint8_t type; + int class; + + info =3D g_new0(PciDeviceInfo, 1); + info->bus =3D bus_num; + info->slot =3D PCI_SLOT(dev->devfn); + info->function =3D PCI_FUNC(dev->devfn); + + info->class_info =3D g_new0(PciDeviceClass, 1); + class =3D pci_get_word(dev->config + PCI_CLASS_DEVICE); + info->class_info->q_class =3D class; + desc =3D get_class_desc(class); + if (desc->desc) { + info->class_info->desc =3D g_strdup(desc->desc); + } + + info->id =3D g_new0(PciDeviceId, 1); + info->id->vendor =3D pci_get_word(dev->config + PCI_VENDOR_ID); + info->id->device =3D pci_get_word(dev->config + PCI_DEVICE_ID); + info->regions =3D qmp_query_pci_regions(dev); + info->qdev_id =3D g_strdup(dev->qdev.id ? dev->qdev.id : ""); + + info->irq_pin =3D dev->config[PCI_INTERRUPT_PIN]; + if (dev->config[PCI_INTERRUPT_PIN] !=3D 0) { + info->has_irq =3D true; + info->irq =3D dev->config[PCI_INTERRUPT_LINE]; + } + + type =3D dev->config[PCI_HEADER_TYPE] & ~PCI_HEADER_TYPE_MULTI_FUNCTIO= N; + if (type =3D=3D PCI_HEADER_TYPE_BRIDGE) { + info->pci_bridge =3D qmp_query_pci_bridge(dev, bus, bus_num); + } else if (type =3D=3D PCI_HEADER_TYPE_NORMAL) { + info->id->has_subsystem =3D info->id->has_subsystem_vendor =3D tru= e; + info->id->subsystem =3D pci_get_word(dev->config + PCI_SUBSYSTEM_I= D); + info->id->subsystem_vendor =3D + pci_get_word(dev->config + PCI_SUBSYSTEM_VENDOR_ID); + } else if (type =3D=3D PCI_HEADER_TYPE_CARDBUS) { + info->id->has_subsystem =3D info->id->has_subsystem_vendor =3D tru= e; + info->id->subsystem =3D pci_get_word(dev->config + PCI_CB_SUBSYSTE= M_ID); + info->id->subsystem_vendor =3D + pci_get_word(dev->config + PCI_CB_SUBSYSTEM_VENDOR_ID); + } + + return info; +} + +static PciDeviceInfoList *qmp_query_pci_devices(PCIBus *bus, int bus_num) +{ + PciDeviceInfoList *head =3D NULL, **tail =3D &head; + PCIDevice *dev; + int devfn; + + for (devfn =3D 0; devfn < ARRAY_SIZE(bus->devices); devfn++) { + dev =3D bus->devices[devfn]; + if (dev) { + QAPI_LIST_APPEND(tail, qmp_query_pci_device(dev, bus, bus_num)= ); + } + } + + return head; +} + +static PciInfo *qmp_query_pci_bus(PCIBus *bus, int bus_num) +{ + PciInfo *info =3D NULL; + + bus =3D pci_find_bus_nr(bus, bus_num); + if (bus) { + info =3D g_malloc0(sizeof(*info)); + info->bus =3D bus_num; + info->devices =3D qmp_query_pci_devices(bus, bus_num); + } + + return info; +} + +PciInfoList *qmp_query_pci(Error **errp) +{ + PciInfoList *head =3D NULL, **tail =3D &head; + PCIHostState *host_bridge; + + QLIST_FOREACH(host_bridge, &pci_host_bridges, next) { + QAPI_LIST_APPEND(tail, + qmp_query_pci_bus(host_bridge->bus, + pci_bus_num(host_bridge->bus))); + } + + return head; +} diff --git a/hw/pci/pci.c b/hw/pci/pci.c index d70a567490..7310a82cee 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -47,8 +47,8 @@ #include "hw/hotplug.h" #include "hw/boards.h" #include "qapi/error.h" -#include "qapi/qapi-commands-pci.h" #include "qemu/cutils.h" +#include "pci-internal.h" =20 //#define DEBUG_PCI #ifdef DEBUG_PCI @@ -234,7 +234,6 @@ static const TypeInfo cxl_bus_info =3D { .class_init =3D pcie_bus_class_init, }; =20 -static PCIBus *pci_find_bus_nr(PCIBus *bus, int bus_num); static void pci_update_mappings(PCIDevice *d); static void pci_irq_handler(void *opaque, int irq_num, int level); static void pci_add_option_rom(PCIDevice *pdev, bool is_default_rom, Error= **); @@ -243,7 +242,7 @@ static void pci_del_option_rom(PCIDevice *pdev); static uint16_t pci_default_sub_vendor_id =3D PCI_SUBVENDOR_ID_REDHAT_QUMR= ANET; static uint16_t pci_default_sub_device_id =3D PCI_SUBDEVICE_ID_QEMU; =20 -static QLIST_HEAD(, PCIHostState) pci_host_bridges; +PCIHostStateList pci_host_bridges; =20 int pci_bar(PCIDevice *d, int reg) { @@ -1662,13 +1661,6 @@ int pci_swizzle_map_irq_fn(PCIDevice *pci_dev, int p= in) /***********************************************************/ /* monitor info on PCI */ =20 -typedef struct { - uint16_t class; - const char *desc; - const char *fw_name; - uint16_t fw_ign_bits; -} pci_class_desc; - static const pci_class_desc pci_class_descriptions[] =3D { { 0x0001, "VGA controller", "display"}, @@ -1776,7 +1768,7 @@ void pci_for_each_device(PCIBus *bus, int bus_num, } } =20 -static const pci_class_desc *get_class_desc(int class) +const pci_class_desc *get_class_desc(int class) { const pci_class_desc *desc; =20 @@ -1788,176 +1780,6 @@ static const pci_class_desc *get_class_desc(int cla= ss) return desc; } =20 -static PciDeviceInfoList *qmp_query_pci_devices(PCIBus *bus, int bus_num); - -static PciMemoryRegionList *qmp_query_pci_regions(const PCIDevice *dev) -{ - PciMemoryRegionList *head =3D NULL, **tail =3D &head; - int i; - - for (i =3D 0; i < PCI_NUM_REGIONS; i++) { - const PCIIORegion *r =3D &dev->io_regions[i]; - PciMemoryRegion *region; - - if (!r->size) { - continue; - } - - region =3D g_malloc0(sizeof(*region)); - - if (r->type & PCI_BASE_ADDRESS_SPACE_IO) { - region->type =3D g_strdup("io"); - } else { - region->type =3D g_strdup("memory"); - region->has_prefetch =3D true; - region->prefetch =3D !!(r->type & PCI_BASE_ADDRESS_MEM_PREFETC= H); - region->has_mem_type_64 =3D true; - region->mem_type_64 =3D !!(r->type & PCI_BASE_ADDRESS_MEM_TYPE= _64); - } - - region->bar =3D i; - region->address =3D r->addr; - region->size =3D r->size; - - QAPI_LIST_APPEND(tail, region); - } - - return head; -} - -static PciBridgeInfo *qmp_query_pci_bridge(PCIDevice *dev, PCIBus *bus, - int bus_num) -{ - PciBridgeInfo *info; - PciMemoryRange *range; - - info =3D g_new0(PciBridgeInfo, 1); - - info->bus =3D g_new0(PciBusInfo, 1); - info->bus->number =3D dev->config[PCI_PRIMARY_BUS]; - info->bus->secondary =3D dev->config[PCI_SECONDARY_BUS]; - info->bus->subordinate =3D dev->config[PCI_SUBORDINATE_BUS]; - - range =3D info->bus->io_range =3D g_new0(PciMemoryRange, 1); - range->base =3D pci_bridge_get_base(dev, PCI_BASE_ADDRESS_SPACE_IO); - range->limit =3D pci_bridge_get_limit(dev, PCI_BASE_ADDRESS_SPACE_IO); - - range =3D info->bus->memory_range =3D g_new0(PciMemoryRange, 1); - range->base =3D pci_bridge_get_base(dev, PCI_BASE_ADDRESS_SPACE_MEMORY= ); - range->limit =3D pci_bridge_get_limit(dev, PCI_BASE_ADDRESS_SPACE_MEMO= RY); - - range =3D info->bus->prefetchable_range =3D g_new0(PciMemoryRange, 1); - range->base =3D pci_bridge_get_base(dev, PCI_BASE_ADDRESS_MEM_PREFETCH= ); - range->limit =3D pci_bridge_get_limit(dev, PCI_BASE_ADDRESS_MEM_PREFET= CH); - - if (dev->config[PCI_SECONDARY_BUS] !=3D 0) { - PCIBus *child_bus =3D pci_find_bus_nr(bus, - dev->config[PCI_SECONDARY_BUS]= ); - if (child_bus) { - info->has_devices =3D true; - info->devices =3D qmp_query_pci_devices(child_bus, - dev->config[PCI_SECONDARY_BUS]= ); - } - } - - return info; -} - -static PciDeviceInfo *qmp_query_pci_device(PCIDevice *dev, PCIBus *bus, - int bus_num) -{ - const pci_class_desc *desc; - PciDeviceInfo *info; - uint8_t type; - int class; - - info =3D g_new0(PciDeviceInfo, 1); - info->bus =3D bus_num; - info->slot =3D PCI_SLOT(dev->devfn); - info->function =3D PCI_FUNC(dev->devfn); - - info->class_info =3D g_new0(PciDeviceClass, 1); - class =3D pci_get_word(dev->config + PCI_CLASS_DEVICE); - info->class_info->q_class =3D class; - desc =3D get_class_desc(class); - if (desc->desc) { - info->class_info->desc =3D g_strdup(desc->desc); - } - - info->id =3D g_new0(PciDeviceId, 1); - info->id->vendor =3D pci_get_word(dev->config + PCI_VENDOR_ID); - info->id->device =3D pci_get_word(dev->config + PCI_DEVICE_ID); - info->regions =3D qmp_query_pci_regions(dev); - info->qdev_id =3D g_strdup(dev->qdev.id ? dev->qdev.id : ""); - - info->irq_pin =3D dev->config[PCI_INTERRUPT_PIN]; - if (dev->config[PCI_INTERRUPT_PIN] !=3D 0) { - info->has_irq =3D true; - info->irq =3D dev->config[PCI_INTERRUPT_LINE]; - } - - type =3D dev->config[PCI_HEADER_TYPE] & ~PCI_HEADER_TYPE_MULTI_FUNCTIO= N; - if (type =3D=3D PCI_HEADER_TYPE_BRIDGE) { - info->pci_bridge =3D qmp_query_pci_bridge(dev, bus, bus_num); - } else if (type =3D=3D PCI_HEADER_TYPE_NORMAL) { - info->id->has_subsystem =3D info->id->has_subsystem_vendor =3D tru= e; - info->id->subsystem =3D pci_get_word(dev->config + PCI_SUBSYSTEM_I= D); - info->id->subsystem_vendor =3D - pci_get_word(dev->config + PCI_SUBSYSTEM_VENDOR_ID); - } else if (type =3D=3D PCI_HEADER_TYPE_CARDBUS) { - info->id->has_subsystem =3D info->id->has_subsystem_vendor =3D tru= e; - info->id->subsystem =3D pci_get_word(dev->config + PCI_CB_SUBSYSTE= M_ID); - info->id->subsystem_vendor =3D - pci_get_word(dev->config + PCI_CB_SUBSYSTEM_VENDOR_ID); - } - - return info; -} - -static PciDeviceInfoList *qmp_query_pci_devices(PCIBus *bus, int bus_num) -{ - PciDeviceInfoList *head =3D NULL, **tail =3D &head; - PCIDevice *dev; - int devfn; - - for (devfn =3D 0; devfn < ARRAY_SIZE(bus->devices); devfn++) { - dev =3D bus->devices[devfn]; - if (dev) { - QAPI_LIST_APPEND(tail, qmp_query_pci_device(dev, bus, bus_num)= ); - } - } - - return head; -} - -static PciInfo *qmp_query_pci_bus(PCIBus *bus, int bus_num) -{ - PciInfo *info =3D NULL; - - bus =3D pci_find_bus_nr(bus, bus_num); - if (bus) { - info =3D g_malloc0(sizeof(*info)); - info->bus =3D bus_num; - info->devices =3D qmp_query_pci_devices(bus, bus_num); - } - - return info; -} - -PciInfoList *qmp_query_pci(Error **errp) -{ - PciInfoList *head =3D NULL, **tail =3D &head; - PCIHostState *host_bridge; - - QLIST_FOREACH(host_bridge, &pci_host_bridges, next) { - QAPI_LIST_APPEND(tail, - qmp_query_pci_bus(host_bridge->bus, - pci_bus_num(host_bridge->bus))); - } - - return head; -} - /* Initialize a PCI NIC. */ PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus, const char *default_model, @@ -2106,7 +1928,7 @@ static bool pci_root_bus_in_range(PCIBus *bus, int bu= s_num) return false; } =20 -static PCIBus *pci_find_bus_nr(PCIBus *bus, int bus_num) +PCIBus *pci_find_bus_nr(PCIBus *bus, int bus_num) { PCIBus *sec; =20 diff --git a/hw/pci/meson.build b/hw/pci/meson.build index 5aff7ed1c6..40721f1514 100644 --- a/hw/pci/meson.build +++ b/hw/pci/meson.build @@ -5,6 +5,7 @@ pci_ss.add(files( 'pci.c', 'pci_bridge.c', 'pci_host.c', + 'pci-qmp-cmds.c', 'pcie_sriov.c', 'shpc.c', 'slotid_cap.c' --=20 2.37.3 From nobody Mon May 13 23:06:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1671465178; cv=none; d=zohomail.com; s=zohoarc; b=hLEhdrweoa2PjkCkDrJq+7zrRuKXcH/n/Xad6yax7KtINT7oxxU3PPW4U8TRwqebblPLczI37Ex2k2+HezJdz3NccS2fM9z7V/XcbFs2Lpjxb/6jX87fM2HNxU95t5mcnIxXcowBkm8xrPliVtBIAalL5W2NuoDUa3G4p4U96bA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671465178; 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=8QWj8Yw6xYq9Io6CIfPqaaYjRq3+5lIh2D2ERmlx5n0=; b=U0p8izNUjp9JYcLaNNUMVvbhOzdojTfV6XQ/OYsxvSHKSwtTR7t8rGR0zq3ezfRaaUzHCErCKyzuSaEnVBgYjhraOh9RbK8fmXa1rVYPKpiO74zycu4+v5fil/3wrua4dwO84BTSdwNW4uRM+9oBcbW1dRoi+/bUxpJXzropfxA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1671465178725249.20569853923053; Mon, 19 Dec 2022 07:52:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p7IQZ-0002sr-Re; Mon, 19 Dec 2022 10:51:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7IQN-0002de-C4 for qemu-devel@nongnu.org; Mon, 19 Dec 2022 10:51:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7IQK-0000aR-Qk for qemu-devel@nongnu.org; Mon, 19 Dec 2022 10:51:31 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-460-Fqz2F9X1NWu65BN54pRpEQ-1; Mon, 19 Dec 2022 10:51:25 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D669F3813F4F; Mon, 19 Dec 2022 15:51:21 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.195.91]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 89B211121315; Mon, 19 Dec 2022 15:51:21 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5A8FE21E6808; Mon, 19 Dec 2022 16:51:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671465088; 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=8QWj8Yw6xYq9Io6CIfPqaaYjRq3+5lIh2D2ERmlx5n0=; b=K0ecm/AnHrysScD6WC/jZeHy7HKllte0QuGZp8hSVLQQtAk8acFfBIZZSAGBWzWhfiJvtu 04J45wH7oeglEZlA1pXz79Ex9/+x8i41+bxlGimD/CCVMEf4oQmApLuJeBQKbt7wkQdrbJ wk71PutTcdFXoDeMo328UoYi6FIFPRI= X-MC-Unique: Fqz2F9X1NWu65BN54pRpEQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, "Michael S . Tsirkin" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Dr . David Alan Gilbert" Subject: [PULL 03/13] pci: Move HMP commands from monitor/ to new hw/pci/pci-hmp-cmds.c Date: Mon, 19 Dec 2022 16:51:10 +0100 Message-Id: <20221219155120.2273041-4-armbru@redhat.com> In-Reply-To: <20221219155120.2273041-1-armbru@redhat.com> References: <20221219155120.2273041-1-armbru@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1671465179772100003 This moves these commands from MAINTAINERS section "Human Monitor (HMP)" to "PCI". Signed-off-by: Markus Armbruster Reviewed-by: Michael S. Tsirkin Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Dr. David Alan Gilbert Message-Id: <20221201121133.3813857-4-armbru@redhat.com> --- hw/pci/pci-hmp-cmds.c | 126 ++++++++++++++++++++++++++++++++++++++++++ monitor/hmp-cmds.c | 107 ----------------------------------- hw/pci/meson.build | 1 + 3 files changed, 127 insertions(+), 107 deletions(-) create mode 100644 hw/pci/pci-hmp-cmds.c diff --git a/hw/pci/pci-hmp-cmds.c b/hw/pci/pci-hmp-cmds.c new file mode 100644 index 0000000000..e5e07ea72c --- /dev/null +++ b/hw/pci/pci-hmp-cmds.c @@ -0,0 +1,126 @@ +/* + * HMP commands related to PCI + * + * Copyright IBM, Corp. 2011 + * + * Authors: + * Anthony Liguori + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + * Contributions after 2012-01-13 are licensed under the terms of the + * GNU GPL, version 2 or (at your option) any later version. + */ + +#include "qemu/osdep.h" +#include "monitor/hmp.h" +#include "monitor/monitor.h" +#include "qapi/error.h" +#include "qapi/qapi-commands-pci.h" + +static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev) +{ + PciMemoryRegionList *region; + + monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus); + monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n", + dev->slot, dev->function); + monitor_printf(mon, " "); + + if (dev->class_info->desc) { + monitor_puts(mon, dev->class_info->desc); + } else { + monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class); + } + + monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n", + dev->id->vendor, dev->id->device); + if (dev->id->has_subsystem_vendor && dev->id->has_subsystem) { + monitor_printf(mon, " PCI subsystem %04" PRIx64 ":%04" PRIx64= "\n", + dev->id->subsystem_vendor, dev->id->subsystem); + } + + if (dev->has_irq) { + monitor_printf(mon, " IRQ %" PRId64 ", pin %c\n", + dev->irq, (char)('A' + dev->irq_pin - 1)); + } + + if (dev->pci_bridge) { + monitor_printf(mon, " BUS %" PRId64 ".\n", + dev->pci_bridge->bus->number); + monitor_printf(mon, " secondary bus %" PRId64 ".\n", + dev->pci_bridge->bus->secondary); + monitor_printf(mon, " subordinate bus %" PRId64 ".\n", + dev->pci_bridge->bus->subordinate); + + monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]= \n", + dev->pci_bridge->bus->io_range->base, + dev->pci_bridge->bus->io_range->limit); + + monitor_printf(mon, + " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\= n", + dev->pci_bridge->bus->memory_range->base, + dev->pci_bridge->bus->memory_range->limit); + + monitor_printf(mon, " prefetchable memory range " + "[0x%08"PRIx64", 0x%08"PRIx64"]\n", + dev->pci_bridge->bus->prefetchable_range->base, + dev->pci_bridge->bus->prefetchable_range->limit); + } + + for (region =3D dev->regions; region; region =3D region->next) { + uint64_t addr, size; + + addr =3D region->value->address; + size =3D region->value->size; + + monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar); + + if (!strcmp(region->value->type, "io")) { + monitor_printf(mon, "I/O at 0x%04" PRIx64 + " [0x%04" PRIx64 "].\n", + addr, addr + size - 1); + } else { + monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64 + " [0x%08" PRIx64 "].\n", + region->value->mem_type_64 ? 64 : 32, + region->value->prefetch ? " prefetchable" : "", + addr, addr + size - 1); + } + } + + monitor_printf(mon, " id \"%s\"\n", dev->qdev_id); + + if (dev->pci_bridge) { + if (dev->pci_bridge->has_devices) { + PciDeviceInfoList *cdev; + for (cdev =3D dev->pci_bridge->devices; cdev; cdev =3D cdev->n= ext) { + hmp_info_pci_device(mon, cdev->value); + } + } + } +} + +void hmp_info_pci(Monitor *mon, const QDict *qdict) +{ + PciInfoList *info_list, *info; + Error *err =3D NULL; + + info_list =3D qmp_query_pci(&err); + if (err) { + monitor_printf(mon, "PCI devices not supported\n"); + error_free(err); + return; + } + + for (info =3D info_list; info; info =3D info->next) { + PciDeviceInfoList *dev; + + for (dev =3D info->value->devices; dev; dev =3D dev->next) { + hmp_info_pci_device(mon, dev->value); + } + } + + qapi_free_PciInfoList(info_list); +} diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index b847b26041..ed78a87ddd 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -37,7 +37,6 @@ #include "qapi/qapi-commands-migration.h" #include "qapi/qapi-commands-misc.h" #include "qapi/qapi-commands-net.h" -#include "qapi/qapi-commands-pci.h" #include "qapi/qapi-commands-rocker.h" #include "qapi/qapi-commands-run-state.h" #include "qapi/qapi-commands-stats.h" @@ -698,89 +697,6 @@ void hmp_info_balloon(Monitor *mon, const QDict *qdict) qapi_free_BalloonInfo(info); } =20 -static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev) -{ - PciMemoryRegionList *region; - - monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus); - monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n", - dev->slot, dev->function); - monitor_printf(mon, " "); - - if (dev->class_info->desc) { - monitor_puts(mon, dev->class_info->desc); - } else { - monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class); - } - - monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n", - dev->id->vendor, dev->id->device); - if (dev->id->has_subsystem_vendor && dev->id->has_subsystem) { - monitor_printf(mon, " PCI subsystem %04" PRIx64 ":%04" PRIx64= "\n", - dev->id->subsystem_vendor, dev->id->subsystem); - } - - if (dev->has_irq) { - monitor_printf(mon, " IRQ %" PRId64 ", pin %c\n", - dev->irq, (char)('A' + dev->irq_pin - 1)); - } - - if (dev->pci_bridge) { - monitor_printf(mon, " BUS %" PRId64 ".\n", - dev->pci_bridge->bus->number); - monitor_printf(mon, " secondary bus %" PRId64 ".\n", - dev->pci_bridge->bus->secondary); - monitor_printf(mon, " subordinate bus %" PRId64 ".\n", - dev->pci_bridge->bus->subordinate); - - monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]= \n", - dev->pci_bridge->bus->io_range->base, - dev->pci_bridge->bus->io_range->limit); - - monitor_printf(mon, - " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\= n", - dev->pci_bridge->bus->memory_range->base, - dev->pci_bridge->bus->memory_range->limit); - - monitor_printf(mon, " prefetchable memory range " - "[0x%08"PRIx64", 0x%08"PRIx64"]\n", - dev->pci_bridge->bus->prefetchable_range->base, - dev->pci_bridge->bus->prefetchable_range->limit); - } - - for (region =3D dev->regions; region; region =3D region->next) { - uint64_t addr, size; - - addr =3D region->value->address; - size =3D region->value->size; - - monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar); - - if (!strcmp(region->value->type, "io")) { - monitor_printf(mon, "I/O at 0x%04" PRIx64 - " [0x%04" PRIx64 "].\n", - addr, addr + size - 1); - } else { - monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64 - " [0x%08" PRIx64 "].\n", - region->value->mem_type_64 ? 64 : 32, - region->value->prefetch ? " prefetchable" : "", - addr, addr + size - 1); - } - } - - monitor_printf(mon, " id \"%s\"\n", dev->qdev_id); - - if (dev->pci_bridge) { - if (dev->pci_bridge->has_devices) { - PciDeviceInfoList *cdev; - for (cdev =3D dev->pci_bridge->devices; cdev; cdev =3D cdev->n= ext) { - hmp_info_pci_device(mon, cdev->value); - } - } - } -} - static int hmp_info_pic_foreach(Object *obj, void *opaque) { InterruptStatsProvider *intc; @@ -807,29 +723,6 @@ void hmp_info_pic(Monitor *mon, const QDict *qdict) hmp_info_pic_foreach, mon); } =20 -void hmp_info_pci(Monitor *mon, const QDict *qdict) -{ - PciInfoList *info_list, *info; - Error *err =3D NULL; - - info_list =3D qmp_query_pci(&err); - if (err) { - monitor_printf(mon, "PCI devices not supported\n"); - error_free(err); - return; - } - - for (info =3D info_list; info; info =3D info->next) { - PciDeviceInfoList *dev; - - for (dev =3D info->value->devices; dev; dev =3D dev->next) { - hmp_info_pci_device(mon, dev->value); - } - } - - qapi_free_PciInfoList(info_list); -} - void hmp_info_tpm(Monitor *mon, const QDict *qdict) { #ifdef CONFIG_TPM diff --git a/hw/pci/meson.build b/hw/pci/meson.build index 40721f1514..e42a133f3a 100644 --- a/hw/pci/meson.build +++ b/hw/pci/meson.build @@ -20,3 +20,4 @@ softmmu_ss.add_all(when: 'CONFIG_PCI', if_true: pci_ss) =20 softmmu_ss.add(when: 'CONFIG_PCI', if_false: files('pci-stub.c')) softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('pci-stub.c')) +softmmu_ss.add(files('pci-hmp-cmds.c')) --=20 2.37.3 From nobody Mon May 13 23:06:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1671465123; cv=none; d=zohomail.com; s=zohoarc; b=W76nyO85B9w9rzsUcaf8/VYQ4rqoCZwXvf/6NR1q6CK6+9f5a8xX2/0+prL8vlQZfm3q9Lg7o0S6VZbs2XqOjx7wYwJAGq26huKSbDjy1dJ5+AGMhTtdf1POxi/sqiZcXUz/JFyzxTzDMU/bIuthC0Gw0hoM5fWghvSdQsI8bso= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671465123; 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=roCA9HAITSHUFmVtB6z547lVWvQ3kSGIyYnp+aMqhIM=; b=IlbmoPXpHnFnmSioKv4j/MOBaLJLkFhCYomNMy93b+B09byAaJ6MueMYNEo5kS4tQfcyXcw0K5eG6VA6uq5bSPB701lKsUMK4MLIAw6FvX2Xl/oyu9C8jqrb8+ynBMhdAPXGAe0lU3P2zXmEKX1OV1nbTLskaoesDLOtXPRelR0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1671465123797591.1335391670428; Mon, 19 Dec 2022 07:52:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p7IQQ-0002eF-Le; Mon, 19 Dec 2022 10:51:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7IQJ-0002Xa-4R for qemu-devel@nongnu.org; Mon, 19 Dec 2022 10:51:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7IQH-0000Zf-Hu for qemu-devel@nongnu.org; Mon, 19 Dec 2022 10:51:26 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-596-M2_KWj_sMT-6FTYGt3F9Xg-1; Mon, 19 Dec 2022 10:51:22 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B91EB2932493; Mon, 19 Dec 2022 15:51:21 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.195.91]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 867D72026D4B; Mon, 19 Dec 2022 15:51:21 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5DB2E21E66CC; Mon, 19 Dec 2022 16:51:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671465084; 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=roCA9HAITSHUFmVtB6z547lVWvQ3kSGIyYnp+aMqhIM=; b=MiLPwJlpCd0IW4ra60YtJdHjL7Bg2eAe11cVizFA0c17is93deqySva+0wi+cllNi7FEi3 V2b8lXIN6qXrvBVnDxjVe1+U8eBFKdD6IPZucj1aMvEx3kk8RizGhi7bDfcSHwRWARB3pF yjBZGW5MOZMK3VpGhZL+xWKOb6BkAVk= X-MC-Unique: M2_KWj_sMT-6FTYGt3F9Xg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, "Michael S . Tsirkin" , "Dr . David Alan Gilbert" Subject: [PULL 04/13] pci: Make query-pci stub consistent with the real one Date: Mon, 19 Dec 2022 16:51:11 +0100 Message-Id: <20221219155120.2273041-5-armbru@redhat.com> In-Reply-To: <20221219155120.2273041-1-armbru@redhat.com> References: <20221219155120.2273041-1-armbru@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1671465125518100003 Content-Type: text/plain; charset="utf-8" QMP query-pci and HMP info pci can behave differently when there are no PCI devices. They can report nothing, like this: qemu-system-aarch64 -S -M spitz -display none -monitor stdio QEMU 7.1.91 monitor - type 'help' for more information (qemu) info pci Or they can fail, like this: qemu-system-microblaze -M petalogix-s3adsp1800 -display none -monitor s= tdio QEMU 7.1.91 monitor - type 'help' for more information (qemu) info pci PCI devices not supported They fail when none of the target's machines supports PCI, i.e. when we're using qmp_query_pci() from hw/pci/pci-stub.c. The error is not useful, and reporting nothing makes sense, so do that in pci-stub.c, too. Now qmp_query_pci() can't fail anymore. Drop the dead error handling from hmp_info_pci(). Signed-off-by: Markus Armbruster Reviewed-by: Michael S. Tsirkin Reviewed-by: Dr. David Alan Gilbert Message-Id: <20221201121133.3813857-5-armbru@redhat.com> --- hw/pci/pci-hmp-cmds.c | 8 +------- hw/pci/pci-stub.c | 3 --- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/hw/pci/pci-hmp-cmds.c b/hw/pci/pci-hmp-cmds.c index e5e07ea72c..f8d67bbb09 100644 --- a/hw/pci/pci-hmp-cmds.c +++ b/hw/pci/pci-hmp-cmds.c @@ -105,14 +105,8 @@ static void hmp_info_pci_device(Monitor *mon, const Pc= iDeviceInfo *dev) void hmp_info_pci(Monitor *mon, const QDict *qdict) { PciInfoList *info_list, *info; - Error *err =3D NULL; =20 - info_list =3D qmp_query_pci(&err); - if (err) { - monitor_printf(mon, "PCI devices not supported\n"); - error_free(err); - return; - } + info_list =3D qmp_query_pci(&error_abort); =20 for (info =3D info_list; info; info =3D info->next) { PciDeviceInfoList *dev; diff --git a/hw/pci/pci-stub.c b/hw/pci/pci-stub.c index 3a027c42e4..f29ecc999e 100644 --- a/hw/pci/pci-stub.c +++ b/hw/pci/pci-stub.c @@ -21,9 +21,7 @@ #include "qemu/osdep.h" #include "sysemu/sysemu.h" #include "monitor/monitor.h" -#include "qapi/error.h" #include "qapi/qapi-commands-pci.h" -#include "qapi/qmp/qerror.h" #include "hw/pci/pci.h" #include "hw/pci/msi.h" #include "hw/pci/msix.h" @@ -33,7 +31,6 @@ bool pci_available; =20 PciInfoList *qmp_query_pci(Error **errp) { - error_setg(errp, QERR_UNSUPPORTED); return NULL; } =20 --=20 2.37.3 From nobody Mon May 13 23:06:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1671465110; cv=none; d=zohomail.com; s=zohoarc; b=amb2w9WpLq++M7yqiAGTRylfFQTpXUtKqZ0jUUOPHAR0q0lgB+IvCEGQUfLsYXYFy2R1kYXlEVnhNhQ29R8AQW1PFACZVlNhZ9buTHt3+7iKu0G/jkfCbMvVQttlMQ3Z1nSRyVxNevTtze6xcWNOuvMpqqmLiuWjTk+6Z/Gxu88= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671465110; 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=P5B3X7HdMqjBsciArRVyj+6wZin8F5Pe0ky9uO3x24k=; b=D8w+860Z60SGuo+e1S84Gvz7s7ULijtr9JkqfOxZKSK7rUQ6t/bFmt6NljOiI7W0Zqnu5h/x2NwnnYO3H+UDfY56MNwVbEGSiqGLCsQ0BmLkCvL13aeZCnGmVwKK0O58pbGwxZL5+f2BTlClryuv8n+eIFld/KFGkuu12pSvYhM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1671465110470609.4746260885303; Mon, 19 Dec 2022 07:51:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p7IQS-0002fx-61; Mon, 19 Dec 2022 10:51:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7IQK-0002Xs-F2 for qemu-devel@nongnu.org; Mon, 19 Dec 2022 10:51:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7IQH-0000Zm-RM for qemu-devel@nongnu.org; Mon, 19 Dec 2022 10:51:28 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-642-FyLxK9uKMb2MRr0SOSjjVQ-1; Mon, 19 Dec 2022 10:51:23 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2F0AC1C09C87; Mon, 19 Dec 2022 15:51:23 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.195.91]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0366D2026D4B; Mon, 19 Dec 2022 15:51:23 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5F3DD21E668F; Mon, 19 Dec 2022 16:51:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671465085; 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=P5B3X7HdMqjBsciArRVyj+6wZin8F5Pe0ky9uO3x24k=; b=Yn2DVGSYzY1KaJkukwyz26evXmgDTWg73MB1DqXShxHNq/RhiPfIMfJTc6+7ZA5ioMl3yT Z1vJlAbnhCam1MErzCL+Ywgq7tq6XStlmwwSTM1IQmzn3P1yWWOGuK7irRo8812ZrczqUT aJTRNZitvFeZa2AdiNNcsS0xb653Z5s= X-MC-Unique: FyLxK9uKMb2MRr0SOSjjVQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, "Michael S . Tsirkin" Subject: [PULL 05/13] pci: Build hw/pci/pci-hmp-cmds.c only when CONFIG_PCI Date: Mon, 19 Dec 2022 16:51:12 +0100 Message-Id: <20221219155120.2273041-6-armbru@redhat.com> In-Reply-To: <20221219155120.2273041-1-armbru@redhat.com> References: <20221219155120.2273041-1-armbru@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1671465111442100005 Content-Type: text/plain; charset="utf-8" We compile pci-hmp-cmds.c always, but pci-qmp-cmds.c only when CONFIG_PCI. hw/pci/pci-stub.c keeps the linker happy when !CONFIG_PCI. Build pci-hmp-cmds.c that way, too. Signed-off-by: Markus Armbruster Reviewed-by: Michael S. Tsirkin Message-Id: <20221201121133.3813857-6-armbru@redhat.com> --- hw/pci/pci-stub.c | 5 +++++ hw/pci/meson.build | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/hw/pci/pci-stub.c b/hw/pci/pci-stub.c index f29ecc999e..01d20a2f67 100644 --- a/hw/pci/pci-stub.c +++ b/hw/pci/pci-stub.c @@ -21,6 +21,7 @@ #include "qemu/osdep.h" #include "sysemu/sysemu.h" #include "monitor/monitor.h" +#include "monitor/hmp.h" #include "qapi/qapi-commands-pci.h" #include "hw/pci/pci.h" #include "hw/pci/msi.h" @@ -34,6 +35,10 @@ PciInfoList *qmp_query_pci(Error **errp) return NULL; } =20 +void hmp_info_pci(Monitor *mon, const QDict *qdict) +{ +} + void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict) { monitor_printf(mon, "PCI devices not supported\n"); diff --git a/hw/pci/meson.build b/hw/pci/meson.build index e42a133f3a..4fcd888b27 100644 --- a/hw/pci/meson.build +++ b/hw/pci/meson.build @@ -5,6 +5,7 @@ pci_ss.add(files( 'pci.c', 'pci_bridge.c', 'pci_host.c', + 'pci-hmp-cmds.c', 'pci-qmp-cmds.c', 'pcie_sriov.c', 'shpc.c', @@ -20,4 +21,3 @@ softmmu_ss.add_all(when: 'CONFIG_PCI', if_true: pci_ss) =20 softmmu_ss.add(when: 'CONFIG_PCI', if_false: files('pci-stub.c')) softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('pci-stub.c')) -softmmu_ss.add(files('pci-hmp-cmds.c')) --=20 2.37.3 From nobody Mon May 13 23:06:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1671465108; cv=none; d=zohomail.com; s=zohoarc; b=geBXlOQ3OUi6ppRbwy0meD+CKDwXsSkA+IAJmEOc1sOEebVZEmAX3QXfWvo4zPF3RSO+NxtZJ6MgL96sXJhH/spe/zaF6ZV9WzDoq/2DDVHEA2oLOP1ZiqFYZYqhqY97vuHxrhs79DNtiCe1hAwIXkHV4nITromSkK6mONKJ6hE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671465108; 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=j+ieZgRXa2kZ80x0xTEVSf56xf6CIO4Nn5SBjeeTlXg=; b=HIhLxh5afh3iUBJldGF9kEGBAZ+i15ko0UuoUYXdgexPK8YdhlkbRKsJ8AqMAXswPbR13xPChCp5iRF2rGQH4qFHmPkBYNkdlXqPTYlm9p2dw1Zy4ZgsKgV1agqLUcdq1kASrouq8DDSDt9Ry4si4zhEknQpcWBpzw/6TND953U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1671465108691202.61424145864464; Mon, 19 Dec 2022 07:51:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p7IQS-0002gB-8M; Mon, 19 Dec 2022 10:51:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7IQN-0002ar-3C for qemu-devel@nongnu.org; Mon, 19 Dec 2022 10:51:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7IQK-0000aF-5y for qemu-devel@nongnu.org; Mon, 19 Dec 2022 10:51:29 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-662-nKbkmfMZMN6_A6nRC8jReg-1; Mon, 19 Dec 2022 10:51:23 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 32AE9101157D; Mon, 19 Dec 2022 15:51:23 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.195.91]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0538A40C1073; Mon, 19 Dec 2022 15:51:23 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 6161121E668B; Mon, 19 Dec 2022 16:51:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671465087; 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=j+ieZgRXa2kZ80x0xTEVSf56xf6CIO4Nn5SBjeeTlXg=; b=g+zaZ7g3K6H+PwMMkcVD/RoeB+BAmc9R+3PID0yV9/p54fz2q3vqrNCYXyLtclB9LheLV3 M4FBVCw3p9H0ChtUlPUkuKA8sxVAbC+Unsqq+x3oU8eNEYpeQ9JVaG5VlbTKMqV+0jyGEw orX2+vobvNVG1NqZxQmxecdp56VmFWs= X-MC-Unique: nKbkmfMZMN6_A6nRC8jReg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, "Michael S . Tsirkin" Subject: [PULL 06/13] pci: Deduplicate get_class_desc() Date: Mon, 19 Dec 2022 16:51:13 +0100 Message-Id: <20221219155120.2273041-7-armbru@redhat.com> In-Reply-To: <20221219155120.2273041-1-armbru@redhat.com> References: <20221219155120.2273041-1-armbru@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1671465109443100003 Content-Type: text/plain; charset="utf-8" pcibus_dev_print() contains a copy of get_class_desc(). Call the function instead. Signed-off-by: Markus Armbruster Reviewed-by: Michael S. Tsirkin Message-Id: <20221201121133.3813857-7-armbru@redhat.com> --- hw/pci/pci.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 7310a82cee..41718aaf60 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2409,15 +2409,12 @@ uint8_t pci_find_capability(PCIDevice *pdev, uint8_= t cap_id) static void pcibus_dev_print(Monitor *mon, DeviceState *dev, int indent) { PCIDevice *d =3D (PCIDevice *)dev; - const pci_class_desc *desc; + int class =3D pci_get_word(d->config + PCI_CLASS_DEVICE); + const pci_class_desc *desc =3D get_class_desc(class); char ctxt[64]; PCIIORegion *r; - int i, class; + int i; =20 - class =3D pci_get_word(d->config + PCI_CLASS_DEVICE); - desc =3D pci_class_descriptions; - while (desc->desc && class !=3D desc->class) - desc++; if (desc->desc) { snprintf(ctxt, sizeof(ctxt), "%s", desc->desc); } else { --=20 2.37.3 From nobody Mon May 13 23:06:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1671465272; cv=none; d=zohomail.com; s=zohoarc; b=aghxvRvnW5B7m8cRd7c3zD7GBaWdWdkDoOpji9O67Ipx5yZc/KC12fatlQwXMlbVAnOaf9mU07D3oLzPKU87UatjmFtt+B75lr31VmqtSEOqFgpUKJ7X28OqcWwEnnH4sRuF92xi5Hbep/qDOGq4zAaG3mjMe046WsmXkSXd4z0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671465272; 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=KI+XelsAbW3wEvGOdgtSVHdOKWGkzGCaUEKs93PzZZ4=; b=fOKT4nhHSrLgzeAWv+n3DXq2bsZSlGIb1Gidgm2JytDVrqZfBjMPOSJvejQyTJbm61e7/E4DapJqskxPhruFdUEH8pely5de44S8AmjL+VOzOFZhVjRqdi+BQubBOGx/BlqFmRHeLiI5MKMVEpk8lwGx6HTCaNTGI3aV0bHjA9k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1671465272246620.1074728146265; Mon, 19 Dec 2022 07:54:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p7IQX-0002jG-61; Mon, 19 Dec 2022 10:51:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7IQO-0002eK-US for qemu-devel@nongnu.org; Mon, 19 Dec 2022 10:51:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7IQM-0000b0-EL for qemu-devel@nongnu.org; Mon, 19 Dec 2022 10:51:32 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-339--hXKKfYbPTyUhm1eGfKTHQ-1; Mon, 19 Dec 2022 10:51:24 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 511AC857A85; Mon, 19 Dec 2022 15:51:23 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.195.91]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0534E2026D76; Mon, 19 Dec 2022 15:51:23 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 63BFF21E6692; Mon, 19 Dec 2022 16:51:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671465089; 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=KI+XelsAbW3wEvGOdgtSVHdOKWGkzGCaUEKs93PzZZ4=; b=fDYtOmdjrQBpULwl8SraTEqS9vjMurly8NS12IXJ1Ofgx0ANoHhPRK/8HeubWa4bcJxFIS kDWS6Obs7NHuvB/AO+C8d7b2bgLHEDtZtuZRJ1Hiw1P+OsvsYHsPycE8qRw+H8d/y3WWBr XlJYWfwkv4IlDI8+vP2Jh2eOj4H6r1o= X-MC-Unique: -hXKKfYbPTyUhm1eGfKTHQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, "Michael S . Tsirkin" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 07/13] pci: Move pcibus_dev_print() to pci-hmp-cmds.c Date: Mon, 19 Dec 2022 16:51:14 +0100 Message-Id: <20221219155120.2273041-8-armbru@redhat.com> In-Reply-To: <20221219155120.2273041-1-armbru@redhat.com> References: <20221219155120.2273041-1-armbru@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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=170.10.129.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1671465274284100003 This method is for HMP command "info qtree". Signed-off-by: Markus Armbruster Reviewed-by: Michael S. Tsirkin Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20221201121133.3813857-8-armbru@redhat.com> --- hw/pci/pci-internal.h | 1 + hw/pci/pci-hmp-cmds.c | 38 ++++++++++++++++++++++++++++++++++++++ hw/pci/pci.c | 38 -------------------------------------- 3 files changed, 39 insertions(+), 38 deletions(-) diff --git a/hw/pci/pci-internal.h b/hw/pci/pci-internal.h index 4903a26cbf..3199615e50 100644 --- a/hw/pci/pci-internal.h +++ b/hw/pci/pci-internal.h @@ -16,5 +16,6 @@ extern PCIHostStateList pci_host_bridges; =20 const pci_class_desc *get_class_desc(int class); PCIBus *pci_find_bus_nr(PCIBus *bus, int bus_num); +void pcibus_dev_print(Monitor *mon, DeviceState *dev, int indent); =20 #endif diff --git a/hw/pci/pci-hmp-cmds.c b/hw/pci/pci-hmp-cmds.c index f8d67bbb09..adbc6021f6 100644 --- a/hw/pci/pci-hmp-cmds.c +++ b/hw/pci/pci-hmp-cmds.c @@ -14,8 +14,10 @@ */ =20 #include "qemu/osdep.h" +#include "hw/pci/pci.h" #include "monitor/hmp.h" #include "monitor/monitor.h" +#include "pci-internal.h" #include "qapi/error.h" #include "qapi/qapi-commands-pci.h" =20 @@ -118,3 +120,39 @@ void hmp_info_pci(Monitor *mon, const QDict *qdict) =20 qapi_free_PciInfoList(info_list); } + +void pcibus_dev_print(Monitor *mon, DeviceState *dev, int indent) +{ + PCIDevice *d =3D (PCIDevice *)dev; + int class =3D pci_get_word(d->config + PCI_CLASS_DEVICE); + const pci_class_desc *desc =3D get_class_desc(class); + char ctxt[64]; + PCIIORegion *r; + int i; + + if (desc->desc) { + snprintf(ctxt, sizeof(ctxt), "%s", desc->desc); + } else { + snprintf(ctxt, sizeof(ctxt), "Class %04x", class); + } + + monitor_printf(mon, "%*sclass %s, addr %02x:%02x.%x, " + "pci id %04x:%04x (sub %04x:%04x)\n", + indent, "", ctxt, pci_dev_bus_num(d), + PCI_SLOT(d->devfn), PCI_FUNC(d->devfn), + pci_get_word(d->config + PCI_VENDOR_ID), + pci_get_word(d->config + PCI_DEVICE_ID), + pci_get_word(d->config + PCI_SUBSYSTEM_VENDOR_ID), + pci_get_word(d->config + PCI_SUBSYSTEM_ID)); + for (i =3D 0; i < PCI_NUM_REGIONS; i++) { + r =3D &d->io_regions[i]; + if (!r->size) { + continue; + } + monitor_printf(mon, "%*sbar %d: %s at 0x%"FMT_PCIBUS + " [0x%"FMT_PCIBUS"]\n", + indent, "", + i, r->type & PCI_BASE_ADDRESS_SPACE_IO ? "i/o" : "m= em", + r->addr, r->addr + r->size - 1); + } +} diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 41718aaf60..9598b4b546 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -34,7 +34,6 @@ #include "hw/qdev-properties-system.h" #include "migration/qemu-file-types.h" #include "migration/vmstate.h" -#include "monitor/monitor.h" #include "net/net.h" #include "sysemu/numa.h" #include "sysemu/sysemu.h" @@ -59,7 +58,6 @@ =20 bool pci_available =3D true; =20 -static void pcibus_dev_print(Monitor *mon, DeviceState *dev, int indent); static char *pcibus_get_dev_path(DeviceState *dev); static char *pcibus_get_fw_dev_path(DeviceState *dev); static void pcibus_reset(BusState *qbus); @@ -2406,42 +2404,6 @@ uint8_t pci_find_capability(PCIDevice *pdev, uint8_t= cap_id) return pci_find_capability_list(pdev, cap_id, NULL); } =20 -static void pcibus_dev_print(Monitor *mon, DeviceState *dev, int indent) -{ - PCIDevice *d =3D (PCIDevice *)dev; - int class =3D pci_get_word(d->config + PCI_CLASS_DEVICE); - const pci_class_desc *desc =3D get_class_desc(class); - char ctxt[64]; - PCIIORegion *r; - int i; - - if (desc->desc) { - snprintf(ctxt, sizeof(ctxt), "%s", desc->desc); - } else { - snprintf(ctxt, sizeof(ctxt), "Class %04x", class); - } - - monitor_printf(mon, "%*sclass %s, addr %02x:%02x.%x, " - "pci id %04x:%04x (sub %04x:%04x)\n", - indent, "", ctxt, pci_dev_bus_num(d), - PCI_SLOT(d->devfn), PCI_FUNC(d->devfn), - pci_get_word(d->config + PCI_VENDOR_ID), - pci_get_word(d->config + PCI_DEVICE_ID), - pci_get_word(d->config + PCI_SUBSYSTEM_VENDOR_ID), - pci_get_word(d->config + PCI_SUBSYSTEM_ID)); - for (i =3D 0; i < PCI_NUM_REGIONS; i++) { - r =3D &d->io_regions[i]; - if (!r->size) { - continue; - } - monitor_printf(mon, "%*sbar %d: %s at 0x%"FMT_PCIBUS - " [0x%"FMT_PCIBUS"]\n", - indent, "", - i, r->type & PCI_BASE_ADDRESS_SPACE_IO ? "i/o" : "m= em", - r->addr, r->addr + r->size - 1); - } -} - static char *pci_dev_fw_name(DeviceState *dev, char *buf, int len) { PCIDevice *d =3D (PCIDevice *)dev; --=20 2.37.3 From nobody Mon May 13 23:06:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1671465163; cv=none; d=zohomail.com; s=zohoarc; b=j+JoDrQw6d3PjgA5h3gqTtPBDbKTCNmRDDylHV3x6oULhbrSfBNrwlHaXBwXjgcUPEHf9H0/7P1Ud93EqClDg5lc2DbApc0G3V30aI9VWuauXpkj+LHDauKJQOwvv1RB0w0C36JK1ruDHNYzCMSu4WdXIiQOEp5eco3aIpcmnZc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671465163; 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=zGb8EsvCLDZKFHBORG6IvQ8r89fYsv8L+hwGeHibn5s=; b=lRXAkOQB/RtE+rgzhUsh76TkBts4PRQJMtW5uiD+iCDxCkoF4JChvi7oJH58+mmrVZnaD0l37OtaJ9pjzej1QNCJhqrOR/utoo2sWjmYWn229YX6Z3Zd/hCkSGScUYZ3qfucdX0KQdbKsX1j76TX87wmuDcd7nwIWLGx53FqkzY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16714651630550.28604284537800595; Mon, 19 Dec 2022 07:52:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p7IQY-0002la-5R; Mon, 19 Dec 2022 10:51:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7IQQ-0002g3-NW for qemu-devel@nongnu.org; Mon, 19 Dec 2022 10:51:36 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7IQO-0000ba-NW for qemu-devel@nongnu.org; Mon, 19 Dec 2022 10:51:33 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-327-W8wWch6uN0eXxhZi0O6WeQ-1; Mon, 19 Dec 2022 10:51:23 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2EBC385A588; Mon, 19 Dec 2022 15:51:23 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.195.91]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 036CC1121314; Mon, 19 Dec 2022 15:51:23 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 65DE121E6699; Mon, 19 Dec 2022 16:51:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671465091; 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=zGb8EsvCLDZKFHBORG6IvQ8r89fYsv8L+hwGeHibn5s=; b=VGIumZLC7LLwwJB2jY0bKK9bFhOBFx/HdO6YjfwrTlhqZroiPdajBr06dGAceKnD9Se+NU GT9e8qxGyXFuZIBG6sBzGRdmFE1LOaKuNpf5CvORggqh+GEAoxItZ0PjQI/Nn0UgxIgMOz heC+9waPuXFLymBs8Dkac1zZfQepPWA= X-MC-Unique: W8wWch6uN0eXxhZi0O6WeQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, "Michael S . Tsirkin" Subject: [PULL 08/13] pci: Fix silent truncation of pcie_aer_inject_error argument Date: Mon, 19 Dec 2022 16:51:15 +0100 Message-Id: <20221219155120.2273041-9-armbru@redhat.com> In-Reply-To: <20221219155120.2273041-1-armbru@redhat.com> References: <20221219155120.2273041-1-armbru@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=170.10.129.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1671465163722100001 Content-Type: text/plain; charset="utf-8" PCI AER error status is 32 bit. The HMP command supports both symbolic and numeric error status: anything that isn't a known symbolic value is parsed as number with strtol(). Issues: * Empty argument yields value zero. * Range errors from strtol() are ignored, value is UINT32_MAX. * Values not representable in uint32_t are silently truncated. Fix to reject such input by switching to strtoui(). Signed-off-by: Markus Armbruster Reviewed-by: Michael S. Tsirkin Message-Id: <20221201121133.3813857-9-armbru@redhat.com> --- hw/pci/pcie_aer.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hw/pci/pcie_aer.c b/hw/pci/pcie_aer.c index eff62f3945..58d20816d6 100644 --- a/hw/pci/pcie_aer.c +++ b/hw/pci/pcie_aer.c @@ -30,6 +30,7 @@ #include "hw/pci/pci_bus.h" #include "hw/pci/pcie_regs.h" #include "qapi/error.h" +#include "qemu/cutils.h" =20 //#define DEBUG_PCIE #ifdef DEBUG_PCIE @@ -963,6 +964,7 @@ static int do_pcie_aer_inject_error(Monitor *mon, const char *id =3D qdict_get_str(qdict, "id"); const char *error_name; uint32_t error_status; + unsigned int num; bool correctable; PCIDevice *dev; PCIEAERErr err; @@ -983,14 +985,13 @@ static int do_pcie_aer_inject_error(Monitor *mon, =20 error_name =3D qdict_get_str(qdict, "error_status"); if (pcie_aer_parse_error_string(error_name, &error_status, &correctabl= e)) { - char *e =3D NULL; - error_status =3D strtoul(error_name, &e, 0); - correctable =3D qdict_get_try_bool(qdict, "correctable", false); - if (!e || *e !=3D '\0') { + if (qemu_strtoui(error_name, NULL, 0, &num) < 0) { monitor_printf(mon, "invalid error status value. \"%s\"", error_name); return -EINVAL; } + error_status =3D num; + correctable =3D qdict_get_try_bool(qdict, "correctable", false); } err.status =3D error_status; err.source_id =3D pci_requester_id(dev); --=20 2.37.3 From nobody Mon May 13 23:06:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1671465203; cv=none; d=zohomail.com; s=zohoarc; b=iXdz94XrMXZh5pkQwJ/5iQJy4Hq5SkTcUhX7Wb0fipEqr+PYs4a/hSJ5wHAtVKezRz0YNAQSoGvW3dJ5v5IxQPpRcemepEf3ZmyrYY+msJe+Le6exiRsxvnU1AyTFkLSAnnXasdt9Mwezdbb9Op6BXreOQijXJlyeaPuyUGs2QE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671465203; 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=NEpqcgEZm1Q3ybKNgu3ZAH3ik/GEog6/OpJB7LP51IY=; b=GvEHxTcM274fSRazFkXhqeE1NRl/jpJup1CZEQfKgLWnO6xysIuymZw3IeCutaisvFIMVLRfcZ+aBiRwrjJyn6JpN2vyyfEaTMFjBehVShZOMUiCKO2Lfuk+QpCigQxFkWkhxGX1hinz/YqXB7TVCa+9vjzNFauGuZd2VFwIH6U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1671465203651788.3362969514463; Mon, 19 Dec 2022 07:53:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p7IQa-0002uk-JI; Mon, 19 Dec 2022 10:51:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7IQN-0002cs-Aq for qemu-devel@nongnu.org; Mon, 19 Dec 2022 10:51:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7IQK-0000aM-LI for qemu-devel@nongnu.org; Mon, 19 Dec 2022 10:51:31 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-41-bMnTCbo7OKmWzhhPARLn3Q-1; Mon, 19 Dec 2022 10:51:24 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5483F87A383; Mon, 19 Dec 2022 15:51:23 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.195.91]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 08BC840C2005; Mon, 19 Dec 2022 15:51:23 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 6815C21E66AB; Mon, 19 Dec 2022 16:51:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671465087; 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=NEpqcgEZm1Q3ybKNgu3ZAH3ik/GEog6/OpJB7LP51IY=; b=CqvmJIy2RJsOP2mZPg43m75mCwh7aOUNdTsvQQzNCTt1+/36UZ1IXphr65uJSwZ2ZTVw7v 2Gu4CnYiq3zYe5XIS6enNZ4+lumMFyyiq90zvbtLr3iydIKKfHvYZDt8QtIn4uiCgN65cK +FJSjJfiBbTpzUA+s3LxOklDNcHCgLQ= X-MC-Unique: bMnTCbo7OKmWzhhPARLn3Q-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, "Michael S . Tsirkin" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 09/13] pci: Move HMP command from hw/pci/pcie_aer.c to pci-hmp-cmds.c Date: Mon, 19 Dec 2022 16:51:16 +0100 Message-Id: <20221219155120.2273041-10-armbru@redhat.com> In-Reply-To: <20221219155120.2273041-1-armbru@redhat.com> References: <20221219155120.2273041-1-armbru@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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=170.10.129.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1671465203876100001 Signed-off-by: Markus Armbruster Reviewed-by: Michael S. Tsirkin Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20221201121133.3813857-10-armbru@redhat.com> --- hw/pci/pci-internal.h | 4 ++ include/monitor/hmp.h | 1 + include/sysemu/sysemu.h | 3 -- hw/pci/pci-hmp-cmds.c | 104 ++++++++++++++++++++++++++++++++++++ hw/pci/pci-stub.c | 1 - hw/pci/pcie_aer.c | 114 ++-------------------------------------- 6 files changed, 113 insertions(+), 114 deletions(-) diff --git a/hw/pci/pci-internal.h b/hw/pci/pci-internal.h index 3199615e50..2ea356bdf5 100644 --- a/hw/pci/pci-internal.h +++ b/hw/pci/pci-internal.h @@ -18,4 +18,8 @@ const pci_class_desc *get_class_desc(int class); PCIBus *pci_find_bus_nr(PCIBus *bus, int bus_num); void pcibus_dev_print(Monitor *mon, DeviceState *dev, int indent); =20 +int pcie_aer_parse_error_string(const char *error_name, + uint32_t *status, bool *correctable); +int pcie_aer_inject_error(PCIDevice *dev, const PCIEAERErr *err); + #endif diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index dfbc0c9a2f..27f86399f7 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -143,5 +143,6 @@ void hmp_info_vcpu_dirty_limit(Monitor *mon, const QDic= t *qdict); void hmp_human_readable_text_helper(Monitor *mon, HumanReadableText *(*qmp_handler)(Erro= r **)); void hmp_info_stats(Monitor *mon, const QDict *qdict); +void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict); =20 #endif diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 6a7a31e64d..25be2a692e 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -61,9 +61,6 @@ extern int nb_option_roms; extern const char *prom_envs[MAX_PROM_ENVS]; extern unsigned int nb_prom_envs; =20 -/* pcie aer error injection */ -void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict); - /* serial ports */ =20 /* Return the Chardev for serial port i, or NULL if none */ diff --git a/hw/pci/pci-hmp-cmds.c b/hw/pci/pci-hmp-cmds.c index adbc6021f6..a7c96f156c 100644 --- a/hw/pci/pci-hmp-cmds.c +++ b/hw/pci/pci-hmp-cmds.c @@ -19,7 +19,9 @@ #include "monitor/monitor.h" #include "pci-internal.h" #include "qapi/error.h" +#include "qapi/qmp/qdict.h" #include "qapi/qapi-commands-pci.h" +#include "qemu/cutils.h" =20 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev) { @@ -156,3 +158,105 @@ void pcibus_dev_print(Monitor *mon, DeviceState *dev,= int indent) r->addr, r->addr + r->size - 1); } } + +typedef struct PCIEErrorDetails { + const char *id; + const char *root_bus; + int bus; + int devfn; +} PCIEErrorDetails; + +/* + * Inject an error described by @qdict. + * On success, set @details to show where error was sent. + * Return negative errno if injection failed and a message was emitted. + */ +static int do_pcie_aer_inject_error(Monitor *mon, + const QDict *qdict, + PCIEErrorDetails *details) +{ + const char *id =3D qdict_get_str(qdict, "id"); + const char *error_name; + uint32_t error_status; + unsigned int num; + bool correctable; + PCIDevice *dev; + PCIEAERErr err; + int ret; + + ret =3D pci_qdev_find_device(id, &dev); + if (ret < 0) { + monitor_printf(mon, + "id or pci device path is invalid or device not " + "found. %s\n", id); + return ret; + } + if (!pci_is_express(dev)) { + monitor_printf(mon, "the device doesn't support pci express. %s\n", + id); + return -ENOSYS; + } + + error_name =3D qdict_get_str(qdict, "error_status"); + if (pcie_aer_parse_error_string(error_name, &error_status, &correctabl= e)) { + if (qemu_strtoui(error_name, NULL, 0, &num) < 0) { + monitor_printf(mon, "invalid error status value. \"%s\"", + error_name); + return -EINVAL; + } + error_status =3D num; + correctable =3D qdict_get_try_bool(qdict, "correctable", false); + } + err.status =3D error_status; + err.source_id =3D pci_requester_id(dev); + + err.flags =3D 0; + if (correctable) { + err.flags |=3D PCIE_AER_ERR_IS_CORRECTABLE; + } + if (qdict_get_try_bool(qdict, "advisory_non_fatal", false)) { + err.flags |=3D PCIE_AER_ERR_MAYBE_ADVISORY; + } + if (qdict_haskey(qdict, "header0")) { + err.flags |=3D PCIE_AER_ERR_HEADER_VALID; + } + if (qdict_haskey(qdict, "prefix0")) { + err.flags |=3D PCIE_AER_ERR_TLP_PREFIX_PRESENT; + } + + err.header[0] =3D qdict_get_try_int(qdict, "header0", 0); + err.header[1] =3D qdict_get_try_int(qdict, "header1", 0); + err.header[2] =3D qdict_get_try_int(qdict, "header2", 0); + err.header[3] =3D qdict_get_try_int(qdict, "header3", 0); + + err.prefix[0] =3D qdict_get_try_int(qdict, "prefix0", 0); + err.prefix[1] =3D qdict_get_try_int(qdict, "prefix1", 0); + err.prefix[2] =3D qdict_get_try_int(qdict, "prefix2", 0); + err.prefix[3] =3D qdict_get_try_int(qdict, "prefix3", 0); + + ret =3D pcie_aer_inject_error(dev, &err); + if (ret < 0) { + monitor_printf(mon, "failed to inject error: %s\n", + strerror(-ret)); + return ret; + } + details->id =3D id; + details->root_bus =3D pci_root_bus_path(dev); + details->bus =3D pci_dev_bus_num(dev); + details->devfn =3D dev->devfn; + + return 0; +} + +void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict) +{ + PCIEErrorDetails data; + + if (do_pcie_aer_inject_error(mon, qdict, &data) < 0) { + return; + } + + monitor_printf(mon, "OK id: %s root bus: %s, bus: %x devfn: %x.%x\n", + data.id, data.root_bus, data.bus, + PCI_SLOT(data.devfn), PCI_FUNC(data.devfn)); +} diff --git a/hw/pci/pci-stub.c b/hw/pci/pci-stub.c index 01d20a2f67..f0508682d2 100644 --- a/hw/pci/pci-stub.c +++ b/hw/pci/pci-stub.c @@ -19,7 +19,6 @@ */ =20 #include "qemu/osdep.h" -#include "sysemu/sysemu.h" #include "monitor/monitor.h" #include "monitor/hmp.h" #include "qapi/qapi-commands-pci.h" diff --git a/hw/pci/pcie_aer.c b/hw/pci/pcie_aer.c index 58d20816d6..9a19be44ae 100644 --- a/hw/pci/pcie_aer.c +++ b/hw/pci/pcie_aer.c @@ -19,18 +19,14 @@ */ =20 #include "qemu/osdep.h" -#include "sysemu/sysemu.h" -#include "qapi/qmp/qdict.h" #include "migration/vmstate.h" -#include "monitor/monitor.h" #include "hw/pci/pci_bridge.h" #include "hw/pci/pcie.h" #include "hw/pci/msix.h" #include "hw/pci/msi.h" #include "hw/pci/pci_bus.h" #include "hw/pci/pcie_regs.h" -#include "qapi/error.h" -#include "qemu/cutils.h" +#include "pci-internal.h" =20 //#define DEBUG_PCIE #ifdef DEBUG_PCIE @@ -45,13 +41,6 @@ #define PCI_ERR_SRC_COR_OFFS 0 #define PCI_ERR_SRC_UNCOR_OFFS 2 =20 -typedef struct PCIEErrorDetails { - const char *id; - const char *root_bus; - int bus; - int devfn; -} PCIEErrorDetails; - /* From 6.2.7 Error Listing and Rules. Table 6-2, 6-3 and 6-4 */ static uint32_t pcie_aer_uncor_default_severity(uint32_t status) { @@ -632,7 +621,7 @@ static bool pcie_aer_inject_uncor_error(PCIEAERInject *= inj, bool is_fatal) * Figure 6-2: Flowchart Showing Sequence of Device Error Signaling and Lo= gging * Operations */ -static int pcie_aer_inject_error(PCIDevice *dev, const PCIEAERErr *err) +int pcie_aer_inject_error(PCIDevice *dev, const PCIEAERErr *err) { uint8_t *aer_cap =3D NULL; uint16_t devctl =3D 0; @@ -934,8 +923,8 @@ static const struct PCIEAERErrorName pcie_aer_error_lis= t[] =3D { }, }; =20 -static int pcie_aer_parse_error_string(const char *error_name, - uint32_t *status, bool *correctable) +int pcie_aer_parse_error_string(const char *error_name, + uint32_t *status, bool *correctable) { int i; =20 @@ -951,98 +940,3 @@ static int pcie_aer_parse_error_string(const char *err= or_name, } return -EINVAL; } - -/* - * Inject an error described by @qdict. - * On success, set @details to show where error was sent. - * Return negative errno if injection failed and a message was emitted. - */ -static int do_pcie_aer_inject_error(Monitor *mon, - const QDict *qdict, - PCIEErrorDetails *details) -{ - const char *id =3D qdict_get_str(qdict, "id"); - const char *error_name; - uint32_t error_status; - unsigned int num; - bool correctable; - PCIDevice *dev; - PCIEAERErr err; - int ret; - - ret =3D pci_qdev_find_device(id, &dev); - if (ret < 0) { - monitor_printf(mon, - "id or pci device path is invalid or device not " - "found. %s\n", id); - return ret; - } - if (!pci_is_express(dev)) { - monitor_printf(mon, "the device doesn't support pci express. %s\n", - id); - return -ENOSYS; - } - - error_name =3D qdict_get_str(qdict, "error_status"); - if (pcie_aer_parse_error_string(error_name, &error_status, &correctabl= e)) { - if (qemu_strtoui(error_name, NULL, 0, &num) < 0) { - monitor_printf(mon, "invalid error status value. \"%s\"", - error_name); - return -EINVAL; - } - error_status =3D num; - correctable =3D qdict_get_try_bool(qdict, "correctable", false); - } - err.status =3D error_status; - err.source_id =3D pci_requester_id(dev); - - err.flags =3D 0; - if (correctable) { - err.flags |=3D PCIE_AER_ERR_IS_CORRECTABLE; - } - if (qdict_get_try_bool(qdict, "advisory_non_fatal", false)) { - err.flags |=3D PCIE_AER_ERR_MAYBE_ADVISORY; - } - if (qdict_haskey(qdict, "header0")) { - err.flags |=3D PCIE_AER_ERR_HEADER_VALID; - } - if (qdict_haskey(qdict, "prefix0")) { - err.flags |=3D PCIE_AER_ERR_TLP_PREFIX_PRESENT; - } - - err.header[0] =3D qdict_get_try_int(qdict, "header0", 0); - err.header[1] =3D qdict_get_try_int(qdict, "header1", 0); - err.header[2] =3D qdict_get_try_int(qdict, "header2", 0); - err.header[3] =3D qdict_get_try_int(qdict, "header3", 0); - - err.prefix[0] =3D qdict_get_try_int(qdict, "prefix0", 0); - err.prefix[1] =3D qdict_get_try_int(qdict, "prefix1", 0); - err.prefix[2] =3D qdict_get_try_int(qdict, "prefix2", 0); - err.prefix[3] =3D qdict_get_try_int(qdict, "prefix3", 0); - - ret =3D pcie_aer_inject_error(dev, &err); - if (ret < 0) { - monitor_printf(mon, "failed to inject error: %s\n", - strerror(-ret)); - return ret; - } - details->id =3D id; - details->root_bus =3D pci_root_bus_path(dev); - details->bus =3D pci_dev_bus_num(dev); - details->devfn =3D dev->devfn; - - return 0; -} - -void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict) -{ - PCIEErrorDetails data; - - if (do_pcie_aer_inject_error(mon, qdict, &data) < 0) { - return; - } - - monitor_printf(mon, "OK id: %s root bus: %s, bus: %x devfn: %x.%x\n", - data.id, data.root_bus, data.bus, - PCI_SLOT(data.devfn), PCI_FUNC(data.devfn)); -} --=20 2.37.3 From nobody Mon May 13 23:06:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1671465151; cv=none; d=zohomail.com; s=zohoarc; b=AzyPz+hK7FbHC8Y+KfzoT8d3VNT9U/6hmqi3AScVlc2nx8Mrzn/DBYfxNEuRGvg17yEYHAGCpptDSiCVFSFGFhk7GPHAO7aw/8+8NkMUkSGoS2WAYBaTItpq9hOM1pmayT8IUn1Ltc3KerrtFN7TW78dzRozIzYc1uNYVsNxKkg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671465151; 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=uS90jy8ft6i1uGrq+YPqKALWmyX7WwZtYcMdDpscchA=; b=fi1lZvYJZ7NriNCkpksnqGZKvVnsVCFH/MQuDETolktdO6BUF/pjA7fCbUut1bc6DCwtoGp4T7T1wM6m82g/xPUbVFFxPOflRRDUEzC8t7curDw9WtgBtkwrG+fTmcy26B6L6/P0OcPDpZh8sAap0JTmNkeRlA2GRlVCIMXRM7c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1671465151434517.7012932129954; Mon, 19 Dec 2022 07:52:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p7IQZ-0002oM-5e; Mon, 19 Dec 2022 10:51:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7IQO-0002eJ-UY for qemu-devel@nongnu.org; Mon, 19 Dec 2022 10:51:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7IQL-0000aa-0c for qemu-devel@nongnu.org; Mon, 19 Dec 2022 10:51:31 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-327-kkYIWYSJPPm6YA4XW3Csvw-1; Mon, 19 Dec 2022 10:51:23 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 346673813F53; Mon, 19 Dec 2022 15:51:23 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.195.91]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 057032166B26; Mon, 19 Dec 2022 15:51:23 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 6A22621E65C2; Mon, 19 Dec 2022 16:51:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671465088; 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=uS90jy8ft6i1uGrq+YPqKALWmyX7WwZtYcMdDpscchA=; b=Ygv64lsVfWYhGqw7JCr/KjV3/WOqQ2dCYWaXskWIcJyg4+IROOOvCuMuIBavmXQTuza1Z1 v7Tf20Mq1ZgpTrJ31GX5dM0u53T1t9w/EeCutMnMvvtetM0uLTDefcWydkrKp3aITE+79K EG1+FDSnaqaW5Uobem9DoxnNZlhHIbA= X-MC-Unique: kkYIWYSJPPm6YA4XW3Csvw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, "Michael S . Tsirkin" , "Dr . David Alan Gilbert" Subject: [PULL 10/13] pci: Inline do_pcie_aer_inject_error() into its only caller Date: Mon, 19 Dec 2022 16:51:17 +0100 Message-Id: <20221219155120.2273041-11-armbru@redhat.com> In-Reply-To: <20221219155120.2273041-1-armbru@redhat.com> References: <20221219155120.2273041-1-armbru@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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=170.10.129.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1671465151646100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Reviewed-by: Michael S. Tsirkin Reviewed-by: Dr. David Alan Gilbert Message-Id: <20221201121133.3813857-11-armbru@redhat.com> --- hw/pci/pci-hmp-cmds.c | 41 ++++++----------------------------------- 1 file changed, 6 insertions(+), 35 deletions(-) diff --git a/hw/pci/pci-hmp-cmds.c b/hw/pci/pci-hmp-cmds.c index a7c96f156c..52c86323e5 100644 --- a/hw/pci/pci-hmp-cmds.c +++ b/hw/pci/pci-hmp-cmds.c @@ -159,21 +159,7 @@ void pcibus_dev_print(Monitor *mon, DeviceState *dev, = int indent) } } =20 -typedef struct PCIEErrorDetails { - const char *id; - const char *root_bus; - int bus; - int devfn; -} PCIEErrorDetails; - -/* - * Inject an error described by @qdict. - * On success, set @details to show where error was sent. - * Return negative errno if injection failed and a message was emitted. - */ -static int do_pcie_aer_inject_error(Monitor *mon, - const QDict *qdict, - PCIEErrorDetails *details) +void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict) { const char *id =3D qdict_get_str(qdict, "id"); const char *error_name; @@ -189,12 +175,12 @@ static int do_pcie_aer_inject_error(Monitor *mon, monitor_printf(mon, "id or pci device path is invalid or device not " "found. %s\n", id); - return ret; + return; } if (!pci_is_express(dev)) { monitor_printf(mon, "the device doesn't support pci express. %s\n", id); - return -ENOSYS; + return; } =20 error_name =3D qdict_get_str(qdict, "error_status"); @@ -202,7 +188,7 @@ static int do_pcie_aer_inject_error(Monitor *mon, if (qemu_strtoui(error_name, NULL, 0, &num) < 0) { monitor_printf(mon, "invalid error status value. \"%s\"", error_name); - return -EINVAL; + return; } error_status =3D num; correctable =3D qdict_get_try_bool(qdict, "correctable", false); @@ -238,25 +224,10 @@ static int do_pcie_aer_inject_error(Monitor *mon, if (ret < 0) { monitor_printf(mon, "failed to inject error: %s\n", strerror(-ret)); - return ret; - } - details->id =3D id; - details->root_bus =3D pci_root_bus_path(dev); - details->bus =3D pci_dev_bus_num(dev); - details->devfn =3D dev->devfn; - - return 0; -} - -void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict) -{ - PCIEErrorDetails data; - - if (do_pcie_aer_inject_error(mon, qdict, &data) < 0) { return; } =20 monitor_printf(mon, "OK id: %s root bus: %s, bus: %x devfn: %x.%x\n", - data.id, data.root_bus, data.bus, - PCI_SLOT(data.devfn), PCI_FUNC(data.devfn)); + id, pci_root_bus_path(dev), pci_dev_bus_num(dev), + PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn)); } --=20 2.37.3 From nobody Mon May 13 23:06:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1671465191; cv=none; d=zohomail.com; s=zohoarc; b=DlyY1llO5zrkT9tOFY0gijMHhlhjprYo+SkhB0j8al7Tb2u6VLPWxgNFxS6/NLVqRSbHjNZzVEUP/zqFFLcx2P1TYObGCRPSambSLi29kcY6xqQwzninuRMXnTwpw/K4dFhQYuky0SjfH87uZwcYZlUtqQjWGTSRe7f/MAlVJxY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671465191; 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=GHNKr3NXLHilA68zUnAww/MjADXAGpnep9DTuvX3Xpo=; b=eyIoPiHChHeqZ7rXI+wzDmdlssebNSLPsXzHRxBeFg7WctBHn4PhdjNmQypMMFm+mNXmMHLrARalYKfuqUhVIIdaeSw6h/0vsMo5dWtu/Hsczp2uS2TFOgOuTMyWkEduSUQIrii/MbNO2E/gLnpr1D3W/jR1EIh5VNTHgdwOlL0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1671465191123132.93110523305177; Mon, 19 Dec 2022 07:53:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p7IQY-0002m7-Bl; Mon, 19 Dec 2022 10:51:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7IQN-0002as-3E for qemu-devel@nongnu.org; Mon, 19 Dec 2022 10:51:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7IQJ-0000aA-MH for qemu-devel@nongnu.org; Mon, 19 Dec 2022 10:51:29 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-608-_dYuXw7HMdyv4KfacQBsjQ-1; Mon, 19 Dec 2022 10:51:23 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 33EB8293248B; Mon, 19 Dec 2022 15:51:23 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.195.91]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 053DD40C2004; Mon, 19 Dec 2022 15:51:23 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 6C76921E65CB; Mon, 19 Dec 2022 16:51:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671465086; 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=GHNKr3NXLHilA68zUnAww/MjADXAGpnep9DTuvX3Xpo=; b=BMa1JFd36o1fdArFEpCJ9J0bhRxu/twFeMM62s8OXO8zBcVerOIfZ4leVArJu4gz0E18JO 1AzDu7y9U5Fhfv/XZmuuqZzoJZSOPooz9AJIeJxgTLkcXn8ZgpQ7ZP2M/zzJV56y+NwP7c xlRBgnxJugAYpCMM0e0bjcDJX2IGPsA= X-MC-Unique: _dYuXw7HMdyv4KfacQBsjQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, "Michael S . Tsirkin" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 11/13] pci: Rename hmp_pcie_aer_inject_error()'s local variable @err Date: Mon, 19 Dec 2022 16:51:18 +0100 Message-Id: <20221219155120.2273041-12-armbru@redhat.com> In-Reply-To: <20221219155120.2273041-1-armbru@redhat.com> References: <20221219155120.2273041-1-armbru@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1671465191805100003 I'd like to use @err for an Error *err. Rename PCIEAERErr err to aer_err. Signed-off-by: Markus Armbruster Reviewed-by: Michael S. Tsirkin Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20221201121133.3813857-12-armbru@redhat.com> --- hw/pci/pci-hmp-cmds.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/hw/pci/pci-hmp-cmds.c b/hw/pci/pci-hmp-cmds.c index 52c86323e5..6f0bb95ee4 100644 --- a/hw/pci/pci-hmp-cmds.c +++ b/hw/pci/pci-hmp-cmds.c @@ -167,7 +167,7 @@ void hmp_pcie_aer_inject_error(Monitor *mon, const QDic= t *qdict) unsigned int num; bool correctable; PCIDevice *dev; - PCIEAERErr err; + PCIEAERErr aer_err; int ret; =20 ret =3D pci_qdev_find_device(id, &dev); @@ -193,34 +193,34 @@ void hmp_pcie_aer_inject_error(Monitor *mon, const QD= ict *qdict) error_status =3D num; correctable =3D qdict_get_try_bool(qdict, "correctable", false); } - err.status =3D error_status; - err.source_id =3D pci_requester_id(dev); + aer_err.status =3D error_status; + aer_err.source_id =3D pci_requester_id(dev); =20 - err.flags =3D 0; + aer_err.flags =3D 0; if (correctable) { - err.flags |=3D PCIE_AER_ERR_IS_CORRECTABLE; + aer_err.flags |=3D PCIE_AER_ERR_IS_CORRECTABLE; } if (qdict_get_try_bool(qdict, "advisory_non_fatal", false)) { - err.flags |=3D PCIE_AER_ERR_MAYBE_ADVISORY; + aer_err.flags |=3D PCIE_AER_ERR_MAYBE_ADVISORY; } if (qdict_haskey(qdict, "header0")) { - err.flags |=3D PCIE_AER_ERR_HEADER_VALID; + aer_err.flags |=3D PCIE_AER_ERR_HEADER_VALID; } if (qdict_haskey(qdict, "prefix0")) { - err.flags |=3D PCIE_AER_ERR_TLP_PREFIX_PRESENT; + aer_err.flags |=3D PCIE_AER_ERR_TLP_PREFIX_PRESENT; } =20 - err.header[0] =3D qdict_get_try_int(qdict, "header0", 0); - err.header[1] =3D qdict_get_try_int(qdict, "header1", 0); - err.header[2] =3D qdict_get_try_int(qdict, "header2", 0); - err.header[3] =3D qdict_get_try_int(qdict, "header3", 0); + aer_err.header[0] =3D qdict_get_try_int(qdict, "header0", 0); + aer_err.header[1] =3D qdict_get_try_int(qdict, "header1", 0); + aer_err.header[2] =3D qdict_get_try_int(qdict, "header2", 0); + aer_err.header[3] =3D qdict_get_try_int(qdict, "header3", 0); =20 - err.prefix[0] =3D qdict_get_try_int(qdict, "prefix0", 0); - err.prefix[1] =3D qdict_get_try_int(qdict, "prefix1", 0); - err.prefix[2] =3D qdict_get_try_int(qdict, "prefix2", 0); - err.prefix[3] =3D qdict_get_try_int(qdict, "prefix3", 0); + aer_err.prefix[0] =3D qdict_get_try_int(qdict, "prefix0", 0); + aer_err.prefix[1] =3D qdict_get_try_int(qdict, "prefix1", 0); + aer_err.prefix[2] =3D qdict_get_try_int(qdict, "prefix2", 0); + aer_err.prefix[3] =3D qdict_get_try_int(qdict, "prefix3", 0); =20 - ret =3D pcie_aer_inject_error(dev, &err); + ret =3D pcie_aer_inject_error(dev, &aer_err); if (ret < 0) { monitor_printf(mon, "failed to inject error: %s\n", strerror(-ret)); --=20 2.37.3 From nobody Mon May 13 23:06:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1671465221; cv=none; d=zohomail.com; s=zohoarc; b=hAOz1PkKrpFPHrJwrYJm00W/0WQJdpIwNyVlOhtmTonuGP8/1616tpzP5FdPoH0Q1KaAXYZjOYhmBeGMznGnVbvPRm/rcVHg2L4oXe/us3h3sDCaiaoN9ehYCXt5FCaAmI6mOund4ln7rVa5urLeTcVTRGJ9xiASVvQN2AUQE3k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671465221; 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=92ObYhpSfUlQQaC3UvSunnbX2eEX78YfTFndTt8VRGs=; b=Dj2bg/0K/iMZjENZTwcAnA6lIcONwmyJVCQ/9U7gU+EKjP5I2VSdIITx4SxaS3k7jDSxu0JYr0ndZPIUihu1xYKIFBhbfU2pxORmhXMyIvN8sZN2oTDQI4q4a0vsM3Ox7c5EIRLkJo2MDVDBAfyNxGCmhFpa4Wq6pjttFUg+vC4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1671465221340674.4179449829471; Mon, 19 Dec 2022 07:53:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p7IQY-0002nW-T6; Mon, 19 Dec 2022 10:51:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7IQN-0002aw-45 for qemu-devel@nongnu.org; Mon, 19 Dec 2022 10:51:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7IQK-0000aV-SU for qemu-devel@nongnu.org; Mon, 19 Dec 2022 10:51:30 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-642-VuabuuvEM8-eGG48qyi9aQ-1; Mon, 19 Dec 2022 10:51:23 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2FC3F3813F46; Mon, 19 Dec 2022 15:51:23 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.195.91]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 037C51121315; Mon, 19 Dec 2022 15:51:23 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 6E8AC21E65CC; Mon, 19 Dec 2022 16:51:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671465088; 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=92ObYhpSfUlQQaC3UvSunnbX2eEX78YfTFndTt8VRGs=; b=QGGDROz1jiLe+Xt1axBcpphkEtyZmRnNBwhxQQNLt6ppb85TKoj801736ULoaiyGV/knqz n9vsTSKi0OS3YVfn7yvDoPhIPhr8Y3VVsjzKsJhj8ok+oap3nHNA4+FFdSBFfCX/TVZ+L8 Rs3UoWzDyfQDkO0aES/p4wWJ0mfpXWU= X-MC-Unique: VuabuuvEM8-eGG48qyi9aQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, "Michael S . Tsirkin" , "Dr . David Alan Gilbert" Subject: [PULL 12/13] pci: Improve do_pcie_aer_inject_error()'s error messages Date: Mon, 19 Dec 2022 16:51:19 +0100 Message-Id: <20221219155120.2273041-13-armbru@redhat.com> In-Reply-To: <20221219155120.2273041-1-armbru@redhat.com> References: <20221219155120.2273041-1-armbru@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1671465221954100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Reviewed-by: Michael S. Tsirkin Reviewed-by: Dr. David Alan Gilbert Message-Id: <20221201121133.3813857-13-armbru@redhat.com> --- hw/pci/pci-hmp-cmds.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/hw/pci/pci-hmp-cmds.c b/hw/pci/pci-hmp-cmds.c index 6f0bb95ee4..a292d06ea0 100644 --- a/hw/pci/pci-hmp-cmds.c +++ b/hw/pci/pci-hmp-cmds.c @@ -161,6 +161,7 @@ void pcibus_dev_print(Monitor *mon, DeviceState *dev, i= nt indent) =20 void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict) { + Error *err =3D NULL; const char *id =3D qdict_get_str(qdict, "id"); const char *error_name; uint32_t error_status; @@ -171,24 +172,20 @@ void hmp_pcie_aer_inject_error(Monitor *mon, const QD= ict *qdict) int ret; =20 ret =3D pci_qdev_find_device(id, &dev); - if (ret < 0) { - monitor_printf(mon, - "id or pci device path is invalid or device not " - "found. %s\n", id); - return; + if (ret =3D=3D -ENODEV) { + error_setg(&err, "device '%s' not found", id); + goto out; } - if (!pci_is_express(dev)) { - monitor_printf(mon, "the device doesn't support pci express. %s\n", - id); - return; + if (ret < 0 || !pci_is_express(dev)) { + error_setg(&err, "device '%s' is not a PCIe device", id); + goto out; } =20 error_name =3D qdict_get_str(qdict, "error_status"); if (pcie_aer_parse_error_string(error_name, &error_status, &correctabl= e)) { if (qemu_strtoui(error_name, NULL, 0, &num) < 0) { - monitor_printf(mon, "invalid error status value. \"%s\"", - error_name); - return; + error_setg(&err, "invalid error status value '%s'", error_name= ); + goto out; } error_status =3D num; correctable =3D qdict_get_try_bool(qdict, "correctable", false); @@ -222,12 +219,15 @@ void hmp_pcie_aer_inject_error(Monitor *mon, const QD= ict *qdict) =20 ret =3D pcie_aer_inject_error(dev, &aer_err); if (ret < 0) { - monitor_printf(mon, "failed to inject error: %s\n", - strerror(-ret)); - return; + error_setg_errno(&err, -ret, "failed to inject error"); + goto out; } =20 + monitor_printf(mon, "OK id: %s root bus: %s, bus: %x devfn: %x.%x\n", id, pci_root_bus_path(dev), pci_dev_bus_num(dev), PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn)); + +out: + hmp_handle_error(mon, err); } --=20 2.37.3 From nobody Mon May 13 23:06:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1671465292; cv=none; d=zohomail.com; s=zohoarc; b=HXVmaWpY6J61c1UcbH1zfTM94OGNIMkgHLX1twMZ0ULt9fEtfDKqSHql51tQqfAwRz74jKgcqOod8s+0wJ42jrsVkPJTx2isb5J6yeL6Zeqimn3T+gKy2yqgfLaUmh06PnwKysnRatpq7xbEgg/aYjnIBAuG+EeHT49KAqM2DGM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671465292; 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=sSYPDtoq3erJu/uW+eDQCAcaAO+P7+u9QJIzvey1ZfY=; b=cas6KpbdDdQb6WedjHhH+pAfN1bHmDX4soapostPYYCOABBDHOjyFVxehvut31vb3kWcpQOoGwWFgrukDonUaozBoifo8q1VVFEQ4mlqql+fzHa8NNSE7MG0xZEAGVY/VQYAQRpXjxCZhd0l8MRY7TmIlwWg04oNOTYM/4OlPhA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1671465292573427.77408317980655; Mon, 19 Dec 2022 07:54:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p7IQZ-0002nr-22; Mon, 19 Dec 2022 10:51:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7IQT-0002h4-1T for qemu-devel@nongnu.org; Mon, 19 Dec 2022 10:51:38 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7IQR-0000cI-MH for qemu-devel@nongnu.org; Mon, 19 Dec 2022 10:51:36 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-608-KWY2iu1sPEKmBrurOtujXw-1; Mon, 19 Dec 2022 10:51:24 -0500 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6D2153813F54; Mon, 19 Dec 2022 15:51:23 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.195.91]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 453A0492B00; Mon, 19 Dec 2022 15:51:23 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 7098221E65CF; Mon, 19 Dec 2022 16:51:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671465095; 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=sSYPDtoq3erJu/uW+eDQCAcaAO+P7+u9QJIzvey1ZfY=; b=YjlH0zr11DGAjlMg61xOXNYltCV+0y6NkpXeI+vgGK514EEiS+RBpXW+Qb3cxpJvW4BeAs qDe7HA8UNT1KZu27WPghYtq3WaTKn7vHXKm8vaZrBd52PdpR0iSPFyYEseumvJjCb5hs9A qKmUHCo6U9CkQBVhC3086XhZghdzwlk= X-MC-Unique: KWY2iu1sPEKmBrurOtujXw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org Subject: [PULL 13/13] pci: Reject pcie_aer_inject_error -c with symbolic error status Date: Mon, 19 Dec 2022 16:51:20 +0100 Message-Id: <20221219155120.2273041-14-armbru@redhat.com> In-Reply-To: <20221219155120.2273041-1-armbru@redhat.com> References: <20221219155120.2273041-1-armbru@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 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=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1671465294355100003 Content-Type: text/plain; charset="utf-8" When argument @error_status is symbolic, flag -c is ignored. Reject it instead. Signed-off-by: Markus Armbruster Message-Id: <20221201121133.3813857-14-armbru@redhat.com> --- hw/pci/pci-hmp-cmds.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/pci/pci-hmp-cmds.c b/hw/pci/pci-hmp-cmds.c index a292d06ea0..fb7591d6ab 100644 --- a/hw/pci/pci-hmp-cmds.c +++ b/hw/pci/pci-hmp-cmds.c @@ -189,6 +189,11 @@ void hmp_pcie_aer_inject_error(Monitor *mon, const QDi= ct *qdict) } error_status =3D num; correctable =3D qdict_get_try_bool(qdict, "correctable", false); + } else { + if (qdict_haskey(qdict, "correctable")) { + error_setg(&err, "-c is only valid with numeric error status"); + goto out; + } } aer_err.status =3D error_status; aer_err.source_id =3D pci_requester_id(dev); --=20 2.37.3