• Tomi Valkeinen's avatar
    media: ti-vpe: cal: fix DMA memory corruption · 3dc4365b
    Tomi Valkeinen authored
    When the CAL driver stops streaming, it will shut everything down
    without waiting for the current frame to finish. This leaves the CAL DMA
    in a slightly undefined state, and when CAL DMA is enabled when the
    stream is started the next time, the old DMA transfer will continue.
    
    It is not clear if the old DMA transfer continues with the exact
    settings of the original transfer, or is it a mix of old and new
    settings, but in any case the end result is memory corruption as the
    destination memory address is no longer valid.
    
    I could not find any way to ensure that any old DMA transfer would be
    discarded, except perhaps full CAL reset. But we cannot do a full reset
    when one port is getting enabled, as that would reset both ports.
    
    This patch tries to make sure that the DMA transfer is finished properly
    when the stream is being stopped. I say "tries", as, as mentioned above,
    I don't see a way to force the DMA transfer to finish. I believe this
    fixes the corruptions for normal cases, but if for some reason the DMA
    of the final frame would stall a lot, resulting in timeout in the code
    waiting for the DMA to finish, we'll again end up with unfinished DMA
    transfer. However, I don't know what could cause such a timeout.
    Signed-off-by: default avatarTomi Valkeinen <tomi.valkeinen@ti.com>
    Reviewed-by: default avatarBenoit Parrot <bparrot@ti.com>
    Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
    Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
    3dc4365b
cal.c 62.3 KB