From patchwork Wed Apr 13 19:55:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Ricard X-Patchwork-Id: 8827351 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 5C79DC0553 for ; Wed, 13 Apr 2016 19:56:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3AC3F20361 for ; Wed, 13 Apr 2016 19:56:12 +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 ADEF720357 for ; Wed, 13 Apr 2016 19:56:10 +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 1aqQtV-0004ta-Hl; Wed, 13 Apr 2016 19:56:09 +0000 Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1aqQtU-0004tT-HR for tpmdd-devel@lists.sourceforge.net; Wed, 13 Apr 2016 19:56:08 +0000 Received-SPF: pass (sog-mx-2.v43.ch3.sourceforge.com: domain of gmail.com designates 74.125.82.65 as permitted sender) client-ip=74.125.82.65; envelope-from=christophe.ricard@gmail.com; helo=mail-wm0-f65.google.com; Received: from mail-wm0-f65.google.com ([74.125.82.65]) by sog-mx-2.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1aqQtT-0005l8-4B for tpmdd-devel@lists.sourceforge.net; Wed, 13 Apr 2016 19:56:08 +0000 Received: by mail-wm0-f65.google.com with SMTP id y144so16984617wmd.0 for ; Wed, 13 Apr 2016 12:56:07 -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=ggynQ01Ed6EP3NehvLYEoZWFaZ53ItZV48pKUc0F1uQ=; b=WLyT2L/XcA9sWf+KCOh4dCg+O5M7ea7rytJBUjOaoMzn5td9NGvM2koTE9RR7lhphu EVS0UY0vO6Gg2frF4F4ofGMKVNQocBocYyrl/j4hLfm0CxG7/p8B32BKpgdYgcZIqwBn qCEO9LUTV8rZbiZt8oBz3scov2eCMhvESith1OjZXBNBcjEfYfRlWeKru4dw7cdcRbkP F7feLkgb7I83xqkBTiuTGc77k3ZSPMp3rFbdgJr1iILv4DET16RkYO82YMTcxGuTzvVz pwtqeJlmTepOtDHQ5i2d5GfI91qSSh0+RFh550rES97kMfviQCC00yFXM3DLxLspC8U0 mJVg== X-Gm-Message-State: AOPr4FWtA2hKuC8hxyyaQ/0Hcb1U46e3GA2acy99udz/NQwmyiu7ZVjV+0AN8HS31TMObw== X-Received: by 10.194.223.70 with SMTP id qs6mr11532887wjc.119.1460577361094; Wed, 13 Apr 2016 12:56:01 -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 202sm10488911wmw.5.2016.04.13.12.55.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 13 Apr 2016 12:55:59 -0700 (PDT) From: Christophe Ricard X-Google-Original-From: Christophe Ricard To: jarkko.sakkinen@linux.intel.com Date: Wed, 13 Apr 2016 21:55:40 +0200 Message-Id: <1460577351-24632-2-git-send-email-christophe-h.ricard@st.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1460577351-24632-1-git-send-email-christophe-h.ricard@st.com> References: <1460577351-24632-1-git-send-email-christophe-h.ricard@st.com> X-Spam-Score: -1.6 (-) X-Headers-End: 1aqQtT-0005l8-4B 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 v2 01/12] tpm: tpm_tis: Share common data between phys 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 As preliminary, split priv_data structure in common and phy specific structures. iobase field is specific to lpc bus. Signed-off-by: Christophe Ricard --- drivers/char/tpm/tpm_tis.c | 30 +++++++++++++++++++++++------- drivers/char/tpm/tpm_tis_core.h | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 drivers/char/tpm/tpm_tis_core.h diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c index 1e45e73..cc64edb 100644 --- a/drivers/char/tpm/tpm_tis.c +++ b/drivers/char/tpm/tpm_tis.c @@ -93,14 +93,8 @@ struct tpm_info { #define TPM_DID_VID(l) (0x0F00 | ((l) << 12)) #define TPM_RID(l) (0x0F04 | ((l) << 12)) -struct priv_data { +struct tpm_tis_phy { void __iomem *iobase; - u16 manufacturer_id; - int locality; - int irq; - bool irq_tested; - wait_queue_head_t int_queue; - wait_queue_head_t read_queue; }; #if defined(CONFIG_PNP) && defined(CONFIG_ACPI) @@ -133,6 +127,7 @@ static inline int is_itpm(struct acpi_device *dev) static int wait_startup(struct tpm_chip *chip, int l) { struct priv_data *priv = dev_get_drvdata(&chip->dev); + struct tpm_tis_phy *phy = priv->phy_id; unsigned long stop = jiffies + chip->timeout_a; do { if (ioread8(priv->iobase + TPM_ACCESS(l)) & @@ -146,6 +141,7 @@ static int wait_startup(struct tpm_chip *chip, int l) static int check_locality(struct tpm_chip *chip, int l) { struct priv_data *priv = dev_get_drvdata(&chip->dev); + struct tpm_tis_phy *phy = priv->phy_id; if ((ioread8(priv->iobase + TPM_ACCESS(l)) & (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) == @@ -158,6 +154,7 @@ static int check_locality(struct tpm_chip *chip, int l) static void release_locality(struct tpm_chip *chip, int l, int force) { struct priv_data *priv = dev_get_drvdata(&chip->dev); + struct tpm_tis_phy *phy = priv->phy_id; if (force || (ioread8(priv->iobase + TPM_ACCESS(l)) & (TPM_ACCESS_REQUEST_PENDING | TPM_ACCESS_VALID)) == @@ -169,6 +166,7 @@ static void release_locality(struct tpm_chip *chip, int l, int force) static int request_locality(struct tpm_chip *chip, int l) { struct priv_data *priv = dev_get_drvdata(&chip->dev); + struct tpm_tis_phy *phy = priv->phy_id; unsigned long stop, timeout; long rc; @@ -210,6 +208,7 @@ again: static u8 tpm_tis_status(struct tpm_chip *chip) { struct priv_data *priv = dev_get_drvdata(&chip->dev); + struct tpm_tis_phy *phy = priv->phy_id; return ioread8(priv->iobase + TPM_STS(priv->locality)); @@ -218,6 +217,7 @@ static u8 tpm_tis_status(struct tpm_chip *chip) static void tpm_tis_ready(struct tpm_chip *chip) { struct priv_data *priv = dev_get_drvdata(&chip->dev); + struct tpm_tis_phy *phy = priv->phy_id; /* this causes the current command to be aborted */ iowrite8(TPM_STS_COMMAND_READY, @@ -227,6 +227,7 @@ static void tpm_tis_ready(struct tpm_chip *chip) static int get_burstcount(struct tpm_chip *chip) { struct priv_data *priv = dev_get_drvdata(&chip->dev); + struct tpm_tis_phy *phy = priv->phy_id; unsigned long stop; int burstcnt; @@ -249,6 +250,7 @@ static int get_burstcount(struct tpm_chip *chip) static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count) { struct priv_data *priv = dev_get_drvdata(&chip->dev); + struct tpm_tis_phy *phy = priv->phy_id; int size = 0, burstcnt; while (size < count && wait_for_tpm_stat(chip, @@ -323,6 +325,7 @@ MODULE_PARM_DESC(itpm, "Force iTPM workarounds (found on some Lenovo laptops)"); static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len) { struct priv_data *priv = dev_get_drvdata(&chip->dev); + struct tpm_tis_phy *phy = priv->phy_id; int rc, status, burstcnt; size_t count = 0; @@ -379,6 +382,7 @@ out_err: static void disable_interrupts(struct tpm_chip *chip) { struct priv_data *priv = dev_get_drvdata(&chip->dev); + struct tpm_tis_phy *phy = priv->phy_id; u32 intmask; intmask = @@ -472,6 +476,7 @@ static bool tpm_tis_update_timeouts(struct tpm_chip *chip, unsigned long *timeout_cap) { struct priv_data *priv = dev_get_drvdata(&chip->dev); + struct tpm_tis_phy *phy = priv->phy_id; int i; u32 did_vid; @@ -496,6 +501,7 @@ static bool tpm_tis_update_timeouts(struct tpm_chip *chip, static int probe_itpm(struct tpm_chip *chip) { struct priv_data *priv = dev_get_drvdata(&chip->dev); + struct tpm_tis_phy *phy = priv->phy_id; int rc = 0; u8 cmd_getticks[] = { 0x00, 0xc1, 0x00, 0x00, 0x00, 0x0a, @@ -565,6 +571,7 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id) { struct tpm_chip *chip = dev_id; struct priv_data *priv = dev_get_drvdata(&chip->dev); + struct tpm_tis_phy *phy = priv->phy_id; u32 interrupt; int i; @@ -602,6 +609,7 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, int flags, int irq) { struct priv_data *priv = dev_get_drvdata(&chip->dev); + struct tpm_tis_phy *phy = priv->phy_id; u8 original_int_vec; if (devm_request_irq(&chip->dev, irq, tis_int_handler, flags, @@ -655,6 +663,7 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, static void tpm_tis_probe_irq(struct tpm_chip *chip, u32 intmask) { struct priv_data *priv = dev_get_drvdata(&chip->dev); + struct tpm_tis_phy *phy = priv->phy_id; u8 original_int_vec; int i; @@ -679,6 +688,7 @@ MODULE_PARM_DESC(interrupts, "Enable interrupts"); static void tpm_tis_remove(struct tpm_chip *chip) { struct priv_data *priv = dev_get_drvdata(&chip->dev); + struct tpm_tis_phy *phy = priv->phy_id; void __iomem *reg = priv->iobase + TPM_INT_ENABLE(priv->locality); if (chip->flags & TPM_CHIP_FLAG_TPM2) @@ -695,11 +705,16 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info, int rc, probe; struct tpm_chip *chip; struct priv_data *priv; + struct tpm_tis_phy *phy; priv = devm_kzalloc(dev, sizeof(struct priv_data), GFP_KERNEL); if (priv == NULL) return -ENOMEM; + phy = devm_kzalloc(dev, sizeof(struct tpm_tis_phy), GFP_KERNEL); + if (phy == NULL) + return -ENOMEM; + chip = tpmm_chip_alloc(dev, &tpm_tis); if (IS_ERR(chip)) return PTR_ERR(chip); @@ -717,6 +732,7 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info, chip->timeout_b = TIS_TIMEOUT_B_MAX; chip->timeout_c = TIS_TIMEOUT_C_MAX; chip->timeout_d = TIS_TIMEOUT_D_MAX; + priv->phy_id = phy; dev_set_drvdata(&chip->dev, priv); diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h new file mode 100644 index 0000000..b28ed00 --- /dev/null +++ b/drivers/char/tpm/tpm_tis_core.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2005, 2006 IBM Corporation + * Copyright (C) 2014, 2015 Intel Corporation + * + * Authors: + * Leendert van Doorn + * Kylene Hall + * + * Maintained by: + * + * Device driver for TCG/TCPA TPM (trusted platform module). + * Specifications at www.trustedcomputinggroup.org + * + * This device driver implements the TPM interface as defined in + * the TCG TPM Interface Spec version 1.2, revision 1.0. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, version 2 of the + * License. + */ + +#ifndef __TPM_TIS_CORE_H__ +#define __TPM_TIS_CORE_H__ + +#include "tpm.h" + +struct priv_data { + u16 manufacturer_id; + int locality; + int irq; + bool irq_tested; + wait_queue_head_t int_queue; + wait_queue_head_t read_queue; + void *phy_id; +}; + +#endif