diff options
author | Konstantin Aladyshev <aladyshev22@gmail.com> | 2021-07-09 00:12:34 +0300 |
---|---|---|
committer | Konstantin Aladyshev <aladyshev22@gmail.com> | 2021-07-09 00:13:48 +0300 |
commit | de689d29972d2ccf7d41dc4fe70f96b050538452 (patch) | |
tree | f98269b7cfaddca8c854a00f16cb55ce2058ac79 /Lesson_32/UefiLessonsPkg/DumpPCIroms | |
parent | 92074db23590330dcab7684446cbb0c595308cfb (diff) | |
download | UEFI-Lessons-de689d29972d2ccf7d41dc4fe70f96b050538452.tar.gz UEFI-Lessons-de689d29972d2ccf7d41dc4fe70f96b050538452.tar.bz2 UEFI-Lessons-de689d29972d2ccf7d41dc4fe70f96b050538452.zip |
Source code modifications in lesson 32
Signed-off-by: Konstantin Aladyshev <aladyshev22@gmail.com>
Diffstat (limited to 'Lesson_32/UefiLessonsPkg/DumpPCIroms')
-rw-r--r-- | Lesson_32/UefiLessonsPkg/DumpPCIroms/DumpPCIroms.c | 248 |
1 files changed, 126 insertions, 122 deletions
diff --git a/Lesson_32/UefiLessonsPkg/DumpPCIroms/DumpPCIroms.c b/Lesson_32/UefiLessonsPkg/DumpPCIroms/DumpPCIroms.c index 9842a36..7531192 100644 --- a/Lesson_32/UefiLessonsPkg/DumpPCIroms/DumpPCIroms.c +++ b/Lesson_32/UefiLessonsPkg/DumpPCIroms/DumpPCIroms.c @@ -160,63 +160,16 @@ UINT64 PciConfigurationAddress(UINT8 Bus, return Address; } - -EFI_STATUS PrintPCI(EFI_PCI_IO_PROTOCOL* PciIo) +VOID PrintOptionROM(VOID *RomImage, UINT64 RomSize) { - 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"); - } - Print(L"Has OptionROM at memory %p-%p\n", PciIo->RomImage, (UINT8*)PciIo->RomImage + PciIo->RomSize); - PCI_EXPANSION_ROM_HEADER* RomHeader = (PCI_EXPANSION_ROM_HEADER*) PciIo->RomImage; - UINTN RomImageIndex = 1; - while (TRUE) - { + 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 Status; + return; } PCI_DATA_STRUCTURE* RomImage = (PCI_DATA_STRUCTURE*)((UINT8*)RomHeader + RomHeader->PcirOffset); if ((((CHAR8)((RomImage->Signature >> 0) & 0xFF)) != 'P') && @@ -224,10 +177,11 @@ EFI_STATUS PrintPCI(EFI_PCI_IO_PROTOCOL* PciIo) (((CHAR8)((RomImage->Signature >> 16) & 0xFF)) != 'I') && (((CHAR8)((RomImage->Signature >> 24) & 0xFF)) != 'R')) { Print(L"Error! OptionROM image has wrong signature\n"); - return Status; + 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) { @@ -249,80 +203,130 @@ EFI_STATUS PrintPCI(EFI_PCI_IO_PROTOCOL* PciIo) } 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; + 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"); } - } 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"); + } + 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; } |