Ilias Apalodimas | 590fef6 | 2020-11-11 11:18:11 +0200 | [diff] [blame^] | 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 | |
| 9 | #if !defined _EFI_TCG2_PROTOCOL_H_ |
| 10 | #define _EFI_TCG2_PROTOCOL_H_ |
| 11 | |
| 12 | #include <tpm-v2.h> |
| 13 | |
| 14 | #define EFI_TCG2_PROTOCOL_GUID \ |
| 15 | EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, \ |
| 16 | 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f) |
| 17 | |
| 18 | /* TPMV2 only */ |
| 19 | #define TCG2_EVENT_LOG_FORMAT_TCG_2 0x00000002 |
| 20 | |
| 21 | /* SHA1, SHA256, SHA384, SHA512, TPM_ALG_SM3_256 */ |
| 22 | #define MAX_HASH_COUNT 5 |
| 23 | /* Algorithm Registry */ |
| 24 | #define EFI_TCG2_BOOT_HASH_ALG_SHA1 0x00000001 |
| 25 | #define EFI_TCG2_BOOT_HASH_ALG_SHA256 0x00000002 |
| 26 | #define EFI_TCG2_BOOT_HASH_ALG_SHA384 0x00000004 |
| 27 | #define EFI_TCG2_BOOT_HASH_ALG_SHA512 0x00000008 |
| 28 | #define EFI_TCG2_BOOT_HASH_ALG_SM3_256 0x00000010 |
| 29 | |
| 30 | typedef u32 efi_tcg_event_log_bitmap; |
| 31 | typedef u32 efi_tcg_event_log_format; |
| 32 | typedef u32 efi_tcg_event_algorithm_bitmap; |
| 33 | |
| 34 | struct efi_tcg2_version { |
| 35 | u8 major; |
| 36 | u8 minor; |
| 37 | }; |
| 38 | |
| 39 | struct efi_tcg2_event_header { |
| 40 | u32 header_size; |
| 41 | u16 header_version; |
| 42 | u32 pcr_index; |
| 43 | u32 event_type; |
| 44 | } __packed; |
| 45 | |
| 46 | struct efi_tcg2_event { |
| 47 | u32 size; |
| 48 | struct efi_tcg2_event_header header; |
| 49 | u8 event[]; |
| 50 | } __packed; |
| 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 | |
| 66 | #define boot_service_capability_min \ |
| 67 | sizeof(struct efi_tcg2_boot_service_capability) - \ |
| 68 | offsetof(struct efi_tcg2_boot_service_capability, number_of_pcr_banks) |
| 69 | |
| 70 | struct efi_tcg2_protocol { |
| 71 | efi_status_t (EFIAPI * get_capability)(struct efi_tcg2_protocol *this, |
| 72 | struct efi_tcg2_boot_service_capability *capability); |
| 73 | efi_status_t (EFIAPI * get_eventlog)(struct efi_tcg2_protocol *this, |
| 74 | efi_tcg_event_log_format log_format, |
| 75 | u64 *event_log_location, u64 *event_log_last_entry, |
| 76 | bool *event_log_truncated); |
| 77 | efi_status_t (EFIAPI * hash_log_extend_event)(struct efi_tcg2_protocol *this, |
| 78 | u64 flags, u64 data_to_hash, |
| 79 | u64 data_to_hash_len, |
| 80 | struct efi_tcg2_event *efi_tcg_event); |
| 81 | efi_status_t (EFIAPI * submit_command)(struct efi_tcg2_protocol *this, |
| 82 | u32 input_parameter_block_size, |
| 83 | u8 *input_parameter_block, |
| 84 | u32 output_parameter_block_size, |
| 85 | u8 *output_parameter_block); |
| 86 | efi_status_t (EFIAPI * get_active_pcr_banks)(struct efi_tcg2_protocol *this, |
| 87 | u32 *active_pcr_banks); |
| 88 | efi_status_t (EFIAPI * set_active_pcr_banks)(struct efi_tcg2_protocol *this, |
| 89 | u32 active_pcr_banks); |
| 90 | efi_status_t (EFIAPI * get_result_of_set_active_pcr_banks)(struct efi_tcg2_protocol *this, |
| 91 | u32 *operation_present, |
| 92 | u32 *response); |
| 93 | }; |
| 94 | #endif |