Commit bade7e1f authored by Rijo Thomas's avatar Rijo Thomas Committed by Herbert Xu

tee: amdtee: check TEE status during driver initialization

The AMD-TEE driver should check if TEE is available before
registering itself with TEE subsystem. This ensures that
there is a TEE which the driver can talk to before proceeding
with tee device node allocation.

Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Acked-by: default avatarJens Wiklander <jens.wiklander@linaro.org>
Co-developed-by: default avatarDevaraj Rangasamy <Devaraj.Rangasamy@amd.com>
Signed-off-by: default avatarDevaraj Rangasamy <Devaraj.Rangasamy@amd.com>
Signed-off-by: default avatarRijo Thomas <Rijo-john.Thomas@amd.com>
Reviewed-by: default avatarGary R Hook <gary.hook@amd.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 757cc3e9
...@@ -362,3 +362,14 @@ int psp_tee_process_cmd(enum tee_cmd_id cmd_id, void *buf, size_t len, ...@@ -362,3 +362,14 @@ int psp_tee_process_cmd(enum tee_cmd_id cmd_id, void *buf, size_t len,
return 0; return 0;
} }
EXPORT_SYMBOL(psp_tee_process_cmd); EXPORT_SYMBOL(psp_tee_process_cmd);
int psp_check_tee_status(void)
{
struct psp_device *psp = psp_get_master_device();
if (!psp || !psp->tee_data)
return -ENODEV;
return 0;
}
EXPORT_SYMBOL(psp_check_tee_status);
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <linux/firmware.h> #include <linux/firmware.h>
#include "amdtee_private.h" #include "amdtee_private.h"
#include "../tee_private.h" #include "../tee_private.h"
#include <linux/psp-tee.h>
static struct amdtee_driver_data *drv_data; static struct amdtee_driver_data *drv_data;
static DEFINE_MUTEX(session_list_mutex); static DEFINE_MUTEX(session_list_mutex);
...@@ -438,6 +439,10 @@ static int __init amdtee_driver_init(void) ...@@ -438,6 +439,10 @@ static int __init amdtee_driver_init(void)
struct tee_shm_pool *pool = ERR_PTR(-EINVAL); struct tee_shm_pool *pool = ERR_PTR(-EINVAL);
int rc; int rc;
rc = psp_check_tee_status();
if (rc)
goto err_fail;
drv_data = kzalloc(sizeof(*drv_data), GFP_KERNEL); drv_data = kzalloc(sizeof(*drv_data), GFP_KERNEL);
if (IS_ERR(drv_data)) if (IS_ERR(drv_data))
return -ENOMEM; return -ENOMEM;
...@@ -485,6 +490,7 @@ static int __init amdtee_driver_init(void) ...@@ -485,6 +490,7 @@ static int __init amdtee_driver_init(void)
kfree(drv_data); kfree(drv_data);
drv_data = NULL; drv_data = NULL;
err_fail:
pr_err("amd-tee driver initialization failed\n"); pr_err("amd-tee driver initialization failed\n");
return rc; return rc;
} }
......
...@@ -62,6 +62,19 @@ enum tee_cmd_id { ...@@ -62,6 +62,19 @@ enum tee_cmd_id {
int psp_tee_process_cmd(enum tee_cmd_id cmd_id, void *buf, size_t len, int psp_tee_process_cmd(enum tee_cmd_id cmd_id, void *buf, size_t len,
u32 *status); u32 *status);
/**
* psp_check_tee_status() - Checks whether there is a TEE which a driver can
* talk to.
*
* This function can be used by AMD-TEE driver to query if there is TEE with
* which it can communicate.
*
* Returns:
* 0 if the device has TEE
* -%ENODEV if there is no TEE available
*/
int psp_check_tee_status(void);
#else /* !CONFIG_CRYPTO_DEV_SP_PSP */ #else /* !CONFIG_CRYPTO_DEV_SP_PSP */
static inline int psp_tee_process_cmd(enum tee_cmd_id cmd_id, void *buf, static inline int psp_tee_process_cmd(enum tee_cmd_id cmd_id, void *buf,
...@@ -69,5 +82,10 @@ static inline int psp_tee_process_cmd(enum tee_cmd_id cmd_id, void *buf, ...@@ -69,5 +82,10 @@ static inline int psp_tee_process_cmd(enum tee_cmd_id cmd_id, void *buf,
{ {
return -ENODEV; return -ENODEV;
} }
static inline int psp_check_tee_status(void)
{
return -ENODEV;
}
#endif /* CONFIG_CRYPTO_DEV_SP_PSP */ #endif /* CONFIG_CRYPTO_DEV_SP_PSP */
#endif /* __PSP_TEE_H_ */ #endif /* __PSP_TEE_H_ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment