tee-dev.h 3.3 KB

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