]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.h
IntelSiliconPkg: Clean up source files
[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
0309b719 4Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>\r
cd5ebaa0 5This program and the accompanying materials\r
ed838d0c 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
ed838d0c 13**/\r
14\r
bb80e3b2 15#ifndef _EFI_USB_MOUSE_H_\r
16#define _EFI_USB_MOUSE_H_\r
ed838d0c 17\r
ed7748fe 18\r
60c93673 19#include <Uefi.h>\r
ed7748fe 20\r
ed838d0c 21#include <Protocol/SimplePointer.h>\r
22#include <Protocol/UsbIo.h>\r
23#include <Protocol/DevicePath.h>\r
ed7748fe 24\r
ed838d0c 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
30#include <Library/MemoryAllocationLib.h>\r
dfb74df5 31#include <Library/UefiUsbLib.h>\r
29129ce4 32#include <Library/DebugLib.h>\r
ed838d0c 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_DEV_SIGNATURE SIGNATURE_32 ('u', 'm', 'o', 'u')\r
ed838d0c 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
29129ce4 56///\r
57/// Button range and status\r
58///\r
ed838d0c 59typedef struct {\r
60 BOOLEAN ButtonDetected;\r
61 UINT8 ButtonMinIndex;\r
62 UINT8 ButtonMaxIndex;\r
63 UINT8 Reserved;\r
29129ce4 64} USB_MOUSE_BUTTON_DATA;\r
ed838d0c 65\r
29129ce4 66///\r
67/// Device instance of USB mouse.\r
68///\r
ed838d0c 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
29129ce4 74 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;\r
75 EFI_USB_ENDPOINT_DESCRIPTOR IntEndpointDescriptor;\r
ed838d0c 76 UINT8 NumberOfButtons;\r
77 INT32 XLogicMax;\r
78 INT32 XLogicMin;\r
79 INT32 YLogicMax;\r
80 INT32 YLogicMin;\r
81 EFI_SIMPLE_POINTER_PROTOCOL SimplePointerProtocol;\r
82 EFI_SIMPLE_POINTER_STATE State;\r
83 EFI_SIMPLE_POINTER_MODE Mode;\r
84 BOOLEAN StateChanged;\r
29129ce4 85 USB_MOUSE_BUTTON_DATA PrivateData;\r
ed838d0c 86 EFI_UNICODE_STRING_TABLE *ControllerNameTable;\r
87} USB_MOUSE_DEV;\r
88\r
29129ce4 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
29129ce4 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
29129ce4 109} HID_ITEM;\r
110\r
ed838d0c 111#define USB_MOUSE_DEV_FROM_MOUSE_PROTOCOL(a) \\r
112 CR(a, USB_MOUSE_DEV, SimplePointerProtocol, USB_MOUSE_DEV_SIGNATURE)\r
113\r
29129ce4 114//\r
115// Global Variables\r
116//\r
117extern EFI_DRIVER_BINDING_PROTOCOL gUsbMouseDriverBinding;\r
118extern EFI_COMPONENT_NAME_PROTOCOL gUsbMouseComponentName;\r
119extern EFI_COMPONENT_NAME2_PROTOCOL gUsbMouseComponentName2;\r
120\r
121//\r
122// Functions of Driver Binding Protocol\r
123//\r
bb80e3b2 124\r
125/**\r
29129ce4 126 Check whether USB mouse driver supports this device.\r
bb80e3b2 127\r
29129ce4 128 @param This The USB mouse driver binding protocol.\r
129 @param Controller The controller handle to check.\r
130 @param RemainingDevicePath The remaining device path.\r
bb80e3b2 131\r
29129ce4 132 @retval EFI_SUCCESS The driver supports this controller.\r
133 @retval other This device isn't supported.\r
bb80e3b2 134\r
135**/\r
29129ce4 136EFI_STATUS\r
ed838d0c 137EFIAPI\r
29129ce4 138USBMouseDriverBindingSupported (\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
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 Simple Pointer Protocol, and submits Asynchronous Interrupt\r
149 Transfer to manage the USB mouse device.\r
150\r
151 @param This The USB mouse 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
163EFI_STATUS\r
164EFIAPI\r
165USBMouseDriverBindingStart (\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
171/**\r
172 Stop the USB mouse device handled by this driver.\r
173\r
174 @param This The USB mouse 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 Simple Pointer Protocol is not installed on Controller.\r
181 @retval Others Fail to uninstall protocols attached on the device.\r
182\r
183**/\r
184EFI_STATUS\r
185EFIAPI\r
186USBMouseDriverBindingStop (\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
ed838d0c 191 );\r
192\r
193//\r
29129ce4 194// EFI Component Name Functions\r
ed838d0c 195//\r
ed838d0c 196\r
29129ce4 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
29129ce4 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
233UsbMouseComponentNameGetDriverName (\r
234 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
235 IN CHAR8 *Language,\r
236 OUT CHAR16 **DriverName\r
237 );\r
bb80e3b2 238\r
239/**\r
29129ce4 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
29129ce4 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
29129ce4 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
bb80e3b2 295\r
29129ce4 296**/\r
297EFI_STATUS\r
298EFIAPI\r
299UsbMouseComponentNameGetControllerName (\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
bb80e3b2 306\r
c92e277d 307//\r
308// Functions of EFI_SIMPLE_POINTER_PROTOCOL\r
309//\r
310\r
311/**\r
312 Retrieves the current state of a pointer device.\r
313 \r
314 @param This A pointer to the EFI_SIMPLE_POINTER_PROTOCOL instance. \r
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
319 GetState(). \r
320 @retval EFI_DEVICE_ERROR A device error occurred while attempting to retrieve the pointer device's\r
321 current state. \r
322 @retval EFI_INVALID_PARAMETER MouseState is NULL. \r
323\r
324**/\r
325EFI_STATUS\r
326EFIAPI\r
327GetMouseState (\r
328 IN EFI_SIMPLE_POINTER_PROTOCOL *This,\r
329 OUT EFI_SIMPLE_POINTER_STATE *MouseState\r
330 );\r
331\r
332/** \r
333 Resets the pointer device hardware.\r
334 \r
335 @param This A pointer to the EFI_SIMPLE_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
345UsbMouseReset (\r
346 IN EFI_SIMPLE_POINTER_PROTOCOL *This,\r
347 IN BOOLEAN ExtendedVerification\r
348 );\r
349\r
350/**\r
351 Event notification function for SIMPLE_POINTER.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_DEV instance.\r
355 \r
356**/\r
357VOID\r
358EFIAPI\r
359UsbMouseWaitForInput (\r
360 IN EFI_EVENT Event,\r
361 IN VOID *Context\r
362 );\r
363\r
29129ce4 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
bb80e3b2 375\r
376**/\r
29129ce4 377BOOLEAN\r
378IsUsbMouse (\r
379 IN EFI_USB_IO_PROTOCOL *UsbIo\r
ed838d0c 380 );\r
381\r
aa79b0b3 382/**\r
29129ce4 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_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
aa79b0b3 389\r
29129ce4 390 @param UsbMouseDev Device instance to be initialized.\r
aa79b0b3 391\r
29129ce4 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
aa79b0b3 395\r
396**/\r
397EFI_STATUS\r
29129ce4 398InitializeUsbMouseDevice (\r
399 IN OUT USB_MOUSE_DEV *UsbMouseDev\r
aa79b0b3 400 );\r
401\r
402/**\r
29129ce4 403 Handler function for USB mouse's asynchronous interrupt transfer.\r
aa79b0b3 404\r
29129ce4 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
aa79b0b3 408\r
29129ce4 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
aa79b0b3 417\r
418**/\r
419EFI_STATUS\r
420EFIAPI\r
29129ce4 421OnMouseInterruptComplete (\r
422 IN VOID *Data,\r
423 IN UINTN DataLength,\r
424 IN VOID *Context,\r
425 IN UINT32 Result\r
aa79b0b3 426 );\r
427\r
29129ce4 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_DEV instance.\r
aa79b0b3 439\r
440**/\r
29129ce4 441VOID\r
aa79b0b3 442EFIAPI\r
29129ce4 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_DEV.\r
455\r
456 @param UsbMouse The instance of USB_MOUSE_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_DEV *UsbMouse,\r
467 IN UINT8 *ReportDescriptor,\r
468 IN UINTN ReportSize\r
aa79b0b3 469 );\r
470\r
ed838d0c 471#endif\r