1#ifndef __LINUX_PERCPU_H
2#define __LINUX_PERCPU_H
3
4#include <linux/mmdebug.h>
5#include <linux/preempt.h>
6#include <linux/smp.h>
7#include <linux/cpumask.h>
8#include <linux/printk.h>
9#include <linux/pfn.h>
10#include <linux/init.h>
11
12#include <asm/percpu.h>
13
14
15#ifdef CONFIG_MODULES
16#define PERCPU_MODULE_RESERVE (8 << 10)
17#else
18#define PERCPU_MODULE_RESERVE 0
19#endif
20
21
22#define PCPU_MIN_UNIT_SIZE PFN_ALIGN(32 << 10)
23
24
25
26
27
28
29
30
31#define PERCPU_DYNAMIC_EARLY_SLOTS 128
32#define PERCPU_DYNAMIC_EARLY_SIZE (12 << 10)
33
34
35
36
37
38
39
40
41
42
43
44
45#if BITS_PER_LONG > 32
46#define PERCPU_DYNAMIC_RESERVE (28 << 10)
47#else
48#define PERCPU_DYNAMIC_RESERVE (20 << 10)
49#endif
50
51extern void *pcpu_base_addr;
52extern const unsigned long *pcpu_unit_offsets;
53
54struct pcpu_group_info {
55 int nr_units;
56 unsigned long base_offset;
57 unsigned int *cpu_map;
58
59};
60
61struct pcpu_alloc_info {
62 size_t static_size;
63 size_t reserved_size;
64 size_t dyn_size;
65 size_t unit_size;
66 size_t atom_size;
67 size_t alloc_size;
68 size_t __ai_size;
69 int nr_groups;
70 struct pcpu_group_info groups[];
71};
72
73enum pcpu_fc {
74 PCPU_FC_AUTO,
75 PCPU_FC_EMBED,
76 PCPU_FC_PAGE,
77
78 PCPU_FC_NR,
79};
80extern const char * const pcpu_fc_names[PCPU_FC_NR];
81
82extern enum pcpu_fc pcpu_chosen_fc;
83
84typedef void * (*pcpu_fc_alloc_fn_t)(unsigned int cpu, size_t size,
85 size_t align);
86typedef void (*pcpu_fc_free_fn_t)(void *ptr, size_t size);
87typedef void (*pcpu_fc_populate_pte_fn_t)(unsigned long addr);
88typedef int (pcpu_fc_cpu_distance_fn_t)(unsigned int from, unsigned int to);
89
90extern struct pcpu_alloc_info * __init pcpu_alloc_alloc_info(int nr_groups,
91 int nr_units);
92extern void __init pcpu_free_alloc_info(struct pcpu_alloc_info *ai);
93
94extern int __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai,
95 void *base_addr);
96
97#ifdef CONFIG_NEED_PER_CPU_EMBED_FIRST_CHUNK
98extern int __init pcpu_embed_first_chunk(size_t reserved_size, size_t dyn_size,
99 size_t atom_size,
100 pcpu_fc_cpu_distance_fn_t cpu_distance_fn,
101 pcpu_fc_alloc_fn_t alloc_fn,
102 pcpu_fc_free_fn_t free_fn);
103#endif
104
105#ifdef CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK
106extern int __init pcpu_page_first_chunk(size_t reserved_size,
107 pcpu_fc_alloc_fn_t alloc_fn,
108 pcpu_fc_free_fn_t free_fn,
109 pcpu_fc_populate_pte_fn_t populate_pte_fn);
110#endif
111
112extern void __percpu *__alloc_reserved_percpu(size_t size, size_t align);
113extern bool is_kernel_percpu_address(unsigned long addr);
114
115#if !defined(CONFIG_SMP) || !defined(CONFIG_HAVE_SETUP_PER_CPU_AREA)
116extern void __init setup_per_cpu_areas(void);
117#endif
118extern void __init percpu_init_late(void);
119
120extern void __percpu *__alloc_percpu_gfp(size_t size, size_t align, gfp_t gfp);
121extern void __percpu *__alloc_percpu(size_t size, size_t align);
122extern void free_percpu(void __percpu *__pdata);
123extern phys_addr_t per_cpu_ptr_to_phys(void *addr);
124
125#define alloc_percpu_gfp(type, gfp) \
126 (typeof(type) __percpu *)__alloc_percpu_gfp(sizeof(type), \
127 __alignof__(type), gfp)
128#define alloc_percpu(type) \
129 (typeof(type) __percpu *)__alloc_percpu(sizeof(type), \
130 __alignof__(type))
131
132
133DECLARE_PER_CPU(printk_func_t, printk_func);
134
135#endif
136