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_
14 #include <Protocol/SimplePointer.h>
15 #include <Protocol/UsbIo.h>
16 #include <Protocol/DevicePath.h>
18 #include <Library/ReportStatusCodeLib.h>
19 #include <Library/BaseMemoryLib.h>
20 #include <Library/UefiDriverEntryPoint.h>
21 #include <Library/UefiBootServicesTableLib.h>
22 #include <Library/UefiLib.h>
23 #include <Library/MemoryAllocationLib.h>
24 #include <Library/UefiUsbLib.h>
25 #include <Library/DebugLib.h>
27 #include <IndustryStandard/Usb.h>
30 #define SUBCLASS_BOOT 1
31 #define PROTOCOL_MOUSE 2
33 #define BOOT_PROTOCOL 0
34 #define REPORT_PROTOCOL 1
36 #define USB_MOUSE_DEV_SIGNATURE SIGNATURE_32 ('u', 'm', 'o', 'u')
39 // A common header for usb standard descriptor.
40 // Each stand descriptor has a length and type.
50 /// Button range and status
53 BOOLEAN ButtonDetected
;
57 } USB_MOUSE_BUTTON_DATA
;
60 /// Device instance of USB mouse.
64 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
65 EFI_EVENT DelayedRecoveryEvent
;
66 EFI_USB_IO_PROTOCOL
*UsbIo
;
67 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor
;
68 EFI_USB_ENDPOINT_DESCRIPTOR IntEndpointDescriptor
;
69 UINT8 NumberOfButtons
;
74 EFI_SIMPLE_POINTER_PROTOCOL SimplePointerProtocol
;
75 EFI_SIMPLE_POINTER_STATE State
;
76 EFI_SIMPLE_POINTER_MODE Mode
;
78 USB_MOUSE_BUTTON_DATA PrivateData
;
79 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
83 /// General HID Item structure
104 #define USB_MOUSE_DEV_FROM_MOUSE_PROTOCOL(a) \
105 CR(a, USB_MOUSE_DEV, SimplePointerProtocol, USB_MOUSE_DEV_SIGNATURE)
110 extern EFI_DRIVER_BINDING_PROTOCOL gUsbMouseDriverBinding
;
111 extern EFI_COMPONENT_NAME_PROTOCOL gUsbMouseComponentName
;
112 extern EFI_COMPONENT_NAME2_PROTOCOL gUsbMouseComponentName2
;
115 // Functions of Driver Binding Protocol
119 Check whether USB mouse driver supports this device.
121 @param This The USB mouse driver binding protocol.
122 @param Controller The controller handle to check.
123 @param RemainingDevicePath The remaining device path.
125 @retval EFI_SUCCESS The driver supports this controller.
126 @retval other This device isn't supported.
131 USBMouseDriverBindingSupported (
132 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
133 IN EFI_HANDLE Controller
,
134 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
138 Starts the mouse device with this driver.
140 This function consumes USB I/O Protocol, initializes USB mouse device,
141 installs Simple Pointer Protocol, and submits Asynchronous Interrupt
142 Transfer to manage the USB mouse device.
144 @param This The USB mouse driver binding instance.
145 @param Controller Handle of device to bind driver to.
146 @param RemainingDevicePath Optional parameter use to pick a specific child
149 @retval EFI_SUCCESS This driver supports this device.
150 @retval EFI_UNSUPPORTED This driver does not support this device.
151 @retval EFI_DEVICE_ERROR This driver cannot be started due to device Error.
152 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
153 @retval EFI_ALREADY_STARTED This driver has been started.
158 USBMouseDriverBindingStart (
159 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
160 IN EFI_HANDLE Controller
,
161 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
165 Stop the USB mouse device handled by this driver.
167 @param This The USB mouse driver binding protocol.
168 @param Controller The controller to release.
169 @param NumberOfChildren The number of handles in ChildHandleBuffer.
170 @param ChildHandleBuffer The array of child handle.
172 @retval EFI_SUCCESS The device was stopped.
173 @retval EFI_UNSUPPORTED Simple Pointer Protocol is not installed on Controller.
174 @retval Others Fail to uninstall protocols attached on the device.
179 USBMouseDriverBindingStop (
180 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
181 IN EFI_HANDLE Controller
,
182 IN UINTN NumberOfChildren
,
183 IN EFI_HANDLE
*ChildHandleBuffer
187 // EFI Component Name Functions
191 Retrieves a Unicode string that is the user readable name of the driver.
193 This function retrieves the user readable name of a driver in the form of a
194 Unicode string. If the driver specified by This has a user readable name in
195 the language specified by Language, then a pointer to the driver name is
196 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
197 by This does not support the language specified by Language,
198 then EFI_UNSUPPORTED is returned.
200 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
201 EFI_COMPONENT_NAME_PROTOCOL instance.
202 @param Language A pointer to a Null-terminated ASCII string
203 array indicating the language. This is the
204 language of the driver name that the caller is
205 requesting, and it must match one of the
206 languages specified in SupportedLanguages. The
207 number of languages supported by a driver is up
208 to the driver writer. Language is specified
209 in RFC 4646 or ISO 639-2 language code format.
210 @param DriverName A pointer to the Unicode string to return.
211 This Unicode string is the name of the
212 driver specified by This in the language
213 specified by Language.
215 @retval EFI_SUCCESS The Unicode string for the Driver specified by
216 This and the language specified by Language was
217 returned in DriverName.
218 @retval EFI_INVALID_PARAMETER Language is NULL.
219 @retval EFI_INVALID_PARAMETER DriverName is NULL.
220 @retval EFI_UNSUPPORTED The driver specified by This does not support
221 the language specified by Language.
226 UsbMouseComponentNameGetDriverName (
227 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
229 OUT CHAR16
**DriverName
233 Retrieves a Unicode string that is the user readable name of the controller
234 that is being managed by a driver.
236 This function retrieves the user readable name of the controller specified by
237 ControllerHandle and ChildHandle in the form of a Unicode string. If the
238 driver specified by This has a user readable name in the language specified by
239 Language, then a pointer to the controller name is returned in ControllerName,
240 and EFI_SUCCESS is returned. If the driver specified by This is not currently
241 managing the controller specified by ControllerHandle and ChildHandle,
242 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
243 support the language specified by Language, then EFI_UNSUPPORTED is returned.
245 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
246 EFI_COMPONENT_NAME_PROTOCOL instance.
247 @param ControllerHandle The handle of a controller that the driver
248 specified by This is managing. This handle
249 specifies the controller whose name is to be
251 @param ChildHandle The handle of the child controller to retrieve
252 the name of. This is an optional parameter that
253 may be NULL. It will be NULL for device
254 drivers. It will also be NULL for a bus drivers
255 that wish to retrieve the name of the bus
256 controller. It will not be NULL for a bus
257 driver that wishes to retrieve the name of a
259 @param Language A pointer to a Null-terminated ASCII string
260 array indicating the language. This is the
261 language of the driver name that the caller is
262 requesting, and it must match one of the
263 languages specified in SupportedLanguages. The
264 number of languages supported by a driver is up
265 to the driver writer. Language is specified in
266 RFC 4646 or ISO 639-2 language code format.
267 @param ControllerName A pointer to the Unicode string to return.
268 This Unicode string is the name of the
269 controller specified by ControllerHandle and
270 ChildHandle in the language specified by
271 Language from the point of view of the driver
274 @retval EFI_SUCCESS The Unicode string for the user readable name in
275 the language specified by Language for the
276 driver specified by This was returned in
278 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
279 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
281 @retval EFI_INVALID_PARAMETER Language is NULL.
282 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
283 @retval EFI_UNSUPPORTED The driver specified by This is not currently
284 managing the controller specified by
285 ControllerHandle and ChildHandle.
286 @retval EFI_UNSUPPORTED The driver specified by This does not support
287 the language specified by Language.
292 UsbMouseComponentNameGetControllerName (
293 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
294 IN EFI_HANDLE ControllerHandle
,
295 IN EFI_HANDLE ChildHandle OPTIONAL
,
297 OUT CHAR16
**ControllerName
301 // Functions of EFI_SIMPLE_POINTER_PROTOCOL
305 Retrieves the current state of a pointer device.
307 @param This A pointer to the EFI_SIMPLE_POINTER_PROTOCOL instance.
308 @param MouseState A pointer to the state information on the pointer device.
310 @retval EFI_SUCCESS The state of the pointer device was returned in State.
311 @retval EFI_NOT_READY The state of the pointer device has not changed since the last call to
313 @retval EFI_DEVICE_ERROR A device error occurred while attempting to retrieve the pointer device's
315 @retval EFI_INVALID_PARAMETER MouseState is NULL.
321 IN EFI_SIMPLE_POINTER_PROTOCOL
*This
,
322 OUT EFI_SIMPLE_POINTER_STATE
*MouseState
326 Resets the pointer device hardware.
328 @param This A pointer to the EFI_SIMPLE_POINTER_PROTOCOL instance.
329 @param ExtendedVerification Indicates that the driver may perform a more exhaustive
330 verification operation of the device during reset.
332 @retval EFI_SUCCESS The device was reset.
333 @retval EFI_DEVICE_ERROR The device is not functioning correctly and could not be reset.
339 IN EFI_SIMPLE_POINTER_PROTOCOL
*This
,
340 IN BOOLEAN ExtendedVerification
344 Event notification function for SIMPLE_POINTER.WaitForInput event.
346 @param Event Event to be signaled when there's input from mouse.
347 @param Context Points to USB_MOUSE_DEV instance.
352 UsbMouseWaitForInput (
358 // Internal worker functions
362 Uses USB I/O to check whether the device is a USB mouse device.
364 @param UsbIo Pointer to a USB I/O protocol instance.
366 @retval TRUE Device is a USB mouse device.
367 @retval FALSE Device is a not USB mouse device.
372 IN EFI_USB_IO_PROTOCOL
*UsbIo
376 Initialize the USB mouse device.
378 This function retrieves and parses HID report descriptor, and
379 initializes state of USB_MOUSE_DEV. Then it sets indefinite idle
380 rate for the device. Finally it creates event for delayed recovery,
381 which deals with device error.
383 @param UsbMouseDev Device instance to be initialized.
385 @retval EFI_SUCCESS USB mouse device successfully initialized..
386 @retval EFI_UNSUPPORTED HID descriptor type is not report descriptor.
387 @retval Other USB mouse device was not initialized successfully.
391 InitializeUsbMouseDevice (
392 IN OUT USB_MOUSE_DEV
*UsbMouseDev
396 Handler function for USB mouse's asynchronous interrupt transfer.
398 This function is the handler function for USB mouse's asynchronous interrupt transfer
399 to manage the mouse. It parses data returned from asynchronous interrupt transfer, and
400 get button and movement state.
402 @param Data A pointer to a buffer that is filled with key data which is
403 retrieved via asynchronous interrupt transfer.
404 @param DataLength Indicates the size of the data buffer.
405 @param Context Pointing to USB_KB_DEV instance.
406 @param Result Indicates the result of the asynchronous interrupt transfer.
408 @retval EFI_SUCCESS Asynchronous interrupt transfer is handled successfully.
409 @retval EFI_DEVICE_ERROR Hardware error occurs.
414 OnMouseInterruptComplete (
422 Handler for Delayed Recovery event.
424 This function is the handler for Delayed Recovery event triggered
426 After a device error occurs, the event would be triggered
427 with interval of EFI_USB_INTERRUPT_DELAY. EFI_USB_INTERRUPT_DELAY
428 is defined in USB standard for error handling.
430 @param Event The Delayed Recovery event.
431 @param Context Points to the USB_MOUSE_DEV instance.
436 USBMouseRecoveryHandler (
442 Parse Mouse Report Descriptor.
444 According to USB HID Specification, report descriptors are
445 composed of pieces of information. Each piece of information
446 is called an Item. This function retrieves each item from
447 the report descriptor and updates USB_MOUSE_DEV.
449 @param UsbMouse The instance of USB_MOUSE_DEV
450 @param ReportDescriptor Report descriptor to parse
451 @param ReportSize Report descriptor size
453 @retval EFI_SUCCESS Report descriptor successfully parsed.
454 @retval EFI_UNSUPPORTED Report descriptor contains long item.
458 ParseMouseReportDescriptor (
459 OUT USB_MOUSE_DEV
*UsbMouse
,
460 IN UINT8
*ReportDescriptor
,