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 * -----------------------------------------------------------------------
35 #include "hdt-common.h"
37 void main_show_kernel(int argc __unused
, char **argv __unused
,
38 struct s_hardware
*hardware
)
40 char buffer
[1024] = {0};
41 struct pci_device
*pci_device
;
43 char kernel_modules
[LINUX_KERNEL_MODULE_SIZE
*
44 MAX_KERNEL_MODULES_PER_PCI_DEVICE
];
48 more_printf("Kernel modules\n");
50 // more_printf(" PCI device no: %d \n", p->pci_device_pos);
52 if ((hardware
->modules_pcimap_return_code
== -ENOMODULESPCIMAP
)
53 && (hardware
->modules_alias_return_code
== -ENOMODULESALIAS
)) {
54 more_printf(" modules.pcimap and modules.alias files are missing\n");
58 /* For every detected pci device, compute its submenu */
59 for_each_pci_func(pci_device
, hardware
->pci_domain
) {
60 memset(kernel_modules
, 0, sizeof kernel_modules
);
63 kmod
< pci_device
->dev_info
->linux_kernel_module_count
; kmod
++) {
65 strncat(kernel_modules
, " | ", 3);
67 strncat(kernel_modules
,
68 pci_device
->dev_info
->linux_kernel_module
[kmod
],
69 LINUX_KERNEL_MODULE_SIZE
- 1);
72 if ((pci_device
->dev_info
->linux_kernel_module_count
> 0)
73 && (!strstr(buffer
, kernel_modules
))) {
75 if (pci_device
->dev_info
->linux_kernel_module_count
> 1)
76 strncat(buffer
, "(", 1);
77 strncat(buffer
, kernel_modules
, sizeof(kernel_modules
));
78 if (pci_device
->dev_info
->linux_kernel_module_count
> 1)
79 strncat(buffer
, ")", 1);
80 strncat(buffer
, " # ", 3);
85 strncat(buffer
, "\n", 1);
90 static void show_kernel_modules(int argc __unused
, char **argv __unused
,
91 struct s_hardware
*hardware
)
93 struct pci_device
*pci_device
;
94 char kernel_modules
[LINUX_KERNEL_MODULE_SIZE
*
95 MAX_KERNEL_MODULES_PER_PCI_DEVICE
];
96 bool nopciids
= false;
97 bool nomodulespcimap
= false;
98 char modules
[MAX_PCI_CLASSES
][256] = {{0}};
99 char category_name
[MAX_PCI_CLASSES
][256] = {{0}};
101 detect_pci(hardware
);
103 if (hardware
->pci_ids_return_code
== -ENOPCIIDS
) {
105 more_printf(" Missing pci.ids, we can't compute the list\n");
109 if (hardware
->modules_pcimap_return_code
== -ENOMODULESPCIMAP
) {
110 nomodulespcimap
= true;
111 more_printf(" Missing modules.pcimap, we can't compute the list\n");
116 for_each_pci_func(pci_device
, hardware
->pci_domain
) {
117 memset(kernel_modules
, 0, sizeof kernel_modules
);
120 kmod
< pci_device
->dev_info
->linux_kernel_module_count
; kmod
++) {
121 strncat(kernel_modules
,
122 pci_device
->dev_info
->linux_kernel_module
[kmod
],
123 LINUX_KERNEL_MODULE_SIZE
- 1);
124 strncat(kernel_modules
, " ", 1);
127 if ((pci_device
->dev_info
->linux_kernel_module_count
> 0)
128 && (!strstr(modules
[pci_device
->class[2]], kernel_modules
))) {
129 strncat(modules
[pci_device
->class[2]], kernel_modules
,
130 sizeof(kernel_modules
));
131 snprintf(category_name
[pci_device
->class[2]],
132 sizeof(category_name
[pci_device
->class[2]]),
133 "%s", pci_device
->dev_info
->category_name
);
136 /* Print the found items */
137 for (int i
= 0; i
< MAX_PCI_CLASSES
; i
++) {
138 if (strlen(category_name
[i
]) > 1) {
139 more_printf("%s : %s\n", category_name
[i
], modules
[i
]);
144 struct cli_module_descr kernel_show_modules
= {
146 .default_callback
= show_kernel_modules
,
149 struct cli_mode_descr kernel_mode
= {
152 .default_modules
= NULL
,
153 .show_modules
= &kernel_show_modules
,