2 Helper routine and corresponding data struct used by USB Mouse Driver.
4 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #ifndef _EFI_USB_MOUSE_H_
10 #define _EFI_USB_MOUSE_H_
15 #include <Protocol/SimplePointer.h>
16 #include <Protocol/UsbIo.h>
17 #include <Protocol/DevicePath.h>
19 #include <Library/ReportStatusCodeLib.h>
20 #include <Library/BaseMemoryLib.h>
21 #include <Library/UefiDriverEntryPoint.h>
22 #include <Library/UefiBootServicesTableLib.h>
23 #include <Library/UefiLib.h>
24 #include <Library/MemoryAllocationLib.h>
25 #include <Library/UefiUsbLib.h>
26 #include <Library/DebugLib.h>
28 #include <IndustryStandard/Usb.h>
31 #define SUBCLASS_BOOT 1
32 #define PROTOCOL_MOUSE 2
34 #define BOOT_PROTOCOL 0
35 #define REPORT_PROTOCOL 1
37 #define USB_MOUSE_DEV_SIGNATURE SIGNATURE_32 ('u', 'm', 'o', 'u')
40 // A common header for usb standard descriptor.
41 // Each stand descriptor has a length and type.
51 /// Button range and status
54 BOOLEAN ButtonDetected
;
58 } USB_MOUSE_BUTTON_DATA
;
61 /// Device instance of USB mouse.
65 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
66 EFI_EVENT DelayedRecoveryEvent
;
67 EFI_USB_IO_PROTOCOL
*UsbIo
;
68 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor
;
69 EFI_USB_ENDPOINT_DESCRIPTOR IntEndpointDescriptor
;
70 UINT8 NumberOfButtons
;
75 EFI_SIMPLE_POINTER_PROTOCOL SimplePointerProtocol
;
76 EFI_SIMPLE_POINTER_STATE State
;
77 EFI_SIMPLE_POINTER_MODE Mode
;
79 USB_MOUSE_BUTTON_DATA PrivateData
;
80 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
84 /// General HID Item structure
105 #define USB_MOUSE_DEV_FROM_MOUSE_PROTOCOL(a) \
106 CR(a, USB_MOUSE_DEV, SimplePointerProtocol, USB_MOUSE_DEV_SIGNATURE)
111 extern EFI_DRIVER_BINDING_PROTOCOL gUsbMouseDriverBinding
;
112 extern EFI_COMPONENT_NAME_PROTOCOL gUsbMouseComponentName
;
113 extern EFI_COMPONENT_NAME2_PROTOCOL gUsbMouseComponentName2
;
116 // Functions of Driver Binding Protocol
120 Check whether USB mouse driver supports this device.
122 @param This The USB mouse driver binding protocol.
123 @param Controller The controller handle to check.
124 @param RemainingDevicePath The remaining device path.
126 @retval EFI_SUCCESS The driver supports this controller.
127 @retval other This device isn't supported.
132 USBMouseDriverBindingSupported (
133 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
134 IN EFI_HANDLE Controller
,
135 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
139 Starts the mouse device with this driver.
141 This function consumes USB I/O Portocol, intializes USB mouse device,
142 installs Simple Pointer Protocol, and submits Asynchronous Interrupt
143 Transfer to manage the USB mouse device.
145 @param This The USB mouse driver binding instance.
146 @param Controller Handle of device to bind driver to.
147 @param RemainingDevicePath Optional parameter use to pick a specific child
150 @retval EFI_SUCCESS This driver supports this device.
151 @retval EFI_UNSUPPORTED This driver does not support this device.
152 @retval EFI_DEVICE_ERROR This driver cannot be started due to device Error.
153 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
154 @retval EFI_ALREADY_STARTED This driver has been started.
159 USBMouseDriverBindingStart (
160 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
161 IN EFI_HANDLE Controller
,
162 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
166 Stop the USB mouse device handled by this driver.
168 @param This The USB mouse driver binding protocol.
169 @param Controller The controller to release.
170 @param NumberOfChildren The number of handles in ChildHandleBuffer.
171 @param ChildHandleBuffer The array of child handle.
173 @retval EFI_SUCCESS The device was stopped.
174 @retval EFI_UNSUPPORTED Simple Pointer Protocol is not installed on Controller.
175 @retval Others Fail to uninstall protocols attached on the device.
180 USBMouseDriverBindingStop (
181 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
182 IN EFI_HANDLE Controller
,
183 IN UINTN NumberOfChildren
,
184 IN EFI_HANDLE
*ChildHandleBuffer
188 // EFI Component Name Functions
192 Retrieves a Unicode string that is the user readable name of the driver.
194 This function retrieves the user readable name of a driver in the form of a
195 Unicode string. If the driver specified by This has a user readable name in
196 the language specified by Language, then a pointer to the driver name is
197 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
198 by This does not support the language specified by Language,
199 then EFI_UNSUPPORTED is returned.
201 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
202 EFI_COMPONENT_NAME_PROTOCOL instance.
203 @param Language A pointer to a Null-terminated ASCII string
204 array indicating the language. This is the
205 language of the driver name that the caller is
206 requesting, and it must match one of the
207 languages specified in SupportedLanguages. The
208 number of languages supported by a driver is up
209 to the driver writer. Language is specified
210 in RFC 4646 or ISO 639-2 language code format.
211 @param DriverName A pointer to the Unicode string to return.
212 This Unicode string is the name of the
213 driver specified by This in the language
214 specified by Language.
216 @retval EFI_SUCCESS The Unicode string for the Driver specified by
217 This and the language specified by Language was
218 returned in DriverName.
219 @retval EFI_INVALID_PARAMETER Language is NULL.
220 @retval EFI_INVALID_PARAMETER DriverName is NULL.
221 @retval EFI_UNSUPPORTED The driver specified by This does not support
222 the language specified by Language.
227 UsbMouseComponentNameGetDriverName (
228 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
230 OUT CHAR16
**DriverName
234 Retrieves a Unicode string that is the user readable name of the controller
235 that is being managed by a driver.
237 This function retrieves the user readable name of the controller specified by
238 ControllerHandle and ChildHandle in the form of a Unicode string. If the
239 driver specified by This has a user readable name in the language specified by
240 Language, then a pointer to the controller name is returned in ControllerName,
241 and EFI_SUCCESS is returned. If the driver specified by This is not currently
242 managing the controller specified by ControllerHandle and ChildHandle,
243 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
244 support the language specified by Language, then EFI_UNSUPPORTED is returned.
246 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
247 EFI_COMPONENT_NAME_PROTOCOL instance.
248 @param ControllerHandle The handle of a controller that the driver
249 specified by This is managing. This handle
250 specifies the controller whose name is to be
252 @param ChildHandle The handle of the child controller to retrieve
253 the name of. This is an optional parameter that
254 may be NULL. It will be NULL for device
255 drivers. It will also be NULL for a bus drivers
256 that wish to retrieve the name of the bus
257 controller. It will not be NULL for a bus
258 driver that wishes to retrieve the name of a
260 @param Language A pointer to a Null-terminated ASCII string
261 array indicating the language. This is the
262 language of the driver name that the caller is
263 requesting, and it must match one of the
264 languages specified in SupportedLanguages. The
265 number of languages supported by a driver is up
266 to the driver writer. Language is specified in
267 RFC 4646 or ISO 639-2 language code format.
268 @param ControllerName A pointer to the Unicode string to return.
269 This Unicode string is the name of the
270 controller specified by ControllerHandle and
271 ChildHandle in the language specified by
272 Language from the point of view of the driver
275 @retval EFI_SUCCESS The Unicode string for the user readable name in
276 the language specified by Language for the
277 driver specified by This was returned in
279 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
280 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
282 @retval EFI_INVALID_PARAMETER Language is NULL.
283 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
284 @retval EFI_UNSUPPORTED The driver specified by This is not currently
285 managing the controller specified by
286 ControllerHandle and ChildHandle.
287 @retval EFI_UNSUPPORTED The driver specified by This does not support
288 the language specified by Language.
293 UsbMouseComponentNameGetControllerName (
294 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
295 IN EFI_HANDLE ControllerHandle
,
296 IN EFI_HANDLE ChildHandle OPTIONAL
,
298 OUT CHAR16
**ControllerName
302 // Functions of EFI_SIMPLE_POINTER_PROTOCOL
306 Retrieves the current state of a pointer device.
308 @param This A pointer to the EFI_SIMPLE_POINTER_PROTOCOL instance.
309 @param MouseState A pointer to the state information on the pointer device.
311 @retval EFI_SUCCESS The state of the pointer device was returned in State.
312 @retval EFI_NOT_READY The state of the pointer device has not changed since the last call to
314 @retval EFI_DEVICE_ERROR A device error occurred while attempting to retrieve the pointer device's
316 @retval EFI_INVALID_PARAMETER MouseState is NULL.
322 IN EFI_SIMPLE_POINTER_PROTOCOL
*This
,
323 OUT EFI_SIMPLE_POINTER_STATE
*MouseState
327 Resets the pointer device hardware.
329 @param This A pointer to the EFI_SIMPLE_POINTER_PROTOCOL instance.
330 @param ExtendedVerification Indicates that the driver may perform a more exhaustive
331 verification operation of the device during reset.
333 @retval EFI_SUCCESS The device was reset.
334 @retval EFI_DEVICE_ERROR The device is not functioning correctly and could not be reset.
340 IN EFI_SIMPLE_POINTER_PROTOCOL
*This
,
341 IN BOOLEAN ExtendedVerification
345 Event notification function for SIMPLE_POINTER.WaitForInput event.
347 @param Event Event to be signaled when there's input from mouse.
348 @param Context Points to USB_MOUSE_DEV instance.
353 UsbMouseWaitForInput (
359 // Internal worker functions
363 Uses USB I/O to check whether the device is a USB mouse device.
365 @param UsbIo Pointer to a USB I/O protocol instance.
367 @retval TRUE Device is a USB mouse device.
368 @retval FALSE Device is a not USB mouse device.
373 IN EFI_USB_IO_PROTOCOL
*UsbIo
377 Initialize the USB mouse device.
379 This function retrieves and parses HID report descriptor, and
380 initializes state of USB_MOUSE_DEV. Then it sets indefinite idle
381 rate for the device. Finally it creates event for delayed recovery,
382 which deals with device error.
384 @param UsbMouseDev Device instance to be initialized.
386 @retval EFI_SUCCESS USB mouse device successfully initialized..
387 @retval EFI_UNSUPPORTED HID descriptor type is not report descriptor.
388 @retval Other USB mouse device was not initialized successfully.
392 InitializeUsbMouseDevice (
393 IN OUT USB_MOUSE_DEV
*UsbMouseDev
397 Handler function for USB mouse's asynchronous interrupt transfer.
399 This function is the handler function for USB mouse's asynchronous interrupt transfer
400 to manage the mouse. It parses data returned from asynchronous interrupt transfer, and
401 get button and movement state.
403 @param Data A pointer to a buffer that is filled with key data which is
404 retrieved via asynchronous interrupt transfer.
405 @param DataLength Indicates the size of the data buffer.
406 @param Context Pointing to USB_KB_DEV instance.
407 @param Result Indicates the result of the asynchronous interrupt transfer.
409 @retval EFI_SUCCESS Asynchronous interrupt transfer is handled successfully.
410 @retval EFI_DEVICE_ERROR Hardware error occurs.
415 OnMouseInterruptComplete (
423 Handler for Delayed Recovery event.
425 This function is the handler for Delayed Recovery event triggered
427 After a device error occurs, the event would be triggered
428 with interval of EFI_USB_INTERRUPT_DELAY. EFI_USB_INTERRUPT_DELAY
429 is defined in USB standard for error handling.
431 @param Event The Delayed Recovery event.
432 @param Context Points to the USB_MOUSE_DEV instance.
437 USBMouseRecoveryHandler (
443 Parse Mouse Report Descriptor.
445 According to USB HID Specification, report descriptors are
446 composed of pieces of information. Each piece of information
447 is called an Item. This function retrieves each item from
448 the report descriptor and updates USB_MOUSE_DEV.
450 @param UsbMouse The instance of USB_MOUSE_DEV
451 @param ReportDescriptor Report descriptor to parse
452 @param ReportSize Report descriptor size
454 @retval EFI_SUCCESS Report descriptor successfully parsed.
455 @retval EFI_UNSUPPORTED Report descriptor contains long item.
459 ParseMouseReportDescriptor (
460 OUT USB_MOUSE_DEV
*UsbMouse
,
461 IN UINT8
*ReportDescriptor
,