]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Bus/Isa/Ps2MouseSimulateTouchPadDxe/Ps2MouseSimulateTouchPad.c
use a PS/2 mouse to simulate a faked touchpad device.
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Isa / Ps2MouseSimulateTouchPadDxe / Ps2MouseSimulateTouchPad.c
1 /**@file
2 A faked PS/2 Touchpad driver. Routines that interacts with callers,
3 conforming to EFI driver model
4
5 Copyright (c) 2006 - 2007, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include "Ps2MouseSimulateTouchPad.h"
17 #include "CommPs2.h"
18
19 //
20 // DriverBinding Protocol Instance
21 //
22 EFI_DRIVER_BINDING_PROTOCOL gPS2MouseSimulateTouchPadDriver = {
23 PS2MouseSimulateTouchPadDriverSupported,
24 PS2MouseSimulateTouchPadDriverStart,
25 PS2MouseSimulateTouchPadDriverStop,
26 0x1,
27 NULL,
28 NULL
29 };
30
31 EFI_STATUS
32 EFIAPI
33 PS2MouseSimulateTouchPadDriverSupported (
34 IN EFI_DRIVER_BINDING_PROTOCOL *This,
35 IN EFI_HANDLE Controller,
36 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
37 )
38 /*++
39
40 Routine Description:
41
42 ControllerDriver Protocol Method
43
44 Arguments:
45
46 Returns:
47
48 --*/
49 // GC_TODO: This - add argument and description to function comment
50 // GC_TODO: Controller - add argument and description to function comment
51 // GC_TODO: RemainingDevicePath - add argument and description to function comment
52 {
53 EFI_STATUS Status;
54 EFI_ISA_IO_PROTOCOL *IsaIo;
55
56 Status = EFI_SUCCESS;
57
58 //
59 // Open the IO Abstraction(s) needed to perform the supported test
60 //
61 Status = gBS->OpenProtocol (
62 Controller,
63 &gEfiIsaIoProtocolGuid,
64 (VOID **) &IsaIo,
65 This->DriverBindingHandle,
66 Controller,
67 EFI_OPEN_PROTOCOL_BY_DRIVER
68 );
69 if (EFI_ERROR (Status)) {
70 return Status;
71 }
72 //
73 // Use the ISA I/O Protocol to see if Controller is the Mouse controller
74 //
75 switch (IsaIo->ResourceList->Device.HID) {
76 case EISA_PNP_ID (0xF03):
77 //
78 // Microsoft PS/2 style mouse
79 //
80 case EISA_PNP_ID (0xF13):
81 //
82 // PS/2 Port for PS/2-style Mice
83 //
84 break;
85
86 case EISA_PNP_ID (0x303):
87 //
88 // IBM Enhanced (101/102-key, PS/2 mouse support)
89 //
90 if (IsaIo->ResourceList->Device.UID == 1) {
91 break;
92 }
93
94 default:
95 Status = EFI_UNSUPPORTED;
96 break;
97 }
98 //
99 // Close the I/O Abstraction(s) used to perform the supported test
100 //
101 gBS->CloseProtocol (
102 Controller,
103 &gEfiIsaIoProtocolGuid,
104 This->DriverBindingHandle,
105 Controller
106 );
107
108 return Status;
109 }
110
111 EFI_STATUS
112 EFIAPI
113 PS2MouseSimulateTouchPadDriverStart (
114 IN EFI_DRIVER_BINDING_PROTOCOL *This,
115 IN EFI_HANDLE Controller,
116 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
117 )
118 /*++
119
120 Routine Description:
121 Start protocol interfaces for the mouse device handles.
122
123 Arguments:
124 This - Protocol instance pointer.
125 Controller - Handle of device to bind driver to.
126 RemainingDevicePath - Not used.
127
128 Returns:
129 EFI_SUCCESS - This driver is added to DeviceHandle.
130 other - Errors occurred.
131
132 --*/
133 {
134 EFI_STATUS Status;
135 EFI_STATUS EmptyStatus;
136 EFI_ISA_IO_PROTOCOL *IsaIo;
137 PS2_MOUSE_SIMULATE_TOUCHPAD_DEV *MouseSimulateTouchPadDev;
138 UINT8 Data;
139 EFI_TPL OldTpl;
140 EFI_STATUS_CODE_VALUE StatusCode;
141 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
142
143 StatusCode = 0;
144 MouseSimulateTouchPadDev = NULL;
145 IsaIo = NULL;
146
147 //
148 // Open the device path protocol
149 //
150 Status = gBS->OpenProtocol (
151 Controller,
152 &gEfiDevicePathProtocolGuid,
153 (VOID **) &ParentDevicePath,
154 This->DriverBindingHandle,
155 Controller,
156 EFI_OPEN_PROTOCOL_BY_DRIVER
157 );
158 if (EFI_ERROR (Status)) {
159 return Status;
160 }
161 //
162 // Report that the keyboard is being enabled
163 //
164 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
165 EFI_PROGRESS_CODE,
166 EFI_PERIPHERAL_MOUSE | EFI_P_PC_ENABLE,
167 ParentDevicePath
168 );
169
170 //
171 // Get the ISA I/O Protocol on Controller's handle
172 //
173 Status = gBS->OpenProtocol (
174 Controller,
175 &gEfiIsaIoProtocolGuid,
176 (VOID **) &IsaIo,
177 This->DriverBindingHandle,
178 Controller,
179 EFI_OPEN_PROTOCOL_BY_DRIVER
180 );
181 if (EFI_ERROR (Status)) {
182 gBS->CloseProtocol (
183 Controller,
184 &gEfiDevicePathProtocolGuid,
185 This->DriverBindingHandle,
186 Controller
187 );
188 return EFI_INVALID_PARAMETER;
189 }
190 //
191 // Raise TPL to avoid keyboard operation impact
192 //
193 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
194
195 //
196 // Allocate private data
197 //
198 MouseSimulateTouchPadDev = AllocateZeroPool (sizeof (PS2_MOUSE_SIMULATE_TOUCHPAD_DEV));
199 if (MouseSimulateTouchPadDev == NULL) {
200 Status = EFI_OUT_OF_RESOURCES;
201 goto ErrorExit;
202 }
203 //
204 // Setup the device instance
205 //
206 MouseSimulateTouchPadDev->Signature = PS2_MOUSE_SIMULATE_TOUCHPAD_DEV_SIGNATURE;
207 MouseSimulateTouchPadDev->Handle = Controller;
208 MouseSimulateTouchPadDev->SampleRate = SSR_20;
209 MouseSimulateTouchPadDev->Resolution = CMR4;
210 MouseSimulateTouchPadDev->Scaling = SF1;
211 MouseSimulateTouchPadDev->DataPackageSize = 3;
212 MouseSimulateTouchPadDev->IsaIo = IsaIo;
213 MouseSimulateTouchPadDev->DevicePath = ParentDevicePath;
214
215 //
216 // Resolution = 4 counts/mm
217 //
218 MouseSimulateTouchPadDev->Mode.AbsoluteMaxX = 1024;
219 MouseSimulateTouchPadDev->Mode.AbsoluteMinX = 0;
220 MouseSimulateTouchPadDev->Mode.AbsoluteMaxY = 798;
221 MouseSimulateTouchPadDev->Mode.AbsoluteMinY = 0;
222 MouseSimulateTouchPadDev->Mode.AbsoluteMaxZ = 0;
223 MouseSimulateTouchPadDev->Mode.AbsoluteMinZ = 0;
224 MouseSimulateTouchPadDev->Mode.Attributes = 0x03;
225
226 MouseSimulateTouchPadDev->AbsolutePointerProtocol.Reset = MouseSimulateTouchPadReset;
227 MouseSimulateTouchPadDev->AbsolutePointerProtocol.GetState = MouseSimulateTouchPadGetState;
228 MouseSimulateTouchPadDev->AbsolutePointerProtocol.Mode = &(MouseSimulateTouchPadDev->Mode);
229
230 //
231 // Initialize keyboard controller if necessary
232 //
233 IsaIo->Io.Read (IsaIo, EfiIsaIoWidthUint8, KBC_CMD_STS_PORT, 1, &Data);
234 if ((Data & KBC_SYSF) != KBC_SYSF) {
235 Status = KbcSelfTest (IsaIo);
236 if (EFI_ERROR (Status)) {
237 StatusCode = EFI_PERIPHERAL_MOUSE | EFI_P_EC_CONTROLLER_ERROR;
238 goto ErrorExit;
239 }
240 }
241
242 KbcEnableAux (IsaIo);
243
244 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
245 EFI_PROGRESS_CODE,
246 EFI_PERIPHERAL_MOUSE | EFI_P_PC_PRESENCE_DETECT,
247 ParentDevicePath
248 );
249
250 //
251 // Reset the mouse
252 //
253 Status = MouseSimulateTouchPadDev->AbsolutePointerProtocol.Reset (&MouseSimulateTouchPadDev->AbsolutePointerProtocol, TRUE);
254 if (EFI_ERROR (Status)) {
255 //
256 // mouse not connected
257 //
258 Status = EFI_SUCCESS;
259 StatusCode = EFI_PERIPHERAL_MOUSE | EFI_P_EC_NOT_DETECTED;
260 goto ErrorExit;
261 }
262 //
263 // Setup the WaitForKey event
264 //
265 Status = gBS->CreateEvent (
266 EVT_NOTIFY_WAIT,
267 TPL_NOTIFY,
268 MouseSimulateTouchPadWaitForInput,
269 MouseSimulateTouchPadDev,
270 &((MouseSimulateTouchPadDev->AbsolutePointerProtocol).WaitForInput)
271 );
272 if (EFI_ERROR (Status)) {
273 Status = EFI_OUT_OF_RESOURCES;
274 goto ErrorExit;
275 }
276 //
277 // Setup a periodic timer, used to poll mouse state
278 //
279 Status = gBS->CreateEvent (
280 EVT_TIMER | EVT_NOTIFY_SIGNAL,
281 TPL_NOTIFY,
282 PollMouseSimulateTouchPad,
283 MouseSimulateTouchPadDev,
284 &MouseSimulateTouchPadDev->TimerEvent
285 );
286 if (EFI_ERROR (Status)) {
287 Status = EFI_OUT_OF_RESOURCES;
288 goto ErrorExit;
289 }
290 //
291 // Start timer to poll mouse (100 samples per second)
292 //
293 Status = gBS->SetTimer (MouseSimulateTouchPadDev->TimerEvent, TimerPeriodic, 100000);
294 if (EFI_ERROR (Status)) {
295 Status = EFI_OUT_OF_RESOURCES;
296 goto ErrorExit;
297 }
298
299 MouseSimulateTouchPadDev->ControllerNameTable = NULL;
300 AddUnicodeString2 (
301 "eng",
302 gPs2MouseSimulateTouchPadComponentName.SupportedLanguages,
303 &MouseSimulateTouchPadDev->ControllerNameTable,
304 L"Faked PS/2 Touchpad Device",
305 TRUE
306 );
307 AddUnicodeString2 (
308 "en",
309 gPs2MouseSimulateTouchPadComponentName2.SupportedLanguages,
310 &MouseSimulateTouchPadDev->ControllerNameTable,
311 L"Faked PS/2 Touchpad Device",
312 FALSE
313 );
314
315
316 //
317 // Install protocol interfaces for the mouse device.
318 //
319 Status = gBS->InstallMultipleProtocolInterfaces (
320 &Controller,
321 &gEfiAbsolutePointerProtocolGuid,
322 &MouseSimulateTouchPadDev->AbsolutePointerProtocol,
323 NULL
324 );
325 if (EFI_ERROR (Status)) {
326 goto ErrorExit;
327 }
328
329 gBS->RestoreTPL (OldTpl);
330
331 return Status;
332
333 ErrorExit:
334
335 KbcDisableAux (IsaIo);
336
337 if (StatusCode != 0) {
338 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
339 EFI_ERROR_CODE | EFI_ERROR_MINOR,
340 StatusCode,
341 ParentDevicePath
342 );
343 }
344
345 if ((MouseSimulateTouchPadDev != NULL) && (MouseSimulateTouchPadDev->AbsolutePointerProtocol.WaitForInput != NULL)) {
346 gBS->CloseEvent (MouseSimulateTouchPadDev->AbsolutePointerProtocol.WaitForInput);
347 }
348
349 if ((MouseSimulateTouchPadDev != NULL) && (MouseSimulateTouchPadDev->TimerEvent != NULL)) {
350 gBS->CloseEvent (MouseSimulateTouchPadDev->TimerEvent);
351 }
352
353 if ((MouseSimulateTouchPadDev != NULL) && (MouseSimulateTouchPadDev->ControllerNameTable != NULL)) {
354 FreeUnicodeStringTable (MouseSimulateTouchPadDev->ControllerNameTable);
355 }
356 //
357 // Since there will be no timer handler for mouse input any more,
358 // exhaust input data just in case there is still mouse data left
359 //
360 EmptyStatus = EFI_SUCCESS;
361 while (!EFI_ERROR (EmptyStatus)) {
362 EmptyStatus = In8042Data (IsaIo, &Data);
363 }
364
365 if (MouseSimulateTouchPadDev != NULL) {
366 gBS->FreePool (MouseSimulateTouchPadDev);
367 }
368
369 gBS->CloseProtocol (
370 Controller,
371 &gEfiDevicePathProtocolGuid,
372 This->DriverBindingHandle,
373 Controller
374 );
375
376 gBS->CloseProtocol (
377 Controller,
378 &gEfiIsaIoProtocolGuid,
379 This->DriverBindingHandle,
380 Controller
381 );
382
383 gBS->RestoreTPL (OldTpl);
384
385 return Status;
386 }
387
388 EFI_STATUS
389 EFIAPI
390 PS2MouseSimulateTouchPadDriverStop (
391 IN EFI_DRIVER_BINDING_PROTOCOL *This,
392 IN EFI_HANDLE Controller,
393 IN UINTN NumberOfChildren,
394 IN EFI_HANDLE *ChildHandleBuffer
395 )
396 /*++
397
398 Routine Description:
399
400 Arguments:
401
402 Returns:
403
404 --*/
405 // GC_TODO: This - add argument and description to function comment
406 // GC_TODO: Controller - add argument and description to function comment
407 // GC_TODO: NumberOfChildren - add argument and description to function comment
408 // GC_TODO: ChildHandleBuffer - add argument and description to function comment
409 // GC_TODO: EFI_SUCCESS - add return value to function comment
410 // GC_TODO: EFI_SUCCESS - add return value to function comment
411 {
412 EFI_STATUS Status;
413 EFI_ABSOLUTE_POINTER_PROTOCOL *AbsolutePointerProtocol;
414 PS2_MOUSE_SIMULATE_TOUCHPAD_DEV *MouseSimulateTouchPadDev;
415 UINT8 Data;
416
417 Status = gBS->OpenProtocol (
418 Controller,
419 &gEfiAbsolutePointerProtocolGuid,
420 (VOID **) &AbsolutePointerProtocol,
421 This->DriverBindingHandle,
422 Controller,
423 EFI_OPEN_PROTOCOL_GET_PROTOCOL
424 );
425 if (EFI_ERROR (Status)) {
426 return EFI_SUCCESS;
427 }
428
429 MouseSimulateTouchPadDev = PS2_MOUSE_SIMULATE_TOUCHPAD_DEV_FROM_THIS (AbsolutePointerProtocol);
430
431 //
432 // Report that the keyboard is being disabled
433 //
434 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
435 EFI_PROGRESS_CODE,
436 EFI_PERIPHERAL_MOUSE | EFI_P_PC_DISABLE,
437 MouseSimulateTouchPadDev->DevicePath
438 );
439
440 Status = gBS->UninstallProtocolInterface (
441 Controller,
442 &gEfiAbsolutePointerProtocolGuid,
443 &MouseSimulateTouchPadDev->AbsolutePointerProtocol
444 );
445 if (EFI_ERROR (Status)) {
446 return Status;
447 }
448 //
449 // Disable mouse on keyboard controller
450 //
451 KbcDisableAux (MouseSimulateTouchPadDev->IsaIo);
452
453 //
454 // Cancel mouse data polling timer, close timer event
455 //
456 gBS->SetTimer (MouseSimulateTouchPadDev->TimerEvent, TimerCancel, 0);
457 gBS->CloseEvent (MouseSimulateTouchPadDev->TimerEvent);
458
459 //
460 // Since there will be no timer handler for mouse input any more,
461 // exhaust input data just in case there is still mouse data left
462 //
463 Status = EFI_SUCCESS;
464 while (!EFI_ERROR (Status)) {
465 Status = In8042Data (MouseSimulateTouchPadDev->IsaIo, &Data);
466 }
467
468 gBS->CloseEvent (MouseSimulateTouchPadDev->AbsolutePointerProtocol.WaitForInput);
469 FreeUnicodeStringTable (MouseSimulateTouchPadDev->ControllerNameTable);
470 gBS->FreePool (MouseSimulateTouchPadDev);
471
472 gBS->CloseProtocol (
473 Controller,
474 &gEfiDevicePathProtocolGuid,
475 This->DriverBindingHandle,
476 Controller
477 );
478
479 gBS->CloseProtocol (
480 Controller,
481 &gEfiIsaIoProtocolGuid,
482 This->DriverBindingHandle,
483 Controller
484 );
485
486 return EFI_SUCCESS;
487 }
488
489 EFI_STATUS
490 EFIAPI
491 MouseSimulateTouchPadReset (
492 IN EFI_ABSOLUTE_POINTER_PROTOCOL *This,
493 IN BOOLEAN ExtendedVerification
494 )
495 /*++
496
497 Routine Description:
498
499 Reset the Mouse and do BAT test for it, if ExtendedVerification isTRUE and there is a mouse device connectted to system
500
501 Arguments:
502
503 This - Pointer of simple pointer Protocol.
504 ExtendedVerification - Whether configure mouse parameters. True: do; FALSE: skip.
505
506 Returns:
507
508 EFI_SUCCESS - The command byte is written successfully.
509 EFI_DEVICE_ERROR - Errors occurred during reseting keyboard.
510
511 --*/
512 {
513 EFI_STATUS Status;
514 PS2_MOUSE_SIMULATE_TOUCHPAD_DEV *MouseSimulateTouchPadDev;
515 EFI_TPL OldTpl;
516 BOOLEAN KeyboardEnable;
517 UINT8 Data;
518
519 MouseSimulateTouchPadDev = PS2_MOUSE_SIMULATE_TOUCHPAD_DEV_FROM_THIS (This);
520
521 //
522 // Report reset progress code
523 //
524 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
525 EFI_PROGRESS_CODE,
526 EFI_PERIPHERAL_MOUSE | EFI_P_PC_RESET,
527 MouseSimulateTouchPadDev->DevicePath
528 );
529
530 KeyboardEnable = FALSE;
531
532 //
533 // Raise TPL to avoid keyboard operation impact
534 //
535 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
536
537 ZeroMem (&MouseSimulateTouchPadDev->State, sizeof (EFI_ABSOLUTE_POINTER_STATE));
538 MouseSimulateTouchPadDev->StateChanged = FALSE;
539
540 //
541 // Exhaust input data
542 //
543 Status = EFI_SUCCESS;
544 while (!EFI_ERROR (Status)) {
545 Status = In8042Data (MouseSimulateTouchPadDev->IsaIo, &Data);
546 }
547
548 CheckKbStatus (MouseSimulateTouchPadDev->IsaIo, &KeyboardEnable);
549
550 KbcDisableKb (MouseSimulateTouchPadDev->IsaIo);
551
552 MouseSimulateTouchPadDev->IsaIo->Io.Read (MouseSimulateTouchPadDev->IsaIo, EfiIsaIoWidthUint8, KBC_CMD_STS_PORT, 1, &Data);
553
554 //
555 // if there's data block on KBC data port, read it out
556 //
557 if ((Data & KBC_OUTB) == KBC_OUTB) {
558 MouseSimulateTouchPadDev->IsaIo->Io.Read (MouseSimulateTouchPadDev->IsaIo, EfiIsaIoWidthUint8, KBC_DATA_PORT, 1, &Data);
559 }
560
561 Status = EFI_SUCCESS;
562 //
563 // The PS2 mouse driver reset behavior is always successfully return no matter wheater or not there is mouse connected to system.
564 // This behavior is needed by performance speed. The following mouse command only succeessfully finish when mouse device is
565 // connected to system, so if PS2 mouse device not connect to system or user not ask for, we skip the mouse configuration and enabling
566 //
567 if (ExtendedVerification && CheckMouseSimulateTouchPadConnect (MouseSimulateTouchPadDev)) {
568 //
569 // Send mouse reset command and set mouse default configure
570 //
571 Status = PS2MouseReset (MouseSimulateTouchPadDev->IsaIo);
572 if (EFI_ERROR (Status)) {
573 Status = EFI_DEVICE_ERROR;
574 goto Exit;
575 }
576
577 Status = PS2MouseSetSampleRate (MouseSimulateTouchPadDev->IsaIo, MouseSimulateTouchPadDev->SampleRate);
578 if (EFI_ERROR (Status)) {
579 Status = EFI_DEVICE_ERROR;
580 goto Exit;
581 }
582
583 Status = PS2MouseSetResolution (MouseSimulateTouchPadDev->IsaIo, MouseSimulateTouchPadDev->Resolution);
584 if (EFI_ERROR (Status)) {
585 Status = EFI_DEVICE_ERROR;
586 goto Exit;
587 }
588
589 Status = PS2MouseSetScaling (MouseSimulateTouchPadDev->IsaIo, MouseSimulateTouchPadDev->Scaling);
590 if (EFI_ERROR (Status)) {
591 Status = EFI_DEVICE_ERROR;
592 goto Exit;
593 }
594
595 Status = PS2MouseEnable (MouseSimulateTouchPadDev->IsaIo);
596 if (EFI_ERROR (Status)) {
597 Status = EFI_DEVICE_ERROR;
598 goto Exit;
599 }
600 }
601 Exit:
602 gBS->RestoreTPL (OldTpl);
603
604 if (KeyboardEnable) {
605 KbcEnableKb (MouseSimulateTouchPadDev->IsaIo);
606 }
607
608 return Status;
609 }
610
611 BOOLEAN
612 CheckMouseSimulateTouchPadConnect (
613 IN PS2_MOUSE_SIMULATE_TOUCHPAD_DEV *MouseSimulateTouchPadDev
614 )
615 /*++
616
617 Routine Description:
618
619 Check whether there is Ps/2 mouse device in system
620
621 Arguments:
622
623 PS2_MOUSE_DEV - Mouse Private Data Structure
624
625 Returns:
626
627 TRUE - Keyboard in System.
628 FALSE - Keyboard not in System.
629
630 --*/
631 {
632 EFI_STATUS Status;
633
634 Status = PS2MouseEnable (MouseSimulateTouchPadDev->IsaIo);
635 if (!EFI_ERROR (Status)) {
636 return TRUE;
637 }
638
639 return FALSE;
640 }
641
642 EFI_STATUS
643 EFIAPI
644 MouseSimulateTouchPadGetState (
645 IN EFI_ABSOLUTE_POINTER_PROTOCOL *This,
646 IN OUT EFI_ABSOLUTE_POINTER_STATE *State
647 )
648 /*++
649
650 Routine Description:
651
652 GC_TODO: Add function description
653
654 Arguments:
655
656 This - GC_TODO: add argument description
657 State - GC_TODO: add argument description
658
659 Returns:
660
661 EFI_INVALID_PARAMETER - GC_TODO: Add description for return value
662 EFI_NOT_READY - GC_TODO: Add description for return value
663 EFI_SUCCESS - GC_TODO: Add description for return value
664
665 --*/
666 {
667 PS2_MOUSE_SIMULATE_TOUCHPAD_DEV *MouseSimulateTouchPadDev;
668 EFI_TPL OldTpl;
669
670 MouseSimulateTouchPadDev = PS2_MOUSE_SIMULATE_TOUCHPAD_DEV_FROM_THIS (This);
671
672 if (State == NULL) {
673 return EFI_INVALID_PARAMETER;
674 }
675
676 if (!MouseSimulateTouchPadDev->StateChanged) {
677 return EFI_NOT_READY;
678 }
679
680 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
681 CopyMem (State, &(MouseSimulateTouchPadDev->State), sizeof (EFI_ABSOLUTE_POINTER_STATE));
682
683 //
684 // clear mouse state
685 //
686 MouseSimulateTouchPadDev->State.CurrentX = 0;
687 MouseSimulateTouchPadDev->State.CurrentY = 0;
688 MouseSimulateTouchPadDev->State.CurrentZ = 0;
689 MouseSimulateTouchPadDev->State.ActiveButtons = 0x0;
690 MouseSimulateTouchPadDev->StateChanged = FALSE;
691 gBS->RestoreTPL (OldTpl);
692
693 return EFI_SUCCESS;
694 }
695
696 VOID
697 EFIAPI
698 MouseSimulateTouchPadWaitForInput (
699 IN EFI_EVENT Event,
700 IN VOID *Context
701 )
702 /*++
703
704 Routine Description:
705
706 Event notification function for SIMPLE_POINTER.WaitForInput event
707 Signal the event if there is input from mouse
708
709 Arguments:
710
711 Returns:
712
713 --*/
714 // GC_TODO: Event - add argument and description to function comment
715 // GC_TODO: Context - add argument and description to function comment
716 {
717 PS2_MOUSE_SIMULATE_TOUCHPAD_DEV *MouseSimulateTouchPadDev;
718
719 MouseSimulateTouchPadDev = (PS2_MOUSE_SIMULATE_TOUCHPAD_DEV *) Context;
720
721 //
722 // Someone is waiting on the mouse event, if there's
723 // input from mouse, signal the event
724 //
725 if (MouseSimulateTouchPadDev->StateChanged) {
726 gBS->SignalEvent (Event);
727 }
728
729 }
730
731 VOID
732 EFIAPI
733 PollMouseSimulateTouchPad(
734 IN EFI_EVENT Event,
735 IN VOID *Context
736 )
737 /*++
738
739 Routine Description:
740
741 Event notification function for TimerEvent event
742 If mouse device is connected to system, try to get the mouse packet data
743
744 Arguments:
745
746 Event - TimerEvent in PS2_MOUSE_DEV
747 Context - Pointer to PS2_MOUSE_DEV structure
748
749 Returns:
750
751 None
752
753 --*/
754 {
755 PS2_MOUSE_SIMULATE_TOUCHPAD_DEV *MouseSimulateTouchPadDev;
756
757 MouseSimulateTouchPadDev = (PS2_MOUSE_SIMULATE_TOUCHPAD_DEV *) Context;
758
759 //
760 // Polling mouse packet data
761 //
762 PS2MouseGetPacket (MouseSimulateTouchPadDev);
763 }
764
765 /**
766 The user Entry Point for module Ps2MouseSimulateTouchPad. The user code starts with this function.
767
768 @param[in] ImageHandle The firmware allocated handle for the EFI image.
769 @param[in] SystemTable A pointer to the EFI System Table.
770
771 @retval EFI_SUCCESS The entry point is executed successfully.
772 @retval other Some error occurs when executing this entry point.
773
774 **/
775 EFI_STATUS
776 EFIAPI
777 InitializePs2MouseSimulateTouchPad(
778 IN EFI_HANDLE ImageHandle,
779 IN EFI_SYSTEM_TABLE *SystemTable
780 )
781 {
782 EFI_STATUS Status;
783
784 //
785 // Install driver model protocol(s).
786 //
787 Status = EfiLibInstallDriverBindingComponentName2 (
788 ImageHandle,
789 SystemTable,
790 &gPS2MouseSimulateTouchPadDriver,
791 ImageHandle,
792 &gPs2MouseSimulateTouchPadComponentName,
793 &gPs2MouseSimulateTouchPadComponentName2
794 );
795 ASSERT_EFI_ERROR (Status);
796
797
798 return Status;
799 }