1*22ce4affSfengbojiang /** @file
2*22ce4affSfengbojiang   Provides library functions to construct and parse UEFI Device Paths.
3*22ce4affSfengbojiang 
4*22ce4affSfengbojiang   This library provides defines, macros, and functions to help create and parse
5*22ce4affSfengbojiang   EFI_DEVICE_PATH_PROTOCOL structures.
6*22ce4affSfengbojiang 
7*22ce4affSfengbojiang Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
8*22ce4affSfengbojiang SPDX-License-Identifier: BSD-2-Clause-Patent
9*22ce4affSfengbojiang 
10*22ce4affSfengbojiang **/
11*22ce4affSfengbojiang 
12*22ce4affSfengbojiang #ifndef __DEVICE_PATH_LIB_H__
13*22ce4affSfengbojiang #define __DEVICE_PATH_LIB_H__
14*22ce4affSfengbojiang 
15*22ce4affSfengbojiang #define END_DEVICE_PATH_LENGTH               (sizeof (EFI_DEVICE_PATH_PROTOCOL))
16*22ce4affSfengbojiang 
17*22ce4affSfengbojiang /**
18*22ce4affSfengbojiang   Determine whether a given device path is valid.
19*22ce4affSfengbojiang 
20*22ce4affSfengbojiang   @param  DevicePath  A pointer to a device path data structure.
21*22ce4affSfengbojiang   @param  MaxSize     The maximum size of the device path data structure.
22*22ce4affSfengbojiang 
23*22ce4affSfengbojiang   @retval TRUE        DevicePath is valid.
24*22ce4affSfengbojiang   @retval FALSE       DevicePath is NULL.
25*22ce4affSfengbojiang   @retval FALSE       Maxsize is less than sizeof(EFI_DEVICE_PATH_PROTOCOL).
26*22ce4affSfengbojiang   @retval FALSE       The length of any node node in the DevicePath is less
27*22ce4affSfengbojiang                       than sizeof (EFI_DEVICE_PATH_PROTOCOL).
28*22ce4affSfengbojiang   @retval FALSE       If MaxSize is not zero, the size of the DevicePath
29*22ce4affSfengbojiang                       exceeds MaxSize.
30*22ce4affSfengbojiang   @retval FALSE       If PcdMaximumDevicePathNodeCount is not zero, the node
31*22ce4affSfengbojiang                       count of the DevicePath exceeds PcdMaximumDevicePathNodeCount.
32*22ce4affSfengbojiang **/
33*22ce4affSfengbojiang BOOLEAN
34*22ce4affSfengbojiang EFIAPI
35*22ce4affSfengbojiang IsDevicePathValid (
36*22ce4affSfengbojiang   IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
37*22ce4affSfengbojiang   IN       UINTN                    MaxSize
38*22ce4affSfengbojiang   );
39*22ce4affSfengbojiang 
40*22ce4affSfengbojiang /**
41*22ce4affSfengbojiang   Returns the Type field of a device path node.
42*22ce4affSfengbojiang 
43*22ce4affSfengbojiang   Returns the Type field of the device path node specified by Node.
44*22ce4affSfengbojiang 
45*22ce4affSfengbojiang   If Node is NULL, then ASSERT().
46*22ce4affSfengbojiang 
47*22ce4affSfengbojiang   @param  Node      A pointer to a device path node data structure.
48*22ce4affSfengbojiang 
49*22ce4affSfengbojiang   @return The Type field of the device path node specified by Node.
50*22ce4affSfengbojiang 
51*22ce4affSfengbojiang **/
52*22ce4affSfengbojiang UINT8
53*22ce4affSfengbojiang EFIAPI
54*22ce4affSfengbojiang DevicePathType (
55*22ce4affSfengbojiang   IN CONST VOID  *Node
56*22ce4affSfengbojiang   );
57*22ce4affSfengbojiang 
58*22ce4affSfengbojiang /**
59*22ce4affSfengbojiang   Returns the SubType field of a device path node.
60*22ce4affSfengbojiang 
61*22ce4affSfengbojiang   Returns the SubType field of the device path node specified by Node.
62*22ce4affSfengbojiang 
63*22ce4affSfengbojiang   If Node is NULL, then ASSERT().
64*22ce4affSfengbojiang 
65*22ce4affSfengbojiang   @param  Node      A pointer to a device path node data structure.
66*22ce4affSfengbojiang 
67*22ce4affSfengbojiang   @return The SubType field of the device path node specified by Node.
68*22ce4affSfengbojiang 
69*22ce4affSfengbojiang **/
70*22ce4affSfengbojiang UINT8
71*22ce4affSfengbojiang EFIAPI
72*22ce4affSfengbojiang DevicePathSubType (
73*22ce4affSfengbojiang   IN CONST VOID  *Node
74*22ce4affSfengbojiang   );
75*22ce4affSfengbojiang 
76*22ce4affSfengbojiang /**
77*22ce4affSfengbojiang   Returns the 16-bit Length field of a device path node.
78*22ce4affSfengbojiang 
79*22ce4affSfengbojiang   Returns the 16-bit Length field of the device path node specified by Node.
80*22ce4affSfengbojiang   Node is not required to be aligned on a 16-bit boundary, so it is recommended
81*22ce4affSfengbojiang   that a function such as ReadUnaligned16() be used to extract the contents of
82*22ce4affSfengbojiang   the Length field.
83*22ce4affSfengbojiang 
84*22ce4affSfengbojiang   If Node is NULL, then ASSERT().
85*22ce4affSfengbojiang 
86*22ce4affSfengbojiang   @param  Node      A pointer to a device path node data structure.
87*22ce4affSfengbojiang 
88*22ce4affSfengbojiang   @return The 16-bit Length field of the device path node specified by Node.
89*22ce4affSfengbojiang 
90*22ce4affSfengbojiang **/
91*22ce4affSfengbojiang UINTN
92*22ce4affSfengbojiang EFIAPI
93*22ce4affSfengbojiang DevicePathNodeLength (
94*22ce4affSfengbojiang   IN CONST VOID  *Node
95*22ce4affSfengbojiang   );
96*22ce4affSfengbojiang 
97*22ce4affSfengbojiang /**
98*22ce4affSfengbojiang   Returns a pointer to the next node in a device path.
99*22ce4affSfengbojiang 
100*22ce4affSfengbojiang   Returns a pointer to the device path node that follows the device path node specified by Node.
101*22ce4affSfengbojiang 
102*22ce4affSfengbojiang   If Node is NULL, then ASSERT().
103*22ce4affSfengbojiang 
104*22ce4affSfengbojiang   @param  Node      A pointer to a device path node data structure.
105*22ce4affSfengbojiang 
106*22ce4affSfengbojiang   @return a pointer to the device path node that follows the device path node specified by Node.
107*22ce4affSfengbojiang 
108*22ce4affSfengbojiang **/
109*22ce4affSfengbojiang EFI_DEVICE_PATH_PROTOCOL *
110*22ce4affSfengbojiang EFIAPI
111*22ce4affSfengbojiang NextDevicePathNode (
112*22ce4affSfengbojiang   IN CONST VOID  *Node
113*22ce4affSfengbojiang   );
114*22ce4affSfengbojiang 
115*22ce4affSfengbojiang /**
116*22ce4affSfengbojiang   Determines if a device path node is an end node of a device path.
117*22ce4affSfengbojiang   This includes nodes that are the end of a device path instance and nodes that
118*22ce4affSfengbojiang   are the end of an entire device path.
119*22ce4affSfengbojiang 
120*22ce4affSfengbojiang   Determines if the device path node specified by Node is an end node of a device path.
121*22ce4affSfengbojiang   This includes nodes that are the end of a device path instance and nodes that are the
122*22ce4affSfengbojiang   end of an entire device path.  If Node represents an end node of a device path,
123*22ce4affSfengbojiang   then TRUE is returned.  Otherwise, FALSE is returned.
124*22ce4affSfengbojiang 
125*22ce4affSfengbojiang   If Node is NULL, then ASSERT().
126*22ce4affSfengbojiang 
127*22ce4affSfengbojiang   @param  Node      A pointer to a device path node data structure.
128*22ce4affSfengbojiang 
129*22ce4affSfengbojiang   @retval TRUE      The device path node specified by Node is an end node of a device path.
130*22ce4affSfengbojiang   @retval FALSE     The device path node specified by Node is not an end node of a device path.
131*22ce4affSfengbojiang 
132*22ce4affSfengbojiang **/
133*22ce4affSfengbojiang BOOLEAN
134*22ce4affSfengbojiang EFIAPI
135*22ce4affSfengbojiang IsDevicePathEndType (
136*22ce4affSfengbojiang   IN CONST VOID  *Node
137*22ce4affSfengbojiang   );
138*22ce4affSfengbojiang 
139*22ce4affSfengbojiang /**
140*22ce4affSfengbojiang   Determines if a device path node is an end node of an entire device path.
141*22ce4affSfengbojiang 
142*22ce4affSfengbojiang   Determines if a device path node specified by Node is an end node of an entire device path.
143*22ce4affSfengbojiang   If Node represents the end of an entire device path, then TRUE is returned.
144*22ce4affSfengbojiang   Otherwise, FALSE is returned.
145*22ce4affSfengbojiang 
146*22ce4affSfengbojiang   If Node is NULL, then ASSERT().
147*22ce4affSfengbojiang 
148*22ce4affSfengbojiang   @param  Node      A pointer to a device path node data structure.
149*22ce4affSfengbojiang 
150*22ce4affSfengbojiang   @retval TRUE      The device path node specified by Node is the end of an entire device path.
151*22ce4affSfengbojiang   @retval FALSE     The device path node specified by Node is not the end of an entire device path.
152*22ce4affSfengbojiang 
153*22ce4affSfengbojiang **/
154*22ce4affSfengbojiang BOOLEAN
155*22ce4affSfengbojiang EFIAPI
156*22ce4affSfengbojiang IsDevicePathEnd (
157*22ce4affSfengbojiang   IN CONST VOID  *Node
158*22ce4affSfengbojiang   );
159*22ce4affSfengbojiang 
160*22ce4affSfengbojiang /**
161*22ce4affSfengbojiang   Determines if a device path node is an end node of a device path instance.
162*22ce4affSfengbojiang 
163*22ce4affSfengbojiang   Determines if a device path node specified by Node is an end node of a device path instance.
164*22ce4affSfengbojiang   If Node represents the end of a device path instance, then TRUE is returned.
165*22ce4affSfengbojiang   Otherwise, FALSE is returned.
166*22ce4affSfengbojiang 
167*22ce4affSfengbojiang   If Node is NULL, then ASSERT().
168*22ce4affSfengbojiang 
169*22ce4affSfengbojiang   @param  Node      A pointer to a device path node data structure.
170*22ce4affSfengbojiang 
171*22ce4affSfengbojiang   @retval TRUE      The device path node specified by Node is the end of a device path instance.
172*22ce4affSfengbojiang   @retval FALSE     The device path node specified by Node is not the end of a device path instance.
173*22ce4affSfengbojiang 
174*22ce4affSfengbojiang **/
175*22ce4affSfengbojiang BOOLEAN
176*22ce4affSfengbojiang EFIAPI
177*22ce4affSfengbojiang IsDevicePathEndInstance (
178*22ce4affSfengbojiang   IN CONST VOID  *Node
179*22ce4affSfengbojiang   );
180*22ce4affSfengbojiang 
181*22ce4affSfengbojiang /**
182*22ce4affSfengbojiang   Sets the length, in bytes, of a device path node.
183*22ce4affSfengbojiang 
184*22ce4affSfengbojiang   Sets the length of the device path node specified by Node to the value specified
185*22ce4affSfengbojiang   by NodeLength.  NodeLength is returned.  Node is not required to be aligned on
186*22ce4affSfengbojiang   a 16-bit boundary, so it is recommended that a function such as WriteUnaligned16()
187*22ce4affSfengbojiang   be used to set the contents of the Length field.
188*22ce4affSfengbojiang 
189*22ce4affSfengbojiang   If Node is NULL, then ASSERT().
190*22ce4affSfengbojiang   If NodeLength >= 0x10000, then ASSERT().
191*22ce4affSfengbojiang   If NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL), then ASSERT().
192*22ce4affSfengbojiang 
193*22ce4affSfengbojiang   @param  Node      A pointer to a device path node data structure.
194*22ce4affSfengbojiang   @param  Length    The length, in bytes, of the device path node.
195*22ce4affSfengbojiang 
196*22ce4affSfengbojiang   @return Length
197*22ce4affSfengbojiang 
198*22ce4affSfengbojiang **/
199*22ce4affSfengbojiang UINT16
200*22ce4affSfengbojiang EFIAPI
201*22ce4affSfengbojiang SetDevicePathNodeLength (
202*22ce4affSfengbojiang   IN OUT VOID  *Node,
203*22ce4affSfengbojiang   IN UINTN     Length
204*22ce4affSfengbojiang   );
205*22ce4affSfengbojiang 
206*22ce4affSfengbojiang /**
207*22ce4affSfengbojiang   Fills in all the fields of a device path node that is the end of an entire device path.
208*22ce4affSfengbojiang 
209*22ce4affSfengbojiang   Fills in all the fields of a device path node specified by Node so Node represents
210*22ce4affSfengbojiang   the end of an entire device path.  The Type field of Node is set to
211*22ce4affSfengbojiang   END_DEVICE_PATH_TYPE, the SubType field of Node is set to
212*22ce4affSfengbojiang   END_ENTIRE_DEVICE_PATH_SUBTYPE, and the Length field of Node is set to
213*22ce4affSfengbojiang   END_DEVICE_PATH_LENGTH.  Node is not required to be aligned on a 16-bit boundary,
214*22ce4affSfengbojiang   so it is recommended that a function such as WriteUnaligned16() be used to set
215*22ce4affSfengbojiang   the contents of the Length field.
216*22ce4affSfengbojiang 
217*22ce4affSfengbojiang   If Node is NULL, then ASSERT().
218*22ce4affSfengbojiang 
219*22ce4affSfengbojiang   @param  Node      A pointer to a device path node data structure.
220*22ce4affSfengbojiang 
221*22ce4affSfengbojiang **/
222*22ce4affSfengbojiang VOID
223*22ce4affSfengbojiang EFIAPI
224*22ce4affSfengbojiang SetDevicePathEndNode (
225*22ce4affSfengbojiang   OUT VOID  *Node
226*22ce4affSfengbojiang   );
227*22ce4affSfengbojiang 
228*22ce4affSfengbojiang /**
229*22ce4affSfengbojiang   Returns the size of a device path in bytes.
230*22ce4affSfengbojiang 
231*22ce4affSfengbojiang   This function returns the size, in bytes, of the device path data structure
232*22ce4affSfengbojiang   specified by DevicePath including the end of device path node.
233*22ce4affSfengbojiang   If DevicePath is NULL or invalid, then 0 is returned.
234*22ce4affSfengbojiang 
235*22ce4affSfengbojiang   @param  DevicePath  A pointer to a device path data structure.
236*22ce4affSfengbojiang 
237*22ce4affSfengbojiang   @retval 0           If DevicePath is NULL or invalid.
238*22ce4affSfengbojiang   @retval Others      The size of a device path in bytes.
239*22ce4affSfengbojiang 
240*22ce4affSfengbojiang **/
241*22ce4affSfengbojiang UINTN
242*22ce4affSfengbojiang EFIAPI
243*22ce4affSfengbojiang GetDevicePathSize (
244*22ce4affSfengbojiang   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath
245*22ce4affSfengbojiang   );
246*22ce4affSfengbojiang 
247*22ce4affSfengbojiang /**
248*22ce4affSfengbojiang   Creates a new copy of an existing device path.
249*22ce4affSfengbojiang 
250*22ce4affSfengbojiang   This function allocates space for a new copy of the device path specified by DevicePath.  If
251*22ce4affSfengbojiang   DevicePath is NULL, then NULL is returned.  If the memory is successfully allocated, then the
252*22ce4affSfengbojiang   contents of DevicePath are copied to the newly allocated buffer, and a pointer to that buffer
253*22ce4affSfengbojiang   is returned.  Otherwise, NULL is returned.
254*22ce4affSfengbojiang   The memory for the new device path is allocated from EFI boot services memory.
255*22ce4affSfengbojiang   It is the responsibility of the caller to free the memory allocated.
256*22ce4affSfengbojiang 
257*22ce4affSfengbojiang   @param  DevicePath                 A pointer to a device path data structure.
258*22ce4affSfengbojiang 
259*22ce4affSfengbojiang   @retval NULL    DevicePath is NULL or invalid.
260*22ce4affSfengbojiang   @retval Others  A pointer to the duplicated device path.
261*22ce4affSfengbojiang 
262*22ce4affSfengbojiang **/
263*22ce4affSfengbojiang EFI_DEVICE_PATH_PROTOCOL *
264*22ce4affSfengbojiang EFIAPI
265*22ce4affSfengbojiang DuplicateDevicePath (
266*22ce4affSfengbojiang   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath
267*22ce4affSfengbojiang   );
268*22ce4affSfengbojiang 
269*22ce4affSfengbojiang /**
270*22ce4affSfengbojiang   Creates a new device path by appending a second device path to a first device path.
271*22ce4affSfengbojiang 
272*22ce4affSfengbojiang   This function creates a new device path by appending a copy of SecondDevicePath to a copy of
273*22ce4affSfengbojiang   FirstDevicePath in a newly allocated buffer.  Only the end-of-device-path device node from
274*22ce4affSfengbojiang   SecondDevicePath is retained. The newly created device path is returned.
275*22ce4affSfengbojiang   If FirstDevicePath is NULL, then it is ignored, and a duplicate of SecondDevicePath is returned.
276*22ce4affSfengbojiang   If SecondDevicePath is NULL, then it is ignored, and a duplicate of FirstDevicePath is returned.
277*22ce4affSfengbojiang   If both FirstDevicePath and SecondDevicePath are NULL, then a copy of an end-of-device-path is
278*22ce4affSfengbojiang   returned.
279*22ce4affSfengbojiang   If there is not enough memory for the newly allocated buffer, then NULL is returned.
280*22ce4affSfengbojiang   The memory for the new device path is allocated from EFI boot services memory. It is the
281*22ce4affSfengbojiang   responsibility of the caller to free the memory allocated.
282*22ce4affSfengbojiang 
283*22ce4affSfengbojiang   @param  FirstDevicePath            A pointer to a device path data structure.
284*22ce4affSfengbojiang   @param  SecondDevicePath           A pointer to a device path data structure.
285*22ce4affSfengbojiang 
286*22ce4affSfengbojiang   @retval NULL      If there is not enough memory for the newly allocated buffer.
287*22ce4affSfengbojiang   @retval NULL      If FirstDevicePath or SecondDevicePath is invalid.
288*22ce4affSfengbojiang   @retval Others    A pointer to the new device path if success.
289*22ce4affSfengbojiang                     Or a copy an end-of-device-path if both FirstDevicePath and SecondDevicePath are NULL.
290*22ce4affSfengbojiang 
291*22ce4affSfengbojiang **/
292*22ce4affSfengbojiang EFI_DEVICE_PATH_PROTOCOL *
293*22ce4affSfengbojiang EFIAPI
294*22ce4affSfengbojiang AppendDevicePath (
295*22ce4affSfengbojiang   IN CONST EFI_DEVICE_PATH_PROTOCOL  *FirstDevicePath,  OPTIONAL
296*22ce4affSfengbojiang   IN CONST EFI_DEVICE_PATH_PROTOCOL  *SecondDevicePath  OPTIONAL
297*22ce4affSfengbojiang   );
298*22ce4affSfengbojiang 
299*22ce4affSfengbojiang /**
300*22ce4affSfengbojiang   Creates a new path by appending the device node to the device path.
301*22ce4affSfengbojiang 
302*22ce4affSfengbojiang   This function creates a new device path by appending a copy of the device node specified by
303*22ce4affSfengbojiang   DevicePathNode to a copy of the device path specified by DevicePath in an allocated buffer.
304*22ce4affSfengbojiang   The end-of-device-path device node is moved after the end of the appended device node.
305*22ce4affSfengbojiang   If DevicePathNode is NULL then a copy of DevicePath is returned.
306*22ce4affSfengbojiang   If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device path device
307*22ce4affSfengbojiang   node is returned.
308*22ce4affSfengbojiang   If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path device node
309*22ce4affSfengbojiang   is returned.
310*22ce4affSfengbojiang   If there is not enough memory to allocate space for the new device path, then NULL is returned.
311*22ce4affSfengbojiang   The memory is allocated from EFI boot services memory. It is the responsibility of the caller to
312*22ce4affSfengbojiang   free the memory allocated.
313*22ce4affSfengbojiang 
314*22ce4affSfengbojiang   @param  DevicePath                 A pointer to a device path data structure.
315*22ce4affSfengbojiang   @param  DevicePathNode             A pointer to a single device path node.
316*22ce4affSfengbojiang 
317*22ce4affSfengbojiang   @retval NULL      There is not enough memory for the new device path.
318*22ce4affSfengbojiang   @retval Others    A pointer to the new device path if success.
319*22ce4affSfengbojiang                     A copy of DevicePathNode followed by an end-of-device-path node
320*22ce4affSfengbojiang                     if both FirstDevicePath and SecondDevicePath are NULL.
321*22ce4affSfengbojiang                     A copy of an end-of-device-path node if both FirstDevicePath and SecondDevicePath are NULL.
322*22ce4affSfengbojiang 
323*22ce4affSfengbojiang **/
324*22ce4affSfengbojiang EFI_DEVICE_PATH_PROTOCOL *
325*22ce4affSfengbojiang EFIAPI
326*22ce4affSfengbojiang AppendDevicePathNode (
327*22ce4affSfengbojiang   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath,     OPTIONAL
328*22ce4affSfengbojiang   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePathNode  OPTIONAL
329*22ce4affSfengbojiang   );
330*22ce4affSfengbojiang 
331*22ce4affSfengbojiang /**
332*22ce4affSfengbojiang   Creates a new device path by appending the specified device path instance to the specified device
333*22ce4affSfengbojiang   path.
334*22ce4affSfengbojiang 
335*22ce4affSfengbojiang   This function creates a new device path by appending a copy of the device path instance specified
336*22ce4affSfengbojiang   by DevicePathInstance to a copy of the device path secified by DevicePath in a allocated buffer.
337*22ce4affSfengbojiang   The end-of-device-path device node is moved after the end of the appended device path instance
338*22ce4affSfengbojiang   and a new end-of-device-path-instance node is inserted between.
339*22ce4affSfengbojiang   If DevicePath is NULL, then a copy if DevicePathInstance is returned.
340*22ce4affSfengbojiang   If DevicePathInstance is NULL, then NULL is returned.
341*22ce4affSfengbojiang   If DevicePath or DevicePathInstance is invalid, then NULL is returned.
342*22ce4affSfengbojiang   If there is not enough memory to allocate space for the new device path, then NULL is returned.
343*22ce4affSfengbojiang   The memory is allocated from EFI boot services memory. It is the responsibility of the caller to
344*22ce4affSfengbojiang   free the memory allocated.
345*22ce4affSfengbojiang 
346*22ce4affSfengbojiang   @param  DevicePath                 A pointer to a device path data structure.
347*22ce4affSfengbojiang   @param  DevicePathInstance         A pointer to a device path instance.
348*22ce4affSfengbojiang 
349*22ce4affSfengbojiang   @return A pointer to the new device path.
350*22ce4affSfengbojiang 
351*22ce4affSfengbojiang **/
352*22ce4affSfengbojiang EFI_DEVICE_PATH_PROTOCOL *
353*22ce4affSfengbojiang EFIAPI
354*22ce4affSfengbojiang AppendDevicePathInstance (
355*22ce4affSfengbojiang   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath,        OPTIONAL
356*22ce4affSfengbojiang   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePathInstance OPTIONAL
357*22ce4affSfengbojiang   );
358*22ce4affSfengbojiang 
359*22ce4affSfengbojiang /**
360*22ce4affSfengbojiang   Creates a copy of the current device path instance and returns a pointer to the next device path
361*22ce4affSfengbojiang   instance.
362*22ce4affSfengbojiang 
363*22ce4affSfengbojiang   This function creates a copy of the current device path instance. It also updates DevicePath to
364*22ce4affSfengbojiang   point to the next device path instance in the device path (or NULL if no more) and updates Size
365*22ce4affSfengbojiang   to hold the size of the device path instance copy.
366*22ce4affSfengbojiang   If DevicePath is NULL, then NULL is returned.
367*22ce4affSfengbojiang   If DevicePath points to a invalid device path, then NULL is returned.
368*22ce4affSfengbojiang   If there is not enough memory to allocate space for the new device path, then NULL is returned.
369*22ce4affSfengbojiang   The memory is allocated from EFI boot services memory. It is the responsibility of the caller to
370*22ce4affSfengbojiang   free the memory allocated.
371*22ce4affSfengbojiang   If Size is NULL, then ASSERT().
372*22ce4affSfengbojiang 
373*22ce4affSfengbojiang   @param  DevicePath                 On input, this holds the pointer to the current device path
374*22ce4affSfengbojiang                                      instance. On output, this holds the pointer to the next device
375*22ce4affSfengbojiang                                      path instance or NULL if there are no more device path
376*22ce4affSfengbojiang                                      instances in the device path pointer to a device path data
377*22ce4affSfengbojiang                                      structure.
378*22ce4affSfengbojiang   @param  Size                       On output, this holds the size of the device path instance, in
379*22ce4affSfengbojiang                                      bytes or zero, if DevicePath is NULL.
380*22ce4affSfengbojiang 
381*22ce4affSfengbojiang   @return A pointer to the current device path instance.
382*22ce4affSfengbojiang 
383*22ce4affSfengbojiang **/
384*22ce4affSfengbojiang EFI_DEVICE_PATH_PROTOCOL *
385*22ce4affSfengbojiang EFIAPI
386*22ce4affSfengbojiang GetNextDevicePathInstance (
387*22ce4affSfengbojiang   IN OUT EFI_DEVICE_PATH_PROTOCOL    **DevicePath,
388*22ce4affSfengbojiang   OUT UINTN                          *Size
389*22ce4affSfengbojiang   );
390*22ce4affSfengbojiang 
391*22ce4affSfengbojiang /**
392*22ce4affSfengbojiang   Creates a device node.
393*22ce4affSfengbojiang 
394*22ce4affSfengbojiang   This function creates a new device node in a newly allocated buffer of size NodeLength and
395*22ce4affSfengbojiang   initializes the device path node header with NodeType and NodeSubType.  The new device path node
396*22ce4affSfengbojiang   is returned.
397*22ce4affSfengbojiang   If NodeLength is smaller than a device path header, then NULL is returned.
398*22ce4affSfengbojiang   If there is not enough memory to allocate space for the new device path, then NULL is returned.
399*22ce4affSfengbojiang   The memory is allocated from EFI boot services memory. It is the responsibility of the caller to
400*22ce4affSfengbojiang   free the memory allocated.
401*22ce4affSfengbojiang 
402*22ce4affSfengbojiang   @param  NodeType                   The device node type for the new device node.
403*22ce4affSfengbojiang   @param  NodeSubType                The device node sub-type for the new device node.
404*22ce4affSfengbojiang   @param  NodeLength                 The length of the new device node.
405*22ce4affSfengbojiang 
406*22ce4affSfengbojiang   @return The new device path.
407*22ce4affSfengbojiang 
408*22ce4affSfengbojiang **/
409*22ce4affSfengbojiang EFI_DEVICE_PATH_PROTOCOL *
410*22ce4affSfengbojiang EFIAPI
411*22ce4affSfengbojiang CreateDeviceNode (
412*22ce4affSfengbojiang   IN UINT8                           NodeType,
413*22ce4affSfengbojiang   IN UINT8                           NodeSubType,
414*22ce4affSfengbojiang   IN UINT16                          NodeLength
415*22ce4affSfengbojiang   );
416*22ce4affSfengbojiang 
417*22ce4affSfengbojiang /**
418*22ce4affSfengbojiang   Determines if a device path is single or multi-instance.
419*22ce4affSfengbojiang 
420*22ce4affSfengbojiang   This function returns TRUE if the device path specified by DevicePath is multi-instance.
421*22ce4affSfengbojiang   Otherwise, FALSE is returned.
422*22ce4affSfengbojiang   If DevicePath is NULL or invalid, then FALSE is returned.
423*22ce4affSfengbojiang 
424*22ce4affSfengbojiang   @param  DevicePath                 A pointer to a device path data structure.
425*22ce4affSfengbojiang 
426*22ce4affSfengbojiang   @retval  TRUE                      DevicePath is multi-instance.
427*22ce4affSfengbojiang   @retval  FALSE                     DevicePath is not multi-instance, or DevicePath is NULL or invalid.
428*22ce4affSfengbojiang 
429*22ce4affSfengbojiang **/
430*22ce4affSfengbojiang BOOLEAN
431*22ce4affSfengbojiang EFIAPI
432*22ce4affSfengbojiang IsDevicePathMultiInstance (
433*22ce4affSfengbojiang   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath
434*22ce4affSfengbojiang   );
435*22ce4affSfengbojiang 
436*22ce4affSfengbojiang /**
437*22ce4affSfengbojiang   Retrieves the device path protocol from a handle.
438*22ce4affSfengbojiang 
439*22ce4affSfengbojiang   This function returns the device path protocol from the handle specified by Handle.  If Handle is
440*22ce4affSfengbojiang   NULL or Handle does not contain a device path protocol, then NULL is returned.
441*22ce4affSfengbojiang 
442*22ce4affSfengbojiang   @param  Handle                     The handle from which to retrieve the device path protocol.
443*22ce4affSfengbojiang 
444*22ce4affSfengbojiang   @return The device path protocol from the handle specified by Handle.
445*22ce4affSfengbojiang 
446*22ce4affSfengbojiang **/
447*22ce4affSfengbojiang EFI_DEVICE_PATH_PROTOCOL *
448*22ce4affSfengbojiang EFIAPI
449*22ce4affSfengbojiang DevicePathFromHandle (
450*22ce4affSfengbojiang   IN EFI_HANDLE                      Handle
451*22ce4affSfengbojiang   );
452*22ce4affSfengbojiang 
453*22ce4affSfengbojiang /**
454*22ce4affSfengbojiang   Allocates a device path for a file and appends it to an existing device path.
455*22ce4affSfengbojiang 
456*22ce4affSfengbojiang   If Device is a valid device handle that contains a device path protocol, then a device path for
457*22ce4affSfengbojiang   the file specified by FileName  is allocated and appended to the device path associated with the
458*22ce4affSfengbojiang   handle Device.  The allocated device path is returned.  If Device is NULL or Device is a handle
459*22ce4affSfengbojiang   that does not support the device path protocol, then a device path containing a single device
460*22ce4affSfengbojiang   path node for the file specified by FileName is allocated and returned.
461*22ce4affSfengbojiang   The memory for the new device path is allocated from EFI boot services memory. It is the responsibility
462*22ce4affSfengbojiang   of the caller to free the memory allocated.
463*22ce4affSfengbojiang 
464*22ce4affSfengbojiang   If FileName is NULL, then ASSERT().
465*22ce4affSfengbojiang   If FileName is not aligned on a 16-bit boundary, then ASSERT().
466*22ce4affSfengbojiang 
467*22ce4affSfengbojiang   @param  Device                     A pointer to a device handle.  This parameter is optional and
468*22ce4affSfengbojiang                                      may be NULL.
469*22ce4affSfengbojiang   @param  FileName                   A pointer to a Null-terminated Unicode string.
470*22ce4affSfengbojiang 
471*22ce4affSfengbojiang   @return The allocated device path.
472*22ce4affSfengbojiang 
473*22ce4affSfengbojiang **/
474*22ce4affSfengbojiang EFI_DEVICE_PATH_PROTOCOL *
475*22ce4affSfengbojiang EFIAPI
476*22ce4affSfengbojiang FileDevicePath (
477*22ce4affSfengbojiang   IN EFI_HANDLE                      Device,     OPTIONAL
478*22ce4affSfengbojiang   IN CONST CHAR16                    *FileName
479*22ce4affSfengbojiang   );
480*22ce4affSfengbojiang 
481*22ce4affSfengbojiang /**
482*22ce4affSfengbojiang   Converts a device path to its text representation.
483*22ce4affSfengbojiang 
484*22ce4affSfengbojiang   @param DevicePath      A Pointer to the device to be converted.
485*22ce4affSfengbojiang   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
486*22ce4affSfengbojiang                          of the display node is used, where applicable. If DisplayOnly
487*22ce4affSfengbojiang                          is FALSE, then the longer text representation of the display node
488*22ce4affSfengbojiang                          is used.
489*22ce4affSfengbojiang   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
490*22ce4affSfengbojiang                          representation for a device node can be used, where applicable.
491*22ce4affSfengbojiang 
492*22ce4affSfengbojiang   @return A pointer to the allocated text representation of the device path or
493*22ce4affSfengbojiang           NULL if DeviceNode is NULL or there was insufficient memory.
494*22ce4affSfengbojiang 
495*22ce4affSfengbojiang **/
496*22ce4affSfengbojiang CHAR16 *
497*22ce4affSfengbojiang EFIAPI
498*22ce4affSfengbojiang ConvertDevicePathToText (
499*22ce4affSfengbojiang   IN CONST EFI_DEVICE_PATH_PROTOCOL   *DevicePath,
500*22ce4affSfengbojiang   IN BOOLEAN                          DisplayOnly,
501*22ce4affSfengbojiang   IN BOOLEAN                          AllowShortcuts
502*22ce4affSfengbojiang   );
503*22ce4affSfengbojiang 
504*22ce4affSfengbojiang /**
505*22ce4affSfengbojiang   Converts a device node to its string representation.
506*22ce4affSfengbojiang 
507*22ce4affSfengbojiang   @param DeviceNode        A Pointer to the device node to be converted.
508*22ce4affSfengbojiang   @param DisplayOnly       If DisplayOnly is TRUE, then the shorter text representation
509*22ce4affSfengbojiang                            of the display node is used, where applicable. If DisplayOnly
510*22ce4affSfengbojiang                            is FALSE, then the longer text representation of the display node
511*22ce4affSfengbojiang                            is used.
512*22ce4affSfengbojiang   @param AllowShortcuts    If AllowShortcuts is TRUE, then the shortcut forms of text
513*22ce4affSfengbojiang                            representation for a device node can be used, where applicable.
514*22ce4affSfengbojiang 
515*22ce4affSfengbojiang   @return A pointer to the allocated text representation of the device node or NULL if DeviceNode
516*22ce4affSfengbojiang           is NULL or there was insufficient memory.
517*22ce4affSfengbojiang 
518*22ce4affSfengbojiang **/
519*22ce4affSfengbojiang CHAR16 *
520*22ce4affSfengbojiang EFIAPI
521*22ce4affSfengbojiang ConvertDeviceNodeToText (
522*22ce4affSfengbojiang   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DeviceNode,
523*22ce4affSfengbojiang   IN BOOLEAN                         DisplayOnly,
524*22ce4affSfengbojiang   IN BOOLEAN                         AllowShortcuts
525*22ce4affSfengbojiang   );
526*22ce4affSfengbojiang 
527*22ce4affSfengbojiang /**
528*22ce4affSfengbojiang   Convert text to the binary representation of a device node.
529*22ce4affSfengbojiang 
530*22ce4affSfengbojiang   @param TextDeviceNode  TextDeviceNode points to the text representation of a device
531*22ce4affSfengbojiang                          node. Conversion starts with the first character and continues
532*22ce4affSfengbojiang                          until the first non-device node character.
533*22ce4affSfengbojiang 
534*22ce4affSfengbojiang   @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was
535*22ce4affSfengbojiang           insufficient memory or text unsupported.
536*22ce4affSfengbojiang 
537*22ce4affSfengbojiang **/
538*22ce4affSfengbojiang EFI_DEVICE_PATH_PROTOCOL *
539*22ce4affSfengbojiang EFIAPI
540*22ce4affSfengbojiang ConvertTextToDeviceNode (
541*22ce4affSfengbojiang   IN CONST CHAR16 *TextDeviceNode
542*22ce4affSfengbojiang   );
543*22ce4affSfengbojiang 
544*22ce4affSfengbojiang /**
545*22ce4affSfengbojiang   Convert text to the binary representation of a device path.
546*22ce4affSfengbojiang 
547*22ce4affSfengbojiang   @param TextDevicePath  TextDevicePath points to the text representation of a device
548*22ce4affSfengbojiang                          path. Conversion starts with the first character and continues
549*22ce4affSfengbojiang                          until the first non-device node character.
550*22ce4affSfengbojiang 
551*22ce4affSfengbojiang   @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or
552*22ce4affSfengbojiang           there was insufficient memory.
553*22ce4affSfengbojiang 
554*22ce4affSfengbojiang **/
555*22ce4affSfengbojiang EFI_DEVICE_PATH_PROTOCOL *
556*22ce4affSfengbojiang EFIAPI
557*22ce4affSfengbojiang ConvertTextToDevicePath (
558*22ce4affSfengbojiang   IN CONST CHAR16 *TextDevicePath
559*22ce4affSfengbojiang   );
560*22ce4affSfengbojiang 
561*22ce4affSfengbojiang #endif
562