xilinx_pci.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * PCI support for Xilinx plbv46_pci soft-core which can be used on
  3. * Xilinx Virtex ML410 / ML510 boards.
  4. *
  5. * Copyright 2009 Roderick Colenbrander
  6. * Copyright 2009 Secret Lab Technologies Ltd.
  7. *
  8. * The pci bridge fixup code was copied from ppc4xx_pci.c and was written
  9. * by Benjamin Herrenschmidt.
  10. * Copyright 2007 Ben. Herrenschmidt <benh@kernel.crashing.org>, IBM Corp.
  11. *
  12. * This file is licensed under the terms of the GNU General Public License
  13. * version 2. This program is licensed "as is" without any warranty of any
  14. * kind, whether express or implied.
  15. */
  16. #include <linux/ioport.h>
  17. #include <linux/of.h>
  18. #include <linux/pci.h>
  19. #include <asm/io.h>
  20. #define XPLB_PCI_ADDR 0x10c
  21. #define XPLB_PCI_DATA 0x110
  22. #define XPLB_PCI_BUS 0x114
  23. #define PCI_HOST_ENABLE_CMD (PCI_COMMAND_SERR | PCI_COMMAND_PARITY | \
  24. PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY)
  25. static struct of_device_id xilinx_pci_match[] = {
  26. { .compatible = "xlnx,plbv46-pci-1.03.a", },
  27. {}
  28. };
  29. /**
  30. * xilinx_pci_fixup_bridge - Block Xilinx PHB configuration.
  31. */
  32. static void xilinx_pci_fixup_bridge(struct pci_dev *dev)
  33. {
  34. struct pci_controller *hose;
  35. int i;
  36. if (dev->devfn || dev->bus->self)
  37. return;
  38. hose = pci_bus_to_host(dev->bus);
  39. if (!hose)
  40. return;
  41. if (!of_match_node(xilinx_pci_match, hose->dn))
  42. return;
  43. /* Hide the PCI host BARs from the kernel as their content doesn't
  44. * fit well in the resource management
  45. */
  46. for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
  47. dev->resource[i].start = 0;
  48. dev->resource[i].end = 0;
  49. dev->resource[i].flags = 0;
  50. }
  51. dev_info(&dev->dev, "Hiding Xilinx plb-pci host bridge resources %s\n",
  52. pci_name(dev));
  53. }
  54. DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, xilinx_pci_fixup_bridge);
  55. #ifdef DEBUG
  56. /**
  57. * xilinx_pci_exclude_device - Don't do config access for non-root bus
  58. *
  59. * This is a hack. Config access to any bus other than bus 0 does not
  60. * currently work on the ML510 so we prevent it here.
  61. */
  62. static int
  63. xilinx_pci_exclude_device(struct pci_controller *hose, u_char bus, u8 devfn)
  64. {
  65. return (bus != 0);
  66. }
  67. /**
  68. * xilinx_early_pci_scan - List pci config space for available devices
  69. *
  70. * List pci devices in very early phase.
  71. */
  72. void __init xilinx_early_pci_scan(struct pci_controller *hose)
  73. {
  74. u32 bus = 0;
  75. u32 val, dev, func, offset;
  76. /* Currently we have only 2 device connected - up-to 32 devices */
  77. for (dev = 0; dev < 2; dev++) {
  78. /* List only first function number - up-to 8 functions */
  79. for (func = 0; func < 1; func++) {
  80. printk(KERN_INFO "%02x:%02x:%02x", bus, dev, func);
  81. /* read the first 64 standardized bytes */
  82. /* Up-to 192 bytes can be list of capabilities */
  83. for (offset = 0; offset < 64; offset += 4) {
  84. early_read_config_dword(hose, bus,
  85. PCI_DEVFN(dev, func), offset, &val);
  86. if (offset == 0 && val == 0xFFFFFFFF) {
  87. printk(KERN_CONT "\nABSENT");
  88. break;
  89. }
  90. if (!(offset % 0x10))
  91. printk(KERN_CONT "\n%04x: ", offset);
  92. printk(KERN_CONT "%08x ", val);
  93. }
  94. printk(KERN_INFO "\n");
  95. }
  96. }
  97. }
  98. #else
  99. void __init xilinx_early_pci_scan(struct pci_controller *hose)
  100. {
  101. }
  102. #endif
  103. /**
  104. * xilinx_pci_init - Find and register a Xilinx PCI host bridge
  105. */
  106. void __init xilinx_pci_init(void)
  107. {
  108. struct pci_controller *hose;
  109. struct resource r;
  110. void __iomem *pci_reg;
  111. struct device_node *pci_node;
  112. pci_node = of_find_matching_node(NULL, xilinx_pci_match);
  113. if (!pci_node)
  114. return;
  115. if (of_address_to_resource(pci_node, 0, &r)) {
  116. pr_err("xilinx-pci: cannot resolve base address\n");
  117. return;
  118. }
  119. hose = pcibios_alloc_controller(pci_node);
  120. if (!hose) {
  121. pr_err("xilinx-pci: pcibios_alloc_controller() failed\n");
  122. return;
  123. }
  124. /* Setup config space */
  125. setup_indirect_pci(hose, r.start + XPLB_PCI_ADDR,
  126. r.start + XPLB_PCI_DATA,
  127. INDIRECT_TYPE_SET_CFG_TYPE);
  128. /* According to the xilinx plbv46_pci documentation the soft-core starts
  129. * a self-init when the bus master enable bit is set. Without this bit
  130. * set the pci bus can't be scanned.
  131. */
  132. early_write_config_word(hose, 0, 0, PCI_COMMAND, PCI_HOST_ENABLE_CMD);
  133. /* Set the max latency timer to 255 */
  134. early_write_config_byte(hose, 0, 0, PCI_LATENCY_TIMER, 0xff);
  135. /* Set the max bus number to 255, and bus/subbus no's to 0 */
  136. pci_reg = of_iomap(pci_node, 0);
  137. out_be32(pci_reg + XPLB_PCI_BUS, 0x000000ff);
  138. iounmap(pci_reg);
  139. /* Register the host bridge with the linux kernel! */
  140. pci_process_bridge_OF_ranges(hose, pci_node,
  141. INDIRECT_TYPE_SET_CFG_TYPE);
  142. pr_info("xilinx-pci: Registered PCI host bridge\n");
  143. xilinx_early_pci_scan(hose);
  144. }