aboutsummaryrefslogtreecommitdiffstats
path: root/UefiLessonsPkg
diff options
context:
space:
mode:
Diffstat (limited to 'UefiLessonsPkg')
-rw-r--r--UefiLessonsPkg/ProtocolEventDriver/ProtocolEventDriver.c99
-rw-r--r--UefiLessonsPkg/ProtocolEventDriver/ProtocolEventDriver.inf28
-rw-r--r--UefiLessonsPkg/UefiLessonsPkg.dsc1
3 files changed, 128 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
diff --git a/UefiLessonsPkg/UefiLessonsPkg.dsc b/UefiLessonsPkg/UefiLessonsPkg.dsc
index d0cc2df..970b5a6 100644
--- a/UefiLessonsPkg/UefiLessonsPkg.dsc
+++ b/UefiLessonsPkg/UefiLessonsPkg.dsc
@@ -93,6 +93,7 @@
UefiLessonsPkg/SetSku/SetSku.inf
UefiLessonsPkg/HiddenSettings/HiddenSettings.inf
UefiLessonsPkg/ShowHIIext/ShowHIIext.inf
+ UefiLessonsPkg/ProtocolEventDriver/ProtocolEventDriver.inf
#[PcdsFixedAtBuild]
# gUefiLessonsPkgTokenSpaceGuid.PcdInt8|0x88|UINT8|0x3B81CDF1