add big endian version of ld_/st_ IO access macros and convert main 8xx code to use it
PATCH 1/1 add big endian version of ld_/st_ IO access macros and convert main 8xx code to use it
Hi,
The following patch adds big endian version of ld_/st_ macros and converts core 8xx code to use them.
Other than making IO accesses explicit (which is a plus for readability), a common set of macros provides a unified place for the volatile flag to constraint compiler code reordering.
There are several unlucky places at the moment which lack the volatile flag.
arch/ppc/8xx_io/commproc.c +10 -10
@@ -73,7 +73,7 @@ cpm_mask_irq(unsigned int irq) {int cpm_vec = irq -CPM_IRQ_OFFSET ; - ((immap_t *)IMAP_ADDR )->im_cpic.cpic_cimr &= ~(1 << cpm_vec); +st_be32 (&((immap_t *)IMAP_ADDR )->im_cpic.cpic_cimr,ld_be32 (&((immap_t *)IMAP_ADDR )->im_cpic.cpic_cimr) & ~(1 << cpm_vec)); } static void
@@ -81,7 +81,7 @@ cpm_unmask_irq(unsigned int irq) {int cpm_vec = irq -CPM_IRQ_OFFSET ; - ((immap_t *)IMAP_ADDR )->im_cpic.cpic_cimr |= (1 << cpm_vec); +st_be32 (&((immap_t *)IMAP_ADDR )->im_cpic.cpic_cimr,ld_be32 (&((immap_t *)IMAP_ADDR )->im_cpic.cpic_cimr) | (1 << cpm_vec)); } static void
@@ -95,7 +95,7 @@ cpm_eoi(unsigned int irq) {int cpm_vec = irq -CPM_IRQ_OFFSET ; - ((immap_t *)IMAP_ADDR )->im_cpic.cpic_cisr = (1 << cpm_vec); +st_be32 (&((immap_t *)IMAP_ADDR )->im_cpic.cpic_cisr, (1 << cpm_vec)); }struct hw_interrupt_type cpm_pic = {
@@ -133,7 +133,7 @@ m8xx_cpm_reset(void)* manual recommends it. * Bit 25, FAM can also be set to use FEC aggressive mode (860T). */ - imp->im_siu_conf.sc_sdcr =1 ; +st_be32 (&imp->im_siu_conf.sc_sdcr,1 );/* Reclaim the DP memory for our use. */ m8xx_cpm_dpinit ();
@@ -178,10 +178,10 @@ cpm_interrupt_init(void)/* Initialize the CPM interrupt controller. */ - ((immap_t *)IMAP_ADDR )->im_cpic.cpic_cicr = +st_be32 (&((immap_t *)IMAP_ADDR )->im_cpic.cpic_cicr, (CICR_SCD_SCC4 |CICR_SCC_SCC3 |CICR_SCB_SCC2 |CICR_SCA_SCC1 ) | - ((CPM_INTERRUPT /2 ) <<13 ) |CICR_HP_MASK ; - ((immap_t *)IMAP_ADDR )->im_cpic.cpic_cimr =0 ; + ((CPM_INTERRUPT /2 ) <<13 ) |CICR_HP_MASK ); +st_be32 (&((immap_t *)IMAP_ADDR )->im_cpic.cpic_cimr,0 );/* install the CPM interrupt controller routines for the CPM * interrupt vectors
@@ -198,7 +198,7 @@ cpm_interrupt_init(void)if (setup_irq (CPM_IRQ_OFFSET +CPMVEC_ERROR , &cpm_error_irqaction))panic ("Could not allocate CPM error IRQ!" ); - ((immap_t *)IMAP_ADDR )->im_cpic.cpic_cicr |=CICR_IEN ; +st_be32 (&((immap_t *)IMAP_ADDR )->im_cpic.cpic_cicr,ld_be32 (&((immap_t *)IMAP_ADDR )->im_cpic.cpic_cicr) |CICR_IEN ); }/*
@@ -212,8 +212,8 @@ cpm_get_irq(struct pt_regs *regs)/* Get the vector by setting the ACK bit and then reading * the register. */ - ((volatile immap_t *)IMAP_ADDR )->im_cpic.cpic_civr =1 ; - cpm_vec = ((volatile immap_t *)IMAP_ADDR )->im_cpic.cpic_civr; +st_be16 (&((volatile immap_t *)IMAP_ADDR )->im_cpic.cpic_civr,1 ); + cpm_vec =ld_be16 (&((volatile immap_t *)IMAP_ADDR )->im_cpic.cpic_civr); cpm_vec >>=11 ;return cpm_vec;
arch/ppc/syslib/m8xx_setup.c +20 -25
97 lines not on this page · raw message
arch/ppc/syslib/m8xx_wdt.c +7 -7
@@ -29,8 +29,8 @@ void m8xx_wdt_reset(void) {volatile immap_t *imap = (volatile immap_t *)IMAP_ADDR ; - imap->im_siu_conf.sc_swsr =0x556c ;/* write magic1 */ - imap->im_siu_conf.sc_swsr =0xaa39 ;/* write magic2 */ +st_be16 (imap->im_siu_conf.sc_swsr,0x556c );/* write magic1 */ +st_be16 (imap->im_siu_conf.sc_swsr,0xaa39 );/* write magic2 */ }static irqreturn_t m8xx_wdt_interrupt (int irq,void *dev,struct pt_regs *regs)
@@ -39,7 +39,7 @@ static irqreturn_t m8xx_wdt_interrupt(inm8xx_wdt_reset (); - imap->im_sit.sit_piscr |=PISCR_PS ;/* clear irq */ +st_be16 (imap->im_sit.sit_piscr,ld_be16 (imap->im_sit.sit_piscr |PISCR_PS ));/* clear irq */ return IRQ_HANDLED ; }
@@ -51,7 +51,7 @@ void __init m8xx_wdt_handler_install(bd_u32 sypcr;u32 pitrtclk; - sypcr = imap->im_siu_conf.sc_sypcr; + sypcr =ld_be32 (imap->im_siu_conf.sc_sypcr);if (!(sypcr &0x04 )) { printk(KERN_NOTICE "m8xx_wdt: wdt disabled (SYPCR: 0x%08X)\n",
@@ -87,9 +87,9 @@ void __init m8xx_wdt_handler_install(bd_else pitc = pitrtclk * wdt_timeout / binfo->bi_intfreq /2 ; - imap->im_sit.sit_pitc = pitc <<16 ; - imap->im_sit.sit_piscr = - (mk_int_int_mask (PIT_INTERRUPT ) <<8 ) |PISCR_PIE |PISCR_PTE ; +st_be32 (imap->im_sit.sit_pitc, pitc <<16 ); + +st_be16 (imap->im_sit.sit_piscr, (mk_int_int_mask (PIT_INTERRUPT ) <<8 ) |PISCR_PIE |PISCR_PTE );if (setup_irq (PIT_INTERRUPT , &m8xx_wdt_irqaction))panic ("m8xx_wdt: error setting up the watchdog irq!" );
arch/ppc/syslib/ppc8xx_pic.c +6 -10
@@ -29,8 +29,7 @@ static void m8xx_mask_irq(unsigned int i word = irq_nr >>5 ; ppc_cached_irq_mask[word] &= ~(1 << (31 -bit)); - ((immap_t *)IMAP_ADDR )->im_siu_conf.sc_simask = - ppc_cached_irq_mask[word]; +st_be32 (&((immap_t *)IMAP_ADDR )->im_siu_conf.sc_simask, ppc_cached_irq_mask[word]); }static void m8xx_unmask_irq (unsigned int irq_nr)
@@ -41,8 +40,7 @@ static void m8xx_unmask_irq(unsigned int word = irq_nr >>5 ; ppc_cached_irq_mask[word] |= (1 << (31 -bit)); - ((immap_t *)IMAP_ADDR )->im_siu_conf.sc_simask = - ppc_cached_irq_mask[word]; +st_be32 (&((immap_t *)IMAP_ADDR )->im_siu_conf.sc_simask, ppc_cached_irq_mask[word]); }static void m8xx_end_irq (unsigned int irq_nr)
@@ -55,8 +53,7 @@ static void m8xx_end_irq(unsigned int ir word = irq_nr >>5 ; ppc_cached_irq_mask[word] |= (1 << (31 -bit)); - ((immap_t *)IMAP_ADDR )->im_siu_conf.sc_simask = - ppc_cached_irq_mask[word]; +st_be32 (&((immap_t *)IMAP_ADDR )->im_siu_conf.sc_simask, ppc_cached_irq_mask[word]); } }
@@ -69,9 +66,8 @@ static void m8xx_mask_and_ack(unsigned i word = irq_nr >>5 ; ppc_cached_irq_mask[word] &= ~(1 << (31 -bit)); - ((immap_t *)IMAP_ADDR )->im_siu_conf.sc_simask = - ppc_cached_irq_mask[word]; - ((immap_t *)IMAP_ADDR )->im_siu_conf.sc_sipend =1 << (31 -bit); +st_be32 (&((immap_t *)IMAP_ADDR )->im_siu_conf.sc_simask, ppc_cached_irq_mask[word]); +st_be32 (&((immap_t *)IMAP_ADDR )->im_siu_conf.sc_sipend,1 << (31 -bit)); }struct hw_interrupt_type ppc8xx_pic = {
@@ -93,7 +89,7 @@ m8xx_get_irq(struct pt_regs *regs)/* For MPC8xx, read the SIVEC register and shift the bits down * to get the irq number. */ - irq = ((immap_t *)IMAP_ADDR )->im_siu_conf.sc_sivec >>26 ; + irq =ld_be32 (&((immap_t *)IMAP_ADDR )->im_siu_conf.sc_sivec) >>26 ;/* * When we read the sivec without an interrupt to process, we will
include/asm-ppc/byteorder.h +42 -0
48 lines not on this page · raw message
Quoted 11 lines · Marcelo Tosatti
Hi,
The following patch adds big endian version of ld_/st_ macros and converts core 8xx code to use them.
Other than making IO accesses explicit (which is a plus for readability), a common set of macros provides a unified place for the volatile flag to constraint compiler code reordering.
There are several unlucky places at the moment which lack the volatile flag.
I'm not fan of the approach. You should use in_/out_ macros for IOs. If you don't need eieio on 8xx , then just #ifdef it out of the implementation of these.
Ben.
Quoted 3 lines · Benjamin Herrenschmidt
I'm not fan of the approach. You should use in_/out_ macros for IOs. If you don't need eieio on 8xx , then just #ifdef it out of the implementation of these.
Yeah, #ifdef :-) That patch wouldn't go anywhere (well, to /dev/null perhaps).
We can just use the in_/out_ macros that are there. The eieio doesn't hurt anything on the 8xx.
Thanks.
-- Dan
Quoted 8 lines · Dan Malek
Quoted 3 lines · Benjamin Herrenschmidt
I'm not fan of the approach. You should use in_/out_ macros for IOs. If you don't need eieio on 8xx , then just #ifdef it out of the implementation of these.
Yeah, #ifdef :-) That patch wouldn't go anywhere (well, to
/dev/nullperhaps).
Heh, it can be done properly: use an eieio() macro/inline and have _that_ be #ifdef'ed to nothing on 8xx...
Quoted 2 lines
We can just use the in_/out_ macros that are there. The eieio doesn't hurt anything on the 8xx.
Ok, in that case, I don't see any problem.
Ben.
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 9 lines · Marcelo Tosatti
Hi,
The following patch adds big endian version of ld_/st_ macros and converts core 8xx code to use them.
Other than making IO accesses explicit (which is a plus for readability), a common set of macros provides a unified place for the volatile flag to constraint compiler code reordering.
Quoted 6 lines
Quoted 2 lines
There are several unlucky places at the moment which lack the volatile flag.
I'm not fan of the approach. You should use in_/out_ macros for IOs. If you don't need eieio on 8xx , then just #ifdef it out of the implementation of these.
The reason for that is that in_/out_ are supposed to be the standard IO macros (conformance)? In practice most drivers using the std macros can benefit from the change.
A common routine is shared by all architectures. Doing something like
/*
* 8, 16 and 32 bit, big and little endian I/O operations, with barrier. */
extern inline int in_8(volatile unsigned char __iomem *addr)
{
int ret;
__asm__ __volatile__(
"lbz%U1%X1 %0,%1;\n"
#ifndef CONFIG_8xx
"twi 0,%0,0;\n"
"isync" : "=r" (ret) : "m" (*addr));
#else
: "=r" (ret) : "m" (*addr));
#endif
return ret;
}Seems somewhat ugly?
Quoted 9 lines · Dan Malek
Quoted 3 lines · Benjamin Herrenschmidt
I'm not fan of the approach. You should use in_/out_ macros for IOs. If you don't need eieio on 8xx , then just #ifdef it out of the implementation of these.
Yeah, #ifdef :-) That patch wouldn't go anywhere (well, to
/dev/nullperhaps).
Well, its easy to s/st/out/ - s/ld/in/, so its still a useful patch. ;)
Quoted 2 lines
We can just use the in_/out_ macros that are there. The eieio doesn't hurt anything on the 8xx.
eieio/isync are not required. There's no need to execute redudant instructions and occupy kernel space.
Quoted 20 lines
e is shared by all architectures. Doing something like
/*
* 8, 16 and 32 bit, big and little endian I/O operations, with barrier. */
extern inline intin_8(volatile unsigned char __iomem *addr){ int ret; __asm__ __volatile__( "lbz%U1%X1 %0,%1;\n" #ifndef CONFIG_8xx "twi 0,%0,0;\n" "isync" : "=r" (ret) : "m" (*addr)); #else : "=r" (ret) : "m" (*addr)); #endif return ret; }
Quoted 1 line
Seems somewhat ugly?
Yes. You can work around that by macro-generating the functions with different rules for different CPUs, or having the twi/isync be a separate asm block that is itself in a macro or inline that gets defined differently on 8xx
Ben.
Quoted 2 lines · Marcelo Tosatti
eieio/isync are not required. There's no need to execute redudant instructions and occupy kernel space.
Given how long it takes to access I/O devices, I don't believe an extra instruction or two is going to make a measurable difference. Feel free to show me measurements proving me wrong, of course... :)
Paul.
Quoted 2 lines · Paul Mackerras
Given how long it takes to access I/O devices, I don't believe an extra instruction or two is going to make a measurable difference.
That's kind of true. However, the access to the CPM is nearly instruction speed, except in the case when you actually use a real IO register (like a GPIO on a port), then it's a little slower.
-- Dan
Quoted 8 lines · Paul Mackerras
Quoted 2 lines · Marcelo Tosatti
eieio/isync are not required. There's no need to execute redudant instructions and occupy kernel space.
Given how long it takes to access I/O devices, I don't believe an extra instruction or two is going to make a measurable difference. Feel free to show me measurements proving me wrong, of course... :)
I will try to measure it later on and change out_/in_ macros as suggested.
For now are there any objections against this? Otherwise I'll merge it.
There are a few more places which need conversion, plan to change them later on also.
Thanks everyone.
arch/ppc/8xx_io/commproc.c +10 -10
@@ -73,7 +73,7 @@ cpm_mask_irq(unsigned int irq) {int cpm_vec = irq -CPM_IRQ_OFFSET ; - ((immap_t *)IMAP_ADDR )->im_cpic.cpic_cimr &= ~(1 << cpm_vec); +out_be32 (&((immap_t *)IMAP_ADDR )->im_cpic.cpic_cimr,in_be32 (&((immap_t *)IMAP_ADDR )->im_cpic.cpic_cimr) & ~(1 << cpm_vec)); } static void
@@ -81,7 +81,7 @@ cpm_unmask_irq(unsigned int irq) {int cpm_vec = irq -CPM_IRQ_OFFSET ; - ((immap_t *)IMAP_ADDR )->im_cpic.cpic_cimr |= (1 << cpm_vec); +out_be32 (&((immap_t *)IMAP_ADDR )->im_cpic.cpic_cimr,in_be32 (&((immap_t *)IMAP_ADDR )->im_cpic.cpic_cimr) | (1 << cpm_vec)); } static void
@@ -95,7 +95,7 @@ cpm_eoi(unsigned int irq) {int cpm_vec = irq -CPM_IRQ_OFFSET ; - ((immap_t *)IMAP_ADDR )->im_cpic.cpic_cisr = (1 << cpm_vec); +out_be32 (&((immap_t *)IMAP_ADDR )->im_cpic.cpic_cisr, (1 << cpm_vec)); }struct hw_interrupt_type cpm_pic = {
@@ -133,7 +133,7 @@ m8xx_cpm_reset(void)* manual recommends it. * Bit 25, FAM can also be set to use FEC aggressive mode (860T). */ - imp->im_siu_conf.sc_sdcr =1 ; +out_be32 (&imp->im_siu_conf.sc_sdcr,1 ),/* Reclaim the DP memory for our use. */ m8xx_cpm_dpinit ();
@@ -178,10 +178,10 @@ cpm_interrupt_init(void)/* Initialize the CPM interrupt controller. */ - ((immap_t *)IMAP_ADDR )->im_cpic.cpic_cicr = +out_be32 (&((immap_t *)IMAP_ADDR )->im_cpic.cpic_cicr, (CICR_SCD_SCC4 |CICR_SCC_SCC3 |CICR_SCB_SCC2 |CICR_SCA_SCC1 ) | - ((CPM_INTERRUPT /2 ) <<13 ) |CICR_HP_MASK ; - ((immap_t *)IMAP_ADDR )->im_cpic.cpic_cimr =0 ; + ((CPM_INTERRUPT /2 ) <<13 ) |CICR_HP_MASK ); +out_be32 (&((immap_t *)IMAP_ADDR )->im_cpic.cpic_cimr,0 );/* install the CPM interrupt controller routines for the CPM * interrupt vectors
@@ -198,7 +198,7 @@ cpm_interrupt_init(void)if (setup_irq (CPM_IRQ_OFFSET +CPMVEC_ERROR , &cpm_error_irqaction))panic ("Could not allocate CPM error IRQ!" ); - ((immap_t *)IMAP_ADDR )->im_cpic.cpic_cicr |=CICR_IEN ; +out_be32 (&((immap_t *)IMAP_ADDR )->im_cpic.cpic_cicr,in_be32 (&((immap_t *)IMAP_ADDR )->im_cpic.cpic_cicr) |CICR_IEN ); }/*
@@ -212,8 +212,8 @@ cpm_get_irq(struct pt_regs *regs)/* Get the vector by setting the ACK bit and then reading * the register. */ - ((volatile immap_t *)IMAP_ADDR )->im_cpic.cpic_civr =1 ; - cpm_vec = ((volatile immap_t *)IMAP_ADDR )->im_cpic.cpic_civr; +out_be16 (&((volatile immap_t *)IMAP_ADDR )->im_cpic.cpic_civr,1 ); + cpm_vec =in_be16 (&((volatile immap_t *)IMAP_ADDR )->im_cpic.cpic_civr); cpm_vec >>=11 ;return cpm_vec;
arch/ppc/syslib/m8xx_setup.c +20 -25
97 lines not on this page · raw message
arch/ppc/syslib/m8xx_wdt.c +7 -7
@@ -29,8 +29,8 @@ void m8xx_wdt_reset(void) {volatile immap_t *imap = (volatile immap_t *)IMAP_ADDR ; - imap->im_siu_conf.sc_swsr =0x556c ;/* write magic1 */ - imap->im_siu_conf.sc_swsr =0xaa39 ;/* write magic2 */ +out_be16 (imap->im_siu_conf.sc_swsr,0x556c );/* write magic1 */ +out_be16 (imap->im_siu_conf.sc_swsr,0xaa39 );/* write magic2 */ }static irqreturn_t m8xx_wdt_interrupt (int irq,void *dev,struct pt_regs *regs)
@@ -39,7 +39,7 @@ static irqreturn_t m8xx_wdt_interrupt(inm8xx_wdt_reset (); - imap->im_sit.sit_piscr |=PISCR_PS ;/* clear irq */ +out_be16 (imap->im_sit.sit_piscr,in_be16 (imap->im_sit.sit_piscr |PISCR_PS ));/* clear irq */ return IRQ_HANDLED ; }
@@ -51,7 +51,7 @@ void __init m8xx_wdt_handler_install(bd_u32 sypcr;u32 pitrtclk; - sypcr = imap->im_siu_conf.sc_sypcr; + sypcr =in_be32 (imap->im_siu_conf.sc_sypcr); irch/ppc/syslib/ppc8xx_pic.c:32:f (!(sypcr & 0x04)) { printk(KERN_NOTICE "m8xx_wdt: wdt disabled (SYPCR: 0x%08X)\n",
@@ -87,9 +87,9 @@ void __init m8xx_wdt_handler_install(bd_else pitc = pitrtclk * wdt_timeout / binfo->bi_intfreq /2 ; - imap->im_sit.sit_pitc = pitc <<16 ; - imap->im_sit.sit_piscr = - (mk_int_int_mask (PIT_INTERRUPT ) <<8 ) |PISCR_PIE |PISCR_PTE ; +out_be32 (imap->im_sit.sit_pitc, pitc <<16 ); + +out_be16 (imap->im_sit.sit_piscr, (mk_int_int_mask (PIT_INTERRUPT ) <<8 ) |PISCR_PIE |PISCR_PTE );if (setup_irq (PIT_INTERRUPT , &m8xx_wdt_irqaction))panic ("m8xx_wdt: error setting up the watchdog irq!" );
arch/ppc/syslib/ppc8xx_pic.c +7 -10
@@ -6,6 +6,7 @@#include <linux/signal.h> #include <linux/interrupt.h> #include <asm/irq.h> +#include <asm/io.h> #include <asm/8xx_immap.h> #include <asm/mpc8xx.h> #include "ppc8xx_pic.h"
@@ -29,8 +30,7 @@ static void m8xx_mask_irq(unsigned int i word = irq_nr >>5 ; ppc_cached_irq_mask[word] &= ~(1 << (31 -bit)); - ((immap_t *)IMAP_ADDR )->im_siu_conf.sc_simask = - ppc_cached_irq_mask[word]; +out_be32 (&((immap_t *)IMAP_ADDR )->im_siu_conf.sc_simask, ppc_cached_irq_mask[word]); }static void m8xx_unmask_irq (unsigned int irq_nr)
@@ -41,8 +41,7 @@ static void m8xx_unmask_irq(unsigned int word = irq_nr >>5 ; ppc_cached_irq_mask[word] |= (1 << (31 -bit)); - ((immap_t *)IMAP_ADDR )->im_siu_conf.sc_simask = - ppc_cached_irq_mask[word]; +out_be32 (&((immap_t *)IMAP_ADDR )->im_siu_conf.sc_simask, ppc_cached_irq_mask[word]); }static void m8xx_end_irq (unsigned int irq_nr)
@@ -55,8 +54,7 @@ static void m8xx_end_irq(unsigned int ir word = irq_nr >>5 ; ppc_cached_irq_mask[word] |= (1 << (31 -bit)); - ((immap_t *)IMAP_ADDR )->im_siu_conf.sc_simask = - ppc_cached_irq_mask[word]; +out_be32 (&((immap_t *)IMAP_ADDR )->im_siu_conf.sc_simask, ppc_cached_irq_mask[word]); } }
@@ -69,9 +67,8 @@ static void m8xx_mask_and_ack(unsigned i word = irq_nr >>5 ; ppc_cached_irq_mask[word] &= ~(1 << (31 -bit)); - ((immap_t *)IMAP_ADDR )->im_siu_conf.sc_simask = - ppc_cached_irq_mask[word]; - ((immap_t *)IMAP_ADDR )->im_siu_conf.sc_sipend =1 << (31 -bit); +out_be32 (&((immap_t *)IMAP_ADDR )->im_siu_conf.sc_simask, ppc_cached_irq_mask[word]); +out_be32 (&((immap_t *)IMAP_ADDR )->im_siu_conf.sc_sipend,1 << (31 -bit)); }struct hw_interrupt_type ppc8xx_pic = {
@@ -93,7 +90,7 @@ m8xx_get_irq(struct pt_regs *regs)/* For MPC8xx, read the SIVEC register and shift the bits down * to get the irq number. */ - irq = ((immap_t *)IMAP_ADDR )->im_siu_conf.sc_sivec >>26 ; + irq =in_be32 (&((immap_t *)IMAP_ADDR )->im_siu_conf.sc_sivec) >>26 ;/* * When we read the sivec without an interrupt to process, we will