xref: /freebsd/sys/contrib/edk2/Include/Protocol/DevicePathUtilities.h (revision c66ec88fed842fbaad62c30d510644ceb7bd2d71)
1 /** @file
2   EFI_DEVICE_PATH_UTILITIES_PROTOCOL as defined in UEFI 2.0.
3   Use to create and manipulate device paths and device nodes.
4 
5   Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
6   SPDX-License-Identifier: BSD-2-Clause-Patent
7 
8 **/
9 
10 #ifndef __DEVICE_PATH_UTILITIES_PROTOCOL_H__
11 #define __DEVICE_PATH_UTILITIES_PROTOCOL_H__
12 
13 ///
14 /// Device Path Utilities protocol
15 ///
16 #define EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID \
17   { \
18     0x379be4e, 0xd706, 0x437d, {0xb0, 0x37, 0xed, 0xb8, 0x2f, 0xb7, 0x72, 0xa4 } \
19   }
20 
21 /**
22   Returns the size of the device path, in bytes.
23 
24   @param  DevicePath Points to the start of the EFI device path.
25 
26   @return Size  Size of the specified device path, in bytes, including the end-of-path tag.
27   @retval 0     DevicePath is NULL
28 
29 **/
30 typedef
31 UINTN
32 (EFIAPI *EFI_DEVICE_PATH_UTILS_GET_DEVICE_PATH_SIZE)(
33   IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
34   );
35 
36 
37 /**
38   Create a duplicate of the specified path.
39 
40   @param  DevicePath Points to the source EFI device path.
41 
42   @retval Pointer    A pointer to the duplicate device path.
43   @retval NULL       insufficient memory or DevicePath is NULL
44 
45 **/
46 typedef
47 EFI_DEVICE_PATH_PROTOCOL*
48 (EFIAPI *EFI_DEVICE_PATH_UTILS_DUP_DEVICE_PATH)(
49   IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
50   );
51 
52 /**
53   Create a new path by appending the second device path to the first.
54   If Src1 is NULL and Src2 is non-NULL, then a duplicate of Src2 is returned.
55   If Src1 is non-NULL and Src2 is NULL, then a duplicate of Src1 is returned.
56   If Src1 and Src2 are both NULL, then a copy of an end-of-device-path is returned.
57 
58   @param  Src1 Points to the first device path.
59   @param  Src2 Points to the second device path.
60 
61   @retval Pointer  A pointer to the newly created device path.
62   @retval NULL     Memory could not be allocated
63 
64 **/
65 typedef
66 EFI_DEVICE_PATH_PROTOCOL*
67 (EFIAPI *EFI_DEVICE_PATH_UTILS_APPEND_PATH)(
68   IN CONST EFI_DEVICE_PATH_PROTOCOL *Src1,
69   IN CONST EFI_DEVICE_PATH_PROTOCOL *Src2
70   );
71 
72 /**
73   Creates a new path by appending the device node to the device path.
74   If DeviceNode is NULL then a copy of DevicePath is returned.
75   If DevicePath is NULL then a copy of DeviceNode, followed by an end-of-device path device node is returned.
76   If both DeviceNode and DevicePath are NULL then a copy of an end-of-device-path device node is returned.
77 
78   @param  DevicePath Points to the device path.
79   @param  DeviceNode Points to the device node.
80 
81   @retval Pointer    A pointer to the allocated device node.
82   @retval NULL       There was insufficient memory.
83 
84 **/
85 typedef
86 EFI_DEVICE_PATH_PROTOCOL*
87 (EFIAPI *EFI_DEVICE_PATH_UTILS_APPEND_NODE)(
88   IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
89   IN CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode
90   );
91 
92 /**
93   Creates a new path by appending the specified device path instance to the specified device path.
94 
95   @param  DevicePath         Points to the device path. If NULL, then ignored.
96   @param  DevicePathInstance Points to the device path instance.
97 
98   @retval Pointer            A pointer to the newly created device path
99   @retval NULL               Memory could not be allocated or DevicePathInstance is NULL.
100 
101 **/
102 typedef
103 EFI_DEVICE_PATH_PROTOCOL*
104 (EFIAPI *EFI_DEVICE_PATH_UTILS_APPEND_INSTANCE)(
105   IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
106   IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance
107   );
108 
109 /**
110   Creates a copy of the current device path instance and returns a pointer to the next device path
111   instance.
112 
113   @param  DevicePathInstance     On input, this holds the pointer to the current device path
114                                  instance. On output, this holds the pointer to the next
115                                  device path instance or NULL if there are no more device
116                                  path instances in the device path.
117   @param  DevicePathInstanceSize On output, this holds the size of the device path instance,
118                                  in bytes or zero, if DevicePathInstance is NULL.
119                                  If NULL, then the instance size is not output.
120 
121   @retval Pointer                A pointer to the copy of the current device path instance.
122   @retval NULL                   DevicePathInstace was NULL on entry or there was insufficient memory.
123 
124 **/
125 typedef
126 EFI_DEVICE_PATH_PROTOCOL*
127 (EFIAPI *EFI_DEVICE_PATH_UTILS_GET_NEXT_INSTANCE)(
128   IN  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathInstance,
129   OUT UINTN                         *DevicePathInstanceSize
130   );
131 
132 /**
133   Creates a device node
134 
135   @param  NodeType    NodeType is the device node type (EFI_DEVICE_PATH.Type) for
136                       the new device node.
137   @param  NodeSubType NodeSubType is the device node sub-type
138                       EFI_DEVICE_PATH.SubType) for the new device node.
139   @param  NodeLength  NodeLength is the length of the device node
140                       (EFI_DEVICE_PATH.Length) for the new device node.
141 
142   @retval Pointer     A pointer to the newly created device node.
143   @retval NULL        NodeLength is less than
144                       the size of the header or there was insufficient memory.
145 
146 **/
147 typedef
148 EFI_DEVICE_PATH_PROTOCOL*
149 (EFIAPI *EFI_DEVICE_PATH_UTILS_CREATE_NODE)(
150   IN UINT8                          NodeType,
151   IN UINT8                          NodeSubType,
152   IN UINT16                         NodeLength
153 );
154 
155 /**
156   Returns whether a device path is multi-instance.
157 
158   @param  DevicePath Points to the device path. If NULL, then ignored.
159 
160   @retval TRUE       The device path has more than one instance
161   @retval FALSE      The device path is empty or contains only a single instance.
162 
163 **/
164 typedef
165 BOOLEAN
166 (EFIAPI *EFI_DEVICE_PATH_UTILS_IS_MULTI_INSTANCE)(
167   IN CONST EFI_DEVICE_PATH_PROTOCOL         *DevicePath
168   );
169 
170 ///
171 /// This protocol is used to creates and manipulates device paths and device nodes.
172 ///
173 typedef struct {
174   EFI_DEVICE_PATH_UTILS_GET_DEVICE_PATH_SIZE GetDevicePathSize;
175   EFI_DEVICE_PATH_UTILS_DUP_DEVICE_PATH      DuplicateDevicePath;
176   EFI_DEVICE_PATH_UTILS_APPEND_PATH          AppendDevicePath;
177   EFI_DEVICE_PATH_UTILS_APPEND_NODE          AppendDeviceNode;
178   EFI_DEVICE_PATH_UTILS_APPEND_INSTANCE      AppendDevicePathInstance;
179   EFI_DEVICE_PATH_UTILS_GET_NEXT_INSTANCE    GetNextDevicePathInstance;
180   EFI_DEVICE_PATH_UTILS_IS_MULTI_INSTANCE    IsDevicePathMultiInstance;
181   EFI_DEVICE_PATH_UTILS_CREATE_NODE          CreateDeviceNode;
182 } EFI_DEVICE_PATH_UTILITIES_PROTOCOL;
183 
184 extern EFI_GUID gEfiDevicePathUtilitiesProtocolGuid;
185 
186 #endif
187