Skip to contentSkip to conversation

Locality support for tpm_crb

PATCH Superseded Jarkko Sakkinen 2 participants 13 messages Dec 7, 2016 – Dec 12, 2016 TPM device driver

lore
Share & tools
lore
#0 lore raw

v3 cover Locality support for tpm_crb

The tpm_crb driver should follow the policy of reserving and relinquishing the locality it uses when multiple localities are used, like when TXT is another locality.

Jarkko Sakkinen (3):
tpm_crb: map locality registers
tpm_crb: encapsulate crb_wait_for_reg_32
tpm_crb: request and relinquish locality 0

 drivers/char/tpm/tpm_crb.c | 185 +++++++++++++++++++++++++++++++++------------
 1 file changed, 137 insertions(+), 48 deletions(-)
Signature · 7 lines
v2: 
added sanity check for start address of the control area
v3:
do locality request/relinquish as part of send/recv
check priv->regs_h before using it
just assing the base address to regs_h instead of using crb_map_res
2.9.3
#1 lore raw

PATCH v3 1/3 tpm_crb: map locality registers

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.

---
 drivers/char/tpm/tpm_crb.c | 89 +++++++++++++++++++++++++++++-----------------
 1 file changed, 57 insertions(+), 32 deletions(-)
drivers/char/tpm/tpm_crb.c +57 -32
index 717b6b4..80b9759 100644
@@ -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,21 +139,23 @@ 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))
 			return 0;
 		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;
 	}
@@ -155,7 +168,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;
 
@@ -171,7 +184,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);
@@ -210,7 +223,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",
@@ -224,7 +237,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);
@@ -236,7 +249,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");
@@ -245,7 +258,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;
 }
@@ -322,10 +335,22 @@ 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);
+	/* The ACPI IO region starts at the head area and continues to include
+	 * the control area, as one nice sane region except for some older
+	 * stuff that puts the control area outside the ACPI IO region.
+	 */
+	if (!(priv->flags & CRB_FL_ACPI_START)) {
+		if (buf->control_address == io_res.start +
+		    sizeof(*priv->regs_h))
+			priv->regs_h = priv->iobase;
+		else
+			dev_warn(dev, FW_BUG "Bad ACPI memory layout");
+	}
+
+	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);
 
 	/*
 	 * PTT HW bug w/a: wake up the device to access
@@ -335,10 +360,10 @@ static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,
 	if (ret)
 		return ret;
 
-	pa_high = ioread32(&priv->cca->cmd_pa_high);
-	pa_low  = ioread32(&priv->cca->cmd_pa_low);
+	pa_high = ioread32(&priv->regs_t->ctrl_cmd_pa_high);
+	pa_low  = ioread32(&priv->regs_t->ctrl_cmd_pa_low);
 	cmd_pa = ((u64)pa_high << 32) | pa_low;
-	cmd_size = ioread32(&priv->cca->cmd_size);
+	cmd_size = ioread32(&priv->regs_t->ctrl_cmd_size);
 
 	dev_dbg(dev, "cmd_hi = %X cmd_low = %X cmd_size %X\n",
 		pa_high, pa_low, cmd_size);
@@ -349,9 +374,9 @@ static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,
 		goto out;
 	}
 
-	memcpy_fromio(&rsp_pa, &priv->cca->rsp_pa, 8);
+	memcpy_fromio(&rsp_pa, &priv->regs_t->ctrl_rsp_pa, 8);
 	rsp_pa = le64_to_cpu(rsp_pa);
-	rsp_size = ioread32(&priv->cca->rsp_size);
+	rsp_size = ioread32(&priv->regs_t->ctrl_rsp_size);
 
 	if (cmd_pa != rsp_pa) {
 		priv->rsp = crb_map_res(dev, priv, &io_res, rsp_pa, rsp_size);
Signature · 9 lines
2.9.3


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/xeonphi
#2 lore raw

RE: [tpmdd-devel] [PATCH v3 1/3] tpm_crb: map locality registers

Quoted 32 lines

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.

---
 drivers/char/tpm/tpm_crb.c | 89 +++++++++++++++++++++++++++++------------
-----
 1 file changed, 57 insertions(+), 32 deletions(-)
drivers/char/tpm/tpm_crb.c index renamed from drivers/char/tpm/tpm_crb.c +0 -0

717b6b4..80b9759 100644

drivers/char/tpm/tpm_crb.c +2 -12
@@ -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;

drivers/char/tpm/tpm_crb.c enum crb_cancel { · line 66

Quoted 10 lines
drivers/char/tpm/tpm_crb.c +9 -0
+	u32 reserved1;
+	u32 loc_ctrl;
+	u32 loc_sts;
+	u8 reserved2[32];
+	u64 intf_id;
+	u64 ctrl_ext;
+} __packed;
+
 
+struct crb_regs_tail {

Why to change the name this is still control_area

Quoted 15 lines
drivers/char/tpm/tpm_crb.c +11 -0
+	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 {

drivers/char/tpm/tpm_crb.c enum crb_flags { · line 92

Quoted 6 lines
drivers/char/tpm/tpm_crb.c +2 -1
@@ -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;

Same here, why to change the name, let's keep it cca it will reduce the size of patch and make it more back portable.

Quoted 99 lines
drivers/char/tpm/tpm_crb.c +1 -1
 	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 */
 
