Home | History | Annotate | Line # | Download | only in drm
drm_cache.c revision 1.1
      1  1.1  riastrad /**************************************************************************
      2  1.1  riastrad  *
      3  1.1  riastrad  * Copyright (c) 2006-2007 Tungsten Graphics, Inc., Cedar Park, TX., USA
      4  1.1  riastrad  * All Rights Reserved.
      5  1.1  riastrad  *
      6  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
      7  1.1  riastrad  * copy of this software and associated documentation files (the
      8  1.1  riastrad  * "Software"), to deal in the Software without restriction, including
      9  1.1  riastrad  * without limitation the rights to use, copy, modify, merge, publish,
     10  1.1  riastrad  * distribute, sub license, and/or sell copies of the Software, and to
     11  1.1  riastrad  * permit persons to whom the Software is furnished to do so, subject to
     12  1.1  riastrad  * the following conditions:
     13  1.1  riastrad  *
     14  1.1  riastrad  * The above copyright notice and this permission notice (including the
     15  1.1  riastrad  * next paragraph) shall be included in all copies or substantial portions
     16  1.1  riastrad  * of the Software.
     17  1.1  riastrad  *
     18  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     19  1.1  riastrad  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     20  1.1  riastrad  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
     21  1.1  riastrad  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
     22  1.1  riastrad  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
     23  1.1  riastrad  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
     24  1.1  riastrad  * USE OR OTHER DEALINGS IN THE SOFTWARE.
     25  1.1  riastrad  *
     26  1.1  riastrad  **************************************************************************/
     27  1.1  riastrad /*
     28  1.1  riastrad  * Authors: Thomas Hellstrm <thomas-at-tungstengraphics-dot-com>
     29  1.1  riastrad  */
     30  1.1  riastrad 
     31  1.1  riastrad #include <linux/export.h>
     32  1.1  riastrad #include <drm/drmP.h>
     33  1.1  riastrad 
     34  1.1  riastrad #if defined(CONFIG_X86)
     35  1.1  riastrad static void
     36  1.1  riastrad drm_clflush_page(struct page *page)
     37  1.1  riastrad {
     38  1.1  riastrad 	uint8_t *page_virtual;
     39  1.1  riastrad 	unsigned int i;
     40  1.1  riastrad 	const int size = boot_cpu_data.x86_clflush_size;
     41  1.1  riastrad 
     42  1.1  riastrad 	if (unlikely(page == NULL))
     43  1.1  riastrad 		return;
     44  1.1  riastrad 
     45  1.1  riastrad 	page_virtual = kmap_atomic(page);
     46  1.1  riastrad 	for (i = 0; i < PAGE_SIZE; i += size)
     47  1.1  riastrad 		clflush(page_virtual + i);
     48  1.1  riastrad 	kunmap_atomic(page_virtual);
     49  1.1  riastrad }
     50  1.1  riastrad 
     51  1.1  riastrad static void drm_cache_flush_clflush(struct page *pages[],
     52  1.1  riastrad 				    unsigned long num_pages)
     53  1.1  riastrad {
     54  1.1  riastrad 	unsigned long i;
     55  1.1  riastrad 
     56  1.1  riastrad 	mb();
     57  1.1  riastrad 	for (i = 0; i < num_pages; i++)
     58  1.1  riastrad 		drm_clflush_page(*pages++);
     59  1.1  riastrad 	mb();
     60  1.1  riastrad }
     61  1.1  riastrad 
     62  1.1  riastrad static void
     63  1.1  riastrad drm_clflush_ipi_handler(void *null)
     64  1.1  riastrad {
     65  1.1  riastrad 	wbinvd();
     66  1.1  riastrad }
     67  1.1  riastrad #endif
     68  1.1  riastrad 
     69  1.1  riastrad void
     70  1.1  riastrad drm_clflush_pages(struct page *pages[], unsigned long num_pages)
     71  1.1  riastrad {
     72  1.1  riastrad 
     73  1.1  riastrad #if defined(CONFIG_X86)
     74  1.1  riastrad 	if (cpu_has_clflush) {
     75  1.1  riastrad 		drm_cache_flush_clflush(pages, num_pages);
     76  1.1  riastrad 		return;
     77  1.1  riastrad 	}
     78  1.1  riastrad 
     79  1.1  riastrad 	if (on_each_cpu(drm_clflush_ipi_handler, NULL, 1) != 0)
     80  1.1  riastrad 		printk(KERN_ERR "Timed out waiting for cache flush.\n");
     81  1.1  riastrad 
     82  1.1  riastrad #elif defined(__powerpc__)
     83  1.1  riastrad 	unsigned long i;
     84  1.1  riastrad 	for (i = 0; i < num_pages; i++) {
     85  1.1  riastrad 		struct page *page = pages[i];
     86  1.1  riastrad 		void *page_virtual;
     87  1.1  riastrad 
     88  1.1  riastrad 		if (unlikely(page == NULL))
     89  1.1  riastrad 			continue;
     90  1.1  riastrad 
     91  1.1  riastrad 		page_virtual = kmap_atomic(page);
     92  1.1  riastrad 		flush_dcache_range((unsigned long)page_virtual,
     93  1.1  riastrad 				   (unsigned long)page_virtual + PAGE_SIZE);
     94  1.1  riastrad 		kunmap_atomic(page_virtual);
     95  1.1  riastrad 	}
     96  1.1  riastrad #else
     97  1.1  riastrad 	printk(KERN_ERR "Architecture has no drm_cache.c support\n");
     98  1.1  riastrad 	WARN_ON_ONCE(1);
     99  1.1  riastrad #endif
    100  1.1  riastrad }
    101  1.1  riastrad EXPORT_SYMBOL(drm_clflush_pages);
    102  1.1  riastrad 
    103  1.1  riastrad void
    104  1.1  riastrad drm_clflush_sg(struct sg_table *st)
    105  1.1  riastrad {
    106  1.1  riastrad #if defined(CONFIG_X86)
    107  1.1  riastrad 	if (cpu_has_clflush) {
    108  1.1  riastrad 		struct scatterlist *sg;
    109  1.1  riastrad 		int i;
    110  1.1  riastrad 
    111  1.1  riastrad 		mb();
    112  1.1  riastrad 		for_each_sg(st->sgl, sg, st->nents, i)
    113  1.1  riastrad 			drm_clflush_page(sg_page(sg));
    114  1.1  riastrad 		mb();
    115  1.1  riastrad 
    116  1.1  riastrad 		return;
    117  1.1  riastrad 	}
    118  1.1  riastrad 
    119  1.1  riastrad 	if (on_each_cpu(drm_clflush_ipi_handler, NULL, 1) != 0)
    120  1.1  riastrad 		printk(KERN_ERR "Timed out waiting for cache flush.\n");
    121  1.1  riastrad #else
    122  1.1  riastrad 	printk(KERN_ERR "Architecture has no drm_cache.c support\n");
    123  1.1  riastrad 	WARN_ON_ONCE(1);
    124  1.1  riastrad #endif
    125  1.1  riastrad }
    126  1.1  riastrad EXPORT_SYMBOL(drm_clflush_sg);
    127  1.1  riastrad 
    128  1.1  riastrad void
    129  1.1  riastrad drm_clflush_virt_range(char *addr, unsigned long length)
    130  1.1  riastrad {
    131  1.1  riastrad #if defined(CONFIG_X86)
    132  1.1  riastrad 	if (cpu_has_clflush) {
    133  1.1  riastrad 		char *end = addr + length;
    134  1.1  riastrad 		mb();
    135  1.1  riastrad 		for (; addr < end; addr += boot_cpu_data.x86_clflush_size)
    136  1.1  riastrad 			clflush(addr);
    137  1.1  riastrad 		clflush(end - 1);
    138  1.1  riastrad 		mb();
    139  1.1  riastrad 		return;
    140  1.1  riastrad 	}
    141  1.1  riastrad 
    142  1.1  riastrad 	if (on_each_cpu(drm_clflush_ipi_handler, NULL, 1) != 0)
    143  1.1  riastrad 		printk(KERN_ERR "Timed out waiting for cache flush.\n");
    144  1.1  riastrad #else
    145  1.1  riastrad 	printk(KERN_ERR "Architecture has no drm_cache.c support\n");
    146  1.1  riastrad 	WARN_ON_ONCE(1);
    147  1.1  riastrad #endif
    148  1.1  riastrad }
    149  1.1  riastrad EXPORT_SYMBOL(drm_clflush_virt_range);
    150