/**************************************************************************1*2* Copyright 2009 Red Hat Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR18* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,19* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL20* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,21* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR22* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE23* USE OR OTHER DEALINGS IN THE SOFTWARE.24*25*26**************************************************************************/27/*28* Authors:29* Dave Airlie <[email protected]>30*/3132#ifndef _DRM_CACHE_H_33#define _DRM_CACHE_H_3435#include <linux/scatterlist.h>3637struct iosys_map;3839void drm_clflush_pages(struct page *pages[], unsigned long num_pages);40void drm_clflush_sg(struct sg_table *st);41void drm_clflush_virt_range(void *addr, unsigned long length);42bool drm_need_swiotlb(int dma_bits);434445static inline bool drm_arch_can_wc_memory(void)46{47#if defined(CONFIG_PPC) && !defined(CONFIG_NOT_COHERENT_CACHE)48return false;49#elif defined(CONFIG_MIPS) && defined(CONFIG_CPU_LOONGSON64)50return false;51#elif defined(CONFIG_ARM) || defined(CONFIG_ARM64)52/*53* The DRM driver stack is designed to work with cache coherent devices54* only, but permits an optimization to be enabled in some cases, where55* for some buffers, both the CPU and the GPU use uncached mappings,56* removing the need for DMA snooping and allocation in the CPU caches.57*58* The use of uncached GPU mappings relies on the correct implementation59* of the PCIe NoSnoop TLP attribute by the platform, otherwise the GPU60* will use cached mappings nonetheless. On x86 platforms, this does not61* seem to matter, as uncached CPU mappings will snoop the caches in any62* case. However, on ARM and arm64, enabling this optimization on a63* platform where NoSnoop is ignored results in loss of coherency, which64* breaks correct operation of the device. Since we have no way of65* detecting whether NoSnoop works or not, just disable this66* optimization entirely for ARM and arm64.67*/68return false;69#elif defined(CONFIG_LOONGARCH)70/*71* LoongArch maintains cache coherency in hardware, but its WUC attribute72* (Weak-ordered UnCached, which is similar to WC) is out of the scope of73* cache coherency machanism. This means WUC can only used for write-only74* memory regions.75*/76return false;77#else78return true;79#endif80}8182void drm_memcpy_init_early(void);8384void drm_memcpy_from_wc(struct iosys_map *dst,85const struct iosys_map *src,86unsigned long len);87#endif888990