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