ttm merge ttm_backend & ttm_t V2
Subsystems (6)
Hi,
So attached is last batch of patch, i split the ttm put page fix and i fixed a bug in the pages alloc when clear flags wasn't set. I tested them on a bunch of radeon and everythings seems fine (several gl app, firefox, compositor ...). I will do more testing on agp and nouveau tomorrow.
The last patch add callback for populating and unpopulating (better name if any welcome) a ttm_tt. Allowing the driver to choose btw different choice, idea is that Konrad dma allocator would provide helper function the driver can call.
I choosed to allocate all page at once because ttm_tt object are meant to be bind and thus to be fully populated in their lifetime (vmwgfx might be different in this regard). It simplify code in several place. I didn't see any performances impact in the few gl benchmark i ran.
Konrad so i am planning on rebasing the last 4 patch of your patchset on top of that. They will likely shrink in size a bit.
Cheers,
Jerome Glisse
PATCH 1/8 drm/ttm: remove userspace backed ttm object support
From: Jerome Glisse <[email protected]>
This was never use in none of the driver, properly using userspace page for bo would need more code (vma interaction mostly). Removing this dead code in preparation of ttm_tt & backend merge.
--- drivers/gpu/drm/ttm/ttm_bo.c | 22 -------- drivers/gpu/drm/ttm/ttm_tt.c | 105 +-------------------------------------- include/drm/ttm/ttm_bo_api.h | 5 -- include/drm/ttm/ttm_bo_driver.h | 24 --------- 4 files changed, 1 insertions(+), 155 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +0 -22
@@ -342,22 +342,6 @@ static int ttm_bo_add_ttm(struct ttm_buffer_object *bo, bool zero_alloc)if (unlikely (bo->ttm ==NULL )) ret = -ENOMEM ;break ; -case ttm_bo_type_user: - bo->ttm =ttm_tt_create (bdev, bo->num_pages <<PAGE_SHIFT , - page_flags |TTM_PAGE_FLAG_USER , - glob->dummy_read_page); -if (unlikely (bo->ttm ==NULL )) { - ret = -ENOMEM ; -break ; - } - - ret =ttm_tt_set_user (bo->ttm, current, - bo->buffer_start, bo->num_pages); -if (unlikely (ret !=0 )) { -ttm_tt_destroy (bo->ttm); - bo->ttm =NULL ; - } -break ;default : printk(KERN_ERR TTM_PFX "Illegal buffer object type\n"); ret = -EINVAL ;
@@ -907,16 +891,12 @@ static uint32_t ttm_bo_select_caching(struct ttm_mem_type_manager *man, }static bool ttm_bo_mt_compatible (struct ttm_mem_type_manager *man, -bool disallow_fixed,uint32_t mem_type,uint32_t proposed_placement,uint32_t *masked_placement) {uint32_t cur_flags =ttm_bo_type_flags (mem_type); -if ((man->flags &TTM_MEMTYPE_FLAG_FIXED ) && disallow_fixed) -return false; -if ((cur_flags & proposed_placement &TTM_PL_MASK_MEM ) ==0 )return false;
@@ -961,7 +941,6 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo, man = &bdev->man[mem_type]; type_ok =ttm_bo_mt_compatible (man, - bo->type == ttm_bo_type_user, mem_type, placement->placement[i], &cur_flags);
@@ -1009,7 +988,6 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,if (!man->has_type)continue ;if (!ttm_bo_mt_compatible (man, - bo->type == ttm_bo_type_user, mem_type, placement->busy_placement[i], &cur_flags))
drivers/gpu/drm/ttm/ttm_tt.c +1 -104
141 lines not on this page · raw message
include/drm/ttm/ttm_bo_api.h +0 -5
@@ -122,17 +122,12 @@ struct ttm_mem_reg {* be mmapped by user space. Each of these bos occupy a slot in the * device address space, that can be used for normal vm operations. * -* @ttm_bo_type_user: These are user-space memory areas that are made -* available to the GPU by mapping the buffer pages into the GPU aperture -* space. These buffers cannot be mmaped from the device address space. -* * @ttm_bo_type_kernel: These buffers are like ttm_bo_type_device buffers, * but they cannot be accessed from user-space. For kernel-only use. */ enum ttm_bo_type { ttm_bo_type_device, - ttm_bo_type_user, ttm_bo_type_kernel };
include/drm/ttm/ttm_bo_driver.h +0 -24
@@ -118,8 +118,6 @@ struct ttm_backend {struct ttm_backend_func *func; }; -#define TTM_PAGE_FLAG_USER (1 << 1) -#define TTM_PAGE_FLAG_USER_DIRTY (1 << 2)#define TTM_PAGE_FLAG_WRITE (1 << 3)#define TTM_PAGE_FLAG_SWAPPED (1 << 4)#define TTM_PAGE_FLAG_PERSISTENT_SWAP (1 << 5)
@@ -146,8 +144,6 @@ enum ttm_caching_state {* @num_pages: Number of pages in the page array. * @bdev: Pointer to the current struct ttm_bo_device. * @be: Pointer to the ttm backend. -* @tsk: The task for user ttm. -* @start: virtual address for user ttm. * @swap_storage: Pointer to shmem struct file for swap storage. * @caching_state: The current caching state of the pages. * @state: The current binding state of the pages.
@@ -167,8 +163,6 @@ struct ttm_tt {unsigned long num_pages;struct ttm_bo_global *glob;struct ttm_backend *be; -struct task_struct *tsk; -unsigned long start;struct file *swap_storage;enum ttm_caching_state caching_state;enum {
@@ -618,24 +612,6 @@ extern struct ttm_tt *ttm_tt_create(struct ttm_bo_device *bdev, struct page *dummy_read_page);/** -* ttm_tt_set_user: -* -* @ttm: The struct ttm_tt to populate. -* @tsk: A struct task_struct for which @start is a valid user-space address. -* @start: A valid user-space address. -* @num_pages: Size in pages of the user memory area. -* -* Populate a struct ttm_tt with a user-space memory area after first pinning -* the pages backing it. -* Returns: -* !0: Error. -*/ - -extern int ttm_tt_set_user (struct ttm_tt *ttm, -struct task_struct *tsk, -unsigned long start,unsigned long num_pages); - -/** * ttm_ttm_bind: * * @ttm: The struct ttm_tt containing backing pages.
Signature · 1 line
1.7.1
PATCH 2/8 drm/ttm: remove split btw highmen and lowmem page
In reply to [email protected]From: Jerome Glisse <[email protected]>
Split btw highmem and lowmem page was rendered useless by the pool code. Remove it. Note further cleanup would change the ttm page allocation helper to actualy take an array instead of relying on list this could drasticly reduce the number of function call in the common case of allocation whole buffer.
--- drivers/gpu/drm/ttm/ttm_tt.c | 11 ++--------- include/drm/ttm/ttm_bo_driver.h | 7 ------- 2 files changed, 2 insertions(+), 16 deletions(-)
drivers/gpu/drm/ttm/ttm_tt.c +2 -9
@@ -69,7 +69,7 @@ static struct page *__ttm_tt_get_page(struct ttm_tt *ttm, int index)struct ttm_mem_global *mem_glob = ttm->glob->mem_glob;int ret; -while (NULL == (p = ttm->pages[index])) { +if (NULL == (p = ttm->pages[index])) {INIT_LIST_HEAD (&h);
@@ -85,10 +85,7 @@ static struct page *__ttm_tt_get_page(struct ttm_tt *ttm, int index)if (unlikely (ret !=0 )) goto out_err; -if (PageHighMem (p)) - ttm->pages[--ttm->first_himem_page] = p; -else - ttm->pages[++ttm->last_lomem_page] = p; + ttm->pages[index] = p; }return p; out_err:
@@ -270,8 +267,6 @@ static void ttm_tt_free_alloced_pages(struct ttm_tt *ttm)ttm_put_pages (&h, count, ttm->page_flags, ttm->caching_state, ttm->dma_address); ttm->state = tt_unpopulated; - ttm->first_himem_page = ttm->num_pages; - ttm->last_lomem_page =-1 ; }void ttm_tt_destroy (struct ttm_tt *ttm)
@@ -315,8 +310,6 @@ struct ttm_tt *ttm_tt_create(struct ttm_bo_device *bdev, unsigned long size, ttm->glob = bdev->glob; ttm->num_pages = (size +PAGE_SIZE -1 ) >>PAGE_SHIFT ; - ttm->first_himem_page = ttm->num_pages; - ttm->last_lomem_page =-1 ; ttm->caching_state = tt_cached; ttm->page_flags = page_flags;
include/drm/ttm/ttm_bo_driver.h +0 -7
@@ -136,11 +136,6 @@ enum ttm_caching_state {* @dummy_read_page: Page to map where the ttm_tt page array contains a NULL * pointer. * @pages: Array of pages backing the data. -* @first_himem_page: Himem pages are put last in the page array, which -* enables us to run caching attribute changes on only the first part -* of the page array containing lomem pages. This is the index of the -* first himem page. -* @last_lomem_page: Index of the last lomem page in the page array. * @num_pages: Number of pages in the page array. * @bdev: Pointer to the current struct ttm_bo_device. * @be: Pointer to the ttm backend.
@@ -157,8 +152,6 @@ enum ttm_caching_state {struct ttm_tt {struct page *dummy_read_page;struct page **pages; -long first_himem_page; -long last_lomem_page;uint32_t page_flags;unsigned long num_pages;struct ttm_bo_global *glob;
Signature · 1 line
1.7.1
PATCH 3/8 drm/ttm: remove unused backend flags field
In reply to [email protected]From: Jerome Glisse <[email protected]>
This field is not use by any of the driver just drop it.
--- drivers/gpu/drm/radeon/radeon_ttm.c | 1 - include/drm/ttm/ttm_bo_driver.h | 2 -- 2 files changed, 0 insertions(+), 3 deletions(-)
drivers/gpu/drm/radeon/radeon_ttm.c +0 -1
@@ -787,7 +787,6 @@ struct ttm_backend *radeon_ttm_backend_create(struct radeon_device *rdev)return NULL ; } gtt->backend.bdev = &rdev->mman.bdev; - gtt->backend.flags =0 ; gtt->backend.func = &radeon_backend_func; gtt->rdev = rdev; gtt->pages =NULL ;
include/drm/ttm/ttm_bo_driver.h +0 -2
@@ -106,7 +106,6 @@ struct ttm_backend_func {* struct ttm_backend * * @bdev: Pointer to a struct ttm_bo_device. -* @flags: For driver use. * @func: Pointer to a struct ttm_backend_func that describes * the backend methods. *
@@ -114,7 +113,6 @@ struct ttm_backend_func {struct ttm_backend {struct ttm_bo_device *bdev; -uint32_t flags;struct ttm_backend_func *func; };
Signature · 1 line
1.7.1
PATCH 4/8 drm/ttm: use ttm put pages function to properly restore cache attribute
In reply to [email protected]From: Jerome Glisse <[email protected]>
On failure we need to make sure the page we free has wb cache attribute. Do this pas call the proper ttm page helper function.
--- drivers/gpu/drm/ttm/ttm_tt.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
drivers/gpu/drm/ttm/ttm_tt.c +4 -1
@@ -89,7 +89,10 @@ static struct page *__ttm_tt_get_page(struct ttm_tt *ttm, int index) }return p; out_err: -put_page (p); +INIT_LIST_HEAD (&h); +list_add (&p->lru, &h); +ttm_put_pages (&h,1 , ttm->page_flags, + ttm->caching_state, &ttm->dma_address[index]);return NULL ; }
Signature · 1 line
1.7.1
PATCH 5/8 drm/ttm: convert page allocation to use page ptr array instead of list V2
In reply to [email protected]From: Jerome Glisse <[email protected]>
Use the ttm_tt page ptr array for page allocation, move the list to array unwinding into the page allocation functions.
V2 split the fix to use ttm put page as a separate fix properly fill pages array when TTM_PAGE_FLAG_ZERO_ALLOC is not set
--- drivers/gpu/drm/ttm/ttm_memory.c | 44 +++++++++++++-------- drivers/gpu/drm/ttm/ttm_page_alloc.c | 70 +++++++++++++++++++--------------- drivers/gpu/drm/ttm/ttm_tt.c | 61 ++++++++++-------------------- include/drm/ttm/ttm_memory.h | 11 +++-- include/drm/ttm/ttm_page_alloc.h | 17 ++++---- 5 files changed, 101 insertions(+), 102 deletions(-)
drivers/gpu/drm/ttm/ttm_memory.c +28 -16
@@ -543,41 +543,53 @@ int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory, }EXPORT_SYMBOL (ttm_mem_global_alloc); -int ttm_mem_global_alloc_page (struct ttm_mem_global *glob, -struct page *page, -bool no_wait,bool interruptible) +int ttm_mem_global_alloc_pages (struct ttm_mem_global *glob, +struct page **pages, +unsigned npages, +bool no_wait,bool interruptible) {struct ttm_mem_zone *zone =NULL ; +unsigned i; +int r;/** * Page allocations may be registed in a single zone * only if highmem or !dma32. */ - +for (i =0 ; i < npages; i++) {#ifdef CONFIG_HIGHMEM -if (PageHighMem (page) && glob->zone_highmem !=NULL ) - zone = glob->zone_highmem; +if (PageHighMem (pages[i]) && glob->zone_highmem !=NULL ) + zone = glob->zone_highmem;#else -if (glob->zone_dma32 &&page_to_pfn (page) >0x00100000UL ) - zone = glob->zone_kernel; +if (glob->zone_dma32 &&page_to_pfn (pages[i]) >0x00100000UL ) + zone = glob->zone_kernel;#endif -return ttm_mem_global_alloc_zone (glob, zone,PAGE_SIZE , no_wait, - interruptible); + r =ttm_mem_global_alloc_zone (glob, zone,PAGE_SIZE , no_wait, + interruptible); +if (r) { +return r; + } + } +return 0 ; } -void ttm_mem_global_free_page (struct ttm_mem_global *glob,struct page *page) +void ttm_mem_global_free_pages (struct ttm_mem_global *glob, +struct page **pages,unsigned npages) {struct ttm_mem_zone *zone =NULL ; +unsigned i; +for (i =0 ; i < npages; i++) {#ifdef CONFIG_HIGHMEM -if (PageHighMem (page) && glob->zone_highmem !=NULL ) - zone = glob->zone_highmem; +if (PageHighMem (pages[i]) && glob->zone_highmem !=NULL ) + zone = glob->zone_highmem;#else -if (glob->zone_dma32 &&page_to_pfn (page) >0x00100000UL ) - zone = glob->zone_kernel; +if (glob->zone_dma32 &&page_to_pfn (pages[i]) >0x00100000UL ) + zone = glob->zone_kernel;#endif -ttm_mem_global_free_zone (glob, zone,PAGE_SIZE ); +ttm_mem_global_free_zone (glob, zone,PAGE_SIZE ); + } }
drivers/gpu/drm/ttm/ttm_page_alloc.c +39 -31
142 lines not on this page · raw message
drivers/gpu/drm/ttm/ttm_tt.c +20 -41
104 lines not on this page · raw message
include/drm/ttm/ttm_memory.h +6 -5
@@ -150,10 +150,11 @@ extern int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory, bool no_wait, bool interruptible);extern void ttm_mem_global_free (struct ttm_mem_global *glob,uint64_t amount); -extern int ttm_mem_global_alloc_page (struct ttm_mem_global *glob, -struct page *page, -bool no_wait,bool interruptible); -extern void ttm_mem_global_free_page (struct ttm_mem_global *glob, -struct page *page); +extern int ttm_mem_global_alloc_pages (struct ttm_mem_global *glob, +struct page **pages, +unsigned npages, +bool no_wait,bool interruptible); +extern void ttm_mem_global_free_pages (struct ttm_mem_global *glob, +struct page **pages,unsigned npages);extern size_t ttm_round_pot (size_t size);#endif
include/drm/ttm/ttm_page_alloc.h +8 -9
@@ -32,29 +32,28 @@/** * Get count number of pages from pool to pages list. * -* @pages: head of empty linked list where pages are filled. +* @pages: array of pages ptr +* @npages: number of pages to allocate. * @flags: ttm flags for page allocation. * @cstate: ttm caching state for the page. -* @count: number of pages to allocate. * @dma_address: The DMA (bus) address of pages (if TTM_PAGE_FLAG_DMA32 set). */ -int ttm_get_pages (struct list_head *pages, +int ttm_get_pages (struct page **pages, +unsigned npages,int flags,enum ttm_caching_state cstate, -unsigned count,dma_addr_t *dma_address);/** * Put linked list of pages to pool. * -* @pages: list of pages to free. -* @page_count: number of pages in the list. Zero can be passed for unknown -* count. +* @pages: array of pages ptr +* @npages: number of pages to free. * @flags: ttm flags for page allocation. * @cstate: ttm caching state. * @dma_address: The DMA (bus) address of pages (if TTM_PAGE_FLAG_DMA32 set). */ -void ttm_put_pages (struct list_head *pages, -unsigned page_count, +void ttm_put_pages (struct page **pages, +unsigned npages,int flags,enum ttm_caching_state cstate,dma_addr_t *dma_address);
Signature · 1 line
1.7.1
PATCH 6/8 drm/ttm: test for dma_address array allocation failure
In reply to [email protected]From: Jerome Glisse <[email protected]>
--- drivers/gpu/drm/ttm/ttm_tt.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/gpu/drm/ttm/ttm_tt.c +1 -1
@@ -298,7 +298,7 @@ struct ttm_tt *ttm_tt_create(struct ttm_bo_device *bdev, unsigned long size, ttm->dummy_read_page = dummy_read_page;ttm_tt_alloc_page_directory (ttm); -if (!ttm->pages) { +if (!ttm->pages || !ttm->dma_address) {ttm_tt_destroy (ttm); printk(KERN_ERR TTM_PFX "Failed allocating page table\n");return NULL ;
Signature · 1 line
1.7.1
PATCH 7/8 drm/ttm: merge ttm_backend and ttm_tt
In reply to [email protected]From: Jerome Glisse <[email protected]>
ttm_backend will exist only and only with a ttm_tt, and ttm_tt will be of interesting use only when bind to a backend. Thus to avoid code & data duplication btw the two merge them.
--- drivers/gpu/drm/nouveau/nouveau_bo.c | 14 ++- drivers/gpu/drm/nouveau/nouveau_drv.h | 5 +- drivers/gpu/drm/nouveau/nouveau_sgdma.c | 188 ++++++++++++-------------- drivers/gpu/drm/radeon/radeon_ttm.c | 222 ++++++++++++------------------- drivers/gpu/drm/ttm/ttm_agp_backend.c | 88 +++++-------- drivers/gpu/drm/ttm/ttm_bo.c | 9 +- drivers/gpu/drm/ttm/ttm_tt.c | 59 ++------- drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c | 66 +++------ include/drm/ttm/ttm_bo_driver.h | 104 ++++++--------- 9 files changed, 295 insertions(+), 460 deletions(-)
drivers/gpu/drm/nouveau/nouveau_bo.c +9 -5
@@ -343,8 +343,10 @@ nouveau_bo_wr32(struct nouveau_bo *nvbo, unsigned index, u32 val) *mem = val; } -static struct ttm_backend * -nouveau_bo_create_ttm_backend_entry (struct ttm_bo_device *bdev) +static struct ttm_tt * +nouveau_ttm_tt_create (struct ttm_bo_device *bdev, +unsigned long size,uint32_t page_flags, +struct page *dummy_read_page) {struct drm_nouveau_private *dev_priv =nouveau_bdev (bdev);struct drm_device *dev = dev_priv->dev;
@@ -352,11 +354,13 @@ nouveau_bo_create_ttm_backend_entry(struct ttm_bo_device *bdev)switch (dev_priv->gart_info.type) {#if __OS_HAS_AGPcase NOUVEAU_GART_AGP : -return ttm_agp_backend_init (bdev, dev->agp->bridge); +return ttm_agp_tt_create (bdev, dev->agp->bridge, + size, page_flags, dummy_read_page);#endif case NOUVEAU_GART_PDMA :case NOUVEAU_GART_HW : -return nouveau_sgdma_init_ttm (dev); +return nouveau_sgdma_create_ttm (bdev, size, page_flags, + dummy_read_page);default :NV_ERROR (dev,"Unknown GART type %d\n" , dev_priv->gart_info.type);
@@ -1045,7 +1049,7 @@ nouveau_bo_fence(struct nouveau_bo *nvbo, struct nouveau_fence *fence) }struct ttm_bo_driver nouveau_bo_driver = { - .create_ttm_backend_entry = nouveau_bo_create_ttm_backend_entry, + .ttm_tt_create = &nouveau_ttm_tt_create, .invalidate_caches = nouveau_bo_invalidate_caches, .init_mem_type = nouveau_bo_init_mem_type, .evict_flags = nouveau_bo_evict_flags,
drivers/gpu/drm/nouveau/nouveau_drv.h +4 -1
@@ -1000,7 +1000,10 @@ extern int nouveau_sgdma_init(struct drm_device *);extern void nouveau_sgdma_takedown (struct drm_device *);extern uint32_t nouveau_sgdma_get_physical (struct drm_device *,uint32_t offset); -extern struct ttm_backend *nouveau_sgdma_init_ttm (struct drm_device *); +extern struct ttm_tt *nouveau_sgdma_create_ttm (struct ttm_bo_device *bdev, +unsigned long size, +uint32_t page_flags, +struct page *dummy_read_page);/* nouveau_debugfs.c */ #if defined(CONFIG_DRM_NOUVEAU_DEBUG )
drivers/gpu/drm/nouveau/nouveau_sgdma.c +85 -103
376 lines not on this page · raw message
drivers/gpu/drm/radeon/radeon_ttm.c +86 -136
241 lines not on this page · raw message
drivers/gpu/drm/ttm/ttm_agp_backend.c +34 -54
139 lines not on this page · raw message
drivers/gpu/drm/ttm/ttm_bo.c +3 -6
@@ -337,8 +337,8 @@ static int ttm_bo_add_ttm(struct ttm_buffer_object *bo, bool zero_alloc)if (zero_alloc) page_flags |=TTM_PAGE_FLAG_ZERO_ALLOC ;case ttm_bo_type_kernel: - bo->ttm =ttm_tt_create (bdev, bo->num_pages <<PAGE_SHIFT , - page_flags, glob->dummy_read_page); + bo->ttm = bdev->driver->ttm_tt_create (bdev, bo->num_pages <<PAGE_SHIFT , + page_flags, glob->dummy_read_page);if (unlikely (bo->ttm ==NULL )) ret = -ENOMEM ;break ;
@@ -1437,10 +1437,7 @@ int ttm_bo_global_init(struct drm_global_reference *ref) goto out_no_shrink; } - glob->ttm_bo_extra_size = -ttm_round_pot (sizeof (struct ttm_tt )) + -ttm_round_pot (sizeof (struct ttm_backend )); - + glob->ttm_bo_extra_size =ttm_round_pot (sizeof (struct ttm_tt )); glob->ttm_bo_size = glob->ttm_bo_extra_size +ttm_round_pot (sizeof (struct ttm_buffer_object ));
drivers/gpu/drm/ttm/ttm_tt.c +12 -47
139 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c +21 -45
113 lines not on this page · raw message
include/drm/ttm/ttm_bo_driver.h +41 -63
186 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 8/8 drm/ttm: introduce callback for ttm_tt populate & unpopulate
In reply to [email protected]From: Jerome Glisse <[email protected]>
Move the page allocation and freeing to driver callback and provide ttm code helper function for those.
Most intrusive change, is the fact that we now only fully populate an object this simplify some of code designed around the page fault design.
--- drivers/gpu/drm/nouveau/nouveau_bo.c | 3 + drivers/gpu/drm/radeon/radeon_ttm.c | 2 + drivers/gpu/drm/ttm/ttm_bo_util.c | 31 ++++++----- drivers/gpu/drm/ttm/ttm_bo_vm.c | 13 ++-- drivers/gpu/drm/ttm/ttm_page_alloc.c | 42 ++++++++++++++ drivers/gpu/drm/ttm/ttm_tt.c | 97 +++---------------------------- drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c | 3 + include/drm/ttm/ttm_bo_driver.h | 41 ++++++++------ include/drm/ttm/ttm_page_alloc.h | 18 ++++++ 9 files changed, 125 insertions(+), 125 deletions(-)
drivers/gpu/drm/nouveau/nouveau_bo.c +3 -0
@@ -28,6 +28,7 @@*/ #include "drmP.h" +#include "ttm/ttm_page_alloc.h" #include "nouveau_drm.h" #include "nouveau_drv.h"
@@ -1050,6 +1051,8 @@ nouveau_bo_fence(struct nouveau_bo *nvbo, struct nouveau_fence *fence)struct ttm_bo_driver nouveau_bo_driver = { .ttm_tt_create = &nouveau_ttm_tt_create, + .ttm_tt_populate = &ttm_page_alloc_ttm_tt_populate, + .ttm_tt_unpopulate = &ttm_page_alloc_ttm_tt_unpopulate, .invalidate_caches = nouveau_bo_invalidate_caches, .init_mem_type = nouveau_bo_init_mem_type, .evict_flags = nouveau_bo_evict_flags,
drivers/gpu/drm/radeon/radeon_ttm.c +2 -0
@@ -584,6 +584,8 @@ struct ttm_tt *radeon_ttm_tt_create(struct ttm_bo_device *bdev,static struct ttm_bo_driver radeon_bo_driver = { .ttm_tt_create = &radeon_ttm_tt_create, + .ttm_tt_populate = &ttm_page_alloc_ttm_tt_populate, + .ttm_tt_unpopulate = &ttm_page_alloc_ttm_tt_unpopulate, .invalidate_caches = &radeon_invalidate_caches, .init_mem_type = &radeon_init_mem_type, .evict_flags = &radeon_evict_flags,
drivers/gpu/drm/ttm/ttm_bo_util.c +17 -14
@@ -244,7 +244,7 @@ static int ttm_copy_io_ttm_page(struct ttm_tt *ttm, void *src, unsigned long page, pgprot_t prot) { -struct page *d =ttm_tt_get_page (ttm, page); +struct page *d = ttm->pages[page];void *dst;if (!d)
@@ -281,7 +281,7 @@ static int ttm_copy_ttm_io_page(struct ttm_tt *ttm, void *dst, unsigned long page, pgprot_t prot) { -struct page *s =ttm_tt_get_page (ttm, page); +struct page *s = ttm->pages[page];void *src;if (!s)
@@ -342,6 +342,12 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,if (old_iomap ==NULL && ttm ==NULL ) goto out2; +if (ttm->state == tt_unpopulated) { + ret = ttm->bdev->driver->ttm_tt_populate (ttm); +if (ret) + goto out1; + } + add =0 ; dir =1 ;
@@ -502,10 +508,16 @@ static int ttm_bo_kmap_ttm(struct ttm_buffer_object *bo, {struct ttm_mem_reg *mem = &bo->mem;pgprot_t prot;struct ttm_tt *ttm = bo->ttm; -struct page *d; -int i; +int ret;BUG_ON (!ttm); + +if (ttm->state == tt_unpopulated) { + ret = ttm->bdev->driver->ttm_tt_populate (ttm); +if (ret) +return ret; + } +if (num_pages ==1 && (mem->placement &TTM_PL_FLAG_CACHED )) {/* * We're mapping a single page, and the desired
@@ -513,18 +525,9 @@ static int ttm_bo_kmap_ttm(struct ttm_buffer_object *bo,*/ map->bo_kmap_type = ttm_bo_map_kmap; - map->page =ttm_tt_get_page (ttm, start_page); + map->page = ttm->pages[start_page]; map->virtual =kmap (map->page); }else { -/* -* Populate the part we're mapping; -*/ -for (i = start_page; i < start_page + num_pages; ++i) { - d =ttm_tt_get_page (ttm, i); -if (!d) -return -ENOMEM ; - } -/* * We need to use vmap to get the desired page protection * or to make the buffer object look contiguous.
drivers/gpu/drm/ttm/ttm_bo_vm.c +7 -6
@@ -174,18 +174,19 @@ static int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf) vma->vm_page_prot = (bo->mem.placement &TTM_PL_FLAG_CACHED ) ?vm_get_page_prot (vma->vm_flags) :ttm_io_prot (bo->mem.placement, vma->vm_page_prot); - } -/* -* Speculatively prefault a number of pages. Only error on -* first page. -*/ +/* Allocate all page at once, most common usage */ +if (ttm->bdev->driver->ttm_tt_populate (ttm)) { + retval =VM_FAULT_OOM ; + goto out_io_unlock; + } + }for (i =0 ; i <TTM_BO_VM_NUM_PREFAULT ; ++i) {if (bo->mem.bus.is_iomem) pfn = ((bo->mem.bus.base + bo->mem.bus.offset) >>PAGE_SHIFT ) + page_offset;else { - page =ttm_tt_get_page (ttm, page_offset); + page = ttm->pages[page_offset];if (unlikely (!page && i ==0 )) { retval =VM_FAULT_OOM ; goto out_io_unlock;
drivers/gpu/drm/ttm/ttm_page_alloc.c +42 -0
48 lines not on this page · raw message
drivers/gpu/drm/ttm/ttm_tt.c +10 -87
157 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c +3 -0
@@ -28,6 +28,7 @@#include "vmwgfx_drv.h" #include "ttm/ttm_bo_driver.h" #include "ttm/ttm_placement.h" +#include "ttm/ttm_page_alloc.h" static uint32_t vram_placement_flags =TTM_PL_FLAG_VRAM |TTM_PL_FLAG_CACHED ;
@@ -334,6 +335,8 @@ static int vmw_sync_obj_wait(void *sync_obj, void *sync_arg,struct ttm_bo_driver vmw_bo_driver = { .ttm_tt_create = &vmw_ttm_tt_create, + .ttm_tt_populate = &ttm_page_alloc_ttm_tt_populate, + .ttm_tt_unpopulate = &ttm_page_alloc_ttm_tt_unpopulate, .invalidate_caches = vmw_invalidate_caches, .init_mem_type = vmw_init_mem_type, .evict_flags = vmw_evict_flags,
include/drm/ttm/ttm_bo_driver.h +23 -18
63 lines not on this page · raw message
include/drm/ttm/ttm_page_alloc.h +18 -0
@@ -67,6 +67,24 @@ int ttm_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages);void ttm_page_alloc_fini (void );/** +* ttm_page_alloc_ttm_tt_populate: +* +* @ttm: The struct ttm_tt to contain the backing pages. +* +* Add backing pages to all of @ttm +*/ +extern int ttm_page_alloc_ttm_tt_populate (struct ttm_tt *ttm); + +/** +* ttm_page_alloc_ttm_tt_unpopulate: +* +* @ttm: The struct ttm_tt which to free backing pages. +* +* Free all pages of @ttm +*/ +extern void ttm_page_alloc_ttm_tt_unpopulate (struct ttm_tt *ttm); + +/** * Output the state of pools to debugfs file */ extern int ttm_page_alloc_debugfs (struct seq_file *m,void *data);
Signature · 1 line
1.7.1
Re: [PATCH 4/8] drm/ttm: use ttm put pages function to properly restore cache attribute
In reply to [email protected]Quoted 6 lines · On Wed, Nov 02, 2011 at 07:37:51PM -0400, [email protected] wrote:
From: Jerome Glisse <[email protected]>
On failure we need to make sure the page we free has wb cache attribute. Do this pas call the proper ttm page helper function.
Signed-off-by Jerome Glisse <[email protected]>
Reviewed-by...
Quoted 22 lines
--- drivers/gpu/drm/ttm/ttm_tt.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)drivers/gpu/drm/ttm/ttm_tt.c +4
-1@@ -89,7 +89,10 @@ static struct page *__ttm_tt_get_page(struct ttm_tt *ttm, int index) }return p; out_err: -put_page (p); +INIT_LIST_HEAD (&h); +list_add (&p->lru, &h); +ttm_put_pages (&h,1 , ttm->page_flags, + ttm->caching_state, &ttm->dma_address[index]);return NULL ; }Signature · 1 line
1.7.1
Re: [PATCH 5/8] drm/ttm: convert page allocation to use page ptr array instead of list V2
In reply to [email protected]Quoted 10 lines · On Wed, Nov 02, 2011 at 07:37:52PM -0400, [email protected] wrote:
From: Jerome Glisse <[email protected]>
Use the
ttm_ttpage ptr array for page allocation, move the list to array unwinding into the page allocation functions.V2 split the fix to use ttm put page as a separate fix properly fill pages array when
TTM_PAGE_FLAG_ZERO_ALLOCis not setSigned-off-by Jerome Glisse <[email protected]>
.. snip..
Quoted 9 lines
static void
ttm_tt_free_alloced_pages(struct ttm_tt *ttm){drivers/gpu/drm/ttm/ttm_tt.c +0
-6-int i; -unsigned count =0 ; -struct list_head h; -struct page *cur_page;struct ttm_backend *be = ttm->be; - -INIT_LIST_HEAD (&h);
drivers/gpu/drm/ttm/ttm_tt.c EXPORT_SYMBOL(ttm_tt_set_placement_caching); · line 260
Quoted 10 lines
drivers/gpu/drm/ttm/ttm_tt.c +1
-5+struct ttm_mem_global *glob = ttm->glob->mem_glob;if (be) be->func->clear (be); -for (i =0 ; i < ttm->num_pages; ++i) { - cur_page = ttm->pages[i]; - ttm->pages[i] =NULL ; -if (cur_page) { -if (page_count (cur_page) !=1 )
We don't want to keep that check? Or perhaps move that functionality into ttm_put_pages?
Quoted 6 lines
drivers/gpu/drm/ttm/ttm_tt.c +0
-6- printk(KERN_ERR TTM_PFX -"Erroneous page count. " - "Leaking pages.\n"); -ttm_mem_global_free_page (ttm->glob->mem_glob, - cur_page); -list_add (&cur_page->lru, &h);
drivers/gpu/drm/ttm/ttm_tt.c EXPORT_SYMBOL(ttm_tt_set_placement_caching); · line 252
Quoted 10 lines
drivers/gpu/drm/ttm/ttm_tt.c +3
-5- count++; - } - } -ttm_put_pages (&h, count, ttm->page_flags, ttm->caching_state, - ttm->dma_address); +ttm_mem_global_free_pages (glob, ttm->pages, ttm->num_pages); +ttm_put_pages (ttm->pages, ttm->num_pages, ttm->page_flags, + ttm->caching_state, ttm->dma_address); ttm->state = tt_unpopulated; }
Otherwise Reviewd-by...
Re: [PATCH 6/8] drm/ttm: test for dma_address array allocation failure
In reply to [email protected]Quoted 3 lines · On Wed, Nov 02, 2011 at 07:37:53PM -0400, [email protected] wrote:
From: Jerome Glisse <[email protected]>
Signed-off-by Jerome Glisse <[email protected]>
Reviewed-by-me.
Quoted 19 lines
--- drivers/gpu/drm/ttm/ttm_tt.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)drivers/gpu/drm/ttm/ttm_tt.c +1
-1@@ -298,7 +298,7 @@ struct ttm_tt *ttm_tt_create(struct ttm_bo_device *bdev, unsigned long size, ttm->dummy_read_page = dummy_read_page;ttm_tt_alloc_page_directory (ttm); -if (!ttm->pages) { +if (!ttm->pages || !ttm->dma_address) {ttm_tt_destroy (ttm); printk(KERN_ERR TTM_PFX "Failed allocating page table\n");return NULL ;Signature · 1 line
1.7.1