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=-15.8 required=3.0 tests=BAYES_00,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 C91BEC07E99 for ; Mon, 12 Jul 2021 18:22:58 +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 D46CF60230 for ; Mon, 12 Jul 2021 18:22:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D46CF60230 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.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 DC53D82D62; Mon, 12 Jul 2021 20:22:55 +0200 (CEST) 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="QOVs/Ask"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 411D782D71; Mon, 12 Jul 2021 20:22:54 +0200 (CEST) Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) (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 1CC1080F47 for ; Mon, 12 Jul 2021 20:22:51 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-wr1-x430.google.com with SMTP id t5so13045358wrw.12 for ; Mon, 12 Jul 2021 11:22:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=sEue3Iep+Q3YBPRc4X6xl/0XCNSLNC83iQ6jr8EQIOg=; b=QOVs/Ask7pzczvOU2wXsK31xs2rd/TXtH6z4glHnLMm4HDyiFG7JqiKV9dBpbruMDo bAcf82AEuu3Yt5JijefB5AWQZy2tYuy/ftk6Wyigt+1N39GeZNhNSh4WmFJfPRWgWD5M VkfHWA0472eel2KhPGpHuMw1P563dpg6HFUXf2HQor67xl1ld8Y/gIgxamcybOS/n3xh 04D3BqCtgDkDDUBe1S1bbR7tbfuanpXd9fsahnbCNm/UTB8q9FS2UlAcCAn8b+NcD7fu ycShF1tLjyKj8bqLH/efrL7brKeYm4z4baMV864RqfpgJM0m7rdyDEuKZlmlfn4Xixwx HOnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=sEue3Iep+Q3YBPRc4X6xl/0XCNSLNC83iQ6jr8EQIOg=; b=YXxLmhXUPvtWFoZeDrndng66IEAvf0GB7oNb/5eDKTkNnJF0s5dq+0tIyq60v3eRvM pe+/NnwxftX65z1Wn4AZqBOmbmcVO9UaSEXdEoJVDV+oInT7stQiyoD+SzQkqmlbpDLM cZ1O82IdMlCnqjMSP1nCkBIblB8PUvmcAjHhVFyRZwTVzNaGkk0saqq0dldgHxBIu56W okAxQF4ikd1PKetG08OXHihKtnbfu+Yz+vhtj19RmIhz57dphCc2R63i1r3Q0CZlaNhh XRQXPHiy9fMpKJyofCiRsY9cYyYN/0z6bsGixNzRo+V83a6Ol3/Y4uAOb9e2lopeTnAl z4XA== X-Gm-Message-State: AOAM531GfGnFbAS+v9dS5k/2tnlBpX9Ughb+yfys44wdbF9V3w4+sIqW azvHRbZ2uQtoYRDtGSn0HVkmPQ== X-Google-Smtp-Source: ABdhPJz6ezIQaJunUMDa/ztmY2mHpY8WCZsqDgPdaHLOX72vS3dapuwBFsd11Ni6qxbvR23VQ8RjdA== X-Received: by 2002:adf:edd1:: with SMTP id v17mr362325wro.276.1626114170617; Mon, 12 Jul 2021 11:22:50 -0700 (PDT) Received: from enceladus (athedsl-417902.home.otenet.gr. [79.131.184.108]) by smtp.gmail.com with ESMTPSA id v14sm5601869wru.77.2021.07.12.11.22.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jul 2021 11:22:50 -0700 (PDT) Date: Mon, 12 Jul 2021 21:22:47 +0300 From: Ilias Apalodimas To: Simon Glass Cc: Heinrich Schuchardt , Johannes Holland , Masahisa Kojima , Dhananjay Phadke , U-Boot Mailing List Subject: Re: [PATCH 2/2] tpm2: Add a TPMv2 MMIO TIS driver Message-ID: References: <20210707162604.84196-1-ilias.apalodimas@linaro.org> <20210707162604.84196-2-ilias.apalodimas@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Simon, On Sat, Jul 10, 2021 at 06:00:59PM -0600, Simon Glass wrote: > Hi Ilias, > > On Wed, 7 Jul 2021 at 10:26, Ilias Apalodimas > wrote: > > > > 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 > > --- > > Changes since v1: > > - split off the tis core code into a different file > > drivers/tpm/Kconfig | 9 +++ > > drivers/tpm/Makefile | 1 + > > drivers/tpm/tpm2_tis_mmio.c | 156 ++++++++++++++++++++++++++++++++++++ > > 3 files changed, 166 insertions(+) > > create mode 100644 drivers/tpm/tpm2_tis_mmio.c > > Looks good to me Thanks! > > > > +struct tpm_tis_chip_data { > > + unsigned int pcr_count; > > + unsigned int pcr_select_min; > > + unsigned int time_before_first_cmd_ms; > > + void __iomem *iobase; > > +}; > > comments > You mean on all the internal functions? Sure I can add them > > + > > +static int mmio_read_bytes(struct udevice *udev, u32 addr, u16 len, > > + u8 *result) > > +{ > > + struct tpm_tis_chip_data *drv_data = (void *)dev_get_driver_data(udev); > > + > > + while (len--) > > + *result++ = ioread8(drv_data->iobase + addr); > > We normally put a blank line before the final return > sure > > + return 0; > > +} > > + > > +static int mmio_write_bytes(struct udevice *udev, u32 addr, u16 len, > > + const u8 *value) > > +{ > > + struct tpm_tis_chip_data *drv_data = (void *)dev_get_driver_data(udev); > > + > > + while (len--) > > + iowrite8(*value++, drv_data->iobase + addr); > > + return 0; > > +} > > + > > +static int mmio_read16(struct udevice *udev, u32 addr, u16 *result) > > +{ > > + struct tpm_tis_chip_data *drv_data = (void *)dev_get_driver_data(udev); > > + > > + *result = ioread16(drv_data->iobase + addr); > > + return 0; > > +} > > + > > +static int mmio_read32(struct udevice *udev, u32 addr, u32 *result) > > +{ > > + struct tpm_tis_chip_data *drv_data = (void *)dev_get_driver_data(udev); > > + > > + *result = ioread32(drv_data->iobase + addr); > > + return 0; > > +} > > + > > +static int mmio_write32(struct udevice *udev, u32 addr, u32 value) > > +{ > > + struct tpm_tis_chip_data *drv_data = (void *)dev_get_driver_data(udev); > > + > > + iowrite32(value, drv_data->iobase + addr); > > + return 0; > > +} > > + > > +static struct tpm_tis_phy_ops phy_ops = { > > Should be a uclass interface. > Why? A uclass is supposed to describe and abstract hardware. This is just a specific implementation of a TPM, not all TPMs are TIS compliant. We already have a uclass for those. > > + .read_bytes = mmio_read_bytes, > > + .write_bytes = mmio_write_bytes, > > + .read16 = mmio_read16, > > + .read32 = mmio_read32, > > + .write32 = mmio_write32, > > +}; > > + > > +static int tpm_tis_probe(struct udevice *udev) > > +{ > > + struct tpm_tis_chip_data *drv_data = (void *)dev_get_driver_data(udev); > > + struct tpm_chip_priv *priv = dev_get_uclass_priv(udev); > > + int ret = 0; > > + fdt_addr_t ioaddr; > > + u64 sz; > > + > > + ioaddr = dev_read_addr(udev); > > + if (ioaddr == FDT_ADDR_T_NONE) > > + return -EINVAL; > > consider this for easier debugging: > > return log_msg_ret("ioaddr", -EINVAL); > Sure > > + > > + ret = dev_read_u64(udev, "reg", &sz); > > + if (ret) > > + return -EINVAL; > > + > > + drv_data->iobase = ioremap(ioaddr, sz); > > + log_info("Remapped TPM2 base: 0x%llx size: 0x%llx\n", ioaddr, sz); > > log_debug() I think? > Yea, that's a leftover of my initial code, were I needed to make sure the ioremap worked. > > + tpm_tis_ops_register(udev, &phy_ops); > > + ret = tpm_tis_init(udev); > > + 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 *udev) > > +{ > > + struct tpm_tis_chip_data *drv_data = (void *)dev_get_driver_data(udev); > > + > > + iounmap(drv_data->iobase); > > + return tpm_tis_cleanup(udev); > > +} > > + > > +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), > > +}; > > -- > > 2.32.0.rc0 > > > > Regards, > Simon Thanks for looking at this /Ilias