]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Bus/Isa/Ps2MouseDxe/Ps2Mouse.c
Fix comparisons of enumerated types which may cause warnings for some compilers.
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Isa / Ps2MouseDxe / Ps2Mouse.c
CommitLineData
172870ef 1/** @file\r
f8cd287b 2 PS/2 Mouse driver. Routines that interacts with callers,\r
24a2dd3d 3 conforming to EFI driver model.\r
f8cd287b 4 \r
abfbafd5 5Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
180a5a35 6This program and the accompanying materials\r
92a428e1 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
24a2dd3d 19///\r
20/// DriverBinding Protocol Instance\r
21///\r
05fbd06d 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
24a2dd3d 112 Start this driver on ControllerHandle by opening a IsaIo protocol, creating \r
113 PS2_MOUSE_ABSOLUTE_POINTER_DEV device and install gEfiAbsolutePointerProtocolGuid\r
114 finally.\r
ff1fcef8 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
3ae99102 208 MouseDev->SampleRate = SampleRate20;\r
209 MouseDev->Resolution = MouseResolution4;\r
210 MouseDev->Scaling = Scaling1;\r
05fbd06d 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
007c18f5 231 //\r
232 // Fix for random hangs in System waiting for the Key if no KBC is present in BIOS.\r
233 //\r
234 if ((Data & (KBC_PARE | KBC_TIM)) == (KBC_PARE | KBC_TIM)) {\r
235 //\r
236 // If nobody decodes KBC I/O port, it will read back as 0xFF.\r
237 // Check the Time-Out and Parity bit to see if it has an active KBC in system\r
238 //\r
239 Status = EFI_DEVICE_ERROR;\r
240 StatusCode = EFI_PERIPHERAL_MOUSE | EFI_P_EC_NOT_DETECTED;\r
241 goto ErrorExit;\r
242 } \r
4bb5fd67 243\r
244 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
245 EFI_PROGRESS_CODE,\r
246 EFI_PERIPHERAL_MOUSE | EFI_P_MOUSE_PC_SELF_TEST,\r
247 ParentDevicePath\r
248 );\r
249\r
05fbd06d 250 if ((Data & KBC_SYSF) != KBC_SYSF) {\r
251 Status = KbcSelfTest (IsaIo);\r
252 if (EFI_ERROR (Status)) {\r
253 StatusCode = EFI_PERIPHERAL_MOUSE | EFI_P_EC_CONTROLLER_ERROR;\r
254 goto ErrorExit;\r
255 }\r
256 }\r
257\r
258 KbcEnableAux (IsaIo);\r
259\r
260 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
261 EFI_PROGRESS_CODE,\r
262 EFI_PERIPHERAL_MOUSE | EFI_P_PC_PRESENCE_DETECT,\r
263 ParentDevicePath\r
264 );\r
265\r
266 //\r
267 // Reset the mouse\r
268 //\r
ace74c67 269 Status = MouseDev->SimplePointerProtocol.Reset (\r
270 &MouseDev->SimplePointerProtocol,\r
271 FeaturePcdGet (PcdPs2MouseExtendedVerification)\r
272 );\r
05fbd06d 273 if (EFI_ERROR (Status)) {\r
274 //\r
275 // mouse not connected\r
276 //\r
277 Status = EFI_SUCCESS;\r
278 StatusCode = EFI_PERIPHERAL_MOUSE | EFI_P_EC_NOT_DETECTED;\r
279 goto ErrorExit;\r
280 }\r
281 //\r
282 // Setup the WaitForKey event\r
283 //\r
284 Status = gBS->CreateEvent (\r
285 EVT_NOTIFY_WAIT,\r
286 TPL_NOTIFY,\r
287 MouseWaitForInput,\r
288 MouseDev,\r
289 &((MouseDev->SimplePointerProtocol).WaitForInput)\r
290 );\r
291 if (EFI_ERROR (Status)) {\r
292 Status = EFI_OUT_OF_RESOURCES;\r
293 goto ErrorExit;\r
294 }\r
295 //\r
296 // Setup a periodic timer, used to poll mouse state\r
297 //\r
298 Status = gBS->CreateEvent (\r
299 EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
300 TPL_NOTIFY,\r
301 PollMouse,\r
302 MouseDev,\r
303 &MouseDev->TimerEvent\r
304 );\r
305 if (EFI_ERROR (Status)) {\r
306 Status = EFI_OUT_OF_RESOURCES;\r
307 goto ErrorExit;\r
308 }\r
309 //\r
310 // Start timer to poll mouse (100 samples per second)\r
311 //\r
312 Status = gBS->SetTimer (MouseDev->TimerEvent, TimerPeriodic, 100000);\r
313 if (EFI_ERROR (Status)) {\r
314 Status = EFI_OUT_OF_RESOURCES;\r
315 goto ErrorExit;\r
316 }\r
317\r
318 MouseDev->ControllerNameTable = NULL;\r
f3d08ccf 319 AddUnicodeString2 (\r
05fbd06d 320 "eng",\r
321 gPs2MouseComponentName.SupportedLanguages,\r
322 &MouseDev->ControllerNameTable,\r
f3d08ccf 323 L"PS/2 Mouse Device",\r
324 TRUE\r
05fbd06d 325 );\r
f3d08ccf 326 AddUnicodeString2 (\r
327 "en",\r
328 gPs2MouseComponentName2.SupportedLanguages,\r
329 &MouseDev->ControllerNameTable,\r
330 L"PS/2 Mouse Device",\r
331 FALSE\r
332 );\r
333\r
05fbd06d 334\r
335 //\r
336 // Install protocol interfaces for the mouse device.\r
337 //\r
338 Status = gBS->InstallMultipleProtocolInterfaces (\r
339 &Controller,\r
340 &gEfiSimplePointerProtocolGuid,\r
341 &MouseDev->SimplePointerProtocol,\r
342 NULL\r
343 );\r
344 if (EFI_ERROR (Status)) {\r
345 goto ErrorExit;\r
346 }\r
347\r
348 gBS->RestoreTPL (OldTpl);\r
349\r
350 return Status;\r
351\r
352ErrorExit:\r
353\r
007c18f5 354 if (Status != EFI_DEVICE_ERROR) {\r
355 KbcDisableAux (IsaIo);\r
356 }\r
05fbd06d 357\r
358 if (StatusCode != 0) {\r
359 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
360 EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
361 StatusCode,\r
362 ParentDevicePath\r
363 );\r
364 }\r
365\r
366 if ((MouseDev != NULL) && (MouseDev->SimplePointerProtocol.WaitForInput != NULL)) {\r
367 gBS->CloseEvent (MouseDev->SimplePointerProtocol.WaitForInput);\r
368 }\r
369\r
370 if ((MouseDev != NULL) && (MouseDev->TimerEvent != NULL)) {\r
371 gBS->CloseEvent (MouseDev->TimerEvent);\r
372 }\r
373\r
374 if ((MouseDev != NULL) && (MouseDev->ControllerNameTable != NULL)) {\r
375 FreeUnicodeStringTable (MouseDev->ControllerNameTable);\r
376 }\r
007c18f5 377 \r
378 if (Status != EFI_DEVICE_ERROR) {\r
379 //\r
380 // Since there will be no timer handler for mouse input any more,\r
381 // exhaust input data just in case there is still mouse data left\r
382 //\r
383 EmptyStatus = EFI_SUCCESS;\r
384 while (!EFI_ERROR (EmptyStatus)) {\r
385 EmptyStatus = In8042Data (IsaIo, &Data);\r
386 }\r
05fbd06d 387 }\r
388\r
389 if (MouseDev != NULL) {\r
24a2dd3d 390 FreePool (MouseDev);\r
05fbd06d 391 }\r
392\r
393 gBS->CloseProtocol (\r
394 Controller,\r
395 &gEfiDevicePathProtocolGuid,\r
396 This->DriverBindingHandle,\r
397 Controller\r
398 );\r
399\r
400 gBS->CloseProtocol (\r
401 Controller,\r
402 &gEfiIsaIoProtocolGuid,\r
403 This->DriverBindingHandle,\r
404 Controller\r
405 );\r
406\r
407 gBS->RestoreTPL (OldTpl);\r
408\r
409 return Status;\r
410}\r
411\r
ff1fcef8 412/**\r
413 Stop this driver on ControllerHandle. Support stoping any child handles\r
414 created by this driver.\r
415\r
416 @param This Protocol instance pointer.\r
417 @param ControllerHandle Handle of device to stop driver on\r
418 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r
419 children is zero stop the entire bus driver.\r
420 @param ChildHandleBuffer List of Child Handles to Stop.\r
421\r
422 @retval EFI_SUCCESS This driver is removed ControllerHandle\r
423 @retval other This driver was not removed from this device\r
424\r
425**/\r
05fbd06d 426EFI_STATUS\r
427EFIAPI\r
428PS2MouseDriverStop (\r
429 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
430 IN EFI_HANDLE Controller,\r
431 IN UINTN NumberOfChildren,\r
432 IN EFI_HANDLE *ChildHandleBuffer\r
433 )\r
05fbd06d 434{\r
435 EFI_STATUS Status;\r
436 EFI_SIMPLE_POINTER_PROTOCOL *SimplePointerProtocol;\r
437 PS2_MOUSE_DEV *MouseDev;\r
438 UINT8 Data;\r
439\r
440 Status = gBS->OpenProtocol (\r
441 Controller,\r
442 &gEfiSimplePointerProtocolGuid,\r
443 (VOID **) &SimplePointerProtocol,\r
444 This->DriverBindingHandle,\r
445 Controller,\r
446 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
447 );\r
448 if (EFI_ERROR (Status)) {\r
449 return EFI_SUCCESS;\r
450 }\r
451\r
452 MouseDev = PS2_MOUSE_DEV_FROM_THIS (SimplePointerProtocol);\r
453\r
454 //\r
455 // Report that the keyboard is being disabled\r
456 //\r
457 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
458 EFI_PROGRESS_CODE,\r
459 EFI_PERIPHERAL_MOUSE | EFI_P_PC_DISABLE,\r
460 MouseDev->DevicePath\r
461 );\r
462\r
463 Status = gBS->UninstallProtocolInterface (\r
464 Controller,\r
465 &gEfiSimplePointerProtocolGuid,\r
466 &MouseDev->SimplePointerProtocol\r
467 );\r
468 if (EFI_ERROR (Status)) {\r
469 return Status;\r
470 }\r
05fbd06d 471\r
472 //\r
473 // Cancel mouse data polling timer, close timer event\r
474 //\r
475 gBS->SetTimer (MouseDev->TimerEvent, TimerCancel, 0);\r
476 gBS->CloseEvent (MouseDev->TimerEvent);\r
477\r
478 //\r
479 // Since there will be no timer handler for mouse input any more,\r
480 // exhaust input data just in case there is still mouse data left\r
481 //\r
482 Status = EFI_SUCCESS;\r
483 while (!EFI_ERROR (Status)) {\r
484 Status = In8042Data (MouseDev->IsaIo, &Data);\r
485 }\r
486\r
487 gBS->CloseEvent (MouseDev->SimplePointerProtocol.WaitForInput);\r
488 FreeUnicodeStringTable (MouseDev->ControllerNameTable);\r
24a2dd3d 489 FreePool (MouseDev);\r
05fbd06d 490\r
491 gBS->CloseProtocol (\r
492 Controller,\r
493 &gEfiDevicePathProtocolGuid,\r
494 This->DriverBindingHandle,\r
495 Controller\r
496 );\r
497\r
498 gBS->CloseProtocol (\r
499 Controller,\r
500 &gEfiIsaIoProtocolGuid,\r
501 This->DriverBindingHandle,\r
502 Controller\r
503 );\r
504\r
505 return EFI_SUCCESS;\r
506}\r
507\r
bcd70414 508/**\r
05fbd06d 509 Reset the Mouse and do BAT test for it, if ExtendedVerification isTRUE and there is a mouse device connectted to system\r
510\r
ff1fcef8 511 @param This - Pointer of simple pointer Protocol.\r
512 @param ExtendedVerification - Whether configure mouse parameters. True: do; FALSE: skip.\r
05fbd06d 513\r
05fbd06d 514\r
ff1fcef8 515 @retval EFI_SUCCESS - The command byte is written successfully.\r
516 @retval EFI_DEVICE_ERROR - Errors occurred during reseting keyboard.\r
05fbd06d 517\r
bcd70414 518**/\r
ff1fcef8 519EFI_STATUS\r
520EFIAPI\r
521MouseReset (\r
522 IN EFI_SIMPLE_POINTER_PROTOCOL *This,\r
523 IN BOOLEAN ExtendedVerification\r
524 )\r
05fbd06d 525{\r
526 EFI_STATUS Status;\r
527 PS2_MOUSE_DEV *MouseDev;\r
528 EFI_TPL OldTpl;\r
529 BOOLEAN KeyboardEnable;\r
530 UINT8 Data;\r
531\r
532 MouseDev = PS2_MOUSE_DEV_FROM_THIS (This);\r
533\r
534 //\r
535 // Report reset progress code\r
536 //\r
537 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
538 EFI_PROGRESS_CODE,\r
539 EFI_PERIPHERAL_MOUSE | EFI_P_PC_RESET,\r
540 MouseDev->DevicePath\r
541 );\r
542\r
543 KeyboardEnable = FALSE;\r
544\r
545 //\r
546 // Raise TPL to avoid keyboard operation impact\r
547 //\r
548 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
549\r
550 ZeroMem (&MouseDev->State, sizeof (EFI_SIMPLE_POINTER_STATE));\r
551 MouseDev->StateChanged = FALSE;\r
552\r
553 //\r
554 // Exhaust input data\r
555 //\r
556 Status = EFI_SUCCESS;\r
557 while (!EFI_ERROR (Status)) {\r
558 Status = In8042Data (MouseDev->IsaIo, &Data);\r
559 }\r
560\r
561 CheckKbStatus (MouseDev->IsaIo, &KeyboardEnable);\r
562\r
563 KbcDisableKb (MouseDev->IsaIo);\r
564\r
565 MouseDev->IsaIo->Io.Read (MouseDev->IsaIo, EfiIsaIoWidthUint8, KBC_CMD_STS_PORT, 1, &Data);\r
566\r
567 //\r
568 // if there's data block on KBC data port, read it out\r
569 //\r
570 if ((Data & KBC_OUTB) == KBC_OUTB) {\r
571 MouseDev->IsaIo->Io.Read (MouseDev->IsaIo, EfiIsaIoWidthUint8, KBC_DATA_PORT, 1, &Data);\r
572 }\r
573\r
574 Status = EFI_SUCCESS;\r
575 //\r
576 // The PS2 mouse driver reset behavior is always successfully return no matter wheater or not there is mouse connected to system.\r
577 // This behavior is needed by performance speed. The following mouse command only succeessfully finish when mouse device is\r
578 // 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
579 //\r
580 if (ExtendedVerification && CheckMouseConnect (MouseDev)) {\r
581 //\r
582 // Send mouse reset command and set mouse default configure\r
583 //\r
584 Status = PS2MouseReset (MouseDev->IsaIo);\r
585 if (EFI_ERROR (Status)) {\r
586 Status = EFI_DEVICE_ERROR;\r
587 goto Exit;\r
588 }\r
589\r
590 Status = PS2MouseSetSampleRate (MouseDev->IsaIo, MouseDev->SampleRate);\r
591 if (EFI_ERROR (Status)) {\r
592 Status = EFI_DEVICE_ERROR;\r
593 goto Exit;\r
594 }\r
595\r
596 Status = PS2MouseSetResolution (MouseDev->IsaIo, MouseDev->Resolution);\r
597 if (EFI_ERROR (Status)) {\r
598 Status = EFI_DEVICE_ERROR;\r
599 goto Exit;\r
600 }\r
601\r
602 Status = PS2MouseSetScaling (MouseDev->IsaIo, MouseDev->Scaling);\r
603 if (EFI_ERROR (Status)) {\r
604 Status = EFI_DEVICE_ERROR;\r
605 goto Exit;\r
606 }\r
607\r
608 Status = PS2MouseEnable (MouseDev->IsaIo);\r
609 if (EFI_ERROR (Status)) {\r
610 Status = EFI_DEVICE_ERROR;\r
611 goto Exit;\r
612 }\r
613 }\r
614Exit:\r
615 gBS->RestoreTPL (OldTpl);\r
616\r
617 if (KeyboardEnable) {\r
618 KbcEnableKb (MouseDev->IsaIo);\r
619 }\r
620\r
621 return Status;\r
622}\r
623\r
bcd70414 624/**\r
05fbd06d 625 Check whether there is Ps/2 mouse device in system\r
626\r
172870ef 627 @param MouseDev - Mouse Private Data Structure\r
05fbd06d 628\r
172870ef 629 @retval TRUE - Keyboard in System.\r
630 @retval FALSE - Keyboard not in System.\r
05fbd06d 631\r
bcd70414 632**/\r
ff1fcef8 633BOOLEAN\r
634CheckMouseConnect (\r
635 IN PS2_MOUSE_DEV *MouseDev\r
636 )\r
637\r
05fbd06d 638{\r
639 EFI_STATUS Status;\r
640\r
641 Status = PS2MouseEnable (MouseDev->IsaIo);\r
642 if (!EFI_ERROR (Status)) {\r
643 return TRUE;\r
644 }\r
645\r
646 return FALSE;\r
647}\r
648\r
ff1fcef8 649/**\r
650 Get and Clear mouse status.\r
651 \r
652 @param This - Pointer of simple pointer Protocol.\r
653 @param State - Output buffer holding status.\r
654\r
655 @retval EFI_INVALID_PARAMETER Output buffer is invalid.\r
656 @retval EFI_NOT_READY Mouse is not changed status yet.\r
657 @retval EFI_SUCCESS Mouse status is changed and get successful.\r
658**/\r
05fbd06d 659EFI_STATUS\r
660EFIAPI\r
661MouseGetState (\r
662 IN EFI_SIMPLE_POINTER_PROTOCOL *This,\r
663 IN OUT EFI_SIMPLE_POINTER_STATE *State\r
664 )\r
05fbd06d 665{\r
666 PS2_MOUSE_DEV *MouseDev;\r
667 EFI_TPL OldTpl;\r
668\r
669 MouseDev = PS2_MOUSE_DEV_FROM_THIS (This);\r
670\r
671 if (State == NULL) {\r
672 return EFI_INVALID_PARAMETER;\r
673 }\r
674\r
675 if (!MouseDev->StateChanged) {\r
676 return EFI_NOT_READY;\r
677 }\r
678\r
679 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
680 CopyMem (State, &(MouseDev->State), sizeof (EFI_SIMPLE_POINTER_STATE));\r
681\r
682 //\r
683 // clear mouse state\r
684 //\r
685 MouseDev->State.RelativeMovementX = 0;\r
686 MouseDev->State.RelativeMovementY = 0;\r
687 MouseDev->State.RelativeMovementZ = 0;\r
688 MouseDev->StateChanged = FALSE;\r
689 gBS->RestoreTPL (OldTpl);\r
690\r
691 return EFI_SUCCESS;\r
692}\r
693\r
bcd70414 694/**\r
05fbd06d 695\r
172870ef 696 Event notification function for SIMPLE_POINTER.WaitForInput event.\r
697 Signal the event if there is input from mouse.\r
05fbd06d 698\r
ff1fcef8 699 @param Event event object\r
700 @param Context event context\r
05fbd06d 701\r
bcd70414 702**/\r
ff1fcef8 703VOID\r
704EFIAPI\r
705MouseWaitForInput (\r
706 IN EFI_EVENT Event,\r
707 IN VOID *Context\r
708 )\r
05fbd06d 709{\r
710 PS2_MOUSE_DEV *MouseDev;\r
711\r
712 MouseDev = (PS2_MOUSE_DEV *) Context;\r
713\r
714 //\r
715 // Someone is waiting on the mouse event, if there's\r
716 // input from mouse, signal the event\r
717 //\r
718 if (MouseDev->StateChanged) {\r
719 gBS->SignalEvent (Event);\r
720 }\r
721\r
722}\r
723\r
ff1fcef8 724/**\r
18a73eb7 725 Event notification function for TimerEvent event.\r
726 If mouse device is connected to system, try to get the mouse packet data.\r
ff1fcef8 727\r
728 @param Event - TimerEvent in PS2_MOUSE_DEV\r
729 @param Context - Pointer to PS2_MOUSE_DEV structure\r
730\r
731**/\r
05fbd06d 732VOID\r
733EFIAPI\r
734PollMouse (\r
735 IN EFI_EVENT Event,\r
736 IN VOID *Context\r
737 )\r
05fbd06d 738\r
05fbd06d 739{\r
740 PS2_MOUSE_DEV *MouseDev;\r
741\r
742 MouseDev = (PS2_MOUSE_DEV *) Context;\r
743\r
744 //\r
745 // Polling mouse packet data\r
746 //\r
747 PS2MouseGetPacket (MouseDev);\r
748}\r
c21fc3e8 749\r
750/**\r
751 The user Entry Point for module Ps2Mouse. The user code starts with this function.\r
752\r
753 @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
754 @param[in] SystemTable A pointer to the EFI System Table.\r
755 \r
756 @retval EFI_SUCCESS The entry point is executed successfully.\r
757 @retval other Some error occurs when executing this entry point.\r
758\r
759**/\r
760EFI_STATUS\r
761EFIAPI\r
762InitializePs2Mouse(\r
763 IN EFI_HANDLE ImageHandle,\r
764 IN EFI_SYSTEM_TABLE *SystemTable\r
765 )\r
766{\r
767 EFI_STATUS Status;\r
768\r
769 //\r
770 // Install driver model protocol(s).\r
771 //\r
f3d08ccf 772 Status = EfiLibInstallDriverBindingComponentName2 (\r
c21fc3e8 773 ImageHandle,\r
774 SystemTable,\r
775 &gPS2MouseDriver,\r
776 ImageHandle,\r
777 &gPs2MouseComponentName,\r
f3d08ccf 778 &gPs2MouseComponentName2\r
c21fc3e8 779 );\r
780 ASSERT_EFI_ERROR (Status);\r
781\r
782\r
783 return Status;\r
784}\r
ff1fcef8 785\r