1 /* ----------------------------------------------------------------------- *
3 * Copyright 2006 Erwan Velu - All Rights Reserved
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use,
9 * copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom
11 * the Software is furnished to do so, subject to the following
14 * The above copyright notice and this permission notice shall
15 * be included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
26 * -----------------------------------------------------------------------
44 # define dprintf printf
46 # define dprintf(...) ((void)0)
49 char display_line
= 0;
50 #define moreprintf(...) \
53 if (display_line == 24) { \
56 printf("Press Enter to continue\n"); \
57 fgets(tempbuf, sizeof tempbuf, stdin); \
59 printf ( __VA_ARGS__); \
62 void display_pci_devices(struct pci_domain
*pci_domain
)
64 struct pci_device
*pci_device
;
65 char kernel_modules
[LINUX_KERNEL_MODULE_SIZE
*
66 MAX_KERNEL_MODULES_PER_PCI_DEVICE
];
68 for_each_pci_func(pci_device
, pci_domain
) {
70 memset(kernel_modules
, 0, sizeof kernel_modules
);
72 /* printf("PCI: found %d kernel modules for %04x:%04x[%04x:%04x]\n",
73 pci_device->dev_info->linux_kernel_module_count,
74 pci_device->vendor, pci_device->product,
75 pci_device->sub_vendor, pci_device->sub_product);
77 for (int i
= 0; i
< pci_device
->dev_info
->linux_kernel_module_count
;
80 strncat(kernel_modules
, " | ", 3);
82 strncat(kernel_modules
,
83 pci_device
->dev_info
->linux_kernel_module
[i
],
84 LINUX_KERNEL_MODULE_SIZE
- 1);
87 moreprintf("%04x:%04x[%04x:%04x]: %s\n",
88 pci_device
->vendor
, pci_device
->product
,
89 pci_device
->sub_vendor
, pci_device
->sub_product
,
90 pci_device
->dev_info
->class_name
);
92 moreprintf(" Vendor Name : %s\n",
93 pci_device
->dev_info
->vendor_name
);
94 moreprintf(" Product Name : %s\n",
95 pci_device
->dev_info
->product_name
);
96 moreprintf(" PCI bus position : %02x:%02x.%01x\n", __pci_bus
,
97 __pci_slot
, __pci_func
);
98 moreprintf(" Kernel modules : %s\n\n", kernel_modules
);
102 int main(int argc
, char *argv
[])
104 struct pci_domain
*pci_domain
;
106 int nb_pci_devices
= 0;
111 openconsole(&dev_stdcon_r
, &dev_stdcon_w
);
113 /* Scanning to detect pci buses and devices */
114 printf("PCI: Scanning PCI BUS\n");
115 pci_domain
= pci_scan();
117 printf("PCI: no devices found!\n");
121 struct pci_device
*pci_device
;
122 for_each_pci_func(pci_device
, pci_domain
) {
126 printf("PCI: %d PCI devices found\n", nb_pci_devices
);
128 printf("PCI: Looking for device name\n");
129 /* Assigning product & vendor name for each device */
130 return_code
= get_name_from_pci_ids(pci_domain
, "pci.ids");
131 if (return_code
== -ENOPCIIDS
) {
132 printf("PCI: ERROR !\n");
133 printf("PCI: Unable to open pci.ids file in current directory.\n");
134 printf("PCI: PCI Device names can't be computed.\n");
137 printf("PCI: Resolving class names\n");
138 /* Assigning class name for each device */
139 return_code
= get_class_name_from_pci_ids(pci_domain
, "pci.ids");
140 if (return_code
== -ENOPCIIDS
) {
141 printf("PCI: ERROR !\n");
142 printf("PCI: Unable to open pci.ids file in current directory.\n");
143 printf("PCI: PCI class names can't be computed.\n");
146 printf("PCI: Looking for Kernel modules\n");
147 /* Detecting which kernel module should match each device */
148 return_code
= get_module_name_from_pcimap(pci_domain
, "modules.pcimap");
149 if (return_code
== -ENOMODULESPCIMAP
) {
150 printf("PCI: ERROR !\n");
151 printf("PCI: Unable to open modules.pcimap file in current directory.\n");
152 printf("PCI: Kernel Module names can't be computed.\n");
155 /* display the pci devices we found */
156 display_pci_devices(pci_domain
);