feat(hob): add HOB definitions to TFTF
Add necessary HOB structure definitions and HOB library to TFTF.
Signed-off-by: Kathleen Capella <kathleen.capella@arm.com>
Change-Id: I1a81cd99df52436a077a71030244ca642122497a
diff --git a/include/lib/hob/efi_types.h b/include/lib/hob/efi_types.h
new file mode 100644
index 0000000..2d1158d
--- /dev/null
+++ b/include/lib/hob/efi_types.h
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2024, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef EFI_TYPES_H
+#define EFI_TYPES_H
+
+#include <lib/libc/uuid.h>
+#include <stdint.h>
+
+typedef uint64_t efi_physical_address_t;
+
+/*****************************************************************************
+ * EFI_BOOT_MODE *
+ *****************************************************************************/
+
+typedef uint32_t efi_boot_mode_t;
+/**
+ * EFI boot mode.
+ */
+#define EFI_BOOT_WITH_FULL_CONFIGURATION U(0x00)
+#define EFI_BOOT_WITH_MINIMAL_CONFIGURATION U(0x01)
+#define EFI_BOOT_ASSUMING_NO_CONFIGURATION_CHANGES U(0x02)
+#define EFI_BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS U(0x03)
+#define EFI_BOOT_WITH_DEFAULT_SETTINGS U(0x04)
+#define EFI_BOOT_ON_S4_RESUME U(0x05)
+#define EFI_BOOT_ON_S5_RESUME U(0x06)
+#define EFI_BOOT_WITH_MFG_MODE_SETTINGS U(0x07)
+#define EFI_BOOT_ON_S2_RESUME U(0x10)
+#define EFI_BOOT_ON_S3_RESUME U(0x11)
+#define EFI_BOOT_ON_FLASH_UPDATE U(0x12)
+#define EFI_BOOT_IN_RECOVERY_MODE U(0x20)
+
+/*****************************************************************************
+ * EFI_RESOURCE_TYPE *
+ *****************************************************************************/
+
+typedef uint32_t efi_resource_type_t;
+
+/**
+ * Value of EFI_RESOURCE_TYPE used in EFI_HOB_RESOURCE_DESCRIPTOR.
+ */
+#define EFI_RESOURCE_SYSTEM_MEMORY U(0x00000000)
+#define EFI_RESOURCE_MEMORY_MAPPED_IO U(0x00000001)
+#define EFI_RESOURCE_IO U(0x00000002)
+#define EFI_RESOURCE_FIRMWARE_DEVICE U(0x00000003)
+#define EFI_RESOURCE_MEMORY_MAPPED_IO_PORT U(0x00000004)
+#define EFI_RESOURCE_MEMORY_RESERVED U(0x00000005)
+#define EFI_RESOURCE_IO_RESERVED U(0x00000006)
+
+/*****************************************************************************
+ * EFI_RESOURCE_ATTRIBUTE_TYPE *
+ *****************************************************************************/
+
+typedef uint32_t efi_resource_attribute_type_t;
+
+#define EFI_RESOURCE_ATTRIBUTE_PRESENT U(0x00000001)
+#define EFI_RESOURCE_ATTRIBUTE_INITIALIZED U(0x00000002)
+#define EFI_RESOURCE_ATTRIBUTE_TESTED U(0x00000004)
+#define EFI_RESOURCE_ATTRIBUTE_READ_PROTECTED U(0x00000080)
+#define EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTED U(0x00000100)
+#define EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTED U(0x00000200)
+#define EFI_RESOURCE_ATTRIBUTE_PERSISTENT U(0x00800000)
+#define EFI_RESOURCE_ATTRIBUTE_SINGLE_BIT_ECC U(0x00000008)
+#define EFI_RESOURCE_ATTRIBUTE_MULTIPLE_BIT_ECC U(0x00000010)
+#define EFI_RESOURCE_ATTRIBUTE_ECC_RESERVED_1 U(0x00000020)
+#define EFI_RESOURCE_ATTRIBUTE_ECC_RESERVED_2 U(0x00000040)
+#define EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE U(0x00000400)
+#define EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE U(0x00000800)
+#define EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE U(0x00001000)
+#define EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE U(0x00002000)
+#define EFI_RESOURCE_ATTRIBUTE_16_BIT_IO U(0x00004000)
+#define EFI_RESOURCE_ATTRIBUTE_32_BIT_IO U(0x00008000)
+#define EFI_RESOURCE_ATTRIBUTE_64_BIT_IO U(0x00010000)
+#define EFI_RESOURCE_ATTRIBUTE_UNCACHED_EXPORTED U(0x00020000)
+#define EFI_RESOURCE_ATTRIBUTE_READ_PROTECTABLE U(0x00100000)
+#define EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTABLE U(0x00200000)
+#define EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTABLE U(0x00400000)
+#define EFI_RESOURCE_ATTRIBUTE_PERSISTABLE U(0x01000000)
+#define EFI_RESOURCE_ATTRIBUTE_READ_ONLY_PROTECTED U(0x00040000)
+#define EFI_RESOURCE_ATTRIBUTE_READ_ONLY_PROTECTABLE U(0x00080000)
+#define EFI_RESOURCE_ATTRIBUTE_MORE_RELIABLE U(0x02000000)
+
+#endif /* EFI_TYPES_H */
diff --git a/include/lib/hob/hob.h b/include/lib/hob/hob.h
new file mode 100644
index 0000000..5c217e3
--- /dev/null
+++ b/include/lib/hob/hob.h
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2024, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef HOB_H
+#define HOB_H
+
+#include <lib/libc/uuid.h>
+#include <stdbool.h>
+#include <stdint.h>
+
+#include <lib/hob/efi_types.h>
+#include <lib/utils_def.h>
+
+/*****************************************************************************
+ * Hob Generic Header *
+ *****************************************************************************/
+
+/**
+ * HobType values of EFI_HOB_GENERIC_HEADER.
+ */
+#define EFI_HOB_TYPE_HANDOFF U(0x0001)
+#define EFI_HOB_TYPE_MEMORY_ALLOCATION U(0x0002)
+#define EFI_HOB_TYPE_RESOURCE_DESCRIPTOR U(0x0003)
+#define EFI_HOB_TYPE_GUID_EXTENSION U(0x0004)
+#define EFI_HOB_TYPE_FV U(0x0005)
+#define EFI_HOB_TYPE_CPU U(0x0006)
+#define EFI_HOB_TYPE_MEMORY_POOL U(0x0007)
+#define EFI_HOB_TYPE_FV2 U(0x0009)
+#define EFI_HOB_TYPE_LOAD_PEIM_UNUSED U(0x000A)
+#define EFI_HOB_TYPE_UEFI_CAPSULE U(0x000B)
+#define EFI_HOB_TYPE_FV3 U(0x000C)
+#define EFI_HOB_TYPE_UNUSED U(0xFFFE)
+#define EFI_HOB_TYPE_END_OF_HOB_LIST U(0xFFFF)
+
+struct efi_hob_generic_header {
+ uint16_t hob_type;
+ uint16_t hob_length;
+ uint32_t reserved;
+};
+
+/*****************************************************************************
+ * PHIT Hob. *
+ *****************************************************************************/
+
+#define EFI_HOB_HANDOFF_TABLE_VERSION U(0x000a)
+
+struct efi_hob_handoff_info_table {
+ struct efi_hob_generic_header header;
+ uint32_t version;
+ efi_boot_mode_t boot_mode;
+ efi_physical_address_t efi_memory_top;
+ efi_physical_address_t efi_memory_bottom;
+ efi_physical_address_t efi_free_memory_top;
+ efi_physical_address_t efi_free_memory_bottom;
+ efi_physical_address_t efi_end_of_hob_list;
+};
+
+/*****************************************************************************
+ * Resource Descriptor Hob. *
+ *****************************************************************************/
+
+struct efi_hob_resource_descriptor {
+ struct efi_hob_generic_header header;
+ struct efi_guid owner;
+ efi_resource_type_t resource_type;
+ efi_resource_attribute_type_t resource_attribute;
+ efi_physical_address_t physical_start;
+ uint64_t resource_length;
+};
+
+/*****************************************************************************
+ * Guid Extension Hob. *
+ *****************************************************************************/
+struct efi_hob_guid_type {
+ struct efi_hob_generic_header header;
+ struct efi_guid name;
+ /**
+ * Guid specific data goes here.
+ */
+};
+
+/*****************************************************************************
+ * Firmware Volume Hob. *
+ *****************************************************************************/
+struct efi_hob_firmware_volume {
+ struct efi_hob_generic_header header;
+ efi_physical_address_t base_address;
+ uint64_t length;
+};
+
+/*****************************************************************************
+ * Interfaces. *
+ *****************************************************************************/
+
+void tftf_dump_hob_generic_header(struct efi_hob_generic_header h);
+
+#endif /* HOB_H */
diff --git a/include/lib/hob/hob_guid.h b/include/lib/hob/hob_guid.h
new file mode 100644
index 0000000..65d3dbf
--- /dev/null
+++ b/include/lib/hob/hob_guid.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2024, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef HOB_GUID_H
+#define HOB_GUID_H
+
+#include <lib/hob/efi_types.h>
+
+/**
+ * Guid used for creating StandaloneMm related information.
+ */
+
+#define MM_PEI_MMRAM_MEMORY_RESERVE_GUID \
+{ \
+ 0x0703f912, 0xbf8d, 0x4e2a, {0xbe, 0x07, 0xab, 0x27, 0x25, 0x25, 0xc5, 0x92 } \
+}
+
+#define MM_NS_BUFFER_GUID \
+{ \
+ 0xf00497e3, 0xbfa2, 0x41a1, {0x9d, 0x29, 0x54, 0xc2, 0xe9, 0x37, 0x21, 0xc5 } \
+}
+
+#define MM_MP_INFORMATION_GUID \
+{ \
+ 0xba33f15d, 0x4000, 0x45c1, {0x8e, 0x88, 0xf9, 0x16, 0x92, 0xd4, 0x57, 0xe3} \
+}
+
+#endif /* HOB_GUID_H */
diff --git a/include/lib/hob/mmram.h b/include/lib/hob/mmram.h
new file mode 100644
index 0000000..b269c64
--- /dev/null
+++ b/include/lib/hob/mmram.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2024, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#ifndef MMRAM_H
+#define MMRAM_H
+
+#include <lib/hob/efi_types.h>
+
+/**
+ * MMRAM states and capabilities
+ * See UEFI Platform Initialization Specification Version 1.8, IV-5.3.5
+ */
+#define EFI_MMRAM_OPEN U(0x00000001)
+#define EFI_MMRAM_CLOSED U(0x00000002)
+#define EFI_MMRAM_LOCKED U(0x00000004)
+#define EFI_CACHEABLE U(0x00000008)
+#define EFI_ALLOCATED U(0x00000010)
+#define EFI_NEEDS_TESTING U(0x00000020)
+#define EFI_NEEDS_ECC_INITIALIZATION U(0x00000040)
+
+#define EFI_SMRAM_OPEN EFI_MMRAM_OPEN
+#define EFI_SMRAM_CLOSED EFI_MMRAM_CLOSED
+#define EFI_SMRAM_LOCKED EFI_MMRAM_LOCKED
+
+struct efi_mmram_descriptor {
+ efi_physical_address_t physical_start;
+ efi_physical_address_t cpu_start;
+ uint64_t physical_size;
+ uint64_t region_state;
+};
+
+/**
+ * MMRAM block descriptor
+ * This definition comes from
+ * https://github.com/tianocore/edk2/blob/master/StandaloneMmPkg/Include/Guid/MmramMemoryReserve.h
+ */
+struct efi_mmram_hob_descriptor_block {
+ uint32_t number_of_mm_reserved_regions;
+ struct efi_mmram_descriptor descriptor[];
+};
+
+#endif /* MMRAM_H */
diff --git a/include/lib/libc/uuid.h b/include/lib/libc/uuid.h
index 3a1699b..8ba973d 100644
--- a/include/lib/libc/uuid.h
+++ b/include/lib/libc/uuid.h
@@ -51,6 +51,18 @@
uint8_t node[_UUID_NODE_LEN];
};
+struct efi_guid {
+ uint32_t time_low;
+ uint16_t time_mid;
+ uint16_t time_hi_and_version;
+ uint8_t clock_seq_and_node[8];
+};
+
+union uuid_helper_t {
+ struct uuid uuid_struct;
+ struct efi_guid efi_guid;
+};
+
typedef struct uuid uuid_t;
#endif /* _SYS_UUID_H_ */
diff --git a/lib/hob/hob.c b/lib/hob/hob.c
new file mode 100644
index 0000000..ce35e2f
--- /dev/null
+++ b/lib/hob/hob.c
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2024, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <stddef.h>
+#include <stdio.h>
+#include <lib/hob/hob.h>
+#include <lib/hob/hob_guid.h>
+#include <lib/hob/mmram.h>
+#include <lib/utils_def.h>
+
+#define ALIGN_UP(x, a) ((x + (a - 1)) & ~(a - 1))
+
+void tftf_dump_hob_generic_header(struct efi_hob_generic_header h)
+{
+ printf("Hob Type: 0x%x\n", h.hob_type);
+ printf("Hob Length: 0x%x\n", h.hob_length);
+}
diff --git a/lib/hob/hob.mk b/lib/hob/hob.mk
new file mode 100644
index 0000000..332738b
--- /dev/null
+++ b/lib/hob/hob.mk
@@ -0,0 +1,12 @@
+#
+# Copyright (c) 2024, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+HOB_LIST_SOURCES += $(addprefix lib/hob/, \
+ hob.c)
+
+INCLUDES += -Iinclude/lib/hob
+
+BL31_SOURCES += $(HOB_LIST_SOURCES)
diff --git a/tftf/framework/framework.mk b/tftf/framework/framework.mk
index 4e27995..d5d3300 100644
--- a/tftf/framework/framework.mk
+++ b/tftf/framework/framework.mk
@@ -19,6 +19,7 @@
-Iinclude/lib \
-Iinclude/lib/${ARCH} \
-Iinclude/lib/extensions \
+ -Iinclude/lib/hob \
-Iinclude/lib/pcie \
-Iinclude/lib/spdm \
-Iinclude/lib/utils \
@@ -57,6 +58,7 @@
lib/extensions/amu/${ARCH}/amu.c \
lib/extensions/amu/${ARCH}/amu_helpers.S \
lib/exceptions/irq.c \
+ lib/hob/hob.c \
lib/locks/${ARCH}/spinlock.S \
lib/power_management/hotplug/hotplug.c \
lib/power_management/suspend/${ARCH}/asm_tftf_suspend.S \