Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4538411ybb; Tue, 7 Apr 2020 09:22:21 -0700 (PDT) X-Google-Smtp-Source: APiQypLAqaLuUoDX/VzYIefQXRVNtdxvdQb/bH1cQRaTcpv7HkJfAIILezipaHpWTkvEOjdnVyB5 X-Received: by 2002:a9d:6a12:: with SMTP id g18mr2214813otn.19.1586276541794; Tue, 07 Apr 2020 09:22:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586276541; cv=none; d=google.com; s=arc-20160816; b=mqKGHZwnLAzfaLZINeJTJ0+skAx5Z2LSMj0pULRHda9bbvV+jkN40u4UN5l8/O7Kbu h+ulBM0dkZCUVbv/4ln5FoyMboIa4tjQF1tOG8XbxAknISlW6MG6s01SxONu1AonP/5V wS5BitMp/vayPPtENFQsJmSp88j4GGLJ/Z0C5Y97SnnKw6gJEm/srqD+/PFlphUsK7G7 qRJ5ZrKVhyih+ttgwu9pBEMrDcKfoMNgGBfMAJY+AZBi81mg5V8+5d/oCT9R2AsD39de J/3bUwGDSuV4N8rZ8wjV42etuCRU8NH6o8A8nPZPBNkJ5SSYU3z0hg0tjdc3AVhlwKHo eO8Q== 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=xYHTQNhJnu2McDXc6qXpLTnCswMLuAEyz6KcTB6k8sAEcFttDvFY1ALaWUm9IjGOKs Uk1ZALobIujXHbfmalQ++HDKtY3fNYcaMV0zzHiOUEWOvCKV4IyZ9AQbaT/PHhaUQHkP p59QvhTgaC5JHIhjaTpyxri++gGUT8MH3Pj5q7kf6ZzJ46wVF6DdjDMo+QYamTy7qGIZ ERFP5k2w0zNKLWJfSJxjn884kurpeHXIrXXl/QSsWJumgWhaTwXyG2iP3AUuan+o4g+X GmQ1J2hicA2hLkgGYthucLF5Ve4ZTLXgpRGEt3/mz4ub/Eh7RnFo+FDow2wrXYN11SGn xdiA== 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 v1si1365035otp.155.2020.04.07.09.22.07; Tue, 07 Apr 2020 09:22:21 -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 S1728176AbgDGQV1 (ORCPT + 99 others); Tue, 7 Apr 2020 12:21:27 -0400 Received: from 212.199.177.27.static.012.net.il ([212.199.177.27]:40596 "EHLO herzl.nuvoton.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727717AbgDGQVZ (ORCPT ); Tue, 7 Apr 2020 12:21:25 -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 037GKqmf002261; Tue, 7 Apr 2020 19:20:52 +0300 Received: by taln60.nuvoton.co.il (Postfix, from userid 10140) id 1261F639B1; Tue, 7 Apr 2020 19:20:52 +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, 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, Dan.Morav@nuvoton.com, oren.tanami@nuvoton.com, shmulik.hager@nuvoton.com, amir.mizinski@nuvoton.com, Amir Mizinski , Alexander Steffen Subject: [PATCH v6 1/7] tpm: tpm_tis: Make implementation of read16 read32 write32 optional Date: Tue, 7 Apr 2020 19:20:38 +0300 Message-Id: <20200407162044.168890-2-amirmizi6@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20200407162044.168890-1-amirmizi6@gmail.com> References: <20200407162044.168890-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