From patchwork Sun Nov 7 21:33:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 518015 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp2739856iml; Sun, 7 Nov 2021 13:33:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJwx6usiDQZfxK8qLTQbiXr9Ok/ErjNiFVK7NqttmQvnGiiCy5DiFDtW6w34KskGiHGn55ZF X-Received: by 2002:a17:906:f74a:: with SMTP id jp10mr34221768ejb.358.1636320816572; Sun, 07 Nov 2021 13:33:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636320816; cv=none; d=google.com; s=arc-20160816; b=rV4gs274Bz4JkETGQubT2miynPI5Fk2N8Jkhy4VwweiKdLM0OVvDaJ1eQqvZKypJqV HExECX9aXNajci5jl2VvXBpojveQgz3bmubfdKhocZCmKgT8MbknGhq9iblMlkdvHIOr uv5QhAhY1Lc0Eg4JttGk7latbu2SgL7sdYdk0JeZ4MFcK5w8P+Kk7cbjLrYOkTRdTDF0 w4ZFuywoDvmMPUTXTdPmoxrDPXC0jthzzxOb1e+EokKPp+T/xMsmFQFOXDNYy6gB7uS+ IwiWwyakPLzM6Oved6t23Z3afsxeukrlF5eYlRxEFAkPMEq3n6IMXHn8vQCrVU9+n83Z m8gA== 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=hkFln6ATxtVzMYz5UnT009KaZJSatKpVfYeAH18CZJ0=; b=VDVMY7oewNJW20r5/nvx07Pvn/PaSQ+VR2nfEEdQDi7lMH4oywFbCyhgsXhS7y4Wer rRGFYTiptWMQ/Z1H2i7sBYO6hpp9+JtQ2k8OcXZzyiUoMzzni+1YJYwEMrUoVH17l7j+ x7KiAvxwG1Fojc9ukbapvZgE6Sgp+I06fBVeF21aflTJSz6JFPx36F/8h5Ryj6QatzXE L5w7cn01mtu7YOJAcgtpo0lHInQIG4cqRvkLaEpct0+zblGuBLAqnrNsybsyX5ekpflB Eo+QWloTalz6UHlWZE611/HO+NZmJmNtD7XdEy7aiHcGjwN5z7qAjOjmDvAPiBQfiNWh zMUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lg0IL8WB; 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 dk5si20828601edb.601.2021.11.07.13.33.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Nov 2021 13:33:36 -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=lg0IL8WB; 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 DD4D3837F7; Sun, 7 Nov 2021 22:33:25 +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="lg0IL8WB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C227C837EF; Sun, 7 Nov 2021 22:33:21 +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-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) (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 2C41F837EC for ; Sun, 7 Nov 2021 22:33:18 +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-ed1-x52d.google.com with SMTP id ee33so54948815edb.8 for ; Sun, 07 Nov 2021 13:33:18 -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=hkFln6ATxtVzMYz5UnT009KaZJSatKpVfYeAH18CZJ0=; b=lg0IL8WB+WRHzY5HhNFsK10PvTkwsffepVQIvyjapkM/vS8uKFwXhHdNHDf/PNaj18 igHP1zLlbvqqll1QRqJKlgNjTm0KttH8AWCzgo/Ryb60RbI5s4f4Epo0j832nniRPdtC TfdyzpHm8Z5fbp4urD4N9qfdlki5dIMwoAav20F0nqbLlYWoO3AHEnJg5HBYaRNjzKVb WDYJxFQ9mQFfSd8oYB/4W3mmNix4jOcpfaRUVZ7qRZ7rFg6LjHdbnpsEDbNWUdpVsdxz /t6aD6mQEDzBpO5Flxv4/8yMHQlEhRg8i6nlmSfteMJOely0VG6FwhcWJO0RZzCJIC0X CXkA== 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=hkFln6ATxtVzMYz5UnT009KaZJSatKpVfYeAH18CZJ0=; b=SSmijp9QbQ5hVFQoZzlAoaxmiFPjY79iECVo+wiQeEAF1MtWVMn2kTwpqOb/481lMI jipjeXAGb2A7FlW2MOJPbnchSnNaX34VvWkoDeE3JFVFhZORy5mCjctQP52GjeSoGA76 iKNRUZtxihZ23qpt80ua3otEsinrnxnSsWTK+xi7+VSh9OtPjHJ3UjsX9Gx8mDncP5Op VmKIcsTEMbjBGgfLoTKh4WuLB1JRRQIgprHgsDhnNub7S3B+QEewg+ZmJgvInZz4ftvn RIHR3r5MYwhHmomt3T1BgLjEbflsUOE8eESnIqvcKXbgnbyC+JJULpBBayvNbhHc8L0B RJ2g== X-Gm-Message-State: AOAM5309MEwqAu/SDmz5jFP6o+3wG0g0hz0tT0GhTvgg0hQq9a3ngVjF FQHOTwxtWxmMVzYyyrmAC1wQBldQgeigqQ== X-Received: by 2002:a05:6402:41a:: with SMTP id q26mr56784344edv.387.1636320797800; Sun, 07 Nov 2021 13:33:17 -0800 (PST) Received: from apalos.home ([2a02:587:4680:8a9c:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id hw8sm5042150ejc.58.2021.11.07.13.33.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Nov 2021 13:33:17 -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 1/8 v6] tpm: refactor function names and macros for infineon v1.2 TPM Date: Sun, 7 Nov 2021 23:33:04 +0200 Message-Id: <20211107213312.263357-2-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211107213312.263357-1-ilias.apalodimas@linaro.org> References: <20211107213312.263357-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 function names are part of the new header file. So switch conflicting driver defined function names and defines. Signed-off-by: Ilias Apalodimas Reviewed-by: Simon Glass --- 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..aa66e931bada 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 TPM1_ACCESS(l) (0x0000 | ((l) << 4)) +#define TPM1_STS(l) (0x0001 | ((l) << 4)) +#define TPM1_DATA_FIFO(l) (0x0005 | ((l) << 4)) +#define TPM1_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, TPM1_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, TPM1_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, TPM1_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, TPM1_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, TPM1_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, TPM1_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 = TPM1_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, TPM1_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, TPM1_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, TPM1_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, TPM1_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 Sun Nov 7 21:33:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 518016 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp2739951iml; Sun, 7 Nov 2021 13:33:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJwaouU8IVhuSdf3ielvc7pNQNZis9lGpqW7d3OGp6hQT0bR48UVYIwfarso8bULziydxY5p X-Received: by 2002:a17:907:1c0a:: with SMTP id nc10mr80129607ejc.211.1636320826089; Sun, 07 Nov 2021 13:33:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636320826; cv=none; d=google.com; s=arc-20160816; b=QG/JIQPFFzLqE9WJVPfhR+TGXR/zqDPshlS5muxlP0lREhUW0OyCj/NrzUVN53QR/T 2UM/2CpXT9e6fYxQwA68sQrdCEkxPCBvhSdyIMC3dJTunwBf90GsLpSG/bF2rPiYE/DJ cRVKMX0ByzmjtCHgnbN7q3mtRKa/JDz9Bw+c8KqvafDE9q2J8vkoxvbwR28yYRqAxALn sqet26lFK2SsiaQd2sVY2r9PeoOXQBIsiDlgt9IjAJkCCmUtzINt1cqFyDAxT8st4lE8 jy+LY0KZiswhUgpn4BHFxmmRkhHrRZdUW/IScuiXaG5hNwt6WF3xDLuLol5rakkggwMG J+ew== 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=JZxRo5P8fZFrC3MT+FzI0tSaspIUJ0antbq6gv5pNEw=; b=naB+CMZAziOFYzu3cW0rDtKew5blxcSLDnyKS10lU03VdOR9T5tA72h0cUhrEPY8/z v7gEsr2e8FYlyz1KEBFaHCW3ET3gX4N5AXEA7K2K/iIEF6+8ZrpSa6Q34NEo6a5KqRTw w9pMAioEnXooZvkOuMbbLjE6krxN+M/BtHXIzW8v5rC36z2g7DND4mInmklC4u6XDhU5 3QyJb2D6lLuQFNuLnFUWhOZpzKNYo+vvNZB1fzcC/m4gXJh9mZ/6Cy3AeW0jv3CLmDgt yoz2/IJ4GsJhnDQlbCQdFBqW34iZ+44+mEuKI13C7cStqooB+ptixIVGSx74RRw4/IQq uq1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Bn7ZBk1z; 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 h24si25042686ejt.408.2021.11.07.13.33.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Nov 2021 13:33:46 -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=Bn7ZBk1z; 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 DB152837EF; Sun, 7 Nov 2021 22:33:29 +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="Bn7ZBk1z"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9CE1C837B7; Sun, 7 Nov 2021 22:33:23 +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-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) (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 176BF837B7 for ; Sun, 7 Nov 2021 22:33:20 +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-ed1-x535.google.com with SMTP id ee33so54949026edb.8 for ; Sun, 07 Nov 2021 13:33:20 -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=JZxRo5P8fZFrC3MT+FzI0tSaspIUJ0antbq6gv5pNEw=; b=Bn7ZBk1zeCK1rSwlX7j7xZOiMM7os7ikgmrGpPJOtXmsFjidebhoPLjSn2fU1h6qjK 00r9Srdk9CYqgbLxhjXCFMsInymcN/GA33cmQbMf6GP1UL1uslnifgBcEzX9+VOiUEsb jstrkSx+UOloYEaItDNyeDkILIHpZtLWj9gCiNrMTicI0YFBHgoWCKWN4mPhpKat09LY 9Pk0+9sj6SHXe/wXOiL6jseJvXGS1JhoUgFjZS2K8SF7fEY3/EfY49Fucdrgp+ThNBJ+ VbrdQtoJ9wmHVUgNoXh1EC90UiYKSCOpWFnNBwKTZnZIWa+JG+utYgEDBe5XG3vje2vH WMTA== 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=JZxRo5P8fZFrC3MT+FzI0tSaspIUJ0antbq6gv5pNEw=; b=ww9QDFcVcZVPyQymawUC3bMlgahQ/bGaQhcr66Zxi5IVVU4xN6EhQLGA32e76IgGWI wDei3VtgkKmLkc49Gqxnq1AuTiLlpHEq1Xg6K4T/gNT5b1oeVrZT1bEJtIDNxrgV9o3t t9H93l/Wgi3aIOSvKbWomIQzIYeRZdTdJb1eU0F2vg40+6UbOv4R8J3PtU6wM5LS98sY IHQnFr5+aSJzOoXMfK9m61slUp2cg7UOu1UHAGyygFVJP1nFBuqwR7KX7Konn9nJ9FlQ AAA5kwqn/YapHfIlxGgFbxALCCUHzOFOnkLqYcm7iHph6DVN4ad4XguFmokjL4b2tlDX 7b2Q== X-Gm-Message-State: AOAM533sYP2zzORwQvXT1wnX6s1IuyZ++JQHmGm0QWFx267c3W0LLhGt WWbDeWsUr7uvwwgu3jGMcXtxTCNJ2KDrmw== X-Received: by 2002:a17:907:97d0:: with SMTP id js16mr6809633ejc.199.1636320799682; Sun, 07 Nov 2021 13:33:19 -0800 (PST) Received: from apalos.home ([2a02:587:4680:8a9c:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id hw8sm5042150ejc.58.2021.11.07.13.33.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Nov 2021 13:33:19 -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 2/8 v6] tpm: refactor function names for LPC based TPMs Date: Sun, 7 Nov 2021 23:33:05 +0200 Message-Id: <20211107213312.263357-3-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211107213312.263357-1-ilias.apalodimas@linaro.org> References: <20211107213312.263357-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 function names are part of the new header file. So switch conflicting driver defined function names and defines. Signed-off-by: Ilias Apalodimas Reviewed-by: Simon Glass Reviewed-by: Heinrich Schuchardt --- 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 Sun Nov 7 21:33:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 518017 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp2740059iml; Sun, 7 Nov 2021 13:33:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJyLiuv7yjJSeIe2R5XjNX77I1F1rF/2h9fbEZG846WaJxRl0S2eyfQ+VhU/yHgR6iP0McyI X-Received: by 2002:a05:6402:6c8:: with SMTP id n8mr70289341edy.38.1636320835575; Sun, 07 Nov 2021 13:33:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636320835; cv=none; d=google.com; s=arc-20160816; b=q/DgATd3k5bBqF1zzAsTDCLgAXWWVGIO8aCFuM/C5od2cFety3yOKqJNP4ia52lDjx pFWEZuZFD9zikb56Qb0oBvzv3OuuLNJVi/XdOdhzYWdcCGTcFK/tuN6BsiPLctrDhdQt s54B0lsM07haIky2F3DDrjPEN2vP+X11NSgCmRz+TYYVlkkDd4YQWvO4KTgS+R+cZK3H Ngonj7G8v2OFoPmn+Z7UNDOk7X1ONH02a8hY4csSEjYcV4sKIT+L2CjlnLnF7MWsGK4N Kjn3C0E8TN/l9OZjzS6eE2dGOwGB48d1/Zbrax+pgHLFJBeknfsxoLJXNbX+IS7bU1h3 og+A== 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=UZyIk/VvX1j7zzkwXuvPHuxTWHVPnrmD0qjFM7LgOXs=; b=IiEUweOc2wykXVZuXgsYijerNFMQn+uDTpGxxUTDtDyn3rEb1fTVOF54QONeX2lzum 5aNFd0TxaOJmK2P1smi8yUrwRAK/mBNh9jPEGab6awJ+rzbwYiEGgxqZAQmv3lZD6HAW 9CgR1jjQZnGpZsPt7HbTffr4Dmsg7FtFzkm33Ea+MVcq6t7hhr6lh1M5Pm0AxnGA07Lo p7DZELNeH9/h5l00BVj95giMAz0MWUcK4zcVjp2t9yWS+4paSgfKL8QrgZsJ0mceT0e6 ynlVrWz2siCuJw/nDc7eqv7jkF/PEFnVyvmrYjYw9PLgZf+xBC505MPiNY4ShaHXzq0N fl4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vAQOfigw; 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 q19si27321228ejs.198.2021.11.07.13.33.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Nov 2021 13:33:55 -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=vAQOfigw; 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 8FD2083810; Sun, 7 Nov 2021 22:33: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=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="vAQOfigw"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9E7FE837FC; Sun, 7 Nov 2021 22:33:28 +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-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) (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 0CC0B837EC for ; Sun, 7 Nov 2021 22:33:22 +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-ed1-x52b.google.com with SMTP id o8so54620805edc.3 for ; Sun, 07 Nov 2021 13:33:22 -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=UZyIk/VvX1j7zzkwXuvPHuxTWHVPnrmD0qjFM7LgOXs=; b=vAQOfigwAFUOE3rEj+dfb2wjnqaiq0VmjfwhiPx3u8Cn2t3D5I8tksOgBfsfC8JJLr SwM3LgpewVmuBKq/eS1k1EEwQBJuzUS5Y4e0Tc4sz14JDyIELCmngNM516dNk5qKHnzc NWVWiEa384t7N9f0rJcEYME8W4xIeaFM0ov+pSpgOPNFyTC2jtTij41jNq7hi13SFoRl vrKf0W4E0cOi0UlXRJys2pkif4FBM61aLGPRnLrfwy1MQqkKfS0QUJiH1SZyvjzQSh0w 8NcxfXbYfsr+bd4MUU7XxysgOA4KOdoyExNscSxf0+pmE/m8cTSfBpeAaOJ6RviIi3Q6 SRIw== 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=UZyIk/VvX1j7zzkwXuvPHuxTWHVPnrmD0qjFM7LgOXs=; b=jKMZSJ07lAvk6IHQBUtk6HBdgTCW5GI/EGfWlVIRbEuTaLGLIZXc6PGCdJwX0ugwLq F6LVfV/Vdrv0/2pyhgCUXK9JVvVXEePcuChIBKOV11nfWRqm/2LFZ80iytRc2LfiseCI WvxPmcwUPiF3vunwIbYOu06cPJCBsJDEEu4HY0Bals7mneyDK6m1+FrUUFR0v1YbX5OQ dAZTGhG4OwHMV07dwyRNRiwsATRqg5i6kVoOdar9QHqkxBWWE+hFc0uAXiuZrdfkrjDo 8iI15hWCCeilK2qXH80HZkkQnmZNUHrm+/Qsp4qRjqfpeZSi/HEqyc7Wly8CXG/l6sW6 IrCw== X-Gm-Message-State: AOAM532kKg+y309v9qZ15YNNoDJHMNKCe9TAGk/GVmiv2/taFYWQ3uPN 9lH06L0cUAd8tp7hA0p1S/WkP8zTuokdSw== X-Received: by 2002:aa7:d155:: with SMTP id r21mr91387872edo.341.1636320801621; Sun, 07 Nov 2021 13:33:21 -0800 (PST) Received: from apalos.home ([2a02:587:4680:8a9c:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id hw8sm5042150ejc.58.2021.11.07.13.33.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Nov 2021 13:33:21 -0800 (PST) From: Ilias Apalodimas To: u-boot@lists.denx.de Cc: trini@konsulko.com, Ilias Apalodimas , Rick Chen , Sean Anderson , Simon Glass , Heinrich Schuchardt , Masahisa Kojima Subject: [PATCH 3/8 v6] tpm2: Introduce TIS tpm core Date: Sun, 7 Nov 2021 23:33:06 +0200 Message-Id: <20211107213312.263357-4-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211107213312.263357-1-ilias.apalodimas@linaro.org> References: <20211107213312.263357-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 --- drivers/tpm/tpm2_tis_core.c | 463 ++++++++++++++++++++++++++++++++++++ drivers/tpm/tpm_tis.h | 128 ++++++++++ include/tpm-v2.h | 1 + 3 files changed, 592 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..7a69bace6828 100644 --- a/drivers/tpm/tpm_tis.h +++ b/drivers/tpm/tpm_tis.h @@ -21,6 +21,65 @@ #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 + */ + 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 + */ + 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 + */ + 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 + */ + 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 +102,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 +190,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 13b3db67c60f..e6b68769f3ff 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 Sun Nov 7 21:33:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 518018 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp2740167iml; Sun, 7 Nov 2021 13:34:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJxXKYXq47hxw3zlgjtrbFPBaJZAjDn2bTYYn+zD8hD1GX9lEdPKQQ/NFDN8Mn8vKnphfiub X-Received: by 2002:aa7:cdc9:: with SMTP id h9mr73409645edw.370.1636320844692; Sun, 07 Nov 2021 13:34:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636320844; cv=none; d=google.com; s=arc-20160816; b=sv4m2aeVX4Xc9yzxSEffLn/8cvuK1SeC8pXLlg2HBtoIsFJwxWiyJm0XG8inmv+KsK 9sRF7qYZIgIyuzJ/v3ozn2V7I5S7UaSUBZFZwAhdUs9CAwXME/v6SjNIfNdmzUo/NNWp pO2/NIgiwjTFz/KN2QgHAruyV4aPbFSYZFTnBLvVQBCqNDGYeD2BRlhI0VrgapbIWdiZ cFfv6oRfxHFb6tipv3UdTLLBXsNLa3fWq0JSNogI2zPkYSRMwzn8Ywt+Q87RyuCYn8ex LOuf0+7YoHzdJz5bJ9sEGwPI+wCAdIHsC2kr2zKyIBPYXBrPzLO6JLMEhI/BOVgoaFoP 6XgQ== 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=5/38ld++WFpD0hel5Qsmgb7xYTQIBsNUFT8nYI86+qQ=; b=PrlKdQ0CqFtaxYv9vJXcA5CHIYlF5bQJtNtgLWzsx7zAiVugcOiQacSL11bk6P/igS 8WWYXQcwMPgdNImhYSv4hntwMFVvFY0bJvxZV/HcmLAINFaPghAhzPvdnhUjiI23wiO1 3rhWtjPyESXKkuWhJRn3dSRh2hxQtyJLGvguH5KUEGPCQhMqu8VKe0FWi6ffTWokNwvx /Pm4mRkvc/HzocpcX5yAe3qyW+Xr66C8EtKZjEvWMt3TbGlh7QTeQVeouHL0PHAvUdwt ONJqaZ708aKOJVIjPXn+spldTFnejQPMz+YWrsPbCy6mwKnsPUR1+SM+D3u+q5T9TEE1 Ms3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="xU/RDEX+"; 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 hr41si34241809ejc.558.2021.11.07.13.34.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Nov 2021 13:34:04 -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="xU/RDEX+"; 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 9FBC7837F9; Sun, 7 Nov 2021 22:33: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="xU/RDEX+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D0C49837FC; Sun, 7 Nov 2021 22:33:29 +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-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) (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 DF310837E9 for ; Sun, 7 Nov 2021 22:33:23 +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-ed1-x52e.google.com with SMTP id r12so54721760edt.6 for ; Sun, 07 Nov 2021 13:33:23 -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=5/38ld++WFpD0hel5Qsmgb7xYTQIBsNUFT8nYI86+qQ=; b=xU/RDEX+o9hzpE6j0XIszqOw9r5kYaO5LO8XvK8mPENphzvckx4YkWoLcqtmBEz6zn MwFmKBsZB/uhfqxN/8FFMSjglM3a1CX8fBwLjTWRgW/ENb2Uix+33Zedk+sL4iyUXbpG sK5nvcdGHUf32HlH8xmgtPo2pQdhfyEFplGa1JCQS2lKmy2UW1Bd29is58m/uMWT/OcV WpfJqPpXqyehhJ0UijQvBDcmSBQ6PinY2nSKMNZPlKqEnmkeJk/I9IKdzhabBNQQ/IcY UnHof4zjHa+I3ibl2gfMf6uiZNLkueaU2ZTE4rpIO80Y8dZnVp4/4sqQyfK5H1n0yAPP mIWg== 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=5/38ld++WFpD0hel5Qsmgb7xYTQIBsNUFT8nYI86+qQ=; b=3nckOmhD90bh4UuQ0wnV3WAqKLeV6VaZhItHAg6cRuXeU25fi4vo0/t65N3JzbL+Y/ G2q6vut10lgGpbUZ5Mtdjy76a/rc6HKsdWWPnIdyPouZkT+R27aYmFILgAKALCRVvxFt P6/BzrMPNVSK/g6Xs0x+IQ6RA+Ft/Zv7TGd8JGV2E/RWw3LzRkzsWH1nOsd8UN/dXIye toxA7kuQ+h7lF4EUX0B2Wq1yygVWwOgoTteEdbPMw/3Fit5LU34TLVGQwzSRHbDpeWW5 Ks5gb3BwOvPDbi5KPnaT2CxmWSHA/3siSyJLhgmB+MmuB0XYSzXxr+0XGW0EkTHxpKhM foOA== X-Gm-Message-State: AOAM530NrzF/hZFDNe0z/xwj9VEpMWQaxfuUJleCJd1DZ3PHTWvdKDYy IWtLHcfn/MGGTj7tzCEOXhHZ0QitasRoYw== X-Received: by 2002:a17:906:368e:: with SMTP id a14mr89128153ejc.60.1636320803502; Sun, 07 Nov 2021 13:33:23 -0800 (PST) Received: from apalos.home ([2a02:587:4680:8a9c:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id hw8sm5042150ejc.58.2021.11.07.13.33.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Nov 2021 13:33:23 -0800 (PST) From: Ilias Apalodimas To: u-boot@lists.denx.de Cc: trini@konsulko.com, Ilias Apalodimas , Rick Chen , Sean Anderson , Simon Glass , Heinrich Schuchardt , Masahisa Kojima Subject: [PATCH 4/8 v6] tpm2: Add a TPMv2 MMIO TIS driver Date: Sun, 7 Nov 2021 23:33:07 +0200 Message-Id: <20211107213312.263357-5-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211107213312.263357-1-ilias.apalodimas@linaro.org> References: <20211107213312.263357-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. Signed-off-by: Ilias Apalodimas Reviewed-by: Simon Glass --- drivers/tpm/Kconfig | 9 +++ drivers/tpm/Makefile | 1 + drivers/tpm/tpm2_tis_mmio.c | 151 ++++++++++++++++++++++++++++++++++++ 3 files changed, 161 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..73e664da2758 --- /dev/null +++ b/drivers/tpm/tpm2_tis_mmio.c @@ -0,0 +1,151 @@ +// 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 Sun Nov 7 21:33:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 518021 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp2740462iml; Sun, 7 Nov 2021 13:34:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJy+qn36zX/v6YHeVFwYJBNtUKi1VgcDZtfWzAMeTFYQ7rG3wTXYOaSDfgQPkXJXKjBQSf3/ X-Received: by 2002:a17:906:9402:: with SMTP id q2mr24721034ejx.106.1636320874058; Sun, 07 Nov 2021 13:34:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636320874; cv=none; d=google.com; s=arc-20160816; b=jfgQewPKZS5RXCyQMx+YiAYGxoyiknZcCxFp/KkAuP6Dh9LoNaWRnkMWY6E2VI6glM kPMM9mq185Y1bzZrt/vUFlmoFwaWurKX2C4aR42CF43NKowbT5iRmHnvu2nq9EW7Vrli Yb8PAHEie/XvSjDK1VheV37YJgNmQxYRo3R+1BzTC4oaSbBreJxWHKLjbCPUo7PJN8xA 8ZNeqVRym5YeHvmZXz2H8UqWPi9dNuYupxnR0OnNAlpJIDSJ3ft91yEF8qoDrDVyIhfV s0MxQF+vubkHYFSBbpbXX2LSRX/P2p4xVTwg+nWI/b1VxRnpSzylfbILHjsgsDplsZSQ RuOw== 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=fXe0bD+sPdfmASaZBmzln51WgMHbDANeg/DOM8/gcRH9sMwWkuZZq45vlTgA+hNOtR js0yntsVY56Q0tszXuHEfyYMDdCmS3bm/z1HC8arA9FdAYl3H2NQpLVz1eS1IaVUcGEk NAMGyFPaKzFgOINESUU/K23f+gRx9zC8+ybO59uJGfhhRKKWi5SQhYt9RZGJXYASqZob lT1YA1Tlni3W0rKrYIBkyVAVGMQN5HJEZWQz2vu6fnnYvs44rKVozEYRRdriQyDPYAfX 26rcEg8G//n1PHQ0OwyN8AZIomfZQpuIoVda0kwuiRfVTtOUFiIDSjH4VHgfjaMTzm5h miHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QytH0Ncd; 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 sh11si19960791ejc.687.2021.11.07.13.34.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Nov 2021 13:34:34 -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=QytH0Ncd; 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 BDCCE83808; Sun, 7 Nov 2021 22:33:45 +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="QytH0Ncd"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1B1A6837EE; Sun, 7 Nov 2021 22:33:35 +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-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) (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 D243F837F9 for ; Sun, 7 Nov 2021 22:33:25 +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-ed1-x52b.google.com with SMTP id g14so54165587edz.2 for ; Sun, 07 Nov 2021 13:33:25 -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=QytH0NcdK2kC3uUxgvvoy38BHAdA7twrMlfxgCSU8lO2BucrMM51CTR65P8HUWztF5 phPf4FehwNg/0ApxHXi07Ig6UQI27p11oest7Rrm7WBtR2RvipzKWs8sMpbWFJr7HIzh C0SPrjtfBpicDHuWUAzProUMXEyd6w+9cZzWBSPqy28PWJy0iU8dhCxNODlm3/dRXqz4 J1V1H7lu8/7LoqpEaZNVR5YOEPQeGyjMPW6E+z20jHl8pSqHMnjOUUvSomJH7Os3vCpQ UtSJUY0yLOlvx+jxm1ewkPvzdEO6OfjS/s6K4bhjfUyo4oJP6hbF9A0V6EOf8jFqhGnB /XUg== 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=5rk51idpUOMww9HJb+PZfn6JBk+3KKetvRLfPwUTf0IF4kf5LEk4yS8rD0iTWxOBKm YWVfRx9J1VDlDwadokNEoQex8YAXw1mYb/3SGqDTifb+wzfCtAE70ZNU8W5iWsS0aXDu Dvqpto6teJnnKm7hBQhquwKK+SaHks67H4qSd2toBSXEldvY/KHQ2TviELfDtCvWUuq5 /6oDEGeR7BsmrexDGmustYN0xXBOYmB9SCgCY/wIozild/vbLuuAgzpzoHocs7C+6QUc lgCenEPW39p7wY2pIZr/gzqiTYXyu42iRd5r3DC12ST/XKc8HCFV3xGtsyLzrVYPoQbd fGpA== X-Gm-Message-State: AOAM53119D4YrsNeIxw8XOziRVJYBYdfgWklI3cl53V1h4yy6h9ovsoW EnSge6T4KHjk735sRa7cOvoons0QpFd8AQ== X-Received: by 2002:a17:906:258d:: with SMTP id m13mr93139582ejb.208.1636320805365; Sun, 07 Nov 2021 13:33:25 -0800 (PST) Received: from apalos.home ([2a02:587:4680:8a9c:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id hw8sm5042150ejc.58.2021.11.07.13.33.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Nov 2021 13:33:25 -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 5/8 v6] tpm: Use the new API on tpm2 spi driver Date: Sun, 7 Nov 2021 23:33:08 +0200 Message-Id: <20211107213312.263357-6-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211107213312.263357-1-ilias.apalodimas@linaro.org> References: <20211107213312.263357-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 Sun Nov 7 21:33:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 518020 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp2740385iml; Sun, 7 Nov 2021 13:34:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJzNfPcrHxp1ZHkZ7qy6ro8Vq0UN7Z329tATNHzZlzH/U6YzNdmgnh4Pr8d7zSxem/8xZgDy X-Received: by 2002:a17:907:6e8e:: with SMTP id sh14mr20503879ejc.536.1636320864550; Sun, 07 Nov 2021 13:34:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636320864; cv=none; d=google.com; s=arc-20160816; b=vZm2WDS82f5r/pv22HpKiHh2m1YppMNUVqyQpcUm4spS4qJSHiuqk8njpFAdN9zS4v TCuAc2YVHCdvywTRvF2GTChFasZRjR4AF2NS80kUMyAhrsHeRQyKNr5MqhfI7SlnKXYL +A8sIIxXFL+pvL2q/jqjXBllDWYkV7PXp1h/OR0cECnJyGxhJki3qhCZqTbsLC71KPEo p0pOnNyibzFHCiai6dVuaTgPSDlzKiEHm4GaH/DJCOL1BzmorcBH1eAxRQAcRQy20GXn M2p+XFVq48Xmuo6opYgZHhTnjTyRucwPhtHcG3CeSUN/yLlkOTVsJLx+Koj6AGdjJ0vS zCeQ== 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=jV1yI4++3ssXtukVw2rKMSQbv01y3uQVp2pOjcdYSS6zPiF8N7+1K2n3VVIy3JkpAM 8C62HLHcvNPeVXnIMtTk9Mi7M4cpbJ+pG54r2Xgz4HF/dmmZn4kIFpVo6U9z1XiPzttY NEe/SRoB+2TppZdeZxidAtgG4DNONQTXZ/0Ga4Oc6yfRFA9zwGUDlYVdfH8OPuMcCpMl MJW9lYJT8Wzlve1L5vTKl1zoZZHEU8WmUp8fO71EiWR25yTBP6XG3uNvdVYtufpldue5 9u72ucJYTbfQrCrSc75tAkujWsgipI8RuAeRuYPBAcGDx+e9PNqYTIlUkyXe7L4y7R/b 39VQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=A56owunj; 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 l10si30647606edb.287.2021.11.07.13.34.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Nov 2021 13:34:24 -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=A56owunj; 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 A858283818; Sun, 7 Nov 2021 22:33: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=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="A56owunj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 831458380F; Sun, 7 Nov 2021 22:33:33 +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-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) (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 9A73C837FD for ; Sun, 7 Nov 2021 22:33:27 +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-ed1-x52f.google.com with SMTP id v11so52134453edc.9 for ; Sun, 07 Nov 2021 13:33:27 -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=A56owunjOgHvXSlu8Te1EFhgTJxY253h9PhsuCiHkgX8G/Q2Qhve0L9zX92qFSjO6r Tw3YRMBqD4E9eGxK5AQn249kr0rN/vfVQZx6bfOr3lmhjr3KmmtY2vNygaZP+tYfKUMX e2bveMluxJUUC1ynwBcv3gjJZUiE4bveqK1a6nvLEeO2wUDOhpCIKZngHNKSnwQdEO4W B54SYWKD0g/3+S68JQv66FQnK9KV6/nQ7Pda4DASpICEBzaXOdU2LqWSlRCHPyVefOkz 4+Kkgl70USNG1aGgxeZfVpk3RVzK/M+paDV0sEB2b8/+ZsUSS5u1NpNWV1BQGOdx31mn cU6g== 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=QujLB5Aj3ynjw4AyNhixpS9WzP/IxgHaHVl+lgKLpcmfsCWwYWuSrFmq1CUi0LzvKm l6KBtDjmilIjISr88pglZayopvpfp1I+hSwpc4596Vy0s/JBVTrF++Qsl3atEV1zwwsu pQrjqpePph9eMyrrHlHxGORnOz7gWTA0hbO/yTv25HWwa4vUOgBtkcIJxiVLiTbihm5v 6vQUY0J7wr0sPU1jLSiH0g4A9tujQpvFgTlfeSdPQyRupmMnPVCZri1QW6e1GmFKt6Fo MZPbiuDjItuQic9S0DDQ1p43w7iwhclBF+hGRVHRACmZMB3iwg66Rgl/5bxsj5UT/cIS FWJQ== X-Gm-Message-State: AOAM533xTAW2pDisRxfxyccPD0XnVAdy9NYYC6/Sz1VfAgVCJnImhvc8 AvJxp+mr1ijDYeZ0ZCJEtsWEJLxS1YUYGg== X-Received: by 2002:a05:6402:3493:: with SMTP id v19mr42782851edc.149.1636320807285; Sun, 07 Nov 2021 13:33:27 -0800 (PST) Received: from apalos.home ([2a02:587:4680:8a9c:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id hw8sm5042150ejc.58.2021.11.07.13.33.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Nov 2021 13:33:26 -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 6/8 v6] configs: Enable tpmv2 mmio on qemu for arm/arm64 Date: Sun, 7 Nov 2021 23:33:09 +0200 Message-Id: <20211107213312.263357-7-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211107213312.263357-1-ilias.apalodimas@linaro.org> References: <20211107213312.263357-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 Sun Nov 7 21:33:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 518019 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp2740275iml; Sun, 7 Nov 2021 13:34:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJyIxXPvWcqQ57iTvKP1ZF3Ca0vvVvcZd+QTi0Q1Bf1+LQvQa4Y8lKJh65V5T+Ew68JaJuFG X-Received: by 2002:a17:906:684:: with SMTP id u4mr45782167ejb.48.1636320854540; Sun, 07 Nov 2021 13:34:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636320854; cv=none; d=google.com; s=arc-20160816; b=OuFE5WHkeWNpFJ9QqSFXPFhPonO91uaAysO9oUzJ6t7poZaoAHbMubS6RbXYzBjUEx g6ykzFwI6YGahAc9q4ooBsfhT4RR/bIHe9nLhZviXuGLjJ+Y9ICuEytujVWnOMLdbsbt YtVg8SXcTxdDzLdMTc/RxQZxJvGbxCHKuRhT+Z87Shyf8HLKF66W9jNjePRqrDH9hLTx tbmAoI5hgYr4aV6wKCkXY0b8rE1aUX9wBBhGzwZGaTEM0TU/NFnmYx+ympBh5d9kjTme QCZ53NTlTAl3PZkwmJjphBtujbtuRtowoxQHJ37nm3h/EgyGi8h2n9c5dED2tbPrzS1c HM0g== 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=FqdOVIy+6UwDLO9bKsbcbwZQPmGvM9BHiKbynkbZ7xl+866WRrHRv/RJaNl8AZH34D tfOQsfnM18Smo/vlBMjZHmBFbXsnomSknvb8I5Z23G+j9zPSdNX2BLBhfr9DYX1YB6k6 pvPh0xqs5FgeeA9+H1oFXHOHwI0BTNzmDzF8T7ilEhlrFX4F4RPcr1KPHrJX99QobKT+ uMyDbklhY4x4RzEnw5sHwpbVynZzwoDffPW5nLV90jHT9LpRsAe50rQOQGiEIdTKe0xB 3hgKQh0Fw78lZqW4XWmK4xpFC+66A99sGvXbvSispcEJnI+POqakm64iyDmPUFI0PqD7 KY0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wiTz+EJF; 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 k3si24882905edk.215.2021.11.07.13.34.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Nov 2021 13:34:14 -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=wiTz+EJF; 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 BAB268380B; Sun, 7 Nov 2021 22:33: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="wiTz+EJF"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 03B0D837FD; Sun, 7 Nov 2021 22:33: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-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) (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 A1DD183805 for ; Sun, 7 Nov 2021 22:33:29 +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-ed1-x531.google.com with SMTP id j21so54544746edt.11 for ; Sun, 07 Nov 2021 13:33:29 -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=wiTz+EJFA22fEFH+jY88ssNW93O8s0TCCJwvDrrB8P//hsDRXCQOsV/y1kQB/YHftK kc5qPdQyd4mlb/wueStjxComIDucFodcS2FpQM16RHso+ess8w2M+txVt/CgG75IUbKL CWifujk7qhUUpii5PHzl9cZj1h4DU5+bojz0eyDEboJgt+B4eXwb7qJnV4HlbFOvROAx ZcuLD3OzsWO91ug4t6I0a96hs5JqUL6s+WOudgNS7DVMve4EHFkL5eHdr/oB08TyV93/ mJWMgMF1iVK1D3V1eHmWVqcoDSoaoF03hLqbTLPM4HagOg/vq9gSEXsUlQYdianacmE8 jeXA== 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=O28jkvKZ3SMyL1AkEjl4itMq6v6KRIQZ4DtDmBXdLIBOmIVr2i/KG/WdUZi1OJBBi9 fqSXfWAP9TgkwktDHsJMrRWvAWohCm2VgBSWXW5fdy+puN65YdnuAeBH0QPfgC1bNeJW V1w45im7A3f+ug5laynWTxYla/haPyH+vv0ypdHWlWAx7jZsOzz1zwqQ3IwPoeGc3tAW LQPUogi0IcuoCKSdcQrret13HLnabPvAVHA/i8/hEfDoy4hiCOLFFfq3GueBvpv6+ux2 /42jfNPgNxfVSeoZtgrk3kblWbjpTJU6Glz2ui4C0yO5jfJuqP+fAIvgm3avMFQMjiC7 gJwA== X-Gm-Message-State: AOAM533EPOxkpMar7cTbfvPawP+yh1aIwkxjVetm4K8dYlL3p/1ll/m+ gvpi3uSsCphmOtZL5q92SE4GE4dfgbJiHg== X-Received: by 2002:aa7:c391:: with SMTP id k17mr77054578edq.263.1636320809119; Sun, 07 Nov 2021 13:33:29 -0800 (PST) Received: from apalos.home ([2a02:587:4680:8a9c:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id hw8sm5042150ejc.58.2021.11.07.13.33.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Nov 2021 13:33:28 -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 v6] doc: qemu: Add instructions for swtpm usage Date: Sun, 7 Nov 2021 23:33:10 +0200 Message-Id: <20211107213312.263357-8-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211107213312.263357-1-ilias.apalodimas@linaro.org> References: <20211107213312.263357-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 Sun Nov 7 21:33:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 518022 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp2740571iml; Sun, 7 Nov 2021 13:34:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJxQgSmb80jbkxcQn2+vaSv/X/8dzngODfcEXnOM3xrPUvVtdwsyasDJfQYpAi8LTKVDPett X-Received: by 2002:a17:907:3f95:: with SMTP id hr21mr41800160ejc.427.1636320883674; Sun, 07 Nov 2021 13:34:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636320883; cv=none; d=google.com; s=arc-20160816; b=vnJc6RChXyarSTFZO8FpdklFBF1mBgkRLMGuX3enCT5hbsn8DErN0ZRUrxjAOXNWyv zcSyvNkFJtfkGlj3vFGXLXjYaHebVG0OsGAFaK1WXYG9CviU+MbEERD01PyBIKl5hV2X ExY1C4QlkrDjrLVwjTHpahTWq3MJLLpY2gosLDWBxdGT2FtLmCJ1K5X+fqGJxilvXSL1 7/SRbGIJMMfZVqmV9/tZNXKyOplzxoAw+Hewkpv8O7ThWOM5a84wRJ7xfbws7bfGqJSK bS49uL4XUkMUVvTsKgb+s8Mcx7Xrw5Z4KpdOtrsBKhEw4lbIMGpak2qsSGGX76+okILU 8z9g== 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=ke88fZzvlcU9i7FjucnfDYhYGcY2qwH8YwyQALWsgJA=; b=M/UAVIMzdDL9xk4sBlp57OVK38PDbgYJDPZm5a5SBba7ZSP8RNiBX1cUseNBjsxMCY olmGU1feEFFyuQiusoQW6sTeGYpErqB68Q7DzQKyYnBxTHG3nOJzhSMmOAfAmIk9Z1gx jJ//HrROYmsmZ2j91Ht5O8qAES+x7xgur33kHaf9Ny5MTN14VhA7qp3JAao65EYy1PZT h95/fW/baIyw5h1y75YB6M/4xJdGTf/oYxTCDYDQmMRVoPve77z6l35qtGZa8JmyshRW lazNlCHb/hoMy+0Pb+0b9bJxv6dgZNu8IzzfS//VnzJoCkoQTxFBcGzDbtu0OQHNB64E IOnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xppl1ADJ; 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 sg16si27578517ejc.99.2021.11.07.13.34.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Nov 2021 13:34:43 -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=xppl1ADJ; 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 66B7183813; Sun, 7 Nov 2021 22:33: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="xppl1ADJ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 35290837E9; Sun, 7 Nov 2021 22:33:37 +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-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) (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 74321837FC for ; Sun, 7 Nov 2021 22:33:31 +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-ed1-x52b.google.com with SMTP id x15so23469983edv.1 for ; Sun, 07 Nov 2021 13:33:31 -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=ke88fZzvlcU9i7FjucnfDYhYGcY2qwH8YwyQALWsgJA=; b=xppl1ADJQl+TDjuqD4/w1rh4Qe3TNyyuIU29wwVkxAcvV5AGb1nd7gWbalwhw05A+4 dMknrVb3bbBY8zUKL/HIBl0dxwyYXR2Ju0pt5kcIGSE1Bw2d+yk1Xn2h807YXe7sOfDF 0IgTcUqAE/ea+s+h0DLCdKUHIhhHSr8W9IrjOyueD/wOs33TaSGa7LimeQYYsqxg3p0H hxMJi6BwRYlA8mnLUcICe6nIeklfrmdrdWYHgZDz0G203iKnagrALXfrHlrqsDvCZn6H OIZA8Z34i8SDEVUbT5qPn8sIzgBYQsl3QgH5myG4Ri4A11rCYYACbMYxMiNAXTNzkaks PeJA== 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=ke88fZzvlcU9i7FjucnfDYhYGcY2qwH8YwyQALWsgJA=; b=tL+AbJlk1JOD6RRRivpKwEu6S9LAU5leYVoyjjANIlGUPf5KdupkkE/qV8Oea1hy1z gbaexSMdH3alF/BMDXmom81O6QJA/mFpXwnr2hTi4bbJqIpvea24t15RU5dKy6vdw+ti R9NFLsRGTCAXaPVseau+y+Kl7e4qXqcoPRTo9oy4Sc5OyjxdnM3YuvPDoa38OM6FUXYc qp4lytdSEzomkzQmH8MogLtomXxAWfo+hX0NsgT3BLGqguHSh4NP/JrfB7G9sIG9TGDN yn9v54Ic2JKBxBIjH+sHbpIxvl82G8VOfzxk5fAtM2B2IBuatdIb8+xIOJ/1AmlvS9Pb cs8A== X-Gm-Message-State: AOAM530hlHU2/++o84Y4GRMbdfh6w/NpkE8i+L5W2fMr9goASNKc86Vp l2cUpgdwdkxGEQa4NTHndjZiQpiRFWjtvw== X-Received: by 2002:a17:906:2a5a:: with SMTP id k26mr46334126eje.135.1636320811026; Sun, 07 Nov 2021 13:33:31 -0800 (PST) Received: from apalos.home ([2a02:587:4680:8a9c:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id hw8sm5042150ejc.58.2021.11.07.13.33.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Nov 2021 13:33:30 -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 v6] MAINTAINERS: Add entry for TPM drivers Date: Sun, 7 Nov 2021 23:33:11 +0200 Message-Id: <20211107213312.263357-9-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211107213312.263357-1-ilias.apalodimas@linaro.org> References: <20211107213312.263357-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 9d8cba902800..f02901c55de5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1183,6 +1183,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)