dma-contiguous.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #ifndef __LINUX_CMA_H
  2. #define __LINUX_CMA_H
  3. /*
  4. * Contiguous Memory Allocator for DMA mapping framework
  5. * Copyright (c) 2010-2011 by Samsung Electronics.
  6. * Written by:
  7. * Marek Szyprowski <m.szyprowski@samsung.com>
  8. * Michal Nazarewicz <mina86@mina86.com>
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of the
  13. * License or (at your optional) any later version of the license.
  14. */
  15. /*
  16. * Contiguous Memory Allocator
  17. *
  18. * The Contiguous Memory Allocator (CMA) makes it possible to
  19. * allocate big contiguous chunks of memory after the system has
  20. * booted.
  21. *
  22. * Why is it needed?
  23. *
  24. * Various devices on embedded systems have no scatter-getter and/or
  25. * IO map support and require contiguous blocks of memory to
  26. * operate. They include devices such as cameras, hardware video
  27. * coders, etc.
  28. *
  29. * Such devices often require big memory buffers (a full HD frame
  30. * is, for instance, more then 2 mega pixels large, i.e. more than 6
  31. * MB of memory), which makes mechanisms such as kmalloc() or
  32. * alloc_page() ineffective.
  33. *
  34. * At the same time, a solution where a big memory region is
  35. * reserved for a device is suboptimal since often more memory is
  36. * reserved then strictly required and, moreover, the memory is
  37. * inaccessible to page system even if device drivers don't use it.
  38. *
  39. * CMA tries to solve this issue by operating on memory regions
  40. * where only movable pages can be allocated from. This way, kernel
  41. * can use the memory for pagecache and when device driver requests
  42. * it, allocated pages can be migrated.
  43. *
  44. * Driver usage
  45. *
  46. * CMA should not be used by the device drivers directly. It is
  47. * only a helper framework for dma-mapping subsystem.
  48. *
  49. * For more information, see kernel-docs in drivers/base/dma-contiguous.c
  50. */
  51. #ifdef __KERNEL__
  52. struct cma;
  53. struct page;
  54. struct device;
  55. #ifdef CONFIG_DMA_CMA
  56. /*
  57. * There is always at least global CMA area and a few optional device
  58. * private areas configured in kernel .config.
  59. */
  60. #define MAX_CMA_AREAS (1 + CONFIG_CMA_AREAS)
  61. extern struct cma *dma_contiguous_default_area;
  62. void dma_contiguous_reserve(phys_addr_t addr_limit);
  63. int dma_declare_contiguous(struct device *dev, phys_addr_t size,
  64. phys_addr_t base, phys_addr_t limit);
  65. struct page *dma_alloc_from_contiguous(struct device *dev, int count,
  66. unsigned int order);
  67. bool dma_release_from_contiguous(struct device *dev, struct page *pages,
  68. int count);
  69. #else
  70. #define MAX_CMA_AREAS (0)
  71. static inline void dma_contiguous_reserve(phys_addr_t limit) { }
  72. static inline
  73. int dma_declare_contiguous(struct device *dev, phys_addr_t size,
  74. phys_addr_t base, phys_addr_t limit)
  75. {
  76. return -ENOSYS;
  77. }
  78. static inline
  79. struct page *dma_alloc_from_contiguous(struct device *dev, int count,
  80. unsigned int order)
  81. {
  82. return NULL;
  83. }
  84. static inline
  85. bool dma_release_from_contiguous(struct device *dev, struct page *pages,
  86. int count)
  87. {
  88. return false;
  89. }
  90. #endif
  91. #endif
  92. #endif