]>
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 |
67b8a9ce | 4 | Copyright (c) 2004 - 2008, 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 |
31 | #include <Library/PcdLib.h>\r | |
dfb74df5 | 32 | #include <Library/UefiUsbLib.h>\r |
67b8a9ce | 33 | #include <Library/DebugLib.h>\r |
09f72ae8 | 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_ABSOLUTE_POINTER_DEV_SIGNATURE SIGNATURE_32 ('u', 'm', 's', 't')\r |
09f72ae8 | 45 | \r |
67b8a9ce | 46 | ///\r |
47 | /// Button range and status\r | |
48 | ///\r | |
09f72ae8 | 49 | typedef struct {\r |
50 | BOOLEAN ButtonDetected;\r | |
51 | UINT8 ButtonMinIndex;\r | |
52 | UINT8 ButtonMaxIndex;\r | |
53 | UINT8 Reserved;\r | |
67b8a9ce | 54 | } USB_MOUSE_BUTTON_DATA;\r |
09f72ae8 | 55 | \r |
67b8a9ce | 56 | ///\r |
57 | /// Device instance of USB mouse.\r | |
58 | ///\r | |
09f72ae8 | 59 | typedef 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 | |
67b8a9ce | 64 | EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;\r |
65 | EFI_USB_ENDPOINT_DESCRIPTOR IntEndpointDescriptor;\r | |
09f72ae8 | 66 | UINT8 NumberOfButtons;\r |
67 | INT32 XLogicMax;\r | |
68 | INT32 XLogicMin;\r | |
69 | INT32 YLogicMax;\r | |
70 | INT32 YLogicMin;\r | |
09f72ae8 | 71 | EFI_ABSOLUTE_POINTER_PROTOCOL AbsolutePointerProtocol;\r |
67b8a9ce | 72 | EFI_ABSOLUTE_POINTER_STATE State;\r |
73 | EFI_ABSOLUTE_POINTER_MODE Mode;\r | |
74 | BOOLEAN StateChanged;\r | |
75 | USB_MOUSE_BUTTON_DATA PrivateData;\r | |
09f72ae8 | 76 | EFI_UNICODE_STRING_TABLE *ControllerNameTable;\r |
77 | } USB_MOUSE_ABSOLUTE_POINTER_DEV;\r | |
78 | \r | |
67b8a9ce | 79 | ///\r |
80 | /// General HID Item structure\r | |
81 | ///\r | |
82 | typedef 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 | |
09f72ae8 | 98 | #define USB_MOUSE_ABSOLUTE_POINTER_DEV_FROM_MOUSE_PROTOCOL(a) \\r |
99 | CR(a, USB_MOUSE_ABSOLUTE_POINTER_DEV, AbsolutePointerProtocol, USB_MOUSE_ABSOLUTE_POINTER_DEV_SIGNATURE)\r | |
100 | \r | |
09f72ae8 | 101 | //\r |
102 | // Global Variables\r | |
103 | //\r | |
104 | extern EFI_DRIVER_BINDING_PROTOCOL gUsbMouseAbsolutePointerDriverBinding;\r | |
105 | extern EFI_COMPONENT_NAME_PROTOCOL gUsbMouseAbsolutePointerComponentName;\r | |
106 | extern EFI_COMPONENT_NAME2_PROTOCOL gUsbMouseAbsolutePointerComponentName2;\r | |
09f72ae8 | 107 | \r |
aa79b0b3 | 108 | //\r |
67b8a9ce | 109 | // Functions of Driver Binding Protocol\r |
aa79b0b3 | 110 | //\r |
aa79b0b3 | 111 | \r |
67b8a9ce | 112 | /**\r |
113 | Check whether USB Mouse Absolute Pointer Driver supports this device.\r | |
114 | \r | |
115 | @param This The driver binding protocol.\r | |
116 | @param Controller The controller handle to check.\r | |
117 | @param RemainingDevicePath The remaining device path.\r | |
118 | \r | |
119 | @retval EFI_SUCCESS The driver supports this controller.\r | |
120 | @retval other This device isn't supported.\r | |
121 | \r | |
122 | **/\r | |
aa79b0b3 | 123 | EFI_STATUS\r |
124 | EFIAPI\r | |
125 | USBMouseAbsolutePointerDriverBindingSupported (\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 | |
67b8a9ce | 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 Absolute Pointer Protocol, and submits Asynchronous Interrupt\r | |
136 | Transfer to manage the USB mouse device.\r | |
137 | \r | |
138 | @param This The 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 | |
aa79b0b3 | 150 | EFI_STATUS\r |
151 | EFIAPI\r | |
152 | USBMouseAbsolutePointerDriverBindingStart (\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 | |
67b8a9ce | 158 | /**\r |
159 | Stop the USB mouse device handled by this driver.\r | |
160 | \r | |
161 | @param This The 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 Absolute Pointer Protocol is not installed on Controller.\r | |
168 | @retval Others Fail to uninstall protocols attached on the device.\r | |
169 | \r | |
170 | **/\r | |
aa79b0b3 | 171 | EFI_STATUS\r |
172 | EFIAPI\r | |
173 | USBMouseAbsolutePointerDriverBindingStop (\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 | |
178 | );\r | |
179 | \r | |
67b8a9ce | 180 | //\r |
181 | // EFI Component Name Functions\r | |
182 | //\r | |
183 | \r | |
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 | |
218 | EFI_STATUS\r | |
219 | EFIAPI\r | |
220 | UsbMouseAbsolutePointerComponentNameGetDriverName (\r | |
221 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r | |
222 | IN CHAR8 *Language,\r | |
223 | OUT CHAR16 **DriverName\r | |
224 | );\r | |
225 | \r | |
226 | /**\r | |
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 | |
282 | \r | |
283 | **/\r | |
284 | EFI_STATUS\r | |
285 | EFIAPI\r | |
286 | UsbMouseAbsolutePointerComponentNameGetControllerName (\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 | |
293 | \r | |
294 | //\r | |
295 | // Functions of EFI_ABSOLUTE_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_ABSOLUTE_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 State is NULL. \r | |
310 | \r | |
311 | **/\r | |
312 | EFI_STATUS\r | |
313 | EFIAPI\r | |
314 | GetMouseAbsolutePointerState (\r | |
315 | IN EFI_ABSOLUTE_POINTER_PROTOCOL *This,\r | |
316 | OUT EFI_ABSOLUTE_POINTER_STATE *State\r | |
317 | );\r | |
318 | \r | |
319 | /**\r | |
320 | Resets the pointer device hardware.\r | |
321 | \r | |
322 | @param This A pointer to the EFI_ABSOLUTE_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 | |
330 | EFI_STATUS\r | |
331 | EFIAPI\r | |
332 | UsbMouseAbsolutePointerReset (\r | |
333 | IN EFI_ABSOLUTE_POINTER_PROTOCOL *This,\r | |
334 | IN BOOLEAN ExtendedVerification\r | |
335 | );\r | |
336 | \r | |
337 | /**\r | |
338 | Event notification function for EFI_ABSOLUTE_POINTER_PROTOCOL.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_ABSOLUTE_POINTER_DEV instance.\r | |
342 | \r | |
343 | **/\r | |
344 | VOID\r | |
345 | EFIAPI\r | |
346 | UsbMouseAbsolutePointerWaitForInput (\r | |
347 | IN EFI_EVENT Event,\r | |
348 | IN VOID *Context\r | |
349 | );\r | |
350 | \r | |
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 | |
362 | \r | |
363 | **/\r | |
364 | BOOLEAN\r | |
365 | IsUsbMouse (\r | |
366 | IN EFI_USB_IO_PROTOCOL *UsbIo\r | |
367 | );\r | |
368 | \r | |
369 | /**\r | |
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_ABSOLUTE_POINTER_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 | |
376 | \r | |
377 | @param UsbMouseAbsolutePointerDev Device instance to be initialized.\r | |
378 | \r | |
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 | |
382 | \r | |
383 | **/\r | |
384 | EFI_STATUS\r | |
385 | InitializeUsbMouseDevice (\r | |
386 | IN USB_MOUSE_ABSOLUTE_POINTER_DEV *UsbMouseAbsolutePointerDev\r | |
387 | );\r | |
388 | \r | |
389 | /**\r | |
390 | Handler function for USB mouse's asynchronous interrupt transfer.\r | |
391 | \r | |
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 | |
395 | \r | |
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 | |
404 | \r | |
405 | **/\r | |
406 | EFI_STATUS\r | |
407 | EFIAPI\r | |
408 | OnMouseInterruptComplete (\r | |
409 | IN VOID *Data,\r | |
410 | IN UINTN DataLength,\r | |
411 | IN VOID *Context,\r | |
412 | IN UINT32 Result\r | |
413 | );\r | |
414 | \r | |
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_ABSOLUTE_POINTER_DEV instance.\r | |
426 | \r | |
427 | **/\r | |
428 | VOID\r | |
429 | EFIAPI\r | |
430 | USBMouseRecoveryHandler (\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_ABSOLUTE_POINTER_DEV.\r | |
442 | \r | |
443 | @param UsbMouseAbsolutePointer The instance of USB_MOUSE_ABSOLUTE_POINTER_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 | |
451 | EFI_STATUS\r | |
452 | ParseMouseReportDescriptor (\r | |
453 | OUT USB_MOUSE_ABSOLUTE_POINTER_DEV *UsbMouseAbsolutePointer,\r | |
454 | IN UINT8 *ReportDescriptor,\r | |
455 | IN UINTN ReportSize\r | |
456 | );\r | |
aa79b0b3 | 457 | \r |
09f72ae8 | 458 | #endif\r |