TianoCore EDK2 master
Loading...
Searching...
No Matches
OpenInfo.c
Go to the documentation of this file.
1
11
12STATIC CONST CHAR16 StringHandProt[] = L"HandProt ";
13STATIC CONST CHAR16 StringGetProt[] = L"GetProt ";
14STATIC CONST CHAR16 StringTestProt[] = L"TestProt ";
15STATIC CONST CHAR16 StringChild[] = L"Child ";
16STATIC CONST CHAR16 StringDriver[] = L"Driver ";
17STATIC CONST CHAR16 StringExclusive[] = L"Exclusive";
18STATIC CONST CHAR16 StringDriverEx[] = L"DriverEx ";
19STATIC CONST CHAR16 StringUnknown[] = L"Unknown ";
20
32 IN CONST EFI_HANDLE TheHandle
33 )
34{
35 EFI_STATUS Status;
36 EFI_GUID **ProtocolGuidArray;
37 UINTN ArrayCount;
38 UINTN ProtocolIndex;
40 UINTN OpenInfoCount;
41 UINTN OpenInfoIndex;
42 CONST CHAR16 *OpenTypeString;
43 CHAR16 *TempString;
44 UINTN HandleIndex;
45 CONST CHAR16 *Name;
46 UINTN ControllerIndex;
47
48 if (TheHandle == NULL) {
49 return (EFI_INVALID_PARAMETER);
50 }
51
52 //
53 // Retrieve the list of all the protocols on the handle
54 //
55 Status = gBS->ProtocolsPerHandle (
56 TheHandle,
57 &ProtocolGuidArray,
58 &ArrayCount
59 );
60 ASSERT_EFI_ERROR (Status);
61 if (!EFI_ERROR (Status)) {
62 for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++) {
63 //
64 // print out the human readable name for this one.
65 //
66 TempString = GetStringNameFromGuid (ProtocolGuidArray[ProtocolIndex], NULL);
67 if (TempString == NULL) {
68 continue;
69 }
70
71 ShellPrintEx (-1, -1, L"%H%s%N\r\n", TempString);
72 FreePool (TempString);
73
74 //
75 // Retrieve the list of agents that have opened each protocol
76 //
77 Status = gBS->OpenProtocolInformation (
78 TheHandle,
79 ProtocolGuidArray[ProtocolIndex],
80 &OpenInfo,
81 &OpenInfoCount
82 );
83 ASSERT_EFI_ERROR (Status);
84 if (!EFI_ERROR (Status)) {
85 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
86 switch (OpenInfo[OpenInfoIndex].Attributes) {
87 case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL: OpenTypeString = StringHandProt;
88 break;
89 case EFI_OPEN_PROTOCOL_GET_PROTOCOL: OpenTypeString = StringGetProt;
90 break;
91 case EFI_OPEN_PROTOCOL_TEST_PROTOCOL: OpenTypeString = StringTestProt;
92 break;
93 case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER: OpenTypeString = StringChild;
94 break;
95 case EFI_OPEN_PROTOCOL_BY_DRIVER: OpenTypeString = StringDriver;
96 break;
97 case EFI_OPEN_PROTOCOL_EXCLUSIVE: OpenTypeString = StringExclusive;
98 break;
99 case EFI_OPEN_PROTOCOL_BY_DRIVER|EFI_OPEN_PROTOCOL_EXCLUSIVE:
100 OpenTypeString = StringDriverEx;
101 break;
102 default: OpenTypeString = StringUnknown;
103 break;
104 }
105
106 HandleIndex = ConvertHandleToHandleIndex (OpenInfo[OpenInfoIndex].AgentHandle);
107 if (HandleIndex == 0) {
108 FreePool (OpenInfo);
109 FreePool (ProtocolGuidArray);
110 return EFI_OUT_OF_RESOURCES;
111 }
112
113 Name = GetStringNameFromHandle (OpenInfo[OpenInfoIndex].AgentHandle, NULL);
114 ControllerIndex = ConvertHandleToHandleIndex (OpenInfo[OpenInfoIndex].ControllerHandle);
115 if ((ControllerIndex != 0) && (Name != NULL)) {
117 -1,
118 -1,
119 NULL,
120 STRING_TOKEN (STR_OPENINFO_LINE),
121 gShellDriver1HiiHandle,
122 HandleIndex,
123 ControllerIndex,
124 OpenInfo[OpenInfoIndex].OpenCount,
125 OpenTypeString,
126 Name
127 );
128 } else {
130 -1,
131 -1,
132 NULL,
133 STRING_TOKEN (STR_OPENINFO_MIN_LINE),
134 gShellDriver1HiiHandle,
135 HandleIndex,
136 OpenInfo[OpenInfoIndex].OpenCount,
137 OpenTypeString,
138 Name ? Name : L""
139 );
140 }
141 }
142
143 FreePool (OpenInfo);
144 }
145 }
146
147 FreePool (ProtocolGuidArray);
148 }
149
150 return Status;
151}
152
160EFIAPI
162 IN EFI_HANDLE ImageHandle,
163 IN EFI_SYSTEM_TABLE *SystemTable
164 )
165{
166 EFI_STATUS Status;
167 LIST_ENTRY *Package;
168 CHAR16 *ProblemParam;
169 SHELL_STATUS ShellStatus;
170 EFI_HANDLE TheHandle;
171 CONST CHAR16 *Param1;
172 UINT64 Intermediate;
173
174 ShellStatus = SHELL_SUCCESS;
175
176 //
177 // initialize the shell lib (we must be in non-auto-init...)
178 //
179 Status = ShellInitialize ();
180 ASSERT_EFI_ERROR (Status);
181
182 Status = CommandInit ();
183 ASSERT_EFI_ERROR (Status);
184
185 //
186 // parse the command line
187 //
188 Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
189 if (EFI_ERROR (Status)) {
190 if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
191 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, L"openinfo", ProblemParam);
192 FreePool (ProblemParam);
193 ShellStatus = SHELL_INVALID_PARAMETER;
194 } else {
195 ASSERT (FALSE);
196 }
197 } else {
198 if (ShellCommandLineGetCount (Package) > 2) {
199 //
200 // error for too many parameters
201 //
202 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle, L"openinfo");
203 ShellStatus = SHELL_INVALID_PARAMETER;
204 } else if (ShellCommandLineGetCount (Package) == 0) {
205 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDriver1HiiHandle, L"openinfo");
206 ShellStatus = SHELL_INVALID_PARAMETER;
207 } else {
208 Param1 = ShellCommandLineGetRawValue (Package, 1);
209 if (Param1 != NULL) {
210 Status = ShellConvertStringToUint64 (Param1, &Intermediate, TRUE, FALSE);
211 }
212
213 if (EFI_ERROR (Status) || (Param1 == NULL) || (ConvertHandleIndexToHandle ((UINTN)Intermediate) == NULL)) {
214 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"openinfo", Param1);
215 ShellStatus = SHELL_INVALID_PARAMETER;
216 } else {
217 TheHandle = ConvertHandleIndexToHandle ((UINTN)Intermediate);
218 if (TheHandle == NULL) {
219 ASSERT (TheHandle != NULL);
220 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"openinfo", Param1);
222 }
223
224 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_OPENINFO_HEADER_LINE), gShellDriver1HiiHandle, (UINTN)Intermediate, TheHandle);
225
226 Status = TraverseHandleDatabase (TheHandle);
227 if (!EFI_ERROR (Status)) {
228 } else {
229 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"openinfo", Param1);
230 ShellStatus = SHELL_NOT_FOUND;
231 }
232 }
233 }
234 }
235
236 return (ShellStatus);
237}
UINT64 UINTN
VOID EFIAPI FreePool(IN VOID *Buffer)
CONST CHAR16 *EFIAPI GetStringNameFromHandle(IN CONST EFI_HANDLE TheHandle, IN CONST CHAR8 *Language)
CHAR16 *EFIAPI GetStringNameFromGuid(IN CONST EFI_GUID *Guid, IN CONST CHAR8 *Lang OPTIONAL)
EFI_HANDLE EFIAPI ConvertHandleIndexToHandle(IN CONST UINTN TheIndex)
UINTN EFIAPI ConvertHandleToHandleIndex(IN CONST EFI_HANDLE TheHandle)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
SHELL_STATUS
Definition: Shell.h:21
@ SHELL_SUCCESS
Definition: Shell.h:25
@ SHELL_NOT_FOUND
Definition: Shell.h:101
@ SHELL_INVALID_PARAMETER
Definition: Shell.h:35
EFI_STATUS TraverseHandleDatabase(IN CONST EFI_HANDLE TheHandle)
Definition: OpenInfo.c:31
SHELL_STATUS EFIAPI ShellCommandRunOpenInfo(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: OpenInfo.c:161
EFI_STATUS EFIAPI CommandInit(VOID)
#define ShellCommandLineParse(CheckList, CheckPackage, ProblemParam, AutoPageBreak)
Make it easy to upgrade from older versions of the shell library.
Definition: ShellLib.h:755
EFI_STATUS EFIAPI ShellPrintHiiEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR8 *Language OPTIONAL, IN CONST EFI_STRING_ID HiiFormatStringId, IN CONST EFI_HII_HANDLE HiiFormatHandle,...)
EFI_STATUS EFIAPI ShellInitialize(VOID)
Definition: UefiShellLib.c:532
EFI_STATUS EFIAPI ShellPrintEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR16 *Format,...)
CONST CHAR16 *EFIAPI ShellCommandLineGetRawValue(IN CONST LIST_ENTRY *CONST CheckPackage, IN UINTN Position)
UINTN EFIAPI ShellCommandLineGetCount(IN CONST LIST_ENTRY *CheckPackage)
EFI_STATUS EFIAPI ShellConvertStringToUint64(IN CONST CHAR16 *String, OUT UINT64 *Value, IN CONST BOOLEAN ForceHex, IN CONST BOOLEAN StopAtSpace)
SHELL_PARAM_ITEM EmptyParamList[]
Helper structure for no parameters (besides -? and -b)
Definition: UefiShellLib.c:19
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
EFI_BOOT_SERVICES * gBS
#define STRING_TOKEN(t)
Definition: Base.h:213