Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Christian König and committed by
Alex Deucher
a1d29476 43251981

+42 -14
+10
drivers/gpu/drm/amd/amdgpu/Kconfig
··· 15 15 help 16 16 This option selects CONFIG_MMU_NOTIFIER if it isn't already 17 17 selected to enabled full userptr support. 18 + 19 + config DRM_AMDGPU_GART_DEBUGFS 20 + bool "Allow GART access through debugfs" 21 + depends on DRM_AMDGPU 22 + depends on DEBUG_FS 23 + default n 24 + help 25 + Selecting this option creates a debugfs file to inspect the mapped 26 + pages. Uses more memory for housekeeping, enable only for debugging. 27 +
+2
drivers/gpu/drm/amd/amdgpu/amdgpu.h
··· 611 611 unsigned num_gpu_pages; 612 612 unsigned num_cpu_pages; 613 613 unsigned table_size; 614 + #ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS 614 615 struct page **pages; 616 + #endif 615 617 bool ready; 616 618 const struct amdgpu_gart_funcs *gart_funcs; 617 619 };
+21 -14
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
··· 238 238 t = offset / AMDGPU_GPU_PAGE_SIZE; 239 239 p = t / (PAGE_SIZE / AMDGPU_GPU_PAGE_SIZE); 240 240 for (i = 0; i < pages; i++, p++) { 241 - if (adev->gart.pages[p]) { 242 - adev->gart.pages[p] = NULL; 243 - page_base = adev->dummy_page.addr; 244 - if (!adev->gart.ptr) 245 - continue; 241 + #ifdef CONFIG_AMDGPU_GART_DEBUGFS 242 + adev->gart.pages[p] = NULL; 243 + #endif 244 + page_base = adev->dummy_page.addr; 245 + if (!adev->gart.ptr) 246 + continue; 246 247 247 - for (j = 0; j < (PAGE_SIZE / AMDGPU_GPU_PAGE_SIZE); j++, t++) { 248 - amdgpu_gart_set_pte_pde(adev, adev->gart.ptr, 249 - t, page_base, flags); 250 - page_base += AMDGPU_GPU_PAGE_SIZE; 251 - } 248 + for (j = 0; j < (PAGE_SIZE / AMDGPU_GPU_PAGE_SIZE); j++, t++) { 249 + amdgpu_gart_set_pte_pde(adev, adev->gart.ptr, 250 + t, page_base, flags); 251 + page_base += AMDGPU_GPU_PAGE_SIZE; 252 252 } 253 253 } 254 254 mb(); ··· 286 286 p = t / (PAGE_SIZE / AMDGPU_GPU_PAGE_SIZE); 287 287 288 288 for (i = 0; i < pages; i++, p++) { 289 + #ifdef CONFIG_AMDGPU_GART_DEBUGFS 289 290 adev->gart.pages[p] = pagelist[i]; 291 + #endif 290 292 if (adev->gart.ptr) { 291 293 page_base = dma_addr[i]; 292 294 for (j = 0; j < (PAGE_SIZE / AMDGPU_GPU_PAGE_SIZE); j++, t++) { ··· 314 312 { 315 313 int r; 316 314 317 - if (adev->gart.pages) { 315 + if (adev->dummy_page.page) 318 316 return 0; 319 - } 317 + 320 318 /* We need PAGE_SIZE >= AMDGPU_GPU_PAGE_SIZE */ 321 319 if (PAGE_SIZE < AMDGPU_GPU_PAGE_SIZE) { 322 320 DRM_ERROR("Page size is smaller than GPU page size!\n"); ··· 330 328 adev->gart.num_gpu_pages = adev->mc.gtt_size / AMDGPU_GPU_PAGE_SIZE; 331 329 DRM_INFO("GART: num cpu pages %u, num gpu pages %u\n", 332 330 adev->gart.num_cpu_pages, adev->gart.num_gpu_pages); 331 + 332 + #ifdef CONFIG_AMDGPU_GART_DEBUGFS 333 333 /* Allocate pages table */ 334 334 adev->gart.pages = vzalloc(sizeof(void *) * adev->gart.num_cpu_pages); 335 335 if (adev->gart.pages == NULL) { 336 336 amdgpu_gart_fini(adev); 337 337 return -ENOMEM; 338 338 } 339 + #endif 340 + 339 341 return 0; 340 342 } 341 343 ··· 352 346 */ 353 347 void amdgpu_gart_fini(struct amdgpu_device *adev) 354 348 { 355 - if (adev->gart.pages && adev->gart.ready) { 349 + if (adev->gart.ready) { 356 350 /* unbind pages */ 357 351 amdgpu_gart_unbind(adev, 0, adev->gart.num_cpu_pages); 358 352 } 359 353 adev->gart.ready = false; 354 + #ifdef CONFIG_AMDGPU_GART_DEBUGFS 360 355 vfree(adev->gart.pages); 361 356 adev->gart.pages = NULL; 362 - 357 + #endif 363 358 amdgpu_dummy_page_fini(adev); 364 359 }
+9
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
··· 1216 1216 .llseek = default_llseek 1217 1217 }; 1218 1218 1219 + #ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS 1220 + 1219 1221 static ssize_t amdgpu_ttm_gtt_read(struct file *f, char __user *buf, 1220 1222 size_t size, loff_t *pos) 1221 1223 { ··· 1265 1263 1266 1264 #endif 1267 1265 1266 + #endif 1267 + 1268 1268 static int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev) 1269 1269 { 1270 1270 #if defined(CONFIG_DEBUG_FS) ··· 1282 1278 i_size_write(ent->d_inode, adev->mc.mc_vram_size); 1283 1279 adev->mman.vram = ent; 1284 1280 1281 + #ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS 1285 1282 ent = debugfs_create_file("amdgpu_gtt", S_IFREG | S_IRUGO, root, 1286 1283 adev, &amdgpu_ttm_gtt_fops); 1287 1284 if (IS_ERR(ent)) ··· 1290 1285 i_size_write(ent->d_inode, adev->mc.gtt_size); 1291 1286 adev->mman.gtt = ent; 1292 1287 1288 + #endif 1293 1289 count = ARRAY_SIZE(amdgpu_ttm_debugfs_list); 1294 1290 1295 1291 #ifdef CONFIG_SWIOTLB ··· 1312 1306 debugfs_remove(adev->mman.vram); 1313 1307 adev->mman.vram = NULL; 1314 1308 1309 + #ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS 1315 1310 debugfs_remove(adev->mman.gtt); 1316 1311 adev->mman.gtt = NULL; 1312 + #endif 1313 + 1317 1314 #endif 1318 1315 }