pci_indirect.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. #if defined(CONFIG_MPC8260)
  20. #define INDIRECT_PCI_OP(rw, size, type, op, mask) \
  21. static int \
  22. indirect_##rw##_config_##size(struct pci_controller *hose, \
  23. pci_dev_t dev, int offset, type val) \
  24. { \
  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)
  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. *(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_440_GX)
  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. if (PCI_BUS(dev) > 0) \
  48. out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000001); \
  49. else \
  50. out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
  51. cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
  52. return 0; \
  53. }
  54. #else
  55. #define INDIRECT_PCI_OP(rw, size, type, op, mask) \
  56. static int \
  57. indirect_##rw##_config_##size(struct pci_controller *hose, \
  58. pci_dev_t dev, int offset, type val) \
  59. { \
  60. out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
  61. cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
  62. return 0; \
  63. }
  64. #endif
  65. #define INDIRECT_PCI_OP_ERRATA6(rw, size, type, op, mask) \
  66. static int \
  67. indirect_##rw##_config_##size(struct pci_controller *hose, \
  68. pci_dev_t dev, int offset, type val) \
  69. { \
  70. unsigned int msr = mfmsr(); \
  71. mtmsr(msr & ~(MSR_EE | MSR_CE)); \
  72. out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
  73. cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
  74. out_le32(hose->cfg_addr, 0x00000000); \
  75. mtmsr(msr); \
  76. return 0; \
  77. }
  78. INDIRECT_PCI_OP(read, byte, u8 *, in_8, 3)
  79. INDIRECT_PCI_OP(read, word, u16 *, in_le16, 2)
  80. INDIRECT_PCI_OP(read, dword, u32 *, in_le32, 0)
  81. #ifdef CONFIG_405GP
  82. INDIRECT_PCI_OP_ERRATA6(write, byte, u8, out_8, 3)
  83. INDIRECT_PCI_OP_ERRATA6(write, word, u16, out_le16, 2)
  84. INDIRECT_PCI_OP_ERRATA6(write, dword, u32, out_le32, 0)
  85. #else
  86. INDIRECT_PCI_OP(write, byte, u8, out_8, 3)
  87. INDIRECT_PCI_OP(write, word, u16, out_le16, 2)
  88. INDIRECT_PCI_OP(write, dword, u32, out_le32, 0)
  89. #endif
  90. void pci_setup_indirect(struct pci_controller* hose, u32 cfg_addr, u32 cfg_data)
  91. {
  92. pci_set_ops(hose,
  93. indirect_read_config_byte,
  94. indirect_read_config_word,
  95. indirect_read_config_dword,
  96. indirect_write_config_byte,
  97. indirect_write_config_word,
  98. indirect_write_config_dword);
  99. hose->cfg_addr = (unsigned int *) cfg_addr;
  100. hose->cfg_data = (unsigned char *) cfg_data;
  101. }
  102. #endif
  103. #endif