]> mj.ucw.cz Git - pciutils.git/blob - ls-ecaps.c
MacOS: An attempt to appease compiler picky about attribute placement
[pciutils.git] / ls-ecaps.c
1 /*
2  *      The PCI Utilities -- Show Extended Capabilities
3  *
4  *      Copyright (c) 1997--2022 Martin Mares <mj@ucw.cz>
5  *
6  *      Can be freely distributed and used under the terms of the GNU GPL v2+.
7  *
8  *      SPDX-License-Identifier: GPL-2.0-or-later
9  */
10
11 #include <stdio.h>
12 #include <string.h>
13
14 #include "lspci.h"
15
16 static void
17 cap_tph(struct device *d, int where)
18 {
19   u32 tph_cap;
20   printf("Transaction Processing Hints\n");
21   if (verbose < 2)
22     return;
23
24   if (!config_fetch(d, where + PCI_TPH_CAPABILITIES, 4))
25     return;
26
27   tph_cap = get_conf_long(d, where + PCI_TPH_CAPABILITIES);
28
29   if (tph_cap & PCI_TPH_INTVEC_SUP)
30     printf("\t\tInterrupt vector mode supported\n");
31   if (tph_cap & PCI_TPH_DEV_SUP)
32     printf("\t\tDevice specific mode supported\n");
33   if (tph_cap & PCI_TPH_EXT_REQ_SUP)
34     printf("\t\tExtended requester support\n");
35
36   switch (tph_cap & PCI_TPH_ST_LOC_MASK) {
37   case PCI_TPH_ST_NONE:
38     printf("\t\tNo steering table available\n");
39     break;
40   case PCI_TPH_ST_CAP:
41     printf("\t\tSteering table in TPH capability structure\n");
42     break;
43   case PCI_TPH_ST_MSIX:
44     printf("\t\tSteering table in MSI-X table\n");
45     break;
46   default:
47     printf("\t\tReserved steering table location\n");
48     break;
49   }
50 }
51
52 static u32
53 cap_ltr_scale(u8 scale)
54 {
55   return 1 << (scale * 5);
56 }
57
58 static void
59 cap_ltr(struct device *d, int where)
60 {
61   u32 scale;
62   u16 snoop, nosnoop;
63   printf("Latency Tolerance Reporting\n");
64   if (verbose < 2)
65     return;
66
67   if (!config_fetch(d, where + PCI_LTR_MAX_SNOOP, 4))
68     return;
69
70   snoop = get_conf_word(d, where + PCI_LTR_MAX_SNOOP);
71   scale = cap_ltr_scale((snoop >> PCI_LTR_SCALE_SHIFT) & PCI_LTR_SCALE_MASK);
72   printf("\t\tMax snoop latency: %" PCI_U64_FMT_U "ns\n",
73          ((u64)snoop & PCI_LTR_VALUE_MASK) * scale);
74
75   nosnoop = get_conf_word(d, where + PCI_LTR_MAX_NOSNOOP);
76   scale = cap_ltr_scale((nosnoop >> PCI_LTR_SCALE_SHIFT) & PCI_LTR_SCALE_MASK);
77   printf("\t\tMax no snoop latency: %" PCI_U64_FMT_U "ns\n",
78          ((u64)nosnoop & PCI_LTR_VALUE_MASK) * scale);
79 }
80
81 static void
82 cap_sec(struct device *d, int where)
83 {
84   u32 ctrl3, lane_err_stat;
85   u8 lane;
86   printf("Secondary PCI Express\n");
87   if (verbose < 2)
88     return;
89
90   if (!config_fetch(d, where + PCI_SEC_LNKCTL3, 12))
91     return;
92
93   ctrl3 = get_conf_word(d, where + PCI_SEC_LNKCTL3);
94   printf("\t\tLnkCtl3: LnkEquIntrruptEn%c PerformEqu%c\n",
95         FLAG(ctrl3, PCI_SEC_LNKCTL3_LNK_EQU_REQ_INTR_EN),
96         FLAG(ctrl3, PCI_SEC_LNKCTL3_PERFORM_LINK_EQU));
97
98   lane_err_stat = get_conf_word(d, where + PCI_SEC_LANE_ERR);
99   printf("\t\tLaneErrStat: ");
100   if (lane_err_stat)
101     {
102       printf("LaneErr at lane:");
103       for (lane = 0; lane_err_stat; lane_err_stat >>= 1, lane += 1)
104         if (BITS(lane_err_stat, 0, 1))
105           printf(" %u", lane);
106     }
107   else
108     printf("0");
109   printf("\n");
110 }
111
112 static void
113 cap_dsn(struct device *d, int where)
114 {
115   u32 t1, t2;
116   if (!config_fetch(d, where + 4, 8))
117     return;
118   t1 = get_conf_long(d, where + 4);
119   t2 = get_conf_long(d, where + 8);
120   printf("Device Serial Number %02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x\n",
121         t2 >> 24, (t2 >> 16) & 0xff, (t2 >> 8) & 0xff, t2 & 0xff,
122         t1 >> 24, (t1 >> 16) & 0xff, (t1 >> 8) & 0xff, t1 & 0xff);
123 }
124
125 static void
126 cap_aer(struct device *d, int where, int type)
127 {
128   u32 l, l0, l1, l2, l3;
129   u16 w;
130
131   printf("Advanced Error Reporting\n");
132   if (verbose < 2)
133     return;
134
135   if (!config_fetch(d, where + PCI_ERR_UNCOR_STATUS, 40))
136     return;
137
138   l = get_conf_long(d, where + PCI_ERR_UNCOR_STATUS);
139   printf("\t\tUESta:\tDLP%c SDES%c TLP%c FCP%c CmpltTO%c CmpltAbrt%c UnxCmplt%c RxOF%c "
140         "MalfTLP%c ECRC%c UnsupReq%c ACSViol%c\n",
141         FLAG(l, PCI_ERR_UNC_DLP), FLAG(l, PCI_ERR_UNC_SDES), FLAG(l, PCI_ERR_UNC_POISON_TLP),
142         FLAG(l, PCI_ERR_UNC_FCP), FLAG(l, PCI_ERR_UNC_COMP_TIME), FLAG(l, PCI_ERR_UNC_COMP_ABORT),
143         FLAG(l, PCI_ERR_UNC_UNX_COMP), FLAG(l, PCI_ERR_UNC_RX_OVER), FLAG(l, PCI_ERR_UNC_MALF_TLP),
144         FLAG(l, PCI_ERR_UNC_ECRC), FLAG(l, PCI_ERR_UNC_UNSUP), FLAG(l, PCI_ERR_UNC_ACS_VIOL));
145   l = get_conf_long(d, where + PCI_ERR_UNCOR_MASK);
146   printf("\t\tUEMsk:\tDLP%c SDES%c TLP%c FCP%c CmpltTO%c CmpltAbrt%c UnxCmplt%c RxOF%c "
147         "MalfTLP%c ECRC%c UnsupReq%c ACSViol%c\n",
148         FLAG(l, PCI_ERR_UNC_DLP), FLAG(l, PCI_ERR_UNC_SDES), FLAG(l, PCI_ERR_UNC_POISON_TLP),
149         FLAG(l, PCI_ERR_UNC_FCP), FLAG(l, PCI_ERR_UNC_COMP_TIME), FLAG(l, PCI_ERR_UNC_COMP_ABORT),
150         FLAG(l, PCI_ERR_UNC_UNX_COMP), FLAG(l, PCI_ERR_UNC_RX_OVER), FLAG(l, PCI_ERR_UNC_MALF_TLP),
151         FLAG(l, PCI_ERR_UNC_ECRC), FLAG(l, PCI_ERR_UNC_UNSUP), FLAG(l, PCI_ERR_UNC_ACS_VIOL));
152   l = get_conf_long(d, where + PCI_ERR_UNCOR_SEVER);
153   printf("\t\tUESvrt:\tDLP%c SDES%c TLP%c FCP%c CmpltTO%c CmpltAbrt%c UnxCmplt%c RxOF%c "
154         "MalfTLP%c ECRC%c UnsupReq%c ACSViol%c\n",
155         FLAG(l, PCI_ERR_UNC_DLP), FLAG(l, PCI_ERR_UNC_SDES), FLAG(l, PCI_ERR_UNC_POISON_TLP),
156         FLAG(l, PCI_ERR_UNC_FCP), FLAG(l, PCI_ERR_UNC_COMP_TIME), FLAG(l, PCI_ERR_UNC_COMP_ABORT),
157         FLAG(l, PCI_ERR_UNC_UNX_COMP), FLAG(l, PCI_ERR_UNC_RX_OVER), FLAG(l, PCI_ERR_UNC_MALF_TLP),
158         FLAG(l, PCI_ERR_UNC_ECRC), FLAG(l, PCI_ERR_UNC_UNSUP), FLAG(l, PCI_ERR_UNC_ACS_VIOL));
159   l = get_conf_long(d, where + PCI_ERR_COR_STATUS);
160   printf("\t\tCESta:\tRxErr%c BadTLP%c BadDLLP%c Rollover%c Timeout%c AdvNonFatalErr%c\n",
161         FLAG(l, PCI_ERR_COR_RCVR), FLAG(l, PCI_ERR_COR_BAD_TLP), FLAG(l, PCI_ERR_COR_BAD_DLLP),
162         FLAG(l, PCI_ERR_COR_REP_ROLL), FLAG(l, PCI_ERR_COR_REP_TIMER), FLAG(l, PCI_ERR_COR_REP_ANFE));
163   l = get_conf_long(d, where + PCI_ERR_COR_MASK);
164   printf("\t\tCEMsk:\tRxErr%c BadTLP%c BadDLLP%c Rollover%c Timeout%c AdvNonFatalErr%c\n",
165         FLAG(l, PCI_ERR_COR_RCVR), FLAG(l, PCI_ERR_COR_BAD_TLP), FLAG(l, PCI_ERR_COR_BAD_DLLP),
166         FLAG(l, PCI_ERR_COR_REP_ROLL), FLAG(l, PCI_ERR_COR_REP_TIMER), FLAG(l, PCI_ERR_COR_REP_ANFE));
167   l = get_conf_long(d, where + PCI_ERR_CAP);
168   printf("\t\tAERCap:\tFirst Error Pointer: %02x, ECRCGenCap%c ECRCGenEn%c ECRCChkCap%c ECRCChkEn%c\n"
169         "\t\t\tMultHdrRecCap%c MultHdrRecEn%c TLPPfxPres%c HdrLogCap%c\n",
170         PCI_ERR_CAP_FEP(l), FLAG(l, PCI_ERR_CAP_ECRC_GENC), FLAG(l, PCI_ERR_CAP_ECRC_GENE),
171         FLAG(l, PCI_ERR_CAP_ECRC_CHKC), FLAG(l, PCI_ERR_CAP_ECRC_CHKE),
172         FLAG(l, PCI_ERR_CAP_MULT_HDRC), FLAG(l, PCI_ERR_CAP_MULT_HDRE),
173         FLAG(l, PCI_ERR_CAP_TLP_PFX), FLAG(l, PCI_ERR_CAP_HDR_LOG));
174
175   l0 = get_conf_long(d, where + PCI_ERR_HEADER_LOG);
176   l1 = get_conf_long(d, where + PCI_ERR_HEADER_LOG + 4);
177   l2 = get_conf_long(d, where + PCI_ERR_HEADER_LOG + 8);
178   l3 = get_conf_long(d, where + PCI_ERR_HEADER_LOG + 12);
179   printf("\t\tHeaderLog: %08x %08x %08x %08x\n", l0, l1, l2, l3);
180
181   if (type == PCI_EXP_TYPE_ROOT_PORT || type == PCI_EXP_TYPE_ROOT_EC)
182     {
183       if (!config_fetch(d, where + PCI_ERR_ROOT_COMMAND, 12))
184         return;
185
186       l = get_conf_long(d, where + PCI_ERR_ROOT_COMMAND);
187       printf("\t\tRootCmd: CERptEn%c NFERptEn%c FERptEn%c\n",
188             FLAG(l, PCI_ERR_ROOT_CMD_COR_EN),
189             FLAG(l, PCI_ERR_ROOT_CMD_NONFATAL_EN),
190             FLAG(l, PCI_ERR_ROOT_CMD_FATAL_EN));
191
192       l = get_conf_long(d, where + PCI_ERR_ROOT_STATUS);
193       printf("\t\tRootSta: CERcvd%c MultCERcvd%c UERcvd%c MultUERcvd%c\n"
194             "\t\t\t FirstFatal%c NonFatalMsg%c FatalMsg%c IntMsgNum %d\n",
195             FLAG(l, PCI_ERR_ROOT_COR_RCV),
196             FLAG(l, PCI_ERR_ROOT_MULTI_COR_RCV),
197             FLAG(l, PCI_ERR_ROOT_UNCOR_RCV),
198             FLAG(l, PCI_ERR_ROOT_MULTI_UNCOR_RCV),
199             FLAG(l, PCI_ERR_ROOT_FIRST_FATAL),
200             FLAG(l, PCI_ERR_ROOT_NONFATAL_RCV),
201             FLAG(l, PCI_ERR_ROOT_FATAL_RCV),
202             PCI_ERR_MSG_NUM(l));
203
204       w = get_conf_word(d, where + PCI_ERR_ROOT_COR_SRC);
205       printf("\t\tErrorSrc: ERR_COR: %04x ", w);
206
207       w = get_conf_word(d, where + PCI_ERR_ROOT_SRC);
208       printf("ERR_FATAL/NONFATAL: %04x\n", w);
209     }
210 }
211
212 static void cap_dpc(struct device *d, int where)
213 {
214   u16 l;
215
216   printf("Downstream Port Containment\n");
217   if (verbose < 2)
218     return;
219
220   if (!config_fetch(d, where + PCI_DPC_CAP, 8))
221     return;
222
223   l = get_conf_word(d, where + PCI_DPC_CAP);
224   printf("\t\tDpcCap:\tIntMsgNum %d, RPExt%c PoisonedTLP%c SwTrigger%c RP PIO Log %d, DL_ActiveErr%c\n",
225     PCI_DPC_CAP_INT_MSG(l), FLAG(l, PCI_DPC_CAP_RP_EXT), FLAG(l, PCI_DPC_CAP_TLP_BLOCK),
226     FLAG(l, PCI_DPC_CAP_SW_TRIGGER), PCI_DPC_CAP_RP_LOG(l), FLAG(l, PCI_DPC_CAP_DL_ACT_ERR));
227
228   l = get_conf_word(d, where + PCI_DPC_CTL);
229   printf("\t\tDpcCtl:\tTrigger:%x Cmpl%c INT%c ErrCor%c PoisonedTLP%c SwTrigger%c DL_ActiveErr%c\n",
230     PCI_DPC_CTL_TRIGGER(l), FLAG(l, PCI_DPC_CTL_CMPL), FLAG(l, PCI_DPC_CTL_INT),
231     FLAG(l, PCI_DPC_CTL_ERR_COR), FLAG(l, PCI_DPC_CTL_TLP), FLAG(l, PCI_DPC_CTL_SW_TRIGGER),
232     FLAG(l, PCI_DPC_CTL_DL_ACTIVE));
233
234   l = get_conf_word(d, where + PCI_DPC_STATUS);
235   printf("\t\tDpcSta:\tTrigger%c Reason:%02x INT%c RPBusy%c TriggerExt:%02x RP PIO ErrPtr:%02x\n",
236     FLAG(l, PCI_DPC_STS_TRIGGER), PCI_DPC_STS_REASON(l), FLAG(l, PCI_DPC_STS_INT),
237     FLAG(l, PCI_DPC_STS_RP_BUSY), PCI_DPC_STS_TRIGGER_EXT(l), PCI_DPC_STS_PIO_FEP(l));
238
239   l = get_conf_word(d, where + PCI_DPC_SOURCE);
240   printf("\t\tSource:\t%04x\n", l);
241 }
242
243 static void
244 cap_acs(struct device *d, int where)
245 {
246   u16 w;
247
248   printf("Access Control Services\n");
249   if (verbose < 2)
250     return;
251
252   if (!config_fetch(d, where + PCI_ACS_CAP, 4))
253     return;
254
255   w = get_conf_word(d, where + PCI_ACS_CAP);
256   printf("\t\tACSCap:\tSrcValid%c TransBlk%c ReqRedir%c CmpltRedir%c UpstreamFwd%c EgressCtrl%c "
257         "DirectTrans%c\n",
258         FLAG(w, PCI_ACS_CAP_VALID), FLAG(w, PCI_ACS_CAP_BLOCK), FLAG(w, PCI_ACS_CAP_REQ_RED),
259         FLAG(w, PCI_ACS_CAP_CMPLT_RED), FLAG(w, PCI_ACS_CAP_FORWARD), FLAG(w, PCI_ACS_CAP_EGRESS),
260         FLAG(w, PCI_ACS_CAP_TRANS));
261   w = get_conf_word(d, where + PCI_ACS_CTRL);
262   printf("\t\tACSCtl:\tSrcValid%c TransBlk%c ReqRedir%c CmpltRedir%c UpstreamFwd%c EgressCtrl%c "
263         "DirectTrans%c\n",
264         FLAG(w, PCI_ACS_CTRL_VALID), FLAG(w, PCI_ACS_CTRL_BLOCK), FLAG(w, PCI_ACS_CTRL_REQ_RED),
265         FLAG(w, PCI_ACS_CTRL_CMPLT_RED), FLAG(w, PCI_ACS_CTRL_FORWARD), FLAG(w, PCI_ACS_CTRL_EGRESS),
266         FLAG(w, PCI_ACS_CTRL_TRANS));
267 }
268
269 static void
270 cap_ari(struct device *d, int where)
271 {
272   u16 w;
273
274   printf("Alternative Routing-ID Interpretation (ARI)\n");
275   if (verbose < 2)
276     return;
277
278   if (!config_fetch(d, where + PCI_ARI_CAP, 4))
279     return;
280
281   w = get_conf_word(d, where + PCI_ARI_CAP);
282   printf("\t\tARICap:\tMFVC%c ACS%c, Next Function: %d\n",
283         FLAG(w, PCI_ARI_CAP_MFVC), FLAG(w, PCI_ARI_CAP_ACS),
284         PCI_ARI_CAP_NFN(w));
285   w = get_conf_word(d, where + PCI_ARI_CTRL);
286   printf("\t\tARICtl:\tMFVC%c ACS%c, Function Group: %d\n",
287         FLAG(w, PCI_ARI_CTRL_MFVC), FLAG(w, PCI_ARI_CTRL_ACS),
288         PCI_ARI_CTRL_FG(w));
289 }
290
291 static void
292 cap_ats(struct device *d, int where)
293 {
294   u16 w;
295
296   printf("Address Translation Service (ATS)\n");
297   if (verbose < 2)
298     return;
299
300   if (!config_fetch(d, where + PCI_ATS_CAP, 4))
301     return;
302
303   w = get_conf_word(d, where + PCI_ATS_CAP);
304   printf("\t\tATSCap:\tInvalidate Queue Depth: %02x\n", PCI_ATS_CAP_IQD(w));
305   w = get_conf_word(d, where + PCI_ATS_CTRL);
306   printf("\t\tATSCtl:\tEnable%c, Smallest Translation Unit: %02x\n",
307         FLAG(w, PCI_ATS_CTRL_ENABLE), PCI_ATS_CTRL_STU(w));
308 }
309
310 static void
311 cap_pri(struct device *d, int where)
312 {
313   u16 w;
314   u32 l;
315
316   printf("Page Request Interface (PRI)\n");
317   if (verbose < 2)
318     return;
319
320   if (!config_fetch(d, where + PCI_PRI_CTRL, 0xc))
321     return;
322
323   w = get_conf_word(d, where + PCI_PRI_CTRL);
324   printf("\t\tPRICtl: Enable%c Reset%c\n",
325         FLAG(w, PCI_PRI_CTRL_ENABLE), FLAG(w, PCI_PRI_CTRL_RESET));
326   w = get_conf_word(d, where + PCI_PRI_STATUS);
327   printf("\t\tPRISta: RF%c UPRGI%c Stopped%c PASID%c\n",
328         FLAG(w, PCI_PRI_STATUS_RF), FLAG(w, PCI_PRI_STATUS_UPRGI),
329         FLAG(w, PCI_PRI_STATUS_STOPPED), FLAG(w, PCI_PRI_STATUS_PASID));
330   l = get_conf_long(d, where + PCI_PRI_MAX_REQ);
331   printf("\t\tPage Request Capacity: %08x, ", l);
332   l = get_conf_long(d, where + PCI_PRI_ALLOC_REQ);
333   printf("Page Request Allocation: %08x\n", l);
334 }
335
336 static void
337 cap_pasid(struct device *d, int where)
338 {
339   u16 w;
340
341   printf("Process Address Space ID (PASID)\n");
342   if (verbose < 2)
343     return;
344
345   if (!config_fetch(d, where + PCI_PASID_CAP, 4))
346     return;
347
348   w = get_conf_word(d, where + PCI_PASID_CAP);
349   printf("\t\tPASIDCap: Exec%c Priv%c, Max PASID Width: %02x\n",
350         FLAG(w, PCI_PASID_CAP_EXEC), FLAG(w, PCI_PASID_CAP_PRIV),
351         PCI_PASID_CAP_WIDTH(w));
352   w = get_conf_word(d, where + PCI_PASID_CTRL);
353   printf("\t\tPASIDCtl: Enable%c Exec%c Priv%c\n",
354         FLAG(w, PCI_PASID_CTRL_ENABLE), FLAG(w, PCI_PASID_CTRL_EXEC),
355         FLAG(w, PCI_PASID_CTRL_PRIV));
356 }
357
358 static void
359 cap_sriov(struct device *d, int where)
360 {
361   u16 b;
362   u16 w;
363   u32 l;
364   int i;
365
366   printf("Single Root I/O Virtualization (SR-IOV)\n");
367   if (verbose < 2)
368     return;
369
370   if (!config_fetch(d, where + PCI_IOV_CAP, 0x3c))
371     return;
372
373   l = get_conf_long(d, where + PCI_IOV_CAP);
374   printf("\t\tIOVCap:\tMigration%c 10BitTagReq%c IntMsgNum %d\n",
375         FLAG(l, PCI_IOV_CAP_VFM), FLAG(l, PCI_IOV_CAP_VF_10BIT_TAG_REQ), PCI_IOV_CAP_IMN(l));
376   w = get_conf_word(d, where + PCI_IOV_CTRL);
377   printf("\t\tIOVCtl:\tEnable%c Migration%c Interrupt%c MSE%c ARIHierarchy%c 10BitTagReq%c\n",
378         FLAG(w, PCI_IOV_CTRL_VFE), FLAG(w, PCI_IOV_CTRL_VFME),
379         FLAG(w, PCI_IOV_CTRL_VFMIE), FLAG(w, PCI_IOV_CTRL_MSE),
380         FLAG(w, PCI_IOV_CTRL_ARI), FLAG(w, PCI_IOV_CTRL_VF_10BIT_TAG_REQ_EN));
381   w = get_conf_word(d, where + PCI_IOV_STATUS);
382   printf("\t\tIOVSta:\tMigration%c\n", FLAG(w, PCI_IOV_STATUS_MS));
383   w = get_conf_word(d, where + PCI_IOV_INITIALVF);
384   printf("\t\tInitial VFs: %d, ", w);
385   w = get_conf_word(d, where + PCI_IOV_TOTALVF);
386   printf("Total VFs: %d, ", w);
387   w = get_conf_word(d, where + PCI_IOV_NUMVF);
388   printf("Number of VFs: %d, ", w);
389   b = get_conf_byte(d, where + PCI_IOV_FDL);
390   printf("Function Dependency Link: %02x\n", b);
391   w = get_conf_word(d, where + PCI_IOV_OFFSET);
392   printf("\t\tVF offset: %d, ", w);
393   w = get_conf_word(d, where + PCI_IOV_STRIDE);
394   printf("stride: %d, ", w);
395   w = get_conf_word(d, where + PCI_IOV_DID);
396   printf("Device ID: %04x\n", w);
397   l = get_conf_long(d, where + PCI_IOV_SUPPS);
398   printf("\t\tSupported Page Size: %08x, ", l);
399   l = get_conf_long(d, where + PCI_IOV_SYSPS);
400   printf("System Page Size: %08x\n", l);
401
402   for (i=0; i < PCI_IOV_NUM_BAR; i++)
403     {
404       u32 addr;
405       int type;
406       u32 h;
407       l = get_conf_long(d, where + PCI_IOV_BAR_BASE + 4*i);
408       if (l == 0xffffffff)
409         l = 0;
410       if (!l)
411         continue;
412       printf("\t\tRegion %d: Memory at ", i);
413       addr = l & PCI_ADDR_MEM_MASK;
414       type = l & PCI_BASE_ADDRESS_MEM_TYPE_MASK;
415       if (type == PCI_BASE_ADDRESS_MEM_TYPE_64)
416         {
417           i++;
418           h = get_conf_long(d, where + PCI_IOV_BAR_BASE + (i*4));
419           printf("%08x", h);
420         }
421       printf("%08x (%s-bit, %sprefetchable)\n",
422         addr,
423         (type == PCI_BASE_ADDRESS_MEM_TYPE_32) ? "32" : "64",
424         (l & PCI_BASE_ADDRESS_MEM_PREFETCH) ? "" : "non-");
425     }
426
427   l = get_conf_long(d, where + PCI_IOV_MSAO);
428   printf("\t\tVF Migration: offset: %08x, BIR: %x\n", PCI_IOV_MSA_OFFSET(l),
429         PCI_IOV_MSA_BIR(l));
430 }
431
432 static void
433 cap_multicast(struct device *d, int where, int type)
434 {
435   u16 w;
436   u32 l;
437   u64 bar, rcv, block;
438
439   printf("Multicast\n");
440   if (verbose < 2)
441     return;
442
443   if (!config_fetch(d, where + PCI_MCAST_CAP, 0x30))
444     return;
445
446   w = get_conf_word(d, where + PCI_MCAST_CAP);
447   printf("\t\tMcastCap: MaxGroups %d", PCI_MCAST_CAP_MAX_GROUP(w) + 1);
448   if (type == PCI_EXP_TYPE_ENDPOINT || type == PCI_EXP_TYPE_ROOT_INT_EP)
449     printf(", WindowSz %d (%d bytes)",
450       PCI_MCAST_CAP_WIN_SIZE(w), 1 << PCI_MCAST_CAP_WIN_SIZE(w));
451   if (type == PCI_EXP_TYPE_ROOT_PORT ||
452       type == PCI_EXP_TYPE_UPSTREAM || type == PCI_EXP_TYPE_DOWNSTREAM)
453     printf(", ECRCRegen%c\n", FLAG(w, PCI_MCAST_CAP_ECRC));
454   w = get_conf_word(d, where + PCI_MCAST_CTRL);
455   printf("\t\tMcastCtl: NumGroups %d, Enable%c\n",
456     PCI_MCAST_CTRL_NUM_GROUP(w) + 1, FLAG(w, PCI_MCAST_CTRL_ENABLE));
457   bar = get_conf_long(d, where + PCI_MCAST_BAR);
458   l = get_conf_long(d, where + PCI_MCAST_BAR + 4);
459   bar |= (u64) l << 32;
460   printf("\t\tMcastBAR: IndexPos %d, BaseAddr %016" PCI_U64_FMT_X "\n",
461     PCI_MCAST_BAR_INDEX_POS(bar), bar & PCI_MCAST_BAR_MASK);
462   rcv = get_conf_long(d, where + PCI_MCAST_RCV);
463   l = get_conf_long(d, where + PCI_MCAST_RCV + 4);
464   rcv |= (u64) l << 32;
465   printf("\t\tMcastReceiveVec:      %016" PCI_U64_FMT_X "\n", rcv);
466   block = get_conf_long(d, where + PCI_MCAST_BLOCK);
467   l = get_conf_long(d, where + PCI_MCAST_BLOCK + 4);
468   block |= (u64) l << 32;
469   printf("\t\tMcastBlockAllVec:     %016" PCI_U64_FMT_X "\n", block);
470   block = get_conf_long(d, where + PCI_MCAST_BLOCK_UNTRANS);
471   l = get_conf_long(d, where + PCI_MCAST_BLOCK_UNTRANS + 4);
472   block |= (u64) l << 32;
473   printf("\t\tMcastBlockUntransVec: %016" PCI_U64_FMT_X "\n", block);
474
475   if (type == PCI_EXP_TYPE_ENDPOINT || type == PCI_EXP_TYPE_ROOT_INT_EP)
476     return;
477   bar = get_conf_long(d, where + PCI_MCAST_OVL_BAR);
478   l = get_conf_long(d, where + PCI_MCAST_OVL_BAR + 4);
479   bar |= (u64) l << 32;
480   printf("\t\tMcastOverlayBAR: OverlaySize %d ", PCI_MCAST_OVL_SIZE(bar));
481   if (PCI_MCAST_OVL_SIZE(bar) >= 6)
482     printf("(%d bytes)", 1 << PCI_MCAST_OVL_SIZE(bar));
483   else
484     printf("(disabled)");
485   printf(", BaseAddr %016" PCI_U64_FMT_X "\n", bar & PCI_MCAST_OVL_MASK);
486 }
487
488 static void
489 cap_vc(struct device *d, int where)
490 {
491   u32 cr1, cr2;
492   u16 ctrl, status;
493   int evc_cnt;
494   int arb_table_pos;
495   int i, j;
496   static const char ref_clocks[][6] = { "100ns" };
497   static const char arb_selects[8][7] = { "Fixed", "WRR32", "WRR64", "WRR128", "??4", "??5", "??6", "??7" };
498   static const char vc_arb_selects[8][8] = { "Fixed", "WRR32", "WRR64", "WRR128", "TWRR128", "WRR256", "??6", "??7" };
499   char buf[8];
500
501   printf("Virtual Channel\n");
502   if (verbose < 2)
503     return;
504
505   if (!config_fetch(d, where + 4, 0x1c - 4))
506     return;
507
508   cr1 = get_conf_long(d, where + PCI_VC_PORT_REG1);
509   cr2 = get_conf_long(d, where + PCI_VC_PORT_REG2);
510   ctrl = get_conf_word(d, where + PCI_VC_PORT_CTRL);
511   status = get_conf_word(d, where + PCI_VC_PORT_STATUS);
512
513   evc_cnt = BITS(cr1, 0, 3);
514   printf("\t\tCaps:\tLPEVC=%d RefClk=%s PATEntryBits=%d\n",
515     BITS(cr1, 4, 3),
516     TABLE(ref_clocks, BITS(cr1, 8, 2), buf),
517     1 << BITS(cr1, 10, 2));
518
519   printf("\t\tArb:");
520   for (i=0; i<8; i++)
521     if (arb_selects[i][0] != '?' || cr2 & (1 << i))
522       printf("%c%s%c", (i ? ' ' : '\t'), arb_selects[i], FLAG(cr2, 1 << i));
523   arb_table_pos = BITS(cr2, 24, 8);
524
525   printf("\n\t\tCtrl:\tArbSelect=%s\n", TABLE(arb_selects, BITS(ctrl, 1, 3), buf));
526   printf("\t\tStatus:\tInProgress%c\n", FLAG(status, 1));
527
528   if (arb_table_pos)
529     {
530       arb_table_pos = where + 16*arb_table_pos;
531       printf("\t\tPort Arbitration Table [%x] <?>\n", arb_table_pos);
532     }
533
534   for (i=0; i<=evc_cnt; i++)
535     {
536       int pos = where + PCI_VC_RES_CAP + 12*i;
537       u32 rcap, rctrl;
538       u16 rstatus;
539       int pat_pos;
540
541       printf("\t\tVC%d:\t", i);
542       if (!config_fetch(d, pos, 12))
543         {
544           printf("<unreadable>\n");
545           continue;
546         }
547       rcap = get_conf_long(d, pos);
548       rctrl = get_conf_long(d, pos+4);
549       rstatus = get_conf_word(d, pos+10);
550
551       pat_pos = BITS(rcap, 24, 8);
552       printf("Caps:\tPATOffset=%02x MaxTimeSlots=%d RejSnoopTrans%c\n",
553         pat_pos,
554         BITS(rcap, 16, 7) + 1,
555         FLAG(rcap, 1 << 15));
556
557       printf("\t\t\tArb:");
558       for (j=0; j<8; j++)
559         if (vc_arb_selects[j][0] != '?' || rcap & (1 << j))
560           printf("%c%s%c", (j ? ' ' : '\t'), vc_arb_selects[j], FLAG(rcap, 1 << j));
561
562       printf("\n\t\t\tCtrl:\tEnable%c ID=%d ArbSelect=%s TC/VC=%02x\n",
563         FLAG(rctrl, 1 << 31),
564         BITS(rctrl, 24, 3),
565         TABLE(vc_arb_selects, BITS(rctrl, 17, 3), buf),
566         BITS(rctrl, 0, 8));
567
568       printf("\t\t\tStatus:\tNegoPending%c InProgress%c\n",
569         FLAG(rstatus, 2),
570         FLAG(rstatus, 1));
571
572       if (pat_pos)
573         printf("\t\t\tPort Arbitration Table <?>\n");
574     }
575 }
576
577 static void
578 cap_rclink(struct device *d, int where)
579 {
580   u32 esd;
581   int num_links;
582   int i;
583   static const char elt_types[][9] = { "Config", "Egress", "Internal" };
584   char buf[8];
585
586   printf("Root Complex Link\n");
587   if (verbose < 2)
588     return;
589
590   if (!config_fetch(d, where + 4, PCI_RCLINK_LINK1 - 4))
591     return;
592
593   esd = get_conf_long(d, where + PCI_RCLINK_ESD);
594   num_links = BITS(esd, 8, 8);
595   printf("\t\tDesc:\tPortNumber=%02x ComponentID=%02x EltType=%s\n",
596     BITS(esd, 24, 8),
597     BITS(esd, 16, 8),
598     TABLE(elt_types, BITS(esd, 0, 8), buf));
599
600   for (i=0; i<num_links; i++)
601     {
602       int pos = where + PCI_RCLINK_LINK1 + i*PCI_RCLINK_LINK_SIZE;
603       u32 desc;
604       u32 addr_lo, addr_hi;
605
606       printf("\t\tLink%d:\t", i);
607       if (!config_fetch(d, pos, PCI_RCLINK_LINK_SIZE))
608         {
609           printf("<unreadable>\n");
610           return;
611         }
612       desc = get_conf_long(d, pos + PCI_RCLINK_LINK_DESC);
613       addr_lo = get_conf_long(d, pos + PCI_RCLINK_LINK_ADDR);
614       addr_hi = get_conf_long(d, pos + PCI_RCLINK_LINK_ADDR + 4);
615
616       printf("Desc:\tTargetPort=%02x TargetComponent=%02x AssocRCRB%c LinkType=%s LinkValid%c\n",
617         BITS(desc, 24, 8),
618         BITS(desc, 16, 8),
619         FLAG(desc, 4),
620         ((desc & 2) ? "Config" : "MemMapped"),
621         FLAG(desc, 1));
622
623       if (desc & 2)
624         {
625           int n = addr_lo & 7;
626           if (!n)
627             n = 8;
628           printf("\t\t\tAddr:\t%02x:%02x.%d  CfgSpace=%08x%08x\n",
629             BITS(addr_lo, 20, n),
630             BITS(addr_lo, 15, 5),
631             BITS(addr_lo, 12, 3),
632             addr_hi, addr_lo);
633         }
634       else
635         printf("\t\t\tAddr:\t%08x%08x\n", addr_hi, addr_lo);
636     }
637 }
638
639 static void
640 cap_rcec(struct device *d, int where)
641 {
642   printf("Root Complex Event Collector Endpoint Association\n");
643   if (verbose < 2)
644     return;
645
646   if (!config_fetch(d, where, 12))
647     return;
648
649   u32 hdr = get_conf_long(d, where);
650   byte cap_ver = PCI_RCEC_EP_CAP_VER(hdr);
651   u32 bmap = get_conf_long(d, where + PCI_RCEC_RCIEP_BMAP);
652   printf("\t\tRCiEPBitmap: ");
653   if (bmap)
654     {
655       int prevmatched=0;
656       int adjcount=0;
657       int prevdev=0;
658       printf("RCiEP at Device(s):");
659       for (int dev=0; dev < 32; dev++)
660         {
661           if (BITS(bmap, dev, 1))
662             {
663               if (!adjcount)
664                 printf("%s %u", (prevmatched) ? "," : "", dev);
665               adjcount++;
666               prevdev=dev;
667               prevmatched=1;
668             }
669           else
670             {
671               if (adjcount > 1)
672                 printf("-%u", prevdev);
673               adjcount=0;
674             }
675         }
676    }
677   else
678     printf("%s", (verbose > 2) ? "00000000 [none]" : "[none]");
679   printf("\n");
680
681   if (cap_ver < PCI_RCEC_BUSN_REG_VER)
682     return;
683
684   u32 busn = get_conf_long(d, where + PCI_RCEC_BUSN_REG);
685   u8 lastbusn = BITS(busn, 16, 8);
686   u8 nextbusn = BITS(busn, 8, 8);
687
688   if ((lastbusn == 0x00) && (nextbusn == 0xff))
689     printf("\t\tAssociatedBusNumbers: %s\n", (verbose > 2) ? "ff-00 [none]" : "[none]");
690   else
691     printf("\t\tAssociatedBusNumbers: %02x-%02x\n", nextbusn, lastbusn );
692 }
693
694 static void
695 cxl_range(u64 base, u64 size, int n)
696 {
697   u32 interleave[] = { 0, 256, 4096, 512, 1024, 2048, 8192, 16384 };
698   const char *type[] = { "Volatile", "Non-volatile", "CDAT" };
699   const char *class[] = { "DRAM", "Storage", "CDAT" };
700   u16 w;
701
702   w = (u16) size;
703
704   size &= ~0x0fffffffULL;
705
706   printf("\t\tRange%d: %016"PCI_U64_FMT_X"-%016"PCI_U64_FMT_X" [size=0x%"PCI_U64_FMT_X"]\n", n, base, base + size - 1, size);
707   printf("\t\t\tValid%c Active%c Type=%s Class=%s interleave=%d timeout=%ds\n",
708     FLAG(w, PCI_CXL_RANGE_VALID), FLAG(w, PCI_CXL_RANGE_ACTIVE),
709     type[PCI_CXL_RANGE_TYPE(w)], class[PCI_CXL_RANGE_CLASS(w)],
710     interleave[PCI_CXL_RANGE_INTERLEAVE(w)],
711     1 << (PCI_CXL_RANGE_TIMEOUT(w) * 2));
712 }
713
714 static void
715 dvsec_cxl_device(struct device *d, int rev, int where, int len)
716 {
717   u32 cache_size, cache_unit_size;
718   u64 range_base, range_size;
719   u16 w;
720
721   /* Legacy 1.1 revs aren't handled */
722   if (rev == 0)
723     return;
724
725   if (rev >= 1 && len >= PCI_CXL_DEV_LEN)
726     {
727       w = get_conf_word(d, where + PCI_CXL_DEV_CAP);
728       printf("\t\tCXLCap:\tCache%c IO%c Mem%c MemHWInit%c HDMCount %d Viral%c\n",
729         FLAG(w, PCI_CXL_DEV_CAP_CACHE), FLAG(w, PCI_CXL_DEV_CAP_IO), FLAG(w, PCI_CXL_DEV_CAP_MEM),
730         FLAG(w, PCI_CXL_DEV_CAP_MEM_HWINIT), PCI_CXL_DEV_CAP_HDM_CNT(w), FLAG(w, PCI_CXL_DEV_CAP_VIRAL));
731
732       w = get_conf_word(d, where + PCI_CXL_DEV_CTRL);
733       printf("\t\tCXLCtl:\tCache%c IO%c Mem%c CacheSFCov %d CacheSFGran %d CacheClean%c Viral%c\n",
734         FLAG(w, PCI_CXL_DEV_CTRL_CACHE), FLAG(w, PCI_CXL_DEV_CTRL_IO), FLAG(w, PCI_CXL_DEV_CTRL_MEM),
735         PCI_CXL_DEV_CTRL_CACHE_SF_COV(w), PCI_CXL_DEV_CTRL_CACHE_SF_GRAN(w), FLAG(w, PCI_CXL_DEV_CTRL_CACHE_CLN),
736         FLAG(w, PCI_CXL_DEV_CTRL_VIRAL));
737
738       w = get_conf_word(d, where + PCI_CXL_DEV_STATUS);
739       printf("\t\tCXLSta:\tViral%c\n", FLAG(w, PCI_CXL_DEV_STATUS_VIRAL));
740
741       w = get_conf_word(d, where + PCI_CXL_DEV_CTRL2);
742       printf("\t\tCXLCtl2:\tDisableCaching%c InitCacheWB&Inval%c InitRst%c RstMemClrEn%c",
743         FLAG(w, PCI_CXL_DEV_CTRL2_DISABLE_CACHING),
744         FLAG(w, PCI_CXL_DEV_CTRL2_INIT_WB_INVAL),
745         FLAG(w, PCI_CXL_DEV_CTRL2_INIT_CXL_RST),
746         FLAG(w, PCI_CXL_DEV_CTRL2_INIT_CXL_RST_CLR_EN));
747       if (rev >= 2)
748           printf(" DesiredVolatileHDMStateAfterHotReset%c", FLAG(w, PCI_CXL_DEV_CTRL2_INIT_CXL_HDM_STATE_HOTRST));
749       printf("\n");
750
751       w = get_conf_word(d, where + PCI_CXL_DEV_STATUS2);
752       printf("\t\tCXLSta2:\tResetComplete%c ResetError%c PMComplete%c\n",
753         FLAG(w, PCI_CXL_DEV_STATUS_RC), FLAG(w,PCI_CXL_DEV_STATUS_RE), FLAG(w, PCI_CXL_DEV_STATUS_PMC));
754
755       w = get_conf_word(d, where + PCI_CXL_DEV_CAP2);
756       printf("\t\tCXLCap2:\t");
757       cache_unit_size = BITS(w, 0, 4);
758       cache_size = BITS(w, 8, 8);
759       switch (cache_unit_size)
760         {
761         case PCI_CXL_DEV_CAP2_CACHE_1M:
762           printf("Cache Size: %08x\n", cache_size * (1<<20));
763           break;
764         case PCI_CXL_DEV_CAP2_CACHE_64K:
765           printf("Cache Size: %08x\n", cache_size * (64<<10));
766           break;
767         case PCI_CXL_DEV_CAP2_CACHE_UNK:
768           printf("Cache Size Not Reported\n");
769           break;
770         default:
771           printf("Cache Size: %d of unknown unit size (%d)\n", cache_size, cache_unit_size);
772           break;
773         }
774
775       range_size = (u64) get_conf_long(d, where + PCI_CXL_DEV_RANGE1_SIZE_HI) << 32;
776       range_size |= get_conf_long(d, where + PCI_CXL_DEV_RANGE1_SIZE_LO);
777       range_base = (u64) get_conf_long(d, where + PCI_CXL_DEV_RANGE1_BASE_HI) << 32;
778       range_base |= get_conf_long(d, where + PCI_CXL_DEV_RANGE1_BASE_LO);
779       cxl_range(range_base, range_size, 1);
780
781       range_size = (u64) get_conf_long(d, where + PCI_CXL_DEV_RANGE2_SIZE_HI) << 32;
782       range_size |= get_conf_long(d, where + PCI_CXL_DEV_RANGE2_SIZE_LO);
783       range_base = (u64) get_conf_long(d, where + PCI_CXL_DEV_RANGE2_BASE_HI) << 32;
784       range_base |= get_conf_long(d, where + PCI_CXL_DEV_RANGE2_BASE_LO);
785       cxl_range(range_base, range_size, 2);
786     }
787
788   if (rev >= 2 && len >= PCI_CXL_DEV_LEN_REV2)
789     {
790       w = get_conf_word(d, where + PCI_CXL_DEV_CAP3);
791       printf("\t\tCXLCap3:\tDefaultVolatile HDM State After:\tColdReset%c WarmReset%c HotReset%c HotResetConfigurability%c\n",
792         FLAG(w, PCI_CXL_DEV_CAP3_HDM_STATE_RST_COLD),
793         FLAG(w, PCI_CXL_DEV_CAP3_HDM_STATE_RST_WARM),
794         FLAG(w, PCI_CXL_DEV_CAP3_HDM_STATE_RST_HOT),
795         FLAG(w, PCI_CXL_DEV_CAP3_HDM_STATE_RST_HOT_CFG));
796     }
797
798   // Unparsed data
799   if (len > PCI_CXL_DEV_LEN_REV2)
800     printf("\t\t<?>\n");
801 }
802
803 static void
804 dvsec_cxl_port(struct device *d, int where, int len)
805 {
806   u16 w, m1, m2;
807   u8 b1, b2;
808
809   if (len < PCI_CXL_PORT_EXT_LEN)
810     return;
811
812   w = get_conf_word(d, where + PCI_CXL_PORT_EXT_STATUS);
813   printf("\t\tCXLPortSta:\tPMComplete%c\n", FLAG(w, PCI_CXL_PORT_EXT_STATUS));
814
815   w = get_conf_word(d, where + PCI_CXL_PORT_CTRL);
816   printf("\t\tCXLPortCtl:\tUnmaskSBR%c UnmaskLinkDisable%c AltMem%c AltBME%c ViralEnable%c\n",
817     FLAG(w, PCI_CXL_PORT_UNMASK_SBR), FLAG(w, PCI_CXL_PORT_UNMASK_LINK),
818     FLAG(w, PCI_CXL_PORT_ALT_MEMORY), FLAG(w, PCI_CXL_PORT_ALT_BME),
819     FLAG(w, PCI_CXL_PORT_VIRAL_EN));
820
821   b1 = get_conf_byte(d, where + PCI_CXL_PORT_ALT_BUS_BASE);
822   b2 = get_conf_byte(d, where + PCI_CXL_PORT_ALT_BUS_LIMIT);
823   printf("\t\tAlternateBus:\t%02x-%02x\n", b1, b2);
824   m1 = get_conf_word(d, where + PCI_CXL_PORT_ALT_MEM_BASE);
825   m2 = get_conf_word(d, where + PCI_CXL_PORT_ALT_MEM_LIMIT);
826   printf("\t\tAlternateBus:\t%04x-%04x\n", m1, m2);
827 }
828
829 static void
830 dvsec_cxl_register_locator(struct device *d, int where, int len)
831 {
832   static const char * const id_names[] = {
833     "empty",
834     "component registers",
835     "BAR virtualization",
836     "CXL device registers",
837     "CPMU registers",
838   };
839
840   for (int i=0; ; i++)
841     {
842       int pos = where + PCI_CXL_RL_BLOCK1_LO + 8*i;
843       if (pos + 7 >= where + len)
844         break;
845
846       u32 lo = get_conf_long(d, pos);
847       u32 hi = get_conf_long(d, pos + 4);
848
849       unsigned int bir = BITS(lo, 0, 3);
850       unsigned int block_id = BITS(lo, 8, 8);
851       u64 base = (BITS(lo, 16, 16) << 16) | ((u64) hi << 32);
852
853       if (!block_id)
854         continue;
855
856       const char *id_name;
857       if (block_id < sizeof(id_names) / sizeof(*id_names))
858         id_name = id_names[block_id];
859       else if (block_id == 0xff)
860         id_name = "vendor-specific";
861       else
862         id_name = "<?>";
863
864       printf("\t\tBlock%d: BIR: bar%d, ID: %s, offset: %016" PCI_U64_FMT_X "\n", i + 1, bir, id_name, base);
865     }
866 }
867
868 static void
869 dvsec_cxl_gpf_device(struct device *d, int where)
870 {
871   u32 l;
872   u16 w, duration;
873   u8 time_base, time_scale;
874
875   w = get_conf_word(d, where + PCI_CXL_GPF_DEV_PHASE2_DUR);
876   time_base = BITS(w, 0, 4);
877   time_scale = BITS(w, 8, 4);
878
879   switch (time_scale)
880     {
881       case PCI_CXL_GPF_DEV_100US:
882       case PCI_CXL_GPF_DEV_100MS:
883         duration = time_base * 100;
884         break;
885       case PCI_CXL_GPF_DEV_10US:
886       case PCI_CXL_GPF_DEV_10MS:
887       case PCI_CXL_GPF_DEV_10S:
888         duration = time_base * 10;
889         break;
890       case PCI_CXL_GPF_DEV_1US:
891       case PCI_CXL_GPF_DEV_1MS:
892       case PCI_CXL_GPF_DEV_1S:
893         duration = time_base;
894         break;
895       default:
896         /* Reserved */
897         printf("\t\tReserved time scale encoding %x\n", time_scale);
898         duration = time_base;
899     }
900
901   printf("\t\tGPF Phase 2 Duration: %u%s\n", duration,
902       (time_scale < PCI_CXL_GPF_DEV_1MS) ? "us":
903       (time_scale < PCI_CXL_GPF_DEV_1S) ? "ms" :
904       (time_scale == PCI_CXL_GPF_DEV_1S) ? "s" : "<?>");
905
906   l = get_conf_long(d, where + PCI_CXL_GPF_DEV_PHASE2_POW);
907   printf("\t\tGPF Phase 2 Power: %umW\n", (unsigned int)l);
908 }
909
910 static void
911 dvsec_cxl_gpf_port(struct device *d, int where)
912 {
913   u16 w, timeout;
914   u8 time_base, time_scale;
915
916   w = get_conf_word(d, where + PCI_CXL_GPF_PORT_PHASE1_CTRL);
917   time_base = BITS(w, 0, 4);
918   time_scale = BITS(w, 8, 4);
919
920   switch (time_scale)
921     {
922       case PCI_CXL_GPF_PORT_100US:
923       case PCI_CXL_GPF_PORT_100MS:
924         timeout = time_base * 100;
925         break;
926       case PCI_CXL_GPF_PORT_10US:
927       case PCI_CXL_GPF_PORT_10MS:
928       case PCI_CXL_GPF_PORT_10S:
929         timeout = time_base * 10;
930         break;
931       case PCI_CXL_GPF_PORT_1US:
932       case PCI_CXL_GPF_PORT_1MS:
933       case PCI_CXL_GPF_PORT_1S:
934         timeout = time_base;
935         break;
936       default:
937         /* Reserved */
938         printf("\t\tReserved time scale encoding %x\n", time_scale);
939         timeout = time_base;
940     }
941
942   printf("\t\tGPF Phase 1 Timeout: %d%s\n", timeout,
943       (time_scale < PCI_CXL_GPF_PORT_1MS) ? "us":
944       (time_scale < PCI_CXL_GPF_PORT_1S) ? "ms" :
945       (time_scale == PCI_CXL_GPF_PORT_1S) ? "s" : "<?>");
946
947   w = get_conf_word(d, where + PCI_CXL_GPF_PORT_PHASE2_CTRL);
948   time_base = BITS(w, 0, 4);
949   time_scale = BITS(w, 8, 4);
950
951   switch (time_scale)
952     {
953       case PCI_CXL_GPF_PORT_100US:
954       case PCI_CXL_GPF_PORT_100MS:
955         timeout = time_base * 100;
956         break;
957       case PCI_CXL_GPF_PORT_10US:
958       case PCI_CXL_GPF_PORT_10MS:
959       case PCI_CXL_GPF_PORT_10S:
960         timeout = time_base * 10;
961         break;
962       case PCI_CXL_GPF_PORT_1US:
963       case PCI_CXL_GPF_PORT_1MS:
964       case PCI_CXL_GPF_PORT_1S:
965         timeout = time_base;
966         break;
967       default:
968         /* Reserved */
969         printf("\t\tReserved time scale encoding %x\n", time_scale);
970         timeout = time_base;
971     }
972
973   printf("\t\tGPF Phase 2 Timeout: %d%s\n", timeout,
974       (time_scale < PCI_CXL_GPF_PORT_1MS) ? "us":
975       (time_scale < PCI_CXL_GPF_PORT_1S) ? "ms" :
976       (time_scale == PCI_CXL_GPF_PORT_1S) ? "s" : "<?>");
977 }
978
979 static void
980 dvsec_cxl_flex_bus(struct device *d, int where, int rev, int len)
981 {
982   u16 w;
983   u32 l, data;
984
985   // Sanity check: Does the length correspond to its revision?
986   switch (rev) {
987     case 0:
988       if (len != PCI_CXL_FB_MOD_TS_DATA)
989         printf("\t\t<Wrong length for Revision %d>\n", rev);
990       break;
991     case 1:
992       if (len != PCI_CXL_FB_PORT_CAP2)
993         printf("\t\t<Wrong length for Revision %d>\n", rev);
994       break;
995     case 2:
996       if (len != PCI_CXL_FB_NEXT_UNSUPPORTED)
997         printf("\t\t<Wrong length for Revision %d>\n", rev);
998       break;
999     default:
1000       break;
1001   }
1002
1003   // From Rev 0
1004   w = get_conf_word(d, where + PCI_CXL_FB_PORT_CAP);
1005   printf("\t\tFBCap:\tCache%c IO%c Mem%c 68BFlit%c MltLogDev%c",
1006       FLAG(w, PCI_CXL_FB_CAP_CACHE), FLAG(w, PCI_CXL_FB_CAP_IO),
1007       FLAG(w, PCI_CXL_FB_CAP_MEM), FLAG(w, PCI_CXL_FB_CAP_68B_FLIT),
1008       FLAG(w, PCI_CXL_FB_CAP_MULT_LOG_DEV));
1009
1010   if (rev > 1)
1011     printf(" 256BFlit%c PBRFlit%c",
1012         FLAG(w, PCI_CXL_FB_CAP_256B_FLIT), FLAG(w, PCI_CXL_FB_CAP_PBR_FLIT));
1013
1014   w = get_conf_word(d, where + PCI_CXL_FB_PORT_CTRL);
1015   printf("\n\t\tFBCtl:\tCache%c IO%c Mem%c SynHdrByp%c DrftBuf%c 68BFlit%c MltLogDev%c RCD%c Retimer1%c Retimer2%c",
1016       FLAG(w, PCI_CXL_FB_CTRL_CACHE), FLAG(w, PCI_CXL_FB_CTRL_IO),
1017       FLAG(w, PCI_CXL_FB_CTRL_MEM), FLAG(w, PCI_CXL_FB_CTRL_SYNC_HDR_BYP),
1018       FLAG(w, PCI_CXL_FB_CTRL_DRFT_BUF), FLAG(w, PCI_CXL_FB_CTRL_68B_FLIT),
1019       FLAG(w, PCI_CXL_FB_CTRL_MULT_LOG_DEV), FLAG(w, PCI_CXL_FB_CTRL_RCD),
1020       FLAG(w, PCI_CXL_FB_CTRL_RETIMER1), FLAG(w, PCI_CXL_FB_CTRL_RETIMER2));
1021
1022   if (rev > 1)
1023     printf(" 256BFlit%c PBRFlit%c",
1024         FLAG(w, PCI_CXL_FB_CTRL_256B_FLIT), FLAG(w, PCI_CXL_FB_CTRL_PBR_FLIT));
1025
1026   w = get_conf_word(d, where + PCI_CXL_FB_PORT_STATUS);
1027   printf("\n\t\tFBSta:\tCache%c IO%c Mem%c SynHdrByp%c DrftBuf%c 68BFlit%c MltLogDev%c",
1028       FLAG(w, PCI_CXL_FB_STAT_CACHE), FLAG(w, PCI_CXL_FB_STAT_IO),
1029       FLAG(w, PCI_CXL_FB_STAT_MEM), FLAG(w, PCI_CXL_FB_STAT_SYNC_HDR_BYP),
1030       FLAG(w, PCI_CXL_FB_STAT_DRFT_BUF), FLAG(w, PCI_CXL_FB_STAT_68B_FLIT),
1031       FLAG(w, PCI_CXL_FB_STAT_MULT_LOG_DEV));
1032
1033   if (rev > 1)
1034     printf(" 256BFlit%c PBRFlit%c",
1035         FLAG(w, PCI_CXL_FB_STAT_256B_FLIT), FLAG(w, PCI_CXL_FB_STAT_PBR_FLIT));
1036   printf("\n");
1037
1038   // From Rev 1
1039   if (rev >= 1)
1040     {
1041       l = get_conf_long(d, where + PCI_CXL_FB_MOD_TS_DATA);
1042       data = BITS(l, 0, 24);
1043       printf("\t\tFBModTS:\tReceived FB Data: %06x\n", (unsigned int)data);
1044     }
1045
1046   // From Rev 2
1047   if (rev >= 2)
1048     {
1049       u8 nop;
1050
1051       l = get_conf_long(d, where + PCI_CXL_FB_PORT_CAP2);
1052       printf("\t\tFBCap2:\tNOPHint%c\n", FLAG(l, PCI_CXL_FB_CAP2_NOP_HINT));
1053
1054       l = get_conf_long(d, where + PCI_CXL_FB_PORT_CTRL2);
1055       printf("\t\tFBCtl2:\tNOPHint%c\n", FLAG(l, PCI_CXL_FB_CTRL2_NOP_HINT));
1056
1057       l = get_conf_long(d, where + PCI_CXL_FB_PORT_STATUS2);
1058       nop = BITS(l, 0, 2);
1059       printf("\t\tFBSta2:\tNOPHintInfo: %x\n", nop);
1060     }
1061
1062   // Unparsed data
1063   if (len > PCI_CXL_FB_LEN)
1064     printf("\t\t<?>\n");
1065 }
1066
1067 static void
1068 dvsec_cxl_mld(struct device *d, int where)
1069 {
1070   u16 w;
1071
1072   w = get_conf_word(d, where + PCI_CXL_MLD_NUM_LD);
1073
1074   /* Encodings greater than 16 are reserved */
1075   if (w && w <= PCI_CXL_MLD_MAX_LD)
1076     printf("\t\tNumLogDevs: %d\n", w);
1077 }
1078
1079 static void
1080 dvsec_cxl_function_map(struct device *d, int where)
1081 {
1082
1083   printf("\t\tFuncMap 0: %08x\n",
1084       (unsigned int)(get_conf_word(d, where + PCI_CXL_FUN_MAP_REG_0)));
1085
1086   printf("\t\tFuncMap 1: %08x\n",
1087     (unsigned int)(get_conf_word(d, where + PCI_CXL_FUN_MAP_REG_1)));
1088
1089   printf("\t\tFuncMap 2: %08x\n",
1090     (unsigned int)(get_conf_word(d, where + PCI_CXL_FUN_MAP_REG_2)));
1091
1092   printf("\t\tFuncMap 3: %08x\n",
1093       (unsigned int)(get_conf_word(d, where + PCI_CXL_FUN_MAP_REG_3)));
1094
1095   printf("\t\tFuncMap 4: %08x\n",
1096       (unsigned int)(get_conf_word(d, where + PCI_CXL_FUN_MAP_REG_4)));
1097
1098   printf("\t\tFuncMap 5: %08x\n",
1099       (unsigned int)(get_conf_word(d, where + PCI_CXL_FUN_MAP_REG_5)));
1100
1101   printf("\t\tFuncMap 6: %08x\n",
1102       (unsigned int)(get_conf_word(d, where + PCI_CXL_FUN_MAP_REG_6)));
1103
1104   printf("\t\tFuncMap 7: %08x\n",
1105       (unsigned int)(get_conf_word(d, where + PCI_CXL_FUN_MAP_REG_7)));
1106 }
1107
1108 static void
1109 cap_dvsec_cxl(struct device *d, int id, int rev, int where, int len)
1110 {
1111   printf(": CXL\n");
1112   if (verbose < 2)
1113     return;
1114
1115   if (!config_fetch(d, where, len))
1116     return;
1117
1118   switch (id)
1119     {
1120     case 0:
1121       printf("\t\tPCIe DVSEC for CXL Devices\n");
1122       dvsec_cxl_device(d, rev, where, len);
1123       break;
1124     case 2:
1125       printf("\t\tNon-CXL Function Map DVSEC\n");
1126       dvsec_cxl_function_map(d, where);
1127       break;
1128     case 3:
1129       printf("\t\tCXL Extensions DVSEC for Ports\n");
1130       dvsec_cxl_port(d, where, len);
1131       break;
1132     case 4:
1133       printf("\t\tGPF DVSEC for CXL Ports\n");
1134       dvsec_cxl_gpf_port(d, where);
1135       break;
1136     case 5:
1137       printf("\t\tGPF DVSEC for CXL Devices\n");
1138       dvsec_cxl_gpf_device(d, where);
1139       break;
1140     case 7:
1141       printf("\t\tPCIe DVSEC for Flex Bus Port\n");
1142       dvsec_cxl_flex_bus(d, where, rev, len);
1143       break;
1144     case 8:
1145       printf("\t\tRegister Locator DVSEC\n");
1146       dvsec_cxl_register_locator(d, where, len);
1147       break;
1148     case 9:
1149       printf("\t\tMLD DVSEC\n");
1150       dvsec_cxl_mld(d, where);
1151       break;
1152     case 0xa:
1153       printf("\t\tPCIe DVSEC for Test Capability <?>\n");
1154       break;
1155     default:
1156       printf("\t\tUnknown ID %04x\n", id);
1157     }
1158 }
1159
1160 static void
1161 cap_dvsec(struct device *d, int where)
1162 {
1163   printf("Designated Vendor-Specific: ");
1164   if (!config_fetch(d, where + PCI_DVSEC_HEADER1, 8))
1165     {
1166       printf("<unreadable>\n");
1167       return;
1168     }
1169
1170   u32 hdr = get_conf_long(d, where + PCI_DVSEC_HEADER1);
1171   u16 vendor = BITS(hdr, 0, 16);
1172   byte rev = BITS(hdr, 16, 4);
1173   u16 len = BITS(hdr, 20, 12);
1174
1175   u16 id = get_conf_long(d, where + PCI_DVSEC_HEADER2);
1176
1177   printf("Vendor=%04x ID=%04x Rev=%d Len=%d", vendor, id, rev, len);
1178   if (vendor == PCI_DVSEC_VENDOR_ID_CXL && len >= 16)
1179     cap_dvsec_cxl(d, id, rev, where, len);
1180   else
1181     printf(" <?>\n");
1182 }
1183
1184 static void
1185 cap_evendor(struct device *d, int where)
1186 {
1187   u32 hdr;
1188
1189   printf("Vendor Specific Information: ");
1190   if (!config_fetch(d, where + PCI_EVNDR_HEADER, 4))
1191     {
1192       printf("<unreadable>\n");
1193       return;
1194     }
1195
1196   hdr = get_conf_long(d, where + PCI_EVNDR_HEADER);
1197   printf("ID=%04x Rev=%d Len=%03x <?>\n",
1198     BITS(hdr, 0, 16),
1199     BITS(hdr, 16, 4),
1200     BITS(hdr, 20, 12));
1201 }
1202
1203 static int l1pm_calc_pwron(int scale, int value)
1204 {
1205   switch (scale)
1206     {
1207       case 0:
1208         return 2 * value;
1209       case 1:
1210         return 10 * value;
1211       case 2:
1212         return 100 * value;
1213     }
1214   return -1;
1215 }
1216
1217 static void
1218 cap_l1pm(struct device *d, int where)
1219 {
1220   u32 l1_cap, val, scale;
1221   int time;
1222
1223   printf("L1 PM Substates\n");
1224
1225   if (verbose < 2)
1226     return;
1227
1228   if (!config_fetch(d, where + PCI_L1PM_SUBSTAT_CAP, 12))
1229     {
1230       printf("\t\t<unreadable>\n");
1231       return;
1232     }
1233
1234   l1_cap = get_conf_long(d, where + PCI_L1PM_SUBSTAT_CAP);
1235   printf("\t\tL1SubCap: ");
1236   printf("PCI-PM_L1.2%c PCI-PM_L1.1%c ASPM_L1.2%c ASPM_L1.1%c L1_PM_Substates%c\n",
1237     FLAG(l1_cap, PCI_L1PM_SUBSTAT_CAP_PM_L12),
1238     FLAG(l1_cap, PCI_L1PM_SUBSTAT_CAP_PM_L11),
1239     FLAG(l1_cap, PCI_L1PM_SUBSTAT_CAP_ASPM_L12),
1240     FLAG(l1_cap, PCI_L1PM_SUBSTAT_CAP_ASPM_L11),
1241     FLAG(l1_cap, PCI_L1PM_SUBSTAT_CAP_L1PM_SUPP));
1242
1243   if (l1_cap & PCI_L1PM_SUBSTAT_CAP_PM_L12 || l1_cap & PCI_L1PM_SUBSTAT_CAP_ASPM_L12)
1244     {
1245       printf("\t\t\t  PortCommonModeRestoreTime=%dus ", BITS(l1_cap, 8, 8));
1246       time = l1pm_calc_pwron(BITS(l1_cap, 16, 2), BITS(l1_cap, 19, 5));
1247       if (time != -1)
1248         printf("PortTPowerOnTime=%dus\n", time);
1249       else
1250         printf("PortTPowerOnTime=<error>\n");
1251     }
1252
1253   val = get_conf_long(d, where + PCI_L1PM_SUBSTAT_CTL1);
1254   printf("\t\tL1SubCtl1: PCI-PM_L1.2%c PCI-PM_L1.1%c ASPM_L1.2%c ASPM_L1.1%c\n",
1255     FLAG(val, PCI_L1PM_SUBSTAT_CTL1_PM_L12),
1256     FLAG(val, PCI_L1PM_SUBSTAT_CTL1_PM_L11),
1257     FLAG(val, PCI_L1PM_SUBSTAT_CTL1_ASPM_L12),
1258     FLAG(val, PCI_L1PM_SUBSTAT_CTL1_ASPM_L11));
1259
1260   if (l1_cap & PCI_L1PM_SUBSTAT_CAP_PM_L12 || l1_cap & PCI_L1PM_SUBSTAT_CAP_ASPM_L12)
1261     {
1262       printf("\t\t\t   T_CommonMode=%dus", BITS(val, 8, 8));
1263
1264       if (l1_cap & PCI_L1PM_SUBSTAT_CAP_ASPM_L12)
1265         {
1266           scale = BITS(val, 29, 3);
1267           if (scale > 5)
1268             printf(" LTR1.2_Threshold=<error>");
1269           else
1270             printf(" LTR1.2_Threshold=%" PCI_U64_FMT_U "ns", BITS(val, 16, 10) * (u64) cap_ltr_scale(scale));
1271         }
1272       printf("\n");
1273     }
1274
1275   val = get_conf_long(d, where + PCI_L1PM_SUBSTAT_CTL2);
1276   printf("\t\tL1SubCtl2:");
1277   if (l1_cap & PCI_L1PM_SUBSTAT_CAP_PM_L12 || l1_cap & PCI_L1PM_SUBSTAT_CAP_ASPM_L12)
1278     {
1279       time = l1pm_calc_pwron(BITS(val, 0, 2), BITS(val, 3, 5));
1280       if (time != -1)
1281         printf(" T_PwrOn=%dus", time);
1282       else
1283         printf(" T_PwrOn=<error>");
1284     }
1285   printf("\n");
1286 }
1287
1288 static void
1289 cap_ptm(struct device *d, int where)
1290 {
1291   u32 buff;
1292   u16 clock;
1293
1294   printf("Precision Time Measurement\n");
1295
1296   if (verbose < 2)
1297     return;
1298
1299   if (!config_fetch(d, where + 4, 8))
1300     {
1301       printf("\t\t<unreadable>\n");
1302       return;
1303     }
1304
1305   buff = get_conf_long(d, where + 4);
1306   printf("\t\tPTMCap: ");
1307   printf("Requester%c Responder%c Root%c\n",
1308     FLAG(buff, 0x1),
1309     FLAG(buff, 0x2),
1310     FLAG(buff, 0x4));
1311
1312   clock = BITS(buff, 8, 8);
1313   printf("\t\tPTMClockGranularity: ");
1314   switch (clock)
1315     {
1316       case 0x00:
1317         printf("Unimplemented\n");
1318         break;
1319       case 0xff:
1320         printf("Greater than 254ns\n");
1321         break;
1322       default:
1323         printf("%huns\n", clock);
1324     }
1325
1326   buff = get_conf_long(d, where + 8);
1327   printf("\t\tPTMControl: ");
1328   printf("Enabled%c RootSelected%c\n",
1329     FLAG(buff, 0x1),
1330     FLAG(buff, 0x2));
1331
1332   clock = BITS(buff, 8, 8);
1333   printf("\t\tPTMEffectiveGranularity: ");
1334   switch (clock)
1335     {
1336       case 0x00:
1337         printf("Unknown\n");
1338         break;
1339       case 0xff:
1340         printf("Greater than 254ns\n");
1341         break;
1342       default:
1343         printf("%huns\n", clock);
1344     }
1345 }
1346
1347 static void
1348 print_rebar_range_size(int ld2_size)
1349 {
1350   // This function prints the input as a power-of-2 size value
1351   // It is biased with 1MB = 0, ...
1352   // Maximum resizable BAR value supported is 2^63 bytes = 43
1353   // for the extended resizable BAR capability definition
1354   // (otherwise it would stop at 2^28)
1355
1356   if (ld2_size >= 0 && ld2_size < 10)
1357     printf(" %dMB", (1 << ld2_size));
1358   else if (ld2_size >= 10 && ld2_size < 20)
1359     printf(" %dGB", (1 << (ld2_size-10)));
1360   else if (ld2_size >= 20 && ld2_size < 30)
1361     printf(" %dTB", (1 << (ld2_size-20)));
1362   else if (ld2_size >= 30 && ld2_size < 40)
1363     printf(" %dPB", (1 << (ld2_size-30)));
1364   else if (ld2_size >= 40 && ld2_size < 44)
1365     printf(" %dEB", (1 << (ld2_size-40)));
1366   else
1367     printf(" <unknown>");
1368 }
1369
1370 static void
1371 cap_rebar(struct device *d, int where, int virtual)
1372 {
1373   u32 sizes_buffer, control_buffer, ext_sizes, current_size;
1374   u16 bar_index, barcount, i;
1375   // If the structure exists, at least one bar is defined
1376   u16 num_bars = 1;
1377
1378   printf("%s Resizable BAR\n", (virtual) ? "Virtual" : "Physical");
1379
1380   if (verbose < 2)
1381     return;
1382
1383   // Go through all defined BAR definitions of the caps, at minimum 1
1384   // (loop also terminates if num_bars read from caps is > 6)
1385   for (barcount = 0; barcount < num_bars; barcount++)
1386     {
1387       where += 4;
1388
1389       // Get the next BAR configuration
1390       if (!config_fetch(d, where, 8))
1391         {
1392           printf("\t\t<unreadable>\n");
1393           return;
1394         }
1395
1396       sizes_buffer = get_conf_long(d, where) >> 4;
1397       where += 4;
1398       control_buffer = get_conf_long(d, where);
1399
1400       bar_index  = BITS(control_buffer, 0, 3);
1401       current_size = BITS(control_buffer, 8, 6);
1402       ext_sizes = BITS(control_buffer, 16, 16);
1403
1404       if (barcount == 0)
1405         {
1406           // Only index 0 controlreg has the num_bar count definition
1407           num_bars = BITS(control_buffer, 5, 3);
1408           if (num_bars < 1 || num_bars > 6)
1409             {
1410               printf("\t\t<error in resizable BAR: num_bars=%d is out of specification>\n", num_bars);
1411               break;
1412             }
1413         }
1414
1415       // Resizable BAR list entry have an arbitrary index and current size
1416       printf("\t\tBAR %d: current size:", bar_index);
1417       print_rebar_range_size(current_size);
1418
1419       if (sizes_buffer || ext_sizes)
1420         {
1421           printf(", supported:");
1422
1423           for (i=0; i<28; i++)
1424             if (sizes_buffer & (1U << i))
1425               print_rebar_range_size(i);
1426
1427           for (i=0; i<16; i++)
1428             if (ext_sizes & (1U << i))
1429               print_rebar_range_size(i + 28);
1430         }
1431
1432       printf("\n");
1433     }
1434 }
1435
1436 static void
1437 cap_doe(struct device *d, int where)
1438 {
1439   u32 l;
1440
1441   printf("Data Object Exchange\n");
1442
1443   if (verbose < 2)
1444     return;
1445
1446   if (!config_fetch(d, where + PCI_DOE_CAP, 0x14))
1447     {
1448       printf("\t\t<unreadable>\n");
1449       return;
1450     }
1451
1452   l = get_conf_long(d, where + PCI_DOE_CAP);
1453   printf("\t\tDOECap: IntSup%c\n",
1454          FLAG(l, PCI_DOE_CAP_INT_SUPP));
1455   if (l & PCI_DOE_CAP_INT_SUPP)
1456     printf("\t\t\tIntMsgNum %d\n",
1457            PCI_DOE_CAP_INT_MSG(l));
1458
1459   l = get_conf_long(d, where + PCI_DOE_CTL);
1460   printf("\t\tDOECtl: IntEn%c\n",
1461          FLAG(l, PCI_DOE_CTL_INT));
1462
1463   l = get_conf_long(d, where + PCI_DOE_STS);
1464   printf("\t\tDOESta: Busy%c IntSta%c Error%c ObjectReady%c\n",
1465          FLAG(l, PCI_DOE_STS_BUSY),
1466          FLAG(l, PCI_DOE_STS_INT),
1467          FLAG(l, PCI_DOE_STS_ERROR),
1468          FLAG(l, PCI_DOE_STS_OBJECT_READY));
1469 }
1470
1471 void
1472 show_ext_caps(struct device *d, int type)
1473 {
1474   int where = 0x100;
1475   char been_there[0x1000];
1476   memset(been_there, 0, 0x1000);
1477   do
1478     {
1479       u32 header;
1480       int id, version;
1481
1482       if (!config_fetch(d, where, 4))
1483         break;
1484       header = get_conf_long(d, where);
1485       if (!header || header == 0xffffffff)
1486         break;
1487       id = header & 0xffff;
1488       version = (header >> 16) & 0xf;
1489       printf("\tCapabilities: [%03x", where);
1490       if (verbose > 1)
1491         printf(" v%d", version);
1492       printf("] ");
1493       if (been_there[where]++)
1494         {
1495           printf("<chain looped>\n");
1496           break;
1497         }
1498       switch (id)
1499         {
1500           case PCI_EXT_CAP_ID_NULL:
1501             printf("Null\n");
1502             break;
1503           case PCI_EXT_CAP_ID_AER:
1504             cap_aer(d, where, type);
1505             break;
1506           case PCI_EXT_CAP_ID_DPC:
1507             cap_dpc(d, where);
1508             break;
1509           case PCI_EXT_CAP_ID_VC:
1510           case PCI_EXT_CAP_ID_VC2:
1511             cap_vc(d, where);
1512             break;
1513           case PCI_EXT_CAP_ID_DSN:
1514             cap_dsn(d, where);
1515             break;
1516           case PCI_EXT_CAP_ID_PB:
1517             printf("Power Budgeting <?>\n");
1518             break;
1519           case PCI_EXT_CAP_ID_RCLINK:
1520             cap_rclink(d, where);
1521             break;
1522           case PCI_EXT_CAP_ID_RCILINK:
1523             printf("Root Complex Internal Link <?>\n");
1524             break;
1525           case PCI_EXT_CAP_ID_RCEC:
1526             cap_rcec(d, where);
1527             break;
1528           case PCI_EXT_CAP_ID_MFVC:
1529             printf("Multi-Function Virtual Channel <?>\n");
1530             break;
1531           case PCI_EXT_CAP_ID_RCRB:
1532             printf("Root Complex Register Block <?>\n");
1533             break;
1534           case PCI_EXT_CAP_ID_VNDR:
1535             cap_evendor(d, where);
1536             break;
1537           case PCI_EXT_CAP_ID_ACS:
1538             cap_acs(d, where);
1539             break;
1540           case PCI_EXT_CAP_ID_ARI:
1541             cap_ari(d, where);
1542             break;
1543           case PCI_EXT_CAP_ID_ATS:
1544             cap_ats(d, where);
1545             break;
1546           case PCI_EXT_CAP_ID_SRIOV:
1547             cap_sriov(d, where);
1548             break;
1549           case PCI_EXT_CAP_ID_MRIOV:
1550             printf("Multi-Root I/O Virtualization <?>\n");
1551             break;
1552           case PCI_EXT_CAP_ID_MCAST:
1553             cap_multicast(d, where, type);
1554             break;
1555           case PCI_EXT_CAP_ID_PRI:
1556             cap_pri(d, where);
1557             break;
1558           case PCI_EXT_CAP_ID_REBAR:
1559             cap_rebar(d, where, 0);
1560             break;
1561           case PCI_EXT_CAP_ID_DPA:
1562             printf("Dynamic Power Allocation <?>\n");
1563             break;
1564           case PCI_EXT_CAP_ID_TPH:
1565             cap_tph(d, where);
1566             break;
1567           case PCI_EXT_CAP_ID_LTR:
1568             cap_ltr(d, where);
1569             break;
1570           case PCI_EXT_CAP_ID_SECPCI:
1571             cap_sec(d, where);
1572             break;
1573           case PCI_EXT_CAP_ID_PMUX:
1574             printf("Protocol Multiplexing <?>\n");
1575             break;
1576           case PCI_EXT_CAP_ID_PASID:
1577             cap_pasid(d, where);
1578             break;
1579           case PCI_EXT_CAP_ID_LNR:
1580             printf("LN Requester <?>\n");
1581             break;
1582           case PCI_EXT_CAP_ID_L1PM:
1583             cap_l1pm(d, where);
1584             break;
1585           case PCI_EXT_CAP_ID_PTM:
1586             cap_ptm(d, where);
1587             break;
1588           case PCI_EXT_CAP_ID_M_PCIE:
1589             printf("PCI Express over M_PHY <?>\n");
1590             break;
1591           case PCI_EXT_CAP_ID_FRS:
1592             printf("FRS Queueing <?>\n");
1593             break;
1594           case PCI_EXT_CAP_ID_RTR:
1595             printf("Readiness Time Reporting <?>\n");
1596             break;
1597           case PCI_EXT_CAP_ID_DVSEC:
1598             cap_dvsec(d, where);
1599             break;
1600           case PCI_EXT_CAP_ID_VF_REBAR:
1601             cap_rebar(d, where, 1);
1602             break;
1603           case PCI_EXT_CAP_ID_DLNK:
1604             printf("Data Link Feature <?>\n");
1605             break;
1606           case PCI_EXT_CAP_ID_16GT:
1607             printf("Physical Layer 16.0 GT/s <?>\n");
1608             break;
1609           case PCI_EXT_CAP_ID_LMR:
1610             printf("Lane Margining at the Receiver <?>\n");
1611             break;
1612           case PCI_EXT_CAP_ID_HIER_ID:
1613             printf("Hierarchy ID <?>\n");
1614             break;
1615           case PCI_EXT_CAP_ID_NPEM:
1616             printf("Native PCIe Enclosure Management <?>\n");
1617             break;
1618       case PCI_EXT_CAP_ID_32GT:
1619             printf("Physical Layer 32.0 GT/s <?>\n");
1620         break;
1621           case PCI_EXT_CAP_ID_DOE:
1622             cap_doe(d, where);
1623             break;
1624           default:
1625             printf("Extended Capability ID %#02x\n", id);
1626             break;
1627         }
1628       where = (header >> 20) & ~3;
1629     } while (where);
1630 }