On Fri, Feb 20, 2009 at 07:09:51PM +0530, arun c wrote: > PCI host machine (PPC cpu) writes commands to > the PCI memory space of the (Coldfire CPU) > target device. Target device takes the command > and executes it. > > Target devices SDRAM is exposed over PCI to host. > A circular buffer residing on target memory is used > for command exchange. > > I should not allow host and target to play on the > buffer simultaneously in order to avoid corruption. > > Does anybody know how to implement a lock > suitable for this issue? > > or any lock less algorithm exists for communication > over PCI? I would have thought that a standard head and tail lockless queue would be perfect for your application. Expressed in C: struct queue { unsigned head; unsigned entries[QUEUE_SIZE]; unsigned tail; } int queue_size(struct queue __iomem *q) { int size = readl(&q->head) - readl(&q->tail); if (size < 0) size += QUEUE_SIZE; return size; } int queue_empty(struct queue __iomem *q) { return readl(&q->head) == readl(&q->tail); } int queue_push(struct queue __iomem *q, unsigned item) { unsigned head = readl(&q->head) + 1; if (head == readl(&q->tail)) return FAIL; writel(&q->entries[head], item); writel(&q->head, head); } Something like that anyway ... I obviously haven't tested or even compiled it. -- Matthew Wilcox Intel Open Source Technology Centre "Bill, look, we understand that you're interested in selling us this operating system, but compare it to ours. We can't possibly take such a retrograde step." -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