indirect_pci.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 <linux/kernel.h>
  12. #include <linux/pci.h>
  13. #include <linux/delay.h>
  14. #include <linux/string.h>
  15. #include <linux/init.h>
  16. #include <asm/io.h>
  17. #include <asm/prom.h>
  18. #include <asm/pci-bridge.h>
  19. #include <asm/machdep.h>
  20. int __indirect_read_config(struct pci_controller *hose,
  21. unsigned char bus_number, unsigned int devfn,
  22. int offset, int len, u32 *val)
  23. {
  24. volatile void __iomem *cfg_data;
  25. u8 cfg_type = 0;
  26. u32 bus_no, reg;
  27. if (hose->indirect_type & PPC_INDIRECT_TYPE_NO_PCIE_LINK) {
  28. if (bus_number != hose->first_busno)
  29. return PCIBIOS_DEVICE_NOT_FOUND;
  30. if (devfn != 0)
  31. return PCIBIOS_DEVICE_NOT_FOUND;
  32. }
  33. if (ppc_md.pci_exclude_device)
  34. if (ppc_md.pci_exclude_device(hose, bus_number, devfn))
  35. return PCIBIOS_DEVICE_NOT_FOUND;
  36. if (hose->indirect_type & PPC_INDIRECT_TYPE_SET_CFG_TYPE)
  37. if (bus_number != hose->first_busno)
  38. cfg_type = 1;
  39. bus_no = (bus_number == hose->first_busno) ?
  40. hose->self_busno : bus_number;
  41. if (hose->indirect_type & PPC_INDIRECT_TYPE_EXT_REG)
  42. reg = ((offset & 0xf00) << 16) | (offset & 0xfc);
  43. else
  44. reg = offset & 0xfc;
  45. if (hose->indirect_type & PPC_INDIRECT_TYPE_BIG_ENDIAN)
  46. out_be32(hose->cfg_addr, (0x80000000 | (bus_no << 16) |
  47. (devfn << 8) | reg | cfg_type));
  48. else
  49. out_le32(hose->cfg_addr, (0x80000000 | (bus_no << 16) |
  50. (devfn << 8) | reg | cfg_type));
  51. /*
  52. * Note: the caller has already checked that offset is
  53. * suitably aligned and that len is 1, 2 or 4.
  54. */
  55. cfg_data = hose->cfg_data + (offset & 3);
  56. switch (len) {
  57. case 1:
  58. *val = in_8(cfg_data);
  59. break;
  60. case 2:
  61. *val = in_le16(cfg_data);
  62. break;
  63. default:
  64. *val = in_le32(cfg_data);
  65. break;
  66. }
  67. return PCIBIOS_SUCCESSFUL;
  68. }
  69. int indirect_read_config(struct pci_bus *bus, unsigned int devfn,
  70. int offset, int len, u32 *val)
  71. {
  72. struct pci_controller *hose = pci_bus_to_host(bus);
  73. return __indirect_read_config(hose, bus->number, devfn, offset, len,
  74. val);
  75. }
  76. int indirect_write_config(struct pci_bus *bus, unsigned int devfn,
  77. int offset, int len, u32 val)
  78. {
  79. struct pci_controller *hose = pci_bus_to_host(bus);
  80. volatile void __iomem *cfg_data;
  81. u8 cfg_type = 0;
  82. u32 bus_no, reg;
  83. if (hose->indirect_type & PPC_INDIRECT_TYPE_NO_PCIE_LINK) {
  84. if (bus->number != hose->first_busno)
  85. return PCIBIOS_DEVICE_NOT_FOUND;
  86. if (devfn != 0)
  87. return PCIBIOS_DEVICE_NOT_FOUND;
  88. }
  89. if (ppc_md.pci_exclude_device)
  90. if (ppc_md.pci_exclude_device(hose, bus->number, devfn))
  91. return PCIBIOS_DEVICE_NOT_FOUND;
  92. if (hose->indirect_type & PPC_INDIRECT_TYPE_SET_CFG_TYPE)
  93. if (bus->number != hose->first_busno)
  94. cfg_type = 1;
  95. bus_no = (bus->number == hose->first_busno) ?
  96. hose->self_busno : bus->number;
  97. if (hose->indirect_type & PPC_INDIRECT_TYPE_EXT_REG)
  98. reg = ((offset & 0xf00) << 16) | (offset & 0xfc);
  99. else
  100. reg = offset & 0xfc;
  101. if (hose->indirect_type & PPC_INDIRECT_TYPE_BIG_ENDIAN)
  102. out_be32(hose->cfg_addr, (0x80000000 | (bus_no << 16) |
  103. (devfn << 8) | reg | cfg_type));
  104. else
  105. out_le32(hose->cfg_addr, (0x80000000 | (bus_no << 16) |
  106. (devfn << 8) | reg | cfg_type));
  107. /* suppress setting of PCI_PRIMARY_BUS */
  108. if (hose->indirect_type & PPC_INDIRECT_TYPE_SURPRESS_PRIMARY_BUS)
  109. if ((offset == PCI_PRIMARY_BUS) &&
  110. (bus->number == hose->first_busno))
  111. val &= 0xffffff00;
  112. /* Workaround for PCI_28 Errata in 440EPx/GRx */
  113. if ((hose->indirect_type & PPC_INDIRECT_TYPE_BROKEN_MRM) &&
  114. offset == PCI_CACHE_LINE_SIZE) {
  115. val = 0;
  116. }
  117. /*
  118. * Note: the caller has already checked that offset is
  119. * suitably aligned and that len is 1, 2 or 4.
  120. */
  121. cfg_data = hose->cfg_data + (offset & 3);
  122. switch (len) {
  123. case 1:
  124. out_8(cfg_data, val);
  125. break;
  126. case 2:
  127. out_le16(cfg_data, val);
  128. break;
  129. default:
  130. out_le32(cfg_data, val);
  131. break;
  132. }
  133. return PCIBIOS_SUCCESSFUL;
  134. }
  135. static struct pci_ops indirect_pci_ops =
  136. {
  137. .read = indirect_read_config,
  138. .write = indirect_write_config,
  139. };
  140. void setup_indirect_pci(struct pci_controller *hose, resource_size_t cfg_addr,
  141. resource_size_t cfg_data, u32 flags)
  142. {
  143. resource_size_t base = cfg_addr & PAGE_MASK;
  144. void __iomem *mbase;
  145. mbase = ioremap(base, PAGE_SIZE);
  146. hose->cfg_addr = mbase + (cfg_addr & ~PAGE_MASK);
  147. if ((cfg_data & PAGE_MASK) != base)
  148. mbase = ioremap(cfg_data & PAGE_MASK, PAGE_SIZE);
  149. hose->cfg_data = mbase + (cfg_data & ~PAGE_MASK);
  150. hose->ops = &indirect_pci_ops;
  151. hose->indirect_type = flags;
  152. }