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 char display_line = 0;
45 #define moreprintf(...) \
48 if (display_line == 24) { \
51 printf("Press Enter to continue\n"); \
52 fgets(tempbuf, sizeof tempbuf, stdin); \
54 printf ( __VA_ARGS__); \
57 void display_pci_devices(struct pci_domain *pci_domain)
59 struct pci_device *pci_device;
60 char kernel_modules[LINUX_KERNEL_MODULE_SIZE *
61 MAX_KERNEL_MODULES_PER_PCI_DEVICE];
63 for_each_pci_func(pci_device, pci_domain) {
65 memset(kernel_modules, 0, sizeof kernel_modules);
67 /* printf("PCI: found %d kernel modules for %04x:%04x[%04x:%04x]\n",
68 pci_device->dev_info->linux_kernel_module_count,
69 pci_device->vendor, pci_device->product,
70 pci_device->sub_vendor, pci_device->sub_product);
72 for (int i = 0; i < pci_device->dev_info->linux_kernel_module_count;
75 strncat(kernel_modules, " | ", 3);
77 strncat(kernel_modules,
78 pci_device->dev_info->linux_kernel_module[i],
79 LINUX_KERNEL_MODULE_SIZE - 1);
82 moreprintf("%04x:%04x[%04x:%04x]: %s\n",
83 pci_device->vendor, pci_device->product,
84 pci_device->sub_vendor, pci_device->sub_product,
85 pci_device->dev_info->class_name);
87 moreprintf(" Vendor Name : %s\n",
88 pci_device->dev_info->vendor_name);
89 moreprintf(" Product Name : %s\n",
90 pci_device->dev_info->product_name);
91 moreprintf(" PCI bus position : %02x:%02x.%01x\n", __pci_bus,
92 __pci_slot, __pci_func);
93 moreprintf(" Kernel modules : %s\n\n", kernel_modules);
97 int main(int argc, char *argv[])
99 struct pci_domain *pci_domain;
101 int nb_pci_devices = 0;
106 openconsole(&dev_stdcon_r, &dev_stdcon_w);
108 /* Scanning to detect pci buses and devices */
109 printf("PCI: Scanning PCI BUS\n");
110 pci_domain = pci_scan();
112 printf("PCI: no devices found!\n");
116 struct pci_device *pci_device;
117 for_each_pci_func(pci_device, pci_domain) {
121 printf("PCI: %d PCI devices found\n", nb_pci_devices);
123 printf("PCI: Looking for device name\n");
124 /* Assigning product & vendor name for each device */
125 return_code = get_name_from_pci_ids(pci_domain, "pci.ids");
126 if (return_code == -ENOPCIIDS) {
127 printf("PCI: ERROR !\n");
128 printf("PCI: Unable to open pci.ids file in current directory.\n");
129 printf("PCI: PCI Device names can't be computed.\n");
132 printf("PCI: Resolving class names\n");
133 /* Assigning class name for each device */
134 return_code = get_class_name_from_pci_ids(pci_domain, "pci.ids");
135 if (return_code == -ENOPCIIDS) {
136 printf("PCI: ERROR !\n");
137 printf("PCI: Unable to open pci.ids file in current directory.\n");
138 printf("PCI: PCI class names can't be computed.\n");
141 printf("PCI: Looking for Kernel modules\n");
142 /* Detecting which kernel module should match each device */
143 return_code = get_module_name_from_pcimap(pci_domain, "modules.pcimap");
144 if (return_code == -ENOMODULESPCIMAP) {
145 printf("PCI: ERROR !\n");
146 printf("PCI: Unable to open modules.pcimap file in current directory.\n");
147 printf("PCI: Kernel Module names can't be computed.\n");
150 /* display the pci devices we found */
151 display_pci_devices(pci_domain);