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