]> git.proxmox.com Git - mirror_edk2.git/blame - CorebootPayloadPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
CorebootPayloadPkg: Fix various typos
[mirror_edk2.git] / CorebootPayloadPkg / Library / PciHostBridgeLib / PciHostBridgeLib.c
CommitLineData
69787a9d
MM
1/** @file\r
2 Library instance of PciHostBridgeLib library class for coreboot.\r
3\r
4 Copyright (C) 2016, Red Hat, Inc.\r
5 Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
6\r
7 This program and the accompanying materials are licensed and made available\r
8 under the terms and conditions of the BSD License which accompanies this\r
9 distribution. The full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php.\r
11\r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT\r
13 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16#include <PiDxe.h>\r
17\r
18#include <IndustryStandard/Pci.h>\r
19#include <Protocol/PciHostBridgeResourceAllocation.h>\r
20#include <Protocol/PciRootBridgeIo.h>\r
21\r
22#include <Library/BaseMemoryLib.h>\r
23#include <Library/DebugLib.h>\r
24#include <Library/DevicePathLib.h>\r
25#include <Library/MemoryAllocationLib.h>\r
26#include <Library/PciHostBridgeLib.h>\r
27#include <Library/PciLib.h>\r
28\r
29#include "PciHostBridge.h"\r
30\r
31STATIC\r
32CONST\r
33CB_PCI_ROOT_BRIDGE_DEVICE_PATH mRootBridgeDevicePathTemplate = {\r
34 {\r
35 {\r
36 ACPI_DEVICE_PATH,\r
37 ACPI_DP,\r
38 {\r
39 (UINT8) (sizeof(ACPI_HID_DEVICE_PATH)),\r
40 (UINT8) ((sizeof(ACPI_HID_DEVICE_PATH)) >> 8)\r
41 }\r
42 },\r
43 EISA_PNP_ID(0x0A03), // HID\r
44 0 // UID\r
45 },\r
46\r
47 {\r
48 END_DEVICE_PATH_TYPE,\r
49 END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
50 {\r
51 END_DEVICE_PATH_LENGTH,\r
52 0\r
53 }\r
54 }\r
55};\r
56\r
57\r
58/**\r
59 Initialize a PCI_ROOT_BRIDGE structure.\r
60\r
61 @param[in] Supports Supported attributes.\r
62\r
63 @param[in] Attributes Initial attributes.\r
64\r
65 @param[in] AllocAttributes Allocation attributes.\r
66\r
67 @param[in] RootBusNumber The bus number to store in RootBus.\r
68\r
69 @param[in] MaxSubBusNumber The inclusive maximum bus number that can be\r
70 assigned to any subordinate bus found behind any\r
71 PCI bridge hanging off this root bus.\r
72\r
68f87b25 73 The caller is responsible for ensuring that\r
69787a9d
MM
74 RootBusNumber <= MaxSubBusNumber. If\r
75 RootBusNumber equals MaxSubBusNumber, then the\r
76 root bus has no room for subordinate buses.\r
77\r
78 @param[in] Io IO aperture.\r
79\r
80 @param[in] Mem MMIO aperture.\r
81\r
82 @param[in] MemAbove4G MMIO aperture above 4G.\r
83\r
84 @param[in] PMem Prefetchable MMIO aperture.\r
85\r
86 @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.\r
87\r
88 @param[out] RootBus The PCI_ROOT_BRIDGE structure (allocated by the\r
89 caller) that should be filled in by this\r
90 function.\r
91\r
92 @retval EFI_SUCCESS Initialization successful. A device path\r
93 consisting of an ACPI device path node, with\r
94 UID = RootBusNumber, has been allocated and\r
95 linked into RootBus.\r
96\r
97 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.\r
98**/\r
99EFI_STATUS\r
100InitRootBridge (\r
101 IN UINT64 Supports,\r
102 IN UINT64 Attributes,\r
103 IN UINT64 AllocAttributes,\r
104 IN UINT8 RootBusNumber,\r
105 IN UINT8 MaxSubBusNumber,\r
106 IN PCI_ROOT_BRIDGE_APERTURE *Io,\r
107 IN PCI_ROOT_BRIDGE_APERTURE *Mem,\r
108 IN PCI_ROOT_BRIDGE_APERTURE *MemAbove4G,\r
109 IN PCI_ROOT_BRIDGE_APERTURE *PMem,\r
110 IN PCI_ROOT_BRIDGE_APERTURE *PMemAbove4G,\r
111 OUT PCI_ROOT_BRIDGE *RootBus\r
112)\r
113{\r
114 CB_PCI_ROOT_BRIDGE_DEVICE_PATH *DevicePath;\r
115\r
116 //\r
117 // Be safe if other fields are added to PCI_ROOT_BRIDGE later.\r
118 //\r
119 ZeroMem (RootBus, sizeof *RootBus);\r
120\r
121 RootBus->Segment = 0;\r
122\r
123 RootBus->Supports = Supports;\r
124 RootBus->Attributes = Attributes;\r
125\r
126 RootBus->DmaAbove4G = FALSE;\r
127\r
128 RootBus->AllocationAttributes = AllocAttributes;\r
129 RootBus->Bus.Base = RootBusNumber;\r
130 RootBus->Bus.Limit = MaxSubBusNumber;\r
131 CopyMem (&RootBus->Io, Io, sizeof (*Io));\r
132 CopyMem (&RootBus->Mem, Mem, sizeof (*Mem));\r
133 CopyMem (&RootBus->MemAbove4G, MemAbove4G, sizeof (*MemAbove4G));\r
134 CopyMem (&RootBus->PMem, PMem, sizeof (*PMem));\r
135 CopyMem (&RootBus->PMemAbove4G, PMemAbove4G, sizeof (*PMemAbove4G));\r
136\r
137 RootBus->NoExtendedConfigSpace = FALSE;\r
138\r
139 DevicePath = AllocateCopyPool (sizeof (mRootBridgeDevicePathTemplate),\r
140 &mRootBridgeDevicePathTemplate);\r
141 if (DevicePath == NULL) {\r
142 DEBUG ((EFI_D_ERROR, "%a: %r\n", __FUNCTION__, EFI_OUT_OF_RESOURCES));\r
143 return EFI_OUT_OF_RESOURCES;\r
144 }\r
145 DevicePath->AcpiDevicePath.UID = RootBusNumber;\r
146 RootBus->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)DevicePath;\r
147\r
148 DEBUG ((EFI_D_INFO,\r
149 "%a: populated root bus %d, with room for %d subordinate bus(es)\n",\r
150 __FUNCTION__, RootBusNumber, MaxSubBusNumber - RootBusNumber));\r
151 return EFI_SUCCESS;\r
152}\r
153\r
154\r
155/**\r
156 Return all the root bridge instances in an array.\r
157\r
158 @param Count Return the count of root bridge instances.\r
159\r
160 @return All the root bridge instances in an array.\r
161 The array should be passed into PciHostBridgeFreeRootBridges()\r
162 when it's not used.\r
163**/\r
164PCI_ROOT_BRIDGE *\r
165EFIAPI\r
166PciHostBridgeGetRootBridges (\r
167 UINTN *Count\r
168)\r
169{\r
170 return ScanForRootBridges (Count);\r
171}\r
172\r
173\r
174/**\r
175 Free the root bridge instances array returned from\r
176 PciHostBridgeGetRootBridges().\r
177\r
178 @param The root bridge instances array.\r
179 @param The count of the array.\r
180**/\r
181VOID\r
182EFIAPI\r
183PciHostBridgeFreeRootBridges (\r
184 PCI_ROOT_BRIDGE *Bridges,\r
185 UINTN Count\r
186)\r
187{\r
188 if (Bridges == NULL && Count == 0) {\r
189 return;\r
190 }\r
191 ASSERT (Bridges != NULL && Count > 0);\r
192\r
193 do {\r
194 --Count;\r
195 FreePool (Bridges[Count].DevicePath);\r
196 } while (Count > 0);\r
197\r
198 FreePool (Bridges);\r
199}\r
200\r
201\r
202/**\r
203 Inform the platform that the resource conflict happens.\r
204\r
205 @param HostBridgeHandle Handle of the Host Bridge.\r
206 @param Configuration Pointer to PCI I/O and PCI memory resource\r
207 descriptors. The Configuration contains the resources\r
208 for all the root bridges. The resource for each root\r
209 bridge is terminated with END descriptor and an\r
210 additional END is appended indicating the end of the\r
211 entire resources. The resource descriptor field\r
212 values follow the description in\r
213 EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL\r
214 .SubmitResources().\r
215**/\r
216VOID\r
217EFIAPI\r
218PciHostBridgeResourceConflict (\r
219 EFI_HANDLE HostBridgeHandle,\r
220 VOID *Configuration\r
221)\r
222{\r
223 //\r
224 // coreboot UEFI Payload does not do PCI enumeration and should not call this\r
225 // library interface.\r
226 //\r
227 ASSERT (FALSE);\r
228}\r