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