efi_tcg2.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. * Copyright (c) 2020, Linaro Limited
  7. */
  8. #if !defined _EFI_TCG2_PROTOCOL_H_
  9. #define _EFI_TCG2_PROTOCOL_H_
  10. #include <efi_api.h>
  11. #include <tpm-v2.h>
  12. #define EFI_TCG2_PROTOCOL_GUID \
  13. EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, \
  14. 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f)
  15. /* TPMV2 only */
  16. #define TCG2_EVENT_LOG_FORMAT_TCG_2 0x00000002
  17. #define EFI_TCG2_EXTEND_ONLY 0x0000000000000001
  18. #define PE_COFF_IMAGE 0x0000000000000010
  19. /* Algorithm Registry */
  20. #define EFI_TCG2_BOOT_HASH_ALG_SHA1 0x00000001
  21. #define EFI_TCG2_BOOT_HASH_ALG_SHA256 0x00000002
  22. #define EFI_TCG2_BOOT_HASH_ALG_SHA384 0x00000004
  23. #define EFI_TCG2_BOOT_HASH_ALG_SHA512 0x00000008
  24. #define EFI_TCG2_BOOT_HASH_ALG_SM3_256 0x00000010
  25. #define EFI_TCG2_FINAL_EVENTS_TABLE_VERSION 1
  26. #define TPM2_EVENT_LOG_SIZE CONFIG_EFI_TCG2_PROTOCOL_EVENTLOG_SIZE
  27. typedef u32 efi_tcg_event_log_bitmap;
  28. typedef u32 efi_tcg_event_log_format;
  29. typedef u32 efi_tcg_event_algorithm_bitmap;
  30. struct efi_tcg2_version {
  31. u8 major;
  32. u8 minor;
  33. };
  34. struct efi_tcg2_event_header {
  35. u32 header_size;
  36. u16 header_version;
  37. u32 pcr_index;
  38. u32 event_type;
  39. } __packed;
  40. struct efi_tcg2_event {
  41. u32 size;
  42. struct efi_tcg2_event_header header;
  43. u8 event[];
  44. } __packed;
  45. struct uefi_image_load_event {
  46. efi_physical_addr_t image_location_in_memory;
  47. u64 image_length_in_memory;
  48. u64 image_link_time_address;
  49. u64 length_of_device_path;
  50. struct efi_device_path device_path[];
  51. };
  52. struct efi_tcg2_boot_service_capability {
  53. u8 size;
  54. struct efi_tcg2_version structure_version;
  55. struct efi_tcg2_version protocol_version;
  56. efi_tcg_event_algorithm_bitmap hash_algorithm_bitmap;
  57. efi_tcg_event_log_bitmap supported_event_logs;
  58. u8 tpm_present_flag;
  59. u16 max_command_size;
  60. u16 max_response_size;
  61. u32 manufacturer_id;
  62. u32 number_of_pcr_banks;
  63. efi_tcg_event_algorithm_bitmap active_pcr_banks;
  64. };
  65. #define boot_service_capability_min \
  66. sizeof(struct efi_tcg2_boot_service_capability) - \
  67. offsetof(struct efi_tcg2_boot_service_capability, number_of_pcr_banks)
  68. #define TCG_EFI_SPEC_ID_EVENT_SIGNATURE_03 "Spec ID Event03"
  69. #define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_MAJOR_TPM2 2
  70. #define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_MINOR_TPM2 0
  71. #define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_ERRATA_TPM2 2
  72. /**
  73. * struct TCG_EfiSpecIdEventAlgorithmSize
  74. *
  75. * @algorithm_id: algorithm defined in enum tpm2_algorithms
  76. * @digest_size: size of the algorithm
  77. */
  78. struct tcg_efi_spec_id_event_algorithm_size {
  79. u16 algorithm_id;
  80. u16 digest_size;
  81. } __packed;
  82. /**
  83. * struct TCG_EfiSpecIDEventStruct
  84. *
  85. * @signature: signature, set to Spec ID Event03
  86. * @platform_class: class defined in TCG ACPI Specification
  87. * Client Common Header.
  88. * @spec_version_minor: minor version
  89. * @spec_version_major: major version
  90. * @spec_version_errata: major version
  91. * @uintn_size: size of the efi_uintn_t fields used in various
  92. * data structures used in this specification.
  93. * 0x01 indicates u32 and 0x02 indicates u64
  94. * @number_of_algorithms: hashing algorithms used in this event log
  95. * @digest_sizes: array of number_of_algorithms pairs
  96. * 1st member defines the algorithm id
  97. * 2nd member defines the algorithm size
  98. * @vendor_info_size: size in bytes for vendor specific info
  99. * @vendor_info: vendor specific info
  100. */
  101. struct tcg_efi_spec_id_event {
  102. u8 signature[16];
  103. u32 platform_class;
  104. u8 spec_version_minor;
  105. u8 spec_version_major;
  106. u8 spec_errata;
  107. u8 uintn_size;
  108. u32 number_of_algorithms;
  109. struct tcg_efi_spec_id_event_algorithm_size digest_sizes[TPM2_NUM_PCR_BANKS];
  110. u8 vendor_info_size;
  111. /* U-Boot does not provide any vendor info */
  112. u8 vendor_info[];
  113. } __packed;
  114. /**
  115. * struct tdEFI_TCG2_FINAL_EVENTS_TABLE
  116. * @version: version number for this structure
  117. * @number_of_events: number of events recorded after invocation of
  118. * GetEventLog()
  119. * @event: List of events of type tcg_pcr_event2
  120. */
  121. struct efi_tcg2_final_events_table {
  122. u64 version;
  123. u64 number_of_events;
  124. struct tcg_pcr_event2 event[];
  125. };
  126. struct efi_tcg2_protocol {
  127. efi_status_t (EFIAPI * get_capability)(struct efi_tcg2_protocol *this,
  128. struct efi_tcg2_boot_service_capability *capability);
  129. efi_status_t (EFIAPI * get_eventlog)(struct efi_tcg2_protocol *this,
  130. efi_tcg_event_log_format log_format,
  131. u64 *event_log_location, u64 *event_log_last_entry,
  132. bool *event_log_truncated);
  133. efi_status_t (EFIAPI * hash_log_extend_event)(struct efi_tcg2_protocol *this,
  134. u64 flags,
  135. efi_physical_addr_t data_to_hash,
  136. u64 data_to_hash_len,
  137. struct efi_tcg2_event *efi_tcg_event);
  138. efi_status_t (EFIAPI * submit_command)(struct efi_tcg2_protocol *this,
  139. u32 input_parameter_block_size,
  140. u8 *input_parameter_block,
  141. u32 output_parameter_block_size,
  142. u8 *output_parameter_block);
  143. efi_status_t (EFIAPI * get_active_pcr_banks)(struct efi_tcg2_protocol *this,
  144. u32 *active_pcr_banks);
  145. efi_status_t (EFIAPI * set_active_pcr_banks)(struct efi_tcg2_protocol *this,
  146. u32 active_pcr_banks);
  147. efi_status_t (EFIAPI * get_result_of_set_active_pcr_banks)(struct efi_tcg2_protocol *this,
  148. u32 *operation_present,
  149. u32 *response);
  150. };
  151. #endif