pci_indirect.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Support for indirect PCI bridges.
  3. *
  4. * Copyright (C) 1998 Gabriel Paubert.
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <common.h>
  9. #if !defined(__I386__)
  10. #include <asm/processor.h>
  11. #include <asm/io.h>
  12. #include <pci.h>
  13. #define cfg_read(val, addr, type, op) *val = op((type)(addr))
  14. #define cfg_write(val, addr, type, op) op((type *)(addr), (val))
  15. #if defined(CONFIG_MPC8260)
  16. #define INDIRECT_PCI_OP(rw, size, type, op, mask) \
  17. static int \
  18. indirect_##rw##_config_##size(struct pci_controller *hose, \
  19. pci_dev_t dev, int offset, type val) \
  20. { \
  21. u32 b, d,f; \
  22. b = PCI_BUS(dev); d = PCI_DEV(dev); f = PCI_FUNC(dev); \
  23. b = b - hose->first_busno; \
  24. dev = PCI_BDF(b, d, f); \
  25. out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
  26. sync(); \
  27. cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
  28. return 0; \
  29. }
  30. #elif defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
  31. #define INDIRECT_PCI_OP(rw, size, type, op, mask) \
  32. static int \
  33. indirect_##rw##_config_##size(struct pci_controller *hose, \
  34. pci_dev_t dev, int offset, type val) \
  35. { \
  36. u32 b, d,f; \
  37. b = PCI_BUS(dev); d = PCI_DEV(dev); f = PCI_FUNC(dev); \
  38. b = b - hose->first_busno; \
  39. dev = PCI_BDF(b, d, f); \
  40. *(hose->cfg_addr) = dev | (offset & 0xfc) | ((offset & 0xf00) << 16) | 0x80000000; \
  41. sync(); \
  42. cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
  43. return 0; \
  44. }
  45. #elif defined(CONFIG_440GX) || defined(CONFIG_440GP) || defined(CONFIG_440SP) || \
  46. defined(CONFIG_440SPE) || defined(CONFIG_460EX) || defined(CONFIG_460GT)
  47. #define INDIRECT_PCI_OP(rw, size, type, op, mask) \
  48. static int \
  49. indirect_##rw##_config_##size(struct pci_controller *hose, \
  50. pci_dev_t dev, int offset, type val) \
  51. { \
  52. u32 b, d,f; \
  53. b = PCI_BUS(dev); d = PCI_DEV(dev); f = PCI_FUNC(dev); \
  54. b = b - hose->first_busno; \
  55. dev = PCI_BDF(b, d, f); \
  56. if (PCI_BUS(dev) > 0) \
  57. out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000001); \
  58. else \
  59. out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
  60. cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
  61. return 0; \
  62. }
  63. #else
  64. #define INDIRECT_PCI_OP(rw, size, type, op, mask) \
  65. static int \
  66. indirect_##rw##_config_##size(struct pci_controller *hose, \
  67. pci_dev_t dev, int offset, type val) \
  68. { \
  69. u32 b, d,f; \
  70. b = PCI_BUS(dev); d = PCI_DEV(dev); f = PCI_FUNC(dev); \
  71. b = b - hose->first_busno; \
  72. dev = PCI_BDF(b, d, f); \
  73. out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
  74. cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
  75. return 0; \
  76. }
  77. #endif
  78. #define INDIRECT_PCI_OP_ERRATA6(rw, size, type, op, mask) \
  79. static int \
  80. indirect_##rw##_config_##size(struct pci_controller *hose, \
  81. pci_dev_t dev, int offset, type val) \
  82. { \
  83. unsigned int msr = mfmsr(); \
  84. mtmsr(msr & ~(MSR_EE | MSR_CE)); \
  85. out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
  86. cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
  87. out_le32(hose->cfg_addr, 0x00000000); \
  88. mtmsr(msr); \
  89. return 0; \
  90. }
  91. INDIRECT_PCI_OP(read, byte, u8 *, in_8, 3)
  92. INDIRECT_PCI_OP(read, word, u16 *, in_le16, 2)
  93. INDIRECT_PCI_OP(read, dword, u32 *, in_le32, 0)
  94. #ifdef CONFIG_405GP
  95. INDIRECT_PCI_OP_ERRATA6(write, byte, u8, out_8, 3)
  96. INDIRECT_PCI_OP_ERRATA6(write, word, u16, out_le16, 2)
  97. INDIRECT_PCI_OP_ERRATA6(write, dword, u32, out_le32, 0)
  98. #else
  99. INDIRECT_PCI_OP(write, byte, u8, out_8, 3)
  100. INDIRECT_PCI_OP(write, word, u16, out_le16, 2)
  101. INDIRECT_PCI_OP(write, dword, u32, out_le32, 0)
  102. #endif
  103. void pci_setup_indirect(struct pci_controller* hose, u32 cfg_addr, u32 cfg_data)
  104. {
  105. pci_set_ops(hose,
  106. indirect_read_config_byte,
  107. indirect_read_config_word,
  108. indirect_read_config_dword,
  109. indirect_write_config_byte,
  110. indirect_write_config_word,
  111. indirect_write_config_dword);
  112. hose->cfg_addr = (unsigned int *) cfg_addr;
  113. hose->cfg_data = (unsigned char *) cfg_data;
  114. }
  115. #endif /* !__I386__ */