efi_loader: rework bootmgr/bootefi using load_image API
[oweals/u-boot.git] / lib / efi_loader / efi_root_node.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  *  Root node for system services
4  *
5  *  Copyright (c) 2018 Heinrich Schuchardt
6  */
7
8 #include <common.h>
9 #include <malloc.h>
10 #include <efi_loader.h>
11
12 const efi_guid_t efi_u_boot_guid = U_BOOT_GUID;
13
14 efi_handle_t efi_root = NULL;
15
16 struct efi_root_dp {
17         struct efi_device_path_vendor vendor;
18         struct efi_device_path end;
19 } __packed;
20
21 /**
22  * efi_root_node_register() - create root node
23  *
24  * Create the root node on which we install all protocols that are
25  * not related to a loaded image or a driver.
26  *
27  * Return:      status code
28  */
29 efi_status_t efi_root_node_register(void)
30 {
31         struct efi_root_dp *dp;
32
33         /* Create device path protocol */
34         dp = calloc(1, sizeof(*dp));
35         if (!dp)
36                 return EFI_OUT_OF_RESOURCES;
37
38         /* Fill vendor node */
39         dp->vendor.dp.type = DEVICE_PATH_TYPE_HARDWARE_DEVICE;
40         dp->vendor.dp.sub_type = DEVICE_PATH_SUB_TYPE_VENDOR;
41         dp->vendor.dp.length = sizeof(struct efi_device_path_vendor);
42         dp->vendor.guid = efi_u_boot_guid;
43
44         /* Fill end node */
45         dp->end.type = DEVICE_PATH_TYPE_END;
46         dp->end.sub_type = DEVICE_PATH_SUB_TYPE_END;
47         dp->end.length = sizeof(struct efi_device_path);
48
49         /* Create root node and install protocols */
50         return EFI_CALL(efi_install_multiple_protocol_interfaces(&efi_root,
51                        /* Device path protocol */
52                        &efi_guid_device_path, dp,
53                        /* Device path to text protocol */
54                        &efi_guid_device_path_to_text_protocol,
55                        (void *)&efi_device_path_to_text,
56                        /* Device path utilities protocol */
57                        &efi_guid_device_path_utilities_protocol,
58                        (void *)&efi_device_path_utilities,
59                        /* Unicode collation protocol */
60                        &efi_guid_unicode_collation_protocol,
61                        (void *)&efi_unicode_collation_protocol,
62 #if CONFIG_IS_ENABLED(EFI_LOADER_HII)
63                        /* HII string protocol */
64                        &efi_guid_hii_string_protocol,
65                        (void *)&efi_hii_string,
66                        /* HII database protocol */
67                        &efi_guid_hii_database_protocol,
68                        (void *)&efi_hii_database,
69                        /* HII configuration routing protocol */
70                        &efi_guid_hii_config_routing_protocol,
71                        (void *)&efi_hii_config_routing,
72 #endif
73                        NULL));
74 }