Raspberry-Pi-DMA-Example icon indicating copy to clipboard operation
Raspberry-Pi-DMA-Example copied to clipboard

Raspberry Pi 2 Support

Open MaPePeR opened this issue 8 years ago • 6 comments

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;
}

MaPePeR avatar Sep 12 '17 08:09 MaPePeR

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.....

NickQian avatar Mar 06 '18 09:03 NickQian

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.

NickQian avatar Mar 07 '18 09:03 NickQian

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.

MaPePeR avatar Mar 07 '18 16:03 MaPePeR

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.

juj avatar May 02 '18 08:05 juj

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.

MaPePeR avatar May 02 '18 08:05 MaPePeR

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.

juj avatar May 02 '18 09:05 juj