1 /** @file
2 UEFI Component Name(2) protocol implementation for USB Keyboard driver.
3
4 Copyright (c) 2004 - 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
16 #include "KeyBoard.h"
17
18 //
19 // EFI Component Name Protocol
20 //
21 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gUsbKeyboardComponentName = {
22 UsbKeyboardComponentNameGetDriverName,
23 UsbKeyboardComponentNameGetControllerName,
24 "eng"
25 };
26
27 //
28 // EFI Component Name 2 Protocol
29 //
30 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gUsbKeyboardComponentName2 = {
31 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) UsbKeyboardComponentNameGetDriverName,
32 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) UsbKeyboardComponentNameGetControllerName,
33 "en"
34 };
35
36
37 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mUsbKeyboardDriverNameTable[] = {
38 { "eng;en", L"Usb Keyboard Driver" },
39 { NULL , NULL }
40 };
41
42 /**
43 Retrieves a Unicode string that is the user readable name of the driver.
44
45 This function retrieves the user readable name of a driver in the form of a
46 Unicode string. If the driver specified by This has a user readable name in
47 the language specified by Language, then a pointer to the driver name is
48 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
49 by This does not support the language specified by Language,
50 then EFI_UNSUPPORTED is returned.
51
52 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
53 EFI_COMPONENT_NAME_PROTOCOL instance.
54 @param Language A pointer to a Null-terminated ASCII string
55 array indicating the language. This is the
56 language of the driver name that the caller is
57 requesting, and it must match one of the
58 languages specified in SupportedLanguages. The
59 number of languages supported by a driver is up
60 to the driver writer. Language is specified
61 in RFC 4646 or ISO 639-2 language code format.
62 @param DriverName A pointer to the Unicode string to return.
63 This Unicode string is the name of the
64 driver specified by This in the language
65 specified by Language.
66
67 @retval EFI_SUCCESS The Unicode string for the Driver specified by
68 This and the language specified by Language was
69 returned in DriverName.
70 @retval EFI_INVALID_PARAMETER Language is NULL.
71 @retval EFI_INVALID_PARAMETER DriverName is NULL.
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
UsbKeyboardComponentNameGetDriverName(IN EFI_COMPONENT_NAME_PROTOCOL * This,IN CHAR8 * Language,OUT CHAR16 ** DriverName)78 UsbKeyboardComponentNameGetDriverName (
79 IN EFI_COMPONENT_NAME_PROTOCOL *This,
80 IN CHAR8 *Language,
81 OUT CHAR16 **DriverName
82 )
83 {
84 return LookupUnicodeString2 (
85 Language,
86 This->SupportedLanguages,
87 mUsbKeyboardDriverNameTable,
88 DriverName,
89 (BOOLEAN)(This == &gUsbKeyboardComponentName)
90 );
91 }
92
93 /**
94 Retrieves a Unicode string that is the user readable name of the controller
95 that is being managed by a driver.
96
97 This function retrieves the user readable name of the controller specified by
98 ControllerHandle and ChildHandle in the form of a Unicode string. If the
99 driver specified by This has a user readable name in the language specified by
100 Language, then a pointer to the controller name is returned in ControllerName,
101 and EFI_SUCCESS is returned. If the driver specified by This is not currently
102 managing the controller specified by ControllerHandle and ChildHandle,
103 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
104 support the language specified by Language, then EFI_UNSUPPORTED is returned.
105
106 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
107 EFI_COMPONENT_NAME_PROTOCOL instance.
108 @param ControllerHandle The handle of a controller that the driver
109 specified by This is managing. This handle
110 specifies the controller whose name is to be
111 returned.
112 @param ChildHandle The handle of the child controller to retrieve
113 the name of. This is an optional parameter that
114 may be NULL. It will be NULL for device
115 drivers. It will also be NULL for a bus drivers
116 that wish to retrieve the name of the bus
117 controller. It will not be NULL for a bus
118 driver that wishes to retrieve the name of a
119 child controller.
120 @param Language A pointer to a Null-terminated ASCII string
121 array indicating the language. This is the
122 language of the driver name that the caller is
123 requesting, and it must match one of the
124 languages specified in SupportedLanguages. The
125 number of languages supported by a driver is up
126 to the driver writer. Language is specified in
127 RFC 4646 or ISO 639-2 language code format.
128 @param ControllerName A pointer to the Unicode string to return.
129 This Unicode string is the name of the
130 controller specified by ControllerHandle and
131 ChildHandle in the language specified by
132 Language from the point of view of the driver
133 specified by This.
134
135 @retval EFI_SUCCESS The Unicode string for the user readable name in
136 the language specified by Language for the
137 driver specified by This was returned in
138 DriverName.
139 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
140 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
141 EFI_HANDLE.
142 @retval EFI_INVALID_PARAMETER Language is NULL.
143 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
144 @retval EFI_UNSUPPORTED The driver specified by This is not currently
145 managing the controller specified by
146 ControllerHandle and ChildHandle.
147 @retval EFI_UNSUPPORTED The driver specified by This does not support
148 the language specified by Language.
149
150 **/
151 EFI_STATUS
152 EFIAPI
UsbKeyboardComponentNameGetControllerName(IN EFI_COMPONENT_NAME_PROTOCOL * This,IN EFI_HANDLE ControllerHandle,IN EFI_HANDLE ChildHandle OPTIONAL,IN CHAR8 * Language,OUT CHAR16 ** ControllerName)153 UsbKeyboardComponentNameGetControllerName (
154 IN EFI_COMPONENT_NAME_PROTOCOL *This,
155 IN EFI_HANDLE ControllerHandle,
156 IN EFI_HANDLE ChildHandle OPTIONAL,
157 IN CHAR8 *Language,
158 OUT CHAR16 **ControllerName
159 )
160 {
161 EFI_STATUS Status;
162 USB_KB_DEV *UsbKbDev;
163 EFI_SIMPLE_TEXT_INPUT_PROTOCOL *SimpleTxtIn;
164 EFI_USB_IO_PROTOCOL *UsbIoProtocol;
165 //
166 // This is a device driver, so ChildHandle must be NULL.
167 //
168 if (ChildHandle != NULL) {
169 return EFI_UNSUPPORTED;
170 }
171
172 //
173 // Check Controller's handle
174 //
175 Status = gBS->OpenProtocol (
176 ControllerHandle,
177 &gEfiUsbIoProtocolGuid,
178 (VOID **) &UsbIoProtocol,
179 gUsbKeyboardDriverBinding.DriverBindingHandle,
180 ControllerHandle,
181 EFI_OPEN_PROTOCOL_BY_DRIVER
182 );
183 if (!EFI_ERROR (Status)) {
184 gBS->CloseProtocol (
185 ControllerHandle,
186 &gEfiUsbIoProtocolGuid,
187 gUsbKeyboardDriverBinding.DriverBindingHandle,
188 ControllerHandle
189 );
190
191 return EFI_UNSUPPORTED;
192 }
193
194 if (Status != EFI_ALREADY_STARTED) {
195 return EFI_UNSUPPORTED;
196 }
197 //
198 // Get the device context
199 //
200 Status = gBS->OpenProtocol (
201 ControllerHandle,
202 &gEfiSimpleTextInProtocolGuid,
203 (VOID **) &SimpleTxtIn,
204 gUsbKeyboardDriverBinding.DriverBindingHandle,
205 ControllerHandle,
206 EFI_OPEN_PROTOCOL_GET_PROTOCOL
207 );
208
209 if (EFI_ERROR (Status)) {
210 return Status;
211 }
212
213 UsbKbDev = USB_KB_DEV_FROM_THIS (SimpleTxtIn);
214
215 return LookupUnicodeString2 (
216 Language,
217 This->SupportedLanguages,
218 UsbKbDev->ControllerNameTable,
219 ControllerName,
220 (BOOLEAN)(This == &gUsbKeyboardComponentName)
221 );
222
223 }
224