smcmod.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* Qualcomm SMC Module API */
  2. #ifndef __SMCMOD_H_
  3. #define __SMCMOD_H_
  4. #include <linux/types.h>
  5. #include <linux/ioctl.h>
  6. #define SMCMOD_DEV "smcmod"
  7. #define SMCMOD_REG_REQ_MAX_ARGS 2
  8. /**
  9. * struct smcmod_reg_req - for SMC register ioctl request
  10. *
  11. * @service_id - requested service.
  12. * @command_id - requested command.
  13. * @num_args - number of arguments.
  14. * @args - argument(s) to be passed to the secure world.
  15. * @return_val - return value from secure world operation.
  16. */
  17. struct smcmod_reg_req {
  18. uint32_t service_id; /* in */
  19. uint32_t command_id; /* in */
  20. uint8_t num_args; /* in */
  21. uint32_t args[SMCMOD_REG_REQ_MAX_ARGS]; /* in */
  22. uint32_t return_val; /* out */
  23. };
  24. /**
  25. * struct smcmod_buf_req - for SMC buffer ioctl request
  26. *
  27. * @service_id - requested service.
  28. * @command_id - requested command.
  29. * @ion_cmd_fd - fd obtained from ION_IOC_MAP or ION_IOC_SHARE.
  30. * @cmd_len - length of command data buffer in bytes.
  31. * @ion_resp_fd - fd obtained from ION_IOC_MAP or ION_IOC_SHARE.
  32. * @resp_len - length of response data buffer in bytes.
  33. * @return_val - return value from secure world operation.
  34. */
  35. struct smcmod_buf_req {
  36. uint32_t service_id;/* in */
  37. uint32_t command_id; /* in */
  38. int32_t ion_cmd_fd; /* in */
  39. uint32_t cmd_len; /* in */
  40. int32_t ion_resp_fd; /* in */
  41. uint32_t resp_len; /* in */
  42. uint32_t return_val; /* out */
  43. };
  44. /**
  45. * struct smcmod_cipher_req - for SMC cipher command ioctl
  46. *
  47. * @algorithm - specifies the cipher algorithm.
  48. * @operation - specifies encryption or decryption.
  49. * @mode - specifies cipher mode.
  50. * @ion_key_fd - fd obtained form ION_IOC_MAP or ION_IOC_SHARE.
  51. * @key_size - key size in bytes.
  52. * @ion_plain_text_fd - fd obtained form ION_IOC_MAP or ION_IOC_SHARE.
  53. * @plain_text_size - size of plain text in bytes.
  54. * @ion_cipher_text_fd - fd obtained form ION_IOC_MAP or ION_IOC_SHARE.
  55. * @cipher_text_size - cipher text size in bytes.
  56. * @ion_init_vector_fd - fd obtained form ION_IOC_MAP or ION_IOC_SHARE.
  57. * @init_vector_size - size of initialization vector in bytes.
  58. * @key_is_null - indicates that the key is null.
  59. * @return_val - return value from secure world opreation.
  60. */
  61. struct smcmod_cipher_req {
  62. uint32_t algorithm; /* in */
  63. uint32_t operation; /* in */
  64. uint32_t mode; /* in */
  65. int32_t ion_key_fd; /* in */
  66. uint32_t key_size; /* in */
  67. int32_t ion_plain_text_fd; /* in (encrypt)/out (decrypt) */
  68. uint32_t plain_text_size; /* in */
  69. int32_t ion_cipher_text_fd; /* out (encrypt)/in (decrypt) */
  70. uint32_t cipher_text_size; /* in */
  71. int32_t ion_init_vector_fd; /* in */
  72. uint32_t init_vector_size; /* in */
  73. uint32_t key_is_null; /* in */
  74. uint32_t return_val; /* out */
  75. };
  76. /**
  77. * struct smcmod_msg_digest_req - for message digest command ioctl
  78. *
  79. * @algorithm - specifies the cipher algorithm.
  80. * @ion_key_fd - fd obtained form ION_IOC_MAP or ION_IOC_SHARE.
  81. * @key_size - hash key size in bytes.
  82. * @ion_input_fd - fd obtained form ION_IOC_MAP or ION_IOC_SHARE.
  83. * @input_size - input data size in bytes.
  84. * @ion_output_fd - fd obtained form ION_IOC_MAP or ION_IOC_SHARE.
  85. * @output_size - size of output buffer in bytes.
  86. * @fixed_block - indicates whether this is a fixed block digest.
  87. * @key_is_null - indicates that the key is null.
  88. * @return_val - return value from secure world opreation.
  89. */
  90. struct smcmod_msg_digest_req {
  91. uint32_t algorithm; /* in */
  92. int32_t ion_key_fd; /* in */
  93. uint32_t key_size; /* in */
  94. int32_t ion_input_fd; /* in */
  95. uint32_t input_size; /* in */
  96. int32_t ion_output_fd; /* in/out */
  97. uint32_t output_size; /* in */
  98. uint32_t fixed_block; /* in */
  99. uint32_t key_is_null; /* in */
  100. uint32_t return_val; /* out */
  101. } __packed;
  102. /**
  103. * struct smcmod_decrypt_req - used to decrypt image fragments.
  104. * @service_id - requested service.
  105. * @command_id - requested command.
  106. * @operation - specifies metadata parsing or image fragment decrypting.
  107. * @request - describes request parameters depending on operation.
  108. * @response - this is the response of the request.
  109. */
  110. struct smcmod_decrypt_req {
  111. uint32_t service_id;
  112. uint32_t command_id;
  113. #define SMCMOD_DECRYPT_REQ_OP_METADATA 1
  114. #define SMCMOD_DECRYPT_REQ_OP_IMG_FRAG 2
  115. uint32_t operation;
  116. union {
  117. struct {
  118. uint32_t len;
  119. uint32_t ion_fd;
  120. } metadata;
  121. struct {
  122. uint32_t ctx_id;
  123. uint32_t last_frag;
  124. uint32_t frag_len;
  125. uint32_t ion_fd;
  126. uint32_t offset;
  127. } img_frag;
  128. } request;
  129. union {
  130. struct {
  131. uint32_t status;
  132. uint32_t ctx_id;
  133. uint32_t end_offset;
  134. } metadata;
  135. struct {
  136. uint32_t status;
  137. } img_frag;
  138. } response;
  139. };
  140. #define SMCMOD_IOC_MAGIC 0x97
  141. /* Number chosen to avoid any conflicts */
  142. #define SMCMOD_IOCTL_SEND_REG_CMD \
  143. _IOWR(SMCMOD_IOC_MAGIC, 32, struct smcmod_reg_req)
  144. #define SMCMOD_IOCTL_SEND_BUF_CMD \
  145. _IOWR(SMCMOD_IOC_MAGIC, 33, struct smcmod_buf_req)
  146. #define SMCMOD_IOCTL_SEND_CIPHER_CMD \
  147. _IOWR(SMCMOD_IOC_MAGIC, 34, struct smcmod_cipher_req)
  148. #define SMCMOD_IOCTL_SEND_MSG_DIGEST_CMD \
  149. _IOWR(SMCMOD_IOC_MAGIC, 35, struct smcmod_msg_digest_req)
  150. #define SMCMOD_IOCTL_GET_VERSION _IOWR(SMCMOD_IOC_MAGIC, 36, uint32_t)
  151. #define SMCMOD_IOCTL_SEND_DECRYPT_CMD \
  152. _IOWR(SMCMOD_IOC_MAGIC, 37, struct smcmod_decrypt_req)
  153. #endif /* __SMCMOD_H_ */