blob: 88a0595670b766cd9780476f7dacb71fd9979e34 [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
Hari Bathini27d121d2022-03-22 14:46:14 -070033 bool reserve_pages_on_error;
Sasha Levin28b24c12015-04-14 15:44:57 -070034};
35
36extern struct cma cma_areas[MAX_CMA_AREAS];
37extern unsigned cma_area_count;
38
Gregory Fongf21838e2015-08-14 15:35:21 -070039static inline unsigned long cma_bitmap_maxno(struct cma *cma)
Sasha Levin28b24c12015-04-14 15:44:57 -070040{
41 return cma->count >> cma->order_per_bit;
42}
43
Minchan Kim43ca1062021-05-04 18:37:28 -070044#ifdef CONFIG_CMA_SYSFS
45void cma_sysfs_account_success_pages(struct cma *cma, unsigned long nr_pages);
46void cma_sysfs_account_fail_pages(struct cma *cma, unsigned long nr_pages);
47#else
48static inline void cma_sysfs_account_success_pages(struct cma *cma,
49 unsigned long nr_pages) {};
50static inline void cma_sysfs_account_fail_pages(struct cma *cma,
51 unsigned long nr_pages) {};
52#endif
Sasha Levin28b24c12015-04-14 15:44:57 -070053#endif