18c2ecf20Sopenharmony_ci/**************************************************************************
28c2ecf20Sopenharmony_ci *
38c2ecf20Sopenharmony_ci * Copyright 2009 Red Hat Inc.
48c2ecf20Sopenharmony_ci * All Rights Reserved.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
78c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the
88c2ecf20Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
98c2ecf20Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
108c2ecf20Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
118c2ecf20Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
128c2ecf20Sopenharmony_ci * the following conditions:
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the
158c2ecf20Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
168c2ecf20Sopenharmony_ci * of the Software.
178c2ecf20Sopenharmony_ci *
188c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
198c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
208c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
218c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
228c2ecf20Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
238c2ecf20Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
248c2ecf20Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE.
258c2ecf20Sopenharmony_ci *
268c2ecf20Sopenharmony_ci *
278c2ecf20Sopenharmony_ci **************************************************************************/
288c2ecf20Sopenharmony_ci/*
298c2ecf20Sopenharmony_ci * Authors:
308c2ecf20Sopenharmony_ci * Dave Airlie <airlied@redhat.com>
318c2ecf20Sopenharmony_ci */
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#ifndef _DRM_CACHE_H_
348c2ecf20Sopenharmony_ci#define _DRM_CACHE_H_
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#include <linux/scatterlist.h>
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_civoid drm_clflush_pages(struct page *pages[], unsigned long num_pages);
398c2ecf20Sopenharmony_civoid drm_clflush_sg(struct sg_table *st);
408c2ecf20Sopenharmony_civoid drm_clflush_virt_range(void *addr, unsigned long length);
418c2ecf20Sopenharmony_cibool drm_need_swiotlb(int dma_bits);
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cistatic inline bool drm_arch_can_wc_memory(void)
458c2ecf20Sopenharmony_ci{
468c2ecf20Sopenharmony_ci#if defined(CONFIG_PPC) && !defined(CONFIG_NOT_COHERENT_CACHE)
478c2ecf20Sopenharmony_ci	return false;
488c2ecf20Sopenharmony_ci#elif defined(CONFIG_MIPS) && defined(CONFIG_CPU_LOONGSON64)
498c2ecf20Sopenharmony_ci	return false;
508c2ecf20Sopenharmony_ci#elif defined(CONFIG_ARM) || defined(CONFIG_ARM64)
518c2ecf20Sopenharmony_ci	/*
528c2ecf20Sopenharmony_ci	 * The DRM driver stack is designed to work with cache coherent devices
538c2ecf20Sopenharmony_ci	 * only, but permits an optimization to be enabled in some cases, where
548c2ecf20Sopenharmony_ci	 * for some buffers, both the CPU and the GPU use uncached mappings,
558c2ecf20Sopenharmony_ci	 * removing the need for DMA snooping and allocation in the CPU caches.
568c2ecf20Sopenharmony_ci	 *
578c2ecf20Sopenharmony_ci	 * The use of uncached GPU mappings relies on the correct implementation
588c2ecf20Sopenharmony_ci	 * of the PCIe NoSnoop TLP attribute by the platform, otherwise the GPU
598c2ecf20Sopenharmony_ci	 * will use cached mappings nonetheless. On x86 platforms, this does not
608c2ecf20Sopenharmony_ci	 * seem to matter, as uncached CPU mappings will snoop the caches in any
618c2ecf20Sopenharmony_ci	 * case. However, on ARM and arm64, enabling this optimization on a
628c2ecf20Sopenharmony_ci	 * platform where NoSnoop is ignored results in loss of coherency, which
638c2ecf20Sopenharmony_ci	 * breaks correct operation of the device. Since we have no way of
648c2ecf20Sopenharmony_ci	 * detecting whether NoSnoop works or not, just disable this
658c2ecf20Sopenharmony_ci	 * optimization entirely for ARM and arm64.
668c2ecf20Sopenharmony_ci	 */
678c2ecf20Sopenharmony_ci	return false;
688c2ecf20Sopenharmony_ci#elif defined(CONFIG_LOONGARCH)
698c2ecf20Sopenharmony_ci	/*
708c2ecf20Sopenharmony_ci	 * LoongArch maintains cache coherency in hardware, but its WUC attribute
718c2ecf20Sopenharmony_ci	 * (Weak-ordered UnCached, which is similar to WC) is out of the scope of
728c2ecf20Sopenharmony_ci	 * cache coherency machanism. This means WUC can only used for write-only
738c2ecf20Sopenharmony_ci	 * memory regions.
748c2ecf20Sopenharmony_ci	 */
758c2ecf20Sopenharmony_ci	return false;
768c2ecf20Sopenharmony_ci#else
778c2ecf20Sopenharmony_ci	return true;
788c2ecf20Sopenharmony_ci#endif
798c2ecf20Sopenharmony_ci}
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci#endif
82