2 Helper routine and corresponding data struct used by USB Mouse Driver.
4 Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #ifndef _EFI_USB_MOUSE_H_
16 #define _EFI_USB_MOUSE_H_
21 #include <Protocol/SimplePointer.h>
22 #include <Protocol/UsbIo.h>
23 #include <Protocol/DevicePath.h>
25 #include <Library/ReportStatusCodeLib.h>
26 #include <Library/BaseMemoryLib.h>
27 #include <Library/UefiDriverEntryPoint.h>
28 #include <Library/UefiBootServicesTableLib.h>
29 #include <Library/UefiLib.h>
30 #include <Library/MemoryAllocationLib.h>
31 #include <Library/UefiUsbLib.h>
32 #include <Library/DebugLib.h>
34 #include <IndustryStandard/Usb.h>
37 #define SUBCLASS_BOOT 1
38 #define PROTOCOL_MOUSE 2
40 #define BOOT_PROTOCOL 0
41 #define REPORT_PROTOCOL 1
43 #define USB_MOUSE_DEV_SIGNATURE SIGNATURE_32 ('u', 'm', 'o', 'u')
46 // A common header for usb standard descriptor.
47 // Each stand descriptor has a length and type.
57 /// Button range and status
60 BOOLEAN ButtonDetected
;
64 } USB_MOUSE_BUTTON_DATA
;
67 /// Device instance of USB mouse.
71 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
72 EFI_EVENT DelayedRecoveryEvent
;
73 EFI_USB_IO_PROTOCOL
*UsbIo
;
74 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor
;
75 EFI_USB_ENDPOINT_DESCRIPTOR IntEndpointDescriptor
;
76 UINT8 NumberOfButtons
;
81 EFI_SIMPLE_POINTER_PROTOCOL SimplePointerProtocol
;
82 EFI_SIMPLE_POINTER_STATE State
;
83 EFI_SIMPLE_POINTER_MODE Mode
;
85 USB_MOUSE_BUTTON_DATA PrivateData
;
86 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
90 /// General HID Item structure
111 #define USB_MOUSE_DEV_FROM_MOUSE_PROTOCOL(a) \
112 CR(a, USB_MOUSE_DEV, SimplePointerProtocol, USB_MOUSE_DEV_SIGNATURE)
117 extern EFI_DRIVER_BINDING_PROTOCOL gUsbMouseDriverBinding
;
118 extern EFI_COMPONENT_NAME_PROTOCOL gUsbMouseComponentName
;
119 extern EFI_COMPONENT_NAME2_PROTOCOL gUsbMouseComponentName2
;
122 // Functions of Driver Binding Protocol
126 Check whether USB mouse driver supports this device.
128 @param This The USB mouse driver binding protocol.
129 @param Controller The controller handle to check.
130 @param RemainingDevicePath The remaining device path.
132 @retval EFI_SUCCESS The driver supports this controller.
133 @retval other This device isn't supported.
138 USBMouseDriverBindingSupported (
139 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
140 IN EFI_HANDLE Controller
,
141 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
145 Starts the mouse device with this driver.
147 This function consumes USB I/O Portocol, intializes USB mouse device,
148 installs Simple Pointer Protocol, and submits Asynchronous Interrupt
149 Transfer to manage the USB mouse device.
151 @param This The USB mouse driver binding instance.
152 @param Controller Handle of device to bind driver to.
153 @param RemainingDevicePath Optional parameter use to pick a specific child
156 @retval EFI_SUCCESS This driver supports this device.
157 @retval EFI_UNSUPPORTED This driver does not support this device.
158 @retval EFI_DEVICE_ERROR This driver cannot be started due to device Error.
159 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
160 @retval EFI_ALREADY_STARTED This driver has been started.
165 USBMouseDriverBindingStart (
166 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
167 IN EFI_HANDLE Controller
,
168 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
172 Stop the USB mouse device handled by this driver.
174 @param This The USB mouse driver binding protocol.
175 @param Controller The controller to release.
176 @param NumberOfChildren The number of handles in ChildHandleBuffer.
177 @param ChildHandleBuffer The array of child handle.
179 @retval EFI_SUCCESS The device was stopped.
180 @retval EFI_UNSUPPORTED Simple Pointer Protocol is not installed on Controller.
181 @retval Others Fail to uninstall protocols attached on the device.
186 USBMouseDriverBindingStop (
187 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
188 IN EFI_HANDLE Controller
,
189 IN UINTN NumberOfChildren
,
190 IN EFI_HANDLE
*ChildHandleBuffer
194 // EFI Component Name Functions
198 Retrieves a Unicode string that is the user readable name of the driver.
200 This function retrieves the user readable name of a driver in the form of a
201 Unicode string. If the driver specified by This has a user readable name in
202 the language specified by Language, then a pointer to the driver name is
203 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
204 by This does not support the language specified by Language,
205 then EFI_UNSUPPORTED is returned.
207 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
208 EFI_COMPONENT_NAME_PROTOCOL instance.
209 @param Language A pointer to a Null-terminated ASCII string
210 array indicating the language. This is the
211 language of the driver name that the caller is
212 requesting, and it must match one of the
213 languages specified in SupportedLanguages. The
214 number of languages supported by a driver is up
215 to the driver writer. Language is specified
216 in RFC 4646 or ISO 639-2 language code format.
217 @param DriverName A pointer to the Unicode string to return.
218 This Unicode string is the name of the
219 driver specified by This in the language
220 specified by Language.
222 @retval EFI_SUCCESS The Unicode string for the Driver specified by
223 This and the language specified by Language was
224 returned in DriverName.
225 @retval EFI_INVALID_PARAMETER Language is NULL.
226 @retval EFI_INVALID_PARAMETER DriverName is NULL.
227 @retval EFI_UNSUPPORTED The driver specified by This does not support
228 the language specified by Language.
233 UsbMouseComponentNameGetDriverName (
234 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
236 OUT CHAR16
**DriverName
240 Retrieves a Unicode string that is the user readable name of the controller
241 that is being managed by a driver.
243 This function retrieves the user readable name of the controller specified by
244 ControllerHandle and ChildHandle in the form of a Unicode string. If the
245 driver specified by This has a user readable name in the language specified by
246 Language, then a pointer to the controller name is returned in ControllerName,
247 and EFI_SUCCESS is returned. If the driver specified by This is not currently
248 managing the controller specified by ControllerHandle and ChildHandle,
249 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
250 support the language specified by Language, then EFI_UNSUPPORTED is returned.
252 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
253 EFI_COMPONENT_NAME_PROTOCOL instance.
254 @param ControllerHandle The handle of a controller that the driver
255 specified by This is managing. This handle
256 specifies the controller whose name is to be
258 @param ChildHandle The handle of the child controller to retrieve
259 the name of. This is an optional parameter that
260 may be NULL. It will be NULL for device
261 drivers. It will also be NULL for a bus drivers
262 that wish to retrieve the name of the bus
263 controller. It will not be NULL for a bus
264 driver that wishes to retrieve the name of a
266 @param Language A pointer to a Null-terminated ASCII string
267 array indicating the language. This is the
268 language of the driver name that the caller is
269 requesting, and it must match one of the
270 languages specified in SupportedLanguages. The
271 number of languages supported by a driver is up
272 to the driver writer. Language is specified in
273 RFC 4646 or ISO 639-2 language code format.
274 @param ControllerName A pointer to the Unicode string to return.
275 This Unicode string is the name of the
276 controller specified by ControllerHandle and
277 ChildHandle in the language specified by
278 Language from the point of view of the driver
281 @retval EFI_SUCCESS The Unicode string for the user readable name in
282 the language specified by Language for the
283 driver specified by This was returned in
285 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
286 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
288 @retval EFI_INVALID_PARAMETER Language is NULL.
289 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
290 @retval EFI_UNSUPPORTED The driver specified by This is not currently
291 managing the controller specified by
292 ControllerHandle and ChildHandle.
293 @retval EFI_UNSUPPORTED The driver specified by This does not support
294 the language specified by Language.
299 UsbMouseComponentNameGetControllerName (
300 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
301 IN EFI_HANDLE ControllerHandle
,
302 IN EFI_HANDLE ChildHandle OPTIONAL
,
304 OUT CHAR16
**ControllerName
308 // Functions of EFI_SIMPLE_POINTER_PROTOCOL
312 Retrieves the current state of a pointer device.
314 @param This A pointer to the EFI_SIMPLE_POINTER_PROTOCOL instance.
315 @param MouseState A pointer to the state information on the pointer device.
317 @retval EFI_SUCCESS The state of the pointer device was returned in State.
318 @retval EFI_NOT_READY The state of the pointer device has not changed since the last call to
320 @retval EFI_DEVICE_ERROR A device error occurred while attempting to retrieve the pointer device's
322 @retval EFI_INVALID_PARAMETER MouseState is NULL.
328 IN EFI_SIMPLE_POINTER_PROTOCOL
*This
,
329 OUT EFI_SIMPLE_POINTER_STATE
*MouseState
333 Resets the pointer device hardware.
335 @param This A pointer to the EFI_SIMPLE_POINTER_PROTOCOL instance.
336 @param ExtendedVerification Indicates that the driver may perform a more exhaustive
337 verification operation of the device during reset.
339 @retval EFI_SUCCESS The device was reset.
340 @retval EFI_DEVICE_ERROR The device is not functioning correctly and could not be reset.
346 IN EFI_SIMPLE_POINTER_PROTOCOL
*This
,
347 IN BOOLEAN ExtendedVerification
351 Event notification function for SIMPLE_POINTER.WaitForInput event.
353 @param Event Event to be signaled when there's input from mouse.
354 @param Context Points to USB_MOUSE_DEV instance.
359 UsbMouseWaitForInput (
365 // Internal worker functions
369 Uses USB I/O to check whether the device is a USB mouse device.
371 @param UsbIo Pointer to a USB I/O protocol instance.
373 @retval TRUE Device is a USB mouse device.
374 @retval FALSE Device is a not USB mouse device.
379 IN EFI_USB_IO_PROTOCOL
*UsbIo
383 Initialize the USB mouse device.
385 This function retrieves and parses HID report descriptor, and
386 initializes state of USB_MOUSE_DEV. Then it sets indefinite idle
387 rate for the device. Finally it creates event for delayed recovery,
388 which deals with device error.
390 @param UsbMouseDev Device instance to be initialized.
392 @retval EFI_SUCCESS USB mouse device successfully initialized..
393 @retval EFI_UNSUPPORTED HID descriptor type is not report descriptor.
394 @retval Other USB mouse device was not initialized successfully.
398 InitializeUsbMouseDevice (
399 IN OUT USB_MOUSE_DEV
*UsbMouseDev
403 Handler function for USB mouse's asynchronous interrupt transfer.
405 This function is the handler function for USB mouse's asynchronous interrupt transfer
406 to manage the mouse. It parses data returned from asynchronous interrupt transfer, and
407 get button and movement state.
409 @param Data A pointer to a buffer that is filled with key data which is
410 retrieved via asynchronous interrupt transfer.
411 @param DataLength Indicates the size of the data buffer.
412 @param Context Pointing to USB_KB_DEV instance.
413 @param Result Indicates the result of the asynchronous interrupt transfer.
415 @retval EFI_SUCCESS Asynchronous interrupt transfer is handled successfully.
416 @retval EFI_DEVICE_ERROR Hardware error occurs.
421 OnMouseInterruptComplete (
429 Handler for Delayed Recovery event.
431 This function is the handler for Delayed Recovery event triggered
433 After a device error occurs, the event would be triggered
434 with interval of EFI_USB_INTERRUPT_DELAY. EFI_USB_INTERRUPT_DELAY
435 is defined in USB standard for error handling.
437 @param Event The Delayed Recovery event.
438 @param Context Points to the USB_MOUSE_DEV instance.
443 USBMouseRecoveryHandler (
449 Parse Mouse Report Descriptor.
451 According to USB HID Specification, report descriptors are
452 composed of pieces of information. Each piece of information
453 is called an Item. This function retrieves each item from
454 the report descriptor and updates USB_MOUSE_DEV.
456 @param UsbMouse The instance of USB_MOUSE_DEV
457 @param ReportDescriptor Report descriptor to parse
458 @param ReportSize Report descriptor size
460 @retval EFI_SUCCESS Report descriptor successfully parsed.
461 @retval EFI_UNSUPPORTED Report descriptor contains long item.
465 ParseMouseReportDescriptor (
466 OUT USB_MOUSE_DEV
*UsbMouse
,
467 IN UINT8
*ReportDescriptor
,