]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - IntelFrameworkModulePkg/Bus/Isa/Ps2MouseSimulateTouchPadDxe/Ps2MouseAbsolutePointer.c
change "Ps2MouseSimulateTouchPad" to "Ps2MouseAbsolutePointer" for more clearing...
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Isa / Ps2MouseSimulateTouchPadDxe / Ps2MouseAbsolutePointer.c
... / ...
CommitLineData
1/**@file\r
2 A faked PS/2 Touchpad driver. Routines that interacts with callers,\r
3 conforming to EFI driver model\r
4 \r
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
13\r
14**/\r
15\r
16#include "Ps2MouseAbsolutePointer.h"\r
17#include "CommPs2.h"\r
18\r
19//\r
20// DriverBinding Protocol Instance\r
21//\r
22EFI_DRIVER_BINDING_PROTOCOL gPS2MouseAbsolutePointerDriver = {\r
23 PS2MouseAbsolutePointerDriverSupported,\r
24 PS2MouseAbsolutePointerDriverStart,\r
25 PS2MouseAbsolutePointerDriverStop,\r
26 0x1,\r
27 NULL,\r
28 NULL\r
29};\r
30\r
31EFI_STATUS\r
32EFIAPI\r
33PS2MouseAbsolutePointerDriverSupported (\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 Mouse 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
113PS2MouseAbsolutePointerDriverStart (\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_ABSOLUTE_POINTER_DEV *MouseAbsolutePointerDev;\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 MouseAbsolutePointerDev = 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 MouseAbsolutePointerDev = AllocateZeroPool (sizeof (PS2_MOUSE_ABSOLUTE_POINTER_DEV));\r
199 if (MouseAbsolutePointerDev == 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 MouseAbsolutePointerDev->Signature = PS2_MOUSE_ABSOLUTE_POINTER_DEV_SIGNATURE;\r
207 MouseAbsolutePointerDev->Handle = Controller;\r
208 MouseAbsolutePointerDev->SampleRate = SSR_20;\r
209 MouseAbsolutePointerDev->Resolution = CMR4;\r
210 MouseAbsolutePointerDev->Scaling = SF1;\r
211 MouseAbsolutePointerDev->DataPackageSize = 3;\r
212 MouseAbsolutePointerDev->IsaIo = IsaIo;\r
213 MouseAbsolutePointerDev->DevicePath = ParentDevicePath;\r
214\r
215 //\r
216 // Resolution = 4 counts/mm\r
217 //\r
218 MouseAbsolutePointerDev->Mode.AbsoluteMaxX = 1024;\r
219 MouseAbsolutePointerDev->Mode.AbsoluteMinX = 0;\r
220 MouseAbsolutePointerDev->Mode.AbsoluteMaxY = 798;\r
221 MouseAbsolutePointerDev->Mode.AbsoluteMinY = 0;\r
222 MouseAbsolutePointerDev->Mode.AbsoluteMaxZ = 0;\r
223 MouseAbsolutePointerDev->Mode.AbsoluteMinZ = 0;\r
224 MouseAbsolutePointerDev->Mode.Attributes = 0x03;\r
225\r
226 MouseAbsolutePointerDev->AbsolutePointerProtocol.Reset = MouseAbsolutePointerReset;\r
227 MouseAbsolutePointerDev->AbsolutePointerProtocol.GetState = MouseAbsolutePointerGetState;\r
228 MouseAbsolutePointerDev->AbsolutePointerProtocol.Mode = &(MouseAbsolutePointerDev->Mode);\r
229\r
230 //\r
231 // Initialize keyboard controller if necessary\r
232 //\r
233 IsaIo->Io.Read (IsaIo, EfiIsaIoWidthUint8, KBC_CMD_STS_PORT, 1, &Data);\r
234 if ((Data & KBC_SYSF) != KBC_SYSF) {\r
235 Status = KbcSelfTest (IsaIo);\r
236 if (EFI_ERROR (Status)) {\r
237 StatusCode = EFI_PERIPHERAL_MOUSE | EFI_P_EC_CONTROLLER_ERROR;\r
238 goto ErrorExit;\r
239 }\r
240 }\r
241\r
242 KbcEnableAux (IsaIo);\r
243\r
244 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
245 EFI_PROGRESS_CODE,\r
246 EFI_PERIPHERAL_MOUSE | EFI_P_PC_PRESENCE_DETECT,\r
247 ParentDevicePath\r
248 );\r
249\r
250 //\r
251 // Reset the mouse\r
252 //\r
253 Status = MouseAbsolutePointerDev->AbsolutePointerProtocol.Reset (&MouseAbsolutePointerDev->AbsolutePointerProtocol, TRUE);\r
254 if (EFI_ERROR (Status)) {\r
255 //\r
256 // mouse not connected\r
257 //\r
258 Status = EFI_SUCCESS;\r
259 StatusCode = EFI_PERIPHERAL_MOUSE | EFI_P_EC_NOT_DETECTED;\r
260 goto ErrorExit;\r
261 }\r
262 //\r
263 // Setup the WaitForKey event\r
264 //\r
265 Status = gBS->CreateEvent (\r
266 EVT_NOTIFY_WAIT,\r
267 TPL_NOTIFY,\r
268 MouseAbsolutePointerWaitForInput,\r
269 MouseAbsolutePointerDev,\r
270 &((MouseAbsolutePointerDev->AbsolutePointerProtocol).WaitForInput)\r
271 );\r
272 if (EFI_ERROR (Status)) {\r
273 Status = EFI_OUT_OF_RESOURCES;\r
274 goto ErrorExit;\r
275 }\r
276 //\r
277 // Setup a periodic timer, used to poll mouse state\r
278 //\r
279 Status = gBS->CreateEvent (\r
280 EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
281 TPL_NOTIFY,\r
282 PollMouseAbsolutePointer,\r
283 MouseAbsolutePointerDev,\r
284 &MouseAbsolutePointerDev->TimerEvent\r
285 );\r
286 if (EFI_ERROR (Status)) {\r
287 Status = EFI_OUT_OF_RESOURCES;\r
288 goto ErrorExit;\r
289 }\r
290 //\r
291 // Start timer to poll mouse (100 samples per second)\r
292 //\r
293 Status = gBS->SetTimer (MouseAbsolutePointerDev->TimerEvent, TimerPeriodic, 100000);\r
294 if (EFI_ERROR (Status)) {\r
295 Status = EFI_OUT_OF_RESOURCES;\r
296 goto ErrorExit;\r
297 }\r
298\r
299 MouseAbsolutePointerDev->ControllerNameTable = NULL;\r
300 AddUnicodeString2 (\r
301 "eng",\r
302 gPs2MouseAbsolutePointerComponentName.SupportedLanguages,\r
303 &MouseAbsolutePointerDev->ControllerNameTable,\r
304 L"Faked PS/2 Touchpad Device",\r
305 TRUE\r
306 );\r
307 AddUnicodeString2 (\r
308 "en",\r
309 gPs2MouseAbsolutePointerComponentName2.SupportedLanguages,\r
310 &MouseAbsolutePointerDev->ControllerNameTable,\r
311 L"Faked PS/2 Touchpad Device",\r
312 FALSE\r
313 );\r
314\r
315\r
316 //\r
317 // Install protocol interfaces for the mouse device.\r
318 //\r
319 Status = gBS->InstallMultipleProtocolInterfaces (\r
320 &Controller,\r
321 &gEfiAbsolutePointerProtocolGuid,\r
322 &MouseAbsolutePointerDev->AbsolutePointerProtocol,\r
323 NULL\r
324 );\r
325 if (EFI_ERROR (Status)) {\r
326 goto ErrorExit;\r
327 }\r
328\r
329 gBS->RestoreTPL (OldTpl);\r
330\r
331 return Status;\r
332\r
333ErrorExit:\r
334\r
335 KbcDisableAux (IsaIo);\r
336\r
337 if (StatusCode != 0) {\r
338 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
339 EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
340 StatusCode,\r
341 ParentDevicePath\r
342 );\r
343 }\r
344\r
345 if ((MouseAbsolutePointerDev != NULL) && (MouseAbsolutePointerDev->AbsolutePointerProtocol.WaitForInput != NULL)) {\r
346 gBS->CloseEvent (MouseAbsolutePointerDev->AbsolutePointerProtocol.WaitForInput);\r
347 }\r
348\r
349 if ((MouseAbsolutePointerDev != NULL) && (MouseAbsolutePointerDev->TimerEvent != NULL)) {\r
350 gBS->CloseEvent (MouseAbsolutePointerDev->TimerEvent);\r
351 }\r
352\r
353 if ((MouseAbsolutePointerDev != NULL) && (MouseAbsolutePointerDev->ControllerNameTable != NULL)) {\r
354 FreeUnicodeStringTable (MouseAbsolutePointerDev->ControllerNameTable);\r
355 }\r
356 //\r
357 // Since there will be no timer handler for mouse input any more,\r
358 // exhaust input data just in case there is still mouse data left\r
359 //\r
360 EmptyStatus = EFI_SUCCESS;\r
361 while (!EFI_ERROR (EmptyStatus)) {\r
362 EmptyStatus = In8042Data (IsaIo, &Data);\r
363 }\r
364\r
365 if (MouseAbsolutePointerDev != NULL) {\r
366 gBS->FreePool (MouseAbsolutePointerDev);\r
367 }\r
368\r
369 gBS->CloseProtocol (\r
370 Controller,\r
371 &gEfiDevicePathProtocolGuid,\r
372 This->DriverBindingHandle,\r
373 Controller\r
374 );\r
375\r
376 gBS->CloseProtocol (\r
377 Controller,\r
378 &gEfiIsaIoProtocolGuid,\r
379 This->DriverBindingHandle,\r
380 Controller\r
381 );\r
382\r
383 gBS->RestoreTPL (OldTpl);\r
384\r
385 return Status;\r
386}\r
387\r
388EFI_STATUS\r
389EFIAPI\r
390PS2MouseAbsolutePointerDriverStop (\r
391 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
392 IN EFI_HANDLE Controller,\r
393 IN UINTN NumberOfChildren,\r
394 IN EFI_HANDLE *ChildHandleBuffer\r
395 )\r
396/*++\r
397\r
398 Routine Description:\r
399\r
400 Arguments:\r
401\r
402 Returns:\r
403\r
404--*/\r
405// GC_TODO: This - add argument and description to function comment\r
406// GC_TODO: Controller - add argument and description to function comment\r
407// GC_TODO: NumberOfChildren - add argument and description to function comment\r
408// GC_TODO: ChildHandleBuffer - add argument and description to function comment\r
409// GC_TODO: EFI_SUCCESS - add return value to function comment\r
410// GC_TODO: EFI_SUCCESS - add return value to function comment\r
411{\r
412 EFI_STATUS Status;\r
413 EFI_ABSOLUTE_POINTER_PROTOCOL *AbsolutePointerProtocol;\r
414 PS2_MOUSE_ABSOLUTE_POINTER_DEV *MouseAbsolutePointerDev;\r
415 UINT8 Data;\r
416\r
417 Status = gBS->OpenProtocol (\r
418 Controller,\r
419 &gEfiAbsolutePointerProtocolGuid,\r
420 (VOID **) &AbsolutePointerProtocol,\r
421 This->DriverBindingHandle,\r
422 Controller,\r
423 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
424 );\r
425 if (EFI_ERROR (Status)) {\r
426 return EFI_SUCCESS;\r
427 }\r
428\r
429 MouseAbsolutePointerDev = PS2_MOUSE_ABSOLUTE_POINTER_DEV_FROM_THIS (AbsolutePointerProtocol);\r
430\r
431 //\r
432 // Report that the keyboard is being disabled\r
433 //\r
434 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
435 EFI_PROGRESS_CODE,\r
436 EFI_PERIPHERAL_MOUSE | EFI_P_PC_DISABLE,\r
437 MouseAbsolutePointerDev->DevicePath\r
438 );\r
439\r
440 Status = gBS->UninstallProtocolInterface (\r
441 Controller,\r
442 &gEfiAbsolutePointerProtocolGuid,\r
443 &MouseAbsolutePointerDev->AbsolutePointerProtocol\r
444 );\r
445 if (EFI_ERROR (Status)) {\r
446 return Status;\r
447 }\r
448 //\r
449 // Disable mouse on keyboard controller\r
450 //\r
451 KbcDisableAux (MouseAbsolutePointerDev->IsaIo);\r
452\r
453 //\r
454 // Cancel mouse data polling timer, close timer event\r
455 //\r
456 gBS->SetTimer (MouseAbsolutePointerDev->TimerEvent, TimerCancel, 0);\r
457 gBS->CloseEvent (MouseAbsolutePointerDev->TimerEvent);\r
458\r
459 //\r
460 // Since there will be no timer handler for mouse input any more,\r
461 // exhaust input data just in case there is still mouse data left\r
462 //\r
463 Status = EFI_SUCCESS;\r
464 while (!EFI_ERROR (Status)) {\r
465 Status = In8042Data (MouseAbsolutePointerDev->IsaIo, &Data);\r
466 }\r
467\r
468 gBS->CloseEvent (MouseAbsolutePointerDev->AbsolutePointerProtocol.WaitForInput);\r
469 FreeUnicodeStringTable (MouseAbsolutePointerDev->ControllerNameTable);\r
470 gBS->FreePool (MouseAbsolutePointerDev);\r
471\r
472 gBS->CloseProtocol (\r
473 Controller,\r
474 &gEfiDevicePathProtocolGuid,\r
475 This->DriverBindingHandle,\r
476 Controller\r
477 );\r
478\r
479 gBS->CloseProtocol (\r
480 Controller,\r
481 &gEfiIsaIoProtocolGuid,\r
482 This->DriverBindingHandle,\r
483 Controller\r
484 );\r
485\r
486 return EFI_SUCCESS;\r
487}\r
488\r
489EFI_STATUS\r
490EFIAPI\r
491MouseAbsolutePointerReset (\r
492 IN EFI_ABSOLUTE_POINTER_PROTOCOL *This,\r
493 IN BOOLEAN ExtendedVerification\r
494 )\r
495/*++\r
496\r
497Routine Description:\r
498\r
499 Reset the Mouse and do BAT test for it, if ExtendedVerification isTRUE and there is a mouse device connectted to system\r
500\r
501Arguments:\r
502\r
503 This - Pointer of simple pointer Protocol.\r
504 ExtendedVerification - Whether configure mouse parameters. True: do; FALSE: skip.\r
505\r
506Returns:\r
507\r
508 EFI_SUCCESS - The command byte is written successfully.\r
509 EFI_DEVICE_ERROR - Errors occurred during reseting keyboard.\r
510\r
511--*/\r
512{\r
513 EFI_STATUS Status;\r
514 PS2_MOUSE_ABSOLUTE_POINTER_DEV *MouseAbsolutePointerDev;\r
515 EFI_TPL OldTpl;\r
516 BOOLEAN KeyboardEnable;\r
517 UINT8 Data;\r
518\r
519 MouseAbsolutePointerDev = PS2_MOUSE_ABSOLUTE_POINTER_DEV_FROM_THIS (This);\r
520\r
521 //\r
522 // Report reset progress code\r
523 //\r
524 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
525 EFI_PROGRESS_CODE,\r
526 EFI_PERIPHERAL_MOUSE | EFI_P_PC_RESET,\r
527 MouseAbsolutePointerDev->DevicePath\r
528 );\r
529\r
530 KeyboardEnable = FALSE;\r
531\r
532 //\r
533 // Raise TPL to avoid keyboard operation impact\r
534 //\r
535 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
536\r
537 ZeroMem (&MouseAbsolutePointerDev->State, sizeof (EFI_ABSOLUTE_POINTER_STATE));\r
538 MouseAbsolutePointerDev->StateChanged = FALSE;\r
539\r
540 //\r
541 // Exhaust input data\r
542 //\r
543 Status = EFI_SUCCESS;\r
544 while (!EFI_ERROR (Status)) {\r
545 Status = In8042Data (MouseAbsolutePointerDev->IsaIo, &Data);\r
546 }\r
547\r
548 CheckKbStatus (MouseAbsolutePointerDev->IsaIo, &KeyboardEnable);\r
549\r
550 KbcDisableKb (MouseAbsolutePointerDev->IsaIo);\r
551\r
552 MouseAbsolutePointerDev->IsaIo->Io.Read (MouseAbsolutePointerDev->IsaIo, EfiIsaIoWidthUint8, KBC_CMD_STS_PORT, 1, &Data);\r
553\r
554 //\r
555 // if there's data block on KBC data port, read it out\r
556 //\r
557 if ((Data & KBC_OUTB) == KBC_OUTB) {\r
558 MouseAbsolutePointerDev->IsaIo->Io.Read (MouseAbsolutePointerDev->IsaIo, EfiIsaIoWidthUint8, KBC_DATA_PORT, 1, &Data);\r
559 }\r
560\r
561 Status = EFI_SUCCESS;\r
562 //\r
563 // The PS2 mouse driver reset behavior is always successfully return no matter wheater or not there is mouse connected to system.\r
564 // This behavior is needed by performance speed. The following mouse command only succeessfully finish when mouse device is\r
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\r
566 //\r
567 if (ExtendedVerification && CheckMouseAbsolutePointerConnect (MouseAbsolutePointerDev)) {\r
568 //\r
569 // Send mouse reset command and set mouse default configure\r
570 //\r
571 Status = PS2MouseReset (MouseAbsolutePointerDev->IsaIo);\r
572 if (EFI_ERROR (Status)) {\r
573 Status = EFI_DEVICE_ERROR;\r
574 goto Exit;\r
575 }\r
576\r
577 Status = PS2MouseSetSampleRate (MouseAbsolutePointerDev->IsaIo, MouseAbsolutePointerDev->SampleRate);\r
578 if (EFI_ERROR (Status)) {\r
579 Status = EFI_DEVICE_ERROR;\r
580 goto Exit;\r
581 }\r
582\r
583 Status = PS2MouseSetResolution (MouseAbsolutePointerDev->IsaIo, MouseAbsolutePointerDev->Resolution);\r
584 if (EFI_ERROR (Status)) {\r
585 Status = EFI_DEVICE_ERROR;\r
586 goto Exit;\r
587 }\r
588\r
589 Status = PS2MouseSetScaling (MouseAbsolutePointerDev->IsaIo, MouseAbsolutePointerDev->Scaling);\r
590 if (EFI_ERROR (Status)) {\r
591 Status = EFI_DEVICE_ERROR;\r
592 goto Exit;\r
593 }\r
594\r
595 Status = PS2MouseEnable (MouseAbsolutePointerDev->IsaIo);\r
596 if (EFI_ERROR (Status)) {\r
597 Status = EFI_DEVICE_ERROR;\r
598 goto Exit;\r
599 }\r
600 }\r
601Exit:\r
602 gBS->RestoreTPL (OldTpl);\r
603\r
604 if (KeyboardEnable) {\r
605 KbcEnableKb (MouseAbsolutePointerDev->IsaIo);\r
606 }\r
607\r
608 return Status;\r
609}\r
610\r
611BOOLEAN\r
612CheckMouseAbsolutePointerConnect (\r
613 IN PS2_MOUSE_ABSOLUTE_POINTER_DEV *MouseAbsolutePointerDev\r
614 )\r
615/*++\r
616\r
617Routine Description:\r
618\r
619 Check whether there is Ps/2 mouse device in system\r
620\r
621Arguments:\r
622\r
623 PS2_MOUSE_DEV - Mouse Private Data Structure\r
624\r
625Returns:\r
626\r
627 TRUE - Keyboard in System.\r
628 FALSE - Keyboard not in System.\r
629\r
630--*/\r
631{\r
632 EFI_STATUS Status;\r
633\r
634 Status = PS2MouseEnable (MouseAbsolutePointerDev->IsaIo);\r
635 if (!EFI_ERROR (Status)) {\r
636 return TRUE;\r
637 }\r
638\r
639 return FALSE;\r
640}\r
641\r
642EFI_STATUS\r
643EFIAPI\r
644MouseAbsolutePointerGetState (\r
645 IN EFI_ABSOLUTE_POINTER_PROTOCOL *This,\r
646 IN OUT EFI_ABSOLUTE_POINTER_STATE *State\r
647 )\r
648/*++\r
649\r
650Routine Description:\r
651\r
652 GC_TODO: Add function description\r
653\r
654Arguments:\r
655\r
656 This - GC_TODO: add argument description\r
657 State - GC_TODO: add argument description\r
658\r
659Returns:\r
660\r
661 EFI_INVALID_PARAMETER - GC_TODO: Add description for return value\r
662 EFI_NOT_READY - GC_TODO: Add description for return value\r
663 EFI_SUCCESS - GC_TODO: Add description for return value\r
664\r
665--*/\r
666{\r
667 PS2_MOUSE_ABSOLUTE_POINTER_DEV *MouseAbsolutePointerDev;\r
668 EFI_TPL OldTpl;\r
669\r
670 MouseAbsolutePointerDev = PS2_MOUSE_ABSOLUTE_POINTER_DEV_FROM_THIS (This);\r
671\r
672 if (State == NULL) {\r
673 return EFI_INVALID_PARAMETER;\r
674 }\r
675\r
676 if (!MouseAbsolutePointerDev->StateChanged) {\r
677 return EFI_NOT_READY;\r
678 }\r
679\r
680 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
681 CopyMem (State, &(MouseAbsolutePointerDev->State), sizeof (EFI_ABSOLUTE_POINTER_STATE));\r
682\r
683 //\r
684 // clear mouse state\r
685 //\r
686 MouseAbsolutePointerDev->State.CurrentX = 0;\r
687 MouseAbsolutePointerDev->State.CurrentY = 0;\r
688 MouseAbsolutePointerDev->State.CurrentZ = 0;\r
689 MouseAbsolutePointerDev->State.ActiveButtons = 0x0;\r
690 MouseAbsolutePointerDev->StateChanged = FALSE;\r
691 gBS->RestoreTPL (OldTpl);\r
692\r
693 return EFI_SUCCESS;\r
694}\r
695\r
696VOID\r
697EFIAPI\r
698MouseAbsolutePointerWaitForInput (\r
699 IN EFI_EVENT Event,\r
700 IN VOID *Context\r
701 )\r
702/*++\r
703\r
704Routine Description:\r
705\r
706 Event notification function for SIMPLE_POINTER.WaitForInput event\r
707 Signal the event if there is input from mouse\r
708\r
709Arguments:\r
710\r
711Returns:\r
712\r
713--*/\r
714// GC_TODO: Event - add argument and description to function comment\r
715// GC_TODO: Context - add argument and description to function comment\r
716{\r
717 PS2_MOUSE_ABSOLUTE_POINTER_DEV *MouseAbsolutePointerDev;\r
718\r
719 MouseAbsolutePointerDev = (PS2_MOUSE_ABSOLUTE_POINTER_DEV *) Context;\r
720\r
721 //\r
722 // Someone is waiting on the mouse event, if there's\r
723 // input from mouse, signal the event\r
724 //\r
725 if (MouseAbsolutePointerDev->StateChanged) {\r
726 gBS->SignalEvent (Event);\r
727 }\r
728\r
729}\r
730\r
731VOID\r
732EFIAPI\r
733PollMouseAbsolutePointer(\r
734 IN EFI_EVENT Event,\r
735 IN VOID *Context\r
736 )\r
737/*++\r
738\r
739Routine Description:\r
740\r
741 Event notification function for TimerEvent event\r
742 If mouse device is connected to system, try to get the mouse packet data\r
743\r
744Arguments:\r
745\r
746 Event - TimerEvent in PS2_MOUSE_DEV\r
747 Context - Pointer to PS2_MOUSE_DEV structure\r
748\r
749Returns:\r
750\r
751 None\r
752\r
753--*/\r
754{\r
755 PS2_MOUSE_ABSOLUTE_POINTER_DEV *MouseAbsolutePointerDev;\r
756\r
757 MouseAbsolutePointerDev = (PS2_MOUSE_ABSOLUTE_POINTER_DEV *) Context;\r
758\r
759 //\r
760 // Polling mouse packet data\r
761 //\r
762 PS2MouseGetPacket (MouseAbsolutePointerDev);\r
763}\r
764\r
765/**\r
766 The user Entry Point for module Ps2MouseAbsolutePointer. The user code starts with this function.\r
767\r
768 @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
769 @param[in] SystemTable A pointer to the EFI System Table.\r
770 \r
771 @retval EFI_SUCCESS The entry point is executed successfully.\r
772 @retval other Some error occurs when executing this entry point.\r
773\r
774**/\r
775EFI_STATUS\r
776EFIAPI\r
777InitializePs2MouseAbsolutePointer(\r
778 IN EFI_HANDLE ImageHandle,\r
779 IN EFI_SYSTEM_TABLE *SystemTable\r
780 )\r
781{\r
782 EFI_STATUS Status;\r
783\r
784 //\r
785 // Install driver model protocol(s).\r
786 //\r
787 Status = EfiLibInstallDriverBindingComponentName2 (\r
788 ImageHandle,\r
789 SystemTable,\r
790 &gPS2MouseAbsolutePointerDriver,\r
791 ImageHandle,\r
792 &gPs2MouseAbsolutePointerComponentName,\r
793 &gPs2MouseAbsolutePointerComponentName2\r
794 );\r
795 ASSERT_EFI_ERROR (Status);\r
796\r
797\r
798 return Status;\r
799}\r