Skip to content

Commit a3fbfae

Browse files
author
Jarkko Sakkinen
committed
tpm: take TPM chip power gating out of tpm_transmit()
Call tpm_chip_start() and tpm_chip_stop() in * tpm_chip_register() * tpm_class_shutdown() * tpm_del_char_device() * tpm_pm_suspend() * tpm_try_get_ops() and tpm_put_ops() * tpm2_del_space() And remove these calls from tpm_transmit(). The core reason for this change is that in tpm_vtpm_proxy a locality change requires a virtual TPM command (a command made up just for that driver). The consequence of this is that this commit removes the remaining nested calls. Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Reviewed-by: Stefan Berger <stefanb@linux.ibm.com> Tested-by: Stefan Berger <stefanb@linux.ibm.com> Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com> Reviewed-by: James Bottomley <James.Bottomley@HansenPartnership.com> Tested-by: Alexander Steffen <Alexander.Steffen@infineon.com>
1 parent 719b7d8 commit a3fbfae

File tree

6 files changed

+40
-37
lines changed

6 files changed

+40
-37
lines changed

drivers/char/tpm/tpm-chip.c

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ static int tpm_request_locality(struct tpm_chip *chip, unsigned int flags)
4141
{
4242
int rc;
4343

44-
if (flags & TPM_TRANSMIT_NESTED)
45-
return 0;
46-
4744
if (!chip->ops->request_locality)
4845
return 0;
4946

@@ -59,9 +56,6 @@ static void tpm_relinquish_locality(struct tpm_chip *chip, unsigned int flags)
5956
{
6057
int rc;
6158

62-
if (flags & TPM_TRANSMIT_NESTED)
63-
return;
64-
6559
if (!chip->ops->relinquish_locality)
6660
return;
6761

@@ -74,9 +68,6 @@ static void tpm_relinquish_locality(struct tpm_chip *chip, unsigned int flags)
7468

7569
static int tpm_cmd_ready(struct tpm_chip *chip, unsigned int flags)
7670
{
77-
if (flags & TPM_TRANSMIT_NESTED)
78-
return 0;
79-
8071
if (!chip->ops->cmd_ready)
8172
return 0;
8273

@@ -85,9 +76,6 @@ static int tpm_cmd_ready(struct tpm_chip *chip, unsigned int flags)
8576

8677
static int tpm_go_idle(struct tpm_chip *chip, unsigned int flags)
8778
{
88-
if (flags & TPM_TRANSMIT_NESTED)
89-
return 0;
90-
9179
if (!chip->ops->go_idle)
9280
return 0;
9381

@@ -167,11 +155,17 @@ int tpm_try_get_ops(struct tpm_chip *chip)
167155

168156
down_read(&chip->ops_sem);
169157
if (!chip->ops)
170-
goto out_lock;
158+
goto out_ops;
171159

172160
mutex_lock(&chip->tpm_mutex);
161+
rc = tpm_chip_start(chip, 0);
162+
if (rc)
163+
goto out_lock;
164+
173165
return 0;
174166
out_lock:
167+
mutex_unlock(&chip->tpm_mutex);
168+
out_ops:
175169
up_read(&chip->ops_sem);
176170
put_device(&chip->dev);
177171
return rc;
@@ -187,6 +181,7 @@ EXPORT_SYMBOL_GPL(tpm_try_get_ops);
187181
*/
188182
void tpm_put_ops(struct tpm_chip *chip)
189183
{
184+
tpm_chip_stop(chip, 0);
190185
mutex_unlock(&chip->tpm_mutex);
191186
up_read(&chip->ops_sem);
192187
put_device(&chip->dev);
@@ -302,7 +297,10 @@ static int tpm_class_shutdown(struct device *dev)
302297

303298
if (chip->flags & TPM_CHIP_FLAG_TPM2) {
304299
down_write(&chip->ops_sem);
305-
tpm2_shutdown(chip, TPM2_SU_CLEAR);
300+
if (!tpm_chip_start(chip, 0)) {
301+
tpm2_shutdown(chip, TPM2_SU_CLEAR);
302+
tpm_chip_stop(chip, 0);
303+
}
306304
chip->ops = NULL;
307305
up_write(&chip->ops_sem);
308306
}
@@ -481,8 +479,12 @@ static void tpm_del_char_device(struct tpm_chip *chip)
481479

482480
/* Make the driver uncallable. */
483481
down_write(&chip->ops_sem);
484-
if (chip->flags & TPM_CHIP_FLAG_TPM2)
485-
tpm2_shutdown(chip, TPM2_SU_CLEAR);
482+
if (chip->flags & TPM_CHIP_FLAG_TPM2) {
483+
if (!tpm_chip_start(chip, 0)) {
484+
tpm2_shutdown(chip, TPM2_SU_CLEAR);
485+
tpm_chip_stop(chip, 0);
486+
}
487+
}
486488
chip->ops = NULL;
487489
up_write(&chip->ops_sem);
488490
}
@@ -564,7 +566,11 @@ int tpm_chip_register(struct tpm_chip *chip)
564566
{
565567
int rc;
566568

569+
rc = tpm_chip_start(chip, 0);
570+
if (rc)
571+
return rc;
567572
rc = tpm_auto_startup(chip);
573+
tpm_chip_stop(chip, 0);
568574
if (rc)
569575
return rc;
570576

drivers/char/tpm/tpm-interface.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,7 @@ ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
177177
memcpy(save, buf, save_size);
178178

179179
for (;;) {
180-
ret = tpm_chip_start(chip, flags);
181-
if (ret)
182-
return ret;
183-
184180
ret = tpm_try_transmit(chip, buf, bufsiz, flags);
185-
186-
tpm_chip_stop(chip, flags);
187181
if (ret < 0)
188182
break;
189183
rc = be32_to_cpu(header->return_code);
@@ -420,10 +414,16 @@ int tpm_pm_suspend(struct device *dev)
420414
if (chip->flags & TPM_CHIP_FLAG_ALWAYS_POWERED)
421415
return 0;
422416

423-
if (chip->flags & TPM_CHIP_FLAG_TPM2)
424-
tpm2_shutdown(chip, TPM2_SU_STATE);
425-
else
417+
if (chip->flags & TPM_CHIP_FLAG_TPM2) {
418+
mutex_lock(&chip->tpm_mutex);
419+
if (!tpm_chip_start(chip, 0)) {
420+
tpm2_shutdown(chip, TPM2_SU_STATE);
421+
tpm_chip_stop(chip, 0);
422+
}
423+
mutex_unlock(&chip->tpm_mutex);
424+
} else {
426425
rc = tpm1_pm_suspend(chip, tpm_suspend_pcr);
426+
}
427427

428428
return rc;
429429
}

drivers/char/tpm/tpm.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -485,15 +485,6 @@ extern const struct file_operations tpm_fops;
485485
extern const struct file_operations tpmrm_fops;
486486
extern struct idr dev_nums_idr;
487487

488-
/**
489-
* enum tpm_transmit_flags - flags for tpm_transmit()
490-
*
491-
* %TPM_TRANSMIT_NESTED: discard setup steps (power management, locality)
492-
*/
493-
enum tpm_transmit_flags {
494-
TPM_TRANSMIT_NESTED = BIT(0),
495-
};
496-
497488
ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
498489
unsigned int flags);
499490
ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_buf *buf,

drivers/char/tpm/tpm2-space.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ int tpm2_init_space(struct tpm_space *space)
6060
void tpm2_del_space(struct tpm_chip *chip, struct tpm_space *space)
6161
{
6262
mutex_lock(&chip->tpm_mutex);
63-
tpm2_flush_sessions(chip, space);
63+
if (!tpm_chip_start(chip, 0)) {
64+
tpm2_flush_sessions(chip, space);
65+
tpm_chip_stop(chip, 0);
66+
}
6467
mutex_unlock(&chip->tpm_mutex);
6568
kfree(space->context_buf);
6669
kfree(space->session_buf);

drivers/char/tpm/tpm_tis_core.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,11 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
916916
intmask &= ~TPM_GLOBAL_INT_ENABLE;
917917
tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask);
918918

919+
rc = tpm_chip_start(chip, 0);
920+
if (rc)
921+
goto out_err;
919922
rc = tpm2_probe(chip);
923+
tpm_chip_stop(chip, 0);
920924
if (rc)
921925
goto out_err;
922926

drivers/char/tpm/tpm_vtpm_proxy.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,7 @@ static int vtpm_proxy_request_locality(struct tpm_chip *chip, int locality)
416416

417417
proxy_dev->state |= STATE_DRIVER_COMMAND;
418418

419-
rc = tpm_transmit_cmd(chip, &buf, 0, TPM_TRANSMIT_NESTED,
420-
"attempting to set locality");
419+
rc = tpm_transmit_cmd(chip, &buf, 0, 0, "attempting to set locality");
421420

422421
proxy_dev->state &= ~STATE_DRIVER_COMMAND;
423422

0 commit comments

Comments
 (0)