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