3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 Option Rom Support for PCI Bus Driver
25 #include "PciRomTable.h"
28 EFI_HANDLE ImageHandle
;
35 } EFI_PCI_ROM_IMAGE_MAPPING
;
37 static UINTN mNumberOfPciRomImages
= 0;
38 static UINTN mMaxNumberOfPciRomImages
= 0;
39 static EFI_PCI_ROM_IMAGE_MAPPING
*mRomImageTable
= NULL
;
42 PciRomAddImageMapping (
43 IN EFI_HANDLE ImageHandle
,
55 TODO: Add function description
59 ImageHandle - TODO: add argument description
60 Seg - TODO: add argument description
61 Bus - TODO: add argument description
62 Dev - TODO: add argument description
63 Func - TODO: add argument description
64 RomAddress - TODO: add argument description
65 RomLength - TODO: add argument description
69 TODO: add return values
73 EFI_PCI_ROM_IMAGE_MAPPING
*TempMapping
;
75 if (mNumberOfPciRomImages
>= mMaxNumberOfPciRomImages
) {
77 mMaxNumberOfPciRomImages
+= 0x20;
80 TempMapping
= AllocatePool (mMaxNumberOfPciRomImages
* sizeof (EFI_PCI_ROM_IMAGE_MAPPING
));
81 if (TempMapping
== NULL
) {
85 CopyMem (TempMapping
, mRomImageTable
, mNumberOfPciRomImages
* sizeof (EFI_PCI_ROM_IMAGE_MAPPING
));
87 if (mRomImageTable
!= NULL
) {
88 gBS
->FreePool (mRomImageTable
);
91 mRomImageTable
= TempMapping
;
94 mRomImageTable
[mNumberOfPciRomImages
].ImageHandle
= ImageHandle
;
95 mRomImageTable
[mNumberOfPciRomImages
].Seg
= Seg
;
96 mRomImageTable
[mNumberOfPciRomImages
].Bus
= Bus
;
97 mRomImageTable
[mNumberOfPciRomImages
].Dev
= Dev
;
98 mRomImageTable
[mNumberOfPciRomImages
].Func
= Func
;
99 mRomImageTable
[mNumberOfPciRomImages
].RomAddress
= RomAddress
;
100 mRomImageTable
[mNumberOfPciRomImages
].RomLength
= RomLength
;
101 mNumberOfPciRomImages
++;
105 PciRomGetRomResourceFromPciOptionRomTable (
106 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
107 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
,
108 PCI_IO_DEVICE
*PciIoDevice
119 // TODO: This - add argument and description to function comment
120 // TODO: PciRootBridgeIo - add argument and description to function comment
121 // TODO: PciIoDevice - add argument and description to function comment
122 // TODO: EFI_NOT_FOUND - add return value to function comment
123 // TODO: EFI_SUCCESS - add return value to function comment
126 EFI_PCI_OPTION_ROM_TABLE
*PciOptionRomTable
;
127 EFI_PCI_OPTION_ROM_DESCRIPTOR
*PciOptionRomDescriptor
;
130 Status
= EfiGetSystemConfigurationTable (&gEfiPciOptionRomTableGuid
, (VOID
**) &PciOptionRomTable
);
131 if (EFI_ERROR (Status
)) {
132 return EFI_NOT_FOUND
;
135 for (Index
= 0; Index
< PciOptionRomTable
->PciOptionRomCount
; Index
++) {
136 PciOptionRomDescriptor
= &PciOptionRomTable
->PciOptionRomDescriptors
[Index
];
137 if (PciOptionRomDescriptor
->Seg
== PciRootBridgeIo
->SegmentNumber
&&
138 PciOptionRomDescriptor
->Bus
== PciIoDevice
->BusNumber
&&
139 PciOptionRomDescriptor
->Dev
== PciIoDevice
->DeviceNumber
&&
140 PciOptionRomDescriptor
->Func
== PciIoDevice
->FunctionNumber
) {
142 PciIoDevice
->PciIo
.RomImage
= (VOID
*) (UINTN
) PciOptionRomDescriptor
->RomAddress
;
143 PciIoDevice
->PciIo
.RomSize
= (UINTN
) PciOptionRomDescriptor
->RomLength
;
147 for (Index
= 0; Index
< mNumberOfPciRomImages
; Index
++) {
148 if (mRomImageTable
[Index
].Seg
== PciRootBridgeIo
->SegmentNumber
&&
149 mRomImageTable
[Index
].Bus
== PciIoDevice
->BusNumber
&&
150 mRomImageTable
[Index
].Dev
== PciIoDevice
->DeviceNumber
&&
151 mRomImageTable
[Index
].Func
== PciIoDevice
->FunctionNumber
) {
153 AddDriver (PciIoDevice
, mRomImageTable
[Index
].ImageHandle
);
161 PciRomGetImageMapping (
162 PCI_IO_DEVICE
*PciIoDevice
173 // TODO: PciIoDevice - add argument and description to function comment
174 // TODO: EFI_SUCCESS - add return value to function comment
176 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
179 PciRootBridgeIo
= PciIoDevice
->PciRootBridgeIo
;
181 for (Index
= 0; Index
< mNumberOfPciRomImages
; Index
++) {
182 if (mRomImageTable
[Index
].Seg
== PciRootBridgeIo
->SegmentNumber
&&
183 mRomImageTable
[Index
].Bus
== PciIoDevice
->BusNumber
&&
184 mRomImageTable
[Index
].Dev
== PciIoDevice
->DeviceNumber
&&
185 mRomImageTable
[Index
].Func
== PciIoDevice
->FunctionNumber
) {
187 if (mRomImageTable
[Index
].ImageHandle
!= NULL
) {
188 AddDriver (PciIoDevice
, mRomImageTable
[Index
].ImageHandle
);
190 PciIoDevice
->PciIo
.RomImage
= (VOID
*) (UINTN
) mRomImageTable
[Index
].RomAddress
;
191 PciIoDevice
->PciIo
.RomSize
= (UINTN
) mRomImageTable
[Index
].RomLength
;