diff --git a/headers/private/shared/pci-utils.h b/headers/private/shared/pci-utils.h new file mode 100644 index 0000000000..fad70ebfc4 --- /dev/null +++ b/headers/private/shared/pci-utils.h @@ -0,0 +1,86 @@ +/* + * Copyright 2006, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Jérôme Duval + */ + +#include + +static void +get_class_info(uint8 pci_class_base_id, uint8 pci_class_sub_id, uint8 pci_class_api_id, char *classInfo) +{ + if (pci_class_base_id == 0x80) + sprintf(classInfo, " (Other)"); + else { + PCI_CLASSCODETABLE *s = PciClassCodeTable, *foundItem = NULL; + while (s->BaseDesc) { + if ((pci_class_base_id == s->BaseClass) + && (pci_class_sub_id == s->SubClass)) { + foundItem = s; + if (pci_class_api_id == s->ProgIf) + break; + } + s++; + } + if (!s->BaseDesc) + s = foundItem; + if (pci_class_sub_id != 0x80) + sprintf(classInfo, "%s (%s%s%s)", s->BaseDesc, s->SubDesc, + (s->ProgDesc && strcmp("", s->ProgDesc)) ? ", " : "", s->ProgDesc); + else + sprintf(classInfo, "%s", s->BaseDesc); + } +} + +static void +get_vendor_info(uint16 vendorID, const char **venShort, const char **venFull) +{ + int i; + for (i = 0; i < (int)PCI_VENTABLE_LEN; i++) { + if (PciVenTable[i].VenId == vendorID) { + if (PciVenTable[i].VenShort && PciVenTable[i].VenFull + && 0 == strcmp(PciVenTable[i].VenShort, PciVenTable[i].VenFull)) { + *venShort = PciVenTable[i].VenShort[0] ? PciVenTable[i].VenShort : NULL; + *venFull = NULL; + } else { + *venShort = PciVenTable[i].VenShort && PciVenTable[i].VenShort[0] ? PciVenTable[i].VenShort : NULL; + *venFull = PciVenTable[i].VenFull && PciVenTable[i].VenFull[0] ? PciVenTable[i].VenFull : NULL; + } + return; + } + } + *venShort = NULL; + *venFull = NULL; +} + + +static void +get_device_info(uint16 vendorID, uint16 deviceID, + uint16 subvendorID, uint16 subsystemID, const char **devShort, const char **devFull) +{ + int i; + *devShort = NULL; + *devFull = NULL; + + // search for the device + for (i = 0; i < (int)PCI_DEVTABLE_LEN; i++) { + if (PciDevTable[i].VenId == vendorID && PciDevTable[i].DevId == deviceID ) { + *devShort = PciDevTable[i].Chip && PciDevTable[i].Chip[0] ? PciDevTable[i].Chip : NULL; + *devFull = PciDevTable[i].ChipDesc && PciDevTable[i].ChipDesc[0] ? PciDevTable[i].ChipDesc : NULL; + break; + } + } + + // search for the subsystem eventually + for (; i < (int)PCI_DEVTABLE_LEN; i++) { + if (PciDevTable[i].VenId != vendorID || PciDevTable[i].DevId != deviceID) + break; + if (PciDevTable[i].SubVenId == subvendorID && PciDevTable[i].SubDevId == subsystemID ) { + *devShort = PciDevTable[i].Chip && PciDevTable[i].Chip[0] ? PciDevTable[i].Chip : NULL; + *devFull = PciDevTable[i].ChipDesc && PciDevTable[i].ChipDesc[0] ? PciDevTable[i].ChipDesc : NULL; + break; + } + } +} diff --git a/src/add-ons/kernel/bus_managers/pci/Jamfile b/src/add-ons/kernel/bus_managers/pci/Jamfile index 36c0359a0e..61ecde0063 100644 --- a/src/add-ons/kernel/bus_managers/pci/Jamfile +++ b/src/add-ons/kernel/bus_managers/pci/Jamfile @@ -1,6 +1,6 @@ SubDir HAIKU_TOP src add-ons kernel bus_managers pci ; -UsePrivateHeaders [ FDirName kernel ] ; +UsePrivateHeaders kernel shared ; UsePrivateHeaders [ FDirName kernel util ] ; KernelAddon pci : diff --git a/src/add-ons/kernel/bus_managers/pci/pci_info.cpp b/src/add-ons/kernel/bus_managers/pci/pci_info.cpp index ca054c3473..dcfc134ead 100644 --- a/src/add-ons/kernel/bus_managers/pci/pci_info.cpp +++ b/src/add-ons/kernel/bus_managers/pci/pci_info.cpp @@ -17,13 +17,9 @@ #if USE_PCI_HEADER # include "pcihdr.h" +# include "pci-utils.h" #endif - -void get_vendor_info(uint16 vendorID, const char **venShort, const char **venFull); -void get_device_info(uint16 vendorID, uint16 deviceID, uint16 subvendorID, - uint16 subsystemID, const char **devShort, const char **devFull); -const char *get_class_info(uint8 class_base, uint8 class_sub, uint8 class_api); const char *get_capability_name(uint8 cap_id); @@ -183,7 +179,9 @@ print_info_basic(const pci_info *info, bool verbose) TRACE(("PCI: device %04x: %s\n", info->device_id, devShort ? devShort : devFull)); } #endif - TRACE(("PCI: info: %s\n", get_class_info(info->class_base, info->class_sub, info->class_api))); + char classInfo[255]; + get_class_info(info->class_base, info->class_sub, info->class_api, classInfo); + TRACE(("PCI: info: %s\n", classInfo)); } TRACE(("PCI: line_size %02x, latency %02x, header_type %02x, BIST %02x\n", info->line_size, info->latency, info->header_type, info->bist)); @@ -216,412 +214,6 @@ pci_print_info() } -const char * -get_class_info(uint8 class_base, uint8 class_sub, uint8 class_api) -{ - switch (class_base) { - case PCI_early: - switch (class_sub) { - case PCI_early_not_vga: - return "Not VGA-compatible pre-2.0 PCI specification device"; - case PCI_early_vga: - return "VGA-compatible pre-2.0 PCI specification device"; - default: - return "Unknown pre-2.0 PCI specification device"; - } - - case PCI_mass_storage: - switch (class_sub) { - case PCI_scsi: - return "SCSI mass storage controller"; - case PCI_ide: - return "IDE mass storage controller"; - case PCI_floppy: - return "Floppy disk controller"; - case PCI_ipi: - return "IPI mass storage controller"; - case PCI_raid: - return "RAID mass storage controller"; - case PCI_mass_storage_other: - return "Other mass storage controller"; - default: - return "Unknown mass storage controller"; - } - - case PCI_network: - switch (class_sub) { - case PCI_ethernet: - return "Ethernet network controller"; - case PCI_token_ring: - return "Token ring network controller"; - case PCI_fddi: - return "FDDI network controller"; - case PCI_atm: - return "ATM network controller"; - case PCI_isdn: - return "ISDN network controller"; - case PCI_network_other: - return "Other network controller"; - default: - return "Unknown network controller"; - } - - case PCI_display: - switch (class_sub) { - case PCI_vga: - switch (class_api) { - case 0x00: - return "VGA-compatible display controller"; - case 0x01: - return "8514-compatible display controller"; - default: - return "Unknown VGA display controller"; - } - case PCI_xga: - return "XGA display controller"; - case PCI_3d: - return "3D display controller"; - case PCI_display_other: - return "Other display controller"; - default: - return "Unknown display controller"; - } - - case PCI_multimedia: - switch (class_sub) { - case PCI_video: - return "Video multimedia device"; - case PCI_audio: - return "Audio multimedia device"; - case PCI_telephony: - return "Computer telephony multimedia device"; - case PCI_multimedia_other: - return "Other multimedia device"; - default: - return "Unknown multimedia device"; - } - - case PCI_memory: - switch (class_sub) { - case PCI_ram: - return "RAM memory controller"; - case PCI_flash: - return "Flash memory controller"; - case PCI_memory_other: - return "Other memory controller"; - default: - return "Unknown memory controller"; - } - - case PCI_bridge: - switch (class_sub) { - case PCI_host: - return "Host/PCI bridge device"; - case PCI_isa: - return "PCI/ISA bridge device"; - case PCI_eisa: - return "PCI/EISA bridge device"; - case PCI_microchannel: - return "PCI/Micro Channel bridge device"; - case PCI_pci: - switch (class_api) { - case 0x00: - return "PCI/PCI bridge device"; - case 0x01: - return "Transparent PCI/PCI bridge device"; - default: - return "Unknown PCI/PCI bridge device"; - } - case PCI_pcmcia: - return "PCI/PCMCIA bridge device"; - case PCI_nubus: - return "PCI/NuBus bridge device"; - case PCI_cardbus: - return "PCI/CardBus bridge device"; - case PCI_raceway: - if (class_api & 1) - return "PCI/RACEway bridge device, end-point mode"; - else - return "PCI/RACEway bridge device, transparent mode"; - case PCI_bridge_other: - return "Other bridge device"; - default: - return "Unknown bridge device"; - } - - case PCI_simple_communications: - switch (class_sub) { - case PCI_serial: - switch (class_api) { - case PCI_serial_xt: - return "Generic XT-compatible serial communications controller"; - case PCI_serial_16450: - return "16450-compatible serial communications controller"; - case PCI_serial_16550: - return "16550-compatible serial communications controller"; - case 0x03: - return "16650-compatible serial communications controller"; - case 0x04: - return "16750-compatible serial communications controller"; - case 0x05: - return "16850-compatible serial communications controller"; - case 0x06: - return "16950-compatible serial communications controller"; - default: - return "Unknown serial communications controller"; - } - case PCI_parallel: - switch (class_api) { - case PCI_parallel_simple: - return "Simple parallel port communications controller"; - case PCI_parallel_bidirectional: - return "Bi-directional parallel port communications controller"; - case PCI_parallel_ecp: - return "ECP 1.x compliant parallel port communications controller"; - case 0x03: - return "IEEE 1284 parallel communications controller"; - case 0xfe: - return "IEEE 1284 parallel communications target device"; - default: - return "Unknown parallel communications controller"; - } - case PCI_multiport_serial: - return "Multiport serial communications controller"; - case PCI_modem: - switch (class_api) { - case 0x00: - return "Generic modem"; - case 0x01: - return "Hayes-compatible modem, 16450-compatible interface"; - case 0x02: - return "Hayes-compatible modem, 16550-compatible interface"; - case 0x03: - return "Hayes-compatible modem, 16650-compatible interface"; - case 0x04: - return "Hayes-compatible modem, 16750-compatible interface"; - default: - return "Unknown modem communications controller"; - } - case PCI_simple_communications_other: - return "Other simple communications controller"; - default: - return "Unknown simple communications controller"; - } - - case PCI_base_peripheral: - switch (class_sub) { - case PCI_pic: - switch (class_api) { - case PCI_pic_8259: - return "Generic 8259 programmable interrupt controller (PIC)"; - case PCI_pic_isa: - return "ISA programmable interrupt controller (PIC)"; - case PCI_pic_eisa: - return "EISA programmable interrupt controller (PIC)"; - case 0x10: - return "IO advanced programmable interrupt controller (APIC)"; - case 0x20: - return "IO(x) advanced programmable interrupt controller (APIC)"; - default: - return "Unknown programmable interrupt controller (PIC)"; - } - case PCI_dma: - switch (class_api) { - case PCI_dma_8237: - return "Generic 8237 DMA controller"; - case PCI_dma_isa: - return "ISA DMA controller"; - case PCI_dma_eisa: - return "EISA DMA controller"; - default: - return "Unknown DMA controller"; - } - case PCI_timer: - switch (class_api) { - case PCI_timer_8254: - return "Generic 8254 timer"; - case PCI_timer_isa: - return "ISA system timers"; - case PCI_timer_eisa: - return "EISA system timers"; - default: - return "Unknown timer"; - } - case PCI_rtc: - switch (class_api) { - case PCI_rtc_generic: - return "Generic real time clock (RTC) controller"; - case PCI_rtc_isa: - return "ISA real time clock (RTC) controller"; - default: - return "Unknown real time clock (RTC) controller"; - } - case PCI_generic_hot_plug: - return "Generic PCI Hot-Plug controller"; - case PCI_system_peripheral_other: - return "Other base system peripheral"; - default: - return "Unknown base system peripheral"; - } - - case PCI_input: - switch (class_sub) { - case PCI_keyboard: - return "Keyboard controller"; - case PCI_pen: - return "Digitizer (pen) input device"; - case PCI_mouse: - return "Mouse controller"; - case PCI_scanner: - return "Scanner controller"; - case PCI_gameport: - switch (class_api) { - case 0x00: - return "Generic gameport controller"; - case 0x10: - return "Gameport controller"; - default: - return "Unknown gameport controller"; - } - case PCI_input_other: - return "Other input controller"; - default: - return "Unknown input controller"; - } - - case PCI_docking_station: - switch (class_sub) { - case PCI_docking_generic: - return "Generic docking station"; - case 0x80: - return "Other type of docking station"; - default: - return "Unknown docking station"; - } - - case PCI_processor: - switch (class_sub) { - case PCI_386: - return "386 processor"; - case PCI_486: - return "486 processor"; - case PCI_pentium: - return "Pentium processor"; - case PCI_alpha: - return "Alpha processor"; - case PCI_PowerPC: - return "PowerPC processor"; - case PCI_mips: - return "MIPS processor"; - case PCI_coprocessor: - return "Co-processor"; - default: - return "Unknown processor"; - } - - case PCI_serial_bus: - switch (class_sub) { - case PCI_firewire: - switch (class_api) { - case 0x00: - return "Firewire (IEEE 1394) serial bus controller"; - case 0x10: - return "Firewire (IEEE 1394) OpenHCI serial bus controller"; - default: - return "Unknown Firewire (IEEE 1394) serial bus controller"; - } - case PCI_access: - return "ACCESS serial bus controller"; - case PCI_ssa: - return "Serial Storage Architecture (SSA) controller"; - case PCI_usb: - switch (class_api) { - case PCI_usb_uhci: - return "USB UHCI controller"; - case PCI_usb_ohci: - return "USB OHCI controller"; - case 0x80: - return "Other USB controller"; - case 0xfe: - return "USB device"; - default: - return "Unknown USB serial bus controller"; - } - case PCI_fibre_channel: - return "Fibre Channel serial bus controller"; - case 0x05: - return "System Management Bus (SMBus) controller"; - default: - return "Unknown serial bus controller"; - } - - case PCI_wireless: - switch (class_sub) { - case 0x00: - return "iRDA compatible wireless controller"; - case 0x01: - return "Consumer IR wireless controller"; - case 0x10: - return "RF wireless controller"; - case 0x80: - return "Other wireless controller"; - default: - return "Unknown wireless controller"; - } - - case PCI_intelligent_io: - switch (class_sub) { - case 0x00: - return "Intelligent IO controller"; - default: - return "Unknown intelligent IO controller"; - } - - case PCI_satellite_communications: - switch (class_sub) { - case 0x01: - return "TV satellite communications controller"; - case 0x02: - return "Audio satellite communications controller"; - case 0x03: - return "Voice satellite communications controller"; - case 0x04: - return "Data satellite communications controller"; - default: - return "Unknown satellite communications controller"; - } - - case PCI_encryption_decryption: - switch (class_sub) { - case 0x00: - return "Network and computing encryption/decryption controller"; - case 0x10: - return "Entertainment encryption/decryption controller"; - case 0x80: - return "Other encryption/decryption controller"; - default: - return "Unknown encryption/decryption controller"; - } - - case PCI_data_acquisition: - switch (class_sub) { - case 0x00: - return "DPIO modules (data acquisition and signal processing controller)"; - case 0x80: - return "Other data acquisition and signal processing controller"; - default: - return "Unknown data acquisition and signal processing controller"; - } - - case PCI_undefined: - return "Does not fit any defined class"; - - default: - return "Unknown device class base"; - } -} - - const char * get_capability_name(uint8 cap_id) { @@ -657,55 +249,3 @@ get_capability_name(uint8 cap_id) } } - -#if USE_PCI_HEADER -void -get_vendor_info(uint16 vendorID, const char **venShort, const char **venFull) -{ - for (int i = 0; i < (int)PCI_VENTABLE_LEN; i++) { - if (PciVenTable[i].VenId == vendorID) { - if (PciVenTable[i].VenShort && PciVenTable[i].VenFull - && 0 == strcmp(PciVenTable[i].VenShort, PciVenTable[i].VenFull)) { - *venShort = PciVenTable[i].VenShort[0] ? PciVenTable[i].VenShort : NULL; - *venFull = NULL; - } else { - *venShort = PciVenTable[i].VenShort && PciVenTable[i].VenShort[0] ? PciVenTable[i].VenShort : NULL; - *venFull = PciVenTable[i].VenFull && PciVenTable[i].VenFull[0] ? PciVenTable[i].VenFull : NULL; - } - return; - } - } - *venShort = NULL; - *venFull = NULL; -} - - -void -get_device_info(uint16 vendorID, uint16 deviceID, - uint16 subvendorID, uint16 subsystemID, const char **devShort, const char **devFull) -{ - int i; - *devShort = NULL; - *devFull = NULL; - - // search for the device - for (i = 0; i < (int)PCI_DEVTABLE_LEN; i++) { - if (PciDevTable[i].VenId == vendorID && PciDevTable[i].DevId == deviceID ) { - *devShort = PciDevTable[i].Chip && PciDevTable[i].Chip[0] ? PciDevTable[i].Chip : NULL; - *devFull = PciDevTable[i].ChipDesc && PciDevTable[i].ChipDesc[0] ? PciDevTable[i].ChipDesc : NULL; - break; - } - } - - // search for the subsystem eventually - for (; i < (int)PCI_DEVTABLE_LEN; i++) { - if (PciDevTable[i].VenId != vendorID || PciDevTable[i].DevId != deviceID) - break; - if (PciDevTable[i].SubVenId == subvendorID && PciDevTable[i].SubDevId == subsystemID ) { - *devShort = PciDevTable[i].Chip && PciDevTable[i].Chip[0] ? PciDevTable[i].Chip : NULL; - *devFull = PciDevTable[i].ChipDesc && PciDevTable[i].ChipDesc[0] ? PciDevTable[i].ChipDesc : NULL; - break; - } - } -} -#endif /* USE_PCI_HEADER */ diff --git a/src/bin/listdev/Jamfile b/src/bin/listdev/Jamfile index c1330dca73..b167e2660d 100644 --- a/src/bin/listdev/Jamfile +++ b/src/bin/listdev/Jamfile @@ -1,6 +1,6 @@ SubDir HAIKU_TOP src bin listdev ; -UsePrivateHeaders kernel ; +UsePrivateHeaders kernel shared ; UsePrivateHeaders [ FDirName kernel arch $(TARGET_ARCH) ] ; UsePrivateHeaders [ FDirName kernel boot platform $(TARGET_BOOT_PLATFORM) ] ; diff --git a/src/bin/listdev/listdev.c b/src/bin/listdev/listdev.c index 75524a42be..33e63a95dc 100644 --- a/src/bin/listdev/listdev.c +++ b/src/bin/listdev/listdev.c @@ -20,6 +20,7 @@ #include "dm_wrapper.h" #include "pcihdr.h" +#include "pci-utils.h" extern const char *__progname; @@ -31,58 +32,6 @@ int gMode = USER_MODE; #define BUS_PCI 2 -static void -get_vendor_info(uint16 vendorID, const char **venShort, const char **venFull) -{ - int i; - for (i = 0; i < (int)PCI_VENTABLE_LEN; i++) { - if (PciVenTable[i].VenId == vendorID) { - if (PciVenTable[i].VenShort && PciVenTable[i].VenFull - && 0 == strcmp(PciVenTable[i].VenShort, PciVenTable[i].VenFull)) { - *venShort = PciVenTable[i].VenShort[0] ? PciVenTable[i].VenShort : NULL; - *venFull = NULL; - } else { - *venShort = PciVenTable[i].VenShort && PciVenTable[i].VenShort[0] ? PciVenTable[i].VenShort : NULL; - *venFull = PciVenTable[i].VenFull && PciVenTable[i].VenFull[0] ? PciVenTable[i].VenFull : NULL; - } - return; - } - } - *venShort = NULL; - *venFull = NULL; -} - - -static void -get_device_info(uint16 vendorID, uint16 deviceID, - uint16 subvendorID, uint16 subsystemID, const char **devShort, const char **devFull) -{ - int i; - *devShort = NULL; - *devFull = NULL; - - // search for the device - for (i = 0; i < (int)PCI_DEVTABLE_LEN; i++) { - if (PciDevTable[i].VenId == vendorID && PciDevTable[i].DevId == deviceID ) { - *devShort = PciDevTable[i].Chip && PciDevTable[i].Chip[0] ? PciDevTable[i].Chip : NULL; - *devFull = PciDevTable[i].ChipDesc && PciDevTable[i].ChipDesc[0] ? PciDevTable[i].ChipDesc : NULL; - break; - } - } - - // search for the subsystem eventually - for (; i < (int)PCI_DEVTABLE_LEN; i++) { - if (PciDevTable[i].VenId != vendorID || PciDevTable[i].DevId != deviceID) - break; - if (PciDevTable[i].SubVenId == subvendorID && PciDevTable[i].SubDevId == subsystemID ) { - *devShort = PciDevTable[i].Chip && PciDevTable[i].Chip[0] ? PciDevTable[i].Chip : NULL; - *devFull = PciDevTable[i].ChipDesc && PciDevTable[i].ChipDesc[0] ? PciDevTable[i].ChipDesc : NULL; - break; - } - } -} - - static void usage() { @@ -188,6 +137,7 @@ display_device(uint32 *node, uint8 level, int parent_bus, int *bus) const char *venFull; const char *devShort; const char *devFull; + char classInfo[255]; attr.cookie = 0; attr.node_cookie = *node; @@ -237,30 +187,8 @@ display_device(uint32 *node, uint8 level, int parent_bus, int *bus) case BUS_ISA: break; case BUS_PCI: - printf("device "); - - if (pci_class_base_id == 0x80) - printf(" (Other)"); - else { - PCI_CLASSCODETABLE *s = PciClassCodeTable, *foundItem; - - while (s->BaseDesc) { - if ((pci_class_base_id == s->BaseClass) - && (pci_class_sub_id == s->SubClass)) { - foundItem = s; - if (pci_class_api_id == s->ProgIf) - break; - } - s++; - } - if (!s->BaseDesc) - s = foundItem; - printf("%s", s->BaseDesc); - if (pci_class_sub_id != 0x80) - printf(" (%s%s%s)", s->SubDesc, - (s->ProgDesc && strcmp("", s->ProgDesc)) ? ", " : "", s->ProgDesc); - } - printf(" [%x|%x|%x]\n", pci_class_base_id, pci_class_sub_id, pci_class_api_id); + get_class_info(pci_class_base_id, pci_class_sub_id, pci_class_api_id, classInfo); + printf("device %s [%x|%x|%x]\n", classInfo, pci_class_base_id, pci_class_sub_id, pci_class_api_id); get_vendor_info(pci_vendor_id, &venShort, &venFull); if (!venShort && !venFull) {