diff options
Diffstat (limited to 'include/asm-generic')
-rw-r--r-- | include/asm-generic/futex.h | 6 | ||||
-rw-r--r-- | include/asm-generic/local.h | 80 | ||||
-rw-r--r-- | include/asm-generic/memory_model.h | 77 | ||||
-rw-r--r-- | include/asm-generic/percpu.h | 2 |
4 files changed, 93 insertions, 72 deletions
diff --git a/include/asm-generic/futex.h b/include/asm-generic/futex.h index 3ae2c7347549..df893c160318 100644 --- a/include/asm-generic/futex.h +++ b/include/asm-generic/futex.h | |||
@@ -49,5 +49,11 @@ futex_atomic_op_inuser (int encoded_op, int __user *uaddr) | |||
49 | return ret; | 49 | return ret; |
50 | } | 50 | } |
51 | 51 | ||
52 | static inline int | ||
53 | futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, int newval) | ||
54 | { | ||
55 | return -ENOSYS; | ||
56 | } | ||
57 | |||
52 | #endif | 58 | #endif |
53 | #endif | 59 | #endif |
diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h index 16fc00360f75..de4614840c2c 100644 --- a/include/asm-generic/local.h +++ b/include/asm-generic/local.h | |||
@@ -4,28 +4,28 @@ | |||
4 | #include <linux/config.h> | 4 | #include <linux/config.h> |
5 | #include <linux/percpu.h> | 5 | #include <linux/percpu.h> |
6 | #include <linux/hardirq.h> | 6 | #include <linux/hardirq.h> |
7 | #include <asm/atomic.h> | ||
7 | #include <asm/types.h> | 8 | #include <asm/types.h> |
8 | 9 | ||
9 | /* An unsigned long type for operations which are atomic for a single | 10 | /* An unsigned long type for operations which are atomic for a single |
10 | * CPU. Usually used in combination with per-cpu variables. */ | 11 | * CPU. Usually used in combination with per-cpu variables. */ |
11 | 12 | ||
12 | #if BITS_PER_LONG == 32 | ||
13 | /* Implement in terms of atomics. */ | 13 | /* Implement in terms of atomics. */ |
14 | 14 | ||
15 | /* Don't use typedef: don't want them to be mixed with atomic_t's. */ | 15 | /* Don't use typedef: don't want them to be mixed with atomic_t's. */ |
16 | typedef struct | 16 | typedef struct |
17 | { | 17 | { |
18 | atomic_t a; | 18 | atomic_long_t a; |
19 | } local_t; | 19 | } local_t; |
20 | 20 | ||
21 | #define LOCAL_INIT(i) { ATOMIC_INIT(i) } | 21 | #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) } |
22 | 22 | ||
23 | #define local_read(l) ((unsigned long)atomic_read(&(l)->a)) | 23 | #define local_read(l) ((unsigned long)atomic_long_read(&(l)->a)) |
24 | #define local_set(l,i) atomic_set((&(l)->a),(i)) | 24 | #define local_set(l,i) atomic_long_set((&(l)->a),(i)) |
25 | #define local_inc(l) atomic_inc(&(l)->a) | 25 | #define local_inc(l) atomic_long_inc(&(l)->a) |
26 | #define local_dec(l) atomic_dec(&(l)->a) | 26 | #define local_dec(l) atomic_long_dec(&(l)->a) |
27 | #define local_add(i,l) atomic_add((i),(&(l)->a)) | 27 | #define local_add(i,l) atomic_long_add((i),(&(l)->a)) |
28 | #define local_sub(i,l) atomic_sub((i),(&(l)->a)) | 28 | #define local_sub(i,l) atomic_long_sub((i),(&(l)->a)) |
29 | 29 | ||
30 | /* Non-atomic variants, ie. preemption disabled and won't be touched | 30 | /* Non-atomic variants, ie. preemption disabled and won't be touched |
31 | * in interrupt, etc. Some archs can optimize this case well. */ | 31 | * in interrupt, etc. Some archs can optimize this case well. */ |
@@ -34,68 +34,6 @@ typedef struct | |||
34 | #define __local_add(i,l) local_set((l), local_read(l) + (i)) | 34 | #define __local_add(i,l) local_set((l), local_read(l) + (i)) |
35 | #define __local_sub(i,l) local_set((l), local_read(l) - (i)) | 35 | #define __local_sub(i,l) local_set((l), local_read(l) - (i)) |
36 | 36 | ||
37 | #else /* ... can't use atomics. */ | ||
38 | /* Implement in terms of three variables. | ||
39 | Another option would be to use local_irq_save/restore. */ | ||
40 | |||
41 | typedef struct | ||
42 | { | ||
43 | /* 0 = in hardirq, 1 = in softirq, 2 = usermode. */ | ||
44 | unsigned long v[3]; | ||
45 | } local_t; | ||
46 | |||
47 | #define _LOCAL_VAR(l) ((l)->v[!in_interrupt() + !in_irq()]) | ||
48 | |||
49 | #define LOCAL_INIT(i) { { (i), 0, 0 } } | ||
50 | |||
51 | static inline unsigned long local_read(local_t *l) | ||
52 | { | ||
53 | return l->v[0] + l->v[1] + l->v[2]; | ||
54 | } | ||
55 | |||
56 | static inline void local_set(local_t *l, unsigned long v) | ||
57 | { | ||
58 | l->v[0] = v; | ||
59 | l->v[1] = l->v[2] = 0; | ||
60 | } | ||
61 | |||
62 | static inline void local_inc(local_t *l) | ||
63 | { | ||
64 | preempt_disable(); | ||
65 | _LOCAL_VAR(l)++; | ||
66 | preempt_enable(); | ||
67 | } | ||
68 | |||
69 | static inline void local_dec(local_t *l) | ||
70 | { | ||
71 | preempt_disable(); | ||
72 | _LOCAL_VAR(l)--; | ||
73 | preempt_enable(); | ||
74 | } | ||
75 | |||
76 | static inline void local_add(unsigned long v, local_t *l) | ||
77 | { | ||
78 | preempt_disable(); | ||
79 | _LOCAL_VAR(l) += v; | ||
80 | preempt_enable(); | ||
81 | } | ||
82 | |||
83 | static inline void local_sub(unsigned long v, local_t *l) | ||
84 | { | ||
85 | preempt_disable(); | ||
86 | _LOCAL_VAR(l) -= v; | ||
87 | preempt_enable(); | ||
88 | } | ||
89 | |||
90 | /* Non-atomic variants, ie. preemption disabled and won't be touched | ||
91 | * in interrupt, etc. Some archs can optimize this case well. */ | ||
92 | #define __local_inc(l) ((l)->v[0]++) | ||
93 | #define __local_dec(l) ((l)->v[0]--) | ||
94 | #define __local_add(i,l) ((l)->v[0] += (i)) | ||
95 | #define __local_sub(i,l) ((l)->v[0] -= (i)) | ||
96 | |||
97 | #endif /* Non-atomic implementation */ | ||
98 | |||
99 | /* Use these for per-cpu local_t variables: on some archs they are | 37 | /* Use these for per-cpu local_t variables: on some archs they are |
100 | * much more efficient than these naive implementations. Note they take | 38 | * much more efficient than these naive implementations. Note they take |
101 | * a variable (eg. mystruct.foo), not an address. | 39 | * a variable (eg. mystruct.foo), not an address. |
diff --git a/include/asm-generic/memory_model.h b/include/asm-generic/memory_model.h new file mode 100644 index 000000000000..0cfb086dd373 --- /dev/null +++ b/include/asm-generic/memory_model.h | |||
@@ -0,0 +1,77 @@ | |||
1 | #ifndef __ASM_MEMORY_MODEL_H | ||
2 | #define __ASM_MEMORY_MODEL_H | ||
3 | |||
4 | #ifdef __KERNEL__ | ||
5 | #ifndef __ASSEMBLY__ | ||
6 | |||
7 | #if defined(CONFIG_FLATMEM) | ||
8 | |||
9 | #ifndef ARCH_PFN_OFFSET | ||
10 | #define ARCH_PFN_OFFSET (0UL) | ||
11 | #endif | ||
12 | |||
13 | #elif defined(CONFIG_DISCONTIGMEM) | ||
14 | |||
15 | #ifndef arch_pfn_to_nid | ||
16 | #define arch_pfn_to_nid(pfn) pfn_to_nid(pfn) | ||
17 | #endif | ||
18 | |||
19 | #ifndef arch_local_page_offset | ||
20 | #define arch_local_page_offset(pfn, nid) \ | ||
21 | ((pfn) - NODE_DATA(nid)->node_start_pfn) | ||
22 | #endif | ||
23 | |||
24 | #endif /* CONFIG_DISCONTIGMEM */ | ||
25 | |||
26 | #ifdef CONFIG_OUT_OF_LINE_PFN_TO_PAGE | ||
27 | struct page; | ||
28 | /* this is useful when inlined pfn_to_page is too big */ | ||
29 | extern struct page *pfn_to_page(unsigned long pfn); | ||
30 | extern unsigned long page_to_pfn(struct page *page); | ||
31 | #else | ||
32 | /* | ||
33 | * supports 3 memory models. | ||
34 | */ | ||
35 | #if defined(CONFIG_FLATMEM) | ||
36 | |||
37 | #define pfn_to_page(pfn) (mem_map + ((pfn) - ARCH_PFN_OFFSET)) | ||
38 | #define page_to_pfn(page) ((unsigned long)((page) - mem_map) + \ | ||
39 | ARCH_PFN_OFFSET) | ||
40 | #elif defined(CONFIG_DISCONTIGMEM) | ||
41 | |||
42 | #define pfn_to_page(pfn) \ | ||
43 | ({ unsigned long __pfn = (pfn); \ | ||
44 | unsigned long __nid = arch_pfn_to_nid(pfn); \ | ||
45 | NODE_DATA(__nid)->node_mem_map + arch_local_page_offset(__pfn, __nid);\ | ||
46 | }) | ||
47 | |||
48 | #define page_to_pfn(pg) \ | ||
49 | ({ struct page *__pg = (pg); \ | ||
50 | struct pglist_data *__pgdat = NODE_DATA(page_to_nid(__pg)); \ | ||
51 | (unsigned long)(__pg - __pgdat->node_mem_map) + \ | ||
52 | __pgdat->node_start_pfn; \ | ||
53 | }) | ||
54 | |||
55 | #elif defined(CONFIG_SPARSEMEM) | ||
56 | /* | ||
57 | * Note: section's mem_map is encorded to reflect its start_pfn. | ||
58 | * section[i].section_mem_map == mem_map's address - start_pfn; | ||
59 | */ | ||
60 | #define page_to_pfn(pg) \ | ||
61 | ({ struct page *__pg = (pg); \ | ||
62 | int __sec = page_to_section(__pg); \ | ||
63 | __pg - __section_mem_map_addr(__nr_to_section(__sec)); \ | ||
64 | }) | ||
65 | |||
66 | #define pfn_to_page(pfn) \ | ||
67 | ({ unsigned long __pfn = (pfn); \ | ||
68 | struct mem_section *__sec = __pfn_to_section(__pfn); \ | ||
69 | __section_mem_map_addr(__sec) + __pfn; \ | ||
70 | }) | ||
71 | #endif /* CONFIG_FLATMEM/DISCONTIGMEM/SPARSEMEM */ | ||
72 | #endif /* CONFIG_OUT_OF_LINE_PFN_TO_PAGE */ | ||
73 | |||
74 | #endif /* __ASSEMBLY__ */ | ||
75 | #endif /* __KERNEL__ */ | ||
76 | |||
77 | #endif | ||
diff --git a/include/asm-generic/percpu.h b/include/asm-generic/percpu.h index 78cf45547e31..c0caf433a7d7 100644 --- a/include/asm-generic/percpu.h +++ b/include/asm-generic/percpu.h | |||
@@ -19,7 +19,7 @@ extern unsigned long __per_cpu_offset[NR_CPUS]; | |||
19 | #define percpu_modcopy(pcpudst, src, size) \ | 19 | #define percpu_modcopy(pcpudst, src, size) \ |
20 | do { \ | 20 | do { \ |
21 | unsigned int __i; \ | 21 | unsigned int __i; \ |
22 | for_each_cpu(__i) \ | 22 | for_each_possible_cpu(__i) \ |
23 | memcpy((pcpudst)+__per_cpu_offset[__i], \ | 23 | memcpy((pcpudst)+__per_cpu_offset[__i], \ |
24 | (src), (size)); \ | 24 | (src), (size)); \ |
25 | } while (0) | 25 | } while (0) |