2006-08-22 01:47:33 -06:00
|
|
|
|
/**************************************************************************
|
2007-03-18 15:23:43 -06:00
|
|
|
|
*
|
2007-02-08 16:07:29 -07:00
|
|
|
|
* Copyright (c) 2006-2007 Tungsten Graphics, Inc., Cedar Park, TX., USA
|
2006-08-22 01:47:33 -06:00
|
|
|
|
* All Rights Reserved.
|
2007-03-18 15:23:43 -06:00
|
|
|
|
*
|
2006-08-22 01:47:33 -06:00
|
|
|
|
* 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:
|
2007-03-18 15:23:43 -06:00
|
|
|
|
*
|
2007-02-08 16:07:29 -07:00
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
|
* next paragraph) shall be included in all copies or substantial portions
|
|
|
|
|
* of the Software.
|
2007-03-18 15:23:43 -06:00
|
|
|
|
*
|
2006-08-22 01:47:33 -06:00
|
|
|
|
* 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,
|
2007-03-18 15:23:43 -06:00
|
|
|
|
* 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
|
2006-08-22 01:47:33 -06:00
|
|
|
|
* USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2007-03-18 15:23:43 -06:00
|
|
|
|
*
|
2006-08-22 01:47:33 -06:00
|
|
|
|
**************************************************************************/
|
2007-02-08 16:07:29 -07:00
|
|
|
|
/*
|
|
|
|
|
* Authors: Thomas Hellstr<EFBFBD>m <thomas-at-tungstengraphics-dot-com>
|
|
|
|
|
*/
|
2006-08-22 01:47:33 -06:00
|
|
|
|
|
|
|
|
|
#include "drmP.h"
|
|
|
|
|
|
2006-10-21 06:17:51 -06:00
|
|
|
|
static void drm_ttm_ipi_handler(void *null)
|
|
|
|
|
{
|
2006-10-30 03:18:44 -07:00
|
|
|
|
flush_agp_cache();
|
2006-10-21 06:17:51 -06:00
|
|
|
|
}
|
|
|
|
|
|
2007-09-22 05:34:33 -06:00
|
|
|
|
void drm_ttm_cache_flush(void)
|
2006-10-21 06:17:51 -06:00
|
|
|
|
{
|
|
|
|
|
if (on_each_cpu(drm_ttm_ipi_handler, NULL, 1, 1) != 0)
|
|
|
|
|
DRM_ERROR("Timed out waiting for drm cache flush.\n");
|
|
|
|
|
}
|
2007-09-22 05:34:33 -06:00
|
|
|
|
EXPORT_SYMBOL(drm_ttm_cache_flush);
|
2006-10-21 06:17:51 -06:00
|
|
|
|
|
2006-09-08 09:24:38 -06:00
|
|
|
|
/*
|
|
|
|
|
* Use kmalloc if possible. Otherwise fall back to vmalloc.
|
|
|
|
|
*/
|
|
|
|
|
|
2007-12-16 01:54:25 -07:00
|
|
|
|
static void drm_ttm_alloc_pages(struct drm_ttm *ttm)
|
2006-09-08 09:24:38 -06:00
|
|
|
|
{
|
2007-01-08 21:51:29 -07:00
|
|
|
|
unsigned long size = ttm->num_pages * sizeof(*ttm->pages);
|
|
|
|
|
ttm->pages = NULL;
|
2006-09-08 09:24:38 -06:00
|
|
|
|
|
2006-10-17 11:40:57 -06:00
|
|
|
|
if (drm_alloc_memctl(size))
|
2007-01-08 21:51:29 -07:00
|
|
|
|
return;
|
|
|
|
|
|
2007-11-05 02:09:18 -07:00
|
|
|
|
if (size <= PAGE_SIZE)
|
2007-01-08 21:51:29 -07:00
|
|
|
|
ttm->pages = drm_calloc(1, size, DRM_MEM_TTM);
|
2007-11-05 02:09:18 -07:00
|
|
|
|
|
2007-01-08 21:51:29 -07:00
|
|
|
|
if (!ttm->pages) {
|
|
|
|
|
ttm->pages = vmalloc_user(size);
|
|
|
|
|
if (ttm->pages)
|
|
|
|
|
ttm->page_flags |= DRM_TTM_PAGE_VMALLOC;
|
2006-09-08 09:24:38 -06:00
|
|
|
|
}
|
2007-11-05 02:09:18 -07:00
|
|
|
|
if (!ttm->pages)
|
2006-10-17 11:40:57 -06:00
|
|
|
|
drm_free_memctl(size);
|
2006-09-08 09:24:38 -06:00
|
|
|
|
}
|
2006-09-14 08:42:00 -06:00
|
|
|
|
|
2007-12-16 01:54:25 -07:00
|
|
|
|
static void drm_ttm_free_pages(struct drm_ttm *ttm)
|
2006-09-08 09:24:38 -06:00
|
|
|
|
{
|
2007-01-08 21:51:29 -07:00
|
|
|
|
unsigned long size = ttm->num_pages * sizeof(*ttm->pages);
|
2006-10-17 11:57:06 -06:00
|
|
|
|
|
2007-01-08 21:51:29 -07:00
|
|
|
|
if (ttm->page_flags & DRM_TTM_PAGE_VMALLOC) {
|
|
|
|
|
vfree(ttm->pages);
|
|
|
|
|
ttm->page_flags &= ~DRM_TTM_PAGE_VMALLOC;
|
2006-09-14 08:42:00 -06:00
|
|
|
|
} else {
|
2007-01-08 21:51:29 -07:00
|
|
|
|
drm_free(ttm->pages, size, DRM_MEM_TTM);
|
2006-09-08 09:24:38 -06:00
|
|
|
|
}
|
2006-10-17 11:40:57 -06:00
|
|
|
|
drm_free_memctl(size);
|
2007-01-08 21:51:29 -07:00
|
|
|
|
ttm->pages = NULL;
|
2006-10-17 11:57:06 -06:00
|
|
|
|
}
|
2006-09-08 09:24:38 -06:00
|
|
|
|
|
2007-02-08 05:29:08 -07:00
|
|
|
|
static struct page *drm_ttm_alloc_page(void)
|
2006-08-22 01:47:33 -06:00
|
|
|
|
{
|
2007-02-02 06:47:44 -07:00
|
|
|
|
struct page *page;
|
2006-10-11 14:21:01 -06:00
|
|
|
|
|
2007-11-05 02:09:18 -07:00
|
|
|
|
if (drm_alloc_memctl(PAGE_SIZE))
|
2007-02-02 06:47:44 -07:00
|
|
|
|
return NULL;
|
2007-11-05 02:09:18 -07:00
|
|
|
|
|
2007-02-02 06:47:44 -07:00
|
|
|
|
page = alloc_page(GFP_KERNEL | __GFP_ZERO | GFP_DMA32);
|
|
|
|
|
if (!page) {
|
|
|
|
|
drm_free_memctl(PAGE_SIZE);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2007-11-15 02:38:55 -07:00
|
|
|
|
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15))
|
2007-02-02 06:47:44 -07:00
|
|
|
|
SetPageReserved(page);
|
2006-10-11 14:21:01 -06:00
|
|
|
|
#endif
|
2007-02-02 06:47:44 -07:00
|
|
|
|
return page;
|
2006-08-22 01:47:33 -06:00
|
|
|
|
}
|
|
|
|
|
|
2006-10-11 05:40:35 -06:00
|
|
|
|
/*
|
2007-03-18 15:23:43 -06:00
|
|
|
|
* Change caching policy for the linear kernel map
|
2006-10-11 05:40:35 -06:00
|
|
|
|
* for range of pages in a ttm.
|
|
|
|
|
*/
|
|
|
|
|
|
2007-12-16 01:54:25 -07:00
|
|
|
|
static int drm_ttm_set_caching(struct drm_ttm *ttm, int noncached)
|
2006-10-11 05:40:35 -06:00
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
struct page **cur_page;
|
|
|
|
|
int do_tlbflush = 0;
|
|
|
|
|
|
|
|
|
|
if ((ttm->page_flags & DRM_TTM_PAGE_UNCACHED) == noncached)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2007-02-12 12:34:50 -07:00
|
|
|
|
if (noncached)
|
2006-10-21 06:17:51 -06:00
|
|
|
|
drm_ttm_cache_flush();
|
|
|
|
|
|
2006-10-11 05:40:35 -06:00
|
|
|
|
for (i = 0; i < ttm->num_pages; ++i) {
|
|
|
|
|
cur_page = ttm->pages + i;
|
|
|
|
|
if (*cur_page) {
|
|
|
|
|
if (!PageHighMem(*cur_page)) {
|
|
|
|
|
if (noncached) {
|
|
|
|
|
map_page_into_agp(*cur_page);
|
|
|
|
|
} else {
|
|
|
|
|
unmap_page_from_agp(*cur_page);
|
|
|
|
|
}
|
|
|
|
|
do_tlbflush = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (do_tlbflush)
|
|
|
|
|
flush_agp_mappings();
|
|
|
|
|
|
2007-02-07 09:25:13 -07:00
|
|
|
|
DRM_FLAG_MASKED(ttm->page_flags, noncached, DRM_TTM_PAGE_UNCACHED);
|
2006-10-11 05:40:35 -06:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-02 09:03:41 -06:00
|
|
|
|
|
|
|
|
|
static void drm_ttm_free_user_pages(struct drm_ttm *ttm)
|
|
|
|
|
{
|
|
|
|
|
int write;
|
|
|
|
|
int dirty;
|
|
|
|
|
struct page *page;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
BUG_ON(!(ttm->page_flags & DRM_TTM_PAGE_USER));
|
2007-12-16 02:12:07 -07:00
|
|
|
|
write = ((ttm->page_flags & DRM_TTM_PAGE_WRITE) != 0);
|
2007-11-02 09:03:41 -06:00
|
|
|
|
dirty = ((ttm->page_flags & DRM_TTM_PAGE_USER_DIRTY) != 0);
|
|
|
|
|
|
2007-11-05 02:09:18 -07:00
|
|
|
|
for (i = 0; i < ttm->num_pages; ++i) {
|
2007-11-02 09:03:41 -06:00
|
|
|
|
page = ttm->pages[i];
|
|
|
|
|
if (page == NULL)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (page == ttm->dummy_read_page) {
|
|
|
|
|
BUG_ON(write);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (write && dirty && !PageReserved(page))
|
2007-11-15 02:38:55 -07:00
|
|
|
|
set_page_dirty_lock(page);
|
2007-11-02 09:03:41 -06:00
|
|
|
|
|
|
|
|
|
ttm->pages[i] = NULL;
|
2007-11-15 02:38:55 -07:00
|
|
|
|
put_page(page);
|
2007-11-02 09:03:41 -06:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void drm_ttm_free_alloced_pages(struct drm_ttm *ttm)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
struct drm_buffer_manager *bm = &ttm->dev->bm;
|
|
|
|
|
struct page **cur_page;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < ttm->num_pages; ++i) {
|
|
|
|
|
cur_page = ttm->pages + i;
|
|
|
|
|
if (*cur_page) {
|
2007-11-15 02:38:55 -07:00
|
|
|
|
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15))
|
2007-11-02 09:03:41 -06:00
|
|
|
|
ClearPageReserved(*cur_page);
|
|
|
|
|
#endif
|
2007-11-05 02:09:18 -07:00
|
|
|
|
if (page_count(*cur_page) != 1)
|
|
|
|
|
DRM_ERROR("Erroneous page count. Leaking pages.\n");
|
|
|
|
|
if (page_mapped(*cur_page))
|
|
|
|
|
DRM_ERROR("Erroneous map count. Leaking page mappings.\n");
|
2007-11-02 09:03:41 -06:00
|
|
|
|
__free_page(*cur_page);
|
|
|
|
|
drm_free_memctl(PAGE_SIZE);
|
|
|
|
|
--bm->cur_pages;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-22 01:47:33 -06:00
|
|
|
|
/*
|
|
|
|
|
* Free all resources associated with a ttm.
|
|
|
|
|
*/
|
|
|
|
|
|
2007-12-14 12:42:17 -07:00
|
|
|
|
int drm_ttm_destroy(struct drm_ttm *ttm)
|
2006-08-22 01:47:33 -06:00
|
|
|
|
{
|
2007-07-15 21:37:02 -06:00
|
|
|
|
struct drm_ttm_backend *be;
|
2006-08-22 01:47:33 -06:00
|
|
|
|
|
|
|
|
|
if (!ttm)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2006-10-11 05:40:35 -06:00
|
|
|
|
be = ttm->be;
|
|
|
|
|
if (be) {
|
2007-04-18 08:33:28 -06:00
|
|
|
|
be->func->destroy(be);
|
2006-10-11 05:40:35 -06:00
|
|
|
|
ttm->be = NULL;
|
2006-08-22 01:47:33 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ttm->pages) {
|
2006-10-17 11:57:06 -06:00
|
|
|
|
if (ttm->page_flags & DRM_TTM_PAGE_UNCACHED)
|
2007-12-16 01:54:25 -07:00
|
|
|
|
drm_ttm_set_caching(ttm, 0);
|
2006-10-11 05:40:35 -06:00
|
|
|
|
|
2007-11-02 09:03:41 -06:00
|
|
|
|
if (ttm->page_flags & DRM_TTM_PAGE_USER)
|
|
|
|
|
drm_ttm_free_user_pages(ttm);
|
|
|
|
|
else
|
|
|
|
|
drm_ttm_free_alloced_pages(ttm);
|
|
|
|
|
|
2007-12-16 01:54:25 -07:00
|
|
|
|
drm_ttm_free_pages(ttm);
|
2006-08-22 01:47:33 -06:00
|
|
|
|
}
|
2006-08-22 03:19:53 -06:00
|
|
|
|
|
2006-10-17 11:40:57 -06:00
|
|
|
|
drm_ctl_free(ttm, sizeof(*ttm), DRM_MEM_TTM);
|
2006-08-22 01:47:33 -06:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-05 02:09:18 -07:00
|
|
|
|
struct page *drm_ttm_get_page(struct drm_ttm *ttm, int index)
|
2007-02-08 05:29:08 -07:00
|
|
|
|
{
|
|
|
|
|
struct page *p;
|
2007-07-15 21:37:02 -06:00
|
|
|
|
struct drm_buffer_manager *bm = &ttm->dev->bm;
|
2007-02-08 05:29:08 -07:00
|
|
|
|
|
|
|
|
|
p = ttm->pages[index];
|
|
|
|
|
if (!p) {
|
|
|
|
|
p = drm_ttm_alloc_page();
|
|
|
|
|
if (!p)
|
|
|
|
|
return NULL;
|
|
|
|
|
ttm->pages[index] = p;
|
|
|
|
|
++bm->cur_pages;
|
|
|
|
|
}
|
|
|
|
|
return p;
|
|
|
|
|
}
|
2007-10-30 01:51:59 -06:00
|
|
|
|
EXPORT_SYMBOL(drm_ttm_get_page);
|
2007-02-08 05:29:08 -07:00
|
|
|
|
|
2007-12-14 14:19:35 -07:00
|
|
|
|
/**
|
|
|
|
|
* drm_ttm_set_user:
|
|
|
|
|
*
|
|
|
|
|
* @ttm: the ttm to map pages to. This must always be
|
|
|
|
|
* a freshly created ttm.
|
|
|
|
|
*
|
|
|
|
|
* @tsk: a pointer to the address space from which to map
|
|
|
|
|
* pages.
|
|
|
|
|
*
|
|
|
|
|
* @write: a boolean indicating that write access is desired
|
|
|
|
|
*
|
|
|
|
|
* start: the starting address
|
|
|
|
|
*
|
|
|
|
|
* Map a range of user addresses to a new ttm object. This
|
|
|
|
|
* provides access to user memory from the graphics device.
|
|
|
|
|
*/
|
2007-11-02 09:03:41 -06:00
|
|
|
|
int drm_ttm_set_user(struct drm_ttm *ttm,
|
|
|
|
|
struct task_struct *tsk,
|
|
|
|
|
unsigned long start,
|
2007-12-16 02:12:07 -07:00
|
|
|
|
unsigned long num_pages)
|
2007-11-02 09:03:41 -06:00
|
|
|
|
{
|
|
|
|
|
struct mm_struct *mm = tsk->mm;
|
|
|
|
|
int ret;
|
2007-12-16 02:12:07 -07:00
|
|
|
|
int write = (ttm->page_flags & DRM_TTM_PAGE_WRITE) != 0;
|
2007-11-02 09:03:41 -06:00
|
|
|
|
|
|
|
|
|
BUG_ON(num_pages != ttm->num_pages);
|
2007-12-14 12:42:17 -07:00
|
|
|
|
BUG_ON((ttm->page_flags & DRM_TTM_PAGE_USER) == 0);
|
2007-11-02 09:03:41 -06:00
|
|
|
|
|
|
|
|
|
down_read(&mm->mmap_sem);
|
|
|
|
|
ret = get_user_pages(tsk, mm, start, num_pages,
|
|
|
|
|
write, 0, ttm->pages, NULL);
|
|
|
|
|
up_read(&mm->mmap_sem);
|
|
|
|
|
|
|
|
|
|
if (ret != num_pages && write) {
|
|
|
|
|
drm_ttm_free_user_pages(ttm);
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-16 01:54:25 -07:00
|
|
|
|
/**
|
|
|
|
|
* drm_ttm_populate:
|
|
|
|
|
*
|
|
|
|
|
* @ttm: the object to allocate pages for
|
|
|
|
|
*
|
|
|
|
|
* Allocate pages for all unset page entries, then
|
|
|
|
|
* call the backend to create the hardware mappings
|
|
|
|
|
*/
|
2007-11-05 02:09:18 -07:00
|
|
|
|
int drm_ttm_populate(struct drm_ttm *ttm)
|
2006-10-11 05:40:35 -06:00
|
|
|
|
{
|
|
|
|
|
struct page *page;
|
|
|
|
|
unsigned long i;
|
2007-07-15 21:37:02 -06:00
|
|
|
|
struct drm_ttm_backend *be;
|
2006-10-11 05:40:35 -06:00
|
|
|
|
|
2006-10-17 11:57:06 -06:00
|
|
|
|
if (ttm->state != ttm_unpopulated)
|
2006-10-11 05:40:35 -06:00
|
|
|
|
return 0;
|
2006-10-17 11:57:06 -06:00
|
|
|
|
|
2006-10-11 05:40:35 -06:00
|
|
|
|
be = ttm->be;
|
2007-12-16 02:47:51 -07:00
|
|
|
|
if (ttm->page_flags & DRM_TTM_PAGE_WRITE) {
|
|
|
|
|
for (i = 0; i < ttm->num_pages; ++i) {
|
|
|
|
|
page = drm_ttm_get_page(ttm, i);
|
|
|
|
|
if (!page)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
}
|
2006-10-11 05:40:35 -06:00
|
|
|
|
}
|
2007-12-16 02:47:51 -07:00
|
|
|
|
be->func->populate(be, ttm->num_pages, ttm->pages, ttm->dummy_read_page);
|
2006-10-11 05:40:35 -06:00
|
|
|
|
ttm->state = ttm_unbound;
|
|
|
|
|
return 0;
|
2006-10-17 11:57:06 -06:00
|
|
|
|
}
|
2006-10-11 05:40:35 -06:00
|
|
|
|
|
2007-12-16 01:54:25 -07:00
|
|
|
|
/**
|
|
|
|
|
* drm_ttm_create:
|
|
|
|
|
*
|
|
|
|
|
* @dev: the drm_device
|
|
|
|
|
*
|
|
|
|
|
* @size: The size (in bytes) of the desired object
|
|
|
|
|
*
|
|
|
|
|
* @page_flags: various DRM_TTM_PAGE_* flags. See drm_object.h.
|
|
|
|
|
*
|
|
|
|
|
* Allocate and initialize a ttm, leaving it unpopulated at this time
|
2006-08-22 01:47:33 -06:00
|
|
|
|
*/
|
|
|
|
|
|
2007-12-16 02:12:07 -07:00
|
|
|
|
struct drm_ttm *drm_ttm_create(struct drm_device *dev, unsigned long size,
|
|
|
|
|
uint32_t page_flags, struct page *dummy_read_page)
|
2006-08-22 01:47:33 -06:00
|
|
|
|
{
|
2007-07-15 21:37:02 -06:00
|
|
|
|
struct drm_bo_driver *bo_driver = dev->driver->bo_driver;
|
|
|
|
|
struct drm_ttm *ttm;
|
2006-08-22 01:47:33 -06:00
|
|
|
|
|
2006-10-11 05:40:35 -06:00
|
|
|
|
if (!bo_driver)
|
2006-08-22 01:47:33 -06:00
|
|
|
|
return NULL;
|
|
|
|
|
|
2006-10-17 11:40:57 -06:00
|
|
|
|
ttm = drm_ctl_calloc(1, sizeof(*ttm), DRM_MEM_TTM);
|
2006-08-22 01:47:33 -06:00
|
|
|
|
if (!ttm)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2006-09-12 04:01:00 -06:00
|
|
|
|
ttm->dev = dev;
|
2006-08-22 01:47:33 -06:00
|
|
|
|
atomic_set(&ttm->vma_count, 0);
|
2006-08-27 11:03:20 -06:00
|
|
|
|
|
2006-08-22 03:57:08 -06:00
|
|
|
|
ttm->destroy = 0;
|
2006-08-22 01:47:33 -06:00
|
|
|
|
ttm->num_pages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
|
|
|
|
|
|
2007-12-14 12:42:17 -07:00
|
|
|
|
ttm->page_flags = page_flags;
|
2006-10-17 11:40:57 -06:00
|
|
|
|
|
2007-12-16 02:12:07 -07:00
|
|
|
|
ttm->dummy_read_page = dummy_read_page;
|
|
|
|
|
|
2006-10-17 11:40:57 -06:00
|
|
|
|
/*
|
|
|
|
|
* Account also for AGP module memory usage.
|
|
|
|
|
*/
|
|
|
|
|
|
2007-12-16 01:54:25 -07:00
|
|
|
|
drm_ttm_alloc_pages(ttm);
|
2006-08-22 01:47:33 -06:00
|
|
|
|
if (!ttm->pages) {
|
2007-12-14 12:42:17 -07:00
|
|
|
|
drm_ttm_destroy(ttm);
|
2006-08-22 01:47:33 -06:00
|
|
|
|
DRM_ERROR("Failed allocating page table\n");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2006-10-12 04:09:16 -06:00
|
|
|
|
ttm->be = bo_driver->create_ttm_backend_entry(dev);
|
2006-10-11 05:40:35 -06:00
|
|
|
|
if (!ttm->be) {
|
2007-12-14 12:42:17 -07:00
|
|
|
|
drm_ttm_destroy(ttm);
|
2006-10-11 05:40:35 -06:00
|
|
|
|
DRM_ERROR("Failed creating ttm backend entry\n");
|
2006-08-22 01:47:33 -06:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2006-10-11 05:40:35 -06:00
|
|
|
|
ttm->state = ttm_unpopulated;
|
2006-08-22 01:47:33 -06:00
|
|
|
|
return ttm;
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-16 01:54:25 -07:00
|
|
|
|
/**
|
|
|
|
|
* drm_ttm_evict:
|
|
|
|
|
*
|
|
|
|
|
* @ttm: the object to be unbound from the aperture.
|
|
|
|
|
*
|
|
|
|
|
* Transition a ttm from bound to evicted, where it
|
|
|
|
|
* isn't present in the aperture, but various caches may
|
|
|
|
|
* not be consistent.
|
2006-08-22 01:47:33 -06:00
|
|
|
|
*/
|
2007-11-05 02:09:18 -07:00
|
|
|
|
void drm_ttm_evict(struct drm_ttm *ttm)
|
2006-08-22 01:47:33 -06:00
|
|
|
|
{
|
2007-07-15 21:37:02 -06:00
|
|
|
|
struct drm_ttm_backend *be = ttm->be;
|
2007-02-02 11:49:11 -07:00
|
|
|
|
int ret;
|
2006-08-22 01:47:33 -06:00
|
|
|
|
|
2007-02-02 11:49:11 -07:00
|
|
|
|
if (ttm->state == ttm_bound) {
|
2007-04-18 08:33:28 -06:00
|
|
|
|
ret = be->func->unbind(be);
|
2007-02-02 11:49:11 -07:00
|
|
|
|
BUG_ON(ret);
|
|
|
|
|
}
|
2007-02-02 06:47:44 -07:00
|
|
|
|
|
2006-10-11 05:40:35 -06:00
|
|
|
|
ttm->state = ttm_evicted;
|
2006-08-22 01:47:33 -06:00
|
|
|
|
}
|
|
|
|
|
|
2007-12-16 01:54:25 -07:00
|
|
|
|
/**
|
|
|
|
|
* drm_ttm_fixup_caching:
|
|
|
|
|
*
|
|
|
|
|
* @ttm: the object to set unbound
|
|
|
|
|
*
|
|
|
|
|
* XXX this function is misnamed. Transition a ttm from evicted to
|
|
|
|
|
* unbound, flushing caches as appropriate.
|
|
|
|
|
*/
|
2007-11-05 02:09:18 -07:00
|
|
|
|
void drm_ttm_fixup_caching(struct drm_ttm *ttm)
|
2006-08-22 01:47:33 -06:00
|
|
|
|
{
|
|
|
|
|
|
2006-10-11 05:40:35 -06:00
|
|
|
|
if (ttm->state == ttm_evicted) {
|
2007-07-15 21:37:02 -06:00
|
|
|
|
struct drm_ttm_backend *be = ttm->be;
|
2007-11-05 02:09:18 -07:00
|
|
|
|
if (be->func->needs_ub_cache_adjust(be))
|
2007-12-16 01:54:25 -07:00
|
|
|
|
drm_ttm_set_caching(ttm, 0);
|
2006-10-11 05:40:35 -06:00
|
|
|
|
ttm->state = ttm_unbound;
|
2006-08-22 01:47:33 -06:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-16 01:54:25 -07:00
|
|
|
|
/**
|
|
|
|
|
* drm_ttm_unbind:
|
|
|
|
|
*
|
|
|
|
|
* @ttm: the object to unbind from the graphics device
|
|
|
|
|
*
|
|
|
|
|
* Unbind an object from the aperture. This removes the mappings
|
|
|
|
|
* from the graphics device and flushes caches if necessary.
|
|
|
|
|
*/
|
2007-11-05 02:09:18 -07:00
|
|
|
|
void drm_ttm_unbind(struct drm_ttm *ttm)
|
2006-08-22 01:47:33 -06:00
|
|
|
|
{
|
2006-10-17 11:57:06 -06:00
|
|
|
|
if (ttm->state == ttm_bound)
|
2007-02-02 11:49:11 -07:00
|
|
|
|
drm_ttm_evict(ttm);
|
2006-08-22 01:47:33 -06:00
|
|
|
|
|
2007-02-02 06:47:44 -07:00
|
|
|
|
drm_ttm_fixup_caching(ttm);
|
2006-08-22 01:47:33 -06:00
|
|
|
|
}
|
|
|
|
|
|
2007-12-16 01:54:25 -07:00
|
|
|
|
/**
|
|
|
|
|
* drm_ttm_bind:
|
|
|
|
|
*
|
|
|
|
|
* @ttm: the ttm object to bind to the graphics device
|
|
|
|
|
*
|
|
|
|
|
* @bo_mem: the aperture memory region which will hold the object
|
|
|
|
|
*
|
|
|
|
|
* Bind a ttm object to the aperture. This ensures that the necessary
|
|
|
|
|
* pages are allocated, flushes CPU caches as needed and marks the
|
|
|
|
|
* ttm as DRM_TTM_PAGE_USER_DIRTY to indicate that it may have been
|
|
|
|
|
* modified by the GPU
|
|
|
|
|
*/
|
|
|
|
|
int drm_ttm_bind(struct drm_ttm *ttm, struct drm_bo_mem_reg *bo_mem)
|
2006-08-22 01:47:33 -06:00
|
|
|
|
{
|
2007-10-30 01:51:59 -06:00
|
|
|
|
struct drm_bo_driver *bo_driver = ttm->dev->driver->bo_driver;
|
2006-08-22 01:47:33 -06:00
|
|
|
|
int ret = 0;
|
2007-07-15 21:37:02 -06:00
|
|
|
|
struct drm_ttm_backend *be;
|
2006-08-22 01:47:33 -06:00
|
|
|
|
|
2006-10-11 05:40:35 -06:00
|
|
|
|
if (!ttm)
|
2006-08-22 01:47:33 -06:00
|
|
|
|
return -EINVAL;
|
2006-10-11 05:40:35 -06:00
|
|
|
|
if (ttm->state == ttm_bound)
|
|
|
|
|
return 0;
|
2006-08-22 01:47:33 -06:00
|
|
|
|
|
2006-10-11 05:40:35 -06:00
|
|
|
|
be = ttm->be;
|
2006-10-17 11:57:06 -06:00
|
|
|
|
|
2006-10-11 14:21:01 -06:00
|
|
|
|
ret = drm_ttm_populate(ttm);
|
|
|
|
|
if (ret)
|
|
|
|
|
return ret;
|
2007-02-01 05:19:05 -07:00
|
|
|
|
|
2007-11-05 02:09:18 -07:00
|
|
|
|
if (ttm->state == ttm_unbound && !(bo_mem->flags & DRM_BO_FLAG_CACHED))
|
2007-12-16 01:54:25 -07:00
|
|
|
|
drm_ttm_set_caching(ttm, DRM_TTM_PAGE_UNCACHED);
|
2007-11-05 02:09:18 -07:00
|
|
|
|
else if ((bo_mem->flags & DRM_BO_FLAG_CACHED_MAPPED) &&
|
2007-10-30 01:51:59 -06:00
|
|
|
|
bo_driver->ttm_cache_flush)
|
|
|
|
|
bo_driver->ttm_cache_flush(ttm);
|
2007-02-02 11:49:11 -07:00
|
|
|
|
|
2007-11-05 02:09:18 -07:00
|
|
|
|
ret = be->func->bind(be, bo_mem);
|
|
|
|
|
if (ret) {
|
2006-10-11 14:21:01 -06:00
|
|
|
|
ttm->state = ttm_evicted;
|
2006-08-22 01:47:33 -06:00
|
|
|
|
DRM_ERROR("Couldn't bind backend.\n");
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-11 05:40:35 -06:00
|
|
|
|
ttm->state = ttm_bound;
|
2007-11-02 09:03:41 -06:00
|
|
|
|
if (ttm->page_flags & DRM_TTM_PAGE_USER)
|
|
|
|
|
ttm->page_flags |= DRM_TTM_PAGE_USER_DIRTY;
|
2006-08-22 01:47:33 -06:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
2007-12-16 01:54:25 -07:00
|
|
|
|
EXPORT_SYMBOL(drm_ttm_bind);
|