/**************************************************************************1*2* Copyright (c) 2006-2007 Tungsten Graphics, Inc., Cedar Park, TX., USA3* 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* Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>28*/2930#include "drmP.h"3132#if defined(CONFIG_X86)33static void34drm_clflush_page(struct page *page)35{36uint8_t *page_virtual;37unsigned int i;3839if (unlikely(page == NULL))40return;4142page_virtual = kmap_atomic(page, KM_USER0);43for (i = 0; i < PAGE_SIZE; i += boot_cpu_data.x86_clflush_size)44clflush(page_virtual + i);45kunmap_atomic(page_virtual, KM_USER0);46}4748static void drm_cache_flush_clflush(struct page *pages[],49unsigned long num_pages)50{51unsigned long i;5253mb();54for (i = 0; i < num_pages; i++)55drm_clflush_page(*pages++);56mb();57}5859static void60drm_clflush_ipi_handler(void *null)61{62wbinvd();63}64#endif6566void67drm_clflush_pages(struct page *pages[], unsigned long num_pages)68{6970#if defined(CONFIG_X86)71if (cpu_has_clflush) {72drm_cache_flush_clflush(pages, num_pages);73return;74}7576if (on_each_cpu(drm_clflush_ipi_handler, NULL, 1) != 0)77printk(KERN_ERR "Timed out waiting for cache flush.\n");7879#elif defined(__powerpc__)80unsigned long i;81for (i = 0; i < num_pages; i++) {82struct page *page = pages[i];83void *page_virtual;8485if (unlikely(page == NULL))86continue;8788page_virtual = kmap_atomic(page, KM_USER0);89flush_dcache_range((unsigned long)page_virtual,90(unsigned long)page_virtual + PAGE_SIZE);91kunmap_atomic(page_virtual, KM_USER0);92}93#else94printk(KERN_ERR "Architecture has no drm_cache.c support\n");95WARN_ON_ONCE(1);96#endif97}98EXPORT_SYMBOL(drm_clflush_pages);99100101