Extend TPM PPI interface to support revision 1.3
Subsystems (3)
v2 cover Extend TPM PPI interface to support revision 1.3
This series of patches extends the TPM subsystem's PPI support to support TPM PPI revision 1.3 where more commands are supported (up to 101) and the TPM 2 command code '23' takes an additional parameter.
For the command code '23' see this document here on document page 39:
https://trustedcomputinggroup.org/wp-content/uploads/Physical-Presence-Interface_1-30_0-52.pdf
Stefan
v1->v2:
- reformatted badly aligned code
- changed TPM_PPI_REVISION_1 to TPM_PPI_REVISION_ID_1
- Added R-b's and T-b's
Stefan Berger (5):
tpm: ppi: pass function revision ID to tpm_eval_dsm()
tpm: ppi: rename TPM_PPI_REVISION_ID to TPM_PPI_REVISION_ID_1
tpm: ppi: Display up to 101 operations as define for version 1.3
tpm: ppi: Possibly show command parameter if TPM PPI 1.3 is used
tpm: ppi: Enable submission of optional command parameter for PPI 1.3
drivers/char/tpm/tpm_ppi.c | 78 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 58 insertions(+), 20 deletions(-)
Signature · 1 line
2.13.6
PATCH v2 1/5 tpm: ppi: pass function revision ID to tpm_eval_dsm()
Since we will need to pass different function revision numbers to tpm_eval_dsm, convert this function now to take the function revision as an additional parameter.
--- drivers/char/tpm/tpm_ppi.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/char/tpm/tpm_ppi.c +8 -8
@@ -38,12 +38,11 @@ static const guid_t tpm_ppi_guid =static inline union acpi_object *tpm_eval_dsm (acpi_handle ppi_handle,int func,acpi_object_type type, -union acpi_object *argv4) +union acpi_object *argv4,u64 rev) {BUG_ON (!ppi_handle);return acpi_evaluate_dsm_typed (ppi_handle, &tpm_ppi_guid, -TPM_PPI_REVISION_ID , - func, argv4, type); + rev, func, argv4, type); } static ssize_t tpm_show_ppi_version(struct device *dev,
@@ -62,7 +61,7 @@ static ssize_t tpm_show_ppi_request(struct device *dev,struct tpm_chip *chip =to_tpm_chip (dev); obj =tpm_eval_dsm (chip->acpi_dev_handle,TPM_PPI_FN_GETREQ , -ACPI_TYPE_PACKAGE ,NULL ); +ACPI_TYPE_PACKAGE ,NULL ,TPM_PPI_REVISION_ID );if (!obj)return -ENXIO ;
@@ -126,7 +125,7 @@ static ssize_t tpm_store_ppi_request(struct device *dev, } obj =tpm_eval_dsm (chip->acpi_dev_handle, func,ACPI_TYPE_INTEGER , - &argv4); + &argv4,TPM_PPI_REVISION_ID );if (!obj) {return -ENXIO ; }else {
@@ -170,7 +169,7 @@ static ssize_t tpm_show_ppi_transition_action(struct device *dev,if (strcmp (chip->ppi_version,"1.2" ) <0 ) obj = &tmp; obj =tpm_eval_dsm (chip->acpi_dev_handle,TPM_PPI_FN_GETACT , -ACPI_TYPE_INTEGER , obj); +ACPI_TYPE_INTEGER , obj,TPM_PPI_REVISION_ID );if (!obj) {return -ENXIO ; }else {
@@ -196,7 +195,7 @@ static ssize_t tpm_show_ppi_response(struct device *dev,struct tpm_chip *chip =to_tpm_chip (dev); obj =tpm_eval_dsm (chip->acpi_dev_handle,TPM_PPI_FN_GETRSP , -ACPI_TYPE_PACKAGE ,NULL ); +ACPI_TYPE_PACKAGE ,NULL ,TPM_PPI_REVISION_ID );if (!obj)return -ENXIO ;
@@ -272,7 +271,8 @@ static ssize_t show_ppi_operations(acpi_handle dev_handle, char *buf, u32 start,for (i = start; i <= end; i++) { tmp.integer.value = i; obj =tpm_eval_dsm (dev_handle,TPM_PPI_FN_GETOPR , -ACPI_TYPE_INTEGER , &argv); +ACPI_TYPE_INTEGER , &argv, +TPM_PPI_REVISION_ID );if (!obj) {return -ENOMEM ; }else {
Signature · 1 line
2.13.6
PATCH v2 2/5 tpm: ppi: rename TPM_PPI_REVISION_ID to TPM_PPI_REVISION_ID_1
In reply to Stefan BergerTPM PPI 1.3 introduces a function revision 2 for some functions. So, rename the existing TPM_PPI_REVISION_ID to TPM_PPI_REVISION_ID_1.
--- drivers/char/tpm/tpm_ppi.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
drivers/char/tpm/tpm_ppi.c +11 -10
@@ -20,7 +20,7 @@#include <linux/acpi.h> #include "tpm.h" -#define TPM_PPI_REVISION_ID 1 +#define TPM_PPI_REVISION_ID_1 1#define TPM_PPI_FN_VERSION 1#define TPM_PPI_FN_SUBREQ 2#define TPM_PPI_FN_GETREQ 3
@@ -61,7 +61,7 @@ static ssize_t tpm_show_ppi_request(struct device *dev,struct tpm_chip *chip =to_tpm_chip (dev); obj =tpm_eval_dsm (chip->acpi_dev_handle,TPM_PPI_FN_GETREQ , -ACPI_TYPE_PACKAGE ,NULL ,TPM_PPI_REVISION_ID ); +ACPI_TYPE_PACKAGE ,NULL ,TPM_PPI_REVISION_ID_1 );if (!obj)return -ENXIO ;
@@ -103,7 +103,7 @@ static ssize_t tpm_store_ppi_request(struct device *dev,* version 1.1 */ if (acpi_check_dsm (chip->acpi_dev_handle, &tpm_ppi_guid, -TPM_PPI_REVISION_ID ,1 <<TPM_PPI_FN_SUBREQ2 )) +TPM_PPI_REVISION_ID_1 ,1 <<TPM_PPI_FN_SUBREQ2 )) func =TPM_PPI_FN_SUBREQ2 ;/*
@@ -125,7 +125,7 @@ static ssize_t tpm_store_ppi_request(struct device *dev, } obj =tpm_eval_dsm (chip->acpi_dev_handle, func,ACPI_TYPE_INTEGER , - &argv4,TPM_PPI_REVISION_ID ); + &argv4,TPM_PPI_REVISION_ID_1 );if (!obj) {return -ENXIO ; }else {
@@ -169,7 +169,7 @@ static ssize_t tpm_show_ppi_transition_action(struct device *dev,if (strcmp (chip->ppi_version,"1.2" ) <0 ) obj = &tmp; obj =tpm_eval_dsm (chip->acpi_dev_handle,TPM_PPI_FN_GETACT , -ACPI_TYPE_INTEGER , obj,TPM_PPI_REVISION_ID ); +ACPI_TYPE_INTEGER , obj,TPM_PPI_REVISION_ID_1 );if (!obj) {return -ENXIO ; }else {
@@ -195,7 +195,7 @@ static ssize_t tpm_show_ppi_response(struct device *dev,struct tpm_chip *chip =to_tpm_chip (dev); obj =tpm_eval_dsm (chip->acpi_dev_handle,TPM_PPI_FN_GETRSP , -ACPI_TYPE_PACKAGE ,NULL ,TPM_PPI_REVISION_ID ); +ACPI_TYPE_PACKAGE ,NULL ,TPM_PPI_REVISION_ID_1 );if (!obj)return -ENXIO ;
@@ -263,7 +263,7 @@ static ssize_t show_ppi_operations(acpi_handle dev_handle, char *buf, u32 start, "User not required", }; -if (!acpi_check_dsm (dev_handle, &tpm_ppi_guid,TPM_PPI_REVISION_ID , +if (!acpi_check_dsm (dev_handle, &tpm_ppi_guid,TPM_PPI_REVISION_ID_1 ,1 <<TPM_PPI_FN_GETOPR ))return -EPERM ;
@@ -272,7 +272,7 @@ static ssize_t show_ppi_operations(acpi_handle dev_handle, char *buf, u32 start, tmp.integer.value = i; obj =tpm_eval_dsm (dev_handle,TPM_PPI_FN_GETOPR ,ACPI_TYPE_INTEGER , &argv, -TPM_PPI_REVISION_ID ); +TPM_PPI_REVISION_ID_1 );if (!obj) {return -ENOMEM ; }else {
@@ -338,12 +338,13 @@ void tpm_add_ppi(struct tpm_chip *chip)return ;if (!acpi_check_dsm (chip->acpi_dev_handle, &tpm_ppi_guid, -TPM_PPI_REVISION_ID ,1 <<TPM_PPI_FN_VERSION )) +TPM_PPI_REVISION_ID_1 ,1 <<TPM_PPI_FN_VERSION ))return ;/* Cache PPI version string. */ obj =acpi_evaluate_dsm_typed (chip->acpi_dev_handle, &tpm_ppi_guid, -TPM_PPI_REVISION_ID ,TPM_PPI_FN_VERSION , +TPM_PPI_REVISION_ID_1 , +TPM_PPI_FN_VERSION ,NULL ,ACPI_TYPE_STRING );if (obj) { strlcpy(chip->ppi_version, obj->string.pointer,
Signature · 1 line
2.13.6
Re: [PATCH v2 2/5] tpm: ppi: rename TPM_PPI_REVISION_ID to TPM_PPI_REVISION_ID_1
Quoted 5 lines · Stefan Berger
TPM PPI 1.3 introduces a function revision 2 for some functions. So, rename the existing
TPM_PPI_REVISION_IDtoTPM_PPI_REVISION_ID_1.Signed-off-by Stefan Berger <[email protected]>Tested-by David Safford <[email protected]>
/Jarkko
PATCH v2 3/5 tpm: ppi: Display up to 101 operations as define for version 1.3
In reply to Stefan BergerTPM PPI 1.3 defines operations up to number 101. We need to query up to this number to show the user what the firmware implements.
--- drivers/char/tpm/tpm_ppi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/tpm/tpm_ppi.c +1 -1
@@ -28,7 +28,7 @@#define TPM_PPI_FN_GETRSP 5#define TPM_PPI_FN_SUBREQ2 7#define TPM_PPI_FN_GETOPR 8 -#define PPI_TPM_REQ_MAX 22 +#define PPI_TPM_REQ_MAX 101/* PPI 1.3 for TPM 2 */ #define PPI_VS_REQ_START 128#define PPI_VS_REQ_END 255
Signature · 1 line
2.13.6
PATCH v2 4/5 tpm: ppi: Possibly show command parameter if TPM PPI 1.3 is used
In reply to Stefan BergerTPM PPI 1.3 introduces an additional optional command parameter that may be needed for some commands. Display the parameter if the command requires such a parameter. Only command 23 needs one.
The PPI request file will show output like this then:
# echo "23 16" > request # cat request 23 16
# echo "5" > request # cat request 5
--- drivers/char/tpm/tpm_ppi.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-)
drivers/char/tpm/tpm_ppi.c +29 -2
@@ -21,6 +21,7 @@#include "tpm.h" #define TPM_PPI_REVISION_ID_1 1 +#define TPM_PPI_REVISION_ID_2 2#define TPM_PPI_FN_VERSION 1#define TPM_PPI_FN_SUBREQ 2#define TPM_PPI_FN_GETREQ 3
@@ -36,6 +37,11 @@ static const guid_t tpm_ppi_guid =GUID_INIT (0x3DDDFAA6 ,0x361B ,0x4EB4 ,0xA4 ,0x24 ,0x8D ,0x10 ,0x08 ,0x9D ,0x16 ,0x53 ); +static bool tpm_ppi_req_has_parameter (u64 req) +{ +return req ==23 ; +} +static inline union acpi_object *tpm_eval_dsm (acpi_handle ppi_handle,int func,acpi_object_type type,union acpi_object *argv4,u64 rev)
@@ -59,9 +65,14 @@ static ssize_t tpm_show_ppi_request(struct device *dev,ssize_t size = -EINVAL ;union acpi_object *obj;struct tpm_chip *chip =to_tpm_chip (dev); +u64 rev =TPM_PPI_REVISION_ID_2 ; +u64 req; + +if (strcmp (chip->ppi_version,"1.2" ) <0 ) + rev =TPM_PPI_REVISION_ID_1 ; obj =tpm_eval_dsm (chip->acpi_dev_handle,TPM_PPI_FN_GETREQ , -ACPI_TYPE_PACKAGE ,NULL ,TPM_PPI_REVISION_ID_1 ); +ACPI_TYPE_PACKAGE ,NULL , rev);if (!obj)return -ENXIO ;
@@ -71,7 +82,23 @@ static ssize_t tpm_show_ppi_request(struct device *dev,* error. The second is pending TPM operation requested by the OS, 0 * means none and >0 means operation value. */ -if (obj->package.count ==2 && +if (obj->package.count ==3 && + obj->package.elements[0 ].type ==ACPI_TYPE_INTEGER && + obj->package.elements[1 ].type ==ACPI_TYPE_INTEGER && + obj->package.elements[2 ].type ==ACPI_TYPE_INTEGER ) { +if (obj->package.elements[0 ].integer.value) + size = -EFAULT ; +else { + req = obj->package.elements[1 ].integer.value; +if (tpm_ppi_req_has_parameter (req)) + size =scnprintf (buf,PAGE_SIZE , +"%llu %llu\n" , req, + obj->package.elements[2 ].integer.value); +else + size =scnprintf (buf,PAGE_SIZE , +"%llu\n" , req); + } + }else if (obj->package.count ==2 && obj->package.elements[0 ].type ==ACPI_TYPE_INTEGER && obj->package.elements[1 ].type ==ACPI_TYPE_INTEGER ) {if (obj->package.elements[0 ].integer.value)
Signature · 1 line
2.13.6
Re: [PATCH v2 4/5] tpm: ppi: Possibly show command parameter if TPM PPI 1.3 is used
Quoted 10 lines · Stefan Berger
TPM PPI 1.3 introduces an additional optional command parameter that may be needed for some commands. Display the parameter if the command requires such a parameter. Only command 23 needs one.
The PPI request file will show output like this then:
# echo "23 16" > request # cat request 23 16
Quoted 6 lines
# echo "5" > request # cat request 5Signed-off-by Stefan Berger <[email protected]>Tested-by David Safford <[email protected]>
/Jarkko
PATCH v2 5/5 tpm: ppi: Enable submission of optional command parameter for PPI 1.3
In reply to Stefan BergerThis patch enables a user to specify the additional optional command parameter by writing it into the request file:
# echo "23 16" > request # cat request 23 16
For backwards compatibility:
If only 1 parameter is given then we assume this is the operation request number.
# echo "5" > request # cat request 5
--- drivers/char/tpm/tpm_ppi.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
drivers/char/tpm/tpm_ppi.c +16 -6
@@ -120,9 +120,10 @@ static ssize_t tpm_store_ppi_request(struct device *dev,u32 req;u64 ret;int func =TPM_PPI_FN_SUBREQ ; -union acpi_object *obj, tmp; -union acpi_object argv4 =ACPI_INIT_DSM_ARGV4 (1 , &tmp); +union acpi_object *obj, tmp[2 ]; +union acpi_object argv4 =ACPI_INIT_DSM_ARGV4 (2 , tmp);struct tpm_chip *chip =to_tpm_chip (dev); +u64 rev =TPM_PPI_REVISION_ID_1 ;/* * the function to submit TPM operation request to pre-os environment
@@ -139,20 +140,29 @@ static ssize_t tpm_store_ppi_request(struct device *dev,* string/package type. For PPI version 1.0 and 1.1, use buffer type * for compatibility, and use package type since 1.2 according to spec. */ -if (strcmp (chip->ppi_version,"1.2" ) <0 ) { +if (strcmp (chip->ppi_version,"1.3" ) ==0 ) { +if (sscanf (buf,"%llu %llu" , &tmp[0 ].integer.value, + &tmp[1 ].integer.value) !=2 ) + goto ppi12; + rev =TPM_PPI_REVISION_ID_2 ; + tmp[0 ].type =ACPI_TYPE_INTEGER ; + tmp[1 ].type =ACPI_TYPE_INTEGER ; + }else if (strcmp (chip->ppi_version,"1.2" ) <0 ) {if (sscanf (buf,"%d" , &req) !=1 )return -EINVAL ; argv4.type =ACPI_TYPE_BUFFER ; argv4.buffer.length =sizeof (req); argv4.buffer.pointer = (u8 *)&req; }else { - tmp.type =ACPI_TYPE_INTEGER ; -if (sscanf (buf,"%llu" , &tmp.integer.value) !=1 ) +ppi12: + argv4.package.count =1 ; + tmp[0 ].type =ACPI_TYPE_INTEGER ; +if (sscanf (buf,"%llu" , &tmp[0 ].integer.value) !=1 )return -EINVAL ; } obj =tpm_eval_dsm (chip->acpi_dev_handle, func,ACPI_TYPE_INTEGER , - &argv4,TPM_PPI_REVISION_ID_1 ); + &argv4, rev);if (!obj) {return -ENXIO ; }else {
Signature · 1 line
2.13.6
Re: [PATCH v2 5/5] tpm: ppi: Enable submission of optional command parameter for PPI 1.3
Quoted 12 lines · Stefan Berger
This patch enables a user to specify the additional optional command parameter by writing it into the request file:
# echo "23 16" > request # cat request 23 16For backwards compatibility:
If only 1 parameter is given then we assume this is the operation request number.
Quoted 6 lines
# echo "5" > request # cat request 5Signed-off-by Stefan Berger <[email protected]>Tested-by David Safford <[email protected]>
/Jarkko
Re: [PATCH v2 5/5] tpm: ppi: Enable submission of optional command parameter for PPI 1.3
Quoted 13 lines · Jarkko Sakkinen
Quoted 12 lines · Stefan Berger
This patch enables a user to specify the additional optional command parameter by writing it into the request file:
# echo "23 16" > request # cat request 23 16For backwards compatibility:
If only 1 parameter is given then we assume this is the operation request number.
Quoted 8 lines
Quoted 6 lines
# echo "5" > request # cat request 5Signed-off-by Stefan Berger <[email protected]>Tested-by David Safford <[email protected]>Reviewed-by Jarkko Sakkinen <[email protected]>
Oops, sorry, this was meant for 4/5, so please ignore that.
The goto statement in tpm_store_ppi_request() is a bit messy as you jump between branches. Definitely works, but very unreadable.
To get around it, you could change the branching as
if (strcmp(chip->ppi_version, "1.3") == 0 &&
sscanf(buf, "%llu %llu", &tmp[0].integer.value,
&tmp[1].integer.value) == 2) {
/* ... */
} else if (strcmp(chip->ppi_version, "1.2") == 0) {
/* ... */
} else {
/* ... */
}/Jarkko