pci_indirect.c 5.0 KB

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