36 IN VOID *Buffer OPTIONAL
46 UINT32 DestinationSize;
50 UINT32 InitializationSize;
53 if ((EfiOpRomImageNode ==
NULL) ||
58 (EfiOpRomImageNode->StartingOffset > EfiOpRomImageNode->EndingOffset) ||
59 (EfiOpRomImageNode->EndingOffset >= PciIoDevice->RomSize) ||
63 return EFI_INVALID_PARAMETER;
67 (UINT8 *)PciIoDevice->PciIo.RomImage + EfiOpRomImageNode->StartingOffset
69 if (EfiRomHeader->
Signature != PCI_EXPANSION_ROM_HEADER_SIGNATURE) {
74 ASSERT (Pcir->
Signature == PCI_DATA_STRUCTURE_SIGNATURE);
76 if ((Pcir->CodeType == PCI_CODE_TYPE_EFI_IMAGE) &&
78 ((EfiRomHeader->EfiSubsystem == EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER) ||
79 (EfiRomHeader->EfiSubsystem == EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER)) &&
83 ImageSize = Pcir->ImageLength * 512;
84 InitializationSize = (UINT32)EfiRomHeader->InitializationSize * 512;
85 if ((InitializationSize > ImageSize) || (EfiRomHeader->EfiImageHeaderOffset >= InitializationSize)) {
89 ImageBuffer = (UINT8 *)EfiRomHeader + EfiRomHeader->EfiImageHeaderOffset;
90 ImageLength = InitializationSize - EfiRomHeader->EfiImageHeaderOffset;
96 if ((Buffer ==
NULL) || (*BufferSize < ImageLength)) {
97 *BufferSize = ImageLength;
98 return EFI_BUFFER_TOO_SMALL;
101 *BufferSize = ImageLength;
102 CopyMem (Buffer, ImageBuffer, ImageLength);
108 Status =
gBS->LocateProtocol (&gEfiDecompressProtocolGuid,
NULL, (VOID **)&
Decompress);
109 if (EFI_ERROR (Status)) {
110 return EFI_DEVICE_ERROR;
120 if (EFI_ERROR (Status)) {
121 return EFI_DEVICE_ERROR;
124 if ((Buffer ==
NULL) || (*BufferSize < DestinationSize)) {
125 *BufferSize = DestinationSize;
126 return EFI_BUFFER_TOO_SMALL;
129 *BufferSize = DestinationSize;
131 if (Scratch ==
NULL) {
132 return EFI_DEVICE_ERROR;
146 if (EFI_ERROR (Status)) {
147 return EFI_DEVICE_ERROR;
154 return EFI_NOT_FOUND;
168 PciIoDevice->LoadFile2.LoadFile =
LoadFile2;
199 IN BOOLEAN BootPolicy,
201 IN VOID *Buffer OPTIONAL
207 return EFI_UNSUPPORTED;
210 PciIoDevice = PCI_IO_DEVICE_FROM_LOAD_FILE2_THIS (This);
244 Bus = PciIoDevice->BusNumber;
245 Device = PciIoDevice->DeviceNumber;
246 Function = PciIoDevice->FunctionNumber;
248 PciRootBridgeIo = PciIoDevice->PciRootBridgeIo;
257 RomBarIndex = PCI_EXPANSION_ROM_BASE;
269 AllOnes = 0xfffffffe;
270 Address = EFI_PCI_ADDRESS (Bus, Device, Function, RomBarIndex);
272 Status = PciRootBridgeIo->Pci.
Write (
279 if (EFI_ERROR (Status)) {
280 return EFI_NOT_FOUND;
286 Status = PciRootBridgeIo->Pci.
Read (
293 if (EFI_ERROR (Status)) {
294 return EFI_NOT_FOUND;
300 AllOnes &= 0xFFFFF800;
301 if ((AllOnes == 0) || (AllOnes == 0xFFFFF800)) {
302 return EFI_NOT_FOUND;
305 PciIoDevice->RomSize = (~AllOnes) + 1;
330 RomHeader = RomImage;
331 if (RomHeader ==
NULL) {
336 if (RomHeader->
Signature != PCI_EXPANSION_ROM_HEADER_SIGNATURE) {
344 if ((RomHeader->PcirOffset == 0) ||
345 ((RomHeader->PcirOffset & 3) != 0) ||
346 ((UINT8 *)RomHeader + RomHeader->PcirOffset + sizeof (
PCI_DATA_STRUCTURE) > (UINT8 *)RomImage + RomSize))
352 if (RomPcir->
Signature != PCI_DATA_STRUCTURE_SIGNATURE) {
356 if (RomPcir->CodeType == PCI_CODE_TYPE_EFI_IMAGE) {
360 Indicator = RomPcir->Indicator;
362 }
while (((UINT8 *)RomHeader < (UINT8 *)RomImage + RomSize) && ((Indicator & 0x80) == 0x00));
395 UINT32 LegacyImageLength;
399 RomSize = PciDevice->RomSize;
413 RomBarIndex = PCI_EXPANSION_ROM_BASE;
429 if (RomHeader ==
NULL) {
430 return EFI_OUT_OF_RESOURCES;
434 if (RomPcir ==
NULL) {
436 return EFI_OUT_OF_RESOURCES;
439 RomBar = (UINT32)RomBase;
446 RomBarOffset = RomBar;
447 RetStatus = EFI_NOT_FOUND;
449 LegacyImageLength = 0;
452 PciDevice->PciRootBridgeIo->Mem.Read (
453 PciDevice->PciRootBridgeIo,
460 if (RomHeader->Signature != PCI_EXPANSION_ROM_HEADER_SIGNATURE) {
461 RomBarOffset = RomBarOffset + 512;
465 RomImageSize = RomImageSize + 512;
471 OffsetPcir = RomHeader->PcirOffset;
476 if ((OffsetPcir == 0) ||
477 ((OffsetPcir & 3) != 0) ||
483 PciDevice->PciRootBridgeIo->Mem.Read (
484 PciDevice->PciRootBridgeIo,
486 RomBarOffset + OffsetPcir,
493 if (RomPcir->Signature != PCI_DATA_STRUCTURE_SIGNATURE) {
497 if (RomImageSize + RomPcir->ImageLength * 512 > RomSize) {
501 if (RomPcir->CodeType == PCI_CODE_TYPE_PCAT_IMAGE) {
502 CodeType = PCI_CODE_TYPE_PCAT_IMAGE;
506 Indicator = RomPcir->Indicator;
507 RomImageSize = RomImageSize + RomPcir->ImageLength * 512;
508 RomBarOffset = RomBarOffset + RomPcir->ImageLength * 512;
509 }
while (((Indicator & 0x80) == 0x00) && ((RomBarOffset - RomBar) < RomSize) && (RomImageSize > 0));
515 if ((RomImageSize > 0) && (CodeType == PCI_CODE_TYPE_PCAT_IMAGE)) {
516 RomImageSize =
MAX (RomImageSize, LegacyImageLength);
519 if (RomImageSize > 0) {
526 return EFI_OUT_OF_RESOURCES;
532 PciDevice->PciRootBridgeIo->Mem.Read (
533 PciDevice->PciRootBridgeIo,
536 (UINT32)RomImageSize/sizeof (UINT32),
544 PciDevice->EmbeddedRom =
TRUE;
545 PciDevice->PciIo.RomSize = RomImageSize;
546 PciDevice->PciIo.RomImage = RomInMemory;
554 PciDevice->PciRootBridgeIo->SegmentNumber,
555 PciDevice->BusNumber,
556 PciDevice->DeviceNumber,
557 PciDevice->FunctionNumber,
558 PciDevice->PciIo.RomImage,
559 PciDevice->PciIo.RomSize
584 IN UINT8 RomBarIndex,
592 PciIo = &PciDevice->PciIo;
598 Value32 = RomBar | 0x1;
630 Value32 = 0xFFFFFFFE;
674 RomBar = PciDevice->PciIo.RomImage;
675 RomBarOffset = (UINT8 *)RomBar;
676 RetStatus = EFI_NOT_FOUND;
678 if (RomBar ==
NULL) {
686 if (EfiRomHeader->
Signature != PCI_EXPANSION_ROM_HEADER_SIGNATURE) {
692 ASSERT (Pcir->
Signature == PCI_DATA_STRUCTURE_SIGNATURE);
693 ImageSize = (UINT32)(Pcir->ImageLength * 512);
694 Indicator = Pcir->Indicator;
699 if (Pcir->CodeType != PCI_CODE_TYPE_EFI_IMAGE) {
706 if (EfiRomHeader->EfiSubsystem == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) {
713 EfiOpRomImageNode.Header.
Type = MEDIA_DEVICE_PATH;
716 EfiOpRomImageNode.StartingOffset = (
UINTN)RomBarOffset - (
UINTN)RomBar;
717 EfiOpRomImageNode.EndingOffset = (
UINTN)RomBarOffset + ImageSize - 1 - (
UINTN)RomBar;
719 PciOptionRomImageDevicePath =
AppendDevicePathNode (PciDevice->DevicePath, &EfiOpRomImageNode.Header);
720 ASSERT (PciOptionRomImageDevicePath !=
NULL);
729 Status =
gBS->LoadImage (
732 PciOptionRomImageDevicePath,
737 if (EFI_ERROR (Status)) {
744 Status =
gBS->StartImage (ImageHandle,
NULL,
NULL);
745 if (!EFI_ERROR (Status)) {
752 PciDevice->PciRootBridgeIo->SegmentNumber,
753 PciDevice->BusNumber,
754 PciDevice->DeviceNumber,
755 PciDevice->FunctionNumber,
756 PciDevice->PciIo.RomImage,
757 PciDevice->PciIo.RomSize
763 FreePool (PciOptionRomImageDevicePath);
766 RomBarOffset += ImageSize;
767 }
while (((Indicator & 0x80) == 0x00) && (((
UINTN)RomBarOffset - (
UINTN)RomBar) < PciDevice->RomSize));
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
#define MEDIA_RELATIVE_OFFSET_RANGE_DP
UINT8 EFIAPI DevicePathType(IN CONST VOID *Node)
UINT16 EFIAPI SetDevicePathNodeLength(IN OUT VOID *Node, IN UINTN Length)
UINTN EFIAPI DevicePathNodeLength(IN CONST VOID *Node)
UINT8 EFIAPI DevicePathSubType(IN CONST VOID *Node)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI AppendDevicePathNode(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL, IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL)
BOOLEAN EFIAPI IsDevicePathEnd(IN CONST VOID *Node)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI NextDevicePathNode(IN CONST VOID *Node)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS EFIAPI Decompress(IN CONST EFI_PEI_DECOMPRESS_PPI *This, IN CONST EFI_COMPRESSION_SECTION *CompressionSection, OUT VOID **OutputBuffer, OUT UINTN *OutputSize)
EFI_PCI_IO_PROTOCOL_WIDTH
#define IS_PCI_BRIDGE(_p)
#define EFI_PCI_COMMAND_MEMORY_SPACE
0x0002
#define EFI_PCI_EXPANSION_ROM_HEADER_EFISIGNATURE
defined in UEFI Spec.
#define EFI_PCI_EXPANSION_ROM_HEADER_COMPRESSED
defined in UEFI spec.
#define PCI_BRIDGE_ROMBAR
#define PCI_DISABLE_COMMAND_REGISTER(a, b)
#define PCI_ENABLE_COMMAND_REGISTER(a, b)
EFI_STATUS AddDriver(IN PCI_IO_DEVICE *PciIoDevice, IN EFI_HANDLE DriverImageHandle, IN EFI_DEVICE_PATH_PROTOCOL *DriverImagePath)
EFI_STATUS GetOpRomInfo(IN OUT PCI_IO_DEVICE *PciIoDevice)
EFI_STATUS EFIAPI LoadFile2(IN EFI_LOAD_FILE2_PROTOCOL *This, IN EFI_DEVICE_PATH_PROTOCOL *FilePath, IN BOOLEAN BootPolicy, IN OUT UINTN *BufferSize, IN VOID *Buffer OPTIONAL)
VOID InitializePciLoadFile2(IN PCI_IO_DEVICE *PciIoDevice)
EFI_STATUS LocalLoadFile2(IN PCI_IO_DEVICE *PciIoDevice, IN EFI_DEVICE_PATH_PROTOCOL *FilePath, IN OUT UINTN *BufferSize, IN VOID *Buffer OPTIONAL)
BOOLEAN ContainEfiImage(IN VOID *RomImage, IN UINT64 RomSize)
EFI_STATUS ProcessOpRomImage(IN PCI_IO_DEVICE *PciDevice)
EFI_STATUS LoadOpRomImage(IN PCI_IO_DEVICE *PciDevice, IN UINT64 RomBase)
VOID RomDecode(IN PCI_IO_DEVICE *PciDevice, IN UINT8 RomBarIndex, IN UINT32 RomBar, IN BOOLEAN Enable)
VOID ProgramUpstreamBridgeForRom(IN PCI_IO_DEVICE *PciDevice, IN UINT32 OptionRomBase, IN BOOLEAN Enable)
VOID PciRomAddImageMapping(IN EFI_HANDLE ImageHandle, IN UINTN Seg, IN UINT8 Bus, IN UINT8 Dev, IN UINT8 Func, IN VOID *RomImage, IN UINT64 RomSize)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_HANDLE DriverBindingHandle
UINT32 EfiSignature
0x0EF1
EFI_PCI_IO_PROTOCOL_CONFIG Write
EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_IO_MEM Write
EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_IO_MEM Read