2 Set up ROM Table for PCI Bus module.
4 Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 // PCI ROM image information
21 EFI_HANDLE ImageHandle
;
30 UINTN mNumberOfPciRomImages
= 0;
31 UINTN mMaxNumberOfPciRomImages
= 0;
32 PCI_ROM_IMAGE
*mRomImageTable
= NULL
;
35 Add the Rom Image to internal database for later PCI light enumeration.
37 @param ImageHandle Option Rom image handle.
38 @param Seg Segment of PCI space.
39 @param Bus Bus NO of PCI space.
40 @param Dev Dev NO of PCI space.
41 @param Func Func NO of PCI space.
42 @param RomImage Option Rom buffer.
43 @param RomSize Size of Option Rom buffer.
46 PciRomAddImageMapping (
47 IN EFI_HANDLE ImageHandle
,
57 PCI_ROM_IMAGE
*NewTable
;
59 for (Index
= 0; Index
< mNumberOfPciRomImages
; Index
++) {
60 if (mRomImageTable
[Index
].Seg
== Seg
&&
61 mRomImageTable
[Index
].Bus
== Bus
&&
62 mRomImageTable
[Index
].Dev
== Dev
&&
63 mRomImageTable
[Index
].Func
== Func
) {
65 // Expect once RomImage and RomSize are recorded, they will be passed in
66 // later when updating ImageHandle
68 ASSERT ((mRomImageTable
[Index
].RomImage
== NULL
) || (RomImage
== mRomImageTable
[Index
].RomImage
));
69 ASSERT ((mRomImageTable
[Index
].RomSize
== 0 ) || (RomSize
== mRomImageTable
[Index
].RomSize
));
74 if (Index
== mNumberOfPciRomImages
) {
76 // Rom Image Table buffer needs to grow.
78 if (mNumberOfPciRomImages
== mMaxNumberOfPciRomImages
) {
79 NewTable
= ReallocatePool (
80 mMaxNumberOfPciRomImages
* sizeof (PCI_ROM_IMAGE
),
81 (mMaxNumberOfPciRomImages
+ 0x20) * sizeof (PCI_ROM_IMAGE
),
84 if (NewTable
== NULL
) {
88 mRomImageTable
= NewTable
;
89 mMaxNumberOfPciRomImages
+= 0x20;
92 // Record the new PCI device
94 mRomImageTable
[Index
].Seg
= Seg
;
95 mRomImageTable
[Index
].Bus
= Bus
;
96 mRomImageTable
[Index
].Dev
= Dev
;
97 mRomImageTable
[Index
].Func
= Func
;
98 mNumberOfPciRomImages
++;
101 mRomImageTable
[Index
].ImageHandle
= ImageHandle
;
102 mRomImageTable
[Index
].RomImage
= RomImage
;
103 mRomImageTable
[Index
].RomSize
= RomSize
;
107 Get Option rom driver's mapping for PCI device.
109 @param PciIoDevice Device instance.
111 @retval TRUE Found Image mapping.
112 @retval FALSE Cannot found image mapping.
116 PciRomGetImageMapping (
117 IN PCI_IO_DEVICE
*PciIoDevice
120 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
123 PciRootBridgeIo
= PciIoDevice
->PciRootBridgeIo
;
125 for (Index
= 0; Index
< mNumberOfPciRomImages
; Index
++) {
126 if (mRomImageTable
[Index
].Seg
== PciRootBridgeIo
->SegmentNumber
&&
127 mRomImageTable
[Index
].Bus
== PciIoDevice
->BusNumber
&&
128 mRomImageTable
[Index
].Dev
== PciIoDevice
->DeviceNumber
&&
129 mRomImageTable
[Index
].Func
== PciIoDevice
->FunctionNumber
) {
131 if (mRomImageTable
[Index
].ImageHandle
!= NULL
) {
132 AddDriver (PciIoDevice
, mRomImageTable
[Index
].ImageHandle
, NULL
);
134 PciIoDevice
->PciIo
.RomImage
= mRomImageTable
[Index
].RomImage
;
135 PciIoDevice
->PciIo
.RomSize
= mRomImageTable
[Index
].RomSize
;