]> git.proxmox.com Git - mirror_edk2.git/blob - OptionRomPkg/UndiRuntimeDxe/ComponentName.c
EmulatorPkg: Remove framework pkgs dependency from EmulatorPkg
[mirror_edk2.git] / OptionRomPkg / UndiRuntimeDxe / ComponentName.c
1 /** @file
2 UEFI Component Name(2) protocol implementation for EFI UNDI32 driver.
3
4 Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9
10 #include "Undi32.h"
11
12 //
13 // EFI Component Name Functions
14 //
15 /**
16 Retrieves a Unicode string that is the user readable name of the driver.
17
18 This function retrieves the user readable name of a driver in the form of a
19 Unicode string. If the driver specified by This has a user readable name in
20 the language specified by Language, then a pointer to the driver name is
21 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
22 by This does not support the language specified by Language,
23 then EFI_UNSUPPORTED is returned.
24
25 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
26 EFI_COMPONENT_NAME_PROTOCOL instance.
27
28 @param Language[in] A pointer to a Null-terminated ASCII string
29 array indicating the language. This is the
30 language of the driver name that the caller is
31 requesting, and it must match one of the
32 languages specified in SupportedLanguages. The
33 number of languages supported by a driver is up
34 to the driver writer. Language is specified
35 in RFC 4646 or ISO 639-2 language code format.
36
37 @param DriverName[out] A pointer to the Unicode string to return.
38 This Unicode string is the name of the
39 driver specified by This in the language
40 specified by Language.
41
42 @retval EFI_SUCCESS The Unicode string for the Driver specified by
43 This and the language specified by Language was
44 returned in DriverName.
45
46 @retval EFI_INVALID_PARAMETER Language is NULL.
47
48 @retval EFI_INVALID_PARAMETER DriverName is NULL.
49
50 @retval EFI_UNSUPPORTED The driver specified by This does not support
51 the language specified by Language.
52
53 **/
54 EFI_STATUS
55 EFIAPI
56 UndiComponentNameGetDriverName (
57 IN EFI_COMPONENT_NAME_PROTOCOL *This,
58 IN CHAR8 *Language,
59 OUT CHAR16 **DriverName
60 );
61
62
63 /**
64 Retrieves a Unicode string that is the user readable name of the controller
65 that is being managed by a driver.
66
67 This function retrieves the user readable name of the controller specified by
68 ControllerHandle and ChildHandle in the form of a Unicode string. If the
69 driver specified by This has a user readable name in the language specified by
70 Language, then a pointer to the controller name is returned in ControllerName,
71 and EFI_SUCCESS is returned. If the driver specified by This is not currently
72 managing the controller specified by ControllerHandle and ChildHandle,
73 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
74 support the language specified by Language, then EFI_UNSUPPORTED is returned.
75
76 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
77 EFI_COMPONENT_NAME_PROTOCOL instance.
78
79 @param ControllerHandle[in] The handle of a controller that the driver
80 specified by This is managing. This handle
81 specifies the controller whose name is to be
82 returned.
83
84 @param ChildHandle[in] The handle of the child controller to retrieve
85 the name of. This is an optional parameter that
86 may be NULL. It will be NULL for device
87 drivers. It will also be NULL for a bus drivers
88 that wish to retrieve the name of the bus
89 controller. It will not be NULL for a bus
90 driver that wishes to retrieve the name of a
91 child controller.
92
93 @param Language[in] A pointer to a Null-terminated ASCII string
94 array indicating the language. This is the
95 language of the driver name that the caller is
96 requesting, and it must match one of the
97 languages specified in SupportedLanguages. The
98 number of languages supported by a driver is up
99 to the driver writer. Language is specified in
100 RFC 4646 or ISO 639-2 language code format.
101
102 @param ControllerName[out] A pointer to the Unicode string to return.
103 This Unicode string is the name of the
104 controller specified by ControllerHandle and
105 ChildHandle in the language specified by
106 Language from the point of view of the driver
107 specified by This.
108
109 @retval EFI_SUCCESS The Unicode string for the user readable name in
110 the language specified by Language for the
111 driver specified by This was returned in
112 DriverName.
113
114 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
115
116 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
117 EFI_HANDLE.
118
119 @retval EFI_INVALID_PARAMETER Language is NULL.
120
121 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
122
123 @retval EFI_UNSUPPORTED The driver specified by This is not currently
124 managing the controller specified by
125 ControllerHandle and ChildHandle.
126
127 @retval EFI_UNSUPPORTED The driver specified by This does not support
128 the language specified by Language.
129
130 **/
131 EFI_STATUS
132 EFIAPI
133 UndiComponentNameGetControllerName (
134 IN EFI_COMPONENT_NAME_PROTOCOL *This,
135 IN EFI_HANDLE ControllerHandle,
136 IN EFI_HANDLE ChildHandle OPTIONAL,
137 IN CHAR8 *Language,
138 OUT CHAR16 **ControllerName
139 );
140
141
142 //
143 // EFI Component Name Protocol
144 //
145 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gUndiComponentName = {
146 UndiComponentNameGetDriverName,
147 UndiComponentNameGetControllerName,
148 "eng"
149 };
150
151 //
152 // EFI Component Name 2 Protocol
153 //
154 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gUndiComponentName2 = {
155 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) UndiComponentNameGetDriverName,
156 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) UndiComponentNameGetControllerName,
157 "en"
158 };
159
160
161 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mUndiDriverNameTable[] = {
162 {
163 "eng;en",
164 L"UNDI32 Driver"
165 },
166 {
167 NULL,
168 NULL
169 }
170 };
171
172 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mUndiControllerNameTable[] = {
173 {
174 "eng;en",
175 L"UNDI32 Controller"
176 },
177 {
178 NULL,
179 NULL
180 }
181 };
182
183 /**
184 Retrieves a Unicode string that is the user readable name of the driver.
185
186 This function retrieves the user readable name of a driver in the form of a
187 Unicode string. If the driver specified by This has a user readable name in
188 the language specified by Language, then a pointer to the driver name is
189 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
190 by This does not support the language specified by Language,
191 then EFI_UNSUPPORTED is returned.
192
193 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
194 EFI_COMPONENT_NAME_PROTOCOL instance.
195
196 @param Language[in] A pointer to a Null-terminated ASCII string
197 array indicating the language. This is the
198 language of the driver name that the caller is
199 requesting, and it must match one of the
200 languages specified in SupportedLanguages. The
201 number of languages supported by a driver is up
202 to the driver writer. Language is specified
203 in RFC 4646 or ISO 639-2 language code format.
204
205 @param DriverName[out] A pointer to the Unicode string to return.
206 This Unicode string is the name of the
207 driver specified by This in the language
208 specified by Language.
209
210 @retval EFI_SUCCESS The Unicode string for the Driver specified by
211 This and the language specified by Language was
212 returned in DriverName.
213
214 @retval EFI_INVALID_PARAMETER Language is NULL.
215
216 @retval EFI_INVALID_PARAMETER DriverName is NULL.
217
218 @retval EFI_UNSUPPORTED The driver specified by This does not support
219 the language specified by Language.
220
221 **/
222 EFI_STATUS
223 EFIAPI
224 UndiComponentNameGetDriverName (
225 IN EFI_COMPONENT_NAME_PROTOCOL *This,
226 IN CHAR8 *Language,
227 OUT CHAR16 **DriverName
228 )
229 {
230 return LookupUnicodeString2 (
231 Language,
232 This->SupportedLanguages,
233 mUndiDriverNameTable,
234 DriverName,
235 (BOOLEAN)(This == &gUndiComponentName)
236 );
237 }
238
239 /**
240 Retrieves a Unicode string that is the user readable name of the controller
241 that is being managed by a driver.
242
243 This function retrieves the user readable name of the controller specified by
244 ControllerHandle and ChildHandle in the form of a Unicode string. If the
245 driver specified by This has a user readable name in the language specified by
246 Language, then a pointer to the controller name is returned in ControllerName,
247 and EFI_SUCCESS is returned. If the driver specified by This is not currently
248 managing the controller specified by ControllerHandle and ChildHandle,
249 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
250 support the language specified by Language, then EFI_UNSUPPORTED is returned.
251 Currently not implemented.
252
253 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
254 EFI_COMPONENT_NAME_PROTOCOL instance.
255
256 @param ControllerHandle[in] The handle of a controller that the driver
257 specified by This is managing. This handle
258 specifies the controller whose name is to be
259 returned.
260
261 @param ChildHandle[in] The handle of the child controller to retrieve
262 the name of. This is an optional parameter that
263 may be NULL. It will be NULL for device
264 drivers. It will also be NULL for a bus drivers
265 that wish to retrieve the name of the bus
266 controller. It will not be NULL for a bus
267 driver that wishes to retrieve the name of a
268 child controller.
269
270 @param Language[in] A pointer to a Null-terminated ASCII string
271 array indicating the language. This is the
272 language of the driver name that the caller is
273 requesting, and it must match one of the
274 languages specified in SupportedLanguages. The
275 number of languages supported by a driver is up
276 to the driver writer. Language is specified in
277 RFC 4646 or ISO 639-2 language code format.
278
279 @param ControllerName[out] A pointer to the Unicode string to return.
280 This Unicode string is the name of the
281 controller specified by ControllerHandle and
282 ChildHandle in the language specified by
283 Language from the point of view of the driver
284 specified by This.
285
286 @retval EFI_SUCCESS The Unicode string for the user readable name in
287 the language specified by Language for the
288 driver specified by This was returned in
289 DriverName.
290
291 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
292
293 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
294 EFI_HANDLE.
295
296 @retval EFI_INVALID_PARAMETER Language is NULL.
297
298 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
299
300 @retval EFI_UNSUPPORTED The driver specified by This is not currently
301 managing the controller specified by
302 ControllerHandle and ChildHandle.
303
304 @retval EFI_UNSUPPORTED The driver specified by This does not support
305 the language specified by Language.
306
307 **/
308 EFI_STATUS
309 EFIAPI
310 UndiComponentNameGetControllerName (
311 IN EFI_COMPONENT_NAME_PROTOCOL *This,
312 IN EFI_HANDLE ControllerHandle,
313 IN EFI_HANDLE ChildHandle OPTIONAL,
314 IN CHAR8 *Language,
315 OUT CHAR16 **ControllerName
316 )
317 {
318 EFI_STATUS Status;
319 EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL *Nii;
320
321 if (ChildHandle != NULL) {
322 return EFI_UNSUPPORTED;
323 }
324
325 //
326 // Make sure this driver is currently managing ControllHandle
327 //
328 Status = EfiTestManagedDevice (
329 ControllerHandle,
330 gUndiDriverBinding.DriverBindingHandle,
331 &gEfiPciIoProtocolGuid
332 );
333 if (EFI_ERROR (Status)) {
334 return Status;
335 }
336
337 //
338 // Retrieve an instance of a produced protocol from ControllerHandle
339 //
340 Status = gBS->OpenProtocol (
341 ControllerHandle,
342 &gEfiNetworkInterfaceIdentifierProtocolGuid_31,
343 (VOID **)&Nii,
344 NULL,
345 NULL,
346 EFI_OPEN_PROTOCOL_GET_PROTOCOL
347 );
348 if (EFI_ERROR (Status)) {
349 return Status;
350 }
351
352 return LookupUnicodeString2 (
353 Language,
354 This->SupportedLanguages,
355 mUndiControllerNameTable,
356 ControllerName,
357 (BOOLEAN)(This == &gUndiComponentName)
358 );
359 }