early.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #include <linux/kernel.h>
  2. #include <linux/pci.h>
  3. #include <asm/pci-direct.h>
  4. #include <asm/io.h>
  5. #include "pci.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: %02x:%02x:%02x", bus, slot, func);
  63. for (i = 0; i < 256; i += 4) {
  64. if (!(i & 0x0f))
  65. printk("\n%04x:",i);
  66. val = read_pci_config(bus, slot, func, i);
  67. for (j = 0; j < 4; j++) {
  68. printk(" %02x", val & 0xff);
  69. val >>= 8;
  70. }
  71. }
  72. printk("\n");
  73. }
  74. void early_dump_pci_devices(void)
  75. {
  76. unsigned bus, slot, func;
  77. if (!early_pci_allowed())
  78. return;
  79. for (bus = 0; bus < 256; bus++) {
  80. for (slot = 0; slot < 32; slot++) {
  81. for (func = 0; func < 8; func++) {
  82. u32 class;
  83. u8 type;
  84. class = read_pci_config(bus, slot, func,
  85. PCI_CLASS_REVISION);
  86. if (class == 0xffffffff)
  87. break;
  88. early_dump_pci_device(bus, slot, func);
  89. /* No multi-function device? */
  90. type = read_pci_config_byte(bus, slot, func,
  91. PCI_HEADER_TYPE);
  92. if (!(type & 0x80))
  93. break;
  94. }
  95. }
  96. }
  97. }