Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1589504ybl; Mon, 2 Dec 2019 05:39:01 -0800 (PST) X-Google-Smtp-Source: APXvYqy7jj4Z5ImvMNg/ZezspUCvrTQQU0FNCC1k01vli1Noq5XhmiMPVBhCjPOmUlW4BKoHkDOQ X-Received: by 2002:aa7:ce13:: with SMTP id d19mr4830659edv.296.1575293941171; Mon, 02 Dec 2019 05:39:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575293941; cv=none; d=google.com; s=arc-20160816; b=dJ0+s8UGVkLyPm6u4sS4RfhGWKrcGDk1bEOO9ve87uo4LytnrRnCv8OJAEfEDCYzHb VSA2pEHeuW0yGo/PLcUAkEe1JXprbiA/kG7nK4V0AnlGa3CZmyS3F39LctTknF/9AULU 2g5CgnxiCmm45KCmgeO0DxGH+8U/UqxbVllbEMGhPCAdnhKU307el5KgAU+o2Hi90HhT J+LpHbjJUsAIKeqk2KLuiE8Y61HTP8KCZiY2Z+PZ9+zhrbJtU5I0jHeDlR/8OBqwS2pW CSxtxkMb7OnwaxcsFKhCO1WtdM3MI/mTfhTN4fmg6HbQCTqrMNcBDgVzHAvDF00CKKyI dm0g== 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=vt7vvbpqmt7sMJzjCuOmqO2rGv3G6qrTVp+y6kv4n3w=; b=ykV+3QcAKq7RFy72KbSPMEgvVxaJF6TEQ6OJF23tZ55nHnk1LL7udNqJ9rhfr5taG4 0EjyGPnxmh9lZ7uGhPQXlXoWEtdTo5oT0GqJrspb43EdS9vycESG1iPtrtegfr62ZaJK ALCh4Suta4TagOz25A8lI8X/BX0kgaSly23LpwcGx0TRawlN6EyFyVaQub4IAfuTlkHb ixKbeZa3z96ovKeOw1wf0UymY3rfEb5xxUEZtRaky/sVgG4yhPzW6a1Ikf655aBNsRWd 6HwJ/jHcEmJjFRKMppQJNYP8fuhbhSsuCCSP4TtRAlE5oLdNlNsyYfk6pvWbSR6ETowL Vy4w== 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 z8si7850363ejx.126.2019.12.02.05.38.37; Mon, 02 Dec 2019 05:39:01 -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 S1727579AbfLBNes (ORCPT + 99 others); Mon, 2 Dec 2019 08:34:48 -0500 Received: from 212.199.177.27.static.012.net.il ([212.199.177.27]:45897 "EHLO herzl.nuvoton.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727364AbfLBNer (ORCPT ); Mon, 2 Dec 2019 08:34:47 -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 xB2DYIfw015794; Mon, 2 Dec 2019 15:34:18 +0200 Received: by taln60.nuvoton.co.il (Postfix, from userid 10140) id B283F6026B; Mon, 2 Dec 2019 15:34:18 +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 v2 1/5] char: tpm: Make implementation of read16 read32 write32 optional Date: Mon, 2 Dec 2019 15:33:28 +0200 Message-Id: <20191202133332.178110-2-amirmizi6@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20191202133332.178110-1-amirmizi6@gmail.com> References: <20191202133332.178110-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