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
)
39 cli_detect_pci(hardware
);
42 more_printf(" NB Devices : %d\n", hardware
->nb_pci_devices
);
45 static void show_pci_device(int argc
, char **argv
, struct s_hardware
*hardware
)
48 struct pci_device
*pci_device
= NULL
, *temp_pci_device
;
50 bool nopciids
= false;
51 bool nomodulespcimap
= false;
52 bool nomodulesalias
= false;
53 bool nomodulesfiles
= false;
54 char kernel_modules
[LINUX_KERNEL_MODULE_SIZE
*
55 MAX_KERNEL_MODULES_PER_PCI_DEVICE
];
56 int bus
= 0, slot
= 0, func
= 0;
59 /* Sanitize arguments */
61 more_printf("show device <number>\n");
64 pcidev
= strtol(argv
[0], (char **)NULL
, 10);
66 if (errno
== ERANGE
) {
67 more_printf("This PCI device number is incorrect\n");
70 if ((pcidev
> hardware
->nb_pci_devices
) || (pcidev
<= 0)) {
71 more_printf("PCI device %d doesn't exist\n", pcidev
);
74 if (hardware
->pci_ids_return_code
== -ENOPCIIDS
) {
77 if (hardware
->modules_pcimap_return_code
== -ENOMODULESPCIMAP
) {
78 nomodulespcimap
= true;
80 if (hardware
->modules_alias_return_code
== -ENOMODULESALIAS
) {
81 nomodulesalias
= true;
83 nomodulesfiles
= nomodulespcimap
&& nomodulesalias
;
84 for_each_pci_func(temp_pci_device
, hardware
->pci_domain
) {
90 pci_device
= temp_pci_device
;
94 if (pci_device
== NULL
) {
95 more_printf("We were enabled to find PCI device %d\n", pcidev
);
99 memset(kernel_modules
, 0, sizeof kernel_modules
);
101 kmod
< pci_device
->dev_info
->linux_kernel_module_count
; kmod
++) {
103 strncat(kernel_modules
, " | ", 3);
105 strncat(kernel_modules
,
106 pci_device
->dev_info
->linux_kernel_module
[kmod
],
107 LINUX_KERNEL_MODULE_SIZE
- 1);
109 if (pci_device
->dev_info
->linux_kernel_module_count
== 0)
110 strlcpy(kernel_modules
, "unknown", 7);
112 more_printf("PCI Device %d\n", pcidev
);
114 if (nopciids
== false) {
115 more_printf("Vendor Name : %s\n", pci_device
->dev_info
->vendor_name
);
116 more_printf("Product Name : %s\n", pci_device
->dev_info
->product_name
);
117 more_printf("Class Name : %s\n", pci_device
->dev_info
->class_name
);
120 if (nomodulesfiles
== false) {
121 more_printf("Kernel module : %s\n", kernel_modules
);
124 more_printf("Vendor ID : %04x\n", pci_device
->vendor
);
125 more_printf("Product ID : %04x\n", pci_device
->product
);
126 more_printf("SubVendor ID : %04x\n", pci_device
->sub_vendor
);
127 more_printf("SubProduct ID : %04x\n", pci_device
->sub_product
);
128 more_printf("Class ID : %02x.%02x.%02x\n", pci_device
->class[2],
129 pci_device
->class[1], pci_device
->class[0]);
130 more_printf("Revision : %02x\n", pci_device
->revision
);
131 if ((pci_device
->dev_info
->irq
> 0)
132 && (pci_device
->dev_info
->irq
< 255))
133 more_printf("IRQ : %0d\n", pci_device
->dev_info
->irq
);
134 more_printf("Latency : %0d\n", pci_device
->dev_info
->latency
);
135 more_printf("PCI Bus : %02d\n", bus
);
136 more_printf("PCI Slot : %02d\n", slot
);
137 more_printf("PCI Func : %02d\n", func
);
139 if (hardware
->is_pxe_valid
== true) {
140 if ((hardware
->pxe
.pci_device
!= NULL
)
141 && (hardware
->pxe
.pci_device
== pci_device
)) {
142 more_printf("Mac Address : %s\n", hardware
->pxe
.mac_addr
);
143 more_printf("PXE : Current boot device\n");
148 static void show_pci_devices(int argc __unused
, char **argv __unused
,
149 struct s_hardware
*hardware
)
152 struct pci_device
*pci_device
;
153 char kernel_modules
[LINUX_KERNEL_MODULE_SIZE
*
154 MAX_KERNEL_MODULES_PER_PCI_DEVICE
];
155 bool nopciids
= false;
156 bool nomodulespcimap
= false;
157 bool nomodulesalias
= false;
158 bool nomodulesfile
= false;
160 char second_line
[81];
163 more_printf("%d PCI devices detected\n", hardware
->nb_pci_devices
);
165 if (hardware
->pci_ids_return_code
== -ENOPCIIDS
) {
168 if (hardware
->modules_pcimap_return_code
== -ENOMODULESPCIMAP
) {
169 nomodulespcimap
= true;
171 if (hardware
->modules_pcimap_return_code
== -ENOMODULESALIAS
) {
172 nomodulesalias
= true;
175 nomodulesfile
= nomodulespcimap
&& nomodulesalias
;
177 /* For every detected pci device, compute its submenu */
178 for_each_pci_func(pci_device
, hardware
->pci_domain
) {
179 memset(kernel_modules
, 0, sizeof kernel_modules
);
181 kmod
< pci_device
->dev_info
->linux_kernel_module_count
; kmod
++) {
183 strncat(kernel_modules
, " | ", 3);
185 strncat(kernel_modules
,
186 pci_device
->dev_info
->linux_kernel_module
[kmod
],
187 LINUX_KERNEL_MODULE_SIZE
- 1);
189 if (pci_device
->dev_info
->linux_kernel_module_count
== 0)
190 strlcpy(kernel_modules
, "unknown", 7);
192 if (nopciids
== false) {
193 snprintf(first_line
, sizeof(first_line
),
195 pci_device
->dev_info
->vendor_name
,
196 pci_device
->dev_info
->product_name
);
197 if (nomodulesfile
== false)
198 snprintf(second_line
, sizeof(second_line
),
199 " # %-25s # Kmod: %s\n",
200 pci_device
->dev_info
->class_name
, kernel_modules
);
202 snprintf(second_line
, sizeof(second_line
),
203 " # %-25s # ID:%04x:%04x[%04x:%04x]\n",
204 pci_device
->dev_info
->class_name
,
207 pci_device
->sub_vendor
, pci_device
->sub_product
);
209 more_printf("%s", first_line
);
210 more_printf("%s", second_line
);
212 } else if (nopciids
== true) {
213 if (nomodulesfile
== true) {
214 more_printf("%02d: %04x:%04x [%04x:%04x] \n",
215 i
, pci_device
->vendor
,
217 pci_device
->sub_vendor
, pci_device
->sub_product
);
220 ("%02d: %04x:%04x [%04x:%04x] Kmod:%s\n", i
,
221 pci_device
->vendor
, pci_device
->product
,
222 pci_device
->sub_vendor
,
223 pci_device
->sub_product
, kernel_modules
);
230 static void show_pci_irq(int argc __unused
, char **argv __unused
,
231 struct s_hardware
*hardware
)
233 struct pci_device
*pci_device
;
234 bool nopciids
= false;
237 more_printf("%d PCI devices detected\n", hardware
->nb_pci_devices
);
238 more_printf("IRQ : product\n");
239 more_printf("-------------\n");
241 if (hardware
->pci_ids_return_code
== -ENOPCIIDS
) {
245 /* For every detected pci device, compute its submenu */
246 for_each_pci_func(pci_device
, hardware
->pci_domain
) {
247 /* Only display valid IRQs */
248 if ((pci_device
->dev_info
->irq
> 0)
249 && (pci_device
->dev_info
->irq
< 255)) {
250 if (nopciids
== false) {
251 more_printf("%02d : %s %s \n",
252 pci_device
->dev_info
->irq
,
253 pci_device
->dev_info
->vendor_name
,
254 pci_device
->dev_info
->product_name
);
256 more_printf("%02d : %04x:%04x [%04x:%04x] \n",
257 pci_device
->dev_info
->irq
,
260 pci_device
->sub_vendor
, pci_device
->sub_product
);
266 struct cli_callback_descr list_pci_show_modules
[] = {
269 .exec
= show_pci_irq
,
272 .name
= CLI_PCI_DEVICE
,
273 .exec
= show_pci_device
,
281 struct cli_module_descr pci_show_modules
= {
282 .modules
= list_pci_show_modules
,
283 .default_callback
= show_pci_devices
,
286 struct cli_mode_descr pci_mode
= {
289 .default_modules
= NULL
,
290 .show_modules
= &pci_show_modules
,
294 void cli_detect_pci(struct s_hardware
*hardware
)
297 if (hardware
->pci_detection
== false) {
298 detect_pci(hardware
);
299 if (hardware
->pci_ids_return_code
== -ENOPCIIDS
) {
301 ("The pci.ids file is missing, device names can't be computed.\n");
302 more_printf("Please put one in same dir as hdt\n");
305 if ((hardware
->modules_pcimap_return_code
== -ENOMODULESPCIMAP
) &&
306 (hardware
->modules_alias_return_code
== -ENOMODULESALIAS
)) {
308 ("The modules.pcimap or modules.alias files are missing, device names can't be computed.\n");
309 more_printf("Please put one of them in same dir as hdt\n");
314 more_printf("Press enter to continue\n");
315 fgets(tempbuf
, sizeof(tempbuf
), stdin
);