From nobody Thu Apr 25 04:23:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1493692816667657.2330871515559; Mon, 1 May 2017 19:40:16 -0700 (PDT) Received: from localhost ([::1]:56441 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d5Njb-0003wJ-6O for importer@patchew.org; Mon, 01 May 2017 22:40:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d5Nip-0003fT-3T for qemu-devel@nongnu.org; Mon, 01 May 2017 22:39:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d5Nik-00088p-CO for qemu-devel@nongnu.org; Mon, 01 May 2017 22:39:27 -0400 Received: from mx7.zte.com.cn ([202.103.147.169]:36555) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d5Nii-00086j-CZ for qemu-devel@nongnu.org; Mon, 01 May 2017 22:39:22 -0400 Received: from unknown (HELO mse01.zte.com.cn) (10.30.3.20) by localhost with (AES256-SHA encrypted) SMTP; 2 May 2017 02:33:12 -0000 Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id v422cqZw045898; Tue, 2 May 2017 10:38:52 +0800 (GMT-8) (envelope-from lu.zhipeng@zte.com.cn) Received: from ceshi.localdomain ([10.74.120.130]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2017050210385395-161387 ; Tue, 2 May 2017 10:38:53 +0800 X-scanvirus: By SEG_CYREN AntiVirus Engine X-scanresult: CLEAN X-MAILFROM: X-RCPTTO: X-FROMIP: 10.30.3.20 X-SEG-Scaned: 1 X-Received: unknown,10.30.3.20,20170502103312 From: ZhiPeng Lu To: dgilbert@redhat.com, mst@redhat.com, marcel@redhat.com Date: Tue, 2 May 2017 10:38:11 +0800 Message-Id: <1493692691-30801-1-git-send-email-lu.zhipeng@zte.com.cn> X-Mailer: git-send-email 1.8.3.1 X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2017-05-02 10:38:54, Serialize by Router on notes_smtp/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2017-05-02 10:38:36, Serialize complete at 2017-05-02 10:38:36 X-MAIL: mse01.zte.com.cn v422cqZw045898 X-HQIP: 127.0.0.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x [fuzzy] X-Received-From: 202.103.147.169 Subject: [Qemu-devel] [PATCH] hmp: add 'info virtio-pci-status id' command X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ZhiPeng Lu , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add command to query a virtio pci device status. we can get id of the virtio pci device by 'info pci' command. HMP Test case: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D virsh # qemu-monitor-command --hmp 3 info pci Bus 0, device 3, function 0: Ethernet controller: PCI device 1af4:1000 IRQ 11. BAR0: I/O at 0xc000 [0xc03f]. BAR1: 32 bit memory at 0xfebd1000 [0xfebd1fff]. BAR4: 64 bit prefetchable memory at 0xfe000000 [0xfe003fff]. BAR6: 32 bit memory at 0xffffffffffffffff [0x0003fffe]. id "net0" Bus 0, device 4, function 0: USB controller: PCI device 8086:24cd IRQ 11. BAR0: 32 bit memory at 0xfebd2000 [0xfebd2fff]. id "usb" virsh # qemu-monitor-command 3 --hmp "info virtio-pci-status net0" status=3D15 virsh # qemu-monitor-command 3 --hmp "info virtio-pci-status usb" the 'info virtio_pci_status' command only supports virtio pci devices Signed-off-by: ZhiPeng Lu --- hmp-commands-info.hx | 14 ++++++++++++++ hw/pci/pci-stub.c | 6 ++++++ hw/virtio/virtio-pci.c | 47 +++++++++++++++++++++++++++++++++++++++++++++= ++ include/sysemu/sysemu.h | 1 + 4 files changed, 68 insertions(+) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index a53f105..7b9c4db 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -815,6 +815,20 @@ ETEXI .cmd =3D hmp_info_vm_generation_id, }, =20 + { + .name =3D "virtio-pci-status", + .args_type =3D "id:s", + .params =3D "id", + .help =3D "show virtio pci device status", + .cmd =3D hmp_info_virtio_pci_status, + }, + +STEXI +@item info virtio-pci-status @var{id} +@findex virtio-pci-status +Show status about virtio pci device +ETEXI + STEXI @end table ETEXI diff --git a/hw/pci/pci-stub.c b/hw/pci/pci-stub.c index 36d2c43..3609a52 100644 --- a/hw/pci/pci-stub.c +++ b/hw/pci/pci-stub.c @@ -35,3 +35,9 @@ void hmp_pcie_aer_inject_error(Monitor *mon, const QDict = *qdict) { monitor_printf(mon, "PCI devices not supported\n"); } + +void hmp_info_virtio_pci_status(Monitor *mon, const QDict *qdict) +{ + monitor_printf(mon, "PCI devices not supported\n"); +} + diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index f9b7244..5fa862b 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -37,6 +37,7 @@ #include "qemu/range.h" #include "hw/virtio/virtio-bus.h" #include "qapi/visitor.h" +#include "monitor/monitor.h" =20 #define VIRTIO_PCI_REGION_SIZE(dev) VIRTIO_PCI_CONFIG_OFF(msix_present= (dev)) =20 @@ -50,6 +51,7 @@ static void virtio_pci_bus_new(VirtioBusState *bus, size_= t bus_size, VirtIOPCIProxy *dev); static void virtio_pci_reset(DeviceState *qdev); =20 +static void query_virtio_pci_status(Monitor *mon, const char *id); /* virtio device */ /* DeviceState to VirtIOPCIProxy. For use off data-path. TODO: use QOM. */ static inline VirtIOPCIProxy *to_virtio_pci_proxy(DeviceState *d) @@ -2556,6 +2558,51 @@ static void virtio_pci_bus_new(VirtioBusState *bus, = size_t bus_size, virtio_bus_name); } =20 +static void query_virtio_pci_status(Monitor *mon, const char *id) +{ + int ret =3D 0, i =3D 0; + PCIDevice *dev =3D NULL; + hwaddr addr =3D 0; + uint8_t val =3D 0; + const char *devtype =3D NULL; + + ret =3D pci_qdev_find_device(id, &dev); + if (ret) { + monitor_printf(mon, "Can not find device %s\n", id); + return; + } + devtype =3D object_get_typename(OBJECT(dev)); + if (strncmp("virtio-", devtype, 7) =3D=3D 0) { + for (i =3D 0; i < PCI_NUM_REGIONS; i++) { + if (dev->io_regions[i].type =3D=3D PCI_BASE_ADDRESS_SPACE_IO) { + addr =3D dev->io_regions[i].addr; + break; + } + } + if (addr !=3D -1 && addr !=3D 0) { + address_space_rw(&address_space_io, addr + VIRTIO_PCI_STATUS, + MEMTXATTRS_UNSPECIFIED, &val, 1, 0); + if (val & VIRTIO_CONFIG_S_DRIVER_OK) { + fprintf(stderr, "driver is ok\n"); + } else { + fprintf(stderr, "driver is not ok\n"); + } + monitor_printf(mon, "status=3D%d", val); + } else { + monitor_printf(mon, "status=3D%d", val); + } + } else { + monitor_printf(mon, "the 'info virtio_pci_status' command " + "only supports virtio pci devices"); + } +} + +void hmp_info_virtio_pci_status(Monitor *mon, const QDict *qdict) +{ + const char *id =3D qdict_get_try_str(qdict, "id"); + query_virtio_pci_status(mon, id); +} + static void virtio_pci_bus_class_init(ObjectClass *klass, void *data) { BusClass *bus_class =3D BUS_CLASS(klass); diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 576c7ce..de66cc0 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -238,4 +238,5 @@ extern QemuOptsList qemu_net_opts; extern QemuOptsList qemu_global_opts; extern QemuOptsList qemu_mon_opts; =20 +extern void hmp_info_virtio_pci_status(Monitor *mon, const QDict *qdict); #endif --=20 1.8.3.1