From: Jarkko Sakkinen <jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
To: Peter Huewe <peterhuewe-Mmb7MZpHnFY@public.gmane.org>
Cc: "moderated list:TPM DEVICE DRIVER"
<tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>,
open list <linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: [PATCH 1/3] tpm_crb: map locality registers
Date: Tue, 11 Oct 2016 14:25:30 +0300 [thread overview]
Message-ID: <20161011112530.GC21688@intel.com> (raw)
In-Reply-To: <1476177787-15003-3-git-send-email-jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
On Tue, Oct 11, 2016 at 12:23:04PM +0300, Jarkko Sakkinen wrote:
> In order to provide access to locality registers, this commits adds
> mapping of the head of the CRB registers, which are located right
> before the control area.
>
> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
> ---
> drivers/char/tpm/tpm_crb.c | 86 +++++++++++++++++++++++++++++-----------------
> 1 file changed, 54 insertions(+), 32 deletions(-)
>
> diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c
> index 65040d7..c34318b 100644
> --- a/drivers/char/tpm/tpm_crb.c
> +++ b/drivers/char/tpm/tpm_crb.c
> @@ -52,18 +52,28 @@ enum crb_cancel {
> CRB_CANCEL_INVOKE = BIT(0),
> };
>
> -struct crb_control_area {
> - u32 req;
> - u32 sts;
> - u32 cancel;
> - u32 start;
> - u32 int_enable;
> - u32 int_sts;
> - u32 cmd_size;
> - u32 cmd_pa_low;
> - u32 cmd_pa_high;
> - u32 rsp_size;
> - u64 rsp_pa;
> +struct crb_regs_head {
> + u32 loc_state;
> + u32 reserved1;
> + u32 loc_ctrl;
> + u32 loc_sts;
> + u8 reserved2[32];
> + u64 intf_id;
> + u64 ctrl_ext;
> +} __packed;
> +
> +struct crb_regs_tail {
> + u32 ctrl_req;
> + u32 ctrl_sts;
> + u32 ctrl_cancel;
> + u32 ctrl_start;
> + u32 ctrl_int_enable;
> + u32 ctrl_int_sts;
> + u32 ctrl_cmd_size;
> + u32 ctrl_cmd_pa_low;
> + u32 ctrl_cmd_pa_high;
> + u32 ctrl_rsp_size;
> + u64 ctrl_rsp_pa;
> } __packed;
>
> enum crb_status {
> @@ -78,7 +88,8 @@ enum crb_flags {
> struct crb_priv {
> unsigned int flags;
> void __iomem *iobase;
> - struct crb_control_area __iomem *cca;
> + struct crb_regs_head __iomem *regs_h;
> + struct crb_regs_tail __iomem *regs_t;
> u8 __iomem *cmd;
> u8 __iomem *rsp;
> u32 cmd_size;
> @@ -104,7 +115,7 @@ static int __maybe_unused crb_go_idle(struct device *dev, struct crb_priv *priv)
> if (priv->flags & CRB_FL_ACPI_START)
> return 0;
>
> - iowrite32(CRB_CTRL_REQ_GO_IDLE, &priv->cca->req);
> + iowrite32(CRB_CTRL_REQ_GO_IDLE, &priv->regs_t->ctrl_req);
> /* we don't really care when this settles */
>
> return 0;
> @@ -128,16 +139,18 @@ static int __maybe_unused crb_cmd_ready(struct device *dev,
> struct crb_priv *priv)
> {
> ktime_t stop, start;
> + u32 req;
>
> if (priv->flags & CRB_FL_ACPI_START)
> return 0;
>
> - iowrite32(CRB_CTRL_REQ_CMD_READY, &priv->cca->req);
> + iowrite32(CRB_CTRL_REQ_CMD_READY, &priv->regs_t->ctrl_req);
>
> start = ktime_get();
> stop = ktime_add(start, ms_to_ktime(TPM2_TIMEOUT_C));
> do {
> - if (!(ioread32(&priv->cca->req) & CRB_CTRL_REQ_CMD_READY)) {
> + req = ioread32(&priv->regs_t->ctrl_req);
> + if (!(req & CRB_CTRL_REQ_CMD_READY)) {
> dev_dbg(dev, "cmdReady in %lld usecs\n",
> ktime_to_us(ktime_sub(ktime_get(), start)));
> return 0;
> @@ -145,7 +158,7 @@ static int __maybe_unused crb_cmd_ready(struct device *dev,
> usleep_range(50, 100);
> } while (ktime_before(ktime_get(), stop));
>
> - if (ioread32(&priv->cca->req) & CRB_CTRL_REQ_CMD_READY) {
> + if (ioread32(&priv->regs_t->ctrl_req) & CRB_CTRL_REQ_CMD_READY) {
> dev_warn(dev, "cmdReady timed out\n");
> return -ETIME;
> }
> @@ -158,7 +171,7 @@ static u8 crb_status(struct tpm_chip *chip)
> struct crb_priv *priv = dev_get_drvdata(&chip->dev);
> u8 sts = 0;
>
> - if ((ioread32(&priv->cca->start) & CRB_START_INVOKE) !=
> + if ((ioread32(&priv->regs_t->ctrl_start) & CRB_START_INVOKE) !=
> CRB_START_INVOKE)
> sts |= CRB_DRV_STS_COMPLETE;
>
> @@ -174,7 +187,7 @@ static int crb_recv(struct tpm_chip *chip, u8 *buf, size_t count)
> if (count < 6)
> return -EIO;
>
> - if (ioread32(&priv->cca->sts) & CRB_CTRL_STS_ERROR)
> + if (ioread32(&priv->regs_t->ctrl_sts) & CRB_CTRL_STS_ERROR)
> return -EIO;
>
> memcpy_fromio(buf, priv->rsp, 6);
> @@ -213,7 +226,7 @@ static int crb_send(struct tpm_chip *chip, u8 *buf, size_t len)
> /* Zero the cancel register so that the next command will not get
> * canceled.
> */
> - iowrite32(0, &priv->cca->cancel);
> + iowrite32(0, &priv->regs_t->ctrl_cancel);
>
> if (len > priv->cmd_size) {
> dev_err(&chip->dev, "invalid command count value %zd %d\n",
> @@ -227,7 +240,7 @@ static int crb_send(struct tpm_chip *chip, u8 *buf, size_t len)
> wmb();
>
> if (priv->flags & CRB_FL_CRB_START)
> - iowrite32(CRB_START_INVOKE, &priv->cca->start);
> + iowrite32(CRB_START_INVOKE, &priv->regs_t->ctrl_start);
>
> if (priv->flags & CRB_FL_ACPI_START)
> rc = crb_do_acpi_start(chip);
> @@ -239,7 +252,7 @@ static void crb_cancel(struct tpm_chip *chip)
> {
> struct crb_priv *priv = dev_get_drvdata(&chip->dev);
>
> - iowrite32(CRB_CANCEL_INVOKE, &priv->cca->cancel);
> + iowrite32(CRB_CANCEL_INVOKE, &priv->regs_t->ctrl_cancel);
>
> if ((priv->flags & CRB_FL_ACPI_START) && crb_do_acpi_start(chip))
> dev_err(&chip->dev, "ACPI Start failed\n");
> @@ -248,7 +261,7 @@ static void crb_cancel(struct tpm_chip *chip)
> static bool crb_req_canceled(struct tpm_chip *chip, u8 status)
> {
> struct crb_priv *priv = dev_get_drvdata(&chip->dev);
> - u32 cancel = ioread32(&priv->cca->cancel);
> + u32 cancel = ioread32(&priv->regs_t->ctrl_cancel);
>
> return (cancel & CRB_CANCEL_INVOKE) == CRB_CANCEL_INVOKE;
> }
> @@ -290,6 +303,8 @@ static void __iomem *crb_map_res(struct device *dev, struct crb_priv *priv,
> if (start != new_res.start)
> return (void __iomem *) ERR_PTR(-EINVAL);
>
> + dev_dbg(dev, "%pr %pr", io_res, &new_res);
> +
> if (!resource_contains(io_res, &new_res))
> return devm_ioremap_resource(dev, &new_res);
>
> @@ -325,10 +340,17 @@ static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,
> if (IS_ERR(priv->iobase))
> return PTR_ERR(priv->iobase);
>
> - priv->cca = crb_map_res(dev, priv, &io_res, buf->control_address,
> - sizeof(struct crb_control_area));
> - if (IS_ERR(priv->cca))
> - return PTR_ERR(priv->cca);
> + if (priv->flags & CRB_FL_CRB_START) {
Oops. Should be check for CRB_FL_ACPI_START.
Because we anyway *always* set CRB_FL_CRB_START for everything
how about ripping of CRB_FL_CRB_START flag completely in order
to not cause mistakes like this in future?
/Jarkko
> + priv->regs_h = crb_map_res(dev, priv, &io_res, io_res.start,
> + sizeof(struct crb_regs_head));
> + if (IS_ERR(priv->regs_h))
> + return PTR_ERR(priv->regs_h);
> + }
> +
> + priv->regs_t = crb_map_res(dev, priv, &io_res, buf->control_address,
> + sizeof(struct crb_regs_tail));
> + if (IS_ERR(priv->regs_t))
> + return PTR_ERR(priv->regs_t);
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
next prev parent reply other threads:[~2016-10-11 11:25 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-11 9:23 [PATCH 0/3] Locality support for the CRB driver Jarkko Sakkinen
[not found] ` <1476177787-15003-1-git-send-email-jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2016-10-11 9:23 ` [PATCH RFC 1/3] tpm_crb: expand struct crb_control_area to struct crb_regs Jarkko Sakkinen
2016-10-11 9:23 ` [PATCH 1/3] tpm_crb: map locality registers Jarkko Sakkinen
[not found] ` <1476177787-15003-3-git-send-email-jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2016-10-11 11:25 ` Jarkko Sakkinen [this message]
2016-10-11 17:01 ` Jason Gunthorpe
[not found] ` <20161011170143.GC6881-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-10-11 18:21 ` Jarkko Sakkinen
[not found] ` <20161011182100.GC6900-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-10-11 18:29 ` Jason Gunthorpe
[not found] ` <20161011182922.GB20253-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-10-11 19:48 ` Jarkko Sakkinen
2016-10-11 9:23 ` [PATCH 2/3] tpm_crb: encapsulate crb_wait_for_reg_32 Jarkko Sakkinen
[not found] ` <1476177787-15003-4-git-send-email-jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2016-10-11 10:21 ` Winkler, Tomas
[not found] ` <5B8DA87D05A7694D9FA63FD143655C1B542F7FD8-Jy8z56yoSI8MvF1YICWikbfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2016-10-11 11:29 ` Jarkko Sakkinen
2016-10-11 9:23 ` [PATCH 3/3] tpm_crb: request and relinquish locality 0 Jarkko Sakkinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161011112530.GC21688@intel.com \
--to=jarkko.sakkinen-vuqaysv1563yd54fqh9/ca@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=peterhuewe-Mmb7MZpHnFY@public.gmane.org \
--cc=tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).