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

Merge tag 'drm-intel-next-fixes-2015-06-18' of git://anongit.freedesktop.org/drm-intel into drm-next

i915 fixes for stuff in next

* tag 'drm-intel-next-fixes-2015-06-18' of git://anongit.freedesktop.org/drm-intel:
drm/i915: Don't set enabled value of all CRTCs when restoring the mode
drm/i915: Don't update staged config during force restore modesets
drm/i915: Don't check modeset state in the hw state force restore path
drm/i915: Add SCRATCH1 and ROW_CHICKEN3 to the register whitelist.
drm/i915: Extend the parser to check register writes against a mask/value pair.
drm/i915: Fix command parser to validate multiple register access with the same command.
drm/i915: Don't skip request retirement if the active list is empty

+165 -101
+132 -65
drivers/gpu/drm/i915/i915_cmd_parser.c
··· 123 123 CMD( MI_SEMAPHORE_MBOX, SMI, !F, 0xFF, R ), 124 124 CMD( MI_STORE_DWORD_INDEX, SMI, !F, 0xFF, R ), 125 125 CMD( MI_LOAD_REGISTER_IMM(1), SMI, !F, 0xFF, W, 126 - .reg = { .offset = 1, .mask = 0x007FFFFC } ), 126 + .reg = { .offset = 1, .mask = 0x007FFFFC, .step = 2 } ), 127 127 CMD( MI_STORE_REGISTER_MEM(1), SMI, !F, 0xFF, W | B, 128 128 .reg = { .offset = 1, .mask = 0x007FFFFC }, 129 129 .bits = {{ ··· 395 395 396 396 /* 397 397 * Register whitelists, sorted by increasing register offset. 398 + */ 399 + 400 + /* 401 + * An individual whitelist entry granting access to register addr. If 402 + * mask is non-zero the argument of immediate register writes will be 403 + * AND-ed with mask, and the command will be rejected if the result 404 + * doesn't match value. 405 + * 406 + * Registers with non-zero mask are only allowed to be written using 407 + * LRI. 408 + */ 409 + struct drm_i915_reg_descriptor { 410 + u32 addr; 411 + u32 mask; 412 + u32 value; 413 + }; 414 + 415 + /* Convenience macro for adding 32-bit registers. */ 416 + #define REG32(address, ...) \ 417 + { .addr = address, __VA_ARGS__ } 418 + 419 + /* 420 + * Convenience macro for adding 64-bit registers. 398 421 * 399 422 * Some registers that userspace accesses are 64 bits. The register 400 423 * access commands only allow 32-bit accesses. Hence, we have to include 401 424 * entries for both halves of the 64-bit registers. 402 425 */ 426 + #define REG64(addr) \ 427 + REG32(addr), REG32(addr + sizeof(u32)) 403 428 404 - /* Convenience macro for adding 64-bit registers */ 405 - #define REG64(addr) (addr), (addr + sizeof(u32)) 406 - 407 - static const u32 gen7_render_regs[] = { 429 + static const struct drm_i915_reg_descriptor gen7_render_regs[] = { 408 430 REG64(GPGPU_THREADS_DISPATCHED), 409 431 REG64(HS_INVOCATION_COUNT), 410 432 REG64(DS_INVOCATION_COUNT), ··· 439 417 REG64(CL_PRIMITIVES_COUNT), 440 418 REG64(PS_INVOCATION_COUNT), 441 419 REG64(PS_DEPTH_COUNT), 442 - OACONTROL, /* Only allowed for LRI and SRM. See below. */ 420 + REG32(OACONTROL), /* Only allowed for LRI and SRM. See below. */ 443 421 REG64(MI_PREDICATE_SRC0), 444 422 REG64(MI_PREDICATE_SRC1), 445 - GEN7_3DPRIM_END_OFFSET, 446 - GEN7_3DPRIM_START_VERTEX, 447 - GEN7_3DPRIM_VERTEX_COUNT, 448 - GEN7_3DPRIM_INSTANCE_COUNT, 449 - GEN7_3DPRIM_START_INSTANCE, 450 - GEN7_3DPRIM_BASE_VERTEX, 423 + REG32(GEN7_3DPRIM_END_OFFSET), 424 + REG32(GEN7_3DPRIM_START_VERTEX), 425 + REG32(GEN7_3DPRIM_VERTEX_COUNT), 426 + REG32(GEN7_3DPRIM_INSTANCE_COUNT), 427 + REG32(GEN7_3DPRIM_START_INSTANCE), 428 + REG32(GEN7_3DPRIM_BASE_VERTEX), 451 429 REG64(GEN7_SO_NUM_PRIMS_WRITTEN(0)), 452 430 REG64(GEN7_SO_NUM_PRIMS_WRITTEN(1)), 453 431 REG64(GEN7_SO_NUM_PRIMS_WRITTEN(2)), ··· 456 434 REG64(GEN7_SO_PRIM_STORAGE_NEEDED(1)), 457 435 REG64(GEN7_SO_PRIM_STORAGE_NEEDED(2)), 458 436 REG64(GEN7_SO_PRIM_STORAGE_NEEDED(3)), 459 - GEN7_SO_WRITE_OFFSET(0), 460 - GEN7_SO_WRITE_OFFSET(1), 461 - GEN7_SO_WRITE_OFFSET(2), 462 - GEN7_SO_WRITE_OFFSET(3), 463 - GEN7_L3SQCREG1, 464 - GEN7_L3CNTLREG2, 465 - GEN7_L3CNTLREG3, 437 + REG32(GEN7_SO_WRITE_OFFSET(0)), 438 + REG32(GEN7_SO_WRITE_OFFSET(1)), 439 + REG32(GEN7_SO_WRITE_OFFSET(2)), 440 + REG32(GEN7_SO_WRITE_OFFSET(3)), 441 + REG32(GEN7_L3SQCREG1), 442 + REG32(GEN7_L3CNTLREG2), 443 + REG32(GEN7_L3CNTLREG3), 444 + REG32(HSW_SCRATCH1, 445 + .mask = ~HSW_SCRATCH1_L3_DATA_ATOMICS_DISABLE, 446 + .value = 0), 447 + REG32(HSW_ROW_CHICKEN3, 448 + .mask = ~(HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE << 16 | 449 + HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE), 450 + .value = 0), 466 451 }; 467 452 468 - static const u32 gen7_blt_regs[] = { 469 - BCS_SWCTRL, 453 + static const struct drm_i915_reg_descriptor gen7_blt_regs[] = { 454 + REG32(BCS_SWCTRL), 470 455 }; 471 456 472 - static const u32 ivb_master_regs[] = { 473 - FORCEWAKE_MT, 474 - DERRMR, 475 - GEN7_PIPE_DE_LOAD_SL(PIPE_A), 476 - GEN7_PIPE_DE_LOAD_SL(PIPE_B), 477 - GEN7_PIPE_DE_LOAD_SL(PIPE_C), 457 + static const struct drm_i915_reg_descriptor ivb_master_regs[] = { 458 + REG32(FORCEWAKE_MT), 459 + REG32(DERRMR), 460 + REG32(GEN7_PIPE_DE_LOAD_SL(PIPE_A)), 461 + REG32(GEN7_PIPE_DE_LOAD_SL(PIPE_B)), 462 + REG32(GEN7_PIPE_DE_LOAD_SL(PIPE_C)), 478 463 }; 479 464 480 - static const u32 hsw_master_regs[] = { 481 - FORCEWAKE_MT, 482 - DERRMR, 465 + static const struct drm_i915_reg_descriptor hsw_master_regs[] = { 466 + REG32(FORCEWAKE_MT), 467 + REG32(DERRMR), 483 468 }; 484 469 485 470 #undef REG64 471 + #undef REG32 486 472 487 473 static u32 gen7_render_get_cmd_length_mask(u32 cmd_header) 488 474 { ··· 580 550 return ret; 581 551 } 582 552 583 - static bool check_sorted(int ring_id, const u32 *reg_table, int reg_count) 553 + static bool check_sorted(int ring_id, 554 + const struct drm_i915_reg_descriptor *reg_table, 555 + int reg_count) 584 556 { 585 557 int i; 586 558 u32 previous = 0; 587 559 bool ret = true; 588 560 589 561 for (i = 0; i < reg_count; i++) { 590 - u32 curr = reg_table[i]; 562 + u32 curr = reg_table[i].addr; 591 563 592 564 if (curr < previous) { 593 565 DRM_ERROR("CMD: table not sorted ring=%d entry=%d reg=0x%08X prev=0x%08X\n", ··· 836 804 return default_desc; 837 805 } 838 806 839 - static bool valid_reg(const u32 *table, int count, u32 addr) 807 + static const struct drm_i915_reg_descriptor * 808 + find_reg(const struct drm_i915_reg_descriptor *table, 809 + int count, u32 addr) 840 810 { 841 - if (table && count != 0) { 811 + if (table) { 842 812 int i; 843 813 844 814 for (i = 0; i < count; i++) { 845 - if (table[i] == addr) 846 - return true; 815 + if (table[i].addr == addr) 816 + return &table[i]; 847 817 } 848 818 } 849 819 850 - return false; 820 + return NULL; 851 821 } 852 822 853 823 static u32 *vmap_batch(struct drm_i915_gem_object *obj, ··· 968 934 969 935 static bool check_cmd(const struct intel_engine_cs *ring, 970 936 const struct drm_i915_cmd_descriptor *desc, 971 - const u32 *cmd, 937 + const u32 *cmd, u32 length, 972 938 const bool is_master, 973 939 bool *oacontrol_set) 974 940 { ··· 984 950 } 985 951 986 952 if (desc->flags & CMD_DESC_REGISTER) { 987 - u32 reg_addr = cmd[desc->reg.offset] & desc->reg.mask; 988 - 989 953 /* 990 - * OACONTROL requires some special handling for writes. We 991 - * want to make sure that any batch which enables OA also 992 - * disables it before the end of the batch. The goal is to 993 - * prevent one process from snooping on the perf data from 994 - * another process. To do that, we need to check the value 995 - * that will be written to the register. Hence, limit 996 - * OACONTROL writes to only MI_LOAD_REGISTER_IMM commands. 954 + * Get the distance between individual register offset 955 + * fields if the command can perform more than one 956 + * access at a time. 997 957 */ 998 - if (reg_addr == OACONTROL) { 999 - if (desc->cmd.value == MI_LOAD_REGISTER_MEM) { 1000 - DRM_DEBUG_DRIVER("CMD: Rejected LRM to OACONTROL\n"); 958 + const u32 step = desc->reg.step ? desc->reg.step : length; 959 + u32 offset; 960 + 961 + for (offset = desc->reg.offset; offset < length; 962 + offset += step) { 963 + const u32 reg_addr = cmd[offset] & desc->reg.mask; 964 + const struct drm_i915_reg_descriptor *reg = 965 + find_reg(ring->reg_table, ring->reg_count, 966 + reg_addr); 967 + 968 + if (!reg && is_master) 969 + reg = find_reg(ring->master_reg_table, 970 + ring->master_reg_count, 971 + reg_addr); 972 + 973 + if (!reg) { 974 + DRM_DEBUG_DRIVER("CMD: Rejected register 0x%08X in command: 0x%08X (ring=%d)\n", 975 + reg_addr, *cmd, ring->id); 1001 976 return false; 1002 977 } 1003 978 1004 - if (desc->cmd.value == MI_LOAD_REGISTER_IMM(1)) 1005 - *oacontrol_set = (cmd[2] != 0); 1006 - } 979 + /* 980 + * OACONTROL requires some special handling for 981 + * writes. We want to make sure that any batch which 982 + * enables OA also disables it before the end of the 983 + * batch. The goal is to prevent one process from 984 + * snooping on the perf data from another process. To do 985 + * that, we need to check the value that will be written 986 + * to the register. Hence, limit OACONTROL writes to 987 + * only MI_LOAD_REGISTER_IMM commands. 988 + */ 989 + if (reg_addr == OACONTROL) { 990 + if (desc->cmd.value == MI_LOAD_REGISTER_MEM) { 991 + DRM_DEBUG_DRIVER("CMD: Rejected LRM to OACONTROL\n"); 992 + return false; 993 + } 1007 994 1008 - if (!valid_reg(ring->reg_table, 1009 - ring->reg_count, reg_addr)) { 1010 - if (!is_master || 1011 - !valid_reg(ring->master_reg_table, 1012 - ring->master_reg_count, 1013 - reg_addr)) { 1014 - DRM_DEBUG_DRIVER("CMD: Rejected register 0x%08X in command: 0x%08X (ring=%d)\n", 1015 - reg_addr, 1016 - *cmd, 1017 - ring->id); 1018 - return false; 995 + if (desc->cmd.value == MI_LOAD_REGISTER_IMM(1)) 996 + *oacontrol_set = (cmd[offset + 1] != 0); 997 + } 998 + 999 + /* 1000 + * Check the value written to the register against the 1001 + * allowed mask/value pair given in the whitelist entry. 1002 + */ 1003 + if (reg->mask) { 1004 + if (desc->cmd.value == MI_LOAD_REGISTER_MEM) { 1005 + DRM_DEBUG_DRIVER("CMD: Rejected LRM to masked register 0x%08X\n", 1006 + reg_addr); 1007 + return false; 1008 + } 1009 + 1010 + if (desc->cmd.value == MI_LOAD_REGISTER_IMM(1) && 1011 + (offset + 2 > length || 1012 + (cmd[offset + 1] & reg->mask) != reg->value)) { 1013 + DRM_DEBUG_DRIVER("CMD: Rejected LRI to masked register 0x%08X\n", 1014 + reg_addr); 1015 + return false; 1016 + } 1019 1017 } 1020 1018 } 1021 1019 } ··· 1171 1105 break; 1172 1106 } 1173 1107 1174 - if (!check_cmd(ring, desc, cmd, is_master, &oacontrol_set)) { 1108 + if (!check_cmd(ring, desc, cmd, length, is_master, 1109 + &oacontrol_set)) { 1175 1110 ret = -EINVAL; 1176 1111 break; 1177 1112 }
+5
drivers/gpu/drm/i915/i915_drv.h
··· 2300 2300 * Describes where to find a register address in the command to check 2301 2301 * against the ring's register whitelist. Only valid if flags has the 2302 2302 * CMD_DESC_REGISTER bit set. 2303 + * 2304 + * A non-zero step value implies that the command may access multiple 2305 + * registers in sequence (e.g. LRI), in that case step gives the 2306 + * distance in dwords between individual offset fields. 2303 2307 */ 2304 2308 struct { 2305 2309 u32 offset; 2306 2310 u32 mask; 2311 + u32 step; 2307 2312 } reg; 2308 2313 2309 2314 #define MAX_CMD_DESC_BITMASKS 3
-3
drivers/gpu/drm/i915/i915_gem.c
··· 2813 2813 { 2814 2814 WARN_ON(i915_verify_lists(ring->dev)); 2815 2815 2816 - if (list_empty(&ring->active_list)) 2817 - return; 2818 - 2819 2816 /* Retire requests first as we use it above for the early return. 2820 2817 * If we retire requests last, we may use a later seqno and so clear 2821 2818 * the requests lists without clearing the active list, leading to
+25 -31
drivers/gpu/drm/i915/intel_display.c
··· 87 87 struct intel_crtc_state *pipe_config); 88 88 89 89 static int intel_set_mode(struct drm_crtc *crtc, 90 - struct drm_atomic_state *state); 90 + struct drm_atomic_state *state, 91 + bool force_restore); 91 92 static int intel_framebuffer_init(struct drm_device *dev, 92 93 struct intel_framebuffer *ifb, 93 94 struct drm_mode_fb_cmd2 *mode_cmd, ··· 10097 10096 10098 10097 drm_mode_copy(&crtc_state->base.mode, mode); 10099 10098 10100 - if (intel_set_mode(crtc, state)) { 10099 + if (intel_set_mode(crtc, state, true)) { 10101 10100 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n"); 10102 10101 if (old->release_fb) 10103 10102 old->release_fb->funcs->destroy(old->release_fb); ··· 10171 10170 if (ret) 10172 10171 goto fail; 10173 10172 10174 - ret = intel_set_mode(crtc, state); 10173 + ret = intel_set_mode(crtc, state, true); 10175 10174 if (ret) 10176 10175 goto fail; 10177 10176 ··· 11386 11385 crtc->base.enabled = crtc->base.state->enable; 11387 11386 crtc->config = to_intel_crtc_state(crtc->base.state); 11388 11387 } 11389 - 11390 - /* Copy the new configuration to the staged state, to keep the few 11391 - * pieces of code that haven't been converted yet happy */ 11392 - intel_modeset_update_staged_output_state(state->dev); 11393 11388 } 11394 11389 11395 11390 static void ··· 12643 12646 } 12644 12647 12645 12648 static int intel_set_mode_with_config(struct drm_crtc *crtc, 12646 - struct intel_crtc_state *pipe_config) 12649 + struct intel_crtc_state *pipe_config, 12650 + bool force_restore) 12647 12651 { 12648 12652 int ret; 12649 12653 12650 12654 ret = __intel_set_mode(crtc, pipe_config); 12651 12655 12652 - if (ret == 0) 12656 + if (ret == 0 && force_restore) { 12657 + intel_modeset_update_staged_output_state(crtc->dev); 12653 12658 intel_modeset_check_state(crtc->dev); 12659 + } 12654 12660 12655 12661 return ret; 12656 12662 } 12657 12663 12658 12664 static int intel_set_mode(struct drm_crtc *crtc, 12659 - struct drm_atomic_state *state) 12665 + struct drm_atomic_state *state, 12666 + bool force_restore) 12660 12667 { 12661 12668 struct intel_crtc_state *pipe_config; 12662 12669 int ret = 0; ··· 12671 12670 goto out; 12672 12671 } 12673 12672 12674 - ret = intel_set_mode_with_config(crtc, pipe_config); 12673 + ret = intel_set_mode_with_config(crtc, pipe_config, force_restore); 12675 12674 if (ret) 12676 12675 goto out; 12677 12676 ··· 12683 12682 { 12684 12683 struct drm_device *dev = crtc->dev; 12685 12684 struct drm_atomic_state *state; 12686 - struct intel_crtc *intel_crtc; 12687 12685 struct intel_encoder *encoder; 12688 12686 struct intel_connector *connector; 12689 12687 struct drm_connector_state *connector_state; ··· 12725 12725 } 12726 12726 } 12727 12727 12728 - for_each_intel_crtc(dev, intel_crtc) { 12729 - if (intel_crtc->new_enabled == intel_crtc->base.enabled) 12730 - continue; 12731 - 12732 - crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); 12733 - if (IS_ERR(crtc_state)) { 12734 - DRM_DEBUG_KMS("Failed to add [CRTC:%d] to state: %ld\n", 12735 - intel_crtc->base.base.id, 12736 - PTR_ERR(crtc_state)); 12737 - continue; 12738 - } 12739 - 12740 - crtc_state->base.active = crtc_state->base.enable = 12741 - intel_crtc->new_enabled; 12742 - 12743 - if (&intel_crtc->base == crtc) 12744 - drm_mode_copy(&crtc_state->base.mode, &crtc->mode); 12728 + crtc_state = intel_atomic_get_crtc_state(state, to_intel_crtc(crtc)); 12729 + if (IS_ERR(crtc_state)) { 12730 + DRM_DEBUG_KMS("Failed to add [CRTC:%d] to state: %ld\n", 12731 + crtc->base.id, PTR_ERR(crtc_state)); 12732 + drm_atomic_state_free(state); 12733 + return; 12745 12734 } 12735 + 12736 + crtc_state->base.active = crtc_state->base.enable = 12737 + to_intel_crtc(crtc)->new_enabled; 12738 + 12739 + drm_mode_copy(&crtc_state->base.mode, &crtc->mode); 12746 12740 12747 12741 intel_modeset_setup_plane_state(state, crtc, &crtc->mode, 12748 12742 crtc->primary->fb, crtc->x, crtc->y); 12749 12743 12750 - ret = intel_set_mode(crtc, state); 12744 + ret = intel_set_mode(crtc, state, false); 12751 12745 if (ret) 12752 12746 drm_atomic_state_free(state); 12753 12747 } ··· 12941 12947 12942 12948 primary_plane_was_visible = primary_plane_visible(set->crtc); 12943 12949 12944 - ret = intel_set_mode_with_config(set->crtc, pipe_config); 12950 + ret = intel_set_mode_with_config(set->crtc, pipe_config, true); 12945 12951 12946 12952 if (ret == 0 && 12947 12953 pipe_config->base.enable &&
+3 -2
drivers/gpu/drm/i915/intel_ringbuffer.h
··· 118 118 }; 119 119 120 120 struct intel_context; 121 + struct drm_i915_reg_descriptor; 121 122 122 123 struct intel_engine_cs { 123 124 const char *name; ··· 301 300 /* 302 301 * Table of registers allowed in commands that read/write registers. 303 302 */ 304 - const u32 *reg_table; 303 + const struct drm_i915_reg_descriptor *reg_table; 305 304 int reg_count; 306 305 307 306 /* 308 307 * Table of registers allowed in commands that read/write registers, but 309 308 * only from the DRM master. 310 309 */ 311 - const u32 *master_reg_table; 310 + const struct drm_i915_reg_descriptor *master_reg_table; 312 311 int master_reg_count; 313 312 314 313 /*