1 // SPDX-License-Identifier: GPL-2.0+
3 * efi_selftest_devicepath
5 * Copyright (c) 2020 Heinrich Schuchardt <xypron.glpk@gmx.de>
7 * Test the EFI_TCG2_PROTOCOL
10 #include <efi_selftest.h>
13 static struct efi_boot_services *boottime;
14 static const efi_guid_t guid_tcg2 = EFI_TCG2_PROTOCOL_GUID;
17 * efi_st_tcg2_setup() - setup test
19 * @handle: handle of the loaded image
20 * @systable: system table
21 * @return: status code
23 static int efi_st_tcg2_setup(const efi_handle_t img_handle,
24 const struct efi_system_table *systable)
26 boottime = systable->boottime;
28 return EFI_ST_SUCCESS;
32 * efi_st_tcg2_execute() - execute test
34 * Call the GetCapability service of the EFI_TCG2_PROTOCOL.
38 static int efi_st_tcg2_execute(void)
40 struct efi_tcg2_protocol *tcg2;
41 struct efi_tcg2_boot_service_capability capability;
44 ret = boottime->locate_protocol(&guid_tcg2, NULL, (void **)&tcg2);
45 if (ret != EFI_SUCCESS) {
46 efi_st_error("TCG2 protocol is not available.\n");
47 return EFI_ST_FAILURE;
49 capability.size = sizeof(struct efi_tcg2_boot_service_capability) - 1;
50 ret = tcg2->get_capability(tcg2, &capability);
51 if (ret != EFI_BUFFER_TOO_SMALL) {
52 efi_st_error("tcg2->get_capability on small buffer failed\n");
53 return EFI_ST_FAILURE;
55 capability.size = sizeof(struct efi_tcg2_boot_service_capability);
56 ret = tcg2->get_capability(tcg2, &capability);
57 if (ret != EFI_SUCCESS) {
58 efi_st_error("tcg2->get_capability failed\n");
59 return EFI_ST_FAILURE;
61 if (!capability.tpm_present_flag) {
62 efi_st_error("TPM not present\n");
63 return EFI_ST_FAILURE;
65 efi_st_printf("TPM supports 0x%.8x event logs\n",
66 capability.supported_event_logs);
67 return EFI_ST_SUCCESS;
70 EFI_UNIT_TEST(tcg2) = {
72 .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,
73 .execute = efi_st_tcg2_execute,
74 .setup = efi_st_tcg2_setup,