cc.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2022 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef GRUB_EFI_CC_H
  19. #define GRUB_EFI_CC_H 1
  20. #include <grub/efi/api.h>
  21. #include <grub/efi/efi.h>
  22. #include <grub/err.h>
  23. #define GRUB_EFI_CC_MEASUREMENT_PROTOCOL_GUID \
  24. { 0x96751a3d, 0x72f4, 0x41a6, \
  25. { 0xa7, 0x94, 0xed, 0x5d, 0x0e, 0x67, 0xae, 0x6b } \
  26. };
  27. struct grub_efi_cc_version
  28. {
  29. grub_efi_uint8_t Major;
  30. grub_efi_uint8_t Minor;
  31. };
  32. typedef struct grub_efi_cc_version grub_efi_cc_version_t;
  33. /* EFI_CC Type/SubType definition. */
  34. #define GRUB_EFI_CC_TYPE_NONE 0
  35. #define GRUB_EFI_CC_TYPE_SEV 1
  36. #define GRUB_EFI_CC_TYPE_TDX 2
  37. struct grub_efi_cc_type
  38. {
  39. grub_efi_uint8_t Type;
  40. grub_efi_uint8_t SubType;
  41. };
  42. typedef struct grub_efi_cc_type grub_efi_cc_type_t;
  43. typedef grub_efi_uint32_t grub_efi_cc_event_log_bitmap_t;
  44. typedef grub_efi_uint32_t grub_efi_cc_event_log_format_t;
  45. typedef grub_efi_uint32_t grub_efi_cc_event_algorithm_bitmap_t;
  46. typedef grub_efi_uint32_t grub_efi_cc_mr_index_t;
  47. /* Intel TDX measure register index. */
  48. #define GRUB_TDX_MR_INDEX_MRTD 0
  49. #define GRUB_TDX_MR_INDEX_RTMR0 1
  50. #define GRUB_TDX_MR_INDEX_RTMR1 2
  51. #define GRUB_TDX_MR_INDEX_RTMR2 3
  52. #define GRUB_TDX_MR_INDEX_RTMR3 4
  53. #define GRUB_EFI_CC_EVENT_LOG_FORMAT_TCG_2 0x00000002
  54. #define GRUB_EFI_CC_BOOT_HASH_ALG_SHA384 0x00000004
  55. #define GRUB_EFI_CC_EVENT_HEADER_VERSION 1
  56. struct grub_efi_cc_event_header
  57. {
  58. /* Size of the event header itself (sizeof(EFI_TD_EVENT_HEADER)). */
  59. grub_efi_uint32_t HeaderSize;
  60. /*
  61. * Header version. For this version of this specification,
  62. * the value shall be 1.
  63. */
  64. grub_efi_uint16_t HeaderVersion;
  65. /* Index of the MR that shall be extended. */
  66. grub_efi_cc_mr_index_t MrIndex;
  67. /* Type of the event that shall be extended (and optionally logged). */
  68. grub_efi_uint32_t EventType;
  69. } GRUB_PACKED;
  70. typedef struct grub_efi_cc_event_header grub_efi_cc_event_header_t;
  71. struct grub_efi_cc_event
  72. {
  73. /* Total size of the event including the Size component, the header and the Event data. */
  74. grub_efi_uint32_t Size;
  75. grub_efi_cc_event_header_t Header;
  76. grub_efi_uint8_t Event[0];
  77. } GRUB_PACKED;
  78. typedef struct grub_efi_cc_event grub_efi_cc_event_t;
  79. struct grub_efi_cc_boot_service_capability
  80. {
  81. /* Allocated size of the structure. */
  82. grub_efi_uint8_t Size;
  83. /*
  84. * Version of the grub_efi_cc_boot_service_capability_t structure itself.
  85. * For this version of the protocol, the Major version shall be set to 1
  86. * and the Minor version shall be set to 1.
  87. */
  88. grub_efi_cc_version_t StructureVersion;
  89. /*
  90. * Version of the EFI TD protocol.
  91. * For this version of the protocol, the Major version shall be set to 1
  92. * and the Minor version shall be set to 1.
  93. */
  94. grub_efi_cc_version_t ProtocolVersion;
  95. /* Supported hash algorithms. */
  96. grub_efi_cc_event_algorithm_bitmap_t HashAlgorithmBitmap;
  97. /* Bitmap of supported event log formats. */
  98. grub_efi_cc_event_log_bitmap_t SupportedEventLogs;
  99. /* Indicates the CC type. */
  100. grub_efi_cc_type_t CcType;
  101. };
  102. typedef struct grub_efi_cc_boot_service_capability grub_efi_cc_boot_service_capability_t;
  103. struct grub_efi_cc_protocol
  104. {
  105. grub_efi_status_t
  106. (__grub_efi_api *get_capability) (struct grub_efi_cc_protocol *this,
  107. grub_efi_cc_boot_service_capability_t *ProtocolCapability);
  108. grub_efi_status_t
  109. (__grub_efi_api *get_event_log) (struct grub_efi_cc_protocol *this,
  110. grub_efi_cc_event_log_format_t EventLogFormat,
  111. grub_efi_physical_address_t *EventLogLocation,
  112. grub_efi_physical_address_t *EventLogLastEntry,
  113. grub_efi_boolean_t *EventLogTruncated);
  114. grub_efi_status_t
  115. (__grub_efi_api *hash_log_extend_event) (struct grub_efi_cc_protocol *this,
  116. grub_efi_uint64_t Flags,
  117. grub_efi_physical_address_t DataToHash,
  118. grub_efi_uint64_t DataToHashLen,
  119. grub_efi_cc_event_t *EfiCcEvent);
  120. grub_efi_status_t
  121. (__grub_efi_api *map_pcr_to_mr_index) (struct grub_efi_cc_protocol *this,
  122. grub_efi_uint32_t PcrIndex,
  123. grub_efi_cc_mr_index_t *MrIndex);
  124. };
  125. typedef struct grub_efi_cc_protocol grub_efi_cc_protocol_t;
  126. #endif