psp-tee.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* SPDX-License-Identifier: MIT */
  2. /*
  3. * AMD Trusted Execution Environment (TEE) interface
  4. *
  5. * Author: Rijo Thomas <[email protected]>
  6. *
  7. * Copyright 2019 Advanced Micro Devices, Inc.
  8. *
  9. */
  10. #ifndef __PSP_TEE_H_
  11. #define __PSP_TEE_H_
  12. #include <linux/types.h>
  13. #include <linux/errno.h>
  14. /* This file defines the Trusted Execution Environment (TEE) interface commands
  15. * and the API exported by AMD Secure Processor driver to communicate with
  16. * AMD-TEE Trusted OS.
  17. */
  18. /**
  19. * enum tee_cmd_id - TEE Interface Command IDs
  20. * @TEE_CMD_ID_LOAD_TA: Load Trusted Application (TA) binary into
  21. * TEE environment
  22. * @TEE_CMD_ID_UNLOAD_TA: Unload TA binary from TEE environment
  23. * @TEE_CMD_ID_OPEN_SESSION: Open session with loaded TA
  24. * @TEE_CMD_ID_CLOSE_SESSION: Close session with loaded TA
  25. * @TEE_CMD_ID_INVOKE_CMD: Invoke a command with loaded TA
  26. * @TEE_CMD_ID_MAP_SHARED_MEM: Map shared memory
  27. * @TEE_CMD_ID_UNMAP_SHARED_MEM: Unmap shared memory
  28. */
  29. enum tee_cmd_id {
  30. TEE_CMD_ID_LOAD_TA = 1,
  31. TEE_CMD_ID_UNLOAD_TA,
  32. TEE_CMD_ID_OPEN_SESSION,
  33. TEE_CMD_ID_CLOSE_SESSION,
  34. TEE_CMD_ID_INVOKE_CMD,
  35. TEE_CMD_ID_MAP_SHARED_MEM,
  36. TEE_CMD_ID_UNMAP_SHARED_MEM,
  37. };
  38. #ifdef CONFIG_CRYPTO_DEV_SP_PSP
  39. /**
  40. * psp_tee_process_cmd() - Process command in Trusted Execution Environment
  41. * @cmd_id: TEE command ID (&enum tee_cmd_id)
  42. * @buf: Command buffer for TEE processing. On success, is updated
  43. * with the response
  44. * @len: Length of command buffer in bytes
  45. * @status: On success, holds the TEE command execution status
  46. *
  47. * This function submits a command to the Trusted OS for processing in the
  48. * TEE environment and waits for a response or until the command times out.
  49. *
  50. * Returns:
  51. * 0 if TEE successfully processed the command
  52. * -%ENODEV if PSP device not available
  53. * -%EINVAL if invalid input
  54. * -%ETIMEDOUT if TEE command timed out
  55. * -%EBUSY if PSP device is not responsive
  56. */
  57. int psp_tee_process_cmd(enum tee_cmd_id cmd_id, void *buf, size_t len,
  58. u32 *status);
  59. /**
  60. * psp_check_tee_status() - Checks whether there is a TEE which a driver can
  61. * talk to.
  62. *
  63. * This function can be used by AMD-TEE driver to query if there is TEE with
  64. * which it can communicate.
  65. *
  66. * Returns:
  67. * 0 if the device has TEE
  68. * -%ENODEV if there is no TEE available
  69. */
  70. int psp_check_tee_status(void);
  71. #else /* !CONFIG_CRYPTO_DEV_SP_PSP */
  72. static inline int psp_tee_process_cmd(enum tee_cmd_id cmd_id, void *buf,
  73. size_t len, u32 *status)
  74. {
  75. return -ENODEV;
  76. }
  77. static inline int psp_check_tee_status(void)
  78. {
  79. return -ENODEV;
  80. }
  81. #endif /* CONFIG_CRYPTO_DEV_SP_PSP */
  82. #endif /* __PSP_TEE_H_ */