From: Ruiyu Ni <ruiyu.ni@intel.com>
To: edk2-devel@lists.01.org
Cc: Star Zeng <star.zeng@intel.com>
Subject: [PATCH 2/3] MdeModulePkg/PciBus: Don't create entry when recording ImageHandle
Date: Fri, 27 Oct 2017 14:54:37 +0800 [thread overview]
Message-ID: <20171027065438.284440-3-ruiyu.ni@intel.com> (raw)
In-Reply-To: <20171027065438.284440-1-ruiyu.ni@intel.com>
The patch shouldn't impact functionality.
Original code records the ImageHandle of Option ROM by creating a
new entry. It's not necessary.
The patch updates the ImageHandle in the old entry.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
---
MdeModulePkg/Bus/Pci/PciBusDxe/PciRomTable.c | 72 ++++++++++++++++++----------
1 file changed, 46 insertions(+), 26 deletions(-)
diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciRomTable.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciRomTable.c
index 0eef41739c..fc6f579293 100644
--- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciRomTable.c
+++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciRomTable.c
@@ -53,31 +53,54 @@ PciRomAddImageMapping (
IN UINT64 RomSize
)
{
+ UINTN Index;
PCI_ROM_IMAGE *NewTable;
- if (mNumberOfPciRomImages == mMaxNumberOfPciRomImages) {
-
- NewTable = ReallocatePool (
- mMaxNumberOfPciRomImages * sizeof (PCI_ROM_IMAGE),
- (mMaxNumberOfPciRomImages + 0x20) * sizeof (PCI_ROM_IMAGE),
- mRomImageTable
- );
- if (NewTable == NULL) {
- return ;
+ for (Index = 0; Index < mNumberOfPciRomImages; Index++) {
+ if (mRomImageTable[Index].Seg == Seg &&
+ mRomImageTable[Index].Bus == Bus &&
+ mRomImageTable[Index].Dev == Dev &&
+ mRomImageTable[Index].Func == Func) {
+ //
+ // Expect once RomImage and RomSize are recorded, they will be passed in
+ // later when updating ImageHandle
+ //
+ ASSERT ((mRomImageTable[Index].RomImage == NULL) || (RomImage == mRomImageTable[Index].RomImage));
+ ASSERT ((mRomImageTable[Index].RomSize == 0 ) || (RomSize == mRomImageTable[Index].RomSize ));
+ break;
}
+ }
- mRomImageTable = NewTable;
- mMaxNumberOfPciRomImages += 0x20;
+ if (Index == mNumberOfPciRomImages) {
+ //
+ // Rom Image Table buffer needs to grow.
+ //
+ if (mNumberOfPciRomImages == mMaxNumberOfPciRomImages) {
+ NewTable = ReallocatePool (
+ mMaxNumberOfPciRomImages * sizeof (PCI_ROM_IMAGE),
+ (mMaxNumberOfPciRomImages + 0x20) * sizeof (PCI_ROM_IMAGE),
+ mRomImageTable
+ );
+ if (NewTable == NULL) {
+ return ;
+ }
+
+ mRomImageTable = NewTable;
+ mMaxNumberOfPciRomImages += 0x20;
+ }
+ //
+ // Record the new PCI device
+ //
+ mRomImageTable[Index].Seg = Seg;
+ mRomImageTable[Index].Bus = Bus;
+ mRomImageTable[Index].Dev = Dev;
+ mRomImageTable[Index].Func = Func;
+ mNumberOfPciRomImages++;
}
- mRomImageTable[mNumberOfPciRomImages].ImageHandle = ImageHandle;
- mRomImageTable[mNumberOfPciRomImages].Seg = Seg;
- mRomImageTable[mNumberOfPciRomImages].Bus = Bus;
- mRomImageTable[mNumberOfPciRomImages].Dev = Dev;
- mRomImageTable[mNumberOfPciRomImages].Func = Func;
- mRomImageTable[mNumberOfPciRomImages].RomImage = RomImage;
- mRomImageTable[mNumberOfPciRomImages].RomSize = RomSize;
- mNumberOfPciRomImages++;
+ mRomImageTable[Index].ImageHandle = ImageHandle;
+ mRomImageTable[Index].RomImage = RomImage;
+ mRomImageTable[Index].RomSize = RomSize;
}
/**
@@ -96,26 +119,23 @@ PciRomGetImageMapping (
{
EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;
UINTN Index;
- BOOLEAN Found;
PciRootBridgeIo = PciIoDevice->PciRootBridgeIo;
- Found = FALSE;
for (Index = 0; Index < mNumberOfPciRomImages; Index++) {
if (mRomImageTable[Index].Seg == PciRootBridgeIo->SegmentNumber &&
mRomImageTable[Index].Bus == PciIoDevice->BusNumber &&
mRomImageTable[Index].Dev == PciIoDevice->DeviceNumber &&
mRomImageTable[Index].Func == PciIoDevice->FunctionNumber ) {
- Found = TRUE;
if (mRomImageTable[Index].ImageHandle != NULL) {
AddDriver (PciIoDevice, mRomImageTable[Index].ImageHandle);
- } else {
- PciIoDevice->PciIo.RomImage = mRomImageTable[Index].RomImage;
- PciIoDevice->PciIo.RomSize = mRomImageTable[Index].RomSize;
}
+ PciIoDevice->PciIo.RomImage = mRomImageTable[Index].RomImage;
+ PciIoDevice->PciIo.RomSize = mRomImageTable[Index].RomSize;
+ return TRUE;
}
}
- return Found;
+ return FALSE;
}
--
2.12.2.windows.2
next prev parent reply other threads:[~2017-10-27 6:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-27 6:54 [PATCH 0/3] MdeModulePkg/PciBus: Fix bug that doesn't produce BusOverride Ruiyu Ni
2017-10-27 6:54 ` [PATCH 1/3] MdeModulePkg/PciBus: Refine EFI_PCI_ROM_IMAGE_MAPPING Ruiyu Ni
2017-10-27 6:54 ` Ruiyu Ni [this message]
2017-10-27 6:54 ` [PATCH 3/3] MdeModulePkg/PciBus: Fix bug that doesn't produce BusOverride Ruiyu Ni
2017-10-30 8:42 ` [PATCH 0/3] " Zeng, Star
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171027065438.284440-3-ruiyu.ni@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox