From patchwork Thu Aug 31 09:32:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huang Rui X-Patchwork-Id: 13371167 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A2A26C83F01 for ; Thu, 31 Aug 2023 09:34:10 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.593574.926600 (Exim 4.92) (envelope-from ) id 1qbe3i-0006wy-9F; Thu, 31 Aug 2023 09:33:50 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 593574.926600; Thu, 31 Aug 2023 09:33:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbe3i-0006wo-66; Thu, 31 Aug 2023 09:33:50 +0000 Received: by outflank-mailman (input) for mailman id 593574; Thu, 31 Aug 2023 09:33:48 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbe3g-0006tw-Et for xen-devel@lists.xenproject.org; Thu, 31 Aug 2023 09:33:48 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2060b.outbound.protection.outlook.com [2a01:111:f400:7e8a::60b]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7a465ee2-47e1-11ee-9b0d-b553b5be7939; Thu, 31 Aug 2023 11:33:45 +0200 (CEST) Received: from MW4PR03CA0342.namprd03.prod.outlook.com (2603:10b6:303:dc::17) by MW5PR12MB5649.namprd12.prod.outlook.com (2603:10b6:303:19d::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.20; Thu, 31 Aug 2023 09:33:39 +0000 Received: from MWH0EPF000989EC.namprd02.prod.outlook.com (2603:10b6:303:dc:cafe::58) by MW4PR03CA0342.outlook.office365.com (2603:10b6:303:dc::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.21 via Frontend Transport; Thu, 31 Aug 2023 09:33:39 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by MWH0EPF000989EC.mail.protection.outlook.com (10.167.241.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.16 via Frontend Transport; Thu, 31 Aug 2023 09:33:39 +0000 Received: from hr-amd.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 31 Aug 2023 04:33:31 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 7a465ee2-47e1-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N8xIynprutMEn5MAtCwoQkUCKbA5fvmB7FULIYJLqInGzKjRL14bXZZQyUi3VPiw7QREw2GF0cX2Dpq04dix0aTox3zz20S2x8XNHMRl0dGwbMIzL7IhBmIdrJDFwFAvUMfnLs8Uhmuqej4JJ/lpLCsu24SDLVSd8x8oNGUWg4hDugoKr3BSB0yW+YG4v32HyDvD4FIJ3ywaDI6yX+awybQ+u0s+Q1CbvBvKiN/FkuQ+LbBoBnDMA/kCC10SDlzxRXtxDqwGxJQ4hBsbzPZmM0jq9ZRkSGJfwLZNcTtRT+tBL5v8KDeOa4EgyAE8rx3irBLbT3C9Zy99trzLib006Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BbWnAkGTDkIuiyxFJjQRvGBwHS6OgVoyaJjKb6dSr5M=; b=ZqfTgLbHr4FdbHfAY6Z0NYcABB0IkcVL9FzQckPhduBC97GUuWl7RVgyJ6ZWkbCIAw7pfqKQB4eUo4A6zrjZVLgktJx0+xkdcqIXBnWwL95wJPWIjvNn9Y3DiJWYbOoL5Hd7N473UzalFaU442rYmvQoHWo4qQEi64xddVvUKyI/assWNU6Ht84466b0gjtcBWWgBsFUwlA0FMqv/Wu/BDrVPiPVrezC5om4UUOEZm3ZU4kTrO8hG52ooSPlODvYBLaON7NkBaUBLamKuMm2ikQ3OzZpD4WXbpkxu4HeX2hoeM5bpLrn59u4z9bdB954bybBxTO4VL/1B6VigaaxCQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BbWnAkGTDkIuiyxFJjQRvGBwHS6OgVoyaJjKb6dSr5M=; b=oD307W5QKTyu90ZGdMYv+Uy39SdUAStwnX5ilhPt5b9rEtH55wSJakI7jShkjxznCESHtpc01EOJtiQ8aOy3SEy6peRYRRqA/uUuSXGOEaIOigPXZyWk+FsVDO/3nidcNb81+BGh2CdG2zN2zdtHe0GjcR/3Qh0DyXEJnvja2G4= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Huang Rui To: Gerd Hoffmann , "Michael S . Tsirkin" , Stefano Stabellini , Anthony PERARD , Antonio Caggiano , "Dr . David Alan Gilbert" , Robert Beckett , "Dmitry Osipenko" , =?utf-8?q?Alex_Benn?= =?utf-8?q?=C3=A9e?= , CC: , Gurchetan Singh , , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Akihiko Odaki , Alyssa Ross , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= , Xenia Ragiadakou , Pierre-Eric Pelloux-Prayer , "Honglei Huang" , Julia Zhang , "Chen Jiqian" , Huang Rui Subject: [QEMU PATCH v4 03/13] virtio-gpu: hostmem Date: Thu, 31 Aug 2023 17:32:42 +0800 Message-ID: <20230831093252.2461282-4-ray.huang@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230831093252.2461282-1-ray.huang@amd.com> References: <20230831093252.2461282-1-ray.huang@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000989EC:EE_|MW5PR12MB5649:EE_ X-MS-Office365-Filtering-Correlation-Id: 0e62684b-ddd7-4c79-5b1d-08dbaa055bea X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9eeY67tes1/Myu7fpK8tPRbZHeo1HLTkuhLdhATXE/KhXw+uJ2E7vlaBn6zaJ3bTyyox4Auzi3vzEzKX9rB2v3wM4a0+5vpHzB/D6u8VKpFd41kiskoguO5uoFc7DcfNEPwTL0o9ivS/u5w4LgPigFeXwM7Tk3EbB46OcKF3JbqZgf/8OGQ2V9mDdAvp4Fp/8NAFfdG4MYFIpxzFt0sXkvYOoRwIZbO7p1Xn7vBRB9pkRDRoPitqQv/TQhEnj3iDL5eF4TTqUYTpXgEFPe7LxT8gp0Pd8Z2HjiQsUEe2cd5TtBh1Vbt8cs9D7YCWWZabskuLKLv8IwVXce95AkNsQ9Dhd6uybqGyaXCoIls72uqbe7tCD6HhupkC/J3WGkJwxh0nDdZELQ1Ya/BGgWvZlnjeCRmwrUmBuSxWZkk905D3QXVvyQslIHz5EloDX/6ZYdf9sxvNrIY/FK2pdHhQ2UYYRRI3RSAvfiPDhp/29/lXkZBddysHtvOdoFaQzOthyZWg0FE3cBRytCRsZvoX8jZan2RolNgY/nrdVYK/nqWTWFwpJHLC3+Lnh2YfmRkmY9ULg5KbKL1dNmF0oMD7bXMYf5ompUzc8CkzxhV2JJiptpn+hvpqBZ08MhmVaIeXsOytYOoiqgTNb3mlS1K1ofqcNojOE8oGhWKhlJ+m3ohqosu1HdtHuzJOfR9tzGGOje2JtFcpGQwoKztLbDDI7C6jxOP+bMCMuDbYEPG4IAf94tWqJf0dS+OdrCkNj+AqDccP9Xs1KoGVNHr2thMaJSA7cpC0/WUEM7ja0hgxVoE= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(346002)(136003)(376002)(396003)(39860400002)(1800799009)(451199024)(82310400011)(186009)(40470700004)(46966006)(36840700001)(36756003)(40460700003)(7416002)(40480700001)(2616005)(83380400001)(8676002)(86362001)(41300700001)(4326008)(8936002)(5660300002)(6666004)(336012)(7696005)(1076003)(426003)(16526019)(26005)(36860700001)(47076005)(81166007)(921005)(110136005)(478600001)(82740400003)(356005)(70586007)(54906003)(70206006)(316002)(2906002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Aug 2023 09:33:39.4982 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0e62684b-ddd7-4c79-5b1d-08dbaa055bea X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000989EC.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW5PR12MB5649 From: Gerd Hoffmann Use VIRTIO_GPU_SHM_ID_HOST_VISIBLE as id for virtio-gpu. Signed-off-by: Antonio Caggiano Tested-by: Alyssa Ross Tested-by: Akihiko Odaki Acked-by: Michael S. Tsirkin Reviewed-by: Akihiko Odaki Signed-off-by: Huang Rui --- This patch is already under review as part of the "rutabaga_gfx + gfxstream" series (already in v13) and has been included here because of dependency. hw/display/virtio-gpu-pci.c | 14 ++++++++++++++ hw/display/virtio-gpu.c | 1 + hw/display/virtio-vga.c | 33 ++++++++++++++++++++++++--------- include/hw/virtio/virtio-gpu.h | 5 +++++ 4 files changed, 44 insertions(+), 9 deletions(-) diff --git a/hw/display/virtio-gpu-pci.c b/hw/display/virtio-gpu-pci.c index 93f214ff58..da6a99f038 100644 --- a/hw/display/virtio-gpu-pci.c +++ b/hw/display/virtio-gpu-pci.c @@ -33,6 +33,20 @@ static void virtio_gpu_pci_base_realize(VirtIOPCIProxy *vpci_dev, Error **errp) DeviceState *vdev = DEVICE(g); int i; + if (virtio_gpu_hostmem_enabled(g->conf)) { + vpci_dev->msix_bar_idx = 1; + vpci_dev->modern_mem_bar_idx = 2; + memory_region_init(&g->hostmem, OBJECT(g), "virtio-gpu-hostmem", + g->conf.hostmem); + pci_register_bar(&vpci_dev->pci_dev, 4, + PCI_BASE_ADDRESS_SPACE_MEMORY | + PCI_BASE_ADDRESS_MEM_PREFETCH | + PCI_BASE_ADDRESS_MEM_TYPE_64, + &g->hostmem); + virtio_pci_add_shm_cap(vpci_dev, 4, 0, g->conf.hostmem, + VIRTIO_GPU_SHM_ID_HOST_VISIBLE); + } + virtio_pci_force_virtio_1(vpci_dev); if (!qdev_realize(vdev, BUS(&vpci_dev->bus), errp)) { return; diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index bbd5c6561a..48ef0d9fad 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -1509,6 +1509,7 @@ static Property virtio_gpu_properties[] = { 256 * MiB), DEFINE_PROP_BIT("blob", VirtIOGPU, parent_obj.conf.flags, VIRTIO_GPU_FLAG_BLOB_ENABLED, false), + DEFINE_PROP_SIZE("hostmem", VirtIOGPU, parent_obj.conf.hostmem, 0), DEFINE_PROP_END_OF_LIST(), }; diff --git a/hw/display/virtio-vga.c b/hw/display/virtio-vga.c index e6fb0aa876..c8552ff760 100644 --- a/hw/display/virtio-vga.c +++ b/hw/display/virtio-vga.c @@ -115,17 +115,32 @@ static void virtio_vga_base_realize(VirtIOPCIProxy *vpci_dev, Error **errp) pci_register_bar(&vpci_dev->pci_dev, 0, PCI_BASE_ADDRESS_MEM_PREFETCH, &vga->vram); - /* - * Configure virtio bar and regions - * - * We use bar #2 for the mmio regions, to be compatible with stdvga. - * virtio regions are moved to the end of bar #2, to make room for - * the stdvga mmio registers at the start of bar #2. - */ - vpci_dev->modern_mem_bar_idx = 2; - vpci_dev->msix_bar_idx = 4; vpci_dev->modern_io_bar_idx = 5; + if (!virtio_gpu_hostmem_enabled(g->conf)) { + /* + * Configure virtio bar and regions + * + * We use bar #2 for the mmio regions, to be compatible with stdvga. + * virtio regions are moved to the end of bar #2, to make room for + * the stdvga mmio registers at the start of bar #2. + */ + vpci_dev->modern_mem_bar_idx = 2; + vpci_dev->msix_bar_idx = 4; + } else { + vpci_dev->msix_bar_idx = 1; + vpci_dev->modern_mem_bar_idx = 2; + memory_region_init(&g->hostmem, OBJECT(g), "virtio-gpu-hostmem", + g->conf.hostmem); + pci_register_bar(&vpci_dev->pci_dev, 4, + PCI_BASE_ADDRESS_SPACE_MEMORY | + PCI_BASE_ADDRESS_MEM_PREFETCH | + PCI_BASE_ADDRESS_MEM_TYPE_64, + &g->hostmem); + virtio_pci_add_shm_cap(vpci_dev, 4, 0, g->conf.hostmem, + VIRTIO_GPU_SHM_ID_HOST_VISIBLE); + } + if (!(vpci_dev->flags & VIRTIO_PCI_FLAG_PAGE_PER_VQ)) { /* * with page-per-vq=off there is no padding space we can use diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 8377c365ef..de4f624e94 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -108,12 +108,15 @@ enum virtio_gpu_base_conf_flags { (_cfg.flags & (1 << VIRTIO_GPU_FLAG_BLOB_ENABLED)) #define virtio_gpu_context_init_enabled(_cfg) \ (_cfg.flags & (1 << VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLED)) +#define virtio_gpu_hostmem_enabled(_cfg) \ + (_cfg.hostmem > 0) struct virtio_gpu_base_conf { uint32_t max_outputs; uint32_t flags; uint32_t xres; uint32_t yres; + uint64_t hostmem; }; struct virtio_gpu_ctrl_command { @@ -137,6 +140,8 @@ struct VirtIOGPUBase { int renderer_blocked; int enable; + MemoryRegion hostmem; + struct virtio_gpu_scanout scanout[VIRTIO_GPU_MAX_SCANOUTS]; int enabled_output_bitmask;