From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D24CC07E99 for ; Mon, 12 Jul 2021 11:42:24 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8DD02610FA for ; Mon, 12 Jul 2021 11:42:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8DD02610FA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CE3EE82916; Mon, 12 Jul 2021 13:42:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="QeDoMjc1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D2C2682C53; Mon, 12 Jul 2021 13:42:19 +0200 (CEST) Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) (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 1121080796 for ; Mon, 12 Jul 2021 13:42:16 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@google.com Received: by mail-wm1-x335.google.com with SMTP id y21-20020a7bc1950000b02902161fccabf1so11019967wmi.2 for ; Mon, 12 Jul 2021 04:42:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=cNGe9KPc39K6GMsKsA5TUjb6WVwh/E3epzAaZCQb+E0=; b=QeDoMjc1jIFUa0vhm2qMuFAi8/3c5TDqMF/l4IqFqsUrGIAW/DtG/pfNLQsANncVv7 TKdhDsuUd5lUUQAh0l9zovcKLRlIk3WRJcbzUK6TxLfSi+qhpeaHsa0pDYcHEaxsrscp KY0LYni3gSoOU9BDzEKe4be608dA6uF7QkBFM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=cNGe9KPc39K6GMsKsA5TUjb6WVwh/E3epzAaZCQb+E0=; b=qASZVXoC81PEbDchIduZKPx6yuoir2F3IgVJ3vL5k+7knuX+d6ClVNNRa4DXWRDpHa IdzJnG21eLi8Y7DZ0JWpr4nJUK7NAsBpkPiCZgn51hWTCePdE5Bj+O1YMC0WDqU6d8wI 4GVf4O1qbOIjTewQwBZkX4sMMN2RyTn0YFPMs1ncy1F9CL/Ro1D3pggoIqOszNcLASoK cOy3hqD5VL0c9B8QtlDFR1gxQ2hYNHW5tWqpgJBPO0jWAc8KViVlmZLWt2DAyIOy9lNJ JBqfPXpfvoNSp+ghsO4yCJc2PTyUuErTsI23B0RnqfnfKwxBFPZbGKd3BnvnSLTuMGXy Lkww== X-Gm-Message-State: AOAM5333ERKPyX7LQA0muTkwNn9IuAwbVOx01wFaDRfkmdReZy6mKbnW wURqOKs+pAkWOOy0w0L6StuGg5Jwk7Lc7X588mUtdw== X-Google-Smtp-Source: ABdhPJwJQdSBDQU9/v8+T0T4E9J4Ay90RWcvGGra0FJ7CktrnWgnNWRe5zoeankIlenrp8zD5eaACpPBt092Tdo9qY8= X-Received: by 2002:a1c:4e0c:: with SMTP id g12mr13830451wmh.120.1626090135146; Mon, 12 Jul 2021 04:42:15 -0700 (PDT) MIME-Version: 1.0 References: <20210707162604.84196-1-ilias.apalodimas@linaro.org> In-Reply-To: From: Simon Glass Date: Mon, 12 Jul 2021 05:42:03 -0600 Message-ID: Subject: Re: [PATCH 1/2 v2] tpm2: Introduce TIS tpm core To: Ilias Apalodimas Cc: Heinrich Schuchardt , Johannes Holland , Masahisa Kojima , Dhananjay Phadke , U-Boot Mailing List Content-Type: text/plain; charset="UTF-8" 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 Hi Ilias, On Mon, 12 Jul 2021 at 00:24, Ilias Apalodimas wrote: > > On Sat, Jul 10, 2021 at 06:00:57PM -0600, Simon Glass wrote: > > Hi Ilias, > > > > On Wed, 7 Jul 2021 at 10:26, Ilias Apalodimas > > wrote: > > > > > > There's a lot of code duplication in U-Boot right now. All the TPM TIS > > > > You mean in the TPM code I think. > > > > Yes. Basically al TPM drivers duplicate this. > > > > 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 > > > --- > > > Changes since v1: > > > - > > > drivers/tpm/tpm2_tis_core.c | 545 ++++++++++++++++++++++++++++++++++++ > > > drivers/tpm/tpm_tis.h | 40 +++ > > > include/tpm-v2.h | 1 + > > > 3 files changed, 586 insertions(+) > > > create mode 100644 drivers/tpm/tpm2_tis_core.c > > > > [..] > > > > > diff --git a/drivers/tpm/tpm_tis.h b/drivers/tpm/tpm_tis.h > > > index 2a160fe05c9a..fde3bb71f7c2 100644 > > > --- a/drivers/tpm/tpm_tis.h > > > +++ b/drivers/tpm/tpm_tis.h > > > @@ -21,6 +21,37 @@ > > > #include > > > #include > > > > > > +struct tpm_tis_phy_ops { > > > + int (*read_bytes)(struct udevice *udev, u32 addr, u16 len, > > > + u8 *result); > > > + int (*write_bytes)(struct udevice *udev, u32 addr, u16 len, > > > + const u8 *value); > > > + int (*read16)(struct udevice *udev, u32 addr, u16 *result); > > > + int (*read32)(struct udevice *udev, u32 addr, u32 *result); > > > + int (*write32)(struct udevice *udev, u32 addr, u32 src); > > > > A few points: > > > > - these need comments > > - can we use uint instead of u32 for the value args? We should use > > native types where we can > > Yes probably, I'll have a look > ` > > - it seems like this should be a driver interface - see for example > > how cros_ec.c works. It has a shared code library and the drivers each > > implement an interface similar to the above, but on different buses. > > In general function pointers are a sign we should be using a driver > > > > I am not sure I am following, but I'll have a look on the code you pointed > out. > > > > +}; > > > + > > > +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 +74,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 +162,12 @@ enum tis_status { > > > }; > > > #endif > > > > > > +int tpm_tis_open(struct udevice *udev); > > > +int tpm_tis_close(struct udevice *udev); > > > +int tpm_tis_cleanup(struct udevice *udev); > > > +int tpm_tis_send(struct udevice *udev, const u8 *buf, size_t len); > > > +int tpm_tis_recv(struct udevice *udev, u8 *buf, size_t count); > > > +int tpm_tis_get_desc(struct udevice *udev, char *buf, int size); > > > +int tpm_tis_init(struct udevice *udev); > > > +void tpm_tis_ops_register(struct udevice *udev, struct tpm_tis_phy_ops *ops); > > > > comments on all of these > > > > > #endif > > > diff --git a/include/tpm-v2.h b/include/tpm-v2.h > > > index 247b38696766..3e48e358613f 100644 > > > --- a/include/tpm-v2.h > > > +++ b/include/tpm-v2.h > > > @@ -378,6 +378,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 > > > > Does this below in another patch? > > > > It's a general tpm2 update. I can move it to the driver patch if it makes > more sense. > > > > }; > > > > > > enum { > > > -- > > > 2.32.0.rc0 > > > > > > > I feel that this API could be useful in reducing code duplication, but > > in fact it has just created more, so far as I can see from this series > > :-) So I think you should convert at least one driver to show its > > value (and not make things any worse). > > The mmio tpm driver uses it and instead of ~700 lines (like the tpmv2 spi > driver) it drops down to ~100. I don't have access to any other TPM > hardware to rewrite any of those. Yes, but I hope you see my point, that you have added a new interface. It is definitely better than adding a new driver and duplicating all the code, but it is still one more copy and in fact, the code is duplicated. Can you get access to TPM hardware? I see that you have offered to be the maintainer for this subsystem, so I think that would be useful. Can sandbox use your new API? Regards, Simon