• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ----------------------------------------------------------------------- *
2  *
3  *   Copyright 2009 Erwan Velu - All Rights Reserved
4  *
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:
13  *
14  *   The above copyright notice and this permission notice shall
15  *   be included in all copies or substantial portions of the Software.
16  *
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.
25  *
26  * -----------------------------------------------------------------------
27  */
28 
29 #include "hdt-menu.h"
30 
31 /* Main Kernel menu */
compute_kernel(struct s_my_menu * menu,struct s_hardware * hardware)32 void compute_kernel(struct s_my_menu *menu, struct s_hardware *hardware)
33 {
34     char buffer[SUBMENULEN + 1];
35     char infobar[STATLEN + 1];
36     char kernel_modules[LINUX_KERNEL_MODULE_SIZE *
37 			MAX_KERNEL_MODULES_PER_PCI_DEVICE];
38     struct pci_device *pci_device;
39 
40     menu->menu = add_menu(" Kernel Modules ", -1);
41     menu->items_count = 0;
42     set_menu_pos(SUBMENU_Y, SUBMENU_X);
43 
44     if ((hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP) &&
45 	(hardware->modules_alias_return_code == -ENOMODULESALIAS)) {
46 	add_item("The modules.{pcimap|alias} file is missing",
47 		 "Missing modules.{pcimap|alias} file", OPT_INACTIVE, NULL, 0);
48 	add_item("Kernel modules can't be computed.",
49 		 "Missing modules.{pcimap|alias} file", OPT_INACTIVE, NULL, 0);
50 	add_item("Please put one of them in same dir as hdt",
51 		 "Missing modules.{pcimap|alias} file", OPT_INACTIVE, NULL, 0);
52 	add_item("", "", OPT_SEP, "", 0);
53     } else {
54 	/*
55 	 * For every detected pci device, grab its kernel module to
56 	 * compute this submenu
57 	 */
58 	for_each_pci_func(pci_device, hardware->pci_domain) {
59 	    memset(kernel_modules, 0, sizeof kernel_modules);
60 	    for (int i = 0;
61 		 i < pci_device->dev_info->linux_kernel_module_count; i++) {
62 		if (i > 0) {
63 		    strncat(kernel_modules, " | ", 3);
64 		}
65 		strncat(kernel_modules,
66 			pci_device->dev_info->linux_kernel_module[i],
67 			LINUX_KERNEL_MODULE_SIZE - 1);
68 	    }
69 	    /* No need to add unknown kernel modules */
70 	    if (strlen(kernel_modules) > 0) {
71 		snprintf(buffer, sizeof buffer, "%s (%s)",
72 			 kernel_modules, pci_device->dev_info->class_name);
73 		snprintf(infobar, sizeof infobar,
74 			 "%04x:%04x %s : %s",
75 			 pci_device->vendor,
76 			 pci_device->product,
77 			 pci_device->dev_info->vendor_name,
78 			 pci_device->dev_info->product_name);
79 
80 		add_item(buffer, infobar, OPT_INACTIVE, NULL, 0);
81 		menu->items_count++;
82 	    }
83 	}
84     }
85 
86     printf("MENU: Kernel menu done (%d items)\n", menu->items_count);
87 }
88