]> git.proxmox.com Git - mirror_edk2.git/blob - OptionRomPkg/DriverHealthDxe/ComponentName.c
Fix a obvious bug for judge whether the PPB support ISA
[mirror_edk2.git] / OptionRomPkg / DriverHealthDxe / ComponentName.c
1 /** @file
2 UEFI Component Name(2) protocol implementation for DiskIo driver.
3
4 Copyright (c) 2006 - 2009, Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "DriverHealthDxe.h"
16
17 #define DISK_IO_CONTRORLLER_NAME "Disk Io Controller # "
18
19 //
20 // EFI Component Name Protocol
21 //
22 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gDiskIoComponentName = {
23 DiskIoComponentNameGetDriverName,
24 DiskIoComponentNameGetControllerName,
25 "eng"
26 };
27
28 //
29 // EFI Component Name 2 Protocol
30 //
31 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gDiskIoComponentName2 = {
32 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) DiskIoComponentNameGetDriverName,
33 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) DiskIoComponentNameGetControllerName,
34 "en"
35 };
36
37 //
38 // Driver name table for DiskIo module.
39 // It is shared by the implementation of ComponentName & ComponentName2 Protocol.
40 //
41 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mDiskIoDriverNameTable[] = {
42 {
43 "eng;en",
44 (CHAR16 *)L"Generic Disk I/O Driver"
45 },
46 {
47 NULL,
48 NULL
49 }
50 };
51
52
53
54 /**
55 Retrieves a Unicode string that is the user readable name of the driver.
56
57 This function retrieves the user readable name of a driver in the form of a
58 Unicode string. If the driver specified by This has a user readable name in
59 the language specified by Language, then a pointer to the driver name is
60 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
61 by This does not support the language specified by Language,
62 then EFI_UNSUPPORTED is returned.
63
64 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
65 EFI_COMPONENT_NAME_PROTOCOL instance.
66
67 @param Language[in] A pointer to a Null-terminated ASCII string
68 array indicating the language. This is the
69 language of the driver name that the caller is
70 requesting, and it must match one of the
71 languages specified in SupportedLanguages. The
72 number of languages supported by a driver is up
73 to the driver writer. Language is specified
74 in RFC 4646 or ISO 639-2 language code format.
75
76 @param DriverName[out] A pointer to the Unicode string to return.
77 This Unicode string is the name of the
78 driver specified by This in the language
79 specified by Language.
80
81 @retval EFI_SUCCESS The Unicode string for the Driver specified by
82 This and the language specified by Language was
83 returned in DriverName.
84
85 @retval EFI_INVALID_PARAMETER Language is NULL.
86
87 @retval EFI_INVALID_PARAMETER DriverName is NULL.
88
89 @retval EFI_UNSUPPORTED The driver specified by This does not support
90 the language specified by Language.
91
92 **/
93 EFI_STATUS
94 EFIAPI
95 DiskIoComponentNameGetDriverName (
96 IN EFI_COMPONENT_NAME_PROTOCOL *This,
97 IN CHAR8 *Language,
98 OUT CHAR16 **DriverName
99 )
100 {
101 return LookupUnicodeString2 (
102 Language,
103 This->SupportedLanguages,
104 mDiskIoDriverNameTable,
105 DriverName,
106 (BOOLEAN)(This == &gDiskIoComponentName)
107 );
108 }
109
110
111
112 /**
113 Retrieves a Unicode string that is the user readable name of the controller
114 that is being managed by a driver.
115
116 This function retrieves the user readable name of the controller specified by
117 ControllerHandle and ChildHandle in the form of a Unicode string. If the
118 driver specified by This has a user readable name in the language specified by
119 Language, then a pointer to the controller name is returned in ControllerName,
120 and EFI_SUCCESS is returned. If the driver specified by This is not currently
121 managing the controller specified by ControllerHandle and ChildHandle,
122 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
123 support the language specified by Language, then EFI_UNSUPPORTED is returned.
124
125 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
126 EFI_COMPONENT_NAME_PROTOCOL instance.
127
128 @param ControllerHandle[in] The handle of a controller that the driver
129 specified by This is managing. This handle
130 specifies the controller whose name is to be
131 returned.
132
133 @param ChildHandle[in] The handle of the child controller to retrieve
134 the name of. This is an optional parameter that
135 may be NULL. It will be NULL for device
136 drivers. It will also be NULL for a bus drivers
137 that wish to retrieve the name of the bus
138 controller. It will not be NULL for a bus
139 driver that wishes to retrieve the name of a
140 child controller.
141
142 @param Language[in] A pointer to a Null-terminated ASCII string
143 array indicating the language. This is the
144 language of the driver name that the caller is
145 requesting, and it must match one of the
146 languages specified in SupportedLanguages. The
147 number of languages supported by a driver is up
148 to the driver writer. Language is specified in
149 RFC 4646 or ISO 639-2 language code format.
150
151 @param ControllerName[out] A pointer to the Unicode string to return.
152 This Unicode string is the name of the
153 controller specified by ControllerHandle and
154 ChildHandle in the language specified by
155 Language from the point of view of the driver
156 specified by This.
157
158 @retval EFI_SUCCESS The Unicode string for the user readable name in
159 the language specified by Language for the
160 driver specified by This was returned in
161 DriverName.
162
163 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
164
165 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
166 EFI_HANDLE.
167
168 @retval EFI_INVALID_PARAMETER Language is NULL.
169
170 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
171
172 @retval EFI_UNSUPPORTED The driver specified by This is not currently
173 managing the controller specified by
174 ControllerHandle and ChildHandle.
175
176 @retval EFI_UNSUPPORTED The driver specified by This does not support
177 the language specified by Language.
178
179 **/
180 EFI_STATUS
181 EFIAPI
182 DiskIoComponentNameGetControllerName (
183 IN EFI_COMPONENT_NAME_PROTOCOL *This,
184 IN EFI_HANDLE ControllerHandle,
185 IN EFI_HANDLE ChildHandle OPTIONAL,
186 IN CHAR8 *Language,
187 OUT CHAR16 **ControllerName
188 )
189 {
190 EFI_STATUS Status;
191 EFI_DISK_IO_PROTOCOL *DiskIo;
192 DISK_IO_PRIVATE_DATA *Private;
193
194 //
195 // This is a device driver, so ChildHandle must be NULL.
196 //
197 if (ChildHandle != NULL) {
198 return EFI_UNSUPPORTED;
199 }
200 //
201 // Make sure this driver is currently managing ControllerHandle
202 //
203 Status = EfiTestManagedDevice (
204 ControllerHandle,
205 gDiskIoDriverBinding.DriverBindingHandle,
206 &gEfiBlockIoProtocolGuid
207 );
208 if (EFI_ERROR (Status)) {
209 return Status;
210 }
211 //
212 // Get the Block I/O Protocol on Controller
213 //
214 Status = gBS->OpenProtocol (
215 ControllerHandle,
216 &gEfiDiskIoProtocolGuid,
217 (VOID **) &DiskIo,
218 gDiskIoDriverBinding.DriverBindingHandle,
219 ControllerHandle,
220 EFI_OPEN_PROTOCOL_GET_PROTOCOL
221 );
222 if (EFI_ERROR (Status)) {
223 return Status;
224 }
225 //
226 // Get the Serial Controller's Device structure
227 //
228 Private = DISK_IO_PRIVATE_DATA_FROM_THIS (DiskIo);
229
230 return LookupUnicodeString2 (
231 Language,
232 This->SupportedLanguages,
233 Private->ControllerNameTable,
234 ControllerName,
235 (BOOLEAN)(This == &gDiskIoComponentName)
236 );
237 }
238
239 /**
240 Add the ISO639-2 and RFC4646 component name both for the Disk IO device
241
242 @param DiskIoDevice A pointer to the DISK_IO_PRIVATE_DATA instance.
243
244 **/
245 VOID
246 AddName (
247 IN DISK_IO_PRIVATE_DATA *DiskIoDevice
248 )
249 {
250 CHAR16 DiskIoControllerName[sizeof (DISK_IO_CONTRORLLER_NAME)];
251
252 StrCpy (DiskIoControllerName, L"Disk Io Controller # ");
253 DiskIoControllerName[sizeof (DISK_IO_CONTRORLLER_NAME) - 2] = (CHAR16) (L'0' + DiskIoDevice->ControllerIndex);
254 AddUnicodeString2 (
255 "eng",
256 gDiskIoComponentName.SupportedLanguages,
257 &DiskIoDevice->ControllerNameTable,
258 (CHAR16 *) DiskIoControllerName,
259 TRUE
260 );
261 AddUnicodeString2 (
262 "en",
263 gDiskIoComponentName2.SupportedLanguages,
264 &DiskIoDevice->ControllerNameTable,
265 (CHAR16 *) DiskIoControllerName,
266 FALSE
267 );
268
269 }