]>
Commit | Line | Data |
---|---|---|
1 | /*++ | |
2 | ||
3 | Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR> | |
4 | Portions copyright (c) 2010, Apple, Inc. All rights reserved.<BR> | |
5 | Portions copyright (c) 2010, Apple Inc. All rights reserved.<BR> | |
6 | This program and the accompanying materials | |
7 | are licensed and made available under the terms and conditions of the BSD License | |
8 | which accompanies this distribution. The full text of the license may be found at | |
9 | http://opensource.org/licenses/bsd-license.php | |
10 | ||
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. | |
13 | ||
14 | ||
15 | --*/ | |
16 | ||
17 | #include "UnixGop.h" | |
18 | ||
19 | ||
20 | BOOLEAN | |
21 | GopPrivateIsKeyRegistered ( | |
22 | IN EFI_KEY_DATA *RegsiteredData, | |
23 | IN EFI_KEY_DATA *InputData | |
24 | ) | |
25 | /*++ | |
26 | ||
27 | Routine Description: | |
28 | ||
29 | Arguments: | |
30 | ||
31 | RegsiteredData - A pointer to a buffer that is filled in with the keystroke | |
32 | state data for the key that was registered. | |
33 | InputData - A pointer to a buffer that is filled in with the keystroke | |
34 | state data for the key that was pressed. | |
35 | ||
36 | Returns: | |
37 | TRUE - Key be pressed matches a registered key. | |
38 | FLASE - Match failed. | |
39 | ||
40 | --*/ | |
41 | { | |
42 | ASSERT (RegsiteredData != NULL && InputData != NULL); | |
43 | ||
44 | if ((RegsiteredData->Key.ScanCode != InputData->Key.ScanCode) || | |
45 | (RegsiteredData->Key.UnicodeChar != InputData->Key.UnicodeChar)) { | |
46 | return FALSE; | |
47 | } | |
48 | ||
49 | // | |
50 | // Assume KeyShiftState/KeyToggleState = 0 in Registered key data means these state could be ignored. | |
51 | // | |
52 | if (RegsiteredData->KeyState.KeyShiftState != 0 && | |
53 | RegsiteredData->KeyState.KeyShiftState != InputData->KeyState.KeyShiftState) { | |
54 | return FALSE; | |
55 | } | |
56 | if (RegsiteredData->KeyState.KeyToggleState != 0 && | |
57 | RegsiteredData->KeyState.KeyToggleState != InputData->KeyState.KeyToggleState) { | |
58 | return FALSE; | |
59 | } | |
60 | ||
61 | return TRUE; | |
62 | ||
63 | } | |
64 | ||
65 | ||
66 | VOID | |
67 | EFIAPI | |
68 | GopPrivateInvokeRegisteredFunction ( | |
69 | IN VOID *Context, | |
70 | IN EFI_KEY_DATA *KeyData | |
71 | ) | |
72 | { | |
73 | LIST_ENTRY *Link; | |
74 | UNIX_GOP_SIMPLE_TEXTIN_EX_NOTIFY *CurrentNotify; | |
75 | GOP_PRIVATE_DATA *Private = (GOP_PRIVATE_DATA *)Context; | |
76 | ||
77 | for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) { | |
78 | CurrentNotify = CR ( | |
79 | Link, | |
80 | UNIX_GOP_SIMPLE_TEXTIN_EX_NOTIFY, | |
81 | NotifyEntry, | |
82 | UNIX_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE | |
83 | ); | |
84 | if (GopPrivateIsKeyRegistered (&CurrentNotify->KeyData, KeyData)) { | |
85 | // We could be called at a high TPL so signal an event to call the registered function | |
86 | // at a lower TPL. | |
87 | gBS->SignalEvent (CurrentNotify->Event); | |
88 | } | |
89 | } | |
90 | } | |
91 | ||
92 | ||
93 | ||
94 | // | |
95 | // Simple Text In implementation. | |
96 | // | |
97 | ||
98 | /** | |
99 | Reset the input device and optionally run diagnostics | |
100 | ||
101 | @param This Protocol instance pointer. | |
102 | @param ExtendedVerification Driver may perform diagnostics on reset. | |
103 | ||
104 | @retval EFI_SUCCESS The device was reset. | |
105 | @retval EFI_DEVICE_ERROR The device is not functioning properly and could not be reset. | |
106 | ||
107 | **/ | |
108 | EFI_STATUS | |
109 | EFIAPI | |
110 | UnixGopSimpleTextInReset ( | |
111 | IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, | |
112 | IN BOOLEAN ExtendedVerification | |
113 | ) | |
114 | { | |
115 | GOP_PRIVATE_DATA *Private; | |
116 | EFI_KEY_DATA KeyData; | |
117 | EFI_TPL OldTpl; | |
118 | ||
119 | Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_THIS (This); | |
120 | if (Private->UgaIo == NULL) { | |
121 | return EFI_SUCCESS; | |
122 | } | |
123 | ||
124 | // | |
125 | // Enter critical section | |
126 | // | |
127 | OldTpl = gBS->RaiseTPL (TPL_NOTIFY); | |
128 | ||
129 | // | |
130 | // A reset is draining the Queue | |
131 | // | |
132 | while (Private->UgaIo->UgaGetKey (Private->UgaIo, &KeyData) == EFI_SUCCESS) | |
133 | ; | |
134 | ||
135 | // | |
136 | // Leave critical section and return | |
137 | // | |
138 | gBS->RestoreTPL (OldTpl); | |
139 | return EFI_SUCCESS; | |
140 | } | |
141 | ||
142 | ||
143 | /** | |
144 | Reads the next keystroke from the input device. The WaitForKey Event can | |
145 | be used to test for existence of a keystroke via WaitForEvent () call. | |
146 | ||
147 | @param This Protocol instance pointer. | |
148 | @param Key A pointer to a buffer that is filled in with the keystroke | |
149 | information for the key that was pressed. | |
150 | ||
151 | @retval EFI_SUCCESS The keystroke information was returned. | |
152 | @retval EFI_NOT_READY There was no keystroke data available. | |
153 | @retval EFI_DEVICE_ERROR The keystroke information was not returned due to | |
154 | hardware errors. | |
155 | ||
156 | **/ | |
157 | EFI_STATUS | |
158 | EFIAPI | |
159 | UnixGopSimpleTextInReadKeyStroke ( | |
160 | IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, | |
161 | OUT EFI_INPUT_KEY *Key | |
162 | ) | |
163 | { | |
164 | GOP_PRIVATE_DATA *Private; | |
165 | EFI_STATUS Status; | |
166 | EFI_TPL OldTpl; | |
167 | EFI_KEY_DATA KeyData; | |
168 | ||
169 | Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_THIS (This); | |
170 | if (Private->UgaIo == NULL) { | |
171 | return EFI_NOT_READY; | |
172 | } | |
173 | ||
174 | // | |
175 | // Enter critical section | |
176 | // | |
177 | OldTpl = gBS->RaiseTPL (TPL_NOTIFY); | |
178 | ||
179 | Status = Private->UgaIo->UgaGetKey(Private->UgaIo, &KeyData); | |
180 | CopyMem (Key, &KeyData.Key, sizeof (EFI_INPUT_KEY)); | |
181 | ||
182 | // | |
183 | // Leave critical section and return | |
184 | // | |
185 | gBS->RestoreTPL (OldTpl); | |
186 | ||
187 | return Status; | |
188 | } | |
189 | ||
190 | ||
191 | ||
192 | /** | |
193 | SimpleTextIn and SimpleTextInEx Notify Wait Event | |
194 | ||
195 | @param Event Event whose notification function is being invoked. | |
196 | @param Context Pointer to GOP_PRIVATE_DATA. | |
197 | ||
198 | **/ | |
199 | VOID | |
200 | EFIAPI | |
201 | UnixGopSimpleTextInWaitForKey ( | |
202 | IN EFI_EVENT Event, | |
203 | IN VOID *Context | |
204 | ) | |
205 | { | |
206 | GOP_PRIVATE_DATA *Private; | |
207 | EFI_STATUS Status; | |
208 | EFI_TPL OldTpl; | |
209 | ||
210 | Private = (GOP_PRIVATE_DATA *) Context; | |
211 | if (Private->UgaIo == NULL) { | |
212 | return; | |
213 | } | |
214 | ||
215 | // | |
216 | // Enter critical section | |
217 | // | |
218 | OldTpl = gBS->RaiseTPL (TPL_NOTIFY); | |
219 | ||
220 | Status = Private->UgaIo->UgaCheckKey (Private->UgaIo); | |
221 | if (!EFI_ERROR (Status)) { | |
222 | // | |
223 | // If a there is a key in the queue signal our event. | |
224 | // | |
225 | gBS->SignalEvent (Event); | |
226 | } | |
227 | // | |
228 | // Leave critical section and return | |
229 | // | |
230 | gBS->RestoreTPL (OldTpl); | |
231 | } | |
232 | ||
233 | ||
234 | // | |
235 | // Simple Text Input Ex protocol functions | |
236 | // | |
237 | ||
238 | ||
239 | /** | |
240 | The Reset() function resets the input device hardware. As part | |
241 | of initialization process, the firmware/device will make a quick | |
242 | but reasonable attempt to verify that the device is functioning. | |
243 | If the ExtendedVerification flag is TRUE the firmware may take | |
244 | an extended amount of time to verify the device is operating on | |
245 | reset. Otherwise the reset operation is to occur as quickly as | |
246 | possible. The hardware verification process is not defined by | |
247 | this specification and is left up to the platform firmware or | |
248 | driver to implement. | |
249 | ||
250 | @param This A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance. | |
251 | ||
252 | @param ExtendedVerification Indicates that the driver may | |
253 | perform a more exhaustive | |
254 | verification operation of the | |
255 | device during reset. | |
256 | ||
257 | ||
258 | @retval EFI_SUCCESS The device was reset. | |
259 | ||
260 | @retval EFI_DEVICE_ERROR The device is not functioning | |
261 | correctly and could not be reset. | |
262 | ||
263 | **/ | |
264 | EFI_STATUS | |
265 | EFIAPI | |
266 | UnixGopSimpleTextInExResetEx ( | |
267 | IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, | |
268 | IN BOOLEAN ExtendedVerification | |
269 | ) | |
270 | /*++ | |
271 | ||
272 | Routine Description: | |
273 | Reset the input device and optionaly run diagnostics | |
274 | ||
275 | Arguments: | |
276 | This - Protocol instance pointer. | |
277 | ExtendedVerification - Driver may perform diagnostics on reset. | |
278 | ||
279 | Returns: | |
280 | EFI_SUCCESS - The device was reset. | |
281 | ||
282 | --*/ | |
283 | { | |
284 | GOP_PRIVATE_DATA *Private; | |
285 | ||
286 | Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_EX_THIS (This); | |
287 | ||
288 | return EFI_SUCCESS; | |
289 | } | |
290 | ||
291 | ||
292 | ||
293 | /** | |
294 | The function reads the next keystroke from the input device. If | |
295 | there is no pending keystroke the function returns | |
296 | EFI_NOT_READY. If there is a pending keystroke, then | |
297 | KeyData.Key.ScanCode is the EFI scan code defined in Error! | |
298 | Reference source not found. The KeyData.Key.UnicodeChar is the | |
299 | actual printable character or is zero if the key does not | |
300 | represent a printable character (control key, function key, | |
301 | etc.). The KeyData.KeyState is shift state for the character | |
302 | reflected in KeyData.Key.UnicodeChar or KeyData.Key.ScanCode . | |
303 | When interpreting the data from this function, it should be | |
304 | noted that if a class of printable characters that are | |
305 | normally adjusted by shift modifiers (e.g. Shift Key + "f" | |
306 | key) would be presented solely as a KeyData.Key.UnicodeChar | |
307 | without the associated shift state. So in the previous example | |
308 | of a Shift Key + "f" key being pressed, the only pertinent | |
309 | data returned would be KeyData.Key.UnicodeChar with the value | |
310 | of "F". This of course would not typically be the case for | |
311 | non-printable characters such as the pressing of the Right | |
312 | Shift Key + F10 key since the corresponding returned data | |
313 | would be reflected both in the KeyData.KeyState.KeyShiftState | |
314 | and KeyData.Key.ScanCode values. UEFI drivers which implement | |
315 | the EFI_SIMPLE_TEXT_INPUT_EX protocol are required to return | |
316 | KeyData.Key and KeyData.KeyState values. These drivers must | |
317 | always return the most current state of | |
318 | KeyData.KeyState.KeyShiftState and | |
319 | KeyData.KeyState.KeyToggleState. It should also be noted that | |
320 | certain input devices may not be able to produce shift or toggle | |
321 | state information, and in those cases the high order bit in the | |
322 | respective Toggle and Shift state fields should not be active. | |
323 | ||
324 | ||
325 | @param This A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance. | |
326 | ||
327 | @param KeyData A pointer to a buffer that is filled in with | |
328 | the keystroke state data for the key that was | |
329 | pressed. | |
330 | ||
331 | ||
332 | @retval EFI_SUCCESS The keystroke information was | |
333 | returned. | |
334 | ||
335 | @retval EFI_NOT_READY There was no keystroke data available. | |
336 | EFI_DEVICE_ERROR The keystroke | |
337 | information was not returned due to | |
338 | hardware errors. | |
339 | ||
340 | ||
341 | **/ | |
342 | EFI_STATUS | |
343 | EFIAPI | |
344 | UnixGopSimpleTextInExReadKeyStrokeEx ( | |
345 | IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, | |
346 | OUT EFI_KEY_DATA *KeyData | |
347 | ) | |
348 | /*++ | |
349 | ||
350 | Routine Description: | |
351 | Reads the next keystroke from the input device. The WaitForKey Event can | |
352 | be used to test for existance of a keystroke via WaitForEvent () call. | |
353 | ||
354 | Arguments: | |
355 | This - Protocol instance pointer. | |
356 | KeyData - A pointer to a buffer that is filled in with the keystroke | |
357 | state data for the key that was pressed. | |
358 | ||
359 | Returns: | |
360 | EFI_SUCCESS - The keystroke information was returned. | |
361 | EFI_NOT_READY - There was no keystroke data availiable. | |
362 | EFI_DEVICE_ERROR - The keystroke information was not returned due to | |
363 | hardware errors. | |
364 | EFI_INVALID_PARAMETER - KeyData is NULL. | |
365 | ||
366 | --*/ | |
367 | { | |
368 | EFI_STATUS Status; | |
369 | GOP_PRIVATE_DATA *Private; | |
370 | EFI_TPL OldTpl; | |
371 | ||
372 | ||
373 | if (KeyData == NULL) { | |
374 | return EFI_INVALID_PARAMETER; | |
375 | } | |
376 | ||
377 | Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_THIS (This); | |
378 | if (Private->UgaIo == NULL) { | |
379 | return EFI_NOT_READY; | |
380 | } | |
381 | ||
382 | // | |
383 | // Enter critical section | |
384 | // | |
385 | OldTpl = gBS->RaiseTPL (TPL_NOTIFY); | |
386 | ||
387 | Status = Private->UgaIo->UgaGetKey(Private->UgaIo, KeyData); | |
388 | ||
389 | // | |
390 | // Leave critical section and return | |
391 | // | |
392 | gBS->RestoreTPL (OldTpl); | |
393 | ||
394 | return Status; | |
395 | } | |
396 | ||
397 | ||
398 | ||
399 | /** | |
400 | The SetState() function allows the input device hardware to | |
401 | have state settings adjusted. | |
402 | ||
403 | @param This A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance. | |
404 | ||
405 | @param KeyToggleState Pointer to the EFI_KEY_TOGGLE_STATE to | |
406 | set the state for the input device. | |
407 | ||
408 | ||
409 | @retval EFI_SUCCESS The device state was set appropriately. | |
410 | ||
411 | @retval EFI_DEVICE_ERROR The device is not functioning | |
412 | correctly and could not have the | |
413 | setting adjusted. | |
414 | ||
415 | @retval EFI_UNSUPPORTED The device does not support the | |
416 | ability to have its state set. | |
417 | ||
418 | **/ | |
419 | EFI_STATUS | |
420 | EFIAPI | |
421 | UnixGopSimpleTextInExSetState ( | |
422 | IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, | |
423 | IN EFI_KEY_TOGGLE_STATE *KeyToggleState | |
424 | ) | |
425 | { | |
426 | GOP_PRIVATE_DATA *Private; | |
427 | EFI_STATUS Status; | |
428 | EFI_TPL OldTpl; | |
429 | ||
430 | Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_THIS (This); | |
431 | if (Private->UgaIo == NULL) { | |
432 | return EFI_NOT_READY; | |
433 | } | |
434 | ||
435 | // | |
436 | // Enter critical section | |
437 | // | |
438 | OldTpl = gBS->RaiseTPL (TPL_NOTIFY); | |
439 | ||
440 | Status = Private->UgaIo->UgaKeySetState (Private->UgaIo, KeyToggleState); | |
441 | // | |
442 | // Leave critical section and return | |
443 | // | |
444 | gBS->RestoreTPL (OldTpl); | |
445 | ||
446 | return Status; | |
447 | } | |
448 | ||
449 | ||
450 | /** | |
451 | SimpleTextIn and SimpleTextInEx Notify Wait Event | |
452 | ||
453 | @param Event Event whose notification function is being invoked. | |
454 | @param Context Pointer to GOP_PRIVATE_DATA. | |
455 | ||
456 | **/ | |
457 | VOID | |
458 | EFIAPI | |
459 | UnixGopRegisterKeyCallback ( | |
460 | IN EFI_EVENT Event, | |
461 | IN VOID *Context | |
462 | ) | |
463 | { | |
464 | UNIX_GOP_SIMPLE_TEXTIN_EX_NOTIFY *ExNotify = (UNIX_GOP_SIMPLE_TEXTIN_EX_NOTIFY *)Context; | |
465 | ||
466 | ExNotify->KeyNotificationFn (&ExNotify->KeyData); | |
467 | } | |
468 | ||
469 | ||
470 | ||
471 | /** | |
472 | The RegisterKeystrokeNotify() function registers a function | |
473 | which will be called when a specified keystroke will occur. | |
474 | ||
475 | @param This A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance. | |
476 | ||
477 | @param KeyData A pointer to a buffer that is filled in with | |
478 | the keystroke information for the key that was | |
479 | pressed. | |
480 | ||
481 | @param KeyNotificationFunction Points to the function to be | |
482 | called when the key sequence | |
483 | is typed specified by KeyData. | |
484 | ||
485 | ||
486 | @param NotifyHandle Points to the unique handle assigned to | |
487 | the registered notification. | |
488 | ||
489 | @retval EFI_SUCCESS The device state was set | |
490 | appropriately. | |
491 | ||
492 | @retval EFI_OUT_OF_RESOURCES Unable to allocate necessary | |
493 | data structures. | |
494 | ||
495 | **/ | |
496 | EFI_STATUS | |
497 | EFIAPI | |
498 | UnixGopSimpleTextInExRegisterKeyNotify ( | |
499 | IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, | |
500 | IN EFI_KEY_DATA *KeyData, | |
501 | IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction, | |
502 | OUT EFI_HANDLE *NotifyHandle | |
503 | ) | |
504 | { | |
505 | EFI_STATUS Status; | |
506 | GOP_PRIVATE_DATA *Private; | |
507 | UNIX_GOP_SIMPLE_TEXTIN_EX_NOTIFY *CurrentNotify; | |
508 | LIST_ENTRY *Link; | |
509 | UNIX_GOP_SIMPLE_TEXTIN_EX_NOTIFY *NewNotify; | |
510 | ||
511 | if (KeyData == NULL || KeyNotificationFunction == NULL || NotifyHandle == NULL) { | |
512 | return EFI_INVALID_PARAMETER; | |
513 | } | |
514 | ||
515 | Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_EX_THIS (This); | |
516 | ||
517 | // | |
518 | // Return EFI_SUCCESS if the (KeyData, NotificationFunction) is already registered. | |
519 | // | |
520 | for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) { | |
521 | CurrentNotify = CR ( | |
522 | Link, | |
523 | UNIX_GOP_SIMPLE_TEXTIN_EX_NOTIFY, | |
524 | NotifyEntry, | |
525 | UNIX_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE | |
526 | ); | |
527 | if (GopPrivateIsKeyRegistered (&CurrentNotify->KeyData, KeyData)) { | |
528 | if (CurrentNotify->KeyNotificationFn == KeyNotificationFunction) { | |
529 | *NotifyHandle = CurrentNotify->NotifyHandle; | |
530 | return EFI_SUCCESS; | |
531 | } | |
532 | } | |
533 | } | |
534 | ||
535 | // | |
536 | // Allocate resource to save the notification function | |
537 | // | |
538 | NewNotify = (UNIX_GOP_SIMPLE_TEXTIN_EX_NOTIFY *) AllocateZeroPool (sizeof (UNIX_GOP_SIMPLE_TEXTIN_EX_NOTIFY)); | |
539 | if (NewNotify == NULL) { | |
540 | return EFI_OUT_OF_RESOURCES; | |
541 | } | |
542 | ||
543 | NewNotify->Signature = UNIX_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE; | |
544 | NewNotify->KeyNotificationFn = KeyNotificationFunction; | |
545 | NewNotify->NotifyHandle = (EFI_HANDLE) NewNotify; | |
546 | CopyMem (&NewNotify->KeyData, KeyData, sizeof (KeyData)); | |
547 | InsertTailList (&Private->NotifyList, &NewNotify->NotifyEntry); | |
548 | ||
549 | Status = gBS->CreateEvent ( | |
550 | EVT_NOTIFY_SIGNAL, | |
551 | TPL_NOTIFY, | |
552 | UnixGopRegisterKeyCallback, | |
553 | NewNotify, | |
554 | NewNotify->Event | |
555 | ); | |
556 | ASSERT_EFI_ERROR (Status); | |
557 | ||
558 | ||
559 | *NotifyHandle = NewNotify->NotifyHandle; | |
560 | ||
561 | return EFI_SUCCESS; | |
562 | ||
563 | } | |
564 | ||
565 | ||
566 | /** | |
567 | The UnregisterKeystrokeNotify() function removes the | |
568 | notification which was previously registered. | |
569 | ||
570 | @param This A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance. | |
571 | ||
572 | @param NotificationHandle The handle of the notification | |
573 | function being unregistered. | |
574 | ||
575 | @retval EFI_SUCCESS The device state was set appropriately. | |
576 | ||
577 | @retval EFI_INVALID_PARAMETER The NotificationHandle is | |
578 | invalid. | |
579 | ||
580 | **/ | |
581 | EFI_STATUS | |
582 | EFIAPI | |
583 | UnixGopSimpleTextInExUnregisterKeyNotify ( | |
584 | IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, | |
585 | IN EFI_HANDLE NotificationHandle | |
586 | ) | |
587 | /*++ | |
588 | ||
589 | Routine Description: | |
590 | Remove a registered notification function from a particular keystroke. | |
591 | ||
592 | Arguments: | |
593 | This - Protocol instance pointer. | |
594 | NotificationHandle - The handle of the notification function being unregistered. | |
595 | ||
596 | Returns: | |
597 | EFI_SUCCESS - The notification function was unregistered successfully. | |
598 | EFI_INVALID_PARAMETER - The NotificationHandle is invalid. | |
599 | ||
600 | --*/ | |
601 | { | |
602 | GOP_PRIVATE_DATA *Private; | |
603 | LIST_ENTRY *Link; | |
604 | UNIX_GOP_SIMPLE_TEXTIN_EX_NOTIFY *CurrentNotify; | |
605 | ||
606 | if (NotificationHandle == NULL) { | |
607 | return EFI_INVALID_PARAMETER; | |
608 | } | |
609 | ||
610 | if (((UNIX_GOP_SIMPLE_TEXTIN_EX_NOTIFY *) NotificationHandle)->Signature != UNIX_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE) { | |
611 | return EFI_INVALID_PARAMETER; | |
612 | } | |
613 | ||
614 | Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_EX_THIS (This); | |
615 | ||
616 | for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) { | |
617 | CurrentNotify = CR ( | |
618 | Link, | |
619 | UNIX_GOP_SIMPLE_TEXTIN_EX_NOTIFY, | |
620 | NotifyEntry, | |
621 | UNIX_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE | |
622 | ); | |
623 | if (CurrentNotify->NotifyHandle == NotificationHandle) { | |
624 | // | |
625 | // Remove the notification function from NotifyList and free resources | |
626 | // | |
627 | RemoveEntryList (&CurrentNotify->NotifyEntry); | |
628 | ||
629 | gBS->CloseEvent (CurrentNotify->Event); | |
630 | ||
631 | gBS->FreePool (CurrentNotify); | |
632 | return EFI_SUCCESS; | |
633 | } | |
634 | } | |
635 | ||
636 | // | |
637 | // Can not find the specified Notification Handle | |
638 | // | |
639 | return EFI_INVALID_PARAMETER; | |
640 | } | |
641 | ||
642 | ||
643 | ||
644 | /** | |
645 | Initialize SimplelTextIn and SimpleTextInEx protocols in the Private | |
646 | context structure. | |
647 | ||
648 | @param Private Context structure to fill in. | |
649 | ||
650 | @return EFI_SUCCESS Initialization was a success | |
651 | ||
652 | **/ | |
653 | EFI_STATUS | |
654 | UnixGopInitializeSimpleTextInForWindow ( | |
655 | IN GOP_PRIVATE_DATA *Private | |
656 | ) | |
657 | { | |
658 | EFI_STATUS Status; | |
659 | ||
660 | // | |
661 | // Initialize Simple Text In protoocol | |
662 | // | |
663 | Private->SimpleTextIn.Reset = UnixGopSimpleTextInReset; | |
664 | Private->SimpleTextIn.ReadKeyStroke = UnixGopSimpleTextInReadKeyStroke; | |
665 | ||
666 | Status = gBS->CreateEvent ( | |
667 | EVT_NOTIFY_WAIT, | |
668 | TPL_NOTIFY, | |
669 | UnixGopSimpleTextInWaitForKey, | |
670 | Private, | |
671 | &Private->SimpleTextIn.WaitForKey | |
672 | ); | |
673 | ASSERT_EFI_ERROR (Status); | |
674 | ||
675 | ||
676 | // | |
677 | // Initialize Simple Text In Ex | |
678 | // | |
679 | ||
680 | Private->SimpleTextInEx.Reset = UnixGopSimpleTextInExResetEx; | |
681 | Private->SimpleTextInEx.ReadKeyStrokeEx = UnixGopSimpleTextInExReadKeyStrokeEx; | |
682 | Private->SimpleTextInEx.SetState = UnixGopSimpleTextInExSetState; | |
683 | Private->SimpleTextInEx.RegisterKeyNotify = UnixGopSimpleTextInExRegisterKeyNotify; | |
684 | Private->SimpleTextInEx.UnregisterKeyNotify = UnixGopSimpleTextInExUnregisterKeyNotify; | |
685 | ||
686 | Private->SimpleTextInEx.Reset (&Private->SimpleTextInEx, FALSE); | |
687 | ||
688 | InitializeListHead (&Private->NotifyList); | |
689 | ||
690 | Status = gBS->CreateEvent ( | |
691 | EVT_NOTIFY_WAIT, | |
692 | TPL_NOTIFY, | |
693 | UnixGopSimpleTextInWaitForKey, | |
694 | Private, | |
695 | &Private->SimpleTextInEx.WaitForKeyEx | |
696 | ); | |
697 | ASSERT_EFI_ERROR (Status); | |
698 | ||
699 | ||
700 | return Status; | |
701 | } | |
702 | ||
703 | ||
704 | ||
705 | ||
706 | ||
707 | ||
708 | ||
709 | // | |
710 | // Simple Pointer implementation. | |
711 | // | |
712 | ||
713 | ||
714 | /** | |
715 | Resets the pointer device hardware. | |
716 | ||
717 | @param This A pointer to the EFI_SIMPLE_POINTER_PROTOCOL | |
718 | instance. | |
719 | @param ExtendedVerification Indicates that the driver may perform a more exhaustive | |
720 | verification operation of the device during reset. | |
721 | ||
722 | @retval EFI_SUCCESS The device was reset. | |
723 | @retval EFI_DEVICE_ERROR The device is not functioning correctly and could not be reset. | |
724 | ||
725 | **/ | |
726 | EFI_STATUS | |
727 | EFIAPI | |
728 | UnixGopSimplePointerReset ( | |
729 | IN EFI_SIMPLE_POINTER_PROTOCOL *This, | |
730 | IN BOOLEAN ExtendedVerification | |
731 | ) | |
732 | { | |
733 | GOP_PRIVATE_DATA *Private; | |
734 | EFI_SIMPLE_POINTER_STATE State; | |
735 | EFI_TPL OldTpl; | |
736 | ||
737 | Private = GOP_PRIVATE_DATA_FROM_POINTER_MODE_THIS (This); | |
738 | if (Private->UgaIo == NULL) { | |
739 | return EFI_SUCCESS; | |
740 | } | |
741 | ||
742 | // | |
743 | // Enter critical section | |
744 | // | |
745 | OldTpl = gBS->RaiseTPL (TPL_NOTIFY); | |
746 | ||
747 | // | |
748 | // A reset is draining the Queue | |
749 | // | |
750 | while (Private->UgaIo->UgaGetPointerState (Private->UgaIo, &State) == EFI_SUCCESS) | |
751 | ; | |
752 | ||
753 | // | |
754 | // Leave critical section and return | |
755 | // | |
756 | gBS->RestoreTPL (OldTpl); | |
757 | return EFI_SUCCESS; | |
758 | } | |
759 | ||
760 | ||
761 | /** | |
762 | Retrieves the current state of a pointer device. | |
763 | ||
764 | @param This A pointer to the EFI_SIMPLE_POINTER_PROTOCOL | |
765 | instance. | |
766 | @param State A pointer to the state information on the pointer device. | |
767 | ||
768 | @retval EFI_SUCCESS The state of the pointer device was returned in State. | |
769 | @retval EFI_NOT_READY The state of the pointer device has not changed since the last call to | |
770 | GetState(). | |
771 | @retval EFI_DEVICE_ERROR A device error occurred while attempting to retrieve the pointer device's | |
772 | current state. | |
773 | ||
774 | **/ | |
775 | EFI_STATUS | |
776 | EFIAPI | |
777 | UnixGopSimplePointerGetState ( | |
778 | IN EFI_SIMPLE_POINTER_PROTOCOL *This, | |
779 | IN OUT EFI_SIMPLE_POINTER_STATE *State | |
780 | ) | |
781 | { | |
782 | GOP_PRIVATE_DATA *Private; | |
783 | EFI_STATUS Status; | |
784 | EFI_TPL OldTpl; | |
785 | ||
786 | Private = GOP_PRIVATE_DATA_FROM_POINTER_MODE_THIS (This); | |
787 | if (Private->UgaIo == NULL) { | |
788 | return EFI_NOT_READY; | |
789 | } | |
790 | ||
791 | // | |
792 | // Enter critical section | |
793 | // | |
794 | OldTpl = gBS->RaiseTPL (TPL_NOTIFY); | |
795 | ||
796 | Status = Private->UgaIo->UgaGetPointerState (Private->UgaIo, State); | |
797 | // | |
798 | // Leave critical section and return | |
799 | // | |
800 | gBS->RestoreTPL (OldTpl); | |
801 | ||
802 | return Status; | |
803 | } | |
804 | ||
805 | ||
806 | /** | |
807 | SimplePointer Notify Wait Event | |
808 | ||
809 | @param Event Event whose notification function is being invoked. | |
810 | @param Context Pointer to GOP_PRIVATE_DATA. | |
811 | ||
812 | **/ | |
813 | VOID | |
814 | EFIAPI | |
815 | UnixGopSimplePointerWaitForInput ( | |
816 | IN EFI_EVENT Event, | |
817 | IN VOID *Context | |
818 | ) | |
819 | { | |
820 | GOP_PRIVATE_DATA *Private; | |
821 | EFI_STATUS Status; | |
822 | EFI_TPL OldTpl; | |
823 | ||
824 | Private = (GOP_PRIVATE_DATA *) Context; | |
825 | if (Private->UgaIo == NULL) { | |
826 | return; | |
827 | } | |
828 | ||
829 | // | |
830 | // Enter critical section | |
831 | // | |
832 | OldTpl = gBS->RaiseTPL (TPL_NOTIFY); | |
833 | ||
834 | Status = Private->UgaIo->UgaCheckPointer (Private->UgaIo); | |
835 | if (!EFI_ERROR (Status)) { | |
836 | // | |
837 | // If the pointer state has changed, signal our event. | |
838 | // | |
839 | gBS->SignalEvent (Event); | |
840 | } | |
841 | // | |
842 | // Leave critical section and return | |
843 | // | |
844 | gBS->RestoreTPL (OldTpl); | |
845 | } | |
846 | ||
847 | ||
848 | /** | |
849 | SimplePointer constructor | |
850 | ||
851 | @param Private Context structure to fill in. | |
852 | ||
853 | @retval EFI_SUCCESS Constructor had success | |
854 | ||
855 | **/ | |
856 | EFI_STATUS | |
857 | UnixGopInitializeSimplePointerForWindow ( | |
858 | IN GOP_PRIVATE_DATA *Private | |
859 | ) | |
860 | { | |
861 | EFI_STATUS Status; | |
862 | ||
863 | // | |
864 | // Initialize Simple Pointer protoocol | |
865 | // | |
866 | Private->PointerMode.ResolutionX = 1; | |
867 | Private->PointerMode.ResolutionY = 1; | |
868 | Private->PointerMode.ResolutionZ = 1; | |
869 | Private->PointerMode.LeftButton = TRUE; | |
870 | Private->PointerMode.RightButton = TRUE; | |
871 | ||
872 | Private->SimplePointer.Reset = UnixGopSimplePointerReset; | |
873 | Private->SimplePointer.GetState = UnixGopSimplePointerGetState; | |
874 | Private->SimplePointer.Mode = &Private->PointerMode; | |
875 | ||
876 | Status = gBS->CreateEvent ( | |
877 | EVT_NOTIFY_WAIT, | |
878 | TPL_NOTIFY, | |
879 | UnixGopSimplePointerWaitForInput, | |
880 | Private, | |
881 | &Private->SimplePointer.WaitForInput | |
882 | ); | |
883 | ||
884 | return Status; | |
885 | } |