drivers/char/tpm/tpm_crb.c +5 -3
 	return 0;
@@ -128,21 +139,23 @@ 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))
 			return 0;
 		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)
 {
drivers/char/tpm/tpm_crb.c +2 -2
 		dev_warn(dev, "cmdReady timed out\n");
 		return -ETIME;
 	}
@@ -155,7 +168,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;
 
@@ -171,7 +184,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;
 
drivers/char/tpm/tpm_crb.c +1 -1
 	memcpy_fromio(buf, priv->rsp, 6);
@@ -210,7 +223,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) {
drivers/char/tpm/tpm_crb.c +1 -1
 		dev_err(&chip->dev, "invalid command count value %zd %d\n",
@@ -224,7 +237,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)
drivers/char/tpm/tpm_crb.c +1 -1
 		rc = crb_do_acpi_start(chip);
@@ -236,7 +249,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"); @@ -245,7 +258,7

@@ static void crb_cancel(struct tpm_chip *chip) static bool crb_req_canceled(struct tpm_chip *chip, u8 status) {

drivers/char/tpm/tpm_crb.c +1 -1
 	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;  }
@@ -322,10 +335,22 @@ static int crb_map_io(struct acpi_device *device,
 struct crb_priv *priv,

drivers/char/tpm/tpm_crb.c static int crb_map_io(struct acpi_device *device, · line 341

Quoted 10 lines
drivers/char/tpm/tpm_crb.c +3 -4
 	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);
+	/* The ACPI IO region starts at the head area and continues to include
+	 * the control area, as one nice sane region except for some older
+	 * stuff that puts the control area outside the ACPI IO region.

This is not explained correctly. BDW and older platforms implement only a PC subset of the spec. On those platforms there are only CCA registers, other registers are not implemented.

Quoted 45 lines
drivers/char/tpm/tpm_crb.c +13 -0
+	 */
+	if (!(priv->flags & CRB_FL_ACPI_START)) {
+		if (buf->control_address == io_res.start +
+		    sizeof(*priv->regs_h))
+			priv->regs_h = priv->iobase;
+		else
+			dev_warn(dev, FW_BUG "Bad ACPI memory layout");
+	}
+
+	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);
 
 	/*

* PTT HW bug w/a: wake up the device to access @@ -335,10 +360,10
@@ static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,

drivers/char/tpm/tpm_crb.c +5 -5
 	if (ret)
 		return ret;
 
-	pa_high = ioread32(&priv->cca->cmd_pa_high);
-	pa_low  = ioread32(&priv->cca->cmd_pa_low);
+	pa_high = ioread32(&priv->regs_t->ctrl_cmd_pa_high);
+	pa_low  = ioread32(&priv->regs_t->ctrl_cmd_pa_low);
 	cmd_pa = ((u64)pa_high << 32) | pa_low;
-	cmd_size = ioread32(&priv->cca->cmd_size);
+	cmd_size = ioread32(&priv->regs_t->ctrl_cmd_size);
 
 	dev_dbg(dev, "cmd_hi = %X cmd_low = %X cmd_size %X\n",
 		pa_high, pa_low, cmd_size);
@@ -349,9 +374,9 @@ static int crb_map_io(struct acpi_device *device, struct
 crb_priv *priv,
 		goto out;
 	}
 
-	memcpy_fromio(&rsp_pa, &priv->cca->rsp_pa, 8);
+	memcpy_fromio(&rsp_pa, &priv->regs_t->ctrl_rsp_pa, 8);
 	rsp_pa = le64_to_cpu(rsp_pa);
-	rsp_size = ioread32(&priv->cca->rsp_size);
+	rsp_size = ioread32(&priv->regs_t->ctrl_rsp_size);
 
 	if (cmd_pa != rsp_pa) {

priv->rsp = crb_map_res(dev, priv, &io_res, rsp_pa, rsp_size);
--
2.9.3

#3 lore raw

Re: [tpmdd-devel] [PATCH v3 1/3] tpm_crb: map locality registers

Quoted 169 lines · Tomas
Quoted 32 lines

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.

---
 drivers/char/tpm/tpm_crb.c | 89 +++++++++++++++++++++++++++++------------
-----
 1 file changed, 57 insertions(+), 32 deletions(-)
drivers/char/tpm/tpm_crb.c index renamed from drivers/char/tpm/tpm_crb.c +0 -0

717b6b4..80b9759 100644

drivers/char/tpm/tpm_crb.c +2 -12
@@ -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;

drivers/char/tpm/tpm_crb.c enum crb_cancel { · line 66

Quoted 10 lines
drivers/char/tpm/tpm_crb.c +9 -0
+	u32 reserved1;
+	u32 loc_ctrl;
+	u32 loc_sts;
+	u8 reserved2[32];
+	u64 intf_id;
+	u64 ctrl_ext;
+} __packed;
+
 
+struct crb_regs_tail {

Why to change the name this is still control_area

Quoted 15 lines
drivers/char/tpm/tpm_crb.c +11 -0
+	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 {

drivers/char/tpm/tpm_crb.c enum crb_flags { · line 92

Quoted 6 lines
drivers/char/tpm/tpm_crb.c +2 -1
@@ -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;

Same here, why to change the name, let's keep it cca it will reduce the size of patch and make it more back portable.

Quoted 102 lines
drivers/char/tpm/tpm_crb.c +1 -1
 	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 */
 
drivers/char/tpm/tpm_crb.c +5 -3
 	return 0;
@@ -128,21 +139,23 @@ 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))
 			return 0;
 		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)
 {
drivers/char/tpm/tpm_crb.c +2 -2
 		dev_warn(dev, "cmdReady timed out\n");
 		return -ETIME;
 	}
