]>
Commit | Line | Data |
---|---|---|
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 | 5 | Copyright (c) 2006 - 2007, Intel Corporation\r |
6 | All rights reserved. This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT 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 | |
22 | EFI_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 | |
31 | EFI_STATUS\r | |
32 | EFIAPI\r | |
33 | PS2MouseDriverSupported (\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 | |
40 | Routine Description:\r | |
41 | \r | |
42 | ControllerDriver Protocol Method\r | |
43 | \r | |
44 | Arguments:\r | |
45 | \r | |
46 | Returns:\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 | |
111 | EFI_STATUS\r | |
112 | EFIAPI\r | |
113 | PS2MouseDriverStart (\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 | |
120 | Routine Description:\r | |
121 | Start protocol interfaces for the mouse device handles.\r | |
122 | \r | |
123 | Arguments:\r | |
124 | This - Protocol instance pointer.\r | |
125 | Controller - Handle of device to bind driver to.\r | |
126 | RemainingDevicePath - Not used.\r | |
127 | \r | |
128 | Returns:\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 | |
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 | |
330 | ErrorExit:\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 | |
385 | EFI_STATUS\r | |
386 | EFIAPI\r | |
387 | PS2MouseDriverStop (\r | |
388 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
389 | IN EFI_HANDLE Controller,\r | |
390 | IN UINTN NumberOfChildren,\r | |
391 | IN EFI_HANDLE *ChildHandleBuffer\r | |
392 | )\r | |
393 | /*++\r | |
394 | \r | |
395 | Routine Description:\r | |
396 | \r | |
397 | Arguments:\r | |
398 | \r | |
399 | Returns:\r | |
400 | \r | |
401 | --*/\r | |
402 | // GC_TODO: This - add argument and description to function comment\r | |
403 | // GC_TODO: Controller - add argument and description to function comment\r | |
404 | // GC_TODO: NumberOfChildren - add argument and description to function comment\r | |
405 | // GC_TODO: ChildHandleBuffer - add argument and description to function comment\r | |
406 | // GC_TODO: EFI_SUCCESS - add return value to function comment\r | |
407 | // GC_TODO: EFI_SUCCESS - add return value to function comment\r | |
408 | {\r | |
409 | EFI_STATUS Status;\r | |
410 | EFI_SIMPLE_POINTER_PROTOCOL *SimplePointerProtocol;\r | |
411 | PS2_MOUSE_DEV *MouseDev;\r | |
412 | UINT8 Data;\r | |
413 | \r | |
414 | Status = gBS->OpenProtocol (\r | |
415 | Controller,\r | |
416 | &gEfiSimplePointerProtocolGuid,\r | |
417 | (VOID **) &SimplePointerProtocol,\r | |
418 | This->DriverBindingHandle,\r | |
419 | Controller,\r | |
420 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
421 | );\r | |
422 | if (EFI_ERROR (Status)) {\r | |
423 | return EFI_SUCCESS;\r | |
424 | }\r | |
425 | \r | |
426 | MouseDev = PS2_MOUSE_DEV_FROM_THIS (SimplePointerProtocol);\r | |
427 | \r | |
428 | //\r | |
429 | // Report that the keyboard is being disabled\r | |
430 | //\r | |
431 | REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r | |
432 | EFI_PROGRESS_CODE,\r | |
433 | EFI_PERIPHERAL_MOUSE | EFI_P_PC_DISABLE,\r | |
434 | MouseDev->DevicePath\r | |
435 | );\r | |
436 | \r | |
437 | Status = gBS->UninstallProtocolInterface (\r | |
438 | Controller,\r | |
439 | &gEfiSimplePointerProtocolGuid,\r | |
440 | &MouseDev->SimplePointerProtocol\r | |
441 | );\r | |
442 | if (EFI_ERROR (Status)) {\r | |
443 | return Status;\r | |
444 | }\r | |
445 | //\r | |
446 | // Disable mouse on keyboard controller\r | |
447 | //\r | |
448 | KbcDisableAux (MouseDev->IsaIo);\r | |
449 | \r | |
450 | //\r | |
451 | // Cancel mouse data polling timer, close timer event\r | |
452 | //\r | |
453 | gBS->SetTimer (MouseDev->TimerEvent, TimerCancel, 0);\r | |
454 | gBS->CloseEvent (MouseDev->TimerEvent);\r | |
455 | \r | |
456 | //\r | |
457 | // Since there will be no timer handler for mouse input any more,\r | |
458 | // exhaust input data just in case there is still mouse data left\r | |
459 | //\r | |
460 | Status = EFI_SUCCESS;\r | |
461 | while (!EFI_ERROR (Status)) {\r | |
462 | Status = In8042Data (MouseDev->IsaIo, &Data);\r | |
463 | }\r | |
464 | \r | |
465 | gBS->CloseEvent (MouseDev->SimplePointerProtocol.WaitForInput);\r | |
466 | FreeUnicodeStringTable (MouseDev->ControllerNameTable);\r | |
467 | gBS->FreePool (MouseDev);\r | |
468 | \r | |
469 | gBS->CloseProtocol (\r | |
470 | Controller,\r | |
471 | &gEfiDevicePathProtocolGuid,\r | |
472 | This->DriverBindingHandle,\r | |
473 | Controller\r | |
474 | );\r | |
475 | \r | |
476 | gBS->CloseProtocol (\r | |
477 | Controller,\r | |
478 | &gEfiIsaIoProtocolGuid,\r | |
479 | This->DriverBindingHandle,\r | |
480 | Controller\r | |
481 | );\r | |
482 | \r | |
483 | return EFI_SUCCESS;\r | |
484 | }\r | |
485 | \r | |
486 | EFI_STATUS\r | |
487 | EFIAPI\r | |
488 | MouseReset (\r | |
489 | IN EFI_SIMPLE_POINTER_PROTOCOL *This,\r | |
490 | IN BOOLEAN ExtendedVerification\r | |
491 | )\r | |
492 | /*++\r | |
493 | \r | |
494 | Routine Description:\r | |
495 | \r | |
496 | Reset the Mouse and do BAT test for it, if ExtendedVerification isTRUE and there is a mouse device connectted to system\r | |
497 | \r | |
498 | Arguments:\r | |
499 | \r | |
500 | This - Pointer of simple pointer Protocol.\r | |
501 | ExtendedVerification - Whether configure mouse parameters. True: do; FALSE: skip.\r | |
502 | \r | |
503 | Returns:\r | |
504 | \r | |
505 | EFI_SUCCESS - The command byte is written successfully.\r | |
506 | EFI_DEVICE_ERROR - Errors occurred during reseting keyboard.\r | |
507 | \r | |
508 | --*/\r | |
509 | {\r | |
510 | EFI_STATUS Status;\r | |
511 | PS2_MOUSE_DEV *MouseDev;\r | |
512 | EFI_TPL OldTpl;\r | |
513 | BOOLEAN KeyboardEnable;\r | |
514 | UINT8 Data;\r | |
515 | \r | |
516 | MouseDev = PS2_MOUSE_DEV_FROM_THIS (This);\r | |
517 | \r | |
518 | //\r | |
519 | // Report reset progress code\r | |
520 | //\r | |
521 | REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r | |
522 | EFI_PROGRESS_CODE,\r | |
523 | EFI_PERIPHERAL_MOUSE | EFI_P_PC_RESET,\r | |
524 | MouseDev->DevicePath\r | |
525 | );\r | |
526 | \r | |
527 | KeyboardEnable = FALSE;\r | |
528 | \r | |
529 | //\r | |
530 | // Raise TPL to avoid keyboard operation impact\r | |
531 | //\r | |
532 | OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r | |
533 | \r | |
534 | ZeroMem (&MouseDev->State, sizeof (EFI_SIMPLE_POINTER_STATE));\r | |
535 | MouseDev->StateChanged = FALSE;\r | |
536 | \r | |
537 | //\r | |
538 | // Exhaust input data\r | |
539 | //\r | |
540 | Status = EFI_SUCCESS;\r | |
541 | while (!EFI_ERROR (Status)) {\r | |
542 | Status = In8042Data (MouseDev->IsaIo, &Data);\r | |
543 | }\r | |
544 | \r | |
545 | CheckKbStatus (MouseDev->IsaIo, &KeyboardEnable);\r | |
546 | \r | |
547 | KbcDisableKb (MouseDev->IsaIo);\r | |
548 | \r | |
549 | MouseDev->IsaIo->Io.Read (MouseDev->IsaIo, EfiIsaIoWidthUint8, KBC_CMD_STS_PORT, 1, &Data);\r | |
550 | \r | |
551 | //\r | |
552 | // if there's data block on KBC data port, read it out\r | |
553 | //\r | |
554 | if ((Data & KBC_OUTB) == KBC_OUTB) {\r | |
555 | MouseDev->IsaIo->Io.Read (MouseDev->IsaIo, EfiIsaIoWidthUint8, KBC_DATA_PORT, 1, &Data);\r | |
556 | }\r | |
557 | \r | |
558 | Status = EFI_SUCCESS;\r | |
559 | //\r | |
560 | // The PS2 mouse driver reset behavior is always successfully return no matter wheater or not there is mouse connected to system.\r | |
561 | // This behavior is needed by performance speed. The following mouse command only succeessfully finish when mouse device is\r | |
562 | // 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 | |
563 | //\r | |
564 | if (ExtendedVerification && CheckMouseConnect (MouseDev)) {\r | |
565 | //\r | |
566 | // Send mouse reset command and set mouse default configure\r | |
567 | //\r | |
568 | Status = PS2MouseReset (MouseDev->IsaIo);\r | |
569 | if (EFI_ERROR (Status)) {\r | |
570 | Status = EFI_DEVICE_ERROR;\r | |
571 | goto Exit;\r | |
572 | }\r | |
573 | \r | |
574 | Status = PS2MouseSetSampleRate (MouseDev->IsaIo, MouseDev->SampleRate);\r | |
575 | if (EFI_ERROR (Status)) {\r | |
576 | Status = EFI_DEVICE_ERROR;\r | |
577 | goto Exit;\r | |
578 | }\r | |
579 | \r | |
580 | Status = PS2MouseSetResolution (MouseDev->IsaIo, MouseDev->Resolution);\r | |
581 | if (EFI_ERROR (Status)) {\r | |
582 | Status = EFI_DEVICE_ERROR;\r | |
583 | goto Exit;\r | |
584 | }\r | |
585 | \r | |
586 | Status = PS2MouseSetScaling (MouseDev->IsaIo, MouseDev->Scaling);\r | |
587 | if (EFI_ERROR (Status)) {\r | |
588 | Status = EFI_DEVICE_ERROR;\r | |
589 | goto Exit;\r | |
590 | }\r | |
591 | \r | |
592 | Status = PS2MouseEnable (MouseDev->IsaIo);\r | |
593 | if (EFI_ERROR (Status)) {\r | |
594 | Status = EFI_DEVICE_ERROR;\r | |
595 | goto Exit;\r | |
596 | }\r | |
597 | }\r | |
598 | Exit:\r | |
599 | gBS->RestoreTPL (OldTpl);\r | |
600 | \r | |
601 | if (KeyboardEnable) {\r | |
602 | KbcEnableKb (MouseDev->IsaIo);\r | |
603 | }\r | |
604 | \r | |
605 | return Status;\r | |
606 | }\r | |
607 | \r | |
608 | BOOLEAN\r | |
609 | CheckMouseConnect (\r | |
610 | IN PS2_MOUSE_DEV *MouseDev\r | |
611 | )\r | |
612 | /*++\r | |
613 | \r | |
614 | Routine Description:\r | |
615 | \r | |
616 | Check whether there is Ps/2 mouse device in system\r | |
617 | \r | |
618 | Arguments:\r | |
619 | \r | |
620 | PS2_MOUSE_DEV - Mouse Private Data Structure\r | |
621 | \r | |
622 | Returns:\r | |
623 | \r | |
624 | TRUE - Keyboard in System.\r | |
625 | FALSE - Keyboard not in System.\r | |
626 | \r | |
627 | --*/\r | |
628 | {\r | |
629 | EFI_STATUS Status;\r | |
630 | \r | |
631 | Status = PS2MouseEnable (MouseDev->IsaIo);\r | |
632 | if (!EFI_ERROR (Status)) {\r | |
633 | return TRUE;\r | |
634 | }\r | |
635 | \r | |
636 | return FALSE;\r | |
637 | }\r | |
638 | \r | |
639 | EFI_STATUS\r | |
640 | EFIAPI\r | |
641 | MouseGetState (\r | |
642 | IN EFI_SIMPLE_POINTER_PROTOCOL *This,\r | |
643 | IN OUT EFI_SIMPLE_POINTER_STATE *State\r | |
644 | )\r | |
645 | /*++\r | |
646 | \r | |
647 | Routine Description:\r | |
648 | \r | |
649 | GC_TODO: Add function description\r | |
650 | \r | |
651 | Arguments:\r | |
652 | \r | |
653 | This - GC_TODO: add argument description\r | |
654 | State - GC_TODO: add argument description\r | |
655 | \r | |
656 | Returns:\r | |
657 | \r | |
658 | EFI_INVALID_PARAMETER - GC_TODO: Add description for return value\r | |
659 | EFI_NOT_READY - GC_TODO: Add description for return value\r | |
660 | EFI_SUCCESS - GC_TODO: Add description for return value\r | |
661 | \r | |
662 | --*/\r | |
663 | {\r | |
664 | PS2_MOUSE_DEV *MouseDev;\r | |
665 | EFI_TPL OldTpl;\r | |
666 | \r | |
667 | MouseDev = PS2_MOUSE_DEV_FROM_THIS (This);\r | |
668 | \r | |
669 | if (State == NULL) {\r | |
670 | return EFI_INVALID_PARAMETER;\r | |
671 | }\r | |
672 | \r | |
673 | if (!MouseDev->StateChanged) {\r | |
674 | return EFI_NOT_READY;\r | |
675 | }\r | |
676 | \r | |
677 | OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r | |
678 | CopyMem (State, &(MouseDev->State), sizeof (EFI_SIMPLE_POINTER_STATE));\r | |
679 | \r | |
680 | //\r | |
681 | // clear mouse state\r | |
682 | //\r | |
683 | MouseDev->State.RelativeMovementX = 0;\r | |
684 | MouseDev->State.RelativeMovementY = 0;\r | |
685 | MouseDev->State.RelativeMovementZ = 0;\r | |
686 | MouseDev->StateChanged = FALSE;\r | |
687 | gBS->RestoreTPL (OldTpl);\r | |
688 | \r | |
689 | return EFI_SUCCESS;\r | |
690 | }\r | |
691 | \r | |
692 | VOID\r | |
693 | EFIAPI\r | |
694 | MouseWaitForInput (\r | |
695 | IN EFI_EVENT Event,\r | |
696 | IN VOID *Context\r | |
697 | )\r | |
698 | /*++\r | |
699 | \r | |
700 | Routine Description:\r | |
701 | \r | |
702 | Event notification function for SIMPLE_POINTER.WaitForInput event\r | |
703 | Signal the event if there is input from mouse\r | |
704 | \r | |
705 | Arguments:\r | |
706 | \r | |
707 | Returns:\r | |
708 | \r | |
709 | --*/\r | |
710 | // GC_TODO: Event - add argument and description to function comment\r | |
711 | // GC_TODO: Context - add argument and description to function comment\r | |
712 | {\r | |
713 | PS2_MOUSE_DEV *MouseDev;\r | |
714 | \r | |
715 | MouseDev = (PS2_MOUSE_DEV *) Context;\r | |
716 | \r | |
717 | //\r | |
718 | // Someone is waiting on the mouse event, if there's\r | |
719 | // input from mouse, signal the event\r | |
720 | //\r | |
721 | if (MouseDev->StateChanged) {\r | |
722 | gBS->SignalEvent (Event);\r | |
723 | }\r | |
724 | \r | |
725 | }\r | |
726 | \r | |
727 | VOID\r | |
728 | EFIAPI\r | |
729 | PollMouse (\r | |
730 | IN EFI_EVENT Event,\r | |
731 | IN VOID *Context\r | |
732 | )\r | |
733 | /*++\r | |
734 | \r | |
735 | Routine Description:\r | |
736 | \r | |
737 | Event notification function for TimerEvent event\r | |
738 | If mouse device is connected to system, try to get the mouse packet data\r | |
739 | \r | |
740 | Arguments:\r | |
741 | \r | |
742 | Event - TimerEvent in PS2_MOUSE_DEV\r | |
743 | Context - Pointer to PS2_MOUSE_DEV structure\r | |
744 | \r | |
745 | Returns:\r | |
746 | \r | |
747 | None\r | |
748 | \r | |
749 | --*/\r | |
750 | {\r | |
751 | PS2_MOUSE_DEV *MouseDev;\r | |
752 | \r | |
753 | MouseDev = (PS2_MOUSE_DEV *) Context;\r | |
754 | \r | |
755 | //\r | |
756 | // Polling mouse packet data\r | |
757 | //\r | |
758 | PS2MouseGetPacket (MouseDev);\r | |
759 | }\r | |
c21fc3e8 | 760 | \r |
761 | /**\r | |
762 | The user Entry Point for module Ps2Mouse. The user code starts with this function.\r | |
763 | \r | |
764 | @param[in] ImageHandle The firmware allocated handle for the EFI image. \r | |
765 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
766 | \r | |
767 | @retval EFI_SUCCESS The entry point is executed successfully.\r | |
768 | @retval other Some error occurs when executing this entry point.\r | |
769 | \r | |
770 | **/\r | |
771 | EFI_STATUS\r | |
772 | EFIAPI\r | |
773 | InitializePs2Mouse(\r | |
774 | IN EFI_HANDLE ImageHandle,\r | |
775 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
776 | )\r | |
777 | {\r | |
778 | EFI_STATUS Status;\r | |
779 | \r | |
780 | //\r | |
781 | // Install driver model protocol(s).\r | |
782 | //\r | |
f3d08ccf | 783 | Status = EfiLibInstallDriverBindingComponentName2 (\r |
c21fc3e8 | 784 | ImageHandle,\r |
785 | SystemTable,\r | |
786 | &gPS2MouseDriver,\r | |
787 | ImageHandle,\r | |
788 | &gPs2MouseComponentName,\r | |
f3d08ccf | 789 | &gPs2MouseComponentName2\r |
c21fc3e8 | 790 | );\r |
791 | ASSERT_EFI_ERROR (Status);\r | |
792 | \r | |
793 | \r | |
794 | return Status;\r | |
795 | }\r |