Use tpm_transmit_cmd() consistently
v2 cover Use tpm_transmit_cmd() consistently
These commits update the subsystem consistently to use tpm_transmit_cmd() throughout the subsystem the exception being tpm_write() where it makes sense to use the raw interface because higher level command handling is delegated to user space.
v2: Added commit that drops externs from all function declarations in tpm.h as suggested by Jason Gunthorpe.
Jarkko Sakkinen (6):
tpm: remove unnecessary externs from tpm.h
tpm: unify tpm_gen_interrupt()
tpm: return error code from tpm_gen_interrupt()
tpm: use tpm_transmit_cmd() in tpm2_probe()
tpm: rename tpm_pcr_read_dev() to tpm1_pcr_read()
tpm: use tpm1_pcr_read() in tpm_do_selftest()
drivers/char/tpm/tpm-interface.c | 36 ++++++++++++++++++---------------- drivers/char/tpm/tpm-sysfs.c | 2 +- drivers/char/tpm/tpm.h | 42 +++++++++++++++++++--------------------- drivers/char/tpm/tpm2-cmd.c | 21 +------------------- drivers/char/tpm/tpm_tis_core.c | 7 +++---- 5 files changed, 44 insertions(+), 64 deletions(-)
Signature · 9 lines
2.7.4 ------------------------------------------------------------------------------ Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San Francisco, CA to explore cutting-edge tech and listen to tech luminaries present their vision of the future. This family event has something for everyone, including kids. Get more information and register today. http://sdm.link/attshape
PATCH v2 1/6 tpm: remove unnecessary externs from tpm.h
Removed unnecessary externs from tpm.h.
--- drivers/char/tpm/tpm.h | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-)
drivers/char/tpm/tpm.h +20 -20
@@ -482,25 +482,25 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf, size_t bufsiz);ssize_t tpm_transmit_cmd (struct tpm_chip *chip,void *cmd,int len,const char *desc); -extern int tpm_get_timeouts (struct tpm_chip *); -extern void tpm_gen_interrupt (struct tpm_chip *); -extern int tpm_do_selftest (struct tpm_chip *); -extern unsigned long tpm_calc_ordinal_duration (struct tpm_chip *,u32 ); -extern int tpm_pm_suspend (struct device *); -extern int tpm_pm_resume (struct device *); -extern int wait_for_tpm_stat (struct tpm_chip *,u8 ,unsigned long , -wait_queue_head_t *,bool ); +int tpm_get_timeouts (struct tpm_chip *chip); +void tpm_gen_interrupt (struct tpm_chip *chip); +int tpm_do_selftest (struct tpm_chip *chip); +unsigned long tpm_calc_ordinal_duration (struct tpm_chip *chip,u32 ordinal); +int tpm_pm_suspend (struct device *dev); +int tpm_pm_resume (struct device *dev); +int wait_for_tpm_stat (struct tpm_chip *chip,u8 mask,unsigned long timeout, +wait_queue_head_t *queue,bool check_cancel);struct tpm_chip *tpm_chip_find_get (int chip_num);__must_check int tpm_try_get_ops (struct tpm_chip *chip);void tpm_put_ops (struct tpm_chip *chip); -extern struct tpm_chip *tpm_chip_alloc (struct device *dev, -const struct tpm_class_ops *ops); -extern struct tpm_chip *tpmm_chip_alloc (struct device *pdev, -const struct tpm_class_ops *ops); -extern int tpm_chip_register (struct tpm_chip *chip); -extern void tpm_chip_unregister (struct tpm_chip *chip); +struct tpm_chip *tpm_chip_alloc (struct device *dev, +const struct tpm_class_ops *ops); +struct tpm_chip *tpmm_chip_alloc (struct device *pdev, +const struct tpm_class_ops *ops); +int tpm_chip_register (struct tpm_chip *chip); +void tpm_chip_unregister (struct tpm_chip *chip);void tpm_sysfs_add_device (struct tpm_chip *chip);
@@ -526,10 +526,10 @@ int tpm2_unseal_trusted(struct tpm_chip *chip,ssize_t tpm2_get_tpm_pt (struct tpm_chip *chip,u32 property_id,u32 *value,const char *desc); -extern int tpm2_startup (struct tpm_chip *chip,u16 startup_type); -extern void tpm2_shutdown (struct tpm_chip *chip,u16 shutdown_type); -extern unsigned long tpm2_calc_ordinal_duration (struct tpm_chip *,u32 ); -extern int tpm2_do_selftest (struct tpm_chip *chip); -extern int tpm2_gen_interrupt (struct tpm_chip *chip); -extern int tpm2_probe (struct tpm_chip *chip); +int tpm2_startup (struct tpm_chip *chip,u16 startup_type); +void tpm2_shutdown (struct tpm_chip *chip,u16 shutdown_type); +unsigned long tpm2_calc_ordinal_duration (struct tpm_chip *chip,u32 ordinal); +int tpm2_do_selftest (struct tpm_chip *chip); +int tpm2_gen_interrupt (struct tpm_chip *chip); +int tpm2_probe (struct tpm_chip *chip);#endif
Signature · 9 lines
2.7.4 ------------------------------------------------------------------------------ Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San Francisco, CA to explore cutting-edge tech and listen to tech luminaries present their vision of the future. This family event has something for everyone, including kids. Get more information and register today. http://sdm.link/attshape
PATCH v2 2/6 tpm: unify tpm_gen_interrupt()
In reply to Jarkko SakkinenMigrated into single tpm_gen_interrupt() function and cleaned up the whole construction in general because it was starting to turn into a train wreck.
--- drivers/char/tpm/tpm-interface.c | 23 ++++++++++++++--------- drivers/char/tpm/tpm.h | 2 -- drivers/char/tpm/tpm2-cmd.c | 17 ----------------- drivers/char/tpm/tpm_tis_core.c | 5 +---- 4 files changed, 15 insertions(+), 32 deletions(-)
drivers/char/tpm/tpm-interface.c +14 -9
@@ -459,18 +459,23 @@ ssize_t tpm_getcap(struct tpm_chip *chip, __be32 subcap_id, cap_t *cap,return rc; } +/** +* tpm_gen_interrupt -- generate an interrupt by issuing an idempotent command +* @chip: TPM chip to use +* +* Returns 0 on success, < 0 in case of fatal error or a value > 0 representing +* a TPM error code. +*/ void tpm_gen_interrupt (struct tpm_chip *chip) { -struct tpm_cmd_t tpm_cmd; -ssize_t rc; +const char *desc ="attempting to generate an interrupt" ; +u32 cap2; +cap_t cap; - tpm_cmd.header.in = tpm_getcap_header; - tpm_cmd.params.getcap_in.cap =TPM_CAP_PROP ; - tpm_cmd.params.getcap_in.subcap_size =cpu_to_be32 (4 ); - tpm_cmd.params.getcap_in.subcap =TPM_CAP_PROP_TIS_TIMEOUT ; - - rc =tpm_transmit_cmd (chip, &tpm_cmd,TPM_INTERNAL_RESULT_SIZE , -"attempting to determine the timeouts" ); +if (chip->flags &TPM_CHIP_FLAG_TPM2 ) +tpm2_get_tpm_pt (chip,0x100 , &cap2, desc); +else +tpm_getcap (chip,TPM_CAP_PROP_TIS_TIMEOUT , &cap, desc); }EXPORT_SYMBOL_GPL (tpm_gen_interrupt);
drivers/char/tpm/tpm.h +0 -2
@@ -525,11 +525,9 @@ int tpm2_unseal_trusted(struct tpm_chip *chip, struct trusted_key_options *options);ssize_t tpm2_get_tpm_pt (struct tpm_chip *chip,u32 property_id,u32 *value,const char *desc); -int tpm2_startup (struct tpm_chip *chip,u16 startup_type);void tpm2_shutdown (struct tpm_chip *chip,u16 shutdown_type);unsigned long tpm2_calc_ordinal_duration (struct tpm_chip *chip,u32 ordinal);int tpm2_do_selftest (struct tpm_chip *chip); -int tpm2_gen_interrupt (struct tpm_chip *chip);int tpm2_probe (struct tpm_chip *chip);#endif
drivers/char/tpm/tpm2-cmd.c +0 -17
@@ -897,23 +897,6 @@ int tpm2_do_selftest(struct tpm_chip *chip)EXPORT_SYMBOL_GPL (tpm2_do_selftest);/** -* tpm2_gen_interrupt() - generate an interrupt -* @chip: TPM chip to use -* -* 0 is returned when the operation is successful. If a negative number is -* returned it remarks a POSIX error code. If a positive number is returned -* it remarks a TPM error. -*/ -int tpm2_gen_interrupt (struct tpm_chip *chip) -{ -u32 dummy; - -return tpm2_get_tpm_pt (chip,0x100 , &dummy, -"attempting to generate an interrupt" ); -} -EXPORT_SYMBOL_GPL (tpm2_gen_interrupt); - -/** * tpm2_probe() - probe TPM 2.0 * @chip: TPM chip to use *
drivers/char/tpm/tpm_tis_core.c +1 -4
@@ -580,10 +580,7 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask,/* Generate an interrupt by having the core call through to * tpm_tis_send */ -if (chip->flags &TPM_CHIP_FLAG_TPM2 ) -tpm2_gen_interrupt (chip); -else -tpm_gen_interrupt (chip); +tpm_gen_interrupt (chip);/* tpm_tis_send will either confirm the interrupt is working or it * will call disable_irq which undoes all of the above.
Signature · 9 lines
2.7.4 ------------------------------------------------------------------------------ Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San Francisco, CA to explore cutting-edge tech and listen to tech luminaries present their vision of the future. This family event has something for everyone, including kids. Get more information and register today. http://sdm.link/attshape
PATCH v2 3/6 tpm: return error code from tpm_gen_interrupt()
In reply to Jarkko SakkinenReturn error code from tpm_gen_interrupt() and fail tpm_tis family of drivers on a system error. It doesn't make sense to continue if we cannot even reach the TPM.
--- drivers/char/tpm/tpm-interface.c | 6 +++--- drivers/char/tpm/tpm.h | 2 +- drivers/char/tpm/tpm_tis_core.c | 4 +++- 3 files changed, 7 insertions(+), 5 deletions(-)
drivers/char/tpm/tpm-interface.c +3 -3
@@ -466,16 +466,16 @@ ssize_t tpm_getcap(struct tpm_chip *chip, __be32 subcap_id, cap_t *cap,* Returns 0 on success, < 0 in case of fatal error or a value > 0 representing * a TPM error code. */ -void tpm_gen_interrupt (struct tpm_chip *chip) +int tpm_gen_interrupt (struct tpm_chip *chip) {const char *desc ="attempting to generate an interrupt" ;u32 cap2;cap_t cap;if (chip->flags &TPM_CHIP_FLAG_TPM2 ) -tpm2_get_tpm_pt (chip,0x100 , &cap2, desc); +return tpm2_get_tpm_pt (chip,0x100 , &cap2, desc);else -tpm_getcap (chip,TPM_CAP_PROP_TIS_TIMEOUT , &cap, desc); +return tpm_getcap (chip,TPM_CAP_PROP_TIS_TIMEOUT , &cap, desc); }EXPORT_SYMBOL_GPL (tpm_gen_interrupt);
drivers/char/tpm/tpm.h +1 -1
@@ -483,7 +483,7 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,ssize_t tpm_transmit_cmd (struct tpm_chip *chip,void *cmd,int len,const char *desc);int tpm_get_timeouts (struct tpm_chip *chip); -void tpm_gen_interrupt (struct tpm_chip *chip); +int tpm_gen_interrupt (struct tpm_chip *chip);int tpm_do_selftest (struct tpm_chip *chip);unsigned long tpm_calc_ordinal_duration (struct tpm_chip *chip,u32 ordinal);int tpm_pm_suspend (struct device *dev);
drivers/char/tpm/tpm_tis_core.c +3 -1
@@ -580,7 +580,9 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask,/* Generate an interrupt by having the core call through to * tpm_tis_send */ -tpm_gen_interrupt (chip); + rc =tpm_gen_interrupt (chip); +if (rc <0 ) +return rc;/* tpm_tis_send will either confirm the interrupt is working or it * will call disable_irq which undoes all of the above.
Signature · 9 lines
2.7.4 ------------------------------------------------------------------------------ Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San Francisco, CA to explore cutting-edge tech and listen to tech luminaries present their vision of the future. This family event has something for everyone, including kids. Get more information and register today. http://sdm.link/attshape
PATCH v2 4/6 tpm: use tpm_transmit_cmd() in tpm2_probe()
In reply to Jarkko SakkinenIt is better to tpm_transmit_cmd() in tpm2_probe() in order to get consistent command handling throughout the subsystem.
--- drivers/char/tpm/tpm2-cmd.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/char/tpm/tpm2-cmd.c +1 -3
@@ -913,11 +913,9 @@ int tpm2_probe(struct tpm_chip *chip) cmd.params.get_tpm_pt_in.property_id =cpu_to_be32 (0x100 ); cmd.params.get_tpm_pt_in.property_cnt =cpu_to_be32 (1 ); - rc =tpm_transmit (chip, (const char *) &cmd,sizeof (cmd)); + rc =tpm_transmit_cmd (chip, &cmd,sizeof (cmd),NULL );if (rc <0 )return rc; -else if (rc <TPM_HEADER_SIZE ) -return -EFAULT ;if (be16_to_cpu (cmd.header.out.tag) ==TPM2_ST_NO_SESSIONS ) chip->flags |=TPM_CHIP_FLAG_TPM2 ;
Signature · 9 lines
2.7.4 ------------------------------------------------------------------------------ Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San Francisco, CA to explore cutting-edge tech and listen to tech luminaries present their vision of the future. This family event has something for everyone, including kids. Get more information and register today. http://sdm.link/attshape
PATCH v2 5/6 tpm: rename tpm_pcr_read_dev() to tpm1_pcr_read()
In reply to Jarkko SakkinenGave more consistent name tpm1_pcr_read() as the TPM2 version is called tpm2_pcr_read().
--- drivers/char/tpm/tpm-interface.c | 4 ++-- drivers/char/tpm/tpm-sysfs.c | 2 +- drivers/char/tpm/tpm.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/char/tpm/tpm-interface.c +2 -2
@@ -670,7 +670,7 @@ static struct tpm_input_header pcrread_header = { .ordinal = TPM_ORDINAL_PCRREAD }; -int tpm_pcr_read_dev (struct tpm_chip *chip,int pcr_idx,u8 *res_buf) +int tpm1_pcr_read (struct tpm_chip *chip,int pcr_idx,u8 *res_buf) {int rc;struct tpm_cmd_t cmd;
@@ -732,7 +732,7 @@ int tpm_pcr_read(u32 chip_num, int pcr_idx, u8 *res_buf)if (chip->flags &TPM_CHIP_FLAG_TPM2 ) rc =tpm2_pcr_read (chip, pcr_idx, res_buf);else - rc =tpm_pcr_read_dev (chip, pcr_idx, res_buf); + rc =tpm1_pcr_read (chip, pcr_idx, res_buf);tpm_put_ops (chip);return rc; }
drivers/char/tpm/tpm-sysfs.c +1 -1
@@ -101,7 +101,7 @@ static ssize_t pcrs_show(struct device *dev, struct device_attribute *attr, num_pcrs =be32_to_cpu (cap.num_pcrs);for (i =0 ; i < num_pcrs; i++) { - rc =tpm_pcr_read_dev (chip, i, digest); + rc =tpm1_pcr_read (chip, i, digest);if (rc)break ; str +=sprintf (str,"PCR-%02d: " , i);
drivers/char/tpm/tpm.h +1 -1
@@ -504,7 +504,7 @@ void tpm_chip_unregister(struct tpm_chip *chip);void tpm_sysfs_add_device (struct tpm_chip *chip); -int tpm_pcr_read_dev (struct tpm_chip *chip,int pcr_idx,u8 *res_buf); +int tpm1_pcr_read (struct tpm_chip *chip,int pcr_idx,u8 *res_buf);#ifdef CONFIG_ACPI extern void tpm_add_ppi (struct tpm_chip *chip);
Signature · 9 lines
2.7.4 ------------------------------------------------------------------------------ Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San Francisco, CA to explore cutting-edge tech and listen to tech luminaries present their vision of the future. This family event has something for everyone, including kids. Get more information and register today. http://sdm.link/attshape
PATCH v2 6/6 tpm: use tpm1_pcr_read() in tpm_do_selftest()
In reply to Jarkko SakkinenRemove ad-hoc protocol message construction and call instead tpm1_pcr_read().
--- drivers/char/tpm/tpm-interface.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/char/tpm/tpm-interface.c +2 -5
@@ -797,7 +797,7 @@ int tpm_do_selftest(struct tpm_chip *chip)unsigned int loops;unsigned int delay_msec =100 ;unsigned long duration; -struct tpm_cmd_t cmd; +u8 dummy[TPM_DIGEST_SIZE ]; duration =tpm_calc_ordinal_duration (chip,TPM_ORD_CONTINUE_SELFTEST );
@@ -812,9 +812,7 @@ int tpm_do_selftest(struct tpm_chip *chip) do { /* Attempt to read a PCR value */ - cmd.header.in = pcrread_header; - cmd.params.pcrread_in.pcr_idx = cpu_to_be32(0); - rc = tpm_transmit(chip, (u8 *) &cmd, READ_PCR_RESULT_SIZE); + rc = tpm1_pcr_read(chip, 0, dummy); /* Some buggy TPMs will not respond to tpm_tis_ready() for * around 300ms while the self test is ongoing, keep trying * until the self test duration expires. */
@@ -829,7 +827,6 @@ int tpm_do_selftest(struct tpm_chip *chip)if (rc <TPM_HEADER_SIZE )return -EFAULT ; - rc =be32_to_cpu (cmd.header.out.return_code);if (rc ==TPM_ERR_DISABLED || rc ==TPM_ERR_DEACTIVATED ) {dev_info (&chip->dev,"TPM is disabled/deactivated (0x%X)\n" , rc);
Signature · 9 lines
2.7.4 ------------------------------------------------------------------------------ Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San Francisco, CA to explore cutting-edge tech and listen to tech luminaries present their vision of the future. This family event has something for everyone, including kids. Get more information and register today. http://sdm.link/attshape
Pending for reviews. These are quite trivial patches.
/Jarkko
Quoted 16 lines · Jarkko Sakkinen
These commits update the subsystem consistently to use
tpm_transmit_cmd()throughout the subsystem the exception beingtpm_write()where it makes sense to use the raw interface because higher level command handling is delegated to user space.v2: Added commit that drops externs from all function declarations in
tpm.has suggested by Jason Gunthorpe.Jarkko Sakkinen (6):
tpm: remove unnecessary externs fromtpm.h
tpm: unifytpm_gen_interrupt()
tpm: return error code fromtpm_gen_interrupt()
tpm: usetpm_transmit_cmd()intpm2_probe()
tpm: renametpm_pcr_read_dev()totpm1_pcr_read()
tpm: usetpm1_pcr_read()intpm_do_selftest()
Quoted 10 lines
drivers/char/tpm/tpm-interface.c | 36 ++++++++++++++++++---------------- drivers/char/tpm/tpm-sysfs.c | 2 +- drivers/char/tpm/tpm.h | 42 +++++++++++++++++++--------------------- drivers/char/tpm/tpm2-cmd.c | 21 +------------------- drivers/char/tpm/tpm_tis_core.c | 7 +++---- 5 files changed, 44 insertions(+), 64 deletions(-)Signature · 1 line
2.7.4
------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San Francisco, CA to explore cutting-edge tech and listen to tech luminaries present their vision of the future. This family event has something for everyone, including kids. Get more information and register today.
http://sdm.link/attshape
Quoted 12 lines · Jarkko Sakkinen
Pending for reviews. These are quite trivial patches.
/Jarkko
Quoted 7 lines · Jarkko Sakkinen
These commits update the subsystem consistently to use
tpm_transmit_cmd()throughout the subsystem the exception beingtpm_write()where it makes sense to use the raw interface because higher level command handling is delegated to user space.v2: Added commit that drops externs from all function declarations in
tpm.has suggested by Jason Gunthorpe.
Jason, do you think I could apply these to master or do you see anything wrong in them?
/Jarkko
Quoted 29 lines
Quoted 8 lines
Jarkko Sakkinen (6):
tpm: remove unnecessary externs fromtpm.h
tpm: unifytpm_gen_interrupt()
tpm: return error code fromtpm_gen_interrupt()
tpm: usetpm_transmit_cmd()intpm2_probe()
tpm: renametpm_pcr_read_dev()totpm1_pcr_read()
tpm: usetpm1_pcr_read()intpm_do_selftest()Quoted 10 lines
drivers/char/tpm/tpm-interface.c | 36 ++++++++++++++++++---------------- drivers/char/tpm/tpm-sysfs.c | 2 +- drivers/char/tpm/tpm.h | 42 +++++++++++++++++++--------------------- drivers/char/tpm/tpm2-cmd.c | 21 +------------------- drivers/char/tpm/tpm_tis_core.c | 7 +++---- 5 files changed, 44 insertions(+), 64 deletions(-)Signature · 1 line
2.7.4------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San Francisco, CA to explore cutting-edge tech and listen to tech luminaries present their vision of the future. This family event has something for everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
tpmdd-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel