]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Bus/Isa/Ps2MouseDxe/Ps2Mouse.c
Replace references to RFC 3066 with RFC 4646.
[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
ff1fcef8 31/**\r
32 Test to see if this driver supports ControllerHandle. Any ControllerHandle\r
33 than contains a IsaIo protocol can be supported.\r
34\r
35 @param This Protocol instance pointer.\r
36 @param ControllerHandle Handle of device to test\r
37 @param RemainingDevicePath Optional parameter use to pick a specific child\r
38 device to start.\r
39\r
40 @retval EFI_SUCCESS This driver supports this device\r
41 @retval EFI_ALREADY_STARTED This driver is already running on this device\r
42 @retval other This driver does not support this device\r
43\r
44**/\r
05fbd06d 45EFI_STATUS\r
46EFIAPI\r
47PS2MouseDriverSupported (\r
48 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
49 IN EFI_HANDLE Controller,\r
50 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
51 )\r
05fbd06d 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
ff1fcef8 111/**\r
112 Start this driver on ControllerHandle by opening a IsaIo\r
113 protocol, creating PS2_MOUSE_ABSOLUTE_POINTER_DEV device and install gEfiAbsolutePointerProtocolGuid\r
114 finnally.\r
115\r
116 @param This Protocol instance pointer.\r
117 @param ControllerHandle Handle of device to bind driver to\r
118 @param RemainingDevicePath Optional parameter use to pick a specific child\r
119 device to start.\r
120\r
121 @retval EFI_SUCCESS This driver is added to ControllerHandle\r
122 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle\r
123 @retval other This driver does not support this device\r
124\r
125**/\r
05fbd06d 126EFI_STATUS\r
127EFIAPI\r
128PS2MouseDriverStart (\r
129 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
130 IN EFI_HANDLE Controller,\r
131 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
132 )\r
05fbd06d 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
f3d08ccf 297 AddUnicodeString2 (\r
05fbd06d 298 "eng",\r
299 gPs2MouseComponentName.SupportedLanguages,\r
300 &MouseDev->ControllerNameTable,\r
f3d08ccf 301 L"PS/2 Mouse Device",\r
302 TRUE\r
05fbd06d 303 );\r
f3d08ccf 304 AddUnicodeString2 (\r
305 "en",\r
306 gPs2MouseComponentName2.SupportedLanguages,\r
307 &MouseDev->ControllerNameTable,\r
308 L"PS/2 Mouse Device",\r
309 FALSE\r
310 );\r
311\r
05fbd06d 312\r
313 //\r
314 // Install protocol interfaces for the mouse device.\r
315 //\r
316 Status = gBS->InstallMultipleProtocolInterfaces (\r
317 &Controller,\r
318 &gEfiSimplePointerProtocolGuid,\r
319 &MouseDev->SimplePointerProtocol,\r
320 NULL\r
321 );\r
322 if (EFI_ERROR (Status)) {\r
323 goto ErrorExit;\r
324 }\r
325\r
326 gBS->RestoreTPL (OldTpl);\r
327\r
328 return Status;\r
329\r
330ErrorExit:\r
331\r
332 KbcDisableAux (IsaIo);\r
333\r
334 if (StatusCode != 0) {\r
335 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
336 EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
337 StatusCode,\r
338 ParentDevicePath\r
339 );\r
340 }\r
341\r
342 if ((MouseDev != NULL) && (MouseDev->SimplePointerProtocol.WaitForInput != NULL)) {\r
343 gBS->CloseEvent (MouseDev->SimplePointerProtocol.WaitForInput);\r
344 }\r
345\r
346 if ((MouseDev != NULL) && (MouseDev->TimerEvent != NULL)) {\r
347 gBS->CloseEvent (MouseDev->TimerEvent);\r
348 }\r
349\r
350 if ((MouseDev != NULL) && (MouseDev->ControllerNameTable != NULL)) {\r
351 FreeUnicodeStringTable (MouseDev->ControllerNameTable);\r
352 }\r
353 //\r
354 // Since there will be no timer handler for mouse input any more,\r
355 // exhaust input data just in case there is still mouse data left\r
356 //\r
357 EmptyStatus = EFI_SUCCESS;\r
358 while (!EFI_ERROR (EmptyStatus)) {\r
359 EmptyStatus = In8042Data (IsaIo, &Data);\r
360 }\r
361\r
362 if (MouseDev != NULL) {\r
363 gBS->FreePool (MouseDev);\r
364 }\r
365\r
366 gBS->CloseProtocol (\r
367 Controller,\r
368 &gEfiDevicePathProtocolGuid,\r
369 This->DriverBindingHandle,\r
370 Controller\r
371 );\r
372\r
373 gBS->CloseProtocol (\r
374 Controller,\r
375 &gEfiIsaIoProtocolGuid,\r
376 This->DriverBindingHandle,\r
377 Controller\r
378 );\r
379\r
380 gBS->RestoreTPL (OldTpl);\r
381\r
382 return Status;\r
383}\r
384\r
ff1fcef8 385/**\r
386 Stop this driver on ControllerHandle. Support stoping any child handles\r
387 created by this driver.\r
388\r
389 @param This Protocol instance pointer.\r
390 @param ControllerHandle Handle of device to stop driver on\r
391 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r
392 children is zero stop the entire bus driver.\r
393 @param ChildHandleBuffer List of Child Handles to Stop.\r
394\r
395 @retval EFI_SUCCESS This driver is removed ControllerHandle\r
396 @retval other This driver was not removed from this device\r
397\r
398**/\r
05fbd06d 399EFI_STATUS\r
400EFIAPI\r
401PS2MouseDriverStop (\r
402 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
403 IN EFI_HANDLE Controller,\r
404 IN UINTN NumberOfChildren,\r
405 IN EFI_HANDLE *ChildHandleBuffer\r
406 )\r
05fbd06d 407{\r
408 EFI_STATUS Status;\r
409 EFI_SIMPLE_POINTER_PROTOCOL *SimplePointerProtocol;\r
410 PS2_MOUSE_DEV *MouseDev;\r
411 UINT8 Data;\r
412\r
413 Status = gBS->OpenProtocol (\r
414 Controller,\r
415 &gEfiSimplePointerProtocolGuid,\r
416 (VOID **) &SimplePointerProtocol,\r
417 This->DriverBindingHandle,\r
418 Controller,\r
419 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
420 );\r
421 if (EFI_ERROR (Status)) {\r
422 return EFI_SUCCESS;\r
423 }\r
424\r
425 MouseDev = PS2_MOUSE_DEV_FROM_THIS (SimplePointerProtocol);\r
426\r
427 //\r
428 // Report that the keyboard is being disabled\r
429 //\r
430 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
431 EFI_PROGRESS_CODE,\r
432 EFI_PERIPHERAL_MOUSE | EFI_P_PC_DISABLE,\r
433 MouseDev->DevicePath\r
434 );\r
435\r
436 Status = gBS->UninstallProtocolInterface (\r
437 Controller,\r
438 &gEfiSimplePointerProtocolGuid,\r
439 &MouseDev->SimplePointerProtocol\r
440 );\r
441 if (EFI_ERROR (Status)) {\r
442 return Status;\r
443 }\r
444 //\r
445 // Disable mouse on keyboard controller\r
446 //\r
447 KbcDisableAux (MouseDev->IsaIo);\r
448\r
449 //\r
450 // Cancel mouse data polling timer, close timer event\r
451 //\r
452 gBS->SetTimer (MouseDev->TimerEvent, TimerCancel, 0);\r
453 gBS->CloseEvent (MouseDev->TimerEvent);\r
454\r
455 //\r
456 // Since there will be no timer handler for mouse input any more,\r
457 // exhaust input data just in case there is still mouse data left\r
458 //\r
459 Status = EFI_SUCCESS;\r
460 while (!EFI_ERROR (Status)) {\r
461 Status = In8042Data (MouseDev->IsaIo, &Data);\r
462 }\r
463\r
464 gBS->CloseEvent (MouseDev->SimplePointerProtocol.WaitForInput);\r
465 FreeUnicodeStringTable (MouseDev->ControllerNameTable);\r
466 gBS->FreePool (MouseDev);\r
467\r
468 gBS->CloseProtocol (\r
469 Controller,\r
470 &gEfiDevicePathProtocolGuid,\r
471 This->DriverBindingHandle,\r
472 Controller\r
473 );\r
474\r
475 gBS->CloseProtocol (\r
476 Controller,\r
477 &gEfiIsaIoProtocolGuid,\r
478 This->DriverBindingHandle,\r
479 Controller\r
480 );\r
481\r
482 return EFI_SUCCESS;\r
483}\r
484\r
bcd70414 485/**\r
05fbd06d 486 Reset the Mouse and do BAT test for it, if ExtendedVerification isTRUE and there is a mouse device connectted to system\r
487\r
ff1fcef8 488 @param This - Pointer of simple pointer Protocol.\r
489 @param ExtendedVerification - Whether configure mouse parameters. True: do; FALSE: skip.\r
05fbd06d 490\r
05fbd06d 491\r
ff1fcef8 492 @retval EFI_SUCCESS - The command byte is written successfully.\r
493 @retval EFI_DEVICE_ERROR - Errors occurred during reseting keyboard.\r
05fbd06d 494\r
bcd70414 495**/\r
ff1fcef8 496EFI_STATUS\r
497EFIAPI\r
498MouseReset (\r
499 IN EFI_SIMPLE_POINTER_PROTOCOL *This,\r
500 IN BOOLEAN ExtendedVerification\r
501 )\r
05fbd06d 502{\r
503 EFI_STATUS Status;\r
504 PS2_MOUSE_DEV *MouseDev;\r
505 EFI_TPL OldTpl;\r
506 BOOLEAN KeyboardEnable;\r
507 UINT8 Data;\r
508\r
509 MouseDev = PS2_MOUSE_DEV_FROM_THIS (This);\r
510\r
511 //\r
512 // Report reset progress code\r
513 //\r
514 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
515 EFI_PROGRESS_CODE,\r
516 EFI_PERIPHERAL_MOUSE | EFI_P_PC_RESET,\r
517 MouseDev->DevicePath\r
518 );\r
519\r
520 KeyboardEnable = FALSE;\r
521\r
522 //\r
523 // Raise TPL to avoid keyboard operation impact\r
524 //\r
525 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
526\r
527 ZeroMem (&MouseDev->State, sizeof (EFI_SIMPLE_POINTER_STATE));\r
528 MouseDev->StateChanged = FALSE;\r
529\r
530 //\r
531 // Exhaust input data\r
532 //\r
533 Status = EFI_SUCCESS;\r
534 while (!EFI_ERROR (Status)) {\r
535 Status = In8042Data (MouseDev->IsaIo, &Data);\r
536 }\r
537\r
538 CheckKbStatus (MouseDev->IsaIo, &KeyboardEnable);\r
539\r
540 KbcDisableKb (MouseDev->IsaIo);\r
541\r
542 MouseDev->IsaIo->Io.Read (MouseDev->IsaIo, EfiIsaIoWidthUint8, KBC_CMD_STS_PORT, 1, &Data);\r
543\r
544 //\r
545 // if there's data block on KBC data port, read it out\r
546 //\r
547 if ((Data & KBC_OUTB) == KBC_OUTB) {\r
548 MouseDev->IsaIo->Io.Read (MouseDev->IsaIo, EfiIsaIoWidthUint8, KBC_DATA_PORT, 1, &Data);\r
549 }\r
550\r
551 Status = EFI_SUCCESS;\r
552 //\r
553 // The PS2 mouse driver reset behavior is always successfully return no matter wheater or not there is mouse connected to system.\r
554 // This behavior is needed by performance speed. The following mouse command only succeessfully finish when mouse device is\r
555 // 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
556 //\r
557 if (ExtendedVerification && CheckMouseConnect (MouseDev)) {\r
558 //\r
559 // Send mouse reset command and set mouse default configure\r
560 //\r
561 Status = PS2MouseReset (MouseDev->IsaIo);\r
562 if (EFI_ERROR (Status)) {\r
563 Status = EFI_DEVICE_ERROR;\r
564 goto Exit;\r
565 }\r
566\r
567 Status = PS2MouseSetSampleRate (MouseDev->IsaIo, MouseDev->SampleRate);\r
568 if (EFI_ERROR (Status)) {\r
569 Status = EFI_DEVICE_ERROR;\r
570 goto Exit;\r
571 }\r
572\r
573 Status = PS2MouseSetResolution (MouseDev->IsaIo, MouseDev->Resolution);\r
574 if (EFI_ERROR (Status)) {\r
575 Status = EFI_DEVICE_ERROR;\r
576 goto Exit;\r
577 }\r
578\r
579 Status = PS2MouseSetScaling (MouseDev->IsaIo, MouseDev->Scaling);\r
580 if (EFI_ERROR (Status)) {\r
581 Status = EFI_DEVICE_ERROR;\r
582 goto Exit;\r
583 }\r
584\r
585 Status = PS2MouseEnable (MouseDev->IsaIo);\r
586 if (EFI_ERROR (Status)) {\r
587 Status = EFI_DEVICE_ERROR;\r
588 goto Exit;\r
589 }\r
590 }\r
591Exit:\r
592 gBS->RestoreTPL (OldTpl);\r
593\r
594 if (KeyboardEnable) {\r
595 KbcEnableKb (MouseDev->IsaIo);\r
596 }\r
597\r
598 return Status;\r
599}\r
600\r
bcd70414 601/**\r
05fbd06d 602 Check whether there is Ps/2 mouse device in system\r
603\r
ff1fcef8 604 @param PS2_MOUSE_DEV - Mouse Private Data Structure\r
05fbd06d 605\r
ff1fcef8 606 @retval TRUE - Keyboard in System.\r
607 @retval FALSE - Keyboard not in System.\r
05fbd06d 608\r
bcd70414 609**/\r
ff1fcef8 610BOOLEAN\r
611CheckMouseConnect (\r
612 IN PS2_MOUSE_DEV *MouseDev\r
613 )\r
614\r
05fbd06d 615{\r
616 EFI_STATUS Status;\r
617\r
618 Status = PS2MouseEnable (MouseDev->IsaIo);\r
619 if (!EFI_ERROR (Status)) {\r
620 return TRUE;\r
621 }\r
622\r
623 return FALSE;\r
624}\r
625\r
ff1fcef8 626/**\r
627 Get and Clear mouse status.\r
628 \r
629 @param This - Pointer of simple pointer Protocol.\r
630 @param State - Output buffer holding status.\r
631\r
632 @retval EFI_INVALID_PARAMETER Output buffer is invalid.\r
633 @retval EFI_NOT_READY Mouse is not changed status yet.\r
634 @retval EFI_SUCCESS Mouse status is changed and get successful.\r
635**/\r
05fbd06d 636EFI_STATUS\r
637EFIAPI\r
638MouseGetState (\r
639 IN EFI_SIMPLE_POINTER_PROTOCOL *This,\r
640 IN OUT EFI_SIMPLE_POINTER_STATE *State\r
641 )\r
05fbd06d 642{\r
643 PS2_MOUSE_DEV *MouseDev;\r
644 EFI_TPL OldTpl;\r
645\r
646 MouseDev = PS2_MOUSE_DEV_FROM_THIS (This);\r
647\r
648 if (State == NULL) {\r
649 return EFI_INVALID_PARAMETER;\r
650 }\r
651\r
652 if (!MouseDev->StateChanged) {\r
653 return EFI_NOT_READY;\r
654 }\r
655\r
656 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
657 CopyMem (State, &(MouseDev->State), sizeof (EFI_SIMPLE_POINTER_STATE));\r
658\r
659 //\r
660 // clear mouse state\r
661 //\r
662 MouseDev->State.RelativeMovementX = 0;\r
663 MouseDev->State.RelativeMovementY = 0;\r
664 MouseDev->State.RelativeMovementZ = 0;\r
665 MouseDev->StateChanged = FALSE;\r
666 gBS->RestoreTPL (OldTpl);\r
667\r
668 return EFI_SUCCESS;\r
669}\r
670\r
bcd70414 671/**\r
05fbd06d 672\r
05fbd06d 673 Event notification function for SIMPLE_POINTER.WaitForInput event\r
674 Signal the event if there is input from mouse\r
675\r
ff1fcef8 676 @param Event event object\r
677 @param Context event context\r
05fbd06d 678\r
bcd70414 679**/\r
ff1fcef8 680\r
681VOID\r
682EFIAPI\r
683MouseWaitForInput (\r
684 IN EFI_EVENT Event,\r
685 IN VOID *Context\r
686 )\r
05fbd06d 687// GC_TODO: Event - add argument and description to function comment\r
688// GC_TODO: Context - add argument and description to function comment\r
689{\r
690 PS2_MOUSE_DEV *MouseDev;\r
691\r
692 MouseDev = (PS2_MOUSE_DEV *) Context;\r
693\r
694 //\r
695 // Someone is waiting on the mouse event, if there's\r
696 // input from mouse, signal the event\r
697 //\r
698 if (MouseDev->StateChanged) {\r
699 gBS->SignalEvent (Event);\r
700 }\r
701\r
702}\r
703\r
ff1fcef8 704/**\r
705 Event notification function for TimerEvent event\r
706 If mouse device is connected to system, try to get the mouse packet data\r
707\r
708 @param Event - TimerEvent in PS2_MOUSE_DEV\r
709 @param Context - Pointer to PS2_MOUSE_DEV structure\r
710\r
711**/\r
05fbd06d 712VOID\r
713EFIAPI\r
714PollMouse (\r
715 IN EFI_EVENT Event,\r
716 IN VOID *Context\r
717 )\r
05fbd06d 718\r
05fbd06d 719{\r
720 PS2_MOUSE_DEV *MouseDev;\r
721\r
722 MouseDev = (PS2_MOUSE_DEV *) Context;\r
723\r
724 //\r
725 // Polling mouse packet data\r
726 //\r
727 PS2MouseGetPacket (MouseDev);\r
728}\r
c21fc3e8 729\r
730/**\r
731 The user Entry Point for module Ps2Mouse. The user code starts with this function.\r
732\r
733 @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
734 @param[in] SystemTable A pointer to the EFI System Table.\r
735 \r
736 @retval EFI_SUCCESS The entry point is executed successfully.\r
737 @retval other Some error occurs when executing this entry point.\r
738\r
739**/\r
740EFI_STATUS\r
741EFIAPI\r
742InitializePs2Mouse(\r
743 IN EFI_HANDLE ImageHandle,\r
744 IN EFI_SYSTEM_TABLE *SystemTable\r
745 )\r
746{\r
747 EFI_STATUS Status;\r
748\r
749 //\r
750 // Install driver model protocol(s).\r
751 //\r
f3d08ccf 752 Status = EfiLibInstallDriverBindingComponentName2 (\r
c21fc3e8 753 ImageHandle,\r
754 SystemTable,\r
755 &gPS2MouseDriver,\r
756 ImageHandle,\r
757 &gPs2MouseComponentName,\r
f3d08ccf 758 &gPs2MouseComponentName2\r
c21fc3e8 759 );\r
760 ASSERT_EFI_ERROR (Status);\r
761\r
762\r
763 return Status;\r
764}\r
ff1fcef8 765\r