cma.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. /* kobject requires dynamic object */
  28. struct cma_kobject *cma_kobj;
  29. #endif
  30. bool reserve_pages_on_error;
  31. };
  32. extern struct cma cma_areas[MAX_CMA_AREAS];
  33. extern unsigned cma_area_count;
  34. static inline unsigned long cma_bitmap_maxno(struct cma *cma)
  35. {
  36. return cma->count >> cma->order_per_bit;
  37. }
  38. #ifdef CONFIG_CMA_SYSFS
  39. void cma_sysfs_account_success_pages(struct cma *cma, unsigned long nr_pages);
  40. void cma_sysfs_account_fail_pages(struct cma *cma, unsigned long nr_pages);
  41. #else
  42. static inline void cma_sysfs_account_success_pages(struct cma *cma,
  43. unsigned long nr_pages) {};
  44. static inline void cma_sysfs_account_fail_pages(struct cma *cma,
  45. unsigned long nr_pages) {};
  46. #endif
  47. #endif