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