pci-dma.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * arch/xtensa/pci-dma.c
  3. *
  4. * DMA coherent memory allocation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. *
  11. * Copyright (C) 2002 - 2005 Tensilica Inc.
  12. *
  13. * Based on version for i386.
  14. *
  15. * Chris Zankel <chris@zankel.net>
  16. * Joe Taylor <joe@tensilica.com, joetylr@yahoo.com>
  17. */
  18. #include <linux/types.h>
  19. #include <linux/mm.h>
  20. #include <linux/string.h>
  21. #include <linux/pci.h>
  22. #include <asm/io.h>
  23. #include <asm/cacheflush.h>
  24. /*
  25. * Note: We assume that the full memory space is always mapped to 'kseg'
  26. * Otherwise we have to use page attributes (not implemented).
  27. */
  28. void *
  29. dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *handle, int gfp)
  30. {
  31. void *ret;
  32. /* ignore region speicifiers */
  33. gfp &= ~(__GFP_DMA | __GFP_HIGHMEM);
  34. if (dev == NULL || (*dev->dma_mask < 0xffffffff))
  35. gfp |= GFP_DMA;
  36. ret = (void *)__get_free_pages(gfp, get_order(size));
  37. if (ret != NULL) {
  38. memset(ret, 0, size);
  39. *handle = virt_to_bus(ret);
  40. }
  41. return (void*) BYPASS_ADDR((unsigned long)ret);
  42. }
  43. void dma_free_coherent(struct device *hwdev, size_t size,
  44. void *vaddr, dma_addr_t dma_handle)
  45. {
  46. free_pages(CACHED_ADDR((unsigned long)vaddr), get_order(size));
  47. }
  48. void consistent_sync(void *vaddr, size_t size, int direction)
  49. {
  50. switch (direction) {
  51. case PCI_DMA_NONE:
  52. BUG();
  53. case PCI_DMA_FROMDEVICE: /* invalidate only */
  54. __invalidate_dcache_range((unsigned long)vaddr,
  55. (unsigned long)size);
  56. break;
  57. case PCI_DMA_TODEVICE: /* writeback only */
  58. case PCI_DMA_BIDIRECTIONAL: /* writeback and invalidate */
  59. __flush_invalidate_dcache_range((unsigned long)vaddr,
  60. (unsigned long)size);
  61. break;
  62. }
  63. }