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 main_show_pci(int argc __unused
, char **argv __unused
,
37 struct s_hardware
*hardware
)
41 more_printf(" NB Devices : %d\n", hardware
->nb_pci_devices
);
44 static void show_pci_device(int argc
, char **argv
, struct s_hardware
*hardware
)
47 struct pci_device
*pci_device
= NULL
, *temp_pci_device
;
49 bool nopciids
= false;
50 bool nomodulespcimap
= false;
51 bool nomodulesalias
= false;
52 bool nomodulesfiles
= false;
53 char kernel_modules
[LINUX_KERNEL_MODULE_SIZE
*
54 MAX_KERNEL_MODULES_PER_PCI_DEVICE
];
55 int bus
= 0, slot
= 0, func
= 0;
58 /* Sanitize arguments */
60 more_printf("show device <number>\n");
63 pcidev
= strtol(argv
[0], (char **)NULL
, 10);
65 if (errno
== ERANGE
) {
66 more_printf("This PCI device number is incorrect\n");
69 if ((pcidev
> hardware
->nb_pci_devices
) || (pcidev
<= 0)) {
70 more_printf("PCI device %d doesn't exist\n", pcidev
);
73 if (hardware
->pci_ids_return_code
== -ENOPCIIDS
) {
76 if (hardware
->modules_pcimap_return_code
== -ENOMODULESPCIMAP
) {
77 nomodulespcimap
= true;
79 if (hardware
->modules_alias_return_code
== -ENOMODULESALIAS
) {
80 nomodulesalias
= true;
82 nomodulesfiles
= nomodulespcimap
&& nomodulesalias
;
83 for_each_pci_func(temp_pci_device
, hardware
->pci_domain
) {
89 pci_device
= temp_pci_device
;
93 if (pci_device
== NULL
) {
94 more_printf("We were enabled to find PCI device %d\n", pcidev
);
98 memset(kernel_modules
, 0, sizeof kernel_modules
);
100 kmod
< pci_device
->dev_info
->linux_kernel_module_count
; kmod
++) {
102 strncat(kernel_modules
, " | ", 3);
104 strncat(kernel_modules
,
105 pci_device
->dev_info
->linux_kernel_module
[kmod
],
106 LINUX_KERNEL_MODULE_SIZE
- 1);
108 if (pci_device
->dev_info
->linux_kernel_module_count
== 0)
109 strlcpy(kernel_modules
, "unknown", 7);
111 more_printf("PCI Device %d\n", pcidev
);
113 if (nopciids
== false) {
114 more_printf("Vendor Name : %s\n", pci_device
->dev_info
->vendor_name
);
115 more_printf("Product Name : %s\n", pci_device
->dev_info
->product_name
);
116 more_printf("Class Name : %s\n", pci_device
->dev_info
->class_name
);
119 if (nomodulesfiles
== false) {
120 more_printf("Kernel module : %s\n", kernel_modules
);
123 more_printf("Vendor ID : %04x\n", pci_device
->vendor
);
124 more_printf("Product ID : %04x\n", pci_device
->product
);
125 more_printf("SubVendor ID : %04x\n", pci_device
->sub_vendor
);
126 more_printf("SubProduct ID : %04x\n", pci_device
->sub_product
);
127 more_printf("Class ID : %02x.%02x.%02x\n", pci_device
->class[2],
128 pci_device
->class[1], pci_device
->class[0]);
129 more_printf("Revision : %02x\n", pci_device
->revision
);
130 if ((pci_device
->dev_info
->irq
> 0)
131 && (pci_device
->dev_info
->irq
< 255))
132 more_printf("IRQ : %0d\n", pci_device
->dev_info
->irq
);
133 more_printf("Latency : %0d\n", pci_device
->dev_info
->latency
);
134 more_printf("PCI Bus : %02d\n", bus
);
135 more_printf("PCI Slot : %02d\n", slot
);
136 more_printf("PCI Func : %02d\n", func
);
138 if (hardware
->is_pxe_valid
== true) {
139 if ((hardware
->pxe
.pci_device
!= NULL
)
140 && (hardware
->pxe
.pci_device
== pci_device
)) {
141 more_printf("Mac Address : %s\n", hardware
->pxe
.mac_addr
);
142 more_printf("PXE : Current boot device\n");
147 static void show_pci_devices(int argc __unused
, char **argv __unused
,
148 struct s_hardware
*hardware
)
151 struct pci_device
*pci_device
;
152 char kernel_modules
[LINUX_KERNEL_MODULE_SIZE
*
153 MAX_KERNEL_MODULES_PER_PCI_DEVICE
];
154 bool nopciids
= false;
155 bool nomodulespcimap
= false;
156 bool nomodulesalias
= false;
157 bool nomodulesfile
= false;
159 char second_line
[81];
162 more_printf("%d PCI devices detected\n", hardware
->nb_pci_devices
);
164 if (hardware
->pci_ids_return_code
== -ENOPCIIDS
) {
167 if (hardware
->modules_pcimap_return_code
== -ENOMODULESPCIMAP
) {
168 nomodulespcimap
= true;
170 if (hardware
->modules_pcimap_return_code
== -ENOMODULESALIAS
) {
171 nomodulesalias
= true;
174 nomodulesfile
= nomodulespcimap
&& nomodulesalias
;
176 /* For every detected pci device, compute its submenu */
177 for_each_pci_func(pci_device
, hardware
->pci_domain
) {
178 memset(kernel_modules
, 0, sizeof kernel_modules
);
180 kmod
< pci_device
->dev_info
->linux_kernel_module_count
; kmod
++) {
182 strncat(kernel_modules
, " | ", 3);
184 strncat(kernel_modules
,
185 pci_device
->dev_info
->linux_kernel_module
[kmod
],
186 LINUX_KERNEL_MODULE_SIZE
- 1);
188 if (pci_device
->dev_info
->linux_kernel_module_count
== 0)
189 strlcpy(kernel_modules
, "unknown", 7);
191 if (nopciids
== false) {
192 snprintf(first_line
, sizeof(first_line
),
194 pci_device
->dev_info
->vendor_name
,
195 pci_device
->dev_info
->product_name
);
196 if (nomodulesfile
== false)
197 snprintf(second_line
, sizeof(second_line
),
198 " # %-25s # Kmod: %s\n",
199 pci_device
->dev_info
->class_name
, kernel_modules
);
201 snprintf(second_line
, sizeof(second_line
),
202 " # %-25s # ID:%04x:%04x[%04x:%04x]\n",
203 pci_device
->dev_info
->class_name
,
206 pci_device
->sub_vendor
, pci_device
->sub_product
);
208 more_printf("%s", first_line
);
209 more_printf("%s", second_line
);
211 } else if (nopciids
== true) {
212 if (nomodulesfile
== true) {
213 more_printf("%02d: %04x:%04x [%04x:%04x] \n",
214 i
, pci_device
->vendor
,
216 pci_device
->sub_vendor
, pci_device
->sub_product
);
219 ("%02d: %04x:%04x [%04x:%04x] Kmod:%s\n", i
,
220 pci_device
->vendor
, pci_device
->product
,
221 pci_device
->sub_vendor
,
222 pci_device
->sub_product
, kernel_modules
);
229 static void show_pci_irq(int argc __unused
, char **argv __unused
,
230 struct s_hardware
*hardware
)
232 struct pci_device
*pci_device
;
233 bool nopciids
= false;
236 more_printf("%d PCI devices detected\n", hardware
->nb_pci_devices
);
237 more_printf("IRQ : product\n");
238 more_printf("-------------\n");
240 if (hardware
->pci_ids_return_code
== -ENOPCIIDS
) {
244 /* For every detected pci device, compute its submenu */
245 for_each_pci_func(pci_device
, hardware
->pci_domain
) {
246 /* Only display valid IRQs */
247 if ((pci_device
->dev_info
->irq
> 0)
248 && (pci_device
->dev_info
->irq
< 255)) {
249 if (nopciids
== false) {
250 more_printf("%02d : %s %s \n",
251 pci_device
->dev_info
->irq
,
252 pci_device
->dev_info
->vendor_name
,
253 pci_device
->dev_info
->product_name
);
255 more_printf("%02d : %04x:%04x [%04x:%04x] \n",
256 pci_device
->dev_info
->irq
,
259 pci_device
->sub_vendor
, pci_device
->sub_product
);
265 struct cli_callback_descr list_pci_show_modules
[] = {
268 .exec
= show_pci_irq
,
272 .name
= CLI_PCI_DEVICE
,
273 .exec
= show_pci_device
,
283 struct cli_module_descr pci_show_modules
= {
284 .modules
= list_pci_show_modules
,
285 .default_callback
= show_pci_devices
,
288 struct cli_mode_descr pci_mode
= {
291 .default_modules
= NULL
,
292 .show_modules
= &pci_show_modules
,