Well, it works for me on a custom DM6446 board, anyway.  Somebody tell
me why I shouldn't do this, because even though it works, it feels like
black magic and I don't fully understand what I've done:

CMEM's get_phys barfs because vma->vm_pgoff==0 for the first mmap'd
buffer.  It should barf, because it assumes that it can get the physical
address of the page by simply left-shifting this value by PAGE_SHIFT...
0 is clearly erroneous given this assumption.  Deep in the bowels of
videobuf_dma_contig, though, vma->vm_pgoff is, indeed, 0 for the first
buffer, then (buffer size >> PAGE_SHIFT) for the second, and
((buffer_size*2) >> PAGE_SHIFT) for the third.  These values are already
a part of the vm_area_struct passed into __videobuf_mmap_mapper,
although where they come from, I know not.

The description of the vm_pgoff field in vm_area_struct says it is the
offset of the memory from the beginning of the file being mmap'd.  Given
that description, I would assume CMEM is doing the translation
incorrectly since it is not taking the file into account at all, as far
as I can tell.  However, vm_file + (vm_pgoff << PAGE_SHIFT) doesn't give
me the physical address of the video buffer, either.  Maybe it would
with some further translation, but I'm in over my head already.

Instead, my fix was to simply say:

vma->vm_pgoff = (mem->dma_handle >> PAGE_SHIFT);

...at the end of __videobuf_mmap_mapper.  CMEM is then able to find the
physical address of the buffers without modification.  I'm not sure
where else the vm_pgoff field might be used, so I'm not sure what side
effects this might have.  The resulting encoded video looks right, so
the side effects in this particular case may not matter.  I'm assuming
there is a reason the V4L2 drivers did what they did to start with, but
I'm no driver or VM guru.

Anybody have any insight?  I'm happy to post a patch if it seems
worthwhile.

Ryan

_______________________________________________
Davinci-linux-open-source mailing list
[email protected]
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source

Reply via email to