Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1547094ybl; Mon, 2 Dec 2019 05:07:07 -0800 (PST) X-Google-Smtp-Source: APXvYqy1STcpWOTqVOEdMCr+w2zpVk+vYPROltke98QHJ1/rk/w4OyOP1EL1Cq9jwVdbvaD1rzUr X-Received: by 2002:a2e:854c:: with SMTP id u12mr20888689ljj.135.1575292027303; Mon, 02 Dec 2019 05:07:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575292027; cv=none; d=google.com; s=arc-20160816; b=qQCgJC5FXoYtFrZPJyhq4ghuKI9pDntmZ4rZu5gNjGX6dh7MtX61muyrvm+k7SNhGj oINTEqdRrYPYr/LFnrDLDyiA2Z/OTcMv5kjUu7YxUrRCzQQlPGt4HgynThy/uiWzmwqv 0/CfPtq0ka5enJhXeglDNdCGcWQ/XBq0lX6Gsq/WWvh+st5LyqTQTpyXLziMfAGWgNCm DWP6CTtrKpGlWVvqe6aJ+UXL3EjjroMKtpay4o1bS80eTTJNH4EU6AYxyJbouUn6NzXi 5CvL9M5OoDf5ZwhrCP23hvnzbCHW5G5rYWIedTKL1osaEVqsWeJhoWBnyzE4lUpKf1jG f+fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=4/qOgqJifA6tW2+HEYohkFYa6AKBVT+Jx3grGZQ5Chk=; b=RoM5c9uNec60q5Mw6+ffD14u3IAuxIEBnHbNcijEZuZn/OBdFWs5YRvizjbrmvkzth 7s2Fb9CZ3DBfupLe0UODZTIy+7qeIpGnBLjcaFX6oKUOJ+ps6b+yCuhDPGiQ0zIOx4K1 o8x2Z2htu7SJYeqYLQDziapZMGJ2QahH1Y9XU+JCJRqw0TfPPjZnHkVidnOVB+c9drm1 seDWNsj4hCPBXnKLUEZIrUMzGB/R8PkgxYfDyh5vg6Ax5VrENQQMIaNRWlKx6aj7QAx4 NM6HvdQAPkfxwjEgj/Vy/MHpRJvwNzBQVkmWF3fn63D/uAaOgXFG6XHpGWOeLijDTCgq cHqw== ARC-Authentication-Results: i=1; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k26si28171808ljj.65.2019.12.02.05.06.26; Mon, 02 Dec 2019 05:07:07 -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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727495AbfLBNCm (ORCPT + 99 others); Mon, 2 Dec 2019 08:02:42 -0500 Received: from 212.199.177.27.static.012.net.il ([212.199.177.27]:45792 "EHLO herzl.nuvoton.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727391AbfLBNCk (ORCPT ); Mon, 2 Dec 2019 08:02:40 -0500 Received: from taln60.nuvoton.co.il (ntil-fw [212.199.177.25]) by herzl.nuvoton.co.il (8.13.8/8.13.8) with ESMTP id xB2D1nmk015194; Mon, 2 Dec 2019 15:01:49 +0200 Received: by taln60.nuvoton.co.il (Postfix, from userid 10140) id 839D960275; Mon, 2 Dec 2019 15:01:49 +0200 (IST) From: amirmizi6@gmail.com To: Eyal.Cohen@nuvoton.com, jarkko.sakkinen@linux.intel.com, oshrialkoby85@gmail.com, alexander.steffen@infineon.com, robh+dt@kernel.org, mark.rutland@arm.com, peterhuewe@gmx.de, jgg@ziepe.ca, arnd@arndb.de, gregkh@linuxfoundation.org Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-integrity@vger.kernel.org, oshri.alkoby@nuvoton.com, tmaimon77@gmail.com, gcwilson@us.ibm.com, kgoldman@us.ibm.com, ayna@linux.vnet.ibm.com, Dan.Morav@nuvoton.com, oren.tanami@nuvoton.com, shmulik.hager@nuvoton.com, amir.mizinski@nuvoton.com, Amir Mizinski Subject: [PATCH v1 1/5] char: tpm: Make implementation of read16 read32 write32 optional Date: Mon, 2 Dec 2019 15:01:28 +0200 Message-Id: <20191202130132.175382-2-amirmizi6@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20191202130132.175382-1-amirmizi6@gmail.com> References: <20191202130132.175382-1-amirmizi6@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Amir Mizinski Only tpm_tis has a faster way to access multiple bytes at once, every other driver will just fall back to read_bytes/write_bytes. Therefore, move this common code out of tpm_tis_spi into tpm_tis_core, so that it is automatically used when low-level drivers do not implement the specialized methods. this commit is based on previous work by Alexander Steffen Signed-off-by: Amir Mizinski --- drivers/char/tpm/tpm_tis_core.h | 38 +++++++++++++++++++++++++++++++++++--- drivers/char/tpm/tpm_tis_spi.c | 41 ----------------------------------------- 2 files changed, 35 insertions(+), 44 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h index 7337819..d06c65b 100644 --- a/drivers/char/tpm/tpm_tis_core.h +++ b/drivers/char/tpm/tpm_tis_core.h @@ -122,13 +122,35 @@ static inline int tpm_tis_read8(struct tpm_tis_data *data, u32 addr, u8 *result) static inline int tpm_tis_read16(struct tpm_tis_data *data, u32 addr, u16 *result) { - return data->phy_ops->read16(data, addr, result); + __le16 result_le; + int rc; + + if (data->phy_ops->read16) + return data->phy_ops->read16(data, addr, result); + + rc = data->phy_ops->read_bytes(data, addr, sizeof(u16), + (u8 *)&result_le); + if (!rc) + *result = le16_to_cpu(result_le); + + return rc; } static inline int tpm_tis_read32(struct tpm_tis_data *data, u32 addr, u32 *result) { - return data->phy_ops->read32(data, addr, result); + __le32 result_le; + int rc; + + if (data->phy_ops->read32) + return data->phy_ops->read32(data, addr, result); + + rc = data->phy_ops->read_bytes(data, addr, sizeof(u32), + (u8 *)&result_le); + if (!rc) + *result = le32_to_cpu(result_le); + + return rc; } static inline int tpm_tis_write_bytes(struct tpm_tis_data *data, u32 addr, @@ -145,7 +167,17 @@ static inline int tpm_tis_write8(struct tpm_tis_data *data, u32 addr, u8 value) static inline int tpm_tis_write32(struct tpm_tis_data *data, u32 addr, u32 value) { - return data->phy_ops->write32(data, addr, value); + __le32 value_le; + int rc; + + if (data->phy_ops->write32) + return data->phy_ops->write32(data, addr, value); + + value_le = cpu_to_le32(value); + rc = data->phy_ops->write_bytes(data, addr, sizeof(u32), + (u8 *)&value_le); + + return rc; } static inline bool is_bsw(void) diff --git a/drivers/char/tpm/tpm_tis_spi.c b/drivers/char/tpm/tpm_tis_spi.c index 19513e6..da82924 100644 --- a/drivers/char/tpm/tpm_tis_spi.c +++ b/drivers/char/tpm/tpm_tis_spi.c @@ -146,50 +146,9 @@ static int tpm_tis_spi_write_bytes(struct tpm_tis_data *data, u32 addr, return tpm_tis_spi_transfer(data, addr, len, NULL, value); } -static int tpm_tis_spi_read16(struct tpm_tis_data *data, u32 addr, u16 *result) -{ - __le16 result_le; - int rc; - - rc = data->phy_ops->read_bytes(data, addr, sizeof(u16), - (u8 *)&result_le); - if (!rc) - *result = le16_to_cpu(result_le); - - return rc; -} - -static int tpm_tis_spi_read32(struct tpm_tis_data *data, u32 addr, u32 *result) -{ - __le32 result_le; - int rc; - - rc = data->phy_ops->read_bytes(data, addr, sizeof(u32), - (u8 *)&result_le); - if (!rc) - *result = le32_to_cpu(result_le); - - return rc; -} - -static int tpm_tis_spi_write32(struct tpm_tis_data *data, u32 addr, u32 value) -{ - __le32 value_le; - int rc; - - value_le = cpu_to_le32(value); - rc = data->phy_ops->write_bytes(data, addr, sizeof(u32), - (u8 *)&value_le); - - return rc; -} - static const struct tpm_tis_phy_ops tpm_spi_phy_ops = { .read_bytes = tpm_tis_spi_read_bytes, .write_bytes = tpm_tis_spi_write_bytes, - .read16 = tpm_tis_spi_read16, - .read32 = tpm_tis_spi_read32, - .write32 = tpm_tis_spi_write32, }; static int tpm_tis_spi_probe(struct spi_device *dev) -- 2.7.4