]>
Commit | Line | Data |
---|---|---|
7dbc50bd YZ |
1 | /** @file\r |
2 | Device Path services. The thing to remember is device paths are built out of\r | |
3 | nodes. The device path is terminated by an end node that is length\r | |
4 | sizeof(EFI_DEVICE_PATH_PROTOCOL). That would be why there is sizeof(EFI_DEVICE_PATH_PROTOCOL)\r | |
5 | all over this file.\r | |
6 | \r | |
7 | The only place where multi-instance device paths are supported is in\r | |
8 | environment varibles. Multi-instance device paths should never be placed\r | |
9 | on a Handle.\r | |
10 | \r | |
11 | Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r | |
12 | This program and the accompanying materials\r | |
13 | are licensed and made available under the terms and conditions of the BSD License\r | |
14 | which accompanies this distribution. The full text of the license may be found at\r | |
15 | http://opensource.org/licenses/bsd-license.php.\r | |
16 | \r | |
17 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
18 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
19 | \r | |
20 | **/\r | |
21 | \r | |
22 | \r | |
23 | #include "UefiDevicePathLib.h"\r | |
24 | \r | |
25 | /**\r | |
26 | Returns the size of a device path in bytes.\r | |
27 | \r | |
28 | This function returns the size, in bytes, of the device path data structure\r | |
29 | specified by DevicePath including the end of device path node.\r | |
30 | If DevicePath is NULL or invalid, then 0 is returned.\r | |
31 | \r | |
32 | @param DevicePath A pointer to a device path data structure.\r | |
33 | \r | |
34 | @retval 0 If DevicePath is NULL or invalid.\r | |
35 | @retval Others The size of a device path in bytes.\r | |
36 | \r | |
37 | **/\r | |
38 | UINTN\r | |
39 | GetDevicePathSize (\r | |
40 | CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
41 | )\r | |
42 | {\r | |
43 | return UefiDevicePathLibGetDevicePathSize (DevicePath);\r | |
44 | }\r | |
45 | \r | |
46 | /**\r | |
47 | Creates a new copy of an existing device path.\r | |
48 | \r | |
49 | This function allocates space for a new copy of the device path specified by DevicePath.\r | |
50 | If DevicePath is NULL, then NULL is returned. If the memory is successfully\r | |
51 | allocated, then the contents of DevicePath are copied to the newly allocated\r | |
52 | buffer, and a pointer to that buffer is returned. Otherwise, NULL is returned.\r | |
53 | The memory for the new device path is allocated from EFI boot services memory.\r | |
54 | It is the responsibility of the caller to free the memory allocated.\r | |
55 | \r | |
56 | @param DevicePath A pointer to a device path data structure.\r | |
57 | \r | |
58 | @retval NULL DevicePath is NULL or invalid.\r | |
59 | @retval Others A pointer to the duplicated device path.\r | |
60 | \r | |
61 | **/\r | |
62 | EFI_DEVICE_PATH_PROTOCOL *\r | |
63 | DuplicateDevicePath (\r | |
64 | CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
65 | )\r | |
66 | {\r | |
67 | return UefiDevicePathLibDuplicateDevicePath (DevicePath);\r | |
68 | }\r | |
69 | \r | |
70 | /**\r | |
71 | Creates a new device path by appending a second device path to a first device path.\r | |
72 | \r | |
73 | This function creates a new device path by appending a copy of SecondDevicePath\r | |
74 | to a copy of FirstDevicePath in a newly allocated buffer. Only the end-of-device-path\r | |
75 | device node from SecondDevicePath is retained. The newly created device path is\r | |
76 | returned. If FirstDevicePath is NULL, then it is ignored, and a duplicate of\r | |
77 | SecondDevicePath is returned. If SecondDevicePath is NULL, then it is ignored,\r | |
78 | and a duplicate of FirstDevicePath is returned. If both FirstDevicePath and\r | |
79 | SecondDevicePath are NULL, then a copy of an end-of-device-path is returned.\r | |
80 | \r | |
81 | If there is not enough memory for the newly allocated buffer, then NULL is returned.\r | |
82 | The memory for the new device path is allocated from EFI boot services memory.\r | |
83 | It is the responsibility of the caller to free the memory allocated.\r | |
84 | \r | |
85 | @param FirstDevicePath A pointer to a device path data structure.\r | |
86 | @param SecondDevicePath A pointer to a device path data structure.\r | |
87 | \r | |
88 | @retval NULL If there is not enough memory for the newly allocated buffer.\r | |
89 | @retval NULL If FirstDevicePath or SecondDevicePath is invalid.\r | |
90 | @retval Others A pointer to the new device path if success.\r | |
91 | Or a copy an end-of-device-path if both FirstDevicePath and SecondDevicePath are NULL.\r | |
92 | \r | |
93 | **/\r | |
94 | EFI_DEVICE_PATH_PROTOCOL *\r | |
95 | AppendDevicePath (\r | |
96 | CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath, OPTIONAL\r | |
97 | CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL\r | |
98 | )\r | |
99 | {\r | |
100 | return UefiDevicePathLibAppendDevicePath (FirstDevicePath, SecondDevicePath);\r | |
101 | }\r | |
102 | \r | |
103 | /**\r | |
104 | Creates a new path by appending the device node to the device path.\r | |
105 | \r | |
106 | This function creates a new device path by appending a copy of the device node\r | |
107 | specified by DevicePathNode to a copy of the device path specified by DevicePath\r | |
108 | in an allocated buffer. The end-of-device-path device node is moved after the\r | |
109 | end of the appended device node.\r | |
110 | If DevicePathNode is NULL then a copy of DevicePath is returned.\r | |
111 | If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device\r | |
112 | path device node is returned.\r | |
113 | If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path\r | |
114 | device node is returned.\r | |
115 | If there is not enough memory to allocate space for the new device path, then\r | |
116 | NULL is returned.\r | |
117 | The memory is allocated from EFI boot services memory. It is the responsibility\r | |
118 | of the caller to free the memory allocated.\r | |
119 | \r | |
120 | @param DevicePath A pointer to a device path data structure.\r | |
121 | @param DevicePathNode A pointer to a single device path node.\r | |
122 | \r | |
123 | @retval NULL If there is not enough memory for the new device path.\r | |
124 | @retval Others A pointer to the new device path if success.\r | |
125 | A copy of DevicePathNode followed by an end-of-device-path node\r | |
126 | if both FirstDevicePath and SecondDevicePath are NULL.\r | |
127 | A copy of an end-of-device-path node if both FirstDevicePath\r | |
128 | and SecondDevicePath are NULL.\r | |
129 | \r | |
130 | **/\r | |
131 | EFI_DEVICE_PATH_PROTOCOL *\r | |
132 | AppendDevicePathNode (\r | |
133 | CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL\r | |
134 | CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL\r | |
135 | )\r | |
136 | {\r | |
137 | return UefiDevicePathLibAppendDevicePathNode (DevicePath, DevicePathNode);\r | |
138 | }\r | |
139 | \r | |
140 | /**\r | |
141 | Creates a new device path by appending the specified device path instance to the specified device\r | |
142 | path.\r | |
143 | \r | |
144 | This function creates a new device path by appending a copy of the device path\r | |
145 | instance specified by DevicePathInstance to a copy of the device path specified\r | |
146 | by DevicePath in a allocated buffer.\r | |
147 | The end-of-device-path device node is moved after the end of the appended device\r | |
148 | path instance and a new end-of-device-path-instance node is inserted between.\r | |
149 | If DevicePath is NULL, then a copy if DevicePathInstance is returned.\r | |
150 | If DevicePathInstance is NULL, then NULL is returned.\r | |
151 | If DevicePath or DevicePathInstance is invalid, then NULL is returned.\r | |
152 | If there is not enough memory to allocate space for the new device path, then\r | |
153 | NULL is returned.\r | |
154 | The memory is allocated from EFI boot services memory. It is the responsibility\r | |
155 | of the caller to free the memory allocated.\r | |
156 | \r | |
157 | @param DevicePath A pointer to a device path data structure.\r | |
158 | @param DevicePathInstance A pointer to a device path instance.\r | |
159 | \r | |
160 | @return A pointer to the new device path.\r | |
161 | \r | |
162 | **/\r | |
163 | EFI_DEVICE_PATH_PROTOCOL *\r | |
164 | AppendDevicePathInstance (\r | |
165 | CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL\r | |
166 | CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL\r | |
167 | )\r | |
168 | {\r | |
169 | return UefiDevicePathLibAppendDevicePathInstance (DevicePath, DevicePathInstance);\r | |
170 | }\r | |
171 | \r | |
172 | /**\r | |
173 | Creates a copy of the current device path instance and returns a pointer to the next device path\r | |
174 | instance.\r | |
175 | \r | |
176 | This function creates a copy of the current device path instance. It also updates\r | |
177 | DevicePath to point to the next device path instance in the device path (or NULL\r | |
178 | if no more) and updates Size to hold the size of the device path instance copy.\r | |
179 | If DevicePath is NULL, then NULL is returned.\r | |
180 | If DevicePath points to a invalid device path, then NULL is returned.\r | |
181 | If there is not enough memory to allocate space for the new device path, then\r | |
182 | NULL is returned.\r | |
183 | The memory is allocated from EFI boot services memory. It is the responsibility\r | |
184 | of the caller to free the memory allocated.\r | |
185 | If Size is NULL, then ASSERT().\r | |
186 | \r | |
187 | @param DevicePath On input, this holds the pointer to the current\r | |
188 | device path instance. On output, this holds\r | |
189 | the pointer to the next device path instance\r | |
190 | or NULL if there are no more device path\r | |
191 | instances in the device path pointer to a\r | |
192 | device path data structure.\r | |
193 | @param Size On output, this holds the size of the device\r | |
194 | path instance, in bytes or zero, if DevicePath\r | |
195 | is NULL.\r | |
196 | \r | |
197 | @return A pointer to the current device path instance.\r | |
198 | \r | |
199 | **/\r | |
200 | EFI_DEVICE_PATH_PROTOCOL *\r | |
201 | GetNextDevicePathInstance (\r | |
202 | EFI_DEVICE_PATH_PROTOCOL **DevicePath,\r | |
203 | UINTN *Size\r | |
204 | )\r | |
205 | {\r | |
206 | return UefiDevicePathLibGetNextDevicePathInstance (DevicePath, Size);\r | |
207 | }\r | |
208 | \r | |
209 | /**\r | |
210 | Creates a device node.\r | |
211 | \r | |
212 | This function creates a new device node in a newly allocated buffer of size\r | |
213 | NodeLength and initializes the device path node header with NodeType and NodeSubType.\r | |
214 | The new device path node is returned.\r | |
215 | If NodeLength is smaller than a device path header, then NULL is returned.\r | |
216 | If there is not enough memory to allocate space for the new device path, then\r | |
217 | NULL is returned.\r | |
218 | The memory is allocated from EFI boot services memory. It is the responsibility\r | |
219 | of the caller to free the memory allocated.\r | |
220 | \r | |
221 | @param NodeType The device node type for the new device node.\r | |
222 | @param NodeSubType The device node sub-type for the new device node.\r | |
223 | @param NodeLength The length of the new device node.\r | |
224 | \r | |
225 | @return The new device path.\r | |
226 | \r | |
227 | **/\r | |
228 | EFI_DEVICE_PATH_PROTOCOL *\r | |
229 | CreateDeviceNode (\r | |
230 | UINT8 NodeType,\r | |
231 | UINT8 NodeSubType,\r | |
232 | UINT16 NodeLength\r | |
233 | )\r | |
234 | {\r | |
235 | return UefiDevicePathLibCreateDeviceNode (NodeType, NodeSubType, NodeLength);\r | |
236 | }\r | |
237 | \r | |
238 | /**\r | |
239 | Determines if a device path is single or multi-instance.\r | |
240 | \r | |
241 | This function returns TRUE if the device path specified by DevicePath is\r | |
242 | multi-instance.\r | |
243 | Otherwise, FALSE is returned.\r | |
244 | If DevicePath is NULL or invalid, then FALSE is returned.\r | |
245 | \r | |
246 | @param DevicePath A pointer to a device path data structure.\r | |
247 | \r | |
248 | @retval TRUE DevicePath is multi-instance.\r | |
249 | @retval FALSE DevicePath is not multi-instance, or DevicePath\r | |
250 | is NULL or invalid.\r | |
251 | \r | |
252 | **/\r | |
253 | BOOLEAN\r | |
254 | IsDevicePathMultiInstance (\r | |
255 | CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
256 | )\r | |
257 | {\r | |
258 | return UefiDevicePathLibIsDevicePathMultiInstance (DevicePath);\r | |
259 | }\r | |
260 | \r | |
261 | /**\r | |
262 | Convert text to the binary representation of a device node.\r | |
263 | \r | |
264 | @param TextDeviceNode TextDeviceNode points to the text representation of a device\r | |
265 | node. Conversion starts with the first character and continues\r | |
266 | until the first non-device node character.\r | |
267 | \r | |
268 | @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was\r | |
269 | insufficient memory or text unsupported.\r | |
270 | \r | |
271 | **/\r | |
272 | EFI_DEVICE_PATH_PROTOCOL *\r | |
273 | ConvertTextToDeviceNode (\r | |
274 | CONST CHAR16 *TextDeviceNode\r | |
275 | )\r | |
276 | {\r | |
277 | return UefiDevicePathLibConvertTextToDeviceNode (TextDeviceNode);\r | |
278 | }\r | |
279 | \r | |
280 | /**\r | |
281 | Convert text to the binary representation of a device path.\r | |
282 | \r | |
283 | \r | |
284 | @param TextDevicePath TextDevicePath points to the text representation of a device\r | |
285 | path. Conversion starts with the first character and continues\r | |
286 | until the first non-device node character.\r | |
287 | \r | |
288 | @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or\r | |
289 | there was insufficient memory.\r | |
290 | \r | |
291 | **/\r | |
292 | EFI_DEVICE_PATH_PROTOCOL *\r | |
293 | ConvertTextToDevicePath (\r | |
294 | CONST CHAR16 *TextDevicePath\r | |
295 | )\r | |
296 | {\r | |
297 | return UefiDevicePathLibConvertTextToDevicePath (TextDevicePath);\r | |
298 | }\r |