efi_tcg2.h 5.0 KB

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