aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Ellerman <michael@ellerman.id.au>2008-06-23 21:32:54 -0400
committerPaul Mackerras <paulus@samba.org>2008-06-30 21:28:28 -0400
commitfac23fe4be23259a8eaa9bad822f5b14dd07d15c (patch)
tree23979268a5b893d676bba2bdb514307d5417ea56
parentc1137c37a9370f510dc022e6e95fff036ccb90be (diff)
powerpc: Introduce infrastructure for feature sections with alternatives
The current feature section logic only supports nop'ing out code, this means if you want to choose at runtime between instruction sequences, one or both cases will have to execute the nop'ed out contents of the other section, eg: BEGIN_FTR_SECTION or 1,1,1 END_FTR_SECTION_IFSET(FOO) BEGIN_FTR_SECTION or 2,2,2 END_FTR_SECTION_IFCLR(FOO) and the resulting code will be either, or 1,1,1 nop or, nop or 2,2,2 For small code segments this is fine, but for larger code blocks and in performance criticial code segments, it would be nice to avoid the nops. This commit starts to implement logic to allow the following: BEGIN_FTR_SECTION or 1,1,1 FTR_SECTION_ELSE or 2,2,2 ALT_FTR_SECTION_END_IFSET(FOO) and the resulting code will be: or 1,1,1 or, or 2,2,2 We achieve this by extending the existing FTR macros. The current feature section semantic just becomes a special case, ie. if the else case is empty we nop out the default case. The key limitation is that the size of the else case must be less than or equal to the size of the default case. If the else case is smaller the remainder of the section is nop'ed. We let the linker put the else case code in with the rest of the text, so that relative branches from the else case are more likley to link, this has the disadvantage that we can't free the unused else cases. This commit introduces the required macro and linker script changes, but does not enable the patching of the alternative sections. We also need to update two hand-made section entries in reg.h and timex.h Signed-off-by: Michael Ellerman <michael@ellerman.id.au> Signed-off-by: Paul Mackerras <paulus@samba.org>
-rw-r--r--arch/powerpc/kernel/vdso32/vdso32.lds.S2
-rw-r--r--arch/powerpc/kernel/vdso64/vdso64.lds.S2
-rw-r--r--arch/powerpc/kernel/vmlinux.lds.S2
-rw-r--r--arch/powerpc/lib/feature-fixups.c2
-rw-r--r--include/asm-powerpc/feature-fixups.h68
-rw-r--r--include/asm-powerpc/reg.h2
-rw-r--r--include/asm-powerpc/timex.h2
7 files changed, 64 insertions, 16 deletions
diff --git a/arch/powerpc/kernel/vdso32/vdso32.lds.S b/arch/powerpc/kernel/vdso32/vdso32.lds.S
index 9352ab5200e5..271793577cdc 100644
--- a/arch/powerpc/kernel/vdso32/vdso32.lds.S
+++ b/arch/powerpc/kernel/vdso32/vdso32.lds.S
@@ -24,7 +24,7 @@ SECTIONS
24 24
25 . = ALIGN(16); 25 . = ALIGN(16);
26 .text : { 26 .text : {
27 *(.text .stub .text.* .gnu.linkonce.t.*) 27 *(.text .stub .text.* .gnu.linkonce.t.* __ftr_alt_*)
28 } 28 }
29 PROVIDE(__etext = .); 29 PROVIDE(__etext = .);
30 PROVIDE(_etext = .); 30 PROVIDE(_etext = .);
diff --git a/arch/powerpc/kernel/vdso64/vdso64.lds.S b/arch/powerpc/kernel/vdso64/vdso64.lds.S
index 7d6585f90277..e608d1bd3bff 100644
--- a/arch/powerpc/kernel/vdso64/vdso64.lds.S
+++ b/arch/powerpc/kernel/vdso64/vdso64.lds.S
@@ -24,7 +24,7 @@ SECTIONS
24 24
25 . = ALIGN(16); 25 . = ALIGN(16);
26 .text : { 26 .text : {
27 *(.text .stub .text.* .gnu.linkonce.t.*) 27 *(.text .stub .text.* .gnu.linkonce.t.* __ftr_alt_*)
28 *(.sfpr .glink) 28 *(.sfpr .glink)
29 } :text 29 } :text
30 PROVIDE(__etext = .); 30 PROVIDE(__etext = .);
diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
index 0c3000bf8d75..3c07811989fc 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -35,7 +35,7 @@ SECTIONS
35 ALIGN_FUNCTION(); 35 ALIGN_FUNCTION();
36 *(.text.head) 36 *(.text.head)
37 _text = .; 37 _text = .;
38 *(.text .fixup .text.init.refok .exit.text.refok) 38 *(.text .fixup .text.init.refok .exit.text.refok __ftr_alt_*)
39 SCHED_TEXT 39 SCHED_TEXT
40 LOCK_TEXT 40 LOCK_TEXT
41 KPROBES_TEXT 41 KPROBES_TEXT
diff --git a/arch/powerpc/lib/feature-fixups.c b/arch/powerpc/lib/feature-fixups.c
index f6fd5d2ff10d..973d547ef01d 100644
--- a/arch/powerpc/lib/feature-fixups.c
+++ b/arch/powerpc/lib/feature-fixups.c
@@ -22,6 +22,8 @@ struct fixup_entry {
22 unsigned long value; 22 unsigned long value;
23 long start_off; 23 long start_off;
24 long end_off; 24 long end_off;
25 long alt_start_off;
26 long alt_end_off;
25}; 27};
26 28
27static void patch_feature_section(unsigned long value, struct fixup_entry *fcur) 29static void patch_feature_section(unsigned long value, struct fixup_entry *fcur)
diff --git a/include/asm-powerpc/feature-fixups.h b/include/asm-powerpc/feature-fixups.h
index 35f927888fe8..ab30129dced7 100644
--- a/include/asm-powerpc/feature-fixups.h
+++ b/include/asm-powerpc/feature-fixups.h
@@ -29,24 +29,35 @@
29#define FTR_ENTRY_OFFSET PPC_LONG 29#define FTR_ENTRY_OFFSET PPC_LONG
30#endif 30#endif
31 31
32#define START_FTR_SECTION(label) label##1:
33
34#define FTR_SECTION_ELSE_NESTED(label) \
35label##2: \
36 .pushsection __ftr_alt_##label,"a"; \
37 .align 2; \
38label##3:
39
32#define MAKE_FTR_SECTION_ENTRY(msk, val, label, sect) \ 40#define MAKE_FTR_SECTION_ENTRY(msk, val, label, sect) \
3399: \ 41label##4: \
34 .section sect,"a"; \ 42 .popsection; \
43 .pushsection sect,"a"; \
35 .align 3; \ 44 .align 3; \
3698: \ 45label##5: \
37 FTR_ENTRY_LONG msk; \ 46 FTR_ENTRY_LONG msk; \
38 FTR_ENTRY_LONG val; \ 47 FTR_ENTRY_LONG val; \
39 FTR_ENTRY_OFFSET label##b-98b; \ 48 FTR_ENTRY_OFFSET label##1b-label##5b; \
40 FTR_ENTRY_OFFSET 99b-98b; \ 49 FTR_ENTRY_OFFSET label##2b-label##5b; \
41 .previous 50 FTR_ENTRY_OFFSET label##3b-label##5b; \
42 51 FTR_ENTRY_OFFSET label##4b-label##5b; \
52 .popsection;
43 53
44 54
45/* CPU feature dependent sections */ 55/* CPU feature dependent sections */
46#define BEGIN_FTR_SECTION_NESTED(label) label: 56#define BEGIN_FTR_SECTION_NESTED(label) START_FTR_SECTION(label)
47#define BEGIN_FTR_SECTION BEGIN_FTR_SECTION_NESTED(97) 57#define BEGIN_FTR_SECTION START_FTR_SECTION(97)
48 58
49#define END_FTR_SECTION_NESTED(msk, val, label) \ 59#define END_FTR_SECTION_NESTED(msk, val, label) \
60 FTR_SECTION_ELSE_NESTED(label) \
50 MAKE_FTR_SECTION_ENTRY(msk, val, label, __ftr_fixup) 61 MAKE_FTR_SECTION_ENTRY(msk, val, label, __ftr_fixup)
51 62
52#define END_FTR_SECTION(msk, val) \ 63#define END_FTR_SECTION(msk, val) \
@@ -55,12 +66,27 @@
55#define END_FTR_SECTION_IFSET(msk) END_FTR_SECTION((msk), (msk)) 66#define END_FTR_SECTION_IFSET(msk) END_FTR_SECTION((msk), (msk))
56#define END_FTR_SECTION_IFCLR(msk) END_FTR_SECTION((msk), 0) 67#define END_FTR_SECTION_IFCLR(msk) END_FTR_SECTION((msk), 0)
57 68
69/* CPU feature sections with alternatives, use BEGIN_FTR_SECTION to start */
70#define FTR_SECTION_ELSE FTR_SECTION_ELSE_NESTED(97)
71#define ALT_FTR_SECTION_END_NESTED(msk, val, label) \
72 MAKE_FTR_SECTION_ENTRY(msk, val, label, __ftr_fixup)
73#define ALT_FTR_SECTION_END_NESTED_IFSET(msk, label) \
74 ALT_FTR_SECTION_END_NESTED(msk, msk, label)
75#define ALT_FTR_SECTION_END_NESTED_IFCLR(msk, label) \
76 ALT_FTR_SECTION_END_NESTED(msk, 0, label)
77#define ALT_FTR_SECTION_END(msk, val) \
78 ALT_FTR_SECTION_END_NESTED(msk, val, 97)
79#define ALT_FTR_SECTION_END_IFSET(msk) \
80 ALT_FTR_SECTION_END_NESTED_IFSET(msk, 97)
81#define ALT_FTR_SECTION_END_IFCLR(msk) \
82 ALT_FTR_SECTION_END_NESTED_IFCLR(msk, 97)
58 83
59/* Firmware feature dependent sections */ 84/* Firmware feature dependent sections */
60#define BEGIN_FW_FTR_SECTION_NESTED(label) label: 85#define BEGIN_FW_FTR_SECTION_NESTED(label) START_FTR_SECTION(label)
61#define BEGIN_FW_FTR_SECTION BEGIN_FW_FTR_SECTION_NESTED(97) 86#define BEGIN_FW_FTR_SECTION START_FTR_SECTION(97)
62 87
63#define END_FW_FTR_SECTION_NESTED(msk, val, label) \ 88#define END_FW_FTR_SECTION_NESTED(msk, val, label) \
89 FTR_SECTION_ELSE_NESTED(label) \
64 MAKE_FTR_SECTION_ENTRY(msk, val, label, __fw_ftr_fixup) 90 MAKE_FTR_SECTION_ENTRY(msk, val, label, __fw_ftr_fixup)
65 91
66#define END_FW_FTR_SECTION(msk, val) \ 92#define END_FW_FTR_SECTION(msk, val) \
@@ -69,6 +95,22 @@
69#define END_FW_FTR_SECTION_IFSET(msk) END_FW_FTR_SECTION((msk), (msk)) 95#define END_FW_FTR_SECTION_IFSET(msk) END_FW_FTR_SECTION((msk), (msk))
70#define END_FW_FTR_SECTION_IFCLR(msk) END_FW_FTR_SECTION((msk), 0) 96#define END_FW_FTR_SECTION_IFCLR(msk) END_FW_FTR_SECTION((msk), 0)
71 97
98/* Firmware feature sections with alternatives */
99#define FW_FTR_SECTION_ELSE_NESTED(label) FTR_SECTION_ELSE_NESTED(label)
100#define FW_FTR_SECTION_ELSE FTR_SECTION_ELSE_NESTED(97)
101#define ALT_FW_FTR_SECTION_END_NESTED(msk, val, label) \
102 MAKE_FTR_SECTION_ENTRY(msk, val, label, __fw_ftr_fixup)
103#define ALT_FW_FTR_SECTION_END_NESTED_IFSET(msk, label) \
104 ALT_FW_FTR_SECTION_END_NESTED(msk, msk, label)
105#define ALT_FW_FTR_SECTION_END_NESTED_IFCLR(msk, label) \
106 ALT_FW_FTR_SECTION_END_NESTED(msk, 0, label)
107#define ALT_FW_FTR_SECTION_END(msk, val) \
108 ALT_FW_FTR_SECTION_END_NESTED(msk, val, 97)
109#define ALT_FW_FTR_SECTION_END_IFSET(msk) \
110 ALT_FW_FTR_SECTION_END_NESTED_IFSET(msk, 97)
111#define ALT_FW_FTR_SECTION_END_IFCLR(msk) \
112 ALT_FW_FTR_SECTION_END_NESTED_IFCLR(msk, 97)
113
72#endif /* __ASSEMBLY__ */ 114#endif /* __ASSEMBLY__ */
73 115
74#endif /* __ASM_POWERPC_FEATURE_FIXUPS_H */ 116#endif /* __ASM_POWERPC_FEATURE_FIXUPS_H */
diff --git a/include/asm-powerpc/reg.h b/include/asm-powerpc/reg.h
index 079999b032af..7256efb5c140 100644
--- a/include/asm-powerpc/reg.h
+++ b/include/asm-powerpc/reg.h
@@ -732,6 +732,8 @@
732 " .llong %1\n" \ 732 " .llong %1\n" \
733 " .llong 97b-98b\n" \ 733 " .llong 97b-98b\n" \
734 " .llong 99b-98b\n" \ 734 " .llong 99b-98b\n" \
735 " .llong 0\n" \
736 " .llong 0\n" \
735 ".previous" \ 737 ".previous" \
736 : "=r" (rval) : "i" (CPU_FTR_CELL_TB_BUG)); rval;}) 738 : "=r" (rval) : "i" (CPU_FTR_CELL_TB_BUG)); rval;})
737#else 739#else
diff --git a/include/asm-powerpc/timex.h b/include/asm-powerpc/timex.h
index 92dedde761d1..c55e14f7ef44 100644
--- a/include/asm-powerpc/timex.h
+++ b/include/asm-powerpc/timex.h
@@ -38,6 +38,8 @@ static inline cycles_t get_cycles(void)
38 " .long 0\n" 38 " .long 0\n"
39 " .long 97b-98b\n" 39 " .long 97b-98b\n"
40 " .long 99b-98b\n" 40 " .long 99b-98b\n"
41 " .long 0\n"
42 " .long 0\n"
41 ".previous" 43 ".previous"
42 : "=r" (ret) : "i" (CPU_FTR_601)); 44 : "=r" (ret) : "i" (CPU_FTR_601));
43 return ret; 45 return ret;