Skip to content

Commit 718370f

Browse files
Jocelyn FalempeMaarten Lankhorst
authored andcommitted
drm/ttm: Add ttm_bo_kmap_try_from_panic()
If the ttm bo is backed by pages, then it's possible to safely kmap one page at a time, using kmap_try_from_panic(). Unfortunately there is no way to do the same with ioremap, so it only supports the kmap case. This is needed for proper drm_panic support with xe driver. Signed-off-by: Jocelyn Falempe <[email protected]> Reviewed-by: Christian König <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Maarten Lankhorst <[email protected]>
1 parent 796f437 commit 718370f

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

drivers/gpu/drm/ttm/ttm_bo_util.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,33 @@ static int ttm_bo_kmap_ttm(struct ttm_buffer_object *bo,
381381
return (!map->virtual) ? -ENOMEM : 0;
382382
}
383383

384+
/**
385+
*
386+
* ttm_bo_kmap_try_from_panic
387+
*
388+
* @bo: The buffer object
389+
* @page: The page to map
390+
*
391+
* Sets up a kernel virtual mapping using kmap_local_page_try_from_panic().
392+
* This should only be called from the panic handler, if you make sure the bo
393+
* is the one being displayed, so is properly allocated, and protected.
394+
*
395+
* Returns the vaddr, that you can use to write to the bo, and that you should
396+
* pass to kunmap_local() when you're done with this page, or NULL if the bo
397+
* is in iomem.
398+
*/
399+
void *ttm_bo_kmap_try_from_panic(struct ttm_buffer_object *bo, unsigned long page)
400+
{
401+
if (page + 1 > PFN_UP(bo->resource->size))
402+
return NULL;
403+
404+
if (!bo->resource->bus.is_iomem && bo->ttm->pages && bo->ttm->pages[page])
405+
return kmap_local_page_try_from_panic(bo->ttm->pages[page]);
406+
407+
return NULL;
408+
}
409+
EXPORT_SYMBOL(ttm_bo_kmap_try_from_panic);
410+
384411
/**
385412
* ttm_bo_kmap
386413
*

include/drm/ttm/ttm_bo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ int ttm_bo_init_validate(struct ttm_device *bdev, struct ttm_buffer_object *bo,
401401
int ttm_bo_kmap(struct ttm_buffer_object *bo, unsigned long start_page,
402402
unsigned long num_pages, struct ttm_bo_kmap_obj *map);
403403
void ttm_bo_kunmap(struct ttm_bo_kmap_obj *map);
404+
void *ttm_bo_kmap_try_from_panic(struct ttm_buffer_object *bo, unsigned long page);
404405
int ttm_bo_vmap(struct ttm_buffer_object *bo, struct iosys_map *map);
405406
void ttm_bo_vunmap(struct ttm_buffer_object *bo, struct iosys_map *map);
406407
int ttm_bo_mmap_obj(struct vm_area_struct *vma, struct ttm_buffer_object *bo);

0 commit comments

Comments
 (0)