Skip to content

Commit

Permalink
drm/ttm: consolidate cache flushing code in one place.
Browse files Browse the repository at this point in the history
This merges the TTM and drm cache flushing into one file in the
drm core.

Signed-off-by: Dave Airlie <airlied@redhat.com>
  • Loading branch information
Dave Airlie committed Aug 26, 2009
1 parent 50f1530 commit c9c97b8
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 74 deletions.
51 changes: 42 additions & 9 deletions drivers/gpu/drm/drm_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,58 @@ drm_clflush_page(struct page *page)
clflush(page_virtual + i);
kunmap_atomic(page_virtual, KM_USER0);
}
#endif

static void drm_cache_flush_clflush(struct page *pages[],
unsigned long num_pages)
{
unsigned long i;

mb();
for (i = 0; i < num_pages; i++)
drm_clflush_page(*pages++);
mb();
}

static void
drm_clflush_ipi_handler(void *null)
{
wbinvd();
}
#elif !defined(__powerpc__)
static void drm_cache_ipi_handler(void *dummy)
{
}
#endif
void
drm_clflush_pages(struct page *pages[], unsigned long num_pages)
{

#if defined(CONFIG_X86)
if (cpu_has_clflush) {
unsigned long i;

mb();
for (i = 0; i < num_pages; ++i)
drm_clflush_page(*pages++);
mb();

drm_cache_flush_clflush(pages, num_pages);
return;
}

wbinvd();
if (on_each_cpu(drm_clflush_ipi_handler, NULL, 1) != 0)
printk(KERN_ERR "Timed out waiting for cache flush.\n");

#elif defined(__powerpc__)
unsigned long i;
for (i = 0; i < num_pages; i++) {
struct page *page = pages[i];
void *page_virtual;

if (unlikely(page == NULL))
continue;

page_virtual = kmap_atomic(page, KM_USER0);
flush_dcache_range((unsigned long)page_virtual,
(unsigned long)page_virtual + PAGE_SIZE);
kunmap_atomic(page_virtual, KM_USER0);
}
#else
if (on_each_cpu(drm_clflush_ipi_handler, NULL, 1) != 0)
printk(KERN_ERR "Timed out waiting for drm cache flush\n");
#endif
}
EXPORT_SYMBOL(drm_clflush_pages);
67 changes: 2 additions & 65 deletions drivers/gpu/drm/ttm/ttm_tt.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,76 +34,13 @@
#include <linux/pagemap.h>
#include <linux/file.h>
#include <linux/swap.h>
#include "drm_cache.h"
#include "ttm/ttm_module.h"
#include "ttm/ttm_bo_driver.h"
#include "ttm/ttm_placement.h"

static int ttm_tt_swapin(struct ttm_tt *ttm);

#if defined(CONFIG_X86)
static void ttm_tt_clflush_page(struct page *page)
{
uint8_t *page_virtual;
unsigned int i;

if (unlikely(page == NULL))
return;

page_virtual = kmap_atomic(page, KM_USER0);

for (i = 0; i < PAGE_SIZE; i += boot_cpu_data.x86_clflush_size)
clflush(page_virtual + i);

kunmap_atomic(page_virtual, KM_USER0);
}

static void ttm_tt_cache_flush_clflush(struct page *pages[],
unsigned long num_pages)
{
unsigned long i;

mb();
for (i = 0; i < num_pages; ++i)
ttm_tt_clflush_page(*pages++);
mb();
}
#elif !defined(__powerpc__)
static void ttm_tt_ipi_handler(void *null)
{
;
}
#endif

void ttm_tt_cache_flush(struct page *pages[], unsigned long num_pages)
{

#if defined(CONFIG_X86)
if (cpu_has_clflush) {
ttm_tt_cache_flush_clflush(pages, num_pages);
return;
}
#elif defined(__powerpc__)
unsigned long i;

for (i = 0; i < num_pages; ++i) {
struct page *page = pages[i];
void *page_virtual;

if (unlikely(page == NULL))
continue;

page_virtual = kmap_atomic(page, KM_USER0);
flush_dcache_range((unsigned long) page_virtual,
(unsigned long) page_virtual + PAGE_SIZE);
kunmap_atomic(page_virtual, KM_USER0);
}
#else
if (on_each_cpu(ttm_tt_ipi_handler, NULL, 1) != 0)
printk(KERN_ERR TTM_PFX
"Timed out waiting for drm cache flush.\n");
#endif
}

/**
* Allocates storage for pointers to the pages that back the ttm.
*
Expand Down Expand Up @@ -302,7 +239,7 @@ static int ttm_tt_set_caching(struct ttm_tt *ttm,
}

if (ttm->caching_state == tt_cached)
ttm_tt_cache_flush(ttm->pages, ttm->num_pages);
drm_clflush_pages(ttm->pages, ttm->num_pages);

for (i = 0; i < ttm->num_pages; ++i) {
cur_page = ttm->pages[i];
Expand Down
38 changes: 38 additions & 0 deletions include/drm/drm_cache.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**************************************************************************
*
* Copyright 2009 Red Hat Inc.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
* USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*
**************************************************************************/
/*
* Authors:
* Dave Airlie <airlied@redhat.com>
*/

#ifndef _DRM_CACHE_H_
#define _DRM_CACHE_H_

void drm_clflush_pages(struct page *pages[], unsigned long num_pages);

#endif

0 comments on commit c9c97b8

Please sign in to comment.