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