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