devpath.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. /*++
  2. Copyright (c) 2014 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. devpath.h
  9. Abstract:
  10. This header contains definitions for the UEFI core device path support.
  11. Author:
  12. Evan Green 5-Mar-2014
  13. --*/
  14. //
  15. // ------------------------------------------------------------------- Includes
  16. //
  17. //
  18. // ---------------------------------------------------------------- Definitions
  19. //
  20. //
  21. // ------------------------------------------------------ Data Type Definitions
  22. //
  23. //
  24. // -------------------------------------------------------------------- Globals
  25. //
  26. //
  27. // -------------------------------------------------------- Function Prototypes
  28. //
  29. EFIAPI
  30. EFI_DEVICE_PATH_PROTOCOL *
  31. EfiCoreDuplicateDevicePath (
  32. CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
  33. );
  34. /*++
  35. Routine Description:
  36. This routine creates a duplicate of the specified path.
  37. Arguments:
  38. DevicePath - Supplies a pointer to the device path instance.
  39. Return Value:
  40. Returns a pointer to the duplicate device path on success.
  41. NULL on allocation failure or if the input device path was null.
  42. --*/
  43. EFIAPI
  44. EFI_DEVICE_PATH_PROTOCOL *
  45. EfiCoreAppendDevicePath (
  46. CONST EFI_DEVICE_PATH_PROTOCOL *First,
  47. CONST EFI_DEVICE_PATH_PROTOCOL *Second
  48. );
  49. /*++
  50. Routine Description:
  51. This routine creates a new path by appending the second device path to the
  52. first. If the first source is NULL and the second is not, then a duplicate
  53. of the second is returned. If the first is not NULL and the second is, a
  54. duplicate of the first is made. If both are NULL, then a copy of an
  55. end-of-device-path is returned.
  56. Arguments:
  57. First - Supplies an optional pointer to the first device path instance.
  58. Second - Supplies an optional pointer to the second device path instance.
  59. Return Value:
  60. Returns a pointer to the duplicate appended device path on success.
  61. NULL on allocation failure.
  62. --*/
  63. EFIAPI
  64. EFI_DEVICE_PATH_PROTOCOL *
  65. EfiCoreAppendDevicePathInstance (
  66. CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
  67. CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance
  68. );
  69. /*++
  70. Routine Description:
  71. This routine creates a new path by appending the second device path
  72. instance to the first. The end-of-device-path device node is moved after
  73. the end of the appended device path instance and a new
  74. end-of-device-path-instance node is inserted between. If DevicePath is
  75. NULL, then a copy if DevicePathInstance is returned. If the device path
  76. instance is NULL, then NULL is returned. If the device path or device path
  77. instance is invalid, then NULL is returned. If there is not enough memory
  78. to allocate space for the new device path, then NULL is returned. The
  79. memory is allocated from EFI boot services memory. It is the responsibility
  80. of the caller to free the memory allocated.
  81. Arguments:
  82. DevicePath - Supplies an optional pointer to the device path.
  83. DevicePathInstance - Supplies a pointer to the device path instance to
  84. append.
  85. Return Value:
  86. Returns a pointer to the appended device path on success. The caller is
  87. responsible for freeing this newly allocated memory.
  88. NULL on allocation failure.
  89. --*/
  90. EFIAPI
  91. EFI_DEVICE_PATH_PROTOCOL *
  92. EfiCoreAppendDevicePathNode (
  93. CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
  94. CONST EFI_DEVICE_PATH_PROTOCOL *Node
  95. );
  96. /*++
  97. Routine Description:
  98. This routine creates a new device path by appending a copy of the given
  99. device path node to a copy of the given device path in an allocated buffer.
  100. The end-of-device-path device node is moved after the end of the appended
  101. device node. If the node is NULL then a copy of the device path is returned.
  102. If the device path is NULL then a copy of the node, followed by an
  103. end-of-device path device node is returned. If both are NULL then a copy of
  104. an end-of-device-path device node is returned. If there is not enough
  105. memory to allocate space for the new device path, then NULL is returned.
  106. The memory is allocated from EFI boot services memory. It is the
  107. responsibility of the caller to free the memory allocated.
  108. Arguments:
  109. DevicePath - Supplies an optional pointer to the device path.
  110. Node - Supplies an optional pointer to the device path node to append.
  111. Return Value:
  112. Returns a pointer to the appended device path on success. The caller is
  113. responsible for freeing this newly allocated memory.
  114. NULL on allocation failure.
  115. --*/
  116. EFIAPI
  117. UINTN
  118. EfiCoreGetDevicePathSize (
  119. CONST VOID *DevicePath
  120. );
  121. /*++
  122. Routine Description:
  123. This routine returns the length of the given device path in bytes.
  124. Arguments:
  125. DevicePath - Supplies a pointer to the device path.
  126. Return Value:
  127. Returns the device path size in bytes.
  128. 0 if the device path is NULL or invalid.
  129. --*/
  130. EFIAPI
  131. EFI_DEVICE_PATH_PROTOCOL *
  132. EfiCoreGetNextDevicePathNode (
  133. CONST VOID *Node
  134. );
  135. /*++
  136. Routine Description:
  137. This routine returns a pointer to the next node in the device.
  138. Arguments:
  139. Node - Supplies a pointer to the device path node.
  140. Return Value:
  141. Returns a pointer to the device path node that follows this node.
  142. --*/
  143. EFIAPI
  144. EFI_DEVICE_PATH_PROTOCOL *
  145. EfiCoreGetNextDevicePathInstance (
  146. EFI_DEVICE_PATH_PROTOCOL **DevicePath,
  147. UINTN *Size
  148. );
  149. /*++
  150. Routine Description:
  151. This routine creates a copy of the current device path instance and returns
  152. a pointer to the next device path instance.
  153. Arguments:
  154. DevicePath - Supplies a pointer that on input contains a pointer to the
  155. device path instance to copy. On output, this will point to the next
  156. device path instance on success or NULL on failure.
  157. Size - Supplies a pointer that on input contains the size of the device
  158. path. On output this value will be updated to contain the remaining
  159. size.
  160. Return Value:
  161. Returns a pointer to the current device path instance (duplicate).
  162. --*/
  163. EFIAPI
  164. EFI_DEVICE_PATH_PROTOCOL *
  165. EfiCoreGetDevicePathFromHandle (
  166. EFI_HANDLE Handle
  167. );
  168. /*++
  169. Routine Description:
  170. This routine returns the device path protocol instance on the given handle.
  171. Arguments:
  172. Handle - Supplies the handle to get the device path on.
  173. Return Value:
  174. Returns a pointer to the device path protocol on the handle.
  175. NULL on failure.
  176. --*/
  177. EFIAPI
  178. BOOLEAN
  179. EfiCoreIsDevicePathValid (
  180. CONST VOID *DevicePath,
  181. UINTN MaxSize
  182. );
  183. /*++
  184. Routine Description:
  185. This routine determines if a device path is valid.
  186. Arguments:
  187. DevicePath - Supplies a pointer to the device path to query.
  188. MaxSize - Supplies the maximum size of the device path structure.
  189. Return Value:
  190. TRUE if the device path is valid.
  191. FALSE if the length of any node is less than the header size, or the length
  192. exceeds the given maximum size (if not zero).
  193. --*/
  194. EFIAPI
  195. BOOLEAN
  196. EfiCoreIsDevicePathEnd (
  197. CONST VOID *Node
  198. );
  199. /*++
  200. Routine Description:
  201. This routine determines if a device path node is an end node of an
  202. entire device path.
  203. Arguments:
  204. Node - Supplies a pointer to the device path node.
  205. Return Value:
  206. TRUE if this node is the end of the entire device path.
  207. FALSE if this node is not the end of the entire device path.
  208. --*/
  209. EFIAPI
  210. BOOLEAN
  211. EfiCoreIsDevicePathEndInstance (
  212. CONST VOID *Node
  213. );
  214. /*++
  215. Routine Description:
  216. This routine determines if a device path node is an end node of a
  217. device path instance.
  218. Arguments:
  219. Node - Supplies a pointer to the device path node.
  220. Return Value:
  221. TRUE if this node is the end of the device path instance.
  222. FALSE if this node is not the end of the device path instance.
  223. --*/
  224. EFIAPI
  225. BOOLEAN
  226. EfiCoreIsDevicePathEndType (
  227. CONST VOID *Node
  228. );
  229. /*++
  230. Routine Description:
  231. This routine determines if a device path node is the end device path type.
  232. Arguments:
  233. Node - Supplies a pointer to the device path node.
  234. Return Value:
  235. TRUE if this node's type is the end type.
  236. FALSE if this node's type is not the end type.
  237. --*/
  238. EFIAPI
  239. UINT8
  240. EfiCoreGetDevicePathType (
  241. CONST VOID *Node
  242. );
  243. /*++
  244. Routine Description:
  245. This routine returns the device path type for the given node.
  246. Arguments:
  247. Node - Supplies a pointer to the device path node.
  248. Return Value:
  249. Returns the node's type.
  250. --*/
  251. EFIAPI
  252. UINT8
  253. EfiCoreGetDevicePathSubType (
  254. CONST VOID *Node
  255. );
  256. /*++
  257. Routine Description:
  258. This routine returns the device path sub-type for the given node.
  259. Arguments:
  260. Node - Supplies a pointer to the device path node.
  261. Return Value:
  262. Returns the node's sub-type.
  263. --*/
  264. EFIAPI
  265. UINTN
  266. EfiCoreGetDevicePathNodeLength (
  267. CONST VOID *Node
  268. );
  269. /*++
  270. Routine Description:
  271. This routine returns the length of the given device path node.
  272. Arguments:
  273. Node - Supplies a pointer to the device path node.
  274. Return Value:
  275. Returns the device path node length.
  276. --*/
  277. EFIAPI
  278. VOID
  279. EfiCoreInitializeFirmwareVolumeDevicePathNode (
  280. MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FirmwareFile,
  281. EFI_GUID *NameGuid
  282. );
  283. /*++
  284. Routine Description:
  285. This routine initializes a firmware volume file path.
  286. Arguments:
  287. FirmwareFile - Supplies a pointer to the device path node to initialize.
  288. NameGuid - Supplies a pointer to the name of the file.
  289. Return Value:
  290. None.
  291. --*/
  292. EFIAPI
  293. EFI_DEVICE_PATH_PROTOCOL *
  294. EfiCoreCreateFileDevicePath (
  295. EFI_HANDLE Device,
  296. CONST CHAR16 *FileName
  297. );
  298. /*++
  299. Routine Description:
  300. This routine creates a device path for a file and appends it to an existing
  301. device path. If the given device is a valid handle that contains a device
  302. path protocol, then a device path for the file specified by the given file
  303. name is allocated and appended to the device path associated with the
  304. given handle. The allocated device path is returned. If the device is NULL
  305. or the device is a handle that does not support the device path protocol,
  306. then a device path containing a single device path node for the file
  307. specified by the file name is allocated and returned. The memory for the
  308. new device path is allocated from EFI boot services memory. It is the
  309. responsibility of the caller to free the memory allocated.
  310. Arguments:
  311. Device - Supplies an optional device handle.
  312. FileName - Supplies a pointer to a null-terminated file path string.
  313. Return Value:
  314. Returns a pointer to the created device path.
  315. --*/
  316. EFIAPI
  317. EFI_GUID *
  318. EfiCoreGetNameGuidFromFirmwareVolumeDevicePathNode (
  319. CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *DevicePathNode
  320. );
  321. /*++
  322. Routine Description:
  323. This routine returns the file name GUID out of a firmware volume file
  324. path node.
  325. Arguments:
  326. DevicePathNode - Supplies a pointer to the device path node.
  327. Return Value:
  328. Returns a pointer to the file name GUID.
  329. --*/
  330. EFIAPI
  331. UINT16
  332. EfiCoreSetDevicePathNodeLength (
  333. VOID *Node,
  334. UINTN Length
  335. );
  336. /*++
  337. Routine Description:
  338. This routine sets a device path node length.
  339. Arguments:
  340. Node - Supplies a pointer to the device path header.
  341. Length - Supplies the length to set.
  342. Return Value:
  343. Returns the length value.
  344. --*/
  345. EFIAPI
  346. VOID
  347. EfiCoreSetDevicePathEndNode (
  348. VOID *Node
  349. );
  350. /*++
  351. Routine Description:
  352. This routine sets the given device path node as an end of the entire
  353. device path.
  354. Arguments:
  355. Node - Supplies a pointer to the device path header.
  356. Return Value:
  357. None.
  358. --*/