pcie.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * arch/arm/mach-kirkwood/pcie.c
  3. *
  4. * PCIe functions for Marvell Kirkwood SoCs
  5. *
  6. * This file is licensed under the terms of the GNU General Public
  7. * License version 2. This program is licensed "as is" without any
  8. * warranty of any kind, whether express or implied.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/pci.h>
  12. #include <linux/mbus.h>
  13. #include <asm/mach/pci.h>
  14. #include <plat/pcie.h>
  15. #include "common.h"
  16. #define PCIE_BASE ((void __iomem *)PCIE_VIRT_BASE)
  17. static int pcie_valid_config(int bus, int dev)
  18. {
  19. /*
  20. * Don't go out when trying to access --
  21. * 1. nonexisting device on local bus
  22. * 2. where there's no device connected (no link)
  23. */
  24. if (bus == 0 && dev == 0)
  25. return 1;
  26. if (!orion_pcie_link_up(PCIE_BASE))
  27. return 0;
  28. if (bus == 0 && dev != 1)
  29. return 0;
  30. return 1;
  31. }
  32. /*
  33. * PCIe config cycles are done by programming the PCIE_CONF_ADDR register
  34. * and then reading the PCIE_CONF_DATA register. Need to make sure these
  35. * transactions are atomic.
  36. */
  37. static DEFINE_SPINLOCK(kirkwood_pcie_lock);
  38. static int pcie_rd_conf(struct pci_bus *bus, u32 devfn, int where,
  39. int size, u32 *val)
  40. {
  41. unsigned long flags;
  42. int ret;
  43. if (pcie_valid_config(bus->number, PCI_SLOT(devfn)) == 0) {
  44. *val = 0xffffffff;
  45. return PCIBIOS_DEVICE_NOT_FOUND;
  46. }
  47. spin_lock_irqsave(&kirkwood_pcie_lock, flags);
  48. ret = orion_pcie_rd_conf(PCIE_BASE, bus, devfn, where, size, val);
  49. spin_unlock_irqrestore(&kirkwood_pcie_lock, flags);
  50. return ret;
  51. }
  52. static int pcie_wr_conf(struct pci_bus *bus, u32 devfn,
  53. int where, int size, u32 val)
  54. {
  55. unsigned long flags;
  56. int ret;
  57. if (pcie_valid_config(bus->number, PCI_SLOT(devfn)) == 0)
  58. return PCIBIOS_DEVICE_NOT_FOUND;
  59. spin_lock_irqsave(&kirkwood_pcie_lock, flags);
  60. ret = orion_pcie_wr_conf(PCIE_BASE, bus, devfn, where, size, val);
  61. spin_unlock_irqrestore(&kirkwood_pcie_lock, flags);
  62. return ret;
  63. }
  64. static struct pci_ops pcie_ops = {
  65. .read = pcie_rd_conf,
  66. .write = pcie_wr_conf,
  67. };
  68. static int kirkwood_pcie_setup(int nr, struct pci_sys_data *sys)
  69. {
  70. struct resource *res;
  71. /*
  72. * Generic PCIe unit setup.
  73. */
  74. orion_pcie_setup(PCIE_BASE, &kirkwood_mbus_dram_info);
  75. /*
  76. * Request resources.
  77. */
  78. res = kzalloc(sizeof(struct resource) * 2, GFP_KERNEL);
  79. if (!res)
  80. panic("pcie_setup unable to alloc resources");
  81. /*
  82. * IORESOURCE_IO
  83. */
  84. res[0].name = "PCIe I/O Space";
  85. res[0].flags = IORESOURCE_IO;
  86. res[0].start = KIRKWOOD_PCIE_IO_PHYS_BASE;
  87. res[0].end = res[0].start + KIRKWOOD_PCIE_IO_SIZE - 1;
  88. if (request_resource(&ioport_resource, &res[0]))
  89. panic("Request PCIe IO resource failed\n");
  90. sys->resource[0] = &res[0];
  91. /*
  92. * IORESOURCE_MEM
  93. */
  94. res[1].name = "PCIe Memory Space";
  95. res[1].flags = IORESOURCE_MEM;
  96. res[1].start = KIRKWOOD_PCIE_MEM_PHYS_BASE;
  97. res[1].end = res[1].start + KIRKWOOD_PCIE_MEM_SIZE - 1;
  98. if (request_resource(&iomem_resource, &res[1]))
  99. panic("Request PCIe Memory resource failed\n");
  100. sys->resource[1] = &res[1];
  101. sys->resource[2] = NULL;
  102. sys->io_offset = 0;
  103. return 1;
  104. }
  105. static void __devinit rc_pci_fixup(struct pci_dev *dev)
  106. {
  107. /*
  108. * Prevent enumeration of root complex.
  109. */
  110. if (dev->bus->parent == NULL && dev->devfn == 0) {
  111. int i;
  112. for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
  113. dev->resource[i].start = 0;
  114. dev->resource[i].end = 0;
  115. dev->resource[i].flags = 0;
  116. }
  117. }
  118. }
  119. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL, PCI_ANY_ID, rc_pci_fixup);
  120. static struct pci_bus __init *
  121. kirkwood_pcie_scan_bus(int nr, struct pci_sys_data *sys)
  122. {
  123. struct pci_bus *bus;
  124. if (nr == 0) {
  125. bus = pci_scan_bus(sys->busnr, &pcie_ops, sys);
  126. } else {
  127. bus = NULL;
  128. BUG();
  129. }
  130. return bus;
  131. }
  132. static int __init kirkwood_pcie_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
  133. {
  134. return IRQ_KIRKWOOD_PCIE;
  135. }
  136. static struct hw_pci kirkwood_pci __initdata = {
  137. .nr_controllers = 1,
  138. .swizzle = pci_std_swizzle,
  139. .setup = kirkwood_pcie_setup,
  140. .scan = kirkwood_pcie_scan_bus,
  141. .map_irq = kirkwood_pcie_map_irq,
  142. };
  143. void __init kirkwood_pcie_init(void)
  144. {
  145. pci_common_init(&kirkwood_pci);
  146. }