spider-pci.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * IO workarounds for PCI on Celleb/Cell platform
  3. *
  4. * (C) Copyright 2006-2007 TOSHIBA CORPORATION
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. */
  20. #undef DEBUG
  21. #include <linux/kernel.h>
  22. #include <linux/of_platform.h>
  23. #include <linux/slab.h>
  24. #include <linux/io.h>
  25. #include <asm/ppc-pci.h>
  26. #include <asm/pci-bridge.h>
  27. #include <asm/io-workarounds.h>
  28. #define SPIDER_PCI_DISABLE_PREFETCH
  29. struct spiderpci_iowa_private {
  30. void __iomem *regs;
  31. };
  32. static void spiderpci_io_flush(struct iowa_bus *bus)
  33. {
  34. struct spiderpci_iowa_private *priv;
  35. u32 val;
  36. priv = bus->private;
  37. val = in_be32(priv->regs + SPIDER_PCI_DUMMY_READ);
  38. iosync();
  39. }
  40. #define SPIDER_PCI_MMIO_READ(name, ret) \
  41. static ret spiderpci_##name(const PCI_IO_ADDR addr) \
  42. { \
  43. ret val = __do_##name(addr); \
  44. spiderpci_io_flush(iowa_mem_find_bus(addr)); \
  45. return val; \
  46. }
  47. #define SPIDER_PCI_MMIO_READ_STR(name) \
  48. static void spiderpci_##name(const PCI_IO_ADDR addr, void *buf, \
  49. unsigned long count) \
  50. { \
  51. __do_##name(addr, buf, count); \
  52. spiderpci_io_flush(iowa_mem_find_bus(addr)); \
  53. }
  54. SPIDER_PCI_MMIO_READ(readb, u8)
  55. SPIDER_PCI_MMIO_READ(readw, u16)
  56. SPIDER_PCI_MMIO_READ(readl, u32)
  57. SPIDER_PCI_MMIO_READ(readq, u64)
  58. SPIDER_PCI_MMIO_READ(readw_be, u16)
  59. SPIDER_PCI_MMIO_READ(readl_be, u32)
  60. SPIDER_PCI_MMIO_READ(readq_be, u64)
  61. SPIDER_PCI_MMIO_READ_STR(readsb)
  62. SPIDER_PCI_MMIO_READ_STR(readsw)
  63. SPIDER_PCI_MMIO_READ_STR(readsl)
  64. static void spiderpci_memcpy_fromio(void *dest, const PCI_IO_ADDR src,
  65. unsigned long n)
  66. {
  67. __do_memcpy_fromio(dest, src, n);
  68. spiderpci_io_flush(iowa_mem_find_bus(src));
  69. }
  70. static int __init spiderpci_pci_setup_chip(struct pci_controller *phb,
  71. void __iomem *regs)
  72. {
  73. void *dummy_page_va;
  74. dma_addr_t dummy_page_da;
  75. #ifdef SPIDER_PCI_DISABLE_PREFETCH
  76. u32 val = in_be32(regs + SPIDER_PCI_VCI_CNTL_STAT);
  77. pr_debug("SPIDER_IOWA:PVCI_Control_Status was 0x%08x\n", val);
  78. out_be32(regs + SPIDER_PCI_VCI_CNTL_STAT, val | 0x8);
  79. #endif /* SPIDER_PCI_DISABLE_PREFETCH */
  80. /* setup dummy read */
  81. /*
  82. * On CellBlade, we can't know that which XDR memory is used by
  83. * kmalloc() to allocate dummy_page_va.
  84. * In order to imporve the performance, the XDR which is used to
  85. * allocate dummy_page_va is the nearest the spider-pci.
  86. * We have to select the CBE which is the nearest the spider-pci
  87. * to allocate memory from the best XDR, but I don't know that
  88. * how to do.
  89. *
  90. * Celleb does not have this problem, because it has only one XDR.
  91. */
  92. dummy_page_va = kmalloc(PAGE_SIZE, GFP_KERNEL);
  93. if (!dummy_page_va) {
  94. pr_err("SPIDERPCI-IOWA:Alloc dummy_page_va failed.\n");
  95. return -1;
  96. }
  97. dummy_page_da = dma_map_single(phb->parent, dummy_page_va,
  98. PAGE_SIZE, DMA_FROM_DEVICE);
  99. if (dma_mapping_error(phb->parent, dummy_page_da)) {
  100. pr_err("SPIDER-IOWA:Map dummy page filed.\n");
  101. kfree(dummy_page_va);
  102. return -1;
  103. }
  104. out_be32(regs + SPIDER_PCI_DUMMY_READ_BASE, dummy_page_da);
  105. return 0;
  106. }
  107. int __init spiderpci_iowa_init(struct iowa_bus *bus, void *data)
  108. {
  109. void __iomem *regs = NULL;
  110. struct spiderpci_iowa_private *priv;
  111. struct device_node *np = bus->phb->dn;
  112. struct resource r;
  113. unsigned long offset = (unsigned long)data;
  114. pr_debug("SPIDERPCI-IOWA:Bus initialize for spider(%s)\n",
  115. np->full_name);
  116. priv = kzalloc(sizeof(struct spiderpci_iowa_private), GFP_KERNEL);
  117. if (!priv) {
  118. pr_err("SPIDERPCI-IOWA:"
  119. "Can't allocate struct spiderpci_iowa_private");
  120. return -1;
  121. }
  122. if (of_address_to_resource(np, 0, &r)) {
  123. pr_err("SPIDERPCI-IOWA:Can't get resource.\n");
  124. goto error;
  125. }
  126. regs = ioremap(r.start + offset, SPIDER_PCI_REG_SIZE);
  127. if (!regs) {
  128. pr_err("SPIDERPCI-IOWA:ioremap failed.\n");
  129. goto error;
  130. }
  131. priv->regs = regs;
  132. bus->private = priv;
  133. if (spiderpci_pci_setup_chip(bus->phb, regs))
  134. goto error;
  135. return 0;
  136. error:
  137. kfree(priv);
  138. bus->private = NULL;
  139. if (regs)
  140. iounmap(regs);
  141. return -1;
  142. }
  143. struct ppc_pci_io spiderpci_ops = {
  144. .readb = spiderpci_readb,
  145. .readw = spiderpci_readw,
  146. .readl = spiderpci_readl,
  147. .readq = spiderpci_readq,
  148. .readw_be = spiderpci_readw_be,
  149. .readl_be = spiderpci_readl_be,
  150. .readq_be = spiderpci_readq_be,
  151. .readsb = spiderpci_readsb,
  152. .readsw = spiderpci_readsw,
  153. .readsl = spiderpci_readsl,
  154. .memcpy_fromio = spiderpci_memcpy_fromio,
  155. };