1 /* ----------------------------------------------------------------------- *
3 * Copyright 2009 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 * -----------------------------------------------------------------------
34 #include "hdt-common.h"
36 void show_pci_device(struct s_hardware *hardware, const char *item)
39 struct pci_device *pci_device = NULL, *temp_pci_device;
40 long pcidev = strtol(item, (char **)NULL, 10);
41 bool nopciids = false;
42 bool nomodulespcimap = false;
43 char kernel_modules[LINUX_KERNEL_MODULE_SIZE *
44 MAX_KERNEL_MODULES_PER_PCI_DEVICE];
45 int bus = 0, slot = 0, func = 0;
47 if (errno == ERANGE) {
48 printf("This PCI device number is incorrect\n");
51 if ((pcidev > hardware->nb_pci_devices) || (pcidev <= 0)) {
52 printf("PCI device %d doesn't exists\n", pcidev);
55 if (hardware->pci_ids_return_code == -ENOPCIIDS) {
58 if (hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP) {
59 nomodulespcimap = true;
62 for_each_pci_func(temp_pci_device, hardware->pci_domain) {
68 pci_device = temp_pci_device;
72 if (pci_device == NULL) {
73 printf("We were enabled to find PCI device %d\n", pcidev);
77 memset(kernel_modules, 0, sizeof kernel_modules);
79 kmod < pci_device->dev_info->linux_kernel_module_count; kmod++) {
81 strncat(kernel_modules, " | ", 3);
83 strncat(kernel_modules,
84 pci_device->dev_info->linux_kernel_module[kmod],
85 LINUX_KERNEL_MODULE_SIZE - 1);
87 if (pci_device->dev_info->linux_kernel_module_count == 0)
88 strlcpy(kernel_modules, "unknown", 7);
91 printf("PCI Device %d\n", pcidev);
93 if (nopciids == false) {
94 more_printf("Vendor Name : %s\n",
95 pci_device->dev_info->vendor_name);
96 more_printf("Product Name : %s\n",
97 pci_device->dev_info->product_name);
98 more_printf("Class Name : %s\n",
99 pci_device->dev_info->class_name);
102 if (nomodulespcimap == false) {
103 more_printf("Kernel module : %s\n", kernel_modules);
106 more_printf("Vendor ID : %04x\n", pci_device->vendor);
107 more_printf("Product ID : %04x\n", pci_device->product);
108 more_printf("SubVendor ID : %04x\n", pci_device->sub_vendor);
109 more_printf("SubProduct ID : %04x\n", pci_device->sub_product);
110 more_printf("Class ID : %02x.%02x.%02x\n", pci_device->class[2],
111 pci_device->class[1], pci_device->class[0]);
112 more_printf("Revision : %02x\n", pci_device->revision);
113 if ((pci_device->dev_info->irq > 0)
114 && (pci_device->dev_info->irq < 255))
115 more_printf("IRQ : %0d\n", pci_device->dev_info->irq);
116 more_printf("Latency : %0d\n",pci_device->dev_info->latency);
117 more_printf("PCI Bus : %02d\n", bus);
118 more_printf("PCI Slot : %02d\n", slot);
119 more_printf("PCI Func : %02d\n", func);
121 if (hardware->is_pxe_valid == true) {
122 more_printf("Mac Address : %s\n", hardware->pxe.mac_addr);
123 if ((hardware->pxe.pci_device != NULL)
124 && (hardware->pxe.pci_device == pci_device))
125 more_printf("PXE : Current boot device\n",
130 static void show_pci_devices(struct s_hardware *hardware)
133 struct pci_device *pci_device;
134 char kernel_modules[LINUX_KERNEL_MODULE_SIZE *
135 MAX_KERNEL_MODULES_PER_PCI_DEVICE];
136 bool nopciids = false;
137 bool nomodulespcimap = false;
139 char second_line[81];
142 more_printf("%d PCI devices detected\n", hardware->nb_pci_devices);
144 if (hardware->pci_ids_return_code == -ENOPCIIDS) {
147 if (hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP) {
148 nomodulespcimap = true;
151 /* For every detected pci device, compute its submenu */
152 for_each_pci_func(pci_device, hardware->pci_domain) {
153 memset(kernel_modules, 0, sizeof kernel_modules);
155 kmod < pci_device->dev_info->linux_kernel_module_count;
158 strncat(kernel_modules, " | ", 3);
160 strncat(kernel_modules,
161 pci_device->dev_info->linux_kernel_module[kmod],
162 LINUX_KERNEL_MODULE_SIZE - 1);
164 if (pci_device->dev_info->linux_kernel_module_count == 0)
165 strlcpy(kernel_modules, "unknown", 7);
167 if (nopciids == false) {
168 snprintf(first_line, sizeof(first_line),
170 pci_device->dev_info->vendor_name,
171 pci_device->dev_info->product_name);
172 if (nomodulespcimap == false)
173 snprintf(second_line, sizeof(second_line),
174 " # %-25s # Kmod: %s\n",
175 pci_device->dev_info->class_name,
178 snprintf(second_line, sizeof(second_line),
179 " # %-25s # ID:%04x:%04x[%04x:%04x]\n",
180 pci_device->dev_info->class_name,
183 pci_device->sub_vendor,
184 pci_device->sub_product);
186 more_printf(first_line);
187 more_printf(second_line);
189 } else if (nopciids == true) {
190 if (nomodulespcimap == true) {
191 more_printf("%02d: %04x:%04x [%04x:%04x] \n",
192 i, pci_device->vendor,
194 pci_device->sub_vendor,
195 pci_device->sub_product);
198 ("%02d: %04x:%04x [%04x:%04x] Kmod:%s\n", i,
199 pci_device->vendor, pci_device->product,
200 pci_device->sub_vendor,
201 pci_device->sub_product, kernel_modules,
202 pci_device->sub_product, kernel_modules);
210 static void show_pci_irq(struct s_hardware *hardware)
212 struct pci_device *pci_device;
213 bool nopciids = false;
216 more_printf("%d PCI devices detected\n", hardware->nb_pci_devices);
217 more_printf("IRQ : product\n");
218 more_printf("-------------\n");
220 if (hardware->pci_ids_return_code == -ENOPCIIDS) {
224 /* For every detected pci device, compute its submenu */
225 for_each_pci_func(pci_device, hardware->pci_domain) {
226 /* Only display valid IRQs */
227 if ((pci_device->dev_info->irq > 0) && (pci_device->dev_info->irq < 255)) {
228 if (nopciids == false) {
229 more_printf("%02d : %s %s \n",
230 pci_device->dev_info->irq,
231 pci_device->dev_info->vendor_name,
232 pci_device->dev_info->product_name);
234 more_printf("%02d : %04x:%04x [%04x:%04x] \n",
235 pci_device->dev_info->irq, pci_device->vendor,
237 pci_device->sub_vendor,
238 pci_device->sub_product);
244 static void show_pci_help()
246 more_printf("Show supports the following commands : \n");
247 more_printf(" %s\n", CLI_SHOW_LIST);
248 more_printf(" %s <device_number>\n", CLI_PCI_DEVICE);
249 more_printf(" %s\n",CLI_IRQ);
252 static void pci_show(char *item, struct s_hardware *hardware)
254 if (!strncmp(item, CLI_SHOW_LIST, sizeof(CLI_SHOW_LIST) - 1)) {
255 show_pci_devices(hardware);
258 if (!strncmp(item, CLI_IRQ, sizeof(CLI_IRQ) - 1)) {
259 show_pci_irq(hardware);
262 if (!strncmp(item, CLI_PCI_DEVICE, sizeof(CLI_PCI_DEVICE) - 1)) {
263 show_pci_device(hardware, item + sizeof(CLI_PCI_DEVICE) - 1);
269 void handle_pci_commands(char *cli_line, struct s_hardware *hardware)
271 if (!strncmp(cli_line, CLI_SHOW, sizeof(CLI_SHOW) - 1)) {
272 pci_show(strstr(cli_line, "show") + sizeof(CLI_SHOW), hardware);
277 void cli_detect_pci(struct s_hardware *hardware)
280 if (hardware->pci_detection == false) {
281 detect_pci(hardware);
282 if (hardware->pci_ids_return_code == -ENOPCIIDS) {
284 ("The pci.ids file is missing, device names can't be computed.\n");
285 more_printf("Please put one in same dir as hdt\n");
288 if (hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP) {
290 ("The modules.pcimap file is missing, device names can't be computed.\n");
291 more_printf("Please put one in same dir as hdt\n");
296 printf("Press enter to continue\n");
297 fgets(tempbuf, sizeof(tempbuf), stdin);
302 void main_show_pci(struct s_hardware *hardware)
304 cli_detect_pci(hardware);
306 more_printf("PCI\n");
307 more_printf(" NB Devices : %d\n", hardware->nb_pci_devices);