diff options
author | Konstantin Aladyshev <aladyshev22@gmail.com> | 2024-02-12 16:21:34 +0300 |
---|---|---|
committer | Konstantin Aladyshev <aladyshev22@gmail.com> | 2024-02-12 16:21:34 +0300 |
commit | 505dad17d2216fab0342afb5794f300a949dd4c8 (patch) | |
tree | a0f1cd8e247f30e0bd8a988739f894e78353d4c2 /UefiLessonsPkg/ProtocolEventDriver | |
parent | f06fa2232b871dde41da965eace6fb3702a8ddca (diff) | |
download | UEFI-Lessons-505dad17d2216fab0342afb5794f300a949dd4c8.tar.gz UEFI-Lessons-505dad17d2216fab0342afb5794f300a949dd4c8.tar.bz2 UEFI-Lessons-505dad17d2216fab0342afb5794f300a949dd4c8.zip |
Add protocol installation callbacks lesson
Signed-off-by: Konstantin Aladyshev <aladyshev22@gmail.com>
Diffstat (limited to 'UefiLessonsPkg/ProtocolEventDriver')
-rw-r--r-- | UefiLessonsPkg/ProtocolEventDriver/ProtocolEventDriver.c | 99 | ||||
-rw-r--r-- | UefiLessonsPkg/ProtocolEventDriver/ProtocolEventDriver.inf | 28 |
2 files changed, 127 insertions, 0 deletions
diff --git a/UefiLessonsPkg/ProtocolEventDriver/ProtocolEventDriver.c b/UefiLessonsPkg/ProtocolEventDriver/ProtocolEventDriver.c new file mode 100644 index 0000000..02ed0f9 --- /dev/null +++ b/UefiLessonsPkg/ProtocolEventDriver/ProtocolEventDriver.c @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2024, Konstantin Aladyshev <aladyshev22@gmail.com> + * + * SPDX-License-Identifier: MIT + */ + +#include <Library/UefiBootServicesTableLib.h> +#include <Library/UefiLib.h> + +#include <Protocol/SimpleClass.h> + +EFI_EVENT Event; +STATIC VOID *mRegistrationTracker; +UINTN NotifyData = 0; + +VOID EFIAPI NotifyFunc(EFI_EVENT Event, VOID* Context) +{ + if (Context == NULL) + return; + + Print(L"\nEvent is signaled! Context = %d\n", *(UINTN*)Context); + *(UINTN*)Context += 1; + + SIMPLE_CLASS_PROTOCOL* SimpleClass; + EFI_STATUS Status; + Status = gBS->LocateProtocol(&gSimpleClassProtocolGuid, + // NULL, + mRegistrationTracker, + (VOID**)&SimpleClass); + if (EFI_ERROR(Status)) { + Print(L"Error! LocateProtocol returned: %r\n", Status); + return; + } + + UINTN Number; + Status = SimpleClass->GetNumber(&Number); + if (!EFI_ERROR(Status)) { + Print(L"Current number = %d\n", Number); + } else { + Print(L"Error! Can't get number: %r\n", Status); + return; + } + + Status = SimpleClass->SetNumber(Number+5); + if (EFI_ERROR(Status)) { + Print(L"Error! Can't set number: %r\n", Status); + return; + } +} + + +EFI_STATUS +EFIAPI +ProtocolEventDriverUnload ( + EFI_HANDLE ImageHandle + ) +{ + gBS->CloseEvent(Event); + + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +ProtocolEventDriverEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + + EFI_STATUS Status; + + Status = gBS->CreateEvent(EVT_NOTIFY_SIGNAL, + TPL_NOTIFY, + &NotifyFunc, + &NotifyData, + &Event); + if (EFI_ERROR(Status)) { + Print(L"Error! CreateEvent returned: %r\n", Status); + return Status; + } + + Status = gBS->RegisterProtocolNotify(&gSimpleClassProtocolGuid, + Event, + &mRegistrationTracker); + if (EFI_ERROR(Status)) { + Print(L"Error! RegisterProtocolNotify returned: %r\n", Status); + return Status; + } + +/* + Event = EfiCreateProtocolNotifyEvent(&gSimpleClassProtocolGuid, + TPL_NOTIFY, + &NotifyFunc, + &NotifyData, + &mRegistrationTracker); +*/ + return EFI_SUCCESS; +} diff --git a/UefiLessonsPkg/ProtocolEventDriver/ProtocolEventDriver.inf b/UefiLessonsPkg/ProtocolEventDriver/ProtocolEventDriver.inf new file mode 100644 index 0000000..b05651f --- /dev/null +++ b/UefiLessonsPkg/ProtocolEventDriver/ProtocolEventDriver.inf @@ -0,0 +1,28 @@ +## +# Copyright (c) 2024, Konstantin Aladyshev <aladyshev22@gmail.com> +# +# SPDX-License-Identifier: MIT +## + +[Defines] + INF_VERSION = 1.25 + BASE_NAME = ProtocolEventDriver + FILE_GUID = 0b59d62a-3250-42eb-9859-364faf5bc9c8 + MODULE_TYPE = UEFI_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = ProtocolEventDriverEntryPoint + UNLOAD_IMAGE = ProtocolEventDriverUnload + +[Sources] + ProtocolEventDriver.c + +[Packages] + MdePkg/MdePkg.dec + UefiLessonsPkg/UefiLessonsPkg.dec + +[LibraryClasses] + UefiDriverEntryPoint + UefiLib + +[Protocols] + gSimpleClassProtocolGuid |