162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef __MM_CMA_H__
362306a36Sopenharmony_ci#define __MM_CMA_H__
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#include <linux/debugfs.h>
662306a36Sopenharmony_ci#include <linux/kobject.h>
762306a36Sopenharmony_ci
862306a36Sopenharmony_cistruct cma_kobject {
962306a36Sopenharmony_ci	struct kobject kobj;
1062306a36Sopenharmony_ci	struct cma *cma;
1162306a36Sopenharmony_ci};
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_cistruct cma {
1462306a36Sopenharmony_ci	unsigned long   base_pfn;
1562306a36Sopenharmony_ci	unsigned long   count;
1662306a36Sopenharmony_ci	unsigned long   *bitmap;
1762306a36Sopenharmony_ci	unsigned int order_per_bit; /* Order of pages represented by one bit */
1862306a36Sopenharmony_ci	spinlock_t	lock;
1962306a36Sopenharmony_ci#ifdef CONFIG_CMA_DEBUGFS
2062306a36Sopenharmony_ci	struct hlist_head mem_head;
2162306a36Sopenharmony_ci	spinlock_t mem_head_lock;
2262306a36Sopenharmony_ci	struct debugfs_u32_array dfs_bitmap;
2362306a36Sopenharmony_ci#endif
2462306a36Sopenharmony_ci	char name[CMA_MAX_NAME];
2562306a36Sopenharmony_ci#ifdef CONFIG_CMA_SYSFS
2662306a36Sopenharmony_ci	/* the number of CMA page successful allocations */
2762306a36Sopenharmony_ci	atomic64_t nr_pages_succeeded;
2862306a36Sopenharmony_ci	/* the number of CMA page allocation failures */
2962306a36Sopenharmony_ci	atomic64_t nr_pages_failed;
3062306a36Sopenharmony_ci	/* kobject requires dynamic object */
3162306a36Sopenharmony_ci	struct cma_kobject *cma_kobj;
3262306a36Sopenharmony_ci#endif
3362306a36Sopenharmony_ci	bool reserve_pages_on_error;
3462306a36Sopenharmony_ci};
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ciextern struct cma cma_areas[MAX_CMA_AREAS];
3762306a36Sopenharmony_ciextern unsigned cma_area_count;
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_cistatic inline unsigned long cma_bitmap_maxno(struct cma *cma)
4062306a36Sopenharmony_ci{
4162306a36Sopenharmony_ci	return cma->count >> cma->order_per_bit;
4262306a36Sopenharmony_ci}
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci#ifdef CONFIG_CMA_SYSFS
4562306a36Sopenharmony_civoid cma_sysfs_account_success_pages(struct cma *cma, unsigned long nr_pages);
4662306a36Sopenharmony_civoid cma_sysfs_account_fail_pages(struct cma *cma, unsigned long nr_pages);
4762306a36Sopenharmony_ci#else
4862306a36Sopenharmony_cistatic inline void cma_sysfs_account_success_pages(struct cma *cma,
4962306a36Sopenharmony_ci						   unsigned long nr_pages) {};
5062306a36Sopenharmony_cistatic inline void cma_sysfs_account_fail_pages(struct cma *cma,
5162306a36Sopenharmony_ci						unsigned long nr_pages) {};
5262306a36Sopenharmony_ci#endif
5362306a36Sopenharmony_ci#endif
54