Subversion Repositories Kolibri OS

Rev

Rev 4293 | Rev 5271 | 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 <linux/scatterlist.h>
  33. #include <drm/drmP.h>
  34.  
  35. extern int x86_clflush_size;
  36.  
  37. static inline void clflush(volatile void *__p)
  38. {
  39.     asm volatile("clflush %0" : "+m" (*(volatile char*)__p));
  40. }
  41.  
  42. #if 0
  43. static void
  44. drm_clflush_page(struct page *page)
  45. {
  46.         uint8_t *page_virtual;
  47.         unsigned int i;
  48.         const int size = boot_cpu_data.x86_clflush_size;
  49.  
  50.         if (unlikely(page == NULL))
  51.                 return;
  52.  
  53.         page_virtual = kmap_atomic(page);
  54.         for (i = 0; i < PAGE_SIZE; i += size)
  55.                 clflush(page_virtual + i);
  56.         kunmap_atomic(page_virtual);
  57. }
  58.  
  59. static void drm_cache_flush_clflush(struct page *pages[],
  60.                                     unsigned long num_pages)
  61. {
  62.         unsigned long i;
  63.  
  64.         mb();
  65.         for (i = 0; i < num_pages; i++)
  66.                 drm_clflush_page(*pages++);
  67.         mb();
  68. }
  69.  
  70. static void
  71. drm_clflush_ipi_handler(void *null)
  72. {
  73.         wbinvd();
  74. }
  75. #endif
  76.  
  77. void
  78. drm_clflush_pages(struct page *pages[], unsigned long num_pages)
  79. {
  80.     uint8_t *pva;
  81.     unsigned int i, j;
  82.  
  83.     pva = AllocKernelSpace(4096);
  84.  
  85.     if(pva != NULL)
  86.     {
  87.         dma_addr_t *src, *dst;
  88.         u32 count;
  89.  
  90.         for (i = 0; i < num_pages; i++)
  91.         {
  92.             mb();
  93.             MapPage(pva, page_to_phys(pages[i]), 0x001);
  94.             for (j = 0; j < PAGE_SIZE; j += x86_clflush_size)
  95.                 clflush(pva + j);
  96.         }
  97.         FreeKernelSpace(pva);
  98.     }
  99.     mb();
  100. }
  101. EXPORT_SYMBOL(drm_clflush_pages);
  102.  
  103. void
  104. drm_clflush_sg(struct sg_table *st)
  105. {
  106.     struct sg_page_iter sg_iter;
  107.     struct page *page;
  108.  
  109.     uint8_t *pva;
  110.     unsigned int i;
  111.  
  112.     pva = AllocKernelSpace(4096);
  113.     if( pva != NULL)
  114.     {
  115.         mb();
  116.         for_each_sg_page(st->sgl, &sg_iter, st->nents, 0)
  117.         {
  118.             page = sg_page_iter_page(&sg_iter);
  119.  
  120.             MapPage(pva,page_to_phys(page), 0x001);
  121.  
  122.             for (i = 0; i < PAGE_SIZE; i += x86_clflush_size)
  123.                 clflush(pva + i);
  124.         };
  125.         FreeKernelSpace(pva);
  126.     };
  127.     mb();
  128. }
  129. EXPORT_SYMBOL(drm_clflush_sg);
  130.  
  131. #if 0
  132. void
  133. drm_clflush_virt_range(char *addr, unsigned long length)
  134. {
  135. #if defined(CONFIG_X86)
  136.         if (cpu_has_clflush) {
  137.                 char *end = addr + length;
  138.                 mb();
  139.                 for (; addr < end; addr += boot_cpu_data.x86_clflush_size)
  140.                         clflush(addr);
  141.                 clflush(end - 1);
  142.                 mb();
  143.                 return;
  144.         }
  145.  
  146.         if (on_each_cpu(drm_clflush_ipi_handler, NULL, 1) != 0)
  147.                 printk(KERN_ERR "Timed out waiting for cache flush.\n");
  148. #else
  149.         printk(KERN_ERR "Architecture has no drm_cache.c support\n");
  150.         WARN_ON_ONCE(1);
  151. #endif
  152. }
  153. EXPORT_SYMBOL(drm_clflush_virt_range);
  154.  
  155. #endif
  156.