• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2   UEFI Component Name(2) protocol implementation for USB Mouse 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 "UsbMouse.h"
17 
18 //
19 // EFI Component Name Protocol
20 //
21 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL  gUsbMouseComponentName = {
22   UsbMouseComponentNameGetDriverName,
23   UsbMouseComponentNameGetControllerName,
24   "eng"
25 };
26 
27 //
28 // EFI Component Name 2 Protocol
29 //
30 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gUsbMouseComponentName2 = {
31   (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) UsbMouseComponentNameGetDriverName,
32   (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) UsbMouseComponentNameGetControllerName,
33   "en"
34 };
35 
36 
37 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mUsbMouseDriverNameTable[] = {
38   { "eng;en", L"Usb Mouse 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
UsbMouseComponentNameGetDriverName(IN EFI_COMPONENT_NAME_PROTOCOL * This,IN CHAR8 * Language,OUT CHAR16 ** DriverName)78 UsbMouseComponentNameGetDriverName (
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            mUsbMouseDriverNameTable,
88            DriverName,
89            (BOOLEAN)(This == &gUsbMouseComponentName)
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
UsbMouseComponentNameGetControllerName(IN EFI_COMPONENT_NAME_PROTOCOL * This,IN EFI_HANDLE ControllerHandle,IN EFI_HANDLE ChildHandle OPTIONAL,IN CHAR8 * Language,OUT CHAR16 ** ControllerName)153 UsbMouseComponentNameGetControllerName (
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_MOUSE_DEV               *UsbMouseDev;
163   EFI_SIMPLE_POINTER_PROTOCOL *SimplePointerProtocol;
164   EFI_USB_IO_PROTOCOL         *UsbIoProtocol;
165 
166   //
167   // This is a device driver, so ChildHandle must be NULL.
168   //
169   if (ChildHandle != NULL) {
170     return EFI_UNSUPPORTED;
171   }
172 
173   //
174   // Check Controller's handle
175   //
176   Status = gBS->OpenProtocol (
177                   ControllerHandle,
178                   &gEfiUsbIoProtocolGuid,
179                   (VOID **) &UsbIoProtocol,
180                   gUsbMouseDriverBinding.DriverBindingHandle,
181                   ControllerHandle,
182                   EFI_OPEN_PROTOCOL_BY_DRIVER
183                   );
184   if (!EFI_ERROR (Status)) {
185     gBS->CloseProtocol (
186            ControllerHandle,
187            &gEfiUsbIoProtocolGuid,
188            gUsbMouseDriverBinding.DriverBindingHandle,
189            ControllerHandle
190            );
191 
192     return EFI_UNSUPPORTED;
193   }
194 
195   if (Status != EFI_ALREADY_STARTED) {
196     return EFI_UNSUPPORTED;
197   }
198   //
199   // Get the device context
200   //
201   Status = gBS->OpenProtocol (
202                   ControllerHandle,
203                  &gEfiSimplePointerProtocolGuid,
204                   (VOID **) &SimplePointerProtocol,
205                   gUsbMouseDriverBinding.DriverBindingHandle,
206                   ControllerHandle,
207                   EFI_OPEN_PROTOCOL_GET_PROTOCOL
208                   );
209 
210   if (EFI_ERROR (Status)) {
211     return Status;
212   }
213 
214   UsbMouseDev = USB_MOUSE_DEV_FROM_MOUSE_PROTOCOL (SimplePointerProtocol);
215 
216   return LookupUnicodeString2 (
217            Language,
218            This->SupportedLanguages,
219            UsbMouseDev->ControllerNameTable,
220            ControllerName,
221            (BOOLEAN)(This == &gUsbMouseComponentName)
222            );
223 
224 }
225