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
47 lines
1.4 KiB
C
47 lines
1.4 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.
|
|
*
|
|
*/
|
|
|
|
#ifndef __LIB_UEFI_EVENTS_H_
|
|
#define __LIB_UEFI_EVENTS_H_
|
|
#include <kernel/event.h>
|
|
#include <kernel/thread.h>
|
|
#include <uefi/types.h>
|
|
|
|
struct EfiEventImpl final {
|
|
EfiEventType type;
|
|
event_t ev;
|
|
EfiEventNotify notify_fn = nullptr;
|
|
void *notify_ctx = nullptr;
|
|
volatile bool callback_called = false;
|
|
thread_t *creator_thread = nullptr;
|
|
bool ready() const { return ev.signaled; }
|
|
};
|
|
|
|
EfiStatus wait_for_event(size_t num_events, EfiEvent *event, size_t *index);
|
|
|
|
EfiStatus signal_event(EfiEvent event);
|
|
|
|
EfiStatus check_event(EfiEvent event);
|
|
|
|
EfiStatus create_event(EfiEventType type, EfiTpl notify_tpl,
|
|
EfiEventNotify notify_fn, void *notify_ctx,
|
|
EfiEvent *event);
|
|
|
|
EfiStatus close_event(EfiEvent event);
|
|
|
|
#endif
|