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