Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __CMA_H__
0003 #define __CMA_H__
0004 
0005 #include <linux/init.h>
0006 #include <linux/types.h>
0007 #include <linux/numa.h>
0008 
0009 /*
0010  * There is always at least global CMA area and a few optional
0011  * areas configured in kernel .config.
0012  */
0013 #ifdef CONFIG_CMA_AREAS
0014 #define MAX_CMA_AREAS   (1 + CONFIG_CMA_AREAS)
0015 #endif
0016 
0017 #define CMA_MAX_NAME 64
0018 
0019 /*
0020  *  the buddy -- especially pageblock merging and alloc_contig_range()
0021  * -- can deal with only some pageblocks of a higher-order page being
0022  *  MIGRATE_CMA, we can use pageblock_nr_pages.
0023  */
0024 #define CMA_MIN_ALIGNMENT_PAGES pageblock_nr_pages
0025 #define CMA_MIN_ALIGNMENT_BYTES (PAGE_SIZE * CMA_MIN_ALIGNMENT_PAGES)
0026 
0027 struct cma;
0028 
0029 extern unsigned long totalcma_pages;
0030 extern phys_addr_t cma_get_base(const struct cma *cma);
0031 extern unsigned long cma_get_size(const struct cma *cma);
0032 extern const char *cma_get_name(const struct cma *cma);
0033 
0034 extern int __init cma_declare_contiguous_nid(phys_addr_t base,
0035             phys_addr_t size, phys_addr_t limit,
0036             phys_addr_t alignment, unsigned int order_per_bit,
0037             bool fixed, const char *name, struct cma **res_cma,
0038             int nid);
0039 static inline int __init cma_declare_contiguous(phys_addr_t base,
0040             phys_addr_t size, phys_addr_t limit,
0041             phys_addr_t alignment, unsigned int order_per_bit,
0042             bool fixed, const char *name, struct cma **res_cma)
0043 {
0044     return cma_declare_contiguous_nid(base, size, limit, alignment,
0045             order_per_bit, fixed, name, res_cma, NUMA_NO_NODE);
0046 }
0047 extern int cma_init_reserved_mem(phys_addr_t base, phys_addr_t size,
0048                     unsigned int order_per_bit,
0049                     const char *name,
0050                     struct cma **res_cma);
0051 extern struct page *cma_alloc(struct cma *cma, unsigned long count, unsigned int align,
0052                   bool no_warn);
0053 extern bool cma_pages_valid(struct cma *cma, const struct page *pages, unsigned long count);
0054 extern bool cma_release(struct cma *cma, const struct page *pages, unsigned long count);
0055 
0056 extern int cma_for_each_area(int (*it)(struct cma *cma, void *data), void *data);
0057 
0058 extern void cma_reserve_pages_on_error(struct cma *cma);
0059 #endif