efi_tcg2.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Defines data structures and APIs that allow an OS to interact with UEFI
  4. * firmware to query information about the device
  5. *
  6. * This file refers the following TCG specification.
  7. * - TCG PC Client Platform Firmware Profile Specification
  8. * https://trustedcomputinggroup.org/resource/pc-client-specific-platform-firmware-profile-specification/
  9. *
  10. * - TCG EFI Protocol Specification
  11. * https://trustedcomputinggroup.org/resource/tcg-efi-protocol-specification/
  12. *
  13. * Copyright (c) 2020, Linaro Limited
  14. */
  15. #if !defined _EFI_TCG2_PROTOCOL_H_
  16. #define _EFI_TCG2_PROTOCOL_H_
  17. #include <efi_api.h>
  18. #include <tpm-v2.h>
  19. #define EFI_TCG2_PROTOCOL_GUID \
  20. EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, \
  21. 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f)
  22. /* TPMV2 only */
  23. #define TCG2_EVENT_LOG_FORMAT_TCG_2 0x00000002
  24. #define EFI_TCG2_EXTEND_ONLY 0x0000000000000001
  25. #define PE_COFF_IMAGE 0x0000000000000010
  26. /* Algorithm Registry */
  27. #define EFI_TCG2_BOOT_HASH_ALG_SHA1 0x00000001
  28. #define EFI_TCG2_BOOT_HASH_ALG_SHA256 0x00000002
  29. #define EFI_TCG2_BOOT_HASH_ALG_SHA384 0x00000004
  30. #define EFI_TCG2_BOOT_HASH_ALG_SHA512 0x00000008
  31. #define EFI_TCG2_BOOT_HASH_ALG_SM3_256 0x00000010
  32. #define EFI_TCG2_FINAL_EVENTS_TABLE_VERSION 1
  33. #define TPM2_EVENT_LOG_SIZE CONFIG_EFI_TCG2_PROTOCOL_EVENTLOG_SIZE
  34. typedef u32 efi_tcg_event_log_bitmap;
  35. typedef u32 efi_tcg_event_log_format;
  36. typedef u32 efi_tcg_event_algorithm_bitmap;
  37. /**
  38. * struct tdEFI_TCG2_VERSION - structure of EFI TCG2 version
  39. * @major: major version
  40. * @minor: minor version
  41. */
  42. struct efi_tcg2_version {
  43. u8 major;
  44. u8 minor;
  45. };
  46. /**
  47. * struct tdEFI_TCG2_EVENT_HEADER - structure of EFI TCG2 event header
  48. * @header_size: size of the event header
  49. * @header_version: header version
  50. * @pcr_index: index of the PCR that is extended
  51. * @event_type: type of the event that is extended
  52. */
  53. struct efi_tcg2_event_header {
  54. u32 header_size;
  55. u16 header_version;
  56. u32 pcr_index;
  57. u32 event_type;
  58. } __packed;
  59. /**
  60. * struct tdEFI_TCG2_EVENT - structure of EFI TCG2 event
  61. * @size: total size of the event including the size component, the header
  62. * and the event data
  63. * @header: event header
  64. * @event: event to add
  65. */
  66. struct efi_tcg2_event {
  67. u32 size;
  68. struct efi_tcg2_event_header header;
  69. u8 event[];
  70. } __packed;
  71. /**
  72. * struct tdUEFI_IMAGE_LOAD_EVENT - structure of PE/COFF image measurement
  73. * @image_location_in_memory: image address
  74. * @image_length_in_memory: image size
  75. * @image_link_time_address: image link time address
  76. * @length_of_device_path: devive path size
  77. * @device_path: device path
  78. */
  79. struct uefi_image_load_event {
  80. efi_physical_addr_t image_location_in_memory;
  81. u64 image_length_in_memory;
  82. u64 image_link_time_address;
  83. u64 length_of_device_path;
  84. struct efi_device_path device_path[];
  85. };
  86. /**
  87. * struct tdEFI_TCG2_BOOT_SERVICE_CAPABILITY - protocol capability information
  88. * @size: allocated size of the structure
  89. * @structure_version: version of this structure
  90. * @protocol_version: version of the EFI TCG2 protocol.
  91. * @hash_algorithm_bitmap: supported hash algorithms
  92. * @supported_event_logs: bitmap of supported event log formats
  93. * @tpm_present_flag: false = TPM not present
  94. * @max_command_size: max size (in bytes) of a command
  95. * that can be sent to the TPM
  96. * @max_response_size: max size (in bytes) of a response that
  97. * can be provided by the TPM
  98. * @manufacturer_id: 4-byte Vendor ID
  99. * @number_of_pcr_banks: maximum number of PCR banks
  100. * @active_pcr_banks: bitmap of currently active
  101. * PCR banks (hashing algorithms).
  102. */
  103. struct efi_tcg2_boot_service_capability {
  104. u8 size;
  105. struct efi_tcg2_version structure_version;
  106. struct efi_tcg2_version protocol_version;
  107. efi_tcg_event_algorithm_bitmap hash_algorithm_bitmap;
  108. efi_tcg_event_log_bitmap supported_event_logs;
  109. u8 tpm_present_flag;
  110. u16 max_command_size;
  111. u16 max_response_size;
  112. u32 manufacturer_id;
  113. u32 number_of_pcr_banks;
  114. efi_tcg_event_algorithm_bitmap active_pcr_banks;
  115. };
  116. #define boot_service_capability_min \
  117. sizeof(struct efi_tcg2_boot_service_capability) - \
  118. offsetof(struct efi_tcg2_boot_service_capability, number_of_pcr_banks)
  119. #define TCG_EFI_SPEC_ID_EVENT_SIGNATURE_03 "Spec ID Event03"
  120. #define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_MAJOR_TPM2 2
  121. #define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_MINOR_TPM2 0
  122. #define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_ERRATA_TPM2 2
  123. /**
  124. * struct TCG_EfiSpecIdEventAlgorithmSize - hashing algorithm information
  125. *
  126. * @algorithm_id: algorithm defined in enum tpm2_algorithms
  127. * @digest_size: size of the algorithm
  128. */
  129. struct tcg_efi_spec_id_event_algorithm_size {
  130. u16 algorithm_id;
  131. u16 digest_size;
  132. } __packed;
  133. /**
  134. * struct TCG_EfiSpecIDEventStruct - content of the event log header
  135. *
  136. * @signature: signature, set to Spec ID Event03
  137. * @platform_class: class defined in TCG ACPI Specification
  138. * Client Common Header.
  139. * @spec_version_minor: minor version
  140. * @spec_version_major: major version
  141. * @spec_version_errata: major version
  142. * @uintn_size: size of the efi_uintn_t fields used in various
  143. * data structures used in this specification.
  144. * 0x01 indicates u32 and 0x02 indicates u64
  145. * @number_of_algorithms: hashing algorithms used in this event log
  146. * @digest_sizes: array of number_of_algorithms pairs
  147. * 1st member defines the algorithm id
  148. * 2nd member defines the algorithm size
  149. * @vendor_info_size: size in bytes for vendor specific info
  150. * @vendor_info: vendor specific info
  151. */
  152. struct tcg_efi_spec_id_event {
  153. u8 signature[16];
  154. u32 platform_class;
  155. u8 spec_version_minor;
  156. u8 spec_version_major;
  157. u8 spec_errata;
  158. u8 uintn_size;
  159. u32 number_of_algorithms;
  160. struct tcg_efi_spec_id_event_algorithm_size digest_sizes[TPM2_NUM_PCR_BANKS];
  161. u8 vendor_info_size;
  162. /* U-Boot does not provide any vendor info */
  163. u8 vendor_info[];
  164. } __packed;
  165. /**
  166. * struct tdEFI_TCG2_FINAL_EVENTS_TABLE - log entries after Get Event Log
  167. * @version: version number for this structure
  168. * @number_of_events: number of events recorded after invocation of
  169. * GetEventLog()
  170. * @event: List of events of type tcg_pcr_event2
  171. */
  172. struct efi_tcg2_final_events_table {
  173. u64 version;
  174. u64 number_of_events;
  175. struct tcg_pcr_event2 event[];
  176. };
  177. /**
  178. * struct tdUEFI_VARIABLE_DATA - event log structure of UEFI variable
  179. * @variable_name: The vendorGUID parameter in the
  180. * GetVariable() API.
  181. * @unicode_name_length: The length in CHAR16 of the Unicode name of
  182. * the variable.
  183. * @variable_data_length: The size of the variable data.
  184. * @unicode_name: The CHAR16 unicode name of the variable
  185. * without NULL-terminator.
  186. * @variable_data: The data parameter of the efi variable
  187. * in the GetVariable() API.
  188. */
  189. struct efi_tcg2_uefi_variable_data {
  190. efi_guid_t variable_name;
  191. u64 unicode_name_length;
  192. u64 variable_data_length;
  193. u16 unicode_name[1];
  194. u8 variable_data[1];
  195. };
  196. struct efi_tcg2_protocol {
  197. efi_status_t (EFIAPI * get_capability)(struct efi_tcg2_protocol *this,
  198. struct efi_tcg2_boot_service_capability *capability);
  199. efi_status_t (EFIAPI * get_eventlog)(struct efi_tcg2_protocol *this,
  200. efi_tcg_event_log_format log_format,
  201. u64 *event_log_location, u64 *event_log_last_entry,
  202. bool *event_log_truncated);
  203. efi_status_t (EFIAPI * hash_log_extend_event)(struct efi_tcg2_protocol *this,
  204. u64 flags,
  205. efi_physical_addr_t data_to_hash,
  206. u64 data_to_hash_len,
  207. struct efi_tcg2_event *efi_tcg_event);
  208. efi_status_t (EFIAPI * submit_command)(struct efi_tcg2_protocol *this,
  209. u32 input_parameter_block_size,
  210. u8 *input_parameter_block,
  211. u32 output_parameter_block_size,
  212. u8 *output_parameter_block);
  213. efi_status_t (EFIAPI * get_active_pcr_banks)(struct efi_tcg2_protocol *this,
  214. u32 *active_pcr_banks);
  215. efi_status_t (EFIAPI * set_active_pcr_banks)(struct efi_tcg2_protocol *this,
  216. u32 active_pcr_banks);
  217. efi_status_t (EFIAPI * get_result_of_set_active_pcr_banks)(struct efi_tcg2_protocol *this,
  218. u32 *operation_present,
  219. u32 *response);
  220. };
  221. #endif