2 Option Rom Support for PCI Bus Driver
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
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.
16 #include "PciRomTable.h"
19 EFI_HANDLE ImageHandle
;
26 } EFI_PCI_ROM_IMAGE_MAPPING
;
28 static UINTN mNumberOfPciRomImages
= 0;
29 static UINTN mMaxNumberOfPciRomImages
= 0;
30 static EFI_PCI_ROM_IMAGE_MAPPING
*mRomImageTable
= NULL
;
33 PciRomAddImageMapping (
34 IN EFI_HANDLE ImageHandle
,
46 TODO: Add function description
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
60 TODO: add return values
64 EFI_PCI_ROM_IMAGE_MAPPING
*TempMapping
;
66 if (mNumberOfPciRomImages
>= mMaxNumberOfPciRomImages
) {
68 mMaxNumberOfPciRomImages
+= 0x20;
71 TempMapping
= AllocatePool (mMaxNumberOfPciRomImages
* sizeof (EFI_PCI_ROM_IMAGE_MAPPING
));
72 if (TempMapping
== NULL
) {
76 CopyMem (TempMapping
, mRomImageTable
, mNumberOfPciRomImages
* sizeof (EFI_PCI_ROM_IMAGE_MAPPING
));
78 if (mRomImageTable
!= NULL
) {
79 gBS
->FreePool (mRomImageTable
);
82 mRomImageTable
= TempMapping
;
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
++;
96 PciRomGetRomResourceFromPciOptionRomTable (
97 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
98 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
,
99 PCI_IO_DEVICE
*PciIoDevice
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
117 EFI_PCI_OPTION_ROM_TABLE
*PciOptionRomTable
;
118 EFI_PCI_OPTION_ROM_DESCRIPTOR
*PciOptionRomDescriptor
;
121 Status
= EfiGetSystemConfigurationTable (&gEfiPciOptionRomTableGuid
, (VOID
**) &PciOptionRomTable
);
122 if (EFI_ERROR (Status
)) {
123 return EFI_NOT_FOUND
;
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
) {
133 PciIoDevice
->PciIo
.RomImage
= (VOID
*) (UINTN
) PciOptionRomDescriptor
->RomAddress
;
134 PciIoDevice
->PciIo
.RomSize
= (UINTN
) PciOptionRomDescriptor
->RomLength
;
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
) {
144 AddDriver (PciIoDevice
, mRomImageTable
[Index
].ImageHandle
);
152 PciRomGetImageMapping (
153 PCI_IO_DEVICE
*PciIoDevice
164 // TODO: PciIoDevice - add argument and description to function comment
165 // TODO: EFI_SUCCESS - add return value to function comment
167 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
170 PciRootBridgeIo
= PciIoDevice
->PciRootBridgeIo
;
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
) {
178 if (mRomImageTable
[Index
].ImageHandle
!= NULL
) {
179 AddDriver (PciIoDevice
, mRomImageTable
[Index
].ImageHandle
);
181 PciIoDevice
->PciIo
.RomImage
= (VOID
*) (UINTN
) mRomImageTable
[Index
].RomAddress
;
182 PciIoDevice
->PciIo
.RomSize
= (UINTN
) mRomImageTable
[Index
].RomLength
;