]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h
90fdaa3b62b97dc1e94fda4847b2340ad3c374aa
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / PciBusDxe / PciBus.h
1 /** @file
2 Header files and data structures needed by PCI Bus module.
3
4 Copyright (c) 2006 - 2009, 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
16 #ifndef _EFI_PCI_BUS_H_
17 #define _EFI_PCI_BUS_H_
18
19 #include <PiDxe.h>
20
21 #include <Protocol/LoadedImage.h>
22 #include <Protocol/PciHostBridgeResourceAllocation.h>
23 #include <Protocol/PciIo.h>
24 #include <Protocol/LoadFile2.h>
25 #include <Protocol/PciRootBridgeIo.h>
26 #include <Protocol/PciHotPlugRequest.h>
27 #include <Protocol/DevicePath.h>
28 #include <Protocol/PciPlatform.h>
29 #include <Protocol/PciHotPlugInit.h>
30 #include <Protocol/Decompress.h>
31 #include <Protocol/BusSpecificDriverOverride.h>
32 #include <Protocol/IncompatiblePciDeviceSupport.h>
33 #include <Protocol/PciOverride.h>
34 #include <Protocol/PciEnumerationComplete.h>
35
36 #include <Library/DebugLib.h>
37 #include <Library/UefiDriverEntryPoint.h>
38 #include <Library/BaseLib.h>
39 #include <Library/UefiLib.h>
40 #include <Library/BaseMemoryLib.h>
41 #include <Library/ReportStatusCodeLib.h>
42 #include <Library/MemoryAllocationLib.h>
43 #include <Library/UefiBootServicesTableLib.h>
44 #include <Library/DevicePathLib.h>
45 #include <Library/PcdLib.h>
46 #include <Library/PeCoffLib.h>
47
48 #include <IndustryStandard/Pci.h>
49 #include <IndustryStandard/PeImage.h>
50 #include <IndustryStandard/Acpi.h>
51
52 typedef struct _PCI_IO_DEVICE PCI_IO_DEVICE;
53 typedef struct _PCI_BAR PCI_BAR;
54
55 #define EFI_PCI_RID(Bus, Device, Function) (((UINT32)Bus << 8) + ((UINT32)Device << 3) + (UINT32)Function)
56 #define EFI_PCI_BUS_OF_RID(RID) ((UINT32)RID >> 8)
57
58 #define EFI_PCI_IOV_POLICY_ARI 0x0001
59 #define EFI_PCI_IOV_POLICY_SRIOV 0x0002
60 #define EFI_PCI_IOV_POLICY_MRIOV 0x0004
61
62 typedef enum {
63 PciBarTypeUnknown = 0,
64 PciBarTypeIo16,
65 PciBarTypeIo32,
66 PciBarTypeMem32,
67 PciBarTypePMem32,
68 PciBarTypeMem64,
69 PciBarTypePMem64,
70 PciBarTypeIo,
71 PciBarTypeMem,
72 PciBarTypeMaxType
73 } PCI_BAR_TYPE;
74
75 #include "ComponentName.h"
76 #include "PciIo.h"
77 #include "PciCommand.h"
78 #include "PciDeviceSupport.h"
79 #include "PciEnumerator.h"
80 #include "PciEnumeratorSupport.h"
81 #include "PciDriverOverride.h"
82 #include "PciRomTable.h"
83 #include "PciOptionRomSupport.h"
84 #include "PciPowerManagement.h"
85 #include "PciHotPlugSupport.h"
86 #include "PciLib.h"
87
88 #define VGABASE1 0x3B0
89 #define VGALIMIT1 0x3BB
90
91 #define VGABASE2 0x3C0
92 #define VGALIMIT2 0x3DF
93
94 #define ISABASE 0x100
95 #define ISALIMIT 0x3FF
96
97 //
98 // PCI BAR parameters
99 //
100 struct _PCI_BAR {
101 UINT64 BaseAddress;
102 UINT64 Length;
103 UINT64 Alignment;
104 PCI_BAR_TYPE BarType;
105 BOOLEAN Prefetchable;
106 UINT8 MemType;
107 UINT8 Offset;
108 };
109
110 //
111 // defined in PCI Card Specification, 8.0
112 //
113 #define PCI_CARD_MEMORY_BASE_0 0x1C
114 #define PCI_CARD_MEMORY_LIMIT_0 0x20
115 #define PCI_CARD_MEMORY_BASE_1 0x24
116 #define PCI_CARD_MEMORY_LIMIT_1 0x28
117 #define PCI_CARD_IO_BASE_0_LOWER 0x2C
118 #define PCI_CARD_IO_BASE_0_UPPER 0x2E
119 #define PCI_CARD_IO_LIMIT_0_LOWER 0x30
120 #define PCI_CARD_IO_LIMIT_0_UPPER 0x32
121 #define PCI_CARD_IO_BASE_1_LOWER 0x34
122 #define PCI_CARD_IO_BASE_1_UPPER 0x36
123 #define PCI_CARD_IO_LIMIT_1_LOWER 0x38
124 #define PCI_CARD_IO_LIMIT_1_UPPER 0x3A
125 #define PCI_CARD_BRIDGE_CONTROL 0x3E
126
127 #define PCI_CARD_PREFETCHABLE_MEMORY_0_ENABLE BIT8
128 #define PCI_CARD_PREFETCHABLE_MEMORY_1_ENABLE BIT9
129
130 #define PPB_BAR_0 0
131 #define PPB_BAR_1 1
132 #define PPB_IO_RANGE 2
133 #define PPB_MEM32_RANGE 3
134 #define PPB_PMEM32_RANGE 4
135 #define PPB_PMEM64_RANGE 5
136 #define PPB_MEM64_RANGE 0xFF
137
138 #define P2C_BAR_0 0
139 #define P2C_MEM_1 1
140 #define P2C_MEM_2 2
141 #define P2C_IO_1 3
142 #define P2C_IO_2 4
143
144 #define EFI_BRIDGE_IO32_DECODE_SUPPORTED 0x0001
145 #define EFI_BRIDGE_PMEM32_DECODE_SUPPORTED 0x0002
146 #define EFI_BRIDGE_PMEM64_DECODE_SUPPORTED 0x0004
147 #define EFI_BRIDGE_IO16_DECODE_SUPPORTED 0x0008
148 #define EFI_BRIDGE_PMEM_MEM_COMBINE_SUPPORTED 0x0010
149 #define EFI_BRIDGE_MEM64_DECODE_SUPPORTED 0x0020
150 #define EFI_BRIDGE_MEM32_DECODE_SUPPORTED 0x0040
151
152 #define PCI_MAX_HOST_BRIDGE_NUM 0x0010
153
154 //
155 // Define option for attribute
156 //
157 #define EFI_SET_SUPPORTS 0
158 #define EFI_SET_ATTRIBUTES 1
159
160 #define PCI_IO_DEVICE_SIGNATURE SIGNATURE_32 ('p', 'c', 'i', 'o')
161
162 struct _PCI_IO_DEVICE {
163 UINT32 Signature;
164 EFI_HANDLE Handle;
165 EFI_PCI_IO_PROTOCOL PciIo;
166 LIST_ENTRY Link;
167
168 EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL PciDriverOverride;
169 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
170 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;
171 EFI_LOAD_FILE2_PROTOCOL LoadFile2;
172
173 //
174 // PCI configuration space header type
175 //
176 PCI_TYPE00 Pci;
177
178 //
179 // Bus number, Device number, Function number
180 //
181 UINT8 BusNumber;
182 UINT8 DeviceNumber;
183 UINT8 FunctionNumber;
184
185 //
186 // BAR for this PCI Device
187 //
188 PCI_BAR PciBar[PCI_MAX_BAR];
189
190 //
191 // The bridge device this pci device is subject to
192 //
193 PCI_IO_DEVICE *Parent;
194
195 //
196 // A linked list for children Pci Device if it is bridge device
197 //
198 LIST_ENTRY ChildList;
199
200 //
201 // TURE if the PCI bus driver creates the handle for this PCI device
202 //
203 BOOLEAN Registered;
204
205 //
206 // TRUE if the PCI bus driver successfully allocates the resource required by
207 // this PCI device
208 //
209 BOOLEAN Allocated;
210
211 //
212 // The attribute this PCI device currently set
213 //
214 UINT64 Attributes;
215
216 //
217 // The attributes this PCI device actually supports
218 //
219 UINT64 Supports;
220
221 //
222 // The resource decode the bridge supports
223 //
224 UINT32 Decodes;
225
226 //
227 // The OptionRom Size
228 //
229 UINT64 RomSize;
230
231 //
232 // The OptionRom Size
233 //
234 UINT64 RomBase;
235
236 //
237 // TRUE if all OpROM (in device or in platform specific position) have been processed
238 //
239 BOOLEAN AllOpRomProcessed;
240
241 //
242 // TRUE if there is any EFI driver in the OptionRom
243 //
244 BOOLEAN BusOverride;
245
246 //
247 // A list tracking reserved resource on a bridge device
248 //
249 LIST_ENTRY ReservedResourceList;
250
251 //
252 // A list tracking image handle of platform specific overriding driver
253 //
254 LIST_ENTRY OptionRomDriverList;
255
256 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *ResourcePaddingDescriptors;
257 EFI_HPC_PADDING_ATTRIBUTES PaddingAttributes;
258
259 BOOLEAN IsPciExp;
260 //
261 // For SR-IOV
262 //
263 UINT8 PciExpressCapabilityOffset;
264 UINT32 AriCapabilityOffset;
265 UINT32 SrIovCapabilityOffset;
266 UINT32 MrIovCapabilityOffset;
267 PCI_BAR VfPciBar[PCI_MAX_BAR];
268 UINT32 SystemPageSize;
269 UINT16 InitialVFs;
270 UINT16 ReservedBusNum;
271 //
272 // Per PCI to PCI Bridge spec, I/O window is 4K aligned,
273 // but some chipsets support non-stardard I/O window aligments less than 4K.
274 // This field is used to support this case.
275 //
276 UINT16 BridgeIoAlignment;
277 };
278
279 #define PCI_IO_DEVICE_FROM_PCI_IO_THIS(a) \
280 CR (a, PCI_IO_DEVICE, PciIo, PCI_IO_DEVICE_SIGNATURE)
281
282 #define PCI_IO_DEVICE_FROM_PCI_DRIVER_OVERRIDE_THIS(a) \
283 CR (a, PCI_IO_DEVICE, PciDriverOverride, PCI_IO_DEVICE_SIGNATURE)
284
285 #define PCI_IO_DEVICE_FROM_LINK(a) \
286 CR (a, PCI_IO_DEVICE, Link, PCI_IO_DEVICE_SIGNATURE)
287
288 #define PCI_IO_DEVICE_FROM_LOAD_FILE2_THIS(a) \
289 CR (a, PCI_IO_DEVICE, LoadFile2, PCI_IO_DEVICE_SIGNATURE)
290
291
292
293 //
294 // Global Variables
295 //
296 extern EFI_INCOMPATIBLE_PCI_DEVICE_SUPPORT_PROTOCOL *gEfiIncompatiblePciDeviceSupport;
297 extern EFI_DRIVER_BINDING_PROTOCOL gPciBusDriverBinding;
298 extern EFI_COMPONENT_NAME_PROTOCOL gPciBusComponentName;
299 extern EFI_COMPONENT_NAME2_PROTOCOL gPciBusComponentName2;
300 extern BOOLEAN gFullEnumeration;
301 extern UINTN gPciHostBridgeNumber;
302 extern EFI_HANDLE gPciHostBrigeHandles[PCI_MAX_HOST_BRIDGE_NUM];
303 extern UINT64 gAllOne;
304 extern UINT64 gAllZero;
305 extern EFI_PCI_PLATFORM_PROTOCOL *gPciPlatformProtocol;
306 extern EFI_PCI_OVERRIDE_PROTOCOL *gPciOverrideProtocol;
307
308
309
310 /**
311 Macro that checks whether device is a GFX device.
312
313 @param _p Specified device.
314
315 @retval TRUE Device is a a GFX device.
316 @retval FALSE Device is not a a GFX device.
317
318 **/
319 #define IS_PCI_GFX(_p) IS_CLASS2 (_p, PCI_CLASS_DISPLAY, PCI_CLASS_DISPLAY_OTHER)
320
321 /**
322 Test to see if this driver supports ControllerHandle. Any ControllerHandle
323 than contains a gEfiPciRootBridgeIoProtocolGuid protocol can be supported.
324
325 @param This Protocol instance pointer.
326 @param Controller Handle of device to test.
327 @param RemainingDevicePath Optional parameter use to pick a specific child.
328 device to start.
329
330 @retval EFI_SUCCESS This driver supports this device.
331 @retval EFI_ALREADY_STARTED This driver is already running on this device.
332 @retval other This driver does not support this device.
333
334 **/
335 EFI_STATUS
336 EFIAPI
337 PciBusDriverBindingSupported (
338 IN EFI_DRIVER_BINDING_PROTOCOL *This,
339 IN EFI_HANDLE Controller,
340 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
341 );
342
343 /**
344 Start this driver on ControllerHandle and enumerate Pci bus and start
345 all device under PCI bus.
346
347 @param This Protocol instance pointer.
348 @param Controller Handle of device to bind driver to.
349 @param RemainingDevicePath Optional parameter use to pick a specific child.
350 device to start.
351
352 @retval EFI_SUCCESS This driver is added to ControllerHandle.
353 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.
354 @retval other This driver does not support this device.
355
356 **/
357 EFI_STATUS
358 EFIAPI
359 PciBusDriverBindingStart (
360 IN EFI_DRIVER_BINDING_PROTOCOL *This,
361 IN EFI_HANDLE Controller,
362 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
363 );
364
365 /**
366 Stop this driver on ControllerHandle. Support stoping any child handles
367 created by this driver.
368
369 @param This Protocol instance pointer.
370 @param Controller Handle of device to stop driver on.
371 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
372 children is zero stop the entire bus driver.
373 @param ChildHandleBuffer List of Child Handles to Stop.
374
375 @retval EFI_SUCCESS This driver is removed ControllerHandle.
376 @retval other This driver was not removed from this device.
377
378 **/
379 EFI_STATUS
380 EFIAPI
381 PciBusDriverBindingStop (
382 IN EFI_DRIVER_BINDING_PROTOCOL *This,
383 IN EFI_HANDLE Controller,
384 IN UINTN NumberOfChildren,
385 IN EFI_HANDLE *ChildHandleBuffer
386 );
387
388 #endif