]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/DevicePathDxe/DevicePathUtilities.c
544c28bd447b57f700080691f12838ebfbf5af12
[mirror_edk2.git] / MdeModulePkg / Universal / DevicePathDxe / DevicePathUtilities.c
1 /** @file
2 Implementation file for Device Path Utilities Protocol
3
4 Copyright (c) 2006 - 2008, Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "DevicePath.h"
16
17 /**
18 Returns the size of a device path in bytes.
19
20 This function returns the size, in bytes, of the device path data structure specified by
21 DevicePath including the end of device path node. If DevicePath is NULL, then 0 is returned.
22
23 @param DevicePath A pointer to a device path data structure.
24
25 @return The size of a device path in bytes.
26
27 **/
28 UINTN
29 EFIAPI
30 GetDevicePathSizeProtocolInterface (
31 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
32 )
33 {
34 return GetDevicePathSize (DevicePath);
35 }
36
37
38 /**
39 Creates a new device path by appending a second device path to a first device path.
40
41 This function allocates space for a new copy of the device path specified by DevicePath. If
42 DevicePath is NULL, then NULL is returned. If the memory is successfully allocated, then the
43 contents of DevicePath are copied to the newly allocated buffer, and a pointer to that buffer
44 is returned. Otherwise, NULL is returned.
45
46 @param DevicePath A pointer to a device path data structure.
47
48 @return A pointer to the duplicated device path.
49
50 **/
51 EFI_DEVICE_PATH_PROTOCOL *
52 EFIAPI
53 DuplicateDevicePathProtocolInterface (
54 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
55 )
56 {
57 return DuplicateDevicePath (DevicePath);
58 }
59
60 /**
61 Creates a new device path by appending a second device path to a first device path.
62
63 This function creates a new device path by appending a copy of SecondDevicePath to a copy of
64 FirstDevicePath in a newly allocated buffer. Only the end-of-device-path device node from
65 SecondDevicePath is retained. The newly created device path is returned.
66 If FirstDevicePath is NULL, then it is ignored, and a duplicate of SecondDevicePath is returned.
67 If SecondDevicePath is NULL, then it is ignored, and a duplicate of FirstDevicePath is returned.
68 If both FirstDevicePath and SecondDevicePath are NULL, then a copy of an end-of-device-path is
69 returned.
70 If there is not enough memory for the newly allocated buffer, then NULL is returned.
71 The memory for the new device path is allocated from EFI boot services memory. It is the
72 responsibility of the caller to free the memory allocated.
73
74 @param FirstDevicePath A pointer to a device path data structure.
75 @param SecondDevicePath A pointer to a device path data structure.
76
77 @return A pointer to the new device path.
78
79 **/
80 EFI_DEVICE_PATH_PROTOCOL *
81 EFIAPI
82 AppendDevicePathProtocolInterface (
83 IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath,
84 IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath
85 )
86 {
87 return AppendDevicePath (FirstDevicePath, SecondDevicePath);
88 }
89
90 /**
91 Creates a new path by appending the device node to the device path.
92
93 This function creates a new device path by appending a copy of the device node specified by
94 DevicePathNode to a copy of the device path specified by DevicePath in an allocated buffer.
95 The end-of-device-path device node is moved after the end of the appended device node.
96 If DevicePathNode is NULL then a copy of DevicePath is returned.
97 If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device path device
98 node is returned.
99 If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path device node
100 is returned.
101 If there is not enough memory to allocate space for the new device path, then NULL is returned.
102 The memory is allocated from EFI boot services memory. It is the responsibility of the caller to
103 free the memory allocated.
104
105 @param DevicePath A pointer to a device path data structure.
106 @param DevicePathNode A pointer to a single device path node.
107
108 @return A pointer to the new device path.
109
110 **/
111 EFI_DEVICE_PATH_PROTOCOL *
112 EFIAPI
113 AppendDeviceNodeProtocolInterface (
114 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
115 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode
116 )
117 {
118 return AppendDevicePathNode (DevicePath, DevicePathNode);
119 }
120
121 /**
122 Creates a new device path by appending the specified device path instance to the specified device
123 path.
124
125 This function creates a new device path by appending a copy of the device path instance specified
126 by DevicePathInstance to a copy of the device path specified by DevicePath in a allocated buffer.
127 The end-of-device-path device node is moved after the end of the appended device path instance
128 and a new end-of-device-path-instance node is inserted between.
129 If DevicePath is NULL, then a copy if DevicePathInstance is returned.
130 If DevicePathInstance is NULL, then NULL is returned.
131 If there is not enough memory to allocate space for the new device path, then NULL is returned.
132 The memory is allocated from EFI boot services memory. It is the responsibility of the caller to
133 free the memory allocated.
134
135 @param DevicePath A pointer to a device path data structure.
136 @param DevicePathInstance A pointer to a device path instance.
137
138 @return A pointer to the new device path.
139
140 **/
141 EFI_DEVICE_PATH_PROTOCOL *
142 EFIAPI
143 AppendDevicePathInstanceProtocolInterface (
144 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
145 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance
146 )
147 {
148 return AppendDevicePathInstance (DevicePath, DevicePathInstance);
149 }
150
151 /**
152 Creates a copy of the current device path instance and returns a pointer to the next device path
153 instance.
154
155 This function creates a copy of the current device path instance. It also updates DevicePath to
156 point to the next device path instance in the device path (or NULL if no more) and updates Size
157 to hold the size of the device path instance copy.
158 If DevicePath is NULL, then NULL is returned.
159 If there is not enough memory to allocate space for the new device path, then NULL is returned.
160 The memory is allocated from EFI boot services memory. It is the responsibility of the caller to
161 free the memory allocated.
162 If Size is NULL, then ASSERT().
163
164 @param DevicePath On input, this holds the pointer to the current device path
165 instance. On output, this holds the pointer to the next device
166 path instance or NULL if there are no more device path
167 instances in the device path pointer to a device path data
168 structure.
169 @param Size On output, this holds the size of the device path instance, in
170 bytes or zero, if DevicePath is NULL.
171
172 @return A pointer to the current device path instance.
173
174 **/
175 EFI_DEVICE_PATH_PROTOCOL *
176 EFIAPI
177 GetNextDevicePathInstanceProtocolInterface (
178 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,
179 OUT UINTN *Size
180 )
181 {
182 return GetNextDevicePathInstance (DevicePath, Size);
183 }
184
185 /**
186 Determines if a device path is single or multi-instance.
187
188 This function returns TRUE if the device path specified by DevicePath is multi-instance.
189 Otherwise, FALSE is returned. If DevicePath is NULL, then FALSE is returned.
190
191 @param DevicePath A pointer to a device path data structure.
192
193 @retval TRUE DevicePath is multi-instance.
194 @retval FALSE DevicePath is not multi-instance or DevicePath is NULL.
195
196 **/
197 BOOLEAN
198 EFIAPI
199 IsDevicePathMultiInstanceProtocolInterface (
200 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
201 )
202 {
203 return IsDevicePathMultiInstance (DevicePath);
204 }
205
206 /**
207 Creates a copy of the current device path instance and returns a pointer to the next device path
208 instance.
209
210 This function creates a new device node in a newly allocated buffer of size NodeLength and
211 initializes the device path node header with NodeType and NodeSubType. The new device path node
212 is returned.
213 If NodeLength is smaller than a device path header, then NULL is returned.
214 If there is not enough memory to allocate space for the new device path, then NULL is returned.
215 The memory is allocated from EFI boot services memory. It is the responsibility of the caller to
216 free the memory allocated.
217
218 @param NodeType The device node type for the new device node.
219 @param NodeSubType The device node sub-type for the new device node.
220 @param NodeLength The length of the new device node.
221
222 @return The new device path.
223
224 **/
225 EFI_DEVICE_PATH_PROTOCOL *
226 EFIAPI
227 CreateDeviceNodeProtocolInterface (
228 IN UINT8 NodeType,
229 IN UINT8 NodeSubType,
230 IN UINT16 NodeLength
231 )
232 {
233 return CreateDeviceNode (NodeType, NodeSubType, NodeLength);
234 }