From patchwork Wed Apr 8 03:00:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1267702 X-Patchwork-Delegate: bmeng.cn@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=KkpSrKoR; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48xpx62xZcz9sSX for ; Wed, 8 Apr 2020 13:02:50 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E77BF8190C; Wed, 8 Apr 2020 05:01:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="KkpSrKoR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7081E818F3; Wed, 8 Apr 2020 05:01:33 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd44.google.com (mail-io1-xd44.google.com [IPv6:2607:f8b0:4864:20::d44]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 1FE2F8006F for ; Wed, 8 Apr 2020 05:01:29 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd44.google.com with SMTP id f3so5683457ioj.1 for ; Tue, 07 Apr 2020 20:01:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CGnMowJb1G+sykdInI/T70VT1sesFyk7ThAC19C/sbg=; b=KkpSrKoRIMGsm8rjSlavwsAJYNh7Yk+rJOALQcLxYufHacDthF3qQZPHtgEJjEsNIi UoIfdbAs5A9iTsPjscIqR0B3FnH7Vw59PrNBkW2zNrVdBv8ZGwqM756Uk/fRrViOyzxi MGQZ0iKz0wGbNWHhbB57JnsZ8N5FZUyVrCrv8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CGnMowJb1G+sykdInI/T70VT1sesFyk7ThAC19C/sbg=; b=i6obfUNYCiEvucqGpCHe3aSP+DvpFbDVgQu+UNVmcVb70dOMC9wlV5fWTTYBd9RfjS kiSDPdSNGknYsYuhsu7zqxahC7bJeBdUmiGFckjqoS9eIXiC7bIx0uxBv6rj0rZbCKqa hSlbrh/v34JpCkyHapW1/KcKcOwHzVQGnt0HbAl2oKF2h08IuKtlNcboMOrHO3GZ6GBZ fadgZ/yQz2nhx+RVXwMXasdCgPcxABHDOAslovGFjW+jlDE/kqVbzDSN+E8ojf8cjGEA qyhCo9DSDgp7qdYDlvXcQG1z6ZEjVkYQ2CYzinHFK0IdyqQs618WVTlRBuOywerZU0Vl gEXA== X-Gm-Message-State: AGi0PuafLj6MYNQ+/RYeNrutPtn/UKYGIaW7yDBhtRdlhz4Q+zqiT1Aj NgYtPZho9GNPmvwaWfTPqVz6tpYdwims/w== X-Google-Smtp-Source: APiQypKneEWhB4KDV0ZDPTkge/cdJdFRzc4y2BxtWqlaNgam87DYoB1iAbcwMyVqigkydXFgIr/1xg== X-Received: by 2002:a6b:6d1a:: with SMTP id a26mr5099506iod.32.1586314887782; Tue, 07 Apr 2020 20:01:27 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id l6sm7732310ilh.27.2020.04.07.20.01.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 20:01:27 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Wolfgang Wallner , Bin Meng , Andy Shevchenko , Leif Lindholm , Simon Glass Subject: [PATCH v4 05/31] tpm: cr50: Release locality on exit Date: Tue, 7 Apr 2020 21:00:41 -0600 Message-Id: <20200407210023.v4.5.Ic7bc756f1622775532c4536a2dfd4ee783ee4a35@changeid> X-Mailer: git-send-email 2.26.0.292.g33ef6b2f38-goog In-Reply-To: <20200408030107.168474-1-sjg@chromium.org> References: <20200408030107.168474-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.2 at phobos.denx.de X-Virus-Status: Clean At present the cr50 driver claims the locality and does not release it for Linux. This causes problems. Fix this by tracking what is claimed, and adding a 'remove' method. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- Changes in v4: None Changes in v3: None Changes in v2: None drivers/tpm/cr50_i2c.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/tpm/cr50_i2c.c b/drivers/tpm/cr50_i2c.c index b904a7d426e..b30f55b40d3 100644 --- a/drivers/tpm/cr50_i2c.c +++ b/drivers/tpm/cr50_i2c.c @@ -206,7 +206,7 @@ static int release_locality(struct udevice *dev, int force) cr50_i2c_write(dev, addr, &buf, 1); } - priv->locality = 0; + priv->locality = -1; return 0; } @@ -499,6 +499,7 @@ static int process_reset(struct udevice *dev) static int claim_locality(struct udevice *dev, int loc) { const u8 mask = TPM_ACCESS_VALID | TPM_ACCESS_ACTIVE_LOCALITY; + struct cr50_priv *priv = dev_get_priv(dev); u8 access; int ret; @@ -525,6 +526,7 @@ static int claim_locality(struct udevice *dev, int loc) return -EPERM; } log_info("Claimed locality %d\n", loc); + priv->locality = loc; return 0; } @@ -559,7 +561,11 @@ static int cr50_i2c_open(struct udevice *dev) static int cr50_i2c_cleanup(struct udevice *dev) { - release_locality(dev, 1); + struct cr50_priv *priv = dev_get_priv(dev); + + printf("%s: cleanup %d\n", __func__, priv->locality); + if (priv->locality != -1) + release_locality(dev, 1); return 0; } @@ -631,6 +637,7 @@ static int cr50_i2c_probe(struct udevice *dev) return log_msg_ret("vendor-id", -EXDEV); } priv->vendor = vendor; + priv->locality = -1; return 0; } @@ -655,5 +662,7 @@ U_BOOT_DRIVER(cr50_i2c) = { .ops = &cr50_i2c_ops, .ofdata_to_platdata = cr50_i2c_ofdata_to_platdata, .probe = cr50_i2c_probe, + .remove = cr50_i2c_cleanup, .priv_auto_alloc_size = sizeof(struct cr50_priv), + .flags = DM_FLAG_OS_PREPARE, };