ARM: fix be8 support for phys/virt address conversion
Subsystems (3)
PATCH 1/6 ARM: fix be8 support for phys/virt address conversion
phys_to_virt() and virt_to_phys() is implemented by one assembler instruction, add/sub an offset between the physical and virtual address. For some arm machines with CONFIG_ARM_PATCH_PHYS_VIRT defined, this offset is unknown at compile time, it is calculated dynamically at run time and then patched to the add/sub instruction. To support BE8 mode, firstly we need to convert the instruntion to big-endian after loading it from the memory, and then modify its offset field, at last convert it to little-endian and write it back to the memory.
--- arch/arm/kernel/head.S | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-)
arch/arm/kernel/head.S +12 -0
@@ -522,8 +522,14 @@ __fixup_a_pv_table: b 2f 1: add r7, r3 ldrh ip, [r7, #2] +#ifdef CONFIG_CPU_ENDIAN_BE8 + rev16 ip, ip +#endif and ip, 0x8f00 orr ip, r6 @ mask in offset bits 31-24 +#ifdef CONFIG_CPU_ENDIAN_BE8 + rev16 ip, ip +#endif strh ip, [r7, #2] 2: cmp r4, r5 ldrcc r7, [r4], #4 @ use branch for delay slot
@@ -532,8 +538,14 @@ __fixup_a_pv_table: #else b 2f 1: ldr ip, [r7, r3] +#ifdef CONFIG_CPU_ENDIAN_BE8 + rev ip, ip +#endif bic ip, ip, #0x000000ff orr ip, ip, r6 @ mask in offset bits 31-24 +#ifdef CONFIG_CPU_ENDIAN_BE8 + rev ip, ip +#endif str ip, [r7, r3] 2: cmp r4, r5 ldrcc r7, [r4], #4 @ use branch for delay slot
Signature · 1 line
1.7.0.4
PATCH 1/6 ARM: fix be8 support for phys/virt address conversion
Hi Russell,
Would you please help to review this patch series?
Great thanks.
Quoted 48 lines · Junxiao Bi
phys_to_virt()andvirt_to_phys()is implemented by one assembler instruction, add/sub an offset between the physical and virtual address. For some arm machines withCONFIG_ARM_PATCH_PHYS_VIRTdefined, this offset is unknown at compile time, it is calculated dynamically at run time and then patched to the add/sub instruction. To support BE8 mode, firstly we need to convert the instruntion to big-endian after loading it from the memory, and then modify its offset field, at last convert it to little-endian and write it back to the memory.Signed-off-by Junxiao Bi<[email protected]>--- arch/arm/kernel/head.S | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-)arch/arm/kernel/head.S +12
-0@@ -522,8 +522,14 @@ __fixup_a_pv_table: b 2f 1: add r7, r3 ldrh ip, [r7, #2] +#ifdef CONFIG_CPU_ENDIAN_BE8 + rev16 ip, ip +#endif and ip, 0x8f00 orr ip, r6 @ mask in offset bits 31-24 +#ifdef CONFIG_CPU_ENDIAN_BE8 + rev16 ip, ip +#endif strh ip, [r7, #2] 2: cmp r4, r5 ldrcc r7, [r4], #4 @ use branch for delay slot@@ -532,8 +538,14 @@ __fixup_a_pv_table: #else b 2f 1: ldr ip, [r7, r3] +#ifdef CONFIG_CPU_ENDIAN_BE8 + rev ip, ip +#endif bic ip, ip, #0x000000ff orr ip, ip, r6 @ mask in offset bits 31-24 +#ifdef CONFIG_CPU_ENDIAN_BE8 + rev ip, ip +#endif str ip, [r7, r3] 2: cmp r4, r5 ldrcc r7, [r4], #4 @ use branch for delay slot
PATCH 2/6 ARM: gic: fix big endian support
In reply to Junxiao BiThe irq state from gic is in little-endian mode. We need do endian conversion for it in big-endian machine. Usually byte swapping of 32-bits word needs 4 assembler instructions for arm machine which arch < 6. But since the high order half word of the irq state is zero, there is a way that can use lesser instrunctions to improve the performance since we only need a bytes swaping of half word. That's what swab16_low_half and swab16_high_half do.
--- arch/arm/include/asm/assembler.h | 27 +++++++++++++++++++++++ arch/arm/include/asm/hardware/entry-macro-gic.S | 7 ++++++ 2 files changed, 34 insertions(+), 0 deletions(-)
arch/arm/include/asm/assembler.h +27 -0
@@ -302,4 +302,31 @@ .size \name , . - \name .endm +/* + * swab16_low_half is used to swap the bytes order of the low order + * half word, it assumes that the high order half word is zero. + * swab16_high_half is used to swap the bytes order of the high order + * half word, it assumes that the low order half word is zero. + */ +#if __LINUX_ARM_ARCH__ >= 6 + .macro swab16_low_half, reg + rev \reg, \reg + .endm + + .macro swab16_high_half, reg + rev \reg, \reg + .endm +#else + .macro swab16_low_half, reg + mov \reg, \reg, ror #8 + orr \reg, \reg, \reg, lsr #16 + bic \reg, \reg, \reg, lsl #16 + .endm + + .macro swab16_high_half, reg + swab16_low_half \reg + mov \reg, \reg, lsl #16 + .endm +#endif + #endif /* __ASM_ASSEMBLER_H__ */
arch/arm/include/asm/hardware/entry-macro-gic.S +7 -0
@@ -9,6 +9,7 @@ */ #include <asm/hardware/gic.h> +#include <asm/assembler.h> #ifndef HAVE_GET_IRQNR_PREAMBLE .macro get_irqnr_preamble, base, tmp
@@ -35,6 +36,9 @@ .macro get_irqnr_and_base, irqnr, irqstat, base, tmp ldr \irqstat, [\base, #GIC_CPU_INTACK] +#ifdef CONFIG_CPU_BIG_ENDIAN + swab16_low_half \irqstat +#endif /* bits 12-10 = src CPU, 9-0 = int # */ ldr \tmp, =1021
@@ -55,6 +59,9 @@ .macro test_for_ipi, irqnr, irqstat, base, tmp bic \irqnr, \irqstat, #0x1c00 cmp \irqnr, #16 +#ifdef CONFIG_CPU_BIG_ENDIAN + swab16_high_half \irqstat +#endif strcc \irqstat, [\base, #GIC_CPU_EOI] cmpcs \irqnr, \irqnr .endm
Signature · 1 line
1.7.0.4
PATCH 2/6 ARM: gic: fix big endian support
Quoted 9 lines · Junxiao Bi
The irq state from gic is in little-endian mode. We need do endian conversion for it in big-endian machine. Usually byte swapping of 32-bits word needs 4 assembler instructions for arm machine which arch < 6. But since the high order half word of the irq state is zero, there is a way that can use lesser instrunctions to improve the performance since we only need a bytes swaping of half word. That's what
swab16_low_halfandswab16_high_halfdo.Signed-off-by Junxiao Bi <[email protected]>
Comments below.
Quoted 23 lines
--- arch/arm/include/asm/assembler.h | 27 +++++++++++++++++++++++ arch/arm/include/asm/hardware/entry-macro-gic.S | 7 ++++++ 2 files changed, 34 insertions(+), 0 deletions(-)arch/arm/include/asm/assembler.h +10
-0@@ -302,4 +302,31 @@ .size \name , . - \name .endm +/* +* swab16_low_half is used to swap the bytes order of the low order +* half word, it assumes that the high order half word is zero. +* swab16_high_half is used to swap the bytes order of the high order +* half word, it assumes that the low order half word is zero. + */ +#if __LINUX_ARM_ARCH__ >=6 + .macro swab16_low_half, reg + rev \reg, \reg + .endm
arch/arm/include/asm/assembler.h line 324
Quoted 10 lines
arch/arm/include/asm/assembler.h +10
-0+ + .macro swab16_high_half, reg + rev \reg, \reg + .endm +#else + .macro swab16_low_half, reg + mov \reg, \reg, ror #8 + orr \reg, \reg, \reg, lsr #16 + bic \reg, \reg, \reg, lsl #16 + .endm
I fail to see how this macro would be generally useful. Presuming that the top or bottom half has to be zero is not particularly practical.
arch/arm/include/asm/assembler.h line 329
Quoted 4 lines
arch/arm/include/asm/assembler.h +4
-0+ .macro swab16_high_half, reg + swab16_low_half \reg + mov \reg, \reg, lsl #16 + .endm
And this doesn't end up cheaper than a plain swab32.
Furthermore, you're using those macros 1) in the gic code, and 2) onli in the BE8 case. Both of those conditions are only possible on ARMv6 and above anyway, so I'd simply open code a rev instruction inline.
Nicolas
PATCH 2/6 ARM: gic: fix big endian support
Quoted 44 lines · Nicolas Pitre
Quoted 10 lines · Junxiao Bi
The irq state from gic is in little-endian mode. We need do endian conversion for it in big-endian machine. Usually byte swapping of 32-bits word needs 4 assembler instructions for arm machine which arch< 6. But since the high order half word of the irq state is zero, there is a way that can use lesser instrunctions to improve the performance since we only need a bytes swaping of half word. That's what
swab16_low_halfandswab16_high_halfdo.Signed-off-by Junxiao Bi<[email protected]>Comments below.
Quoted 28 lines
--- arch/arm/include/asm/assembler.h | 27 +++++++++++++++++++++++ arch/arm/include/asm/hardware/entry-macro-gic.S | 7 ++++++ 2 files changed, 34 insertions(+), 0 deletions(-)arch/arm/include/asm/assembler.h +15
-0@@ -302,4 +302,31 @@ .size \name , . - \name .endm +/* +* swab16_low_half is used to swap the bytes order of the low order +* half word, it assumes that the high order half word is zero. +* swab16_high_half is used to swap the bytes order of the high order +* half word, it assumes that the low order half word is zero. + */ +#if __LINUX_ARM_ARCH__>=6 + .macro swab16_low_half, reg + rev \reg, \reg + .endm + + .macro swab16_high_half, reg + rev \reg, \reg + .endm +#else
Quoted 9 lines
arch/arm/include/asm/assembler.h
Quoted 6 lines
arch/arm/include/asm/assembler.h +5
-0+ .macro swab16_low_half, reg + mov \reg, \reg, ror #8 + orr \reg, \reg, \reg, lsr #16 + bic \reg, \reg, \reg, lsl #16 + .endmI fail to see how this macro would be generally useful. Presuming that the top or bottom half has to be zero is not particularly practical.
We can use it to swap bytes order of a 16-bits number in 32-bits register in which case the top or bottom half will be zero. For the \irqstat register, as the original implementation assumes its top half is zero, so I make the same assumption.
Quoted 8 lines
arch/arm/include/asm/assembler.h line 329
Quoted 6 lines
arch/arm/include/asm/assembler.h +4
-0+ .macro swab16_high_half, reg + swab16_low_half \reg + mov \reg, \reg, lsl #16 + .endmAnd this doesn't end up cheaper than a plain swab32.
This macro has an advantage that it only needs one register. For swab32, it will need another temporary register besides the target register.
Quoted 4 lines
Furthermore, you're using those macros 1) in the gic code, and 2) onli in the BE8 case. Both of those conditions are only possible on ARMv6 and above anyway, so I'd simply open code a rev instruction inline.
This is not be8 specific. It will be needed for both be8 and be32. So the machine with arch < 6 also needs to be supported.
Quoted 4 lines
Nicolas
PATCH 2/6 ARM: gic: fix big endian support
Quoted 56 lines · Bi Junxiao
Quoted 46 lines · Nicolas Pitre
Quoted 10 lines · Junxiao Bi
The irq state from gic is in little-endian mode. We need do endian conversion for it in big-endian machine. Usually byte swapping of 32-bits word needs 4 assembler instructions for arm machine which arch< 6. But since the high order half word of the irq state is zero, there is a way that can use lesser instrunctions to improve the performance since we only need a bytes swaping of half word. That's what
swab16_low_halfandswab16_high_halfdo.Signed-off-by Junxiao Bi<[email protected]>Comments below.
Quoted 30 lines
--- arch/arm/include/asm/assembler.h | 27 +++++++++++++++++++++++ arch/arm/include/asm/hardware/entry-macro-gic.S | 7 ++++++ 2 files changed, 34 insertions(+), 0 deletions(-)arch/arm/include/asm/assembler.h +15
-0@@ -302,4 +302,31 @@ .size \name , . - \name .endm +/* +* swab16_low_half is used to swap the bytes order of the low order +* half word, it assumes that the high order half word is zero. +* swab16_high_half is used to swap the bytes order of the high order +* half word, it assumes that the low order half word is zero. + */ +#if __LINUX_ARM_ARCH__>=6 + .macro swab16_low_half, reg + rev \reg, \reg + .endm + + .macro swab16_high_half, reg + rev \reg, \reg + .endm +#elseQuoted 9 lines
arch/arm/include/asm/assembler.h
Quoted 6 lines
arch/arm/include/asm/assembler.h +5
-0+ .macro swab16_low_half, reg + mov \reg, \reg, ror #8 + orr \reg, \reg, \reg, lsr #16 + bic \reg, \reg, \reg, lsl #16 + .endmI fail to see how this macro would be generally useful. Presuming that the top or bottom half has to be zero is not particularly practical.
Quoted 4 lines
We can use it to swap bytes order of a 16-bits number in 32-bits register in which case the top or bottom half will be zero. For the \irqstat register, as the original implementation assumes its top half is zero, so I make the same assumption.
The problem is that you're loading some assumption about a particular register onto a generic macro. Unless this is a very common pattern, I don't think this needs to be made generic.
Quoted 9 lines
Quoted 7 lines
arch/arm/include/asm/assembler.h line 329
Quoted 5 lines
arch/arm/include/asm/assembler.h +4
-0+ .macro swab16_high_half, reg + swab16_low_half \reg + mov \reg, \reg, lsl #16 + .endmAnd this doesn't end up cheaper than a plain swab32.
This macro has an advantage that it only needs one register. For swab32, it will need another temporary register besides the target register.
Sure, but I don't think we're so short of registers. And BE on pre-ARMv6 is not that common either. So, unless this particular pattern is heavily used on pre-ARMv6 BE systems, I don't think it is reasonable to create a generic macro with such specific assumptions.
Quoted 6 lines
Quoted 4 lines
Furthermore, you're using those macros 1) in the gic code, and 2) onli in the BE8 case. Both of those conditions are only possible on ARMv6 and above anyway, so I'd simply open code a rev instruction inline.
This is not be8 specific. It will be needed for both be8 and be32. So the machine with arch < 6 also needs to be supported.
There is no gic on machines with arch < 6, no?
If you meant for those macros to be used for other purposes then they deserve a patch of their own.
And Russell just merged in his devel branch a patch from Marc Zyngier completely removing entry-macro-gic.S anyway, so this patch as it is will be moot soon.
Nicolas
PATCH 2/6 ARM: gic: fix big endian support
Quoted 98 lines · Nicolas Pitre
Quoted 62 lines · Bi Junxiao
Quoted 50 lines · Nicolas Pitre
Quoted 11 lines · Junxiao Bi
The irq state from gic is in little-endian mode. We need do endian conversion for it in big-endian machine. Usually byte swapping of 32-bits word needs 4 assembler instructions for arm machine which
arch< 6. But since the high order half word of the irq state is
zero, there is a way that can use lesser instrunctions to improve the performance since we only need a bytes swaping of half word. That's whatswab16_low_halfandswab16_high_halfdo.Signed-off-by Junxiao Bi<[email protected]>Comments below.
Quoted 31 lines
--- arch/arm/include/asm/assembler.h | 27 +++++++++++++++++++++++ arch/arm/include/asm/hardware/entry-macro-gic.S | 7 ++++++ 2 files changed, 34 insertions(+), 0 deletions(-)arch/arm/include/asm/assembler.h +16
-0@@ -302,4 +302,31 @@ .size \name , . - \name .endm +/* +* swab16_low_half is used to swap the bytes order of the low order +* half word, it assumes that the high order half word is zero. +* swab16_high_half is used to swap the bytes order of the high order +* half word, it assumes that the low order half word is zero. + */ +#if __LINUX_ARM_ARCH__>=6 + .macro swab16_low_half, reg + rev \reg, \reg + .endm + + .macro swab16_high_half, reg + rev \reg, \reg + .endm +#else + .macro swab16_low_half, regQuoted 10 lines
arch/arm/include/asm/assembler.h
Quoted 6 lines
arch/arm/include/asm/assembler.h +4
-0+ mov \reg, \reg, ror #8 + orr \reg, \reg, \reg, lsr #16 + bic \reg, \reg, \reg, lsl #16 + .endmI fail to see how this macro would be generally useful. Presuming that the top or bottom half has to be zero is not particularly practical.
Quoted 5 lines
We can use it to swap bytes order of a 16-bits number in 32-bits register in which case the top or bottom half will be zero. For the \irqstat register, as the original implementation assumes its top half is zero, so I make the same assumption.
The problem is that you're loading some assumption about a particular register onto a generic macro. Unless this is a very common pattern, I don't think this needs to be made generic.
Quoted 9 lines
Quoted 9 lines
arch/arm/include/asm/assembler.h line 329
Quoted 6 lines
arch/arm/include/asm/assembler.h +4
-0+ .macro swab16_high_half, reg + swab16_low_half \reg + mov \reg, \reg, lsl #16 + .endmAnd this doesn't end up cheaper than a plain swab32.
Quoted 3 lines
This macro has an advantage that it only needs one register. For swab32, it will need another temporary register besides the target register.
Sure, but I don't think we're so short of registers. And BE on pre-ARMv6 is not that common either. So, unless this particular pattern is heavily used on pre-ARMv6 BE systems, I don't think it is reasonable to create a generic macro with such specific assumptions.
Quoted 5 lines
Quoted 5 lines
Furthermore, you're using those macros 1) in the gic code, and 2) onli in the BE8 case. Both of those conditions are only possible on ARMv6 and above anyway, so I'd simply open code a rev instruction inline.
Quoted 8 lines
Quoted 3 lines
This is not be8 specific. It will be needed for both be8 and be32. So the machine with arch< 6 also needs to be supported.
There is no gic on machines with arch< 6, no?
If you meant for those macros to be used for other purposes then they deserve a patch of their own.
I didn't find other need of the macro yet. I will leave it aside.
Quoted 5 lines
And Russell just merged in his devel branch a patch from Marc Zyngier completely removing
entry-macro-gic.Sanyway, so this patch as it is will be moot soon.
OK, thank you for reviewing it. I will drop this patch.
Quoted 3 lines
Nicolas
PATCH 2/6 ARM: gic: fix big endian support
In reply to Bi JunxiaoQuoted 39 lines · Bi Junxiao
Quoted 38 lines · Nicolas Pitre
Quoted 9 lines · Junxiao Bi
The irq state from gic is in little-endian mode. We need do endian conversion for it in big-endian machine. Usually byte swapping of 32-bits word needs 4 assembler instructions for arm machine which arch< 6. But since the high order half word of the irq state is zero, there is a way that can use lesser instrunctions to improve the performance since we only need a bytes swaping of half word. That's what
swab16_low_halfandswab16_high_halfdo.Signed-off-by Junxiao Bi<[email protected]>Comments below.
Quoted 25 lines
--- arch/arm/include/asm/assembler.h | 27 +++++++++++++++++++++++ arch/arm/include/asm/hardware/entry-macro-gic.S | 7 ++++++ 2 files changed, 34 insertions(+), 0 deletions(-)arch/arm/include/asm/assembler.h +12
-0@@ -302,4 +302,31 @@ .size \name , . - \name .endm +/* +* swab16_low_half is used to swap the bytes order of the low order +* half word, it assumes that the high order half word is zero. +* swab16_high_half is used to swap the bytes order of the high order +* half word, it assumes that the low order half word is zero. + */ +#if __LINUX_ARM_ARCH__>=6 + .macro swab16_low_half, reg + rev \reg, \reg + .endm + + .macro swab16_high_half, reg
Quoted 8 lines
Quoted 8 lines
arch/arm/include/asm/assembler.h line 324
Quoted 8 lines
arch/arm/include/asm/assembler.h +8
-0+ rev \reg, \reg + .endm +#else + .macro swab16_low_half, reg + mov \reg, \reg, ror #8 + orr \reg, \reg, \reg, lsr #16 + bic \reg, \reg, \reg, lsl #16 + .endm
Your v6 and <v6 implementations don't seem to produce the same result for swab16_low_half.
If reg=0x0000AABB on >=v6 you transform it to 0xBBAA0000, but on <v6 you translate it to 0x0000BBAA.
Perhaps you meant to use the rev16 instruction instead of rev?
Quoted 11 lines
Quoted 2 lines
I fail to see how this macro would be generally useful. Presuming that the top or bottom half has to be zero is not particularly practical.
We can use it to swap bytes order of a 16-bits number in 32-bits register in which case the top or bottom half will be zero. For the \irqstat register, as the original implementation assumes its top half is zero, so I make the same assumption.
Quoted 5 lines
arch/arm/include/asm/assembler.h line 329
Quoted 4 lines
arch/arm/include/asm/assembler.h +4
-0+ .macro swab16_high_half, reg + swab16_low_half \reg + mov \reg, \reg, lsl #16 + .endmAnd this doesn't end up cheaper than a plain swab32.
Quoted 8 lines
This macro has an advantage that it only needs one register. For swab32, it will need another temporary register besides the target register.
Quoted 3 lines
Furthermore, you're using those macros 1) in the gic code, and 2) onli in the BE8 case. Both of those conditions are only possible on ARMv6 and above anyway, so I'd simply open code a rev instruction inline.
This is not be8 specific. It will be needed for both be8 and be32. So the machine with arch < 6 also needs to be supported.
I also thought the GIC doesn't get used with <v6? I thought the GIC was too new for that, but I'm not an expert on it.
Cheers
---Dave
PATCH 2/6 ARM: gic: fix big endian support
Quoted 57 lines · Dave Martin
Quoted 44 lines · Bi Junxiao
Quoted 42 lines · Nicolas Pitre
Quoted 10 lines · Junxiao Bi
The irq state from gic is in little-endian mode. We need do endian conversion for it in big-endian machine. Usually byte swapping of 32-bits word needs 4 assembler instructions for arm machine which
arch< 6. But since the high order half word of the irq state is
zero, there is a way that can use lesser instrunctions to improve the performance since we only need a bytes swaping of half word. That's whatswab16_low_halfandswab16_high_halfdo.Signed-off-by Junxiao Bi<[email protected]>Comments below.
Quoted 26 lines
--- arch/arm/include/asm/assembler.h | 27 +++++++++++++++++++++++ arch/arm/include/asm/hardware/entry-macro-gic.S | 7 ++++++ 2 files changed, 34 insertions(+), 0 deletions(-)arch/arm/include/asm/assembler.h +13
-0@@ -302,4 +302,31 @@ .size \name , . - \name .endm +/* +* swab16_low_half is used to swap the bytes order of the low order +* half word, it assumes that the high order half word is zero. +* swab16_high_half is used to swap the bytes order of the high order +* half word, it assumes that the low order half word is zero. + */ +#if __LINUX_ARM_ARCH__>=6 + .macro swab16_low_half, reg + rev \reg, \reg + .endm + + .macro swab16_high_half, reg + rev \reg, \regQuoted 8 lines
Quoted 8 lines
arch/arm/include/asm/assembler.h
Quoted 8 lines
arch/arm/include/asm/assembler.h +7
-0+ .endm +#else + .macro swab16_low_half, reg + mov \reg, \reg, ror #8 + orr \reg, \reg, \reg, lsr #16 + bic \reg, \reg, \reg, lsl #16 + .endmYour v6 and<v6 implementations don't seem to produce the same result for
swab16_low_half.
Quoted 3 lines
If reg=0x0000AABB on>=v6 you transform it to
0xBBAA0000, but on<v6 you translate it to0x0000BBAA.
For swab16_low_half, it assumes that the high order half of the word is zero. This mean 0x0000AABB is not a qualified number, but 0xAABB0000 is, it can translate to 0x0000BBAA with this macro which is the same result with "rev".
Quoted 2 lines
Perhaps you meant to use the rev16 instruction instead of rev?
This macro is trying to swap bytes order of a 32-bit word. It make the assumption about the high half for a more cheaper and less register usage implementation than swab32. When I first develop this code, test_for_ltirq is still in entry-macro-gic.S(now it is deleted), I can not find a temporary register for swab32 which needs two registers in it. So I introduced this macro. I am not sure whether there are other cases like test_for_ltirq. Is this marco useful? If so I can make a separate patch for it.
Quoted 24 lines
Quoted 24 lines
Quoted 4 lines
I fail to see how this macro would be generally useful. Presuming that the top or bottom half has to be zero is not particularly practical.
We can use it to swap bytes order of a 16-bits number in 32-bits register in which case the top or bottom half will be zero. For the \irqstat register, as the original implementation assumes its top half is zero, so I make the same assumption.
Quoted 7 lines
arch/arm/include/asm/assembler.h line 329
Quoted 5 lines
arch/arm/include/asm/assembler.h +4
-0+ .macro swab16_high_half, reg + swab16_low_half \reg + mov \reg, \reg, lsl #16 + .endmAnd this doesn't end up cheaper than a plain swab32.
This macro has an advantage that it only needs one register. For swab32, it will need another temporary register besides the target register.
Quoted 4 lines
Furthermore, you're using those macros 1) in the gic code, and 2) onli in the BE8 case. Both of those conditions are only possible on ARMv6 and above anyway, so I'd simply open code a rev instruction inline.
Quoted 6 lines
Quoted 3 lines
This is not be8 specific. It will be needed for both be8 and be32. So the machine with arch< 6 also needs to be supported.
I also thought the GIC doesn't get used with<v6? I thought the GIC was too new for that, but I'm not an expert on it.
I am also not sure about it. I didn't find a official document describe this.
Quoted 5 lines
Cheers
---Dave
PATCH 3/6 ARM: early_printk: pl01x: fix big endian support
In reply to Junxiao BiThe waituart and busyuart need to get one bit flag from UART flag register. For this, we don't need do endian conversion for the entire flag register, providing that flag definition in big-endian mode is enough.
--- arch/arm/include/asm/assembler.h | 6 ++++++ arch/arm/include/asm/hardware/debug-pl01x.S | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-)
arch/arm/include/asm/assembler.h +6 -0
@@ -329,4 +329,10 @@ .endm#endif +#define asm_constant_swab32 (x) \ + ((((x) & 0xff000000) >> 24) | \ + (((x) & 0x00ff0000) >> 8) | \ + (((x) & 0x0000ff00) << 8) | \ + (((x) & 0x000000ff) << 24)) +#endif /* __ASM_ASSEMBLER_H__ */
arch/arm/include/asm/hardware/debug-pl01x.S +10 -2
@@ -11,19 +11,27 @@ * */ #include <linux/amba/serial.h> +#include <asm/assembler.h> +#ifdef CONFIG_CPU_BIG_ENDIAN +#define _UART01x_FR_TXFF asm_constant_swab32(UART01x_FR_TXFF) +#define _UART01x_FR_BUSY asm_constant_swab32(UART01x_FR_BUSY) +#else +#define _UART01x_FR_TXFF UART01x_FR_TXFF +#define _UART01x_FR_BUSY UART01x_FR_BUSY +#endif .macro senduart,rd,rx strb \rd, [\rx, #UART01x_DR] .endm .macro waituart,rd,rx 1001: ldr \rd, [\rx, #UART01x_FR] - tst \rd, #UART01x_FR_TXFF + tst \rd, #_UART01x_FR_TXFF bne 1001b .endm .macro busyuart,rd,rx 1001: ldr \rd, [\rx, #UART01x_FR] - tst \rd, #UART01x_FR_BUSY + tst \rd, #_UART01x_FR_BUSY bne 1001b .endm
Signature · 1 line
1.7.0.4
PATCH 4/6 ARM: add big endian support for peripheral access
In reply to Junxiao BiFrom: Xue Ying <[email protected]>
Since data from arm peripheral are little-endian and __raw_read*/__raw_write* don't do any endian conversion, we should use read*/write*_relaxed to replace them as the _relaxed version only adds endian conversion based on __raw version which isn't like read*/write* that adds IO barriers which will affect performance.
--- arch/arm/kernel/smp_scu.c | 10 +++++----- arch/arm/kernel/smp_twd.c | 20 ++++++++++---------- include/linux/mtd/map.h | 16 ++++++++-------- 3 files changed, 23 insertions(+), 23 deletions(-)
arch/arm/kernel/smp_scu.c +5 -5
@@ -27,7 +27,7 @@*/ unsigned int __init scu_get_core_count (void __iomem *scu_base) { -unsigned int ncores =__raw_readl (scu_base +SCU_CONFIG ); +unsigned int ncores =readl_relaxed (scu_base +SCU_CONFIG );return (ncores &0x03 ) +1 ; }
@@ -41,19 +41,19 @@ void scu_enable(void __iomem *scu_base)#ifdef CONFIG_ARM_ERRATA_764369 /* Cortex-A9 only */ if ((read_cpuid (CPUID_ID ) &0xff0ffff0 ) ==0x410fc090 ) { - scu_ctrl =__raw_readl (scu_base +0x30 ); + scu_ctrl =readl_relaxed (scu_base +0x30 );if (!(scu_ctrl &1 )) -__raw_writel (scu_ctrl |0x1 , scu_base +0x30 ); +writel_relaxed (scu_ctrl |0x1 , scu_base +0x30 ); }#endif - scu_ctrl =__raw_readl (scu_base +SCU_CTRL ); + scu_ctrl =readl_relaxed (scu_base +SCU_CTRL );/* already enabled? */ if (scu_ctrl &1 )return ; scu_ctrl |=1 ; -__raw_writel (scu_ctrl, scu_base +SCU_CTRL ); +writel_relaxed (scu_ctrl, scu_base +SCU_CTRL );/* * Ensure that the data accessed by CPU0 before the SCU was
arch/arm/kernel/smp_twd.c +10 -10
@@ -39,7 +39,7 @@ static void twd_set_mode(enum clock_event_mode mode,/* timer load already set up */ ctrl =TWD_TIMER_CONTROL_ENABLE |TWD_TIMER_CONTROL_IT_ENABLE |TWD_TIMER_CONTROL_PERIODIC ; -__raw_writel (twd_timer_rate /HZ , twd_base +TWD_TIMER_LOAD ); +writel_relaxed (twd_timer_rate /HZ , twd_base +TWD_TIMER_LOAD );break ;case CLOCK_EVT_MODE_ONESHOT :/* period set, and timer enabled in 'next_event' hook */
@@ -51,18 +51,18 @@ static void twd_set_mode(enum clock_event_mode mode, ctrl =0 ; } -__raw_writel (ctrl, twd_base +TWD_TIMER_CONTROL ); +writel_relaxed (ctrl, twd_base +TWD_TIMER_CONTROL ); }static int twd_set_next_event (unsigned long evt,struct clock_event_device *unused) { -unsigned long ctrl =__raw_readl (twd_base +TWD_TIMER_CONTROL ); +unsigned long ctrl =readl_relaxed (twd_base +TWD_TIMER_CONTROL ); ctrl |=TWD_TIMER_CONTROL_ENABLE ; -__raw_writel (evt, twd_base +TWD_TIMER_COUNTER ); -__raw_writel (ctrl, twd_base +TWD_TIMER_CONTROL ); +writel_relaxed (evt, twd_base +TWD_TIMER_COUNTER ); +writel_relaxed (ctrl, twd_base +TWD_TIMER_CONTROL );return 0 ; }
@@ -75,8 +75,8 @@ static int twd_set_next_event(unsigned long evt,*/ int twd_timer_ack (void ) { -if (__raw_readl (twd_base +TWD_TIMER_INTSTAT )) { -__raw_writel (1 , twd_base +TWD_TIMER_INTSTAT ); +if (readl_relaxed (twd_base +TWD_TIMER_INTSTAT )) { +writel_relaxed (1 , twd_base +TWD_TIMER_INTSTAT );return 1 ; }
@@ -111,15 +111,15 @@ static void __cpuinit twd_calibrate_rate(void) waitjiffies +=5 ;/* enable, no interrupt or reload */ -__raw_writel (0x1 , twd_base +TWD_TIMER_CONTROL ); +writel_relaxed (0x1 , twd_base +TWD_TIMER_CONTROL );/* maximum value */ -__raw_writel (0xFFFFFFFFU , twd_base +TWD_TIMER_COUNTER ); +writel_relaxed (0xFFFFFFFFU , twd_base +TWD_TIMER_COUNTER );while (get_jiffies_64 () < waitjiffies)udelay (10 ); - count =__raw_readl (twd_base +TWD_TIMER_COUNTER ); + count =readl_relaxed (twd_base +TWD_TIMER_COUNTER ); twd_timer_rate = (0xFFFFFFFFU - count) * (HZ /5 );
include/linux/mtd/map.h +8 -8
@@ -393,14 +393,14 @@ static inline map_word inline_map_read(struct map_info *map, unsigned long ofs)map_word r;if (map_bankwidth_is_1 (map)) - r.x[0 ] =__raw_readb (map->virt + ofs); + r.x[0 ] =readb_relaxed (map->virt + ofs);else if (map_bankwidth_is_2 (map)) - r.x[0 ] =__raw_readw (map->virt + ofs); + r.x[0 ] =readw_relaxed (map->virt + ofs);else if (map_bankwidth_is_4 (map)) - r.x[0 ] =__raw_readl (map->virt + ofs); + r.x[0 ] =readl_relaxed (map->virt + ofs);#if BITS_PER_LONG >=64 else if (map_bankwidth_is_8(map)) - r.x[0] = __raw_readq(map->virt + ofs); + r.x[0] = readq_relaxed(map->virt + ofs);#endif else if (map_bankwidth_is_large(map)) memcpy_fromio(r.x, map->virt+ofs, map->bankwidth);
@@ -413,14 +413,14 @@ static inline map_word inline_map_read(struct map_info *map, unsigned long ofs)static inline void inline_map_write (struct map_info *map,const map_word datum,unsigned long ofs) {if (map_bankwidth_is_1 (map)) -__raw_writeb (datum.x[0 ], map->virt + ofs); +writeb_relaxed (datum.x[0 ], map->virt + ofs);else if (map_bankwidth_is_2 (map)) -__raw_writew (datum.x[0 ], map->virt + ofs); +writew_relaxed (datum.x[0 ], map->virt + ofs);else if (map_bankwidth_is_4 (map)) -__raw_writel (datum.x[0 ], map->virt + ofs); +writel_relaxed (datum.x[0 ], map->virt + ofs);#if BITS_PER_LONG >=64 else if (map_bankwidth_is_8(map)) - __raw_writeq(datum.x[0], map->virt + ofs); + writeq_relaxed(datum.x[0], map->virt + ofs);#endif else if (map_bankwidth_is_large(map)) memcpy_toio(map->virt+ofs, datum.x, map->bankwidth);
Signature · 1 line
1.7.0.4
PATCH 5/6 ARM: Atomic64: fix 64bit ops in BE mode
In reply to Junxiao BiThe add/sub ops to 64 bits double word are made by adds/subs to the least significant 32 bits first and then adc/sbc to the most significant 32 bits. Using %0 and %H0 can only work in LE mode. If we change them to %Q0 and %R0, it will work in both endian modes since %Q0 always represents the least significant 32 bits and %R0 represents the most.
--- arch/arm/include/asm/atomic.h | 26 +++++++++++++------------- 1 files changed, 13 insertions(+), 13 deletions(-)
arch/arm/include/asm/atomic.h +13 -13
@@ -275,8 +275,8 @@ static inline void atomic64_add(u64 i, atomic64_t *v) __asm__ __volatile__("@ atomic64_add\n" "1: ldrexd %0, %H0, [%3]\n" -" adds %0, %0, %4\n" -" adc %H0, %H0, %H4\n" +" adds %Q0, %Q0, %Q4\n" +" adc %R0, %R0, %R4\n" " strexd %1, %0, %H0, [%3]\n" " teq %1, #0\n" " bne 1b"
@@ -294,8 +294,8 @@ static inline u64 atomic64_add_return(u64 i, atomic64_t *v) __asm__ __volatile__("@ atomic64_add_return\n" "1: ldrexd %0, %H0, [%3]\n" -" adds %0, %0, %4\n" -" adc %H0, %H0, %H4\n" +" adds %Q0, %Q0, %Q4\n" +" adc %R0, %R0, %R4\n" " strexd %1, %0, %H0, [%3]\n" " teq %1, #0\n" " bne 1b"
@@ -315,8 +315,8 @@ static inline void atomic64_sub(u64 i, atomic64_t *v) __asm__ __volatile__("@ atomic64_sub\n" "1: ldrexd %0, %H0, [%3]\n" -" subs %0, %0, %4\n" -" sbc %H0, %H0, %H4\n" +" subs %Q0, %Q0, %Q4\n" +" sbc %R0, %R0, %R4\n" " strexd %1, %0, %H0, [%3]\n" " teq %1, #0\n" " bne 1b"
@@ -334,8 +334,8 @@ static inline u64 atomic64_sub_return(u64 i, atomic64_t *v) __asm__ __volatile__("@ atomic64_sub_return\n" "1: ldrexd %0, %H0, [%3]\n" -" subs %0, %0, %4\n" -" sbc %H0, %H0, %H4\n" +" subs %Q0, %Q0, %Q4\n" +" sbc %R0, %R0, %R4\n" " strexd %1, %0, %H0, [%3]\n" " teq %1, #0\n" " bne 1b"
@@ -402,9 +402,9 @@ static inline u64 atomic64_dec_if_positive(atomic64_t *v) __asm__ __volatile__("@ atomic64_dec_if_positive\n" "1: ldrexd %0, %H0, [%3]\n" -" subs %0, %0, #1\n" -" sbc %H0, %H0, #0\n" -" teq %H0, #0\n" +" subs %Q0, %Q0, #1\n" +" sbc %R0, %R0, #0\n" +" teq %R0, #0\n" " bmi 2f\n" " strexd %1, %0, %H0, [%3]\n" " teq %1, #0\n"
@@ -433,8 +433,8 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)" teqeq %H0, %H5\n" " moveq %1, #0\n" " beq 2f\n" -" adds %0, %0, %6\n" -" adc %H0, %H0, %H6\n" +" adds %Q0, %Q0, %Q6\n" +" adc %R0, %R0, %R6\n" " strexd %2, %0, %H0, [%4]\n" " teq %2, #0\n" " bne 1b\n"
Signature · 1 line
1.7.0.4
PATCH 5/6 ARM: Atomic64: fix 64bit ops in BE mode
Quoted 7 lines · Junxiao Bi
The add/sub ops to 64 bits double word are made by adds/subs to the least significant 32 bits first and then adc/sbc to the most significant 32 bits. Using %0 and %H0 can only work in LE mode. If we change them to %Q0 and %R0, it will work in both endian modes since %Q0 always represents the least significant 32 bits and %R0 represents the most.
Signed-off-by Junxiao Bi <[email protected]>
Quoted 85 lines
--- arch/arm/include/asm/atomic.h | 26 +++++++++++++------------- 1 files changed, 13 insertions(+), 13 deletions(-)arch/arm/include/asm/atomic.h +13
-13@@ -275,8 +275,8 @@ static inline void atomic64_add(u64 i, atomic64_t *v) __asm__ __volatile__("@ atomic64_add\n" "1: ldrexd %0, %H0, [%3]\n" -" adds %0, %0, %4\n" -" adc %H0, %H0, %H4\n" +" adds %Q0, %Q0, %Q4\n" +" adc %R0, %R0, %R4\n" " strexd %1, %0, %H0, [%3]\n" " teq %1, #0\n" " bne 1b"@@ -294,8 +294,8 @@ static inline u64 atomic64_add_return(u64 i, atomic64_t *v) __asm__ __volatile__("@ atomic64_add_return\n" "1: ldrexd %0, %H0, [%3]\n" -" adds %0, %0, %4\n" -" adc %H0, %H0, %H4\n" +" adds %Q0, %Q0, %Q4\n" +" adc %R0, %R0, %R4\n" " strexd %1, %0, %H0, [%3]\n" " teq %1, #0\n" " bne 1b"@@ -315,8 +315,8 @@ static inline void atomic64_sub(u64 i, atomic64_t *v) __asm__ __volatile__("@ atomic64_sub\n" "1: ldrexd %0, %H0, [%3]\n" -" subs %0, %0, %4\n" -" sbc %H0, %H0, %H4\n" +" subs %Q0, %Q0, %Q4\n" +" sbc %R0, %R0, %R4\n" " strexd %1, %0, %H0, [%3]\n" " teq %1, #0\n" " bne 1b"@@ -334,8 +334,8 @@ static inline u64 atomic64_sub_return(u64 i, atomic64_t *v) __asm__ __volatile__("@ atomic64_sub_return\n" "1: ldrexd %0, %H0, [%3]\n" -" subs %0, %0, %4\n" -" sbc %H0, %H0, %H4\n" +" subs %Q0, %Q0, %Q4\n" +" sbc %R0, %R0, %R4\n" " strexd %1, %0, %H0, [%3]\n" " teq %1, #0\n" " bne 1b"@@ -402,9 +402,9 @@ static inline u64 atomic64_dec_if_positive(atomic64_t *v) __asm__ __volatile__("@ atomic64_dec_if_positive\n" "1: ldrexd %0, %H0, [%3]\n" -" subs %0, %0, #1\n" -" sbc %H0, %H0, #0\n" -" teq %H0, #0\n" +" subs %Q0, %Q0, #1\n" +" sbc %R0, %R0, #0\n" +" teq %R0, #0\n" " bmi 2f\n" " strexd %1, %0, %H0, [%3]\n" " teq %1, #0\n"@@ -433,8 +433,8 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)" teqeq %H0, %H5\n" " moveq %1, #0\n" " beq 2f\n" -" adds %0, %0, %6\n" -" adc %H0, %H0, %H6\n" +" adds %Q0, %Q0, %Q6\n" +" adc %R0, %R0, %R6\n" " strexd %2, %0, %H0, [%4]\n" " teq %2, #0\n" " bne 1b\n" Signature · 7 lines
1.7.0.4 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel at lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH 6/6 ARM: support kernel modules in BE8 mode
In reply to Junxiao BiFrom: Stanley.Miao <[email protected]>
In BE8 mode, data must be manipulated in big endian format while text must be little endian. Therefore, when relocating the text section of module in BE8 mode, we must convert the location offset of the text to big endian from the native little endian. After the relocation is complete, the location offset value is re-written as little endian.
Since only BE8 mode has such special requirement while other big endian mode not, cpu_to_le32 and le32_to_cpu can not be used to relocate the text. We introduce write_instr* and read_instr* to do it.
--- arch/arm/Makefile | 1 + arch/arm/include/asm/io.h | 12 ++++++++++ arch/arm/kernel/module.c | 51 +++++++++++++++++++++++---------------------- 3 files changed, 39 insertions(+), 25 deletions(-)
arch/arm/Makefile +1 -0
@@ -13,6 +13,7 @@ LDFLAGS_vmlinux :=-p --no-undefined -X ifeq ($(CONFIG_CPU_ENDIAN_BE8),y) LDFLAGS_vmlinux += --be8 +LDFLAGS_MODULE += --be8 endif OBJCOPYFLAGS :=-O binary -R .comment -S
arch/arm/include/asm/io.h +12 -0
@@ -210,6 +210,18 @@ extern void _memset_io(volatile void __iomem *, int, size_t);* Again, this are defined to perform little endian accesses. See the * IO port primitives for more information. */ +#ifdef CONFIG_CPU_ENDIAN_BE8 +#define read_instr32 (c) __swab32(*(u32 *)(c)) +#define read_instr16 (c) __swab16(*(u16 *)(c)) +#define write_instr32 (v, a) (*(u32 *)(a) = __swab32((__force __u32)(v))) +#define write_instr16 (v, a) (*(u16 *)(a) = __swab16((__force __u16)(v))) +#else +#define read_instr32 (c) (*(u32 *)(c)) +#define read_instr16 (c) (*(u16 *)(c)) +#define write_instr32 (v, a) (*(u32 *)(a) = (v)) +#define write_instr16 (v, a) (*(u16 *)(a) = (v)) +#endif +#ifdef __mem_pci#define readb_relaxed (c) ({ u8 __r = __raw_readb(__mem_pci(c)); __r; })#define readw_relaxed (c) ({ u16 __r = le16_to_cpu((__force __le16) \
arch/arm/kernel/module.c +26 -25
108 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH 6/6 ARM: support kernel modules in BE8 mode
Quoted 42 lines · Junxiao Bi
From: Stanley.Miao <[email protected]>
In BE8 mode, data must be manipulated in big endian format while text must be little endian. Therefore, when relocating the text section of module in BE8 mode, we must convert the location offset of the text to big endian from the native little endian. After the relocation is complete, the location offset value is re-written as little endian.
Since only BE8 mode has such special requirement while other big endian mode not,
cpu_to_le32andle32_to_cpucan not be used to relocate the text. We introduce write_instr* and read_instr* to do it.Signed-off-by Stanley.Miao <[email protected]>Signed-off-by Junxiao Bi <[email protected]>--- arch/arm/Makefile | 1 + arch/arm/include/asm/io.h | 12 ++++++++++ arch/arm/kernel/module.c | 51 +++++++++++++++++++++++---------------------- 3 files changed, 39 insertions(+), 25 deletions(-)arch/arm/Makefile +1
-0@@ -13,6 +13,7 @@ LDFLAGS_vmlinux :=-p --no-undefined -X ifeq ($(CONFIG_CPU_ENDIAN_BE8),y) LDFLAGS_vmlinux += --be8 +LDFLAGS_MODULE += --be8 endif OBJCOPYFLAGS :=-O binary -R .comment -Sarch/arm/include/asm/io.h +1
-0@@ -210,6 +210,18 @@ extern void _memset_io(volatile void __iomem *, int, size_t);* Again, this are defined to perform little endian accesses. See the * IO port primitives for more information. */ +#ifdef CONFIG_CPU_ENDIAN_BE8
arch/arm/include/asm/io.h extern void _memset_io(volatile void __iomem *, int, size_t); · line 223
Quoted 10 lines
arch/arm/include/asm/io.h +10
-0+#define read_instr32 (c) __swab32(*(u32 *)(c)) +#define read_instr16 (c) __swab16(*(u16 *)(c)) +#define write_instr32 (v, a) (*(u32 *)(a) = __swab32((__force __u32)(v))) +#define write_instr16 (v, a) (*(u16 *)(a) = __swab16((__force __u16)(v))) +#else +#define read_instr32 (c) (*(u32 *)(c)) +#define read_instr16 (c) (*(u16 *)(c)) +#define write_instr32 (v, a) (*(u32 *)(a) = (v)) +#define write_instr16 (v, a) (*(u16 *)(a) = (v)) +#endif
NAK. This has nothing to do with IO.
If only module.c requires this, please move those definitions there.
Nicolas
PATCH 6/6 ARM: support kernel modules in BE8 mode
Quoted 58 lines · Nicolas Pitre
Quoted 43 lines · Junxiao Bi
From: Stanley.Miao<[email protected]>
In BE8 mode, data must be manipulated in big endian format while text must be little endian. Therefore, when relocating the text section of module in BE8 mode, we must convert the location offset of the text to big endian from the native little endian. After the relocation is complete, the location offset value is re-written as little endian.
Since only BE8 mode has such special requirement while other big endian mode not,
cpu_to_le32andle32_to_cpucan not be used to relocate the text. We introduce write_instr* and read_instr* to do it.Signed-off-by Stanley.Miao<[email protected]>Signed-off-by Junxiao Bi<[email protected]>--- arch/arm/Makefile | 1 + arch/arm/include/asm/io.h | 12 ++++++++++ arch/arm/kernel/module.c | 51 +++++++++++++++++++++++---------------------- 3 files changed, 39 insertions(+), 25 deletions(-)arch/arm/Makefile +1
-0@@ -13,6 +13,7 @@ LDFLAGS_vmlinux :=-p --no-undefined -X ifeq ($(CONFIG_CPU_ENDIAN_BE8),y) LDFLAGS_vmlinux += --be8 +LDFLAGS_MODULE += --be8 endif OBJCOPYFLAGS :=-O binary -R .comment -Sarch/arm/include/asm/io.h +2
-0@@ -210,6 +210,18 @@ extern void _memset_io(volatile void __iomem *, int, size_t);* Again, this are defined to perform little endian accesses. See the * IO port primitives for more information. */ +#ifdef CONFIG_CPU_ENDIAN_BE8 +#define read_instr32 (c) __swab32(*(u32 *)(c))arch/arm/include/asm/io.h extern void _memset_io(volatile void __iomem *, int, size_t); · line 224
Quoted 10 lines
arch/arm/include/asm/io.h +9
-0+#define read_instr16 (c) __swab16(*(u16 *)(c)) +#define write_instr32 (v, a) (*(u32 *)(a) = __swab32((__force __u32)(v))) +#define write_instr16 (v, a) (*(u16 *)(a) = __swab16((__force __u16)(v))) +#else +#define read_instr32 (c) (*(u32 *)(c)) +#define read_instr16 (c) (*(u16 *)(c)) +#define write_instr32 (v, a) (*(u32 *)(a) = (v)) +#define write_instr16 (v, a) (*(u16 *)(a) = (v)) +#endif NAK. This has nothing to do with IO.
Quoted 2 lines
If only
module.crequires this, please move those definitions there.
Not only modules, all components that needs to read and write text segment like kprobes also needs this. As it is special to arm be8, how about define it in arch/arm/include/asm/swab.h?
Quoted 4 lines
Nicolas
PATCH 6/6 ARM: support kernel modules in BE8 mode
Quoted 16 lines · Bi Junxiao
Quoted 15 lines · Nicolas Pitre
Quoted 12 lines · Junxiao Bi
From: Stanley.Miao<[email protected]>
In BE8 mode, data must be manipulated in big endian format while text must be little endian. Therefore, when relocating the text section of module in BE8 mode, we must convert the location offset of the text to big endian from the native little endian. After the relocation is complete, the location offset value is re-written as little endian.
Since only BE8 mode has such special requirement while other big endian mode not,
cpu_to_le32andle32_to_cpucan not be used to relocate the text. We introduce write_instr* and read_instr* to do it.
[...]
Quoted 5 lines
Quoted 2 lines
If only
module.crequires this, please move those definitions there.Not only modules, all components that needs to read and write text segment like kprobes also needs this. As it is special to arm be8, how about define it in
arch/arm/include/asm/swab.h?
There is a patch series proposed by Leif Lindholm adding generic ARM instruction condition code check that creates an opcode.h file. That would be an ideal location for opcode accessor definitions.
Nicolas
PATCH 6/6 ARM: support kernel modules in BE8 mode
Quoted 27 lines · Nicolas Pitre
Quoted 19 lines · Bi Junxiao
Quoted 17 lines · Nicolas Pitre
Quoted 13 lines · Junxiao Bi
From: Stanley.Miao<[email protected]>
In BE8 mode, data must be manipulated in big endian format while text must be little endian. Therefore, when relocating the text section of module in BE8 mode, we must convert the location offset of the text to big endian from the native little endian. After the relocation is complete, the location offset value is re-written as little endian.
Since only BE8 mode has such special requirement while other big endian mode not,
cpu_to_le32andle32_to_cpucan not be used to relocate the text. We introduce write_instr* and read_instr* to do it.[...]
Quoted 3 lines
Quoted 3 lines
If only
module.crequires this, please move those definitions there.
Quoted 8 lines
Quoted 4 lines
Not only modules, all components that needs to read and write text segment like kprobes also needs this. As it is special to arm be8, how about define it in
arch/arm/include/asm/swab.h?There is a patch series proposed by Leif Lindholm adding generic ARM instruction condition code check that creates an
opcode.hfile. That would be an ideal location for opcode accessor definitions.
Thank you for the guide. I will put there in V2.
Quoted 4 lines
Nicolas
PATCH 6/6 ARM: support kernel modules in BE8 mode
In reply to Bi JunxiaoQuoted 57 lines · Bi Junxiao
Quoted 56 lines · Nicolas Pitre
Quoted 42 lines · Junxiao Bi
From: Stanley.Miao<[email protected]>
In BE8 mode, data must be manipulated in big endian format while text must be little endian. Therefore, when relocating the text section of module in BE8 mode, we must convert the location offset of the text to big endian from the native little endian. After the relocation is complete, the location offset value is re-written as little endian.
Since only BE8 mode has such special requirement while other big endian mode not,
cpu_to_le32andle32_to_cpucan not be used to relocate the text. We introduce write_instr* and read_instr* to do it.Signed-off-by Stanley.Miao<[email protected]>Signed-off-by Junxiao Bi<[email protected]>--- arch/arm/Makefile | 1 + arch/arm/include/asm/io.h | 12 ++++++++++ arch/arm/kernel/module.c | 51 +++++++++++++++++++++++---------------------- 3 files changed, 39 insertions(+), 25 deletions(-)arch/arm/Makefile +1
-0@@ -13,6 +13,7 @@ LDFLAGS_vmlinux :=-p --no-undefined -X ifeq ($(CONFIG_CPU_ENDIAN_BE8),y) LDFLAGS_vmlinux += --be8 +LDFLAGS_MODULE += --be8 endif OBJCOPYFLAGS :=-O binary -R .comment -Sarch/arm/include/asm/io.h +1
-0@@ -210,6 +210,18 @@ extern void _memset_io(volatile void __iomem *, int, size_t);* Again, this are defined to perform little endian accesses. See the * IO port primitives for more information. */ +#ifdef CONFIG_CPU_ENDIAN_BE8 arch/arm/include/asm/io.h extern void _memset_io(volatile void __iomem *, int, size_t); · line 223
Quoted 10 lines
arch/arm/include/asm/io.h +10
-0+#define read_instr32 (c) __swab32(*(u32 *)(c)) +#define read_instr16 (c) __swab16(*(u16 *)(c)) +#define write_instr32 (v, a) (*(u32 *)(a) = __swab32((__force __u32)(v))) +#define write_instr16 (v, a) (*(u16 *)(a) = __swab16((__force __u16)(v))) +#else +#define read_instr32 (c) (*(u32 *)(c)) +#define read_instr16 (c) (*(u16 *)(c)) +#define write_instr32 (v, a) (*(u32 *)(a) = (v)) +#define write_instr16 (v, a) (*(u16 *)(a) = (v)) +#endif NAK. This has nothing to do with IO.
Quoted 4 lines
Quoted 1 line
If only
module.crequires this, please move those definitions there.Not only modules, all components that needs to read and write text segment like kprobes also needs this. As it is special to arm be8, how about define it in
arch/arm/include/asm/swab.h?
I'm not sure where the correct place is, but I think having macros doing something along these lines would be useful. The module loader is one relevant place, but there is also kprobes, and Rabin's recent ftrace series highlights the potential usefulness too.
There are a lot of #ifdefs and swab hacks spread around various places wherever we need to load/store/relocate instructions. Abstracting this properly so we don't need a load of fragile #ifdefs for the big-endian case is clearly a good idea.
Because the Thumb 32-bit case is different from the ARM case, I would also recommend having three macro variants instead of two:
*_instr_arm()*_instr_thumb16()*_instr_thumb32()
Cheers
---Dave
PATCH 6/6 ARM: support kernel modules in BE8 mode
Quoted 78 lines · Dave Martin
Quoted 60 lines · Bi Junxiao
Quoted 58 lines · Nicolas Pitre
Quoted 43 lines · Junxiao Bi
From: Stanley.Miao<[email protected]>
In BE8 mode, data must be manipulated in big endian format while text must be little endian. Therefore, when relocating the text section of module in BE8 mode, we must convert the location offset of the text to big endian from the native little endian. After the relocation is complete, the location offset value is re-written as little endian.
Since only BE8 mode has such special requirement while other big endian mode not,
cpu_to_le32andle32_to_cpucan not be used to relocate the text. We introduce write_instr* and read_instr* to do it.Signed-off-by Stanley.Miao<[email protected]>Signed-off-by Junxiao Bi<[email protected]>--- arch/arm/Makefile | 1 + arch/arm/include/asm/io.h | 12 ++++++++++ arch/arm/kernel/module.c | 51 +++++++++++++++++++++++---------------------- 3 files changed, 39 insertions(+), 25 deletions(-)arch/arm/Makefile +1
-0@@ -13,6 +13,7 @@ LDFLAGS_vmlinux :=-p --no-undefined -X ifeq ($(CONFIG_CPU_ENDIAN_BE8),y) LDFLAGS_vmlinux += --be8 +LDFLAGS_MODULE += --be8 endif OBJCOPYFLAGS :=-O binary -R .comment -Sarch/arm/include/asm/io.h +2
-0@@ -210,6 +210,18 @@ extern void _memset_io(volatile void __iomem *, int, size_t);* Again, this are defined to perform little endian accesses. See the * IO port primitives for more information. */ +#ifdef CONFIG_CPU_ENDIAN_BE8 +#define read_instr32 (c) __swab32(*(u32 *)(c))arch/arm/include/asm/io.h extern void _memset_io(volatile void __iomem *, int, size_t); · line 224
Quoted 10 lines
arch/arm/include/asm/io.h +9
-0+#define read_instr16 (c) __swab16(*(u16 *)(c)) +#define write_instr32 (v, a) (*(u32 *)(a) = __swab32((__force __u32)(v))) +#define write_instr16 (v, a) (*(u16 *)(a) = __swab16((__force __u16)(v))) +#else +#define read_instr32 (c) (*(u32 *)(c)) +#define read_instr16 (c) (*(u16 *)(c)) +#define write_instr32 (v, a) (*(u32 *)(a) = (v)) +#define write_instr16 (v, a) (*(u16 *)(a) = (v)) +#endif NAK. This has nothing to do with IO.
Quoted 6 lines
Quoted 2 lines
If only
module.crequires this, please move those definitions there.Not only modules, all components that needs to read and write text segment like kprobes also needs this. As it is special to arm be8, how about define it in
arch/arm/include/asm/swab.h?I'm not sure where the correct place is, but I think having macros doing something along these lines would be useful. The module loader is one relevant place, but there is also kprobes, and Rabin's recent ftrace series highlights the potential usefulness too.
There are a lot of #ifdefs and swab hacks spread around various places wherever we need to load/store/relocate instructions. Abstracting this properly so we don't need a load of fragile #ifdefs for the big-endian case is clearly a good idea.
Quoted 7 lines
Because the Thumb 32-bit case is different from the ARM case, I would also recommend having three macro variants instead of two:
*_instr_arm()*_instr_thumb16()*_instr_thumb32()
These name makes more sense than mine. I will use them. But it seems that we don't need all the three. It is enough with the first two. For reading and writing thumb code, there is no difference as 32-bit thumb code is organized as two 16-bit parts. To read a 32-bit thumb code, we need using read_instr16 to read the first part, then check if it's a 32-bit thumb, if so then use read_instr16 to read the second part.
Quoted 4 lines
Cheers
---Dave
PATCH 1/6 ARM: fix be8 support for phys/virt address conversion
In reply to Junxiao BiQuoted 9 lines · Junxiao Bi
phys_to_virt()andvirt_to_phys()is implemented by one assembler instruction, add/sub an offset between the physical and virtual address. For some arm machines withCONFIG_ARM_PATCH_PHYS_VIRTdefined, this offset is unknown at compile time, it is calculated dynamically at run time and then patched to the add/sub instruction. To support BE8 mode, firstly we need to convert the instruntion to big-endian after loading it from the memory, and then modify its offset field, at last convert it to little-endian and write it back to the memory.Signed-off-by Junxiao Bi <[email protected]>
Quoted 47 lines
--- arch/arm/kernel/head.S | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-)arch/arm/kernel/head.S +12
-0@@ -522,8 +522,14 @@ __fixup_a_pv_table: b 2f 1: add r7, r3 ldrh ip, [r7, #2] +#ifdef CONFIG_CPU_ENDIAN_BE8 + rev16 ip, ip +#endif and ip, 0x8f00 orr ip, r6 @ mask in offset bits 31-24 +#ifdef CONFIG_CPU_ENDIAN_BE8 + rev16 ip, ip +#endif strh ip, [r7, #2] 2: cmp r4, r5 ldrcc r7, [r4], #4 @ use branch for delay slot@@ -532,8 +538,14 @@ __fixup_a_pv_table: #else b 2f 1: ldr ip, [r7, r3] +#ifdef CONFIG_CPU_ENDIAN_BE8 + rev ip, ip +#endif bic ip, ip, #0x000000ff orr ip, ip, r6 @ mask in offset bits 31-24 +#ifdef CONFIG_CPU_ENDIAN_BE8 + rev ip, ip +#endif str ip, [r7, r3] 2: cmp r4, r5 ldrcc r7, [r4], #4 @ use branch for delay slotSignature · 7 lines
1.7.0.4 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel at lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel