blob: f3ef3eabdae87651acd2315a8736e7ebbe105b8e [file] [log] [blame]
Tom Rini70df9d62018-05-07 17:02:21 -04001// SPDX-License-Identifier: GPL-2.0+
Leif Lindholmb6e6fdc2018-03-09 17:43:21 +01002/*
3 * EFI device path interface
4 *
5 * Copyright (c) 2017 Leif Lindholm
Leif Lindholmb6e6fdc2018-03-09 17:43:21 +01006 */
7
Heinrich Schuchardt955a3212025-01-16 20:26:59 +01008#define LOG_CATEGORY LOGC_EFI
9
Simon Glass37972f42025-05-24 11:28:21 -060010#include <efi_device_path.h>
Leif Lindholmb6e6fdc2018-03-09 17:43:21 +010011#include <efi_loader.h>
12
13const efi_guid_t efi_guid_device_path_utilities_protocol =
14 EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID;
15
Heinrich Schuchardtcb0f7ce2018-04-16 07:59:09 +020016/*
17 * Get size of a device path.
18 *
19 * This function implements the GetDevicePathSize service of the device path
20 * utilities protocol. The device path length includes the end of path tag
21 * which may be an instance end.
22 *
23 * See the Unified Extensible Firmware Interface (UEFI) specification
24 * for details.
25 *
26 * @device_path device path
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010027 * Return: size in bytes
Heinrich Schuchardtcb0f7ce2018-04-16 07:59:09 +020028 */
Leif Lindholmb6e6fdc2018-03-09 17:43:21 +010029static efi_uintn_t EFIAPI get_device_path_size(
30 const struct efi_device_path *device_path)
31{
32 efi_uintn_t sz = 0;
33
Heinrich Schuchardtcb0f7ce2018-04-16 07:59:09 +020034 EFI_ENTRY("%pD", device_path);
Leif Lindholmb6e6fdc2018-03-09 17:43:21 +010035 /* size includes the END node: */
36 if (device_path)
37 sz = efi_dp_size(device_path) + sizeof(struct efi_device_path);
38 return EFI_EXIT(sz);
39}
40
Heinrich Schuchardtcb0f7ce2018-04-16 07:59:09 +020041/*
42 * Duplicate a device path.
43 *
44 * This function implements the DuplicateDevicePath service of the device path
45 * utilities protocol.
46 *
47 * The UEFI spec does not indicate what happens to the end tag. We follow the
48 * EDK2 logic: In case the device path ends with an end of instance tag, the
49 * copy will also end with an end of instance tag.
50 *
51 * See the Unified Extensible Firmware Interface (UEFI) specification
52 * for details.
53 *
54 * @device_path device path
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010055 * Return: copy of the device path
Heinrich Schuchardtcb0f7ce2018-04-16 07:59:09 +020056 */
Leif Lindholmb6e6fdc2018-03-09 17:43:21 +010057static struct efi_device_path * EFIAPI duplicate_device_path(
58 const struct efi_device_path *device_path)
59{
Heinrich Schuchardtcb0f7ce2018-04-16 07:59:09 +020060 EFI_ENTRY("%pD", device_path);
Leif Lindholmb6e6fdc2018-03-09 17:43:21 +010061 return EFI_EXIT(efi_dp_dup(device_path));
62}
63
Heinrich Schuchardtcb0f7ce2018-04-16 07:59:09 +020064/*
65 * Append device path.
66 *
67 * This function implements the AppendDevicePath service of the device path
68 * utilities protocol.
69 *
70 * See the Unified Extensible Firmware Interface (UEFI) specification
71 * for details.
72 *
73 * @src1 1st device path
74 * @src2 2nd device path
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010075 * Return: concatenated device path
Heinrich Schuchardtcb0f7ce2018-04-16 07:59:09 +020076 */
Leif Lindholmb6e6fdc2018-03-09 17:43:21 +010077static struct efi_device_path * EFIAPI append_device_path(
78 const struct efi_device_path *src1,
79 const struct efi_device_path *src2)
80{
Heinrich Schuchardtcb0f7ce2018-04-16 07:59:09 +020081 EFI_ENTRY("%pD, %pD", src1, src2);
Heinrich Schuchardtf8de0092024-05-24 14:54:26 +020082 return EFI_EXIT(efi_dp_concat(src1, src2, 0));
Leif Lindholmb6e6fdc2018-03-09 17:43:21 +010083}
84
Heinrich Schuchardtcb0f7ce2018-04-16 07:59:09 +020085/*
86 * Append device path node.
87 *
88 * This function implements the AppendDeviceNode service of the device path
89 * utilities protocol.
90 *
91 * See the Unified Extensible Firmware Interface (UEFI) specification
92 * for details.
93 *
94 * @device_path device path
95 * @device_node device node
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010096 * Return: concatenated device path
Heinrich Schuchardtcb0f7ce2018-04-16 07:59:09 +020097 */
Leif Lindholmb6e6fdc2018-03-09 17:43:21 +010098static struct efi_device_path * EFIAPI append_device_node(
99 const struct efi_device_path *device_path,
100 const struct efi_device_path *device_node)
101{
Heinrich Schuchardtcb0f7ce2018-04-16 07:59:09 +0200102 EFI_ENTRY("%pD, %p", device_path, device_node);
Leif Lindholmb6e6fdc2018-03-09 17:43:21 +0100103 return EFI_EXIT(efi_dp_append_node(device_path, device_node));
104}
105
Heinrich Schuchardtcb0f7ce2018-04-16 07:59:09 +0200106/*
107 * Append device path instance.
108 *
109 * This function implements the AppendDevicePathInstance service of the device
110 * path utilities protocol.
111 *
112 * See the Unified Extensible Firmware Interface (UEFI) specification
113 * for details.
114 *
115 * @device_path 1st device path
116 * @device_path_instance 2nd device path
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100117 * Return: concatenated device path
Heinrich Schuchardtcb0f7ce2018-04-16 07:59:09 +0200118 */
Leif Lindholmb6e6fdc2018-03-09 17:43:21 +0100119static struct efi_device_path * EFIAPI append_device_path_instance(
120 const struct efi_device_path *device_path,
121 const struct efi_device_path *device_path_instance)
122{
Heinrich Schuchardtcb0f7ce2018-04-16 07:59:09 +0200123 EFI_ENTRY("%pD, %pD", device_path, device_path_instance);
124 return EFI_EXIT(efi_dp_append_instance(device_path,
125 device_path_instance));
Leif Lindholmb6e6fdc2018-03-09 17:43:21 +0100126}
127
Heinrich Schuchardtcb0f7ce2018-04-16 07:59:09 +0200128/*
129 * Get next device path instance.
130 *
131 * This function implements the GetNextDevicePathInstance service of the device
132 * path utilities protocol.
133 *
134 * See the Unified Extensible Firmware Interface (UEFI) specification
135 * for details.
136 *
137 * @device_path_instance next device path instance
138 * @device_path_instance_size size of the device path instance
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100139 * Return: concatenated device path
Heinrich Schuchardtcb0f7ce2018-04-16 07:59:09 +0200140 */
Leif Lindholmb6e6fdc2018-03-09 17:43:21 +0100141static struct efi_device_path * EFIAPI get_next_device_path_instance(
142 struct efi_device_path **device_path_instance,
143 efi_uintn_t *device_path_instance_size)
144{
Heinrich Schuchardtcb0f7ce2018-04-16 07:59:09 +0200145 EFI_ENTRY("%pD, %p", device_path_instance, device_path_instance_size);
146 return EFI_EXIT(efi_dp_get_next_instance(device_path_instance,
147 device_path_instance_size));
Leif Lindholmb6e6fdc2018-03-09 17:43:21 +0100148}
149
Heinrich Schuchardtcb0f7ce2018-04-16 07:59:09 +0200150/*
151 * Check if a device path contains more than one instance.
152 *
153 * This function implements the AppendDeviceNode service of the device path
154 * utilities protocol.
155 *
156 * See the Unified Extensible Firmware Interface (UEFI) specification
157 * for details.
158 *
159 * @device_path device path
160 * @device_node device node
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100161 * Return: concatenated device path
Heinrich Schuchardtcb0f7ce2018-04-16 07:59:09 +0200162 */
Leif Lindholmb6e6fdc2018-03-09 17:43:21 +0100163static bool EFIAPI is_device_path_multi_instance(
164 const struct efi_device_path *device_path)
165{
Heinrich Schuchardtcb0f7ce2018-04-16 07:59:09 +0200166 EFI_ENTRY("%pD", device_path);
167 return EFI_EXIT(efi_dp_is_multi_instance(device_path));
Leif Lindholmb6e6fdc2018-03-09 17:43:21 +0100168}
169
Heinrich Schuchardtb41c8e22018-04-16 07:59:05 +0200170/*
171 * Create device node.
172 *
173 * This function implements the CreateDeviceNode service of the device path
174 * utilities protocol.
175 *
176 * See the Unified Extensible Firmware Interface (UEFI) specification
177 * for details.
178 *
179 * @node_type node type
180 * @node_sub_type node sub type
181 * @node_length node length
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100182 * Return: device path node
Heinrich Schuchardtb41c8e22018-04-16 07:59:05 +0200183 */
Leif Lindholmb6e6fdc2018-03-09 17:43:21 +0100184static struct efi_device_path * EFIAPI create_device_node(
185 uint8_t node_type, uint8_t node_sub_type, uint16_t node_length)
186{
187 EFI_ENTRY("%u, %u, %u", node_type, node_sub_type, node_length);
Heinrich Schuchardtb41c8e22018-04-16 07:59:05 +0200188 return EFI_EXIT(efi_dp_create_device_node(node_type, node_sub_type,
189 node_length));
Leif Lindholmb6e6fdc2018-03-09 17:43:21 +0100190}
191
192const struct efi_device_path_utilities_protocol efi_device_path_utilities = {
193 .get_device_path_size = get_device_path_size,
194 .duplicate_device_path = duplicate_device_path,
195 .append_device_path = append_device_path,
196 .append_device_node = append_device_node,
197 .append_device_path_instance = append_device_path_instance,
198 .get_next_device_path_instance = get_next_device_path_instance,
199 .is_device_path_multi_instance = is_device_path_multi_instance,
200 .create_device_node = create_device_node,
201};