Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1235345rwe; Thu, 1 Sep 2022 15:03:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR6nPnKNIVFNFZpt4GbeZK8EL8AiKO5koOMVPgVn/SG0c5FV+DCzZzG7XTrQ1pSxBagMD06i X-Received: by 2002:a17:902:b607:b0:170:c7fc:388a with SMTP id b7-20020a170902b60700b00170c7fc388amr32867984pls.29.1662069780886; Thu, 01 Sep 2022 15:03:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662069780; cv=none; d=google.com; s=arc-20160816; b=BTq3gB2Tb8tXYakcIqIpBH6QpNk3BhcjOnZXfHxOhPRBXQpwjrjl6xgId/C++0xVa2 uyQmOFxMCirrrDgOs/8TrEU7iJH4tU/1YCvPe75vY2xlt7uczJnVcCmPTNOVbL0FPdSP bmlsItqXzsb93oOhwvYT/QW6oMlxwYb+1zRbGhOZribG0o1MHwxrL4tdymzi+IQlrx1G xrfNYiLoxIo81oMk9Z1PQAyjEh93PwGHTgWnRxYmdGf7DwqeVy73xmZNj7ayqzG7SwpC op+9jqu+/8YJx6JYIWXGj8CVp8KpPLgh84wqFvVEX55CD662i3pfbAcs4YnONaDg6sxh hsjQ== 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=gruSY6eWw/NEwHExJKnsxDdwOlp80csb3xc/7VDhcAE=; b=mK0gESK7zVRQV+dX1w58DI9jIJKW2ItvjkAOgXQtwSyhKkKIZh5UMzHcpbiBpVE0Yr ccUoTqnth7lL/ACKiMCrUvPxe4gBPS2g17Tk39pk4HIainagkA/PmtodPJRM7sg8uiIW hqNc7slzzfMuCy7kDa1rfiGqg57q1/7AatgwjJ0uMaAuYLLKO4mZDtEKQ8kqnKxJiPh7 AHkO5oRm/u+pTbcBHqNApG+sEuJ+yIvHybjevrTxEBim3+PwQOW2GlOkepNa8fqjPaqX wEnFFV4o+wo4tht0/vm1nrVkn/KgE2tWDlrcocgXHI+V/slGjU20FBzMeuBUh1H0kjk6 QDZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=ioZAMWuW; 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 f4-20020a656284000000b0042b57fded7bsi16395pgv.670.2022.09.01.15.02.41; Thu, 01 Sep 2022 15:03:00 -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=ioZAMWuW; 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 S233822AbiIAVqn (ORCPT + 99 others); Thu, 1 Sep 2022 17:46:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233353AbiIAVqi (ORCPT ); Thu, 1 Sep 2022 17:46:38 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34D947A506; Thu, 1 Sep 2022 14:46:37 -0700 (PDT) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 281LD2D3006720; Thu, 1 Sep 2022 21:46:26 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=gruSY6eWw/NEwHExJKnsxDdwOlp80csb3xc/7VDhcAE=; b=ioZAMWuWHiVCCXe7Ggkhw6y4vv3yzLyuJtiWOUVrn8v5RNfv4EjB3LyYmfHAv5N8gDNM DhDrpW8bxxnCoXcuMfRCLMEC4X/Wl2QQg1u/oIHq+NjnC86jN+p29hMo6v2PfapI4IoI fdQyPmyPIU3nFE7tJRIMEZcrNnZpxh0sbNqzdCqbrxyj0sAOFBq7CCT9z0tog0O/AFO4 ChD5IEUaZ0U0oAPIR2BG8jDKH7rt8354Zf+HxjdOCVxkb1AVVgO7K6dSQexC4jt+fOYb 5hvlkLuXr52JNPf7UO/cKMGU0o5opLKU1Is9uq4t885tIKrnvmnGY7ba6MtFrnKk0kx8 iQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jb4f5gvy0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 Sep 2022 21:46:26 +0000 Received: from m0187473.ppops.net (m0187473.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 281LEcpQ019800; Thu, 1 Sep 2022 21:46:25 GMT Received: from ppma04dal.us.ibm.com (7a.29.35a9.ip4.static.sl-reverse.com [169.53.41.122]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jb4f5gvxe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 Sep 2022 21:46:25 +0000 Received: from pps.filterd (ppma04dal.us.ibm.com [127.0.0.1]) by ppma04dal.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 281LZJwU012098; Thu, 1 Sep 2022 21:46:24 GMT Received: from b03cxnp07027.gho.boulder.ibm.com (b03cxnp07027.gho.boulder.ibm.com [9.17.130.14]) by ppma04dal.us.ibm.com with ESMTP id 3j7awacwnc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 Sep 2022 21:46:24 +0000 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp07027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 281LkNbn5308996 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 1 Sep 2022 21:46:23 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A55A6C6057; Thu, 1 Sep 2022 21:46:22 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C6C53C6055; Thu, 1 Sep 2022 21:46:21 +0000 (GMT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP; Thu, 1 Sep 2022 21:46:21 +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 , Mimi Zohar , Nageswara R Sastry , Coiby Xu Subject: [PATCH v8 2/4] tpm: of: Make of-tree specific function commonly available Date: Thu, 1 Sep 2022 17:46:08 -0400 Message-Id: <20220901214610.768645-3-stefanb@linux.ibm.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220901214610.768645-1-stefanb@linux.ibm.com> References: <20220901214610.768645-1-stefanb@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: TKqq_umCHPuN1kpay-xmiI9ot655_6da X-Proofpoint-ORIG-GUID: V1jxbQB1zFNWy15QnMKrZlpGvPTy3gfj X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-09-01_12,2022-08-31_03,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1011 adultscore=0 mlxscore=0 impostorscore=0 bulkscore=0 mlxlogscore=999 spamscore=0 malwarescore=0 suspectscore=0 lowpriorityscore=0 phishscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209010094 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 an inline function that makes it 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. Signed-off-by: Stefan Berger Cc: Jarkko Sakkinen Cc: Jason Gunthorpe Cc: Rob Herring Cc: Frank Rowand Reviewed-by: Mimi Zohar Tested-by: Nageswara R Sastry Reviewed-by: Jarkko Sakkinen Tested-by: Coiby Xu --- v7: - Added original comment back into inlined function v4: - converted to inline function --- drivers/char/tpm/eventlog/of.c | 31 +++++------------------------ include/linux/tpm.h | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 26 deletions(-) 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/include/linux/tpm.h b/include/linux/tpm.h index dfeb25a0362d..6356baaa1393 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -460,4 +460,40 @@ static inline struct tpm_chip *tpm_default_chip(void) return NULL; } #endif + +#ifdef CONFIG_OF +static inline 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; + + /* + * 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; + } + return 0; +} +#endif + #endif -- 2.35.1