aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorDave Gordon <david.s.gordon@intel.com>2015-12-08 08:30:51 -0500
committerDaniel Vetter <daniel.vetter@ffwll.ch>2015-12-10 03:36:42 -0500
commite8ebd8e2bd06e3509e1a4d65cbc7293d72897dd7 (patch)
treef4a3f5581fe7b5228e961f67bac56a09b2978550 /drivers
parenta25c9f00ce2586dfa70ea16fc2e3f2f9043cea62 (diff)
drm/i915: eliminate 'temp' in gen8_for_each_{pdd, pdpe, pml4e} macros
All of these iterator macros require a 'temp' argument, used merely to hold internal partial results. We can instead declare the temporary variable inside the macro, so the caller need not provide it. Some of the old code contained nested iterators that actually reused the same 'temp' variable for both inner and outer instances. It's quite surprising that this didn't introduce bugs! But it does show that the value of 'temp' isn't required to persist during the iterated body. Signed-off-by: Dave Gordon <david.s.gordon@intel.com> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch> Link: http://patchwork.freedesktop.org/patch/msgid/1449581451-11848-2-git-send-email-david.s.gordon@intel.com
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gpu/drm/i915/i915_gem_gtt.c39
-rw-r--r--drivers/gpu/drm/i915/i915_gem_gtt.h49
2 files changed, 41 insertions, 47 deletions
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index 1f7e6b9df45d..c25e8b017875 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -770,10 +770,10 @@ static void gen8_ppgtt_clear_range(struct i915_address_space *vm,
770 gen8_ppgtt_clear_pte_range(vm, &ppgtt->pdp, start, length, 770 gen8_ppgtt_clear_pte_range(vm, &ppgtt->pdp, start, length,
771 scratch_pte); 771 scratch_pte);
772 } else { 772 } else {
773 uint64_t templ4, pml4e; 773 uint64_t pml4e;
774 struct i915_page_directory_pointer *pdp; 774 struct i915_page_directory_pointer *pdp;
775 775
776 gen8_for_each_pml4e(pdp, &ppgtt->pml4, start, length, templ4, pml4e) { 776 gen8_for_each_pml4e(pdp, &ppgtt->pml4, start, length, pml4e) {
777 gen8_ppgtt_clear_pte_range(vm, pdp, start, length, 777 gen8_ppgtt_clear_pte_range(vm, pdp, start, length,
778 scratch_pte); 778 scratch_pte);
779 } 779 }
@@ -839,10 +839,10 @@ static void gen8_ppgtt_insert_entries(struct i915_address_space *vm,
839 cache_level); 839 cache_level);
840 } else { 840 } else {
841 struct i915_page_directory_pointer *pdp; 841 struct i915_page_directory_pointer *pdp;
842 uint64_t templ4, pml4e; 842 uint64_t pml4e;
843 uint64_t length = (uint64_t)pages->orig_nents << PAGE_SHIFT; 843 uint64_t length = (uint64_t)pages->orig_nents << PAGE_SHIFT;
844 844
845 gen8_for_each_pml4e(pdp, &ppgtt->pml4, start, length, templ4, pml4e) { 845 gen8_for_each_pml4e(pdp, &ppgtt->pml4, start, length, pml4e) {
846 gen8_ppgtt_insert_pte_entries(vm, pdp, &sg_iter, 846 gen8_ppgtt_insert_pte_entries(vm, pdp, &sg_iter,
847 start, cache_level); 847 start, cache_level);
848 } 848 }
@@ -1020,10 +1020,9 @@ static int gen8_ppgtt_alloc_pagetabs(struct i915_address_space *vm,
1020{ 1020{
1021 struct drm_device *dev = vm->dev; 1021 struct drm_device *dev = vm->dev;
1022 struct i915_page_table *pt; 1022 struct i915_page_table *pt;
1023 uint64_t temp;
1024 uint32_t pde; 1023 uint32_t pde;
1025 1024
1026 gen8_for_each_pde(pt, pd, start, length, temp, pde) { 1025 gen8_for_each_pde(pt, pd, start, length, pde) {
1027 /* Don't reallocate page tables */ 1026 /* Don't reallocate page tables */
1028 if (test_bit(pde, pd->used_pdes)) { 1027 if (test_bit(pde, pd->used_pdes)) {
1029 /* Scratch is never allocated this way */ 1028 /* Scratch is never allocated this way */
@@ -1082,13 +1081,12 @@ gen8_ppgtt_alloc_page_directories(struct i915_address_space *vm,
1082{ 1081{
1083 struct drm_device *dev = vm->dev; 1082 struct drm_device *dev = vm->dev;
1084 struct i915_page_directory *pd; 1083 struct i915_page_directory *pd;
1085 uint64_t temp;
1086 uint32_t pdpe; 1084 uint32_t pdpe;
1087 uint32_t pdpes = I915_PDPES_PER_PDP(dev); 1085 uint32_t pdpes = I915_PDPES_PER_PDP(dev);
1088 1086
1089 WARN_ON(!bitmap_empty(new_pds, pdpes)); 1087 WARN_ON(!bitmap_empty(new_pds, pdpes));
1090 1088
1091 gen8_for_each_pdpe(pd, pdp, start, length, temp, pdpe) { 1089 gen8_for_each_pdpe(pd, pdp, start, length, pdpe) {
1092 if (test_bit(pdpe, pdp->used_pdpes)) 1090 if (test_bit(pdpe, pdp->used_pdpes))
1093 continue; 1091 continue;
1094 1092
@@ -1136,12 +1134,11 @@ gen8_ppgtt_alloc_page_dirpointers(struct i915_address_space *vm,
1136{ 1134{
1137 struct drm_device *dev = vm->dev; 1135 struct drm_device *dev = vm->dev;
1138 struct i915_page_directory_pointer *pdp; 1136 struct i915_page_directory_pointer *pdp;
1139 uint64_t temp;
1140 uint32_t pml4e; 1137 uint32_t pml4e;
1141 1138
1142 WARN_ON(!bitmap_empty(new_pdps, GEN8_PML4ES_PER_PML4)); 1139 WARN_ON(!bitmap_empty(new_pdps, GEN8_PML4ES_PER_PML4));
1143 1140
1144 gen8_for_each_pml4e(pdp, pml4, start, length, temp, pml4e) { 1141 gen8_for_each_pml4e(pdp, pml4, start, length, pml4e) {
1145 if (!test_bit(pml4e, pml4->used_pml4es)) { 1142 if (!test_bit(pml4e, pml4->used_pml4es)) {
1146 pdp = alloc_pdp(dev); 1143 pdp = alloc_pdp(dev);
1147 if (IS_ERR(pdp)) 1144 if (IS_ERR(pdp))
@@ -1225,7 +1222,6 @@ static int gen8_alloc_va_range_3lvl(struct i915_address_space *vm,
1225 struct i915_page_directory *pd; 1222 struct i915_page_directory *pd;
1226 const uint64_t orig_start = start; 1223 const uint64_t orig_start = start;
1227 const uint64_t orig_length = length; 1224 const uint64_t orig_length = length;
1228 uint64_t temp;
1229 uint32_t pdpe; 1225 uint32_t pdpe;
1230 uint32_t pdpes = I915_PDPES_PER_PDP(dev); 1226 uint32_t pdpes = I915_PDPES_PER_PDP(dev);
1231 int ret; 1227 int ret;
@@ -1252,7 +1248,7 @@ static int gen8_alloc_va_range_3lvl(struct i915_address_space *vm,
1252 } 1248 }
1253 1249
1254 /* For every page directory referenced, allocate page tables */ 1250 /* For every page directory referenced, allocate page tables */
1255 gen8_for_each_pdpe(pd, pdp, start, length, temp, pdpe) { 1251 gen8_for_each_pdpe(pd, pdp, start, length, pdpe) {
1256 ret = gen8_ppgtt_alloc_pagetabs(vm, pd, start, length, 1252 ret = gen8_ppgtt_alloc_pagetabs(vm, pd, start, length,
1257 new_page_tables + pdpe * BITS_TO_LONGS(I915_PDES)); 1253 new_page_tables + pdpe * BITS_TO_LONGS(I915_PDES));
1258 if (ret) 1254 if (ret)
@@ -1264,7 +1260,7 @@ static int gen8_alloc_va_range_3lvl(struct i915_address_space *vm,
1264 1260
1265 /* Allocations have completed successfully, so set the bitmaps, and do 1261 /* Allocations have completed successfully, so set the bitmaps, and do
1266 * the mappings. */ 1262 * the mappings. */
1267 gen8_for_each_pdpe(pd, pdp, start, length, temp, pdpe) { 1263 gen8_for_each_pdpe(pd, pdp, start, length, pdpe) {
1268 gen8_pde_t *const page_directory = kmap_px(pd); 1264 gen8_pde_t *const page_directory = kmap_px(pd);
1269 struct i915_page_table *pt; 1265 struct i915_page_table *pt;
1270 uint64_t pd_len = length; 1266 uint64_t pd_len = length;
@@ -1274,7 +1270,7 @@ static int gen8_alloc_va_range_3lvl(struct i915_address_space *vm,
1274 /* Every pd should be allocated, we just did that above. */ 1270 /* Every pd should be allocated, we just did that above. */
1275 WARN_ON(!pd); 1271 WARN_ON(!pd);
1276 1272
1277 gen8_for_each_pde(pt, pd, pd_start, pd_len, temp, pde) { 1273 gen8_for_each_pde(pt, pd, pd_start, pd_len, pde) {
1278 /* Same reasoning as pd */ 1274 /* Same reasoning as pd */
1279 WARN_ON(!pt); 1275 WARN_ON(!pt);
1280 WARN_ON(!pd_len); 1276 WARN_ON(!pd_len);
@@ -1311,6 +1307,8 @@ static int gen8_alloc_va_range_3lvl(struct i915_address_space *vm,
1311 1307
1312err_out: 1308err_out:
1313 while (pdpe--) { 1309 while (pdpe--) {
1310 unsigned long temp;
1311
1314 for_each_set_bit(temp, new_page_tables + pdpe * 1312 for_each_set_bit(temp, new_page_tables + pdpe *
1315 BITS_TO_LONGS(I915_PDES), I915_PDES) 1313 BITS_TO_LONGS(I915_PDES), I915_PDES)
1316 free_pt(dev, pdp->page_directory[pdpe]->page_table[temp]); 1314 free_pt(dev, pdp->page_directory[pdpe]->page_table[temp]);
@@ -1333,7 +1331,7 @@ static int gen8_alloc_va_range_4lvl(struct i915_address_space *vm,
1333 struct i915_hw_ppgtt *ppgtt = 1331 struct i915_hw_ppgtt *ppgtt =
1334 container_of(vm, struct i915_hw_ppgtt, base); 1332 container_of(vm, struct i915_hw_ppgtt, base);
1335 struct i915_page_directory_pointer *pdp; 1333 struct i915_page_directory_pointer *pdp;
1336 uint64_t temp, pml4e; 1334 uint64_t pml4e;
1337 int ret = 0; 1335 int ret = 0;
1338 1336
1339 /* Do the pml4 allocations first, so we don't need to track the newly 1337 /* Do the pml4 allocations first, so we don't need to track the newly
@@ -1352,7 +1350,7 @@ static int gen8_alloc_va_range_4lvl(struct i915_address_space *vm,
1352 "The allocation has spanned more than 512GB. " 1350 "The allocation has spanned more than 512GB. "
1353 "It is highly likely this is incorrect."); 1351 "It is highly likely this is incorrect.");
1354 1352
1355 gen8_for_each_pml4e(pdp, pml4, start, length, temp, pml4e) { 1353 gen8_for_each_pml4e(pdp, pml4, start, length, pml4e) {
1356 WARN_ON(!pdp); 1354 WARN_ON(!pdp);
1357 1355
1358 ret = gen8_alloc_va_range_3lvl(vm, pdp, start, length); 1356 ret = gen8_alloc_va_range_3lvl(vm, pdp, start, length);
@@ -1392,10 +1390,9 @@ static void gen8_dump_pdp(struct i915_page_directory_pointer *pdp,
1392 struct seq_file *m) 1390 struct seq_file *m)
1393{ 1391{
1394 struct i915_page_directory *pd; 1392 struct i915_page_directory *pd;
1395 uint64_t temp;
1396 uint32_t pdpe; 1393 uint32_t pdpe;
1397 1394
1398 gen8_for_each_pdpe(pd, pdp, start, length, temp, pdpe) { 1395 gen8_for_each_pdpe(pd, pdp, start, length, pdpe) {
1399 struct i915_page_table *pt; 1396 struct i915_page_table *pt;
1400 uint64_t pd_len = length; 1397 uint64_t pd_len = length;
1401 uint64_t pd_start = start; 1398 uint64_t pd_start = start;
@@ -1405,7 +1402,7 @@ static void gen8_dump_pdp(struct i915_page_directory_pointer *pdp,
1405 continue; 1402 continue;
1406 1403
1407 seq_printf(m, "\tPDPE #%d\n", pdpe); 1404 seq_printf(m, "\tPDPE #%d\n", pdpe);
1408 gen8_for_each_pde(pt, pd, pd_start, pd_len, temp, pde) { 1405 gen8_for_each_pde(pt, pd, pd_start, pd_len, pde) {
1409 uint32_t pte; 1406 uint32_t pte;
1410 gen8_pte_t *pt_vaddr; 1407 gen8_pte_t *pt_vaddr;
1411 1408
@@ -1455,11 +1452,11 @@ static void gen8_dump_ppgtt(struct i915_hw_ppgtt *ppgtt, struct seq_file *m)
1455 if (!USES_FULL_48BIT_PPGTT(vm->dev)) { 1452 if (!USES_FULL_48BIT_PPGTT(vm->dev)) {
1456 gen8_dump_pdp(&ppgtt->pdp, start, length, scratch_pte, m); 1453 gen8_dump_pdp(&ppgtt->pdp, start, length, scratch_pte, m);
1457 } else { 1454 } else {
1458 uint64_t templ4, pml4e; 1455 uint64_t pml4e;
1459 struct i915_pml4 *pml4 = &ppgtt->pml4; 1456 struct i915_pml4 *pml4 = &ppgtt->pml4;
1460 struct i915_page_directory_pointer *pdp; 1457 struct i915_page_directory_pointer *pdp;
1461 1458
1462 gen8_for_each_pml4e(pdp, pml4, start, length, templ4, pml4e) { 1459 gen8_for_each_pml4e(pdp, pml4, start, length, pml4e) {
1463 if (!test_bit(pml4e, pml4->used_pml4es)) 1460 if (!test_bit(pml4e, pml4->used_pml4es))
1464 continue; 1461 continue;
1465 1462
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.h b/drivers/gpu/drm/i915/i915_gem_gtt.h
index 877c32c78a6a..b448ad832dcf 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.h
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.h
@@ -455,32 +455,29 @@ static inline uint32_t gen6_pde_index(uint32_t addr)
455 * between from start until start + length. On gen8+ it simply iterates 455 * between from start until start + length. On gen8+ it simply iterates
456 * over every page directory entry in a page directory. 456 * over every page directory entry in a page directory.
457 */ 457 */
458#define gen8_for_each_pde(pt, pd, start, length, temp, iter) \ 458#define gen8_for_each_pde(pt, pd, start, length, iter) \
459 for (iter = gen8_pde_index(start); \ 459 for (iter = gen8_pde_index(start); \
460 length > 0 && iter < I915_PDES ? \ 460 length > 0 && iter < I915_PDES && \
461 (pt = (pd)->page_table[iter]), 1 : 0; \ 461 (pt = (pd)->page_table[iter], true); \
462 iter++, \ 462 ({ u64 temp = ALIGN(start+1, 1 << GEN8_PDE_SHIFT); \
463 temp = ALIGN(start+1, 1 << GEN8_PDE_SHIFT) - start, \ 463 temp = min(temp - start, length); \
464 temp = min(temp, length), \ 464 start += temp, length -= temp; }), ++iter)
465 start += temp, length -= temp) 465
466 466#define gen8_for_each_pdpe(pd, pdp, start, length, iter) \
467#define gen8_for_each_pdpe(pd, pdp, start, length, temp, iter) \ 467 for (iter = gen8_pdpe_index(start); \
468 for (iter = gen8_pdpe_index(start); \ 468 length > 0 && iter < I915_PDPES_PER_PDP(dev) && \
469 length > 0 && (iter < I915_PDPES_PER_PDP(dev)) ? \ 469 (pd = (pdp)->page_directory[iter], true); \
470 (pd = (pdp)->page_directory[iter]), 1 : 0; \ 470 ({ u64 temp = ALIGN(start+1, 1 << GEN8_PDPE_SHIFT); \
471 iter++, \ 471 temp = min(temp - start, length); \
472 temp = ALIGN(start+1, 1 << GEN8_PDPE_SHIFT) - start, \ 472 start += temp, length -= temp; }), ++iter)
473 temp = min(temp, length), \ 473
474 start += temp, length -= temp) 474#define gen8_for_each_pml4e(pdp, pml4, start, length, iter) \
475 475 for (iter = gen8_pml4e_index(start); \
476#define gen8_for_each_pml4e(pdp, pml4, start, length, temp, iter) \ 476 length > 0 && iter < GEN8_PML4ES_PER_PML4 && \
477 for (iter = gen8_pml4e_index(start); \ 477 (pdp = (pml4)->pdps[iter], true); \
478 length > 0 && iter < GEN8_PML4ES_PER_PML4 ? \ 478 ({ u64 temp = ALIGN(start+1, 1ULL << GEN8_PML4E_SHIFT); \
479 (pdp = (pml4)->pdps[iter]), 1 : 0; \ 479 temp = min(temp - start, length); \
480 iter++, \ 480 start += temp, length -= temp; }), ++iter)
481 temp = ALIGN(start+1, 1ULL << GEN8_PML4E_SHIFT) - start, \
482 temp = min(temp, length), \
483 start += temp, length -= temp)
484 481
485static inline uint32_t gen8_pte_index(uint64_t address) 482static inline uint32_t gen8_pte_index(uint64_t address)
486{ 483{