From patchwork Sun Apr 10 21:22:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Ricard X-Patchwork-Id: 8795271 Return-Path: X-Original-To: patchwork-tpmdd-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 70CECC0553 for ; Sun, 10 Apr 2016 21:23:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 572792024D for ; Sun, 10 Apr 2016 21:23:31 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3239920221 for ; Sun, 10 Apr 2016 21:23:30 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-4.v29.ch3.sourceforge.com) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1apMpN-0006nZ-3U; Sun, 10 Apr 2016 21:23:29 +0000 Received: from sog-mx-3.v43.ch3.sourceforge.com ([172.29.43.193] helo=mx.sourceforge.net) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1apMpM-0006n2-Gk for tpmdd-devel@lists.sourceforge.net; Sun, 10 Apr 2016 21:23:28 +0000 Received-SPF: pass (sog-mx-3.v43.ch3.sourceforge.com: domain of gmail.com designates 74.125.82.54 as permitted sender) client-ip=74.125.82.54; envelope-from=christophe.ricard@gmail.com; helo=mail-wm0-f54.google.com; Received: from mail-wm0-f54.google.com ([74.125.82.54]) by sog-mx-3.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1apMpL-0000hC-Gk for tpmdd-devel@lists.sourceforge.net; Sun, 10 Apr 2016 21:23:28 +0000 Received: by mail-wm0-f54.google.com with SMTP id n3so81322624wmn.0 for ; Sun, 10 Apr 2016 14:23:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=43G6RZ+fJTRD75GSxpATr2jpgpHP6n2DFxa3SPvB4pI=; b=Bh1fb5lbhmOTPUELoe4WG4G9HqwOHkMQ8TTfmZqIruJSTZPToOM8SxwHAKjTkqoxt/ 7FZ0G4+YH34PQfcDkSqGyturLHriBmvgvpWP4UmUOe6Huu8xmx+4T8QDLWKv5RRf+CyB Voot09WdeeyfsALtnCUWY3VUfe4ExLtTjLnhx7KtcTQepFd5zIs65SNcMjyAfnV2q7Yx QUIAdTilNBNOfWMjkOLdEqVPJYqK9hpJyIiSIpigN205ULBTOqTmIGsLRch7hW8fpuGZ R+E8tOAPHd6TZDacUDH7jlzqYEhI93MvMd7OgGsAjdKlnJ1IlWw8dXeniGg0B2TrRVyN rYLA== X-Gm-Message-State: AD7BkJL2iLsuGrTlp3/wpFvzRBR+/DtEDMes184bEatEwafGxhoLB/gsWfKbmQ0fCIk3jA== X-Received: by 10.28.148.19 with SMTP id w19mr15107860wmd.10.1460323401541; Sun, 10 Apr 2016 14:23:21 -0700 (PDT) Received: from localhost.localdomain (ax113-6-78-236-204-66.fbx.proxad.net. [78.236.204.66]) by smtp.gmail.com with ESMTPSA id kj9sm24537597wjb.14.2016.04.10.14.23.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 10 Apr 2016 14:23:20 -0700 (PDT) From: Christophe Ricard X-Google-Original-From: Christophe Ricard To: jarkko.sakkinen@linux.intel.com Date: Sun, 10 Apr 2016 23:22:59 +0200 Message-Id: <1460323386-16892-4-git-send-email-christophe-h.ricard@st.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1460323386-16892-1-git-send-email-christophe-h.ricard@st.com> References: <1460323386-16892-1-git-send-email-christophe-h.ricard@st.com> X-Spam-Score: -1.6 (-) X-Headers-End: 1apMpL-0000hC-Gk Cc: jean-luc.blanc@st.com, ashley@ashleylai.com, tpmdd-devel@lists.sourceforge.net, christophe-h.ricard@st.com, benoit.houyere@st.com Subject: [tpmdd-devel] [PATCH 03/10] tpm: Use read/write_bytes for drivers without more specialized methods X-BeenThere: tpmdd-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Tpm Device Driver maintainance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: tpmdd-devel-bounces@lists.sourceforge.net X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,HK_RANDOM_ENVFROM,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some drivers might choose to implement only functions for transferring an arbitrary number of bytes, without special handling of word or dword transfers. Signed-off-by: Alexander Steffen Signed-off-by: Christophe Ricard --- drivers/char/tpm/tpm.h | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index e93e19b..68ce900 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -475,17 +475,35 @@ static inline int tpm_read_bytes(struct tpm_chip *chip, u32 addr, u16 len, static inline int tpm_read8(struct tpm_chip *chip, u32 addr, u8 *result) { - return chip->lowlevel->read_bytes(chip, addr, 1, result); + return chip->lowlevel->read_bytes(chip, addr, sizeof(u8), result); } static inline int tpm_read16(struct tpm_chip *chip, u32 addr, u16 *result) { - return chip->lowlevel->read16(chip, addr, result); + int rc; + + if (chip->lowlevel->read16) + return chip->lowlevel->read16(chip, addr, result); + + rc = chip->lowlevel->read_bytes(chip, addr, sizeof(u16), (u8 *)result); + if (!rc) + *result = le16_to_cpu(*result); + + return rc; } static inline int tpm_read32(struct tpm_chip *chip, u32 addr, u32 *result) { - return chip->lowlevel->read32(chip, addr, result); + int rc; + + if (chip->lowlevel->read32) + return chip->lowlevel->read32(chip, addr, result); + + rc = chip->lowlevel->read_bytes(chip, addr, sizeof(u32), (u8 *)result); + if (!rc) + *result = le32_to_cpu(*result); + + return rc; } static inline int tpm_write_bytes(struct tpm_chip *chip, u32 addr, u16 len, @@ -496,12 +514,17 @@ static inline int tpm_write_bytes(struct tpm_chip *chip, u32 addr, u16 len, static inline int tpm_write8(struct tpm_chip *chip, u32 addr, u8 value) { - return chip->lowlevel->write_bytes(chip, addr, 1, &value); + return chip->lowlevel->write_bytes(chip, addr, sizeof(u8), &value); } static inline int tpm_write32(struct tpm_chip *chip, u32 addr, u32 value) { - return chip->lowlevel->write32(chip, addr, value); + if (chip->lowlevel->write32) + return chip->lowlevel->write32(chip, addr, value); + + value = cpu_to_le32(value); + return chip->lowlevel->write_bytes(chip, addr, sizeof(u32), + (u8 *)&value); } extern struct class *tpm_class;