cma.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __MM_CMA_H__
  3. #define __MM_CMA_H__
  4. #include <linux/debugfs.h>
  5. #include <linux/kobject.h>
  6. struct cma_kobject {
  7. struct kobject kobj;
  8. struct cma *cma;
  9. };
  10. struct cma {
  11. unsigned long base_pfn;
  12. unsigned long count;
  13. unsigned long *bitmap;
  14. unsigned int order_per_bit; /* Order of pages represented by one bit */
  15. spinlock_t lock;
  16. #ifdef CONFIG_CMA_DEBUGFS
  17. struct hlist_head mem_head;
  18. spinlock_t mem_head_lock;
  19. struct debugfs_u32_array dfs_bitmap;
  20. #endif
  21. char name[CMA_MAX_NAME];
  22. #ifdef CONFIG_CMA_SYSFS
  23. /* the number of CMA page successful allocations */
  24. atomic64_t nr_pages_succeeded;
  25. /* the number of CMA page allocation failures */
  26. atomic64_t nr_pages_failed;
  27. /* the number of CMA page released */
  28. atomic64_t nr_pages_released;
  29. /* kobject requires dynamic object */
  30. struct cma_kobject *cma_kobj;
  31. #endif
  32. bool reserve_pages_on_error;
  33. };
  34. extern struct cma cma_areas[MAX_CMA_AREAS];
  35. extern unsigned cma_area_count;
  36. static inline unsigned long cma_bitmap_maxno(struct cma *cma)
  37. {
  38. return cma->count >> cma->order_per_bit;
  39. }
  40. #ifdef CONFIG_CMA_SYSFS
  41. void cma_sysfs_account_success_pages(struct cma *cma, unsigned long nr_pages);
  42. void cma_sysfs_account_fail_pages(struct cma *cma, unsigned long nr_pages);
  43. void cma_sysfs_account_release_pages(struct cma *cma, unsigned long nr_pages);
  44. #else
  45. static inline void cma_sysfs_account_success_pages(struct cma *cma,
  46. unsigned long nr_pages) {};
  47. static inline void cma_sysfs_account_fail_pages(struct cma *cma,
  48. unsigned long nr_pages) {};
  49. static inline void cma_sysfs_account_release_pages(struct cma *cma,
  50. unsigned long nr_pages) {};
  51. #endif
  52. #endif