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