VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/ShellPkg/Library/UefiShellDriver1CommandsLib/OpenInfo.c@ 105670

Last change on this file since 105670 was 99404, checked in by vboxsync, 20 months ago

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

  • Property svn:eol-style set to native
File size: 7.5 KB
Line 
1/** @file
2 Main file for OpenInfo shell Driver1 function.
3
4 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8**/
9
10#include "UefiShellDriver1CommandsLib.h"
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
21/**
22 Open the database and print out all the info about TheHandle.
23
24 @param[in] TheHandle The handle to print info on.
25
26 @retval EFI_SUCCESS The operation was successful.
27 @retval EFI_INVALID_PARAMETER TheHandle was NULL.
28**/
29EFI_STATUS
30TraverseHandleDatabase (
31 IN CONST EFI_HANDLE TheHandle
32 )
33{
34 EFI_STATUS Status;
35 EFI_GUID **ProtocolGuidArray;
36 UINTN ArrayCount;
37 UINTN ProtocolIndex;
38 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo;
39 UINTN OpenInfoCount;
40 UINTN OpenInfoIndex;
41 CONST CHAR16 *OpenTypeString;
42 CHAR16 *TempString;
43 UINTN HandleIndex;
44 CONST CHAR16 *Name;
45 UINTN ControllerIndex;
46
47 if (TheHandle == NULL) {
48 return (EFI_INVALID_PARAMETER);
49 }
50
51 //
52 // Retrieve the list of all the protocols on the handle
53 //
54 Status = gBS->ProtocolsPerHandle (
55 TheHandle,
56 &ProtocolGuidArray,
57 &ArrayCount
58 );
59 ASSERT_EFI_ERROR (Status);
60 if (!EFI_ERROR (Status)) {
61 for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++) {
62 //
63 // print out the human readable name for this one.
64 //
65 TempString = GetStringNameFromGuid (ProtocolGuidArray[ProtocolIndex], NULL);
66 if (TempString == NULL) {
67 continue;
68 }
69
70 ShellPrintEx (-1, -1, L"%H%s%N\r\n", TempString);
71 FreePool (TempString);
72
73 //
74 // Retrieve the list of agents that have opened each protocol
75 //
76 Status = gBS->OpenProtocolInformation (
77 TheHandle,
78 ProtocolGuidArray[ProtocolIndex],
79 &OpenInfo,
80 &OpenInfoCount
81 );
82 ASSERT_EFI_ERROR (Status);
83 if (!EFI_ERROR (Status)) {
84 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
85 switch (OpenInfo[OpenInfoIndex].Attributes) {
86 case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL: OpenTypeString = StringHandProt;
87 break;
88 case EFI_OPEN_PROTOCOL_GET_PROTOCOL: OpenTypeString = StringGetProt;
89 break;
90 case EFI_OPEN_PROTOCOL_TEST_PROTOCOL: OpenTypeString = StringTestProt;
91 break;
92 case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER: OpenTypeString = StringChild;
93 break;
94 case EFI_OPEN_PROTOCOL_BY_DRIVER: OpenTypeString = StringDriver;
95 break;
96 case EFI_OPEN_PROTOCOL_EXCLUSIVE: OpenTypeString = StringExclusive;
97 break;
98 case EFI_OPEN_PROTOCOL_BY_DRIVER|EFI_OPEN_PROTOCOL_EXCLUSIVE:
99 OpenTypeString = StringDriverEx;
100 break;
101 default: OpenTypeString = StringUnknown;
102 break;
103 }
104
105 HandleIndex = ConvertHandleToHandleIndex (OpenInfo[OpenInfoIndex].AgentHandle);
106 Name = GetStringNameFromHandle (OpenInfo[OpenInfoIndex].AgentHandle, NULL);
107 ControllerIndex = ConvertHandleToHandleIndex (OpenInfo[OpenInfoIndex].ControllerHandle);
108 if (ControllerIndex != 0) {
109 ShellPrintHiiEx (
110 -1,
111 -1,
112 NULL,
113 STRING_TOKEN (STR_OPENINFO_LINE),
114 gShellDriver1HiiHandle,
115 HandleIndex,
116 ControllerIndex,
117 OpenInfo[OpenInfoIndex].OpenCount,
118 OpenTypeString,
119 Name
120 );
121 } else {
122 ShellPrintHiiEx (
123 -1,
124 -1,
125 NULL,
126 STRING_TOKEN (STR_OPENINFO_MIN_LINE),
127 gShellDriver1HiiHandle,
128 HandleIndex,
129 OpenInfo[OpenInfoIndex].OpenCount,
130 OpenTypeString,
131 Name
132 );
133 }
134 }
135
136 FreePool (OpenInfo);
137 }
138 }
139
140 FreePool (ProtocolGuidArray);
141 }
142
143 return Status;
144}
145
146/**
147 Function for 'openinfo' command.
148
149 @param[in] ImageHandle Handle to the Image (NULL if Internal).
150 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
151**/
152SHELL_STATUS
153EFIAPI
154ShellCommandRunOpenInfo (
155 IN EFI_HANDLE ImageHandle,
156 IN EFI_SYSTEM_TABLE *SystemTable
157 )
158{
159 EFI_STATUS Status;
160 LIST_ENTRY *Package;
161 CHAR16 *ProblemParam;
162 SHELL_STATUS ShellStatus;
163 EFI_HANDLE TheHandle;
164 CONST CHAR16 *Param1;
165 UINT64 Intermediate;
166
167 ShellStatus = SHELL_SUCCESS;
168
169 //
170 // initialize the shell lib (we must be in non-auto-init...)
171 //
172 Status = ShellInitialize ();
173 ASSERT_EFI_ERROR (Status);
174
175 Status = CommandInit ();
176 ASSERT_EFI_ERROR (Status);
177
178 //
179 // parse the command line
180 //
181 Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
182 if (EFI_ERROR (Status)) {
183 if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
184 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, L"openinfo", ProblemParam);
185 FreePool (ProblemParam);
186 ShellStatus = SHELL_INVALID_PARAMETER;
187 } else {
188 ASSERT (FALSE);
189 }
190 } else {
191 if (ShellCommandLineGetCount (Package) > 2) {
192 //
193 // error for too many parameters
194 //
195 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle, L"openinfo");
196 ShellStatus = SHELL_INVALID_PARAMETER;
197 } else if (ShellCommandLineGetCount (Package) == 0) {
198 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDriver1HiiHandle, L"openinfo");
199 ShellStatus = SHELL_INVALID_PARAMETER;
200 } else {
201 Param1 = ShellCommandLineGetRawValue (Package, 1);
202 Status = ShellConvertStringToUint64 (Param1, &Intermediate, TRUE, FALSE);
203 if (EFI_ERROR (Status) || (Param1 == NULL) || (ConvertHandleIndexToHandle ((UINTN)Intermediate) == NULL)) {
204 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"openinfo", Param1);
205 ShellStatus = SHELL_INVALID_PARAMETER;
206 } else {
207 TheHandle = ConvertHandleIndexToHandle ((UINTN)Intermediate);
208 ASSERT (TheHandle != NULL);
209 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_OPENINFO_HEADER_LINE), gShellDriver1HiiHandle, (UINTN)Intermediate, TheHandle);
210
211 Status = TraverseHandleDatabase (TheHandle);
212 if (!EFI_ERROR (Status)) {
213 } else {
214 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"openinfo", Param1);
215 ShellStatus = SHELL_NOT_FOUND;
216 }
217 }
218 }
219 }
220
221 return (ShellStatus);
222}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette