1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __MM_CMA_H__ 3 #define __MM_CMA_H__ 4 5 #include <linux/cma.h> 6 #include <linux/debugfs.h> 7 #include <linux/kobject.h> 8 9 struct cma_kobject { 10 struct kobject kobj; 11 struct cma *cma; 12 }; 13 14 /* 15 * Multi-range support. This can be useful if the size of the allocation 16 * is not expected to be larger than the alignment (like with hugetlb_cma), 17 * and the total amount of memory requested, while smaller than the total 18 * amount of memory available, is large enough that it doesn't fit in a 19 * single physical memory range because of memory holes. 20 * 21 * Fields: 22 * @base_pfn: physical address of range 23 * @early_pfn: first PFN not reserved through cma_reserve_early 24 * @count: size of range 25 * @bitmap: bitmap of allocated (1 << order_per_bit)-sized chunks. 26 */ 27 struct cma_memrange { 28 unsigned long base_pfn; 29 unsigned long count; 30 union { 31 unsigned long early_pfn; 32 unsigned long *bitmap; 33 }; 34 #ifdef CONFIG_CMA_DEBUGFS 35 struct debugfs_u32_array dfs_bitmap; 36 #endif 37 }; 38 #define CMA_MAX_RANGES 8 39 40 struct cma { 41 unsigned long count; 42 unsigned long available_count; 43 unsigned int order_per_bit; /* Order of pages represented by one bit */ 44 spinlock_t lock; 45 struct mutex alloc_mutex; 46 #ifdef CONFIG_CMA_DEBUGFS 47 struct hlist_head mem_head; 48 spinlock_t mem_head_lock; 49 #endif 50 char name[CMA_MAX_NAME]; 51 int nranges; 52 struct cma_memrange ranges[CMA_MAX_RANGES]; 53 #ifdef CONFIG_CMA_SYSFS 54 /* the number of CMA page successful allocations */ 55 atomic64_t nr_pages_succeeded; 56 /* the number of CMA page allocation failures */ 57 atomic64_t nr_pages_failed; 58 /* the number of CMA page released */ 59 atomic64_t nr_pages_released; 60 /* kobject requires dynamic object */ 61 struct cma_kobject *cma_kobj; 62 #endif 63 unsigned long flags; 64 /* NUMA node (NUMA_NO_NODE if unspecified) */ 65 int nid; 66 }; 67 68 enum cma_flags { 69 CMA_RESERVE_PAGES_ON_ERROR, 70 CMA_ZONES_VALID, 71 CMA_ZONES_INVALID, 72 CMA_ACTIVATED, 73 }; 74 75 extern struct cma cma_areas[MAX_CMA_AREAS]; 76 extern unsigned int cma_area_count; 77 78 static inline unsigned long cma_bitmap_maxno(struct cma *cma, 79 struct cma_memrange *cmr) 80 { 81 return cmr->count >> cma->order_per_bit; 82 } 83 84 #ifdef CONFIG_CMA_SYSFS 85 void cma_sysfs_account_success_pages(struct cma *cma, unsigned long nr_pages); 86 void cma_sysfs_account_fail_pages(struct cma *cma, unsigned long nr_pages); 87 void cma_sysfs_account_release_pages(struct cma *cma, unsigned long nr_pages); 88 #else 89 static inline void cma_sysfs_account_success_pages(struct cma *cma, 90 unsigned long nr_pages) {}; 91 static inline void cma_sysfs_account_fail_pages(struct cma *cma, 92 unsigned long nr_pages) {}; 93 static inline void cma_sysfs_account_release_pages(struct cma *cma, 94 unsigned long nr_pages) {}; 95 #endif 96 #endif 97