]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Bus/Pci/PciBusDxe/PciRomTable.c
f64c64ee39b5a61d799e818bf1e2a73f7e973b97
[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 UINTN mNumberOfPciRomImages = 0;
29 UINTN mMaxNumberOfPciRomImages = 0;
30 EFI_PCI_ROM_IMAGE_MAPPING *mRomImageTable = NULL;
31
32 /**
33 Add the Rom Image to internal database for later PCI light enumeration.
34
35 @param ImageHandle Option Rom image handle.
36 @param Seg Segment of PCI space.
37 @param Bus Bus NO of PCI space.
38 @param Dev Dev NO of PCI space.
39 @param Func Func NO of PCI space.
40 @param RomAddress Base address of OptionRom.
41 @param RomLength Length of rom image.
42 **/
43 VOID
44 PciRomAddImageMapping (
45 IN EFI_HANDLE ImageHandle,
46 IN UINTN Seg,
47 IN UINT8 Bus,
48 IN UINT8 Dev,
49 IN UINT8 Func,
50 IN UINT64 RomAddress,
51 IN UINT64 RomLength
52 )
53 {
54 EFI_PCI_ROM_IMAGE_MAPPING *TempMapping;
55
56 if (mNumberOfPciRomImages >= mMaxNumberOfPciRomImages) {
57
58 mMaxNumberOfPciRomImages += 0x20;
59
60 TempMapping = NULL;
61 TempMapping = AllocatePool (mMaxNumberOfPciRomImages * sizeof (EFI_PCI_ROM_IMAGE_MAPPING));
62 if (TempMapping == NULL) {
63 return ;
64 }
65
66 CopyMem (TempMapping, mRomImageTable, mNumberOfPciRomImages * sizeof (EFI_PCI_ROM_IMAGE_MAPPING));
67
68 if (mRomImageTable != NULL) {
69 gBS->FreePool (mRomImageTable);
70 }
71
72 mRomImageTable = TempMapping;
73 }
74
75 mRomImageTable[mNumberOfPciRomImages].ImageHandle = ImageHandle;
76 mRomImageTable[mNumberOfPciRomImages].Seg = Seg;
77 mRomImageTable[mNumberOfPciRomImages].Bus = Bus;
78 mRomImageTable[mNumberOfPciRomImages].Dev = Dev;
79 mRomImageTable[mNumberOfPciRomImages].Func = Func;
80 mRomImageTable[mNumberOfPciRomImages].RomAddress = RomAddress;
81 mRomImageTable[mNumberOfPciRomImages].RomLength = RomLength;
82 mNumberOfPciRomImages++;
83 }
84
85 /**
86 Load all option rom image to PCI driver list.
87
88 @param This Pointer to protocol instance EFI_DRIVER_BINDING_PROTOCOL
89 @param PciRootBridgeIo Root bridge Io instance
90 @param PciIoDevice device instance
91 **/
92 EFI_STATUS
93 PciRomGetRomResourceFromPciOptionRomTable (
94 IN EFI_DRIVER_BINDING_PROTOCOL *This,
95 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo,
96 PCI_IO_DEVICE *PciIoDevice
97 )
98 {
99 EFI_STATUS Status;
100 EFI_PCI_OPTION_ROM_TABLE *PciOptionRomTable;
101 EFI_PCI_OPTION_ROM_DESCRIPTOR *PciOptionRomDescriptor;
102 UINTN Index;
103
104 Status = EfiGetSystemConfigurationTable (&gEfiPciOptionRomTableGuid, (VOID **) &PciOptionRomTable);
105 if (EFI_ERROR (Status)) {
106 return EFI_NOT_FOUND;
107 }
108
109 for (Index = 0; Index < PciOptionRomTable->PciOptionRomCount; Index++) {
110 PciOptionRomDescriptor = &PciOptionRomTable->PciOptionRomDescriptors[Index];
111 if (PciOptionRomDescriptor->Seg == PciRootBridgeIo->SegmentNumber &&
112 PciOptionRomDescriptor->Bus == PciIoDevice->BusNumber &&
113 PciOptionRomDescriptor->Dev == PciIoDevice->DeviceNumber &&
114 PciOptionRomDescriptor->Func == PciIoDevice->FunctionNumber ) {
115
116 PciIoDevice->PciIo.RomImage = (VOID *) (UINTN) PciOptionRomDescriptor->RomAddress;
117 PciIoDevice->PciIo.RomSize = (UINTN) PciOptionRomDescriptor->RomLength;
118 }
119 }
120
121 for (Index = 0; Index < mNumberOfPciRomImages; Index++) {
122 if (mRomImageTable[Index].Seg == PciRootBridgeIo->SegmentNumber &&
123 mRomImageTable[Index].Bus == PciIoDevice->BusNumber &&
124 mRomImageTable[Index].Dev == PciIoDevice->DeviceNumber &&
125 mRomImageTable[Index].Func == PciIoDevice->FunctionNumber ) {
126
127 AddDriver (PciIoDevice, mRomImageTable[Index].ImageHandle);
128 }
129 }
130
131 return EFI_SUCCESS;
132 }
133
134 /**
135 Get Option rom driver's mapping for PCI device.
136
137 @param PciIoDevice Device instance.
138
139 **/
140 EFI_STATUS
141 PciRomGetImageMapping (
142 PCI_IO_DEVICE *PciIoDevice
143 )
144 {
145 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;
146 UINTN Index;
147
148 PciRootBridgeIo = PciIoDevice->PciRootBridgeIo;
149
150 for (Index = 0; Index < mNumberOfPciRomImages; Index++) {
151 if (mRomImageTable[Index].Seg == PciRootBridgeIo->SegmentNumber &&
152 mRomImageTable[Index].Bus == PciIoDevice->BusNumber &&
153 mRomImageTable[Index].Dev == PciIoDevice->DeviceNumber &&
154 mRomImageTable[Index].Func == PciIoDevice->FunctionNumber ) {
155
156 if (mRomImageTable[Index].ImageHandle != NULL) {
157 AddDriver (PciIoDevice, mRomImageTable[Index].ImageHandle);
158 } else {
159 PciIoDevice->PciIo.RomImage = (VOID *) (UINTN) mRomImageTable[Index].RomAddress;
160 PciIoDevice->PciIo.RomSize = (UINTN) mRomImageTable[Index].RomLength;
161 }
162 }
163 }
164
165 return EFI_SUCCESS;
166 }