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