summaryrefslogtreecommitdiff
path: root/lib/efi_loader/efi_conformance.c
blob: a49aae92497264d4515a4d31b3be79a176fb8d3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// SPDX-License-Identifier: GPL-2.0-only
/*
 *  EFI conformance profile table
 *
 *  Copyright (C) 2022 Arm Ltd.
 */

#include <common.h>
#include <efi_loader.h>
#include <log.h>
#include <efi_api.h>
#include <malloc.h>

static const efi_guid_t efi_ecpt_guid = EFI_CONFORMANCE_PROFILES_TABLE_GUID;
static const efi_guid_t efi_ebbr_2_0_guid =
	EFI_CONFORMANCE_PROFILE_EBBR_2_0_GUID;

/**
 * efi_ecpt_register() - Install the ECPT system table.
 *
 * Return: status code
 */
efi_status_t efi_ecpt_register(void)
{
	int num_entries = 0;
	struct efi_conformance_profiles_table *ecpt;
	efi_status_t ret;
	size_t ecpt_size;

	ecpt_size = num_entries * sizeof(efi_guid_t)
		+ sizeof(struct efi_conformance_profiles_table);
	ret = efi_allocate_pool(EFI_BOOT_SERVICES_DATA, ecpt_size,
				(void **)&ecpt);

	if (ret != EFI_SUCCESS) {
		log_err("Out of memory\n");

		return ret;
	}

	if (CONFIG_IS_ENABLED(EFI_EBBR_2_0_CONFORMANCE))
		guidcpy(&ecpt->conformance_profiles[num_entries++],
			&efi_ebbr_2_0_guid);

	ecpt->version = EFI_CONFORMANCE_PROFILES_TABLE_VERSION;
	ecpt->number_of_profiles = num_entries;

	/* Install the ECPT in the system configuration table. */
	ret = efi_install_configuration_table(&efi_ecpt_guid, (void *)ecpt);
	if (ret != EFI_SUCCESS) {
		log_err("Failed to install ECPT\n");
		efi_free_pool(ecpt);

		return ret;
	}

	log_debug("ECPT created\n");

	return EFI_SUCCESS;
}