Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2371010ybb; Sun, 5 Apr 2020 05:57:53 -0700 (PDT) X-Google-Smtp-Source: APiQypJ+kEXsqIg74RvsvJWCkY7HM3NwjvjM1sEa8HZZfZbQ+dTcWoIewjZ5UZg389sWdWEb12VC X-Received: by 2002:a9d:1a2:: with SMTP id e31mr14641774ote.30.1586091473386; Sun, 05 Apr 2020 05:57:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586091473; cv=none; d=google.com; s=arc-20160816; b=zTLBM9HHPHhUKN52sWQ7zWcgfq9ZlG3w4pG3XKoLmOKXQ3Gl4HgV+kZ1fCBz690f64 Vxs6L7SlXXeqIzu/x0EBkd+K67LwV0F9hKwLbn8nHXQ/0dxTKkYQmvDHaB2h1wcYKsLR Wj+Vc2qbxYvxNQhPd91O/VcGEmnXz/2Jq9sk1rAvX94WSRa+T3kdiQoGRO94zXyPk29c DSNPpCkEhQLYUJCX1Q8HYVox2drEV5F5IWWw+1uYzoU7+mwMXMC6Gj0lhJ/AG9U1PZrp qKHUyDzD43w1nZjwoqhz3Oakps6F3MZC/C7ak5j8ywoAQRkJmPfwiLUMpkjoAhf3rhNz yZzg== 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=zBNeTzUIig2evs2nkFWQmghifzPHcsL2Tm6aps/y/lY=; b=LTCDyI40gKMsi4oy7y+UQtKPA5/Ye/n4Paxs74OBffhhKfHpN11+YWTyWF+yZul9aS BENYVNDUWmVtmapTwchizDWUmZRrFrSYgNzSMMQy6dYM8S3MwFlCnXNtsyxMc+iuf6YY Glmy37Gg1O4bPSvPrk35pbYr97KQ5ABkXudrkkSWC6QxTsYkY5HoQfr/VFOLfv2RNmTc 4cpMbvrBxCllWkkeEwhi8pZqIobsb5zIqwx9c5W0DynOlCGbSsaul6TSl5qNMgzlO0T5 ZeQdo/MKd/N4AR0oGmnHf5nBDN+xey+MmAudPwevqPLFYuhJX/6aWbxOWtt387Ds2OUO l+tg== 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 g1si6647845otp.268.2020.04.05.05.57.41; Sun, 05 Apr 2020 05:57:53 -0700 (PDT) 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 S1726885AbgDEMzx (ORCPT + 99 others); Sun, 5 Apr 2020 08:55:53 -0400 Received: from 212.199.177.27.static.012.net.il ([212.199.177.27]:40270 "EHLO herzl.nuvoton.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726861AbgDEMzx (ORCPT ); Sun, 5 Apr 2020 08:55:53 -0400 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 035CsSge005468; Sun, 5 Apr 2020 15:54:28 +0300 Received: by taln60.nuvoton.co.il (Postfix, from userid 10140) id 318DD639B1; Sun, 5 Apr 2020 15:54:28 +0300 (IDT) 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, "benoit.houyere@st.com--to=mark.rutland"@arm.com, peterhuewe@gmx.de, christophe-h.richard@st.com, 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, Dan.Morav@nuvoton.com, oren.tanami@nuvoton.com, shmulik.hager@nuvoton.com, amir.mizinski@nuvoton.com, Amir Mizinski , Alexander Steffen Subject: [PATCH v5 1/7] tpm: tpm_tis: Make implementation of read16 read32 write32 optional Date: Sun, 5 Apr 2020 15:53:46 +0300 Message-Id: <20200405125352.183693-2-amirmizi6@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20200405125352.183693-1-amirmizi6@gmail.com> References: <20200405125352.183693-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 can use memory mapped I/O, which is truly mapped into the kernel's memory space. So using ioread16/ioread32/iowrite32 turn into a straightforward pointer dereference. Every other driver require more complicated operations to read more than 1 byte at a time and 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. Co-developed-by: Alexander Steffen Signed-off-by: Alexander Steffen Signed-off-by: Amir Mizinski Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.h | 38 +++++++++++++++++++++++++++++++--- drivers/char/tpm/tpm_tis_spi_main.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_main.c b/drivers/char/tpm/tpm_tis_spi_main.c index d1754fd..95fef9d 100644 --- a/drivers/char/tpm/tpm_tis_spi_main.c +++ b/drivers/char/tpm/tpm_tis_spi_main.c @@ -152,44 +152,6 @@ static int tpm_tis_spi_write_bytes(struct tpm_tis_data *data, u32 addr, return tpm_tis_spi_transfer(data, addr, len, NULL, value); } -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; -} - -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; -} - -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; -} - int tpm_tis_spi_init(struct spi_device *spi, struct tpm_tis_spi_phy *phy, int irq, const struct tpm_tis_phy_ops *phy_ops) { @@ -205,9 +167,6 @@ int tpm_tis_spi_init(struct spi_device *spi, struct tpm_tis_spi_phy *phy, 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