]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.h
Update the copyright notice format
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbMouseDxe / UsbMouse.h
CommitLineData
ed838d0c 1/** @file\r
d7db0902 2 Helper routine and corresponding data struct used by USB Mouse Driver.\r
bb80e3b2 3\r
cd5ebaa0
HT
4Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
ed838d0c 6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
ed838d0c 13**/\r
14\r
bb80e3b2 15#ifndef _EFI_USB_MOUSE_H_\r
16#define _EFI_USB_MOUSE_H_\r
ed838d0c 17\r
ed7748fe 18\r
60c93673 19#include <Uefi.h>\r
ed7748fe 20\r
ed838d0c 21#include <Protocol/SimplePointer.h>\r
22#include <Protocol/UsbIo.h>\r
23#include <Protocol/DevicePath.h>\r
ed7748fe 24\r
ed838d0c 25#include <Library/ReportStatusCodeLib.h>\r
26#include <Library/BaseMemoryLib.h>\r
27#include <Library/UefiDriverEntryPoint.h>\r
28#include <Library/UefiBootServicesTableLib.h>\r
29#include <Library/UefiLib.h>\r
30#include <Library/MemoryAllocationLib.h>\r
dfb74df5 31#include <Library/UefiUsbLib.h>\r
29129ce4 32#include <Library/DebugLib.h>\r
ed838d0c 33\r
34#include <IndustryStandard/Usb.h>\r
35\r
36#define CLASS_HID 3\r
37#define SUBCLASS_BOOT 1\r
38#define PROTOCOL_MOUSE 2\r
39\r
40#define BOOT_PROTOCOL 0\r
41#define REPORT_PROTOCOL 1\r
42\r
f3f2e05d 43#define USB_MOUSE_DEV_SIGNATURE SIGNATURE_32 ('u', 'm', 'o', 'u')\r
ed838d0c 44\r
29129ce4 45///\r
46/// Button range and status\r
47///\r
ed838d0c 48typedef struct {\r
49 BOOLEAN ButtonDetected;\r
50 UINT8 ButtonMinIndex;\r
51 UINT8 ButtonMaxIndex;\r
52 UINT8 Reserved;\r
29129ce4 53} USB_MOUSE_BUTTON_DATA;\r
ed838d0c 54\r
29129ce4 55///\r
56/// Device instance of USB mouse.\r
57///\r
ed838d0c 58typedef struct {\r
59 UINTN Signature;\r
60 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
61 EFI_EVENT DelayedRecoveryEvent;\r
62 EFI_USB_IO_PROTOCOL *UsbIo;\r
29129ce4 63 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;\r
64 EFI_USB_ENDPOINT_DESCRIPTOR IntEndpointDescriptor;\r
ed838d0c 65 UINT8 NumberOfButtons;\r
66 INT32 XLogicMax;\r
67 INT32 XLogicMin;\r
68 INT32 YLogicMax;\r
69 INT32 YLogicMin;\r
70 EFI_SIMPLE_POINTER_PROTOCOL SimplePointerProtocol;\r
71 EFI_SIMPLE_POINTER_STATE State;\r
72 EFI_SIMPLE_POINTER_MODE Mode;\r
73 BOOLEAN StateChanged;\r
29129ce4 74 USB_MOUSE_BUTTON_DATA PrivateData;\r
ed838d0c 75 EFI_UNICODE_STRING_TABLE *ControllerNameTable;\r
76} USB_MOUSE_DEV;\r
77\r
29129ce4 78///\r
79/// General HID Item structure\r
80///\r
1ccdbf2a 81\r
82typedef union {\r
4140a663 83 UINT8 Uint8;\r
84 UINT16 Uint16;\r
85 UINT32 Uint32;\r
86 INT8 Int8;\r
87 INT16 Int16;\r
88 INT32 Int32;\r
1ccdbf2a 89 UINT8 *LongData;\r
90} HID_DATA;\r
91\r
29129ce4 92typedef struct {\r
1ccdbf2a 93 UINT16 Format;\r
94 UINT8 Size;\r
95 UINT8 Type;\r
96 UINT8 Tag;\r
97 HID_DATA Data;\r
29129ce4 98} HID_ITEM;\r
99\r
ed838d0c 100#define USB_MOUSE_DEV_FROM_MOUSE_PROTOCOL(a) \\r
101 CR(a, USB_MOUSE_DEV, SimplePointerProtocol, USB_MOUSE_DEV_SIGNATURE)\r
102\r
29129ce4 103//\r
104// Global Variables\r
105//\r
106extern EFI_DRIVER_BINDING_PROTOCOL gUsbMouseDriverBinding;\r
107extern EFI_COMPONENT_NAME_PROTOCOL gUsbMouseComponentName;\r
108extern EFI_COMPONENT_NAME2_PROTOCOL gUsbMouseComponentName2;\r
109\r
110//\r
111// Functions of Driver Binding Protocol\r
112//\r
bb80e3b2 113\r
114/**\r
29129ce4 115 Check whether USB mouse driver supports this device.\r
bb80e3b2 116\r
29129ce4 117 @param This The USB mouse driver binding protocol.\r
118 @param Controller The controller handle to check.\r
119 @param RemainingDevicePath The remaining device path.\r
bb80e3b2 120\r
29129ce4 121 @retval EFI_SUCCESS The driver supports this controller.\r
122 @retval other This device isn't supported.\r
bb80e3b2 123\r
124**/\r
29129ce4 125EFI_STATUS\r
ed838d0c 126EFIAPI\r
29129ce4 127USBMouseDriverBindingSupported (\r
128 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
129 IN EFI_HANDLE Controller,\r
130 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
131 );\r
132\r
133/**\r
134 Starts the mouse device with this driver.\r
135\r
136 This function consumes USB I/O Portocol, intializes USB mouse device,\r
137 installs Simple Pointer Protocol, and submits Asynchronous Interrupt\r
138 Transfer to manage the USB mouse device.\r
139\r
140 @param This The USB mouse driver binding instance.\r
141 @param Controller Handle of device to bind driver to.\r
142 @param RemainingDevicePath Optional parameter use to pick a specific child\r
143 device to start.\r
144\r
145 @retval EFI_SUCCESS This driver supports this device.\r
146 @retval EFI_UNSUPPORTED This driver does not support this device.\r
147 @retval EFI_DEVICE_ERROR This driver cannot be started due to device Error.\r
148 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.\r
149 @retval EFI_ALREADY_STARTED This driver has been started.\r
150\r
151**/\r
152EFI_STATUS\r
153EFIAPI\r
154USBMouseDriverBindingStart (\r
155 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
156 IN EFI_HANDLE Controller,\r
157 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
158 );\r
159\r
160/**\r
161 Stop the USB mouse device handled by this driver.\r
162\r
163 @param This The USB mouse driver binding protocol.\r
164 @param Controller The controller to release.\r
165 @param NumberOfChildren The number of handles in ChildHandleBuffer.\r
166 @param ChildHandleBuffer The array of child handle.\r
167\r
168 @retval EFI_SUCCESS The device was stopped.\r
169 @retval EFI_UNSUPPORTED Simple Pointer Protocol is not installed on Controller.\r
170 @retval Others Fail to uninstall protocols attached on the device.\r
171\r
172**/\r
173EFI_STATUS\r
174EFIAPI\r
175USBMouseDriverBindingStop (\r
176 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
177 IN EFI_HANDLE Controller,\r
178 IN UINTN NumberOfChildren,\r
179 IN EFI_HANDLE *ChildHandleBuffer\r
ed838d0c 180 );\r
181\r
182//\r
29129ce4 183// EFI Component Name Functions\r
ed838d0c 184//\r
ed838d0c 185\r
29129ce4 186/**\r
187 Retrieves a Unicode string that is the user readable name of the driver.\r
188\r
189 This function retrieves the user readable name of a driver in the form of a\r
190 Unicode string. If the driver specified by This has a user readable name in\r
191 the language specified by Language, then a pointer to the driver name is\r
192 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
193 by This does not support the language specified by Language,\r
194 then EFI_UNSUPPORTED is returned.\r
195\r
196 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
197 EFI_COMPONENT_NAME_PROTOCOL instance.\r
198 @param Language A pointer to a Null-terminated ASCII string\r
199 array indicating the language. This is the\r
200 language of the driver name that the caller is\r
201 requesting, and it must match one of the\r
202 languages specified in SupportedLanguages. The\r
203 number of languages supported by a driver is up\r
204 to the driver writer. Language is specified\r
0254efc0 205 in RFC 4646 or ISO 639-2 language code format.\r
29129ce4 206 @param DriverName A pointer to the Unicode string to return.\r
207 This Unicode string is the name of the\r
208 driver specified by This in the language\r
209 specified by Language.\r
210\r
211 @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
212 This and the language specified by Language was\r
213 returned in DriverName.\r
214 @retval EFI_INVALID_PARAMETER Language is NULL.\r
215 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
216 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
217 the language specified by Language.\r
218\r
219**/\r
220EFI_STATUS\r
221EFIAPI\r
222UsbMouseComponentNameGetDriverName (\r
223 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
224 IN CHAR8 *Language,\r
225 OUT CHAR16 **DriverName\r
226 );\r
bb80e3b2 227\r
228/**\r
29129ce4 229 Retrieves a Unicode string that is the user readable name of the controller\r
230 that is being managed by a driver.\r
231\r
232 This function retrieves the user readable name of the controller specified by\r
233 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
234 driver specified by This has a user readable name in the language specified by\r
235 Language, then a pointer to the controller name is returned in ControllerName,\r
236 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
237 managing the controller specified by ControllerHandle and ChildHandle,\r
238 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
239 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
240\r
241 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
242 EFI_COMPONENT_NAME_PROTOCOL instance.\r
243 @param ControllerHandle The handle of a controller that the driver\r
244 specified by This is managing. This handle\r
245 specifies the controller whose name is to be\r
246 returned.\r
247 @param ChildHandle The handle of the child controller to retrieve\r
248 the name of. This is an optional parameter that\r
249 may be NULL. It will be NULL for device\r
250 drivers. It will also be NULL for a bus drivers\r
251 that wish to retrieve the name of the bus\r
252 controller. It will not be NULL for a bus\r
253 driver that wishes to retrieve the name of a\r
254 child controller.\r
255 @param Language A pointer to a Null-terminated ASCII string\r
256 array indicating the language. This is the\r
257 language of the driver name that the caller is\r
258 requesting, and it must match one of the\r
259 languages specified in SupportedLanguages. The\r
260 number of languages supported by a driver is up\r
261 to the driver writer. Language is specified in\r
0254efc0 262 RFC 4646 or ISO 639-2 language code format.\r
29129ce4 263 @param ControllerName A pointer to the Unicode string to return.\r
264 This Unicode string is the name of the\r
265 controller specified by ControllerHandle and\r
266 ChildHandle in the language specified by\r
267 Language from the point of view of the driver\r
268 specified by This.\r
269\r
270 @retval EFI_SUCCESS The Unicode string for the user readable name in\r
271 the language specified by Language for the\r
272 driver specified by This was returned in\r
273 DriverName.\r
274 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.\r
275 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
276 EFI_HANDLE.\r
277 @retval EFI_INVALID_PARAMETER Language is NULL.\r
278 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
279 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
280 managing the controller specified by\r
281 ControllerHandle and ChildHandle.\r
282 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
283 the language specified by Language.\r
bb80e3b2 284\r
29129ce4 285**/\r
286EFI_STATUS\r
287EFIAPI\r
288UsbMouseComponentNameGetControllerName (\r
289 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
290 IN EFI_HANDLE ControllerHandle,\r
291 IN EFI_HANDLE ChildHandle OPTIONAL,\r
292 IN CHAR8 *Language,\r
293 OUT CHAR16 **ControllerName\r
294 );\r
bb80e3b2 295\r
c92e277d 296//\r
297// Functions of EFI_SIMPLE_POINTER_PROTOCOL\r
298//\r
299\r
300/**\r
301 Retrieves the current state of a pointer device.\r
302 \r
303 @param This A pointer to the EFI_SIMPLE_POINTER_PROTOCOL instance. \r
304 @param MouseState A pointer to the state information on the pointer device.\r
305 \r
306 @retval EFI_SUCCESS The state of the pointer device was returned in State.\r
307 @retval EFI_NOT_READY The state of the pointer device has not changed since the last call to\r
308 GetState(). \r
309 @retval EFI_DEVICE_ERROR A device error occurred while attempting to retrieve the pointer device's\r
310 current state. \r
311 @retval EFI_INVALID_PARAMETER MouseState is NULL. \r
312\r
313**/\r
314EFI_STATUS\r
315EFIAPI\r
316GetMouseState (\r
317 IN EFI_SIMPLE_POINTER_PROTOCOL *This,\r
318 OUT EFI_SIMPLE_POINTER_STATE *MouseState\r
319 );\r
320\r
321/** \r
322 Resets the pointer device hardware.\r
323 \r
324 @param This A pointer to the EFI_SIMPLE_POINTER_PROTOCOL instance.\r
325 @param ExtendedVerification Indicates that the driver may perform a more exhaustive\r
326 verification operation of the device during reset.\r
327 \r
328 @retval EFI_SUCCESS The device was reset.\r
329 @retval EFI_DEVICE_ERROR The device is not functioning correctly and could not be reset.\r
330\r
331**/\r
332EFI_STATUS\r
333EFIAPI\r
334UsbMouseReset (\r
335 IN EFI_SIMPLE_POINTER_PROTOCOL *This,\r
336 IN BOOLEAN ExtendedVerification\r
337 );\r
338\r
339/**\r
340 Event notification function for SIMPLE_POINTER.WaitForInput event.\r
341\r
342 @param Event Event to be signaled when there's input from mouse.\r
343 @param Context Points to USB_MOUSE_DEV instance.\r
344 \r
345**/\r
346VOID\r
347EFIAPI\r
348UsbMouseWaitForInput (\r
349 IN EFI_EVENT Event,\r
350 IN VOID *Context\r
351 );\r
352\r
29129ce4 353//\r
354// Internal worker functions\r
355//\r
356\r
357/**\r
358 Uses USB I/O to check whether the device is a USB mouse device.\r
359\r
360 @param UsbIo Pointer to a USB I/O protocol instance.\r
361\r
362 @retval TRUE Device is a USB mouse device.\r
363 @retval FALSE Device is a not USB mouse device.\r
bb80e3b2 364\r
365**/\r
29129ce4 366BOOLEAN\r
367IsUsbMouse (\r
368 IN EFI_USB_IO_PROTOCOL *UsbIo\r
ed838d0c 369 );\r
370\r
aa79b0b3 371/**\r
29129ce4 372 Initialize the USB mouse device.\r
373\r
374 This function retrieves and parses HID report descriptor, and\r
375 initializes state of USB_MOUSE_DEV. Then it sets indefinite idle\r
376 rate for the device. Finally it creates event for delayed recovery,\r
377 which deals with device error.\r
aa79b0b3 378\r
29129ce4 379 @param UsbMouseDev Device instance to be initialized.\r
aa79b0b3 380\r
29129ce4 381 @retval EFI_SUCCESS USB mouse device successfully initialized..\r
382 @retval EFI_UNSUPPORTED HID descriptor type is not report descriptor.\r
383 @retval Other USB mouse device was not initialized successfully.\r
aa79b0b3 384\r
385**/\r
386EFI_STATUS\r
29129ce4 387InitializeUsbMouseDevice (\r
388 IN OUT USB_MOUSE_DEV *UsbMouseDev\r
aa79b0b3 389 );\r
390\r
391/**\r
29129ce4 392 Handler function for USB mouse's asynchronous interrupt transfer.\r
aa79b0b3 393\r
29129ce4 394 This function is the handler function for USB mouse's asynchronous interrupt transfer\r
395 to manage the mouse. It parses data returned from asynchronous interrupt transfer, and\r
396 get button and movement state.\r
aa79b0b3 397\r
29129ce4 398 @param Data A pointer to a buffer that is filled with key data which is\r
399 retrieved via asynchronous interrupt transfer.\r
400 @param DataLength Indicates the size of the data buffer.\r
401 @param Context Pointing to USB_KB_DEV instance.\r
402 @param Result Indicates the result of the asynchronous interrupt transfer.\r
403\r
404 @retval EFI_SUCCESS Asynchronous interrupt transfer is handled successfully.\r
405 @retval EFI_DEVICE_ERROR Hardware error occurs.\r
aa79b0b3 406\r
407**/\r
408EFI_STATUS\r
409EFIAPI\r
29129ce4 410OnMouseInterruptComplete (\r
411 IN VOID *Data,\r
412 IN UINTN DataLength,\r
413 IN VOID *Context,\r
414 IN UINT32 Result\r
aa79b0b3 415 );\r
416\r
29129ce4 417/**\r
418 Handler for Delayed Recovery event.\r
419\r
420 This function is the handler for Delayed Recovery event triggered\r
421 by timer.\r
422 After a device error occurs, the event would be triggered\r
423 with interval of EFI_USB_INTERRUPT_DELAY. EFI_USB_INTERRUPT_DELAY\r
424 is defined in USB standard for error handling.\r
425\r
426 @param Event The Delayed Recovery event.\r
427 @param Context Points to the USB_MOUSE_DEV instance.\r
aa79b0b3 428\r
429**/\r
29129ce4 430VOID\r
aa79b0b3 431EFIAPI\r
29129ce4 432USBMouseRecoveryHandler (\r
433 IN EFI_EVENT Event,\r
434 IN VOID *Context\r
435 );\r
436\r
437/**\r
438 Parse Mouse Report Descriptor.\r
439\r
440 According to USB HID Specification, report descriptors are\r
441 composed of pieces of information. Each piece of information\r
442 is called an Item. This function retrieves each item from\r
443 the report descriptor and updates USB_MOUSE_DEV.\r
444\r
445 @param UsbMouse The instance of USB_MOUSE_DEV\r
446 @param ReportDescriptor Report descriptor to parse\r
447 @param ReportSize Report descriptor size\r
448\r
449 @retval EFI_SUCCESS Report descriptor successfully parsed.\r
450 @retval EFI_UNSUPPORTED Report descriptor contains long item.\r
451\r
452**/\r
453EFI_STATUS\r
454ParseMouseReportDescriptor (\r
455 OUT USB_MOUSE_DEV *UsbMouse,\r
456 IN UINT8 *ReportDescriptor,\r
457 IN UINTN ReportSize\r
aa79b0b3 458 );\r
459\r
ed838d0c 460#endif\r