Skip to content

Commit 3d50d4d

Browse files
GnurouBen Skeggs
authored andcommitted
drm/ttm: expose CPU address of DMA-allocated pages
Pages allocated using the DMA API have a coherent memory mapping. Make this mapping visible to drivers so they can decide to use it instead of creating their own redundant one. Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Acked-by: David Airlie <airlied@linux.ie> Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
1 parent 7963e9d commit 3d50d4d

3 files changed

Lines changed: 12 additions & 5 deletions

File tree

‎drivers/gpu/drm/ttm/ttm_page_alloc_dma.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,7 @@ static int ttm_dma_pool_get_pages(struct dma_pool *pool,
848848
if (count) {
849849
d_page = list_first_entry(&pool->free_list, struct dma_page, page_list);
850850
ttm->pages[index] = d_page->p;
851+
ttm_dma->cpu_address[index] = d_page->vaddr;
851852
ttm_dma->dma_address[index] = d_page->dma;
852853
list_move_tail(&d_page->page_list, &ttm_dma->pages_list);
853854
r = 0;
@@ -979,6 +980,7 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev)
979980
INIT_LIST_HEAD(&ttm_dma->pages_list);
980981
for (i = 0; i < ttm->num_pages; i++) {
981982
ttm->pages[i] = NULL;
983+
ttm_dma->cpu_address[i] = 0;
982984
ttm_dma->dma_address[i] = 0;
983985
}
984986

‎drivers/gpu/drm/ttm/ttm_tt.c‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,12 @@ static void ttm_tt_alloc_page_directory(struct ttm_tt *ttm)
5555

5656
static void ttm_dma_tt_alloc_page_directory(struct ttm_dma_tt *ttm)
5757
{
58-
ttm->ttm.pages = drm_calloc_large(ttm->ttm.num_pages, sizeof(void*));
59-
ttm->dma_address = drm_calloc_large(ttm->ttm.num_pages,
60-
sizeof(*ttm->dma_address));
58+
ttm->ttm.pages = drm_calloc_large(ttm->ttm.num_pages,
59+
sizeof(*ttm->ttm.pages) +
60+
sizeof(*ttm->dma_address) +
61+
sizeof(*ttm->cpu_address));
62+
ttm->cpu_address = (void *) (ttm->ttm.pages + ttm->ttm.num_pages);
63+
ttm->dma_address = (void *) (ttm->cpu_address + ttm->ttm.num_pages);
6164
}
6265

6366
#ifdef CONFIG_X86
@@ -228,7 +231,7 @@ int ttm_dma_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_bo_device *bdev,
228231

229232
INIT_LIST_HEAD(&ttm_dma->pages_list);
230233
ttm_dma_tt_alloc_page_directory(ttm_dma);
231-
if (!ttm->pages || !ttm_dma->dma_address) {
234+
if (!ttm->pages) {
232235
ttm_tt_destroy(ttm);
233236
pr_err("Failed allocating page table\n");
234237
return -ENOMEM;
@@ -243,7 +246,7 @@ void ttm_dma_tt_fini(struct ttm_dma_tt *ttm_dma)
243246

244247
drm_free_large(ttm->pages);
245248
ttm->pages = NULL;
246-
drm_free_large(ttm_dma->dma_address);
249+
ttm_dma->cpu_address = NULL;
247250
ttm_dma->dma_address = NULL;
248251
}
249252
EXPORT_SYMBOL(ttm_dma_tt_fini);

‎include/drm/ttm/ttm_bo_driver.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ struct ttm_tt {
133133
* struct ttm_dma_tt
134134
*
135135
* @ttm: Base ttm_tt struct.
136+
* @cpu_address: The CPU address of the pages
136137
* @dma_address: The DMA (bus) addresses of the pages
137138
* @pages_list: used by some page allocation backend
138139
*
@@ -142,6 +143,7 @@ struct ttm_tt {
142143
*/
143144
struct ttm_dma_tt {
144145
struct ttm_tt ttm;
146+
void **cpu_address;
145147
dma_addr_t *dma_address;
146148
struct list_head pages_list;
147149
};

0 commit comments

Comments
 (0)