From 8953568a2db48032f2a2d4065e68fd1b20980caf Mon Sep 17 00:00:00 2001 From: Levi Yun Date: Mon, 13 May 2024 10:24:31 +0100 Subject: [PATCH] feat(lib): introduce Hob creation library According to Platform Initialization (PI) Specification [1] and discussion on edk2 mailing list [2], StandaloneMm shouldn't create Hob but it should be passed from TF-A. IOW, TF-A should pass boot information via HOB list to initialise StandaloneMm properly. And this HOB lists could be delivered via - SPM_MM: Transfer List according to the firmware handoff spec[3] - FF-A v1.1 >= : FF-A boot protocol. This patch introduces a TF-A HOB creation library and some of definitions which StandaloneMm requires to boot. Link: https://uefi.org/sites/default/files/resources/PI_Spec_1_6.pdf [1] Link: https://edk2.groups.io/g/devel/topic/103675962#114283 [2] Link: https://github.com/FirmwareHandoff/firmware_handoff [3] Signed-off-by: Levi Yun Change-Id: I5e0838adce487110206998a8b79bc3adca922cec --- Makefile | 6 ++ docs/getting_started/build-options.rst | 5 ++ docs/license.rst | 2 + include/lib/hob/efi_types.h | 86 ++++++++++++++++++ include/lib/hob/hob.h | 119 ++++++++++++++++++++++++ include/lib/hob/hob_guid.h | 31 +++++++ include/lib/hob/mmram.h | 45 ++++++++++ include/lib/hob/mpinfo.h | 120 +++++++++++++++++++++++++ lib/hob/hob.mk | 12 +++ make_helpers/defaults.mk | 3 + 10 files changed, 429 insertions(+) create mode 100644 include/lib/hob/efi_types.h create mode 100644 include/lib/hob/hob.h create mode 100644 include/lib/hob/hob_guid.h create mode 100644 include/lib/hob/mmram.h create mode 100644 include/lib/hob/mpinfo.h create mode 100644 lib/hob/hob.mk diff --git a/Makefile b/Makefile index 8e992595c..384c1e43e 100644 --- a/Makefile +++ b/Makefile @@ -1021,6 +1021,10 @@ ifeq ($(DRTM_SUPPORT),1) $(info DRTM_SUPPORT is an experimental feature) endif +ifeq (${HOB_LIST},1) + $(warning HOB_LIST is an experimental feature) +endif + ifeq (${TRANSFER_LIST},1) $(info TRANSFER_LIST is an experimental feature) endif @@ -1234,6 +1238,7 @@ $(eval $(call assert_booleans,\ PLATFORM_REPORT_CTX_MEM_USE \ EARLY_CONSOLE \ PRESERVE_DSU_PMU_REGS \ + HOB_LIST \ ))) # Numeric_Flags @@ -1451,6 +1456,7 @@ $(eval $(call add_defines,\ PLATFORM_REPORT_CTX_MEM_USE \ EARLY_CONSOLE \ PRESERVE_DSU_PMU_REGS \ + HOB_LIST \ ))) ifeq (${PLATFORM_REPORT_CTX_MEM_USE}, 1) diff --git a/docs/getting_started/build-options.rst b/docs/getting_started/build-options.rst index ab0b94d51..7d067c6c5 100644 --- a/docs/getting_started/build-options.rst +++ b/docs/getting_started/build-options.rst @@ -1411,6 +1411,10 @@ Common build options interface through BL31 as a SiP SMC function. Default is disabled (0). +- ``HOB_LIST``: Setting this to ``1`` enables support for passing boot + information using HOB defined in `Platform Initialization specification`_. + This defaults to ``0``. + Firmware update options ~~~~~~~~~~~~~~~~~~~~~~~ @@ -1454,3 +1458,4 @@ Firmware update options .. _Clang: https://clang.llvm.org/docs/DiagnosticsReference.html .. _Firmware Handoff specification: https://github.com/FirmwareHandoff/firmware_handoff/releases/tag/v0.9 .. _PSA Crypto API specification: https://armmbed.github.io/mbed-crypto/html/ +.. _Platform Initialization specification: https://uefi.org/specs/PI/1.8/index.html diff --git a/docs/license.rst b/docs/license.rst index 22d0e067d..e35b9bbc2 100644 --- a/docs/license.rst +++ b/docs/license.rst @@ -116,6 +116,8 @@ license text is included in those source files. These files are: - ``lib/hob/hob.c`` + - ``include/lib/hob/mmram.h`` + - ``include/lib/hob/mpinfo.h`` .. _FreeBSD: http://www.freebsd.org .. _Linux MIT license: https://raw.githubusercontent.com/torvalds/linux/master/LICENSES/preferred/MIT diff --git a/include/lib/hob/efi_types.h b/include/lib/hob/efi_types.h new file mode 100644 index 000000000..071d012f0 --- /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 +#include + +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 000000000..120f5da50 --- /dev/null +++ b/include/lib/hob/hob.h @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2024, Arm Limited and Contributors. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef HOB_H +#define HOB_H + +#include +#include + +#include +#include +#include + +/***************************************************************************** + * 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; + /** + * Guid specific data goes here. + */ +}; + +/***************************************************************************** + * Interfaces. * + *****************************************************************************/ + +struct efi_hob_handoff_info_table * +create_hob_list( + efi_physical_address_t efi_memory_begin, size_t efi_memory_length, + efi_physical_address_t efi_free_memory_bottom, size_t efi_free_memory_length); + +int create_resource_descriptor_hob( + struct efi_hob_handoff_info_table *hob_table, + efi_resource_type_t resource_type, + efi_resource_attribute_type_t resource_attribute, + efi_physical_address_t phy_addr_start, + uint64_t resource_length); + +int create_guid_hob(struct efi_hob_handoff_info_table *hob_table, + struct efi_guid *guid, uint16_t data_length, void **data); + +int create_fv_hob(struct efi_hob_handoff_info_table *hob_table, + efi_physical_address_t base_addr, uint64_t size); + +#endif /* HOB_H */ diff --git a/include/lib/hob/hob_guid.h b/include/lib/hob/hob_guid.h new file mode 100644 index 000000000..65d3dbffe --- /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 + +/** + * 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 000000000..b269c64c4 --- /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 + +/** + * 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/hob/mpinfo.h b/include/lib/hob/mpinfo.h new file mode 100644 index 000000000..b80d8f14e --- /dev/null +++ b/include/lib/hob/mpinfo.h @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2024, Arm Limited and Contributors. All rights reserved. + * + * SPDX-License-Identifier: BSD-2-Clause + */ +#ifndef MPINFO_H +#define MPINFO_H + +#include +#include +#include + +/* + * Value used in the NumberProcessors parameter of the GetProcessorInfo function + */ +#define CPU_V2_EXTENDED_TOPOLOGY UL(1 << 24) + +/* + * This bit is used in the StatusFlag field of EFI_PROCESSOR_INFORMATION and + * indicates whether the processor is playing the role of BSP. If the bit is 1, + * then the processor is BSP. Otherwise, it is AP. + */ +#define PROCESSOR_AS_BSP_BIT UL(1 << 0) + +/* + * This bit is used in the StatusFlag field of EFI_PROCESSOR_INFORMATION and + * indicates whether the processor is enabled. If the bit is 1, then the + * processor is enabled. Otherwise, it is disabled. + */ +#define PROCESSOR_ENABLED_BIT UL(1 << 1) + +/* + * This bit is used in the StatusFlag field of EFI_PROCESSOR_INFORMATION and + * indicates whether the processor is healthy. If the bit is 1, then the + * processor is healthy. Otherwise, some fault has been detected for the processor. + */ +#define PROCESSOR_HEALTH_STATUS_BIT UL(1 << 2) + +/* + * Structure that describes the physical location of a logical CPU. + */ +struct efi_cpu_physical_location { + uint32_t package; + uint32_t core; + uint32_t thread; +}; + +/* + * Structure that defines the 6-level physical location of the processor + */ +struct efi_cpu_physical_location2 { + uint32_t package; + uint32_t module; + uint32_t tile; + uint32_t die; + uint32_t core; + uint32_t thread; +}; + +union extended_processor_information { + /* + * The 6-level physical location of the processor, including the + * physical package number that identifies the cartridge, the physical + * module number within package, the physical tile number within the module, + * the physical die number within the tile, the physical core number within + * package, and logical thread number within core. + */ + struct efi_cpu_physical_location2 location2; +}; + +/* + * Structure that describes information about a logical CPU. + */ +struct efi_processor_information { + /* + * The unique processor ID determined by system hardware. + */ + uint64_t processor_id; + + /* + * Flags indicating if the processor is BSP or AP, if the processor is enabled + * or disabled, and if the processor is healthy. Bits 3..31 are reserved and + * must be 0. + * + *
+	 * BSP  ENABLED  HEALTH  Description
+	 * ===  =======  ======  ===================================================
+	 * 0      0       0     Unhealthy Disabled AP.
+	 * 0      0       1     Healthy Disabled AP.
+	 * 0      1       0     Unhealthy Enabled AP.
+	 * 0      1       1     Healthy Enabled AP.
+	 * 1      0       0     Invalid. The BSP can never be in the disabled state.
+	 * 1      0       1     Invalid. The BSP can never be in the disabled state.
+	 * 1      1       0     Unhealthy Enabled BSP.
+	 * 1      1       1     Healthy Enabled BSP.
+	 * 
+ */ + uint32_t status_flags; + + /* + * The physical location of the processor, including the physical package number + * that identifies the cartridge, the physical core number within package, and + * logical thread number within core. + */ + struct efi_cpu_physical_location location; + + /* + * The extended information of the processor. This field is filled only when + * CPU_V2_EXTENDED_TOPOLOGY is set in parameter ProcessorNumber. + */ + union extended_processor_information extended_information; +}; + +struct efi_mp_information_hob_data { + uint64_t number_of_processors; + uint64_t number_of_enabled_processors; + struct efi_processor_information processor_info[]; +}; + +#endif /* MPINFO_H */ diff --git a/lib/hob/hob.mk b/lib/hob/hob.mk new file mode 100644 index 000000000..332738b84 --- /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/make_helpers/defaults.mk b/make_helpers/defaults.mk index d6c09de66..8a0975bcb 100644 --- a/make_helpers/defaults.mk +++ b/make_helpers/defaults.mk @@ -159,6 +159,9 @@ HANDLE_EA_EL3_FIRST_NS := 0 # Enable Handoff protocol using transfer lists TRANSFER_LIST := 0 +# Enable HOB list to generate boot information +HOB_LIST := 0 + # Enables support for the gcc compiler option "-mharden-sls=all". # By default, disables all SLS hardening. HARDEN_SLS := 0