Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Sasha Levin | 28b24c1 | 2015-04-14 15:44:57 -0700 | [diff] [blame] | 2 | #ifndef __MM_CMA_H__ |
| 3 | #define __MM_CMA_H__ |
| 4 | |
Jakub Kicinski | a2b992c | 2020-07-09 17:42:44 -0700 | [diff] [blame] | 5 | #include <linux/debugfs.h> |
Minchan Kim | 43ca106 | 2021-05-04 18:37:28 -0700 | [diff] [blame] | 6 | #include <linux/kobject.h> |
| 7 | |
| 8 | struct cma_kobject { |
| 9 | struct kobject kobj; |
| 10 | struct cma *cma; |
| 11 | }; |
Jakub Kicinski | a2b992c | 2020-07-09 17:42:44 -0700 | [diff] [blame] | 12 | |
Sasha Levin | 28b24c1 | 2015-04-14 15:44:57 -0700 | [diff] [blame] | 13 | struct cma { |
| 14 | unsigned long base_pfn; |
| 15 | unsigned long count; |
| 16 | unsigned long *bitmap; |
| 17 | unsigned int order_per_bit; /* Order of pages represented by one bit */ |
Mike Kravetz | 0ef7dca | 2021-05-04 18:34:44 -0700 | [diff] [blame] | 18 | spinlock_t lock; |
Sasha Levin | 26b02a1 | 2015-04-14 15:44:59 -0700 | [diff] [blame] | 19 | #ifdef CONFIG_CMA_DEBUGFS |
| 20 | struct hlist_head mem_head; |
| 21 | spinlock_t mem_head_lock; |
Jakub Kicinski | a2b992c | 2020-07-09 17:42:44 -0700 | [diff] [blame] | 22 | struct debugfs_u32_array dfs_bitmap; |
Sasha Levin | 26b02a1 | 2015-04-14 15:44:59 -0700 | [diff] [blame] | 23 | #endif |
Barry Song | 18e98e5 | 2020-08-11 18:31:57 -0700 | [diff] [blame] | 24 | char name[CMA_MAX_NAME]; |
Minchan Kim | 43ca106 | 2021-05-04 18:37:28 -0700 | [diff] [blame] | 25 | #ifdef CONFIG_CMA_SYSFS |
| 26 | /* the number of CMA page successful allocations */ |
| 27 | atomic64_t nr_pages_succeeded; |
| 28 | /* the number of CMA page allocation failures */ |
| 29 | atomic64_t nr_pages_failed; |
| 30 | /* kobject requires dynamic object */ |
| 31 | struct cma_kobject *cma_kobj; |
| 32 | #endif |
Sasha Levin | 28b24c1 | 2015-04-14 15:44:57 -0700 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | extern struct cma cma_areas[MAX_CMA_AREAS]; |
| 36 | extern unsigned cma_area_count; |
| 37 | |
Gregory Fong | f21838e | 2015-08-14 15:35:21 -0700 | [diff] [blame] | 38 | static inline unsigned long cma_bitmap_maxno(struct cma *cma) |
Sasha Levin | 28b24c1 | 2015-04-14 15:44:57 -0700 | [diff] [blame] | 39 | { |
| 40 | return cma->count >> cma->order_per_bit; |
| 41 | } |
| 42 | |
Minchan Kim | 43ca106 | 2021-05-04 18:37:28 -0700 | [diff] [blame] | 43 | #ifdef CONFIG_CMA_SYSFS |
| 44 | void cma_sysfs_account_success_pages(struct cma *cma, unsigned long nr_pages); |
| 45 | void cma_sysfs_account_fail_pages(struct cma *cma, unsigned long nr_pages); |
| 46 | #else |
| 47 | static inline void cma_sysfs_account_success_pages(struct cma *cma, |
| 48 | unsigned long nr_pages) {}; |
| 49 | static inline void cma_sysfs_account_fail_pages(struct cma *cma, |
| 50 | unsigned long nr_pages) {}; |
| 51 | #endif |
Sasha Levin | 28b24c1 | 2015-04-14 15:44:57 -0700 | [diff] [blame] | 52 | #endif |