Raspberry Pi 2 Support
EDIT: This attempt does not really work or only sometimes.
For any future reader: To get this example working on a Raspberry Pi 2 B i had to replace this function:
uintptr_t virtToUncachedPhys(void *virt, int pagemapfd) {
return virtToPhys(virt, pagemapfd) | 0x40000000;
}
with
uintptr_t virtToUncachedPhys(void *virt, int pagemapfd) {
return virtToPhys(virt, pagemapfd) & ~0xC0000000;
}
I tried “& ~0xC0000000“ on pi 2 with Stretch, seems that cannot get correct bus address. I don't know why and I'm planning to change to use the mbox and mem_unlock method.....
I tried the mailbox and mem_lock method, it works well. I guess the mmap and "& ~0xC0000000" way doesn't work on pi2/pi3 with Stretch. they may changed some memory map method again and I don't have the details.
I got it working with that change on a PI 2, but i think it was unreliable, so i also switched to the mailbox method as well.
For any future reader: To get this example working on a Raspberry Pi 2 B i had to replace this function:
uintptr_t virtToUncachedPhys(void *virt, int pagemapfd) { return virtToPhys(virt, pagemapfd) | 0x40000000; }
with
uintptr_t virtToUncachedPhys(void *virt, int pagemapfd) { return virtToPhys(virt, pagemapfd) & ~0xC0000000; }
I think this is a red herring, and does not actually do what it looks on the surface to do. Debugging the code in action, the return value of virtToPhys(virt, pagemapfd) does not have bits 0xC0000000 set in it, so the expression virtToPhys(virt, pagemapfd) & ~0xC0000000 ends up being a no-op, or same as just returning virtToPhys(virt, pagemapfd).
Trying out the code in that form does cause the mmap allocation to superficially succeed (and not crash the Pi), but in actuality the produced virtual address is not an uncached view to the underlying physical memory, and attempting to write to that memory and then DMA from it results in DMA seeing possibly incorrect data, since the writes are still cached. I don't have a solution though.
Trying out the code in that form does cause the mmap allocation to superficially succeed (and not crash the Pi), but in actuality the produced virtual address is not an uncached view to the underlying physical memory, and attempting to write to that memory and then DMA from it results in DMA seeing possibly incorrect data, since the writes are still cached. I don't have a solution though.
This would be a good explanation for what i was seeing.
Sorry for misguiding you.
Sorry for misguiding you.
Oh no harm at all! I actually was poking on the same before having read this bug report, and ended up investigating the same thing, and only after @Wallacoloo posted the link from #3 I noticed this had had the same observation.