]>
Commit | Line | Data |
---|---|---|
c7a34993 MM |
1 | /* |
2 | * The PCI Utilities -- List All PCI Devices | |
3 | * | |
6b056c8e | 4 | * Copyright (c) 1997--2018 Martin Mares <mj@ucw.cz> |
c7a34993 | 5 | * |
61829219 MM |
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 | |
c7a34993 MM |
9 | */ |
10 | ||
11 | #define PCIUTILS_LSPCI | |
12 | #include "pciutils.h" | |
13 | ||
14 | /* | |
15 | * If we aren't being compiled by GCC, use xmalloc() instead of alloca(). | |
16 | * This increases our memory footprint, but only slightly since we don't | |
17 | * use alloca() much. | |
18 | */ | |
5c5ce192 | 19 | #if defined (__FreeBSD__) || defined (__NetBSD__) || defined (__OpenBSD__) || defined (__DragonFly__) || defined (__DJGPP__) |
c7a34993 MM |
20 | /* alloca() is defined in stdlib.h */ |
21 | #elif defined(__GNUC__) && !defined(PCI_OS_WINDOWS) | |
22 | #include <alloca.h> | |
23 | #else | |
24 | #undef alloca | |
25 | #define alloca xmalloc | |
26 | #endif | |
27 | ||
28 | /*** Options ***/ | |
29 | ||
30 | extern int verbose; | |
31 | extern struct pci_filter filter; | |
32 | extern char *opt_pcimap; | |
33 | ||
34 | /*** PCI devices and access to their config space ***/ | |
35 | ||
36 | struct device { | |
37 | struct device *next; | |
38 | struct pci_dev *dev; | |
6b056c8e MM |
39 | /* Bus topology calculated by grow_tree() */ |
40 | struct device *bus_next; | |
41 | struct bus *parent_bus; | |
42 | struct bridge *bridge; | |
43 | /* Cache */ | |
832b07a8 | 44 | int no_config_access; |
c7a34993 MM |
45 | unsigned int config_cached, config_bufsize; |
46 | byte *config; /* Cached configuration space data */ | |
47 | byte *present; /* Maps which configuration bytes are present */ | |
48 | }; | |
49 | ||
50 | extern struct device *first_dev; | |
51 | extern struct pci_access *pacc; | |
52 | ||
53 | struct device *scan_device(struct pci_dev *p); | |
54 | void show_device(struct device *d); | |
55 | ||
56 | int config_fetch(struct device *d, unsigned int pos, unsigned int len); | |
57 | u32 get_conf_long(struct device *d, unsigned int pos); | |
58 | word get_conf_word(struct device *d, unsigned int pos); | |
59 | byte get_conf_byte(struct device *d, unsigned int pos); | |
60 | ||
769ff0a8 MM |
61 | /* Useful macros for decoding of bits and bit fields */ |
62 | ||
c7a34993 | 63 | #define FLAG(x,y) ((x & y) ? '+' : '-') |
769ff0a8 MM |
64 | #define BITS(x,at,width) (((x) >> (at)) & ((1 << (width)) - 1)) |
65 | #define TABLE(tab,x,buf) ((x) < sizeof(tab)/sizeof((tab)[0]) ? (tab)[x] : (sprintf((buf), "??%d", (x)), (buf))) | |
c7a34993 MM |
66 | |
67 | /* ls-vpd.c */ | |
68 | ||
69 | void cap_vpd(struct device *d); | |
70 | ||
71 | /* ls-caps.c */ | |
72 | ||
21510591 | 73 | void show_caps(struct device *d, int where); |
c7a34993 MM |
74 | |
75 | /* ls-ecaps.c */ | |
76 | ||
a1492b88 | 77 | void show_ext_caps(struct device *d, int type); |
c7a34993 | 78 | |
7ff8a323 GH |
79 | /* ls-caps-vendor.c */ |
80 | ||
81 | void show_vendor_caps(struct device *d, int where, int cap); | |
82 | ||
c7a34993 MM |
83 | /* ls-kernel.c */ |
84 | ||
85 | void show_kernel_machine(struct device *d UNUSED); | |
86 | void show_kernel(struct device *d UNUSED); | |
17ec7e70 | 87 | void show_kernel_cleanup(void); |
c7a34993 MM |
88 | |
89 | /* ls-tree.c */ | |
90 | ||
6b056c8e MM |
91 | struct bridge { |
92 | struct bridge *chain; /* Single-linked list of bridges */ | |
6662052f | 93 | struct bridge *next, *prev, *child; /* Tree of bridges */ |
b1cff3a4 | 94 | struct bus *first_bus, *last_bus; /* List of buses connected to this bridge */ |
6b056c8e MM |
95 | unsigned int domain; |
96 | unsigned int primary, secondary, subordinate; /* Bus numbers */ | |
97 | struct device *br_dev; | |
98 | }; | |
99 | ||
100 | struct bus { | |
101 | unsigned int domain; | |
102 | unsigned int number; | |
103 | struct bus *sibling; | |
104 | struct bridge *parent_bridge; | |
105 | struct device *first_dev, **last_dev; | |
106 | }; | |
107 | ||
108 | extern struct bridge host_bridge; | |
109 | ||
110 | void grow_tree(void); | |
888ddf0e | 111 | void show_forest(struct pci_filter *filter); |
c7a34993 MM |
112 | |
113 | /* ls-map.c */ | |
114 | ||
115 | void map_the_bus(void); |