On Wed, 24 Aug 2005, moreau francis wrote: > Hi, > > I'm currently trying to write a USB driver for Linux. The device must be > configured by writing some values into the same register but I want to be > sure that the writing order is respected by either the compiler and the cpu. > > For example, here is a bit of driver's code: > > """ > #include <asm/io.h> > > static inline void dev_out(u32 *reg, u32 value) > { > writel(value, regs); > } > > void config_dev(void) > { > dev_out(reg_a, 0x0); /* first io */ > dev_out(reg_a, 0xA); /* second io */ > } >
This should be fine. The effect of the first bit of code plus all side-effects (if any) should be complete at the first effective sequence-point (;) but you need to change the procedure, dev_out, to: static inline void dev_out(volatile u32 *regs, u32 value) ^^^^^^^^ ... or ... just use writel() directly. wmb() just tells the compiler that memory has been changed. It already knows that but you must use the keyword, "volatile" so the compiler doesn't use something stale that's cached in registers. > void config_dev_fixed(void) > { > dev_out(reg_a, 0x0); /* first io */ > wmb(); > dev_out(reg_a, 0xA); /* second io */ > wmb(); > } > """ > > In this case, am I sure that the order will be respected ? can gcc remove > the first io while optimizing...If so, does "config_dev_fixed" fix it ? > > thanks for your answers, > > Francis > Cheers, Dick Johnson Penguin : Linux version 2.6.12.5 on an i686 machine (5537.79 BogoMips). Warning : 98.36% of all statistics are fiction. . I apologize for the following. I tried to kill it with the above dot : **************************************************************** The information transmitted in this message is confidential and may be privileged. Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited. If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to [EMAIL PROTECTED] - and destroy all copies of this information, including any attachments, without reading or disclosing them. Thank you. - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/