tee-dev.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* SPDX-License-Identifier: MIT */
  2. /*
  3. * Copyright (C) 2019,2021 Advanced Micro Devices, Inc.
  4. *
  5. * Author: Rijo Thomas <Rijo-john.Thomas@amd.com>
  6. * Author: Devaraj Rangasamy <Devaraj.Rangasamy@amd.com>
  7. *
  8. */
  9. /* This file describes the TEE communication interface between host and AMD
  10. * Secure Processor
  11. */
  12. #ifndef __TEE_DEV_H__
  13. #define __TEE_DEV_H__
  14. #include <linux/device.h>
  15. #include <linux/mutex.h>
  16. #define TEE_DEFAULT_CMD_TIMEOUT (10 * MSEC_PER_SEC)
  17. #define TEE_DEFAULT_RING_TIMEOUT 10
  18. #define MAX_BUFFER_SIZE 988
  19. /**
  20. * struct tee_init_ring_cmd - Command to init TEE ring buffer
  21. * @low_addr: bits [31:0] of the physical address of ring buffer
  22. * @hi_addr: bits [63:32] of the physical address of ring buffer
  23. * @size: size of ring buffer in bytes
  24. */
  25. struct tee_init_ring_cmd {
  26. u32 low_addr;
  27. u32 hi_addr;
  28. u32 size;
  29. };
  30. #define MAX_RING_BUFFER_ENTRIES 32
  31. /**
  32. * struct ring_buf_manager - Helper structure to manage ring buffer.
  33. * @ring_start: starting address of ring buffer
  34. * @ring_size: size of ring buffer in bytes
  35. * @ring_pa: physical address of ring buffer
  36. * @wptr: index to the last written entry in ring buffer
  37. */
  38. struct ring_buf_manager {
  39. struct mutex mutex; /* synchronizes access to ring buffer */
  40. void *ring_start;
  41. u32 ring_size;
  42. phys_addr_t ring_pa;
  43. u32 wptr;
  44. };
  45. struct psp_tee_device {
  46. struct device *dev;
  47. struct psp_device *psp;
  48. void __iomem *io_regs;
  49. struct tee_vdata *vdata;
  50. struct ring_buf_manager rb_mgr;
  51. };
  52. /**
  53. * enum tee_cmd_state - TEE command states for the ring buffer interface
  54. * @TEE_CMD_STATE_INIT: initial state of command when sent from host
  55. * @TEE_CMD_STATE_PROCESS: command being processed by TEE environment
  56. * @TEE_CMD_STATE_COMPLETED: command processing completed
  57. */
  58. enum tee_cmd_state {
  59. TEE_CMD_STATE_INIT,
  60. TEE_CMD_STATE_PROCESS,
  61. TEE_CMD_STATE_COMPLETED,
  62. };
  63. /**
  64. * enum cmd_resp_state - TEE command's response status maintained by driver
  65. * @CMD_RESPONSE_INVALID: initial state when no command is written to ring
  66. * @CMD_WAITING_FOR_RESPONSE: driver waiting for response from TEE
  67. * @CMD_RESPONSE_TIMEDOUT: failed to get response from TEE
  68. * @CMD_RESPONSE_COPIED: driver has copied response from TEE
  69. */
  70. enum cmd_resp_state {
  71. CMD_RESPONSE_INVALID,
  72. CMD_WAITING_FOR_RESPONSE,
  73. CMD_RESPONSE_TIMEDOUT,
  74. CMD_RESPONSE_COPIED,
  75. };
  76. /**
  77. * struct tee_ring_cmd - Structure of the command buffer in TEE ring
  78. * @cmd_id: refers to &enum tee_cmd_id. Command id for the ring buffer
  79. * interface
  80. * @cmd_state: refers to &enum tee_cmd_state
  81. * @status: status of TEE command execution
  82. * @res0: reserved region
  83. * @pdata: private data (currently unused)
  84. * @res1: reserved region
  85. * @buf: TEE command specific buffer
  86. * @flag: refers to &enum cmd_resp_state
  87. */
  88. struct tee_ring_cmd {
  89. u32 cmd_id;
  90. u32 cmd_state;
  91. u32 status;
  92. u32 res0[1];
  93. u64 pdata;
  94. u32 res1[2];
  95. u8 buf[MAX_BUFFER_SIZE];
  96. u32 flag;
  97. /* Total size: 1024 bytes */
  98. } __packed;
  99. int tee_dev_init(struct psp_device *psp);
  100. void tee_dev_destroy(struct psp_device *psp);
  101. int tee_restore(struct psp_device *psp);
  102. #endif /* __TEE_DEV_H__ */