]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Pci/PciBusDxe/PciRomTable.c
Revert "EhciDxe: Use common buffer for AsyncInterruptTransfer"
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / PciBusDxe / PciRomTable.c
1 /** @file
2 Set up ROM Table for PCI Bus module.
3
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
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 VOID *RomImage;
27 UINT64 RomSize;
28 } PCI_ROM_IMAGE;
29
30 UINTN mNumberOfPciRomImages = 0;
31 UINTN mMaxNumberOfPciRomImages = 0;
32 PCI_ROM_IMAGE *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 RomImage Option Rom buffer.
43 @param RomSize Size of Option Rom buffer.
44 **/
45 VOID
46 PciRomAddImageMapping (
47 IN EFI_HANDLE ImageHandle,
48 IN UINTN Seg,
49 IN UINT8 Bus,
50 IN UINT8 Dev,
51 IN UINT8 Func,
52 IN VOID *RomImage,
53 IN UINT64 RomSize
54 )
55 {
56 UINTN Index;
57 PCI_ROM_IMAGE *NewTable;
58
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) {
64 //
65 // Expect once RomImage and RomSize are recorded, they will be passed in
66 // later when updating ImageHandle
67 //
68 ASSERT ((mRomImageTable[Index].RomImage == NULL) || (RomImage == mRomImageTable[Index].RomImage));
69 ASSERT ((mRomImageTable[Index].RomSize == 0 ) || (RomSize == mRomImageTable[Index].RomSize ));
70 break;
71 }
72 }
73
74 if (Index == mNumberOfPciRomImages) {
75 //
76 // Rom Image Table buffer needs to grow.
77 //
78 if (mNumberOfPciRomImages == mMaxNumberOfPciRomImages) {
79 NewTable = ReallocatePool (
80 mMaxNumberOfPciRomImages * sizeof (PCI_ROM_IMAGE),
81 (mMaxNumberOfPciRomImages + 0x20) * sizeof (PCI_ROM_IMAGE),
82 mRomImageTable
83 );
84 if (NewTable == NULL) {
85 return ;
86 }
87
88 mRomImageTable = NewTable;
89 mMaxNumberOfPciRomImages += 0x20;
90 }
91 //
92 // Record the new PCI device
93 //
94 mRomImageTable[Index].Seg = Seg;
95 mRomImageTable[Index].Bus = Bus;
96 mRomImageTable[Index].Dev = Dev;
97 mRomImageTable[Index].Func = Func;
98 mNumberOfPciRomImages++;
99 }
100
101 mRomImageTable[Index].ImageHandle = ImageHandle;
102 mRomImageTable[Index].RomImage = RomImage;
103 mRomImageTable[Index].RomSize = RomSize;
104 }
105
106 /**
107 Get Option rom driver's mapping for PCI device.
108
109 @param PciIoDevice Device instance.
110
111 @retval TRUE Found Image mapping.
112 @retval FALSE Cannot found image mapping.
113
114 **/
115 BOOLEAN
116 PciRomGetImageMapping (
117 IN PCI_IO_DEVICE *PciIoDevice
118 )
119 {
120 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;
121 UINTN Index;
122
123 PciRootBridgeIo = PciIoDevice->PciRootBridgeIo;
124
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 ) {
130
131 if (mRomImageTable[Index].ImageHandle != NULL) {
132 AddDriver (PciIoDevice, mRomImageTable[Index].ImageHandle, NULL);
133 }
134 PciIoDevice->PciIo.RomImage = mRomImageTable[Index].RomImage;
135 PciIoDevice->PciIo.RomSize = mRomImageTable[Index].RomSize;
136 return TRUE;
137 }
138 }
139
140 return FALSE;
141 }