ccio-rm-dma.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:5k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  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/pgalloc.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 supportedn");
  65. BUG();
  66. return(0);
  67. }
  68. dev->dma_mask = mask;   /* save it */
  69. /* only support 32-bit devices (ie PCI/GSC) */
  70. return((int) (mask >= 0xffffffffUL));
  71. }
  72. static void *ccio_alloc_consistent(struct pci_dev *dev, size_t size,
  73.  dma_addr_t *handle)
  74. {
  75. void *ret;
  76. ret = (void *)__get_free_pages(GFP_ATOMIC, get_order(size));
  77. if (ret != NULL) {
  78. memset(ret, 0, size);
  79. *handle = virt_to_phys(ret);
  80. }
  81. return ret;
  82. }
  83. static void ccio_free_consistent(struct pci_dev *dev, size_t size,
  84.        void *vaddr, dma_addr_t handle)
  85. {
  86. free_pages((unsigned long)vaddr, get_order(size));
  87. }
  88. static dma_addr_t ccio_map_single(struct pci_dev *dev, void *ptr, size_t size,
  89.   int direction)
  90. {
  91. return virt_to_phys(ptr);
  92. }
  93. static void ccio_unmap_single(struct pci_dev *dev, dma_addr_t dma_addr,
  94.     size_t size, int direction)
  95. {
  96. /* Nothing to do */
  97. }
  98. static int ccio_map_sg(struct pci_dev *dev, struct scatterlist *sglist, int nents, int direction)
  99. {
  100. int tmp = nents;
  101.         /* KISS: map each buffer seperately. */
  102. while (nents) {
  103. sg_dma_address(sglist) = ccio_map_single(dev, sglist->address, sglist->length, direction);
  104. sg_dma_len(sglist) = sglist->length;
  105. nents--;
  106. sglist++;
  107. }
  108. return tmp;
  109. }
  110. static void ccio_unmap_sg(struct pci_dev *dev, struct scatterlist *sglist, int nents, int direction)
  111. {
  112. #if 0
  113. while (nents) {
  114. ccio_unmap_single(dev, sg_dma_address(sglist), sg_dma_len(sglist), direction);
  115. nents--;
  116. sglist++;
  117. }
  118. return;
  119. #else
  120. /* Do nothing (copied from current ccio_unmap_single()  :^) */
  121. #endif
  122. }
  123. static struct pci_dma_ops ccio_ops = {
  124. ccio_dma_supported,
  125. ccio_alloc_consistent,
  126. ccio_free_consistent,
  127. ccio_map_single,
  128. ccio_unmap_single,
  129. ccio_map_sg,
  130. ccio_unmap_sg,
  131. NULL,                   /* dma_sync_single : NOP for U2 */
  132. NULL,                   /* dma_sync_sg     : 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%lxn", MODULE_NAME,
  143. dev->id.hversion == U2_BC_GSC ? "U2" : "UTurn",
  144. dev->hpa);
  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. }