From patchwork Tue Nov 9 07:02:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 518033 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp1319966iml; Mon, 8 Nov 2021 23:02:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJxrEVpGxJZgs7xH7vHl4eH/3Fpn5H9PDvZpiL0BXDQOQBhrOduMLZoWTqjoH5/ltGTTg0+W X-Received: by 2002:a50:d88b:: with SMTP id p11mr7178951edj.287.1636441367021; Mon, 08 Nov 2021 23:02:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636441367; cv=none; d=google.com; s=arc-20160816; b=tj3GVjYa+VcVoPXPdseS1w3eSLJ0/XmVHSDD6DwTlyY/ltD9zowAXCdTRNTUjWyajN l3Sqz2cJUpvSQ7xZl4SWJl7LQ80owckyBHOlL36m/TF6G9bjBHcV67E9mEykBRNjMmzY Z31ImvxElMBtX/+8qcCGD74ungQLj534bHCCCaUcDpuDCrk+ig++xJnlTcD7sMkzUlCj HYNasGHEqjn71cFqORxj8OaHVpW1BlbnJqdBz5wBpH/etM7xkv8FqE/3AHU7YHcKp+Gi hpPS+YCTsk0kqHkfbCEIe+ZENKTLoaS7UmECxG6If5xmMs+0lb+sRzXmVCU0/lgN15hm peCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wNeZylK6Uc6p4s5cJscjplLeA6hT25Mpnx2q1SoGyVw=; b=AddFFB2772ASsFvrGPyWM2jMaB8vl19dPRDopFHlUPnqsAM8tGKZmdpjWXKt82bz3u hJ/UH0YSUAPtTOlI0oiIjerAJicDQeqJPl4lNqyled/VgT4gL5ZJzLjXDM0oduApHnh0 k1OfaeTqsgr1n/Gkdh96VhhWQcKpSvja8LXjmLg26k1BUNgmqZoSPlDGSR7rJqCnCrnA OItLYBtViEuzLcsgO0P4ZXsRLrcEn/sLgLISz2m5vbqkrDonKPM4V0272l4MWPyqptla XYS+sclcdjUMWczldRZnmGyZS67KjHoqv/OwXjO/KO2UNkb0SdGUcSXM7+aC7sh5FzyV jlQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Kf7g9me2; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id d13si10749537edu.169.2021.11.08.23.02.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Nov 2021 23:02:47 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Kf7g9me2; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9810183820; Tue, 9 Nov 2021 08:02:35 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Kf7g9me2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8DE3283820; Tue, 9 Nov 2021 08:02:32 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) (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 71DDD836D5 for ; Tue, 9 Nov 2021 08:02:28 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-wm1-x334.google.com with SMTP id g191-20020a1c9dc8000000b0032fbf912885so1481405wme.4 for ; Mon, 08 Nov 2021 23:02:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wNeZylK6Uc6p4s5cJscjplLeA6hT25Mpnx2q1SoGyVw=; b=Kf7g9me2MpJEKmDoVxkFDyeFI1u9WYbJ9w0hJsrDfVmKYL2gXKDp56bPQ2WJIyfezG mSeK6EcykuBCT2v5zLJ9vipfOvQAhy8cVNi4pdWgmo1j44GnbD2VzjMKtUnMqWTfQr6A ByEF3QbVZ44UAUaLcEo9Cy7Rb8XYEIR4Y3aCIWs/BunG/U1caUk/H5xrMecTRfuKQI3A Rhb0X3Ai09XDp2tLXwk57l4Y5MKJZq6sp4LVm+D2T7VcEE82shb1EiI9tS1Qc5rD+C3s Pw9upjeINTJpI/IvRfu0/Jy1V9ONWSncMv/Qn4brudgVIJwrmt5gxtoC7IynVMoutyNm GHIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wNeZylK6Uc6p4s5cJscjplLeA6hT25Mpnx2q1SoGyVw=; b=s9gmYBrrMXzFIDfqwWARR3NqxfErVS8iDZ0hk0j9G33CQY3KAD0Ww5Wkt4A4FTyuuc u//SFhjJ4brtSfm8Lp9atpGgGXq3Z6zcr1sixLrx/deQIx6LrQvgSGrXum6fC1Xoxcyr 5OP2diuPPIPaQ1IqyCpCfmH/OIbdFUiLGzvnWne8IY5uIaPQDc9ZRIOJ0iQopb5vSoB5 Q8JaGe/P0n/66rRjM4d77oF1cFd3Y/QhIRntVBALHWe6V2bLp9cxSO/xZfH/CMjflVCe y1oMPynZFuGMwWIsdtfJbZD6rSyU0rYwV50wIVF/JtE2t2EpSw80quqiW++Z3j5eJbCU cmFg== X-Gm-Message-State: AOAM532ZBQZw580/M/c0vSlRBwUIRwP/GTZgs6XuKlxXijzOKtzp0Yuj cyoHQTx1bMU6umJkP1ucrsw6nIaQh0OTRg== X-Received: by 2002:a05:600c:430c:: with SMTP id p12mr4774907wme.127.1636441348013; Mon, 08 Nov 2021 23:02:28 -0800 (PST) Received: from apalos.home ([2a02:587:4627:18c0:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id g5sm20897229wri.45.2021.11.08.23.02.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Nov 2021 23:02:27 -0800 (PST) From: Ilias Apalodimas To: u-boot@lists.denx.de Cc: trini@konsulko.com, Ilias Apalodimas , Simon Glass , Rick Chen , Sean Anderson , Heinrich Schuchardt , Masahisa Kojima Subject: [PATCH 1/8 v7] tpm: refactor function names and macros for infineon v1.2 TPM Date: Tue, 9 Nov 2021 09:02:15 +0200 Message-Id: <20211109070223.76456-2-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211109070223.76456-1-ilias.apalodimas@linaro.org> References: <20211109070223.76456-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.103.2 at phobos.denx.de X-Virus-Status: Clean With the upcoming TPM2 API, some of the functions name are part of the new header file. So switch conflicting internal function names and defines. Reviewed-by: Simon Glass Signed-off-by: Ilias Apalodimas --- drivers/tpm/tpm_tis_infineon.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/drivers/tpm/tpm_tis_infineon.c b/drivers/tpm/tpm_tis_infineon.c index f414e5657db9..525ad72f4c92 100644 --- a/drivers/tpm/tpm_tis_infineon.c +++ b/drivers/tpm/tpm_tis_infineon.c @@ -50,10 +50,10 @@ static const char * const chip_name[] = { [UNKNOWN] = "unknown/fallback to slb9635", }; -#define TPM_ACCESS(l) (0x0000 | ((l) << 4)) -#define TPM_STS(l) (0x0001 | ((l) << 4)) -#define TPM_DATA_FIFO(l) (0x0005 | ((l) << 4)) -#define TPM_DID_VID(l) (0x0006 | ((l) << 4)) +#define TPM_INFINEON_ACCESS(l) (0x0000 | ((l) << 4)) +#define TPM_INFINEON_STS(l) (0x0001 | ((l) << 4)) +#define TPM_INFINEON_DATA_FIFO(l) (0x0005 | ((l) << 4)) +#define TPM_INFINEON_DID_VID(l) (0x0006 | ((l) << 4)) /* * tpm_tis_i2c_read() - read from TPM register @@ -197,7 +197,7 @@ static int tpm_tis_i2c_check_locality(struct udevice *dev, int loc) u8 buf; int rc; - rc = tpm_tis_i2c_read(dev, TPM_ACCESS(loc), &buf, 1); + rc = tpm_tis_i2c_read(dev, TPM_INFINEON_ACCESS(loc), &buf, 1); if (rc < 0) return rc; @@ -215,12 +215,12 @@ static void tpm_tis_i2c_release_locality(struct udevice *dev, int loc, const u8 mask = TPM_ACCESS_REQUEST_PENDING | TPM_ACCESS_VALID; u8 buf; - if (tpm_tis_i2c_read(dev, TPM_ACCESS(loc), &buf, 1) < 0) + if (tpm_tis_i2c_read(dev, TPM_INFINEON_ACCESS(loc), &buf, 1) < 0) return; if (force || (buf & mask) == mask) { buf = TPM_ACCESS_ACTIVE_LOCALITY; - tpm_tis_i2c_write(dev, TPM_ACCESS(loc), &buf, 1); + tpm_tis_i2c_write(dev, TPM_INFINEON_ACCESS(loc), &buf, 1); } } @@ -240,7 +240,7 @@ static int tpm_tis_i2c_request_locality(struct udevice *dev, int loc) return rc; } - rc = tpm_tis_i2c_write(dev, TPM_ACCESS(loc), &buf, 1); + rc = tpm_tis_i2c_write(dev, TPM_INFINEON_ACCESS(loc), &buf, 1); if (rc) { debug("%s: Failed to write to TPM: %d\n", __func__, rc); return rc; @@ -271,7 +271,7 @@ static u8 tpm_tis_i2c_status(struct udevice *dev) /* NOTE: Since i2c read may fail, return 0 in this case --> time-out */ u8 buf; - if (tpm_tis_i2c_read(dev, TPM_STS(chip->locality), &buf, 1) < 0) + if (tpm_tis_i2c_read(dev, TPM_INFINEON_STS(chip->locality), &buf, 1) < 0) return 0; else return buf; @@ -286,7 +286,7 @@ static int tpm_tis_i2c_ready(struct udevice *dev) u8 buf = TPM_STS_COMMAND_READY; debug("%s\n", __func__); - rc = tpm_tis_i2c_write_long(dev, TPM_STS(chip->locality), &buf, 1); + rc = tpm_tis_i2c_write_long(dev, TPM_INFINEON_STS(chip->locality), &buf, 1); if (rc) debug("%s: rc=%d\n", __func__, rc); @@ -306,7 +306,7 @@ static ssize_t tpm_tis_i2c_get_burstcount(struct udevice *dev) stop = chip->timeout_d; do { /* Note: STS is little endian */ - addr = TPM_STS(chip->locality) + 1; + addr = TPM_INFINEON_STS(chip->locality) + 1; if (tpm_tis_i2c_read(dev, addr, buf, 3) < 0) burstcnt = 0; else @@ -360,7 +360,7 @@ static int tpm_tis_i2c_recv_data(struct udevice *dev, u8 *buf, size_t count) if (burstcnt > (count - size)) burstcnt = count - size; - rc = tpm_tis_i2c_read(dev, TPM_DATA_FIFO(chip->locality), + rc = tpm_tis_i2c_read(dev, TPM_INFINEON_DATA_FIFO(chip->locality), &(buf[size]), burstcnt); if (rc == 0) size += burstcnt; @@ -462,7 +462,7 @@ static int tpm_tis_i2c_send(struct udevice *dev, const u8 *buf, size_t len) burstcnt = CONFIG_TPM_TIS_I2C_BURST_LIMITATION_LEN; #endif /* CONFIG_TPM_TIS_I2C_BURST_LIMITATION */ - rc = tpm_tis_i2c_write(dev, TPM_DATA_FIFO(chip->locality), + rc = tpm_tis_i2c_write(dev, TPM_INFINEON_DATA_FIFO(chip->locality), &(buf[count]), burstcnt); if (rc == 0) count += burstcnt; @@ -482,7 +482,7 @@ static int tpm_tis_i2c_send(struct udevice *dev, const u8 *buf, size_t len) } /* Go and do it */ - rc = tpm_tis_i2c_write(dev, TPM_STS(chip->locality), &sts, 1); + rc = tpm_tis_i2c_write(dev, TPM_INFINEON_STS(chip->locality), &sts, 1); if (rc < 0) return rc; debug("%s: done, rc=%d\n", __func__, rc); @@ -525,7 +525,7 @@ static int tpm_tis_i2c_init(struct udevice *dev) return rc; /* Read four bytes from DID_VID register */ - if (tpm_tis_i2c_read(dev, TPM_DID_VID(0), (uchar *)&vendor, 4) < 0) { + if (tpm_tis_i2c_read(dev, TPM_INFINEON_DID_VID(0), (uchar *)&vendor, 4) < 0) { tpm_tis_i2c_release_locality(dev, 0, 1); return -EIO; } @@ -583,7 +583,7 @@ static int tpm_tis_i2c_close(struct udevice *dev) return 0; } -static int tpm_tis_get_desc(struct udevice *dev, char *buf, int size) +static int tpm_tis_i2c_get_desc(struct udevice *dev, char *buf, int size) { struct tpm_chip *chip = dev_get_priv(dev); @@ -615,7 +615,7 @@ static int tpm_tis_i2c_probe(struct udevice *dev) static const struct tpm_ops tpm_tis_i2c_ops = { .open = tpm_tis_i2c_open, .close = tpm_tis_i2c_close, - .get_desc = tpm_tis_get_desc, + .get_desc = tpm_tis_i2c_get_desc, .send = tpm_tis_i2c_send, .recv = tpm_tis_i2c_recv, .cleanup = tpm_tis_i2c_cleanup, From patchwork Tue Nov 9 07:02:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 518034 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp1320120iml; Mon, 8 Nov 2021 23:02:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJzbXTha3n1CptM+9pYdz4/C8nTgZDW/dxey/vGnxqoLWoFS89b1i5mHrtHZ+cc8x1T4FnQK X-Received: by 2002:a50:da0a:: with SMTP id z10mr6935677edj.298.1636441377017; Mon, 08 Nov 2021 23:02:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636441377; cv=none; d=google.com; s=arc-20160816; b=vMkItzic5vaPvaoUfpGzszH7Fb2D0ZAH4rtMkNkv6xleqE7DiF5oH1IeK814uOzeaB Wws0uMqqizKbPYrA6on3YHhLi1lxa3V+HsKx5co6O6NeM9XxkNWA29fmLpmDPo6SZDbb G3MC+ClOgprL7jM1K3kAFB99jw2mfRsyT8cmRI54huOiN/jvQ8SkrmStOiY1e77tsU7w q3SjEULF9Z59ttERVVZrhJhZpJb66H7/dsszwCY6C0qQ6jNSYCETxUJL7PVsV0ZLEUQT iGejMaqiJl9JS4vhwg1viti6CiujWNUL1cxVrbUEnw46z4KuPnJYOBKdDoC5dlwr8xnN 2HXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gZhDcb1qySaDmJmIf1A2fwciQBwofkesR+kR8EZazeE=; b=DKrelcaWDsOMrQ1WYGff5efdqgGy+9llz1GOpugJm6jWaa4f+Wqc+ICBZMkRBxB+EZ gtMuGd9u648sCcaTcL7SmfapsQiaStvLLxph2zQ9Z5TZ0wEhcwPWvaVgdJeAZOf3710/ x4jO9qKv74UklkORLSehjlaTmhI6BCtWwnLP5fT1kQhtPxMRIJQUG2q3Wx8guO6q3D1Q HB7hrhrDFh/W2wUSoR1Iz3oTnQSqcbA+qB3kYIi9RagFeKB1DuWAL+t7q3mWFXWt5Ifk wQ6jCc7R0nGa8Heo9c/dXeDIHC/cmFKOZfOXgKG5/+yGFNq6PzYMjdPad9v6Et1LgWpi ZoVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bTHLUmbk; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id g4si28576915edv.455.2021.11.08.23.02.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Nov 2021 23:02:57 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bTHLUmbk; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9C5F5836EA; Tue, 9 Nov 2021 08:02:39 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="bTHLUmbk"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 67109836E5; Tue, 9 Nov 2021 08:02:34 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) (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 7929283695 for ; Tue, 9 Nov 2021 08:02:30 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-wr1-x42e.google.com with SMTP id d27so31179176wrb.6 for ; Mon, 08 Nov 2021 23:02:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gZhDcb1qySaDmJmIf1A2fwciQBwofkesR+kR8EZazeE=; b=bTHLUmbkzzqJ+C5GzlosFgcu8h+ORaU2luIsHhuf6fXcwMbDWb/pSsb9QqJ4jNna6s wRuP9sgXrQiEKFEgd5ZY9EdZr14mqVbJ5IpN/sckzyPiBCbcPq6YqvH00khSHtqyUrKE 0XcBz+pdYDN960KaQZBvQXiFT/AJgqBj2QN+aq8v8j9VO0P80I20cnaACmeQ2y47F9d/ ZIXxKGgRBMoXY3J6fy4MJ/xIOq4uBmsvKct+RvvjCLJdjE8LK9Adu4FVfzpj1QD0Hi36 SVqePbpCu12hD0UDHaiiwoVRMONQGsgUB2QxobNvB+D9yCQRLMC+RsGQ1b+yYBMVpzNM FwUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gZhDcb1qySaDmJmIf1A2fwciQBwofkesR+kR8EZazeE=; b=5Jq/W81lqTYzcTdgit9H5pnS0eBsigLLIK296ysZiaNEsOu3drGCTP+hjHCuwLCNpC FD3oz9XSKT+cwW5iK7eJ9zx5rN4ioAGepAgaktL3q+0YV0ysQWuCmRyuMDhoQKPK0foE mfhjFLXnsY+4L/VWXBJi9oNIvoGZZEHyDeZ6tuDeQdyc95CZzgNR3L0y6/KEBD24OVQl RuKPH2zkioyFRuhbIaY0NlL2HqBWfnkWzIYuZkMsRjkqd9AAeQWv3BjY6MeLIX1l/5SA o9O9tKNCX/90ZcrrTVYfRdJOTK1eU5HTyj8bL6gkanjOTBkwVtzTnlSojMSR4fwHuNM5 hgLw== X-Gm-Message-State: AOAM532tSGerM3jnZwSZ0NzC6kQG7UoxsRrfKfp58Lopsv1brdwx4aQf rIjZzXam+nonQLUP7upxuQzGzYyFpqlWJg== X-Received: by 2002:adf:c986:: with SMTP id f6mr6988031wrh.216.1636441350020; Mon, 08 Nov 2021 23:02:30 -0800 (PST) Received: from apalos.home ([2a02:587:4627:18c0:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id g5sm20897229wri.45.2021.11.08.23.02.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Nov 2021 23:02:29 -0800 (PST) From: Ilias Apalodimas To: u-boot@lists.denx.de Cc: trini@konsulko.com, Ilias Apalodimas , Simon Glass , Heinrich Schuchardt , Rick Chen , Sean Anderson , Heinrich Schuchardt , Masahisa Kojima Subject: [PATCH 2/8 v7] tpm: refactor function names for LPC based TPMs Date: Tue, 9 Nov 2021 09:02:16 +0200 Message-Id: <20211109070223.76456-3-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211109070223.76456-1-ilias.apalodimas@linaro.org> References: <20211109070223.76456-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.103.2 at phobos.denx.de X-Virus-Status: Clean With the upcoming TPM2 API, some of the functions name are part of the new header file. So switch conflicting internal function names and defines. Reviewed-by: Simon Glass Reviewed-by: Heinrich Schuchardt Signed-off-by: Ilias Apalodimas --- drivers/tpm/tpm_tis_lpc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/tpm/tpm_tis_lpc.c b/drivers/tpm/tpm_tis_lpc.c index 003c0d8816d0..13a133d58ebd 100644 --- a/drivers/tpm/tpm_tis_lpc.c +++ b/drivers/tpm/tpm_tis_lpc.c @@ -443,7 +443,7 @@ static int tpm_tis_lpc_open(struct udevice *dev) return 0; } -static int tpm_tis_get_desc(struct udevice *dev, char *buf, int size) +static int tpm_tis_lpc_get_desc(struct udevice *dev, char *buf, int size) { ulong chip_type = dev_get_driver_data(dev); @@ -458,7 +458,7 @@ static int tpm_tis_get_desc(struct udevice *dev, char *buf, int size) static const struct tpm_ops tpm_tis_lpc_ops = { .open = tpm_tis_lpc_open, .close = tpm_tis_lpc_close, - .get_desc = tpm_tis_get_desc, + .get_desc = tpm_tis_lpc_get_desc, .send = tis_senddata, .recv = tis_readresponse, }; From patchwork Tue Nov 9 07:02:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 518035 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp1320237iml; Mon, 8 Nov 2021 23:03:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJw5dNYJapAKz+R+OQWSDKerrGO2458mhcT7enxe7LE+dNER6bDlWyu6os40PBbnZ4Lg1/m6 X-Received: by 2002:a17:907:16ac:: with SMTP id hc44mr6437017ejc.363.1636441387135; Mon, 08 Nov 2021 23:03:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636441387; cv=none; d=google.com; s=arc-20160816; b=m8/1i98p00cb/Ez7yE6wWyFatWgxrfKMBpr0vle9CXnlRZao1xuKnS0eekYp+elfnJ uCRnBnsU5rTp6SGpkbaY5dDcbvy1Qr5aqB0pMO+YA2eo3LaeL9DXnDx5uQV6V00uOVUp vgEW8jWyrHvc/W9p6wBEfNMvrv4FIEgEkrlM7Iw275MhhjwCWTIKpaRzxb+jwLYJPptN bQMDxdXz2VuKGR1EofXpuziX259Hh7jsHIfjGcbPcRmD1Hvg3fyLkDEuAdtBo0d5G61M dydkHGVFX1WGPNMkyEHonechh36cVjk0Fv1Wmq8M/+tmID9g6qVhEDO3yubwmrQNHQM4 5MBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kkKhCsVybrswEzpFYpVz+neJW2/9A7Ec4SSaA1CYV64=; b=I8o+iBzaPmzkyg4QL4AatxbJE1Geonu+Z8Cl9rPgE77pzo5SxEeSduGFYdJ9VnBUWG PXZM7M+jo/VgFifxB7sUmpLgYkhSngPG5kG1QToM6Q1UkxPZqiYKskhvAX9m1ia7929P lcMTg7nlVQ9KgAVzVBJHdPC13Jb+EA0CHj+AMYq+ByZ29ltWWHfcurgFgl5WAlIDILrb mRra4PN0jMFEWxSzkzRz6ZVDPsVQDfGYhUkzUJnG54TRky402vgeREI9jYbJXHsVQy+d bXeSNJfT7sX5cJqi9oPQF6pcasi+f2R0q4suqwKkaZJe0tHpPGlLVGrTBrPvLpUl177c zfsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=X77w41kG; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id dz11si44401342edb.137.2021.11.08.23.03.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Nov 2021 23:03:07 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=X77w41kG; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 172D38385E; Tue, 9 Nov 2021 08:02:44 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="X77w41kG"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9AAEC8386A; Tue, 9 Nov 2021 08:02:38 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) (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 825C3836F8 for ; Tue, 9 Nov 2021 08:02:32 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-wm1-x333.google.com with SMTP id b184-20020a1c1bc1000000b0033140bf8dd5so1481698wmb.5 for ; Mon, 08 Nov 2021 23:02:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kkKhCsVybrswEzpFYpVz+neJW2/9A7Ec4SSaA1CYV64=; b=X77w41kG1A/w7K4ePGljoY+UB7oQbMVXZy9MTivVz42A0Ql7EN3qdgVbhdCq+wXw77 3kHJ0nKgDeLSK0Lz9QihwoDiwGOSy5Dl6g2++1ZovFYLGU5scjzAEVjDgXJlh4G2WoKP rgMaodMd/sVAnDYtolNoLhPDoyFkqo+H4z/nQk8We9EDD2PBDO6VtctH0E5CoQrCX5V6 yoXxLC3395fTsQztK/N9bnnTORTutnwQ1AZ6gD68qvsR/30iVW2Lixgm01DOvXn5cFfQ IUzJOAXdgqCpi2LUFsZ/mhqu+Mn8aI02Rud0tHbKKBio4l40hnKfZC1QHHy8pAk18mzV juhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kkKhCsVybrswEzpFYpVz+neJW2/9A7Ec4SSaA1CYV64=; b=ZT5AePBLgTPezp+nLH+YDqDHwFAHHaL7a8YCDKCHIFtauhcuwdbKGnDMH5I+RSjwCV jSH19ywbgLotYcDSOp29ulVoxlYAVyB7kGf1jF2qyqmvweoDtOkgaFjvylrqebLtaJPv E6adZK+WbVYySTAYqCEDkYAPSyiCs6ofh5arSZxz/C6YoATDHSkCcibvLNn0n36+lk5f DzTg7/spZyEnX4+JZ+X06tv5CnDOAjntksNU2yC86c7dS0TZdRupnoBXtXOWzf12+M6g Ce6Sz6YKSC4zzRw3mCg1L+BjFK8ExAbQMlxE5TBGLRfk2SmsTx1dHNOF+E79+uk92etd 7mbA== X-Gm-Message-State: AOAM533AnW65pTNSqOPmJxW8dXgvlCVtUtlEFMbmkYJpViKSpLvkcc1h WstzZqPtIpUspkHtdRhjPH/LK8yCaFvh0Q== X-Received: by 2002:a05:600c:4f02:: with SMTP id l2mr4724316wmq.26.1636441352049; Mon, 08 Nov 2021 23:02:32 -0800 (PST) Received: from apalos.home ([2a02:587:4627:18c0:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id g5sm20897229wri.45.2021.11.08.23.02.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Nov 2021 23:02:31 -0800 (PST) From: Ilias Apalodimas To: u-boot@lists.denx.de Cc: trini@konsulko.com, Ilias Apalodimas , Rick Chen , Simon Glass , Sean Anderson , Heinrich Schuchardt , Masahisa Kojima Subject: [PATCH 3/8 v7] tpm2: Introduce TIS tpm core Date: Tue, 9 Nov 2021 09:02:17 +0200 Message-Id: <20211109070223.76456-4-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211109070223.76456-1-ilias.apalodimas@linaro.org> References: <20211109070223.76456-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.103.2 at phobos.denx.de X-Virus-Status: Clean There's a lot of code duplication in U-Boot right now. All the TPM TIS compatible drivers we have at the moment have their own copy of a TIS implementation. So let's create a common layer which implements the core TIS functions. Any driver added from now own, which is compatible with the TIS spec, will only have to provide the underlying bus communication mechanisms. Signed-off-by: Ilias Apalodimas Reviewed-by: Simon Glass --- drivers/tpm/tpm2_tis_core.c | 463 ++++++++++++++++++++++++++++++++++++ drivers/tpm/tpm_tis.h | 136 +++++++++++ include/tpm-v2.h | 1 + 3 files changed, 600 insertions(+) create mode 100644 drivers/tpm/tpm2_tis_core.c diff --git a/drivers/tpm/tpm2_tis_core.c b/drivers/tpm/tpm2_tis_core.c new file mode 100644 index 000000000000..ec8c730fe906 --- /dev/null +++ b/drivers/tpm/tpm2_tis_core.c @@ -0,0 +1,463 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2020, Linaro Limited + * + * Based on the Linux TIS core interface and U-Boot original SPI TPM driver + */ + +#include +#include +#include +#include +#include +#include "tpm_tis.h" + +int tpm_tis_get_desc(struct udevice *dev, char *buf, int size) +{ + struct tpm_chip *chip = dev_get_priv(dev); + + if (size < 80) + return -ENOSPC; + + return snprintf(buf, size, + "%s v2.0: VendorID 0x%04x, DeviceID 0x%04x, RevisionID 0x%02x [%s]", + dev->name, chip->vend_dev & 0xFFFF, + chip->vend_dev >> 16, chip->rid, + (chip->is_open ? "open" : "closed")); +} + +/** + * tpm_tis_check_locality - Check the current TPM locality + * + * @dev: TPM device + * @loc: locality + * + * Return: True if the tested locality matches + */ +static bool tpm_tis_check_locality(struct udevice *dev, int loc) +{ + struct tpm_chip *chip = dev_get_priv(dev); + struct tpm_tis_phy_ops *phy_ops = chip->phy_ops; + u8 locality; + + phy_ops->read_bytes(dev, TPM_ACCESS(loc), 1, &locality); + if ((locality & (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID | + TPM_ACCESS_REQUEST_USE)) == + (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) { + chip->locality = loc; + return true; + } + + return false; +} + +/** + * tpm_tis_request_locality - Request a locality from the TPM + * + * @dev: TPM device + * @loc: requested locality + * + * Return: 0 on success -1 on failure + */ +int tpm_tis_request_locality(struct udevice *dev, int loc) +{ + struct tpm_chip *chip = dev_get_priv(dev); + struct tpm_tis_phy_ops *phy_ops = chip->phy_ops; + u8 buf = TPM_ACCESS_REQUEST_USE; + unsigned long start, stop; + + if (tpm_tis_check_locality(dev, loc)) + return 0; + + phy_ops->write_bytes(dev, TPM_ACCESS(loc), 1, &buf); + start = get_timer(0); + stop = chip->timeout_a; + do { + if (tpm_tis_check_locality(dev, loc)) + return 0; + mdelay(TPM_TIMEOUT_MS); + } while (get_timer(start) < stop); + + return -1; +} + +/** + * tpm_tis_status - Check the current device status + * + * @dev: TPM device + * @status: return value of status + * + * Return: 0 on success, negative on failure + */ +static int tpm_tis_status(struct udevice *dev, u8 *status) +{ + struct tpm_chip *chip = dev_get_priv(dev); + struct tpm_tis_phy_ops *phy_ops = chip->phy_ops; + + if (chip->locality < 0) + return -EINVAL; + + phy_ops->read_bytes(dev, TPM_STS(chip->locality), 1, status); + + if ((*status & TPM_STS_READ_ZERO)) { + log_err("TPM returned invalid status\n"); + return -EINVAL; + } + + return 0; +} + +/** + * tpm_tis_release_locality - Release the requested locality + * + * @dev: TPM device + * @loc: requested locality + * + * Return: 0 on success, negative on failure + */ +int tpm_tis_release_locality(struct udevice *dev, int loc) +{ + struct tpm_chip *chip = dev_get_priv(dev); + struct tpm_tis_phy_ops *phy_ops = chip->phy_ops; + u8 buf = TPM_ACCESS_ACTIVE_LOCALITY; + int ret; + + if (chip->locality < 0) + return 0; + + ret = phy_ops->write_bytes(dev, TPM_ACCESS(loc), 1, &buf); + chip->locality = -1; + + return ret; +} + +/** + * tpm_tis_wait_for_stat - Wait for TPM to become ready + * + * @dev: TPM device + * @mask: mask to match + * @timeout: timeout for retries + * @status: current status + * + * Return: 0 on success, negative on failure + */ +static int tpm_tis_wait_for_stat(struct udevice *dev, u8 mask, + unsigned long timeout, u8 *status) +{ + unsigned long start = get_timer(0); + unsigned long stop = timeout; + int ret; + + do { + mdelay(TPM_TIMEOUT_MS); + ret = tpm_tis_status(dev, status); + if (ret) + return ret; + + if ((*status & mask) == mask) + return 0; + } while (get_timer(start) < stop); + + return -ETIMEDOUT; +} + +/** + * tpm_tis_get_burstcount - Get the burstcount for the data FIFO + * + * @dev: TPM device + * @burstcount: current burstcount + * + * Return: 0 on success, negative on failure + */ +static int tpm_tis_get_burstcount(struct udevice *dev, size_t *burstcount) +{ + struct tpm_chip *chip = dev_get_priv(dev); + struct tpm_tis_phy_ops *phy_ops = chip->phy_ops; + unsigned long start, stop; + u32 burst; + + if (chip->locality < 0) + return -EINVAL; + + /* wait for burstcount */ + start = get_timer(0); + /* + * This is the TPMv2 defined timeout. Change this in case you want to + * make the driver compatile to TPMv1 + */ + stop = chip->timeout_a; + do { + phy_ops->read32(dev, TPM_STS(chip->locality), &burst); + *burstcount = (burst >> 8) & 0xFFFF; + if (*burstcount) + return 0; + + mdelay(TPM_TIMEOUT_MS); + } while (get_timer(start) < stop); + + return -ETIMEDOUT; +} + +/** + * tpm_tis_ready - Cancel pending comands and get the device on a ready state + * + * @dev: TPM device + * + * Return: 0 on success, negative on failure + */ +static int tpm_tis_ready(struct udevice *dev) +{ + struct tpm_chip *chip = dev_get_priv(dev); + struct tpm_tis_phy_ops *phy_ops = chip->phy_ops; + u8 data = TPM_STS_COMMAND_READY; + + /* This will cancel any pending commands */ + return phy_ops->write_bytes(dev, TPM_STS(chip->locality), 1, &data); +} + +int tpm_tis_send(struct udevice *dev, const u8 *buf, size_t len) +{ + struct tpm_chip *chip = dev_get_priv(dev); + struct tpm_tis_phy_ops *phy_ops = chip->phy_ops; + size_t burstcnt, wr_size, sent = 0; + u8 data = TPM_STS_GO; + u8 status; + int ret; + + if (!chip) + return -ENODEV; + + ret = tpm_tis_request_locality(dev, 0); + if (ret < 0) + return -EBUSY; + + ret = tpm_tis_status(dev, &status); + if (ret) + goto release_locality; + + if (!(status & TPM_STS_COMMAND_READY)) { + ret = tpm_tis_ready(dev); + if (ret) { + log_err("Can't cancel previous TPM operation\n"); + goto release_locality; + } + ret = tpm_tis_wait_for_stat(dev, TPM_STS_COMMAND_READY, + chip->timeout_b, &status); + if (ret) { + log_err("TPM not ready\n"); + goto release_locality; + } + } + + while (len > 0) { + ret = tpm_tis_get_burstcount(dev, &burstcnt); + if (ret) + goto release_locality; + + wr_size = min(len, burstcnt); + ret = phy_ops->write_bytes(dev, TPM_DATA_FIFO(chip->locality), + wr_size, buf + sent); + if (ret < 0) + goto release_locality; + + ret = tpm_tis_wait_for_stat(dev, TPM_STS_VALID, + chip->timeout_c, &status); + if (ret) + goto release_locality; + + sent += wr_size; + len -= wr_size; + /* make sure the TPM expects more data */ + if (len && !(status & TPM_STS_DATA_EXPECT)) { + ret = -EIO; + goto release_locality; + } + } + + /* + * Make a final check ensuring everything is ok and the TPM expects no + * more data + */ + ret = tpm_tis_wait_for_stat(dev, TPM_STS_VALID, chip->timeout_c, + &status); + if (ret) + goto release_locality; + + if (status & TPM_STS_DATA_EXPECT) { + ret = -EIO; + goto release_locality; + } + + ret = phy_ops->write_bytes(dev, TPM_STS(chip->locality), 1, &data); + if (ret) + goto release_locality; + + return sent; + +release_locality: + tpm_tis_ready(dev); + tpm_tis_release_locality(dev, chip->locality); + + return ret; +} + +static int tpm_tis_recv_data(struct udevice *dev, u8 *buf, size_t count) +{ + struct tpm_chip *chip = dev_get_priv(dev); + struct tpm_tis_phy_ops *phy_ops = chip->phy_ops; + int size = 0, len, ret; + size_t burstcnt; + u8 status; + + while (size < count && + tpm_tis_wait_for_stat(dev, TPM_STS_DATA_AVAIL | TPM_STS_VALID, + chip->timeout_c, &status) == 0) { + ret = tpm_tis_get_burstcount(dev, &burstcnt); + if (ret) + return ret; + + len = min_t(int, burstcnt, count - size); + ret = phy_ops->read_bytes(dev, TPM_DATA_FIFO(chip->locality), + len, buf + size); + if (ret < 0) + return ret; + + size += len; + } + + return size; +} + +/** + * tpm_tis_recv - Receive data from a device + * + * @dev: TPM device + * @buf: buffer to copy data + * @size: buffer size + * + * Return: bytes read or negative on failure + */ +int tpm_tis_recv(struct udevice *dev, u8 *buf, size_t count) +{ + struct tpm_chip *chip = dev_get_priv(dev); + int size, expected; + + if (count < TPM_HEADER_SIZE) + return -E2BIG; + + size = tpm_tis_recv_data(dev, buf, TPM_HEADER_SIZE); + if (size < TPM_HEADER_SIZE) { + log_err("TPM error, unable to read header\n"); + goto out; + } + + expected = get_unaligned_be32(buf + TPM_CMD_COUNT_OFFSET); + if (expected > count) { + size = -EIO; + log_warning("Too much data: %d > %zu\n", expected, count); + goto out; + } + + size += tpm_tis_recv_data(dev, &buf[TPM_HEADER_SIZE], + expected - TPM_HEADER_SIZE); + if (size < expected) { + log(LOGC_NONE, LOGL_ERR, + "TPM error, unable to read remaining bytes of result\n"); + size = -EIO; + goto out; + } + +out: + tpm_tis_ready(dev); + /* acquired in tpm_tis_send */ + tpm_tis_release_locality(dev, chip->locality); + + return size; +} + +int tpm_tis_cleanup(struct udevice *dev) +{ + struct tpm_chip *chip = dev_get_priv(dev); + + tpm_tis_ready(dev); + tpm_tis_release_locality(dev, chip->locality); + + return 0; +} + +int tpm_tis_open(struct udevice *dev) +{ + struct tpm_chip *chip = dev_get_priv(dev); + int ret; + + if (chip->is_open) + return -EBUSY; + + ret = tpm_tis_request_locality(dev, 0); + if (!ret) + chip->is_open = 1; + + return ret; +} + +void tpm_tis_ops_register(struct udevice *dev, struct tpm_tis_phy_ops *ops) +{ + struct tpm_chip *chip = dev_get_priv(dev); + + chip->phy_ops = ops; +} + +static bool tis_check_ops(struct tpm_tis_phy_ops *phy_ops) +{ + if (!phy_ops || !phy_ops->read_bytes || !phy_ops->write_bytes || + !phy_ops->read32 || !phy_ops->write32) + return false; + + return true; +} + +int tpm_tis_init(struct udevice *dev) +{ + struct tpm_chip *chip = dev_get_priv(dev); + struct tpm_tis_phy_ops *phy_ops = chip->phy_ops; + int ret; + u32 tmp; + + if (!tis_check_ops(phy_ops)) { + log_err("Driver bug. No bus ops defined\n"); + return -1; + } + ret = tpm_tis_request_locality(dev, 0); + if (ret) + return ret; + + chip->timeout_a = TIS_SHORT_TIMEOUT_MS; + chip->timeout_b = TIS_LONG_TIMEOUT_MS; + chip->timeout_c = TIS_SHORT_TIMEOUT_MS; + chip->timeout_d = TIS_SHORT_TIMEOUT_MS; + + /* Disable interrupts */ + phy_ops->read32(dev, TPM_INT_ENABLE(chip->locality), &tmp); + tmp |= TPM_INTF_CMD_READY_INT | TPM_INTF_LOCALITY_CHANGE_INT | + TPM_INTF_DATA_AVAIL_INT | TPM_INTF_STS_VALID_INT; + tmp &= ~TPM_GLOBAL_INT_ENABLE; + phy_ops->write32(dev, TPM_INT_ENABLE(chip->locality), tmp); + + phy_ops->read_bytes(dev, TPM_RID(chip->locality), 1, &chip->rid); + phy_ops->read32(dev, TPM_DID_VID(chip->locality), &chip->vend_dev); + + return tpm_tis_release_locality(dev, chip->locality); +} + +int tpm_tis_close(struct udevice *dev) +{ + struct tpm_chip *chip = dev_get_priv(dev); + int ret = 0; + + if (chip->is_open) { + ret = tpm_tis_release_locality(dev, chip->locality); + chip->is_open = 0; + } + + return ret; +} diff --git a/drivers/tpm/tpm_tis.h b/drivers/tpm/tpm_tis.h index 2a160fe05c9a..93f622f29104 100644 --- a/drivers/tpm/tpm_tis.h +++ b/drivers/tpm/tpm_tis.h @@ -21,6 +21,73 @@ #include #include +/** + * struct tpm_tis_phy_ops - low-level TPM bus operations + */ +struct tpm_tis_phy_ops { + /* read_bytes() - Read a number of bytes from the device + * + * @udev: TPM device + * @addr: offset from device base + * @len: len to read + * @result: data read + * + * @return: 0 on success, negative on failure + */ + int (*read_bytes)(struct udevice *udev, u32 addr, u16 len, + u8 *result); + /* write_bytes() - Read a number of bytes from the device + * + * @udev: TPM device + * @addr: offset from device base + * @len: len to read + * @value: data to write + * + * @return: 0 on success, negative on failure + */ + int (*write_bytes)(struct udevice *udev, u32 addr, u16 len, + const u8 *value); + /* read32() - Read a 32bit value of the device + * + * @udev: TPM device + * @addr: offset from device base + * @result: data read + * + * @return: 0 on success, negative on failure + */ + int (*read32)(struct udevice *udev, u32 addr, u32 *result); + /* write32() - write a 32bit value to the device + * + * @udev: TPM device + * @addr: offset from device base + * @src: data to write + * + * @return: 0 on success, negative on failure + */ + int (*write32)(struct udevice *udev, u32 addr, u32 src); +}; + +enum tis_int_flags { + TPM_GLOBAL_INT_ENABLE = 0x80000000, + TPM_INTF_BURST_COUNT_STATIC = 0x100, + TPM_INTF_CMD_READY_INT = 0x080, + TPM_INTF_INT_EDGE_FALLING = 0x040, + TPM_INTF_INT_EDGE_RISING = 0x020, + TPM_INTF_INT_LEVEL_LOW = 0x010, + TPM_INTF_INT_LEVEL_HIGH = 0x008, + TPM_INTF_LOCALITY_CHANGE_INT = 0x004, + TPM_INTF_STS_VALID_INT = 0x002, + TPM_INTF_DATA_AVAIL_INT = 0x001, +}; + +#define TPM_ACCESS(l) (0x0000 | ((l) << 12)) +#define TPM_INT_ENABLE(l) (0x0008 | ((l) << 12)) +#define TPM_STS(l) (0x0018 | ((l) << 12)) +#define TPM_DATA_FIFO(l) (0x0024 | ((l) << 12)) +#define TPM_DID_VID(l) (0x0f00 | ((l) << 12)) +#define TPM_RID(l) (0x0f04 | ((l) << 12)) +#define TPM_INTF_CAPS(l) (0x0014 | ((l) << 12)) + enum tpm_timeout { TPM_TIMEOUT_MS = 5, TIS_SHORT_TIMEOUT_MS = 750, @@ -43,6 +110,7 @@ struct tpm_chip { u8 rid; unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* msec */ ulong chip_type; + struct tpm_tis_phy_ops *phy_ops; }; struct tpm_input_header { @@ -130,4 +198,72 @@ enum tis_status { }; #endif +/** + * tpm_tis_open - Open the device and request locality 0 + * + * @dev: TPM device + * + * @return: 0 on success, negative on failure + */ +int tpm_tis_open(struct udevice *udev); +/** + * tpm_tis_close - Close the device and release locality + * + * @dev: TPM device + * + * @return: 0 on success, negative on failure + */ +int tpm_tis_close(struct udevice *udev); +/** tpm_tis_cleanup - Get the device in ready state and release locality + * + * @dev: TPM device + * + * @return: always 0 + */ +int tpm_tis_cleanup(struct udevice *udev); +/** + * tpm_tis_send - send data to the device + * + * @dev: TPM device + * @buf: buffer to send + * @len: size of the buffer + * + * @return: number of bytes sent or negative on failure + */ +int tpm_tis_send(struct udevice *udev, const u8 *buf, size_t len); +/** + * tpm_tis_recv_data - Receive data from a device. Wrapper for tpm_tis_recv + * + * @dev: TPM device + * @buf: buffer to copy data + * @size: buffer size + * + * @return: bytes read or negative on failure + */ +int tpm_tis_recv(struct udevice *udev, u8 *buf, size_t count); +/** + * tpm_tis_get_desc - Get the TPM description + * + * @dev: TPM device + * @buf: buffer to fill data + * @size: buffer size + * + * @return: Number of characters written (or would have been written) in buffer + */ +int tpm_tis_get_desc(struct udevice *udev, char *buf, int size); +/** + * tpm_tis_init - inititalize the device + * + * @dev: TPM device + * + * @return: 0 on success, negative on failure + */ +int tpm_tis_init(struct udevice *udev); +/** + * tpm_tis_ops_register - register the PHY ops for the device + * + * @dev: TPM device + * @ops: tpm_tis_phy_ops ops for the device + */ +void tpm_tis_ops_register(struct udevice *udev, struct tpm_tis_phy_ops *ops); #endif diff --git a/include/tpm-v2.h b/include/tpm-v2.h index 947458b0bdfd..ceff7d245ed2 100644 --- a/include/tpm-v2.h +++ b/include/tpm-v2.h @@ -396,6 +396,7 @@ enum { TPM_STS_DATA_EXPECT = 1 << 3, TPM_STS_SELF_TEST_DONE = 1 << 2, TPM_STS_RESPONSE_RETRY = 1 << 1, + TPM_STS_READ_ZERO = 0x23 }; enum { From patchwork Tue Nov 9 07:02:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 518036 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp1320395iml; Mon, 8 Nov 2021 23:03:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJyL53QFJiyzGFga7j2zXZVQxSke4j4SON/K4Mcxy1KPfkX+rMjE7eN8iWV+4gZFqmu/WFIw X-Received: by 2002:a17:906:1706:: with SMTP id c6mr6771141eje.343.1636441397285; Mon, 08 Nov 2021 23:03:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636441397; cv=none; d=google.com; s=arc-20160816; b=RRpyu0VQirLyvRL98fPX7WhjwXNpKxW8+NQMm4q1BG80ZjoUAmaw/0dm1+uTEWe6s5 75VD5LcJCTo2AsL8e5x8zb3YG23lreT9Vd2vxhoR0n5R59aRzuNLlxu78ZPtdIzGnGeK PF8gdMkRAt8WjlS2xu8M+LUdXcKgYRldRzggAXyI9CCVStgW92FqNy6RYmoqIQr9W03A PTQYZAI6Czrs9HWLpJJg7BxdgC85e8ndoMnuDCulC1g9NMUraM1FrALWOzB4S0nfl+aR qasY1X7LbX6BBurJLfq8gMqIIUDJbsMR8a9woZr2ZIHocztStbBLZsAlYBP/Vkef08Mc KB2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vEKAopS+Fo2OmqoXy+6BbqTUkmOJU/7ImTKwHy3zLq4=; b=KcufelU14DhkF+9KEMolXXx1vSuuNTn1MuGGwka8jxn/nf3neXRm667EQmEy57td9X DCzOw0uBLkZysk7D3qfR7I+cTJc9XNYZb4phFDZMizoEgE/m40E+EqU6+gEeXo7+sCRP UlFZ1Ygrhn3wpvIliCVvUiM0BHTQib1H7itq0exo+5lah/KDUcM9sEo0G5ChCZ0Emkyr bY1UufZgJQpQOnAjJTRqA/DobaPrR2jnHOyvkmtBZW9GhLi2qRb+MwUkvP5EYDFtLKEs deb6cU882gB2czzpIVK+ccPCXy16ar4s6eh4jzTZPeihIN994UL1Xquu2vJdY7vMGo5m wSUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=S1+RWXkg; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id qa41si37526848ejc.612.2021.11.08.23.03.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Nov 2021 23:03:17 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=S1+RWXkg; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6EAA5838EF; Tue, 9 Nov 2021 08:02:48 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="S1+RWXkg"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 04234836F8; Tue, 9 Nov 2021 08:02:39 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) (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 80224836B4 for ; Tue, 9 Nov 2021 08:02:34 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-wr1-x431.google.com with SMTP id s13so31213885wrb.3 for ; Mon, 08 Nov 2021 23:02:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vEKAopS+Fo2OmqoXy+6BbqTUkmOJU/7ImTKwHy3zLq4=; b=S1+RWXkgB/bGwnLbO00c00Oly1mOohKRS5fuME7IeVXO0SsRQlIPfI/+QbYtk0Fiau kNFa+q3+XsCOBrTrnqwKP0NJpfmpprgg+mN4sR345iZrB01KcRizEsKCK/jvD3KCp2ie n41BWFsoRHtQeZ0H455m6NAvueRXF6z7wsWsR+FmcoUdHVclDjr93Y54qm3TVq8BAHcF WSVnGpdEdvRz4rVaVEsslBFSknghNevoPQPQ+YqnOmxyMCL8D+eaf8rNGJbqjuxBayGI ZgdMdDAC51+Uqp5FKjBRg74p3Bc6Q7UWeY9P3CskNz6aosqSrMxOP6M9ULTWcAbBE58a w1KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vEKAopS+Fo2OmqoXy+6BbqTUkmOJU/7ImTKwHy3zLq4=; b=40smgDGcUabY49nmzTwzR/Kv5wJELNJbO5Cc1gb/iQ6E5i8FSrzR9jeTYliQreU7td cVD9RD6DsYQS0eLfGYtteuj8se/KW53QAWm0qMAi/UTkeJWcN8RdYEYLkdfoPDFZbF/N xXu7Ts/s0UMvsi0DjKsxrazDnQMatgB1GDjaWtvKm7jfYDjM2Ou7bcgRn9Vz1ZiWVPDz anedg3pyjjed3yTCfhopXdbMgXckKz3AvUHYKAH8UzqcfgBeKy633T8vhUzj++0tyUhe O5WeNWIUWe0I++TsAN4SneibgRVmBFZao9Vbf99gdWzRZsTqFWvl4mLQmeAfPD9uBNjR lGbA== X-Gm-Message-State: AOAM530KS2DJ3oVni+QmP8X+OJjEZceN1XPSs6eb6PfQ9XFgqdlwwbdS 2n/cff3wV7UgX5OKhtHu1AAD9kkiwFoK+A== X-Received: by 2002:a5d:47a9:: with SMTP id 9mr6629318wrb.42.1636441354083; Mon, 08 Nov 2021 23:02:34 -0800 (PST) Received: from apalos.home ([2a02:587:4627:18c0:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id g5sm20897229wri.45.2021.11.08.23.02.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Nov 2021 23:02:33 -0800 (PST) From: Ilias Apalodimas To: u-boot@lists.denx.de Cc: trini@konsulko.com, Ilias Apalodimas , Simon Glass , Rick Chen , Sean Anderson , Masahisa Kojima , Heinrich Schuchardt Subject: [PATCH 4/8 v7] tpm2: Add a TPMv2 MMIO TIS driver Date: Tue, 9 Nov 2021 09:02:18 +0200 Message-Id: <20211109070223.76456-5-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211109070223.76456-1-ilias.apalodimas@linaro.org> References: <20211109070223.76456-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.103.2 at phobos.denx.de X-Virus-Status: Clean Add support for devices that expose a TPMv2 though MMIO. Apart from those devices, we can use the driver in our QEMU setups and test TPM related code which is difficult to achieve using the sandbox driver (e.g test the EFI TCG2 protocol). It's worth noting that a previous patch added TPMv2 TIS core functions, which the current driver is consuming. Reviewed-by: Simon Glass Signed-off-by: Ilias Apalodimas --- drivers/tpm/Kconfig | 9 +++ drivers/tpm/Makefile | 1 + drivers/tpm/tpm2_tis_mmio.c | 157 ++++++++++++++++++++++++++++++++++++ 3 files changed, 167 insertions(+) create mode 100644 drivers/tpm/tpm2_tis_mmio.c diff --git a/drivers/tpm/Kconfig b/drivers/tpm/Kconfig index 9eebab5cfd90..406ee8716e1e 100644 --- a/drivers/tpm/Kconfig +++ b/drivers/tpm/Kconfig @@ -161,6 +161,15 @@ config TPM2_FTPM_TEE help This driver supports firmware TPM running in TEE. +config TPM2_MMIO + bool "MMIO based TPM2 Interface" + depends on TPM_V2 + help + This driver supports firmware TPM2.0 MMIO interface. + The usual TPM operations and the 'tpm' command can be used to talk + to the device using the standard TPM Interface Specification (TIS) + protocol. + endif # TPM_V2 endmenu diff --git a/drivers/tpm/Makefile b/drivers/tpm/Makefile index c65be5267002..494aa5a46d30 100644 --- a/drivers/tpm/Makefile +++ b/drivers/tpm/Makefile @@ -14,3 +14,4 @@ obj-$(CONFIG_$(SPL_TPL_)TPM2_CR50_I2C) += cr50_i2c.o obj-$(CONFIG_TPM2_TIS_SANDBOX) += tpm2_tis_sandbox.o sandbox_common.o obj-$(CONFIG_TPM2_TIS_SPI) += tpm2_tis_spi.o obj-$(CONFIG_TPM2_FTPM_TEE) += tpm2_ftpm_tee.o +obj-$(CONFIG_TPM2_MMIO) += tpm2_tis_core.o tpm2_tis_mmio.o diff --git a/drivers/tpm/tpm2_tis_mmio.c b/drivers/tpm/tpm2_tis_mmio.c new file mode 100644 index 000000000000..9cedff222503 --- /dev/null +++ b/drivers/tpm/tpm2_tis_mmio.c @@ -0,0 +1,157 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * driver for mmio TCG/TIS TPM (trusted platform module). + * + * Specifications at www.trustedcomputinggroup.org + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "tpm_tis.h" +#include "tpm_internal.h" + +/** + * struct tpm_tis_chip_data - Information about an MMIO TPM + * @pcr_count: Number of PCR per bank + * @pcr_select_min: Minimum size in bytes of the pcrSelect array + * @iobase: Base address + */ +struct tpm_tis_chip_data { + unsigned int pcr_count; + unsigned int pcr_select_min; + void __iomem *iobase; +}; + +static int mmio_read_bytes(struct udevice *dev, u32 addr, u16 len, + u8 *result) +{ + struct tpm_tis_chip_data *drv_data = (void *)dev_get_driver_data(dev); + + while (len--) + *result++ = ioread8(drv_data->iobase + addr); + + return 0; +} + +static int mmio_write_bytes(struct udevice *dev, u32 addr, u16 len, + const u8 *value) +{ + struct tpm_tis_chip_data *drv_data = (void *)dev_get_driver_data(dev); + + while (len--) + iowrite8(*value++, drv_data->iobase + addr); + + return 0; +} + +static int mmio_read32(struct udevice *dev, u32 addr, u32 *result) +{ + struct tpm_tis_chip_data *drv_data = (void *)dev_get_driver_data(dev); + + *result = ioread32(drv_data->iobase + addr); + + return 0; +} + +static int mmio_write32(struct udevice *dev, u32 addr, u32 value) +{ + struct tpm_tis_chip_data *drv_data = (void *)dev_get_driver_data(dev); + + iowrite32(value, drv_data->iobase + addr); + + return 0; +} + +static struct tpm_tis_phy_ops phy_ops = { + .read_bytes = mmio_read_bytes, + .write_bytes = mmio_write_bytes, + .read32 = mmio_read32, + .write32 = mmio_write32, +}; + +static int tpm_tis_probe(struct udevice *dev) +{ + struct tpm_tis_chip_data *drv_data = (void *)dev_get_driver_data(dev); + struct tpm_chip_priv *priv = dev_get_uclass_priv(dev); + int ret = 0; + fdt_addr_t ioaddr; + u64 sz; + + ioaddr = dev_read_addr(dev); + if (ioaddr == FDT_ADDR_T_NONE) + return log_msg_ret("ioaddr", -EINVAL); + + ret = dev_read_u64(dev, "reg", &sz); + if (ret) + return -EINVAL; + + drv_data->iobase = ioremap(ioaddr, sz); + tpm_tis_ops_register(dev, &phy_ops); + ret = tpm_tis_init(dev); + if (ret) + goto iounmap; + + priv->pcr_count = drv_data->pcr_count; + priv->pcr_select_min = drv_data->pcr_select_min; + /* + * Although the driver probably works with a TPMv1 our Kconfig + * limits the driver to TPMv2 only + */ + priv->version = TPM_V2; + + return ret; +iounmap: + iounmap(drv_data->iobase); + + return -EINVAL; +} + +static int tpm_tis_remove(struct udevice *dev) +{ + struct tpm_tis_chip_data *drv_data = (void *)dev_get_driver_data(dev); + + iounmap(drv_data->iobase); + + return tpm_tis_cleanup(dev); +} + +static const struct tpm_ops tpm_tis_ops = { + .open = tpm_tis_open, + .close = tpm_tis_close, + .get_desc = tpm_tis_get_desc, + .send = tpm_tis_send, + .recv = tpm_tis_recv, + .cleanup = tpm_tis_cleanup, +}; + +static const struct tpm_tis_chip_data tpm_tis_std_chip_data = { + .pcr_count = 24, + .pcr_select_min = 3, +}; + +static const struct udevice_id tpm_tis_ids[] = { + { + .compatible = "tcg,tpm-tis-mmio", + .data = (ulong)&tpm_tis_std_chip_data, + }, + { } +}; + +U_BOOT_DRIVER(tpm_tis_mmio) = { + .name = "tpm_tis_mmio", + .id = UCLASS_TPM, + .of_match = tpm_tis_ids, + .ops = &tpm_tis_ops, + .probe = tpm_tis_probe, + .remove = tpm_tis_remove, + .priv_auto = sizeof(struct tpm_chip), +}; From patchwork Tue Nov 9 07:02:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 518038 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp1320720iml; Mon, 8 Nov 2021 23:03:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJxE4f51h1/ytoyo9KMow0vwjbKMSqNrQRPdTjQsFeEk7BSFT/sYpV6+MkgtVZRhjjZ3qd21 X-Received: by 2002:a50:9fa8:: with SMTP id c37mr6943347edf.83.1636441417801; Mon, 08 Nov 2021 23:03:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636441417; cv=none; d=google.com; s=arc-20160816; b=wQ7lJEI6tRjCuToGmkEOO/K7fqk+9eiycJcnVX79xCRnVxiodW3bqF1ynWMrBztyaQ gBnLloqDifLQ56MKzpnSqTsMqkMz/wiF8sWE6Yx/wjB5fcXInQoinUDo3jIPNbqSdsgL +kvALbJH4oriqRyb2zWsTUhz9wtXz4WsalYzT+ZZhyWHxZDqMgpyxptMik7h60KFVxt/ aorBf9eHa0se1fzBYJ77qv4habNIEARYMSma7fZZqTJ6iwnlUfjh22GTsU/dGMKoH/u4 7/9+sfKoYcKmB4+kIOtj7nxlETx4xS3oRrzCuGrHa7My1Cnt+AbKLS2Wb8bko3aC2wZO F4pQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=itduj/vm8pAuXM1cgITUNK8dELlNKjAMwFg5N7qomTQ=; b=mU7fUdikqX/4seD0JVyScbQ3UGsJAlYnDJL8+03rBzTwnw4gXV3SPi07jC15QqvY5R WccclJ3fWMGYi3p4d1C06W9AwJDJLrgaOBUFxRRe975KlSlzYG2pk1O5qFuB00rwVgI/ gI+lzCjq1rHhWne/ooHAStM578wxfLXOXNAxp3bhvLDFiFL4O9J1vldHkOA9mXo3nETZ uq4x9Gol4N/XqtiLoaT3MwHd9zXEF5eto0hBkRg5NLpEm/X2z/VuQ6as2CQTLENhO4Or HDO4Ut1UXDOFg1NFMsQVk7ckBmgcS5rm+r1LX1+Lwxj3hVcFR/1ZG6kVDB+HYMXAGzCi oFHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tncWPgVP; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id k3si32383563edk.215.2021.11.08.23.03.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Nov 2021 23:03:37 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tncWPgVP; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AA3DB838EE; Tue, 9 Nov 2021 08:02:54 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="tncWPgVP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C9513838F5; Tue, 9 Nov 2021 08:02:43 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) (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 B773F836E5 for ; Tue, 9 Nov 2021 08:02:36 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-wr1-x431.google.com with SMTP id u1so31166350wru.13 for ; Mon, 08 Nov 2021 23:02:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=itduj/vm8pAuXM1cgITUNK8dELlNKjAMwFg5N7qomTQ=; b=tncWPgVP1MhWHATxqnlEqRFR1zV7V5S744BLlSiWGrA60Nw2bE6IfMOBW43uRXdZRY y83oteHoM8mkGQXkDuz81ll30xwKkV9LfySOnUWq6oNlf6NAFErHOEuhAgfHAT1AEnCU ex80C89qS/NKvDc/foX67jCZRr+4I39xaI9fmHCAcSLNw3A69lkstKM6OvakGa3fSczj 2wTDpcY5oXO75NCb9RoxWwpYYiyUMgl9ORybnlZwfmez5bQmLPAUwS+JhRbW+VokOVrt B2q5xkN7l6HeSsnEn0jv5pL9nFSZBp1RteEcfhF6+zsFW3WG1ZM0wn2ZIPDOCb1L6bWg Fu7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=itduj/vm8pAuXM1cgITUNK8dELlNKjAMwFg5N7qomTQ=; b=ax5BSAZpVWJGq108YLAMpNAi3tAYHBXO+Z/bTHls5cXCH9PAspGU1ZuRjhgZLVYOiT AChlcPt0uVi8Hrigug/A1YNznQ+UAVwALGj2RULcnRUqhmxiVZ0de7UVwpVMAQXblaz6 KD4jV6oV3GIUeSYBRMC0cL6ROs2QQmnyq+daPM5lw/Bx+9ZSjKqXSiTMlh0w5CMq6T68 3/8xqBA2lpdASZ6CEdr+ZxvlvqgZ+K5ZwKE42hpcpKQvCbotcq2zwwAlouNZccEqHnED 40X816ZTX7/S4TrHIY7YKpNuDsg7//1IuFHTIpsz/mTEmttKnqbWUMASiC2nwnS0qPuL p5Kg== X-Gm-Message-State: AOAM532lWM9xrRAG1Im9JwtNMn6gVp38pJKgbrxh5nNRxIb3Xa/NakV2 HM/WdfVw8q6A6csBBJfIDH+FtaTgCYwMkg== X-Received: by 2002:a5d:43c5:: with SMTP id v5mr6778687wrr.11.1636441356197; Mon, 08 Nov 2021 23:02:36 -0800 (PST) Received: from apalos.home ([2a02:587:4627:18c0:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id g5sm20897229wri.45.2021.11.08.23.02.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Nov 2021 23:02:35 -0800 (PST) From: Ilias Apalodimas To: u-boot@lists.denx.de Cc: trini@konsulko.com, Ilias Apalodimas , Simon Glass , Rick Chen , Sean Anderson , Masahisa Kojima , Heinrich Schuchardt Subject: [PATCH 5/8 v7] tpm: Use the new API on tpm2 spi driver Date: Tue, 9 Nov 2021 09:02:19 +0200 Message-Id: <20211109070223.76456-6-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211109070223.76456-1-ilias.apalodimas@linaro.org> References: <20211109070223.76456-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.103.2 at phobos.denx.de X-Virus-Status: Clean Convert our SPI TPM driver and use the newly added API Reviewed-by: Simon Glass Signed-off-by: Ilias Apalodimas --- drivers/tpm/Makefile | 2 +- drivers/tpm/tpm2_tis_spi.c | 447 +++---------------------------------- 2 files changed, 32 insertions(+), 417 deletions(-) diff --git a/drivers/tpm/Makefile b/drivers/tpm/Makefile index 494aa5a46d30..51725230c780 100644 --- a/drivers/tpm/Makefile +++ b/drivers/tpm/Makefile @@ -12,6 +12,6 @@ obj-$(CONFIG_TPM_ST33ZP24_SPI) += tpm_tis_st33zp24_spi.o obj-$(CONFIG_$(SPL_TPL_)TPM2_CR50_I2C) += cr50_i2c.o obj-$(CONFIG_TPM2_TIS_SANDBOX) += tpm2_tis_sandbox.o sandbox_common.o -obj-$(CONFIG_TPM2_TIS_SPI) += tpm2_tis_spi.o +obj-$(CONFIG_TPM2_TIS_SPI) += tpm2_tis_core.o tpm2_tis_spi.o obj-$(CONFIG_TPM2_FTPM_TEE) += tpm2_ftpm_tee.o obj-$(CONFIG_TPM2_MMIO) += tpm2_tis_core.o tpm2_tis_mmio.o diff --git a/drivers/tpm/tpm2_tis_spi.c b/drivers/tpm/tpm2_tis_spi.c index 1d24d32d867e..58b6f3351057 100644 --- a/drivers/tpm/tpm2_tis_spi.c +++ b/drivers/tpm/tpm2_tis_spi.c @@ -30,13 +30,6 @@ #include "tpm_tis.h" #include "tpm_internal.h" -#define TPM_ACCESS(l) (0x0000 | ((l) << 12)) -#define TPM_INT_ENABLE(l) (0x0008 | ((l) << 12)) -#define TPM_STS(l) (0x0018 | ((l) << 12)) -#define TPM_DATA_FIFO(l) (0x0024 | ((l) << 12)) -#define TPM_DID_VID(l) (0x0F00 | ((l) << 12)) -#define TPM_RID(l) (0x0F04 | ((l) << 12)) - #define MAX_SPI_FRAMESIZE 64 /* Number of wait states to wait for */ @@ -165,7 +158,7 @@ release_bus: return ret; } -static int tpm_tis_spi_read(struct udevice *dev, u16 addr, u8 *in, u16 len) +static int tpm_tis_spi_read(struct udevice *dev, u32 addr, u16 len, u8 *in) { return tpm_tis_spi_xfer(dev, addr, NULL, in, len); } @@ -175,382 +168,24 @@ static int tpm_tis_spi_read32(struct udevice *dev, u32 addr, u32 *result) __le32 result_le; int ret; - ret = tpm_tis_spi_read(dev, addr, (u8 *)&result_le, sizeof(u32)); + ret = tpm_tis_spi_read(dev, addr, sizeof(u32), (u8 *)&result_le); if (!ret) *result = le32_to_cpu(result_le); return ret; } -static int tpm_tis_spi_write(struct udevice *dev, u16 addr, const u8 *out, - u16 len) -{ - return tpm_tis_spi_xfer(dev, addr, out, NULL, len); -} - -static int tpm_tis_spi_check_locality(struct udevice *dev, int loc) -{ - const u8 mask = TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID; - struct tpm_chip *chip = dev_get_priv(dev); - u8 buf; - int ret; - - ret = tpm_tis_spi_read(dev, TPM_ACCESS(loc), &buf, 1); - if (ret) - return ret; - - if ((buf & mask) == mask) { - chip->locality = loc; - return 0; - } - - return -ENOENT; -} - -static void tpm_tis_spi_release_locality(struct udevice *dev, int loc, - bool force) -{ - const u8 mask = TPM_ACCESS_REQUEST_PENDING | TPM_ACCESS_VALID; - u8 buf; - if (tpm_tis_spi_read(dev, TPM_ACCESS(loc), &buf, 1) < 0) - return; - - if (force || (buf & mask) == mask) { - buf = TPM_ACCESS_ACTIVE_LOCALITY; - tpm_tis_spi_write(dev, TPM_ACCESS(loc), &buf, 1); - } -} - -static int tpm_tis_spi_request_locality(struct udevice *dev, int loc) +static int tpm_tis_spi_write(struct udevice *dev, u32 addr, u16 len, const u8 *out) { - struct tpm_chip *chip = dev_get_priv(dev); - unsigned long start, stop; - u8 buf = TPM_ACCESS_REQUEST_USE; - int ret; - - ret = tpm_tis_spi_check_locality(dev, loc); - if (!ret) - return 0; - - if (ret != -ENOENT) { - log(LOGC_NONE, LOGL_ERR, "%s: Failed to get locality: %d\n", - __func__, ret); - return ret; - } - - ret = tpm_tis_spi_write(dev, TPM_ACCESS(loc), &buf, 1); - if (ret) { - log(LOGC_NONE, LOGL_ERR, "%s: Failed to write to TPM: %d\n", - __func__, ret); - return ret; - } - - start = get_timer(0); - stop = chip->timeout_a; - do { - ret = tpm_tis_spi_check_locality(dev, loc); - if (!ret) - return 0; - - if (ret != -ENOENT) { - log(LOGC_NONE, LOGL_ERR, - "%s: Failed to get locality: %d\n", __func__, ret); - return ret; - } - - mdelay(TPM_TIMEOUT_MS); - } while (get_timer(start) < stop); - - log(LOGC_NONE, LOGL_ERR, "%s: Timeout getting locality: %d\n", __func__, - ret); - - return ret; -} - -static u8 tpm_tis_spi_status(struct udevice *dev, u8 *status) -{ - struct tpm_chip *chip = dev_get_priv(dev); - - return tpm_tis_spi_read(dev, TPM_STS(chip->locality), status, 1); -} - -static int tpm_tis_spi_wait_for_stat(struct udevice *dev, u8 mask, - unsigned long timeout, u8 *status) -{ - unsigned long start = get_timer(0); - unsigned long stop = timeout; - int ret; - - do { - mdelay(TPM_TIMEOUT_MS); - ret = tpm_tis_spi_status(dev, status); - if (ret) - return ret; - - if ((*status & mask) == mask) - return 0; - } while (get_timer(start) < stop); - - return -ETIMEDOUT; -} - -static u8 tpm_tis_spi_valid_status(struct udevice *dev, u8 *status) -{ - struct tpm_chip *chip = dev_get_priv(dev); - - return tpm_tis_spi_wait_for_stat(dev, TPM_STS_VALID, - chip->timeout_c, status); -} - -static int tpm_tis_spi_get_burstcount(struct udevice *dev) -{ - struct tpm_chip *chip = dev_get_priv(dev); - unsigned long start, stop; - u32 burstcount, ret; - - /* wait for burstcount */ - start = get_timer(0); - stop = chip->timeout_d; - do { - ret = tpm_tis_spi_read32(dev, TPM_STS(chip->locality), - &burstcount); - if (ret) - return -EBUSY; - - burstcount = (burstcount >> 8) & 0xFFFF; - if (burstcount) - return burstcount; - - mdelay(TPM_TIMEOUT_MS); - } while (get_timer(start) < stop); - - return -EBUSY; -} - -static int tpm_tis_spi_cancel(struct udevice *dev) -{ - struct tpm_chip *chip = dev_get_priv(dev); - u8 data = TPM_STS_COMMAND_READY; - - return tpm_tis_spi_write(dev, TPM_STS(chip->locality), &data, 1); -} - -static int tpm_tis_spi_recv_data(struct udevice *dev, u8 *buf, size_t count) -{ - struct tpm_chip *chip = dev_get_priv(dev); - int size = 0, burstcnt, len, ret; - u8 status; - - while (size < count && - tpm_tis_spi_wait_for_stat(dev, - TPM_STS_DATA_AVAIL | TPM_STS_VALID, - chip->timeout_c, &status) == 0) { - burstcnt = tpm_tis_spi_get_burstcount(dev); - if (burstcnt < 0) - return burstcnt; - - len = min_t(int, burstcnt, count - size); - ret = tpm_tis_spi_read(dev, TPM_DATA_FIFO(chip->locality), - buf + size, len); - if (ret < 0) - return ret; - - size += len; - } - - return size; -} - -static int tpm_tis_spi_recv(struct udevice *dev, u8 *buf, size_t count) -{ - struct tpm_chip *chip = dev_get_priv(dev); - int size, expected; - - if (!chip) - return -ENODEV; - - if (count < TPM_HEADER_SIZE) { - size = -EIO; - goto out; - } - - size = tpm_tis_spi_recv_data(dev, buf, TPM_HEADER_SIZE); - if (size < TPM_HEADER_SIZE) { - log(LOGC_NONE, LOGL_ERR, "TPM error, unable to read header\n"); - goto out; - } - - expected = get_unaligned_be32(buf + 2); - if (expected > count) { - size = -EIO; - goto out; - } - - size += tpm_tis_spi_recv_data(dev, &buf[TPM_HEADER_SIZE], - expected - TPM_HEADER_SIZE); - if (size < expected) { - log(LOGC_NONE, LOGL_ERR, - "TPM error, unable to read remaining bytes of result\n"); - size = -EIO; - goto out; - } - -out: - tpm_tis_spi_cancel(dev); - tpm_tis_spi_release_locality(dev, chip->locality, false); - - return size; -} - -static int tpm_tis_spi_send(struct udevice *dev, const u8 *buf, size_t len) -{ - struct tpm_chip *chip = dev_get_priv(dev); - u32 i, size; - u8 status; - int burstcnt, ret; - u8 data; - - if (!chip) - return -ENODEV; - - if (len > TPM_DEV_BUFSIZE) - return -E2BIG; /* Command is too long for our tpm, sorry */ - - ret = tpm_tis_spi_request_locality(dev, 0); - if (ret < 0) - return -EBUSY; - - /* - * Check if the TPM is ready. If not, if not, cancel the pending command - * and poll on the status to be finally ready. - */ - ret = tpm_tis_spi_status(dev, &status); - if (ret) - return ret; - - if (!(status & TPM_STS_COMMAND_READY)) { - /* Force the transition, usually this will be done at startup */ - ret = tpm_tis_spi_cancel(dev); - if (ret) { - log(LOGC_NONE, LOGL_ERR, - "%s: Could not cancel previous operation\n", - __func__); - goto out_err; - } - - ret = tpm_tis_spi_wait_for_stat(dev, TPM_STS_COMMAND_READY, - chip->timeout_b, &status); - if (ret < 0 || !(status & TPM_STS_COMMAND_READY)) { - log(LOGC_NONE, LOGL_ERR, - "status %d after wait for stat returned %d\n", - status, ret); - goto out_err; - } - } - - for (i = 0; i < len - 1;) { - burstcnt = tpm_tis_spi_get_burstcount(dev); - if (burstcnt < 0) - return burstcnt; - - size = min_t(int, len - i - 1, burstcnt); - ret = tpm_tis_spi_write(dev, TPM_DATA_FIFO(chip->locality), - buf + i, size); - if (ret < 0) - goto out_err; - - i += size; - } - - ret = tpm_tis_spi_valid_status(dev, &status); - if (ret) - goto out_err; - - if ((status & TPM_STS_DATA_EXPECT) == 0) { - ret = -EIO; - goto out_err; - } - - ret = tpm_tis_spi_write(dev, TPM_DATA_FIFO(chip->locality), - buf + len - 1, 1); - if (ret) - goto out_err; - - ret = tpm_tis_spi_valid_status(dev, &status); - if (ret) - goto out_err; - - if ((status & TPM_STS_DATA_EXPECT) != 0) { - ret = -EIO; - goto out_err; - } - - data = TPM_STS_GO; - ret = tpm_tis_spi_write(dev, TPM_STS(chip->locality), &data, 1); - if (ret) - goto out_err; - - return len; - -out_err: - tpm_tis_spi_cancel(dev); - tpm_tis_spi_release_locality(dev, chip->locality, false); - - return ret; -} - -static int tpm_tis_spi_cleanup(struct udevice *dev) -{ - struct tpm_chip *chip = dev_get_priv(dev); - - tpm_tis_spi_cancel(dev); - /* - * The TPM needs some time to clean up here, - * so we sleep rather than keeping the bus busy - */ - mdelay(2); - tpm_tis_spi_release_locality(dev, chip->locality, false); - - return 0; -} - -static int tpm_tis_spi_open(struct udevice *dev) -{ - struct tpm_chip *chip = dev_get_priv(dev); - - if (chip->is_open) - return -EBUSY; - - chip->is_open = 1; - - return 0; -} - -static int tpm_tis_spi_close(struct udevice *dev) -{ - struct tpm_chip *chip = dev_get_priv(dev); - - if (chip->is_open) { - tpm_tis_spi_release_locality(dev, chip->locality, true); - chip->is_open = 0; - } - - return 0; + return tpm_tis_spi_xfer(dev, addr, out, NULL, len); } -static int tpm_tis_get_desc(struct udevice *dev, char *buf, int size) +static int tpm_tis_spi_write32(struct udevice *dev, u32 addr, u32 value) { - struct tpm_chip *chip = dev_get_priv(dev); - - if (size < 80) - return -ENOSPC; + __le32 value_le = cpu_to_le32(value); - return snprintf(buf, size, - "%s v2.0: VendorID 0x%04x, DeviceID 0x%04x, RevisionID 0x%02x [%s]", - dev->name, chip->vend_dev & 0xFFFF, - chip->vend_dev >> 16, chip->rid, - (chip->is_open ? "open" : "closed")); + return tpm_tis_spi_write(dev, addr, sizeof(value), (u8 *)&value_le); } static int tpm_tis_wait_init(struct udevice *dev, int loc) @@ -565,7 +200,7 @@ static int tpm_tis_wait_init(struct udevice *dev, int loc) do { mdelay(TPM_TIMEOUT_MS); - ret = tpm_tis_spi_read(dev, TPM_ACCESS(loc), &status, 1); + ret = tpm_tis_spi_read(dev, TPM_ACCESS(loc), 1, &status); if (ret) break; @@ -576,6 +211,13 @@ static int tpm_tis_wait_init(struct udevice *dev, int loc) return -EIO; } +static struct tpm_tis_phy_ops phy_ops = { + .read_bytes = tpm_tis_spi_read, + .write_bytes = tpm_tis_spi_write, + .read32 = tpm_tis_spi_read32, + .write32 = tpm_tis_spi_write32, +}; + static int tpm_tis_spi_probe(struct udevice *dev) { struct tpm_tis_chip_data *drv_data = (void *)dev_get_driver_data(dev); @@ -611,65 +253,38 @@ init: /* Ensure a minimum amount of time elapsed since reset of the TPM */ mdelay(drv_data->time_before_first_cmd_ms); - chip->locality = 0; - chip->timeout_a = TIS_SHORT_TIMEOUT_MS; - chip->timeout_b = TIS_LONG_TIMEOUT_MS; - chip->timeout_c = TIS_SHORT_TIMEOUT_MS; - chip->timeout_d = TIS_SHORT_TIMEOUT_MS; - priv->pcr_count = drv_data->pcr_count; - priv->pcr_select_min = drv_data->pcr_select_min; - ret = tpm_tis_wait_init(dev, chip->locality); if (ret) { log(LOGC_DM, LOGL_ERR, "%s: no device found\n", __func__); return ret; } - ret = tpm_tis_spi_request_locality(dev, chip->locality); - if (ret) { - log(LOGC_NONE, LOGL_ERR, "%s: could not request locality %d\n", - __func__, chip->locality); - return ret; - } - - ret = tpm_tis_spi_read32(dev, TPM_DID_VID(chip->locality), - &chip->vend_dev); - if (ret) { - log(LOGC_NONE, LOGL_ERR, - "%s: could not retrieve VendorID/DeviceID\n", __func__); - return ret; - } - - ret = tpm_tis_spi_read(dev, TPM_RID(chip->locality), &chip->rid, 1); - if (ret) { - log(LOGC_NONE, LOGL_ERR, "%s: could not retrieve RevisionID\n", - __func__); - return ret; - } + tpm_tis_ops_register(dev, &phy_ops); + ret = tpm_tis_init(dev); + if (ret) + goto err; - log(LOGC_NONE, LOGL_ERR, - "SPI TPMv2.0 found (vid:%04x, did:%04x, rid:%02x)\n", - chip->vend_dev & 0xFFFF, chip->vend_dev >> 16, chip->rid); + priv->pcr_count = drv_data->pcr_count; + priv->pcr_select_min = drv_data->pcr_select_min; + priv->version = TPM_V2; return 0; +err: + return -EINVAL; } -static int tpm_tis_spi_remove(struct udevice *dev) +static int tpm_tis_spi_remove(struct udevice *udev) { - struct tpm_chip *chip = dev_get_priv(dev); - - tpm_tis_spi_release_locality(dev, chip->locality, true); - - return 0; + return tpm_tis_cleanup(udev); } static const struct tpm_ops tpm_tis_spi_ops = { - .open = tpm_tis_spi_open, - .close = tpm_tis_spi_close, + .open = tpm_tis_open, + .close = tpm_tis_close, .get_desc = tpm_tis_get_desc, - .send = tpm_tis_spi_send, - .recv = tpm_tis_spi_recv, - .cleanup = tpm_tis_spi_cleanup, + .send = tpm_tis_send, + .recv = tpm_tis_recv, + .cleanup = tpm_tis_cleanup, }; static const struct tpm_tis_chip_data tpm_tis_std_chip_data = { From patchwork Tue Nov 9 07:02:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 518037 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp1320553iml; Mon, 8 Nov 2021 23:03:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJzzh9Iv0IYPvYY9H8nJiSTaTlkKw6dv3kWaOXBCo9imPKFSazi/Vz23a41/DBVpmr7PG82Y X-Received: by 2002:a17:906:79c3:: with SMTP id m3mr6654915ejo.332.1636441407101; Mon, 08 Nov 2021 23:03:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636441407; cv=none; d=google.com; s=arc-20160816; b=Ww/hRZ9fSwAkeb0cMHCKDTDAYOlwgiqsX1QMRXxOjbCOiTuCtGpZGDxLfARFJ47w/1 kk0IHSQQ8dsW6FN3lO17fAuW/WQtAPuS3o4/hFTqjiLlK3C6bCHdBPKUpv5vHCLFhq6H kVhckLiI2sQ2XQwv7q596U48hQuZ41yFEYV/lYHsnGVtqrOH9X3pPd8AS3xDn/LtysTN EgIvsuiZ6AbOKq9NeQuW5+UIKCXac60nb8G1sChzAPWuxQ7hHC0zwSIIcCEJaAJMTy7S Jk4oKcFBURxfGepdSf6PCJaq1L43SUh4PEwJOYAvrJ9RUMEqnz3mSCCT6N1cp2yC3PC9 HsDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=CBvaW0qtGIlv7Cpm8B6eAso56uWBpb1MFVIIc+pJJwQ=; b=A6zQgKBGEwG0Nofk0sKhrvwc7iFakV6z6GIL8u+f1fVIlePfjqnGdnymihwRCIOTVZ lvpLl7ST2//Ee1iIpndghxIVPPWAuOyma8i+oRwpnoqUXb8RAYF2cTyI+31tp6Vjxoq6 +GcSl8N42eMtY2GWtyWPS3H3G8aZTqWX7u+L6EtYuckMJPEaV+KUVmK/Fjlz7cHhpRuC EdfGb+m7K15k+/s1yMymkNuWTBrV9b2Aq3Q3SYHkbHniMR0hKE43ERGc/bbU27IaYNPQ N/HNDwbSKeNQVFF81izC+kWojUgkDTE9UEh8nK+Bmg/ENur4RGDAE3bNQ4tJ/f/Hkx5y Wtag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JU06d+RI; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id g15si39095347edb.25.2021.11.08.23.03.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Nov 2021 23:03:27 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JU06d+RI; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8CDF5838FE; Tue, 9 Nov 2021 08:02:51 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="JU06d+RI"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C013D838FA; Tue, 9 Nov 2021 08:02:42 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) (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 BF885836E1 for ; Tue, 9 Nov 2021 08:02:38 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-wr1-x42a.google.com with SMTP id u18so31148680wrg.5 for ; Mon, 08 Nov 2021 23:02:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CBvaW0qtGIlv7Cpm8B6eAso56uWBpb1MFVIIc+pJJwQ=; b=JU06d+RImDFShYxMnHGSrkdUFnUdIzAYeI381cRMSeLC5nCH2f/6jhRw82JV+JnmaO AQklwdMpQrWKMNwgJcOmm50yN3YcybHBRpSY7W0nQhvxad8SuOi/TLrrbk5SEBgOtHuK Z9r1I11/bq8SC6oxRizz6d1US6cOvFqVmk8urAlqzaQd1pVHMq0nBLeUBEJt3RK2KKIS yywD3ffW/tiJmTAMgqI8udaCvavYSCuAYMDc7zJZeqfvV9a6rFmbg8pwU3Jy5B6gWaGQ b0S2Bb3eBwzFX9SBB0FpQHlaIhPpBf1FIfVLUtv0vgi+HwOWSuJYWa1g2Nvvku1LYPjG g0lQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CBvaW0qtGIlv7Cpm8B6eAso56uWBpb1MFVIIc+pJJwQ=; b=zCY+obNLOnig711YccQZ2+RWAoJUCgNSpaBTq0CaM7CACGwlZliF8btXR2MX8UGpu4 g2AWEGgzBmps5j9NFdg4a8vMc6+gWCafJhW34Ai6cpjdxUlSLJne23+R79bb7fXncr0I zSJNGO/XfZMhMaHu9XBo+39OcX1MH1YjAWAZfCx7hgLbZgGmz8bJSycxP7BHf9aoYiw/ pJUv9kK3kQcRAZXaig4X74QXaccWJrSTALTvofEDoVSZ0pITatg83Jy97w0lc5MtjQur W98yip6CLqL65KexeBLIRf0YHXWcbjZv0m0v/ATl9P6otCHgJQLI8/xUiUIW+28y1fA6 W3KA== X-Gm-Message-State: AOAM5312UDxWT3EJXSTW0E+kiBOy+xHL9JT1iRbcEWFWWVLylp/ECtoS 89eEyyx29AgjWBn3pRkPPF3JupDklwlIog== X-Received: by 2002:a5d:6691:: with SMTP id l17mr6426241wru.227.1636441358223; Mon, 08 Nov 2021 23:02:38 -0800 (PST) Received: from apalos.home ([2a02:587:4627:18c0:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id g5sm20897229wri.45.2021.11.08.23.02.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Nov 2021 23:02:37 -0800 (PST) From: Ilias Apalodimas To: u-boot@lists.denx.de Cc: trini@konsulko.com, Ilias Apalodimas , Simon Glass , Rick Chen , Sean Anderson , Masahisa Kojima , Heinrich Schuchardt Subject: [PATCH 6/8 v7] configs: Enable tpmv2 mmio on qemu for arm/arm64 Date: Tue, 9 Nov 2021 09:02:20 +0200 Message-Id: <20211109070223.76456-7-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211109070223.76456-1-ilias.apalodimas@linaro.org> References: <20211109070223.76456-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.103.2 at phobos.denx.de X-Virus-Status: Clean A previous commit is adding an MMIO TPMv2 driver. Include in the default qemu arm configs, since we plan on using them on EFI testing Reviewed-by: Simon Glass Signed-off-by: Ilias Apalodimas --- configs/qemu_arm64_defconfig | 2 ++ configs/qemu_arm_defconfig | 2 ++ 2 files changed, 4 insertions(+) diff --git a/configs/qemu_arm64_defconfig b/configs/qemu_arm64_defconfig index 003717efde28..83d7ae54de4d 100644 --- a/configs/qemu_arm64_defconfig +++ b/configs/qemu_arm64_defconfig @@ -49,6 +49,8 @@ CONFIG_SCSI=y CONFIG_DM_SCSI=y CONFIG_SYSRESET=y CONFIG_SYSRESET_PSCI=y +CONFIG_TPM2_MMIO=y CONFIG_USB=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_EHCI_PCI=y +CONFIG_TPM=y diff --git a/configs/qemu_arm_defconfig b/configs/qemu_arm_defconfig index 27b0e49f6f89..ab5574847e89 100644 --- a/configs/qemu_arm_defconfig +++ b/configs/qemu_arm_defconfig @@ -51,6 +51,8 @@ CONFIG_SCSI=y CONFIG_DM_SCSI=y CONFIG_SYSRESET=y CONFIG_SYSRESET_PSCI=y +CONFIG_TPM2_MMIO=y CONFIG_USB=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_EHCI_PCI=y +CONFIG_TPM=y From patchwork Tue Nov 9 07:02:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 518039 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp1320889iml; Mon, 8 Nov 2021 23:03:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJyMP9eo96P37eC3cbGquz3Je9pY6xvMKC+0XOYBSszMGNZTT9IGHkUtVHJIux7XkTtRkMvZ X-Received: by 2002:a17:907:d08:: with SMTP id gn8mr6509791ejc.395.1636441427292; Mon, 08 Nov 2021 23:03:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636441427; cv=none; d=google.com; s=arc-20160816; b=0SvUHP8LrlUH9NeC1/Yvmb3tIB5jyqzQbp6v5Deww5/dA6ScXRU4MyEm2YoLw9dXdW tCugxfpPtbSegUB0A376BccCZ7+ZqrV7nplZt5lNJwnvRGSHvpq/Flqvo1qKAwmL+m4c EqkI+KDfmHkknIUtO3Kofous6tEY+S1FdgtsDzPS+4p2BShBzF2n3ZaK477XpFA6wsNC S2QVlfLAkQ7XJvPZGogJ0oT6uw9H9/CelFPW8UoLKSVZ4CkjTekVSpJ1QvMMsBCmDKpP oD0VGm+u/dw6LjhCVZ/PCT+OJ6bzzlpTUgwSnyOFAcOO6Tqn8PjIEgXuTC+9h1424pPe 6KSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gVxITKNNyabd+K7xCPMvJ/lgGw/5PpSnX0szDoDYjKE=; b=WQLg1YFUVCjqYGepTQycHi/TgUjonR18aLy1ARC/bJuBJk///ZZGtqHKZ/nLhU9pS1 VLM3fiA9MZJCIyDsXXwnuHJeirK+Lp3ZttXfgRhvNZKvMtx7anh3yxIxvnp9akG3UsAO EFQWHHV+UbCy48U3980h3sMmrkrJyJb/lMWRkYIeo9hSfxQmlq3JMMcpTUErL+y0kA9e cTrFQIxu4CiiLb1i0w56+fhh5l/AlXog+tvyxayXh0i95xTBSr7NfnbsZoc7Qkv6Y99z W2FKezY7yFCxzxuKtoB6ga+7e+nZ89fMb8czofijq/t9NVEAq/zx6EyDZ12PFL/2DvTQ ShGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zm99FJb0; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id v21si27311060eji.11.2021.11.08.23.03.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Nov 2021 23:03:47 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zm99FJb0; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 040A983906; Tue, 9 Nov 2021 08:02:58 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="zm99FJb0"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1EC7D83883; Tue, 9 Nov 2021 08:02:48 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) (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 C2519838F3 for ; Tue, 9 Nov 2021 08:02:40 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-wm1-x329.google.com with SMTP id g191-20020a1c9dc8000000b0032fbf912885so1481728wme.4 for ; Mon, 08 Nov 2021 23:02:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gVxITKNNyabd+K7xCPMvJ/lgGw/5PpSnX0szDoDYjKE=; b=zm99FJb0iUFyEKIuA2jBrsFWgthj2lCljn742ISZZkZ8axJYbqYb83sBbkgJyp1y4E SSugWoeKykVE54UIDlz4LihbYRh+sRmWeGBVGSidQqpDpQnGCF063Nds+kbeZxeT1No0 E4xNYrUCJsdQDt6DKeYzPkZE1dRYnfTVd0F98SRLuRmwwlTahzohEXTdcf/6vFjV6vOu UsCQsUQ607mPNuylazKI/XaIS1qxHqvyo/pG2JAkIVE9hA0TXzBsQHEQxbMRrikWdOkI /fPPMFaL5pj1YwxmuxG3acI+SvO5cFpc3gYJtHclbtG7gTkGk0f/njfFjsKoRieneHzo iEeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gVxITKNNyabd+K7xCPMvJ/lgGw/5PpSnX0szDoDYjKE=; b=BU7dZJ4dy9lesJdulAG3dVZj92KkKRPrcAgf9T3Eo/Z2Xu1YofuXg21JczYxIzBsGx ALRjbP54/tH2bUHrTmxWw8uzyaxf12JbVlO2RTp+m6nKkhR4O8SJLXF69mEdGQW9yhog Hw07H3kMMMs5L3uVne2EUC148mQQIXYZMbNVbVNSBOt0tjkKz+bD0CnygWYUB7YslgBH Qf4QYXJqA4czXj5NROzOju4lXbYC6bUg5IgzETTWy20f/bUTX2SNmBSAvRJu28eiMx7+ 3XEx/Xe15qNqQlbUW0G0srYAcXeA+jTgI3VHh6aEAoUPjozHz37iDD8OEVP9YZAVEfV4 bjSA== X-Gm-Message-State: AOAM530bFyH/VVHvd7TJ1T2LSjItxUl2Scdoyufi4+1PED8yfkpqUzGw qmAPomhOc05V2hANBEra8eGVWAOCpwxJHQ== X-Received: by 2002:a05:600c:1d0e:: with SMTP id l14mr4658599wms.64.1636441360316; Mon, 08 Nov 2021 23:02:40 -0800 (PST) Received: from apalos.home ([2a02:587:4627:18c0:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id g5sm20897229wri.45.2021.11.08.23.02.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Nov 2021 23:02:39 -0800 (PST) From: Ilias Apalodimas To: u-boot@lists.denx.de Cc: trini@konsulko.com, Ilias Apalodimas , Simon Glass , Rick Chen , Sean Anderson , Heinrich Schuchardt , Masahisa Kojima Subject: [PATCH 7/8 v7] doc: qemu: Add instructions for swtpm usage Date: Tue, 9 Nov 2021 09:02:21 +0200 Message-Id: <20211109070223.76456-8-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211109070223.76456-1-ilias.apalodimas@linaro.org> References: <20211109070223.76456-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.103.2 at phobos.denx.de X-Virus-Status: Clean A previous patch added support for an mmio based TPM. Add an example in QEMU on it's usage Reviewed-by: Simon Glass Signed-off-by: Ilias Apalodimas --- doc/board/emulation/qemu-arm.rst | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/doc/board/emulation/qemu-arm.rst b/doc/board/emulation/qemu-arm.rst index 8d7fda10f15e..584ef0a7e150 100644 --- a/doc/board/emulation/qemu-arm.rst +++ b/doc/board/emulation/qemu-arm.rst @@ -81,6 +81,31 @@ can be enabled with the following command line parameters: These have been tested in QEMU 2.9.0 but should work in at least 2.5.0 as well. +Enabling TPMv2 support +---------------------- + +To emulate a TPM the swtpm package may be used. It can be built from the +following repositories: + + https://github.com/stefanberger/swtpm.git + +Swtpm provides a socket for the TPM emulation which can be consumed by QEMU. + +In a first console invoke swtpm with:: + + swtpm socket --tpmstate dir=/tmp/mytpm1 \ + --ctrl type=unixio,path=/tmp/mytpm1/swtpm-sock --log level=20 + +In a second console invoke qemu-system-aarch64 with:: + + -chardev socket,id=chrtpm,path=/tmp/mytpm1/swtpm-sock \ + -tpmdev emulator,id=tpm0,chardev=chrtpm \ + -device tpm-tis-device,tpmdev=tpm0 + +Enable the TPM on U-Boot's command line with:: + + tpm2 startup TPM2_SU_CLEAR + Debug UART ---------- From patchwork Tue Nov 9 07:02:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 518040 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp1321041iml; Mon, 8 Nov 2021 23:03:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJx1DLFzHSveUtOagWeqmImFrph9SoVdzaLlIbayyHseq3HCTEAQhmIliidsDG0XpvozDkEQ X-Received: by 2002:a17:907:6ea1:: with SMTP id sh33mr6824939ejc.150.1636441437116; Mon, 08 Nov 2021 23:03:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636441437; cv=none; d=google.com; s=arc-20160816; b=Q+tiGsUNZ0WFB0b1TuMStAiWjgN8ZxZhleCstP9wWEEMVmWMUgErJzVGQm4Ei5nlcK gnjV5Icd/Qsih1p9HWEyWN/uTwd3ixurKDSCkc+Ha0qpnveFB6TWln+rN8jg4eJqzmAP WbzdPypPkKelnxTKeNaXYgHhI9ilLu3KXnP4LCRlqlHZi/5IPioBm/Dz5WIBf2qX7iLI mFs5ZrkZ5Jv8E/zYjyI8boyt3yTw+I9Vufh6DA+24vpFUytHAZVgbnmBfmEHrIkcEtjZ /OCs+KuERTqEJvfWNE16568Ow0rwMxijzX8r+nN9Cs2LOHVD0Ux2nmVFySXvWuVLuHw0 0zaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nC4uOEefLZMbo1Afh5KTotM/YrhuqigkM4RrqMY/ygY=; b=HOV3bi/cnNFPCECgtZDUE8rTB5uTptk6xBllc8eoLcfwMesJWA5CSr3BFKcVrthJZ3 Phy4FwJpjmnFMSrQtKIfWT4SxgIYNdUEHPoruVvbJCMMiCrYFwjsnNBZHpausJh5zCd5 7lkKaZ4m5gWjEu5+69NB0NNbR+JIIEQ4VeOglDPbRqcHSeDyx/vhqlndtLRhANDoFBug XvV1/4LxhTmuYUl1QIkU5N8OwZncQXerg6Rrh52YUuY+O1vZ9gmbWMUvmq9AIbXw2edY Xe8kiv9qDqIIaoNFeLEGxwoxl+PRSHBOsyapHAPPybpxIvCT25hcb6sJnukQy26Gh32t C4ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="ixh3oHr/"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id x21si37179879edd.390.2021.11.08.23.03.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Nov 2021 23:03:57 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="ixh3oHr/"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5636E83913; Tue, 9 Nov 2021 08:03:02 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="ixh3oHr/"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3A9A1838B0; Tue, 9 Nov 2021 08:02:49 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) (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 B8C2B838F8 for ; Tue, 9 Nov 2021 08:02:42 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-wm1-x32b.google.com with SMTP id d72-20020a1c1d4b000000b00331140f3dc8so1494858wmd.1 for ; Mon, 08 Nov 2021 23:02:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nC4uOEefLZMbo1Afh5KTotM/YrhuqigkM4RrqMY/ygY=; b=ixh3oHr/Zc0qE2oez4FSiT1+7D9t8HSanEhq5TTRDjwoiCL8FZyjL4dgt+DXlTd9yN /N6bY7pyi/YFbn2Fy3y8btdbY8sEJ0FTfor+uh3Xtab4VL9NiG7P+/Roj9SsdqeVhZVO OIA6z/rfiK6/W50CMQjdGJZ0Ob60C7R/oSlCFBuv8DpQ9RyPuaU5/Kb24DMmV5k745yd pI29nHiJLBcM3HwZjdv1aEg2cq4J7E1XPLBQT7jxpPr89GTiHQ7iQJ+2XzY4pVKk1Xnk YIU2CH3wpd0NCn8JlKmkGUbJNHmiP2eGUVRhWcZKYLfFyRiSfVogIo9GbqXnBcvybiIG dKcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nC4uOEefLZMbo1Afh5KTotM/YrhuqigkM4RrqMY/ygY=; b=XfIvg9ky3JjSK7I3Js3g83MCH7NYhGo0QY9v3Kzh3k+PT89pp2C5/Mfoo/kHnLoCAC 1pI6Hm22VawKI9nniNdJTBjNZCp5jvLn7Py4m+slwZCEa4hZ3fh5hMhpUlOh9ZrgTNqU K4WWtCLKdWbPLDnoEXKyjKMGDbD85khP/d+qDP8cxQq25zuEUExjJZDTJWchAticrbuS LDExrEvGMDNBI5AoK3VNbn9ZF3R0sm3jwgZPO/+MOfPQ0r88J9WUutP3gldJUcmTqJGe fXCF7sKB3NyFE00NUc2y03NexC/BqRfsKgQEqH+p13GJm5HT2pPEdEFRT8Tlo0tpVkAy S2og== X-Gm-Message-State: AOAM532qLr+r7R8rtIVTtLljfEQySM53L6g2thGB9WjlpnEHeNJk4YmA /qdbJep5luIAj0mT1zicGp1c43MP9z9SFw== X-Received: by 2002:a05:600c:2156:: with SMTP id v22mr4910730wml.159.1636441362394; Mon, 08 Nov 2021 23:02:42 -0800 (PST) Received: from apalos.home ([2a02:587:4627:18c0:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id g5sm20897229wri.45.2021.11.08.23.02.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Nov 2021 23:02:41 -0800 (PST) From: Ilias Apalodimas To: u-boot@lists.denx.de Cc: trini@konsulko.com, Ilias Apalodimas , Heinrich Schuchardt , Simon Glass , Rick Chen , Sean Anderson , Masahisa Kojima Subject: [PATCH 8/8 v7] MAINTAINERS: Add entry for TPM drivers Date: Tue, 9 Nov 2021 09:02:22 +0200 Message-Id: <20211109070223.76456-9-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211109070223.76456-1-ilias.apalodimas@linaro.org> References: <20211109070223.76456-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.103.2 at phobos.denx.de X-Virus-Status: Clean TPM drivers have currently no maintainers. Add myself since I contributed the TIS implementation. Reviewed-by: Heinrich Schuchardt Reviewed-by: Simon Glass Signed-off-by: Ilias Apalodimas --- MAINTAINERS | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 00ff572d4d23..6db5354322fe 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1187,6 +1187,11 @@ F: configs/am65x_hs_evm_a53_defconfig F: configs/j721e_hs_evm_r5_defconfig F: configs/j721e_hs_evm_a72_defconfig +TPM DRIVERS +M: Ilias Apalodimas +S: Maintained +F: drivers/tpm/ + TQ GROUP #M: Martin Krause S: Orphaned (Since 2016-02)