early.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #include <linux/kernel.h>
  2. #include <linux/pci.h>
  3. #include <asm/pci-direct.h>
  4. #include <asm/io.h>
  5. #include <asm/pci_x86.h>
  6. /* Direct PCI access. This is used for PCI accesses in early boot before
  7. the PCI subsystem works. */
  8. u32 read_pci_config(u8 bus, u8 slot, u8 func, u8 offset)
  9. {
  10. u32 v;
  11. outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8);
  12. v = inl(0xcfc);
  13. return v;
  14. }
  15. u8 read_pci_config_byte(u8 bus, u8 slot, u8 func, u8 offset)
  16. {
  17. u8 v;
  18. outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8);
  19. v = inb(0xcfc + (offset&3));
  20. return v;
  21. }
  22. u16 read_pci_config_16(u8 bus, u8 slot, u8 func, u8 offset)
  23. {
  24. u16 v;
  25. outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8);
  26. v = inw(0xcfc + (offset&2));
  27. return v;
  28. }
  29. void write_pci_config(u8 bus, u8 slot, u8 func, u8 offset,
  30. u32 val)
  31. {
  32. outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8);
  33. outl(val, 0xcfc);
  34. }
  35. void write_pci_config_byte(u8 bus, u8 slot, u8 func, u8 offset, u8 val)
  36. {
  37. outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8);
  38. outb(val, 0xcfc + (offset&3));
  39. }
  40. void write_pci_config_16(u8 bus, u8 slot, u8 func, u8 offset, u16 val)
  41. {
  42. outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8);
  43. outw(val, 0xcfc + (offset&2));
  44. }
  45. int early_pci_allowed(void)
  46. {
  47. return (pci_probe & (PCI_PROBE_CONF1|PCI_PROBE_NOEARLY)) ==
  48. PCI_PROBE_CONF1;
  49. }
  50. void early_dump_pci_device(u8 bus, u8 slot, u8 func)
  51. {
  52. int i;
  53. int j;
  54. u32 val;
  55. printk(KERN_INFO "pci 0000:%02x:%02x.%d config space:",
  56. bus, slot, func);
  57. for (i = 0; i < 256; i += 4) {
  58. if (!(i & 0x0f))
  59. printk("\n %02x:",i);
  60. val = read_pci_config(bus, slot, func, i);
  61. for (j = 0; j < 4; j++) {
  62. printk(" %02x", val & 0xff);
  63. val >>= 8;
  64. }
  65. }
  66. printk("\n");
  67. }
  68. void early_dump_pci_devices(void)
  69. {
  70. unsigned bus, slot, func;
  71. if (!early_pci_allowed())
  72. return;
  73. for (bus = 0; bus < 256; bus++) {
  74. for (slot = 0; slot < 32; slot++) {
  75. for (func = 0; func < 8; func++) {
  76. u32 class;
  77. u8 type;
  78. class = read_pci_config(bus, slot, func,
  79. PCI_CLASS_REVISION);
  80. if (class == 0xffffffff)
  81. continue;
  82. early_dump_pci_device(bus, slot, func);
  83. if (func == 0) {
  84. type = read_pci_config_byte(bus, slot,
  85. func,
  86. PCI_HEADER_TYPE);
  87. if (!(type & 0x80))
  88. break;
  89. }
  90. }
  91. }
  92. }
  93. }