]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Bus/Pci/PciBusDxe/PciRomTable.c
Revert "EhciDxe: Use common buffer for AsyncInterruptTransfer"
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / PciBusDxe / PciRomTable.c
... / ...
CommitLineData
1/** @file\r
2 Set up ROM Table for PCI Bus module.\r
3\r
4Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "PciBus.h"\r
16\r
17//\r
18// PCI ROM image information\r
19//\r
20typedef struct {\r
21 EFI_HANDLE ImageHandle;\r
22 UINTN Seg;\r
23 UINT8 Bus;\r
24 UINT8 Dev;\r
25 UINT8 Func;\r
26 VOID *RomImage;\r
27 UINT64 RomSize;\r
28} PCI_ROM_IMAGE;\r
29\r
30UINTN mNumberOfPciRomImages = 0;\r
31UINTN mMaxNumberOfPciRomImages = 0;\r
32PCI_ROM_IMAGE *mRomImageTable = NULL;\r
33\r
34/**\r
35 Add the Rom Image to internal database for later PCI light enumeration.\r
36\r
37 @param ImageHandle Option Rom image handle.\r
38 @param Seg Segment of PCI space.\r
39 @param Bus Bus NO of PCI space.\r
40 @param Dev Dev NO of PCI space.\r
41 @param Func Func NO of PCI space.\r
42 @param RomImage Option Rom buffer.\r
43 @param RomSize Size of Option Rom buffer.\r
44**/\r
45VOID\r
46PciRomAddImageMapping (\r
47 IN EFI_HANDLE ImageHandle,\r
48 IN UINTN Seg,\r
49 IN UINT8 Bus,\r
50 IN UINT8 Dev,\r
51 IN UINT8 Func,\r
52 IN VOID *RomImage,\r
53 IN UINT64 RomSize\r
54 )\r
55{\r
56 UINTN Index;\r
57 PCI_ROM_IMAGE *NewTable;\r
58\r
59 for (Index = 0; Index < mNumberOfPciRomImages; Index++) {\r
60 if (mRomImageTable[Index].Seg == Seg &&\r
61 mRomImageTable[Index].Bus == Bus &&\r
62 mRomImageTable[Index].Dev == Dev &&\r
63 mRomImageTable[Index].Func == Func) {\r
64 //\r
65 // Expect once RomImage and RomSize are recorded, they will be passed in\r
66 // later when updating ImageHandle\r
67 //\r
68 ASSERT ((mRomImageTable[Index].RomImage == NULL) || (RomImage == mRomImageTable[Index].RomImage));\r
69 ASSERT ((mRomImageTable[Index].RomSize == 0 ) || (RomSize == mRomImageTable[Index].RomSize ));\r
70 break;\r
71 }\r
72 }\r
73\r
74 if (Index == mNumberOfPciRomImages) {\r
75 //\r
76 // Rom Image Table buffer needs to grow.\r
77 //\r
78 if (mNumberOfPciRomImages == mMaxNumberOfPciRomImages) {\r
79 NewTable = ReallocatePool (\r
80 mMaxNumberOfPciRomImages * sizeof (PCI_ROM_IMAGE),\r
81 (mMaxNumberOfPciRomImages + 0x20) * sizeof (PCI_ROM_IMAGE),\r
82 mRomImageTable\r
83 );\r
84 if (NewTable == NULL) {\r
85 return ;\r
86 }\r
87\r
88 mRomImageTable = NewTable;\r
89 mMaxNumberOfPciRomImages += 0x20;\r
90 }\r
91 //\r
92 // Record the new PCI device\r
93 //\r
94 mRomImageTable[Index].Seg = Seg;\r
95 mRomImageTable[Index].Bus = Bus;\r
96 mRomImageTable[Index].Dev = Dev;\r
97 mRomImageTable[Index].Func = Func;\r
98 mNumberOfPciRomImages++;\r
99 }\r
100\r
101 mRomImageTable[Index].ImageHandle = ImageHandle;\r
102 mRomImageTable[Index].RomImage = RomImage;\r
103 mRomImageTable[Index].RomSize = RomSize;\r
104}\r
105\r
106/**\r
107 Get Option rom driver's mapping for PCI device.\r
108\r
109 @param PciIoDevice Device instance.\r
110\r
111 @retval TRUE Found Image mapping.\r
112 @retval FALSE Cannot found image mapping.\r
113\r
114**/\r
115BOOLEAN\r
116PciRomGetImageMapping (\r
117 IN PCI_IO_DEVICE *PciIoDevice\r
118 )\r
119{\r
120 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;\r
121 UINTN Index;\r
122\r
123 PciRootBridgeIo = PciIoDevice->PciRootBridgeIo;\r
124\r
125 for (Index = 0; Index < mNumberOfPciRomImages; Index++) {\r
126 if (mRomImageTable[Index].Seg == PciRootBridgeIo->SegmentNumber &&\r
127 mRomImageTable[Index].Bus == PciIoDevice->BusNumber &&\r
128 mRomImageTable[Index].Dev == PciIoDevice->DeviceNumber &&\r
129 mRomImageTable[Index].Func == PciIoDevice->FunctionNumber ) {\r
130\r
131 if (mRomImageTable[Index].ImageHandle != NULL) {\r
132 AddDriver (PciIoDevice, mRomImageTable[Index].ImageHandle, NULL);\r
133 }\r
134 PciIoDevice->PciIo.RomImage = mRomImageTable[Index].RomImage;\r
135 PciIoDevice->PciIo.RomSize = mRomImageTable[Index].RomSize;\r
136 return TRUE;\r
137 }\r
138 }\r
139\r
140 return FALSE;\r
141}\r