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