indirect_pci.c 4.4 KB

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