pci_indirect.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. #ifndef __I386__
  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. out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
  34. sync(); \
  35. cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
  36. return 0; \
  37. }
  38. #elif defined(CONFIG_E500)
  39. #define INDIRECT_PCI_OP(rw, size, type, op, mask) \
  40. static int \
  41. indirect_##rw##_config_##size(struct pci_controller *hose, \
  42. pci_dev_t dev, int offset, type val) \
  43. { \
  44. *(hose->cfg_addr) = dev | (offset & 0xfc) | 0x80000000; \
  45. sync(); \
  46. cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
  47. return 0; \
  48. }
  49. #elif defined(CONFIG_440_GX) || defined(CONFIG_440_EP) || defined(CONFIG_440_GR)
  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. if (PCI_BUS(dev) > 0) \
  56. out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000001); \
  57. else \
  58. out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
  59. cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
  60. return 0; \
  61. }
  62. #else
  63. #define INDIRECT_PCI_OP(rw, size, type, op, mask) \
  64. static int \
  65. indirect_##rw##_config_##size(struct pci_controller *hose, \
  66. pci_dev_t dev, int offset, type val) \
  67. { \
  68. out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
  69. cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
  70. return 0; \
  71. }
  72. #endif
  73. #define INDIRECT_PCI_OP_ERRATA6(rw, size, type, op, mask) \
  74. static int \
  75. indirect_##rw##_config_##size(struct pci_controller *hose, \
  76. pci_dev_t dev, int offset, type val) \
  77. { \
  78. unsigned int msr = mfmsr(); \
  79. mtmsr(msr & ~(MSR_EE | MSR_CE)); \
  80. out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
  81. cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
  82. out_le32(hose->cfg_addr, 0x00000000); \
  83. mtmsr(msr); \
  84. return 0; \
  85. }
  86. INDIRECT_PCI_OP(read, byte, u8 *, in_8, 3)
  87. INDIRECT_PCI_OP(read, word, u16 *, in_le16, 2)
  88. INDIRECT_PCI_OP(read, dword, u32 *, in_le32, 0)
  89. #ifdef CONFIG_405GP
  90. INDIRECT_PCI_OP_ERRATA6(write, byte, u8, out_8, 3)
  91. INDIRECT_PCI_OP_ERRATA6(write, word, u16, out_le16, 2)
  92. INDIRECT_PCI_OP_ERRATA6(write, dword, u32, out_le32, 0)
  93. #else
  94. INDIRECT_PCI_OP(write, byte, u8, out_8, 3)
  95. INDIRECT_PCI_OP(write, word, u16, out_le16, 2)
  96. INDIRECT_PCI_OP(write, dword, u32, out_le32, 0)
  97. #endif
  98. void pci_setup_indirect(struct pci_controller* hose, u32 cfg_addr, u32 cfg_data)
  99. {
  100. pci_set_ops(hose,
  101. indirect_read_config_byte,
  102. indirect_read_config_word,
  103. indirect_read_config_dword,
  104. indirect_write_config_byte,
  105. indirect_write_config_word,
  106. indirect_write_config_dword);
  107. hose->cfg_addr = (unsigned int *) cfg_addr;
  108. hose->cfg_data = (unsigned char *) cfg_data;
  109. }
  110. #endif
  111. #endif