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