indirect_pci.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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_bus *bus, unsigned int devfn,
  21. int offset, int len, u32 *val)
  22. {
  23. struct pci_controller *hose = pci_bus_to_host(bus);
  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_write_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. volatile void __iomem *cfg_data;
  74. u8 cfg_type = 0;
  75. u32 bus_no, reg;
  76. if (hose->indirect_type & PPC_INDIRECT_TYPE_NO_PCIE_LINK) {
  77. if (bus->number != hose->first_busno)
  78. return PCIBIOS_DEVICE_NOT_FOUND;
  79. if (devfn != 0)
  80. return PCIBIOS_DEVICE_NOT_FOUND;
  81. }
  82. if (ppc_md.pci_exclude_device)
  83. if (ppc_md.pci_exclude_device(hose, bus->number, devfn))
  84. return PCIBIOS_DEVICE_NOT_FOUND;
  85. if (hose->indirect_type & PPC_INDIRECT_TYPE_SET_CFG_TYPE)
  86. if (bus->number != hose->first_busno)
  87. cfg_type = 1;
  88. bus_no = (bus->number == hose->first_busno) ?
  89. hose->self_busno : bus->number;
  90. if (hose->indirect_type & PPC_INDIRECT_TYPE_EXT_REG)
  91. reg = ((offset & 0xf00) << 16) | (offset & 0xfc);
  92. else
  93. reg = offset & 0xfc;
  94. if (hose->indirect_type & PPC_INDIRECT_TYPE_BIG_ENDIAN)
  95. out_be32(hose->cfg_addr, (0x80000000 | (bus_no << 16) |
  96. (devfn << 8) | reg | cfg_type));
  97. else
  98. out_le32(hose->cfg_addr, (0x80000000 | (bus_no << 16) |
  99. (devfn << 8) | reg | cfg_type));
  100. /* suppress setting of PCI_PRIMARY_BUS */
  101. if (hose->indirect_type & PPC_INDIRECT_TYPE_SURPRESS_PRIMARY_BUS)
  102. if ((offset == PCI_PRIMARY_BUS) &&
  103. (bus->number == hose->first_busno))
  104. val &= 0xffffff00;
  105. /* Workaround for PCI_28 Errata in 440EPx/GRx */
  106. if ((hose->indirect_type & PPC_INDIRECT_TYPE_BROKEN_MRM) &&
  107. offset == PCI_CACHE_LINE_SIZE) {
  108. val = 0;
  109. }
  110. /*
  111. * Note: the caller has already checked that offset is
  112. * suitably aligned and that len is 1, 2 or 4.
  113. */
  114. cfg_data = hose->cfg_data + (offset & 3);
  115. switch (len) {
  116. case 1:
  117. out_8(cfg_data, val);
  118. break;
  119. case 2:
  120. out_le16(cfg_data, val);
  121. break;
  122. default:
  123. out_le32(cfg_data, val);
  124. break;
  125. }
  126. return PCIBIOS_SUCCESSFUL;
  127. }
  128. static struct pci_ops indirect_pci_ops =
  129. {
  130. .read = indirect_read_config,
  131. .write = indirect_write_config,
  132. };
  133. void __init
  134. setup_indirect_pci(struct pci_controller* hose,
  135. resource_size_t cfg_addr,
  136. resource_size_t cfg_data, u32 flags)
  137. {
  138. resource_size_t base = cfg_addr & PAGE_MASK;
  139. void __iomem *mbase;
  140. mbase = ioremap(base, PAGE_SIZE);
  141. hose->cfg_addr = mbase + (cfg_addr & ~PAGE_MASK);
  142. if ((cfg_data & PAGE_MASK) != base)
  143. mbase = ioremap(cfg_data & PAGE_MASK, PAGE_SIZE);
  144. hose->cfg_data = mbase + (cfg_data & ~PAGE_MASK);
  145. hose->ops = &indirect_pci_ops;
  146. hose->indirect_type = flags;
  147. }