pci_indirect.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. #ifdef CONFIG_PCI
  13. #if (!defined(__I386__) && !defined(CONFIG_IXDP425))
  14. #include <asm/processor.h>
  15. #include <asm/io.h>
  16. #include <pci.h>
  17. #define cfg_read(val, addr, type, op) *val = op((type)(addr))
  18. #define cfg_write(val, addr, type, op) op((type *)(addr), (val))
  19. #ifdef CONFIG_IXP425
  20. extern unsigned char in_8 (volatile unsigned *addr);
  21. extern unsigned short in_le16 (volatile unsigned *addr);
  22. extern unsigned in_le32 (volatile unsigned *addr);
  23. extern void out_8 (volatile unsigned *addr, char val);
  24. extern void out_le16 (volatile unsigned *addr, unsigned short val);
  25. extern void out_le32 (volatile unsigned *addr, unsigned int val);
  26. #endif /* CONFIG_IXP425 */
  27. #if defined(CONFIG_MPC8260)
  28. #define INDIRECT_PCI_OP(rw, size, type, op, mask) \
  29. static int \
  30. indirect_##rw##_config_##size(struct pci_controller *hose, \
  31. pci_dev_t dev, int offset, type val) \
  32. { \
  33. u32 b, d,f; \
  34. b = PCI_BUS(dev); d = PCI_DEV(dev); f = PCI_FUNC(dev); \
  35. b = b - hose->first_busno; \
  36. dev = PCI_BDF(b, d, f); \
  37. out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
  38. sync(); \
  39. cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
  40. return 0; \
  41. }
  42. #elif defined(CONFIG_E500)
  43. #define INDIRECT_PCI_OP(rw, size, type, op, mask) \
  44. static int \
  45. indirect_##rw##_config_##size(struct pci_controller *hose, \
  46. pci_dev_t dev, int offset, type val) \
  47. { \
  48. u32 b, d,f; \
  49. b = PCI_BUS(dev); d = PCI_DEV(dev); f = PCI_FUNC(dev); \
  50. b = b - hose->first_busno; \
  51. dev = PCI_BDF(b, d, f); \
  52. *(hose->cfg_addr) = dev | (offset & 0xfc) | 0x80000000; \
  53. sync(); \
  54. cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
  55. return 0; \
  56. }
  57. #elif defined(CONFIG_440GX) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
  58. #define INDIRECT_PCI_OP(rw, size, type, op, mask) \
  59. static int \
  60. indirect_##rw##_config_##size(struct pci_controller *hose, \
  61. pci_dev_t dev, int offset, type val) \
  62. { \
  63. u32 b, d,f; \
  64. b = PCI_BUS(dev); d = PCI_DEV(dev); f = PCI_FUNC(dev); \
  65. b = b - hose->first_busno; \
  66. dev = PCI_BDF(b, d, f); \
  67. if (PCI_BUS(dev) > 0) \
  68. out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000001); \
  69. else \
  70. out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
  71. cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
  72. return 0; \
  73. }
  74. #else
  75. #define INDIRECT_PCI_OP(rw, size, type, op, mask) \
  76. static int \
  77. indirect_##rw##_config_##size(struct pci_controller *hose, \
  78. pci_dev_t dev, int offset, type val) \
  79. { \
  80. u32 b, d,f; \
  81. b = PCI_BUS(dev); d = PCI_DEV(dev); f = PCI_FUNC(dev); \
  82. b = b - hose->first_busno; \
  83. dev = PCI_BDF(b, d, f); \
  84. out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
  85. cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
  86. return 0; \
  87. }
  88. #endif
  89. #define INDIRECT_PCI_OP_ERRATA6(rw, size, type, op, mask) \
  90. static int \
  91. indirect_##rw##_config_##size(struct pci_controller *hose, \
  92. pci_dev_t dev, int offset, type val) \
  93. { \
  94. unsigned int msr = mfmsr(); \
  95. mtmsr(msr & ~(MSR_EE | MSR_CE)); \
  96. out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
  97. cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
  98. out_le32(hose->cfg_addr, 0x00000000); \
  99. mtmsr(msr); \
  100. return 0; \
  101. }
  102. INDIRECT_PCI_OP(read, byte, u8 *, in_8, 3)
  103. INDIRECT_PCI_OP(read, word, u16 *, in_le16, 2)
  104. INDIRECT_PCI_OP(read, dword, u32 *, in_le32, 0)
  105. #ifdef CONFIG_405GP
  106. INDIRECT_PCI_OP_ERRATA6(write, byte, u8, out_8, 3)
  107. INDIRECT_PCI_OP_ERRATA6(write, word, u16, out_le16, 2)
  108. INDIRECT_PCI_OP_ERRATA6(write, dword, u32, out_le32, 0)
  109. #else
  110. INDIRECT_PCI_OP(write, byte, u8, out_8, 3)
  111. INDIRECT_PCI_OP(write, word, u16, out_le16, 2)
  112. INDIRECT_PCI_OP(write, dword, u32, out_le32, 0)
  113. #endif
  114. void pci_setup_indirect(struct pci_controller* hose, u32 cfg_addr, u32 cfg_data)
  115. {
  116. pci_set_ops(hose,
  117. indirect_read_config_byte,
  118. indirect_read_config_word,
  119. indirect_read_config_dword,
  120. indirect_write_config_byte,
  121. indirect_write_config_word,
  122. indirect_write_config_dword);
  123. hose->cfg_addr = (unsigned int *) cfg_addr;
  124. hose->cfg_data = (unsigned char *) cfg_data;
  125. }
  126. #endif /* !__I386__ && !CONFIG_IXDP425 */
  127. #endif /* CONFIG_PCI */