pci_indirect.c 4.6 KB

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