1 /** @file
2 
3 Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution.  The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8 
9 **/
10 
11 #include "EmuBusDriverDxe.h"
12 
13 //
14 // EFI Component Name Functions
15 //
16 EFI_STATUS
17 EFIAPI
18 EmuBusDriverComponentNameGetDriverName (
19   IN  EFI_COMPONENT_NAME_PROTOCOL  *This,
20   IN  CHAR8                        *Language,
21   OUT CHAR16                       **DriverName
22   );
23 
24 EFI_STATUS
25 EFIAPI
26 EmuBusDriverComponentNameGetControllerName (
27   IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,
28   IN  EFI_HANDLE                                      ControllerHandle,
29   IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,
30   IN  CHAR8                                           *Language,
31   OUT CHAR16                                          **ControllerName
32   );
33 
34 //
35 // EFI Component Name Protocol
36 //
37 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL     gEmuBusDriverComponentName = {
38   EmuBusDriverComponentNameGetDriverName,
39   EmuBusDriverComponentNameGetControllerName,
40   "eng"
41 };
42 
43 //
44 // EFI Component Name 2 Protocol
45 //
46 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gEmuBusDriverComponentName2 = {
47   (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) EmuBusDriverComponentNameGetDriverName,
48   (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) EmuBusDriverComponentNameGetControllerName,
49   "en"
50 };
51 
52 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mEmuBusDriverNameTable[] = {
53   { "eng", L"Emu Bus Driver" },
54   { NULL , NULL }
55 };
56 
57 /**
58   Retrieves a Unicode string that is the user readable name of the driver.
59 
60   This function retrieves the user readable name of a driver in the form of a
61   Unicode string. If the driver specified by This has a user readable name in
62   the language specified by Language, then a pointer to the driver name is
63   returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
64   by This does not support the language specified by Language,
65   then EFI_UNSUPPORTED is returned.
66 
67   @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
68                                 EFI_COMPONENT_NAME_PROTOCOL instance.
69 
70   @param  Language[in]          A pointer to a Null-terminated ASCII string
71                                 array indicating the language. This is the
72                                 language of the driver name that the caller is
73                                 requesting, and it must match one of the
74                                 languages specified in SupportedLanguages. The
75                                 number of languages supported by a driver is up
76                                 to the driver writer. Language is specified
77                                 in RFC 4646 or ISO 639-2 language code format.
78 
79   @param  DriverName[out]       A pointer to the Unicode string to return.
80                                 This Unicode string is the name of the
81                                 driver specified by This in the language
82                                 specified by Language.
83 
84   @retval EFI_SUCCESS           The Unicode string for the Driver specified by
85                                 This and the language specified by Language was
86                                 returned in DriverName.
87 
88   @retval EFI_INVALID_PARAMETER Language is NULL.
89 
90   @retval EFI_INVALID_PARAMETER DriverName is NULL.
91 
92   @retval EFI_UNSUPPORTED       The driver specified by This does not support
93                                 the language specified by Language.
94 
95 **/
96 EFI_STATUS
97 EFIAPI
EmuBusDriverComponentNameGetDriverName(IN EFI_COMPONENT_NAME_PROTOCOL * This,IN CHAR8 * Language,OUT CHAR16 ** DriverName)98 EmuBusDriverComponentNameGetDriverName (
99   IN  EFI_COMPONENT_NAME_PROTOCOL  *This,
100   IN  CHAR8                        *Language,
101   OUT CHAR16                       **DriverName
102   )
103 {
104   return LookupUnicodeString2 (
105           Language,
106           This->SupportedLanguages,
107           mEmuBusDriverNameTable,
108           DriverName,
109           (BOOLEAN)(This == &gEmuBusDriverComponentName)
110           );
111 }
112 
113 /**
114   Retrieves a Unicode string that is the user readable name of the controller
115   that is being managed by a driver.
116 
117   This function retrieves the user readable name of the controller specified by
118   ControllerHandle and ChildHandle in the form of a Unicode string. If the
119   driver specified by This has a user readable name in the language specified by
120   Language, then a pointer to the controller name is returned in ControllerName,
121   and EFI_SUCCESS is returned.  If the driver specified by This is not currently
122   managing the controller specified by ControllerHandle and ChildHandle,
123   then EFI_UNSUPPORTED is returned.  If the driver specified by This does not
124   support the language specified by Language, then EFI_UNSUPPORTED is returned.
125 
126   @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
127                                 EFI_COMPONENT_NAME_PROTOCOL instance.
128 
129   @param  ControllerHandle[in]  The handle of a controller that the driver
130                                 specified by This is managing.  This handle
131                                 specifies the controller whose name is to be
132                                 returned.
133 
134   @param  ChildHandle[in]       The handle of the child controller to retrieve
135                                 the name of.  This is an optional parameter that
136                                 may be NULL.  It will be NULL for device
137                                 drivers.  It will also be NULL for a bus drivers
138                                 that wish to retrieve the name of the bus
139                                 controller.  It will not be NULL for a bus
140                                 driver that wishes to retrieve the name of a
141                                 child controller.
142 
143   @param  Language[in]          A pointer to a Null-terminated ASCII string
144                                 array indicating the language.  This is the
145                                 language of the driver name that the caller is
146                                 requesting, and it must match one of the
147                                 languages specified in SupportedLanguages. The
148                                 number of languages supported by a driver is up
149                                 to the driver writer. Language is specified in
150                                 RFC 4646 or ISO 639-2 language code format.
151 
152   @param  ControllerName[out]   A pointer to the Unicode string to return.
153                                 This Unicode string is the name of the
154                                 controller specified by ControllerHandle and
155                                 ChildHandle in the language specified by
156                                 Language from the point of view of the driver
157                                 specified by This.
158 
159   @retval EFI_SUCCESS           The Unicode string for the user readable name in
160                                 the language specified by Language for the
161                                 driver specified by This was returned in
162                                 DriverName.
163 
164   @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
165 
166   @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
167                                 EFI_HANDLE.
168 
169   @retval EFI_INVALID_PARAMETER Language is NULL.
170 
171   @retval EFI_INVALID_PARAMETER ControllerName is NULL.
172 
173   @retval EFI_UNSUPPORTED       The driver specified by This is not currently
174                                 managing the controller specified by
175                                 ControllerHandle and ChildHandle.
176 
177   @retval EFI_UNSUPPORTED       The driver specified by This does not support
178                                 the language specified by Language.
179 
180 **/
181 EFI_STATUS
182 EFIAPI
EmuBusDriverComponentNameGetControllerName(IN EFI_COMPONENT_NAME_PROTOCOL * This,IN EFI_HANDLE ControllerHandle,IN EFI_HANDLE ChildHandle OPTIONAL,IN CHAR8 * Language,OUT CHAR16 ** ControllerName)183 EmuBusDriverComponentNameGetControllerName (
184   IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,
185   IN  EFI_HANDLE                                      ControllerHandle,
186   IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,
187   IN  CHAR8                                           *Language,
188   OUT CHAR16                                          **ControllerName
189   )
190 {
191   EFI_STATUS              Status;
192   EMU_IO_THUNK_PROTOCOL   *EmuIo;
193   EMU_IO_DEVICE           *Private;
194 
195   //
196   // Make sure this driver is currently managing ControllHandle
197   //
198   Status = EfiTestManagedDevice (
199              ControllerHandle,
200              gEmuBusDriverBinding.DriverBindingHandle,
201              &gEmuThunkProtocolGuid
202              );
203   if (EFI_ERROR (Status)) {
204     return Status;
205   }
206 
207   //
208   // This is a bus driver, so ChildHandle can not be NULL.
209   //
210   if (ChildHandle == NULL) {
211     return EFI_UNSUPPORTED;
212   }
213 
214   Status = EfiTestChildHandle (
215              ControllerHandle,
216              ChildHandle,
217              &gEmuThunkProtocolGuid
218              );
219   if (EFI_ERROR (Status)) {
220     return Status;
221   }
222 
223   //
224   // Get our context back
225   //
226   Status = gBS->OpenProtocol (
227                   ChildHandle,
228                   &gEmuIoThunkProtocolGuid,
229                   (VOID**)&EmuIo,
230                   gEmuBusDriverBinding.DriverBindingHandle,
231                   ChildHandle,
232                   EFI_OPEN_PROTOCOL_GET_PROTOCOL
233                   );
234   if (EFI_ERROR (Status)) {
235     return EFI_UNSUPPORTED;
236   }
237 
238   Private = EMU_IO_DEVICE_FROM_THIS (EmuIo);
239 
240   return LookupUnicodeString2 (
241            Language,
242            This->SupportedLanguages,
243            Private->ControllerNameTable,
244            ControllerName,
245            (BOOLEAN)(This == &gEmuBusDriverComponentName)
246           );
247 }
248