]>
Commit | Line | Data |
---|---|---|
fb3df220 | 1 | /** @file\r |
50a64e5b | 2 | Provides library functions to construct and parse UEFI Device Paths.\r |
fb3df220 | 3 | \r |
50a64e5b | 4 | Copyright (c) 2006 - 2008, Intel Corporation\r |
5 | All rights reserved. This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
fb3df220 | 9 | \r |
50a64e5b | 10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
fb3df220 | 12 | \r |
fb3df220 | 13 | **/\r |
14 | \r | |
15 | #ifndef __DEVICE_PATH_LIB_H__\r | |
16 | #define __DEVICE_PATH_LIB_H__\r | |
17 | \r | |
e5dab016 | 18 | #include <Library/BaseLib.h>\r |
19 | \r | |
20 | #define END_DEVICE_PATH_LENGTH (sizeof (EFI_DEVICE_PATH_PROTOCOL))\r | |
21 | #define DevicePathNodeLength(Node) ReadUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0])\r | |
22 | #define NextDevicePathNode(Node) ((EFI_DEVICE_PATH_PROTOCOL *)((UINT8 *)(Node) + DevicePathNodeLength(Node)))\r | |
23 | #define DevicePathType(Node) (((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Type) \r | |
24 | #define DevicePathSubType(Node) (((EFI_DEVICE_PATH_PROTOCOL *)(Node))->SubType)\r | |
25 | #define IsDevicePathEndType(Node) (DevicePathType (Node) == END_DEVICE_PATH_TYPE)\r | |
26 | #define IsDevicePathEnd(Node) (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_ENTIRE_DEVICE_PATH_SUBTYPE)\r | |
27 | #define IsDevicePathEndInstance(Node) (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_INSTANCE_DEVICE_PATH_SUBTYPE)\r | |
28 | \r | |
29 | #define SetDevicePathNodeLength(Node,NodeLength) WriteUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0], (UINT16)(NodeLength))\r | |
30 | #define SetDevicePathEndNode(Node) { \\r | |
31 | DevicePathType (Node) = END_DEVICE_PATH_TYPE; \\r | |
32 | DevicePathSubType (Node) = END_ENTIRE_DEVICE_PATH_SUBTYPE; \\r | |
33 | SetDevicePathNodeLength ((Node), END_DEVICE_PATH_LENGTH); \\r | |
34 | }\r | |
35 | \r | |
fb3df220 | 36 | /**\r |
37 | Returns the size of a device path in bytes.\r | |
38 | \r | |
39 | This function returns the size, in bytes, of the device path data structure specified by\r | |
40 | DevicePath including the end of device path node. If DevicePath is NULL, then 0 is returned.\r | |
41 | \r | |
42 | @param DevicePath A pointer to a device path data structure.\r | |
43 | \r | |
44 | @return The size of a device path in bytes.\r | |
45 | \r | |
46 | **/\r | |
47 | UINTN\r | |
48 | EFIAPI\r | |
49 | GetDevicePathSize (\r | |
50 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
51 | );\r | |
52 | \r | |
53 | /**\r | |
54 | Creates a new device path by appending a second device path to a first device path.\r | |
55 | \r | |
56 | This function allocates space for a new copy of the device path specified by DevicePath. If\r | |
57 | DevicePath is NULL, then NULL is returned. If the memory is successfully allocated, then the\r | |
58 | contents of DevicePath are copied to the newly allocated buffer, and a pointer to that buffer\r | |
59 | is returned. Otherwise, NULL is returned. \r | |
60 | \r | |
61 | @param DevicePath A pointer to a device path data structure.\r | |
62 | \r | |
63 | @return A pointer to the duplicated device path.\r | |
64 | \r | |
65 | **/\r | |
66 | EFI_DEVICE_PATH_PROTOCOL *\r | |
67 | EFIAPI\r | |
68 | DuplicateDevicePath (\r | |
69 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
70 | );\r | |
71 | \r | |
72 | /**\r | |
73 | Creates a new device path by appending a second device path to a first device path.\r | |
74 | \r | |
75 | This function creates a new device path by appending a copy of SecondDevicePath to a copy of\r | |
76 | FirstDevicePath in a newly allocated buffer. Only the end-of-device-path device node from\r | |
77 | SecondDevicePath is retained. The newly created device path is returned. \r | |
78 | If FirstDevicePath is NULL, then it is ignored, and a duplicate of SecondDevicePath is returned. \r | |
79 | If SecondDevicePath is NULL, then it is ignored, and a duplicate of FirstDevicePath is returned. \r | |
98a14db6 | 80 | If both FirstDevicePath and SecondDevicePath are NULL, then a copy of an end-of-device-path is\r |
81 | returned. \r | |
fb3df220 | 82 | If there is not enough memory for the newly allocated buffer, then NULL is returned.\r |
83 | The memory for the new device path is allocated from EFI boot services memory. It is the\r | |
84 | responsibility of the caller to free the memory allocated.\r | |
85 | \r | |
86 | @param FirstDevicePath A pointer to a device path data structure.\r | |
87 | @param SecondDevicePath A pointer to a device path data structure.\r | |
88 | \r | |
89 | @return A pointer to the new device path.\r | |
90 | \r | |
91 | **/\r | |
92 | EFI_DEVICE_PATH_PROTOCOL *\r | |
93 | EFIAPI\r | |
94 | AppendDevicePath (\r | |
95 | IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath, OPTIONAL\r | |
96 | IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL\r | |
97 | );\r | |
98 | \r | |
99 | /**\r | |
100 | Creates a new path by appending the device node to the device path.\r | |
101 | \r | |
102 | This function creates a new device path by appending a copy of the device node specified by\r | |
103 | DevicePathNode to a copy of the device path specified by DevicePath in an allocated buffer.\r | |
104 | The end-of-device-path device node is moved after the end of the appended device node.\r | |
98a14db6 | 105 | If DevicePathNode is NULL then a copy of DevicePath is returned.\r |
6336a895 | 106 | If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device path device\r |
107 | node is returned.\r | |
98a14db6 | 108 | If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path device node\r |
109 | is returned.\r | |
fb3df220 | 110 | If there is not enough memory to allocate space for the new device path, then NULL is returned. \r |
111 | The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r | |
112 | free the memory allocated.\r | |
113 | \r | |
114 | @param DevicePath A pointer to a device path data structure.\r | |
115 | @param DevicePathNode A pointer to a single device path node.\r | |
116 | \r | |
117 | @return A pointer to the new device path.\r | |
118 | \r | |
119 | **/\r | |
120 | EFI_DEVICE_PATH_PROTOCOL *\r | |
121 | EFIAPI\r | |
122 | AppendDevicePathNode (\r | |
123 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL\r | |
124 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL\r | |
125 | );\r | |
126 | \r | |
127 | /**\r | |
128 | Creates a new device path by appending the specified device path instance to the specified device\r | |
129 | path.\r | |
130 | \r | |
131 | This function creates a new device path by appending a copy of the device path instance specified\r | |
132 | by DevicePathInstance to a copy of the device path secified by DevicePath in a allocated buffer.\r | |
133 | The end-of-device-path device node is moved after the end of the appended device path instance\r | |
134 | and a new end-of-device-path-instance node is inserted between. \r | |
135 | If DevicePath is NULL, then a copy if DevicePathInstance is returned.\r | |
136 | If DevicePathInstance is NULL, then NULL is returned.\r | |
137 | If there is not enough memory to allocate space for the new device path, then NULL is returned. \r | |
138 | The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r | |
139 | free the memory allocated.\r | |
140 | \r | |
141 | @param DevicePath A pointer to a device path data structure.\r | |
142 | @param DevicePathInstance A pointer to a device path instance.\r | |
143 | \r | |
144 | @return A pointer to the new device path.\r | |
145 | \r | |
146 | **/\r | |
147 | EFI_DEVICE_PATH_PROTOCOL *\r | |
148 | EFIAPI\r | |
149 | AppendDevicePathInstance (\r | |
150 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL\r | |
151 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL\r | |
152 | );\r | |
153 | \r | |
154 | /**\r | |
155 | Creates a copy of the current device path instance and returns a pointer to the next device path\r | |
156 | instance.\r | |
157 | \r | |
158 | This function creates a copy of the current device path instance. It also updates DevicePath to\r | |
159 | point to the next device path instance in the device path (or NULL if no more) and updates Size\r | |
160 | to hold the size of the device path instance copy.\r | |
161 | If DevicePath is NULL, then NULL is returned.\r | |
162 | If there is not enough memory to allocate space for the new device path, then NULL is returned. \r | |
163 | The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r | |
164 | free the memory allocated.\r | |
165 | If Size is NULL, then ASSERT().\r | |
166 | \r | |
167 | @param DevicePath On input, this holds the pointer to the current device path\r | |
168 | instance. On output, this holds the pointer to the next device\r | |
169 | path instance or NULL if there are no more device path\r | |
170 | instances in the device path pointer to a device path data\r | |
171 | structure.\r | |
172 | @param Size On output, this holds the size of the device path instance, in\r | |
173 | bytes or zero, if DevicePath is NULL.\r | |
174 | \r | |
175 | @return A pointer to the current device path instance.\r | |
176 | \r | |
177 | **/\r | |
178 | EFI_DEVICE_PATH_PROTOCOL *\r | |
179 | EFIAPI\r | |
180 | GetNextDevicePathInstance (\r | |
181 | IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,\r | |
182 | OUT UINTN *Size\r | |
183 | );\r | |
184 | \r | |
185 | /**\r | |
186 | Creates a copy of the current device path instance and returns a pointer to the next device path\r | |
187 | instance.\r | |
188 | \r | |
189 | This function creates a new device node in a newly allocated buffer of size NodeLength and\r | |
190 | initializes the device path node header with NodeType and NodeSubType. The new device path node\r | |
191 | is returned.\r | |
192 | If NodeLength is smaller than a device path header, then NULL is returned. \r | |
193 | If there is not enough memory to allocate space for the new device path, then NULL is returned. \r | |
194 | The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r | |
195 | free the memory allocated.\r | |
196 | \r | |
197 | @param NodeType The device node type for the new device node.\r | |
198 | @param NodeSubType The device node sub-type for the new device node.\r | |
199 | @param NodeLength The length of the new device node.\r | |
200 | \r | |
201 | @return The new device path.\r | |
202 | \r | |
203 | **/\r | |
204 | EFI_DEVICE_PATH_PROTOCOL *\r | |
205 | EFIAPI\r | |
206 | CreateDeviceNode (\r | |
207 | IN UINT8 NodeType,\r | |
208 | IN UINT8 NodeSubType,\r | |
209 | IN UINT16 NodeLength\r | |
210 | );\r | |
211 | \r | |
212 | /**\r | |
213 | Determines if a device path is single or multi-instance.\r | |
214 | \r | |
215 | This function returns TRUE if the device path specified by DevicePath is multi-instance.\r | |
216 | Otherwise, FALSE is returned. If DevicePath is NULL, then FALSE is returned.\r | |
217 | \r | |
218 | @param DevicePath A pointer to a device path data structure.\r | |
219 | \r | |
220 | @retval TRUE DevicePath is multi-instance.\r | |
221 | @retval FALSE DevicePath is not multi-instance or DevicePath is NULL.\r | |
222 | \r | |
223 | **/\r | |
224 | BOOLEAN\r | |
225 | EFIAPI\r | |
226 | IsDevicePathMultiInstance (\r | |
227 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
228 | );\r | |
229 | \r | |
230 | /**\r | |
231 | Retrieves the device path protocol from a handle.\r | |
232 | \r | |
233 | This function returns the device path protocol from the handle specified by Handle. If Handle is\r | |
234 | NULL or Handle does not contain a device path protocol, then NULL is returned.\r | |
235 | \r | |
236 | @param Handle The handle from which to retrieve the device path protocol.\r | |
237 | \r | |
238 | @return The device path protocol from the handle specified by Handle.\r | |
239 | \r | |
240 | **/\r | |
241 | EFI_DEVICE_PATH_PROTOCOL *\r | |
242 | EFIAPI\r | |
243 | DevicePathFromHandle (\r | |
244 | IN EFI_HANDLE Handle\r | |
245 | );\r | |
246 | \r | |
247 | /**\r | |
248 | Allocates a device path for a file and appends it to an existing device path.\r | |
249 | \r | |
250 | If Device is a valid device handle that contains a device path protocol, then a device path for\r | |
251 | the file specified by FileName is allocated and appended to the device path associated with the\r | |
252 | handle Device. The allocated device path is returned. If Device is NULL or Device is a handle\r | |
253 | that does not support the device path protocol, then a device path containing a single device\r | |
254 | path node for the file specified by FileName is allocated and returned.\r | |
255 | If FileName is NULL, then ASSERT().\r | |
256 | \r | |
257 | @param Device A pointer to a device handle. This parameter is optional and\r | |
258 | may be NULL.\r | |
259 | @param FileName A pointer to a Null-terminated Unicode string.\r | |
260 | \r | |
261 | @return The allocated device path.\r | |
262 | \r | |
263 | **/\r | |
264 | EFI_DEVICE_PATH_PROTOCOL *\r | |
265 | EFIAPI\r | |
266 | FileDevicePath (\r | |
267 | IN EFI_HANDLE Device, OPTIONAL\r | |
268 | IN CONST CHAR16 *FileName\r | |
269 | );\r | |
270 | \r | |
271 | #endif\r |