Adding upstream version 4.00~pre55+dfsg.
[syslinux-debian/hramrach.git] / com32 / hdt / hdt-cli-kernel.c
blobd4946f30389887737f4c6e9e791266470749b1b7
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
12 * conditions:
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 <stdio.h>
30 #include <string.h>
31 #include <stdlib.h>
32 #include <errno.h>
34 #include "hdt-cli.h"
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;
42 bool found = false;
43 char kernel_modules[LINUX_KERNEL_MODULE_SIZE *
44 MAX_KERNEL_MODULES_PER_PCI_DEVICE];
46 detect_pci(hardware);
47 reset_more_printf();
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");
55 return;
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);
62 for (int kmod = 0;
63 kmod < pci_device->dev_info->linux_kernel_module_count; kmod++) {
64 if (kmod > 0) {
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))) {
74 found = true;
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);
84 if (found == true) {
85 strncat(buffer, "\n", 1);
86 more_printf(buffer);
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) {
104 nopciids = true;
105 more_printf(" Missing pci.ids, we can't compute the list\n");
106 return;
109 if (hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP) {
110 nomodulespcimap = true;
111 more_printf(" Missing modules.pcimap, we can't compute the list\n");
112 return;
115 reset_more_printf();
116 for_each_pci_func(pci_device, hardware->pci_domain) {
117 memset(kernel_modules, 0, sizeof kernel_modules);
119 for (int kmod = 0;
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 = {
145 .modules = NULL,
146 .default_callback = show_kernel_modules,
149 struct cli_mode_descr kernel_mode = {
150 .mode = KERNEL_MODE,
151 .name = CLI_KERNEL,
152 .default_modules = NULL,
153 .show_modules = &kernel_show_modules,
154 .set_modules = NULL,