names.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * PCI Class and Device Name Tables
  3. *
  4. * Copyright 1993--1999 Drew Eckhardt, Frederic Potter,
  5. * David Mosberger-Tang, Martin Mares
  6. */
  7. #include <linux/config.h>
  8. #include <linux/types.h>
  9. #include <linux/kernel.h>
  10. #include <linux/pci.h>
  11. #include <linux/init.h>
  12. #ifdef CONFIG_PCI_NAMES
  13. struct pci_device_info {
  14. unsigned short device;
  15. unsigned short seen;
  16. const char *name;
  17. };
  18. struct pci_vendor_info {
  19. unsigned short vendor;
  20. unsigned short nr;
  21. const char *name;
  22. struct pci_device_info *devices;
  23. };
  24. /*
  25. * This is ridiculous, but we want the strings in
  26. * the .init section so that they don't take up
  27. * real memory.. Parse the same file multiple times
  28. * to get all the info.
  29. */
  30. #define VENDOR( vendor, name ) static char __vendorstr_##vendor[] __devinitdata = name;
  31. #define ENDVENDOR()
  32. #define DEVICE( vendor, device, name ) static char __devicestr_##vendor##device[] __devinitdata = name;
  33. #include "devlist.h"
  34. #define VENDOR( vendor, name ) static struct pci_device_info __devices_##vendor[] __devinitdata = {
  35. #define ENDVENDOR() };
  36. #define DEVICE( vendor, device, name ) { 0x##device, 0, __devicestr_##vendor##device },
  37. #include "devlist.h"
  38. static struct pci_vendor_info __devinitdata pci_vendor_list[] = {
  39. #define VENDOR( vendor, name ) { 0x##vendor, sizeof(__devices_##vendor) / sizeof(struct pci_device_info), __vendorstr_##vendor, __devices_##vendor },
  40. #define ENDVENDOR()
  41. #define DEVICE( vendor, device, name )
  42. #include "devlist.h"
  43. };
  44. #define VENDORS (sizeof(pci_vendor_list)/sizeof(struct pci_vendor_info))
  45. void __devinit pci_name_device(struct pci_dev *dev)
  46. {
  47. const struct pci_vendor_info *vendor_p = pci_vendor_list;
  48. int i = VENDORS;
  49. char *name = dev->pretty_name;
  50. do {
  51. if (vendor_p->vendor == dev->vendor)
  52. goto match_vendor;
  53. vendor_p++;
  54. } while (--i);
  55. /* Couldn't find either the vendor nor the device */
  56. sprintf(name, "PCI device %04x:%04x", dev->vendor, dev->device);
  57. return;
  58. match_vendor: {
  59. struct pci_device_info *device_p = vendor_p->devices;
  60. int i = vendor_p->nr;
  61. while (i > 0) {
  62. if (device_p->device == dev->device)
  63. goto match_device;
  64. device_p++;
  65. i--;
  66. }
  67. /* Ok, found the vendor, but unknown device */
  68. sprintf(name, "PCI device %04x:%04x (%." PCI_NAME_HALF "s)",
  69. dev->vendor, dev->device, vendor_p->name);
  70. return;
  71. /* Full match */
  72. match_device: {
  73. char *n = name + sprintf(name, "%s %s",
  74. vendor_p->name, device_p->name);
  75. int nr = device_p->seen + 1;
  76. device_p->seen = nr;
  77. if (nr > 1)
  78. sprintf(n, " (#%d)", nr);
  79. }
  80. }
  81. }
  82. /*
  83. * Class names. Not in .init section as they are needed in runtime.
  84. */
  85. static u16 pci_class_numbers[] = {
  86. #define CLASS(x,y) 0x##x,
  87. #include "classlist.h"
  88. };
  89. static char *pci_class_names[] = {
  90. #define CLASS(x,y) y,
  91. #include "classlist.h"
  92. };
  93. char *
  94. pci_class_name(u32 class)
  95. {
  96. int i;
  97. for(i=0; i<sizeof(pci_class_numbers)/sizeof(pci_class_numbers[0]); i++)
  98. if (pci_class_numbers[i] == class)
  99. return pci_class_names[i];
  100. return NULL;
  101. }
  102. #else
  103. void __devinit pci_name_device(struct pci_dev *dev)
  104. {
  105. }
  106. char *
  107. pci_class_name(u32 class)
  108. {
  109. return NULL;
  110. }
  111. #endif /* CONFIG_PCI_NAMES */