• Paul Burton's avatar
    MIPS: Perform post-DMA cache flushes on systems with MAARs · cad482c1
    Paul Burton authored
    Recent CPUs from Imagination Technologies such as the I6400 or P6600 are
    able to speculatively fetch data from memory into caches. This means
    that if used in a system with non-coherent DMA they require that caches
    be invalidated after a device performs DMA, and before the CPU reads the
    DMA'd data, in order to ensure that stale values weren't speculatively
    prefetched.
    
    Such CPUs also introduced Memory Accessibility Attribute Registers
    (MAARs) in order to control the regions in which they are allowed to
    speculate. Thus we can use the presence of MAARs as a good indication
    that the CPU requires the above cache maintenance. Use the presence of
    MAARs to determine the result of cpu_needs_post_dma_flush() in the
    default case, in order to handle these recent CPUs correctly.
    
    Note that the return type of cpu_needs_post_dma_flush() is changed to
    bool, such that it's clearer what's happening when cpu_has_maar is cast
    to bool for the return value. If this patch were backported to a
    pre-v4.7 kernel then MIPS_CPU_MAAR was 1ull<<34, so when cast to an int
    we would incorrectly return 0. It so happens that MIPS_CPU_MAAR is
    currently 1ull<<30, so when truncated to an int gives a non-zero value
    anyway, but even so the implicit conversion from long long int to bool
    makes it clearer to understand what will happen than the implicit
    conversion from long long int to int would. The bool return type also
    fits this usage better semantically, so seems like an all-round win.
    
    Thanks to Ed for spotting the issue for pre-v4.7 kernels & suggesting
    the return type change.
    Signed-off-by: default avatarPaul Burton <paul.burton@imgtec.com>
    Reviewed-by: default avatarBryan O'Donoghue <pure.logic@nexus-software.ie>
    Tested-by: default avatarBryan O'Donoghue <pure.logic@nexus-software.ie>
    Cc: Ed Blake <ed.blake@imgtec.com>
    Cc: linux-mips@linux-mips.org
    Patchwork: https://patchwork.linux-mips.org/patch/16363/Signed-off-by: default avatarRalf Baechle <ralf@linux-mips.org>
    cad482c1
dma-default.c 11.9 KB