From patchwork Thu May 26 02:50:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 9136495 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 07624607D3 for ; Thu, 26 May 2016 02:53:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF4AE27EE9 for ; Thu, 26 May 2016 02:53:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E3AB928195; Thu, 26 May 2016 02:53:43 +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=-4.1 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id ABCD827EE9 for ; Thu, 26 May 2016 02:53:42 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b5lOA-0007ax-3J; Thu, 26 May 2016 02:51:10 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b5lO8-0007an-Hb for xen-devel@lists.xen.org; Thu, 26 May 2016 02:51:08 +0000 Received: from [85.158.137.68] by server-15.bemta-3.messagelabs.com id F2/B5-16725-B9466475; Thu, 26 May 2016 02:51:07 +0000 X-Brightmail-Tracker: H4sIA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IP: [65.55.169.81] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.34; banners=-,-,- X-VirusChecked: Checked Received: (qmail 27190 invoked from network); 26 May 2016 02:51:06 -0000 Received: from mail-bl2on0081.outbound.protection.outlook.com (HELO na01-bl2-obe.outbound.protection.outlook.com) (65.55.169.81) by server-8.tower-31.messagelabs.com with AES256-SHA256 encrypted SMTP; 26 May 2016 02:51:06 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=OZRHylS9VRbJ8UfXPPa2iKTWNrhYSGgxqvhkvoAFLRg=; b=Io0KymdAU8FBvU49mHwL4oeAlgdm39DQxNorqTetA1iZLAbXRLPg6U5QMQqneatwoKQG8I/kxAXKgaCxHiOc8LYlDx5/7dPnQQ+G+Rw2uBbgLFVjg6Vo+EUiYQwOn19TfU8jKdCX6ywqnEVuEKEuK2d3TdctOVPiUyhNe9H8+SA= Received: from ssuthiku-cz-dev.amd.com (165.204.77.1) by SN1PR12MB0448.namprd12.prod.outlook.com (10.162.105.141) with Microsoft SMTP Server (TLS) id 15.1.501.7; Thu, 26 May 2016 02:50:57 +0000 From: To: , Date: Wed, 25 May 2016 21:50:47 -0500 Message-ID: <1464231047-11223-1-git-send-email-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN1PR01CA0011.prod.exchangelabs.com (10.165.224.21) To SN1PR12MB0448.namprd12.prod.outlook.com (10.162.105.141) X-MS-Office365-Filtering-Correlation-Id: 7c34419e-55a3-4da6-3136-08d38510932c X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0448; 2:z8K5XYcuActJK+tSPvpZn1Uf4gPHONzuGv6b644pA22trCgCP86sYHgKQo/xOZc7gmBWE1U2N9rikHbr6FNUWOj9Nn31s8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PXAXGOgq2IY+UZF4jOApiSne43F5IG/RdLe5OKXs88mrsZg+Klhf68ohj9H+4Nf1nyMcZx9l0F15vae8q6Tai0AjRLbRrt4Vr51hvoDvgUvgAZEzjgpdId+CkbZleOfyG2jKm5pcOuTdr/np33npdkakATHxYuBn+e18c/IC7pabG5fXYv3OZQqCcxAlWScE1lGQdbibT; 4:V3SHA3jlsUIrubHTS57aMAs+qIJfVUfJqc7CYnpQ37T/0+p/vMVfkfClRWT0mAFY0Acy+XkFm584PeF8H+iZl9+5aK0BIIyJ60ZC0EJG8GEozia5ExbRQsOnRiO95b2VOiEh0qxAbmul4k3vL2ZcFVYN1v93yl26p/aevwm7r2C0PaZZVTnu1VYW3MiigxTGUWtohpHlFhIjqeSWekaUTJl7mehmnjH1Zv7poDSnVWGkyum0NgOYXd4KI+DV7XKpX6YXOIWPvvH485/4awf6WCN8BrdznFSp0XfDQj/T6ATUIqQf47clHOGuSgn/CbO2ii7VQ0S25irI7QRvGoRtsv+bPLSzlF3g0UUyFViPcp0F7lBqaFPvOZhpNQKbrYuRloKbnwkj/j7rwVxWwB6m+dR6OuGgzH8mJvUNmDaov3A= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026); SRVR:SN1PR12MB0448; BCL:0; PCL:0; RULEID:; SRVR:SN1PR12MB0448; X-Forefront-PRVS: 0954EE4910 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(243025005)(48376002)(50466002)(5001770100001)(81166006)(50226002)(33646002)(8666003)(92566002)(5004730100002)(8676002)(15975445007)(5003940100001)(86362001)(50986999)(189998001)(2906002)(229853001)(53416004)(47776003)(77096005)(3846002)(6116002)(19580405001)(2876002)(19580395003)(36756003)(5008740100001)(4326007)(42186005)(586003)(66066001)(86152002)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0448; H:ssuthiku-cz-dev.amd.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN1PR12MB0448; 23:t6LZb2CfYgw6HuN7Da20YUuCbiRJQKxk12556I2aF?= =?us-ascii?Q?qX+t/4M7O8RJx5RGVuPFRBJDWwIUhNyb3CU11QebCz/Igro2XP66tki+RJk1?= =?us-ascii?Q?6g+nmklcEo3SiWcTql3IC/bmU/NlEjo5L3fqpOmoF/a3xyv8Vk/U43ZuiS1w?= =?us-ascii?Q?pCjdXgQnMaDazlGBAo9x2kG6m/qssc9Xv8FG1aN8yN3/4tmRvg7Ts+e4Ffai?= =?us-ascii?Q?MpND5sapueCE2IxDPl7+waef/65KIQubCrj4C78JP4rdW3HTZ4iHAhiv7CDj?= =?us-ascii?Q?6e8bmwtJz7IB2I53ooXiCvEmnk7BT5aSBnuzKHcjhdvMP20q25oxrw4KXa3+?= =?us-ascii?Q?CBR0/xZ6JChOQ1/7sJ0Mc7eHJ6uNACx0MlSJ1jfLH6he/2kMbphAye1ujrqf?= =?us-ascii?Q?2UE7EH7NzUjWq0IsReCfTFlKrZt+b0L9GjwMVrrY/vxVgmAMcx37ZhpgF7CC?= =?us-ascii?Q?WIO7uzri7GnzquKnLxzOKGHlM49RJo7g3EAol6En1QSzUakCUfh0BL9p3LLy?= =?us-ascii?Q?l1uZpUsADlOCyMjDOSeuHAeXQ5881VhS1AqTnhx7bCQrh28+RzWgGQQXuAxX?= =?us-ascii?Q?SpFM3z/9ONAzWbeilu7nQnFyL4SxkNC7+m18jIlMg1CEe/mePdWm5M2pJDYE?= =?us-ascii?Q?NTQ3ZdQOfQgZU6trelQ/jBBSqle47TldIFuLCNtH4eGl3j12S/SRhFKv8kkY?= =?us-ascii?Q?/JYgBTreoRRYWkPjoQFVe7xB4pWANG3mqT5LCinJRw3S/ufWFTq5IABwhzuP?= =?us-ascii?Q?/KHWI/8cTC/EH0RcCHx9mfSveiqcDJarQ1ndT5jcAL/2qbgvkPNanIkZVyOh?= =?us-ascii?Q?FuGyZDNJbe03HsqibbOPv0hyll7ig1TvYveP48b57QrEcJ/B0YHj9R3EVrjv?= =?us-ascii?Q?jWGMJ+IjMDLldyKZv4ZKM6IWU2pLZTWw/+uTNGsIblfwO1qh7PyHPCL1YbNW?= =?us-ascii?Q?EigoRPQNzd70Pr7Osybsin67uLb6sx421lQNoWlMmqIDtGokP5Y9LQ+C70nG?= =?us-ascii?Q?gE=3D?= X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0448; 5:ybXhY3Rayo2IMbczugd5D1D6OwB5AJSS3aSvsLyp00BaFu9NxIUWg4zpX3vJyMm+L7FS1PcHcCJtt/gh3gPSJh4sqxD9OfWob0GDzU6prfbMfFUCQOmOORObcM+DE6tGTfWmtSh+0f8J6CbqV31IvQ==; 24:wG6U3EktozxAhnk5NWSl6N7QFEMr87uDDki7cgWf+nC4sn5mTW85doJTGBXfKqfV72FLQyRQx8CXkFrHkjMYmNi7mBxDZh8/fx+SBvI7Hnk=; 7:Yd8kNHNH4XlB5561NMDHry0VFg75WqjnzJO+nWTAvnvwKieP/zgV9PtNE1mpWOhj+lfnhCGnzaHCJF6KS5d189D3r+pxzAsxfneeXhRASws7SJdSGQyug21p1Gxnh/Xz4uFg7cIst3VY32gt+Xfc0OA8Sby7VhHdpl6nwEhXEOk=; 20:0oFkVH4WkkzAgXYawaGRVUtcxM41bxIbEZVVKEvvxlTUKpqla8Oo5hLBPx4qnrya2JTwqWAss7IhJUppDY1tJrDtbjC9c5W5wq2+599Kerd6stPiOj4AdIf65FGz4+L4lNHTx98KEHrNMJDJB3VpsThBHP42CyhkNPZpt/JPXARYQix7RuOGN5uHh1P/uYmkcd8mblvw1WbwfoPuuKOC5bGbiBmoe6ARPRWgRqE7lwaaZVmflmlhpd4ing4nyyzC X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 May 2016 02:50:57.2456 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0448 Cc: andrew.cooper3@citrix.com, Suravee Suthikulpanit Subject: [Xen-devel] [PATCH v3] AMD IOMMU: Introduce support for IVHD block type 11h X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Suravee Suthikulpanit Along with the IVHD block type 10h, newer AMD platforms also come with types 11h, which is a superset of the older one. Having multiple IVHD block types in the same platform allows backward compatibility of newer systems to work with existing drivers. The driver should only parse the highest-level (newest) type of IVHD block that it can support. However, the current driver returns error when encounters with unknown IVHD block type. This causes existing driver to unnecessarily fail IOMMU initialization on new systems. This patch introduces a new logic, which scans through IVRS table looking for the highest-level supporsted IVHD block type. It also adds support for the new IVHD block type 11h. More information about the IVHD type 11h can be found in the AMD I/O Virtualization Technology (IOMMU) Specification rev 2.62. http://support.amd.com/TechDocs/48882_IOMMU.pdf Signed-off-by: Suravee Suthikulpanit Reviewed-by: Andrew Cooper with two minor Reviewed-by: Jan Beulich --- Changes from V2: * Remove redundant IVHD_HIGHEST_SUPPORT_TYPE. * Misc clean up suggestions from Andrew. xen/drivers/passthrough/amd/iommu_acpi.c | 136 ++++++++++++++++++-------- xen/drivers/passthrough/amd/iommu_init.c | 10 +- xen/include/acpi/actbl2.h | 5 +- xen/include/asm-x86/amd-iommu.h | 1 + xen/include/asm-x86/hvm/svm/amd-iommu-proto.h | 1 + 5 files changed, 108 insertions(+), 45 deletions(-) diff --git a/xen/drivers/passthrough/amd/iommu_acpi.c b/xen/drivers/passthrough/amd/iommu_acpi.c index 79c1f8c..8bad2bc 100644 --- a/xen/drivers/passthrough/amd/iommu_acpi.c +++ b/xen/drivers/passthrough/amd/iommu_acpi.c @@ -821,13 +821,29 @@ static u16 __init parse_ivhd_device_special( return dev_length; } +static inline size_t +get_ivhd_header_size(const struct acpi_ivrs_hardware *ivhd_block) +{ + switch ( ivhd_block->header.type ) + { + case ACPI_IVRS_TYPE_HARDWARE: + return offsetof(struct acpi_ivrs_hardware, efr_image); + case ACPI_IVRS_TYPE_HARDWARE_11H: + return sizeof(struct acpi_ivrs_hardware); + default: + break; + } + return 0; +} + static int __init parse_ivhd_block(const struct acpi_ivrs_hardware *ivhd_block) { const union acpi_ivhd_device *ivhd_device; u16 block_length, dev_length; + size_t hdr_size = get_ivhd_header_size(ivhd_block) ; struct amd_iommu *iommu; - if ( ivhd_block->header.length < sizeof(*ivhd_block) ) + if ( ivhd_block->header.length < hdr_size ) { AMD_IOMMU_DEBUG("IVHD Error: Invalid Block Length!\n"); return -ENODEV; @@ -845,7 +861,7 @@ static int __init parse_ivhd_block(const struct acpi_ivrs_hardware *ivhd_block) } /* parse Device Entries */ - block_length = sizeof(*ivhd_block); + block_length = hdr_size; while ( ivhd_block->header.length >= (block_length + sizeof(struct acpi_ivrs_de_header)) ) { @@ -914,34 +930,6 @@ static int __init parse_ivhd_block(const struct acpi_ivrs_hardware *ivhd_block) return 0; } -static int __init parse_ivrs_block(const struct acpi_ivrs_header *ivrs_block) -{ - const struct acpi_ivrs_hardware *ivhd_block; - const struct acpi_ivrs_memory *ivmd_block; - - switch ( ivrs_block->type ) - { - case ACPI_IVRS_TYPE_HARDWARE: - ivhd_block = container_of(ivrs_block, const struct acpi_ivrs_hardware, - header); - return parse_ivhd_block(ivhd_block); - - case ACPI_IVRS_TYPE_MEMORY_ALL: - case ACPI_IVRS_TYPE_MEMORY_ONE: - case ACPI_IVRS_TYPE_MEMORY_RANGE: - case ACPI_IVRS_TYPE_MEMORY_IOMMU: - ivmd_block = container_of(ivrs_block, const struct acpi_ivrs_memory, - header); - return parse_ivmd_block(ivmd_block); - - default: - AMD_IOMMU_DEBUG("IVRS Error: Invalid Block Type!\n"); - return -ENODEV; - } - - return 0; -} - static void __init dump_acpi_table_header(struct acpi_table_header *table) { int i; @@ -978,6 +966,25 @@ static void __init dump_acpi_table_header(struct acpi_table_header *table) } +#define to_ivhd_block(hdr) \ + container_of(hdr, const struct acpi_ivrs_hardware, header) +#define to_ivmd_block(hdr) \ + container_of(hdr, const struct acpi_ivrs_memory, header) + +static inline bool_t is_ivhd_block(u8 type) +{ + return ( type == ACPI_IVRS_TYPE_HARDWARE || + type == ACPI_IVRS_TYPE_HARDWARE_11H ); +} + +static inline bool_t is_ivmd_block(u8 type) \ +{ + return ( type == ACPI_IVRS_TYPE_MEMORY_ALL || + type == ACPI_IVRS_TYPE_MEMORY_ONE || + type == ACPI_IVRS_TYPE_MEMORY_RANGE || + type == ACPI_IVRS_TYPE_MEMORY_IOMMU ); +} + static int __init parse_ivrs_table(struct acpi_table_header *table) { const struct acpi_ivrs_header *ivrs_block; @@ -1010,7 +1017,10 @@ static int __init parse_ivrs_table(struct acpi_table_header *table) return -ENODEV; } - error = parse_ivrs_block(ivrs_block); + if ( ivrs_block->type == ivhd_type ) + error = parse_ivhd_block(to_ivhd_block(ivrs_block)); + else if ( is_ivmd_block (ivrs_block->type) ) + error = parse_ivmd_block(to_ivmd_block(ivrs_block)); length += ivrs_block->length; } @@ -1083,9 +1093,7 @@ static int __init detect_iommu_acpi(struct acpi_table_header *table) if ( table->length < (length + ivrs_block->length) ) return -ENODEV; if ( ivrs_block->type == ACPI_IVRS_TYPE_HARDWARE && - amd_iommu_detect_one_acpi( - container_of(ivrs_block, const struct acpi_ivrs_hardware, - header)) != 0 ) + amd_iommu_detect_one_acpi(to_ivhd_block(ivrs_block)) != 0 ) return -ENODEV; length += ivrs_block->length; } @@ -1102,15 +1110,16 @@ static int __init get_last_bdf_ivhd( { const union acpi_ivhd_device *ivhd_device; u16 block_length, dev_length; + size_t hdr_size = get_ivhd_header_size(ivhd_block) ; int last_bdf = 0; - if ( ivhd_block->header.length < sizeof(*ivhd_block) ) + if ( ivhd_block->header.length < hdr_size ) { AMD_IOMMU_DEBUG("IVHD Error: Invalid Block Length!\n"); return -ENODEV; } - block_length = sizeof(*ivhd_block); + block_length = hdr_size; while ( ivhd_block->header.length >= (block_length + sizeof(struct acpi_ivrs_de_header)) ) { @@ -1177,11 +1186,9 @@ static int __init get_last_bdf_acpi(struct acpi_table_header *table) ivrs_block = (struct acpi_ivrs_header *)((u8 *)table + length); if ( table->length < (length + ivrs_block->length) ) return -ENODEV; - if ( ivrs_block->type == ACPI_IVRS_TYPE_HARDWARE ) + if ( ivrs_block->type == ivhd_type ) { - int ret = get_last_bdf_ivhd( - container_of(ivrs_block, const struct acpi_ivrs_hardware, - header)); + int ret = get_last_bdf_ivhd(to_ivhd_block(ivrs_block)); if ( ret < 0 ) return ret; @@ -1207,8 +1214,51 @@ int __init amd_iommu_get_ivrs_dev_entries(void) int __init amd_iommu_update_ivrs_mapping_acpi(void) { - if ( unlikely(acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_MSI) ) - return -EPERM; - return acpi_table_parse(ACPI_SIG_IVRS, parse_ivrs_table); } + +static int __init +get_supported_ivhd_type(struct acpi_table_header *table) +{ + size_t length = sizeof(struct acpi_table_ivrs); + const struct acpi_ivrs_header *ivrs_block, *blk = NULL; + + while ( table->length > (length + sizeof(*ivrs_block)) ) + { + ivrs_block = (struct acpi_ivrs_header *)((u8 *)table + length); + + if ( table->length < (length + ivrs_block->length) ) + { + AMD_IOMMU_DEBUG("IVRS Error: " + "Table Length Exceeded: %#x -> %#lx\n", + table->length, + (length + ivrs_block->length)); + return -ENODEV; + } + + if ( is_ivhd_block(ivrs_block->type) && + (!blk || blk->type < ivrs_block->type) ) + { + AMD_IOMMU_DEBUG("IVRS Block: Found type %#x flags %#x len %#x id %#x\n", + ivrs_block->type, ivrs_block->flags, + ivrs_block->length, ivrs_block->device_id); + blk = ivrs_block; + } + length += ivrs_block->length; + } + + if ( !blk ) + { + printk(XENLOG_ERR "Cannot find supported IVHD type.\n"); + return -ENODEV; + } + + AMD_IOMMU_DEBUG("Using IVHD type %#x\n", blk->type); + + return blk->type; +} + +int __init amd_iommu_get_supported_ivhd_type(void) +{ + return acpi_table_parse(ACPI_SIG_IVRS, get_supported_ivhd_type); +} diff --git a/xen/drivers/passthrough/amd/iommu_init.c b/xen/drivers/passthrough/amd/iommu_init.c index 4536106..ba505c3 100644 --- a/xen/drivers/passthrough/amd/iommu_init.c +++ b/xen/drivers/passthrough/amd/iommu_init.c @@ -35,6 +35,7 @@ static int __initdata nr_amd_iommus; static struct tasklet amd_iommu_irq_tasklet; unsigned int __read_mostly ivrs_bdf_entries; +u8 __read_mostly ivhd_type; static struct radix_tree_root ivrs_maps; struct list_head amd_iommu_head; struct table_struct device_table; @@ -1232,8 +1233,15 @@ int __init amd_iommu_init(void) amd_sp5100_erratum28() ) goto error_out; - ivrs_bdf_entries = amd_iommu_get_ivrs_dev_entries(); + /* We implies no IOMMU if ACPI indicates no MSI. */ + if ( unlikely(acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_MSI) ) + goto error_out; + ivhd_type = amd_iommu_get_supported_ivhd_type(); + if ( ivhd_type < 0 ) + goto error_out; + + ivrs_bdf_entries = amd_iommu_get_ivrs_dev_entries(); if ( !ivrs_bdf_entries ) goto error_out; diff --git a/xen/include/acpi/actbl2.h b/xen/include/acpi/actbl2.h index 4341a30..d2327d2 100644 --- a/xen/include/acpi/actbl2.h +++ b/xen/include/acpi/actbl2.h @@ -589,6 +589,7 @@ struct acpi_ivrs_header { enum acpi_ivrs_type { ACPI_IVRS_TYPE_HARDWARE = 0x10, + ACPI_IVRS_TYPE_HARDWARE_11H = 0x11, ACPI_IVRS_TYPE_MEMORY_ALL /* _MEMORY1 */ = 0x20, ACPI_IVRS_TYPE_MEMORY_ONE /* _MEMORY2 */ = 0x21, ACPI_IVRS_TYPE_MEMORY_RANGE /* _MEMORY3 */ = 0x22, @@ -622,7 +623,9 @@ struct acpi_ivrs_hardware { u64 base_address; /* IOMMU control registers */ u16 pci_segment_group; u16 info; /* MSI number and unit ID */ - u32 reserved; + u32 iommu_attr; + u64 efr_image; /* Extd feature register */ + u64 reserved; }; /* Masks for Info field above */ diff --git a/xen/include/asm-x86/amd-iommu.h b/xen/include/asm-x86/amd-iommu.h index e9fa9c2..4ad9bff 100644 --- a/xen/include/asm-x86/amd-iommu.h +++ b/xen/include/asm-x86/amd-iommu.h @@ -126,6 +126,7 @@ struct ivrs_mappings { }; extern unsigned int ivrs_bdf_entries; +extern u8 ivhd_type; struct ivrs_mappings *get_ivrs_mappings(u16 seg); int iterate_ivrs_mappings(int (*)(u16 seg, struct ivrs_mappings *)); diff --git a/xen/include/asm-x86/hvm/svm/amd-iommu-proto.h b/xen/include/asm-x86/hvm/svm/amd-iommu-proto.h index 9c51172..e6065d3 100644 --- a/xen/include/asm-x86/hvm/svm/amd-iommu-proto.h +++ b/xen/include/asm-x86/hvm/svm/amd-iommu-proto.h @@ -42,6 +42,7 @@ struct acpi_ivrs_hardware; /* amd-iommu-detect functions */ int amd_iommu_get_ivrs_dev_entries(void); +int amd_iommu_get_supported_ivhd_type(void); int amd_iommu_detect_one_acpi(const struct acpi_ivrs_hardware *); int amd_iommu_detect_acpi(void); void get_iommu_features(struct amd_iommu *iommu);