0001
0002 #ifndef __LINUX_PERCPU_H
0003 #define __LINUX_PERCPU_H
0004
0005 #include <linux/mmdebug.h>
0006 #include <linux/preempt.h>
0007 #include <linux/smp.h>
0008 #include <linux/cpumask.h>
0009 #include <linux/pfn.h>
0010 #include <linux/init.h>
0011
0012 #include <asm/percpu.h>
0013
0014
0015 #ifdef CONFIG_MODULES
0016 #define PERCPU_MODULE_RESERVE (8 << 10)
0017 #else
0018 #define PERCPU_MODULE_RESERVE 0
0019 #endif
0020
0021
0022 #define PCPU_MIN_UNIT_SIZE PFN_ALIGN(32 << 10)
0023
0024
0025 #define PCPU_MIN_ALLOC_SHIFT 2
0026 #define PCPU_MIN_ALLOC_SIZE (1 << PCPU_MIN_ALLOC_SHIFT)
0027
0028
0029
0030
0031
0032
0033 #define PCPU_BITMAP_BLOCK_SIZE PAGE_SIZE
0034 #define PCPU_BITMAP_BLOCK_BITS (PCPU_BITMAP_BLOCK_SIZE >> \
0035 PCPU_MIN_ALLOC_SHIFT)
0036
0037
0038
0039
0040
0041
0042
0043
0044 #define PERCPU_DYNAMIC_EARLY_SLOTS 128
0045 #define PERCPU_DYNAMIC_EARLY_SIZE (12 << 10)
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058 #if BITS_PER_LONG > 32
0059 #define PERCPU_DYNAMIC_RESERVE (28 << 10)
0060 #else
0061 #define PERCPU_DYNAMIC_RESERVE (20 << 10)
0062 #endif
0063
0064 extern void *pcpu_base_addr;
0065 extern const unsigned long *pcpu_unit_offsets;
0066
0067 struct pcpu_group_info {
0068 int nr_units;
0069 unsigned long base_offset;
0070 unsigned int *cpu_map;
0071
0072 };
0073
0074 struct pcpu_alloc_info {
0075 size_t static_size;
0076 size_t reserved_size;
0077 size_t dyn_size;
0078 size_t unit_size;
0079 size_t atom_size;
0080 size_t alloc_size;
0081 size_t __ai_size;
0082 int nr_groups;
0083 struct pcpu_group_info groups[];
0084 };
0085
0086 enum pcpu_fc {
0087 PCPU_FC_AUTO,
0088 PCPU_FC_EMBED,
0089 PCPU_FC_PAGE,
0090
0091 PCPU_FC_NR,
0092 };
0093 extern const char * const pcpu_fc_names[PCPU_FC_NR];
0094
0095 extern enum pcpu_fc pcpu_chosen_fc;
0096
0097 typedef int (pcpu_fc_cpu_to_node_fn_t)(int cpu);
0098 typedef int (pcpu_fc_cpu_distance_fn_t)(unsigned int from, unsigned int to);
0099
0100 extern struct pcpu_alloc_info * __init pcpu_alloc_alloc_info(int nr_groups,
0101 int nr_units);
0102 extern void __init pcpu_free_alloc_info(struct pcpu_alloc_info *ai);
0103
0104 extern void __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai,
0105 void *base_addr);
0106
0107 #ifdef CONFIG_NEED_PER_CPU_EMBED_FIRST_CHUNK
0108 extern int __init pcpu_embed_first_chunk(size_t reserved_size, size_t dyn_size,
0109 size_t atom_size,
0110 pcpu_fc_cpu_distance_fn_t cpu_distance_fn,
0111 pcpu_fc_cpu_to_node_fn_t cpu_to_nd_fn);
0112 #endif
0113
0114 #ifdef CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK
0115 void __init pcpu_populate_pte(unsigned long addr);
0116 extern int __init pcpu_page_first_chunk(size_t reserved_size,
0117 pcpu_fc_cpu_to_node_fn_t cpu_to_nd_fn);
0118 #endif
0119
0120 extern void __percpu *__alloc_reserved_percpu(size_t size, size_t align) __alloc_size(1);
0121 extern bool __is_kernel_percpu_address(unsigned long addr, unsigned long *can_addr);
0122 extern bool is_kernel_percpu_address(unsigned long addr);
0123
0124 #if !defined(CONFIG_SMP) || !defined(CONFIG_HAVE_SETUP_PER_CPU_AREA)
0125 extern void __init setup_per_cpu_areas(void);
0126 #endif
0127
0128 extern void __percpu *__alloc_percpu_gfp(size_t size, size_t align, gfp_t gfp) __alloc_size(1);
0129 extern void __percpu *__alloc_percpu(size_t size, size_t align) __alloc_size(1);
0130 extern void free_percpu(void __percpu *__pdata);
0131 extern phys_addr_t per_cpu_ptr_to_phys(void *addr);
0132
0133 #define alloc_percpu_gfp(type, gfp) \
0134 (typeof(type) __percpu *)__alloc_percpu_gfp(sizeof(type), \
0135 __alignof__(type), gfp)
0136 #define alloc_percpu(type) \
0137 (typeof(type) __percpu *)__alloc_percpu(sizeof(type), \
0138 __alignof__(type))
0139
0140 extern unsigned long pcpu_nr_pages(void);
0141
0142 #endif