1 /** @file
2 Set up ROM Table for PCI Bus module.
3
4 Copyright (c) 2006 - 2009, 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
9
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.
12
13 **/
14
15 #include "PciBus.h"
16
17 //
18 // PCI ROM image information
19 //
20 typedef struct {
21 EFI_HANDLE ImageHandle;
22 UINTN Seg;
23 UINT8 Bus;
24 UINT8 Dev;
25 UINT8 Func;
26 UINT64 RomAddress;
27 UINT64 RomLength;
28 } EFI_PCI_ROM_IMAGE_MAPPING;
29
30 UINTN mNumberOfPciRomImages = 0;
31 UINTN mMaxNumberOfPciRomImages = 0;
32 EFI_PCI_ROM_IMAGE_MAPPING *mRomImageTable = NULL;
33
34 /**
35 Add the Rom Image to internal database for later PCI light enumeration.
36
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 RomAddress Base address of OptionRom.
43 @param RomLength Length of rom image.
44
45 **/
46 VOID
PciRomAddImageMapping(IN EFI_HANDLE ImageHandle,IN UINTN Seg,IN UINT8 Bus,IN UINT8 Dev,IN UINT8 Func,IN UINT64 RomAddress,IN UINT64 RomLength)47 PciRomAddImageMapping (
48 IN EFI_HANDLE ImageHandle,
49 IN UINTN Seg,
50 IN UINT8 Bus,
51 IN UINT8 Dev,
52 IN UINT8 Func,
53 IN UINT64 RomAddress,
54 IN UINT64 RomLength
55 )
56 {
57 EFI_PCI_ROM_IMAGE_MAPPING *TempMapping;
58
59 if (mNumberOfPciRomImages >= mMaxNumberOfPciRomImages) {
60
61 mMaxNumberOfPciRomImages += 0x20;
62
63 TempMapping = NULL;
64 TempMapping = AllocatePool (mMaxNumberOfPciRomImages * sizeof (EFI_PCI_ROM_IMAGE_MAPPING));
65 if (TempMapping == NULL) {
66 return ;
67 }
68
69 CopyMem (TempMapping, mRomImageTable, mNumberOfPciRomImages * sizeof (EFI_PCI_ROM_IMAGE_MAPPING));
70
71 if (mRomImageTable != NULL) {
72 FreePool (mRomImageTable);
73 }
74
75 mRomImageTable = TempMapping;
76 }
77
78 mRomImageTable[mNumberOfPciRomImages].ImageHandle = ImageHandle;
79 mRomImageTable[mNumberOfPciRomImages].Seg = Seg;
80 mRomImageTable[mNumberOfPciRomImages].Bus = Bus;
81 mRomImageTable[mNumberOfPciRomImages].Dev = Dev;
82 mRomImageTable[mNumberOfPciRomImages].Func = Func;
83 mRomImageTable[mNumberOfPciRomImages].RomAddress = RomAddress;
84 mRomImageTable[mNumberOfPciRomImages].RomLength = RomLength;
85 mNumberOfPciRomImages++;
86 }
87
88 /**
89 Get Option rom driver's mapping for PCI device.
90
91 @param PciIoDevice Device instance.
92
93 @retval TRUE Found Image mapping.
94 @retval FALSE Cannot found image mapping.
95
96 **/
97 BOOLEAN
PciRomGetImageMapping(IN PCI_IO_DEVICE * PciIoDevice)98 PciRomGetImageMapping (
99 IN PCI_IO_DEVICE *PciIoDevice
100 )
101 {
102 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;
103 UINTN Index;
104 BOOLEAN Found;
105
106 PciRootBridgeIo = PciIoDevice->PciRootBridgeIo;
107 Found = FALSE;
108
109 for (Index = 0; Index < mNumberOfPciRomImages; Index++) {
110 if (mRomImageTable[Index].Seg == PciRootBridgeIo->SegmentNumber &&
111 mRomImageTable[Index].Bus == PciIoDevice->BusNumber &&
112 mRomImageTable[Index].Dev == PciIoDevice->DeviceNumber &&
113 mRomImageTable[Index].Func == PciIoDevice->FunctionNumber ) {
114 Found = TRUE;
115
116 if (mRomImageTable[Index].ImageHandle != NULL) {
117 AddDriver (PciIoDevice, mRomImageTable[Index].ImageHandle);
118 } else {
119 PciIoDevice->PciIo.RomImage = (VOID *) (UINTN) mRomImageTable[Index].RomAddress;
120 PciIoDevice->PciIo.RomSize = (UINTN) mRomImageTable[Index].RomLength;
121 }
122 }
123 }
124
125 return Found;
126 }
127