From 16e8768b804e8468563349f892ed99e28cbd295c Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Tue, 10 Feb 2009 21:08:24 +0100 Subject: hdt: Adding get_class_name_from_pci_ids to grab class name from the pciids --- com32/lib/pci/scan.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) (limited to 'com32/lib/pci') diff --git a/com32/lib/pci/scan.c b/com32/lib/pci/scan.c index 98df0dd3..b7bba80e 100644 --- a/com32/lib/pci/scan.c +++ b/com32/lib/pci/scan.c @@ -150,6 +150,92 @@ int get_module_name_from_pci_ids(struct pci_domain *domain) return 0; } +/* Try to match any pci device to the appropriate class name */ +/* it uses the pci.ids from the boot device */ +int get_class_name_from_pci_ids(struct pci_domain *domain) +{ + char line[MAX_LINE]; + char class_name[255]; + char sub_class_name[255]; + char class_id_str[5]; + char sub_class_id_str[5]; + FILE *f; + struct pci_device *dev; + bool class_mode=false; + + /* Intializing the vendor/product name for each pci device to "unknown" */ + /* adding a dev_info member if needed */ + for_each_pci_func(dev, domain) { + /* initialize the dev_info structure if it doesn't exist yet. */ + if (! dev->dev_info) { + dev->dev_info = zalloc(sizeof *dev->dev_info); + if (!dev->dev_info) + return -1; + } + strcpy(dev->dev_info->class_name,"unknown"); + } + + /* Opening the pci.ids from the boot device */ + f = fopen("pci.ids","r"); + if (!f) + return -1; + + strcpy(class_name,"unknown"); + + /* for each line we found in the pci.ids */ + while ( fgets(line, sizeof line, f) ) { + /* Skipping uncessary lines */ + if ((line[0] == '#') || (line[0] == ' ') || + (line[0] == 10)) + continue; + + /* Until we found a line starting with a 'C', we are not parsing classes */ + if (line[0] == 'C') + class_mode=true; + if (class_mode == false) + continue; + + /* If the line doesn't start with a tab, it means that's a class name */ + if (line[0] != '\t') { + + /* ignore the two first char and then copy 2 chars (class id)*/ + strlcpy(class_id_str,&line[2],2); + class_id_str[2]=0; + + /* the class name is the next field */ + strlcpy(class_name,skipspace(strstr(line," ")),255); + remove_eol(class_name); + + /* assign the class_name to any matching pci device */ + for_each_pci_func(dev, domain) { + if (hex_to_int(class_id_str) == dev->class[2]) + strlcpy(dev->dev_info->class_name,class_name,255); + } + /* if we have a tab + a char, it means this is a sub class name */ + } else if ((line[0] == '\t') && (line[1] != '\t')) { + + /* the sub class name the second field */ + strlcpy(sub_class_name,skipspace(strstr(line," ")),255); + remove_eol(sub_class_name); + + /* the sub class id is first field */ + strlcpy(sub_class_id_str,&line[1],2); + sub_class_id_str[2]=0; + + /* assign the product_name to any matching pci device */ + for_each_pci_func(dev, domain) { + if (hex_to_int(class_id_str) == dev->class[2] && + hex_to_int(sub_class_id_str) == dev->class[1]) + strlcpy(dev->dev_info->class_name,sub_class_name,255); + } + + } + } + fclose(f); + return 0; +} + + /* Try to match any pci device to the appropriate vendor and product name */ /* it uses the pci.ids from the boot device */ int get_name_from_pci_ids(struct pci_domain *domain) @@ -193,6 +279,7 @@ int get_name_from_pci_ids(struct pci_domain *domain) if ((line[0] == '#') || (line[0] == ' ') || (line[0] == 'C') || (line[0] == 10)) continue; + /* If the line doesn't start with a tab, it means that's a vendor id */ if (line[0] != '\t') { -- cgit From 0e7c4726848368d36026ca418c6c8ec77107925c Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Wed, 11 Feb 2009 23:21:46 +0100 Subject: hdt: Performance optimisations : avoiding hex_to_int in pci_domain loops --- com32/lib/pci/scan.c | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) (limited to 'com32/lib/pci') diff --git a/com32/lib/pci/scan.c b/com32/lib/pci/scan.c index b7bba80e..dea29481 100644 --- a/com32/lib/pci/scan.c +++ b/com32/lib/pci/scan.c @@ -134,14 +134,18 @@ int get_module_name_from_pci_ids(struct pci_domain *domain) /* Searching the next field */ result = strtok( NULL, delims ); } + int int_vendor_id=hex_to_int(vendor_id); + int int_sub_vendor_id=hex_to_int(sub_vendor_id); + int int_product_id=hex_to_int(product_id); + int int_sub_product_id=hex_to_int(sub_product_id); /* if a pci_device matches an entry, fill the linux_kernel_module with the appropriate kernel module */ for_each_pci_func(dev, domain) { - if (hex_to_int(vendor_id) == dev->vendor && - hex_to_int(product_id) == dev->product && - (hex_to_int(sub_product_id) & dev->sub_product) + if (int_vendor_id == dev->vendor && + int_product_id == dev->product && + (int_sub_product_id & dev->sub_product) == dev->sub_product && - (hex_to_int(sub_vendor_id) & dev->sub_vendor) + (int_sub_vendor_id & dev->sub_vendor) == dev->sub_vendor) strcpy(dev->dev_info->linux_kernel_module, module_name); } @@ -206,9 +210,10 @@ int get_class_name_from_pci_ids(struct pci_domain *domain) strlcpy(class_name,skipspace(strstr(line," ")),255); remove_eol(class_name); + int int_class_id_str=hex_to_int(class_id_str); /* assign the class_name to any matching pci device */ for_each_pci_func(dev, domain) { - if (hex_to_int(class_id_str) == dev->class[2]) + if (int_class_id_str == dev->class[2]) strlcpy(dev->dev_info->class_name,class_name,255); } /* if we have a tab + a char, it means this is a sub class name */ @@ -222,10 +227,12 @@ int get_class_name_from_pci_ids(struct pci_domain *domain) strlcpy(sub_class_id_str,&line[1],2); sub_class_id_str[2]=0; + int int_class_id_str=hex_to_int(class_id_str); + int int_sub_class_id_str=hex_to_int(sub_class_id_str); /* assign the product_name to any matching pci device */ for_each_pci_func(dev, domain) { - if (hex_to_int(class_id_str) == dev->class[2] && - hex_to_int(sub_class_id_str) == dev->class[1]) + if (int_class_id_str == dev->class[2] && + int_sub_class_id_str == dev->class[1]) strlcpy(dev->dev_info->class_name,sub_class_name,255); } @@ -298,9 +305,11 @@ int get_name_from_pci_ids(struct pci_domain *domain) /* ffff is an invalid vendor id */ if (strstr(vendor_id,"ffff")) break; + + int int_vendor_id=hex_to_int(vendor_id); /* assign the vendor_name to any matching pci device */ for_each_pci_func(dev, domain) { - if (hex_to_int(vendor_id) == dev->vendor) + if (int_vendor_id == dev->vendor) strlcpy(dev->dev_info->vendor_name,vendor,255); } /* if we have a tab + a char, it means this is a product id */ @@ -318,10 +327,12 @@ int get_name_from_pci_ids(struct pci_domain *domain) strcpy(sub_product_id,"0000"); strcpy(sub_vendor_id,"0000"); + int int_vendor_id=hex_to_int(vendor_id); + int int_product_id=hex_to_int(product_id); /* assign the product_name to any matching pci device */ for_each_pci_func(dev, domain) { - if (hex_to_int(vendor_id) == dev->vendor && - hex_to_int(product_id) == dev->product) + if (int_vendor_id == dev->vendor && + int_product_id == dev->product) strlcpy(dev->dev_info->product_name,product,255); } @@ -341,12 +352,16 @@ int get_name_from_pci_ids(struct pci_domain *domain) strlcpy(sub_product_id,&line[7],4); sub_product_id[4]=0; + int int_vendor_id=hex_to_int(vendor_id); + int int_sub_vendor_id=hex_to_int(sub_vendor_id); + int int_product_id=hex_to_int(product_id); + int int_sub_product_id=hex_to_int(sub_product_id); /* assign the product_name to any matching pci device */ for_each_pci_func(dev, domain) { - if (hex_to_int(vendor_id) == dev->vendor && - hex_to_int(product_id) == dev->product && - hex_to_int(sub_product_id) == dev->sub_product && - hex_to_int(sub_vendor_id) == dev->sub_vendor) + if (int_vendor_id == dev->vendor && + int_product_id == dev->product && + int_sub_product_id == dev->sub_product && + int_sub_vendor_id == dev->sub_vendor) strlcpy(dev->dev_info->product_name,product,255); } } -- cgit From 410df54dde8dca29f58ce99a2147a3722b2c7d76 Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Thu, 12 Feb 2009 20:50:35 +0100 Subject: hdt: No need to only copy vendor name --- com32/lib/pci/scan.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'com32/lib/pci') diff --git a/com32/lib/pci/scan.c b/com32/lib/pci/scan.c index dea29481..7d11399d 100644 --- a/com32/lib/pci/scan.c +++ b/com32/lib/pci/scan.c @@ -306,12 +306,6 @@ int get_name_from_pci_ids(struct pci_domain *domain) /* ffff is an invalid vendor id */ if (strstr(vendor_id,"ffff")) break; - int int_vendor_id=hex_to_int(vendor_id); - /* assign the vendor_name to any matching pci device */ - for_each_pci_func(dev, domain) { - if (int_vendor_id == dev->vendor) - strlcpy(dev->dev_info->vendor_name,vendor,255); - } /* if we have a tab + a char, it means this is a product id */ } else if ((line[0] == '\t') && (line[1] != '\t')) { @@ -332,8 +326,10 @@ int get_name_from_pci_ids(struct pci_domain *domain) /* assign the product_name to any matching pci device */ for_each_pci_func(dev, domain) { if (int_vendor_id == dev->vendor && - int_product_id == dev->product) + int_product_id == dev->product) { + strlcpy(dev->dev_info->vendor_name,vendor,255); strlcpy(dev->dev_info->product_name,product,255); + } } /* if we have two tabs, it means this is a sub product */ @@ -361,8 +357,10 @@ int get_name_from_pci_ids(struct pci_domain *domain) if (int_vendor_id == dev->vendor && int_product_id == dev->product && int_sub_product_id == dev->sub_product && - int_sub_vendor_id == dev->sub_vendor) + int_sub_vendor_id == dev->sub_vendor) { + strlcpy(dev->dev_info->vendor_name,vendor,255); strlcpy(dev->dev_info->product_name,product,255); + } } } } -- cgit From 04d969ce4d548d3ae4fb2dbce68caa3923153bf8 Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Thu, 12 Feb 2009 21:04:18 +0100 Subject: hdt: Improving detection speed by skipping uncessary lines --- com32/lib/pci/scan.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'com32/lib/pci') diff --git a/com32/lib/pci/scan.c b/com32/lib/pci/scan.c index 7d11399d..06302853 100644 --- a/com32/lib/pci/scan.c +++ b/com32/lib/pci/scan.c @@ -256,6 +256,7 @@ int get_name_from_pci_ids(struct pci_domain *domain) char sub_vendor_id[5]; FILE *f; struct pci_device *dev; + bool skip_to_next_vendor=false; /* Intializing the vendor/product name for each pci device to "unknown" */ /* adding a dev_info member if needed */ @@ -306,9 +307,19 @@ int get_name_from_pci_ids(struct pci_domain *domain) /* ffff is an invalid vendor id */ if (strstr(vendor_id,"ffff")) break; + skip_to_next_vendor=true; + int int_vendor_id=hex_to_int(vendor_id); + for_each_pci_func(dev, domain) { + if (int_vendor_id == dev->vendor) { + skip_to_next_vendor=false; + continue; + } + } /* if we have a tab + a char, it means this is a product id */ } else if ((line[0] == '\t') && (line[1] != '\t')) { + if (skip_to_next_vendor == true) continue; + /* the product name the second field */ strlcpy(product,skipspace(strstr(line," ")),255); remove_eol(product); @@ -335,6 +346,8 @@ int get_name_from_pci_ids(struct pci_domain *domain) /* if we have two tabs, it means this is a sub product */ } else if ((line[0] == '\t') && (line[1] == '\t')) { + if (skip_to_next_vendor == true) continue; + /* the product name is last field */ strlcpy(product,skipspace(strstr(line," ")),255); strlcpy(product,skipspace(strstr(product," ")),255); -- cgit From 7af19ef0ba14d1d631bd2dd124f13226396ccf33 Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Fri, 13 Feb 2009 13:13:22 +0100 Subject: hdt: Improving performances by not computing product ids when the vendor doesn't exist on the local system. Removing useless break() that prevent other com32 module to load --- com32/lib/pci/scan.c | 55 ++++++++++++++++++++++++---------------------------- 1 file changed, 25 insertions(+), 30 deletions(-) (limited to 'com32/lib/pci') diff --git a/com32/lib/pci/scan.c b/com32/lib/pci/scan.c index 06302853..c2c72146 100644 --- a/com32/lib/pci/scan.c +++ b/com32/lib/pci/scan.c @@ -184,8 +184,6 @@ int get_class_name_from_pci_ids(struct pci_domain *domain) if (!f) return -1; - strcpy(class_name,"unknown"); - /* for each line we found in the pci.ids */ while ( fgets(line, sizeof line, f) ) { /* Skipping uncessary lines */ @@ -198,7 +196,7 @@ int get_class_name_from_pci_ids(struct pci_domain *domain) class_mode=true; if (class_mode == false) continue; - + strncpy(class_name,"unknown",7); /* If the line doesn't start with a tab, it means that's a class name */ if (line[0] != '\t') { @@ -257,6 +255,10 @@ int get_name_from_pci_ids(struct pci_domain *domain) FILE *f; struct pci_device *dev; bool skip_to_next_vendor=false; + uint16_t int_vendor_id; + uint16_t int_product_id; + uint16_t int_sub_product_id; + uint16_t int_sub_vendor_id; /* Intializing the vendor/product name for each pci device to "unknown" */ /* adding a dev_info member if needed */ @@ -267,8 +269,8 @@ int get_name_from_pci_ids(struct pci_domain *domain) if (!dev->dev_info) return -1; } - strcpy(dev->dev_info->vendor_name,"unknown"); - strcpy(dev->dev_info->product_name,"unknown"); + strlcpy(dev->dev_info->vendor_name,"unknown",7); + strlcpy(dev->dev_info->product_name,"unknown",7); } /* Opening the pci.ids from the boot device */ @@ -276,10 +278,10 @@ int get_name_from_pci_ids(struct pci_domain *domain) if (!f) return -1; - strcpy(vendor_id,"0000"); - strcpy(product_id,"0000"); - strcpy(sub_product_id,"0000"); - strcpy(sub_vendor_id,"0000"); + strlcpy(vendor_id,"0000",4); + strlcpy(product_id,"0000",4); + strlcpy(sub_product_id,"0000",4); + strlcpy(sub_vendor_id,"0000",4); /* for each line we found in the pci.ids */ while ( fgets(line, sizeof line, f) ) { @@ -300,15 +302,12 @@ int get_name_from_pci_ids(struct pci_domain *domain) remove_eol(vendor); /* init product_id, sub_product and sub_vendor */ - strcpy(product_id,"0000"); - strcpy(sub_product_id,"0000"); - strcpy(sub_vendor_id,"0000"); - - /* ffff is an invalid vendor id */ - if (strstr(vendor_id,"ffff")) break; + strlcpy(product_id,"0000",4); + strlcpy(sub_product_id,"0000",4); + strlcpy(sub_vendor_id,"0000",4); skip_to_next_vendor=true; - int int_vendor_id=hex_to_int(vendor_id); + int_vendor_id=hex_to_int(vendor_id); for_each_pci_func(dev, domain) { if (int_vendor_id == dev->vendor) { skip_to_next_vendor=false; @@ -316,9 +315,7 @@ int get_name_from_pci_ids(struct pci_domain *domain) } } /* if we have a tab + a char, it means this is a product id */ - } else if ((line[0] == '\t') && (line[1] != '\t')) { - - if (skip_to_next_vendor == true) continue; + } else if ((line[0] == '\t') && (line[1] != '\t') && (skip_to_next_vendor == false)) { /* the product name the second field */ strlcpy(product,skipspace(strstr(line," ")),255); @@ -329,11 +326,11 @@ int get_name_from_pci_ids(struct pci_domain *domain) product_id[4]=0; /* init sub_product and sub_vendor */ - strcpy(sub_product_id,"0000"); - strcpy(sub_vendor_id,"0000"); + strlcpy(sub_product_id,"0000",4); + strlcpy(sub_vendor_id,"0000",4); - int int_vendor_id=hex_to_int(vendor_id); - int int_product_id=hex_to_int(product_id); + int_vendor_id=hex_to_int(vendor_id); + int_product_id=hex_to_int(product_id); /* assign the product_name to any matching pci device */ for_each_pci_func(dev, domain) { if (int_vendor_id == dev->vendor && @@ -344,9 +341,7 @@ int get_name_from_pci_ids(struct pci_domain *domain) } /* if we have two tabs, it means this is a sub product */ - } else if ((line[0] == '\t') && (line[1] == '\t')) { - - if (skip_to_next_vendor == true) continue; + } else if ((line[0] == '\t') && (line[1] == '\t') && (skip_to_next_vendor == false)) { /* the product name is last field */ strlcpy(product,skipspace(strstr(line," ")),255); @@ -361,10 +356,10 @@ int get_name_from_pci_ids(struct pci_domain *domain) strlcpy(sub_product_id,&line[7],4); sub_product_id[4]=0; - int int_vendor_id=hex_to_int(vendor_id); - int int_sub_vendor_id=hex_to_int(sub_vendor_id); - int int_product_id=hex_to_int(product_id); - int int_sub_product_id=hex_to_int(sub_product_id); + int_vendor_id=hex_to_int(vendor_id); + int_sub_vendor_id=hex_to_int(sub_vendor_id); + int_product_id=hex_to_int(product_id); + int_sub_product_id=hex_to_int(sub_product_id); /* assign the product_name to any matching pci device */ for_each_pci_func(dev, domain) { if (int_vendor_id == dev->vendor && -- cgit From 5209894429f09bba73a6545d1d495fc9279a7147 Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Mon, 16 Feb 2009 11:17:28 +0100 Subject: hdt: Returning ENOPCIIDS and ENOMODULESPCIMAP when pci.ids and modules.pcidmap files are missing --- com32/lib/pci/scan.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'com32/lib/pci') diff --git a/com32/lib/pci/scan.c b/com32/lib/pci/scan.c index c2c72146..c1345b8e 100644 --- a/com32/lib/pci/scan.c +++ b/com32/lib/pci/scan.c @@ -100,7 +100,7 @@ int get_module_name_from_pci_ids(struct pci_domain *domain) /* Opening the modules.pcimap (of a linux kernel) from the boot device */ f=fopen("modules.pcimap", "r"); if (!f) - return -1; + return -ENOMODULESPCIMAP; strcpy(vendor_id,"0000"); strcpy(product_id,"0000"); @@ -182,7 +182,7 @@ int get_class_name_from_pci_ids(struct pci_domain *domain) /* Opening the pci.ids from the boot device */ f = fopen("pci.ids","r"); if (!f) - return -1; + return -ENOPCIIDS; /* for each line we found in the pci.ids */ while ( fgets(line, sizeof line, f) ) { @@ -276,7 +276,7 @@ int get_name_from_pci_ids(struct pci_domain *domain) /* Opening the pci.ids from the boot device */ f = fopen("pci.ids","r"); if (!f) - return -1; + return -ENOPCIIDS; strlcpy(vendor_id,"0000",4); strlcpy(product_id,"0000",4); -- cgit From 0f106fd324fd22e42fbc6ded1b088ec982d4933f Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Mon, 16 Feb 2009 13:11:42 +0100 Subject: hdt: Adding more defined values for pci components Enabling mulitple kernel modules per pci device Updating pcitest --- com32/lib/pci/scan.c | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) (limited to 'com32/lib/pci') diff --git a/com32/lib/pci/scan.c b/com32/lib/pci/scan.c index c1345b8e..54b5f54e 100644 --- a/com32/lib/pci/scan.c +++ b/com32/lib/pci/scan.c @@ -94,7 +94,9 @@ int get_module_name_from_pci_ids(struct pci_domain *domain) if (!dev->dev_info) return -1; } - strcpy(dev->dev_info->linux_kernel_module, "unknown"); + for (int i=0;idev_info->linux_kernel_module[i], "unknown",7); + } } /* Opening the modules.pcimap (of a linux kernel) from the boot device */ @@ -106,6 +108,7 @@ int get_module_name_from_pci_ids(struct pci_domain *domain) strcpy(product_id,"0000"); strcpy(sub_product_id,"0000"); strcpy(sub_vendor_id,"0000"); + dev->dev_info->linux_kernel_module_count=0; /* for each line we found in the modules.pcimap */ while ( fgets(line, sizeof line, f) ) { @@ -146,8 +149,10 @@ int get_module_name_from_pci_ids(struct pci_domain *domain) (int_sub_product_id & dev->sub_product) == dev->sub_product && (int_sub_vendor_id & dev->sub_vendor) - == dev->sub_vendor) - strcpy(dev->dev_info->linux_kernel_module, module_name); + == dev->sub_vendor) { + strcpy(dev->dev_info->linux_kernel_module[dev->dev_info->linux_kernel_module_count], module_name); + dev->dev_info->linux_kernel_module_count++; + } } } fclose(f); @@ -159,8 +164,8 @@ int get_module_name_from_pci_ids(struct pci_domain *domain) int get_class_name_from_pci_ids(struct pci_domain *domain) { char line[MAX_LINE]; - char class_name[255]; - char sub_class_name[255]; + char class_name[PCI_CLASS_NAME_SIZE]; + char sub_class_name[PCI_CLASS_NAME_SIZE]; char class_id_str[5]; char sub_class_id_str[5]; FILE *f; @@ -176,7 +181,7 @@ int get_class_name_from_pci_ids(struct pci_domain *domain) if (!dev->dev_info) return -1; } - strcpy(dev->dev_info->class_name,"unknown"); + strlcpy(dev->dev_info->class_name,"unknown",7); } /* Opening the pci.ids from the boot device */ @@ -196,7 +201,7 @@ int get_class_name_from_pci_ids(struct pci_domain *domain) class_mode=true; if (class_mode == false) continue; - strncpy(class_name,"unknown",7); + strlcpy(class_name,"unknown",7); /* If the line doesn't start with a tab, it means that's a class name */ if (line[0] != '\t') { @@ -205,20 +210,20 @@ int get_class_name_from_pci_ids(struct pci_domain *domain) class_id_str[2]=0; /* the class name is the next field */ - strlcpy(class_name,skipspace(strstr(line," ")),255); + strlcpy(class_name,skipspace(strstr(line," ")),PCI_CLASS_NAME_SIZE-1); remove_eol(class_name); int int_class_id_str=hex_to_int(class_id_str); /* assign the class_name to any matching pci device */ for_each_pci_func(dev, domain) { if (int_class_id_str == dev->class[2]) - strlcpy(dev->dev_info->class_name,class_name,255); + strlcpy(dev->dev_info->class_name,class_name,PCI_CLASS_NAME_SIZE-1); } /* if we have a tab + a char, it means this is a sub class name */ } else if ((line[0] == '\t') && (line[1] != '\t')) { /* the sub class name the second field */ - strlcpy(sub_class_name,skipspace(strstr(line," ")),255); + strlcpy(sub_class_name,skipspace(strstr(line," ")),PCI_CLASS_NAME_SIZE-1); remove_eol(sub_class_name); /* the sub class id is first field */ @@ -231,7 +236,7 @@ int get_class_name_from_pci_ids(struct pci_domain *domain) for_each_pci_func(dev, domain) { if (int_class_id_str == dev->class[2] && int_sub_class_id_str == dev->class[1]) - strlcpy(dev->dev_info->class_name,sub_class_name,255); + strlcpy(dev->dev_info->class_name,sub_class_name,PCI_CLASS_NAME_SIZE-1); } } @@ -246,9 +251,9 @@ int get_class_name_from_pci_ids(struct pci_domain *domain) int get_name_from_pci_ids(struct pci_domain *domain) { char line[MAX_LINE]; - char vendor[255]; + char vendor[PCI_VENDOR_NAME_SIZE]; char vendor_id[5]; - char product[255]; + char product[PCI_PRODUCT_NAME_SIZE]; char product_id[5]; char sub_product_id[5]; char sub_vendor_id[5]; @@ -298,7 +303,7 @@ int get_name_from_pci_ids(struct pci_domain *domain) /* the vendor name is the next field */ vendor_id[4]=0; - strlcpy(vendor,skipspace(strstr(line," ")),255); + strlcpy(vendor,skipspace(strstr(line," ")),PCI_VENDOR_NAME_SIZE-1); remove_eol(vendor); /* init product_id, sub_product and sub_vendor */ @@ -318,7 +323,7 @@ int get_name_from_pci_ids(struct pci_domain *domain) } else if ((line[0] == '\t') && (line[1] != '\t') && (skip_to_next_vendor == false)) { /* the product name the second field */ - strlcpy(product,skipspace(strstr(line," ")),255); + strlcpy(product,skipspace(strstr(line," ")),PCI_PRODUCT_NAME_SIZE-1); remove_eol(product); /* the product id is first field */ @@ -335,8 +340,8 @@ int get_name_from_pci_ids(struct pci_domain *domain) for_each_pci_func(dev, domain) { if (int_vendor_id == dev->vendor && int_product_id == dev->product) { - strlcpy(dev->dev_info->vendor_name,vendor,255); - strlcpy(dev->dev_info->product_name,product,255); + strlcpy(dev->dev_info->vendor_name,vendor,PCI_VENDOR_NAME_SIZE-1); + strlcpy(dev->dev_info->product_name,product,PCI_PRODUCT_NAME_SIZE-1); } } @@ -344,8 +349,8 @@ int get_name_from_pci_ids(struct pci_domain *domain) } else if ((line[0] == '\t') && (line[1] == '\t') && (skip_to_next_vendor == false)) { /* the product name is last field */ - strlcpy(product,skipspace(strstr(line," ")),255); - strlcpy(product,skipspace(strstr(product," ")),255); + strlcpy(product,skipspace(strstr(line," ")),PCI_PRODUCT_NAME_SIZE-1); + strlcpy(product,skipspace(strstr(product," ")),PCI_PRODUCT_NAME_SIZE-1); remove_eol(product); /* the sub_vendor id is first field */ @@ -366,8 +371,8 @@ int get_name_from_pci_ids(struct pci_domain *domain) int_product_id == dev->product && int_sub_product_id == dev->sub_product && int_sub_vendor_id == dev->sub_vendor) { - strlcpy(dev->dev_info->vendor_name,vendor,255); - strlcpy(dev->dev_info->product_name,product,255); + strlcpy(dev->dev_info->vendor_name,vendor,PCI_VENDOR_NAME_SIZE-1); + strlcpy(dev->dev_info->product_name,product,PCI_PRODUCT_NAME_SIZE-1); } } } -- cgit From a9c2e1645ebeb5d369d10aca48754dfefeb375ec Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Mon, 16 Feb 2009 16:41:57 +0100 Subject: hdt: We have to iterate & copy the vendor name to all matching pci devices as all pci devices might not have a matching vendor/product id. This will help us having the proper vendor device with an unknown product. --- com32/lib/pci/scan.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'com32/lib/pci') diff --git a/com32/lib/pci/scan.c b/com32/lib/pci/scan.c index 54b5f54e..d7c189f8 100644 --- a/com32/lib/pci/scan.c +++ b/com32/lib/pci/scan.c @@ -311,15 +311,23 @@ int get_name_from_pci_ids(struct pci_domain *domain) strlcpy(sub_product_id,"0000",4); strlcpy(sub_vendor_id,"0000",4); + /* Unless we found a matching device, we have to skip to the next vendor */ skip_to_next_vendor=true; + int_vendor_id=hex_to_int(vendor_id); + /* Iterate in all pci devices to find a matching vendor */ for_each_pci_func(dev, domain) { + /* if one device that match this vendor */ if (int_vendor_id == dev->vendor) { - skip_to_next_vendor=false; - continue; + /* copy the vendor name for this device */ + strlcpy(dev->dev_info->vendor_name,vendor,PCI_VENDOR_NAME_SIZE-1); + /* Some pci devices match this vendor, so we have to found them */ + skip_to_next_vendor=false; + /* Let's loop on the other devices as some may have the same vendor */ } } - /* if we have a tab + a char, it means this is a product id */ + /* if we have a tab + a char, it means this is a product id + * but we only look at it if we own some pci devices of the current vendor*/ } else if ((line[0] == '\t') && (line[1] != '\t') && (skip_to_next_vendor == false)) { /* the product name the second field */ @@ -345,7 +353,8 @@ int get_name_from_pci_ids(struct pci_domain *domain) } } - /* if we have two tabs, it means this is a sub product */ + /* if we have two tabs, it means this is a sub product + * but we only look at it if we own some pci devices of the current vendor*/ } else if ((line[0] == '\t') && (line[1] == '\t') && (skip_to_next_vendor == false)) { /* the product name is last field */ -- cgit From db3d9fd124f8971e38fb8b44b83f9d739b10ef7e Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Wed, 25 Feb 2009 21:52:40 +0100 Subject: hdt: PCI: Adding category --- com32/lib/pci/scan.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'com32/lib/pci') diff --git a/com32/lib/pci/scan.c b/com32/lib/pci/scan.c index d7c189f8..598ca9b4 100644 --- a/com32/lib/pci/scan.c +++ b/com32/lib/pci/scan.c @@ -216,8 +216,11 @@ int get_class_name_from_pci_ids(struct pci_domain *domain) int int_class_id_str=hex_to_int(class_id_str); /* assign the class_name to any matching pci device */ for_each_pci_func(dev, domain) { - if (int_class_id_str == dev->class[2]) + if (int_class_id_str == dev->class[2]) { strlcpy(dev->dev_info->class_name,class_name,PCI_CLASS_NAME_SIZE-1); + /* This value is usually the main category*/ + strlcpy(dev->dev_info->category_name,class_name+4,PCI_CLASS_NAME_SIZE-1); + } } /* if we have a tab + a char, it means this is a sub class name */ } else if ((line[0] == '\t') && (line[1] != '\t')) { -- cgit From 9c9636ce7596a4c72e3e36bb9afd19890ff2daed Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Wed, 11 Mar 2009 21:28:25 +0100 Subject: PCI: flexible modules.pcimap & pci.ids paths While detecting the pci names, class name & kernel modules, it's better to let the user choosing the path instead of the harcoded value "/" is not always the wanted path --- com32/lib/pci/scan.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'com32/lib/pci') diff --git a/com32/lib/pci/scan.c b/com32/lib/pci/scan.c index 598ca9b4..cfd9e654 100644 --- a/com32/lib/pci/scan.c +++ b/com32/lib/pci/scan.c @@ -73,7 +73,7 @@ static int hex_to_int(char *hexa) /* Try to match any pci device to the appropriate kernel module */ /* it uses the modules.pcimap from the boot device */ -int get_module_name_from_pci_ids(struct pci_domain *domain) +int get_module_name_from_pci_ids(struct pci_domain *domain, char *modules_pcimap_path) { char line[MAX_LINE]; char module_name[21]; // the module name field is 21 char long @@ -100,7 +100,7 @@ int get_module_name_from_pci_ids(struct pci_domain *domain) } /* Opening the modules.pcimap (of a linux kernel) from the boot device */ - f=fopen("modules.pcimap", "r"); + f=fopen(modules_pcimap_path, "r"); if (!f) return -ENOMODULESPCIMAP; @@ -161,7 +161,7 @@ int get_module_name_from_pci_ids(struct pci_domain *domain) /* Try to match any pci device to the appropriate class name */ /* it uses the pci.ids from the boot device */ -int get_class_name_from_pci_ids(struct pci_domain *domain) +int get_class_name_from_pci_ids(struct pci_domain *domain, char *pciids_path) { char line[MAX_LINE]; char class_name[PCI_CLASS_NAME_SIZE]; @@ -185,7 +185,7 @@ int get_class_name_from_pci_ids(struct pci_domain *domain) } /* Opening the pci.ids from the boot device */ - f = fopen("pci.ids","r"); + f = fopen(pciids_path,"r"); if (!f) return -ENOPCIIDS; @@ -251,7 +251,7 @@ int get_class_name_from_pci_ids(struct pci_domain *domain) /* Try to match any pci device to the appropriate vendor and product name */ /* it uses the pci.ids from the boot device */ -int get_name_from_pci_ids(struct pci_domain *domain) +int get_name_from_pci_ids(struct pci_domain *domain, char *pciids_path) { char line[MAX_LINE]; char vendor[PCI_VENDOR_NAME_SIZE]; @@ -282,7 +282,7 @@ int get_name_from_pci_ids(struct pci_domain *domain) } /* Opening the pci.ids from the boot device */ - f = fopen("pci.ids","r"); + f = fopen(pciids_path,"r"); if (!f) return -ENOPCIIDS; -- cgit