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