@@ -155,7 +168,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;
 
@@ -171,7 +184,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;
 
drivers/char/tpm/tpm_crb.c +1 -1
 	memcpy_fromio(buf, priv->rsp, 6);
@@ -210,7 +223,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) {
drivers/char/tpm/tpm_crb.c +1 -1
 		dev_err(&chip->dev, "invalid command count value %zd %d\n",
@@ -224,7 +237,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)
drivers/char/tpm/tpm_crb.c +1 -1
 		rc = crb_do_acpi_start(chip);
@@ -236,7 +249,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"); @@ -245,7 +258,7

@@ static void crb_cancel(struct tpm_chip *chip) static bool crb_req_canceled(struct tpm_chip *chip, u8 status) {

drivers/char/tpm/tpm_crb.c +1 -1
 	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;  }
@@ -322,10 +335,22 @@ static int crb_map_io(struct acpi_device *device,
 struct crb_priv *priv,
 	if (IS_ERR(priv->iobase))
 		return PTR_ERR(priv->iobase);
 
Quoted 11 lines

drivers/char/tpm/tpm_crb.c static int crb_map_io(struct acpi_device *device, struct crb_priv *priv, · line 340

Quoted 7 lines
drivers/char/tpm/tpm_crb.c +3 -4
-	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);
+	/* The ACPI IO region starts at the head area and continues to include
+	 * the control area, as one nice sane region except for some older
+	 * stuff that puts the control area outside the ACPI IO region.

This is not explained correctly. BDW and older platforms implement only a PC subset of the spec. On those platforms there are only CCA registers, other registers are not implemented.

The region pointed by the TPM2 table at least in some (if not all) old platforms I've tested is completley disjoint from the region pointed by the ACPI device tree (SSDT in PTT's case).

Here's example device from my x250:

Device (TPM)
{
Name (_HID, "MSFT0101" /* TPM 2.0 Security Device */) // _HID: Hardware ID Name (_STR, Unicode ("TPM 2.0 Device")) // _STR: Description String Name (CRS, ResourceTemplate ()
{
Memory32Fixed (ReadOnly,

    0x00000000,         // Address Base
    0x00001000,         // Address Length
    _Y00)
Memory32Fixed (ReadOnly,
    0xFED70000,         // Address Base
    0x00001000,         // Address Length
    )
})

