blob: bebb669b1064d1f29122849f25a77cce233bb332 [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 Kima5903592021-03-24 16:10:53 -07006#include <linux/kobject.h>
rongqianfeng474a7262021-05-20 11:18:26 +08007#include <linux/android_vendor.h>
Minchan Kima5903592021-03-24 16:10:53 -07008
9struct cma_kobject {
10 struct kobject kobj;
11 struct cma *cma;
12};
Jakub Kicinskia2b992c2020-07-09 17:42:44 -070013
Sasha Levin28b24c12015-04-14 15:44:57 -070014struct 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 struct mutex lock;
Sasha Levin26b02a12015-04-14 15:44:59 -070020#ifdef CONFIG_CMA_DEBUGFS
21 struct hlist_head mem_head;
22 spinlock_t mem_head_lock;
Jakub Kicinskia2b992c2020-07-09 17:42:44 -070023 struct debugfs_u32_array dfs_bitmap;
Sasha Levin26b02a12015-04-14 15:44:59 -070024#endif
Barry Song18e98e52020-08-11 18:31:57 -070025 char name[CMA_MAX_NAME];
Minchan Kima5903592021-03-24 16:10:53 -070026#ifdef CONFIG_CMA_SYSFS
27 /* the number of CMA page successful allocations */
28 atomic64_t nr_pages_succeeded;
29 /* the number of CMA page allocation failures */
30 atomic64_t nr_pages_failed;
31 /* kobject requires dynamic object */
32 struct cma_kobject *cma_kobj;
33#endif
rongqianfeng474a7262021-05-20 11:18:26 +080034 ANDROID_OEM_DATA_ARRAY(1, 4);
Sasha Levin28b24c12015-04-14 15:44:57 -070035};
36
37extern struct cma cma_areas[MAX_CMA_AREAS];
38extern unsigned cma_area_count;
39
Gregory Fongf21838e2015-08-14 15:35:21 -070040static inline unsigned long cma_bitmap_maxno(struct cma *cma)
Sasha Levin28b24c12015-04-14 15:44:57 -070041{
42 return cma->count >> cma->order_per_bit;
43}
44
Minchan Kima5903592021-03-24 16:10:53 -070045#ifdef CONFIG_CMA_SYSFS
46void cma_sysfs_account_success_pages(struct cma *cma, unsigned long nr_pages);
47void cma_sysfs_account_fail_pages(struct cma *cma, unsigned long nr_pages);
48#else
49static inline void cma_sysfs_account_success_pages(struct cma *cma,
50 unsigned long nr_pages) {};
51static inline void cma_sysfs_account_fail_pages(struct cma *cma,
52 unsigned long nr_pages) {};
53#endif
Sasha Levin28b24c12015-04-14 15:44:57 -070054#endif