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 struct efi_root_dp {
15 	struct efi_device_path_vendor vendor;
16 	struct efi_device_path end;
17 } __packed;
18 
19 /**
20  * efi_root_node_register() - create root node
21  *
22  * Create the root node on which we install all protocols that are
23  * not related to a loaded image or a driver.
24  *
25  * Return:	status code
26  */
27 efi_status_t efi_root_node_register(void)
28 {
29 	efi_handle_t root;
30 	efi_status_t ret;
31 	struct efi_root_dp *dp;
32 
33 	/* Create handle */
34 	ret = efi_create_handle(&root);
35 	if (ret != EFI_SUCCESS)
36 		return ret;
37 
38 	/* Install device path protocol */
39 	dp = calloc(1, sizeof(*dp));
40 	if (!dp)
41 		return EFI_OUT_OF_RESOURCES;
42 
43 	/* Fill vendor node */
44 	dp->vendor.dp.type = DEVICE_PATH_TYPE_HARDWARE_DEVICE;
45 	dp->vendor.dp.sub_type = DEVICE_PATH_SUB_TYPE_VENDOR;
46 	dp->vendor.dp.length = sizeof(struct efi_device_path_vendor);
47 	dp->vendor.guid = efi_u_boot_guid;
48 
49 	/* Fill end node */
50 	dp->end.type = DEVICE_PATH_TYPE_END;
51 	dp->end.sub_type = DEVICE_PATH_SUB_TYPE_END;
52 	dp->end.length = sizeof(struct efi_device_path);
53 
54 	/* Install device path protocol */
55 	ret = efi_add_protocol(root, &efi_guid_device_path, dp);
56 	if (ret != EFI_SUCCESS)
57 		goto failure;
58 
59 	/* Install device path to text protocol */
60 	ret = efi_add_protocol(root, &efi_guid_device_path_to_text_protocol,
61 			       (void *)&efi_device_path_to_text);
62 	if (ret != EFI_SUCCESS)
63 		goto failure;
64 
65 	/* Install device path utilities protocol */
66 	ret = efi_add_protocol(root, &efi_guid_device_path_utilities_protocol,
67 			       (void *)&efi_device_path_utilities);
68 	if (ret != EFI_SUCCESS)
69 		goto failure;
70 
71 	/* Install Unicode collation protocol */
72 	ret = efi_add_protocol(root, &efi_guid_unicode_collation_protocol,
73 			       (void *)&efi_unicode_collation_protocol);
74 	if (ret != EFI_SUCCESS)
75 		goto failure;
76 
77 failure:
78 	return ret;
79 }
80