Subversion Repositories Kolibri OS

Rev

Rev 4539 | 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.  
  65. static void
  66. drm_clflush_ipi_handler(void *null)
  67. {
  68.         wbinvd();
  69. }
  70. #endif
  71.  
  72. void
  73. drm_clflush_pages(struct page *pages[], unsigned long num_pages)
  74. {
  75.     uint8_t *pva;
  76.     unsigned int i, j;
  77.  
  78.     pva = AllocKernelSpace(4096);
  79.  
  80.     if(pva != NULL)
  81.     {
  82.         dma_addr_t *src, *dst;
  83.         u32 count;
  84.  
  85.         for (i = 0; i < num_pages; i++)
  86.         {
  87.             mb();
  88.             MapPage(pva, page_to_phys(pages[i]), 0x001);
  89.             for (j = 0; j < PAGE_SIZE; j += x86_clflush_size)
  90.                 clflush(pva + j);
  91.         }
  92.         FreeKernelSpace(pva);
  93.     }
  94.     mb();
  95. }
  96. EXPORT_SYMBOL(drm_clflush_pages);
  97.  
  98. void
  99. drm_clflush_sg(struct sg_table *st)
  100. {
  101.     struct sg_page_iter sg_iter;
  102.     struct page *page;
  103.  
  104.     uint8_t *pva;
  105.     unsigned int i;
  106.  
  107.     pva = AllocKernelSpace(4096);
  108.     if( pva != NULL)
  109.     {
  110.         mb();
  111.         for_each_sg_page(st->sgl, &sg_iter, st->nents, 0)
  112.         {
  113.             page = sg_page_iter_page(&sg_iter);
  114.  
  115.             MapPage(pva,page_to_phys(page), 0x001);
  116.  
  117.             for (i = 0; i < PAGE_SIZE; i += x86_clflush_size)
  118.                 clflush(pva + i);
  119.         };
  120.         FreeKernelSpace(pva);
  121.     };
  122.     mb();
  123. }
  124. EXPORT_SYMBOL(drm_clflush_sg);
  125.  
  126. #if 0
  127. void
  128. drm_clflush_virt_range(char *addr, unsigned long length)
  129. {
  130. #if defined(CONFIG_X86)
  131.         if (cpu_has_clflush) {
  132.                 char *end = addr + length;
  133.                 mb();
  134.                 for (; addr < end; addr += boot_cpu_data.x86_clflush_size)
  135.                         clflush(addr);
  136.                 clflush(end - 1);
  137.                 mb();
  138.                 return;
  139.         }
  140.  
  141.         if (on_each_cpu(drm_clflush_ipi_handler, NULL, 1) != 0)
  142.                 printk(KERN_ERR "Timed out waiting for cache flush.\n");
  143. #else
  144.         printk(KERN_ERR "Architecture has no drm_cache.c support\n");
  145.         WARN_ON_ONCE(1);
  146. #endif
  147. }
  148. EXPORT_SYMBOL(drm_clflush_virt_range);
  149.  
  150. #endif
  151.