From patchwork Tue Jan 26 23:14:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Wan X-Patchwork-Id: 60464 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp2033165lbb; Tue, 26 Jan 2016 07:36:47 -0800 (PST) X-Received: by 10.67.2.10 with SMTP id bk10mr33776254pad.26.1453822606910; Tue, 26 Jan 2016 07:36:46 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id by6si1585899pad.69.2016.01.26.07.36.46; Tue, 26 Jan 2016 07:36:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966478AbcAZPgo (ORCPT + 30 others); Tue, 26 Jan 2016 10:36:44 -0500 Received: from mail-bl2on0083.outbound.protection.outlook.com ([65.55.169.83]:56064 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756480AbcAZPgh (ORCPT ); Tue, 26 Jan 2016 10:36:37 -0500 Received: from CY1PR12CA0078.namprd12.prod.outlook.com (10.163.230.46) by SN1PR12MB0863.namprd12.prod.outlook.com (10.164.27.13) with Microsoft SMTP Server (TLS) id 15.1.390.13; Tue, 26 Jan 2016 15:36:34 +0000 Received: from DM3NAM03FT047.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e49::202) by CY1PR12CA0078.outlook.office365.com (2a01:111:e400:c42b::46) with Microsoft SMTP Server (TLS) id 15.1.390.13 via Frontend Transport; Tue, 26 Jan 2016 15:36:34 +0000 Authentication-Results: spf=none (sender IP is 165.204.84.222) smtp.mailfrom=amd.com; 8bytes.org; dkim=none (message not signed) header.d=none; 8bytes.org; dmarc=permerror action=none header.from=amd.com; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from atltwp02.amd.com (165.204.84.222) by DM3NAM03FT047.mail.protection.outlook.com (10.152.83.124) with Microsoft SMTP Server id 15.1.390.12 via Frontend Transport; Tue, 26 Jan 2016 15:36:33 +0000 X-WSS-ID: 0O1KGOS-08-8N2-02 X-M-MSG: Received: from satlvexedge01.amd.com (satlvexedge01.amd.com [10.177.96.28]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by atltwp02.amd.com (Axway MailGate 5.3.1) with ESMTPS id 23A5AD23028; Tue, 26 Jan 2016 10:36:27 -0500 (EST) Received: from SATLEXCHOV02.amd.com (10.181.40.72) by satlvexedge01.amd.com (10.177.96.28) with Microsoft SMTP Server (TLS) id 14.3.195.1; Tue, 26 Jan 2016 09:36:43 -0600 Received: from SCYBEXDAG03.amd.com (10.34.11.13) by SATLEXCHOV02.amd.com (10.181.40.72) with Microsoft SMTP Server (TLS) id 14.3.266.1; Tue, 26 Jan 2016 09:36:30 -0600 Received: from viwan-emmc.amd.com (10.237.75.161) by SCYBEXDAG03.amd.com (10.34.11.13) with Microsoft SMTP Server id 14.3.266.1; Tue, 26 Jan 2016 23:36:26 +0800 From: Wan Zongshun To: Joerg Roedel , CC: Suravee Suthikulpanit , Borislav Petkov , Ray Huang , , , , Subject: [PATCH V2 1/8] iommu/amd: Modify ivhd_header structure to support type 11h and 40h Date: Tue, 26 Jan 2016 18:14:30 -0500 Message-ID: <1453850077-2539-2-git-send-email-vincent.wan@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1453850077-2539-1-git-send-email-vincent.wan@amd.com> References: <1453850077-2539-1-git-send-email-vincent.wan@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:165.204.84.222; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(428002)(189002)(199003)(4326007)(53416004)(19580405001)(50466002)(87936001)(2906002)(5001770100001)(92566002)(33646002)(86362001)(50226001)(1220700001)(1096002)(77096005)(11100500001)(229853001)(2950100001)(106466001)(19580395003)(48376002)(189998001)(97736004)(47776003)(36756003)(5003940100001)(586003)(5008740100001)(50986999)(105586002)(5003600100002)(76176999)(101416001); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0863; H:atltwp02.amd.com; FPR:; SPF:None; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0863; 2:K9W+VVyRcJTyNyufTEJpt6gi8Z3lUzlGejwq9HoVG7KsytqpDvI71vr7u5TwOHFXUMRjpbe8HkQXkwVhjpJAfdkxhxXtW4t2Be3OM7SQYuCRSjGZ+nXEcPrwZfspcpIXAE7Mxf+8GEb/sdAHOXtwbA==; 3:rWxMFeaDx1Y8PUkuFQr34n9szUvNjPgxHxsAoEjK9wR1xZ1EoJOOjM8ExFbluW35ys/oAWMDosBLdTnr4I5FrZr9K/E3+k29GO1FEWCxo/lUEhOdZRA/wvn5hPxsOgWOPBVrD4lGE/X1aMGx6DmnQBBAnghjpbummmI7Em9ohj/rMoDsmEkDDLNlpM1wfMFNrpjvm5GjvxSShz0P8v1aOV5Dou0eAE5iettLDkBC2rE=; 25:WvLL+j7+uq7eShScjH5vjAZwGMhzIEHa42S7Rw9ZwCobyISbL9fJ6xadmsqeQGxovLmMEA02DvNLPSRa3RG96eYNx08z6mRRTyNOAobN3GFKERpsOS+IphIcxfwm7s1ZXlkNImkZ/N9515TpuKWCbgez7KoV6yAO72wLp/MjKt7EUiI3yrkZBFW5sZr2eKJCnaFJLv/W7+L8DaZ/6Zp+fqVChAzqWROOxOJCxaWRTK1EHw752Ykuv5S5ejg1qYTU X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SN1PR12MB0863; X-MS-Office365-Filtering-Correlation-Id: d4bb9b65-c7b6-4330-64b6-08d326667850 X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0863; 20:H4xqipxacBtXI2qp3POPx2wmn1SgKbNDq/Y0F/KW3zZIYpY8N1sU+OAoLt0Jul+XoZ6L1/9L+L63UU5m1TXhoajoKO1k5aVCOA1Y21k0mQHvUw01FmpWSKSZt+q4sZYOYnt0gZONNub2VNJ8v7pJsbOEZs01B2WUtxlGgaZDzYBtY7rMW4cv4KH/0ecA3rIEXREps+eloyVotVvGYGWoF9wkeqhnVce8Pb82rsaCpSSwJVOJWzGooBIelco9uFY+wLIznBPIadthnM8wl+U1yQKZSBDn8Eb/C/vBDQF4+Ol11SvkUSkYlhRNg6VTw8TIVxwoO6pp+mz3QkV6WHmqsIfEKTpjrvo8fiHIkiN2ERrCrE1R2O4krqYipJxSKUXMoQQccRyafGJoLsbtnVrX4TB0oMT0Jc3yS+UeojAjjTwJwAwLXfhBS0PNJ3EaY6H05HZ9ZiN0FphTehSdxIHpjfk1pBO40tfOVDo/eaztFOvUKIC/c69PQ1IamKfdNFZQ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(123027)(601004)(2401047)(13018025)(13024025)(13015025)(5005006)(13023025)(13017025)(520078)(8121501046)(3002001)(10201501046); SRVR:SN1PR12MB0863; BCL:0; PCL:0; RULEID:; SRVR:SN1PR12MB0863; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0863; 4:0hBRlRD8cbQc0SDjxRhiXop1nMkQk9kthjxyOPRmtD3qP+PfZL23X3vqkI0sOlnejHpoGGQnGV2TbcqRtLlau9XZGEJmiJKDFuyq4MQxbbLoDKasrcSlWAGa/VvRjiuJRjYphZKTUhwpbAxMuigHVjNlemkQRjnNo0Kfx7CPRXa5/rAeLMg0pY8UlKzhwfNH7yO8fZFvz+ER6LzqpPJna+4QV+mJtN/caNEF11z5NFtlNg9RF0tNwQCj0Ru+palludE/UMkJ/1L1zyPCNwh7BCsaDCpS7Mctc5yZ0O01mra0XuSmGicabDG21d9WJau6UMcPdf4jQ8ydGkxAwWgDM/vfYj8p4LLNDoAcyEy3bPjchWJ1OTrneEcuhmEd3pc+TfVvWz1wPwugXdWlHCuw0QkXHep0WSeKPH7KTzDmI/bXT8V4jirwkEL2jvhKPD2SXHgB4TnoW+xStqu7O7Kvxlm8jHk3iSzeHascyTcgcfv1Vk/e2F7uGQpaQRPfHH9A0vcT/bd/pzuztAIJJZCfeA== X-Forefront-PRVS: 08331F819E X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN1PR12MB0863; 23:FIXx9zyipilIeEUMLHcn0YV8LJyhMkBb8JVG7zXkk?= =?us-ascii?Q?oxCUmGU42RpejEYirkdcqJzlEcdzLqz8fN2lv/7LkhqtpIlK3hJwJdjAExsO?= =?us-ascii?Q?mZG+m9JShfBja+juOngQhl6OYtuAXvCSHenE2c1nxknoRyuaBAIo4I7L55Pe?= =?us-ascii?Q?LNJmQTZNSfkbrBzdDGGJOZqQMJ9HLzoWLsqlTui67f0iUfbvuNmi8iK8iqUs?= =?us-ascii?Q?A2HuIO5eiV4M5ivP/+B9hb6DGndlMyhXu2vXovyd8pcMWf8eQSY8go3ykuJm?= =?us-ascii?Q?na33atGGKNALOtSltJQ7sA2CvLnUdreT+z89dcp6zKvtmAhzjnIwkqoA3GTC?= =?us-ascii?Q?6/wrVGzJ/V2zLMyMyfApPDFC8H1tPmJ1D/BNaQOv4Eyf/kW0ZDL3LcygoluD?= =?us-ascii?Q?GNODqJkeEBPHr+e13an5g5HrWIqtdrCkU7HwZrRGowW4M2ytLBeDRSLXam7L?= =?us-ascii?Q?dAQjCykKNdvhz4vZcxUbDCCGlwdo/VmpWeOEyZ1n/IdPSbWO/sIyjkyzL14D?= =?us-ascii?Q?2tpksIRmD5NEDrc5KyaCAxIuV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vht56GFK4CS1E2aX98N1A8DhQJbzN6Ws2TeOzUfbHSQsQ9Vq8Gut8Em5W9yg62AymFQbKxX3KpLW6iGoW SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2016 15:36:33.0957 (UTC) 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.222]; Helo=[atltwp02.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0863 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Suravee Suthikulpanit This patch modifies the existing struct ivhd_header, which currently only support IVHD type 0x10, to add new fields from IVHD type 11h and 40h. It also modifies the pointer calculation to allow support for IVHD type 11h and 40h Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd_iommu_init.c | 47 +++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) -- 1.9.1 diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c index 013bdff..2ff7000 100644 --- a/drivers/iommu/amd_iommu_init.c +++ b/drivers/iommu/amd_iommu_init.c @@ -88,7 +88,7 @@ /* * structure describing one IOMMU in the ACPI table. Typically followed by one - * or more ivhd_entrys. + * or more ivhd_entrys. This struct supports both IVHD type 10h, 11h and 40h. */ struct ivhd_header { u8 type; @@ -99,7 +99,11 @@ struct ivhd_header { u64 mmio_phys; u16 pci_seg; u16 info; - u32 efr; + u32 efr_attr; + + /* Following only valid on IVHD type 11h and 40h */ + u64 efr_reg_img; /* Exact copy of MMIO_EXT_FEATURES */ + u64 res; } __attribute__((packed)); /* @@ -399,6 +403,22 @@ static void __init iommu_unmap_mmio_space(struct amd_iommu *iommu) * ****************************************************************************/ +static inline u32 get_ivhd_header_size(struct ivhd_header *h) +{ + u32 size = 0; + + switch (h->type) { + case 0x10: + size = 24; + break; + case 0x11: + case 0x40: + size = 40; + break; + } + return size; +} + /* * This function calculates the length of a given IVHD entry */ @@ -415,8 +435,14 @@ static int __init find_last_devid_from_ivhd(struct ivhd_header *h) { u8 *p = (void *)h, *end = (void *)h; struct ivhd_entry *dev; + u32 ivhd_size = get_ivhd_header_size(h); + + if (!ivhd_size) { + pr_err("AMD-Vi: Unsupported IVHD type %#x\n", h->type); + return -EINVAL; + } - p += sizeof(*h); + p += ivhd_size; end += h->length; while (p < end) { @@ -781,6 +807,7 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu, u32 dev_i, ext_flags = 0; bool alias = false; struct ivhd_entry *e; + u32 ivhd_size; int ret; @@ -796,7 +823,13 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu, /* * Done. Now parse the device entries */ - p += sizeof(struct ivhd_header); + ivhd_size = get_ivhd_header_size(h); + if (!ivhd_size) { + pr_err("AMD-Vi: Unsupported IVHD type %#x\n", h->type); + return -EINVAL; + } + + p += ivhd_size; end += h->length; @@ -1047,9 +1080,9 @@ static int __init init_iommu_one(struct amd_iommu *iommu, struct ivhd_header *h) iommu->mmio_phys = h->mmio_phys; /* Check if IVHD EFR contains proper max banks/counters */ - if ((h->efr != 0) && - ((h->efr & (0xF << 13)) != 0) && - ((h->efr & (0x3F << 17)) != 0)) { + if ((h->efr_attr != 0) && + ((h->efr_attr & (0xF << 13)) != 0) && + ((h->efr_attr & (0x3F << 17)) != 0)) { iommu->mmio_phys_end = MMIO_REG_END_OFFSET; } else { iommu->mmio_phys_end = MMIO_CNTR_CONF_OFFSET;