ccio-rm-dma.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 <asm/uaccess.h>
  41. #include <asm/io.h>
  42. #include <asm/hardware.h>
  43. #include <asm/page.h>
  44. /* Only chose "ccio" since that's what HP-UX calls it....
  45. ** Make it easier for folks to migrate from one to the other :^)
  46. */
  47. #define MODULE_NAME "ccio"
  48. #define U2_IOA_RUNWAY 0x580
  49. #define U2_BC_GSC 0x501
  50. #define UTURN_IOA_RUNWAY 0x581
  51. #define UTURN_BC_GSC 0x502
  52. #define IS_U2(id) ( \
  53. (((id)->hw_type == HPHW_IOA) && ((id)->hversion == U2_IOA_RUNWAY)) || \
  54. (((id)->hw_type == HPHW_BCPORT) && ((id)->hversion == U2_BC_GSC)) \
  55. )
  56. #define IS_UTURN(id) ( \
  57. (((id)->hw_type == HPHW_IOA) && ((id)->hversion == UTURN_IOA_RUNWAY)) || \
  58. (((id)->hw_type == HPHW_BCPORT) && ((id)->hversion == UTURN_BC_GSC)) \
  59. )
  60. static int ccio_dma_supported( struct pci_dev *dev, u64 mask)
  61. {
  62. if (dev == NULL) {
  63. printk(KERN_ERR MODULE_NAME ": EISA/ISA/et al not supported\n");
  64. BUG();
  65. return(0);
  66. }
  67. /* only support 32-bit devices (ie PCI/GSC) */
  68. return((int) (mask >= 0xffffffffUL));
  69. }
  70. static void *ccio_alloc_consistent(struct pci_dev *dev, size_t size,
  71. dma_addr_t *handle)
  72. {
  73. void *ret;
  74. ret = (void *)__get_free_pages(GFP_ATOMIC, get_order(size));
  75. if (ret != NULL) {
  76. memset(ret, 0, size);
  77. *handle = virt_to_phys(ret);
  78. }
  79. return ret;
  80. }
  81. static void ccio_free_consistent(struct pci_dev *dev, size_t size,
  82. void *vaddr, dma_addr_t handle)
  83. {
  84. free_pages((unsigned long)vaddr, get_order(size));
  85. }
  86. static dma_addr_t ccio_map_single(struct pci_dev *dev, void *ptr, size_t size,
  87. int direction)
  88. {
  89. return virt_to_phys(ptr);
  90. }
  91. static void ccio_unmap_single(struct pci_dev *dev, dma_addr_t dma_addr,
  92. size_t size, int direction)
  93. {
  94. /* Nothing to do */
  95. }
  96. static int ccio_map_sg(struct pci_dev *dev, struct scatterlist *sglist, int nents, int direction)
  97. {
  98. int tmp = nents;
  99. /* KISS: map each buffer separately. */
  100. while (nents) {
  101. sg_dma_address(sglist) = ccio_map_single(dev, sglist->address, sglist->length, direction);
  102. sg_dma_len(sglist) = sglist->length;
  103. nents--;
  104. sglist++;
  105. }
  106. return tmp;
  107. }
  108. static void ccio_unmap_sg(struct pci_dev *dev, struct scatterlist *sglist, int nents, int direction)
  109. {
  110. #if 0
  111. while (nents) {
  112. ccio_unmap_single(dev, sg_dma_address(sglist), sg_dma_len(sglist), direction);
  113. nents--;
  114. sglist++;
  115. }
  116. return;
  117. #else
  118. /* Do nothing (copied from current ccio_unmap_single() :^) */
  119. #endif
  120. }
  121. static struct pci_dma_ops ccio_ops = {
  122. ccio_dma_supported,
  123. ccio_alloc_consistent,
  124. ccio_free_consistent,
  125. ccio_map_single,
  126. ccio_unmap_single,
  127. ccio_map_sg,
  128. ccio_unmap_sg,
  129. NULL, /* dma_sync_single_for_cpu : NOP for U2 */
  130. NULL, /* dma_sync_single_for_device : NOP for U2 */
  131. NULL, /* dma_sync_sg_for_cpu : ditto */
  132. NULL, /* dma_sync_sg_for_device : ditto */
  133. };
  134. /*
  135. ** Determine if u2 should claim this chip (return 0) or not (return 1).
  136. ** If so, initialize the chip and tell other partners in crime they
  137. ** have work to do.
  138. */
  139. static int
  140. ccio_probe(struct parisc_device *dev)
  141. {
  142. printk(KERN_INFO "%s found %s at 0x%lx\n", MODULE_NAME,
  143. dev->id.hversion == U2_BC_GSC ? "U2" : "UTurn",
  144. dev->hpa.start);
  145. /*
  146. ** FIXME - should check U2 registers to verify it's really running
  147. ** in "Real Mode".
  148. */
  149. #if 0
  150. /* will need this for "Virtual Mode" operation */
  151. ccio_hw_init(ccio_dev);
  152. ccio_common_init(ccio_dev);
  153. #endif
  154. hppa_dma_ops = &ccio_ops;
  155. return 0;
  156. }
  157. static struct parisc_device_id ccio_tbl[] = {
  158. { HPHW_BCPORT, HVERSION_REV_ANY_ID, U2_BC_GSC, 0xc },
  159. { HPHW_BCPORT, HVERSION_REV_ANY_ID, UTURN_BC_GSC, 0xc },
  160. { 0, }
  161. };
  162. static struct parisc_driver ccio_driver = {
  163. .name = "U2/Uturn",
  164. .id_table = ccio_tbl,
  165. .probe = ccio_probe,
  166. };
  167. void __init ccio_init(void)
  168. {
  169. register_parisc_driver(&ccio_driver);
  170. }