]>
Commit | Line | Data |
---|---|---|
afd0fe22 | 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 | |
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 | |
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 | |
22 | EFI_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 | |
bcd70414 | 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 | |
afd0fe22 | 45 | EFI_STATUS\r |
46 | EFIAPI\r | |
47 | PS2MouseAbsolutePointerDriverSupported (\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 | |
afd0fe22 | 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 | |
bcd70414 | 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 | |
afd0fe22 | 126 | EFI_STATUS\r |
127 | EFIAPI\r | |
128 | PS2MouseAbsolutePointerDriverStart (\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 | |
afd0fe22 | 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 | |
333 | ErrorExit:\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 | |
bcd70414 | 388 | /**\r |
389 | Stop this driver on ControllerHandle. Support stoping any child handles\r | |
390 | created by this driver.\r | |
391 | \r | |
392 | @param This Protocol instance pointer.\r | |
393 | @param ControllerHandle Handle of device to stop driver on\r | |
394 | @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r | |
395 | children is zero stop the entire bus driver.\r | |
396 | @param ChildHandleBuffer List of Child Handles to Stop.\r | |
397 | \r | |
398 | @retval EFI_SUCCESS This driver is removed ControllerHandle\r | |
399 | @retval other This driver was not removed from this device\r | |
400 | \r | |
401 | **/\r | |
afd0fe22 | 402 | EFI_STATUS\r |
403 | EFIAPI\r | |
404 | PS2MouseAbsolutePointerDriverStop (\r | |
405 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
406 | IN EFI_HANDLE Controller,\r | |
407 | IN UINTN NumberOfChildren,\r | |
408 | IN EFI_HANDLE *ChildHandleBuffer\r | |
409 | )\r | |
afd0fe22 | 410 | {\r |
411 | EFI_STATUS Status;\r | |
412 | EFI_ABSOLUTE_POINTER_PROTOCOL *AbsolutePointerProtocol;\r | |
413 | PS2_MOUSE_ABSOLUTE_POINTER_DEV *MouseAbsolutePointerDev;\r | |
414 | UINT8 Data;\r | |
415 | \r | |
416 | Status = gBS->OpenProtocol (\r | |
417 | Controller,\r | |
418 | &gEfiAbsolutePointerProtocolGuid,\r | |
419 | (VOID **) &AbsolutePointerProtocol,\r | |
420 | This->DriverBindingHandle,\r | |
421 | Controller,\r | |
422 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
423 | );\r | |
424 | if (EFI_ERROR (Status)) {\r | |
425 | return EFI_SUCCESS;\r | |
426 | }\r | |
427 | \r | |
428 | MouseAbsolutePointerDev = PS2_MOUSE_ABSOLUTE_POINTER_DEV_FROM_THIS (AbsolutePointerProtocol);\r | |
429 | \r | |
430 | //\r | |
431 | // Report that the keyboard is being disabled\r | |
432 | //\r | |
433 | REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r | |
434 | EFI_PROGRESS_CODE,\r | |
435 | EFI_PERIPHERAL_MOUSE | EFI_P_PC_DISABLE,\r | |
436 | MouseAbsolutePointerDev->DevicePath\r | |
437 | );\r | |
438 | \r | |
439 | Status = gBS->UninstallProtocolInterface (\r | |
440 | Controller,\r | |
441 | &gEfiAbsolutePointerProtocolGuid,\r | |
442 | &MouseAbsolutePointerDev->AbsolutePointerProtocol\r | |
443 | );\r | |
444 | if (EFI_ERROR (Status)) {\r | |
445 | return Status;\r | |
446 | }\r | |
447 | //\r | |
448 | // Disable mouse on keyboard controller\r | |
449 | //\r | |
450 | KbcDisableAux (MouseAbsolutePointerDev->IsaIo);\r | |
451 | \r | |
452 | //\r | |
453 | // Cancel mouse data polling timer, close timer event\r | |
454 | //\r | |
455 | gBS->SetTimer (MouseAbsolutePointerDev->TimerEvent, TimerCancel, 0);\r | |
456 | gBS->CloseEvent (MouseAbsolutePointerDev->TimerEvent);\r | |
457 | \r | |
458 | //\r | |
459 | // Since there will be no timer handler for mouse input any more,\r | |
460 | // exhaust input data just in case there is still mouse data left\r | |
461 | //\r | |
462 | Status = EFI_SUCCESS;\r | |
463 | while (!EFI_ERROR (Status)) {\r | |
464 | Status = In8042Data (MouseAbsolutePointerDev->IsaIo, &Data);\r | |
465 | }\r | |
466 | \r | |
467 | gBS->CloseEvent (MouseAbsolutePointerDev->AbsolutePointerProtocol.WaitForInput);\r | |
468 | FreeUnicodeStringTable (MouseAbsolutePointerDev->ControllerNameTable);\r | |
469 | gBS->FreePool (MouseAbsolutePointerDev);\r | |
470 | \r | |
471 | gBS->CloseProtocol (\r | |
472 | Controller,\r | |
473 | &gEfiDevicePathProtocolGuid,\r | |
474 | This->DriverBindingHandle,\r | |
475 | Controller\r | |
476 | );\r | |
477 | \r | |
478 | gBS->CloseProtocol (\r | |
479 | Controller,\r | |
480 | &gEfiIsaIoProtocolGuid,\r | |
481 | This->DriverBindingHandle,\r | |
482 | Controller\r | |
483 | );\r | |
484 | \r | |
485 | return EFI_SUCCESS;\r | |
486 | }\r | |
487 | \r | |
bcd70414 | 488 | /**\r |
489 | Reset the Mouse and do BAT test for it, if ExtendedVerification isTRUE and there is a mouse device connectted to system\r | |
490 | \r | |
491 | @param This - Pointer of simple pointer Protocol.\r | |
492 | @param ExtendedVerification - Whether configure mouse parameters. True: do; FALSE: skip.\r | |
493 | \r | |
494 | \r | |
495 | @retval EFI_SUCCESS - The command byte is written successfully.\r | |
496 | @retval EFI_DEVICE_ERROR - Errors occurred during reseting keyboard.\r | |
497 | \r | |
498 | **/\r | |
afd0fe22 | 499 | EFI_STATUS\r |
500 | EFIAPI\r | |
501 | MouseAbsolutePointerReset (\r | |
502 | IN EFI_ABSOLUTE_POINTER_PROTOCOL *This,\r | |
503 | IN BOOLEAN ExtendedVerification\r | |
504 | )\r | |
afd0fe22 | 505 | {\r |
506 | EFI_STATUS Status;\r | |
507 | PS2_MOUSE_ABSOLUTE_POINTER_DEV *MouseAbsolutePointerDev;\r | |
508 | EFI_TPL OldTpl;\r | |
509 | BOOLEAN KeyboardEnable;\r | |
510 | UINT8 Data;\r | |
511 | \r | |
512 | MouseAbsolutePointerDev = PS2_MOUSE_ABSOLUTE_POINTER_DEV_FROM_THIS (This);\r | |
513 | \r | |
514 | //\r | |
515 | // Report reset progress code\r | |
516 | //\r | |
517 | REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r | |
518 | EFI_PROGRESS_CODE,\r | |
519 | EFI_PERIPHERAL_MOUSE | EFI_P_PC_RESET,\r | |
520 | MouseAbsolutePointerDev->DevicePath\r | |
521 | );\r | |
522 | \r | |
523 | KeyboardEnable = FALSE;\r | |
524 | \r | |
525 | //\r | |
526 | // Raise TPL to avoid keyboard operation impact\r | |
527 | //\r | |
528 | OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r | |
529 | \r | |
530 | ZeroMem (&MouseAbsolutePointerDev->State, sizeof (EFI_ABSOLUTE_POINTER_STATE));\r | |
531 | MouseAbsolutePointerDev->StateChanged = FALSE;\r | |
532 | \r | |
533 | //\r | |
534 | // Exhaust input data\r | |
535 | //\r | |
536 | Status = EFI_SUCCESS;\r | |
537 | while (!EFI_ERROR (Status)) {\r | |
538 | Status = In8042Data (MouseAbsolutePointerDev->IsaIo, &Data);\r | |
539 | }\r | |
540 | \r | |
541 | CheckKbStatus (MouseAbsolutePointerDev->IsaIo, &KeyboardEnable);\r | |
542 | \r | |
543 | KbcDisableKb (MouseAbsolutePointerDev->IsaIo);\r | |
544 | \r | |
545 | MouseAbsolutePointerDev->IsaIo->Io.Read (MouseAbsolutePointerDev->IsaIo, EfiIsaIoWidthUint8, KBC_CMD_STS_PORT, 1, &Data);\r | |
546 | \r | |
547 | //\r | |
548 | // if there's data block on KBC data port, read it out\r | |
549 | //\r | |
550 | if ((Data & KBC_OUTB) == KBC_OUTB) {\r | |
551 | MouseAbsolutePointerDev->IsaIo->Io.Read (MouseAbsolutePointerDev->IsaIo, EfiIsaIoWidthUint8, KBC_DATA_PORT, 1, &Data);\r | |
552 | }\r | |
553 | \r | |
554 | Status = EFI_SUCCESS;\r | |
555 | //\r | |
556 | // The PS2 mouse driver reset behavior is always successfully return no matter wheater or not there is mouse connected to system.\r | |
557 | // This behavior is needed by performance speed. The following mouse command only succeessfully finish when mouse device is\r | |
558 | // 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 | |
559 | //\r | |
560 | if (ExtendedVerification && CheckMouseAbsolutePointerConnect (MouseAbsolutePointerDev)) {\r | |
561 | //\r | |
562 | // Send mouse reset command and set mouse default configure\r | |
563 | //\r | |
564 | Status = PS2MouseReset (MouseAbsolutePointerDev->IsaIo);\r | |
565 | if (EFI_ERROR (Status)) {\r | |
566 | Status = EFI_DEVICE_ERROR;\r | |
567 | goto Exit;\r | |
568 | }\r | |
569 | \r | |
570 | Status = PS2MouseSetSampleRate (MouseAbsolutePointerDev->IsaIo, MouseAbsolutePointerDev->SampleRate);\r | |
571 | if (EFI_ERROR (Status)) {\r | |
572 | Status = EFI_DEVICE_ERROR;\r | |
573 | goto Exit;\r | |
574 | }\r | |
575 | \r | |
576 | Status = PS2MouseSetResolution (MouseAbsolutePointerDev->IsaIo, MouseAbsolutePointerDev->Resolution);\r | |
577 | if (EFI_ERROR (Status)) {\r | |
578 | Status = EFI_DEVICE_ERROR;\r | |
579 | goto Exit;\r | |
580 | }\r | |
581 | \r | |
582 | Status = PS2MouseSetScaling (MouseAbsolutePointerDev->IsaIo, MouseAbsolutePointerDev->Scaling);\r | |
583 | if (EFI_ERROR (Status)) {\r | |
584 | Status = EFI_DEVICE_ERROR;\r | |
585 | goto Exit;\r | |
586 | }\r | |
587 | \r | |
588 | Status = PS2MouseEnable (MouseAbsolutePointerDev->IsaIo);\r | |
589 | if (EFI_ERROR (Status)) {\r | |
590 | Status = EFI_DEVICE_ERROR;\r | |
591 | goto Exit;\r | |
592 | }\r | |
593 | }\r | |
594 | Exit:\r | |
595 | gBS->RestoreTPL (OldTpl);\r | |
596 | \r | |
597 | if (KeyboardEnable) {\r | |
598 | KbcEnableKb (MouseAbsolutePointerDev->IsaIo);\r | |
599 | }\r | |
600 | \r | |
601 | return Status;\r | |
602 | }\r | |
603 | \r | |
bcd70414 | 604 | /**\r |
afd0fe22 | 605 | Check whether there is Ps/2 mouse device in system\r |
606 | \r | |
bcd70414 | 607 | @param PS2_MOUSE_DEV - Mouse Private Data Structure\r |
afd0fe22 | 608 | \r |
bcd70414 | 609 | @retval TRUE - Keyboard in System.\r |
610 | @retval FALSE - Keyboard not in System.\r | |
afd0fe22 | 611 | \r |
bcd70414 | 612 | **/\r |
613 | BOOLEAN\r | |
614 | CheckMouseAbsolutePointerConnect (\r | |
615 | IN PS2_MOUSE_ABSOLUTE_POINTER_DEV *MouseAbsolutePointerDev\r | |
616 | )\r | |
afd0fe22 | 617 | \r |
afd0fe22 | 618 | {\r |
619 | EFI_STATUS Status;\r | |
620 | \r | |
621 | Status = PS2MouseEnable (MouseAbsolutePointerDev->IsaIo);\r | |
622 | if (!EFI_ERROR (Status)) {\r | |
623 | return TRUE;\r | |
624 | }\r | |
625 | \r | |
626 | return FALSE;\r | |
627 | }\r | |
628 | \r | |
bcd70414 | 629 | /**\r |
630 | Get and Clear mouse status.\r | |
631 | \r | |
632 | @param This - Pointer of simple pointer Protocol.\r | |
633 | @param State - Output buffer holding status.\r | |
634 | \r | |
635 | @retval EFI_INVALID_PARAMETER Output buffer is invalid.\r | |
636 | @retval EFI_NOT_READY Mouse is not changed status yet.\r | |
637 | @retval EFI_SUCCESS Mouse status is changed and get successful.\r | |
638 | **/\r | |
afd0fe22 | 639 | EFI_STATUS\r |
640 | EFIAPI\r | |
641 | MouseAbsolutePointerGetState (\r | |
642 | IN EFI_ABSOLUTE_POINTER_PROTOCOL *This,\r | |
643 | IN OUT EFI_ABSOLUTE_POINTER_STATE *State\r | |
644 | )\r | |
afd0fe22 | 645 | {\r |
646 | PS2_MOUSE_ABSOLUTE_POINTER_DEV *MouseAbsolutePointerDev;\r | |
647 | EFI_TPL OldTpl;\r | |
648 | \r | |
649 | MouseAbsolutePointerDev = PS2_MOUSE_ABSOLUTE_POINTER_DEV_FROM_THIS (This);\r | |
650 | \r | |
651 | if (State == NULL) {\r | |
652 | return EFI_INVALID_PARAMETER;\r | |
653 | }\r | |
654 | \r | |
655 | if (!MouseAbsolutePointerDev->StateChanged) {\r | |
656 | return EFI_NOT_READY;\r | |
657 | }\r | |
658 | \r | |
659 | OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r | |
660 | CopyMem (State, &(MouseAbsolutePointerDev->State), sizeof (EFI_ABSOLUTE_POINTER_STATE));\r | |
661 | \r | |
662 | //\r | |
663 | // clear mouse state\r | |
664 | //\r | |
665 | MouseAbsolutePointerDev->State.CurrentX = 0;\r | |
666 | MouseAbsolutePointerDev->State.CurrentY = 0;\r | |
667 | MouseAbsolutePointerDev->State.CurrentZ = 0;\r | |
668 | MouseAbsolutePointerDev->State.ActiveButtons = 0x0;\r | |
669 | MouseAbsolutePointerDev->StateChanged = FALSE;\r | |
670 | gBS->RestoreTPL (OldTpl);\r | |
671 | \r | |
672 | return EFI_SUCCESS;\r | |
673 | }\r | |
674 | \r | |
bcd70414 | 675 | /**\r |
afd0fe22 | 676 | \r |
677 | Event notification function for SIMPLE_POINTER.WaitForInput event\r | |
678 | Signal the event if there is input from mouse\r | |
679 | \r | |
bcd70414 | 680 | @param Event event object\r |
681 | @param Context event context\r | |
afd0fe22 | 682 | \r |
bcd70414 | 683 | **/\r |
afd0fe22 | 684 | \r |
bcd70414 | 685 | VOID\r |
686 | EFIAPI\r | |
687 | MouseAbsolutePointerWaitForInput (\r | |
688 | IN EFI_EVENT Event,\r | |
689 | IN VOID *Context\r | |
690 | )\r | |
afd0fe22 | 691 | // GC_TODO: Event - add argument and description to function comment\r |
692 | // GC_TODO: Context - add argument and description to function comment\r | |
693 | {\r | |
694 | PS2_MOUSE_ABSOLUTE_POINTER_DEV *MouseAbsolutePointerDev;\r | |
695 | \r | |
696 | MouseAbsolutePointerDev = (PS2_MOUSE_ABSOLUTE_POINTER_DEV *) Context;\r | |
697 | \r | |
698 | //\r | |
699 | // Someone is waiting on the mouse event, if there's\r | |
700 | // input from mouse, signal the event\r | |
701 | //\r | |
702 | if (MouseAbsolutePointerDev->StateChanged) {\r | |
703 | gBS->SignalEvent (Event);\r | |
704 | }\r | |
705 | \r | |
706 | }\r | |
707 | \r | |
bcd70414 | 708 | /**\r |
709 | Event notification function for TimerEvent event\r | |
710 | If mouse device is connected to system, try to get the mouse packet data\r | |
711 | \r | |
712 | @param Event - TimerEvent in PS2_MOUSE_DEV\r | |
713 | @param Context - Pointer to PS2_MOUSE_DEV structure\r | |
714 | \r | |
715 | **/\r | |
afd0fe22 | 716 | VOID\r |
717 | EFIAPI\r | |
718 | PollMouseAbsolutePointer(\r | |
719 | IN EFI_EVENT Event,\r | |
720 | IN VOID *Context\r | |
721 | )\r | |
afd0fe22 | 722 | \r |
afd0fe22 | 723 | {\r |
724 | PS2_MOUSE_ABSOLUTE_POINTER_DEV *MouseAbsolutePointerDev;\r | |
725 | \r | |
726 | MouseAbsolutePointerDev = (PS2_MOUSE_ABSOLUTE_POINTER_DEV *) Context;\r | |
727 | \r | |
728 | //\r | |
729 | // Polling mouse packet data\r | |
730 | //\r | |
731 | PS2MouseGetPacket (MouseAbsolutePointerDev);\r | |
732 | }\r | |
733 | \r | |
734 | /**\r | |
735 | The user Entry Point for module Ps2MouseAbsolutePointer. The user code starts with this function.\r | |
736 | \r | |
737 | @param[in] ImageHandle The firmware allocated handle for the EFI image. \r | |
738 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
739 | \r | |
740 | @retval EFI_SUCCESS The entry point is executed successfully.\r | |
741 | @retval other Some error occurs when executing this entry point.\r | |
742 | \r | |
743 | **/\r | |
744 | EFI_STATUS\r | |
745 | EFIAPI\r | |
746 | InitializePs2MouseAbsolutePointer(\r | |
747 | IN EFI_HANDLE ImageHandle,\r | |
748 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
749 | )\r | |
750 | {\r | |
751 | EFI_STATUS Status;\r | |
752 | \r | |
753 | //\r | |
754 | // Install driver model protocol(s).\r | |
755 | //\r | |
756 | Status = EfiLibInstallDriverBindingComponentName2 (\r | |
757 | ImageHandle,\r | |
758 | SystemTable,\r | |
759 | &gPS2MouseAbsolutePointerDriver,\r | |
760 | ImageHandle,\r | |
761 | &gPs2MouseAbsolutePointerComponentName,\r | |
762 | &gPs2MouseAbsolutePointerComponentName2\r | |
763 | );\r | |
764 | ASSERT_EFI_ERROR (Status);\r | |
765 | \r | |
766 | \r | |
767 | return Status;\r | |
768 | }\r | |
bcd70414 | 769 | \r |