[tpmdd-devel,2/3] tpm: Add start method for ARM Secure Monitor Call

Submitted by Jiandi An on March 10, 2017, 9:58 a.m.

Details

Message ID 1489139889-14376-3-git-send-email-anjiandi@codeaurora.org
State New
Headers show

Commit Message

Jiandi An March 10, 2017, 9:58 a.m.
Add a TPM Command Response Buffer start method that invokes
a secure Monitor Call to request the firmware to execute or
cancel a TPM 2.0 command for ARM64.

Signed-off-by: Jiandi An <anjiandi@codeaurora.org>
---
 drivers/char/tpm/tpm.h | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

Comments

Jason Gunthorpe March 10, 2017, 5 p.m.
On Fri, Mar 10, 2017 at 03:58:08AM -0600, Jiandi An wrote:

> +/*
> + * This is a TPM Command Response Buffer start method that invokes a
> + * Secure Monitor Call to requrest the firmware to execute or cancel
> + * a TPM 2.0 command.
> + */
> +static inline int tpm_crb_smc_start(unsigned long func_id)
> +{
> +	struct arm_smccc_res res;
> +
> +	arm_smccc_smc(func_id, 0, 0, 0, 0, 0, 0, 0, &res);
> +	if (res.a0 != 0) {
> +		WARN(1, "tpm_crb_smc_start() returns res.a0 = 0x%lx\n", res.a0);
> +		return -EIO;

I don't think either of these WARN's are appropriate.

'dev_err(FIRMWARE_BUG'  would be better.

Jason

------------------------------------------------------------------------------
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford
Jiandi An March 11, 2017, 12:44 a.m.
On 03/10/17 11:00, Jason Gunthorpe wrote:
> On Fri, Mar 10, 2017 at 03:58:08AM -0600, Jiandi An wrote:
>
>> +/*
>> + * This is a TPM Command Response Buffer start method that invokes a
>> + * Secure Monitor Call to requrest the firmware to execute or cancel
>> + * a TPM 2.0 command.
>> + */
>> +static inline int tpm_crb_smc_start(unsigned long func_id)
>> +{
>> +	struct arm_smccc_res res;
>> +
>> +	arm_smccc_smc(func_id, 0, 0, 0, 0, 0, 0, 0, &res);
>> +	if (res.a0 != 0) {
>> +		WARN(1, "tpm_crb_smc_start() returns res.a0 = 0x%lx\n",
> res.a0);
>> +		return -EIO;
>
> I don't think either of these WARN's are appropriate.
>
> 'dev_err(FIRMWARE_BUG'  would be better.
>
> Jason

I will fix this in next version.  Waiting to see if there are
more comments from others.
Thanks
- Jiandi

>
> --------------------------------------------------------------------------
> ----
> Announcing the Oxford Dictionaries API! The API offers world-renowned
> dictionary content that is easy and intuitive to access. Sign up for an
> account today to start using our lexical data to power your apps and
> projects. Get started today and enter our developer competition.
> http://sdm.link/oxford
> _______________________________________________
> tpmdd-devel mailing list
> tpmdd-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/tpmdd-devel
>
Jarkko Sakkinen March 11, 2017, 8:39 a.m.
On Fri, Mar 10, 2017 at 03:58:08AM -0600, Jiandi An wrote:
> Add a TPM Command Response Buffer start method that invokes
> a secure Monitor Call to request the firmware to execute or
> cancel a TPM 2.0 command for ARM64.
> 
> Signed-off-by: Jiandi An <anjiandi@codeaurora.org>
> ---

These are placed incorrectly. They should be in tpm_crb.c

/Jarkko

>  drivers/char/tpm/tpm.h | 29 +++++++++++++++++++++++++++++
>  1 file changed, 29 insertions(+)
> 
> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
> index 4937b56..4341594 100644
> --- a/drivers/char/tpm/tpm.h
> +++ b/drivers/char/tpm/tpm.h
> @@ -35,6 +35,9 @@
>  #include <linux/cdev.h>
>  #include <linux/highmem.h>
>  #include <crypto/hash_info.h>
> +#ifdef CONFIG_ARM64
> +#include <linux/arm-smccc.h>
> +#endif
>  
>  enum tpm_const {
>  	TPM_MINOR = 224,	/* officially assigned */
> @@ -484,6 +487,32 @@ static inline void tpm_buf_append_u32(struct tpm_buf *buf, const u32 value)
>  	tpm_buf_append(buf, (u8 *) &value2, 4);
>  }
>  
> +#ifdef CONFIG_ARM64
> +/*
> + * This is a TPM Command Response Buffer start method that invokes a
> + * Secure Monitor Call to requrest the firmware to execute or cancel
> + * a TPM 2.0 command.
> + */
> +static inline int tpm_crb_smc_start(unsigned long func_id)
> +{
> +	struct arm_smccc_res res;
> +
> +	arm_smccc_smc(func_id, 0, 0, 0, 0, 0, 0, 0, &res);
> +	if (res.a0 != 0) {
> +		WARN(1, "tpm_crb_smc_start() returns res.a0 = 0x%lx\n", res.a0);
> +		return -EIO;
> +	}
> +
> +	return 0;
> +}
> +#else
> +static inline int tpm_crb_smc_start(unsigned long func_id)
> +{
> +	WARN(1, "tpm_crb: incorrect start method\n");
> +	return -EINVAL;
> +}
> +#endif
> +
>  extern struct class *tpm_class;
>  extern dev_t tpm_devt;
>  extern const struct file_operations tpm_fops;
> -- 
> Jiandi An
> Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc.
> Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
> 

------------------------------------------------------------------------------
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford

Patch hide | download patch | download mbox

diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 4937b56..4341594 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -35,6 +35,9 @@ 
 #include <linux/cdev.h>
 #include <linux/highmem.h>
 #include <crypto/hash_info.h>
+#ifdef CONFIG_ARM64
+#include <linux/arm-smccc.h>
+#endif
 
 enum tpm_const {
 	TPM_MINOR = 224,	/* officially assigned */
@@ -484,6 +487,32 @@  static inline void tpm_buf_append_u32(struct tpm_buf *buf, const u32 value)
 	tpm_buf_append(buf, (u8 *) &value2, 4);
 }
 
+#ifdef CONFIG_ARM64
+/*
+ * This is a TPM Command Response Buffer start method that invokes a
+ * Secure Monitor Call to requrest the firmware to execute or cancel
+ * a TPM 2.0 command.
+ */
+static inline int tpm_crb_smc_start(unsigned long func_id)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_smc(func_id, 0, 0, 0, 0, 0, 0, 0, &res);
+	if (res.a0 != 0) {
+		WARN(1, "tpm_crb_smc_start() returns res.a0 = 0x%lx\n", res.a0);
+		return -EIO;
+	}
+
+	return 0;
+}
+#else
+static inline int tpm_crb_smc_start(unsigned long func_id)
+{
+	WARN(1, "tpm_crb: incorrect start method\n");
+	return -EINVAL;
+}
+#endif
+
 extern struct class *tpm_class;
 extern dev_t tpm_devt;
 extern const struct file_operations tpm_fops;