fsl_pcie.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. * "Temporary" MPC8548 Errata file -
  12. * The standard indirect_pci code should work with future silicon versions.
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/pci.h>
  16. #include <linux/delay.h>
  17. #include <linux/string.h>
  18. #include <linux/init.h>
  19. #include <linux/bootmem.h>
  20. #include <asm/io.h>
  21. #include <asm/prom.h>
  22. #include <asm/pci-bridge.h>
  23. #include <asm/machdep.h>
  24. #define PCI_CFG_OUT out_be32
  25. /* ERRATA PCI-Ex 14 PCIE Controller timeout */
  26. #define PCIE_FIX out_be32(hose->cfg_addr+0x4, 0x0400ffff)
  27. static int
  28. indirect_read_config_pcie(struct pci_bus *bus, unsigned int devfn, int offset,
  29. int len, u32 *val)
  30. {
  31. struct pci_controller *hose = bus->sysdata;
  32. volatile void __iomem *cfg_data;
  33. u32 temp;
  34. if (ppc_md.pci_exclude_device)
  35. if (ppc_md.pci_exclude_device(bus->number, devfn))
  36. return PCIBIOS_DEVICE_NOT_FOUND;
  37. /* Possible artifact of CDCpp50937 needs further investigation */
  38. if (devfn != 0x0 && bus->number == 0xff)
  39. return PCIBIOS_DEVICE_NOT_FOUND;
  40. PCIE_FIX;
  41. if (bus->number == 0xff) {
  42. PCI_CFG_OUT(hose->cfg_addr,
  43. (0x80000000 | ((offset & 0xf00) << 16) |
  44. ((bus->number - hose->bus_offset) << 16)
  45. | (devfn << 8) | ((offset & 0xfc) )));
  46. } else {
  47. PCI_CFG_OUT(hose->cfg_addr,
  48. (0x80000001 | ((offset & 0xf00) << 16) |
  49. ((bus->number - hose->bus_offset) << 16)
  50. | (devfn << 8) | ((offset & 0xfc) )));
  51. }
  52. /*
  53. * Note: the caller has already checked that offset is
  54. * suitably aligned and that len is 1, 2 or 4.
  55. */
  56. /* ERRATA PCI-Ex 12 - Configuration Address/Data Alignment */
  57. cfg_data = hose->cfg_data;
  58. PCIE_FIX;
  59. temp = in_le32(cfg_data);
  60. switch (len) {
  61. case 1:
  62. *val = (temp >> (((offset & 3))*8)) & 0xff;
  63. break;
  64. case 2:
  65. *val = (temp >> (((offset & 3))*8)) & 0xffff;
  66. break;
  67. default:
  68. *val = temp;
  69. break;
  70. }
  71. return PCIBIOS_SUCCESSFUL;
  72. }
  73. static int
  74. indirect_write_config_pcie(struct pci_bus *bus, unsigned int devfn, int offset,
  75. int len, u32 val)
  76. {
  77. struct pci_controller *hose = bus->sysdata;
  78. volatile void __iomem *cfg_data;
  79. u32 temp;
  80. if (ppc_md.pci_exclude_device)
  81. if (ppc_md.pci_exclude_device(bus->number, devfn))
  82. return PCIBIOS_DEVICE_NOT_FOUND;
  83. /* Possible artifact of CDCpp50937 needs further investigation */
  84. if (devfn != 0x0 && bus->number == 0xff)
  85. return PCIBIOS_DEVICE_NOT_FOUND;
  86. PCIE_FIX;
  87. if (bus->number == 0xff) {
  88. PCI_CFG_OUT(hose->cfg_addr,
  89. (0x80000000 | ((offset & 0xf00) << 16) |
  90. ((bus->number - hose->bus_offset) << 16)
  91. | (devfn << 8) | ((offset & 0xfc) )));
  92. } else {
  93. PCI_CFG_OUT(hose->cfg_addr,
  94. (0x80000001 | ((offset & 0xf00) << 16) |
  95. ((bus->number - hose->bus_offset) << 16)
  96. | (devfn << 8) | ((offset & 0xfc) )));
  97. }
  98. /*
  99. * Note: the caller has already checked that offset is
  100. * suitably aligned and that len is 1, 2 or 4.
  101. */
  102. /* ERRATA PCI-Ex 12 - Configuration Address/Data Alignment */
  103. cfg_data = hose->cfg_data;
  104. switch (len) {
  105. case 1:
  106. PCIE_FIX;
  107. temp = in_le32(cfg_data);
  108. temp = (temp & ~(0xff << ((offset & 3) * 8))) |
  109. (val << ((offset & 3) * 8));
  110. PCIE_FIX;
  111. out_le32(cfg_data, temp);
  112. break;
  113. case 2:
  114. PCIE_FIX;
  115. temp = in_le32(cfg_data);
  116. temp = (temp & ~(0xffff << ((offset & 3) * 8)));
  117. temp |= (val << ((offset & 3) * 8)) ;
  118. PCIE_FIX;
  119. out_le32(cfg_data, temp);
  120. break;
  121. default:
  122. PCIE_FIX;
  123. out_le32(cfg_data, val);
  124. break;
  125. }
  126. PCIE_FIX;
  127. return PCIBIOS_SUCCESSFUL;
  128. }
  129. static struct pci_ops indirect_pcie_ops = {
  130. indirect_read_config_pcie,
  131. indirect_write_config_pcie
  132. };
  133. void __init
  134. setup_indirect_pcie_nomap(struct pci_controller* hose, void __iomem * cfg_addr,
  135. void __iomem * cfg_data)
  136. {
  137. hose->cfg_addr = cfg_addr;
  138. hose->cfg_data = cfg_data;
  139. hose->ops = &indirect_pcie_ops;
  140. }
  141. void __init
  142. setup_indirect_pcie(struct pci_controller* hose, u32 cfg_addr, u32 cfg_data)
  143. {
  144. unsigned long base = cfg_addr & PAGE_MASK;
  145. void __iomem *mbase, *addr, *data;
  146. mbase = ioremap(base, PAGE_SIZE);
  147. addr = mbase + (cfg_addr & ~PAGE_MASK);
  148. if ((cfg_data & PAGE_MASK) != base)
  149. mbase = ioremap(cfg_data & PAGE_MASK, PAGE_SIZE);
  150. data = mbase + (cfg_data & ~PAGE_MASK);
  151. setup_indirect_pcie_nomap(hose, addr, data);
  152. }