blob: 2c775877eae240279d08adc18591a058e34e755e [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Sasha Levin28b24c12015-04-14 15:44:57 -07002#ifndef __MM_CMA_H__
3#define __MM_CMA_H__
4
Jakub Kicinskia2b992c2020-07-09 17:42:44 -07005#include <linux/debugfs.h>
Minchan Kim43ca1062021-05-04 18:37:28 -07006#include <linux/kobject.h>
7
8struct cma_kobject {
9 struct kobject kobj;
10 struct cma *cma;
11};
Jakub Kicinskia2b992c2020-07-09 17:42:44 -070012
Sasha Levin28b24c12015-04-14 15:44:57 -070013struct 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 Kravetz0ef7dca2021-05-04 18:34:44 -070018 spinlock_t lock;
Sasha Levin26b02a12015-04-14 15:44:59 -070019#ifdef CONFIG_CMA_DEBUGFS
20 struct hlist_head mem_head;
21 spinlock_t mem_head_lock;
Jakub Kicinskia2b992c2020-07-09 17:42:44 -070022 struct debugfs_u32_array dfs_bitmap;
Sasha Levin26b02a12015-04-14 15:44:59 -070023#endif
Barry Song18e98e52020-08-11 18:31:57 -070024 char name[CMA_MAX_NAME];
Minchan Kim43ca1062021-05-04 18:37:28 -070025#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 Levin28b24c12015-04-14 15:44:57 -070033};
34
35extern struct cma cma_areas[MAX_CMA_AREAS];
36extern unsigned cma_area_count;
37
Gregory Fongf21838e2015-08-14 15:35:21 -070038static inline unsigned long cma_bitmap_maxno(struct cma *cma)
Sasha Levin28b24c12015-04-14 15:44:57 -070039{
40 return cma->count >> cma->order_per_bit;
41}
42
Minchan Kim43ca1062021-05-04 18:37:28 -070043#ifdef CONFIG_CMA_SYSFS
44void cma_sysfs_account_success_pages(struct cma *cma, unsigned long nr_pages);
45void cma_sysfs_account_fail_pages(struct cma *cma, unsigned long nr_pages);
46#else
47static inline void cma_sysfs_account_success_pages(struct cma *cma,
48 unsigned long nr_pages) {};
49static inline void cma_sysfs_account_fail_pages(struct cma *cma,
50 unsigned long nr_pages) {};
51#endif
Sasha Levin28b24c12015-04-14 15:44:57 -070052#endif