]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.h
MdeModulePkg: Replace BSD License with BSD+Patent License
[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
d1102dba 4Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
9d510e61 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
ed838d0c 6\r
ed838d0c 7**/\r
8\r
bb80e3b2 9#ifndef _EFI_USB_MOUSE_H_\r
10#define _EFI_USB_MOUSE_H_\r
ed838d0c 11\r
ed7748fe 12\r
60c93673 13#include <Uefi.h>\r
ed7748fe 14\r
ed838d0c 15#include <Protocol/SimplePointer.h>\r
16#include <Protocol/UsbIo.h>\r
17#include <Protocol/DevicePath.h>\r
ed7748fe 18\r
ed838d0c 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
24#include <Library/MemoryAllocationLib.h>\r
dfb74df5 25#include <Library/UefiUsbLib.h>\r
29129ce4 26#include <Library/DebugLib.h>\r
ed838d0c 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_DEV_SIGNATURE SIGNATURE_32 ('u', 'm', 'o', 'u')\r
ed838d0c 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
29129ce4 50///\r
51/// Button range and status\r
52///\r
ed838d0c 53typedef struct {\r
54 BOOLEAN ButtonDetected;\r
55 UINT8 ButtonMinIndex;\r
56 UINT8 ButtonMaxIndex;\r
57 UINT8 Reserved;\r
29129ce4 58} USB_MOUSE_BUTTON_DATA;\r
ed838d0c 59\r
29129ce4 60///\r
61/// Device instance of USB mouse.\r
62///\r
ed838d0c 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
29129ce4 68 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;\r
69 EFI_USB_ENDPOINT_DESCRIPTOR IntEndpointDescriptor;\r
ed838d0c 70 UINT8 NumberOfButtons;\r
71 INT32 XLogicMax;\r
72 INT32 XLogicMin;\r
73 INT32 YLogicMax;\r
74 INT32 YLogicMin;\r
75 EFI_SIMPLE_POINTER_PROTOCOL SimplePointerProtocol;\r
76 EFI_SIMPLE_POINTER_STATE State;\r
77 EFI_SIMPLE_POINTER_MODE Mode;\r
78 BOOLEAN StateChanged;\r
29129ce4 79 USB_MOUSE_BUTTON_DATA PrivateData;\r
ed838d0c 80 EFI_UNICODE_STRING_TABLE *ControllerNameTable;\r
81} USB_MOUSE_DEV;\r
82\r
29129ce4 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
29129ce4 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
29129ce4 103} HID_ITEM;\r
104\r
ed838d0c 105#define USB_MOUSE_DEV_FROM_MOUSE_PROTOCOL(a) \\r
106 CR(a, USB_MOUSE_DEV, SimplePointerProtocol, USB_MOUSE_DEV_SIGNATURE)\r
107\r
29129ce4 108//\r
109// Global Variables\r
110//\r
111extern EFI_DRIVER_BINDING_PROTOCOL gUsbMouseDriverBinding;\r
112extern EFI_COMPONENT_NAME_PROTOCOL gUsbMouseComponentName;\r
113extern EFI_COMPONENT_NAME2_PROTOCOL gUsbMouseComponentName2;\r
114\r
115//\r
116// Functions of Driver Binding Protocol\r
117//\r
bb80e3b2 118\r
119/**\r
29129ce4 120 Check whether USB mouse driver supports this device.\r
bb80e3b2 121\r
29129ce4 122 @param This The USB mouse driver binding protocol.\r
123 @param Controller The controller handle to check.\r
124 @param RemainingDevicePath The remaining device path.\r
bb80e3b2 125\r
29129ce4 126 @retval EFI_SUCCESS The driver supports this controller.\r
127 @retval other This device isn't supported.\r
bb80e3b2 128\r
129**/\r
29129ce4 130EFI_STATUS\r
ed838d0c 131EFIAPI\r
29129ce4 132USBMouseDriverBindingSupported (\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
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 Simple Pointer Protocol, and submits Asynchronous Interrupt\r
143 Transfer to manage the USB mouse device.\r
144\r
145 @param This The USB mouse 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
157EFI_STATUS\r
158EFIAPI\r
159USBMouseDriverBindingStart (\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
165/**\r
166 Stop the USB mouse device handled by this driver.\r
167\r
168 @param This The USB mouse 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 Simple Pointer Protocol is not installed on Controller.\r
175 @retval Others Fail to uninstall protocols attached on the device.\r
176\r
177**/\r
178EFI_STATUS\r
179EFIAPI\r
180USBMouseDriverBindingStop (\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
ed838d0c 185 );\r
186\r
187//\r
29129ce4 188// EFI Component Name Functions\r
ed838d0c 189//\r
ed838d0c 190\r
29129ce4 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
29129ce4 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
227UsbMouseComponentNameGetDriverName (\r
228 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
229 IN CHAR8 *Language,\r
230 OUT CHAR16 **DriverName\r
231 );\r
bb80e3b2 232\r
233/**\r
29129ce4 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
29129ce4 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
29129ce4 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
bb80e3b2 289\r
29129ce4 290**/\r
291EFI_STATUS\r
292EFIAPI\r
293UsbMouseComponentNameGetControllerName (\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
bb80e3b2 300\r
c92e277d 301//\r
302// Functions of EFI_SIMPLE_POINTER_PROTOCOL\r
303//\r
304\r
305/**\r
306 Retrieves the current state of a pointer device.\r
d1102dba
LG
307\r
308 @param This A pointer to the EFI_SIMPLE_POINTER_PROTOCOL instance.\r
c92e277d 309 @param MouseState A pointer to the state information on the pointer device.\r
d1102dba 310\r
c92e277d 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
c92e277d 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 MouseState is NULL.\r
c92e277d 317\r
318**/\r
319EFI_STATUS\r
320EFIAPI\r
321GetMouseState (\r
322 IN EFI_SIMPLE_POINTER_PROTOCOL *This,\r
323 OUT EFI_SIMPLE_POINTER_STATE *MouseState\r
324 );\r
325\r
d1102dba 326/**\r
c92e277d 327 Resets the pointer device hardware.\r
d1102dba 328\r
c92e277d 329 @param This A pointer to the EFI_SIMPLE_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
d1102dba 332\r
c92e277d 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
339UsbMouseReset (\r
340 IN EFI_SIMPLE_POINTER_PROTOCOL *This,\r
341 IN BOOLEAN ExtendedVerification\r
342 );\r
343\r
344/**\r
345 Event notification function for SIMPLE_POINTER.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_DEV instance.\r
d1102dba 349\r
c92e277d 350**/\r
351VOID\r
352EFIAPI\r
353UsbMouseWaitForInput (\r
354 IN EFI_EVENT Event,\r
355 IN VOID *Context\r
356 );\r
357\r
29129ce4 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
bb80e3b2 369\r
370**/\r
29129ce4 371BOOLEAN\r
372IsUsbMouse (\r
373 IN EFI_USB_IO_PROTOCOL *UsbIo\r
ed838d0c 374 );\r
375\r
aa79b0b3 376/**\r
29129ce4 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_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
aa79b0b3 383\r
29129ce4 384 @param UsbMouseDev Device instance to be initialized.\r
aa79b0b3 385\r
29129ce4 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
aa79b0b3 389\r
390**/\r
391EFI_STATUS\r
29129ce4 392InitializeUsbMouseDevice (\r
393 IN OUT USB_MOUSE_DEV *UsbMouseDev\r
aa79b0b3 394 );\r
395\r
396/**\r
29129ce4 397 Handler function for USB mouse's asynchronous interrupt transfer.\r
aa79b0b3 398\r
29129ce4 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
aa79b0b3 402\r
29129ce4 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
aa79b0b3 411\r
412**/\r
413EFI_STATUS\r
414EFIAPI\r
29129ce4 415OnMouseInterruptComplete (\r
416 IN VOID *Data,\r
417 IN UINTN DataLength,\r
418 IN VOID *Context,\r
419 IN UINT32 Result\r
aa79b0b3 420 );\r
421\r
29129ce4 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_DEV instance.\r
aa79b0b3 433\r
434**/\r
29129ce4 435VOID\r
aa79b0b3 436EFIAPI\r
29129ce4 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_DEV.\r
449\r
450 @param UsbMouse The instance of USB_MOUSE_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_DEV *UsbMouse,\r
461 IN UINT8 *ReportDescriptor,\r
462 IN UINTN ReportSize\r
aa79b0b3 463 );\r
464\r
ed838d0c 465#endif\r