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