2 Library instance of PciHostBridgeLib library class for coreboot.
4 Copyright (C) 2016, Red Hat, Inc.
5 Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #include <IndustryStandard/Pci.h>
13 #include <Protocol/PciHostBridgeResourceAllocation.h>
14 #include <Protocol/PciRootBridgeIo.h>
16 #include <Library/BaseMemoryLib.h>
17 #include <Library/DebugLib.h>
18 #include <Library/DevicePathLib.h>
19 #include <Library/MemoryAllocationLib.h>
20 #include <Library/PciHostBridgeLib.h>
21 #include <Library/PciLib.h>
23 #include "PciHostBridge.h"
27 CB_PCI_ROOT_BRIDGE_DEVICE_PATH mRootBridgeDevicePathTemplate
= {
33 (UINT8
) (sizeof(ACPI_HID_DEVICE_PATH
)),
34 (UINT8
) ((sizeof(ACPI_HID_DEVICE_PATH
)) >> 8)
37 EISA_PNP_ID(0x0A03), // HID
43 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
45 END_DEVICE_PATH_LENGTH
,
53 Initialize a PCI_ROOT_BRIDGE structure.
55 @param[in] Supports Supported attributes.
57 @param[in] Attributes Initial attributes.
59 @param[in] AllocAttributes Allocation attributes.
61 @param[in] RootBusNumber The bus number to store in RootBus.
63 @param[in] MaxSubBusNumber The inclusive maximum bus number that can be
64 assigned to any subordinate bus found behind any
65 PCI bridge hanging off this root bus.
67 The caller is responsible for ensuring that
68 RootBusNumber <= MaxSubBusNumber. If
69 RootBusNumber equals MaxSubBusNumber, then the
70 root bus has no room for subordinate buses.
72 @param[in] Io IO aperture.
74 @param[in] Mem MMIO aperture.
76 @param[in] MemAbove4G MMIO aperture above 4G.
78 @param[in] PMem Prefetchable MMIO aperture.
80 @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
82 @param[out] RootBus The PCI_ROOT_BRIDGE structure (allocated by the
83 caller) that should be filled in by this
86 @retval EFI_SUCCESS Initialization successful. A device path
87 consisting of an ACPI device path node, with
88 UID = RootBusNumber, has been allocated and
91 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
97 IN UINT64 AllocAttributes
,
98 IN UINT8 RootBusNumber
,
99 IN UINT8 MaxSubBusNumber
,
100 IN PCI_ROOT_BRIDGE_APERTURE
*Io
,
101 IN PCI_ROOT_BRIDGE_APERTURE
*Mem
,
102 IN PCI_ROOT_BRIDGE_APERTURE
*MemAbove4G
,
103 IN PCI_ROOT_BRIDGE_APERTURE
*PMem
,
104 IN PCI_ROOT_BRIDGE_APERTURE
*PMemAbove4G
,
105 OUT PCI_ROOT_BRIDGE
*RootBus
108 CB_PCI_ROOT_BRIDGE_DEVICE_PATH
*DevicePath
;
111 // Be safe if other fields are added to PCI_ROOT_BRIDGE later.
113 ZeroMem (RootBus
, sizeof *RootBus
);
115 RootBus
->Segment
= 0;
117 RootBus
->Supports
= Supports
;
118 RootBus
->Attributes
= Attributes
;
120 RootBus
->DmaAbove4G
= FALSE
;
122 RootBus
->AllocationAttributes
= AllocAttributes
;
123 RootBus
->Bus
.Base
= RootBusNumber
;
124 RootBus
->Bus
.Limit
= MaxSubBusNumber
;
125 CopyMem (&RootBus
->Io
, Io
, sizeof (*Io
));
126 CopyMem (&RootBus
->Mem
, Mem
, sizeof (*Mem
));
127 CopyMem (&RootBus
->MemAbove4G
, MemAbove4G
, sizeof (*MemAbove4G
));
128 CopyMem (&RootBus
->PMem
, PMem
, sizeof (*PMem
));
129 CopyMem (&RootBus
->PMemAbove4G
, PMemAbove4G
, sizeof (*PMemAbove4G
));
131 RootBus
->NoExtendedConfigSpace
= FALSE
;
133 DevicePath
= AllocateCopyPool (sizeof (mRootBridgeDevicePathTemplate
),
134 &mRootBridgeDevicePathTemplate
);
135 if (DevicePath
== NULL
) {
136 DEBUG ((DEBUG_ERROR
, "%a: %r\n", __FUNCTION__
, EFI_OUT_OF_RESOURCES
));
137 return EFI_OUT_OF_RESOURCES
;
139 DevicePath
->AcpiDevicePath
.UID
= RootBusNumber
;
140 RootBus
->DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*)DevicePath
;
143 "%a: populated root bus %d, with room for %d subordinate bus(es)\n",
144 __FUNCTION__
, RootBusNumber
, MaxSubBusNumber
- RootBusNumber
));
150 Return all the root bridge instances in an array.
152 @param Count Return the count of root bridge instances.
154 @return All the root bridge instances in an array.
155 The array should be passed into PciHostBridgeFreeRootBridges()
160 PciHostBridgeGetRootBridges (
164 return ScanForRootBridges (Count
);
169 Free the root bridge instances array returned from
170 PciHostBridgeGetRootBridges().
172 @param The root bridge instances array.
173 @param The count of the array.
177 PciHostBridgeFreeRootBridges (
178 PCI_ROOT_BRIDGE
*Bridges
,
182 if (Bridges
== NULL
&& Count
== 0) {
185 ASSERT (Bridges
!= NULL
&& Count
> 0);
189 FreePool (Bridges
[Count
].DevicePath
);
197 Inform the platform that the resource conflict happens.
199 @param HostBridgeHandle Handle of the Host Bridge.
200 @param Configuration Pointer to PCI I/O and PCI memory resource
201 descriptors. The Configuration contains the resources
202 for all the root bridges. The resource for each root
203 bridge is terminated with END descriptor and an
204 additional END is appended indicating the end of the
205 entire resources. The resource descriptor field
206 values follow the description in
207 EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
212 PciHostBridgeResourceConflict (
213 EFI_HANDLE HostBridgeHandle
,
218 // coreboot UEFI Payload does not do PCI enumeration and should not call this
219 // library interface.