Files
lk/lib/uefi/io_stack.h
Kelvin Zhang e8cea74e9b [lib][uefi] Implement events API in UEFI
LK already has events APIs. To support events protocols in UEFI spec,
I created a wrapper object for LK events. This wrapper object keeps
additional data that are necessary to support UEFI events spec:

* Notification function, or callbacks
* Argument for the notification function
* Type of this UEFI event (which specifies when the callback should be
  called)

The events API is essential for supporting async I/O in UEFI. Intended
use case looks like:

* UEFI app creates an event object, attatch callback to this event
* UEFI app calls LK for asynchronous read/write on a block device, with
  the newly created events object
* LK executes IO operation in background, after IO finishes, signal the
  specified event object
* UEFI's callback gets executed
2025-07-16 14:00:00 -07:00

66 lines
2.3 KiB
C++

/*
* Copyright (C) 2025 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include <stddef.h>
#include <uefi/types.h>
#include "switch_stack.h"
constexpr size_t kIoStackSize = 1024ul * 32;
void* get_io_stack();
template <typename Arg1, EfiStatus (*Func)(Arg1)>
EfiStatus (*switch_stack_wrapper())(Arg1 arg) {
auto trampoline = [](Arg1 arg) -> EfiStatus {
void* io_stack = reinterpret_cast<char*>(get_io_stack()) + kIoStackSize;
return static_cast<EfiStatus>(call_with_stack(io_stack, Func, arg));
};
return trampoline;
}
template <typename Arg1, typename Arg2, EfiStatus (*Func)(Arg1, Arg2)>
EfiStatus (*switch_stack_wrapper())(Arg1 arg1, Arg2 arg2) {
auto trampoline = [](Arg1 arg1, Arg2 arg2) -> EfiStatus {
void* io_stack = reinterpret_cast<char*>(get_io_stack()) + kIoStackSize;
return static_cast<EfiStatus>(call_with_stack(io_stack, Func, arg1, arg2));
};
return trampoline;
}
template <typename Arg1, typename Arg2, typename Arg3,
EfiStatus (*Func)(Arg1, Arg2, Arg3)>
EfiStatus (*switch_stack_wrapper())(Arg1 arg1, Arg2 arg2, Arg3 arg3) {
auto trampoline = [](Arg1 arg1, Arg2 arg2, Arg3 arg3) -> EfiStatus {
void* io_stack = reinterpret_cast<char*>(get_io_stack()) + kIoStackSize;
return static_cast<EfiStatus>(
call_with_stack(io_stack, Func, arg1, arg2, arg3));
};
return trampoline;
}
template <typename Arg1, typename Arg2, typename Arg3, typename Arg4,
EfiStatus (*Func)(Arg1, Arg2, Arg3, Arg4)>
EfiStatus (*switch_stack_wrapper())(Arg1, Arg2, Arg3, Arg4) {
auto trampoline = [](Arg1 arg1, Arg2 arg2, Arg3 arg3,
Arg4 arg4) -> EfiStatus {
void* io_stack = reinterpret_cast<char*>(get_io_stack()) + kIoStackSize;
return static_cast<EfiStatus>(
call_with_stack(io_stack, Func, arg1, arg2, arg3, arg4));
};
return trampoline;
}