From patchwork Tue May 31 16:19:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 68948 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp2052278qge; Tue, 31 May 2016 09:21:29 -0700 (PDT) X-Received: by 10.237.49.66 with SMTP id 60mr3830342qtg.103.1464711689870; Tue, 31 May 2016 09:21:29 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id 79si25865113qhw.132.2016.05.31.09.21.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 31 May 2016 09:21:29 -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 1b7mOn-0005uQ-DA; Tue, 31 May 2016 16:20:09 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b7mOm-0005sQ-GW for xen-devel@lists.xen.org; Tue, 31 May 2016 16:20:08 +0000 Received: from [193.109.254.147] by server-12.bemta-14.messagelabs.com id CE/99-19610-7B9BD475; Tue, 31 May 2016 16:20:07 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA1VSb0gTcRjud3ebpzg5p+Xb0pJBRENXk/6o+GF g5AQ1DUMwyW55boP9627G+lIWpaBEWgQpljMzSo2ydGnOUrNMTZSMyA+aopiJSBFpWkp33jT7 fXre93ne93n48ZK4fEWiIBmng2GttFkp9SMG1Dnpke6W5Iy9/VNR0Xe/VxNapHvd+htLRZkSk 1Vvc56UGAcfLErtP7OcczersHy0oitCfiRBFeIw31uMCQWiriLwuLsIoZBTHQhc9b/4wpeUUj uhZuSFj4CDqVSoGlrCBYxTHLib6lZxEKWDSnfTKiZ4/cjLMYmAZVQS9EwWYQIGajv0vLnu7Qd CT9kkIe4B6JiexkVNODxbWJAKIYC6jGB55N3qgJxSwVBXh1QUJcNQa5uPKFrAoLaw1zt9GLoX lyQiMS6Fsk+1hFg0EXCvu85HVJlhuOwtv4rksQ48tyJETQtvV7WIi8UVAm53ubwDoTAxUY2JR DEBP76Oes0b/OCxZ8nr8U0C9W0jhDgCUNl3ARc9jkB+Y4rYjoK5FZdExFqYap/FSlB4+YYfKd /wIy6E1aJdHMOeYdjIA2o9azIYHRbaZI7UaPapLQzH0QbGTOs59Smb5Qnib2ET/5rRckl8J9p KYsrNMrs7OUMeoLflnDXSnDGbzTMzXCcKJUklyLhmngtkGQPjzDWZ+YNao4H0VwbLsgVaxtlp C2cyiFQviiTnb4w+xOSE1WZlFCEyQhBRgsiYZ11fsXaW71GYIkiG+FByfzvDWkyO//kZFEIiZ ZAsXtjib7I61p1m+BCYEMKYJIRw0P8oRT7aUpEdrNKFbxvbPXPQ+jw3tTHBEjecZbJ99qhONy i0dWFJ7bH7u+9/YVMORecd7Y+t2GHIzDrnSQxOsynmxo/1FXRS1wzmgJKAdAseU8Cct7Cll17 NPp3Be2NKE9JONOgrauM+RDQajvuqNf7ai/Ef1TWqguo7e/4MDCZOcI/ylARnpDUqnOXovwV9 08WRAwAA X-Env-Sender: Suravee.Suthikulpanit@amd.com X-Msg-Ref: server-2.tower-27.messagelabs.com!1464711604!42986890!1 X-Originating-IP: [207.46.100.84] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 17873 invoked from network); 31 May 2016 16:20:06 -0000 Received: from mail-by2on0084.outbound.protection.outlook.com (HELO na01-by2-obe.outbound.protection.outlook.com) (207.46.100.84) by server-2.tower-27.messagelabs.com with AES256-SHA256 encrypted SMTP; 31 May 2016 16:20: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=8qPmMPx5V17yvpNrcmrlYzHrGo/UCswJDJ1LCNJDXxo=; b=WnajnLT1vURm9XrZ2MGMIIN7ybf6A8V9uFK/Zu5yfXqKovYW4zFi7GUW9FFq2ur5PmpKvskxu0D523j73qw+79rJIO5njWAljaJ0oDldkUNFk06Pr5HuX5pAaaTQ72NC++PDq0UZHZftMAWU/KYfTmsvQYq/lbw8zSJLbDvgbVE= Received: from ssuthiku-cz-dev.amd.com (165.204.77.1) by CY1PR12MB0444.namprd12.prod.outlook.com (10.163.91.22) with Microsoft SMTP Server (TLS) id 15.1.506.9; Tue, 31 May 2016 16:19:57 +0000 From: To: , , Date: Tue, 31 May 2016 11:19:41 -0500 Message-ID: <1464711581-2495-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: CY1PR14CA0033.namprd14.prod.outlook.com (10.163.13.171) To CY1PR12MB0444.namprd12.prod.outlook.com (10.163.91.22) X-MS-Office365-Filtering-Correlation-Id: a02de19c-29b8-469b-a09d-08d3896f6b40 X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0444; 2:O724eMZS9vc7F4KoiNMhDF3XO7oZ5VNNsAjpUm0A1FO/IowI+SkMKVCfz9c4yCfTQWPPs6Q29Cl6q0b52YubDSZbdAHqqz4V7ezLyf7Qj3+2SB49Nfw0NKopiR4fu0lkQzDhPWj/5xm6tHs/9CpsoQ6av5W8YRv4FIMm27xzi+UWkutEuDsr9j9i4wkKW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R12MB0444; 20:2eQSoldBsQIuFkhGCFdOyGYT8U2qa1LlNDBvf2VPPy2OgX/q+TTlE4Tym9UYpQXFS/83qtbA5/HG9kirku3AyDcXke4jxlR/CGms7UOcjeQhe8gq5X4UZgPNKxEoN+gg+FreKU3Yhbnpbb1HUJCZYQBdii3EwHRWgz/rz8IepwmrLCpBEpKeKR9bt3RzzGZT5xt4PvY2NNduTuJj3WYL2iI4dXucNEd2yw+jn033VC7C62G5rOzLVSQNpH9+fIvgJP+FSRPObKgL3o/kjFCGir3+FGiHaM5+JG/+aQe8THSwEtI15oB/TgHSCHR6mg9Dx5i7S5QjlvSOYPk0bEH+Cb/QHXRqXeHQIgaZ4xbvbgmmgQEHMzbDaMyky/VBiMR6Edp7uxJsmYPsedekmzGHSiXuTGwRH7yOsr/Kk4VYqs0ETlgHo5xVI5RN5qp6d/XNTKCiO46rXlSZt3Xm38NReHhbstsEFktnc/lKlgbfdvy2nsVgi4C9RRR6LEw8K1wg X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110)(70601490899591); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026); SRVR:CY1PR12MB0444; BCL:0; PCL:0; RULEID:; SRVR:CY1PR12MB0444; X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0444; 4:zYQEPfulaD/vspRKd9EHwGpogPhlWgCJdv4idaMtDTB24Mc4EkRu3wLn+CF3lW0Kc/Mc2p3uFmFx396XjyaFBLwn22MRPQY1iBvsbbaROAPdO9mY274Cah++A9zil1areCVAfa5ZTZujTK54QOAKEa1cDILrLqZiFzzVJEu2LrgCZHPuPgWjluCl5p3bbC+Hg5Aqy3Ly+xFg8Y/ybKoxlsjKir5oZ8fu5Cr5BsDZYK3u23F7NCDE3CWp2eb20Xj8rjRkbN5nRzJ1panad4wDKfz8dykGH88NhV+vQ2HXls2tsJeX4G8x31DNzCFcDGxE2310l/Nf2C95vYyyMSIAZbsZZSy3N8QeaTiwrYZl6AXRGNnW+Fkc8Y6laAVjA/CXGZ1oUodlR7YCBhjy/pDOVT5cbbsf2c9tVIgi/TtH0moDAPt9nJfr7TndXddCQw0jXzMKyTEKJ65jMhdDgfTfYA== X-Forefront-PRVS: 095972DF2F X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(5001770100001)(189998001)(229853001)(5003940100001)(5008740100001)(8666004)(53416004)(42186005)(36756003)(33646002)(92566002)(3846002)(5004730100002)(2201001)(81166006)(86152002)(4326007)(8676002)(6116002)(15975445007)(2906002)(2876002)(77096005)(586003)(19580395003)(19580405001)(86362001)(48376002)(66066001)(50986999)(50466002)(50226002)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR12MB0444; H:ssuthiku-cz-dev.amd.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR12MB0444; 23:ZJJa2zi82/+ByuVnEv4QqsYkKYbmtWi19p2p9NTpj?= =?us-ascii?Q?iCAfCASVZgIyuoxLIBLBszX2D8eM5kjxLkDSRbA6kahQeb3f9NDR1MbBc0UE?= =?us-ascii?Q?QgnNX1RUlYv1onQP54HEPX+uhhRRZZLAwXFvpFzdKkPWHyvUkxjq/ERPN69D?= =?us-ascii?Q?seAWnyJoaUJC3KXBmmBPAChZCoz5HFzUK16/1DsuEsB0BTh4yTnejMNSkeco?= =?us-ascii?Q?UzvVsok9VC6qtzKOoXhphs1tbhuhSFKNhV2r10/tYNdjATtJxNAn0mcQ+p25?= =?us-ascii?Q?JwmYDB3QVmCWaOtFejWpN97GUIOcqRpUkx54MzUmUzJomlXopPi9uAXTvRQ8?= =?us-ascii?Q?3SYk9EYn6fjfDd7+EAYAPyM/qdE2K9vk49MVaVxXZDYRFNbOkUwYSHUqAqwt?= =?us-ascii?Q?uOmInFXNMBj+UPsNnsd03qcRxyvn8mrae/CIkGRuQlGX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8zcb2Mc8TlbLpktdnS1CHL7heq7VXXFodBVpSOSF0NpCNjhTCQlGpZFEldvFV1g0/0bNfTbt8wPgQ=; 20:nKrg2Xl72aLeRlklD2uYORRFHyIISHVRMoEmLXRUNloARnwuADf5broO4715Ptx43ynj6NRaKrvHTXwXqlzmWb9lWQgVMAW9ncZoFzayib3Q/4qzdjNEdFv+wE3jLqfnbCSTvd26pyu0pEndmuq97fPFmRBEaThlBNay6xwyLPxCIrsLWacxB9dWDLME2ZaiOY//v80lSYxcAP/JgK/kRdDDtG32WlpY2hiKP56fmWDvbm4/b35ZvKfkuPXVTq18 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2016 16:19:57.0017 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR12MB0444 Cc: Suravee Suthikulpanit Subject: [Xen-devel] [PATCH v4] 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 Reviewed-by: Jan Beulich Reviewed-by: Andrew Cooper Signed-off-by: Suravee Suthikulpanit --- Changes from V3: * Minor stray space changes. * Getting rid of unnecessary default case in swtich statement. * Adding reviewed by Jan and Andrew. Thanks all for review comments. Suravee xen/drivers/passthrough/amd/iommu_acpi.c | 134 +++++++++++++++++--------- 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, 106 insertions(+), 45 deletions(-) diff --git a/xen/drivers/passthrough/amd/iommu_acpi.c b/xen/drivers/passthrough/amd/iommu_acpi.c index 603c02e..200db2d 100644 --- a/xen/drivers/passthrough/amd/iommu_acpi.c +++ b/xen/drivers/passthrough/amd/iommu_acpi.c @@ -821,13 +821,27 @@ 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); + } + 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 +859,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 +928,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 +964,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 +1015,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 +1091,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 +1108,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)) ) { @@ -1181,11 +1188,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; @@ -1211,8 +1216,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);