efi_tcg2.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. /* TPMV2 only */
  20. #define TCG2_EVENT_LOG_FORMAT_TCG_2 0x00000002
  21. #define EFI_TCG2_EXTEND_ONLY 0x0000000000000001
  22. #define PE_COFF_IMAGE 0x0000000000000010
  23. #define EFI_TCG2_MAX_PCR_INDEX 23
  24. /* Algorithm Registry */
  25. #define EFI_TCG2_BOOT_HASH_ALG_SHA1 0x00000001
  26. #define EFI_TCG2_BOOT_HASH_ALG_SHA256 0x00000002
  27. #define EFI_TCG2_BOOT_HASH_ALG_SHA384 0x00000004
  28. #define EFI_TCG2_BOOT_HASH_ALG_SHA512 0x00000008
  29. #define EFI_TCG2_BOOT_HASH_ALG_SM3_256 0x00000010
  30. #define EFI_TCG2_FINAL_EVENTS_TABLE_VERSION 1
  31. #define TPM2_EVENT_LOG_SIZE CONFIG_EFI_TCG2_PROTOCOL_EVENTLOG_SIZE
  32. typedef u32 efi_tcg_event_log_bitmap;
  33. typedef u32 efi_tcg_event_log_format;
  34. typedef u32 efi_tcg_event_algorithm_bitmap;
  35. /**
  36. * struct tdEFI_TCG2_VERSION - structure of EFI TCG2 version
  37. * @major: major version
  38. * @minor: minor version
  39. */
  40. struct efi_tcg2_version {
  41. u8 major;
  42. u8 minor;
  43. };
  44. /**
  45. * struct tdEFI_TCG2_EVENT_HEADER - structure of EFI TCG2 event header
  46. * @header_size: size of the event header
  47. * @header_version: header version
  48. * @pcr_index: index of the PCR that is extended
  49. * @event_type: type of the event that is extended
  50. */
  51. struct efi_tcg2_event_header {
  52. u32 header_size;
  53. u16 header_version;
  54. u32 pcr_index;
  55. u32 event_type;
  56. } __packed;
  57. /**
  58. * struct tdEFI_TCG2_EVENT - structure of EFI TCG2 event
  59. * @size: total size of the event including the size component, the header
  60. * and the event data
  61. * @header: event header
  62. * @event: event to add
  63. */
  64. struct efi_tcg2_event {
  65. u32 size;
  66. struct efi_tcg2_event_header header;
  67. u8 event[];
  68. } __packed;
  69. /**
  70. * struct tdUEFI_IMAGE_LOAD_EVENT - structure of PE/COFF image measurement
  71. * @image_location_in_memory: image address
  72. * @image_length_in_memory: image size
  73. * @image_link_time_address: image link time address
  74. * @length_of_device_path: devive path size
  75. * @device_path: device path
  76. */
  77. struct uefi_image_load_event {
  78. efi_physical_addr_t image_location_in_memory;
  79. u64 image_length_in_memory;
  80. u64 image_link_time_address;
  81. u64 length_of_device_path;
  82. struct efi_device_path device_path[];
  83. };
  84. /**
  85. * struct tdEFI_TCG2_BOOT_SERVICE_CAPABILITY - protocol capability information
  86. * @size: allocated size of the structure
  87. * @structure_version: version of this structure
  88. * @protocol_version: version of the EFI TCG2 protocol.
  89. * @hash_algorithm_bitmap: supported hash algorithms
  90. * @supported_event_logs: bitmap of supported event log formats
  91. * @tpm_present_flag: false = TPM not present
  92. * @max_command_size: max size (in bytes) of a command
  93. * that can be sent to the TPM
  94. * @max_response_size: max size (in bytes) of a response that
  95. * can be provided by the TPM
  96. * @manufacturer_id: 4-byte Vendor ID
  97. * @number_of_pcr_banks: maximum number of PCR banks
  98. * @active_pcr_banks: bitmap of currently active
  99. * PCR banks (hashing algorithms).
  100. */
  101. struct efi_tcg2_boot_service_capability {
  102. u8 size;
  103. struct efi_tcg2_version structure_version;
  104. struct efi_tcg2_version protocol_version;
  105. efi_tcg_event_algorithm_bitmap hash_algorithm_bitmap;
  106. efi_tcg_event_log_bitmap supported_event_logs;
  107. u8 tpm_present_flag;
  108. u16 max_command_size;
  109. u16 max_response_size;
  110. u32 manufacturer_id;
  111. u32 number_of_pcr_banks;
  112. efi_tcg_event_algorithm_bitmap active_pcr_banks;
  113. };
  114. /* up to and including the vendor ID (manufacturer_id) field */
  115. #define BOOT_SERVICE_CAPABILITY_MIN \
  116. offsetof(struct efi_tcg2_boot_service_capability, number_of_pcr_banks)
  117. #define TCG_EFI_SPEC_ID_EVENT_SIGNATURE_03 "Spec ID Event03"
  118. #define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_MAJOR_TPM2 2
  119. #define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_MINOR_TPM2 0
  120. #define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_ERRATA_TPM2 2
  121. /**
  122. * struct TCG_EfiSpecIdEventAlgorithmSize - hashing algorithm information
  123. *
  124. * @algorithm_id: algorithm defined in enum tpm2_algorithms
  125. * @digest_size: size of the algorithm
  126. */
  127. struct tcg_efi_spec_id_event_algorithm_size {
  128. u16 algorithm_id;
  129. u16 digest_size;
  130. } __packed;
  131. /**
  132. * struct TCG_EfiSpecIDEventStruct - content of the event log header
  133. *
  134. * @signature: signature, set to Spec ID Event03
  135. * @platform_class: class defined in TCG ACPI Specification
  136. * Client Common Header.
  137. * @spec_version_minor: minor version
  138. * @spec_version_major: major version
  139. * @spec_version_errata: major version
  140. * @uintn_size: size of the efi_uintn_t fields used in various
  141. * data structures used in this specification.
  142. * 0x01 indicates u32 and 0x02 indicates u64
  143. * @number_of_algorithms: hashing algorithms used in this event log
  144. * @digest_sizes: array of number_of_algorithms pairs
  145. * 1st member defines the algorithm id
  146. * 2nd member defines the algorithm size
  147. */
  148. struct tcg_efi_spec_id_event {
  149. u8 signature[16];
  150. u32 platform_class;
  151. u8 spec_version_minor;
  152. u8 spec_version_major;
  153. u8 spec_errata;
  154. u8 uintn_size;
  155. u32 number_of_algorithms;
  156. struct tcg_efi_spec_id_event_algorithm_size digest_sizes[];
  157. } __packed;
  158. /**
  159. * struct tdEFI_TCG2_FINAL_EVENTS_TABLE - log entries after Get Event Log
  160. * @version: version number for this structure
  161. * @number_of_events: number of events recorded after invocation of
  162. * GetEventLog()
  163. * @event: List of events of type tcg_pcr_event2
  164. */
  165. struct efi_tcg2_final_events_table {
  166. u64 version;
  167. u64 number_of_events;
  168. struct tcg_pcr_event2 event[];
  169. };
  170. /**
  171. * struct tdUEFI_VARIABLE_DATA - event log structure of UEFI variable
  172. * @variable_name: The vendorGUID parameter in the
  173. * GetVariable() API.
  174. * @unicode_name_length: The length in CHAR16 of the Unicode name of
  175. * the variable.
  176. * @variable_data_length: The size of the variable data.
  177. * @unicode_name: The CHAR16 unicode name of the variable
  178. * without NULL-terminator.
  179. * @variable_data: The data parameter of the efi variable
  180. * in the GetVariable() API.
  181. */
  182. struct efi_tcg2_uefi_variable_data {
  183. efi_guid_t variable_name;
  184. u64 unicode_name_length;
  185. u64 variable_data_length;
  186. u16 unicode_name[1];
  187. u8 variable_data[1];
  188. };
  189. /**
  190. * struct tdUEFI_HANDOFF_TABLE_POINTERS2 - event log structure of SMBOIS tables
  191. * @table_description_size: size of table description
  192. * @table_description: table description
  193. * @number_of_tables: number of uefi configuration table
  194. * @table_entry: uefi configuration table entry
  195. */
  196. #define SMBIOS_HANDOFF_TABLE_DESC "SmbiosTable"
  197. struct smbios_handoff_table_pointers2 {
  198. u8 table_description_size;
  199. u8 table_description[sizeof(SMBIOS_HANDOFF_TABLE_DESC)];
  200. u64 number_of_tables;
  201. struct efi_configuration_table table_entry[];
  202. } __packed;
  203. /**
  204. * struct tdUEFI_GPT_DATA - event log structure of industry standard tables
  205. * @uefi_partition_header: gpt partition header
  206. * @number_of_partitions: the number of partition
  207. * @partitions: partition entries
  208. */
  209. struct efi_gpt_data {
  210. gpt_header uefi_partition_header;
  211. u64 number_of_partitions;
  212. gpt_entry partitions[];
  213. } __packed;
  214. struct efi_tcg2_protocol {
  215. efi_status_t (EFIAPI * get_capability)(struct efi_tcg2_protocol *this,
  216. struct efi_tcg2_boot_service_capability *capability);
  217. efi_status_t (EFIAPI * get_eventlog)(struct efi_tcg2_protocol *this,
  218. efi_tcg_event_log_format log_format,
  219. u64 *event_log_location, u64 *event_log_last_entry,
  220. bool *event_log_truncated);
  221. efi_status_t (EFIAPI * hash_log_extend_event)(struct efi_tcg2_protocol *this,
  222. u64 flags,
  223. efi_physical_addr_t data_to_hash,
  224. u64 data_to_hash_len,
  225. struct efi_tcg2_event *efi_tcg_event);
  226. efi_status_t (EFIAPI * submit_command)(struct efi_tcg2_protocol *this,
  227. u32 input_parameter_block_size,
  228. u8 *input_parameter_block,
  229. u32 output_parameter_block_size,
  230. u8 *output_parameter_block);
  231. efi_status_t (EFIAPI * get_active_pcr_banks)(struct efi_tcg2_protocol *this,
  232. u32 *active_pcr_banks);
  233. efi_status_t (EFIAPI * set_active_pcr_banks)(struct efi_tcg2_protocol *this,
  234. u32 active_pcr_banks);
  235. efi_status_t (EFIAPI * get_result_of_set_active_pcr_banks)(struct efi_tcg2_protocol *this,
  236. u32 *operation_present,
  237. u32 *response);
  238. };
  239. #endif