spider-pci.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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/io.h>
  24. #include <asm/ppc-pci.h>
  25. #include <asm/pci-bridge.h>
  26. #include "io-workarounds.h"
  27. #define SPIDER_PCI_DISABLE_PREFETCH
  28. struct spiderpci_iowa_private {
  29. void __iomem *regs;
  30. };
  31. static void spiderpci_io_flush(struct iowa_bus *bus)
  32. {
  33. struct spiderpci_iowa_private *priv;
  34. u32 val;
  35. priv = bus->private;
  36. val = in_be32(priv->regs + SPIDER_PCI_DUMMY_READ);
  37. iosync();
  38. }
  39. #define SPIDER_PCI_MMIO_READ(name, ret) \
  40. static ret spiderpci_##name(const PCI_IO_ADDR addr) \
  41. { \
  42. ret val = __do_##name(addr); \
  43. spiderpci_io_flush(iowa_mem_find_bus(addr)); \
  44. return val; \
  45. }
  46. #define SPIDER_PCI_MMIO_READ_STR(name) \
  47. static void spiderpci_##name(const PCI_IO_ADDR addr, void *buf, \
  48. unsigned long count) \
  49. { \
  50. __do_##name(addr, buf, count); \
  51. spiderpci_io_flush(iowa_mem_find_bus(addr)); \
  52. }
  53. SPIDER_PCI_MMIO_READ(readb, u8)
  54. SPIDER_PCI_MMIO_READ(readw, u16)
  55. SPIDER_PCI_MMIO_READ(readl, u32)
  56. SPIDER_PCI_MMIO_READ(readq, u64)
  57. SPIDER_PCI_MMIO_READ(readw_be, u16)
  58. SPIDER_PCI_MMIO_READ(readl_be, u32)
  59. SPIDER_PCI_MMIO_READ(readq_be, u64)
  60. SPIDER_PCI_MMIO_READ_STR(readsb)
  61. SPIDER_PCI_MMIO_READ_STR(readsw)
  62. SPIDER_PCI_MMIO_READ_STR(readsl)
  63. static void spiderpci_memcpy_fromio(void *dest, const PCI_IO_ADDR src,
  64. unsigned long n)
  65. {
  66. __do_memcpy_fromio(dest, src, n);
  67. spiderpci_io_flush(iowa_mem_find_bus(src));
  68. }
  69. static int __init spiderpci_pci_setup_chip(struct pci_controller *phb,
  70. void __iomem *regs)
  71. {
  72. void *dummy_page_va;
  73. dma_addr_t dummy_page_da;
  74. #ifdef SPIDER_PCI_DISABLE_PREFETCH
  75. u32 val = in_be32(regs + SPIDER_PCI_VCI_CNTL_STAT);
  76. pr_debug("SPIDER_IOWA:PVCI_Control_Status was 0x%08x\n", val);
  77. out_be32(regs + SPIDER_PCI_VCI_CNTL_STAT, val | 0x8);
  78. #endif /* SPIDER_PCI_DISABLE_PREFETCH */
  79. /* setup dummy read */
  80. /*
  81. * On CellBlade, we can't know that which XDR memory is used by
  82. * kmalloc() to allocate dummy_page_va.
  83. * In order to imporve the performance, the XDR which is used to
  84. * allocate dummy_page_va is the nearest the spider-pci.
  85. * We have to select the CBE which is the nearest the spider-pci
  86. * to allocate memory from the best XDR, but I don't know that
  87. * how to do.
  88. *
  89. * Celleb does not have this problem, because it has only one XDR.
  90. */
  91. dummy_page_va = kmalloc(PAGE_SIZE, GFP_KERNEL);
  92. if (!dummy_page_va) {
  93. pr_err("SPIDERPCI-IOWA:Alloc dummy_page_va failed.\n");
  94. return -1;
  95. }
  96. dummy_page_da = dma_map_single(phb->parent, dummy_page_va,
  97. PAGE_SIZE, DMA_FROM_DEVICE);
  98. if (dma_mapping_error(phb->parent, dummy_page_da)) {
  99. pr_err("SPIDER-IOWA:Map dummy page filed.\n");
  100. kfree(dummy_page_va);
  101. return -1;
  102. }
  103. out_be32(regs + SPIDER_PCI_DUMMY_READ_BASE, dummy_page_da);
  104. return 0;
  105. }
  106. int __init spiderpci_iowa_init(struct iowa_bus *bus, void *data)
  107. {
  108. void __iomem *regs = NULL;
  109. struct spiderpci_iowa_private *priv;
  110. struct device_node *np = bus->phb->dn;
  111. struct resource r;
  112. unsigned long offset = (unsigned long)data;
  113. pr_debug("SPIDERPCI-IOWA:Bus initialize for spider(%s)\n",
  114. np->full_name);
  115. priv = kzalloc(sizeof(struct spiderpci_iowa_private), GFP_KERNEL);
  116. if (!priv) {
  117. pr_err("SPIDERPCI-IOWA:"
  118. "Can't allocate struct spiderpci_iowa_private");
  119. return -1;
  120. }
  121. if (of_address_to_resource(np, 0, &r)) {
  122. pr_err("SPIDERPCI-IOWA:Can't get resource.\n");
  123. goto error;
  124. }
  125. regs = ioremap(r.start + offset, SPIDER_PCI_REG_SIZE);
  126. if (!regs) {
  127. pr_err("SPIDERPCI-IOWA:ioremap failed.\n");
  128. goto error;
  129. }
  130. priv->regs = regs;
  131. bus->private = priv;
  132. if (spiderpci_pci_setup_chip(bus->phb, regs))
  133. goto error;
  134. return 0;
  135. error:
  136. kfree(priv);
  137. bus->private = NULL;
  138. if (regs)
  139. iounmap(regs);
  140. return -1;
  141. }
  142. struct ppc_pci_io spiderpci_ops = {
  143. .readb = spiderpci_readb,
  144. .readw = spiderpci_readw,
  145. .readl = spiderpci_readl,
  146. .readq = spiderpci_readq,
  147. .readw_be = spiderpci_readw_be,
  148. .readl_be = spiderpci_readl_be,
  149. .readq_be = spiderpci_readq_be,
  150. .readsb = spiderpci_readsb,
  151. .readsw = spiderpci_readsw,
  152. .readsl = spiderpci_readsl,
  153. .memcpy_fromio = spiderpci_memcpy_fromio,
  154. };