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