Skip to content

Commit 9db7fe1

Browse files
Tomas WinklerJarkko Sakkinen
authored andcommitted
tpm: factor out tpm_startup function
TPM manual startup is used only from within TPM 1.x or TPM 2.x code, hence remove tpm_startup() function from tpm-interface.c and add two static functions implementations tpm1_startup() and tpm2_startup() into to tpm1-cmd.c and tpm2-cmd.c respectively. Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
1 parent c82a330 commit 9db7fe1

4 files changed

Lines changed: 68 additions & 45 deletions

File tree

‎drivers/char/tpm/tpm-interface.c‎

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -413,47 +413,6 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_space *space,
413413
}
414414
EXPORT_SYMBOL_GPL(tpm_transmit_cmd);
415415

416-
#define TPM_ORD_STARTUP 153
417-
#define TPM_ST_CLEAR 1
418-
419-
/**
420-
* tpm_startup - turn on the TPM
421-
* @chip: TPM chip to use
422-
*
423-
* Normally the firmware should start the TPM. This function is provided as a
424-
* workaround if this does not happen. A legal case for this could be for
425-
* example when a TPM emulator is used.
426-
*
427-
* Return: same as tpm_transmit_cmd()
428-
*/
429-
int tpm_startup(struct tpm_chip *chip)
430-
{
431-
struct tpm_buf buf;
432-
int rc;
433-
434-
dev_info(&chip->dev, "starting up the TPM manually\n");
435-
436-
if (chip->flags & TPM_CHIP_FLAG_TPM2) {
437-
rc = tpm_buf_init(&buf, TPM2_ST_NO_SESSIONS, TPM2_CC_STARTUP);
438-
if (rc < 0)
439-
return rc;
440-
441-
tpm_buf_append_u16(&buf, TPM2_SU_CLEAR);
442-
} else {
443-
rc = tpm_buf_init(&buf, TPM_TAG_RQU_COMMAND, TPM_ORD_STARTUP);
444-
if (rc < 0)
445-
return rc;
446-
447-
tpm_buf_append_u16(&buf, TPM_ST_CLEAR);
448-
}
449-
450-
rc = tpm_transmit_cmd(chip, NULL, buf.data, PAGE_SIZE, 0, 0,
451-
"attempting to start the TPM");
452-
453-
tpm_buf_destroy(&buf);
454-
return rc;
455-
}
456-
457416
int tpm_get_timeouts(struct tpm_chip *chip)
458417
{
459418
if (chip->flags & TPM_CHIP_FLAG_HAVE_TIMEOUTS)

‎drivers/char/tpm/tpm.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,6 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_space *space,
540540
void *buf, size_t bufsiz,
541541
size_t min_rsp_body_length, unsigned int flags,
542542
const char *desc);
543-
int tpm_startup(struct tpm_chip *chip);
544543
int tpm_get_timeouts(struct tpm_chip *);
545544

546545
int tpm1_pm_suspend(struct tpm_chip *chip, int tpm_suspend_pcr);

‎drivers/char/tpm/tpm1-cmd.c‎

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,40 @@ unsigned long tpm1_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal)
308308
return duration;
309309
}
310310

311+
#define TPM_ORD_STARTUP 153
312+
#define TPM_ST_CLEAR 1
313+
314+
/**
315+
* tpm_startup() - turn on the TPM
316+
* @chip: TPM chip to use
317+
*
318+
* Normally the firmware should start the TPM. This function is provided as a
319+
* workaround if this does not happen. A legal case for this could be for
320+
* example when a TPM emulator is used.
321+
*
322+
* Return: same as tpm_transmit_cmd()
323+
*/
324+
static int tpm1_startup(struct tpm_chip *chip)
325+
{
326+
struct tpm_buf buf;
327+
int rc;
328+
329+
dev_info(&chip->dev, "starting up the TPM manually\n");
330+
331+
rc = tpm_buf_init(&buf, TPM_TAG_RQU_COMMAND, TPM_ORD_STARTUP);
332+
if (rc < 0)
333+
return rc;
334+
335+
tpm_buf_append_u16(&buf, TPM_ST_CLEAR);
336+
337+
rc = tpm_transmit_cmd(chip, NULL, buf.data, PAGE_SIZE, 0, 0,
338+
"attempting to start the TPM");
339+
340+
tpm_buf_destroy(&buf);
341+
342+
return rc;
343+
}
344+
311345
int tpm1_get_timeouts(struct tpm_chip *chip)
312346
{
313347
cap_t cap;
@@ -317,7 +351,7 @@ int tpm1_get_timeouts(struct tpm_chip *chip)
317351
rc = tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, NULL,
318352
sizeof(cap.timeout));
319353
if (rc == TPM_ERR_INVALID_POSTINIT) {
320-
if (tpm_startup(chip))
354+
if (tpm1_startup(chip))
321355
return rc;
322356

323357
rc = tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap,
@@ -727,3 +761,4 @@ int tpm1_pm_suspend(struct tpm_chip *chip, int tpm_suspend_pcr)
727761

728762
return rc;
729763
}
764+

‎drivers/char/tpm/tpm2-cmd.c‎

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,36 @@ static int tpm2_get_cc_attrs_tbl(struct tpm_chip *chip)
948948
return rc;
949949
}
950950

951+
/**
952+
* tpm2_startup - turn on the TPM
953+
* @chip: TPM chip to use
954+
*
955+
* Normally the firmware should start the TPM. This function is provided as a
956+
* workaround if this does not happen. A legal case for this could be for
957+
* example when a TPM emulator is used.
958+
*
959+
* Return: same as tpm_transmit_cmd()
960+
*/
961+
962+
static int tpm2_startup(struct tpm_chip *chip)
963+
{
964+
struct tpm_buf buf;
965+
int rc;
966+
967+
dev_info(&chip->dev, "starting up the TPM manually\n");
968+
969+
rc = tpm_buf_init(&buf, TPM2_ST_NO_SESSIONS, TPM2_CC_STARTUP);
970+
if (rc < 0)
971+
return rc;
972+
973+
tpm_buf_append_u16(&buf, TPM2_SU_CLEAR);
974+
rc = tpm_transmit_cmd(chip, NULL, buf.data, PAGE_SIZE, 0, 0,
975+
"attempting to start the TPM");
976+
tpm_buf_destroy(&buf);
977+
978+
return rc;
979+
}
980+
951981
/**
952982
* tpm2_auto_startup - Perform the standard automatic TPM initialization
953983
* sequence
@@ -959,7 +989,7 @@ int tpm2_auto_startup(struct tpm_chip *chip)
959989
{
960990
int rc;
961991

962-
rc = tpm_get_timeouts(chip);
992+
rc = tpm2_get_timeouts(chip);
963993
if (rc)
964994
goto out;
965995

@@ -968,7 +998,7 @@ int tpm2_auto_startup(struct tpm_chip *chip)
968998
goto out;
969999

9701000
if (rc == TPM2_RC_INITIALIZE) {
971-
rc = tpm_startup(chip);
1001+
rc = tpm2_startup(chip);
9721002
if (rc)
9731003
goto out;
9741004

0 commit comments

Comments
 (0)