Re: Q: volatile vs barriers to access memory data changed by deviceDMA
From: Alan Cox
Date: Mon Feb 25 2008 - 03:42:18 EST
> === after conversion
> struct bus_master_interface *interface;
> while (interface->ack != OK) {
> ÂÂÂÂÂÂÂÂdelay(a short while);
> ÂÂÂÂÂÂÂÂrmb();
> [ after X loops device changes interface->ack by dma ]
> };
>
> All I need is for the read of interface->ack in the loop not to be optimised
> away - is rmb() the appropriate incantation to achieve this?
Yes - ish. You want the equivalent of
do {
rmb();
if (interface->ack == OK)
break;
} while(1);
(eg putting another rmb before the while in your case)
You want a barrier before the *first* read in case the
compiler has managed to cache the value before you enter the loop.
> struct bus_master_interface *interface;
> interface->cmd = command;
> wmb();
> iowrite(device_interrupt, 1);
Yes.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/