early.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. if (v != 0xffffffff)
  14. pr_debug("%x reading 4 from %x: %x\n", slot, offset, v);
  15. return v;
  16. }
  17. u8 read_pci_config_byte(u8 bus, u8 slot, u8 func, u8 offset)
  18. {
  19. u8 v;
  20. outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8);
  21. v = inb(0xcfc + (offset&3));
  22. pr_debug("%x reading 1 from %x: %x\n", slot, offset, v);
  23. return v;
  24. }
  25. u16 read_pci_config_16(u8 bus, u8 slot, u8 func, u8 offset)
  26. {
  27. u16 v;
  28. outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8);
  29. v = inw(0xcfc + (offset&2));
  30. pr_debug("%x reading 2 from %x: %x\n", slot, offset, v);
  31. return v;
  32. }
  33. void write_pci_config(u8 bus, u8 slot, u8 func, u8 offset,
  34. u32 val)
  35. {
  36. pr_debug("%x writing to %x: %x\n", slot, offset, val);
  37. outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8);
  38. outl(val, 0xcfc);
  39. }
  40. void write_pci_config_byte(u8 bus, u8 slot, u8 func, u8 offset, u8 val)
  41. {
  42. pr_debug("%x writing to %x: %x\n", slot, offset, val);
  43. outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8);
  44. outb(val, 0xcfc + (offset&3));
  45. }
  46. void write_pci_config_16(u8 bus, u8 slot, u8 func, u8 offset, u16 val)
  47. {
  48. pr_debug("%x writing to %x: %x\n", slot, offset, val);
  49. outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8);
  50. outw(val, 0xcfc + (offset&2));
  51. }
  52. int early_pci_allowed(void)
  53. {
  54. return (pci_probe & (PCI_PROBE_CONF1|PCI_PROBE_NOEARLY)) ==
  55. PCI_PROBE_CONF1;
  56. }
  57. void early_dump_pci_device(u8 bus, u8 slot, u8 func)
  58. {
  59. int i;
  60. int j;
  61. u32 val;
  62. printk(KERN_INFO "pci 0000:%02x:%02x.%d config space:",
  63. bus, slot, func);
  64. for (i = 0; i < 256; i += 4) {
  65. if (!(i & 0x0f))
  66. printk("\n %02x:",i);
  67. val = read_pci_config(bus, slot, func, i);
  68. for (j = 0; j < 4; j++) {
  69. printk(" %02x", val & 0xff);
  70. val >>= 8;
  71. }
  72. }
  73. printk("\n");
  74. }
  75. void early_dump_pci_devices(void)
  76. {
  77. unsigned bus, slot, func;
  78. if (!early_pci_allowed())
  79. return;
  80. for (bus = 0; bus < 256; bus++) {
  81. for (slot = 0; slot < 32; slot++) {
  82. for (func = 0; func < 8; func++) {
  83. u32 class;
  84. u8 type;
  85. class = read_pci_config(bus, slot, func,
  86. PCI_CLASS_REVISION);
  87. if (class == 0xffffffff)
  88. continue;
  89. early_dump_pci_device(bus, slot, func);
  90. if (func == 0) {
  91. type = read_pci_config_byte(bus, slot,
  92. func,
  93. PCI_HEADER_TYPE);
  94. if (!(type & 0x80))
  95. break;
  96. }
  97. }
  98. }
  99. }
  100. }