Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp132433ybg; Sun, 31 May 2020 19:25:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyADNbtbOXUBI7MkAbJh/ZR7wMHyfJYcFLazB0ycm8Qk3pfjAraRHak/1PuaNYVEiChdEJr X-Received: by 2002:a50:fd04:: with SMTP id i4mr19935362eds.43.1590978326394; Sun, 31 May 2020 19:25:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590978326; cv=none; d=google.com; s=arc-20160816; b=OgHowqDazFCUvzQ5laXHRRCH9jVH3FrE67uc2MHA22bdC/w+C14oCLCtPXAiyEEM/A 9MhlJpRbE5kYdPYpqRLUegcOXAFTK9ulXoxsElcwhxtxxZ46ocPnEmS3XmxjWgQIC1oT TSW8R4iUuzZqDAuaE6lMg4S7XWI82AchavgPb6gN6LzPgjWm4Wb01sYpKnYgm1jRHKxC IMwkR94sKyFL7Vws4TD5jiTP0EtYFcMLc4HjDHF6Le5tqu+fm2Yiu9cwPrJvb3qqz7FC z+/6BdaRQ36bNdVRoo5QBetSyOUBMUO5Hu0nhXdreoiuP1wOb1+AqdQkrBFmvprxPdQN bykg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=qIwBrUlhV1RjGUgvvfFt1c6l9/vzS8c6OIJ7CgKLLck=; b=TEhw6kHnUVg61CoAym0S4tRu9rNsVPJ7PjmV0oOgH8yYkz48CIatASxIVU6bLMdExW tarShzTDpKPtjpEYDpQE4abGuH1DeN0a/4xE4AU8aeuV6yi5gb1RuvXtH188MEBZvqvd 8YesSaF0seEHkDbmt+yjRlfyjFwSZZbSX3ltimrkjtVauakTC0/+4/h42NQ/n9oOqRRl ptNJ9nzPoHaWyKkRDRn5e/R1zIPkO3wWxqjicMyV+rgaI5tycrE7HkM3EZYTFH3vfwBm yvu74YfkM55HiZwRF20OB556Ty+hX+NQfnzQRHh2WDJCEZDCvTQ6g8eATIYJ06GfThkD qcSg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gv3si10374100ejb.45.2020.05.31.19.25.02; Sun, 31 May 2020 19:25:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727013AbgFACXN (ORCPT + 99 others); Sun, 31 May 2020 22:23:13 -0400 Received: from mga07.intel.com ([134.134.136.100]:23151 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725953AbgFACXM (ORCPT ); Sun, 31 May 2020 22:23:12 -0400 IronPort-SDR: wi5LGNmf34ObJfPOGYU9gQ/v0L+Lz7yrsLzGuKJ98rwhPcF/aK/rV31LzrNwF+j0tbO1KY/mTl 9zuHUXUJqniQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2020 19:23:12 -0700 IronPort-SDR: jogtF6iv/8NEwGKYG3+f05QlTBYhhBSaft+mnrY0kd7bx1YGqNImp2DR755dWtdve6cnxsXWo8 yk/ZWw8Z898w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,459,1583222400"; d="scan'208";a="286129401" Received: from dytagah-mobl.amr.corp.intel.com (HELO localhost) ([10.252.58.236]) by orsmga002.jf.intel.com with ESMTP; 31 May 2020 19:23:03 -0700 Date: Mon, 1 Jun 2020 05:23:01 +0300 From: Jarkko Sakkinen To: amirmizi6@gmail.com Cc: Eyal.Cohen@nuvoton.com, oshrialkoby85@gmail.com, alexander.steffen@infineon.com, robh+dt@kernel.org, peterhuewe@gmx.de, christophe-h.richard@st.com, jgg@ziepe.ca, arnd@arndb.de, gregkh@linuxfoundation.org, 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 Subject: Re: [PATCH v9 1/8] tpm: tpm_tis: Make implementation of read16, read32 and write32 optional Message-ID: <20200601022301.GA796332@linux.intel.com> References: <20200526141658.157801-1-amirmizi6@gmail.com> <20200526141658.157801-2-amirmizi6@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200526141658.157801-2-amirmizi6@gmail.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Plese, write the short summary as tpm: Make read{16, 32}() and write32() in tpm_tis_phy_ops optional On Tue, May 26, 2020 at 05:16:51PM +0300, amirmizi6@gmail.com wrote: > From: Amir Mizinski > > Only tpm_tis can use memory-mapped I/O, which is truly mapped into > the kernel's memory space. Therefore, using ioread16/ioread32/iowrite32 > turns into a straightforward pointer dereference. > Every other driver requires more complicated operations to read more than > one byte at a time and will just fall back to read_bytes/write_bytes. > Therefore, move this common code out of tpm_tis_spi and into tpm_tis_core > so that it is used automatically 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 > --- > drivers/char/tpm/tpm_tis_core.h | 38 +++++++++++++++++++++++++++++++--- > drivers/char/tpm/tpm_tis_spi.h | 4 ---- > drivers/char/tpm/tpm_tis_spi_cr50.c | 3 --- > drivers/char/tpm/tpm_tis_spi_main.c | 41 ------------------------------------- > 4 files changed, 35 insertions(+), 51 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.h b/drivers/char/tpm/tpm_tis_spi.h > index bba7397..d0f66f6 100644 > --- a/drivers/char/tpm/tpm_tis_spi.h > +++ b/drivers/char/tpm/tpm_tis_spi.h > @@ -31,10 +31,6 @@ extern int tpm_tis_spi_init(struct spi_device *spi, struct tpm_tis_spi_phy *phy, > extern int tpm_tis_spi_transfer(struct tpm_tis_data *data, u32 addr, u16 len, > u8 *in, const u8 *out); > > -extern int tpm_tis_spi_read16(struct tpm_tis_data *data, u32 addr, u16 *result); > -extern int tpm_tis_spi_read32(struct tpm_tis_data *data, u32 addr, u32 *result); > -extern int tpm_tis_spi_write32(struct tpm_tis_data *data, u32 addr, u32 value); > - > #ifdef CONFIG_TCG_TIS_SPI_CR50 > extern int cr50_spi_probe(struct spi_device *spi); > #else > diff --git a/drivers/char/tpm/tpm_tis_spi_cr50.c b/drivers/char/tpm/tpm_tis_spi_cr50.c > index 37d72e8..f339d20 100644 > --- a/drivers/char/tpm/tpm_tis_spi_cr50.c > +++ b/drivers/char/tpm/tpm_tis_spi_cr50.c > @@ -215,9 +215,6 @@ static int tpm_tis_spi_cr50_write_bytes(struct tpm_tis_data *data, u32 addr, > static const struct tpm_tis_phy_ops tpm_spi_cr50_phy_ops = { > .read_bytes = tpm_tis_spi_cr50_read_bytes, > .write_bytes = tpm_tis_spi_cr50_write_bytes, > - .read16 = tpm_tis_spi_read16, > - .read32 = tpm_tis_spi_read32, > - .write32 = tpm_tis_spi_write32, > }; > > static void cr50_print_fw_version(struct tpm_tis_data *data) > 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 Other than that looks good. /Jarkko >