From nobody Mon Feb 9 16:22:00 2026 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1586167164; cv=none; d=zohomail.com; s=zohoarc; b=LL7tMUmfZHATXxAA3nTuYLsOBoQDDzsjDi7acPfgPXQA93nb30tlWD1tVs+s6A+/HK7woi8sAafiB8tuqs9b0AVdR06YwAjEy2BO71CJrqdIOYHQBLVUlcEVoX5qWTyEsAocRX2QsnS94oEiF8ppPIxpGT6ORjaTBX+x+u88o4w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586167164; h=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=1PhzKLozBMPHH7oqxxC9Ov6cuOiC3lWW+T0/mLX01j8=; b=cDCgaPYEEmp0O4cXWYcLm17cSEJ/XJEos3FSdsrNoC0qCl7XsLrbTYzBAE300RkyrqnVBLqM+BE34sVxm9DVrQpSpff3W5z+BMEZwNAL/pQWrqe69D1sve7YyaDbw4Z3W/FXKJDZmRcKyrD1H1ZMbPjez/SvBQrocpLXptX0hf8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1586167164193485.55139501540236; Mon, 6 Apr 2020 02:59:24 -0700 (PDT) Received: from localhost ([::1]:57674 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jLOXK-0007Xt-Sq for importer@patchew.org; Mon, 06 Apr 2020 05:59:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44987) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jLOIw-0006XS-Km for qemu-devel@nongnu.org; Mon, 06 Apr 2020 05:44:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jLOIv-00042b-2M for qemu-devel@nongnu.org; Mon, 06 Apr 2020 05:44:30 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:36838) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jLOIu-00041l-Pm for qemu-devel@nongnu.org; Mon, 06 Apr 2020 05:44:29 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0369hpLH093026; Mon, 6 Apr 2020 09:44:14 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 306hnqwu7r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 06 Apr 2020 09:44:14 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0369ciqa092283; Mon, 6 Apr 2020 09:42:13 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3030.oracle.com with ESMTP id 3073spk6ey-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 06 Apr 2020 09:42:13 +0000 Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0369gC6K032002; Mon, 6 Apr 2020 09:42:12 GMT Received: from flaka.hsd1.ca.comcast.net (/67.180.143.163) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 06 Apr 2020 02:42:12 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=1PhzKLozBMPHH7oqxxC9Ov6cuOiC3lWW+T0/mLX01j8=; b=jQkhXT1MOpd41igH4GxelcfLH4QTc+TTA7Su3HtOjmm3FpWWIJQfJckqI1yTGWp6J/lZ S2X6A7gP+Y5utnK4chznX9nnPRghjOgUvRnJ7+PH4T1l7z3zELN3s6nP/nruJ1Ospfop lbVcfMspJW7V/8cbqXxnXn9/MycjSkV1PlLjYXMq528e5JyjdWGNmUXArqUC9VP+bNI5 KAU/X08dnN8BEi0wFnkd8rNV6gGB6Y9y8jz9i3VStLhgYQcAJ4Hp228mfjimxTlUP37h rMxWxsBXl3hyCTYMrA9TMoP9xvWoD4ovAp9SsAprkobLhvg60eItEvrcBwgEKQgjx65Z YA== From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Subject: [PATCH v6 24/36] multi-process: Retrieve PCI info from remote process Date: Mon, 6 Apr 2020 02:41:14 -0700 Message-Id: X-Mailer: git-send-email 2.25.GIT In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9582 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 phishscore=0 spamscore=0 malwarescore=0 suspectscore=3 adultscore=0 bulkscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2004060083 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9582 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 phishscore=0 adultscore=0 priorityscore=1501 mlxscore=0 malwarescore=0 mlxlogscore=999 lowpriorityscore=0 spamscore=0 impostorscore=0 suspectscore=3 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2004060084 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.86 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, swapnil.ingle@nutanix.com, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Jagannathan Raman Retrieve PCI configuration info about the remote device and configure the Proxy PCI object based on the returned information Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- hw/proxy/qemu-proxy.c | 84 ++++++++++++++++++++++++++++++++++++++++ include/io/mpqemu-link.h | 10 +++++ remote/remote-main.c | 21 ++++++++++ 3 files changed, 115 insertions(+) diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index a78694736b..730e28483e 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -19,6 +19,8 @@ #include "sysemu/kvm.h" #include "util/event_notifier-posix.c" =20 +static void probe_pci_info(PCIDevice *dev); + static int config_op_send(PCIProxyDev *dev, uint32_t addr, uint32_t *val, = int l, unsigned int op) { @@ -182,8 +184,12 @@ static void pci_proxy_dev_realize(PCIDevice *device, E= rror **errp) { PCIProxyDev *dev =3D PCI_PROXY_DEV(device); PCIProxyDevClass *k =3D PCI_PROXY_DEV_GET_CLASS(dev); + uint8_t *pci_conf =3D device->config; Error *local_err =3D NULL; =20 + pci_conf[PCI_LATENCY_TIMER] =3D 0xff; + pci_conf[PCI_INTERRUPT_PIN] =3D 0x01; + if (k->realize) { k->realize(dev, &local_err); if (local_err) { @@ -196,6 +202,8 @@ static void pci_proxy_dev_realize(PCIDevice *device, Er= ror **errp) configure_memory_sync(dev->sync, dev->mpqemu_link); =20 setup_irqfd(dev); + + probe_pci_info(PCI_DEVICE(dev)); } =20 static void pci_proxy_dev_class_init(ObjectClass *klass, void *data) @@ -291,3 +299,79 @@ const MemoryRegionOps proxy_default_ops =3D { .max_access_size =3D 1, }, }; + +static void probe_pci_info(PCIDevice *dev) +{ + PCIDeviceClass *pc =3D PCI_DEVICE_GET_CLASS(dev); + DeviceClass *dc =3D DEVICE_CLASS(pc); + PCIProxyDev *pdev =3D PCI_PROXY_DEV(dev); + MPQemuLinkState *mpqemu_link =3D pdev->mpqemu_link; + MPQemuMsg msg, ret; + uint32_t orig_val, new_val, class; + uint8_t type; + int i, size; + char *name; + + memset(&msg, 0, sizeof(MPQemuMsg)); + msg.bytestream =3D 0; + msg.size =3D 0; + msg.cmd =3D GET_PCI_INFO; + mpqemu_msg_send(&msg, mpqemu_link->dev); + + mpqemu_msg_recv(&ret, mpqemu_link->dev); + + pc->vendor_id =3D ret.data1.ret_pci_info.vendor_id; + pc->device_id =3D ret.data1.ret_pci_info.device_id; + pc->class_id =3D ret.data1.ret_pci_info.class_id; + pc->subsystem_id =3D ret.data1.ret_pci_info.subsystem_id; + + config_op_send(pdev, 11, &class, 1, PCI_CONFIG_READ); + switch (class) { + case PCI_BASE_CLASS_BRIDGE: + set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); + break; + case PCI_BASE_CLASS_STORAGE: + set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); + break; + case PCI_BASE_CLASS_NETWORK: + set_bit(DEVICE_CATEGORY_NETWORK, dc->categories); + break; + case PCI_BASE_CLASS_INPUT: + set_bit(DEVICE_CATEGORY_INPUT, dc->categories); + break; + case PCI_BASE_CLASS_DISPLAY: + set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories); + break; + case PCI_BASE_CLASS_PROCESSOR: + set_bit(DEVICE_CATEGORY_CPU, dc->categories); + break; + default: + set_bit(DEVICE_CATEGORY_MISC, dc->categories); + break; + } + + for (i =3D 0; i < 6; i++) { + config_op_send(pdev, 0x10 + (4 * i), &orig_val, 4, PCI_CONFIG_READ= ); + new_val =3D 0xffffffff; + config_op_send(pdev, 0x10 + (4 * i), &new_val, 4, PCI_CONFIG_WRITE= ); + config_op_send(pdev, 0x10 + (4 * i), &new_val, 4, PCI_CONFIG_READ); + size =3D (~(new_val & 0xFFFFFFF0)) + 1; + config_op_send(pdev, 0x10 + (4 * i), &orig_val, 4, PCI_CONFIG_WRIT= E); + type =3D (new_val & 0x1) ? + PCI_BASE_ADDRESS_SPACE_IO : PCI_BASE_ADDRESS_SPACE_MEMO= RY; + + if (size) { + pdev->region[i].dev =3D pdev; + pdev->region[i].present =3D true; + if (type =3D=3D PCI_BASE_ADDRESS_SPACE_MEMORY) { + pdev->region[i].memory =3D true; + } + name =3D g_strdup_printf("bar-region-%d", i); + memory_region_init_io(&pdev->region[i].mr, OBJECT(pdev), + &proxy_default_ops, &pdev->region[i], + name, size); + pci_register_bar(dev, i, type, &pdev->region[i].mr); + g_free(name); + } + } +} diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index 14e4be2bd0..102c736705 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -48,6 +48,8 @@ typedef enum { BAR_WRITE, BAR_READ, SET_IRQFD, + GET_PCI_INFO, + RET_PCI_INFO, MAX, } mpqemu_cmd_t; =20 @@ -70,6 +72,13 @@ typedef struct { bool memory; } bar_access_msg_t; =20 +typedef struct { + uint16_t vendor_id; + uint16_t device_id; + uint16_t class_id; + uint16_t subsystem_id; +} ret_pci_info_msg_t; + /** * MPQemuMsg: * @cmd: The remote command @@ -98,6 +107,7 @@ typedef struct { sync_sysmem_msg_t sync_sysmem; bar_access_msg_t bar_access; set_irqfd_msg_t set_irqfd; + ret_pci_info_msg_t ret_pci_info; } data1; =20 int fds[REMOTE_MAX_FDS]; diff --git a/remote/remote-main.c b/remote/remote-main.c index 697fb992a1..d249eba9e8 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -165,6 +165,24 @@ fail: PUT_REMOTE_WAIT(wait); } =20 +static void process_get_pci_info_msg(MPQemuLinkState *link, MPQemuMsg *msg) +{ + PCIDevice *pci_dev =3D LINK_TO_DEV(link); + PCIDeviceClass *pc =3D PCI_DEVICE_GET_CLASS(pci_dev); + MPQemuMsg ret =3D { 0 }; + + ret.cmd =3D RET_PCI_INFO; + + ret.data1.ret_pci_info.vendor_id =3D pc->vendor_id; + ret.data1.ret_pci_info.device_id =3D pc->device_id; + ret.data1.ret_pci_info.class_id =3D pc->class_id; + ret.data1.ret_pci_info.subsystem_id =3D pc->subsystem_id; + + ret.size =3D sizeof(ret.data1); + + mpqemu_msg_send(&ret, link->dev); +} + static void process_msg(GIOCondition cond, MPQemuLinkState *link, MPQemuChannel *chan) { @@ -219,6 +237,9 @@ static void process_msg(GIOCondition cond, MPQemuLinkSt= ate *link, case SET_IRQFD: process_set_irqfd_msg(LINK_TO_DEV(link), msg); break; + case GET_PCI_INFO: + process_get_pci_info_msg(link, msg); + break; default: error_setg(&err, "Unknown command"); goto finalize_loop; --=20 2.25.GIT