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