TianoCore EDK2 master
Loading...
Searching...
No Matches
PciRomTable.c
Go to the documentation of this file.
1
9#include "PciBus.h"
10
11//
12// PCI ROM image information
13//
14typedef struct {
15 EFI_HANDLE ImageHandle;
16 UINTN Seg;
17 UINT8 Bus;
18 UINT8 Dev;
19 UINT8 Func;
20 VOID *RomImage;
21 UINT64 RomSize;
23
24UINTN mNumberOfPciRomImages = 0;
25UINTN mMaxNumberOfPciRomImages = 0;
26PCI_ROM_IMAGE *mRomImageTable = NULL;
27
39VOID
41 IN EFI_HANDLE ImageHandle,
42 IN UINTN Seg,
43 IN UINT8 Bus,
44 IN UINT8 Dev,
45 IN UINT8 Func,
46 IN VOID *RomImage,
47 IN UINT64 RomSize
48 )
49{
50 UINTN Index;
51 PCI_ROM_IMAGE *NewTable;
52
53 for (Index = 0; Index < mNumberOfPciRomImages; Index++) {
54 if ((mRomImageTable[Index].Seg == Seg) &&
55 (mRomImageTable[Index].Bus == Bus) &&
56 (mRomImageTable[Index].Dev == Dev) &&
57 (mRomImageTable[Index].Func == Func))
58 {
59 //
60 // Expect once RomImage and RomSize are recorded, they will be passed in
61 // later when updating ImageHandle. They may also be updated with new
62 // values if the platform provides an override of RomImage and RomSize.
63 //
64 break;
65 }
66 }
67
68 if (Index == mNumberOfPciRomImages) {
69 //
70 // Rom Image Table buffer needs to grow.
71 //
72 if (mNumberOfPciRomImages == mMaxNumberOfPciRomImages) {
73 NewTable = ReallocatePool (
74 mMaxNumberOfPciRomImages * sizeof (PCI_ROM_IMAGE),
75 (mMaxNumberOfPciRomImages + 0x20) * sizeof (PCI_ROM_IMAGE),
76 mRomImageTable
77 );
78 if (NewTable == NULL) {
79 return;
80 }
81
82 mRomImageTable = NewTable;
83 mMaxNumberOfPciRomImages += 0x20;
84 }
85
86 //
87 // Record the new PCI device
88 //
89 mRomImageTable[Index].Seg = Seg;
90 mRomImageTable[Index].Bus = Bus;
91 mRomImageTable[Index].Dev = Dev;
92 mRomImageTable[Index].Func = Func;
93 mNumberOfPciRomImages++;
94 }
95
96 mRomImageTable[Index].ImageHandle = ImageHandle;
97 mRomImageTable[Index].RomImage = RomImage;
98 mRomImageTable[Index].RomSize = RomSize;
99}
100
110BOOLEAN
112 IN PCI_IO_DEVICE *PciIoDevice
113 )
114{
115 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;
116 UINTN Index;
117
118 PciRootBridgeIo = PciIoDevice->PciRootBridgeIo;
119
120 for (Index = 0; Index < mNumberOfPciRomImages; Index++) {
121 if ((mRomImageTable[Index].Seg == PciRootBridgeIo->SegmentNumber) &&
122 (mRomImageTable[Index].Bus == PciIoDevice->BusNumber) &&
123 (mRomImageTable[Index].Dev == PciIoDevice->DeviceNumber) &&
124 (mRomImageTable[Index].Func == PciIoDevice->FunctionNumber))
125 {
126 if (mRomImageTable[Index].ImageHandle != NULL) {
127 AddDriver (PciIoDevice, mRomImageTable[Index].ImageHandle, NULL);
128 }
129
130 PciIoDevice->PciIo.RomImage = mRomImageTable[Index].RomImage;
131 PciIoDevice->PciIo.RomSize = mRomImageTable[Index].RomSize;
132 return TRUE;
133 }
134 }
135
136 return FALSE;
137}
UINT64 UINTN
VOID *EFIAPI ReallocatePool(IN UINTN OldSize, IN UINTN NewSize, IN VOID *OldBuffer OPTIONAL)
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
EFI_STATUS AddDriver(IN PCI_IO_DEVICE *PciIoDevice, IN EFI_HANDLE DriverImageHandle, IN EFI_DEVICE_PATH_PROTOCOL *DriverImagePath)
BOOLEAN PciRomGetImageMapping(IN PCI_IO_DEVICE *PciIoDevice)
Definition: PciRomTable.c:111
VOID PciRomAddImageMapping(IN EFI_HANDLE ImageHandle, IN UINTN Seg, IN UINT8 Bus, IN UINT8 Dev, IN UINT8 Func, IN VOID *RomImage, IN UINT64 RomSize)
Definition: PciRomTable.c:40
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33