]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[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
60c93673 12#include <Uefi.h>\r
ed7748fe 13\r
ed838d0c 14#include <Protocol/SimplePointer.h>\r
15#include <Protocol/UsbIo.h>\r
16#include <Protocol/DevicePath.h>\r
ed7748fe 17\r
ed838d0c 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
23#include <Library/MemoryAllocationLib.h>\r
dfb74df5 24#include <Library/UefiUsbLib.h>\r
29129ce4 25#include <Library/DebugLib.h>\r
ed838d0c 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
ed838d0c 32\r
1436aea4
MK
33#define BOOT_PROTOCOL 0\r
34#define REPORT_PROTOCOL 1\r
ed838d0c 35\r
1436aea4 36#define USB_MOUSE_DEV_SIGNATURE SIGNATURE_32 ('u', 'm', 'o', 'u')\r
ed838d0c 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
29129ce4 49///\r
50/// Button range and status\r
51///\r
ed838d0c 52typedef struct {\r
1436aea4
MK
53 BOOLEAN ButtonDetected;\r
54 UINT8 ButtonMinIndex;\r
55 UINT8 ButtonMaxIndex;\r
56 UINT8 Reserved;\r
29129ce4 57} USB_MOUSE_BUTTON_DATA;\r
ed838d0c 58\r
29129ce4 59///\r
60/// Device instance of USB mouse.\r
61///\r
ed838d0c 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_SIMPLE_POINTER_PROTOCOL SimplePointerProtocol;\r
75 EFI_SIMPLE_POINTER_STATE State;\r
76 EFI_SIMPLE_POINTER_MODE Mode;\r
77 BOOLEAN StateChanged;\r
78 USB_MOUSE_BUTTON_DATA PrivateData;\r
79 EFI_UNICODE_STRING_TABLE *ControllerNameTable;\r
ed838d0c 80} USB_MOUSE_DEV;\r
81\r
29129ce4 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
29129ce4 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
29129ce4 102} HID_ITEM;\r
103\r
ed838d0c 104#define USB_MOUSE_DEV_FROM_MOUSE_PROTOCOL(a) \\r
105 CR(a, USB_MOUSE_DEV, SimplePointerProtocol, USB_MOUSE_DEV_SIGNATURE)\r
106\r
29129ce4 107//\r
108// Global Variables\r
109//\r
110extern EFI_DRIVER_BINDING_PROTOCOL gUsbMouseDriverBinding;\r
111extern EFI_COMPONENT_NAME_PROTOCOL gUsbMouseComponentName;\r
112extern EFI_COMPONENT_NAME2_PROTOCOL gUsbMouseComponentName2;\r
113\r
114//\r
115// Functions of Driver Binding Protocol\r
116//\r
bb80e3b2 117\r
118/**\r
29129ce4 119 Check whether USB mouse driver supports this device.\r
bb80e3b2 120\r
29129ce4 121 @param This The USB mouse driver binding protocol.\r
122 @param Controller The controller handle to check.\r
123 @param RemainingDevicePath The remaining device path.\r
bb80e3b2 124\r
29129ce4 125 @retval EFI_SUCCESS The driver supports this controller.\r
126 @retval other This device isn't supported.\r
bb80e3b2 127\r
128**/\r
29129ce4 129EFI_STATUS\r
ed838d0c 130EFIAPI\r
29129ce4 131USBMouseDriverBindingSupported (\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
29129ce4 135 );\r
136\r
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
29129ce4 141 installs Simple Pointer Protocol, and submits Asynchronous Interrupt\r
142 Transfer to manage the USB mouse device.\r
143\r
144 @param This The USB mouse 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
156EFI_STATUS\r
157EFIAPI\r
158USBMouseDriverBindingStart (\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
29129ce4 162 );\r
163\r
164/**\r
165 Stop the USB mouse device handled by this driver.\r
166\r
167 @param This The USB mouse 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 Simple Pointer Protocol is not installed on Controller.\r
174 @retval Others Fail to uninstall protocols attached on the device.\r
175\r
176**/\r
177EFI_STATUS\r
178EFIAPI\r
179USBMouseDriverBindingStop (\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
ed838d0c 184 );\r
185\r
186//\r
29129ce4 187// EFI Component Name Functions\r
ed838d0c 188//\r
ed838d0c 189\r
29129ce4 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
29129ce4 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
226UsbMouseComponentNameGetDriverName (\r
227 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
228 IN CHAR8 *Language,\r
229 OUT CHAR16 **DriverName\r
230 );\r
bb80e3b2 231\r
232/**\r
29129ce4 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
29129ce4 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
29129ce4 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
bb80e3b2 288\r
29129ce4 289**/\r
290EFI_STATUS\r
291EFIAPI\r
292UsbMouseComponentNameGetControllerName (\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
29129ce4 298 );\r
bb80e3b2 299\r
c92e277d 300//\r
301// Functions of EFI_SIMPLE_POINTER_PROTOCOL\r
302//\r
303\r
304/**\r
305 Retrieves the current state of a pointer device.\r
d1102dba
LG
306\r
307 @param This A pointer to the EFI_SIMPLE_POINTER_PROTOCOL instance.\r
c92e277d 308 @param MouseState A pointer to the state information on the pointer device.\r
d1102dba 309\r
c92e277d 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
c92e277d 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 MouseState is NULL.\r
c92e277d 316\r
317**/\r
318EFI_STATUS\r
319EFIAPI\r
320GetMouseState (\r
321 IN EFI_SIMPLE_POINTER_PROTOCOL *This,\r
322 OUT EFI_SIMPLE_POINTER_STATE *MouseState\r
323 );\r
324\r
d1102dba 325/**\r
c92e277d 326 Resets the pointer device hardware.\r
d1102dba 327\r
c92e277d 328 @param This A pointer to the EFI_SIMPLE_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
d1102dba 331\r
c92e277d 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
338UsbMouseReset (\r
1436aea4
MK
339 IN EFI_SIMPLE_POINTER_PROTOCOL *This,\r
340 IN BOOLEAN ExtendedVerification\r
c92e277d 341 );\r
342\r
343/**\r
344 Event notification function for SIMPLE_POINTER.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_DEV instance.\r
d1102dba 348\r
c92e277d 349**/\r
350VOID\r
351EFIAPI\r
352UsbMouseWaitForInput (\r
1436aea4
MK
353 IN EFI_EVENT Event,\r
354 IN VOID *Context\r
c92e277d 355 );\r
356\r
29129ce4 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
bb80e3b2 368\r
369**/\r
29129ce4 370BOOLEAN\r
371IsUsbMouse (\r
1436aea4 372 IN EFI_USB_IO_PROTOCOL *UsbIo\r
ed838d0c 373 );\r
374\r
aa79b0b3 375/**\r
29129ce4 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_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
aa79b0b3 382\r
29129ce4 383 @param UsbMouseDev Device instance to be initialized.\r
aa79b0b3 384\r
29129ce4 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
aa79b0b3 388\r
389**/\r
390EFI_STATUS\r
29129ce4 391InitializeUsbMouseDevice (\r
1436aea4 392 IN OUT USB_MOUSE_DEV *UsbMouseDev\r
aa79b0b3 393 );\r
394\r
395/**\r
29129ce4 396 Handler function for USB mouse's asynchronous interrupt transfer.\r
aa79b0b3 397\r
29129ce4 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
aa79b0b3 401\r
29129ce4 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
aa79b0b3 410\r
411**/\r
412EFI_STATUS\r
413EFIAPI\r
29129ce4 414OnMouseInterruptComplete (\r
1436aea4
MK
415 IN VOID *Data,\r
416 IN UINTN DataLength,\r
417 IN VOID *Context,\r
418 IN UINT32 Result\r
aa79b0b3 419 );\r
420\r
29129ce4 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_DEV instance.\r
aa79b0b3 432\r
433**/\r
29129ce4 434VOID\r
aa79b0b3 435EFIAPI\r
29129ce4 436USBMouseRecoveryHandler (\r
1436aea4
MK
437 IN EFI_EVENT Event,\r
438 IN VOID *Context\r
29129ce4 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_DEV.\r
448\r
449 @param UsbMouse The instance of USB_MOUSE_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_DEV *UsbMouse,\r
460 IN UINT8 *ReportDescriptor,\r
461 IN UINTN ReportSize\r
aa79b0b3 462 );\r
463\r
ed838d0c 464#endif\r