]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Usb/UsbMouseDxe/ComponentName.c
1. Import UsbKbDxe and UsbMouseDxe into MdeModulePkg
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbMouseDxe / ComponentName.c
1 /** @file
2
3 Copyright (c) 2004 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 ComponentName.c
15
16 Abstract:
17
18
19 **/
20
21 #include "usbmouse.h"
22 #include <Library/DebugLib.h>
23
24 //
25 // EFI Component Name Functions
26 //
27 EFI_STATUS
28 EFIAPI
29 UsbMouseComponentNameGetDriverName (
30 IN EFI_COMPONENT_NAME_PROTOCOL *This,
31 IN CHAR8 *Language,
32 OUT CHAR16 **DriverName
33 );
34
35 EFI_STATUS
36 EFIAPI
37 UsbMouseComponentNameGetControllerName (
38 IN EFI_COMPONENT_NAME_PROTOCOL *This,
39 IN EFI_HANDLE ControllerHandle,
40 IN EFI_HANDLE ChildHandle OPTIONAL,
41 IN CHAR8 *Language,
42 OUT CHAR16 **ControllerName
43 );
44
45 //
46 // EFI Component Name Protocol
47 //
48 EFI_COMPONENT_NAME_PROTOCOL gUsbMouseComponentName = {
49 UsbMouseComponentNameGetDriverName,
50 UsbMouseComponentNameGetControllerName,
51 "eng"
52 };
53
54
55 STATIC EFI_UNICODE_STRING_TABLE mUsbMouseDriverNameTable[] = {
56 { "eng", L"Usb Mouse Driver" },
57 { NULL , NULL }
58 };
59
60
61 EFI_STATUS
62 EFIAPI
63 UsbMouseComponentNameGetDriverName (
64 IN EFI_COMPONENT_NAME_PROTOCOL *This,
65 IN CHAR8 *Language,
66 OUT CHAR16 **DriverName
67 )
68 /*++
69
70 Routine Description:
71 Retrieves a Unicode string that is the user readable name of the EFI Driver.
72
73 Arguments:
74 This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
75 Language - A pointer to a three character ISO 639-2 language identifier.
76 This is the language of the driver name that that the caller
77 is requesting, and it must match one of the languages specified
78 in SupportedLanguages. The number of languages supported by a
79 driver is up to the driver writer.
80 DriverName - A pointer to the Unicode string to return. This Unicode string
81 is the name of the driver specified by This in the language
82 specified by Language.
83
84 Returns:
85 EFI_SUCCESS - The Unicode string for the Driver specified by This
86 and the language specified by Language was returned
87 in DriverName.
88 EFI_INVALID_PARAMETER - Language is NULL.
89 EFI_INVALID_PARAMETER - DriverName is NULL.
90 EFI_UNSUPPORTED - The driver specified by This does not support the
91 language specified by Language.
92
93 --*/
94 {
95 return LookupUnicodeString (
96 Language,
97 gUsbMouseComponentName.SupportedLanguages,
98 mUsbMouseDriverNameTable,
99 DriverName
100 );
101 }
102
103 EFI_STATUS
104 EFIAPI
105 UsbMouseComponentNameGetControllerName (
106 IN EFI_COMPONENT_NAME_PROTOCOL *This,
107 IN EFI_HANDLE ControllerHandle,
108 IN EFI_HANDLE ChildHandle OPTIONAL,
109 IN CHAR8 *Language,
110 OUT CHAR16 **ControllerName
111 )
112 /*++
113
114 Routine Description:
115 Retrieves a Unicode string that is the user readable name of the controller
116 that is being managed by an EFI Driver.
117
118 Arguments:
119 This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
120 ControllerHandle - The handle of a controller that the driver specified by
121 This is managing. This handle specifies the controller
122 whose name is to be returned.
123 ChildHandle - The handle of the child controller to retrieve the name
124 of. This is an optional parameter that may be NULL. It
125 will be NULL for device drivers. It will also be NULL
126 for a bus drivers that wish to retrieve the name of the
127 bus controller. It will not be NULL for a bus driver
128 that wishes to retrieve the name of a child controller.
129 Language - A pointer to a three character ISO 639-2 language
130 identifier. This is the language of the controller name
131 that that the caller is requesting, and it must match one
132 of the languages specified in SupportedLanguages. The
133 number of languages supported by a driver is up to the
134 driver writer.
135 ControllerName - A pointer to the Unicode string to return. This Unicode
136 string is the name of the controller specified by
137 ControllerHandle and ChildHandle in the language specified
138 by Language from the point of view of the driver specified
139 by This.
140
141 Returns:
142 EFI_SUCCESS - The Unicode string for the user readable name in the
143 language specified by Language for the driver
144 specified by This was returned in DriverName.
145 EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
146 EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
147 EFI_INVALID_PARAMETER - Language is NULL.
148 EFI_INVALID_PARAMETER - ControllerName is NULL.
149 EFI_UNSUPPORTED - The driver specified by This is not currently managing
150 the controller specified by ControllerHandle and
151 ChildHandle.
152 EFI_UNSUPPORTED - The driver specified by This does not support the
153 language specified by Language.
154
155 --*/
156 {
157 EFI_STATUS Status;
158 USB_MOUSE_DEV *UsbMouseDev;
159 EFI_SIMPLE_POINTER_PROTOCOL *SimplePointerProtocol;
160 EFI_USB_IO_PROTOCOL *UsbIoProtocol;
161
162 //
163 // This is a device driver, so ChildHandle must be NULL.
164 //
165 if (ChildHandle != NULL) {
166 return EFI_UNSUPPORTED;
167 }
168
169 //
170 // Check Controller's handle
171 //
172 Status = gBS->OpenProtocol (
173 ControllerHandle,
174 &gEfiUsbIoProtocolGuid,
175 (VOID **) &UsbIoProtocol,
176 gUsbMouseDriverBinding.DriverBindingHandle,
177 ControllerHandle,
178 EFI_OPEN_PROTOCOL_BY_DRIVER
179 );
180 if (!EFI_ERROR (Status)) {
181 gBS->CloseProtocol (
182 ControllerHandle,
183 &gEfiUsbIoProtocolGuid,
184 gUsbMouseDriverBinding.DriverBindingHandle,
185 ControllerHandle
186 );
187
188 return EFI_UNSUPPORTED;
189 }
190
191 if (Status != EFI_ALREADY_STARTED) {
192 return EFI_UNSUPPORTED;
193 }
194 //
195 // Get the device context
196 //
197 Status = gBS->OpenProtocol (
198 ControllerHandle,
199 &gEfiSimplePointerProtocolGuid,
200 (VOID **) &SimplePointerProtocol,
201 gUsbMouseDriverBinding.DriverBindingHandle,
202 ControllerHandle,
203 EFI_OPEN_PROTOCOL_GET_PROTOCOL
204 );
205
206 if (EFI_ERROR (Status)) {
207 return Status;
208 }
209
210 UsbMouseDev = USB_MOUSE_DEV_FROM_MOUSE_PROTOCOL (SimplePointerProtocol);
211
212 return LookupUnicodeString (
213 Language,
214 gUsbMouseComponentName.SupportedLanguages,
215 UsbMouseDev->ControllerNameTable,
216 ControllerName
217 );
218
219 }