Subversion Repositories Kolibri OS

Rev

Rev 5271 | Rev 6131 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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