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