aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonstantin Aladyshev <aladyshev22@gmail.com>2021-07-12 15:28:51 +0300
committerKonstantin Aladyshev <aladyshev22@gmail.com>2021-07-12 15:34:20 +0300
commitea49e59ed0fc50085716e55d66395b6afef8a554 (patch)
tree91089f5b20ede7ee53f7f613b2d5eb72a23a1017
parentf980e8c1e946285a212fad287164b0c9ef3b1625 (diff)
downloadUEFI-Lessons-ea49e59ed0fc50085716e55d66395b6afef8a554.tar.gz
UEFI-Lessons-ea49e59ed0fc50085716e55d66395b6afef8a554.tar.bz2
UEFI-Lessons-ea49e59ed0fc50085716e55d66395b6afef8a554.zip
Update UefiLessonsPkg
Signed-off-by: Konstantin Aladyshev <aladyshev22@gmail.com>
-rw-r--r--UefiLessonsPkg/Include/Library/SimpleLibrary.h2
-rw-r--r--UefiLessonsPkg/Include/Protocol/SimpleClass.h28
-rw-r--r--UefiLessonsPkg/Library/SimpleLibrary/SimpleLibrary.c5
-rw-r--r--UefiLessonsPkg/Library/SimpleLibrary/SimpleLibrary.inf15
-rw-r--r--UefiLessonsPkg/Library/SimpleLibraryWithConstructor/SimpleLibraryWithConstructor.c18
-rw-r--r--UefiLessonsPkg/Library/SimpleLibraryWithConstructor/SimpleLibraryWithConstructor.inf16
-rw-r--r--UefiLessonsPkg/Library/SimpleLibraryWithConstructorAndDestructor/SimpleLibraryWithConstructorAndDestructor.c28
-rw-r--r--UefiLessonsPkg/Library/SimpleLibraryWithConstructorAndDestructor/SimpleLibraryWithConstructorAndDestructor.inf17
-rw-r--r--UefiLessonsPkg/ListPCI/ListPCI.c25
-rw-r--r--UefiLessonsPkg/PCIRomInfo/PCIRomInfo.c380
-rw-r--r--UefiLessonsPkg/PCIRomInfo/PCIRomInfo.inf (renamed from UefiLessonsPkg/ShowHii/ShowHii.inf)12
-rw-r--r--UefiLessonsPkg/ShowHii/ShowHii.c120
-rw-r--r--UefiLessonsPkg/SimpleClassProtocol/SimpleClassProtocol.c84
-rw-r--r--UefiLessonsPkg/SimpleClassProtocol/SimpleClassProtocol.inf23
-rw-r--r--UefiLessonsPkg/SimpleClassUser/SimpleClassUser.c67
-rw-r--r--UefiLessonsPkg/SimpleClassUser/SimpleClassUser.inf22
-rw-r--r--UefiLessonsPkg/SimpleLibraryUser/SimpleLibraryUser.c16
-rw-r--r--UefiLessonsPkg/SimpleLibraryUser/SimpleLibraryUser.inf20
18 files changed, 760 insertions, 138 deletions
diff --git a/UefiLessonsPkg/Include/Library/SimpleLibrary.h b/UefiLessonsPkg/Include/Library/SimpleLibrary.h
new file mode 100644
index 0000000..105bc87
--- /dev/null
+++ b/UefiLessonsPkg/Include/Library/SimpleLibrary.h
@@ -0,0 +1,2 @@
+UINTN Plus2(UINTN number);
+
diff --git a/UefiLessonsPkg/Include/Protocol/SimpleClass.h b/UefiLessonsPkg/Include/Protocol/SimpleClass.h
new file mode 100644
index 0000000..4ccf629
--- /dev/null
+++ b/UefiLessonsPkg/Include/Protocol/SimpleClass.h
@@ -0,0 +1,28 @@
+#ifndef __SIMPLE_CLASS_PROTOCOL_H__
+#define __SIMPLE_CLASS_PROTOCOL_H__
+
+
+typedef struct _SIMPLE_CLASS_PROTOCOL SIMPLE_CLASS_PROTOCOL;
+
+typedef
+EFI_STATUS
+(EFIAPI* SIMPLE_CLASS_GET_NUMBER)(
+ UINTN* Number
+ );
+
+
+typedef
+EFI_STATUS
+(EFIAPI* SIMPLE_CLASS_SET_NUMBER)(
+ UINTN Number
+ );
+
+
+struct _SIMPLE_CLASS_PROTOCOL {
+ SIMPLE_CLASS_GET_NUMBER GetNumber;
+ SIMPLE_CLASS_SET_NUMBER SetNumber;
+};
+
+
+#endif
+
diff --git a/UefiLessonsPkg/Library/SimpleLibrary/SimpleLibrary.c b/UefiLessonsPkg/Library/SimpleLibrary/SimpleLibrary.c
new file mode 100644
index 0000000..acffba4
--- /dev/null
+++ b/UefiLessonsPkg/Library/SimpleLibrary/SimpleLibrary.c
@@ -0,0 +1,5 @@
+#include <Library/SimpleLibrary.h>
+
+UINTN Plus2(UINTN number) {
+ return number+2;
+}
diff --git a/UefiLessonsPkg/Library/SimpleLibrary/SimpleLibrary.inf b/UefiLessonsPkg/Library/SimpleLibrary/SimpleLibrary.inf
new file mode 100644
index 0000000..92027a4
--- /dev/null
+++ b/UefiLessonsPkg/Library/SimpleLibrary/SimpleLibrary.inf
@@ -0,0 +1,15 @@
+[Defines]
+ INF_VERSION = 1.25
+ BASE_NAME = SimpleLibrary
+ FILE_GUID = 826c8951-5bd2-4d72-a9d9-f7ab48684117
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = SimpleLibrary | UEFI_APPLICATION
+
+[Sources]
+ SimpleLibrary.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UefiLessonsPkg/UefiLessonsPkg.dec
+
diff --git a/UefiLessonsPkg/Library/SimpleLibraryWithConstructor/SimpleLibraryWithConstructor.c b/UefiLessonsPkg/Library/SimpleLibraryWithConstructor/SimpleLibraryWithConstructor.c
new file mode 100644
index 0000000..5ade80e
--- /dev/null
+++ b/UefiLessonsPkg/Library/SimpleLibraryWithConstructor/SimpleLibraryWithConstructor.c
@@ -0,0 +1,18 @@
+#include <Library/UefiLib.h>
+#include <Library/SimpleLibrary.h>
+
+UINTN Plus2(UINTN number) {
+ return number+2;
+}
+
+EFI_STATUS
+EFIAPI
+SimpleLibraryConstructor(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ Print(L"Hello from library constructor!\n");
+ return EFI_SUCCESS;
+}
+
diff --git a/UefiLessonsPkg/Library/SimpleLibraryWithConstructor/SimpleLibraryWithConstructor.inf b/UefiLessonsPkg/Library/SimpleLibraryWithConstructor/SimpleLibraryWithConstructor.inf
new file mode 100644
index 0000000..fc56624
--- /dev/null
+++ b/UefiLessonsPkg/Library/SimpleLibraryWithConstructor/SimpleLibraryWithConstructor.inf
@@ -0,0 +1,16 @@
+[Defines]
+ INF_VERSION = 1.25
+ BASE_NAME = SimpleLibraryWithConstructor
+ FILE_GUID = 96952c1e-86a6-4700-96b0-e7303ac3f92d
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = SimpleLibrary | UEFI_APPLICATION
+ CONSTRUCTOR = SimpleLibraryConstructor
+
+[Sources]
+ SimpleLibraryWithConstructor.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UefiLessonsPkg/UefiLessonsPkg.dec
+
diff --git a/UefiLessonsPkg/Library/SimpleLibraryWithConstructorAndDestructor/SimpleLibraryWithConstructorAndDestructor.c b/UefiLessonsPkg/Library/SimpleLibraryWithConstructorAndDestructor/SimpleLibraryWithConstructorAndDestructor.c
new file mode 100644
index 0000000..f903e99
--- /dev/null
+++ b/UefiLessonsPkg/Library/SimpleLibraryWithConstructorAndDestructor/SimpleLibraryWithConstructorAndDestructor.c
@@ -0,0 +1,28 @@
+#include <Library/UefiLib.h>
+#include <Library/SimpleLibrary.h>
+
+UINTN Plus2(UINTN number) {
+ return number+2;
+}
+
+EFI_STATUS
+EFIAPI
+SimpleLibraryConstructor(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ Print(L"Hello from library constructor!\n");
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+SimpleLibraryDestructor(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ Print(L"Hello from library destructor!\n");
+ return EFI_SUCCESS;
+}
diff --git a/UefiLessonsPkg/Library/SimpleLibraryWithConstructorAndDestructor/SimpleLibraryWithConstructorAndDestructor.inf b/UefiLessonsPkg/Library/SimpleLibraryWithConstructorAndDestructor/SimpleLibraryWithConstructorAndDestructor.inf
new file mode 100644
index 0000000..3fc3bbe
--- /dev/null
+++ b/UefiLessonsPkg/Library/SimpleLibraryWithConstructorAndDestructor/SimpleLibraryWithConstructorAndDestructor.inf
@@ -0,0 +1,17 @@
+[Defines]
+ INF_VERSION = 1.25
+ BASE_NAME = SimpleLibraryWithConstructorAndDestructor
+ FILE_GUID = 96952c1e-86a6-4700-96b0-e7303ac3f92d
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = SimpleLibrary | UEFI_APPLICATION
+ CONSTRUCTOR = SimpleLibraryConstructor
+ DESTRUCTOR = SimpleLibraryDestructor
+
+[Sources]
+ SimpleLibraryWithConstructorAndDestructor.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UefiLessonsPkg/UefiLessonsPkg.dec
+
diff --git a/UefiLessonsPkg/ListPCI/ListPCI.c b/UefiLessonsPkg/ListPCI/ListPCI.c
index 6eb2eef..055906c 100644
--- a/UefiLessonsPkg/ListPCI/ListPCI.c
+++ b/UefiLessonsPkg/ListPCI/ListPCI.c
@@ -20,12 +20,15 @@ VOID ToLowerASCII(CHAR8* Str, UINTN Size)
}
}
-EFI_STATUS FindPCIDevDescription(UINT16 VendorId,
- UINT16 DeviceId,
- CHAR16* VendorDesc,
- CHAR16* DeviceDesc,
- UINTN DescBufferSize)
+EFI_STATUS FindPCIDevDescription(IN UINT16 VendorId,
+ IN UINT16 DeviceId,
+ OUT CHAR16* VendorDesc,
+ OUT CHAR16* DeviceDesc,
+ IN UINTN DescBufferSize)
{
+ BOOLEAN Vendor_found = FALSE;
+ BOOLEAN Device_found = FALSE;
+
EFI_STATUS Status = ShellFileExists(L"pci.ids");
if (EFI_ERROR(Status))
{
@@ -70,8 +73,6 @@ EFI_STATUS FindPCIDevDescription(UINT16 VendorId,
CHAR8 Buffer[BLOCK_READ_SIZE];
UINTN Size;
UINT64 FilePos = 0;
- BOOLEAN Vendor_found = FALSE;
- BOOLEAN Device_found = FALSE;
while (TRUE)
{
Size = BLOCK_READ_SIZE;
@@ -88,7 +89,7 @@ EFI_STATUS FindPCIDevDescription(UINT16 VendorId,
StrEnd=i;
if (!Vendor_found){
// 0123456 7
- //\nXXXX |<desc>|\n
+ //\nVVVV |<desc>|\n
if ((StrEnd - StrStart) > 7) {
if ((Buffer[StrStart+1]==VendorStr[0]) &&
(Buffer[StrStart+2]==VendorStr[1]) &&
@@ -101,7 +102,7 @@ EFI_STATUS FindPCIDevDescription(UINT16 VendorId,
}
} else {
// 0 1234567 8
- //\n\tXXXX |<desc>|\n
+ //\n\tDDDD |<desc>|\n
if ((StrEnd - StrStart) > 8) {
if ((Buffer[StrStart+1]=='\t') &&
(Buffer[StrStart+2]==DeviceStr[0]) &&
@@ -111,7 +112,7 @@ EFI_STATUS FindPCIDevDescription(UINT16 VendorId,
Buffer[StrEnd] = 0;
UnicodeSPrintAsciiFormat(DeviceDesc, DescBufferSize, "%a", &Buffer[StrStart+1+1+4+2]);
Device_found = TRUE;
- break;
+ goto end;
}
}
}
@@ -186,7 +187,7 @@ EFI_STATUS PrintRootBridge(EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL* PciRootBridgeIo)
);
if (!EFI_ERROR(Status)) {
if (PCIConfHdr.VendorId != 0xffff) {
- Print(L"\t%02x:%02x.%02x - Vendor:%04x, Device:%04x",
+ Print(L" %02x:%02x.%02x - Vendor:%04x, Device:%04x",
Bus,
Device,
Func,
@@ -207,7 +208,7 @@ EFI_STATUS PrintRootBridge(EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL* PciRootBridgeIo)
}
}
} else {
- Print(L"\tError in PCI read: %r\n", Status);
+ Print(L" Error in PCI read: %r\n", Status);
}
}
}
diff --git a/UefiLessonsPkg/PCIRomInfo/PCIRomInfo.c b/UefiLessonsPkg/PCIRomInfo/PCIRomInfo.c
new file mode 100644
index 0000000..7531192
--- /dev/null
+++ b/UefiLessonsPkg/PCIRomInfo/PCIRomInfo.c
@@ -0,0 +1,380 @@
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+#include <Protocol/PciIo.h>
+#include <Library/MemoryAllocationLib.h>
+#include <IndustryStandard/Pci.h>
+#include <Library/ShellLib.h>
+#include <Library/PrintLib.h>
+
+#include <IndustryStandard/PeImage.h>
+
+
+#define DESCRIPTOR_STR_MAX_SIZE 200
+#define BLOCK_READ_SIZE (1024*4)
+
+VOID ToLowerASCII(CHAR8* Str, UINTN Size)
+{
+ for (UINT8 i=0; i<Size; i++) {
+ if ((Str[i]>='A')&&(Str[i]<='Z')) {
+ Str[i]+=32;
+ }
+ }
+}
+
+EFI_STATUS FindPCIDevDescription(UINT16 VendorId,
+ UINT16 DeviceId,
+ CHAR16* VendorDesc,
+ CHAR16* DeviceDesc,
+ UINTN DescBufferSize)
+{
+ EFI_STATUS Status = ShellFileExists(L"pci.ids");
+ if (EFI_ERROR(Status))
+ {
+ Print(L"No file pci.ids: %r\n", Status);
+ return Status;
+ }
+
+ SHELL_FILE_HANDLE FileHandle;
+ Status = ShellOpenFileByName(L"pci.ids",
+ &FileHandle,
+ EFI_FILE_MODE_READ,
+ 0);
+ if (EFI_ERROR(Status))
+ {
+ Print(L"Can't open file pci.ids: %r\n", Status);
+ return Status;
+ }
+
+ UINT64 FileSize;
+ Status = ShellGetFileSize(FileHandle, &FileSize);
+ if (EFI_ERROR(Status))
+ {
+ Print(L"Can't get file size for file pci.ids: %r\n", Status);
+ goto end;
+ }
+
+ CHAR8 VendorStr[5];
+ CHAR8 DeviceStr[5];
+ AsciiValueToStringS(VendorStr,
+ 5,
+ RADIX_HEX | PREFIX_ZERO,
+ VendorId,
+ 4);
+ AsciiValueToStringS(DeviceStr,
+ 5,
+ RADIX_HEX | PREFIX_ZERO,
+ DeviceId,
+ 4);
+ ToLowerASCII(VendorStr, 4);
+ ToLowerASCII(DeviceStr, 4);
+
+ CHAR8 Buffer[BLOCK_READ_SIZE];
+ UINTN Size;
+ UINT64 FilePos = 0;
+ BOOLEAN Vendor_found = FALSE;
+ BOOLEAN Device_found = FALSE;
+ while (TRUE)
+ {
+ Size = BLOCK_READ_SIZE;
+ Status = ShellReadFile(FileHandle, &Size, Buffer);
+ if (EFI_ERROR(Status))
+ {
+ Print(L"Can't read file pci.ids: %r\n", Status);
+ goto end;
+ }
+ UINTN StrStart = 0;
+ UINTN StrEnd = 0;
+ for (UINTN i=0; i<Size; i++) {
+ if (Buffer[i]=='\n') {
+ StrEnd=i;
+ if (!Vendor_found){
+ // 0123456 7
+ //\nXXXX |<desc>|\n
+ if ((StrEnd - StrStart) > 7) {
+ if ((Buffer[StrStart+1]==VendorStr[0]) &&
+ (Buffer[StrStart+2]==VendorStr[1]) &&
+ (Buffer[StrStart+3]==VendorStr[2]) &&
+ (Buffer[StrStart+4]==VendorStr[3])) {
+ Buffer[StrEnd] = 0;
+ UnicodeSPrintAsciiFormat(VendorDesc, DescBufferSize, "%a", &Buffer[StrStart+1+4+2]);
+ Vendor_found = TRUE;
+ }
+ }
+ } else {
+ // 0 1234567 8
+ //\n\tXXXX |<desc>|\n
+ if ((StrEnd - StrStart) > 8) {
+ if ((Buffer[StrStart+1]=='\t') &&
+ (Buffer[StrStart+2]==DeviceStr[0]) &&
+ (Buffer[StrStart+3]==DeviceStr[1]) &&
+ (Buffer[StrStart+4]==DeviceStr[2]) &&
+ (Buffer[StrStart+5]==DeviceStr[3])) {
+ Buffer[StrEnd] = 0;
+ UnicodeSPrintAsciiFormat(DeviceDesc, DescBufferSize, "%a", &Buffer[StrStart+1+1+4+2]);
+ Device_found = TRUE;
+ break;
+ }
+ }
+ }
+ StrStart = StrEnd;
+ }
+ }
+
+ if (FilePos+Size >= FileSize) {
+ break;
+ }
+ FilePos += StrEnd;
+ Status = ShellSetFilePosition(FileHandle, FilePos);
+ if (EFI_ERROR(Status))
+ {
+ Print(L"Can't set file position pci.ids: %r\n", Status);
+ goto end;
+ }
+ }
+
+end:
+ if (!Vendor_found) {
+ UnicodeSPrint(VendorDesc, DescBufferSize, L"Undefined");
+ }
+ if (!Device_found) {
+ UnicodeSPrint(DeviceDesc, DescBufferSize, L"Undefined");
+ }
+ ShellCloseFile(&FileHandle);
+
+ return Status;
+}
+
+
+UINT64 PciConfigurationAddress(UINT8 Bus,
+ UINT8 Device,
+ UINT8 Function,
+ UINT32 Register)
+{
+ UINT64 Address = (((UINT64)Bus) << 24) + (((UINT64)Device) << 16) + (((UINT64)Function) << 8);
+ if (Register & 0xFFFFFF00) {
+ Address += (((UINT64)Register) << 32);
+ } else {
+ Address += (((UINT64)Register) << 0);
+ }
+ return Address;
+}
+
+VOID PrintOptionROM(VOID *RomImage, UINT64 RomSize)
+{
+ Print(L"Has OptionROM at memory %p-%p\n", RomImage, (UINT8*)RomImage + RomSize);
+ PCI_EXPANSION_ROM_HEADER* RomHeader = (PCI_EXPANSION_ROM_HEADER*) RomImage;
+ UINTN RomImageIndex = 1;
+ while (TRUE)
+ {
+ if (RomHeader->Signature != PCI_EXPANSION_ROM_HEADER_SIGNATURE) {
+ Print(L"Error! OptionROM has a wrong signature\n");
+ return;
+ }
+ PCI_DATA_STRUCTURE* RomImage = (PCI_DATA_STRUCTURE*)((UINT8*)RomHeader + RomHeader->PcirOffset);
+ if ((((CHAR8)((RomImage->Signature >> 0) & 0xFF)) != 'P') &&
+ (((CHAR8)((RomImage->Signature >> 8) & 0xFF)) != 'C') &&
+ (((CHAR8)((RomImage->Signature >> 16) & 0xFF)) != 'I') &&
+ (((CHAR8)((RomImage->Signature >> 24) & 0xFF)) != 'R')) {
+ Print(L"Error! OptionROM image has wrong signature\n");
+ return;
+ }
+ Print(L"---Code Image %d---\n", RomImageIndex);
+ Print(L"Address: %p-%p\n", RomHeader, (UINT8*)RomHeader + (RomImage->ImageLength)*512);
+ Print(L"PCIR address: %p\n", RomImage);
+ Print(L"VendorId: %04x, DeviceId: %04x\n", RomImage->VendorId, RomImage->DeviceId);
+ Print(L"Type: ");
+ switch (RomImage->CodeType) {
+ case 0x00:
+ Print(L"IA-32, PC-AT compatible\n");
+ break;
+ case 0x01:
+ Print(L"Open Firmware standard for PCI\n");
+ break;
+ case 0x02:
+ Print(L"Hewlett-Packard PA RISC\n");
+ break;
+ case 0x03:
+ Print(L"EFI Image\n");
+ break;
+ default:
+ Print(L"Unknown\n");
+ break;
+ }
+ if (RomImage->CodeType == 0x03) {
+ EFI_PCI_EXPANSION_ROM_HEADER* EfiRomHeader = (EFI_PCI_EXPANSION_ROM_HEADER*) RomHeader;
+ if (EfiRomHeader->EfiSignature == EFI_PCI_EXPANSION_ROM_HEADER_EFISIGNATURE) {
+ Print(L"Subsystem: ");
+ switch (EfiRomHeader->EfiSubsystem) {
+ case EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION:
+ Print(L"EFI Application\n");
+ break;
+ case EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER:
+ Print(L"EFI Boot Service Driver\n");
+ break;
+ case EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER:
+ Print(L"EFI Runtime Driver\n");
+ break;
+ case EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER:
+ Print(L"EFI SAL Runtime Driver\n");
+ break;
+ default:
+ Print(L"Unknown\n");
+ break;
+ }
+ Print(L"Machine type: ");
+ switch (EfiRomHeader->EfiMachineType) {
+ case IMAGE_FILE_MACHINE_I386:
+ Print(L"IA-32\n");
+ break;
+ case IMAGE_FILE_MACHINE_IA64:
+ Print(L"Itanium\n");
+ break;
+ case IMAGE_FILE_MACHINE_EBC:
+ Print(L"EFI Byte Code (EBC)\n");
+ break;
+ case IMAGE_FILE_MACHINE_X64:
+ Print(L"X64\n");
+ break;
+ case IMAGE_FILE_MACHINE_ARMTHUMB_MIXED:
+ Print(L"ARM\n");
+ break;
+ case IMAGE_FILE_MACHINE_ARM64:
+ Print(L"ARM 64-bit\n");
+ break;
+ case IMAGE_FILE_MACHINE_RISCV32:
+ Print(L"RISCV32\n");
+ break;
+ case IMAGE_FILE_MACHINE_RISCV64:
+ Print(L"RISCV64\n");
+ break;
+ case IMAGE_FILE_MACHINE_RISCV128:
+ Print(L"RISCV128\n");
+ break;
+ default:
+ Print(L"Unknown\n");
+ break;
+ }
+ switch (EfiRomHeader->CompressionType) {
+ case EFI_PCI_EXPANSION_ROM_HEADER_COMPRESSED:
+ Print(L"Compressed following the UEFI Compression Algorithm\n");
+ break;
+ case 0:
+ Print(L"Uncompressed\n");
+ break;
+ default:
+ Print(L"Unknown compression type\n");
+ break;
+ }
+ } else {
+ Print(L"EFI signature is incorrect!\n");
+ }
+ }
+ if ((RomImage->Indicator) & 0x80) {
+ break;
+ }
+ RomHeader = (PCI_EXPANSION_ROM_HEADER*)((UINT8*) RomHeader + (RomImage->ImageLength)*512);
+ RomImageIndex++;
+ }
+ Print(L"------------------\n");
+}
+
+EFI_STATUS PrintPCI(EFI_PCI_IO_PROTOCOL* PciIo)
+{
+ UINTN SegmentNumber;
+ UINTN BusNumber;
+ UINTN DeviceNumber;
+ UINTN FunctionNumber;
+ EFI_STATUS Status = PciIo->GetLocation(PciIo,
+ &SegmentNumber,
+ &BusNumber,
+ &DeviceNumber,
+ &FunctionNumber);
+ if (EFI_ERROR(Status)) {
+ Print(L"Error in getting PCI location: %r\n", Status);
+ return Status;
+ }
+
+ PCI_DEVICE_INDEPENDENT_REGION PCIConfHdr;
+ Status = PciIo->Pci.Read(PciIo,
+ EfiPciIoWidthUint8,
+ 0,
+ sizeof(PCI_DEVICE_INDEPENDENT_REGION),
+ &PCIConfHdr);
+
+ if (EFI_ERROR(Status)) {
+ Print(L"Error in reading PCI conf space: %r\n", Status);
+ return Status;
+ }
+
+ if (PciIo->RomSize) {
+ Print(L"%02x:%02x.%02x - Vendor:%04x, Device:%04x", BusNumber,
+ DeviceNumber,
+ FunctionNumber,
+ PCIConfHdr.VendorId,
+ PCIConfHdr.DeviceId);
+
+ CHAR16 VendorDesc[DESCRIPTOR_STR_MAX_SIZE];
+ CHAR16 DeviceDesc[DESCRIPTOR_STR_MAX_SIZE];
+ Status = FindPCIDevDescription(PCIConfHdr.VendorId,
+ PCIConfHdr.DeviceId,
+ VendorDesc,
+ DeviceDesc,
+ DESCRIPTOR_STR_MAX_SIZE);
+ if (!EFI_ERROR(Status)) {
+ Print(L": %s, %s\n", VendorDesc, DeviceDesc);
+ } else {
+ Print(L"\n");
+ }
+ PrintOptionROM(PciIo->RomImage, PciIo->RomSize);
+ }
+ return Status;
+}
+
+EFI_STATUS
+EFIAPI
+UefiMain (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+ UINTN HandleCount;
+ EFI_HANDLE *HandleBuffer;
+ Status = gBS->LocateHandleBuffer(
+ ByProtocol,
+ &gEfiPciIoProtocolGuid,
+ NULL,
+ &HandleCount,
+ &HandleBuffer
+ );
+ if (EFI_ERROR (Status)) {
+ Print(L"Can't locate EFI_PCI_IO_PROTOCOL: %r\n", Status);
+ return Status;
+ }
+
+ //Print(L"Number of PCI devices in the system: %d\n", HandleCount);
+ EFI_PCI_IO_PROTOCOL* PciIo;
+ for (UINTN Index = 0; Index < HandleCount; Index++) {
+ Status = gBS->OpenProtocol (
+ HandleBuffer[Index],
+ &gEfiPciIoProtocolGuid,
+ (VOID **)&PciIo,
+ ImageHandle,
+ NULL,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+ if (EFI_ERROR(Status)) {
+ Print(L"Can't open protocol: %r\n", Status);
+ return Status;
+ }
+ Status = PrintPCI(PciIo);
+ if (EFI_ERROR(Status)) {
+ Print(L"Error in PCI printing\n");
+ }
+
+ }
+ FreePool(HandleBuffer);
+
+ return EFI_SUCCESS;
+}
diff --git a/UefiLessonsPkg/ShowHii/ShowHii.inf b/UefiLessonsPkg/PCIRomInfo/PCIRomInfo.inf
index ec8ba46..b098b26 100644
--- a/UefiLessonsPkg/ShowHii/ShowHii.inf
+++ b/UefiLessonsPkg/PCIRomInfo/PCIRomInfo.inf
@@ -1,22 +1,22 @@
[Defines]
INF_VERSION = 1.25
- BASE_NAME = ShowHii
- FILE_GUID = 75a15862-aa04-47c2-a0ac-14a0a8bf5756
+ BASE_NAME = PCIRomInfo
+ FILE_GUID = 76f1798f-533f-49a2-b94c-96ab3dfebea0
MODULE_TYPE = UEFI_APPLICATION
VERSION_STRING = 1.0
ENTRY_POINT = UefiMain
[Sources]
- ShowHii.c
+ PCIRomInfo.c
[Packages]
MdePkg/MdePkg.dec
+ ShellPkg/ShellPkg.dec
[LibraryClasses]
UefiApplicationEntryPoint
UefiLib
+ ShellLib
[Protocols]
- gEfiHiiDatabaseProtocolGuid
-
-
+ gEfiPciIoProtocolGuid
diff --git a/UefiLessonsPkg/ShowHii/ShowHii.c b/UefiLessonsPkg/ShowHii/ShowHii.c
deleted file mode 100644
index 27f23c3..0000000
--- a/UefiLessonsPkg/ShowHii/ShowHii.c
+++ /dev/null
@@ -1,120 +0,0 @@
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/UefiLib.h>
-
-#include <Protocol/HiiDatabase.h>
-#include <Library/MemoryAllocationLib.h>
-
-
-CHAR16* PackageType(UINTN Type)
-{
- switch(Type) {
- case EFI_HII_PACKAGE_TYPE_ALL:
- return L"ALL";
- case EFI_HII_PACKAGE_TYPE_GUID:
- return L"GUID";
- case EFI_HII_PACKAGE_FORMS:
- return L"FORMS";
- case EFI_HII_PACKAGE_STRINGS:
- return L"STRINGS";
- case EFI_HII_PACKAGE_FONTS:
- return L"FONTS";
- case EFI_HII_PACKAGE_IMAGES:
- return L"IMAGES";
- case EFI_HII_PACKAGE_SIMPLE_FONTS:
- return L"SIMPLE_FONTS";
- case EFI_HII_PACKAGE_DEVICE_PATH:
- return L"DEVICE_PATH";
- case EFI_HII_PACKAGE_KEYBOARD_LAYOUT:
- return L"KEYBOARD_LAYOUT";
- case EFI_HII_PACKAGE_ANIMATIONS:
- return L"ANIMATIONS";
- case EFI_HII_PACKAGE_END:
- return L"END";
- case EFI_HII_PACKAGE_TYPE_SYSTEM_BEGIN:
- return L"SYSTEM_BEGIN";
- case EFI_HII_PACKAGE_TYPE_SYSTEM_END:
- return L"SYSTEM_END";
- }
- return L"UNKNOWN";
-}
-
-VOID ParseHiiPackageLists(EFI_HII_PACKAGE_LIST_HEADER* HiiDatabase, UINTN HiiDatabaseSize)
-{
- EFI_HII_PACKAGE_LIST_HEADER* HiiPackageListHeader;
- HiiPackageListHeader = (EFI_HII_PACKAGE_LIST_HEADER*) HiiDatabase;
-
- UINTN i=0;
- while ((UINTN) HiiPackageListHeader < ((UINTN) HiiDatabase + HiiDatabaseSize)) {
- UINTN HiiPackageListSize = HiiPackageListHeader->PackageLength;
- if (HiiPackageListSize == 0)
- break;
- Print(L"PackageList[%d]: GUID=%g\n", i++, HiiPackageListHeader->PackageListGuid);
-
- EFI_HII_PACKAGE_HEADER* HiiPackageHeader = (EFI_HII_PACKAGE_HEADER*)((UINTN) HiiPackageListHeader + sizeof(EFI_HII_PACKAGE_LIST_HEADER));
- UINTN j=0;
- while ((UINTN) HiiPackageHeader < ((UINTN) HiiPackageListHeader + HiiPackageListSize)) {
- Print(L"\tPackage[%d]: type=%s\n", j++, PackageType(HiiPackageHeader->Type));
- // Go to next Package
- HiiPackageHeader = (EFI_HII_PACKAGE_HEADER*)((UINTN) HiiPackageHeader + HiiPackageHeader->Length);
- }
- // Go to next PackageList
- HiiPackageListHeader = (EFI_HII_PACKAGE_LIST_HEADER*)((UINTN) HiiPackageListHeader + HiiPackageListSize);
- }
-}
-
-EFI_STATUS
-EFIAPI
-UefiMain (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- )
-{
- EFI_STATUS Status;
- EFI_HII_DATABASE_PROTOCOL* HiiDbProtocol;
- Status = gBS->LocateProtocol(&gEfiHiiDatabaseProtocolGuid,
- NULL,
- (VOID**)&HiiDbProtocol);
- if (EFI_ERROR(Status)) {
- Print(L"ERROR: Could not find HII Database protocol: %r\n", Status);
- return Status;
- }
-
-
- UINTN PackageListSize = 0;
- EFI_HII_PACKAGE_LIST_HEADER* PackageList = NULL;
-
- Status = HiiDbProtocol->ExportPackageLists(HiiDbProtocol,
- NULL, // All package lists
- &PackageListSize,
- PackageList);
- if (Status != EFI_BUFFER_TOO_SMALL) {
- Print(L"ERROR: Could not obtain package list size\n");
- return Status;
- }
-
- Status = gBS->AllocatePool(EfiBootServicesData,
- PackageListSize,
- (VOID**)&PackageList);
- if (EFI_ERROR(Status)) {
- Print(L"ERROR: Could not allocate sufficient memory for package list: %r\n", Status);
- return Status;
- }
-
-
- Status = HiiDbProtocol->ExportPackageLists(HiiDbProtocol,
- NULL,
- &PackageListSize,
- PackageList);
- if (EFI_ERROR(Status)) {
- Print(L"ERROR: Could not retrieve the package list: %r\n", Status);
- FreePool(PackageList);
- return Status;
- }
-
- ParseHiiPackageLists(PackageList, PackageListSize);
- ////////
-
- FreePool(PackageList);
-
- return EFI_SUCCESS;
-}
diff --git a/UefiLessonsPkg/SimpleClassProtocol/SimpleClassProtocol.c b/UefiLessonsPkg/SimpleClassProtocol/SimpleClassProtocol.c
new file mode 100644
index 0000000..8bd7f87
--- /dev/null
+++ b/UefiLessonsPkg/SimpleClassProtocol/SimpleClassProtocol.c
@@ -0,0 +1,84 @@
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+#include <Protocol/SimpleClass.h>
+
+
+EFI_HANDLE mSimpleClassHandle = NULL;
+
+UINTN mNumber = 0;
+
+EFI_STATUS
+EFIAPI
+SimpleClassProtocolSetNumber (
+ UINTN Number
+ )
+{
+ mNumber = Number;
+
+ return EFI_SUCCESS;
+}
+
+
+EFI_STATUS
+EFIAPI
+SimpleClassProtocolGetNumber (
+ UINTN* Number
+ )
+{
+ if (Number == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ *Number = mNumber;
+
+ return EFI_SUCCESS;
+}
+
+
+SIMPLE_CLASS_PROTOCOL mSimpleClass = {
+ SimpleClassProtocolGetNumber,
+ SimpleClassProtocolSetNumber
+};
+
+
+EFI_STATUS
+EFIAPI
+SimpleClassProtocolDriverUnload (
+ IN EFI_HANDLE ImageHandle
+ )
+{
+ Print(L"Bye-bye from SimpleClassProtocol driver, handle=%p\n", mSimpleClassHandle);
+
+ EFI_STATUS Status = gBS->UninstallMultipleProtocolInterfaces(
+ mSimpleClassHandle,
+ &gSimpleClassProtocolGuid,
+ &mSimpleClass,
+ NULL
+ );
+
+ return Status;
+}
+
+EFI_STATUS
+EFIAPI
+SimpleClassProtocolDriverEntryPoint (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ Print(L"Hello from SimpleClassProtocol driver");
+
+ EFI_STATUS Status = gBS->InstallMultipleProtocolInterfaces(
+ &mSimpleClassHandle,
+ &gSimpleClassProtocolGuid,
+ &mSimpleClass,
+ NULL
+ );
+ if (!EFI_ERROR(Status))
+ Print(L", handle=%p\n", mSimpleClassHandle);
+ else
+ Print(L"\n", mSimpleClassHandle);
+
+ return Status;
+}
diff --git a/UefiLessonsPkg/SimpleClassProtocol/SimpleClassProtocol.inf b/UefiLessonsPkg/SimpleClassProtocol/SimpleClassProtocol.inf
new file mode 100644
index 0000000..edd2297
--- /dev/null
+++ b/UefiLessonsPkg/SimpleClassProtocol/SimpleClassProtocol.inf
@@ -0,0 +1,23 @@
+[Defines]
+ INF_VERSION = 1.25
+ BASE_NAME = SimpleClassProtocol
+ FILE_GUID = 51d6a90a-c021-4472-b2c1-5fdd1b7f2196
+ MODULE_TYPE = UEFI_DRIVER
+ VERSION_STRING = 1.0
+ ENTRY_POINT = SimpleClassProtocolDriverEntryPoint
+ UNLOAD_IMAGE = SimpleClassProtocolDriverUnload
+
+[Sources]
+ SimpleClassProtocol.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UefiLessonsPkg/UefiLessonsPkg.dec
+
+[Protocols]
+ gSimpleClassProtocolGuid
+
+[LibraryClasses]
+ UefiDriverEntryPoint
+ UefiLib
+
diff --git a/UefiLessonsPkg/SimpleClassUser/SimpleClassUser.c b/UefiLessonsPkg/SimpleClassUser/SimpleClassUser.c
new file mode 100644
index 0000000..bd3ac1d
--- /dev/null
+++ b/UefiLessonsPkg/SimpleClassUser/SimpleClassUser.c
@@ -0,0 +1,67 @@
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+#include <Protocol/SimpleClass.h>
+
+EFI_STATUS
+EFIAPI
+UefiMain (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ UINTN HandleCount;
+ EFI_HANDLE* HandleBuffer;
+ UINTN Index;
+ SIMPLE_CLASS_PROTOCOL* SimpleClass;
+
+ EFI_STATUS Status = gBS->LocateHandleBuffer (
+ ByProtocol,
+ &gSimpleClassProtocolGuid,
+ NULL,
+ &HandleCount,
+ &HandleBuffer
+ );
+ if (EFI_ERROR (Status)) {
+ Print(L"Error! Can't find any handle with gSimpleClassProtocolGuid: %r\n", Status);
+ return Status;
+ }
+
+ for (Index = 0; Index < HandleCount; Index++) {
+ Print(L"Handle = %p\n", HandleBuffer[Index]);
+ Status = gBS->OpenProtocol(
+ HandleBuffer[Index],
+ &gSimpleClassProtocolGuid,
+ (VOID **)&SimpleClass,
+ ImageHandle,
+ NULL,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+
+ if (!EFI_ERROR(Status)) {
+ UINTN Number;
+
+ Status = SimpleClass->GetNumber(&Number);
+ if (!EFI_ERROR(Status)) {
+ Print(L"Number before=%d\n", Number);
+ } else {
+ Print(L"Error! Can't get number: %r\n", Status);
+ }
+
+ Status = SimpleClass->SetNumber(Number+5);
+ if (EFI_ERROR(Status))
+ Print(L"Error! Can't set number: %r\n", Status);
+
+ Status = SimpleClass->GetNumber(&Number);
+ if (!EFI_ERROR(Status)) {
+ Print(L"Number after=%d\n", Number);
+ } else {
+ Print(L"Error! Can't get number: %r\n", Status);
+ }
+ } else {
+ Print(L"Error! Can't open SimpleClass protocol: %r\n", Status);
+ }
+ }
+
+ return Status;
+}
diff --git a/UefiLessonsPkg/SimpleClassUser/SimpleClassUser.inf b/UefiLessonsPkg/SimpleClassUser/SimpleClassUser.inf
new file mode 100644
index 0000000..cb57e68
--- /dev/null
+++ b/UefiLessonsPkg/SimpleClassUser/SimpleClassUser.inf
@@ -0,0 +1,22 @@
+[Defines]
+ INF_VERSION = 1.25
+ BASE_NAME = SimpleClassUser
+ FILE_GUID = 466eed70-8def-44ea-9fb4-9012b266ec8c
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ ENTRY_POINT = UefiMain
+
+[Sources]
+ SimpleClassUser.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UefiLessonsPkg/UefiLessonsPkg.dec
+
+[Protocols]
+ gSimpleClassProtocolGuid
+
+[LibraryClasses]
+ UefiApplicationEntryPoint
+ UefiLib
+
diff --git a/UefiLessonsPkg/SimpleLibraryUser/SimpleLibraryUser.c b/UefiLessonsPkg/SimpleLibraryUser/SimpleLibraryUser.c
new file mode 100644
index 0000000..9747b97
--- /dev/null
+++ b/UefiLessonsPkg/SimpleLibraryUser/SimpleLibraryUser.c
@@ -0,0 +1,16 @@
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+#include <Library/SimpleLibrary.h>
+
+EFI_STATUS
+EFIAPI
+UefiMain (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ Print(L"%d\n", Plus2(3));
+
+ return EFI_SUCCESS;
+}
diff --git a/UefiLessonsPkg/SimpleLibraryUser/SimpleLibraryUser.inf b/UefiLessonsPkg/SimpleLibraryUser/SimpleLibraryUser.inf
new file mode 100644
index 0000000..d7e5be8
--- /dev/null
+++ b/UefiLessonsPkg/SimpleLibraryUser/SimpleLibraryUser.inf
@@ -0,0 +1,20 @@
+[Defines]
+ INF_VERSION = 1.25
+ BASE_NAME = SimpleLibraryUser
+ FILE_GUID = 22a1f57c-21ca-4011-9133-e3df0d01dace
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ ENTRY_POINT = UefiMain
+
+[Sources]
+ SimpleLibraryUser.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UefiLessonsPkg/UefiLessonsPkg.dec
+
+[LibraryClasses]
+ UefiApplicationEntryPoint
+ UefiLib
+ SimpleLibrary
+