DevicePathTextLib.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /** @file
  2. Null Platform Hook Library instance.
  3. Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <Base.h>
  7. #include <Protocol/EmuThunk.h>
  8. #include <Protocol/EmuGraphicsWindow.h>
  9. #include <Protocol/EmuBlockIo.h>
  10. #include <Protocol/SimpleFileSystem.h>
  11. #include <Protocol/EmuThread.h>
  12. #include <Library/BaseLib.h>
  13. #include <Library/DevicePathToTextLib.h>
  14. #include <Library/BaseMemoryLib.h>
  15. #include <Library/DevicePathLib.h>
  16. /**
  17. Converts a Vendor device path structure to its string representative.
  18. @param Str The string representative of input device.
  19. @param DevPath The input device path structure.
  20. @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
  21. of the display node is used, where applicable. If DisplayOnly
  22. is FALSE, then the longer text representation of the display node
  23. is used.
  24. @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
  25. representation for a device node can be used, where applicable.
  26. @return EFI_NOT_FOUND if no string representation exists.
  27. @return EFI_SUCCESS a string representation was created.
  28. **/
  29. EFI_STATUS
  30. EFIAPI
  31. DevPathToTextVendorLib (
  32. IN OUT POOL_PRINT *Str,
  33. IN VOID *DevPath,
  34. IN BOOLEAN DisplayOnly,
  35. IN BOOLEAN AllowShortcuts
  36. )
  37. {
  38. EMU_VENDOR_DEVICE_PATH_NODE *Vendor;
  39. CHAR16 *Type;
  40. Vendor = (EMU_VENDOR_DEVICE_PATH_NODE *)DevPath;
  41. if (CompareGuid (&Vendor->VendorDevicePath.Guid, &gEmuThunkProtocolGuid)) {
  42. CatPrint (Str, L"EmuThunk()");
  43. return EFI_SUCCESS;
  44. }
  45. if (CompareGuid (&Vendor->VendorDevicePath.Guid, &gEmuGraphicsWindowProtocolGuid)) {
  46. CatPrint (Str, L"EmuGraphics(%d)", Vendor->Instance);
  47. return EFI_SUCCESS;
  48. }
  49. if (CompareGuid (&Vendor->VendorDevicePath.Guid, &gEfiSimpleFileSystemProtocolGuid)) {
  50. CatPrint (Str, L"EmuFs(%d)", Vendor->Instance);
  51. return EFI_SUCCESS;
  52. }
  53. if (CompareGuid (&Vendor->VendorDevicePath.Guid, &gEmuBlockIoProtocolGuid)) {
  54. CatPrint (Str, L"EmuBlk(%d)", Vendor->Instance);
  55. return EFI_SUCCESS;
  56. }
  57. if (CompareGuid (&Vendor->VendorDevicePath.Guid, &gEmuThreadThunkProtocolGuid)) {
  58. CatPrint (Str, L"EmuThread()");
  59. return EFI_SUCCESS;
  60. }
  61. return EFI_NOT_FOUND;
  62. }
  63. /**
  64. Converts a text device path node to Hardware Vendor device path structure.
  65. @param TextDeviceNode The input Text device path node.
  66. @return A pointer to the newly-created Hardware Vendor device path structure.
  67. **/
  68. EFI_DEVICE_PATH_PROTOCOL *
  69. DevPathFromTextEmuThunk (
  70. IN CHAR16 *TextDeviceNode
  71. )
  72. {
  73. CHAR16 *Str;
  74. VENDOR_DEVICE_PATH *Vendor;
  75. Str = GetNextParamStr (&TextDeviceNode);
  76. Vendor = (VENDOR_DEVICE_PATH *)CreateDeviceNode (
  77. HARDWARE_DEVICE_PATH,
  78. HW_VENDOR_DP,
  79. (UINT16)sizeof (VENDOR_DEVICE_PATH)
  80. );
  81. CopyGuid (&Vendor->Guid, &gEmuThunkProtocolGuid);
  82. return (EFI_DEVICE_PATH_PROTOCOL *)Vendor;
  83. }
  84. /**
  85. Converts a text device path node to Hardware Vendor device path structure.
  86. @param TextDeviceNode The input Text device path node.
  87. @return A pointer to the newly-created Hardware Vendor device path structure.
  88. **/
  89. EFI_DEVICE_PATH_PROTOCOL *
  90. DevPathFromTextEmuThread (
  91. IN CHAR16 *TextDeviceNode
  92. )
  93. {
  94. CHAR16 *Str;
  95. VENDOR_DEVICE_PATH *Vendor;
  96. Str = GetNextParamStr (&TextDeviceNode);
  97. Vendor = (VENDOR_DEVICE_PATH *)CreateDeviceNode (
  98. HARDWARE_DEVICE_PATH,
  99. HW_VENDOR_DP,
  100. (UINT16)sizeof (VENDOR_DEVICE_PATH)
  101. );
  102. CopyGuid (&Vendor->Guid, &gEmuThreadThunkProtocolGuid);
  103. return (EFI_DEVICE_PATH_PROTOCOL *)Vendor;
  104. }
  105. /**
  106. Converts a text device path node to Hardware Vendor device path structure.
  107. @param TextDeviceNode The input Text device path node.
  108. @return A pointer to the newly-created Hardware Vendor device path structure.
  109. **/
  110. EFI_DEVICE_PATH_PROTOCOL *
  111. DevPathFromTextEmuFs (
  112. IN CHAR16 *TextDeviceNode
  113. )
  114. {
  115. CHAR16 *Str;
  116. EMU_VENDOR_DEVICE_PATH_NODE *Vendor;
  117. Str = GetNextParamStr (&TextDeviceNode);
  118. Vendor = (EMU_VENDOR_DEVICE_PATH_NODE *)CreateDeviceNode (
  119. HARDWARE_DEVICE_PATH,
  120. HW_VENDOR_DP,
  121. (UINT16)sizeof (EMU_VENDOR_DEVICE_PATH_NODE)
  122. );
  123. CopyGuid (&Vendor->VendorDevicePath.Guid, &gEfiSimpleFileSystemProtocolGuid);
  124. Vendor->Instance = (UINT32)StrDecimalToUintn (Str);
  125. return (EFI_DEVICE_PATH_PROTOCOL *)Vendor;
  126. }
  127. /**
  128. Register the Filter function
  129. @param ImageHandle The firmware allocated handle for the EFI image.
  130. @param SystemTable A pointer to the EFI System Table.
  131. @retval EFI_SUCCESS The constructor executed correctly.
  132. **/
  133. EFI_STATUS
  134. EFIAPI
  135. DevicePathToTextLibConstructor (
  136. IN EFI_HANDLE ImageHandle,
  137. IN EFI_SYSTEM_TABLE *SystemTable
  138. )
  139. {
  140. DevPathToTextSetVendorDevicePathFilter (DevPathToTextVendorLib);
  141. DevicePathFromTextAddFilter (L"EmuThunk", DevPathFromTextEmuThunk);
  142. DevicePathFromTextAddFilter (L"EmuThread", DevPathFromTextEmuThread);
  143. DevicePathFromTextAddFilter (L"EmuFs", DevPathFromTextEmuFs);
  144. return EFI_SUCCESS;
  145. }