]> git.proxmox.com Git - mirror_edk2.git/blob - EdkUnixPkg/Dxe/UnixThunk/Bus/Uga/UnixUgaInput.c
Unix version of EFI emulator
[mirror_edk2.git] / EdkUnixPkg / Dxe / UnixThunk / Bus / Uga / UnixUgaInput.c
1 /*++
2
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 UnixUgaInput.c
15
16 Abstract:
17
18 This file produces the Simple Text In for an Uga window.
19
20 This stuff is linked at the hip to the Window, since the window
21 processing is done in a thread kicked off in UnixUgaImplementation.c
22
23 Since the window information is processed in an other thread we need
24 a keyboard Queue to pass data about. The Simple Text In code just
25 takes data off the Queue. The WinProc message loop takes keyboard input
26 and places it in the Queue.
27
28 --*/
29
30 #include "UnixUga.h"
31
32 //
33 // Simple Text In implementation.
34 //
35
36 EFI_STATUS
37 EFIAPI
38 UnixUgaSimpleTextInReset (
39 IN EFI_SIMPLE_TEXT_IN_PROTOCOL *This,
40 IN BOOLEAN ExtendedVerification
41 )
42 /*++
43
44 Routine Description:
45
46 TODO: Add function description
47
48 Arguments:
49
50 This - TODO: add argument description
51 ExtendedVerification - TODO: add argument description
52
53 Returns:
54
55 EFI_SUCCESS - TODO: Add description for return value
56
57 --*/
58 {
59 UGA_PRIVATE_DATA *Private;
60 EFI_INPUT_KEY Key;
61 EFI_TPL OldTpl;
62
63 Private = UGA_PRIVATE_DATA_FROM_TEXT_IN_THIS (This);
64 if (Private->UgaIo == NULL) {
65 return EFI_SUCCESS;
66 }
67
68 //
69 // Enter critical section
70 //
71 OldTpl = gBS->RaiseTPL (EFI_TPL_NOTIFY);
72
73 //
74 // A reset is draining the Queue
75 //
76 while (Private->UgaIo->UgaGetKey(Private->UgaIo, &Key) == EFI_SUCCESS)
77 ;
78
79 //
80 // Leave critical section and return
81 //
82 gBS->RestoreTPL (OldTpl);
83 return EFI_SUCCESS;
84 }
85
86 STATIC
87 EFI_STATUS
88 EFIAPI
89 UnixUgaSimpleTextInReadKeyStroke (
90 IN EFI_SIMPLE_TEXT_IN_PROTOCOL *This,
91 OUT EFI_INPUT_KEY *Key
92 )
93 /*++
94
95 Routine Description:
96
97 TODO: Add function description
98
99 Arguments:
100
101 This - TODO: add argument description
102 Key - TODO: add argument description
103
104 Returns:
105
106 TODO: add return values
107
108 --*/
109 {
110 UGA_PRIVATE_DATA *Private;
111 EFI_STATUS Status;
112 EFI_TPL OldTpl;
113
114 Private = UGA_PRIVATE_DATA_FROM_TEXT_IN_THIS (This);
115 if (Private->UgaIo == NULL) {
116 return EFI_NOT_READY;
117 }
118
119 //
120 // Enter critical section
121 //
122 OldTpl = gBS->RaiseTPL (EFI_TPL_NOTIFY);
123
124 Status = Private->UgaIo->UgaGetKey(Private->UgaIo, Key);
125 //
126 // Leave critical section and return
127 //
128 gBS->RestoreTPL (OldTpl);
129
130 return Status;
131 }
132
133 STATIC
134 VOID
135 EFIAPI
136 UnixUgaSimpleTextInWaitForKey (
137 IN EFI_EVENT Event,
138 IN VOID *Context
139 )
140 /*++
141
142 Routine Description:
143
144 TODO: Add function description
145
146 Arguments:
147
148 Event - TODO: add argument description
149 Context - TODO: add argument description
150
151 Returns:
152
153 TODO: add return values
154
155 --*/
156 {
157 UGA_PRIVATE_DATA *Private;
158 EFI_STATUS Status;
159 EFI_TPL OldTpl;
160
161 Private = (UGA_PRIVATE_DATA *) Context;
162 if (Private->UgaIo == NULL) {
163 return;
164 }
165
166 //
167 // Enter critical section
168 //
169 OldTpl = gBS->RaiseTPL (EFI_TPL_NOTIFY);
170
171 Status = Private->UgaIo->UgaCheckKey(Private->UgaIo);
172 if (!EFI_ERROR (Status)) {
173 //
174 // If a there is a key in the queue signal our event.
175 //
176 gBS->SignalEvent (Event);
177 }
178 //
179 // Leave critical section and return
180 //
181 gBS->RestoreTPL (OldTpl);
182 }
183
184 EFI_STATUS
185 UnixUgaInitializeSimpleTextInForWindow (
186 IN UGA_PRIVATE_DATA *Private
187 )
188 /*++
189
190 Routine Description:
191
192 TODO: Add function description
193
194 Arguments:
195
196 Private - TODO: add argument description
197
198 Returns:
199
200 TODO: add return values
201
202 --*/
203 {
204 EFI_STATUS Status;
205
206 //
207 // Initialize Simple Text In protoocol
208 //
209 Private->SimpleTextIn.Reset = UnixUgaSimpleTextInReset;
210 Private->SimpleTextIn.ReadKeyStroke = UnixUgaSimpleTextInReadKeyStroke;
211
212 Status = gBS->CreateEvent (
213 EFI_EVENT_NOTIFY_WAIT,
214 EFI_TPL_NOTIFY,
215 UnixUgaSimpleTextInWaitForKey,
216 Private,
217 &Private->SimpleTextIn.WaitForKey
218 );
219
220 return Status;
221 }