Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp4155903iog; Tue, 28 Jun 2022 10:06:03 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v6BW5UhWfFFzszEd2aw6wlChhkAAUcilJQA/qTJ+tE6+J5foWt4FCPgkTElAbNnhEhnJNm X-Received: by 2002:a17:902:ea07:b0:16a:2833:3207 with SMTP id s7-20020a170902ea0700b0016a28333207mr5733418plg.86.1656435963323; Tue, 28 Jun 2022 10:06:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656435963; cv=none; d=google.com; s=arc-20160816; b=cZDB9Aer3lCfpVZdF4oq+12HqTMQGcPdtB2FUHvej6W98A7X/u49Wz8JTzGmYeLNw0 RlA4LBe1iDCTOkw1n8c+cifS1kPgY0nGEEPVe0awuwIRjd/kfbpJYHHD2yp/kjGTdojC kZ1FiTOj6VmWV66/u9G6+q9YWSLzBVEHnmlth0/YjGDmAq63dCy1zG0xvUNwV/y8FnWS uS/f0HCVSqUXfbXE+bmAb1LvSrOL41zL97WH7y9BiORyZkN5r4RcmA0HEbNJvKS4adAZ Tw0jmQFSoBONE5qKDwchMCkVsAGWtYUiLuXQCFWlonWre+4142a+71WJIBuxR18gzmnv RygA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qlhl1lk6fdqhJgoMMasfXfIFRDEKsuZkp9LrgskVcNk=; b=T+upJeQVCohW4sIzU5wJYtWHM+9P9C4/s0YOmLkWYgiKuWKQjnZeqSUnwfxdeR1u3M 7j/aMLId0oazCnybeasjO7N3/PZ/SGIpAhf2pWxOBfTbuJv2FIHmF/GfcZcsHtYB3rCt plmbcRdoXcAIIjYtXSRUy+OufpTKy3C2HJu3hHx4jDRRRF3nhMuqkuT//eBlV/p1FKpL Aqsb4D3WhFOoL3ZOg0OMxa3Q3Y8FCd4VIkfcOZVz0/bbrexRHWdCXhX0n+Edb+NFqcCZ UB2IzAo6apuJBPX6ZL+jge3c3ke7rLTv4ww6cKLHjAFSZdzP359EEqzWtSjdZtoufLRn 50cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b="IXYT7+F/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 130-20020a630188000000b00408a74d3d14si18717172pgb.713.2022.06.28.10.05.51; Tue, 28 Jun 2022 10:06:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b="IXYT7+F/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232235AbiF1Q7I (ORCPT + 99 others); Tue, 28 Jun 2022 12:59:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237307AbiF1Q6n (ORCPT ); Tue, 28 Jun 2022 12:58:43 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0CD331A; Tue, 28 Jun 2022 09:58:40 -0700 (PDT) Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25SGglQH024324; Tue, 28 Jun 2022 16:58:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=qlhl1lk6fdqhJgoMMasfXfIFRDEKsuZkp9LrgskVcNk=; b=IXYT7+F/77dNde8/fbnpwU34eVo1AW2IKFkVFqjTfZCt4gyHhiVv+kWpnsBybYHg7loX +kSspbf6Uhs/KlKO9jixeNjDjMpsFodVLBQQBQ/HC212O6dwCNgwdG2JB/5otaCDgEtF GqJkTkgo//Mq33A1ieZQmDyWVI6MAWmy6lEWPq+Zgx+SZ5mVUfGV6HjTazEPkn1XfnNy FQ2Rbrwgo/gUZAw1vJRyS7RZm9EqM92VcHZdH6EcjWi5qHZqiPrSf/fGeyHM/GqXxLLw gBcER+zOjan+exfje2ZsIJCyoVRiMZOgaSZxgwIRG0sAxiPe8vHQFOPq4hSmgg5nTJpG 6g== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3h05dh0byg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 Jun 2022 16:58:29 +0000 Received: from m0098404.ppops.net (m0098404.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 25SGhiM9031341; Tue, 28 Jun 2022 16:58:28 GMT Received: from ppma05wdc.us.ibm.com (1b.90.2fa9.ip4.static.sl-reverse.com [169.47.144.27]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3h05dh0bxy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 Jun 2022 16:58:28 +0000 Received: from pps.filterd (ppma05wdc.us.ibm.com [127.0.0.1]) by ppma05wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 25SGptFF005990; Tue, 28 Jun 2022 16:58:27 GMT Received: from b03cxnp07029.gho.boulder.ibm.com (b03cxnp07029.gho.boulder.ibm.com [9.17.130.16]) by ppma05wdc.us.ibm.com with ESMTP id 3gwt09xs68-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 Jun 2022 16:58:27 +0000 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 25SGwQ7P28574022 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 28 Jun 2022 16:58:26 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 02F757805E; Tue, 28 Jun 2022 16:58:26 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4B9897805F; Tue, 28 Jun 2022 16:58:25 +0000 (GMT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Tue, 28 Jun 2022 16:58:25 +0000 (GMT) From: Stefan Berger To: kexec@lists.infradead.org, devicetree@vger.kernel.org, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: nayna@linux.ibm.com, nasastry@in.ibm.com, mpe@ellerman.id.au, Stefan Berger , Jarkko Sakkinen , Jason Gunthorpe , Rob Herring , Frank Rowand Subject: [PATCH v3 1/3] tpm: of: Make of-tree specific function commonly available Date: Tue, 28 Jun 2022 12:58:18 -0400 Message-Id: <20220628165820.883222-2-stefanb@linux.ibm.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220628165820.883222-1-stefanb@linux.ibm.com> References: <20220628165820.883222-1-stefanb@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: xe27eIK8AXNJXNN6UKLPN4yhlsAKB_dZ X-Proofpoint-ORIG-GUID: f1EvZCYa9hzkQaiLUzTutJYVQZSevIkF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-06-28_09,2022-06-28_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 lowpriorityscore=0 malwarescore=0 phishscore=0 mlxscore=0 priorityscore=1501 bulkscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 clxscore=1015 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206280065 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Simplify tpm_read_log_of() by moving reusable parts of the code into its own file to make the code commonly available so it can be used also for kexec support. Call the new of_tpm_get_sml_parameters() function from the TPM Open Firmware driver. Compile the new file when CONFIG_OF is enabled so that of_tpm_get_sml_parameters() can be called from kexec even if the TPM subsystem is not enabled. Signed-off-by: Stefan Berger Cc: Jarkko Sakkinen Cc: Jason Gunthorpe Cc: Rob Herring Cc: Frank Rowand --- drivers/char/Makefile | 1 + drivers/char/tpm/Makefile | 1 + drivers/char/tpm/eventlog/of.c | 31 +++++------------------------- drivers/char/tpm/eventlog/tpm_of.c | 27 ++++++++++++++++++++++++++ include/linux/tpm.h | 5 +++++ 5 files changed, 39 insertions(+), 26 deletions(-) create mode 100644 drivers/char/tpm/eventlog/tpm_of.c diff --git a/drivers/char/Makefile b/drivers/char/Makefile index 264eb398fdd4..af9edafb944e 100644 --- a/drivers/char/Makefile +++ b/drivers/char/Makefile @@ -40,6 +40,7 @@ obj-$(CONFIG_PCMCIA) += pcmcia/ obj-$(CONFIG_HANGCHECK_TIMER) += hangcheck-timer.o obj-$(CONFIG_TCG_TPM) += tpm/ +obj-$(CONFIG_OF) += tpm/ obj-$(CONFIG_PS3_FLASH) += ps3flash.o diff --git a/drivers/char/tpm/Makefile b/drivers/char/tpm/Makefile index 66d39ea6bd10..3c0eaac81f5c 100644 --- a/drivers/char/tpm/Makefile +++ b/drivers/char/tpm/Makefile @@ -19,6 +19,7 @@ tpm-y += eventlog/tpm2.o tpm-$(CONFIG_ACPI) += tpm_ppi.o eventlog/acpi.o tpm-$(CONFIG_EFI) += eventlog/efi.o tpm-$(CONFIG_OF) += eventlog/of.o +obj-$(CONFIG_OF) += eventlog/tpm_of.o obj-$(CONFIG_TCG_TIS_CORE) += tpm_tis_core.o obj-$(CONFIG_TCG_TIS) += tpm_tis.o obj-$(CONFIG_TCG_TIS_SYNQUACER) += tpm_tis_synquacer.o diff --git a/drivers/char/tpm/eventlog/of.c b/drivers/char/tpm/eventlog/of.c index a9ce66d09a75..f9462d19632e 100644 --- a/drivers/char/tpm/eventlog/of.c +++ b/drivers/char/tpm/eventlog/of.c @@ -12,6 +12,7 @@ #include #include +#include #include #include "../tpm.h" @@ -20,11 +21,10 @@ int tpm_read_log_of(struct tpm_chip *chip) { struct device_node *np; - const u32 *sizep; - const u64 *basep; struct tpm_bios_log *log; u32 size; u64 base; + int ret; log = &chip->log; if (chip->dev.parent && chip->dev.parent->of_node) @@ -35,30 +35,9 @@ int tpm_read_log_of(struct tpm_chip *chip) if (of_property_read_bool(np, "powered-while-suspended")) chip->flags |= TPM_CHIP_FLAG_ALWAYS_POWERED; - sizep = of_get_property(np, "linux,sml-size", NULL); - basep = of_get_property(np, "linux,sml-base", NULL); - if (sizep == NULL && basep == NULL) - return -ENODEV; - if (sizep == NULL || basep == NULL) - return -EIO; - - /* - * For both vtpm/tpm, firmware has log addr and log size in big - * endian format. But in case of vtpm, there is a method called - * sml-handover which is run during kernel init even before - * device tree is setup. This sml-handover function takes care - * of endianness and writes to sml-base and sml-size in little - * endian format. For this reason, vtpm doesn't need conversion - * but physical tpm needs the conversion. - */ - if (of_property_match_string(np, "compatible", "IBM,vtpm") < 0 && - of_property_match_string(np, "compatible", "IBM,vtpm20") < 0) { - size = be32_to_cpup((__force __be32 *)sizep); - base = be64_to_cpup((__force __be64 *)basep); - } else { - size = *sizep; - base = *basep; - } + ret = of_tpm_get_sml_parameters(np, &base, &size); + if (ret < 0) + return ret; if (size == 0) { dev_warn(&chip->dev, "%s: Event log area empty\n", __func__); diff --git a/drivers/char/tpm/eventlog/tpm_of.c b/drivers/char/tpm/eventlog/tpm_of.c new file mode 100644 index 000000000000..2e6cfcc87035 --- /dev/null +++ b/drivers/char/tpm/eventlog/tpm_of.c @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include + +int of_tpm_get_sml_parameters(struct device_node *np, u64 *base, u32 *size) +{ + const u32 *sizep; + const u64 *basep; + + sizep = of_get_property(np, "linux,sml-size", NULL); + basep = of_get_property(np, "linux,sml-base", NULL); + if (sizep == NULL && basep == NULL) + return -ENODEV; + if (sizep == NULL || basep == NULL) + return -EIO; + + if (of_property_match_string(np, "compatible", "IBM,vtpm") < 0 && + of_property_match_string(np, "compatible", "IBM,vtpm20") < 0) { + *size = be32_to_cpup((__force __be32 *)sizep); + *base = be64_to_cpup((__force __be64 *)basep); + } else { + *size = *sizep; + *base = *basep; + } + return 0; +} +EXPORT_SYMBOL_GPL(of_tpm_get_sml_parameters); diff --git a/include/linux/tpm.h b/include/linux/tpm.h index dfeb25a0362d..429bf045db80 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -460,4 +460,9 @@ static inline struct tpm_chip *tpm_default_chip(void) return NULL; } #endif + +#ifdef CONFIG_OF +int of_tpm_get_sml_parameters(struct device_node *np, u64 *base, u32 *size); +#endif + #endif -- 2.35.1