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