blob: 1526fe712ca0368e73e0c0659b65baec7a4ddf42 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _LINUX_VMALLOC_H
2#define _LINUX_VMALLOC_H
3
4#include <linux/spinlock.h>
Nick Piggindb64fe02008-10-18 20:27:03 -07005#include <linux/init.h>
Atsushi Kumagai13ba3fc2013-04-29 15:07:40 -07006#include <linux/list.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <asm/page.h> /* pgprot_t */
Atsushi Kumagai13ba3fc2013-04-29 15:07:40 -07008#include <linux/rbtree.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
Hugh Dickins605d9282008-08-16 11:07:21 +010010struct vm_area_struct; /* vma defining user mapping in mm_types.h */
Nick Piggin83342312006-06-23 02:03:20 -070011
Hugh Dickins605d9282008-08-16 11:07:21 +010012/* bits in flags of vmalloc's vm_struct below */
Zhang Yanfei20fc02b2013-07-08 15:59:58 -070013#define VM_IOREMAP 0x00000001 /* ioremap() and friends */
14#define VM_ALLOC 0x00000002 /* vmalloc() */
15#define VM_MAP 0x00000004 /* vmap()ed pages */
16#define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
17#define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
18#define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
Andrey Ryabinin71394fe2015-02-13 14:40:03 -080019#define VM_NO_GUARD 0x00000040 /* don't add guard page */
Linus Torvalds1da177e2005-04-16 15:20:36 -070020/* bits [20..32] reserved for arch specific ioremap internals */
21
Deepak Saxenafd195c42005-09-03 15:54:58 -070022/*
23 * Maximum alignment for ioremap() regions.
24 * Can be overriden by arch-specific value.
25 */
26#ifndef IOREMAP_MAX_ORDER
27#define IOREMAP_MAX_ORDER (7 + PAGE_SHIFT) /* 128 pages */
28#endif
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030struct vm_struct {
Eric Dumazet2b4ac442006-11-10 12:27:48 -080031 struct vm_struct *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 void *addr;
33 unsigned long size;
34 unsigned long flags;
35 struct page **pages;
36 unsigned int nr_pages;
Kenji Kaneshigeffa71f32010-06-18 12:22:40 +090037 phys_addr_t phys_addr;
Marek Szyprowski5e6cafc2012-04-13 12:32:09 +020038 const void *caller;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039};
40
Atsushi Kumagai13ba3fc2013-04-29 15:07:40 -070041struct vmap_area {
42 unsigned long va_start;
43 unsigned long va_end;
44 unsigned long flags;
45 struct rb_node rb_node; /* address sorted rbtree */
46 struct list_head list; /* address sorted list */
47 struct list_head purge_list; /* "lazy purge" list */
48 struct vm_struct *vm;
49 struct rcu_head rcu_head;
50};
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052/*
53 * Highlevel APIs for driver use
54 */
Nick Piggindb64fe02008-10-18 20:27:03 -070055extern void vm_unmap_ram(const void *mem, unsigned int count);
56extern void *vm_map_ram(struct page **pages, unsigned int count,
57 int node, pgprot_t prot);
58extern void vm_unmap_aliases(void);
59
60#ifdef CONFIG_MMU
61extern void __init vmalloc_init(void);
62#else
63static inline void vmalloc_init(void)
64{
65}
66#endif
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068extern void *vmalloc(unsigned long size);
Dave Younge1ca7782010-10-26 14:22:06 -070069extern void *vzalloc(unsigned long size);
Nick Piggin83342312006-06-23 02:03:20 -070070extern void *vmalloc_user(unsigned long size);
Christoph Lameter930fc452005-10-29 18:15:41 -070071extern void *vmalloc_node(unsigned long size, int node);
Dave Younge1ca7782010-10-26 14:22:06 -070072extern void *vzalloc_node(unsigned long size, int node);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073extern void *vmalloc_exec(unsigned long size);
74extern void *vmalloc_32(unsigned long size);
Nick Piggin83342312006-06-23 02:03:20 -070075extern void *vmalloc_32_user(unsigned long size);
Al Virodd0fc662005-10-07 07:46:04 +010076extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
David Rientjesd0a21262011-01-13 15:46:02 -080077extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
78 unsigned long start, unsigned long end, gfp_t gfp_mask,
Marek Szyprowski5e6cafc2012-04-13 12:32:09 +020079 pgprot_t prot, int node, const void *caller);
Christoph Lameterb3bdda02008-02-04 22:28:32 -080080extern void vfree(const void *addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82extern void *vmap(struct page **pages, unsigned int count,
83 unsigned long flags, pgprot_t prot);
Christoph Lameterb3bdda02008-02-04 22:28:32 -080084extern void vunmap(const void *addr);
Nick Piggin83342312006-06-23 02:03:20 -070085
HATAYAMA Daisukee69e9d4a2013-07-03 15:02:18 -070086extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
87 unsigned long uaddr, void *kaddr,
88 unsigned long size);
89
Nick Piggin83342312006-06-23 02:03:20 -070090extern int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
91 unsigned long pgoff);
Christoph Hellwig1eeb66a2007-05-08 00:27:03 -070092void vmalloc_sync_all(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
94/*
95 * Lowlevel-APIs (not for driver use!)
96 */
Jeremy Fitzhardinge95851162007-07-21 17:11:35 +020097
98static inline size_t get_vm_area_size(const struct vm_struct *area)
99{
Andrey Ryabinin71394fe2015-02-13 14:40:03 -0800100 if (!(area->flags & VM_NO_GUARD))
101 /* return actual size without guard page */
102 return area->size - PAGE_SIZE;
103 else
104 return area->size;
105
Jeremy Fitzhardinge95851162007-07-21 17:11:35 +0200106}
107
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108extern struct vm_struct *get_vm_area(unsigned long size, unsigned long flags);
Christoph Lameter23016962008-04-28 02:12:42 -0700109extern struct vm_struct *get_vm_area_caller(unsigned long size,
Marek Szyprowski5e6cafc2012-04-13 12:32:09 +0200110 unsigned long flags, const void *caller);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111extern struct vm_struct *__get_vm_area(unsigned long size, unsigned long flags,
112 unsigned long start, unsigned long end);
Benjamin Herrenschmidtc2968612009-02-18 14:48:12 -0800113extern struct vm_struct *__get_vm_area_caller(unsigned long size,
114 unsigned long flags,
115 unsigned long start, unsigned long end,
Marek Szyprowski5e6cafc2012-04-13 12:32:09 +0200116 const void *caller);
Christoph Lameterb3bdda02008-02-04 22:28:32 -0800117extern struct vm_struct *remove_vm_area(const void *addr);
Marek Szyprowskie9da6e92012-07-30 09:11:33 +0200118extern struct vm_struct *find_vm_area(const void *addr);
Benjamin Herrenschmidtc19c03f2007-06-04 15:15:35 +1000119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120extern int map_vm_area(struct vm_struct *area, pgprot_t prot,
WANG Chaof6f8ed42014-08-06 16:06:58 -0700121 struct page **pages);
Graf Yangb554cb42011-03-28 12:53:29 +0100122#ifdef CONFIG_MMU
Tejun Heo8fc48982009-02-20 16:29:08 +0900123extern int map_kernel_range_noflush(unsigned long start, unsigned long size,
124 pgprot_t prot, struct page **pages);
125extern void unmap_kernel_range_noflush(unsigned long addr, unsigned long size);
Benjamin Herrenschmidtc19c03f2007-06-04 15:15:35 +1000126extern void unmap_kernel_range(unsigned long addr, unsigned long size);
Graf Yangb554cb42011-03-28 12:53:29 +0100127#else
128static inline int
129map_kernel_range_noflush(unsigned long start, unsigned long size,
130 pgprot_t prot, struct page **pages)
131{
132 return size >> PAGE_SHIFT;
133}
134static inline void
135unmap_kernel_range_noflush(unsigned long addr, unsigned long size)
136{
137}
138static inline void
139unmap_kernel_range(unsigned long addr, unsigned long size)
140{
141}
142#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Jeremy Fitzhardinge5f4352f2007-07-17 18:37:04 -0700144/* Allocate/destroy a 'vmalloc' VM area. */
David Vrabelcd129092011-09-29 16:53:32 +0100145extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
Jeremy Fitzhardinge5f4352f2007-07-17 18:37:04 -0700146extern void free_vm_area(struct vm_struct *area);
147
KOSAKI Motohiro69beeb1d2009-01-06 14:39:46 -0800148/* for /dev/kmem */
149extern long vread(char *buf, char *addr, unsigned long count);
150extern long vwrite(char *buf, char *addr, unsigned long count);
151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152/*
153 * Internals. Dont't use..
154 */
Joonsoo Kimf1c40692013-04-29 15:07:37 -0700155extern struct list_head vmap_area_list;
Nicolas Pitrebe9b7332011-08-25 00:24:21 -0400156extern __init void vm_area_add_early(struct vm_struct *vm);
Tejun Heoc0c0a292009-02-24 11:57:21 +0900157extern __init void vm_area_register_early(struct vm_struct *vm, size_t align);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Tejun Heo4f8b02b2010-09-03 18:22:47 +0200159#ifdef CONFIG_SMP
Graf Yangb554cb42011-03-28 12:53:29 +0100160# ifdef CONFIG_MMU
Tejun Heoca23e402009-08-14 15:00:52 +0900161struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
162 const size_t *sizes, int nr_vms,
David Rientjesec3f64f2011-01-13 15:46:01 -0800163 size_t align);
Tejun Heoca23e402009-08-14 15:00:52 +0900164
165void pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms);
Graf Yangb554cb42011-03-28 12:53:29 +0100166# else
167static inline struct vm_struct **
168pcpu_get_vm_areas(const unsigned long *offsets,
169 const size_t *sizes, int nr_vms,
170 size_t align)
171{
172 return NULL;
173}
174
175static inline void
176pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)
177{
178}
179# endif
Tejun Heo4f8b02b2010-09-03 18:22:47 +0200180#endif
Tejun Heoca23e402009-08-14 15:00:52 +0900181
Joonsoo Kimdb3808c2013-04-29 15:07:28 -0700182struct vmalloc_info {
183 unsigned long used;
184 unsigned long largest_chunk;
185};
186
187#ifdef CONFIG_MMU
188#define VMALLOC_TOTAL (VMALLOC_END - VMALLOC_START)
189extern void get_vmalloc_info(struct vmalloc_info *vmi);
190#else
191
192#define VMALLOC_TOTAL 0UL
193#define get_vmalloc_info(vmi) \
194do { \
195 (vmi)->used = 0; \
196 (vmi)->largest_chunk = 0; \
197} while (0)
198#endif
199
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200#endif /* _LINUX_VMALLOC_H */