This is from TPM2.dsl:

[028h 0040 8] Control Address : 00000000CCDFF000

/Jarkko

#4 lore raw

RE: [tpmdd-devel] [PATCH v3 1/3] tpm_crb: map locality registers

Quoted 6 lines

I've tested is completley disjoint from the region pointed by the ACPI device tree (SSDT in PTT's case).

Here's example device from my x250:

Quoted 8 lines

Device (TPM)
{
Name (_HID, "MSFT0101" /* TPM 2.0 Security Device */) // _HID: Hardware ID Name (_STR, Unicode ("TPM 2.0 Device")) // _STR: Description String Name (CRS, ResourceTemplate () { Memory32Fixed (ReadOnly,

    0x00000000,         // Address Base
    0x00001000,         // Address Length
    _Y00)

I'm not sure what is that?

Quoted 4 lines

Memory32Fixed (ReadOnly,

    0xFED70000,         // Address Base
    0x00001000,         // Address Length
    )

But 0xFED70000 should point to CCA

Tomas
Thanks

#5 lore raw

Re: [tpmdd-devel] [PATCH v3 1/3] tpm_crb: map locality registers

Quoted 16 lines · Tomas
Quoted 6 lines

I've tested is completley disjoint from the region pointed by the ACPI device tree (SSDT in PTT's case).

Here's example device from my x250:

Quoted 8 lines

Device (TPM)
{
Name (_HID, "MSFT0101" /* TPM 2.0 Security Device */) // _HID: Hardware ID Name (_STR, Unicode ("TPM 2.0 Device")) // _STR: Description String Name (CRS, ResourceTemplate () { Memory32Fixed (ReadOnly,

    0x00000000,         // Address Base
    0x00001000,         // Address Length
    _Y00)
Quoted 8 lines

I'm not sure what is that?

Quoted 4 lines

Memory32Fixed (ReadOnly,

    0xFED70000,         // Address Base
    0x00001000,         // Address Length
    )

But 0xFED70000 should point to CCA

When I implemented originally the driver I followed the MS specification and used the value from TPM2 ACPI table.

The driver ioremaps 00000000CCDFF000, not the address from SSDT.

Quoted 2 lines

Tomas
Thanks

/Jarkko

#6 lore raw

