45 IN UINT64 InitialDelay,
46 IN UINT64 SubsequentDelay,
47 IN BOOLEAN PreventInitialRepeat
57 if (*Context == NULL) {
58 DEBUG ((DEBUG_ERROR,
"OCKM: Cannot allocate repeat context\n"));
59 return EFI_OUT_OF_RESOURCES;
62 if (MaxKeysHeld == 0) {
63 (*Context)->KeysHeld = NULL;
65 DEBUG ((
OC_TRACE_UPDOWNKEYS,
"OCKM: Allocating %d for keys held\n", MaxKeysHeld *
sizeof ((*Context)->KeysHeld[0])));
66 (*Context)->KeysHeld = AllocatePool (MaxKeysHeld *
sizeof ((*Context)->KeysHeld[0]));
67 if ((*Context)->KeysHeld == NULL) {
68 DEBUG ((DEBUG_ERROR,
"OCKM: Cannot allocate keys held\n"));
71 return EFI_OUT_OF_RESOURCES;
74 DEBUG ((
OC_TRACE_UPDOWNKEYS,
"OCKM: Allocating %d for key held times\n", MaxKeysHeld *
sizeof ((*Context)->KeyHeldTimes[0])));
75 (*Context)->KeyHeldTimes = AllocatePool (MaxKeysHeld *
sizeof ((*Context)->KeyHeldTimes[0]));
76 if ((*Context)->KeyHeldTimes == NULL) {
77 DEBUG ((DEBUG_ERROR,
"OCKM: Cannot allocate key held times\n"));
78 FreePool ((*Context)->KeysHeld);
81 return EFI_OUT_OF_RESOURCES;
85 (*Context)->KeyMap = KeyMap;
87 (*Context)->NumKeysHeld = 0;
88 (*Context)->MaxKeysHeld = MaxKeysHeld;
90 (*Context)->InitialDelay = InitialDelay;
91 (*Context)->SubsequentDelay = SubsequentDelay;
92 (*Context)->PreviousTime = 0;
94 if ((MaxKeysHeld == 0) || (PreventInitialRepeat == FALSE)) {
100 NumKeysDown = MaxKeysHeld;
112 if (EFI_ERROR (Status)) {
113 DEBUG ((DEBUG_ERROR,
"OCKM: InitKeyRepeatContext initial GetUpDownKeys call - %r\n", Status));
119 DEBUG ((DEBUG_INFO,
"OCKM: Allocated key repeat context %p %p %p\n", *Context, (*Context)->KeysHeld, (*Context)->KeyHeldTimes));
129 IN OUT UINTN *NumKeysUp,
131 IN OUT UINTN *NumKeysDown,
133 IN UINT64 CurrentTime
139 UINTN NumKeysHeldInCopy;
140 UINTN MaxKeysHeldInCopy;
148 BOOLEAN FoundHeldKey;
150 ASSERT (Modifiers != NULL);
151 ASSERT (NumKeysUp != NULL);
152 ASSERT (NumKeysDown != NULL);
153 ASSERT (RepeatContext != NULL);
154 ASSERT (RepeatContext->KeyMap != NULL);
155 ASSERT (RepeatContext->NumKeysHeld <= RepeatContext->MaxKeysHeld);
157 ASSERT_EQUALS (RepeatContext->KeysHeld == NULL, RepeatContext->KeyHeldTimes == NULL);
159 DeltaTime = CurrentTime - RepeatContext->PreviousTime;
160 RepeatContext->PreviousTime = CurrentTime;
162 if (RepeatContext->KeysHeld != NULL) {
166 if ((KeysUp != NULL) && (RepeatContext->MaxKeysHeld > *NumKeysUp)) {
167 DEBUG ((DEBUG_ERROR,
"OCKM: MaxKeysHeld %d exceeds NumKeysUp %d\n", RepeatContext->MaxKeysHeld, *NumKeysUp));
168 return EFI_UNSUPPORTED;
175 if ((KeysDown != NULL) && (*NumKeysDown > RepeatContext->MaxKeysHeld)) {
176 DEBUG ((DEBUG_ERROR,
"OCKM: Number of keys requested %d exceeds MaxKeysHeld %d\n", *NumKeysDown, RepeatContext->MaxKeysHeld));
177 return EFI_UNSUPPORTED;
183 MaxKeysHeldInCopy =
ARRAY_SIZE (KeysHeldCopy);
184 if (RepeatContext->MaxKeysHeld > MaxKeysHeldInCopy) {
185 DEBUG ((DEBUG_ERROR,
"OCKM: MaxKeysHeld %d exceeds supported copy space %d\n", RepeatContext->MaxKeysHeld, MaxKeysHeldInCopy));
186 return EFI_UNSUPPORTED;
189 CopyMem (KeysHeldCopy, RepeatContext->KeysHeld, RepeatContext->NumKeysHeld * sizeof (RepeatContext->KeysHeld[0]));
190 CopyMem (KeyHeldTimesCopy, RepeatContext->KeyHeldTimes, RepeatContext->NumKeysHeld * sizeof (RepeatContext->KeyHeldTimes[0]));
191 NumKeysHeldInCopy = RepeatContext->NumKeysHeld;
193 NumKeysHeldInCopy = 0;
197 if (*NumKeysDown > NumRawKeys) {
198 DEBUG ((DEBUG_ERROR,
"OCKM: Number of keys requested %d exceeds supported raw key bufsize %d\n", *NumKeysDown, NumRawKeys));
199 return EFI_UNSUPPORTED;
202 Status = RepeatContext->KeyMap->GetKeyStrokes (
203 RepeatContext->KeyMap,
209 if (EFI_ERROR (Status)) {
213 if ((KeysDown != NULL) && (NumRawKeys > *NumKeysDown)) {
214 return EFI_BUFFER_TOO_SMALL;
217 DEBUG ((
OC_TRACE_UPDOWNKEYS,
"OCKM: [%p] %ld %ld %ld\n", RepeatContext, RepeatContext->InitialDelay, RepeatContext->SubsequentDelay, DeltaTime));
218 DEBUG ((
OC_TRACE_UPDOWNKEYS,
"OCKM: [%p] I u:%d d:%d n:%d h:%d r:%d m:%d\n", RepeatContext, *NumKeysUp, *NumKeysDown, RepeatContext->MaxKeysHeld, RepeatContext->NumKeysHeld, NumRawKeys, *Modifiers));
222 RepeatContext->NumKeysHeld = 0;
227 for (Index = 0; Index < NumRawKeys; ++Index) {
228 Key = RawKeys[Index];
229 if (RepeatContext->KeysHeld != NULL) {
230 RepeatContext->KeysHeld[RepeatContext->NumKeysHeld] = Key;
233 FoundHeldKey = FALSE;
234 for (Index2 = 0; Index2 < NumKeysHeldInCopy; Index2++) {
235 if (KeysHeldCopy[Index2] == Key) {
237 KeyTime = KeyHeldTimesCopy[Index2] + DeltaTime;
238 KeysHeldCopy[Index2] = 0;
239 DEBUG ((
OC_TRACE_UPDOWNKEYS,
"OCKM: [%p] Still down 0x%X %ld\n", RepeatContext, Key, KeyTime));
240 if ((RepeatContext->InitialDelay != 0) && (KeyTime >= 0)) {
241 if (KeysDown != NULL) {
242 KeysDown[*NumKeysDown] = Key;
246 KeyTime -= RepeatContext->SubsequentDelay;
247 DEBUG ((
OC_TRACE_UPDOWNKEYS,
"OCKM: [%p] Repeating 0x%X %ld\n", RepeatContext, Key, KeyTime));
255 if (KeysDown != NULL) {
256 KeysDown[*NumKeysDown] = Key;
260 KeyTime = -(INT64)RepeatContext->InitialDelay;
261 DEBUG ((
OC_TRACE_UPDOWNKEYS,
"OCKM: [%p] New down 0x%X %ld\n", RepeatContext, Key, KeyTime));
264 if (RepeatContext->KeysHeld != NULL) {
265 RepeatContext->KeyHeldTimes[RepeatContext->NumKeysHeld] = KeyTime;
266 RepeatContext->NumKeysHeld++;
273 for (Index = 0; Index < NumKeysHeldInCopy; Index++) {
274 Key = KeysHeldCopy[Index];
276 DEBUG ((
OC_TRACE_UPDOWNKEYS,
"OCKM: [%p] Gone up 0x%X %ld\n", RepeatContext, Key, KeyHeldTimesCopy[Index]));
277 if (KeysUp != NULL) {
278 KeysUp[*NumKeysUp] = Key;
285 DEBUG ((
OC_TRACE_UPDOWNKEYS,
"OCKM: [%p] O u:%d d:%d n:%d h:%d r:%d\n", RepeatContext, *NumKeysUp, *NumKeysDown, RepeatContext->MaxKeysHeld, RepeatContext->NumKeysHeld, NumRawKeys));