191b1b84aSJérôme Duval /*
291b1b84aSJérôme Duval * Copyright 2006, Haiku, Inc. All Rights Reserved.
391b1b84aSJérôme Duval * Distributed under the terms of the MIT License.
491b1b84aSJérôme Duval *
591b1b84aSJérôme Duval * Authors:
691b1b84aSJérôme Duval * Jérôme Duval
791b1b84aSJérôme Duval */
891b1b84aSJérôme Duval
991b1b84aSJérôme Duval #include <stdio.h>
1091b1b84aSJérôme Duval
1191b1b84aSJérôme Duval static void
get_class_info(uint8 pci_class_base_id,uint8 pci_class_sub_id,uint8 pci_class_api_id,char * classInfo,size_t size)1207d5767dSJérôme Duval get_class_info(uint8 pci_class_base_id, uint8 pci_class_sub_id, uint8 pci_class_api_id, char *classInfo, size_t size)
1391b1b84aSJérôme Duval {
1491b1b84aSJérôme Duval if (pci_class_base_id == 0x80)
1507d5767dSJérôme Duval snprintf(classInfo, size, " (Other)");
1691b1b84aSJérôme Duval else {
17ea62eb1bSFrançois Revol PCI_CLASSCODETABLE *foundItem = NULL;
18ea62eb1bSFrançois Revol int i;
19ea62eb1bSFrançois Revol for (i = 0; i < (int)PCI_CLASSCODETABLE_LEN; i++) {
20ea62eb1bSFrançois Revol if ((pci_class_base_id == PciClassCodeTable[i].BaseClass)
21ea62eb1bSFrançois Revol && (pci_class_sub_id == PciClassCodeTable[i].SubClass)) {
22ea62eb1bSFrançois Revol foundItem = &PciClassCodeTable[i];
23ea62eb1bSFrançois Revol if (pci_class_api_id == PciClassCodeTable[i].ProgIf)
2491b1b84aSJérôme Duval break;
2591b1b84aSJérôme Duval }
2691b1b84aSJérôme Duval }
27ea62eb1bSFrançois Revol if (foundItem) {
2891b1b84aSJérôme Duval if (pci_class_sub_id != 0x80)
29ea62eb1bSFrançois Revol snprintf(classInfo, size, "%s (%s%s%s)", foundItem->BaseDesc, foundItem->SubDesc,
30ea62eb1bSFrançois Revol (foundItem->ProgDesc && strcmp("", foundItem->ProgDesc)) ? ", " : "", foundItem->ProgDesc);
3191b1b84aSJérôme Duval else
32ea62eb1bSFrançois Revol snprintf(classInfo, size, "%s", foundItem->BaseDesc);
33ea62eb1bSFrançois Revol } else
34ea62eb1bSFrançois Revol snprintf(classInfo, size, "%s (%u:%u:%u)", "(Unknown)",
35ea62eb1bSFrançois Revol pci_class_base_id, pci_class_sub_id, pci_class_api_id);
3691b1b84aSJérôme Duval }
3791b1b84aSJérôme Duval }
3891b1b84aSJérôme Duval
3991b1b84aSJérôme Duval static void
get_vendor_info(uint16 vendorID,const char ** venShort,const char ** venFull)4091b1b84aSJérôme Duval get_vendor_info(uint16 vendorID, const char **venShort, const char **venFull)
4191b1b84aSJérôme Duval {
4291b1b84aSJérôme Duval int i;
4391b1b84aSJérôme Duval for (i = 0; i < (int)PCI_VENTABLE_LEN; i++) {
4491b1b84aSJérôme Duval if (PciVenTable[i].VenId == vendorID) {
4591b1b84aSJérôme Duval if (PciVenTable[i].VenShort && PciVenTable[i].VenFull
4691b1b84aSJérôme Duval && 0 == strcmp(PciVenTable[i].VenShort, PciVenTable[i].VenFull)) {
4791b1b84aSJérôme Duval *venShort = PciVenTable[i].VenShort[0] ? PciVenTable[i].VenShort : NULL;
4891b1b84aSJérôme Duval *venFull = NULL;
4991b1b84aSJérôme Duval } else {
5091b1b84aSJérôme Duval *venShort = PciVenTable[i].VenShort && PciVenTable[i].VenShort[0] ? PciVenTable[i].VenShort : NULL;
5191b1b84aSJérôme Duval *venFull = PciVenTable[i].VenFull && PciVenTable[i].VenFull[0] ? PciVenTable[i].VenFull : NULL;
5291b1b84aSJérôme Duval }
5391b1b84aSJérôme Duval return;
5491b1b84aSJérôme Duval }
5591b1b84aSJérôme Duval }
5691b1b84aSJérôme Duval *venShort = NULL;
5791b1b84aSJérôme Duval *venFull = NULL;
5891b1b84aSJérôme Duval }
5991b1b84aSJérôme Duval
6091b1b84aSJérôme Duval
6191b1b84aSJérôme Duval static void
get_device_info(uint16 vendorID,uint16 deviceID,uint16 subvendorID,uint16 subsystemID,const char ** devShort,const char ** devFull)6291b1b84aSJérôme Duval get_device_info(uint16 vendorID, uint16 deviceID,
6391b1b84aSJérôme Duval uint16 subvendorID, uint16 subsystemID, const char **devShort, const char **devFull)
6491b1b84aSJérôme Duval {
6591b1b84aSJérôme Duval int i;
6691b1b84aSJérôme Duval *devShort = NULL;
6791b1b84aSJérôme Duval *devFull = NULL;
6891b1b84aSJérôme Duval
6991b1b84aSJérôme Duval // search for the device
7091b1b84aSJérôme Duval for (i = 0; i < (int)PCI_DEVTABLE_LEN; i++) {
7191b1b84aSJérôme Duval if (PciDevTable[i].VenId == vendorID && PciDevTable[i].DevId == deviceID ) {
72*996f75abSJérôme Duval *devShort = PciDevTable[i].ChipDesc && PciDevTable[i].ChipDesc[0] ? PciDevTable[i].ChipDesc : NULL;
73*996f75abSJérôme Duval if (PciDevTable[i].SubVenId == 0 || PciDevTable[i].SubDevId == 0)
74*996f75abSJérôme Duval i++;
7591b1b84aSJérôme Duval break;
7691b1b84aSJérôme Duval }
7791b1b84aSJérôme Duval }
7891b1b84aSJérôme Duval
7991b1b84aSJérôme Duval // search for the subsystem eventually
8091b1b84aSJérôme Duval for (; i < (int)PCI_DEVTABLE_LEN; i++) {
8191b1b84aSJérôme Duval if (PciDevTable[i].VenId != vendorID || PciDevTable[i].DevId != deviceID)
8291b1b84aSJérôme Duval break;
8391b1b84aSJérôme Duval if (PciDevTable[i].SubVenId == subvendorID && PciDevTable[i].SubDevId == subsystemID) {
8491b1b84aSJérôme Duval *devFull = PciDevTable[i].ChipDesc && PciDevTable[i].ChipDesc[0] ? PciDevTable[i].ChipDesc : NULL;
8591b1b84aSJérôme Duval break;
8691b1b84aSJérôme Duval }
8791b1b84aSJérôme Duval }
8891b1b84aSJérôme Duval }
89