From patchwork Fri Sep 14 18:26:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 10601141 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6F81214BD for ; Fri, 14 Sep 2018 18:28:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C5072BAB9 for ; Fri, 14 Sep 2018 18:28:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 509F32BABD; Fri, 14 Sep 2018 18:28:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7C2642BAB9 for ; Fri, 14 Sep 2018 18:28:47 +0000 (UTC) Received: from localhost ([::1]:52872 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g0spi-0000na-MK for patchwork-qemu-devel@patchwork.kernel.org; Fri, 14 Sep 2018 14:28:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35610) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g0soV-0008MT-DX for qemu-devel@nongnu.org; Fri, 14 Sep 2018 14:27:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g0soS-0003eY-4M for qemu-devel@nongnu.org; Fri, 14 Sep 2018 14:27:31 -0400 Received: from mail-eopbgr690075.outbound.protection.outlook.com ([40.107.69.75]:22016 helo=NAM04-CO1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g0soR-0003bD-Ng for qemu-devel@nongnu.org; Fri, 14 Sep 2018 14:27:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=W85Y2DY3fv3pTExcL7kGPeNXu6ZR6qEYTwmvuI8xzEM=; b=toEi2v7YugeAl8p4GT2ic4b+XNO7Q7MObLaJWLhL9VulOveHq66ciSo4KqaZjEewSbFMB9jK8P4CYI225wT7whC3eMLf6sS0lj4zjwttlVwrJQCouEVaGkdh6R3w+dyMmb7IMg0fzsPex0R9W/QDwn7pzAhVQAgdHLsrbX/YCVA= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from sbrijesh-desktop.amd.com (165.204.77.1) by DM6PR12MB2684.namprd12.prod.outlook.com (2603:10b6:5:4a::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1122.16; Fri, 14 Sep 2018 18:27:23 +0000 From: Brijesh Singh To: qemu-devel@nongnu.org Date: Fri, 14 Sep 2018 13:26:57 -0500 Message-Id: <1536949623-23564-3-git-send-email-brijesh.singh@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1536949623-23564-1-git-send-email-brijesh.singh@amd.com> References: <1536949623-23564-1-git-send-email-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BYAPR01CA0001.prod.exchangelabs.com (2603:10b6:a02:80::14) To DM6PR12MB2684.namprd12.prod.outlook.com (2603:10b6:5:4a::33) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fffc278d-1471-492b-e9df-08d61a6fb78d X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989137)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:DM6PR12MB2684; X-Microsoft-Exchange-Diagnostics: 1; DM6PR12MB2684; 3:gG0V+NpvOcSSpDRf3UczkIdS0kZfPKKbNSPUtEMNTE1/mmMEZaHj3Abm1jhRZmKdQFV2a5fc8MqGKMEMBs5XTuYtu+6U2ASsS+eOsVNPXV7wAy5NjTspvizkw6pKB9Xbpqb1JzDBgbHEriUVR9TE4USGSi7VlNmpn5IsjBKMeejnwjb9FfdnLrC969cBoJnBqPG6elj6oeMTZbTUtFTOMU4+vprrx3LyZ7XkUQ5VLuqxPKqLGU/j58zUR9Y7ZB+3; 25:hDomCm14tsLClbawdUPRSgvaa8Q5klf2Gvstz06cLVQOTa80kyGLGvC8vsoVvWniGOkqnCudwOgbWOTAFnYbZ3CENALa5VB9OFDSvxzDbInGLQ9mYQGnZ72HT15vQWEEponjMohXxjLkDxF0sj8yv2SGYF0dtzw13tkrmaerwp9FIsPeZsmIzTbqWrA8iAXCMI8npuQWhsmIcDDErI/DM+L85blbBWTj2b7mRXnCLLf42eloCzz1kcXLBrg0u2DvdGqF//JxpHMXmG5p2TTfcwmHfPLbXlBK0kdzijILm9K8JXRISqnxtQNkHHByxySkYF5DaqisIYCWR08IGkNQMQ==; 31:Hi6yEYynrZeFBwypf6nhaNw2t7XUsMkaK9Qvgoj3A5nBNuSDMqdhhlFlqWVuTPav6a4rHJstaFkqCK8Rs92aBrqmrwqn794cKXJMy331Vfoz4l0pWvAgB3GsSoVb8tZm3kFurcyLZr0zwMIMLneTWFPdaXGBSPjQjRoaOVDYdGmrw6trTHiOKsV24c910SzR28PEecapboH7YBYEgbsvB7d6f1ntafj0PURZvShhzXc= X-MS-TrafficTypeDiagnostic: DM6PR12MB2684: X-Microsoft-Exchange-Diagnostics: 1; DM6PR12MB2684; 20:ee2o99nRZAd8G9aLBV9qaXtDFBvm5wg4v2guuW4POAFAgCWDBa5yVETB8YQiJp/16Y29AE6NMESnNg3mR27Toda9qQhHI/GEW82+zfVVNLysy2vg5JIdsF4ASedj5nzAdDhAGxsScqsmlv4/NAUIDx7NocHkCP4prDSJM+ohW5Tbt9CTy1TtK8Fjz9M+h1ufzKXVccY/2Wwnk20AXuVa4DydZ+6GaqnG7OKbrZr3rRsZ1py84x0cK1lKgwE7y8rLVSSR1A75Pi+cfGiNetnFFqJvicY2PnETMdX8FeFuMl9fIPjKE3w1JGEjhLfmw2+W+cN5apgKzg+qI1MP40amuZ+vsInP5G2xUBSWcuuSEmZzxyhlU+Ef2tOuTre8GXEmpzOxlj0LIIYHOLYXQyuCqiECXiNRzlAjvfdvv5n9DTbxPrdb7EId7cOm8u36SYwF3NmiLU6cvn7FQJD63kkEadiN0P9lzHZSvk8jpPCZb+IdYMfMdGnEQoeEJS5oc4U5; 4:E9laPMgd49vNf7/6X7svd1GNKvDva1/pSz+SCG9rmPj5Zny9fu1LGn3uBBDbzcBYDBMw563UEce+AIpqXZp9psBC+PHRuBC7gGlQlnfqMjOM1fpA6PLN7O5efvStBksUdN2X1fb9ApmN6ZGezOXGQkETqx7m/Oi624KVW4R/6V6MGDAsvsEyJ4D4mR6fqFnXQ0Z9a11/sn+LZ1tM3xqxHWcvRehm0SwNZCQgjOVsRmtfrcKVJGQaO5s5kjzxMl+ukqxOd4unjwwdbBFtUxWIHBmU8/5cGwldlqyp0n/TG150o1qEijHUFk4NO2exP27yjktgrB+rdaWH3rN0sHkjdt5EyAQKcym+pbpc4Rgh2/k= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(85827821059158)(767451399110); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(823301075)(3002001)(10201501046)(3231311)(944501410)(52105095)(93006095)(93001095)(6055026)(149027)(150027)(6041310)(20161123562045)(20161123558120)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699050); SRVR:DM6PR12MB2684; BCL:0; PCL:0; RULEID:; SRVR:DM6PR12MB2684; X-Forefront-PRVS: 07954CC105 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(396003)(136003)(39860400002)(346002)(376002)(366004)(189003)(199004)(50466002)(66066001)(48376002)(2906002)(25786009)(446003)(16586007)(6486002)(76176011)(39060400002)(7736002)(68736007)(51416003)(7696005)(305945005)(316002)(6666003)(6916009)(47776003)(53936002)(52116002)(386003)(956004)(486006)(11346002)(5660300001)(54906003)(2616005)(8676002)(478600001)(36756003)(476003)(186003)(44832011)(105586002)(2361001)(3846002)(106356001)(26005)(81166006)(81156014)(8936002)(2351001)(53416004)(16526019)(50226002)(4326008)(97736004)(6116002)(86362001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM6PR12MB2684; H:sbrijesh-desktop.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM6PR12MB2684; 23:tYE/0vEhMQjwIy4O6mIdPKuoIyT2AGPAC12UqOmo3?= Etjnpxr+8U9TEuZ8dQ7QnAf4vrVdsxrtuioRxOIkgOQou0/2+FtHwYWyeqJeTs+8/ThwdUhNK5wtqc3deS8PbfTf8DZ+sg6DFs8pUlDP3RprV+TKPjQWAT0bj9zlLzTvTnzMtrT+Ikz7IlXfjVP/dAswf8zHT+6bgYV2lseY6r8ghhKRaX0mNvoHd8v4Id2tPuBdbsXnhjz8sYHPRbWItc5LvccLOU4wJdGQ2CaWRaETtbtZ6T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9uhpCV2tYJoEV4e5orLTnHp2Qq1tKgQrvYWfCKoGZYNdvtPuLpYauWwFHQYxRd3d54T7cbL7CNmq+rLOc6GxBjqrZzg38lpXyUaz5O87t6qLd4nm0q1NM+goPPTNQeWMtITBQu5deNh7ZOkYHdPUM/s4+ SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM6PR12MB2684; 20:+N7VprQued7Jz8IqmE3SCq27tF/Hrawmh+td3zVrpdHpzY2n2wpOw+RXLdkQRtZipFJtNpAL3m0fIGyDhccEVkMtfsb7Zn0/9wV3hhTZaTTFRnLncaJLk9WYzx0Rrz83UZpOkKMkjokzHJ5pFBL4U/iVJtVXF2EIDf4BFBXqR1Ccc2XzbEfmIdHH8lTOyCqdD34SJYCMVrBO+rvjJ1Ei/uboFycz+cFioa5RxFHInd5EMyaM4cFz8u1WJXOKbJFB X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2018 18:27:23.0918 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fffc278d-1471-492b-e9df-08d61a6fb78d X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2684 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.69.75 Subject: [Qemu-devel] [PATCH v2 2/8] x86_iommu: move vtd_generate_msi_message in common file 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: Tom Lendacky , Brijesh Singh , Eduardo Habkost , "Michael S. Tsirkin" , Paolo Bonzini , Suravee Suthikulpanit , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The vtd_generate_msi_message() in intel-iommu is used to construct a MSI Message from IRQ. A similar function will be needed when we add interrupt remapping support in amd-iommu. Moving the function in common file to avoid the code duplication. Rename it to x86_iommu_irq_to_msi_message(). There is no logic changes in the code flow. Signed-off-by: Brijesh Singh Suggested-by: Peter Xu Cc: "Michael S. Tsirkin" Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost Cc: Marcel Apfelbaum Cc: Tom Lendacky Cc: Suravee Suthikulpanit Reviewed-by: Eduardo Habkost --- hw/i386/intel_iommu.c | 32 +++------------------ hw/i386/x86-iommu.c | 24 ++++++++++++++++ include/hw/i386/intel_iommu.h | 59 -------------------------------------- include/hw/i386/x86-iommu.h | 66 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+), 87 deletions(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 84dbc20..014418b 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -2701,7 +2701,7 @@ static int vtd_irte_get(IntelIOMMUState *iommu, uint16_t index, /* Fetch IRQ information of specific IR index */ static int vtd_remap_irq_get(IntelIOMMUState *iommu, uint16_t index, - VTDIrq *irq, uint16_t sid) + X86IOMMUIrq *irq, uint16_t sid) { VTD_IR_TableEntry irte = {}; int ret = 0; @@ -2730,30 +2730,6 @@ static int vtd_remap_irq_get(IntelIOMMUState *iommu, uint16_t index, return 0; } -/* Generate one MSI message from VTDIrq info */ -static void vtd_generate_msi_message(VTDIrq *irq, MSIMessage *msg_out) -{ - VTD_MSIMessage msg = {}; - - /* Generate address bits */ - msg.dest_mode = irq->dest_mode; - msg.redir_hint = irq->redir_hint; - msg.dest = irq->dest; - msg.__addr_hi = irq->dest & 0xffffff00; - msg.__addr_head = cpu_to_le32(0xfee); - /* Keep this from original MSI address bits */ - msg.__not_used = irq->msi_addr_last_bits; - - /* Generate data bits */ - msg.vector = irq->vector; - msg.delivery_mode = irq->delivery_mode; - msg.level = 1; - msg.trigger_mode = irq->trigger_mode; - - msg_out->address = msg.msi_addr; - msg_out->data = msg.msi_data; -} - /* Interrupt remapping for MSI/MSI-X entry */ static int vtd_interrupt_remap_msi(IntelIOMMUState *iommu, MSIMessage *origin, @@ -2763,7 +2739,7 @@ static int vtd_interrupt_remap_msi(IntelIOMMUState *iommu, int ret = 0; VTD_IR_MSIAddress addr; uint16_t index; - VTDIrq irq = {}; + X86IOMMUIrq irq = {}; assert(origin && translated); @@ -2842,8 +2818,8 @@ static int vtd_interrupt_remap_msi(IntelIOMMUState *iommu, */ irq.msi_addr_last_bits = addr.addr.__not_care; - /* Translate VTDIrq to MSI message */ - vtd_generate_msi_message(&irq, translated); + /* Translate X86IOMMUIrq to MSI message */ + x86_iommu_irq_to_msi_message(&irq, translated); out: trace_vtd_ir_remap_msi(origin->address, origin->data, diff --git a/hw/i386/x86-iommu.c b/hw/i386/x86-iommu.c index 7440cb8..abc3c03 100644 --- a/hw/i386/x86-iommu.c +++ b/hw/i386/x86-iommu.c @@ -53,6 +53,30 @@ void x86_iommu_iec_notify_all(X86IOMMUState *iommu, bool global, } } +/* Generate one MSI message from VTDIrq info */ +void x86_iommu_irq_to_msi_message(X86IOMMUIrq *irq, MSIMessage *msg_out) +{ + X86IOMMU_MSIMessage msg = {}; + + /* Generate address bits */ + msg.dest_mode = irq->dest_mode; + msg.redir_hint = irq->redir_hint; + msg.dest = irq->dest; + msg.__addr_hi = irq->dest & 0xffffff00; + msg.__addr_head = cpu_to_le32(0xfee); + /* Keep this from original MSI address bits */ + msg.__not_used = irq->msi_addr_last_bits; + + /* Generate data bits */ + msg.vector = irq->vector; + msg.delivery_mode = irq->delivery_mode; + msg.level = 1; + msg.trigger_mode = irq->trigger_mode; + + msg_out->address = msg.msi_addr; + msg_out->data = msg.msi_data; +} + /* Default X86 IOMMU device */ static X86IOMMUState *x86_iommu_default = NULL; diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index fbfedcb..ed4e758 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -66,8 +66,6 @@ typedef struct VTDIOTLBEntry VTDIOTLBEntry; typedef struct VTDBus VTDBus; typedef union VTD_IR_TableEntry VTD_IR_TableEntry; typedef union VTD_IR_MSIAddress VTD_IR_MSIAddress; -typedef struct VTDIrq VTDIrq; -typedef struct VTD_MSIMessage VTD_MSIMessage; /* Context-Entry */ struct VTDContextEntry { @@ -197,63 +195,6 @@ union VTD_IR_MSIAddress { uint32_t data; }; -/* Generic IRQ entry information */ -struct VTDIrq { - /* Used by both IOAPIC/MSI interrupt remapping */ - uint8_t trigger_mode; - uint8_t vector; - uint8_t delivery_mode; - uint32_t dest; - uint8_t dest_mode; - - /* only used by MSI interrupt remapping */ - uint8_t redir_hint; - uint8_t msi_addr_last_bits; -}; - -struct VTD_MSIMessage { - union { - struct { -#ifdef HOST_WORDS_BIGENDIAN - uint32_t __addr_head:12; /* 0xfee */ - uint32_t dest:8; - uint32_t __reserved:8; - uint32_t redir_hint:1; - uint32_t dest_mode:1; - uint32_t __not_used:2; -#else - uint32_t __not_used:2; - uint32_t dest_mode:1; - uint32_t redir_hint:1; - uint32_t __reserved:8; - uint32_t dest:8; - uint32_t __addr_head:12; /* 0xfee */ -#endif - uint32_t __addr_hi; - } QEMU_PACKED; - uint64_t msi_addr; - }; - union { - struct { -#ifdef HOST_WORDS_BIGENDIAN - uint16_t trigger_mode:1; - uint16_t level:1; - uint16_t __resved:3; - uint16_t delivery_mode:3; - uint16_t vector:8; -#else - uint16_t vector:8; - uint16_t delivery_mode:3; - uint16_t __resved:3; - uint16_t level:1; - uint16_t trigger_mode:1; -#endif - uint16_t __resved1; - } QEMU_PACKED; - uint32_t msi_data; - }; -}; - /* When IR is enabled, all MSI/MSI-X data bits should be zero */ #define VTD_IR_MSI_DATA (0) diff --git a/include/hw/i386/x86-iommu.h b/include/hw/i386/x86-iommu.h index 7c71fc7..2b22a57 100644 --- a/include/hw/i386/x86-iommu.h +++ b/include/hw/i386/x86-iommu.h @@ -22,6 +22,7 @@ #include "hw/sysbus.h" #include "hw/pci/pci.h" +#include "hw/pci/msi.h" #define TYPE_X86_IOMMU_DEVICE ("x86-iommu") #define X86_IOMMU_DEVICE(obj) \ @@ -35,6 +36,8 @@ typedef struct X86IOMMUState X86IOMMUState; typedef struct X86IOMMUClass X86IOMMUClass; +typedef struct X86IOMMUIrq X86IOMMUIrq; +typedef struct X86IOMMU_MSIMessage X86IOMMU_MSIMessage; typedef enum IommuType { TYPE_INTEL, @@ -78,6 +81,63 @@ struct X86IOMMUState { QLIST_HEAD(, IEC_Notifier) iec_notifiers; /* IEC notify list */ }; +/* Generic IRQ entry information when interrupt remapping is enabled */ +struct X86IOMMUIrq { + /* Used by both IOAPIC/MSI interrupt remapping */ + uint8_t trigger_mode; + uint8_t vector; + uint8_t delivery_mode; + uint32_t dest; + uint8_t dest_mode; + + /* only used by MSI interrupt remapping */ + uint8_t redir_hint; + uint8_t msi_addr_last_bits; +}; + +struct X86IOMMU_MSIMessage { + union { + struct { +#ifdef HOST_WORDS_BIGENDIAN + uint32_t __addr_head:12; /* 0xfee */ + uint32_t dest:8; + uint32_t __reserved:8; + uint32_t redir_hint:1; + uint32_t dest_mode:1; + uint32_t __not_used:2; +#else + uint32_t __not_used:2; + uint32_t dest_mode:1; + uint32_t redir_hint:1; + uint32_t __reserved:8; + uint32_t dest:8; + uint32_t __addr_head:12; /* 0xfee */ +#endif + uint32_t __addr_hi; + } QEMU_PACKED; + uint64_t msi_addr; + }; + union { + struct { +#ifdef HOST_WORDS_BIGENDIAN + uint16_t trigger_mode:1; + uint16_t level:1; + uint16_t __resved:3; + uint16_t delivery_mode:3; + uint16_t vector:8; +#else + uint16_t vector:8; + uint16_t delivery_mode:3; + uint16_t __resved:3; + uint16_t level:1; + uint16_t trigger_mode:1; +#endif + uint16_t __resved1; + } QEMU_PACKED; + uint32_t msi_data; + }; +}; + /** * x86_iommu_get_default - get default IOMMU device * @return: pointer to default IOMMU device @@ -110,4 +170,10 @@ void x86_iommu_iec_register_notifier(X86IOMMUState *iommu, void x86_iommu_iec_notify_all(X86IOMMUState *iommu, bool global, uint32_t index, uint32_t mask); +/** + * x86_iommu_irq_to_msi_message - Populate one MSIMessage from X86IOMMUIrq + * @X86IOMMUIrq: The IRQ information + * @out: Output MSI message + */ +void x86_iommu_irq_to_msi_message(X86IOMMUIrq *irq, MSIMessage *out); #endif