Commit a1d29476 authored by Christian König's avatar Christian König Committed by Alex Deucher

drm/amdgpu: optionally enable GART debugfs file

Keeping the pages array around can use a lot of system memory
when you want a large GART.
Signed-off-by: default avatarChristian König <christian.koenig@amd.com>
Reviewed-by: default avatarAlex Deucher <alexander.deucher@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 43251981
...@@ -15,3 +15,13 @@ config DRM_AMDGPU_USERPTR ...@@ -15,3 +15,13 @@ config DRM_AMDGPU_USERPTR
help help
This option selects CONFIG_MMU_NOTIFIER if it isn't already This option selects CONFIG_MMU_NOTIFIER if it isn't already
selected to enabled full userptr support. selected to enabled full userptr support.
config DRM_AMDGPU_GART_DEBUGFS
bool "Allow GART access through debugfs"
depends on DRM_AMDGPU
depends on DEBUG_FS
default n
help
Selecting this option creates a debugfs file to inspect the mapped
pages. Uses more memory for housekeeping, enable only for debugging.
...@@ -611,7 +611,9 @@ struct amdgpu_gart { ...@@ -611,7 +611,9 @@ struct amdgpu_gart {
unsigned num_gpu_pages; unsigned num_gpu_pages;
unsigned num_cpu_pages; unsigned num_cpu_pages;
unsigned table_size; unsigned table_size;
#ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
struct page **pages; struct page **pages;
#endif
bool ready; bool ready;
const struct amdgpu_gart_funcs *gart_funcs; const struct amdgpu_gart_funcs *gart_funcs;
}; };
......
...@@ -238,17 +238,17 @@ void amdgpu_gart_unbind(struct amdgpu_device *adev, unsigned offset, ...@@ -238,17 +238,17 @@ void amdgpu_gart_unbind(struct amdgpu_device *adev, unsigned offset,
t = offset / AMDGPU_GPU_PAGE_SIZE; t = offset / AMDGPU_GPU_PAGE_SIZE;
p = t / (PAGE_SIZE / AMDGPU_GPU_PAGE_SIZE); p = t / (PAGE_SIZE / AMDGPU_GPU_PAGE_SIZE);
for (i = 0; i < pages; i++, p++) { for (i = 0; i < pages; i++, p++) {
if (adev->gart.pages[p]) { #ifdef CONFIG_AMDGPU_GART_DEBUGFS
adev->gart.pages[p] = NULL; adev->gart.pages[p] = NULL;
page_base = adev->dummy_page.addr; #endif
if (!adev->gart.ptr) page_base = adev->dummy_page.addr;
continue; if (!adev->gart.ptr)
continue;
for (j = 0; j < (PAGE_SIZE / AMDGPU_GPU_PAGE_SIZE); j++, t++) { for (j = 0; j < (PAGE_SIZE / AMDGPU_GPU_PAGE_SIZE); j++, t++) {
amdgpu_gart_set_pte_pde(adev, adev->gart.ptr, amdgpu_gart_set_pte_pde(adev, adev->gart.ptr,
t, page_base, flags); t, page_base, flags);
page_base += AMDGPU_GPU_PAGE_SIZE; page_base += AMDGPU_GPU_PAGE_SIZE;
}
} }
} }
mb(); mb();
...@@ -286,7 +286,9 @@ int amdgpu_gart_bind(struct amdgpu_device *adev, unsigned offset, ...@@ -286,7 +286,9 @@ int amdgpu_gart_bind(struct amdgpu_device *adev, unsigned offset,
p = t / (PAGE_SIZE / AMDGPU_GPU_PAGE_SIZE); p = t / (PAGE_SIZE / AMDGPU_GPU_PAGE_SIZE);
for (i = 0; i < pages; i++, p++) { for (i = 0; i < pages; i++, p++) {
#ifdef CONFIG_AMDGPU_GART_DEBUGFS
adev->gart.pages[p] = pagelist[i]; adev->gart.pages[p] = pagelist[i];
#endif
if (adev->gart.ptr) { if (adev->gart.ptr) {
page_base = dma_addr[i]; page_base = dma_addr[i];
for (j = 0; j < (PAGE_SIZE / AMDGPU_GPU_PAGE_SIZE); j++, t++) { for (j = 0; j < (PAGE_SIZE / AMDGPU_GPU_PAGE_SIZE); j++, t++) {
...@@ -312,9 +314,9 @@ int amdgpu_gart_init(struct amdgpu_device *adev) ...@@ -312,9 +314,9 @@ int amdgpu_gart_init(struct amdgpu_device *adev)
{ {
int r; int r;
if (adev->gart.pages) { if (adev->dummy_page.page)
return 0; return 0;
}
/* We need PAGE_SIZE >= AMDGPU_GPU_PAGE_SIZE */ /* We need PAGE_SIZE >= AMDGPU_GPU_PAGE_SIZE */
if (PAGE_SIZE < AMDGPU_GPU_PAGE_SIZE) { if (PAGE_SIZE < AMDGPU_GPU_PAGE_SIZE) {
DRM_ERROR("Page size is smaller than GPU page size!\n"); DRM_ERROR("Page size is smaller than GPU page size!\n");
...@@ -328,12 +330,16 @@ int amdgpu_gart_init(struct amdgpu_device *adev) ...@@ -328,12 +330,16 @@ int amdgpu_gart_init(struct amdgpu_device *adev)
adev->gart.num_gpu_pages = adev->mc.gtt_size / AMDGPU_GPU_PAGE_SIZE; adev->gart.num_gpu_pages = adev->mc.gtt_size / AMDGPU_GPU_PAGE_SIZE;
DRM_INFO("GART: num cpu pages %u, num gpu pages %u\n", DRM_INFO("GART: num cpu pages %u, num gpu pages %u\n",
adev->gart.num_cpu_pages, adev->gart.num_gpu_pages); adev->gart.num_cpu_pages, adev->gart.num_gpu_pages);
#ifdef CONFIG_AMDGPU_GART_DEBUGFS
/* Allocate pages table */ /* Allocate pages table */
adev->gart.pages = vzalloc(sizeof(void *) * adev->gart.num_cpu_pages); adev->gart.pages = vzalloc(sizeof(void *) * adev->gart.num_cpu_pages);
if (adev->gart.pages == NULL) { if (adev->gart.pages == NULL) {
amdgpu_gart_fini(adev); amdgpu_gart_fini(adev);
return -ENOMEM; return -ENOMEM;
} }
#endif
return 0; return 0;
} }
...@@ -346,13 +352,14 @@ int amdgpu_gart_init(struct amdgpu_device *adev) ...@@ -346,13 +352,14 @@ int amdgpu_gart_init(struct amdgpu_device *adev)
*/ */
void amdgpu_gart_fini(struct amdgpu_device *adev) void amdgpu_gart_fini(struct amdgpu_device *adev)
{ {
if (adev->gart.pages && adev->gart.ready) { if (adev->gart.ready) {
/* unbind pages */ /* unbind pages */
amdgpu_gart_unbind(adev, 0, adev->gart.num_cpu_pages); amdgpu_gart_unbind(adev, 0, adev->gart.num_cpu_pages);
} }
adev->gart.ready = false; adev->gart.ready = false;
#ifdef CONFIG_AMDGPU_GART_DEBUGFS
vfree(adev->gart.pages); vfree(adev->gart.pages);
adev->gart.pages = NULL; adev->gart.pages = NULL;
#endif
amdgpu_dummy_page_fini(adev); amdgpu_dummy_page_fini(adev);
} }
...@@ -1216,6 +1216,8 @@ static const struct file_operations amdgpu_ttm_vram_fops = { ...@@ -1216,6 +1216,8 @@ static const struct file_operations amdgpu_ttm_vram_fops = {
.llseek = default_llseek .llseek = default_llseek
}; };
#ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
static ssize_t amdgpu_ttm_gtt_read(struct file *f, char __user *buf, static ssize_t amdgpu_ttm_gtt_read(struct file *f, char __user *buf,
size_t size, loff_t *pos) size_t size, loff_t *pos)
{ {
...@@ -1263,6 +1265,8 @@ static const struct file_operations amdgpu_ttm_gtt_fops = { ...@@ -1263,6 +1265,8 @@ static const struct file_operations amdgpu_ttm_gtt_fops = {
#endif #endif
#endif
static int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev) static int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev)
{ {
#if defined(CONFIG_DEBUG_FS) #if defined(CONFIG_DEBUG_FS)
...@@ -1278,6 +1282,7 @@ static int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev) ...@@ -1278,6 +1282,7 @@ static int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev)
i_size_write(ent->d_inode, adev->mc.mc_vram_size); i_size_write(ent->d_inode, adev->mc.mc_vram_size);
adev->mman.vram = ent; adev->mman.vram = ent;
#ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
ent = debugfs_create_file("amdgpu_gtt", S_IFREG | S_IRUGO, root, ent = debugfs_create_file("amdgpu_gtt", S_IFREG | S_IRUGO, root,
adev, &amdgpu_ttm_gtt_fops); adev, &amdgpu_ttm_gtt_fops);
if (IS_ERR(ent)) if (IS_ERR(ent))
...@@ -1285,6 +1290,7 @@ static int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev) ...@@ -1285,6 +1290,7 @@ static int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev)
i_size_write(ent->d_inode, adev->mc.gtt_size); i_size_write(ent->d_inode, adev->mc.gtt_size);
adev->mman.gtt = ent; adev->mman.gtt = ent;
#endif
count = ARRAY_SIZE(amdgpu_ttm_debugfs_list); count = ARRAY_SIZE(amdgpu_ttm_debugfs_list);
#ifdef CONFIG_SWIOTLB #ifdef CONFIG_SWIOTLB
...@@ -1306,7 +1312,10 @@ static void amdgpu_ttm_debugfs_fini(struct amdgpu_device *adev) ...@@ -1306,7 +1312,10 @@ static void amdgpu_ttm_debugfs_fini(struct amdgpu_device *adev)
debugfs_remove(adev->mman.vram); debugfs_remove(adev->mman.vram);
adev->mman.vram = NULL; adev->mman.vram = NULL;
#ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
debugfs_remove(adev->mman.gtt); debugfs_remove(adev->mman.gtt);
adev->mman.gtt = NULL; adev->mman.gtt = NULL;
#endif #endif
#endif
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment