2 Header file for Pci shell Debug1 function.
4 Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
5 Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #ifndef _EFI_SHELL_PCI_H_
17 #define _EFI_SHELL_PCI_H_
26 #define HEADER_TYPE_MULTI_FUNCTION 0x80
28 #define MAX_BUS_NUMBER 255
29 #define MAX_DEVICE_NUMBER 31
30 #define MAX_FUNCTION_NUMBER 7
32 #define EFI_PCI_CAPABILITY_ID_PCIEXP 0x10
33 #define EFI_PCI_CAPABILITY_ID_PCIX 0x07
35 #define CALC_EFI_PCI_ADDRESS(Bus, Dev, Func, Reg) \
36 ((UINT64) ((((UINTN) Bus) << 24) + (((UINTN) Dev) << 16) + (((UINTN) Func) << 8) + ((UINTN) Reg)))
38 #define CALC_EFI_PCIEX_ADDRESS(Bus, Dev, Func, ExReg) ( \
39 (UINT64) ((((UINTN) Bus) << 24) + (((UINTN) Dev) << 16) + (((UINTN) Func) << 8) + (LShiftU64 ((UINT64) ExReg, 32))) \
42 #define INDEX_OF(Field) ((UINT8 *) (Field) - (UINT8 *) mConfigSpace)
44 #define PCI_BIT_0 0x00000001
45 #define PCI_BIT_1 0x00000002
46 #define PCI_BIT_2 0x00000004
47 #define PCI_BIT_3 0x00000008
48 #define PCI_BIT_4 0x00000010
49 #define PCI_BIT_5 0x00000020
50 #define PCI_BIT_6 0x00000040
51 #define PCI_BIT_7 0x00000080
52 #define PCI_BIT_8 0x00000100
53 #define PCI_BIT_9 0x00000200
54 #define PCI_BIT_10 0x00000400
55 #define PCI_BIT_11 0x00000800
56 #define PCI_BIT_12 0x00001000
57 #define PCI_BIT_13 0x00002000
58 #define PCI_BIT_14 0x00004000
59 #define PCI_BIT_15 0x00008000
62 // PCIE device/port types
64 #define PCIE_PCIE_ENDPOINT 0
65 #define PCIE_LEGACY_PCIE_ENDPOINT 1
66 #define PCIE_ROOT_COMPLEX_ROOT_PORT 4
67 #define PCIE_SWITCH_UPSTREAM_PORT 5
68 #define PCIE_SWITCH_DOWNSTREAM_PORT 6
69 #define PCIE_PCIE_TO_PCIX_BRIDGE 7
70 #define PCIE_PCIX_TO_PCIE_BRIDGE 8
71 #define PCIE_ROOT_COMPLEX_INTEGRATED_PORT 9
72 #define PCIE_ROOT_COMPLEX_EVENT_COLLECTOR 10
73 #define PCIE_DEVICE_PORT_TYPE_MAX 11
75 #define IS_PCIE_ENDPOINT(DevicePortType) \
76 ((DevicePortType) == PCIE_PCIE_ENDPOINT || \
77 (DevicePortType) == PCIE_LEGACY_PCIE_ENDPOINT || \
78 (DevicePortType) == PCIE_ROOT_COMPLEX_INTEGRATED_PORT)
80 #define IS_PCIE_SWITCH(DevicePortType) \
81 ((DevicePortType == PCIE_SWITCH_UPSTREAM_PORT) || \
82 (DevicePortType == PCIE_SWITCH_DOWNSTREAM_PORT))
85 // Capabilities Register
87 #define PCIE_CAP_VERSION(PcieCapReg) \
89 #define PCIE_CAP_DEVICEPORT_TYPE(PcieCapReg) \
90 (((PcieCapReg) >> 4) & 0x0f)
91 #define PCIE_CAP_SLOT_IMPLEMENTED(PcieCapReg) \
92 (((PcieCapReg) >> 8) & 0x1)
93 #define PCIE_CAP_INT_MSG_NUM(PcieCapReg) \
94 (((PcieCapReg) >> 9) & 0x1f)
96 // Device Capabilities Register
98 #define PCIE_CAP_MAX_PAYLOAD(PcieDeviceCap) \
99 ((PcieDeviceCap) & 0x7)
100 #define PCIE_CAP_PHANTOM_FUNC(PcieDeviceCap) \
101 (((PcieDeviceCap) >> 3) & 0x3)
102 #define PCIE_CAP_EXTENDED_TAG(PcieDeviceCap) \
103 (((PcieDeviceCap) >> 5) & 0x1)
104 #define PCIE_CAP_L0SLATENCY(PcieDeviceCap) \
105 (((PcieDeviceCap) >> 6) & 0x7)
106 #define PCIE_CAP_L1LATENCY(PcieDeviceCap) \
107 (((PcieDeviceCap) >> 9) & 0x7)
108 #define PCIE_CAP_ERR_REPORTING(PcieDeviceCap) \
109 (((PcieDeviceCap) >> 15) & 0x1)
110 #define PCIE_CAP_SLOT_POWER_VALUE(PcieDeviceCap) \
111 (((PcieDeviceCap) >> 18) & 0x0ff)
112 #define PCIE_CAP_SLOT_POWER_SCALE(PcieDeviceCap) \
113 (((PcieDeviceCap) >> 26) & 0x3)
114 #define PCIE_CAP_FUNC_LEVEL_RESET(PcieDeviceCap) \
115 (((PcieDeviceCap) >> 28) & 0x1)
117 // Device Control Register
119 #define PCIE_CAP_COR_ERR_REPORTING_ENABLE(PcieDeviceControl) \
120 ((PcieDeviceControl) & 0x1)
121 #define PCIE_CAP_NONFAT_ERR_REPORTING_ENABLE(PcieDeviceControl) \
122 (((PcieDeviceControl) >> 1) & 0x1)
123 #define PCIE_CAP_FATAL_ERR_REPORTING_ENABLE(PcieDeviceControl) \
124 (((PcieDeviceControl) >> 2) & 0x1)
125 #define PCIE_CAP_UNSUP_REQ_REPORTING_ENABLE(PcieDeviceControl) \
126 (((PcieDeviceControl) >> 3) & 0x1)
127 #define PCIE_CAP_RELAXED_ORDERING_ENABLE(PcieDeviceControl) \
128 (((PcieDeviceControl) >> 4) & 0x1)
129 #define PCIE_CAP_MAX_PAYLOAD_SIZE(PcieDeviceControl) \
130 (((PcieDeviceControl) >> 5) & 0x7)
131 #define PCIE_CAP_EXTENDED_TAG_ENABLE(PcieDeviceControl) \
132 (((PcieDeviceControl) >> 8) & 0x1)
133 #define PCIE_CAP_PHANTOM_FUNC_ENABLE(PcieDeviceControl) \
134 (((PcieDeviceControl) >> 9) & 0x1)
135 #define PCIE_CAP_AUX_PM_ENABLE(PcieDeviceControl) \
136 (((PcieDeviceControl) >> 10) & 0x1)
137 #define PCIE_CAP_NO_SNOOP_ENABLE(PcieDeviceControl) \
138 (((PcieDeviceControl) >> 11) & 0x1)
139 #define PCIE_CAP_MAX_READ_REQ_SIZE(PcieDeviceControl) \
140 (((PcieDeviceControl) >> 12) & 0x7)
141 #define PCIE_CAP_BRG_CONF_RETRY(PcieDeviceControl) \
142 (((PcieDeviceControl) >> 15) & 0x1)
144 // Device Status Register
146 #define PCIE_CAP_COR_ERR_DETECTED(PcieDeviceStatus) \
147 ((PcieDeviceStatus) & 0x1)
148 #define PCIE_CAP_NONFAT_ERR_DETECTED(PcieDeviceStatus) \
149 (((PcieDeviceStatus) >> 1) & 0x1)
150 #define PCIE_CAP_FATAL_ERR_DETECTED(PcieDeviceStatus) \
151 (((PcieDeviceStatus) >> 2) & 0x1)
152 #define PCIE_CAP_UNSUP_REQ_DETECTED(PcieDeviceStatus) \
153 (((PcieDeviceStatus) >> 3) & 0x1)
154 #define PCIE_CAP_AUX_POWER_DETECTED(PcieDeviceStatus) \
155 (((PcieDeviceStatus) >> 4) & 0x1)
156 #define PCIE_CAP_TRANSACTION_PENDING(PcieDeviceStatus) \
157 (((PcieDeviceStatus) >> 5) & 0x1)
159 // Link Capabilities Register
161 #define PCIE_CAP_MAX_LINK_SPEED(PcieLinkCap) \
162 ((PcieLinkCap) & 0x0f)
163 #define PCIE_CAP_MAX_LINK_WIDTH(PcieLinkCap) \
164 (((PcieLinkCap) >> 4) & 0x3f)
165 #define PCIE_CAP_ASPM_SUPPORT(PcieLinkCap) \
166 (((PcieLinkCap) >> 10) & 0x3)
167 #define PCIE_CAP_L0S_LATENCY(PcieLinkCap) \
168 (((PcieLinkCap) >> 12) & 0x7)
169 #define PCIE_CAP_L1_LATENCY(PcieLinkCap) \
170 (((PcieLinkCap) >> 15) & 0x7)
171 #define PCIE_CAP_CLOCK_PM(PcieLinkCap) \
172 (((PcieLinkCap) >> 18) & 0x1)
173 #define PCIE_CAP_SUP_DOWN_ERR_REPORTING(PcieLinkCap) \
174 (((PcieLinkCap) >> 19) & 0x1)
175 #define PCIE_CAP_LINK_ACTIVE_REPORTING(PcieLinkCap) \
176 (((PcieLinkCap) >> 20) & 0x1)
177 #define PCIE_CAP_LINK_BWD_NOTIF_CAP(PcieLinkCap) \
178 (((PcieLinkCap) >> 21) & 0x1)
179 #define PCIE_CAP_PORT_NUMBER(PcieLinkCap) \
180 (((PcieLinkCap) >> 24) & 0x0ff)
182 // Link Control Register
184 #define PCIE_CAP_ASPM_CONTROL(PcieLinkControl) \
185 ((PcieLinkControl) & 0x3)
186 #define PCIE_CAP_RCB(PcieLinkControl) \
187 (((PcieLinkControl) >> 3) & 0x1)
188 #define PCIE_CAP_LINK_DISABLE(PcieLinkControl) \
189 (((PcieLinkControl) >> 4) & 0x1)
190 #define PCIE_CAP_COMMON_CLK_CONF(PcieLinkControl) \
191 (((PcieLinkControl) >> 6) & 0x1)
192 #define PCIE_CAP_EXT_SYNC(PcieLinkControl) \
193 (((PcieLinkControl) >> 7) & 0x1)
194 #define PCIE_CAP_CLK_PWR_MNG(PcieLinkControl) \
195 (((PcieLinkControl) >> 8) & 0x1)
196 #define PCIE_CAP_HW_AUTO_WIDTH_DISABLE(PcieLinkControl) \
197 (((PcieLinkControl) >> 9) & 0x1)
198 #define PCIE_CAP_LINK_BDW_MNG_INT_EN(PcieLinkControl) \
199 (((PcieLinkControl) >> 10) & 0x1)
200 #define PCIE_CAP_LINK_AUTO_BDW_INT_EN(PcieLinkControl) \
201 (((PcieLinkControl) >> 11) & 0x1)
203 // Link Status Register
205 #define PCIE_CAP_CUR_LINK_SPEED(PcieLinkStatus) \
206 ((PcieLinkStatus) & 0x0f)
207 #define PCIE_CAP_NEGO_LINK_WIDTH(PcieLinkStatus) \
208 (((PcieLinkStatus) >> 4) & 0x3f)
209 #define PCIE_CAP_LINK_TRAINING(PcieLinkStatus) \
210 (((PcieLinkStatus) >> 11) & 0x1)
211 #define PCIE_CAP_SLOT_CLK_CONF(PcieLinkStatus) \
212 (((PcieLinkStatus) >> 12) & 0x1)
213 #define PCIE_CAP_DATA_LINK_ACTIVE(PcieLinkStatus) \
214 (((PcieLinkStatus) >> 13) & 0x1)
215 #define PCIE_CAP_LINK_BDW_MNG_STAT(PcieLinkStatus) \
216 (((PcieLinkStatus) >> 14) & 0x1)
217 #define PCIE_CAP_LINK_AUTO_BDW_STAT(PcieLinkStatus) \
218 (((PcieLinkStatus) >> 15) & 0x1)
220 // Slot Capabilities Register
222 #define PCIE_CAP_ATT_BUT_PRESENT(PcieSlotCap) \
223 ((PcieSlotCap) & 0x1)
224 #define PCIE_CAP_PWR_CTRLLER_PRESENT(PcieSlotCap) \
225 (((PcieSlotCap) >> 1) & 0x1)
226 #define PCIE_CAP_MRL_SENSOR_PRESENT(PcieSlotCap) \
227 (((PcieSlotCap) >> 2) & 0x1)
228 #define PCIE_CAP_ATT_IND_PRESENT(PcieSlotCap) \
229 (((PcieSlotCap) >> 3) & 0x1)
230 #define PCIE_CAP_PWD_IND_PRESENT(PcieSlotCap) \
231 (((PcieSlotCap) >> 4) & 0x1)
232 #define PCIE_CAP_HOTPLUG_SUPPRISE(PcieSlotCap) \
233 (((PcieSlotCap) >> 5) & 0x1)
234 #define PCIE_CAP_HOTPLUG_CAPABLE(PcieSlotCap) \
235 (((PcieSlotCap) >> 6) & 0x1)
236 #define PCIE_CAP_SLOT_PWR_LIMIT_VALUE(PcieSlotCap) \
237 (((PcieSlotCap) >> 7) & 0x0ff)
238 #define PCIE_CAP_SLOT_PWR_LIMIT_SCALE(PcieSlotCap) \
239 (((PcieSlotCap) >> 15) & 0x3)
240 #define PCIE_CAP_ELEC_INTERLOCK_PRESENT(PcieSlotCap) \
241 (((PcieSlotCap) >> 17) & 0x1)
242 #define PCIE_CAP_NO_COMM_COMPLETED_SUP(PcieSlotCap) \
243 (((PcieSlotCap) >> 18) & 0x1)
244 #define PCIE_CAP_PHY_SLOT_NUM(PcieSlotCap) \
245 (((PcieSlotCap) >> 19) & 0x1fff)
247 // Slot Control Register
249 #define PCIE_CAP_ATT_BUT_ENABLE(PcieSlotControl) \
250 ((PcieSlotControl) & 0x1)
251 #define PCIE_CAP_PWR_FLT_DETECT_ENABLE(PcieSlotControl) \
252 (((PcieSlotControl) >> 1) & 0x1)
253 #define PCIE_CAP_MRL_SENSOR_CHANGE_ENABLE(PcieSlotControl) \
254 (((PcieSlotControl) >> 2) & 0x1)
255 #define PCIE_CAP_PRES_DETECT_CHANGE_ENABLE(PcieSlotControl) \
256 (((PcieSlotControl) >> 3) & 0x1)
257 #define PCIE_CAP_COMM_CMPL_INT_ENABLE(PcieSlotControl) \
258 (((PcieSlotControl) >> 4) & 0x1)
259 #define PCIE_CAP_HOTPLUG_INT_ENABLE(PcieSlotControl) \
260 (((PcieSlotControl) >> 5) & 0x1)
261 #define PCIE_CAP_ATT_IND_CTRL(PcieSlotControl) \
262 (((PcieSlotControl) >> 6) & 0x3)
263 #define PCIE_CAP_PWR_IND_CTRL(PcieSlotControl) \
264 (((PcieSlotControl) >> 8) & 0x3)
265 #define PCIE_CAP_PWR_CTRLLER_CTRL(PcieSlotControl) \
266 (((PcieSlotControl) >> 10) & 0x1)
267 #define PCIE_CAP_ELEC_INTERLOCK_CTRL(PcieSlotControl) \
268 (((PcieSlotControl) >> 11) & 0x1)
269 #define PCIE_CAP_DLINK_STAT_CHANGE_ENABLE(PcieSlotControl) \
270 (((PcieSlotControl) >> 12) & 0x1)
272 // Slot Status Register
274 #define PCIE_CAP_ATT_BUT_PRESSED(PcieSlotStatus) \
275 ((PcieSlotStatus) & 0x1)
276 #define PCIE_CAP_PWR_FLT_DETECTED(PcieSlotStatus) \
277 (((PcieSlotStatus) >> 1) & 0x1)
278 #define PCIE_CAP_MRL_SENSOR_CHANGED(PcieSlotStatus) \
279 (((PcieSlotStatus) >> 2) & 0x1)
280 #define PCIE_CAP_PRES_DETECT_CHANGED(PcieSlotStatus) \
281 (((PcieSlotStatus) >> 3) & 0x1)
282 #define PCIE_CAP_COMM_COMPLETED(PcieSlotStatus) \
283 (((PcieSlotStatus) >> 4) & 0x1)
284 #define PCIE_CAP_MRL_SENSOR_STATE(PcieSlotStatus) \
285 (((PcieSlotStatus) >> 5) & 0x1)
286 #define PCIE_CAP_PRES_DETECT_STATE(PcieSlotStatus) \
287 (((PcieSlotStatus) >> 6) & 0x1)
288 #define PCIE_CAP_ELEC_INTERLOCK_STATE(PcieSlotStatus) \
289 (((PcieSlotStatus) >> 7) & 0x1)
290 #define PCIE_CAP_DLINK_STAT_CHANGED(PcieSlotStatus) \
291 (((PcieSlotStatus) >> 8) & 0x1)
293 // Root Control Register
295 #define PCIE_CAP_SYSERR_ON_CORERR_EN(PcieRootControl) \
296 ((PcieRootControl) & 0x1)
297 #define PCIE_CAP_SYSERR_ON_NONFATERR_EN(PcieRootControl) \
298 (((PcieRootControl) >> 1) & 0x1)
299 #define PCIE_CAP_SYSERR_ON_FATERR_EN(PcieRootControl) \
300 (((PcieRootControl) >> 2) & 0x1)
301 #define PCIE_CAP_PME_INT_ENABLE(PcieRootControl) \
302 (((PcieRootControl) >> 3) & 0x1)
303 #define PCIE_CAP_CRS_SW_VIS_ENABLE(PcieRootControl) \
304 (((PcieRootControl) >> 4) & 0x1)
306 // Root Capabilities Register
308 #define PCIE_CAP_CRS_SW_VIS(PcieRootCap) \
309 ((PcieRootCap) & 0x1)
311 // Root Status Register
313 #define PCIE_CAP_PME_REQ_ID(PcieRootStatus) \
314 ((PcieRootStatus) & 0x0ffff)
315 #define PCIE_CAP_PME_STATUS(PcieRootStatus) \
316 (((PcieRootStatus) >> 16) & 0x1)
317 #define PCIE_CAP_PME_PENDING(PcieRootStatus) \
318 (((PcieRootStatus) >> 17) & 0x1)
322 // Common part of the PCI configuration space header for devices, P2P bridges,
323 // and cardbus bridges
336 UINT8 PrimaryLatencyTimer
;
343 // PCI configuration space header for devices(after the common part)
346 UINT32 Bar
[6]; // Base Address Registers
347 UINT32 CardBusCISPtr
; // CardBus CIS Pointer
348 UINT16 SubVendorId
; // Subsystem Vendor ID
349 UINT16 SubSystemId
; // Subsystem ID
350 UINT32 ROMBar
; // Expansion ROM Base Address
351 UINT8 CapabilitiesPtr
; // Capabilities Pointer
356 UINT8 InterruptLine
; // Interrupt Line
357 UINT8 InterruptPin
; // Interrupt Pin
358 UINT8 MinGnt
; // Min_Gnt
359 UINT8 MaxLat
; // Max_Lat
363 // PCI configuration space header for pci-to-pci bridges(after the common part)
366 UINT32 Bar
[2]; // Base Address Registers
367 UINT8 PrimaryBus
; // Primary Bus Number
368 UINT8 SecondaryBus
; // Secondary Bus Number
369 UINT8 SubordinateBus
; // Subordinate Bus Number
370 UINT8 SecondaryLatencyTimer
; // Secondary Latency Timer
371 UINT8 IoBase
; // I/O Base
372 UINT8 IoLimit
; // I/O Limit
373 UINT16 SecondaryStatus
; // Secondary Status
374 UINT16 MemoryBase
; // Memory Base
375 UINT16 MemoryLimit
; // Memory Limit
376 UINT16 PrefetchableMemBase
; // Pre-fetchable Memory Base
377 UINT16 PrefetchableMemLimit
; // Pre-fetchable Memory Limit
378 UINT32 PrefetchableBaseUpper
; // Pre-fetchable Base Upper 32 bits
379 UINT32 PrefetchableLimitUpper
; // Pre-fetchable Limit Upper 32 bits
380 UINT16 IoBaseUpper
; // I/O Base Upper 16 bits
381 UINT16 IoLimitUpper
; // I/O Limit Upper 16 bits
382 UINT8 CapabilitiesPtr
; // Capabilities Pointer
385 UINT32 ROMBar
; // Expansion ROM Base Address
386 UINT8 InterruptLine
; // Interrupt Line
387 UINT8 InterruptPin
; // Interrupt Pin
388 UINT16 BridgeControl
; // Bridge Control
392 // PCI configuration space header for cardbus bridges(after the common part)
395 UINT32 CardBusSocketReg
; // Cardus Socket/ExCA Base
398 UINT8 CapabilitiesPtr
; // 14h in pci-cardbus bridge.
400 UINT16 SecondaryStatus
; // Secondary Status
401 UINT8 PciBusNumber
; // PCI Bus Number
402 UINT8 CardBusBusNumber
; // CardBus Bus Number
403 UINT8 SubordinateBusNumber
; // Subordinate Bus Number
404 UINT8 CardBusLatencyTimer
; // CardBus Latency Timer
405 UINT32 MemoryBase0
; // Memory Base Register 0
406 UINT32 MemoryLimit0
; // Memory Limit Register 0
410 UINT32 IoLimit0
; // I/O Base Register 0
411 UINT32 IoBase1
; // I/O Limit Register 0
414 UINT8 InterruptLine
; // Interrupt Line
415 UINT8 InterruptPin
; // Interrupt Pin
416 UINT16 BridgeControl
; // Bridge Control
417 } PCI_CARDBUS_HEADER
;
420 // Data region after PCI configuration header(for cardbus bridge)
423 UINT16 SubVendorId
; // Subsystem Vendor ID
424 UINT16 SubSystemId
; // Subsystem ID
425 UINT32 LegacyBase
; // Optional 16-Bit PC Card Legacy
432 PCI_DEVICE_HEADER Device
;
433 PCI_BRIDGE_HEADER Bridge
;
434 PCI_CARDBUS_HEADER CardBus
;
438 PCI_COMMON_HEADER Common
;
439 NON_COMMON_UNION NonCommon
;
447 UINT32 PcieDeviceCap
;
448 UINT16 DeviceControl
;
459 } PCIE_CAP_STURCTURE
;