1 /* ----------------------------------------------------------------------- *
3 * Copyright 2011 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 * -----------------------------------------------------------------------
29 #include "hdt-common.h"
32 void dump_pci(struct s_hardware
*hardware
, ZZJSON_CONFIG
* config
,
36 struct pci_device
*pci_device
=NULL
;
37 char kernel_modules
[LINUX_KERNEL_MODULE_SIZE
*
38 MAX_KERNEL_MODULES_PER_PCI_DEVICE
];
39 bool nopciids
= false;
40 bool nomodulespcimap
= false;
41 bool nomodulesalias
= false;
42 bool nomodulesfile
= false;
43 int bus
= 0, slot
= 0, func
= 0;
45 if (hardware
->pci_ids_return_code
== -ENOPCIIDS
) {
48 if (hardware
->modules_pcimap_return_code
== -ENOMODULESPCIMAP
) {
49 nomodulespcimap
= true;
51 if (hardware
->modules_pcimap_return_code
== -ENOMODULESALIAS
) {
52 nomodulesalias
= true;
55 nomodulesfile
= nomodulespcimap
&& nomodulesalias
;
59 add_i("pci_device.count", hardware
->nb_pci_devices
);
62 /* For every detected pci device, compute its submenu */
63 for_each_pci_func(pci_device
, hardware
->pci_domain
) {
64 if (pci_device
== NULL
)
78 memset(kernel_modules
, 0, sizeof kernel_modules
);
80 kmod
< pci_device
->dev_info
->linux_kernel_module_count
; kmod
++) {
82 strncat(kernel_modules
, " | ", 3);
84 strncat(kernel_modules
,
85 pci_device
->dev_info
->linux_kernel_module
[kmod
],
86 LINUX_KERNEL_MODULE_SIZE
- 1);
88 if (pci_device
->dev_info
->linux_kernel_module_count
== 0)
89 strlcpy(kernel_modules
, "unknown", 7);
91 add_i("pci_device.number", i
);
92 if (nopciids
== false) {
93 add_s("pci_device.vendor_name", pci_device
->dev_info
->vendor_name
);
94 add_s("pci_device.product_name",
95 pci_device
->dev_info
->product_name
);
97 if (nomodulesfile
== false) {
98 add_s("pci_device.class_name", pci_device
->dev_info
->class_name
);
99 add_s("pci_device.kernel_module", kernel_modules
);
102 snprintf(v
, sizeof(v
), "%04x", pci_device
->vendor
);
103 snprintf(p
, sizeof(p
), "%04x", pci_device
->product
);
104 snprintf(sv
, sizeof(sv
), "%04x", pci_device
->sub_vendor
);
105 snprintf(sp
, sizeof(sp
), "%04x", pci_device
->sub_product
);
106 snprintf(c
, sizeof(c
), "%02x.%02x.%02x",
107 pci_device
->class[2],
108 pci_device
->class[1], pci_device
->class[0]);
109 snprintf(r
, sizeof(r
), "%02x", pci_device
->revision
);
110 add_s("pci_device.vendor_id", v
);
111 add_s("pci_device.product_id", p
);
112 add_s("pci_device.sub_vendor_id", sv
);
113 add_s("pci_device.sub_product_id", sp
);
114 add_s("pci_device.class_id", c
);
115 add_s("pci_device.revision", r
);
116 if ((pci_device
->dev_info
->irq
> 0)
117 && (pci_device
->dev_info
->irq
< 255))
118 add_i("pci_device.irq", pci_device
->dev_info
->irq
);
120 add_i("pci_device.latency", pci_device
->dev_info
->latency
);
121 add_i("pci_device.bus", bus
);
122 add_i("pci_device.slot", slot
);
123 add_i("pci_device.func", func
);
125 if (hardware
->is_pxe_valid
== true) {
126 if ((hardware
->pxe
.pci_device
!= NULL
)
127 && (hardware
->pxe
.pci_device
== pci_device
)) {
128 add_hs(pxe
.mac_addr
);
129 add_s("pxe", "Current boot device");