2019-06-04 01:11:33 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2017-05-24 03:24:30 -07:00
|
|
|
/*
|
|
|
|
* Based on linux/arch/arm/mm/dma-mapping.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2000-2004 Russell King
|
|
|
|
*/
|
|
|
|
|
2020-09-22 06:31:03 -07:00
|
|
|
#include <linux/dma-map-ops.h>
|
2017-05-24 03:24:30 -07:00
|
|
|
#include <asm/cachetype.h>
|
|
|
|
#include <asm/cacheflush.h>
|
|
|
|
#include <asm/outercache.h>
|
|
|
|
#include <asm/cp15.h>
|
|
|
|
|
|
|
|
#include "dma.h"
|
|
|
|
|
2021-06-23 05:04:48 -07:00
|
|
|
void arch_sync_dma_for_device(phys_addr_t paddr, size_t size,
|
|
|
|
enum dma_data_direction dir)
|
2017-05-24 03:24:30 -07:00
|
|
|
{
|
|
|
|
dmac_map_area(__va(paddr), size, dir);
|
|
|
|
|
|
|
|
if (dir == DMA_FROM_DEVICE)
|
|
|
|
outer_inv_range(paddr, paddr + size);
|
|
|
|
else
|
|
|
|
outer_clean_range(paddr, paddr + size);
|
|
|
|
}
|
|
|
|
|
2021-06-23 05:04:48 -07:00
|
|
|
void arch_sync_dma_for_cpu(phys_addr_t paddr, size_t size,
|
|
|
|
enum dma_data_direction dir)
|
2017-05-24 03:24:30 -07:00
|
|
|
{
|
|
|
|
if (dir != DMA_TO_DEVICE) {
|
|
|
|
outer_inv_range(paddr, paddr + size);
|
|
|
|
dmac_unmap_area(__va(paddr), size, dir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-19 09:54:46 -07:00
|
|
|
void arch_setup_dma_ops(struct device *dev, bool coherent)
|
2017-05-24 03:24:30 -07:00
|
|
|
{
|
|
|
|
if (IS_ENABLED(CONFIG_CPU_V7M)) {
|
|
|
|
/*
|
|
|
|
* Cache support for v7m is optional, so can be treated as
|
|
|
|
* coherent if no cache has been detected. Note that it is not
|
2024-11-10 22:07:40 -07:00
|
|
|
* enough to check if MPU is in use or not since in absence of
|
2017-05-24 03:24:30 -07:00
|
|
|
* MPU system memory map is used.
|
|
|
|
*/
|
2021-06-23 05:04:48 -07:00
|
|
|
dev->dma_coherent = cacheid ? coherent : true;
|
2017-05-24 03:24:30 -07:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Assume coherent DMA in case MMU/MPU has not been set up.
|
|
|
|
*/
|
2021-06-23 05:04:48 -07:00
|
|
|
dev->dma_coherent = (get_cr() & CR_M) ? coherent : true;
|
2017-05-24 03:24:30 -07:00
|
|
|
}
|
|
|
|
}
|