From patchwork Fri May 13 19:54:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 67800 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp436386qge; Fri, 13 May 2016 12:56:31 -0700 (PDT) X-Received: by 10.55.71.146 with SMTP id u140mr18063863qka.14.1463169391037; Fri, 13 May 2016 12:56:31 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id u66si13019813qkd.259.2016.05.13.12.56.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 May 2016 12:56:31 -0700 (PDT) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@amdcloud.onmicrosoft.com; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b1JAn-0007TD-F5; Fri, 13 May 2016 19:54:57 +0000 Received: from mail6.bemta6.messagelabs.com ([85.158.143.247]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b1JAl-0007T7-GH for xen-devel@lists.xen.org; Fri, 13 May 2016 19:54:55 +0000 Received: from [85.158.143.35] by server-2.bemta-6.messagelabs.com id D5/C1-09532-E0136375; Fri, 13 May 2016 19:54:54 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA1WSW0gUURzGO7Ozu6M5Nq6Gf00lFyJa8RqY1EM SKCVZPYSGPeisTrsbe5GZtbZ8MShcLSgVBTdN0XLDTYswM7zAmgWaWraFouUlM9TEC2JKhjTj rGbz9P3P7zvf+Q5zCIliShpIMBYzwxppvVLmiVfGGVPDyejY1KhlW3Tcw6VaPB6dfNO6jp1Da VKdUW2yZEi1/R2DKLsowzK5YMfzkCupEHkSOJUvgbJqGxIGRN1F0NbchQuDgupCcLNyjCcehI w6AI++dsgF7UfFQKl1WCJoCcVB8wvHpvalEiC/uXHTj/P+9XYrJmiSSoaxkmGZoIEKge63JVJ x3Qe6y7/jYg6Ac3paInr2w8vVVZlQAqh8BPYRx+YGBaUCV5fTHZQMa20LEtFkl8Fi1R9MBIlQ 1tOCi2BADvfrrEgEeph64JCLWgWNn5fcu18hKHhsd8cGQd3GulQEt3CoX2lwF/klh4qhWrk4L EphyjHkzgWoenfDXf0svF767V6PgfmNaj6K4HU8jNuS7qEQ246L23ZcvBph9eggx7BXGDb8cI Sa1Wm0ZgOt04dHR8VGGBiOozWMnlZzEZkmw3PE//Jd/NeCrBsnOlEAgSn3klhYbKrCW23Kuqa lOW06m6NnuE4URBBKIBVRPPNhGQ1juaTT8+9mCwPhpfQjJQImuWzawOk0IupB4cSH0tEGTIEb TUYm0J+siORNlGDS5hi3I7Ze30cUHOhLIr6UwiubYQ068/98FvkTSOlLegtHeemM5u2TZvkSG F8idzBGKGGm/6HAPJRQuK9mJGwP1uvKWiltfa8eV813NbUVaT4l5jn7mvzmxvxGv5w+UtOrSH mS4SoIfXp5ZcL3kLwztziz9kf6T/va9fMpF/td6onjuZONM3H+Hkf7Mq8+c645DGzsctXutBl ERhbHhF6wNB8rUX0z3HYEnykfSF6bTOo+dWeuPS6AVeKclo5WSViO/gu5/jQYeAMAAA== X-Env-Sender: Suravee.Suthikulpanit@amd.com X-Msg-Ref: server-5.tower-21.messagelabs.com!1463169292!14159732!1 X-Originating-IP: [157.56.110.87] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.34; banners=-,-,- X-VirusChecked: Checked Received: (qmail 28142 invoked from network); 13 May 2016 19:54:53 -0000 Received: from mail-bn1on0087.outbound.protection.outlook.com (HELO na01-bn1-obe.outbound.protection.outlook.com) (157.56.110.87) by server-5.tower-21.messagelabs.com with AES256-SHA256 encrypted SMTP; 13 May 2016 19:54:53 -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=IofDPo0YXjA7ZcE01kmuA8JZsv99J9dD/2zTgYJm6YQ=; b=YS040V3IesTsIwPKwF611vrhKoOxfSe0jba7zVnlKnyZGRzQkrMdDvDgQp6Dn1f/v7uLeDwthbZksrsR1Txg8ArN9oNmTO5uEQfaQ5SJbY74QZA7rsG35Q+YFjr0HPz4VB6AZE+O1EgQBEF3fG0/QZzaKdK87n/08wmoYy4ucPc= Received: from ssuthiku-cz-dev.amd.com (165.204.77.1) by SN1PR12MB0445.namprd12.prod.outlook.com (10.162.105.139) with Microsoft SMTP Server (TLS) id 15.1.492.11; Fri, 13 May 2016 19:54:45 +0000 From: To: , Date: Fri, 13 May 2016 14:54:34 -0500 Message-ID: <1463169274-17225-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: CY1PR13CA0010.namprd13.prod.outlook.com (10.162.30.148) To SN1PR12MB0445.namprd12.prod.outlook.com (10.162.105.139) X-MS-Office365-Filtering-Correlation-Id: cd5914bc-b418-4ef9-36d3-08d37b687214 X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0445; 2:nkmgnTQtNx9qv6aVqQQ2PGNMGmOzC5BMzYgTw+V13uABfrQiEY1EnjOQewOeEZSf7OOT6g2xyH3uxrTw03uklbWg6GJctasl4AKSFe1WMPdCI49E9CjehZdIul3PS/L+PrO/GXolkISV255OqT4AkjdjMKTdFjxGEaGa8G8Bql2y74ZQyDXSGQYx0dPrncUt; 3:B5KHayZT3WRcUDU5sbrlIEJnNJO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NXUiw4f5U1bibBgYCJyZDIA26lX5TzMPRuXDUwL6POSg+W4+tGGkj+MUX; 4:PrMmrbc57keUi2pOj0Lsl3XFKLEJlVrQgNHA2eqpe7q4lGaslPG2CqwnsYOHj3wfjNpEKg6uMCY3rdjL4G4TxA6B0S2i9IpjSqUAX6fBceM6exX12KQLP0B1avm6UBNHfkAw5CwwjZu0YrL3G/VYD4ozZy1r9ehkfl0ppguSgzWoybq1uXoj/Cll025+GluNNWYFQg9yv2KsSraiq6Nr30W1gd/H/f/n+seFOhkbxsp3xVllBomC/0Shzu49XlnWJ9TKFApZsmMCU7DUyHjo7VLveLVDkZqpcMurD4zradkJISErR8yJ4VrelEdn/MVGiusXkXMaOOUXSj/LG2yCUT3hXTuEUj0YJvmt3g+xiWidBJxmDovtRXpxhoTJlL6gwZkSHlNQEdODSyqUqiqTgQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026); SRVR:SN1PR12MB0445; BCL:0; PCL:0; RULEID:; SRVR:SN1PR12MB0445; X-Forefront-PRVS: 0941B96580 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(243025005)(8676002)(4326007)(15975445007)(53416004)(47776003)(586003)(6116002)(42186005)(19580395003)(50226002)(77096005)(3846002)(5008740100001)(81166006)(2876002)(19580405001)(2906002)(86152002)(229853001)(48376002)(50466002)(33646002)(5004730100002)(86362001)(92566002)(36756003)(5001770100001)(50986999)(66066001)(5003940100001)(189998001); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0445; H:ssuthiku-cz-dev.amd.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0445; 23:4n87vrFjBHnTMf0Njm3eiLqVtXkLpyQtMRiwBAIGKDNCa3toQgahAZ/2UH/az2TO2CDK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5cEmHcoA==; 24:HCxPPL75Sdgl3J8PKBAe5/UTvwbUM1nT/leJ+g0Si3yHHf9WHHAKvFH+uMsaOeKaQ3AcqJRF94MQRggPzsqIJrKRCbAvWvv9Ifwad6n7lng=; 7:Q5dZ+BNgl91nl98XJLfVCOwqpMtfSjq6Os3cW29AaaUyW7pIsv2pZYcSyOtokyDloyVvf8ZkCgk2ZpsWTs+gW6FENhPJDgBoqGOOKSyKaf6fXjwhxC06VDLbYGjlhwjnSdSa1fZu5iUuRCnBOFdrlfvjClNQmLC7M/0TG7bgiFo=; 20:z3v9u4wF64vBFqeD/57NSpNe3nOdFWFUZZYVmkq6NcZ1J8qT2G/1NB1eLafh7OaaN7kHXlVI+FHt3Zs8d7f/DPn+VIDgN81tIDFa9T5jhw1Y4JONbYmQB/y9Ivpni6nKHTmsfxl03mXdBPkr8amHxujFOQFyxCzTw/HmgldMbTjiTEb6Ao8V33czYYNcygiilGXpM71HlSl8tCa4vJqzY/vXaIEP3XChFAN7LdLZyrEUyiTnIQOb4wqlyJl7aCbg X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 May 2016 19:54:45.5424 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0445 Cc: Suravee Suthikulpanit Subject: [Xen-devel] [PATCH] 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" 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 --- xen/drivers/passthrough/amd/iommu_acpi.c | 133 +++++++++++++++++--------- xen/drivers/passthrough/amd/iommu_init.c | 6 +- xen/include/acpi/actbl2.h | 7 +- xen/include/asm-x86/amd-iommu.h | 1 + xen/include/asm-x86/hvm/svm/amd-iommu-proto.h | 1 + 5 files changed, 103 insertions(+), 45 deletions(-) diff --git a/xen/drivers/passthrough/amd/iommu_acpi.c b/xen/drivers/passthrough/amd/iommu_acpi.c index 79c1f8c..2a2d61b 100644 --- a/xen/drivers/passthrough/amd/iommu_acpi.c +++ b/xen/drivers/passthrough/amd/iommu_acpi.c @@ -821,13 +821,23 @@ static u16 __init parse_ivhd_device_special( return dev_length; } +static inline int get_ivhd_header_size(const struct acpi_ivrs_hardware *ivhd_block) +{ + if ( ivhd_block->header.type == ACPI_IVRS_TYPE_HARDWARE) + return 24; + if ( ivhd_block->header.type == ACPI_IVRS_TYPE_HARDWARE_11H) + return 40; + 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; + int 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 +855,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)) ) { @@ -901,7 +911,7 @@ static int __init parse_ivhd_block(const struct acpi_ivrs_hardware *ivhd_block) ivhd_block->header.length, block_length, iommu); break; default: - AMD_IOMMU_DEBUG("IVHD Error: Invalid Device Type!\n"); + AMD_IOMMU_DEBUG("IVHD Error: %s: Invalid Device Type!\n", __func__); dev_length = 0; break; } @@ -914,34 +924,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 +960,21 @@ 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) ) + +#define is_ivhd_block(x) \ + ( x == ACPI_IVRS_TYPE_HARDWARE || \ + x == ACPI_IVRS_TYPE_HARDWARE_11H ) + +#define is_ivmd_block(x) \ + ( x == ACPI_IVRS_TYPE_MEMORY_ALL || \ + x == ACPI_IVRS_TYPE_MEMORY_ONE || \ + x == ACPI_IVRS_TYPE_MEMORY_RANGE || \ + x == 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 +1007,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 +1083,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 +1100,16 @@ static int __init get_last_bdf_ivhd( { const union acpi_ivhd_device *ivhd_device; u16 block_length, dev_length; + int 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)) ) { @@ -1153,7 +1152,7 @@ static int __init get_last_bdf_ivhd( dev_length = sizeof(ivhd_device->special); break; default: - AMD_IOMMU_DEBUG("IVHD Error: Invalid Device Type!\n"); + AMD_IOMMU_DEBUG("IVHD Error: %s: Invalid Device Type!\n", __func__); dev_length = 0; break; } @@ -1177,12 +1176,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; UPDATE_LAST_BDF(ret); @@ -1212,3 +1208,54 @@ int __init amd_iommu_update_ivrs_mapping_acpi(void) return acpi_table_parse(ACPI_SIG_IVRS, parse_ivrs_table); } + +static int __init +get_supported_ivhd_type(struct acpi_table_header *table) +{ + unsigned long 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) ) + { + 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); + if ( ivrs_block->type > IVHD_HIGHEST_SUPPORT_TYPE ) + break; + 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) +{ + if ( unlikely(acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_MSI) ) + return -EPERM; + + 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 d90a2d2..d76c993 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; +unsigned int __read_mostly ivhd_type; static struct radix_tree_root ivrs_maps; struct list_head amd_iommu_head; struct table_struct device_table; @@ -1233,8 +1234,11 @@ int __init amd_iommu_init(void) amd_sp5100_erratum28() ) goto error_out; - ivrs_bdf_entries = amd_iommu_get_ivrs_dev_entries(); + ivhd_type = amd_iommu_get_supported_ivhd_type(); + if ( !ivhd_type ) + 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 87bc6b3..694d87e 100644 --- a/xen/include/acpi/actbl2.h +++ b/xen/include/acpi/actbl2.h @@ -527,12 +527,15 @@ 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, ACPI_IVRS_TYPE_MEMORY_IOMMU = 0x23 }; +#define IVHD_HIGHEST_SUPPORT_TYPE ACPI_IVRS_TYPE_HARDWARE_11H + /* Masks for Flags field above for IVHD subtable */ #define ACPI_IVHD_TT_ENABLE (1) @@ -560,7 +563,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..722e729 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 unsigned int 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);