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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * This file is subject to the terms and conditions of the GNU General Public
  3.  * License.  See the file "COPYING" in the main directory of this archive
  4.  * for more details.
  5.  *
  6.  * Copyright (C) 2000  Ani Joshi <ajoshi@unixbox.com>
  7.  * Copyright (C) 2000, 2001  Ralf Baechle <ralf@gnu.org>
  8.  * swiped from i386, and cloned for MIPS by Geert, polished by Ralf.
  9.  */
  10. #include <linux/config.h>
  11. #include <linux/types.h>
  12. #include <linux/mm.h>
  13. #include <linux/module.h>
  14. #include <linux/string.h>
  15. #include <linux/pci.h>
  16. #include <asm/io.h>
  17. void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
  18.    dma_addr_t * dma_handle)
  19. {
  20. void *ret;
  21. int gfp = GFP_ATOMIC;
  22. #ifdef CONFIG_ISA
  23. if (hwdev == NULL || hwdev->dma_mask != 0xffffffff)
  24. gfp |= GFP_DMA;
  25. #endif
  26. ret = (void *) __get_free_pages(gfp, get_order(size));
  27. if (ret != NULL) {
  28. memset(ret, 0, size);
  29. *dma_handle = bus_to_baddr(hwdev->bus->number, __pa(ret));
  30. #ifdef CONFIG_NONCOHERENT_IO
  31. dma_cache_wback_inv((unsigned long) ret, size);
  32. ret = UNCAC_ADDR(ret);
  33. #endif
  34. }
  35. return ret;
  36. }
  37. void pci_free_consistent(struct pci_dev *hwdev, size_t size,
  38.  void *vaddr, dma_addr_t dma_handle)
  39. {
  40. unsigned long addr = (unsigned long) vaddr;
  41. #ifdef CONFIG_NONCOHERENT_IO
  42. addr = CAC_ADDR(addr);
  43. #endif
  44. free_pages(addr, get_order(size));
  45. }
  46. EXPORT_SYMBOL(pci_alloc_consistent);
  47. EXPORT_SYMBOL(pci_free_consistent);