Adding upstream version 4.00~pre61+dfsg.
[syslinux-debian/hramrach.git] / com32 / modules / pcitest.c
blob672023ad81ec646ca3c07161493181a49bf9644d
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
12 * conditions:
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 * -----------------------------------------------------------------------
30 * pcitest.c
34 #include <inttypes.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38 #include <console.h>
39 #include <com32.h>
40 #include <sys/pci.h>
41 #include <stdbool.h>
43 #ifdef DEBUG
44 # define dprintf printf
45 #else
46 # define dprintf(...) ((void)0)
47 #endif
49 char display_line = 0;
50 #define moreprintf(...) \
51 do { \
52 display_line++; \
53 if (display_line == 24) { \
54 char tempbuf[10]; \
55 display_line=0; \
56 printf("Press Enter to continue\n"); \
57 fgets(tempbuf, sizeof tempbuf, stdin); \
58 } \
59 printf ( __VA_ARGS__); \
60 } while (0);
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;
78 i++) {
79 if (i > 0) {
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;
105 int return_code = 0;
106 int nb_pci_devices = 0;
108 (void)argc;
109 (void)argv;
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();
116 if (!pci_domain) {
117 printf("PCI: no devices found!\n");
118 return 1;
121 struct pci_device *pci_device;
122 for_each_pci_func(pci_device, pci_domain) {
123 nb_pci_devices++;
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);
157 return 0;