From patchwork Wed Mar 29 07:43:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vandrovec X-Patchwork-Id: 9651003 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 229356034B for ; Wed, 29 Mar 2017 07:58:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1432C283B9 for ; Wed, 29 Mar 2017 07:58:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0881F2845F; Wed, 29 Mar 2017 07:58:39 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5CF752845B for ; Wed, 29 Mar 2017 07:58:38 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1ct8V3-0001Qf-2f; Wed, 29 Mar 2017 07:58:37 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1ct8V2-0001Qa-BY for tpmdd-devel@lists.sourceforge.net; Wed, 29 Mar 2017 07:58:36 +0000 Received-SPF: pass (sog-mx-1.v43.ch3.sourceforge.com: domain of vmware.com designates 208.91.0.190 as permitted sender) client-ip=208.91.0.190; envelope-from=petr@vmware.com; helo=EX13-EDG-OU-002.vmware.com; Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]) by sog-mx-1.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1ct8V1-0003nQ-6o for tpmdd-devel@lists.sourceforge.net; Wed, 29 Mar 2017 07:58:36 +0000 Received: from sc9-mailhost2.vmware.com (10.113.161.72) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Wed, 29 Mar 2017 00:42:36 -0700 Received: from petr-dev3.eng.vmware.com (petr-dev2.eng.vmware.com [10.20.93.186]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id A799FB0649; Wed, 29 Mar 2017 00:43:23 -0700 (PDT) Received: by petr-dev3.eng.vmware.com (Postfix, from userid 884) id A101DA00211; Wed, 29 Mar 2017 00:43:23 -0700 (PDT) Date: Wed, 29 Mar 2017 00:43:23 -0700 From: Petr Vandrovec To: Peter Huewe Message-ID: <20170329074323.s6qkb7pk47jqa4q6@petr-dev3.eng.vmware.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170306 (1.8.0) Received-SPF: None (EX13-EDG-OU-002.vmware.com: petr@vmware.com does not designate permitted sender hosts) X-Headers-End: 1ct8V1-0003nQ-6o Cc: tpmdd-devel@lists.sourceforge.net Subject: [tpmdd-devel] [PATCH 1/4] Add log start/length fields to TPM2 table X-BeenThere: tpmdd-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Tpm Device Driver maintainance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: tpmdd-devel-bounces@lists.sourceforge.net X-Virus-Scanned: ClamAV using ClamSMTP From: Petr Vandrovec Latest revision of TPM 2.0 ACPI spec adds log start/length to the TPM2 table. Add them to our definition. As few places were using sizeof(TPM2) to make sure required fields are present, switch them to use length of table up to and including start type field, as that is what they are after. Also change SMC CRB handling to use TPM2 fields rather than offsets + typecasts. Signed-off-by: Petr Vandrovec --- drivers/char/tpm/tpm_crb.c | 15 +++------------ drivers/char/tpm/tpm_tis.c | 2 +- include/acpi/actbl2.h | 30 +++++++++++++++++++++++++----- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c index 72b03c328198..43bec842e013 100644 --- a/drivers/char/tpm/tpm_crb.c +++ b/drivers/char/tpm/tpm_crb.c @@ -110,14 +110,6 @@ struct crb_priv { u32 smc_func_id; }; -struct tpm2_crb_smc { - u32 interrupt; - u8 interrupt_flags; - u8 op_flags; - u16 reserved2; - u32 smc_func_id; -}; - /** * crb_go_idle - request tpm crb device to go the idle state * @@ -538,7 +530,7 @@ static int crb_acpi_add(struct acpi_device *device) status = acpi_get_table(ACPI_SIG_TPM2, 1, (struct acpi_table_header **) &buf); - if (ACPI_FAILURE(status) || buf->header.length < sizeof(*buf)) { + if (ACPI_FAILURE(status) || buf->header.length < ACPI_TPM2_SIZE_WITH_START) { dev_err(dev, FW_BUG "failed to get TPM2 ACPI table\n"); return -EINVAL; } @@ -565,15 +557,14 @@ static int crb_acpi_add(struct acpi_device *device) priv->flags |= CRB_FL_ACPI_START; if (sm == ACPI_TPM2_COMMAND_BUFFER_WITH_SMC) { - if (buf->header.length < (sizeof(*buf) + sizeof(*crb_smc))) { + if (buf->header.length < ACPI_TPM2_SIZE_WITH_SMC) { dev_err(dev, FW_BUG "TPM2 ACPI table has wrong size %u for start method type %d\n", buf->header.length, ACPI_TPM2_COMMAND_BUFFER_WITH_SMC); return -EINVAL; } - crb_smc = ACPI_ADD_PTR(struct tpm2_crb_smc, buf, - ACPI_TPM2_START_METHOD_PARAMETER_OFFSET); + crb_smc = &buf->platform_specific_data.smc; priv->smc_func_id = crb_smc->smc_func_id; priv->flags |= CRB_FL_CRB_SMC_START; } diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c index c7e1384f1b08..f513a116e195 100644 --- a/drivers/char/tpm/tpm_tis.c +++ b/drivers/char/tpm/tpm_tis.c @@ -257,7 +257,7 @@ static int tpm_tis_acpi_init(struct acpi_device *acpi_dev) st = acpi_get_table(ACPI_SIG_TPM2, 1, (struct acpi_table_header **) &tbl); - if (ACPI_FAILURE(st) || tbl->header.length < sizeof(*tbl)) { + if (ACPI_FAILURE(st) || tbl->header.length < ACPI_TPM2_SIZE_WITH_START) { dev_err(&acpi_dev->dev, FW_BUG "failed to get TPM2 ACPI table\n"); return -EINVAL; diff --git a/include/acpi/actbl2.h b/include/acpi/actbl2.h index 2b4af0769a28..645961f998ef 100644 --- a/include/acpi/actbl2.h +++ b/include/acpi/actbl2.h @@ -1273,20 +1273,42 @@ struct acpi_table_tcpa_server { * Version 4 * * Conforms to "TCG ACPI Specification, Family 1.2 and 2.0", - * December 19, 2014 + * Version 1.2, Revision 8, February 27, 2017, Committee Draft * ******************************************************************************/ +struct tpm2_crb_smc { + u32 interrupt; + u8 interrupt_flags; + u8 op_flags; + u16 reserved2; + u32 smc_func_id; +}; + struct acpi_table_tpm2 { struct acpi_table_header header; /* Common ACPI table header */ u16 platform_class; u16 reserved; u64 control_address; u32 start_method; - - /* Platform-specific data follows */ + /* End of Version 3 or minimal version 4 table. */ + union { + u8 raw[12]; + u32 acpi; /* ACPI start method should have 4 zero bytes here. */ + struct tpm2_crb_smc smc; + } platform_specific_data; /* Added in Level 00 Version 00.37 */ + u32 minimum_log_length; /* Added in Version 1.2 */ + u64 log_address; /* Added in Version 1.2 */ }; +/* TPM2 table sizes. */ + +#define ACPI_TPM2_SIZE_WITH_START offsetofend(struct acpi_table_tpm2, \ + start_method) +#define ACPI_TPM2_SIZE_WITH_SMC offsetofend(struct acpi_table_tpm2, \ + platform_specific_data) +#define ACPI_TPM2_SIZE_WITH_LOG sizeof(struct acpi_table_tpm2) + /* Values for start_method above */ #define ACPI_TPM2_NOT_ALLOWED 0 @@ -1296,8 +1318,6 @@ struct acpi_table_tpm2 { #define ACPI_TPM2_COMMAND_BUFFER_WITH_START_METHOD 8 #define ACPI_TPM2_COMMAND_BUFFER_WITH_SMC 11 -#define ACPI_TPM2_START_METHOD_PARAMETER_OFFSET 52 - /******************************************************************************* * * UEFI - UEFI Boot optimization Table