From patchwork Sat Dec 7 10:55:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Julia" X-Patchwork-Id: 13898249 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 EC429E7717B for ; Sat, 7 Dec 2024 10:57:28 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.850661.1265052 (Exim 4.92) (envelope-from ) id 1tJsUx-0001wW-8O; Sat, 07 Dec 2024 10:57:19 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 850661.1265052; Sat, 07 Dec 2024 10:57:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJsUx-0001wM-5T; Sat, 07 Dec 2024 10:57:19 +0000 Received: by outflank-mailman (input) for mailman id 850661; Sat, 07 Dec 2024 10:57:18 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJsUw-0001tQ-Ll for xen-devel@lists.xenproject.org; Sat, 07 Dec 2024 10:57:18 +0000 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on20623.outbound.protection.outlook.com [2a01:111:f403:240a::623]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 05c6c1eb-b48a-11ef-a0d5-8be0dac302b0; Sat, 07 Dec 2024 11:57:18 +0100 (CET) Received: from BN8PR12CA0026.namprd12.prod.outlook.com (2603:10b6:408:60::39) by DS0PR12MB8343.namprd12.prod.outlook.com (2603:10b6:8:fd::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.18; Sat, 7 Dec 2024 10:57:10 +0000 Received: from BN3PEPF0000B372.namprd21.prod.outlook.com (2603:10b6:408:60:cafe::18) by BN8PR12CA0026.outlook.office365.com (2603:10b6:408:60::39) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.10 via Frontend Transport; Sat, 7 Dec 2024 10:57:10 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by BN3PEPF0000B372.mail.protection.outlook.com (10.167.243.169) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8272.0 via Frontend Transport; Sat, 7 Dec 2024 10:57:10 +0000 Received: from jenkins-julia.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.39; Sat, 7 Dec 2024 04:57:06 -0600 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: 05c6c1eb-b48a-11ef-a0d5-8be0dac302b0 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=FDSTIwzP2hCfkSDlD3jasev3OQMVtkVjWW9QvByL0AmhQjlT0EEfCPACwktnvZGYbST34jlXYK+o5SSIrmMOOpokXF1u6+IPZlwp1A2XFw3z8B4HzuMggj1kaOTH69DbTEV1kgghlxgqSmsU5dzEww3xof1xefhDX0GFz91tibC7ENLeqElrRtKsFed/VF9di6Tnean6b2M4o9PWyFay/uEkHXhti/TCp8O/mrtoU4LtaQf3zzeeDG5+8KDrgJVZP93E1ESRsJY9g6WWGWJjERmHb3hlysEEbZkkomFRM/xFxZnCPnDe3oN9H+Ugl9gh6cNYIgZqkGNMKLWi86YPoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=YaHGUZgM04HQD0VdrKLIvWNrpeh66J4OqCg0Rby1C6g=; b=md9oZJFpqB0rYp5yKsqmkRnaXGuEwySykTGCesIzeQBVQ8BiZaukS3N56vzpV2Zq+9+Blq7ENHw0zLy+/NwqeHtEbOr8TmQY+0HMtAPU39Krs2uA9iPIbuuXbNNHKKN9Gvi8gIukKF2BnYrihZ2WJqxBVWV2zUAz0jLqD8J4zTvaJFJL9VW1YuOtNs//DIs5Hh1gVgg28jByfxfoWq5F2daxOHfs2bitzGkYVFx94rkuNyXA7uXaOfYa2nB4kY0rm3Xude90E8h5xRFBZ16/VztsVj4s7UFu2Qs5XZw36OcGUuKQsslRaqUVfJvo7Dvgf0vfZMKu3DjatNfhwoXXDw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org 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 (0) 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=YaHGUZgM04HQD0VdrKLIvWNrpeh66J4OqCg0Rby1C6g=; b=KjWOBi2l/1Dc2KfPgZ+2nAqRejIp4pj7FgRzi3vmA1Lrf4iU8y+6htA0df0cxx/7P4zhJiGxkbDR8XsVZ7ssH7K5CJ7KxqTKjmGdQhz9q0ho3Zh1Dm5KexDPoBpa0uN8324Vxr13kJW1fJf2eBK2W/z/78AsfxQsZqWtwJSrjF8= 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: Julia Zhang To: Stefano Stabellini , Anthony PERARD , Paul Durrant , "Edgar E . Iglesias" , "Michael S . Tsirkin" , Marcel Apfelbaum , CC: Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= , "Xenia Ragiadakou" , Julia Zhang , "Chen Jiqian" , Huang Rui , Penny Zheng , Zhu Lingshan , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Jan Beulich , Juergen Gross , Oleksandr Tyshchenko , Subject: [PATCH 2/3] pci: introduce a function to get PCIDevice Date: Sat, 7 Dec 2024 18:55:38 +0800 Message-ID: <20241207105537.542441-3-julia.zhang@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241207105537.542441-1-julia.zhang@amd.com> References: <20241207105537.542441-1-julia.zhang@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B372:EE_|DS0PR12MB8343:EE_ X-MS-Office365-Filtering-Correlation-Id: 9529aba0-a848-47bc-c579-08dd16ade65d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|7416014|376014|82310400026; X-Microsoft-Antispam-Message-Info: FalTgiIumSNSHIdOdM/HxAXB5s+CVh6ArP5TPCQfpVyXJJ9aAAfsuu8sF/udfg2PxYXXt6GPlLeQFhPIogNG4UMPeS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WGYLmW+Iw6px845Q9FNBU2hPrmwJzyCZiv0m/bdkP58MUwrZcOTDebTH9vIhwaziNONC1VIRUq5YusrkyptmHt2teTkp6TNydDVApSTkcmRh+vYAlgbLL+zDNG7HpQh8HOODUIvQudGuiiCPzJrz+2VT+Z47oplaiV7zaNYPijfpVw0XQ0JkQ8ZhjMcbLYHPefd6U/3lBl0A6Q7pEN06AoaZkJOaaYMgilv/jJKeSseJKBtjqxBJg4BCXfWnto17SL2UL8uTCT8hiEEO9V8XwBz8 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:(13230040)(1800799024)(36860700013)(7416014)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2024 10:57:10.5911 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9529aba0-a848-47bc-c579-08dd16ade65d 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: BN3PEPF0000B372.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8343 Introduce a helper function to get PCIDevice from qdev pci notation. Signed-off-by: Julia Zhang --- hw/pci/pci.c | 22 ++++++++++++++++++++++ include/hw/pci/pci.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 1416ae202c..95806ead4f 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2617,6 +2617,28 @@ static int pci_qdev_find_recursive(PCIBus *bus, return -EINVAL; } +int pci_qdev_get_device(uint32_t virt_bus, uint32_t virt_slot, uint32_t virt_func, + PCIDevice **pci_dev) +{ + PCIHostState *host_bridge; + PCIDevice *d; + int devfn; + int rc = -ENODEV; + + QLIST_FOREACH(host_bridge, &pci_host_bridges, next) { + for(devfn = 0; devfn < ARRAY_SIZE(host_bridge->bus->devices); devfn++) { + d = host_bridge->bus->devices[devfn]; + if (d && d->devfn == PCI_DEVFN(virt_slot, virt_func) && + pci_bus_num(pci_get_bus(d)) == virt_bus) { + *pci_dev = d; + rc = 0; + break; + } + } + } + return rc; +} + int pci_qdev_find_device(const char *id, PCIDevice **pdev) { PCIHostState *host_bridge; diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 463d9984b3..1b493ab95e 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -366,6 +366,8 @@ const char *pci_root_bus_path(PCIDevice *dev); bool pci_bus_bypass_iommu(PCIBus *bus); PCIDevice *pci_find_device(PCIBus *bus, int bus_num, uint8_t devfn); int pci_qdev_find_device(const char *id, PCIDevice **pdev); +int pci_qdev_get_device(uint32_t virt_bus, uint32_t virt_slot, + uint32_t virt_func, PCIDevice **pci_dev); void pci_bus_get_w64_range(PCIBus *bus, Range *range); void pci_device_deassert_intx(PCIDevice *dev);