ccio-rm-dma.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * ccio-rm-dma.c:
  3. * DMA management routines for first generation cache-coherent machines.
  4. * "Real Mode" operation refers to U2/Uturn chip operation. The chip
  5. * can perform coherency checks w/o using the I/O MMU. That's all we
  6. * need until support for more than 4GB phys mem is needed.
  7. *
  8. * This is the trivial case - basically what x86 does.
  9. *
  10. * Drawbacks of using Real Mode are:
  11. * o outbound DMA is slower since one isn't using the prefetching
  12. * U2 can do for outbound DMA.
  13. * o Ability to do scatter/gather in HW is also lost.
  14. * o only known to work with PCX-W processor. (eg C360)
  15. * (PCX-U/U+ are not coherent with U2 in real mode.)
  16. *
  17. *
  18. * This program is free software; you can redistribute it and/or modify
  19. * it under the terms of the GNU General Public License as published by
  20. * the Free Software Foundation; either version 2 of the License, or
  21. * (at your option) any later version.
  22. *
  23. *
  24. * Original version/author:
  25. * CVSROOT=:pserver:anonymous@198.186.203.37:/cvsroot/linux-parisc
  26. * cvs -z3 co linux/arch/parisc/kernel/dma-rm.c
  27. *
  28. * (C) Copyright 2000 Philipp Rumpf <prumpf@tux.org>
  29. *
  30. *
  31. * Adopted for The Puffin Group's parisc-linux port by Grant Grundler.
  32. * (C) Copyright 2000 Grant Grundler <grundler@puffin.external.hp.com>
  33. *
  34. */
  35. #include <linux/types.h>
  36. #include <linux/init.h>
  37. #include <linux/mm.h>
  38. #include <linux/string.h>
  39. #include <linux/pci.h>
  40. #include <linux/gfp.h>
  41. #include <asm/uaccess.h>
  42. #include <asm/io.h>
  43. #include <asm/hardware.h>
  44. #include <asm/page.h>
  45. /* Only chose "ccio" since that's what HP-UX calls it....
  46. ** Make it easier for folks to migrate from one to the other :^)
  47. */
  48. #define MODULE_NAME "ccio"
  49. #define U2_IOA_RUNWAY 0x580
  50. #define U2_BC_GSC 0x501
  51. #define UTURN_IOA_RUNWAY 0x581
  52. #define UTURN_BC_GSC 0x502
  53. #define IS_U2(id) ( \
  54. (((id)->hw_type == HPHW_IOA) && ((id)->hversion == U2_IOA_RUNWAY)) || \
  55. (((id)->hw_type == HPHW_BCPORT) && ((id)->hversion == U2_BC_GSC)) \
  56. )
  57. #define IS_UTURN(id) ( \
  58. (((id)->hw_type == HPHW_IOA) && ((id)->hversion == UTURN_IOA_RUNWAY)) || \
  59. (((id)->hw_type == HPHW_BCPORT) && ((id)->hversion == UTURN_BC_GSC)) \
  60. )
  61. static int ccio_dma_supported( struct pci_dev *dev, u64 mask)
  62. {
  63. if (dev == NULL) {
  64. printk(KERN_ERR MODULE_NAME ": EISA/ISA/et al not supported\n");
  65. BUG();
  66. return(0);
  67. }
  68. /* only support 32-bit devices (ie PCI/GSC) */
  69. return((int) (mask >= 0xffffffffUL));
  70. }
  71. static void *ccio_alloc_consistent(struct pci_dev *dev, size_t size,
  72. dma_addr_t *handle)
  73. {
  74. void *ret;
  75. ret = (void *)__get_free_pages(GFP_ATOMIC, get_order(size));
  76. if (ret != NULL) {
  77. memset(ret, 0, size);
  78. *handle = virt_to_phys(ret);
  79. }
  80. return ret;
  81. }
  82. static void ccio_free_consistent(struct pci_dev *dev, size_t size,
  83. void *vaddr, dma_addr_t handle)
  84. {
  85. free_pages((unsigned long)vaddr, get_order(size));
  86. }
  87. static dma_addr_t ccio_map_single(struct pci_dev *dev, void *ptr, size_t size,
  88. int direction)
  89. {
  90. return virt_to_phys(ptr);
  91. }
  92. static void ccio_unmap_single(struct pci_dev *dev, dma_addr_t dma_addr,
  93. size_t size, int direction)
  94. {
  95. /* Nothing to do */
  96. }
  97. static int ccio_map_sg(struct pci_dev *dev, struct scatterlist *sglist, int nents, int direction)
  98. {
  99. int tmp = nents;
  100. /* KISS: map each buffer separately. */
  101. while (nents) {
  102. sg_dma_address(sglist) = ccio_map_single(dev, sglist->address, sglist->length, direction);
  103. sg_dma_len(sglist) = sglist->length;
  104. nents--;
  105. sglist++;
  106. }
  107. return tmp;
  108. }
  109. static void ccio_unmap_sg(struct pci_dev *dev, struct scatterlist *sglist, int nents, int direction)
  110. {
  111. #if 0
  112. while (nents) {
  113. ccio_unmap_single(dev, sg_dma_address(sglist), sg_dma_len(sglist), direction);
  114. nents--;
  115. sglist++;
  116. }
  117. return;
  118. #else
  119. /* Do nothing (copied from current ccio_unmap_single() :^) */
  120. #endif
  121. }
  122. static struct pci_dma_ops ccio_ops = {
  123. ccio_dma_supported,
  124. ccio_alloc_consistent,
  125. ccio_free_consistent,
  126. ccio_map_single,
  127. ccio_unmap_single,
  128. ccio_map_sg,
  129. ccio_unmap_sg,
  130. NULL, /* dma_sync_single_for_cpu : NOP for U2 */
  131. NULL, /* dma_sync_single_for_device : NOP for U2 */
  132. NULL, /* dma_sync_sg_for_cpu : ditto */
  133. NULL, /* dma_sync_sg_for_device : ditto */
  134. };
  135. /*
  136. ** Determine if u2 should claim this chip (return 0) or not (return 1).
  137. ** If so, initialize the chip and tell other partners in crime they
  138. ** have work to do.
  139. */
  140. static int
  141. ccio_probe(struct parisc_device *dev)
  142. {
  143. printk(KERN_INFO "%s found %s at 0x%lx\n", MODULE_NAME,
  144. dev->id.hversion == U2_BC_GSC ? "U2" : "UTurn",
  145. dev->hpa.start);
  146. /*
  147. ** FIXME - should check U2 registers to verify it's really running
  148. ** in "Real Mode".
  149. */
  150. #if 0
  151. /* will need this for "Virtual Mode" operation */
  152. ccio_hw_init(ccio_dev);
  153. ccio_common_init(ccio_dev);
  154. #endif
  155. hppa_dma_ops = &ccio_ops;
  156. return 0;
  157. }
  158. static struct parisc_device_id ccio_tbl[] = {
  159. { HPHW_BCPORT, HVERSION_REV_ANY_ID, U2_BC_GSC, 0xc },
  160. { HPHW_BCPORT, HVERSION_REV_ANY_ID, UTURN_BC_GSC, 0xc },
  161. { 0, }
  162. };
  163. static struct parisc_driver ccio_driver = {
  164. .name = "U2/Uturn",
  165. .id_table = ccio_tbl,
  166. .probe = ccio_probe,
  167. };
  168. void __init ccio_init(void)
  169. {
  170. register_parisc_driver(&ccio_driver);
  171. }