Re: [tpmdd-devel] [PATCH v3 1/3] tpm_crb: map locality registers

In reply to Jarkko Sakkinen
Quoted 42 lines · Jarkko Sakkinen
Quoted 41 lines · Tomas
Quoted 40 lines

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.

---
 drivers/char/tpm/tpm_crb.c | 89 +++++++++++++++++++++++++++++------------
-----
 1 file changed, 57 insertions(+), 32 deletions(-)
drivers/char/tpm/tpm_crb.c index renamed from drivers/char/tpm/tpm_crb.c +0 -0

717b6b4..80b9759 100644

drivers/char/tpm/tpm_crb.c +10 -12
@@ -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;
+
Quoted 2 lines
Quoted 2 lines

drivers/char/tpm/tpm_crb.c enum crb_cancel { · line 65

Quoted 1 line
drivers/char/tpm/tpm_crb.c +1 -0
+struct crb_regs_tail {

Why to change the name this is still control_area

And how would you name struct crb_regs_h then?

In my opinion PC it makes a lot of sense to speak about registers here rather than control area now that it is extended to the full range. The PC Client Specification also speaks about registers.

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
drivers/char/tpm/tpm_crb.c +11 -0
+	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;
 
Quoted 11 lines
Quoted 11 lines

drivers/char/tpm/tpm_crb.c enum crb_flags { · line 92

Quoted 8 lines
drivers/char/tpm/tpm_crb.c +2 -1
 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;

Same here, why to change the name, let's keep it cca it will reduce the size of patch and make it more back portable.

Backportability is a always a secondary priority for new features albeit something that can be considered if it doesn't get in the way.

/Jarkko

#7 lore raw

Re: [tpmdd-devel] [PATCH v3 1/3] tpm_crb: map locality registers

Quoted 43 lines · Jarkko Sakkinen
Quoted 42 lines · Jarkko Sakkinen
Quoted 41 lines · Tomas
Quoted 40 lines

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.

---
 drivers/char/tpm/tpm_crb.c | 89 +++++++++++++++++++++++++++++------------
-----
 1 file changed, 57 insertions(+), 32 deletions(-)
drivers/char/tpm/tpm_crb.c index renamed from drivers/char/tpm/tpm_crb.c +0 -0

717b6b4..80b9759 100644

drivers/char/tpm/tpm_crb.c +10 -12
@@ -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;
+
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

drivers/char/tpm/tpm_crb.c enum crb_cancel { · line 65

Quoted 1 line
drivers/char/tpm/tpm_crb.c +1 -0
+struct crb_regs_tail {

Why to change the name this is still control_area

And how would you name struct crb_regs_h then?

In my opinion PC it makes a lot of sense to speak about registers here

                ~~

Typo.

/Jarkko

#8 lore raw

RE: [tpmdd-devel] [PATCH v3 1/3] tpm_crb: map locality registers

In reply to Jarkko Sakkinen
Quoted 45 lines
Quoted 4 lines · Tomas
Quoted 3 lines
Quoted 3 lines

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.

Quoted 40 lines
Quoted 40 lines
Quoted 39 lines
---
 drivers/char/tpm/tpm_crb.c | 89
+++++++++++++++++++++++++++++------------
-----
 1 file changed, 57 insertions(+), 32 deletions(-)
(quoted diff) +0 -0

b/drivers/char/tpm/tpm_crb.c index
717b6b4..80b9759 100644

drivers/char/tpm/tpm_crb.c +10 -12
@@ -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;
+
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines

drivers/char/tpm/tpm_crb.c enum crb_cancel { · line 65

Quoted 1 line
drivers/char/tpm/tpm_crb.c +1 -0
+struct crb_regs_tail {

Why to change the name this is still control_area

And how would you name struct crb_regs_h then?

Just crb_regs

Quoted 3 lines

In my opinion PC it makes a lot of sense to speak about registers here rather than control area now that it is extended to the full range. The PC Client Specification also speaks about registers.

Right so crb_regs is to be and the nonstandard implementation of the legacy platforms should be even factored out.

Quoted 25 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
drivers/char/tpm/tpm_crb.c +11 -0
+	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;
 
Quoted 10 lines
Quoted 10 lines

drivers/char/tpm/tpm_crb.c enum crb_flags { struct crb_priv { · line 91

Quoted 7 lines
drivers/char/tpm/tpm_crb.c +2 -1
 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;

Same here, why to change the name, let's keep it cca it will reduce the size of patch and make it more back portable.

Quoted 2 lines

Backportability is a always a secondary priority for new features albeit something that can be considered if it doesn't get in the way.

I think of it as a staged steps. First do the minimal fix then do the overhaul. Anyway you are kind of counterproductive to yourself as you already know this need a back port.

Thanks
Tomas

#9 lore raw

Re: [tpmdd-devel] [PATCH v3 1/3] tpm_crb: map locality registers

Quoted 50 lines · Tomas
Quoted 45 lines
Quoted 4 lines · Tomas
Quoted 3 lines
Quoted 3 lines

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.

Quoted 40 lines
Quoted 40 lines
Quoted 39 lines
---
 drivers/char/tpm/tpm_crb.c | 89
+++++++++++++++++++++++++++++------------
-----
 1 file changed, 57 insertions(+), 32 deletions(-)
(quoted diff) +0 -0

b/drivers/char/tpm/tpm_crb.c index
717b6b4..80b9759 100644

drivers/char/tpm/tpm_crb.c +10 -12
@@ -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;
+
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines

drivers/char/tpm/tpm_crb.c enum crb_cancel { · line 65

Quoted 1 line
drivers/char/tpm/tpm_crb.c +1 -0
+struct crb_regs_tail {

Why to change the name this is still control_area

And how would you name struct crb_regs_h then?

Quoted 8 lines

Just crb_regs

Quoted 3 lines

In my opinion PC it makes a lot of sense to speak about registers here rather than control area now that it is extended to the full range. The PC Client Specification also speaks about registers.

Right so crb_regs is to be and the nonstandard implementation of the legacy platforms should be even factored out.

I do not see that we would stop supporting pre-Skylake platforms in the near future so probably won't be factored out.

/Jarkko

#10 lore raw

Re: [tpmdd-devel] [PATCH v3 1/3] tpm_crb: map locality registers

Quoted 57 lines · Jarkko Sakkinen
Quoted 56 lines · Tomas
Quoted 45 lines
Quoted 4 lines · Tomas
Quoted 3 lines
Quoted 3 lines

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.

Quoted 40 lines
Quoted 40 lines
Quoted 39 lines
---
 drivers/char/tpm/tpm_crb.c | 89
+++++++++++++++++++++++++++++------------
-----
 1 file changed, 57 insertions(+), 32 deletions(-)
(quoted diff) +0 -0

b/drivers/char/tpm/tpm_crb.c index
717b6b4..80b9759 100644

drivers/char/tpm/tpm_crb.c +10 -12
@@ -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;
+
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines

drivers/char/tpm/tpm_crb.c enum crb_cancel { · line 65

Quoted 1 line
drivers/char/tpm/tpm_crb.c +1 -0
+struct crb_regs_tail {

Why to change the name this is still control_area

And how would you name struct crb_regs_h then?

Just crb_regs

Quoted 3 lines

In my opinion PC it makes a lot of sense to speak about registers here rather than control area now that it is extended to the full range. The PC Client Specification also speaks about registers.

Quoted 5 lines
Quoted 2 lines

Right so crb_regs is to be and the nonstandard implementation of the legacy platforms should be even factored out.

I do not see that we would stop supporting pre-Skylake platforms in the near future so probably won't be factored out.

s/near/forseeable/

/Jarkko

#11 lore raw

PATCH v3 2/3 tpm_crb: encapsulate crb_wait_for_reg_32

In reply to Jarkko Sakkinen

Encapsulated crb_wait_for_reg32() so that state changes in other CRB registers than TPM_CRB_CTRL_REQ_x can be waited.

---
 drivers/char/tpm/tpm_crb.c | 37 +++++++++++++++++++++++--------------
 1 file changed, 23 insertions(+), 14 deletions(-)
drivers/char/tpm/tpm_crb.c +23 -14
index 80b9759..853bd7b 100644
@@ -121,6 +121,25 @@ static int __maybe_unused crb_go_idle(struct device *dev, struct crb_priv *priv)
 	return 0;
 }
 
+static bool crb_wait_for_reg_32(u32 __iomem *reg, u32 mask, u32 value,
+				unsigned long timeout)
+{
+	ktime_t start;
+	ktime_t stop;
+
+	start = ktime_get();
+	stop = ktime_add(start, ms_to_ktime(timeout));
+
+	do {
+		if ((ioread32(reg) & mask) == value)
+			return true;
+
+		usleep_range(50, 100);
+	} while (ktime_before(ktime_get(), stop));
+
+	return false;
+}
+
 /**
  * crb_cmd_ready - request tpm crb device to enter ready state
  *
@@ -138,24 +157,14 @@ static int __maybe_unused crb_go_idle(struct device *dev, struct crb_priv *priv)
 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->regs_t->ctrl_req);
-
-	start = ktime_get();
-	stop = ktime_add(start, ms_to_ktime(TPM2_TIMEOUT_C));
-	do {
-		req = ioread32(&priv->regs_t->ctrl_req);
-		if (!(req & CRB_CTRL_REQ_CMD_READY))
-			return 0;
-		usleep_range(50, 100);
-	} while (ktime_before(ktime_get(), stop));
-
-	if (ioread32(&priv->regs_t->ctrl_req) & CRB_CTRL_REQ_CMD_READY) {
+	if (!crb_wait_for_reg_32(&priv->regs_t->ctrl_req,
+				 CRB_CTRL_REQ_CMD_READY /* mask */,
+				 0, /* value */
+				 TPM2_TIMEOUT_C)) {
 		dev_warn(dev, "cmdReady timed out\n");
 		return -ETIME;
 	}
Signature · 9 lines
2.9.3


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/xeonphi
#12 lore raw

PATCH v3 3/3 tpm_crb: request and relinquish locality 0

In reply to Jarkko Sakkinen

Request and relinquish locality for the driver use in order to be a better citizen in a multi locality environment like TXT.

---
 drivers/char/tpm/tpm_crb.c | 73 ++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 64 insertions(+), 9 deletions(-)
drivers/char/tpm/tpm_crb.c +64 -9
index 853bd7b..96f661a 100644
@@ -34,6 +34,15 @@ enum crb_defaults {
 	CRB_ACPI_START_INDEX = 1,
 };
 
+enum crb_loc_ctrl {
+	CRB_LOC_CTRL_REQUEST_ACCESS	= BIT(0),
+	CRB_LOC_CTRL_RELINQUISH		= BIT(1),
+};
+
+enum crb_loc_state {
+	CRB_LOC_STATE_LOC_ASSIGNED	= BIT(1),
+};
+
 enum crb_ctrl_req {
 	CRB_CTRL_REQ_CMD_READY	= BIT(0),
 	CRB_CTRL_REQ_GO_IDLE	= BIT(1),
@@ -165,13 +174,42 @@ static int __maybe_unused crb_cmd_ready(struct device *dev,
 				 CRB_CTRL_REQ_CMD_READY /* mask */,
 				 0, /* value */
 				 TPM2_TIMEOUT_C)) {
-		dev_warn(dev, "cmdReady timed out\n");
+		dev_warn(dev, "TPM_CRB_CTRL_REQ_x.cmdReady timed out\n");
+		return -ETIME;
+	}
+
+	return 0;
+}
+
+static int crb_request_locality(struct tpm_chip *chip)
+{
+	struct crb_priv *priv = dev_get_drvdata(&chip->dev);
+
+	if (!priv->regs_h)
+		return 0;
+
+	iowrite32(CRB_LOC_CTRL_REQUEST_ACCESS, &priv->regs_h->loc_ctrl);
+	if (!crb_wait_for_reg_32(&priv->regs_h->loc_state,
+				 CRB_LOC_STATE_LOC_ASSIGNED, /* mask */
+				 CRB_LOC_STATE_LOC_ASSIGNED, /* value */
+				 TPM2_TIMEOUT_C)) {
+		dev_warn(&chip->dev, "TPM_LOC_STATE_x.requestAccess timed out\n");
 		return -ETIME;
 	}
 
 	return 0;
 }
 
+static void crb_relinquish_locality(struct tpm_chip *chip)
+{
+	struct crb_priv *priv = dev_get_drvdata(&chip->dev);
+
+	if (!priv->regs_h)
+		return;
+
+	iowrite32(CRB_LOC_CTRL_RELINQUISH, &priv->regs_h->loc_ctrl);
+}
+
 static u8 crb_status(struct tpm_chip *chip)
 {
 	struct crb_priv *priv = dev_get_drvdata(&chip->dev);
@@ -188,23 +226,33 @@ static int crb_recv(struct tpm_chip *chip, u8 *buf, size_t count)
 {
 	struct crb_priv *priv = dev_get_drvdata(&chip->dev);
 	unsigned int expected;
+	int rc;
 
 	/* sanity check */
 	if (count < 6)
 		return -EIO;
 
-	if (ioread32(&priv->regs_t->ctrl_sts) & CRB_CTRL_STS_ERROR)
-		return -EIO;
+	rc = crb_request_locality(chip);
+	if (rc)
+		return rc;
+
+	if (ioread32(&priv->regs_t->ctrl_sts) & CRB_CTRL_STS_ERROR) {
+		rc = -EIO;
+		goto out;
+	}
 
 	memcpy_fromio(buf, priv->rsp, 6);
 	expected = be32_to_cpup((__be32 *) &buf[2]);
-
-	if (expected > count)
-		return -EIO;
+	if (expected > count) {
+		rc = -EIO;
+		goto out;
+	}
 
 	memcpy_fromio(&buf[6], &priv->rsp[6], expected - 6);
 
-	return expected;
+out:
+	crb_relinquish_locality(chip);
+	return rc ? rc : expected;
 }
 
 static int crb_do_acpi_start(struct tpm_chip *chip)
@@ -227,7 +275,11 @@ static int crb_do_acpi_start(struct tpm_chip *chip)
 static int crb_send(struct tpm_chip *chip, u8 *buf, size_t len)
 {
 	struct crb_priv *priv = dev_get_drvdata(&chip->dev);
-	int rc = 0;
+	int rc;
+
+	rc = crb_request_locality(chip);
+	if (rc)
+		return rc;
 
 	/* Zero the cancel register so that the next command will not get
 	 * canceled.
@@ -237,7 +289,8 @@ static int crb_send(struct tpm_chip *chip, u8 *buf, size_t len)
 	if (len > priv->cmd_size) {
 		dev_err(&chip->dev, "invalid command count value %zd %d\n",
 			len, priv->cmd_size);
-		return -E2BIG;
+		rc = -E2BIG;
+		goto out;
 	}
 
 	memcpy_toio(priv->cmd, buf, len);
@@ -251,6 +304,8 @@ static int crb_send(struct tpm_chip *chip, u8 *buf, size_t len)
 	if (priv->flags & CRB_FL_ACPI_START)
 		rc = crb_do_acpi_start(chip);
 
+out:
+	crb_relinquish_locality(chip);
 	return rc;
 }
 
Signature · 9 lines
2.9.3


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/xeonphi