]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Bus/Pci/PciBusDxe/PciRomTable.c
Correct all header files for doxygen format and correct the license issue for VgaClas...
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Pci / PciBusDxe / PciRomTable.c
1 /**@file
2 Option Rom Support for PCI Bus Driver
3
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. 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 #include "PciRomTable.h"
17
18 typedef struct {
19 EFI_HANDLE ImageHandle;
20 UINTN Seg;
21 UINT8 Bus;
22 UINT8 Dev;
23 UINT8 Func;
24 UINT64 RomAddress;
25 UINT64 RomLength;
26 } EFI_PCI_ROM_IMAGE_MAPPING;
27
28 static UINTN mNumberOfPciRomImages = 0;
29 static UINTN mMaxNumberOfPciRomImages = 0;
30 static EFI_PCI_ROM_IMAGE_MAPPING *mRomImageTable = NULL;
31
32 VOID
33 PciRomAddImageMapping (
34 IN EFI_HANDLE ImageHandle,
35 IN UINTN Seg,
36 IN UINT8 Bus,
37 IN UINT8 Dev,
38 IN UINT8 Func,
39 IN UINT64 RomAddress,
40 IN UINT64 RomLength
41 )
42 /*++
43
44 Routine Description:
45
46 TODO: Add function description
47
48 Arguments:
49
50 ImageHandle - TODO: add argument description
51 Seg - TODO: add argument description
52 Bus - TODO: add argument description
53 Dev - TODO: add argument description
54 Func - TODO: add argument description
55 RomAddress - TODO: add argument description
56 RomLength - TODO: add argument description
57
58 Returns:
59
60 TODO: add return values
61
62 --*/
63 {
64 EFI_PCI_ROM_IMAGE_MAPPING *TempMapping;
65
66 if (mNumberOfPciRomImages >= mMaxNumberOfPciRomImages) {
67
68 mMaxNumberOfPciRomImages += 0x20;
69
70 TempMapping = NULL;
71 TempMapping = AllocatePool (mMaxNumberOfPciRomImages * sizeof (EFI_PCI_ROM_IMAGE_MAPPING));
72 if (TempMapping == NULL) {
73 return ;
74 }
75
76 CopyMem (TempMapping, mRomImageTable, mNumberOfPciRomImages * sizeof (EFI_PCI_ROM_IMAGE_MAPPING));
77
78 if (mRomImageTable != NULL) {
79 gBS->FreePool (mRomImageTable);
80 }
81
82 mRomImageTable = TempMapping;
83 }
84
85 mRomImageTable[mNumberOfPciRomImages].ImageHandle = ImageHandle;
86 mRomImageTable[mNumberOfPciRomImages].Seg = Seg;
87 mRomImageTable[mNumberOfPciRomImages].Bus = Bus;
88 mRomImageTable[mNumberOfPciRomImages].Dev = Dev;
89 mRomImageTable[mNumberOfPciRomImages].Func = Func;
90 mRomImageTable[mNumberOfPciRomImages].RomAddress = RomAddress;
91 mRomImageTable[mNumberOfPciRomImages].RomLength = RomLength;
92 mNumberOfPciRomImages++;
93 }
94
95 EFI_STATUS
96 PciRomGetRomResourceFromPciOptionRomTable (
97 IN EFI_DRIVER_BINDING_PROTOCOL *This,
98 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo,
99 PCI_IO_DEVICE *PciIoDevice
100 )
101 /*++
102
103 Routine Description:
104
105 Arguments:
106
107 Returns:
108
109 --*/
110 // TODO: This - add argument and description to function comment
111 // TODO: PciRootBridgeIo - add argument and description to function comment
112 // TODO: PciIoDevice - add argument and description to function comment
113 // TODO: EFI_NOT_FOUND - add return value to function comment
114 // TODO: EFI_SUCCESS - add return value to function comment
115 {
116 EFI_STATUS Status;
117 EFI_PCI_OPTION_ROM_TABLE *PciOptionRomTable;
118 EFI_PCI_OPTION_ROM_DESCRIPTOR *PciOptionRomDescriptor;
119 UINTN Index;
120
121 Status = EfiGetSystemConfigurationTable (&gEfiPciOptionRomTableGuid, (VOID **) &PciOptionRomTable);
122 if (EFI_ERROR (Status)) {
123 return EFI_NOT_FOUND;
124 }
125
126 for (Index = 0; Index < PciOptionRomTable->PciOptionRomCount; Index++) {
127 PciOptionRomDescriptor = &PciOptionRomTable->PciOptionRomDescriptors[Index];
128 if (PciOptionRomDescriptor->Seg == PciRootBridgeIo->SegmentNumber &&
129 PciOptionRomDescriptor->Bus == PciIoDevice->BusNumber &&
130 PciOptionRomDescriptor->Dev == PciIoDevice->DeviceNumber &&
131 PciOptionRomDescriptor->Func == PciIoDevice->FunctionNumber ) {
132
133 PciIoDevice->PciIo.RomImage = (VOID *) (UINTN) PciOptionRomDescriptor->RomAddress;
134 PciIoDevice->PciIo.RomSize = (UINTN) PciOptionRomDescriptor->RomLength;
135 }
136 }
137
138 for (Index = 0; Index < mNumberOfPciRomImages; Index++) {
139 if (mRomImageTable[Index].Seg == PciRootBridgeIo->SegmentNumber &&
140 mRomImageTable[Index].Bus == PciIoDevice->BusNumber &&
141 mRomImageTable[Index].Dev == PciIoDevice->DeviceNumber &&
142 mRomImageTable[Index].Func == PciIoDevice->FunctionNumber ) {
143
144 AddDriver (PciIoDevice, mRomImageTable[Index].ImageHandle);
145 }
146 }
147
148 return EFI_SUCCESS;
149 }
150
151 EFI_STATUS
152 PciRomGetImageMapping (
153 PCI_IO_DEVICE *PciIoDevice
154 )
155 /*++
156
157 Routine Description:
158
159 Arguments:
160
161 Returns:
162
163 --*/
164 // TODO: PciIoDevice - add argument and description to function comment
165 // TODO: EFI_SUCCESS - add return value to function comment
166 {
167 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;
168 UINTN Index;
169
170 PciRootBridgeIo = PciIoDevice->PciRootBridgeIo;
171
172 for (Index = 0; Index < mNumberOfPciRomImages; Index++) {
173 if (mRomImageTable[Index].Seg == PciRootBridgeIo->SegmentNumber &&
174 mRomImageTable[Index].Bus == PciIoDevice->BusNumber &&
175 mRomImageTable[Index].Dev == PciIoDevice->DeviceNumber &&
176 mRomImageTable[Index].Func == PciIoDevice->FunctionNumber ) {
177
178 if (mRomImageTable[Index].ImageHandle != NULL) {
179 AddDriver (PciIoDevice, mRomImageTable[Index].ImageHandle);
180 } else {
181 PciIoDevice->PciIo.RomImage = (VOID *) (UINTN) mRomImageTable[Index].RomAddress;
182 PciIoDevice->PciIo.RomSize = (UINTN) mRomImageTable[Index].RomLength;
183 }
184 }
185 }
186
187 return EFI_SUCCESS;
188 }