aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErwan Velu <erwan.velu@free.fr>2009-02-22 15:49:46 +0100
committerH. Peter Anvin <hpa@zytor.com>2009-02-25 20:58:43 -0800
commitda9f8b1d5bf0246bbcad42c1c3c076f4df187200 (patch)
tree85aeea7a33436164d576ae0d411cf233f283304c
parent6738d1b2f38294c0b4dac690f3a5306007bbb531 (diff)
downloadsyslinux-elf-da9f8b1d5bf0246bbcad42c1c3c076f4df187200.tar.gz
syslinux-elf-da9f8b1d5bf0246bbcad42c1c3c076f4df187200.tar.xz
syslinux-elf-da9f8b1d5bf0246bbcad42c1c3c076f4df187200.zip
hdt: PCI: adding "show list" & "show device <%d>" DMI: Using "show list" instead of "show modules"
-rw-r--r--com32/hdt/hdt-cli-dmi.c2
-rw-r--r--com32/hdt/hdt-cli-pci.c163
-rw-r--r--com32/hdt/hdt-cli.c24
-rw-r--r--com32/hdt/hdt-cli.h24
-rw-r--r--com32/hdt/hdt.h2
5 files changed, 195 insertions, 20 deletions
diff --git a/com32/hdt/hdt-cli-dmi.c b/com32/hdt/hdt-cli-dmi.c
index cdb38abc..7b4ab75f 100644
--- a/com32/hdt/hdt-cli-dmi.c
+++ b/com32/hdt/hdt-cli-dmi.c
@@ -64,7 +64,7 @@ void dmi_show(char *item, struct s_hardware *hardware) {
show_dmi_memory_bank(hardware,item+ sizeof(CLI_DMI_MEMORY_BANK)-1);
return;
}
- if ( !strncmp(item, CLI_DMI_MODULES, sizeof(CLI_DMI_MODULES) - 1) ) {
+ if ( !strncmp(item, CLI_SHOW_LIST, sizeof(CLI_SHOW_LIST) - 1) ) {
show_dmi_modules(hardware);
return;
}
diff --git a/com32/hdt/hdt-cli-pci.c b/com32/hdt/hdt-cli-pci.c
index ae29d737..a459d71c 100644
--- a/com32/hdt/hdt-cli-pci.c
+++ b/com32/hdt/hdt-cli-pci.c
@@ -30,6 +30,167 @@
#include "hdt-common.h"
#include <stdlib.h>
#include <string.h>
+#include <errno.h>
+
+void show_pci_device(struct s_hardware *hardware, const char *item) {
+ int i=0;
+ struct pci_device *pci_device=NULL, *temp_pci_device;
+ long pcidev = strtol(item,(char **) NULL,10);
+ bool nopciids=false;
+ bool nomodulespcimap=false;
+ char kernel_modules [LINUX_KERNEL_MODULE_SIZE*MAX_KERNEL_MODULES_PER_PCI_DEVICE];
+ int bus=0,slot=0,func=0;
+
+ if (errno == ERANGE) {
+ printf("This PCI device number is incorrect\n");
+ return;
+ }
+ if ((pcidev > hardware->nb_pci_devices) || (pcidev<=0)) {
+ printf("PCI device %d doesn't exists\n",pcidev);
+ return;
+ }
+
+ if (hardware->pci_ids_return_code == -ENOPCIIDS) {
+ nopciids=true;
+ }
+
+ if (hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP) {
+ nomodulespcimap=true;
+ }
+
+ for_each_pci_func(temp_pci_device, hardware->pci_domain) {
+ i++;
+ if (i==pcidev) {
+ bus=__pci_bus;
+ slot=__pci_slot;
+ func=__pci_func;
+ pci_device=temp_pci_device;
+ }
+ }
+
+ if (pci_device == NULL) {
+ printf("We were enabled to find PCI device %d\n",pcidev);
+ return;
+ }
+
+ memset(kernel_modules,0,sizeof kernel_modules);
+ for (int kmod=0; kmod<pci_device->dev_info->linux_kernel_module_count;kmod++) {
+ if (kmod>0) {
+ strncat(kernel_modules," | ",3);
+ }
+ strncat(kernel_modules, pci_device->dev_info->linux_kernel_module[kmod],LINUX_KERNEL_MODULE_SIZE-1);
+ }
+ if (pci_device->dev_info->linux_kernel_module_count==0) strlcpy(kernel_modules,"unknown",7);
+
+ clear_screen();
+ printf("PCI Device %d\n",pcidev);
+
+ if (nopciids == false) {
+ more_printf("Vendor Name : %s\n", pci_device->dev_info->vendor_name);
+ more_printf("Product Name : %s\n", pci_device->dev_info->product_name);
+ more_printf("Class Name : %s\n", pci_device->dev_info->class_name);
+ }
+
+ if (nomodulespcimap == false) {
+ more_printf("Kernel module : %s\n", kernel_modules);
+ }
+
+ more_printf("Vendor ID : %04x\n",pci_device->vendor);
+ more_printf("Product ID : %04x\n",pci_device->product);
+ more_printf("SubVendor ID : %04x\n",pci_device->sub_vendor);
+ more_printf("SubProduct ID : %04x\n",pci_device->sub_product);
+ more_printf("Class ID : %02x.%02x.%02x\n",pci_device->class[2], pci_device->class[1],pci_device->class[0]);
+ more_printf("Revision : %02x\n",pci_device->revision);
+ more_printf("PCI Bus : %02d\n",bus);
+ more_printf("PCI Slot : %02d\n",slot);
+ more_printf("PCI Func : %02d\n",func);
+
+}
+
+void show_pci_devices(struct s_hardware *hardware) {
+ int i=1;
+ struct pci_device *pci_device;
+ char kernel_modules [LINUX_KERNEL_MODULE_SIZE*MAX_KERNEL_MODULES_PER_PCI_DEVICE];
+ bool nopciids=false;
+ bool nomodulespcimap=false;
+ char first_line[81];
+ char second_line[81];
+
+ clear_screen();
+ more_printf("%d PCI devices detected\n",hardware->nb_pci_devices);
+
+ if (hardware->pci_ids_return_code == -ENOPCIIDS) {
+ nopciids=true;
+ }
+
+ if (hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP) {
+ nomodulespcimap=true;
+ }
+
+ /* For every detected pci device, compute its submenu */
+ for_each_pci_func(pci_device, hardware->pci_domain) {
+ memset(kernel_modules,0,sizeof kernel_modules);
+ for (int kmod=0; kmod<pci_device->dev_info->linux_kernel_module_count;kmod++) {
+ if (kmod>0) {
+ strncat(kernel_modules," | ",3);
+ }
+ strncat(kernel_modules, pci_device->dev_info->linux_kernel_module[kmod],LINUX_KERNEL_MODULE_SIZE-1);
+ }
+ if (pci_device->dev_info->linux_kernel_module_count==0) strlcpy(kernel_modules,"unknown",7);
+
+ if (nopciids == false) {
+ snprintf(first_line,sizeof(first_line),"%02d: %s %s \n",
+ i,pci_device->dev_info->vendor_name,
+ pci_device->dev_info->product_name);
+ if (nomodulespcimap == false)
+ snprintf(second_line,sizeof(second_line)," # %-25s # Kmod: %s\n", pci_device->dev_info->class_name, kernel_modules);
+ else
+ snprintf(second_line,sizeof(second_line)," # %-25s # ID:%04x:%04x[%04x:%04x]\n",
+ pci_device->dev_info->class_name,
+ pci_device->vendor, pci_device->product,
+ pci_device->sub_vendor, pci_device->sub_product);
+
+ more_printf(first_line);
+ more_printf(second_line);
+ more_printf("\n");
+ } else if (nopciids == true) {
+ if (nomodulespcimap == true) {
+ more_printf("%02d: %04x:%04x [%04x:%04x] \n",
+ i, pci_device->vendor, pci_device->product,
+ pci_device->sub_vendor, pci_device->sub_product,kernel_modules);
+ }
+ else {
+ more_printf("%02d: %04x:%04x [%04x:%04x] Kmod:%s\n",
+ i,
+ pci_device->vendor, pci_device->product,
+ pci_device->sub_vendor, pci_device->sub_product,kernel_modules,
+ pci_device->sub_product,kernel_modules);
+ }
+ }
+ i++;
+ }
+
+}
+
+void pci_show(char *item, struct s_hardware *hardware) {
+ if ( !strncmp(item, CLI_SHOW_LIST, sizeof(CLI_SHOW_LIST) - 1) ) {
+ show_pci_devices(hardware);
+ return;
+ }
+ if ( !strncmp(item, CLI_PCI_DEVICE, sizeof(CLI_PCI_DEVICE) - 1) ) {
+ show_pci_device(hardware,item+ sizeof(CLI_PCI_DEVICE)-1);
+ return;
+ }
+
+}
+
+void handle_pci_commands(char *cli_line, struct s_cli_mode *cli_mode, struct s_hardware *hardware) {
+ if ( !strncmp(cli_line, CLI_SHOW, sizeof(CLI_SHOW) - 1) ) {
+ pci_show(strstr(cli_line,"show")+ sizeof(CLI_SHOW), hardware);
+ return;
+ }
+}
+
void cli_detect_pci(struct s_hardware *hardware) {
bool error=false;
@@ -55,8 +216,8 @@ void cli_detect_pci(struct s_hardware *hardware) {
void main_show_pci(struct s_hardware *hardware) {
int i=1;
- struct pci_device *pci_device;
char kernel_modules [LINUX_KERNEL_MODULE_SIZE*MAX_KERNEL_MODULES_PER_PCI_DEVICE];
+ struct pci_device *pci_device;
bool nopciids=false;
bool nomodulespcimap=false;
char first_line[81];
diff --git a/com32/hdt/hdt-cli.c b/com32/hdt/hdt-cli.c
index 7b1d489b..2071aa06 100644
--- a/com32/hdt/hdt-cli.c
+++ b/com32/hdt/hdt-cli.c
@@ -47,7 +47,7 @@ void set_mode(struct s_cli_mode *cli_mode, cli_mode_t mode, struct s_hardware *h
cli_mode->mode=mode;
snprintf(cli_mode->prompt,sizeof(cli_mode->prompt),"%s:", CLI_PCI);
if (!hardware->pci_detection)
- detect_pci(hardware);
+ cli_detect_pci(hardware);
break;
case DMI_MODE:
@@ -63,6 +63,14 @@ void set_mode(struct s_cli_mode *cli_mode, cli_mode_t mode, struct s_hardware *h
}
}
+void handle_hdt_commands(char *cli_line, struct s_cli_mode *cli_mode, struct s_hardware *hardware) {
+ /* hdt cli mode specific commands */
+ if ( !strncmp(cli_line, CLI_SHOW, sizeof(CLI_SHOW) - 1) ) {
+ main_show(strstr(cli_line,"show")+ sizeof (CLI_SHOW), hardware,cli_mode);
+ return;
+ }
+}
+
/* Code that manage the cli mode */
void start_cli_mode(int argc, char *argv[]) {
char cli_line[256];
@@ -109,15 +117,14 @@ void start_cli_mode(int argc, char *argv[]) {
set_mode(&cli_mode,DMI_MODE,&hardware);
continue;
}
+ /* All commands before that line are common for all cli modes
+ * the following will be specific for every mode */
switch(cli_mode.mode) {
case DMI_MODE: handle_dmi_commands(cli_line,&cli_mode, &hardware); break;
+ case PCI_MODE: handle_pci_commands(cli_line,&cli_mode, &hardware); break;
+ case HDT_MODE: handle_hdt_commands(cli_line,&cli_mode, &hardware); break;
+ case EXIT_MODE: break; /* should not happend */
}
-
- if ( !strncmp(cli_line, CLI_SHOW, sizeof(CLI_SHOW) - 1) ) {
- main_show(strstr(cli_line,"show")+ sizeof (CLI_SHOW), &hardware,&cli_mode);
- continue;
- }
-
}
}
@@ -126,6 +133,7 @@ int do_exit(struct s_cli_mode *cli_mode) {
case HDT_MODE: return EXIT_MODE;
case PCI_MODE: return HDT_MODE;
case DMI_MODE: return HDT_MODE;
+ case EXIT_MODE: return EXIT_MODE; /* should not happend */
}
return HDT_MODE;
}
@@ -141,6 +149,8 @@ switch (cli_mode->mode) {
case DMI_MODE:
printf("Available commands are : %s %s %s %s\n",CLI_CLEAR, CLI_EXIT, CLI_HELP, CLI_SHOW);
break;
+ case EXIT_MODE: /* Should not happend*/
+ break;
}
}
diff --git a/com32/hdt/hdt-cli.h b/com32/hdt/hdt-cli.h
index f388a99a..0c7085d7 100644
--- a/com32/hdt/hdt-cli.h
+++ b/com32/hdt/hdt-cli.h
@@ -39,15 +39,7 @@
#define CLI_PCI "pci"
#define CLI_COMMANDS "commands"
#define CLI_DMI "dmi"
-#define CLI_DMI_BASE_BOARD "base_board"
-#define CLI_DMI_BATTERY "battery"
-#define CLI_DMI_BIOS "bios"
-#define CLI_DMI_CHASSIS "chassis"
-#define CLI_DMI_MEMORY "memory"
-#define CLI_DMI_MEMORY_BANK "bank"
-#define CLI_DMI_PROCESSOR "processor"
-#define CLI_DMI_SYSTEM "system"
-#define CLI_DMI_MODULES "modules"
+#define CLI_SHOW_LIST "list"
typedef enum {
EXIT_MODE,
@@ -68,6 +60,15 @@ void main_show(char *item, struct s_hardware *hardware, struct s_cli_mode *cli_m
int do_exit(struct s_cli_mode *cli_mode);
//DMI STUFF
+#define CLI_DMI_BASE_BOARD "base_board"
+#define CLI_DMI_BATTERY "battery"
+#define CLI_DMI_BIOS "bios"
+#define CLI_DMI_CHASSIS "chassis"
+#define CLI_DMI_MEMORY "memory"
+#define CLI_DMI_MEMORY_BANK "bank"
+#define CLI_DMI_PROCESSOR "processor"
+#define CLI_DMI_SYSTEM "system"
+
void main_show_dmi(struct s_hardware *hardware,struct s_cli_mode *cli_mode);
void handle_dmi_commands(char *cli_line, struct s_cli_mode *cli_mode, struct s_hardware *hardware);
void show_dmi_base_board(struct s_hardware *hardware);
@@ -81,6 +82,9 @@ void show_dmi_memory_bank(struct s_hardware *hardware, const char *item);
void show_dmi_battery(struct s_hardware *hardware);
//PCI STUFF
+#define CLI_PCI_DEVICE "device"
void main_show_pci(struct s_hardware *hardware);
-
+void handle_pci_commands(char *cli_line, struct s_cli_mode *cli_mode, struct s_hardware *hardware);
+void pci_show(char *item, struct s_hardware *hardware);
+void cli_detect_pci(struct s_hardware *hardware);
#endif
diff --git a/com32/hdt/hdt.h b/com32/hdt/hdt.h
index 444d2a73..93b2cbbb 100644
--- a/com32/hdt/hdt.h
+++ b/com32/hdt/hdt.h
@@ -32,7 +32,7 @@
#define PRODUCT_NAME "Hardware Detection Tool"
#define AUTHOR "Erwan Velu"
#define CONTACT "erwan(dot)velu(point)free(dot)fr"
-#define VERSION "0.1.7"
+#define VERSION "0.1.8"
#define ATTR_PACKED __attribute__((packed))