]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
Merge branch 'drm-next-4.9' of git://people.freedesktop.org/~agd5f/linux into drm-next
authorDave Airlie <airlied@redhat.com>
Thu, 25 Aug 2016 02:59:50 +0000 (12:59 +1000)
committerDave Airlie <airlied@redhat.com>
Thu, 25 Aug 2016 02:59:50 +0000 (12:59 +1000)
First drm-next pull for radeon and amdgpu for 4.9.  Highlights:
- powerplay support for iceland asics
- improved GPU reset (both full asic and per block)
- UVD and VCE powergating for CZ and ST
- VCE clockgating for CZ and ST
- Support for pre-initialized (e.g., zeroed) vram buffers
- ttm cleanups
- virtual display support
- core and radeon/amdgpu support for page_flip_target
- lots of bug fixes and clean ups

* 'drm-next-4.9' of git://people.freedesktop.org/~agd5f/linux: (171 commits)
  drm/amdgpu: use memcpy_toio for VCE firmware upload
  drm/amdgpu: use memcpy_to/fromio for UVD fw upload
  drm/amd/powerplay: delete useless code in iceland_hwmgr.c.
  drm/radeon: switch UVD code to use UVD_NO_OP for padding
  drm/amdgpu: switch UVD code to use UVD_NO_OP for padding
  drm/radeon: add support for UVD_NO_OP register
  drm/amdgpu: add support for UVD_NO_OP register
  drm/amdgpu: fix VCE ib alignment value
  drm/amdgpu: fix IB alignment for UVD
  drm/amd/amdgpu: Print ring name in amdgpu_ib_schedule()
  drm/radeon: remove dead code, si_mc_load_microcode (v2)
  drm/radeon/cik: remove dead code (v2)
  drm/amd/powerplay: avoid NULL dereference, cz_hwmgr.c
  drm/amd/powerplay: avoid NULL pointer dereference
  drm/amdgpu/gmc8: remove dead code (v2)
  drm/amdgpu/gmc7: remove dead code (v2)
  drm/amdgpu: Fix indentation in dce_v8_0_audio_write_sad_regs()
  drm/amdgpu: Use correct mask in dce_v8_0_afmt_setmode() and fix comment typos.
  drm/amdgpu: cleanup amdgpu_vm_bo_update params
  drm/amdgpu: stop adding dummy entry in amdgpu_ttm_placement_init
  ...

15 files changed:
1  2 
drivers/gpu/drm/Kconfig
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
drivers/gpu/drm/amd/powerplay/hwmgr/fiji_hwmgr.c
drivers/gpu/drm/amd/powerplay/hwmgr/polaris10_hwmgr.c
drivers/gpu/drm/amd/powerplay/hwmgr/tonga_hwmgr.c
drivers/gpu/drm/drm_crtc.c
drivers/gpu/drm/drm_ioctl.c
drivers/gpu/drm/radeon/atombios_crtc.c
drivers/gpu/drm/radeon/radeon_drv.c
include/drm/drm_crtc.h

diff --combined drivers/gpu/drm/Kconfig
index fe1e86ea6d27734f273a8b1c7f285a384bf3d415,64f2a448a137612a8d71fd8503b4fce7a828a170..cbb64d9a82f8c7a6c4ef2644da76bdf556c28a33
@@@ -129,8 -129,12 +129,8 @@@ config DRM_R12
  config DRM_RADEON
        tristate "ATI Radeon"
        depends on DRM && PCI
 -      select FB_CFB_FILLRECT
 -      select FB_CFB_COPYAREA
 -      select FB_CFB_IMAGEBLIT
        select FW_LOADER
          select DRM_KMS_HELPER
 -      select DRM_KMS_FB_HELPER
          select DRM_TTM
        select POWER_SUPPLY
        select HWMON
@@@ -149,8 -153,12 +149,8 @@@ source "drivers/gpu/drm/radeon/Kconfig
  config DRM_AMDGPU
        tristate "AMD GPU"
        depends on DRM && PCI
 -      select FB_CFB_FILLRECT
 -      select FB_CFB_COPYAREA
 -      select FB_CFB_IMAGEBLIT
        select FW_LOADER
          select DRM_KMS_HELPER
 -      select DRM_KMS_FB_HELPER
          select DRM_TTM
        select POWER_SUPPLY
        select HWMON
          If M is selected, the module will be called amdgpu.
  
  source "drivers/gpu/drm/amd/amdgpu/Kconfig"
- source "drivers/gpu/drm/amd/powerplay/Kconfig"
- source "drivers/gpu/drm/amd/acp/Kconfig"
  
  source "drivers/gpu/drm/nouveau/Kconfig"
  
index 11263c5b9967dbbf63934ff550d051fe833c0dd5,a631c954c4e27116b55befcbf7d9101fab2f89a2..7c911d0be2b3f45007a3ce783fa346f24b2b7687
   * - 3.2.0 - GFX8: Uses EOP_TC_WB_ACTION_EN, so UMDs don't have to do the same
   *           at the end of IBs.
   * - 3.3.0 - Add VM support for UVD on supported hardware.
+  * - 3.4.0 - Add AMDGPU_INFO_NUM_EVICTIONS.
+  * - 3.5.0 - Add support for new UVD_NO_OP register.
   */
  #define KMS_DRIVER_MAJOR      3
- #define KMS_DRIVER_MINOR      3
+ #define KMS_DRIVER_MINOR      5
  #define KMS_DRIVER_PATCHLEVEL 0
  
  int amdgpu_vram_limit = 0;
@@@ -84,11 -86,13 +86,13 @@@ int amdgpu_sched_jobs = 32
  int amdgpu_sched_hw_submission = 2;
  int amdgpu_powerplay = -1;
  int amdgpu_powercontainment = 1;
+ int amdgpu_sclk_deep_sleep_en = 1;
  unsigned amdgpu_pcie_gen_cap = 0;
  unsigned amdgpu_pcie_lane_cap = 0;
  unsigned amdgpu_cg_mask = 0xffffffff;
  unsigned amdgpu_pg_mask = 0xffffffff;
  char *amdgpu_disable_cu = NULL;
+ char *amdgpu_virtual_display = NULL;
  
  MODULE_PARM_DESC(vramlimit, "Restrict VRAM for testing, in megabytes");
  module_param_named(vramlimit, amdgpu_vram_limit, int, 0600);
@@@ -170,6 -174,9 +174,9 @@@ MODULE_PARM_DESC(powercontainment, "Pow
  module_param_named(powercontainment, amdgpu_powercontainment, int, 0444);
  #endif
  
+ MODULE_PARM_DESC(sclkdeepsleep, "SCLK Deep Sleep (1 = enable (default), 0 = disable)");
+ module_param_named(sclkdeepsleep, amdgpu_sclk_deep_sleep_en, int, 0444);
  MODULE_PARM_DESC(pcie_gen_cap, "PCIE Gen Caps (0: autodetect (default))");
  module_param_named(pcie_gen_cap, amdgpu_pcie_gen_cap, uint, 0444);
  
@@@ -185,6 -192,9 +192,9 @@@ module_param_named(pg_mask, amdgpu_pg_m
  MODULE_PARM_DESC(disable_cu, "Disable CUs (se.sh.cu,...)");
  module_param_named(disable_cu, amdgpu_disable_cu, charp, 0444);
  
+ MODULE_PARM_DESC(virtual_display, "Enable virtual display feature (the virtual_display will be set like xxxx:xx:xx.x;xxxx:xx:xx.x)");
+ module_param_named(virtual_display, amdgpu_virtual_display, charp, 0444);
  static const struct pci_device_id pciidlist[] = {
  #ifdef CONFIG_DRM_AMDGPU_CIK
        /* Kaveri */
@@@ -341,7 -351,7 +351,7 @@@ static int amdgpu_kick_out_firmware_fb(
  #ifdef CONFIG_X86
        primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
  #endif
 -      remove_conflicting_framebuffers(ap, "amdgpudrmfb", primary);
 +      drm_fb_helper_remove_conflicting_framebuffers(ap, "amdgpudrmfb", primary);
        kfree(ap);
  
        return 0;
index 741da36cd8b6e6ef819cde0038e8c3d684929efb,db6e6c3eaae2a9ab08aef5384cd8e1c24ca4c5ce..bc5bb4eb9625a0959ad931e41f4c7447ff6f1c2b
@@@ -646,8 -646,8 +646,8 @@@ static void dce_v10_0_resume_mc_access(
  
                if (save->crtc_enabled[i]) {
                        tmp = RREG32(mmMASTER_UPDATE_MODE + crtc_offsets[i]);
-                       if (REG_GET_FIELD(tmp, MASTER_UPDATE_MODE, MASTER_UPDATE_MODE) != 3) {
-                               tmp = REG_SET_FIELD(tmp, MASTER_UPDATE_MODE, MASTER_UPDATE_MODE, 3);
+                       if (REG_GET_FIELD(tmp, MASTER_UPDATE_MODE, MASTER_UPDATE_MODE) != 0) {
+                               tmp = REG_SET_FIELD(tmp, MASTER_UPDATE_MODE, MASTER_UPDATE_MODE, 0);
                                WREG32(mmMASTER_UPDATE_MODE + crtc_offsets[i], tmp);
                        }
                        tmp = RREG32(mmGRPH_UPDATE + crtc_offsets[i]);
@@@ -712,6 -712,45 +712,45 @@@ static void dce_v10_0_set_vga_render_st
        WREG32(mmVGA_RENDER_CONTROL, tmp);
  }
  
+ static int dce_v10_0_get_num_crtc(struct amdgpu_device *adev)
+ {
+       int num_crtc = 0;
+       switch (adev->asic_type) {
+       case CHIP_FIJI:
+       case CHIP_TONGA:
+               num_crtc = 6;
+               break;
+       default:
+               num_crtc = 0;
+       }
+       return num_crtc;
+ }
+ void dce_v10_0_disable_dce(struct amdgpu_device *adev)
+ {
+       /*Disable VGA render and enabled crtc, if has DCE engine*/
+       if (amdgpu_atombios_has_dce_engine_info(adev)) {
+               u32 tmp;
+               int crtc_enabled, i;
+               dce_v10_0_set_vga_render_state(adev, false);
+               /*Disable crtc*/
+               for (i = 0; i < dce_v10_0_get_num_crtc(adev); i++) {
+                       crtc_enabled = REG_GET_FIELD(RREG32(mmCRTC_CONTROL + crtc_offsets[i]),
+                                                                        CRTC_CONTROL, CRTC_MASTER_EN);
+                       if (crtc_enabled) {
+                               WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 1);
+                               tmp = RREG32(mmCRTC_CONTROL + crtc_offsets[i]);
+                               tmp = REG_SET_FIELD(tmp, CRTC_CONTROL, CRTC_MASTER_EN, 0);
+                               WREG32(mmCRTC_CONTROL + crtc_offsets[i], tmp);
+                               WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 0);
+                       }
+               }
+       }
+ }
  static void dce_v10_0_program_fmt(struct drm_encoder *encoder)
  {
        struct drm_device *dev = encoder->dev;
@@@ -2071,7 -2110,6 +2110,7 @@@ static int dce_v10_0_crtc_do_set_base(s
        u32 tmp, viewport_w, viewport_h;
        int r;
        bool bypass_lut = false;
 +      char *format_name;
  
        /* no fb bound */
        if (!atomic && !crtc->primary->fb) {
                bypass_lut = true;
                break;
        default:
 -              DRM_ERROR("Unsupported screen format %s\n",
 -                      drm_get_format_name(target_fb->pixel_format));
 +              format_name = drm_get_format_name(target_fb->pixel_format);
 +              DRM_ERROR("Unsupported screen format %s\n", format_name);
 +              kfree(format_name);
                return -EINVAL;
        }
  
        WREG32(mmVIEWPORT_SIZE + amdgpu_crtc->crtc_offset,
               (viewport_w << 16) | viewport_h);
  
-       /* set pageflip to happen only at start of vblank interval (front porch) */
-       WREG32(mmMASTER_UPDATE_MODE + amdgpu_crtc->crtc_offset, 3);
+       /* set pageflip to happen anywhere in vblank interval */
+       WREG32(mmMASTER_UPDATE_MODE + amdgpu_crtc->crtc_offset, 0);
  
        if (!atomic && fb && fb != crtc->primary->fb) {
                amdgpu_fb = to_amdgpu_framebuffer(fb);
@@@ -2700,7 -2737,7 +2739,7 @@@ static const struct drm_crtc_funcs dce_
        .gamma_set = dce_v10_0_crtc_gamma_set,
        .set_config = amdgpu_crtc_set_config,
        .destroy = dce_v10_0_crtc_destroy,
-       .page_flip = amdgpu_crtc_page_flip,
+       .page_flip_target = amdgpu_crtc_page_flip_target,
  };
  
  static void dce_v10_0_crtc_dpms(struct drm_crtc *crtc, int mode)
@@@ -2964,10 -3001,11 +3003,11 @@@ static int dce_v10_0_early_init(void *h
        dce_v10_0_set_display_funcs(adev);
        dce_v10_0_set_irq_funcs(adev);
  
+       adev->mode_info.num_crtc = dce_v10_0_get_num_crtc(adev);
        switch (adev->asic_type) {
        case CHIP_FIJI:
        case CHIP_TONGA:
-               adev->mode_info.num_crtc = 6; /* XXX 7??? */
                adev->mode_info.num_hpd = 6;
                adev->mode_info.num_dig = 7;
                break;
@@@ -3143,11 -3181,26 +3183,26 @@@ static int dce_v10_0_wait_for_idle(voi
        return 0;
  }
  
+ static int dce_v10_0_check_soft_reset(void *handle)
+ {
+       struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+       if (dce_v10_0_is_display_hung(adev))
+               adev->ip_block_status[AMD_IP_BLOCK_TYPE_DCE].hang = true;
+       else
+               adev->ip_block_status[AMD_IP_BLOCK_TYPE_DCE].hang = false;
+       return 0;
+ }
  static int dce_v10_0_soft_reset(void *handle)
  {
        u32 srbm_soft_reset = 0, tmp;
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  
+       if (!adev->ip_block_status[AMD_IP_BLOCK_TYPE_DCE].hang)
+               return 0;
        if (dce_v10_0_is_display_hung(adev))
                srbm_soft_reset |= SRBM_SOFT_RESET__SOFT_RESET_DC_MASK;
  
@@@ -3514,6 -3567,7 +3569,7 @@@ const struct amd_ip_funcs dce_v10_0_ip_
        .resume = dce_v10_0_resume,
        .is_idle = dce_v10_0_is_idle,
        .wait_for_idle = dce_v10_0_wait_for_idle,
+       .check_soft_reset = dce_v10_0_check_soft_reset,
        .soft_reset = dce_v10_0_soft_reset,
        .set_clockgating_state = dce_v10_0_set_clockgating_state,
        .set_powergating_state = dce_v10_0_set_powergating_state,
index 2282eb60aba6ee04c0fdfdf5b4b4708c961c6625,a35ac3a859eac3d45476da876333b5b738384de5..b93eba0779507d95682cd52eb1ab861588ffe20d
@@@ -673,6 -673,53 +673,53 @@@ static void dce_v11_0_set_vga_render_st
        WREG32(mmVGA_RENDER_CONTROL, tmp);
  }
  
+ static int dce_v11_0_get_num_crtc (struct amdgpu_device *adev)
+ {
+       int num_crtc = 0;
+       switch (adev->asic_type) {
+       case CHIP_CARRIZO:
+               num_crtc = 3;
+               break;
+       case CHIP_STONEY:
+               num_crtc = 2;
+               break;
+       case CHIP_POLARIS10:
+               num_crtc = 6;
+               break;
+       case CHIP_POLARIS11:
+               num_crtc = 5;
+               break;
+       default:
+               num_crtc = 0;
+       }
+       return num_crtc;
+ }
+ void dce_v11_0_disable_dce(struct amdgpu_device *adev)
+ {
+       /*Disable VGA render and enabled crtc, if has DCE engine*/
+       if (amdgpu_atombios_has_dce_engine_info(adev)) {
+               u32 tmp;
+               int crtc_enabled, i;
+               dce_v11_0_set_vga_render_state(adev, false);
+               /*Disable crtc*/
+               for (i = 0; i < dce_v11_0_get_num_crtc(adev); i++) {
+                       crtc_enabled = REG_GET_FIELD(RREG32(mmCRTC_CONTROL + crtc_offsets[i]),
+                                                                        CRTC_CONTROL, CRTC_MASTER_EN);
+                       if (crtc_enabled) {
+                               WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 1);
+                               tmp = RREG32(mmCRTC_CONTROL + crtc_offsets[i]);
+                               tmp = REG_SET_FIELD(tmp, CRTC_CONTROL, CRTC_MASTER_EN, 0);
+                               WREG32(mmCRTC_CONTROL + crtc_offsets[i], tmp);
+                               WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 0);
+                       }
+               }
+       }
+ }
  static void dce_v11_0_program_fmt(struct drm_encoder *encoder)
  {
        struct drm_device *dev = encoder->dev;
@@@ -2046,7 -2093,6 +2093,7 @@@ static int dce_v11_0_crtc_do_set_base(s
        u32 tmp, viewport_w, viewport_h;
        int r;
        bool bypass_lut = false;
 +      char *format_name;
  
        /* no fb bound */
        if (!atomic && !crtc->primary->fb) {
                bypass_lut = true;
                break;
        default:
 -              DRM_ERROR("Unsupported screen format %s\n",
 -                      drm_get_format_name(target_fb->pixel_format));
 +              format_name = drm_get_format_name(target_fb->pixel_format);
 +              DRM_ERROR("Unsupported screen format %s\n", format_name);
 +              kfree(format_name);
                return -EINVAL;
        }
  
        WREG32(mmVIEWPORT_SIZE + amdgpu_crtc->crtc_offset,
               (viewport_w << 16) | viewport_h);
  
-       /* set pageflip to happen only at start of vblank interval (front porch) */
-       WREG32(mmCRTC_MASTER_UPDATE_MODE + amdgpu_crtc->crtc_offset, 3);
+       /* set pageflip to happen anywhere in vblank interval */
+       WREG32(mmCRTC_MASTER_UPDATE_MODE + amdgpu_crtc->crtc_offset, 0);
  
        if (!atomic && fb && fb != crtc->primary->fb) {
                amdgpu_fb = to_amdgpu_framebuffer(fb);
@@@ -2710,7 -2755,7 +2757,7 @@@ static const struct drm_crtc_funcs dce_
        .gamma_set = dce_v11_0_crtc_gamma_set,
        .set_config = amdgpu_crtc_set_config,
        .destroy = dce_v11_0_crtc_destroy,
-       .page_flip = amdgpu_crtc_page_flip,
+       .page_flip_target = amdgpu_crtc_page_flip_target,
  };
  
  static void dce_v11_0_crtc_dpms(struct drm_crtc *crtc, int mode)
@@@ -3001,24 -3046,22 +3048,22 @@@ static int dce_v11_0_early_init(void *h
        dce_v11_0_set_display_funcs(adev);
        dce_v11_0_set_irq_funcs(adev);
  
+       adev->mode_info.num_crtc = dce_v11_0_get_num_crtc(adev);
        switch (adev->asic_type) {
        case CHIP_CARRIZO:
-               adev->mode_info.num_crtc = 3;
                adev->mode_info.num_hpd = 6;
                adev->mode_info.num_dig = 9;
                break;
        case CHIP_STONEY:
-               adev->mode_info.num_crtc = 2;
                adev->mode_info.num_hpd = 6;
                adev->mode_info.num_dig = 9;
                break;
        case CHIP_POLARIS10:
-               adev->mode_info.num_crtc = 6;
                adev->mode_info.num_hpd = 6;
                adev->mode_info.num_dig = 6;
                break;
        case CHIP_POLARIS11:
-               adev->mode_info.num_crtc = 5;
                adev->mode_info.num_hpd = 5;
                adev->mode_info.num_dig = 5;
                break;
index 8b7ad345771f67b2c8d05b8b717703b524b41145,845a30b03cb4051d06f4c2c1452b31f9aa3ddb54..abd5213dfe18785a8d86068e40c55b8ad5fab4a4
@@@ -604,6 -604,52 +604,52 @@@ static void dce_v8_0_set_vga_render_sta
        WREG32(mmVGA_RENDER_CONTROL, tmp);
  }
  
+ static int dce_v8_0_get_num_crtc(struct amdgpu_device *adev)
+ {
+       int num_crtc = 0;
+       switch (adev->asic_type) {
+       case CHIP_BONAIRE:
+       case CHIP_HAWAII:
+               num_crtc = 6;
+               break;
+       case CHIP_KAVERI:
+               num_crtc = 4;
+               break;
+       case CHIP_KABINI:
+       case CHIP_MULLINS:
+               num_crtc = 2;
+               break;
+       default:
+               num_crtc = 0;
+       }
+       return num_crtc;
+ }
+ void dce_v8_0_disable_dce(struct amdgpu_device *adev)
+ {
+       /*Disable VGA render and enabled crtc, if has DCE engine*/
+       if (amdgpu_atombios_has_dce_engine_info(adev)) {
+               u32 tmp;
+               int crtc_enabled, i;
+               dce_v8_0_set_vga_render_state(adev, false);
+               /*Disable crtc*/
+               for (i = 0; i < dce_v8_0_get_num_crtc(adev); i++) {
+                       crtc_enabled = REG_GET_FIELD(RREG32(mmCRTC_CONTROL + crtc_offsets[i]),
+                                                                        CRTC_CONTROL, CRTC_MASTER_EN);
+                       if (crtc_enabled) {
+                               WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 1);
+                               tmp = RREG32(mmCRTC_CONTROL + crtc_offsets[i]);
+                               tmp = REG_SET_FIELD(tmp, CRTC_CONTROL, CRTC_MASTER_EN, 0);
+                               WREG32(mmCRTC_CONTROL + crtc_offsets[i], tmp);
+                               WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 0);
+                       }
+               }
+       }
+ }
  static void dce_v8_0_program_fmt(struct drm_encoder *encoder)
  {
        struct drm_device *dev = encoder->dev;
@@@ -1501,13 -1547,13 +1547,13 @@@ static void dce_v8_0_audio_write_sad_re
  
                        if (sad->format == eld_reg_to_type[i][1]) {
                                if (sad->channels > max_channels) {
-                               value = (sad->channels <<
-                                AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0__MAX_CHANNELS__SHIFT) |
-                               (sad->byte2 <<
-                                AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0__DESCRIPTOR_BYTE_2__SHIFT) |
-                               (sad->freq <<
-                                AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0__SUPPORTED_FREQUENCIES__SHIFT);
-                               max_channels = sad->channels;
+                                       value = (sad->channels <<
+                                                AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0__MAX_CHANNELS__SHIFT) |
+                                               (sad->byte2 <<
+                                                AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0__DESCRIPTOR_BYTE_2__SHIFT) |
+                                               (sad->freq <<
+                                                AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0__SUPPORTED_FREQUENCIES__SHIFT);
+                                       max_channels = sad->channels;
                                }
  
                                if (sad->format == HDMI_AUDIO_CODING_TYPE_PCM)
@@@ -1613,7 -1659,7 +1659,7 @@@ static void dce_v8_0_afmt_update_ACR(st
        struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
        uint32_t offset = dig->afmt->offset;
  
-       WREG32(mmHDMI_ACR_32_0 + offset, (acr.cts_32khz << HDMI_ACR_44_0__HDMI_ACR_CTS_44__SHIFT));
+       WREG32(mmHDMI_ACR_32_0 + offset, (acr.cts_32khz << HDMI_ACR_32_0__HDMI_ACR_CTS_32__SHIFT));
        WREG32(mmHDMI_ACR_32_1 + offset, acr.n_32khz);
  
        WREG32(mmHDMI_ACR_44_0 + offset, (acr.cts_44_1khz << HDMI_ACR_44_0__HDMI_ACR_CTS_44__SHIFT));
@@@ -1693,6 -1739,7 +1739,7 @@@ static void dce_v8_0_afmt_setmode(struc
        /* Silent, r600_hdmi_enable will raise WARN for us */
        if (!dig->afmt->enabled)
                return;
        offset = dig->afmt->offset;
  
        /* hdmi deep color mode general control packets setup, if bpc > 8 */
  
        WREG32_OR(mmHDMI_INFOFRAME_CONTROL0 + offset,
                  HDMI_INFOFRAME_CONTROL0__HDMI_AVI_INFO_SEND_MASK | /* enable AVI info frames */
-                 HDMI_INFOFRAME_CONTROL0__HDMI_AVI_INFO_SEND_MASK); /* required for audio info values to be updated */
+                 HDMI_INFOFRAME_CONTROL0__HDMI_AVI_INFO_CONT_MASK); /* required for audio info values to be updated */
  
        WREG32_P(mmHDMI_INFOFRAME_CONTROL1 + offset,
                 (2 << HDMI_INFOFRAME_CONTROL1__HDMI_AVI_INFO_LINE__SHIFT), /* anything other than 0 */
        WREG32_OR(mmAFMT_AUDIO_PACKET_CONTROL + offset,
                  AFMT_AUDIO_PACKET_CONTROL__AFMT_AUDIO_SAMPLE_SEND_MASK); /* send audio packets */
  
-       /* it's unknown what these bits do excatly, but it's indeed quite useful for debugging */
        WREG32(mmAFMT_RAMP_CONTROL0 + offset, 0x00FFFFFF);
        WREG32(mmAFMT_RAMP_CONTROL1 + offset, 0x007FFFFF);
        WREG32(mmAFMT_RAMP_CONTROL2 + offset, 0x00000001);
        WREG32(mmAFMT_RAMP_CONTROL3 + offset, 0x00000001);
  
-       /* enable audio after to setting up hw */
+       /* enable audio after setting up hw */
        dce_v8_0_audio_enable(adev, dig->afmt->pin, true);
  }
  
@@@ -1952,7 -1998,6 +1998,7 @@@ static int dce_v8_0_crtc_do_set_base(st
        u32 viewport_w, viewport_h;
        int r;
        bool bypass_lut = false;
 +      char *format_name;
  
        /* no fb bound */
        if (!atomic && !crtc->primary->fb) {
        case DRM_FORMAT_XRGB4444:
        case DRM_FORMAT_ARGB4444:
                fb_format = ((GRPH_DEPTH_16BPP << GRPH_CONTROL__GRPH_DEPTH__SHIFT) |
-                            (GRPH_FORMAT_ARGB1555 << GRPH_CONTROL__GRPH_FORMAT__SHIFT));
+                            (GRPH_FORMAT_ARGB4444 << GRPH_CONTROL__GRPH_FORMAT__SHIFT));
  #ifdef __BIG_ENDIAN
                fb_swap = (GRPH_ENDIAN_8IN16 << GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT);
  #endif
                bypass_lut = true;
                break;
        default:
 -              DRM_ERROR("Unsupported screen format %s\n",
 -                        drm_get_format_name(target_fb->pixel_format));
 +              format_name = drm_get_format_name(target_fb->pixel_format);
 +              DRM_ERROR("Unsupported screen format %s\n", format_name);
 +              kfree(format_name);
                return -EINVAL;
        }
  
        WREG32(mmVIEWPORT_SIZE + amdgpu_crtc->crtc_offset,
               (viewport_w << 16) | viewport_h);
  
-       /* set pageflip to happen only at start of vblank interval (front porch) */
-       WREG32(mmMASTER_UPDATE_MODE + amdgpu_crtc->crtc_offset, 3);
+       /* set pageflip to happen anywhere in vblank interval */
+       WREG32(mmMASTER_UPDATE_MODE + amdgpu_crtc->crtc_offset, 0);
  
        if (!atomic && fb && fb != crtc->primary->fb) {
                amdgpu_fb = to_amdgpu_framebuffer(fb);
@@@ -2554,7 -2598,7 +2600,7 @@@ static const struct drm_crtc_funcs dce_
        .gamma_set = dce_v8_0_crtc_gamma_set,
        .set_config = amdgpu_crtc_set_config,
        .destroy = dce_v8_0_crtc_destroy,
-       .page_flip = amdgpu_crtc_page_flip,
+       .page_flip_target = amdgpu_crtc_page_flip_target,
  };
  
  static void dce_v8_0_crtc_dpms(struct drm_crtc *crtc, int mode)
@@@ -2655,7 -2699,7 +2701,7 @@@ static void dce_v8_0_crtc_disable(struc
        case ATOM_PPLL2:
                /* disable the ppll */
                amdgpu_atombios_crtc_program_pll(crtc, amdgpu_crtc->crtc_id, amdgpu_crtc->pll_id,
-                                         0, 0, ATOM_DISABLE, 0, 0, 0, 0, 0, false, &ss);
+                                                  0, 0, ATOM_DISABLE, 0, 0, 0, 0, 0, false, &ss);
                break;
        case ATOM_PPLL0:
                /* disable the ppll */
@@@ -2805,21 -2849,20 +2851,20 @@@ static int dce_v8_0_early_init(void *ha
        dce_v8_0_set_display_funcs(adev);
        dce_v8_0_set_irq_funcs(adev);
  
+       adev->mode_info.num_crtc = dce_v8_0_get_num_crtc(adev);
        switch (adev->asic_type) {
        case CHIP_BONAIRE:
        case CHIP_HAWAII:
-               adev->mode_info.num_crtc = 6;
                adev->mode_info.num_hpd = 6;
                adev->mode_info.num_dig = 6;
                break;
        case CHIP_KAVERI:
-               adev->mode_info.num_crtc = 4;
                adev->mode_info.num_hpd = 6;
                adev->mode_info.num_dig = 7;
                break;
        case CHIP_KABINI:
        case CHIP_MULLINS:
-               adev->mode_info.num_crtc = 2;
                adev->mode_info.num_hpd = 6;
                adev->mode_info.num_dig = 6; /* ? */
                break;
@@@ -3238,7 -3281,6 +3283,6 @@@ static int dce_v8_0_crtc_irq(struct amd
                        drm_handle_vblank(adev->ddev, crtc);
                }
                DRM_DEBUG("IH: D%d vblank\n", crtc + 1);
                break;
        case 1: /* vline */
                if (disp_int & interrupt_status_offsets[crtc].vline)
                        DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  
                DRM_DEBUG("IH: D%d vline\n", crtc + 1);
                break;
        default:
                DRM_DEBUG("Unhandled interrupt: %d %d\n", entry->src_id, entry->src_data);
index b8184617ca250f143ee01779fa40f77edeee80e4,6022208ead3130a4eb79ee6b6e198d14108713b7..c6a63c2f91e3658d61354ce523fc2c40e53a1c68
@@@ -270,8 -270,7 +270,8 @@@ static const u32 tonga_mgcg_cgcg_init[
  
  static const u32 golden_settings_polaris11_a11[] =
  {
 -      mmCB_HW_CONTROL, 0xfffdf3cf, 0x00006208,
 +      mmCB_HW_CONTROL, 0x0000f3cf, 0x00007208,
 +      mmCB_HW_CONTROL_2, 0x0f000000, 0x0f000000,
        mmCB_HW_CONTROL_3, 0x000001ff, 0x00000040,
        mmDB_DEBUG2, 0xf00fffff, 0x00000400,
        mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
        mmPA_SC_RASTER_CONFIG_1, 0x0000003f, 0x00000000,
        mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0001003c,
        mmRLC_CGCG_CGLS_CTRL_3D, 0xffffffff, 0x0001003c,
 -      mmSQ_CONFIG, 0x07f80000, 0x07180000,
 +      mmSQ_CONFIG, 0x07f80000, 0x01180000,
        mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
        mmTCC_CTRL, 0x00100000, 0xf31fff7f,
        mmTCP_ADDR_CONFIG, 0x000003ff, 0x000000f3,
@@@ -302,8 -301,8 +302,8 @@@ static const u32 polaris11_golden_commo
  static const u32 golden_settings_polaris10_a11[] =
  {
        mmATC_MISC_CG, 0x000c0fc0, 0x000c0200,
 -      mmCB_HW_CONTROL, 0xfffdf3cf, 0x00007208,
 -      mmCB_HW_CONTROL_2, 0, 0x0f000000,
 +      mmCB_HW_CONTROL, 0x0001f3cf, 0x00007208,
 +      mmCB_HW_CONTROL_2, 0x0f000000, 0x0f000000,
        mmCB_HW_CONTROL_3, 0x000001ff, 0x00000040,
        mmDB_DEBUG2, 0xf00fffff, 0x00000400,
        mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
@@@ -410,7 -409,6 +410,7 @@@ static const u32 golden_settings_icelan
        mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
        mmPA_SC_RASTER_CONFIG, 0x3f3fffff, 0x00000002,
        mmPA_SC_RASTER_CONFIG_1, 0x0000003f, 0x00000000,
 +      mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0000003c,
        mmSQ_RANDOM_WAVE_PRI, 0x001fffff, 0x000006fd,
        mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
        mmTCC_CTRL, 0x00100000, 0xf31fff7f,
@@@ -507,10 -505,8 +507,10 @@@ static const u32 cz_golden_settings_a11
        mmGB_GPU_ID, 0x0000000f, 0x00000000,
        mmPA_SC_ENHANCE, 0xffffffff, 0x00000001,
        mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
 +      mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0000003c,
        mmSQ_RANDOM_WAVE_PRI, 0x001fffff, 0x000006fd,
        mmTA_CNTL_AUX, 0x000f000f, 0x00010000,
 +      mmTCC_CTRL, 0x00100000, 0xf31fff7f,
        mmTCC_EXE_DISABLE, 0x00000002, 0x00000002,
        mmTCP_ADDR_CONFIG, 0x0000000f, 0x000000f3,
        mmTCP_CHAN_STEER_LO, 0xffffffff, 0x00001302
@@@ -703,7 -699,10 +703,10 @@@ static void gfx_v8_0_init_golden_regist
                                                 polaris10_golden_common_all,
                                                 (const u32)ARRAY_SIZE(polaris10_golden_common_all));
                WREG32_SMC(ixCG_ACLK_CNTL, 0x0000001C);
-               if (adev->pdev->revision == 0xc7) {
+               if (adev->pdev->revision == 0xc7 &&
+                   ((adev->pdev->subsystem_device == 0xb37 && adev->pdev->subsystem_vendor == 0x1002) ||
+                    (adev->pdev->subsystem_device == 0x4a8 && adev->pdev->subsystem_vendor == 0x1043) ||
+                    (adev->pdev->subsystem_device == 0x9480 && adev->pdev->subsystem_vendor == 0x1682))) {
                        amdgpu_atombios_i2c_channel_trans(adev, 0x10, 0x96, 0x1E, 0xDD);
                        amdgpu_atombios_i2c_channel_trans(adev, 0x10, 0x96, 0x1F, 0xD0);
                }
@@@ -1233,10 -1232,9 +1236,9 @@@ static void gfx_v8_0_rlc_fini(struct am
        if (adev->gfx.rlc.clear_state_obj) {
                r = amdgpu_bo_reserve(adev->gfx.rlc.clear_state_obj, false);
                if (unlikely(r != 0))
-                       dev_warn(adev->dev, "(%d) reserve RLC c bo failed\n", r);
+                       dev_warn(adev->dev, "(%d) reserve RLC cbs bo failed\n", r);
                amdgpu_bo_unpin(adev->gfx.rlc.clear_state_obj);
                amdgpu_bo_unreserve(adev->gfx.rlc.clear_state_obj);
                amdgpu_bo_unref(&adev->gfx.rlc.clear_state_obj);
                adev->gfx.rlc.clear_state_obj = NULL;
        }
                        dev_warn(adev->dev, "(%d) reserve RLC cp table bo failed\n", r);
                amdgpu_bo_unpin(adev->gfx.rlc.cp_table_obj);
                amdgpu_bo_unreserve(adev->gfx.rlc.cp_table_obj);
                amdgpu_bo_unref(&adev->gfx.rlc.cp_table_obj);
                adev->gfx.rlc.cp_table_obj = NULL;
        }
@@@ -1290,14 -1287,14 +1291,14 @@@ static int gfx_v8_0_rlc_init(struct amd
                                  &adev->gfx.rlc.clear_state_gpu_addr);
                if (r) {
                        amdgpu_bo_unreserve(adev->gfx.rlc.clear_state_obj);
-                       dev_warn(adev->dev, "(%d) pin RLC c bo failed\n", r);
+                       dev_warn(adev->dev, "(%d) pin RLC cbs bo failed\n", r);
                        gfx_v8_0_rlc_fini(adev);
                        return r;
                }
  
                r = amdgpu_bo_kmap(adev->gfx.rlc.clear_state_obj, (void **)&adev->gfx.rlc.cs_ptr);
                if (r) {
-                       dev_warn(adev->dev, "(%d) map RLC c bo failed\n", r);
+                       dev_warn(adev->dev, "(%d) map RLC cbs bo failed\n", r);
                        gfx_v8_0_rlc_fini(adev);
                        return r;
                }
                                  &adev->gfx.rlc.cp_table_gpu_addr);
                if (r) {
                        amdgpu_bo_unreserve(adev->gfx.rlc.cp_table_obj);
-                       dev_warn(adev->dev, "(%d) pin RLC cp_table bo failed\n", r);
+                       dev_warn(adev->dev, "(%d) pin RLC cp table bo failed\n", r);
                        return r;
                }
                r = amdgpu_bo_kmap(adev->gfx.rlc.cp_table_obj, (void **)&adev->gfx.rlc.cp_table_ptr);
  
                amdgpu_bo_kunmap(adev->gfx.rlc.cp_table_obj);
                amdgpu_bo_unreserve(adev->gfx.rlc.cp_table_obj);
        }
  
        return 0;
@@@ -1361,7 -1357,6 +1361,6 @@@ static void gfx_v8_0_mec_fini(struct am
                        dev_warn(adev->dev, "(%d) reserve HPD EOP bo failed\n", r);
                amdgpu_bo_unpin(adev->gfx.mec.hpd_eop_obj);
                amdgpu_bo_unreserve(adev->gfx.mec.hpd_eop_obj);
                amdgpu_bo_unref(&adev->gfx.mec.hpd_eop_obj);
                adev->gfx.mec.hpd_eop_obj = NULL;
        }
@@@ -2082,24 -2077,21 +2081,21 @@@ static int gfx_v8_0_sw_init(void *handl
        }
  
        /* reserve GDS, GWS and OA resource for gfx */
-       r = amdgpu_bo_create(adev, adev->gds.mem.gfx_partition_size,
-                       PAGE_SIZE, true,
-                       AMDGPU_GEM_DOMAIN_GDS, 0, NULL,
-                       NULL, &adev->gds.gds_gfx_bo);
+       r = amdgpu_bo_create_kernel(adev, adev->gds.mem.gfx_partition_size,
+                                   PAGE_SIZE, AMDGPU_GEM_DOMAIN_GDS,
+                                   &adev->gds.gds_gfx_bo, NULL, NULL);
        if (r)
                return r;
  
-       r = amdgpu_bo_create(adev, adev->gds.gws.gfx_partition_size,
-               PAGE_SIZE, true,
-               AMDGPU_GEM_DOMAIN_GWS, 0, NULL,
-               NULL, &adev->gds.gws_gfx_bo);
+       r = amdgpu_bo_create_kernel(adev, adev->gds.gws.gfx_partition_size,
+                                   PAGE_SIZE, AMDGPU_GEM_DOMAIN_GWS,
+                                   &adev->gds.gws_gfx_bo, NULL, NULL);
        if (r)
                return r;
  
-       r = amdgpu_bo_create(adev, adev->gds.oa.gfx_partition_size,
-                       PAGE_SIZE, true,
-                       AMDGPU_GEM_DOMAIN_OA, 0, NULL,
-                       NULL, &adev->gds.oa_gfx_bo);
+       r = amdgpu_bo_create_kernel(adev, adev->gds.oa.gfx_partition_size,
+                                   PAGE_SIZE, AMDGPU_GEM_DOMAIN_OA,
+                                   &adev->gds.oa_gfx_bo, NULL, NULL);
        if (r)
                return r;
  
@@@ -2127,9 -2119,7 +2123,7 @@@ static int gfx_v8_0_sw_fini(void *handl
                amdgpu_ring_fini(&adev->gfx.compute_ring[i]);
  
        gfx_v8_0_mec_fini(adev);
        gfx_v8_0_rlc_fini(adev);
        gfx_v8_0_free_microcode(adev);
  
        return 0;
@@@ -3465,19 -3455,16 +3459,16 @@@ static void gfx_v8_0_select_se_sh(struc
        else
                data = REG_SET_FIELD(0, GRBM_GFX_INDEX, INSTANCE_INDEX, instance);
  
-       if ((se_num == 0xffffffff) && (sh_num == 0xffffffff)) {
-               data = REG_SET_FIELD(data, GRBM_GFX_INDEX, SH_BROADCAST_WRITES, 1);
+       if (se_num == 0xffffffff)
                data = REG_SET_FIELD(data, GRBM_GFX_INDEX, SE_BROADCAST_WRITES, 1);
-       } else if (se_num == 0xffffffff) {
-               data = REG_SET_FIELD(data, GRBM_GFX_INDEX, SH_INDEX, sh_num);
-               data = REG_SET_FIELD(data, GRBM_GFX_INDEX, SE_BROADCAST_WRITES, 1);
-       } else if (sh_num == 0xffffffff) {
-               data = REG_SET_FIELD(data, GRBM_GFX_INDEX, SH_BROADCAST_WRITES, 1);
+       else
                data = REG_SET_FIELD(data, GRBM_GFX_INDEX, SE_INDEX, se_num);
-       } else {
+       if (sh_num == 0xffffffff)
+               data = REG_SET_FIELD(data, GRBM_GFX_INDEX, SH_BROADCAST_WRITES, 1);
+       else
                data = REG_SET_FIELD(data, GRBM_GFX_INDEX, SH_INDEX, sh_num);
-               data = REG_SET_FIELD(data, GRBM_GFX_INDEX, SE_INDEX, se_num);
-       }
        WREG32(mmGRBM_GFX_INDEX, data);
  }
  
@@@ -3490,11 -3477,10 +3481,10 @@@ static u32 gfx_v8_0_get_rb_active_bitma
  {
        u32 data, mask;
  
-       data = RREG32(mmCC_RB_BACKEND_DISABLE);
-       data |= RREG32(mmGC_USER_RB_BACKEND_DISABLE);
+       data =  RREG32(mmCC_RB_BACKEND_DISABLE) |
+               RREG32(mmGC_USER_RB_BACKEND_DISABLE);
  
-       data &= CC_RB_BACKEND_DISABLE__BACKEND_DISABLE_MASK;
-       data >>= GC_USER_RB_BACKEND_DISABLE__BACKEND_DISABLE__SHIFT;
+       data = REG_GET_FIELD(data, GC_USER_RB_BACKEND_DISABLE, BACKEND_DISABLE);
  
        mask = gfx_v8_0_create_bitmask(adev->gfx.config.max_backends_per_se /
                                       adev->gfx.config.max_sh_per_se);
@@@ -3576,16 -3562,12 +3566,12 @@@ static void gfx_v8_0_gpu_init(struct am
        u32 tmp;
        int i;
  
-       tmp = RREG32(mmGRBM_CNTL);
-       tmp = REG_SET_FIELD(tmp, GRBM_CNTL, READ_TIMEOUT, 0xff);
-       WREG32(mmGRBM_CNTL, tmp);
+       WREG32_FIELD(GRBM_CNTL, READ_TIMEOUT, 0xFF);
        WREG32(mmGB_ADDR_CONFIG, adev->gfx.config.gb_addr_config);
        WREG32(mmHDP_ADDR_CONFIG, adev->gfx.config.gb_addr_config);
        WREG32(mmDMIF_ADDR_CALC, adev->gfx.config.gb_addr_config);
  
        gfx_v8_0_tiling_mode_table_init(adev);
        gfx_v8_0_setup_rb(adev);
        gfx_v8_0_get_cu_info(adev);
  
@@@ -3769,9 -3751,7 +3755,7 @@@ static int gfx_v8_0_init_save_restore_l
                                sizeof(indirect_start_offsets)/sizeof(int));
  
        /* save and restore list */
-       temp = RREG32(mmRLC_SRM_CNTL);
-       temp |= RLC_SRM_CNTL__AUTO_INCR_ADDR_MASK;
-       WREG32(mmRLC_SRM_CNTL, temp);
+       WREG32_FIELD(RLC_SRM_CNTL, AUTO_INCR_ADDR, 1);
  
        WREG32(mmRLC_SRM_ARAM_ADDR, 0);
        for (i = 0; i < adev->gfx.rlc.reg_list_size_bytes >> 2; i++)
  
  static void gfx_v8_0_enable_save_restore_machine(struct amdgpu_device *adev)
  {
-       uint32_t data;
-       data = RREG32(mmRLC_SRM_CNTL);
-       data |= RLC_SRM_CNTL__SRM_ENABLE_MASK;
-       WREG32(mmRLC_SRM_CNTL, data);
+       WREG32_FIELD(RLC_SRM_CNTL, SRM_ENABLE, 1);
  }
  
  static void gfx_v8_0_init_power_gating(struct amdgpu_device *adev)
        if (adev->pg_flags & (AMD_PG_SUPPORT_GFX_PG |
                              AMD_PG_SUPPORT_GFX_SMG |
                              AMD_PG_SUPPORT_GFX_DMG)) {
-               data = RREG32(mmCP_RB_WPTR_POLL_CNTL);
-               data &= ~CP_RB_WPTR_POLL_CNTL__IDLE_POLL_COUNT_MASK;
-               data |= (0x60 << CP_RB_WPTR_POLL_CNTL__IDLE_POLL_COUNT__SHIFT);
-               WREG32(mmCP_RB_WPTR_POLL_CNTL, data);
-               data = 0;
-               data |= (0x10 << RLC_PG_DELAY__POWER_UP_DELAY__SHIFT);
-               data |= (0x10 << RLC_PG_DELAY__POWER_DOWN_DELAY__SHIFT);
-               data |= (0x10 << RLC_PG_DELAY__CMD_PROPAGATE_DELAY__SHIFT);
-               data |= (0x10 << RLC_PG_DELAY__MEM_SLEEP_DELAY__SHIFT);
-               WREG32(mmRLC_PG_DELAY, data);
+               WREG32_FIELD(CP_RB_WPTR_POLL_CNTL, IDLE_POLL_COUNT, 0x60);
  
-               data = RREG32(mmRLC_PG_DELAY_2);
-               data &= ~RLC_PG_DELAY_2__SERDES_CMD_DELAY_MASK;
-               data |= (0x3 << RLC_PG_DELAY_2__SERDES_CMD_DELAY__SHIFT);
-               WREG32(mmRLC_PG_DELAY_2, data);
+               data = REG_SET_FIELD(0, RLC_PG_DELAY, POWER_UP_DELAY, 0x10);
+               data = REG_SET_FIELD(data, RLC_PG_DELAY, POWER_DOWN_DELAY, 0x10);
+               data = REG_SET_FIELD(data, RLC_PG_DELAY, CMD_PROPAGATE_DELAY, 0x10);
+               data = REG_SET_FIELD(data, RLC_PG_DELAY, MEM_SLEEP_DELAY, 0x10);
+               WREG32(mmRLC_PG_DELAY, data);
  
-               data = RREG32(mmRLC_AUTO_PG_CTRL);
-               data &= ~RLC_AUTO_PG_CTRL__GRBM_REG_SAVE_GFX_IDLE_THRESHOLD_MASK;
-               data |= (0x55f0 << RLC_AUTO_PG_CTRL__GRBM_REG_SAVE_GFX_IDLE_THRESHOLD__SHIFT);
-               WREG32(mmRLC_AUTO_PG_CTRL, data);
+               WREG32_FIELD(RLC_PG_DELAY_2, SERDES_CMD_DELAY, 0x3);
+               WREG32_FIELD(RLC_AUTO_PG_CTRL, GRBM_REG_SAVE_GFX_IDLE_THRESHOLD, 0x55f0);
        }
  }
  
  static void cz_enable_sck_slow_down_on_power_up(struct amdgpu_device *adev,
                                                bool enable)
  {
-       u32 data, orig;
-       orig = data = RREG32(mmRLC_PG_CNTL);
-       if (enable)
-               data |= RLC_PG_CNTL__SMU_CLK_SLOWDOWN_ON_PU_ENABLE_MASK;
-       else
-               data &= ~RLC_PG_CNTL__SMU_CLK_SLOWDOWN_ON_PU_ENABLE_MASK;
-       if (orig != data)
-               WREG32(mmRLC_PG_CNTL, data);
+       WREG32_FIELD(RLC_PG_CNTL, SMU_CLK_SLOWDOWN_ON_PU_ENABLE, enable ? 1 : 0);
  }
  
  static void cz_enable_sck_slow_down_on_power_down(struct amdgpu_device *adev,
                                                  bool enable)
  {
-       u32 data, orig;
-       orig = data = RREG32(mmRLC_PG_CNTL);
-       if (enable)
-               data |= RLC_PG_CNTL__SMU_CLK_SLOWDOWN_ON_PD_ENABLE_MASK;
-       else
-               data &= ~RLC_PG_CNTL__SMU_CLK_SLOWDOWN_ON_PD_ENABLE_MASK;
-       if (orig != data)
-               WREG32(mmRLC_PG_CNTL, data);
+       WREG32_FIELD(RLC_PG_CNTL, SMU_CLK_SLOWDOWN_ON_PD_ENABLE, enable ? 1 : 0);
  }
  
  static void cz_enable_cp_power_gating(struct amdgpu_device *adev, bool enable)
  {
-       u32 data, orig;
-       orig = data = RREG32(mmRLC_PG_CNTL);
-       if (enable)
-               data &= ~RLC_PG_CNTL__CP_PG_DISABLE_MASK;
-       else
-               data |= RLC_PG_CNTL__CP_PG_DISABLE_MASK;
-       if (orig != data)
-               WREG32(mmRLC_PG_CNTL, data);
+       WREG32_FIELD(RLC_PG_CNTL, CP_PG_DISABLE, enable ? 1 : 0);
  }
  
  static void gfx_v8_0_init_pg(struct amdgpu_device *adev)
  
  void gfx_v8_0_rlc_stop(struct amdgpu_device *adev)
  {
-       u32 tmp = RREG32(mmRLC_CNTL);
-       tmp = REG_SET_FIELD(tmp, RLC_CNTL, RLC_ENABLE_F32, 0);
-       WREG32(mmRLC_CNTL, tmp);
+       WREG32_FIELD(RLC_CNTL, RLC_ENABLE_F32, 0);
  
        gfx_v8_0_enable_gui_idle_interrupt(adev, false);
        gfx_v8_0_wait_for_rlc_serdes(adev);
  }
  
  static void gfx_v8_0_rlc_reset(struct amdgpu_device *adev)
  {
-       u32 tmp = RREG32(mmGRBM_SOFT_RESET);
-       tmp = REG_SET_FIELD(tmp, GRBM_SOFT_RESET, SOFT_RESET_RLC, 1);
-       WREG32(mmGRBM_SOFT_RESET, tmp);
+       WREG32_FIELD(GRBM_SOFT_RESET, SOFT_RESET_RLC, 1);
        udelay(50);
-       tmp = REG_SET_FIELD(tmp, GRBM_SOFT_RESET, SOFT_RESET_RLC, 0);
-       WREG32(mmGRBM_SOFT_RESET, tmp);
+       WREG32_FIELD(GRBM_SOFT_RESET, SOFT_RESET_RLC, 0);
        udelay(50);
  }
  
  static void gfx_v8_0_rlc_start(struct amdgpu_device *adev)
  {
-       u32 tmp = RREG32(mmRLC_CNTL);
-       tmp = REG_SET_FIELD(tmp, RLC_CNTL, RLC_ENABLE_F32, 1);
-       WREG32(mmRLC_CNTL, tmp);
+       WREG32_FIELD(RLC_CNTL, RLC_ENABLE_F32, 1);
  
        /* carrizo do enable cp interrupt after cp inited */
        if (!(adev->flags & AMD_IS_APU))
@@@ -3998,14 -3923,13 +3927,13 @@@ static int gfx_v8_0_rlc_resume(struct a
        /* disable CG */
        WREG32(mmRLC_CGCG_CGLS_CTRL, 0);
        if (adev->asic_type == CHIP_POLARIS11 ||
-               adev->asic_type == CHIP_POLARIS10)
+           adev->asic_type == CHIP_POLARIS10)
                WREG32(mmRLC_CGCG_CGLS_CTRL_3D, 0);
  
        /* disable PG */
        WREG32(mmRLC_PG_CNTL, 0);
  
        gfx_v8_0_rlc_reset(adev);
        gfx_v8_0_init_pg(adev);
  
        if (!adev->pp_enabled) {
@@@ -4300,12 -4224,10 +4228,10 @@@ static int gfx_v8_0_cp_gfx_resume(struc
        gfx_v8_0_cp_gfx_start(adev);
        ring->ready = true;
        r = amdgpu_ring_test_ring(ring);
-       if (r) {
+       if (r)
                ring->ready = false;
-               return r;
-       }
  
-       return 0;
+       return r;
  }
  
  static void gfx_v8_0_cp_compute_enable(struct amdgpu_device *adev, bool enable)
@@@ -4980,7 -4902,6 +4906,6 @@@ static int gfx_v8_0_hw_init(void *handl
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  
        gfx_v8_0_init_golden_registers(adev);
        gfx_v8_0_gpu_init(adev);
  
        r = gfx_v8_0_rlc_resume(adev);
                return r;
  
        r = gfx_v8_0_cp_resume(adev);
-       if (r)
-               return r;
  
        return r;
  }
@@@ -5037,25 -4956,22 +4960,22 @@@ static bool gfx_v8_0_is_idle(void *hand
  static int gfx_v8_0_wait_for_idle(void *handle)
  {
        unsigned i;
-       u32 tmp;
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  
        for (i = 0; i < adev->usec_timeout; i++) {
-               /* read MC_STATUS */
-               tmp = RREG32(mmGRBM_STATUS) & GRBM_STATUS__GUI_ACTIVE_MASK;
-               if (!REG_GET_FIELD(tmp, GRBM_STATUS, GUI_ACTIVE))
+               if (gfx_v8_0_is_idle(handle))
                        return 0;
                udelay(1);
        }
        return -ETIMEDOUT;
  }
  
- static int gfx_v8_0_soft_reset(void *handle)
+ static int gfx_v8_0_check_soft_reset(void *handle)
  {
+       struct amdgpu_device *adev = (struct amdgpu_device *)handle;
        u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
        u32 tmp;
-       struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  
        /* GRBM_STATUS */
        tmp = RREG32(mmGRBM_STATUS);
                   GRBM_STATUS__TA_BUSY_MASK | GRBM_STATUS__VGT_BUSY_MASK |
                   GRBM_STATUS__DB_BUSY_MASK | GRBM_STATUS__CB_BUSY_MASK |
                   GRBM_STATUS__GDS_BUSY_MASK | GRBM_STATUS__SPI_BUSY_MASK |
-                  GRBM_STATUS__IA_BUSY_MASK | GRBM_STATUS__IA_BUSY_NO_DMA_MASK)) {
+                  GRBM_STATUS__IA_BUSY_MASK | GRBM_STATUS__IA_BUSY_NO_DMA_MASK |
+                  GRBM_STATUS__CP_BUSY_MASK | GRBM_STATUS__CP_COHERENCY_BUSY_MASK)) {
                grbm_soft_reset = REG_SET_FIELD(grbm_soft_reset,
                                                GRBM_SOFT_RESET, SOFT_RESET_CP, 1);
                grbm_soft_reset = REG_SET_FIELD(grbm_soft_reset,
                                                GRBM_SOFT_RESET, SOFT_RESET_GFX, 1);
-       }
-       if (tmp & (GRBM_STATUS__CP_BUSY_MASK | GRBM_STATUS__CP_COHERENCY_BUSY_MASK)) {
-               grbm_soft_reset = REG_SET_FIELD(grbm_soft_reset,
-                                               GRBM_SOFT_RESET, SOFT_RESET_CP, 1);
                srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset,
                                                SRBM_SOFT_RESET, SOFT_RESET_GRBM, 1);
        }
                grbm_soft_reset = REG_SET_FIELD(grbm_soft_reset,
                                                GRBM_SOFT_RESET, SOFT_RESET_RLC, 1);
  
+       if (REG_GET_FIELD(tmp, GRBM_STATUS2, CPF_BUSY) ||
+           REG_GET_FIELD(tmp, GRBM_STATUS2, CPC_BUSY) ||
+           REG_GET_FIELD(tmp, GRBM_STATUS2, CPG_BUSY)) {
+               grbm_soft_reset = REG_SET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET,
+                                               SOFT_RESET_CPF, 1);
+               grbm_soft_reset = REG_SET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET,
+                                               SOFT_RESET_CPC, 1);
+               grbm_soft_reset = REG_SET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET,
+                                               SOFT_RESET_CPG, 1);
+               srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset, SRBM_SOFT_RESET,
+                                               SOFT_RESET_GRBM, 1);
+       }
        /* SRBM_STATUS */
        tmp = RREG32(mmSRBM_STATUS);
        if (REG_GET_FIELD(tmp, SRBM_STATUS, GRBM_RQ_PENDING))
                srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset,
                                                SRBM_SOFT_RESET, SOFT_RESET_GRBM, 1);
+       if (REG_GET_FIELD(tmp, SRBM_STATUS, SEM_BUSY))
+               srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset,
+                                               SRBM_SOFT_RESET, SOFT_RESET_SEM, 1);
  
        if (grbm_soft_reset || srbm_soft_reset) {
-               /* stop the rlc */
-               gfx_v8_0_rlc_stop(adev);
+               adev->ip_block_status[AMD_IP_BLOCK_TYPE_GFX].hang = true;
+               adev->gfx.grbm_soft_reset = grbm_soft_reset;
+               adev->gfx.srbm_soft_reset = srbm_soft_reset;
+       } else {
+               adev->ip_block_status[AMD_IP_BLOCK_TYPE_GFX].hang = false;
+               adev->gfx.grbm_soft_reset = 0;
+               adev->gfx.srbm_soft_reset = 0;
+       }
+       return 0;
+ }
  
+ static void gfx_v8_0_inactive_hqd(struct amdgpu_device *adev,
+                                 struct amdgpu_ring *ring)
+ {
+       int i;
+       vi_srbm_select(adev, ring->me, ring->pipe, ring->queue, 0);
+       if (RREG32(mmCP_HQD_ACTIVE) & CP_HQD_ACTIVE__ACTIVE_MASK) {
+               u32 tmp;
+               tmp = RREG32(mmCP_HQD_DEQUEUE_REQUEST);
+               tmp = REG_SET_FIELD(tmp, CP_HQD_DEQUEUE_REQUEST,
+                                   DEQUEUE_REQ, 2);
+               WREG32(mmCP_HQD_DEQUEUE_REQUEST, tmp);
+               for (i = 0; i < adev->usec_timeout; i++) {
+                       if (!(RREG32(mmCP_HQD_ACTIVE) & CP_HQD_ACTIVE__ACTIVE_MASK))
+                               break;
+                       udelay(1);
+               }
+       }
+ }
+ static int gfx_v8_0_pre_soft_reset(void *handle)
+ {
+       struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+       u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
+       if (!adev->ip_block_status[AMD_IP_BLOCK_TYPE_GFX].hang)
+               return 0;
+       grbm_soft_reset = adev->gfx.grbm_soft_reset;
+       srbm_soft_reset = adev->gfx.srbm_soft_reset;
+       /* stop the rlc */
+       gfx_v8_0_rlc_stop(adev);
+       if (REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CP) ||
+           REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_GFX))
                /* Disable GFX parsing/prefetching */
                gfx_v8_0_cp_gfx_enable(adev, false);
  
+       if (REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CP) ||
+           REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CPF) ||
+           REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CPC) ||
+           REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CPG)) {
+               int i;
+               for (i = 0; i < adev->gfx.num_compute_rings; i++) {
+                       struct amdgpu_ring *ring = &adev->gfx.compute_ring[i];
+                       gfx_v8_0_inactive_hqd(adev, ring);
+               }
                /* Disable MEC parsing/prefetching */
                gfx_v8_0_cp_compute_enable(adev, false);
+       }
  
-               if (grbm_soft_reset || srbm_soft_reset) {
-                       tmp = RREG32(mmGMCON_DEBUG);
-                       tmp = REG_SET_FIELD(tmp,
-                                           GMCON_DEBUG, GFX_STALL, 1);
-                       tmp = REG_SET_FIELD(tmp,
-                                           GMCON_DEBUG, GFX_CLEAR, 1);
-                       WREG32(mmGMCON_DEBUG, tmp);
+        return 0;
+ }
  
-                       udelay(50);
-               }
+ static int gfx_v8_0_soft_reset(void *handle)
+ {
+       struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+       u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
+       u32 tmp;
  
-               if (grbm_soft_reset) {
-                       tmp = RREG32(mmGRBM_SOFT_RESET);
-                       tmp |= grbm_soft_reset;
-                       dev_info(adev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
-                       WREG32(mmGRBM_SOFT_RESET, tmp);
-                       tmp = RREG32(mmGRBM_SOFT_RESET);
+       if (!adev->ip_block_status[AMD_IP_BLOCK_TYPE_GFX].hang)
+               return 0;
  
-                       udelay(50);
+       grbm_soft_reset = adev->gfx.grbm_soft_reset;
+       srbm_soft_reset = adev->gfx.srbm_soft_reset;
  
-                       tmp &= ~grbm_soft_reset;
-                       WREG32(mmGRBM_SOFT_RESET, tmp);
-                       tmp = RREG32(mmGRBM_SOFT_RESET);
-               }
+       if (grbm_soft_reset || srbm_soft_reset) {
+               tmp = RREG32(mmGMCON_DEBUG);
+               tmp = REG_SET_FIELD(tmp, GMCON_DEBUG, GFX_STALL, 1);
+               tmp = REG_SET_FIELD(tmp, GMCON_DEBUG, GFX_CLEAR, 1);
+               WREG32(mmGMCON_DEBUG, tmp);
+               udelay(50);
+       }
  
-               if (srbm_soft_reset) {
-                       tmp = RREG32(mmSRBM_SOFT_RESET);
-                       tmp |= srbm_soft_reset;
-                       dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
-                       WREG32(mmSRBM_SOFT_RESET, tmp);
-                       tmp = RREG32(mmSRBM_SOFT_RESET);
+       if (grbm_soft_reset) {
+               tmp = RREG32(mmGRBM_SOFT_RESET);
+               tmp |= grbm_soft_reset;
+               dev_info(adev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
+               WREG32(mmGRBM_SOFT_RESET, tmp);
+               tmp = RREG32(mmGRBM_SOFT_RESET);
  
-                       udelay(50);
+               udelay(50);
  
-                       tmp &= ~srbm_soft_reset;
-                       WREG32(mmSRBM_SOFT_RESET, tmp);
-                       tmp = RREG32(mmSRBM_SOFT_RESET);
-               }
+               tmp &= ~grbm_soft_reset;
+               WREG32(mmGRBM_SOFT_RESET, tmp);
+               tmp = RREG32(mmGRBM_SOFT_RESET);
+       }
  
-               if (grbm_soft_reset || srbm_soft_reset) {
-                       tmp = RREG32(mmGMCON_DEBUG);
-                       tmp = REG_SET_FIELD(tmp,
-                                           GMCON_DEBUG, GFX_STALL, 0);
-                       tmp = REG_SET_FIELD(tmp,
-                                           GMCON_DEBUG, GFX_CLEAR, 0);
-                       WREG32(mmGMCON_DEBUG, tmp);
-               }
+       if (srbm_soft_reset) {
+               tmp = RREG32(mmSRBM_SOFT_RESET);
+               tmp |= srbm_soft_reset;
+               dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
+               WREG32(mmSRBM_SOFT_RESET, tmp);
+               tmp = RREG32(mmSRBM_SOFT_RESET);
  
-               /* Wait a little for things to settle down */
                udelay(50);
+               tmp &= ~srbm_soft_reset;
+               WREG32(mmSRBM_SOFT_RESET, tmp);
+               tmp = RREG32(mmSRBM_SOFT_RESET);
        }
+       if (grbm_soft_reset || srbm_soft_reset) {
+               tmp = RREG32(mmGMCON_DEBUG);
+               tmp = REG_SET_FIELD(tmp, GMCON_DEBUG, GFX_STALL, 0);
+               tmp = REG_SET_FIELD(tmp, GMCON_DEBUG, GFX_CLEAR, 0);
+               WREG32(mmGMCON_DEBUG, tmp);
+       }
+       /* Wait a little for things to settle down */
+       udelay(50);
+       return 0;
+ }
+ static void gfx_v8_0_init_hqd(struct amdgpu_device *adev,
+                             struct amdgpu_ring *ring)
+ {
+       vi_srbm_select(adev, ring->me, ring->pipe, ring->queue, 0);
+       WREG32(mmCP_HQD_DEQUEUE_REQUEST, 0);
+       WREG32(mmCP_HQD_PQ_RPTR, 0);
+       WREG32(mmCP_HQD_PQ_WPTR, 0);
+       vi_srbm_select(adev, 0, 0, 0, 0);
+ }
+ static int gfx_v8_0_post_soft_reset(void *handle)
+ {
+       struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+       u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
+       if (!adev->ip_block_status[AMD_IP_BLOCK_TYPE_GFX].hang)
+               return 0;
+       grbm_soft_reset = adev->gfx.grbm_soft_reset;
+       srbm_soft_reset = adev->gfx.srbm_soft_reset;
+       if (REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CP) ||
+           REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_GFX))
+               gfx_v8_0_cp_gfx_resume(adev);
+       if (REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CP) ||
+           REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CPF) ||
+           REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CPC) ||
+           REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CPG)) {
+               int i;
+               for (i = 0; i < adev->gfx.num_compute_rings; i++) {
+                       struct amdgpu_ring *ring = &adev->gfx.compute_ring[i];
+                       gfx_v8_0_init_hqd(adev, ring);
+               }
+               gfx_v8_0_cp_compute_resume(adev);
+       }
+       gfx_v8_0_rlc_start(adev);
        return 0;
  }
  
@@@ -5269,8 -5307,6 +5311,6 @@@ static int gfx_v8_0_late_init(void *han
  static void gfx_v8_0_enable_gfx_static_mg_power_gating(struct amdgpu_device *adev,
                                                       bool enable)
  {
-       uint32_t data, temp;
        if (adev->asic_type == CHIP_POLARIS11)
                /* Send msg to SMU via Powerplay */
                amdgpu_set_powergating_state(adev,
                                             enable ?
                                             AMD_PG_STATE_GATE : AMD_PG_STATE_UNGATE);
  
-       temp = data = RREG32(mmRLC_PG_CNTL);
-       /* Enable static MGPG */
-       if (enable)
-               data |= RLC_PG_CNTL__STATIC_PER_CU_PG_ENABLE_MASK;
-       else
-               data &= ~RLC_PG_CNTL__STATIC_PER_CU_PG_ENABLE_MASK;
-       if (temp != data)
-               WREG32(mmRLC_PG_CNTL, data);
+       WREG32_FIELD(RLC_PG_CNTL, STATIC_PER_CU_PG_ENABLE, enable ? 1 : 0);
  }
  
  static void gfx_v8_0_enable_gfx_dynamic_mg_power_gating(struct amdgpu_device *adev,
                                                        bool enable)
  {
-       uint32_t data, temp;
-       temp = data = RREG32(mmRLC_PG_CNTL);
-       /* Enable dynamic MGPG */
-       if (enable)
-               data |= RLC_PG_CNTL__DYN_PER_CU_PG_ENABLE_MASK;
-       else
-               data &= ~RLC_PG_CNTL__DYN_PER_CU_PG_ENABLE_MASK;
-       if (temp != data)
-               WREG32(mmRLC_PG_CNTL, data);
+       WREG32_FIELD(RLC_PG_CNTL, DYN_PER_CU_PG_ENABLE, enable ? 1 : 0);
  }
  
  static void polaris11_enable_gfx_quick_mg_power_gating(struct amdgpu_device *adev,
                bool enable)
  {
-       uint32_t data, temp;
-       temp = data = RREG32(mmRLC_PG_CNTL);
-       /* Enable quick PG */
-       if (enable)
-               data |= RLC_PG_CNTL__QUICK_PG_ENABLE_MASK;
-       else
-               data &= ~RLC_PG_CNTL__QUICK_PG_ENABLE_MASK;
-       if (temp != data)
-               WREG32(mmRLC_PG_CNTL, data);
+       WREG32_FIELD(RLC_PG_CNTL, QUICK_PG_ENABLE, enable ? 1 : 0);
  }
  
  static void cz_enable_gfx_cg_power_gating(struct amdgpu_device *adev,
                                          bool enable)
  {
-       u32 data, orig;
-       orig = data = RREG32(mmRLC_PG_CNTL);
-       if (enable)
-               data |= RLC_PG_CNTL__GFX_POWER_GATING_ENABLE_MASK;
-       else
-               data &= ~RLC_PG_CNTL__GFX_POWER_GATING_ENABLE_MASK;
-       if (orig != data)
-               WREG32(mmRLC_PG_CNTL, data);
+       WREG32_FIELD(RLC_PG_CNTL, GFX_POWER_GATING_ENABLE, enable ? 1 : 0);
  }
  
  static void cz_enable_gfx_pipeline_power_gating(struct amdgpu_device *adev,
                                                bool enable)
  {
-       u32 data, orig;
-       orig = data = RREG32(mmRLC_PG_CNTL);
-       if (enable)
-               data |= RLC_PG_CNTL__GFX_PIPELINE_PG_ENABLE_MASK;
-       else
-               data &= ~RLC_PG_CNTL__GFX_PIPELINE_PG_ENABLE_MASK;
-       if (orig != data)
-               WREG32(mmRLC_PG_CNTL, data);
+       WREG32_FIELD(RLC_PG_CNTL, GFX_PIPELINE_PG_ENABLE, enable ? 1 : 0);
  
        /* Read any GFX register to wake up GFX. */
        if (!enable)
-               data = RREG32(mmDB_RENDER_CONTROL);
+               RREG32(mmDB_RENDER_CONTROL);
  }
  
  static void cz_update_gfx_cg_power_gating(struct amdgpu_device *adev,
@@@ -5430,15 -5418,15 +5422,15 @@@ static void gfx_v8_0_send_serdes_cmd(st
  
        data = RREG32(mmRLC_SERDES_WR_CTRL);
        if (adev->asic_type == CHIP_STONEY)
-                       data &= ~(RLC_SERDES_WR_CTRL__WRITE_COMMAND_MASK |
-                       RLC_SERDES_WR_CTRL__READ_COMMAND_MASK |
-                       RLC_SERDES_WR_CTRL__P1_SELECT_MASK |
-                       RLC_SERDES_WR_CTRL__P2_SELECT_MASK |
-                       RLC_SERDES_WR_CTRL__RDDATA_RESET_MASK |
-                       RLC_SERDES_WR_CTRL__POWER_DOWN_MASK |
-                       RLC_SERDES_WR_CTRL__POWER_UP_MASK |
-                       RLC_SERDES_WR_CTRL__SHORT_FORMAT_MASK |
-                       RLC_SERDES_WR_CTRL__SRBM_OVERRIDE_MASK);
+               data &= ~(RLC_SERDES_WR_CTRL__WRITE_COMMAND_MASK |
+                         RLC_SERDES_WR_CTRL__READ_COMMAND_MASK |
+                         RLC_SERDES_WR_CTRL__P1_SELECT_MASK |
+                         RLC_SERDES_WR_CTRL__P2_SELECT_MASK |
+                         RLC_SERDES_WR_CTRL__RDDATA_RESET_MASK |
+                         RLC_SERDES_WR_CTRL__POWER_DOWN_MASK |
+                         RLC_SERDES_WR_CTRL__POWER_UP_MASK |
+                         RLC_SERDES_WR_CTRL__SHORT_FORMAT_MASK |
+                         RLC_SERDES_WR_CTRL__SRBM_OVERRIDE_MASK);
        else
                data &= ~(RLC_SERDES_WR_CTRL__WRITE_COMMAND_MASK |
                          RLC_SERDES_WR_CTRL__READ_COMMAND_MASK |
  
  #define MSG_ENTER_RLC_SAFE_MODE     1
  #define MSG_EXIT_RLC_SAFE_MODE      0
- #define RLC_GPR_REG2__REQ_MASK           0x00000001
- #define RLC_GPR_REG2__MESSAGE__SHIFT     0x00000001
- #define RLC_GPR_REG2__MESSAGE_MASK       0x0000001e
+ #define RLC_GPR_REG2__REQ_MASK 0x00000001
+ #define RLC_GPR_REG2__REQ__SHIFT 0
+ #define RLC_GPR_REG2__MESSAGE__SHIFT 0x00000001
+ #define RLC_GPR_REG2__MESSAGE_MASK 0x0000001e
  
  static void cz_enter_rlc_safe_mode(struct amdgpu_device *adev)
  {
                }
  
                for (i = 0; i < adev->usec_timeout; i++) {
-                       if ((RREG32(mmRLC_GPR_REG2) & RLC_GPR_REG2__REQ_MASK) == 0)
+                       if (!REG_GET_FIELD(RREG32(mmRLC_GPR_REG2), RLC_GPR_REG2, REQ))
                                break;
                        udelay(1);
                }
@@@ -5522,7 -5510,7 +5514,7 @@@ static void cz_exit_rlc_safe_mode(struc
        }
  
        for (i = 0; i < adev->usec_timeout; i++) {
-               if ((RREG32(mmRLC_GPR_REG2) & RLC_GPR_REG2__REQ_MASK) == 0)
+               if (!REG_GET_FIELD(RREG32(mmRLC_GPR_REG2), RLC_GPR_REG2, REQ))
                        break;
                udelay(1);
        }
@@@ -5554,7 -5542,7 +5546,7 @@@ static void iceland_enter_rlc_safe_mode
                }
  
                for (i = 0; i < adev->usec_timeout; i++) {
-                       if ((RREG32(mmRLC_SAFE_MODE) & RLC_SAFE_MODE__CMD_MASK) == 0)
+                       if (!REG_GET_FIELD(RREG32(mmRLC_SAFE_MODE), RLC_SAFE_MODE, CMD))
                                break;
                        udelay(1);
                }
@@@ -5581,7 -5569,7 +5573,7 @@@ static void iceland_exit_rlc_safe_mode(
        }
  
        for (i = 0; i < adev->usec_timeout; i++) {
-               if ((RREG32(mmRLC_SAFE_MODE) & RLC_SAFE_MODE__CMD_MASK) == 0)
+               if (!REG_GET_FIELD(RREG32(mmRLC_SAFE_MODE), RLC_SAFE_MODE, CMD))
                        break;
                udelay(1);
        }
@@@ -5622,21 -5610,12 +5614,12 @@@ static void gfx_v8_0_update_medium_grai
        /* It is disabled by HW by default */
        if (enable && (adev->cg_flags & AMD_CG_SUPPORT_GFX_MGCG)) {
                if (adev->cg_flags & AMD_CG_SUPPORT_GFX_MGLS) {
-                       if (adev->cg_flags & AMD_CG_SUPPORT_GFX_RLC_LS) {
+                       if (adev->cg_flags & AMD_CG_SUPPORT_GFX_RLC_LS)
                                /* 1 - RLC memory Light sleep */
-                               temp = data = RREG32(mmRLC_MEM_SLP_CNTL);
-                               data |= RLC_MEM_SLP_CNTL__RLC_MEM_LS_EN_MASK;
-                               if (temp != data)
-                                       WREG32(mmRLC_MEM_SLP_CNTL, data);
-                       }
+                               WREG32_FIELD(RLC_MEM_SLP_CNTL, RLC_MEM_LS_EN, 1);
  
-                       if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CP_LS) {
-                               /* 2 - CP memory Light sleep */
-                               temp = data = RREG32(mmCP_MEM_SLP_CNTL);
-                               data |= CP_MEM_SLP_CNTL__CP_MEM_LS_EN_MASK;
-                               if (temp != data)
-                                       WREG32(mmCP_MEM_SLP_CNTL, data);
-                       }
+                       if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CP_LS)
+                               WREG32_FIELD(CP_MEM_SLP_CNTL, CP_MEM_LS_EN, 1);
                }
  
                /* 3 - RLC_CGTT_MGCG_OVERRIDE */
@@@ -5854,25 -5833,18 +5837,18 @@@ static int gfx_v8_0_set_clockgating_sta
  
  static u32 gfx_v8_0_ring_get_rptr_gfx(struct amdgpu_ring *ring)
  {
-       u32 rptr;
-       rptr = ring->adev->wb.wb[ring->rptr_offs];
-       return rptr;
+       return ring->adev->wb.wb[ring->rptr_offs];
  }
  
  static u32 gfx_v8_0_ring_get_wptr_gfx(struct amdgpu_ring *ring)
  {
        struct amdgpu_device *adev = ring->adev;
-       u32 wptr;
  
        if (ring->use_doorbell)
                /* XXX check if swapping is necessary on BE */
-               wptr = ring->adev->wb.wb[ring->wptr_offs];
+               return ring->adev->wb.wb[ring->wptr_offs];
        else
-               wptr = RREG32(mmCP_RB0_WPTR);
-       return wptr;
+               return RREG32(mmCP_RB0_WPTR);
  }
  
  static void gfx_v8_0_ring_set_wptr_gfx(struct amdgpu_ring *ring)
@@@ -5971,9 -5943,9 +5947,9 @@@ static void gfx_v8_0_ring_emit_ib_compu
        amdgpu_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
        amdgpu_ring_write(ring,
  #ifdef __BIG_ENDIAN
-                                         (2 << 0) |
+                               (2 << 0) |
  #endif
-                                         (ib->gpu_addr & 0xFFFFFFFC));
+                               (ib->gpu_addr & 0xFFFFFFFC));
        amdgpu_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFFFF);
        amdgpu_ring_write(ring, control);
  }
@@@ -6118,33 -6090,14 +6094,14 @@@ static void gfx_v8_0_ring_emit_fence_co
  static void gfx_v8_0_set_gfx_eop_interrupt_state(struct amdgpu_device *adev,
                                                 enum amdgpu_interrupt_state state)
  {
-       u32 cp_int_cntl;
-       switch (state) {
-       case AMDGPU_IRQ_STATE_DISABLE:
-               cp_int_cntl = RREG32(mmCP_INT_CNTL_RING0);
-               cp_int_cntl = REG_SET_FIELD(cp_int_cntl, CP_INT_CNTL_RING0,
-                                           TIME_STAMP_INT_ENABLE, 0);
-               WREG32(mmCP_INT_CNTL_RING0, cp_int_cntl);
-               break;
-       case AMDGPU_IRQ_STATE_ENABLE:
-               cp_int_cntl = RREG32(mmCP_INT_CNTL_RING0);
-               cp_int_cntl =
-                       REG_SET_FIELD(cp_int_cntl, CP_INT_CNTL_RING0,
-                                     TIME_STAMP_INT_ENABLE, 1);
-               WREG32(mmCP_INT_CNTL_RING0, cp_int_cntl);
-               break;
-       default:
-               break;
-       }
+       WREG32_FIELD(CP_INT_CNTL_RING0, TIME_STAMP_INT_ENABLE,
+                    state == AMDGPU_IRQ_STATE_DISABLE ? 0 : 1);
  }
  
  static void gfx_v8_0_set_compute_eop_interrupt_state(struct amdgpu_device *adev,
                                                     int me, int pipe,
                                                     enum amdgpu_interrupt_state state)
  {
-       u32 mec_int_cntl, mec_int_cntl_reg;
        /*
         * amdgpu controls only pipe 0 of MEC1. That's why this function only
         * handles the setting of interrupts for this specific pipe. All other
        if (me == 1) {
                switch (pipe) {
                case 0:
-                       mec_int_cntl_reg = mmCP_ME1_PIPE0_INT_CNTL;
                        break;
                default:
                        DRM_DEBUG("invalid pipe %d\n", pipe);
                return;
        }
  
-       switch (state) {
-       case AMDGPU_IRQ_STATE_DISABLE:
-               mec_int_cntl = RREG32(mec_int_cntl_reg);
-               mec_int_cntl = REG_SET_FIELD(mec_int_cntl, CP_ME1_PIPE0_INT_CNTL,
-                                            TIME_STAMP_INT_ENABLE, 0);
-               WREG32(mec_int_cntl_reg, mec_int_cntl);
-               break;
-       case AMDGPU_IRQ_STATE_ENABLE:
-               mec_int_cntl = RREG32(mec_int_cntl_reg);
-               mec_int_cntl = REG_SET_FIELD(mec_int_cntl, CP_ME1_PIPE0_INT_CNTL,
-                                            TIME_STAMP_INT_ENABLE, 1);
-               WREG32(mec_int_cntl_reg, mec_int_cntl);
-               break;
-       default:
-               break;
-       }
+       WREG32_FIELD(CP_ME1_PIPE0_INT_CNTL, TIME_STAMP_INT_ENABLE,
+                    state == AMDGPU_IRQ_STATE_DISABLE ? 0 : 1);
  }
  
  static int gfx_v8_0_set_priv_reg_fault_state(struct amdgpu_device *adev,
                                             unsigned type,
                                             enum amdgpu_interrupt_state state)
  {
-       u32 cp_int_cntl;
-       switch (state) {
-       case AMDGPU_IRQ_STATE_DISABLE:
-               cp_int_cntl = RREG32(mmCP_INT_CNTL_RING0);
-               cp_int_cntl = REG_SET_FIELD(cp_int_cntl, CP_INT_CNTL_RING0,
-                                           PRIV_REG_INT_ENABLE, 0);
-               WREG32(mmCP_INT_CNTL_RING0, cp_int_cntl);
-               break;
-       case AMDGPU_IRQ_STATE_ENABLE:
-               cp_int_cntl = RREG32(mmCP_INT_CNTL_RING0);
-               cp_int_cntl = REG_SET_FIELD(cp_int_cntl, CP_INT_CNTL_RING0,
-                                           PRIV_REG_INT_ENABLE, 1);
-               WREG32(mmCP_INT_CNTL_RING0, cp_int_cntl);
-               break;
-       default:
-               break;
-       }
+       WREG32_FIELD(CP_INT_CNTL_RING0, PRIV_REG_INT_ENABLE,
+                    state == AMDGPU_IRQ_STATE_DISABLE ? 0 : 1);
  
        return 0;
  }
@@@ -6215,24 -6137,8 +6141,8 @@@ static int gfx_v8_0_set_priv_inst_fault
                                              unsigned type,
                                              enum amdgpu_interrupt_state state)
  {
-       u32 cp_int_cntl;
-       switch (state) {
-       case AMDGPU_IRQ_STATE_DISABLE:
-               cp_int_cntl = RREG32(mmCP_INT_CNTL_RING0);
-               cp_int_cntl = REG_SET_FIELD(cp_int_cntl, CP_INT_CNTL_RING0,
-                                           PRIV_INSTR_INT_ENABLE, 0);
-               WREG32(mmCP_INT_CNTL_RING0, cp_int_cntl);
-               break;
-       case AMDGPU_IRQ_STATE_ENABLE:
-               cp_int_cntl = RREG32(mmCP_INT_CNTL_RING0);
-               cp_int_cntl = REG_SET_FIELD(cp_int_cntl, CP_INT_CNTL_RING0,
-                                           PRIV_INSTR_INT_ENABLE, 1);
-               WREG32(mmCP_INT_CNTL_RING0, cp_int_cntl);
-               break;
-       default:
-               break;
-       }
+       WREG32_FIELD(CP_INT_CNTL_RING0, PRIV_INSTR_INT_ENABLE,
+                    state == AMDGPU_IRQ_STATE_DISABLE ? 0 : 1);
  
        return 0;
  }
@@@ -6338,7 -6244,10 +6248,10 @@@ const struct amd_ip_funcs gfx_v8_0_ip_f
        .resume = gfx_v8_0_resume,
        .is_idle = gfx_v8_0_is_idle,
        .wait_for_idle = gfx_v8_0_wait_for_idle,
+       .check_soft_reset = gfx_v8_0_check_soft_reset,
+       .pre_soft_reset = gfx_v8_0_pre_soft_reset,
        .soft_reset = gfx_v8_0_soft_reset,
+       .post_soft_reset = gfx_v8_0_post_soft_reset,
        .set_clockgating_state = gfx_v8_0_set_clockgating_state,
        .set_powergating_state = gfx_v8_0_set_powergating_state,
  };
@@@ -6479,15 -6388,12 +6392,12 @@@ static u32 gfx_v8_0_get_cu_active_bitma
  {
        u32 data, mask;
  
-       data = RREG32(mmCC_GC_SHADER_ARRAY_CONFIG);
-       data |= RREG32(mmGC_USER_SHADER_ARRAY_CONFIG);
-       data &= CC_GC_SHADER_ARRAY_CONFIG__INACTIVE_CUS_MASK;
-       data >>= CC_GC_SHADER_ARRAY_CONFIG__INACTIVE_CUS__SHIFT;
+       data =  RREG32(mmCC_GC_SHADER_ARRAY_CONFIG) |
+               RREG32(mmGC_USER_SHADER_ARRAY_CONFIG);
  
        mask = gfx_v8_0_create_bitmask(adev->gfx.config.max_cu_per_sh);
  
-       return (~data) & mask;
+       return ~REG_GET_FIELD(data, CC_GC_SHADER_ARRAY_CONFIG, INACTIVE_CUS) & mask;
  }
  
  static void gfx_v8_0_get_cu_info(struct amdgpu_device *adev)
index 2aee2c6f3cd5b4719bdd97e38eeba43f6bb06718,8e7127f09ff6b6c5b8727fb8bb4271b7ac67604e..84c10d5117a902bac5ef863511e3f00a8cb14c89
@@@ -103,11 -103,6 +103,11 @@@ static const u32 stoney_mgcg_cgcg_init[
        mmMC_MEM_POWER_LS, 0xffffffff, 0x00000104
  };
  
 +static const u32 golden_settings_stoney_common[] =
 +{
 +      mmMC_HUB_RDREQ_UVD, MC_HUB_RDREQ_UVD__PRESCALE_MASK, 0x00000004,
 +      mmMC_RD_GRP_OTH, MC_RD_GRP_OTH__UVD_MASK, 0x00600000
 +};
  
  static void gmc_v8_0_init_golden_registers(struct amdgpu_device *adev)
  {
                amdgpu_program_register_sequence(adev,
                                                 stoney_mgcg_cgcg_init,
                                                 (const u32)ARRAY_SIZE(stoney_mgcg_cgcg_init));
 +              amdgpu_program_register_sequence(adev,
 +                                               golden_settings_stoney_common,
 +                                               (const u32)ARRAY_SIZE(golden_settings_stoney_common));
                break;
        default:
                break;
@@@ -261,7 -253,7 +261,7 @@@ static int gmc_v8_0_mc_load_microcode(s
        const struct mc_firmware_header_v1_0 *hdr;
        const __le32 *fw_data = NULL;
        const __le32 *io_mc_regs = NULL;
-       u32 running, blackout = 0;
+       u32 running;
        int i, ucode_size, regs_size;
  
        if (!adev->mc.fw)
        running = REG_GET_FIELD(RREG32(mmMC_SEQ_SUP_CNTL), MC_SEQ_SUP_CNTL, RUN);
  
        if (running == 0) {
-               if (running) {
-                       blackout = RREG32(mmMC_SHARED_BLACKOUT_CNTL);
-                       WREG32(mmMC_SHARED_BLACKOUT_CNTL, blackout | 1);
-               }
                /* reset the engine and set to writable */
                WREG32(mmMC_SEQ_SUP_CNTL, 0x00000008);
                WREG32(mmMC_SEQ_SUP_CNTL, 0x00000010);
                                break;
                        udelay(1);
                }
-               if (running)
-                       WREG32(mmMC_SHARED_BLACKOUT_CNTL, blackout);
        }
  
        return 0;
@@@ -477,7 -461,7 +469,7 @@@ static int gmc_v8_0_mc_init(struct amdg
         * size equal to the 1024 or vram, whichever is larger.
         */
        if (amdgpu_gart_size == -1)
-               adev->mc.gtt_size = max((1024ULL << 20), adev->mc.mc_vram_size);
+               adev->mc.gtt_size = amdgpu_ttm_get_gtt_mem_size(adev);
        else
                adev->mc.gtt_size = (uint64_t)amdgpu_gart_size << 20;
  
@@@ -957,6 -941,11 +949,11 @@@ static int gmc_v8_0_sw_init(void *handl
                return r;
        }
  
+       r = amdgpu_ttm_global_init(adev);
+       if (r) {
+               return r;
+       }
        r = gmc_v8_0_mc_init(adev);
        if (r)
                return r;
@@@ -1100,9 -1089,8 +1097,8 @@@ static int gmc_v8_0_wait_for_idle(void 
  
  }
  
- static int gmc_v8_0_soft_reset(void *handle)
+ static int gmc_v8_0_check_soft_reset(void *handle)
  {
-       struct amdgpu_mode_mc_save save;
        u32 srbm_soft_reset = 0;
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
        u32 tmp = RREG32(mmSRBM_STATUS);
                        srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset,
                                                        SRBM_SOFT_RESET, SOFT_RESET_MC, 1);
        }
        if (srbm_soft_reset) {
-               gmc_v8_0_mc_stop(adev, &save);
-               if (gmc_v8_0_wait_for_idle((void *)adev)) {
-                       dev_warn(adev->dev, "Wait for GMC idle timed out !\n");
-               }
+               adev->ip_block_status[AMD_IP_BLOCK_TYPE_GMC].hang = true;
+               adev->mc.srbm_soft_reset = srbm_soft_reset;
+       } else {
+               adev->ip_block_status[AMD_IP_BLOCK_TYPE_GMC].hang = false;
+               adev->mc.srbm_soft_reset = 0;
+       }
+       return 0;
+ }
  
+ static int gmc_v8_0_pre_soft_reset(void *handle)
+ {
+       struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+       if (!adev->ip_block_status[AMD_IP_BLOCK_TYPE_GMC].hang)
+               return 0;
+       gmc_v8_0_mc_stop(adev, &adev->mc.save);
+       if (gmc_v8_0_wait_for_idle(adev)) {
+               dev_warn(adev->dev, "Wait for GMC idle timed out !\n");
+       }
+       return 0;
+ }
+ static int gmc_v8_0_soft_reset(void *handle)
+ {
+       struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+       u32 srbm_soft_reset;
+       if (!adev->ip_block_status[AMD_IP_BLOCK_TYPE_GMC].hang)
+               return 0;
+       srbm_soft_reset = adev->mc.srbm_soft_reset;
+       if (srbm_soft_reset) {
+               u32 tmp;
  
                tmp = RREG32(mmSRBM_SOFT_RESET);
                tmp |= srbm_soft_reset;
  
                /* Wait a little for things to settle down */
                udelay(50);
-               gmc_v8_0_mc_resume(adev, &save);
-               udelay(50);
        }
  
        return 0;
  }
  
+ static int gmc_v8_0_post_soft_reset(void *handle)
+ {
+       struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+       if (!adev->ip_block_status[AMD_IP_BLOCK_TYPE_GMC].hang)
+               return 0;
+       gmc_v8_0_mc_resume(adev, &adev->mc.save);
+       return 0;
+ }
  static int gmc_v8_0_vm_fault_interrupt_state(struct amdgpu_device *adev,
                                             struct amdgpu_irq_src *src,
                                             unsigned type,
@@@ -1414,7 -1439,10 +1447,10 @@@ const struct amd_ip_funcs gmc_v8_0_ip_f
        .resume = gmc_v8_0_resume,
        .is_idle = gmc_v8_0_is_idle,
        .wait_for_idle = gmc_v8_0_wait_for_idle,
+       .check_soft_reset = gmc_v8_0_check_soft_reset,
+       .pre_soft_reset = gmc_v8_0_pre_soft_reset,
        .soft_reset = gmc_v8_0_soft_reset,
+       .post_soft_reset = gmc_v8_0_post_soft_reset,
        .set_clockgating_state = gmc_v8_0_set_clockgating_state,
        .set_powergating_state = gmc_v8_0_set_powergating_state,
  };
index 6483d680bbc831c4f5d5b0bf499e3ff04591d4a4,e93492b15c52259cffa9ef239448c0920a388643..9368e21f5695e7da81be41f837216729160bda46
@@@ -22,6 -22,7 +22,6 @@@
   */
  #include <linux/module.h>
  #include <linux/slab.h>
 -#include <linux/fb.h>
  #include "linux/delay.h"
  
  #include "hwmgr.h"
@@@ -618,9 -619,6 +618,6 @@@ static int fiji_hwmgr_backend_init(stru
        phm_cap_set(hwmgr->platform_descriptor.platformCaps,
                        PHM_PlatformCaps_TablelessHardwareInterface);
  
-       phm_cap_set(hwmgr->platform_descriptor.platformCaps,
-                       PHM_PlatformCaps_SclkDeepSleep);
        data->gpio_debug = 0;
  
        phm_cap_set(hwmgr->platform_descriptor.platformCaps,
index 783dcc3384f12349737c2cb06f7b3e4f36f55545,98e01d17635ad6c1beb279d989458cabcbb25d69..b6913229667217d4b4a530036c5330fd191c666f
@@@ -22,6 -22,7 +22,6 @@@
   */
  #include <linux/module.h>
  #include <linux/slab.h>
 -#include <linux/fb.h>
  #include <asm/div64.h>
  #include "linux/delay.h"
  #include "pp_acpi.h"
  #define PCIE_BUS_CLK                10000
  #define TCLK                        (PCIE_BUS_CLK / 10)
  
- static const uint16_t polaris10_clock_stretcher_lookup_table[2][4] =
- { {600, 1050, 3, 0}, {600, 1050, 6, 1} };
- /*  [FF, SS] type, [] 4 voltage ranges, and [Floor Freq, Boundary Freq, VID min , VID max] */
- static const uint32_t polaris10_clock_stretcher_ddt_table[2][4][4] =
- { { {265, 529, 120, 128}, {325, 650, 96, 119}, {430, 860, 32, 95}, {0, 0, 0, 31} },
-   { {275, 550, 104, 112}, {319, 638, 96, 103}, {360, 720, 64, 95}, {384, 768, 32, 63} } };
- /*  [Use_For_Low_freq] value, [0%, 5%, 10%, 7.14%, 14.28%, 20%] (coming from PWR_CKS_CNTL.stretch_amount reg spec) */
- static const uint8_t polaris10_clock_stretch_amount_conversion[2][6] =
- { {0, 1, 3, 2, 4, 5}, {0, 2, 4, 5, 6, 5} };
  /** Values for the CG_THERMAL_CTRL::DPM_EVENT_SRC field. */
  enum DPM_EVENT_SRC {
        DPM_EVENT_SRC_ANALOG = 0,
@@@ -2771,9 -2759,6 +2758,6 @@@ int polaris10_set_features_platform_cap
  {
        struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
  
-       phm_cap_set(hwmgr->platform_descriptor.platformCaps,
-                       PHM_PlatformCaps_SclkDeepSleep);
        phm_cap_set(hwmgr->platform_descriptor.platformCaps,
                PHM_PlatformCaps_DynamicPatchPowerState);
  
        phm_cap_set(hwmgr->platform_descriptor.platformCaps,
                                                PHM_PlatformCaps_TCPRamping);
  
-       if (hwmgr->powercontainment_enabled)
-               phm_cap_set(hwmgr->platform_descriptor.platformCaps,
-                           PHM_PlatformCaps_PowerContainment);
-       else
-               phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
-                           PHM_PlatformCaps_PowerContainment);
        phm_cap_set(hwmgr->platform_descriptor.platformCaps,
                                                        PHM_PlatformCaps_CAC);
  
@@@ -2904,8 -2882,8 +2881,8 @@@ static int polaris10_get_evv_voltages(s
                                continue;
                        }
  
-                       /* need to make sure vddc is less than 2v or else, it could burn the ASIC.
-                        * real voltage level in unit of 0.01mv */
+                       /* need to make sure vddc is less than 2V or else, it could burn the ASIC.
+                        * real voltage level in unit of 0.01mV */
                        PP_ASSERT_WITH_CODE((vddc < 200000 && vddc != 0),
                                        "Invalid VDDC value", result = -EINVAL;);
  
@@@ -3142,7 -3120,10 +3119,10 @@@ int polaris10_patch_voltage_workaround(
                        table_info->vddc_lookup_table;
        uint32_t i;
  
-       if (hwmgr->chip_id == CHIP_POLARIS10 && hwmgr->hw_revision == 0xC7) {
+       if (hwmgr->chip_id == CHIP_POLARIS10 && hwmgr->hw_revision == 0xC7 &&
+                       ((hwmgr->sub_sys_id == 0xb37 && hwmgr->sub_vendor_id == 0x1002) ||
+                   (hwmgr->sub_sys_id == 0x4a8 && hwmgr->sub_vendor_id == 0x1043) ||
+                   (hwmgr->sub_sys_id == 0x9480 && hwmgr->sub_vendor_id == 0x1682))) {
                if (lookup_table->entries[dep_mclk_table->entries[dep_mclk_table->count-1].vddInd].us_vdd >= 1000)
                        return 0;
  
index 7dc4afd19d26115b1ce27e7c1dbff8dd8637942b,e7c281f6dbc74565668c96dc89c582452d62f7da..7f9ba7f15e19ffe6b4d85ddf98ea35b8b0bcea27
@@@ -22,6 -22,7 +22,6 @@@
   */
  #include <linux/module.h>
  #include <linux/slab.h>
 -#include <linux/fb.h>
  #include "linux/delay.h"
  #include "pp_acpi.h"
  #include "hwmgr.h"
@@@ -301,6 -302,8 +301,8 @@@ void tonga_initialize_dpm_defaults(stru
                phm_cap_set(hwmgr->platform_descriptor.platformCaps,
                        PHM_PlatformCaps_DisableMemoryTransition);
  
+       tonga_initialize_power_tune_defaults(hwmgr);
        data->mclk_strobe_mode_threshold = 40000;
        data->mclk_stutter_mode_threshold = 30000;
        data->mclk_edc_enable_threshold = 40000;
@@@ -2478,7 -2481,7 +2480,7 @@@ static int tonga_populate_single_graphi
        graphic_level->VoltageDownHyst = 0;
        graphic_level->PowerThrottle = 0;
  
-       threshold = engine_clock * data->fast_watemark_threshold / 100;
+       threshold = engine_clock * data->fast_watermark_threshold / 100;
  /*
        *get the DAL clock. do it in funture.
        PECI_GetMinClockSettings(hwmgr->peci, &minClocks);
@@@ -2981,6 -2984,10 +2983,10 @@@ int tonga_init_smc_table(struct pp_hwmg
        PP_ASSERT_WITH_CODE(0 == result,
                "Failed to initialize Boot Level!", return result;);
  
+       result = tonga_populate_bapm_parameters_in_dpm_table(hwmgr);
+       PP_ASSERT_WITH_CODE(result == 0,
+                       "Failed to populate BAPM Parameters!", return result);
        if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
                        PHM_PlatformCaps_ClockStretcher)) {
                result = tonga_populate_clock_stretcher_data_table(hwmgr);
@@@ -4369,6 -4376,10 +4375,10 @@@ int tonga_enable_dpm_tasks(struct pp_hw
        PP_ASSERT_WITH_CODE((0 == tmp_result),
                "Failed to initialize ARB table index!", result = tmp_result);
  
+       tmp_result = tonga_populate_pm_fuses(hwmgr);
+       PP_ASSERT_WITH_CODE((tmp_result == 0),
+                       "Failed to populate PM fuses!", result = tmp_result);
        tmp_result = tonga_populate_initial_mc_reg_table(hwmgr);
        PP_ASSERT_WITH_CODE((0 == tmp_result),
                "Failed to populate initialize MC Reg table!", result = tmp_result);
        PP_ASSERT_WITH_CODE((0 == tmp_result),
                "Failed to start DPM!", result = tmp_result);
  
+       tmp_result = tonga_enable_smc_cac(hwmgr);
+       PP_ASSERT_WITH_CODE((tmp_result == 0),
+                       "Failed to enable SMC CAC!", result = tmp_result);
+       tmp_result = tonga_enable_power_containment(hwmgr);
+       PP_ASSERT_WITH_CODE((tmp_result == 0),
+                       "Failed to enable power containment!", result = tmp_result);
+       tmp_result = tonga_power_control_set_level(hwmgr);
+       PP_ASSERT_WITH_CODE((tmp_result == 0),
+                       "Failed to power control set level!", result = tmp_result);
        return result;
  }
  
index 7f2510524f09c9d487c5334f4f96c712463c001a,93b9821f7f24288747b95d7b0cc7dc489b8aa934..7b21281c4b78ca1b11b9f741360aebd9a00b94fe
  #include <drm/drm_modeset_lock.h>
  #include <drm/drm_atomic.h>
  #include <drm/drm_auth.h>
 +#include <drm/drm_framebuffer.h>
  
  #include "drm_crtc_internal.h"
  #include "drm_internal.h"
  
 -static struct drm_framebuffer *
 -internal_framebuffer_create(struct drm_device *dev,
 -                          const struct drm_mode_fb_cmd2 *r,
 -                          struct drm_file *file_priv);
 -
 -/* Avoid boilerplate.  I'm tired of typing. */
 -#define DRM_ENUM_NAME_FN(fnname, list)                                \
 -      const char *fnname(int val)                             \
 -      {                                                       \
 -              int i;                                          \
 -              for (i = 0; i < ARRAY_SIZE(list); i++) {        \
 -                      if (list[i].type == val)                \
 -                              return list[i].name;            \
 -              }                                               \
 -              return "(unknown)";                             \
 -      }
 -
  /*
   * Global properties
   */
 -static const struct drm_prop_enum_list drm_dpms_enum_list[] = {
 -      { DRM_MODE_DPMS_ON, "On" },
 -      { DRM_MODE_DPMS_STANDBY, "Standby" },
 -      { DRM_MODE_DPMS_SUSPEND, "Suspend" },
 -      { DRM_MODE_DPMS_OFF, "Off" }
 -};
 -
 -DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list)
 -
  static const struct drm_prop_enum_list drm_plane_type_enum_list[] = {
        { DRM_PLANE_TYPE_OVERLAY, "Overlay" },
        { DRM_PLANE_TYPE_PRIMARY, "Primary" },
        { DRM_PLANE_TYPE_CURSOR, "Cursor" },
  };
  
 -/*
 - * Optional properties
 - */
 -static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = {
 -      { DRM_MODE_SCALE_NONE, "None" },
 -      { DRM_MODE_SCALE_FULLSCREEN, "Full" },
 -      { DRM_MODE_SCALE_CENTER, "Center" },
 -      { DRM_MODE_SCALE_ASPECT, "Full aspect" },
 -};
 -
 -static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = {
 -      { DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" },
 -      { DRM_MODE_PICTURE_ASPECT_4_3, "4:3" },
 -      { DRM_MODE_PICTURE_ASPECT_16_9, "16:9" },
 -};
 -
 -/*
 - * Non-global properties, but "required" for certain connectors.
 - */
 -static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = {
 -      { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
 -      { DRM_MODE_SUBCONNECTOR_DVID,      "DVI-D"     }, /* DVI-I  */
 -      { DRM_MODE_SUBCONNECTOR_DVIA,      "DVI-A"     }, /* DVI-I  */
 -};
 -
 -DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list)
 -
 -static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = {
 -      { DRM_MODE_SUBCONNECTOR_Unknown,   "Unknown"   }, /* DVI-I and TV-out */
 -      { DRM_MODE_SUBCONNECTOR_DVID,      "DVI-D"     }, /* DVI-I  */
 -      { DRM_MODE_SUBCONNECTOR_DVIA,      "DVI-A"     }, /* DVI-I  */
 -};
 -
 -DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name,
 -               drm_dvi_i_subconnector_enum_list)
 -
 -static const struct drm_prop_enum_list drm_tv_select_enum_list[] = {
 -      { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
 -      { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
 -      { DRM_MODE_SUBCONNECTOR_SVIDEO,    "SVIDEO"    }, /* TV-out */
 -      { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
 -      { DRM_MODE_SUBCONNECTOR_SCART,     "SCART"     }, /* TV-out */
 -};
 -
 -DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list)
 -
 -static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = {
 -      { DRM_MODE_SUBCONNECTOR_Unknown,   "Unknown"   }, /* DVI-I and TV-out */
 -      { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
 -      { DRM_MODE_SUBCONNECTOR_SVIDEO,    "SVIDEO"    }, /* TV-out */
 -      { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
 -      { DRM_MODE_SUBCONNECTOR_SCART,     "SCART"     }, /* TV-out */
 -};
 -
 -DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name,
 -               drm_tv_subconnector_enum_list)
 -
 -static const struct drm_prop_enum_list drm_dirty_info_enum_list[] = {
 -      { DRM_MODE_DIRTY_OFF,      "Off"      },
 -      { DRM_MODE_DIRTY_ON,       "On"       },
 -      { DRM_MODE_DIRTY_ANNOTATE, "Annotate" },
 -};
 -
 -struct drm_conn_prop_enum_list {
 -      int type;
 -      const char *name;
 -      struct ida ida;
 -};
 -
 -/*
 - * Connector and encoder types.
 - */
 -static struct drm_conn_prop_enum_list drm_connector_enum_list[] = {
 -      { DRM_MODE_CONNECTOR_Unknown, "Unknown" },
 -      { DRM_MODE_CONNECTOR_VGA, "VGA" },
 -      { DRM_MODE_CONNECTOR_DVII, "DVI-I" },
 -      { DRM_MODE_CONNECTOR_DVID, "DVI-D" },
 -      { DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
 -      { DRM_MODE_CONNECTOR_Composite, "Composite" },
 -      { DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" },
 -      { DRM_MODE_CONNECTOR_LVDS, "LVDS" },
 -      { DRM_MODE_CONNECTOR_Component, "Component" },
 -      { DRM_MODE_CONNECTOR_9PinDIN, "DIN" },
 -      { DRM_MODE_CONNECTOR_DisplayPort, "DP" },
 -      { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
 -      { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
 -      { DRM_MODE_CONNECTOR_TV, "TV" },
 -      { DRM_MODE_CONNECTOR_eDP, "eDP" },
 -      { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" },
 -      { DRM_MODE_CONNECTOR_DSI, "DSI" },
 -      { DRM_MODE_CONNECTOR_DPI, "DPI" },
 -};
 -
  static const struct drm_prop_enum_list drm_encoder_enum_list[] = {
        { DRM_MODE_ENCODER_NONE, "None" },
        { DRM_MODE_ENCODER_DAC, "DAC" },
        { DRM_MODE_ENCODER_DPI, "DPI" },
  };
  
 -static const struct drm_prop_enum_list drm_subpixel_enum_list[] = {
 -      { SubPixelUnknown, "Unknown" },
 -      { SubPixelHorizontalRGB, "Horizontal RGB" },
 -      { SubPixelHorizontalBGR, "Horizontal BGR" },
 -      { SubPixelVerticalRGB, "Vertical RGB" },
 -      { SubPixelVerticalBGR, "Vertical BGR" },
 -      { SubPixelNone, "None" },
 -};
 -
 -void drm_connector_ida_init(void)
 -{
 -      int i;
 -
 -      for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
 -              ida_init(&drm_connector_enum_list[i].ida);
 -}
 -
 -void drm_connector_ida_destroy(void)
 -{
 -      int i;
 -
 -      for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
 -              ida_destroy(&drm_connector_enum_list[i].ida);
 -}
 -
 -/**
 - * drm_get_connector_status_name - return a string for connector status
 - * @status: connector status to compute name of
 - *
 - * In contrast to the other drm_get_*_name functions this one here returns a
 - * const pointer and hence is threadsafe.
 - */
 -const char *drm_get_connector_status_name(enum drm_connector_status status)
 -{
 -      if (status == connector_status_connected)
 -              return "connected";
 -      else if (status == connector_status_disconnected)
 -              return "disconnected";
 -      else
 -              return "unknown";
 -}
 -EXPORT_SYMBOL(drm_get_connector_status_name);
 -
 -/**
 - * drm_get_subpixel_order_name - return a string for a given subpixel enum
 - * @order: enum of subpixel_order
 - *
 - * Note you could abuse this and return something out of bounds, but that
 - * would be a caller error.  No unscrubbed user data should make it here.
 +/*
 + * Optional properties
   */
 -const char *drm_get_subpixel_order_name(enum subpixel_order order)
 -{
 -      return drm_subpixel_enum_list[order].name;
 -}
 -EXPORT_SYMBOL(drm_get_subpixel_order_name);
 -
  /*
   * Internal function to assign a slot in the object idr and optionally
   * register the object into the idr.
   */
 -static int drm_mode_object_get_reg(struct drm_device *dev,
 -                                 struct drm_mode_object *obj,
 -                                 uint32_t obj_type,
 -                                 bool register_obj,
 -                                 void (*obj_free_cb)(struct kref *kref))
 +int drm_mode_object_get_reg(struct drm_device *dev,
 +                          struct drm_mode_object *obj,
 +                          uint32_t obj_type,
 +                          bool register_obj,
 +                          void (*obj_free_cb)(struct kref *kref))
  {
        int ret;
  
@@@ -120,8 -291,8 +120,8 @@@ int drm_mode_object_get(struct drm_devi
        return drm_mode_object_get_reg(dev, obj, obj_type, true, NULL);
  }
  
 -static void drm_mode_object_register(struct drm_device *dev,
 -                                   struct drm_mode_object *obj)
 +void drm_mode_object_register(struct drm_device *dev,
 +                            struct drm_mode_object *obj)
  {
        mutex_lock(&dev->mode_config.idr_mutex);
        idr_replace(&dev->mode_config.crtc_idr, obj, obj->id);
@@@ -150,8 -321,8 +150,8 @@@ void drm_mode_object_unregister(struct 
        mutex_unlock(&dev->mode_config.idr_mutex);
  }
  
 -static struct drm_mode_object *_object_find(struct drm_device *dev,
 -              uint32_t id, uint32_t type)
 +struct drm_mode_object *__drm_mode_object_find(struct drm_device *dev,
 +                                             uint32_t id, uint32_t type)
  {
        struct drm_mode_object *obj = NULL;
  
@@@ -186,7 -357,7 +186,7 @@@ struct drm_mode_object *drm_mode_object
  {
        struct drm_mode_object *obj = NULL;
  
 -      obj = _object_find(dev, id, type);
 +      obj = __drm_mode_object_find(dev, id, type);
        return obj;
  }
  EXPORT_SYMBOL(drm_mode_object_find);
@@@ -270,6 -441,199 +270,6 @@@ out
  }
  EXPORT_SYMBOL(drm_crtc_force_disable_all);
  
 -static void drm_framebuffer_free(struct kref *kref)
 -{
 -      struct drm_framebuffer *fb =
 -                      container_of(kref, struct drm_framebuffer, base.refcount);
 -      struct drm_device *dev = fb->dev;
 -
 -      /*
 -       * The lookup idr holds a weak reference, which has not necessarily been
 -       * removed at this point. Check for that.
 -       */
 -      drm_mode_object_unregister(dev, &fb->base);
 -
 -      fb->funcs->destroy(fb);
 -}
 -
 -/**
 - * drm_framebuffer_init - initialize a framebuffer
 - * @dev: DRM device
 - * @fb: framebuffer to be initialized
 - * @funcs: ... with these functions
 - *
 - * Allocates an ID for the framebuffer's parent mode object, sets its mode
 - * functions & device file and adds it to the master fd list.
 - *
 - * IMPORTANT:
 - * This functions publishes the fb and makes it available for concurrent access
 - * by other users. Which means by this point the fb _must_ be fully set up -
 - * since all the fb attributes are invariant over its lifetime, no further
 - * locking but only correct reference counting is required.
 - *
 - * Returns:
 - * Zero on success, error code on failure.
 - */
 -int drm_framebuffer_init(struct drm_device *dev, struct drm_framebuffer *fb,
 -                       const struct drm_framebuffer_funcs *funcs)
 -{
 -      int ret;
 -
 -      INIT_LIST_HEAD(&fb->filp_head);
 -      fb->dev = dev;
 -      fb->funcs = funcs;
 -
 -      ret = drm_mode_object_get_reg(dev, &fb->base, DRM_MODE_OBJECT_FB,
 -                                    false, drm_framebuffer_free);
 -      if (ret)
 -              goto out;
 -
 -      mutex_lock(&dev->mode_config.fb_lock);
 -      dev->mode_config.num_fb++;
 -      list_add(&fb->head, &dev->mode_config.fb_list);
 -      mutex_unlock(&dev->mode_config.fb_lock);
 -
 -      drm_mode_object_register(dev, &fb->base);
 -out:
 -      return ret;
 -}
 -EXPORT_SYMBOL(drm_framebuffer_init);
 -
 -/**
 - * drm_framebuffer_lookup - look up a drm framebuffer and grab a reference
 - * @dev: drm device
 - * @id: id of the fb object
 - *
 - * If successful, this grabs an additional reference to the framebuffer -
 - * callers need to make sure to eventually unreference the returned framebuffer
 - * again, using @drm_framebuffer_unreference.
 - */
 -struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
 -                                             uint32_t id)
 -{
 -      struct drm_mode_object *obj;
 -      struct drm_framebuffer *fb = NULL;
 -
 -      obj = _object_find(dev, id, DRM_MODE_OBJECT_FB);
 -      if (obj)
 -              fb = obj_to_fb(obj);
 -      return fb;
 -}
 -EXPORT_SYMBOL(drm_framebuffer_lookup);
 -
 -/**
 - * drm_framebuffer_unregister_private - unregister a private fb from the lookup idr
 - * @fb: fb to unregister
 - *
 - * Drivers need to call this when cleaning up driver-private framebuffers, e.g.
 - * those used for fbdev. Note that the caller must hold a reference of it's own,
 - * i.e. the object may not be destroyed through this call (since it'll lead to a
 - * locking inversion).
 - */
 -void drm_framebuffer_unregister_private(struct drm_framebuffer *fb)
 -{
 -      struct drm_device *dev;
 -
 -      if (!fb)
 -              return;
 -
 -      dev = fb->dev;
 -
 -      /* Mark fb as reaped and drop idr ref. */
 -      drm_mode_object_unregister(dev, &fb->base);
 -}
 -EXPORT_SYMBOL(drm_framebuffer_unregister_private);
 -
 -/**
 - * drm_framebuffer_cleanup - remove a framebuffer object
 - * @fb: framebuffer to remove
 - *
 - * Cleanup framebuffer. This function is intended to be used from the drivers
 - * ->destroy callback. It can also be used to clean up driver private
 - * framebuffers embedded into a larger structure.
 - *
 - * Note that this function does not remove the fb from active usuage - if it is
 - * still used anywhere, hilarity can ensue since userspace could call getfb on
 - * the id and get back -EINVAL. Obviously no concern at driver unload time.
 - *
 - * Also, the framebuffer will not be removed from the lookup idr - for
 - * user-created framebuffers this will happen in in the rmfb ioctl. For
 - * driver-private objects (e.g. for fbdev) drivers need to explicitly call
 - * drm_framebuffer_unregister_private.
 - */
 -void drm_framebuffer_cleanup(struct drm_framebuffer *fb)
 -{
 -      struct drm_device *dev = fb->dev;
 -
 -      mutex_lock(&dev->mode_config.fb_lock);
 -      list_del(&fb->head);
 -      dev->mode_config.num_fb--;
 -      mutex_unlock(&dev->mode_config.fb_lock);
 -}
 -EXPORT_SYMBOL(drm_framebuffer_cleanup);
 -
 -/**
 - * drm_framebuffer_remove - remove and unreference a framebuffer object
 - * @fb: framebuffer to remove
 - *
 - * Scans all the CRTCs and planes in @dev's mode_config.  If they're
 - * using @fb, removes it, setting it to NULL. Then drops the reference to the
 - * passed-in framebuffer. Might take the modeset locks.
 - *
 - * Note that this function optimizes the cleanup away if the caller holds the
 - * last reference to the framebuffer. It is also guaranteed to not take the
 - * modeset locks in this case.
 - */
 -void drm_framebuffer_remove(struct drm_framebuffer *fb)
 -{
 -      struct drm_device *dev;
 -      struct drm_crtc *crtc;
 -      struct drm_plane *plane;
 -
 -      if (!fb)
 -              return;
 -
 -      dev = fb->dev;
 -
 -      WARN_ON(!list_empty(&fb->filp_head));
 -
 -      /*
 -       * drm ABI mandates that we remove any deleted framebuffers from active
 -       * useage. But since most sane clients only remove framebuffers they no
 -       * longer need, try to optimize this away.
 -       *
 -       * Since we're holding a reference ourselves, observing a refcount of 1
 -       * means that we're the last holder and can skip it. Also, the refcount
 -       * can never increase from 1 again, so we don't need any barriers or
 -       * locks.
 -       *
 -       * Note that userspace could try to race with use and instate a new
 -       * usage _after_ we've cleared all current ones. End result will be an
 -       * in-use fb with fb-id == 0. Userspace is allowed to shoot its own foot
 -       * in this manner.
 -       */
 -      if (drm_framebuffer_read_refcount(fb) > 1) {
 -              drm_modeset_lock_all(dev);
 -              /* remove from any CRTC */
 -              drm_for_each_crtc(crtc, dev) {
 -                      if (crtc->primary->fb == fb) {
 -                              /* should turn off the crtc */
 -                              if (drm_crtc_force_disable(crtc))
 -                                      DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc);
 -                      }
 -              }
 -
 -              drm_for_each_plane(plane, dev) {
 -                      if (plane->fb == fb)
 -                              drm_plane_force_disable(plane);
 -              }
 -              drm_modeset_unlock_all(dev);
 -      }
 -
 -      drm_framebuffer_unreference(fb);
 -}
 -EXPORT_SYMBOL(drm_framebuffer_remove);
 -
  DEFINE_WW_CLASS(crtc_ww_class);
  
  static unsigned int drm_num_crtcs(struct drm_device *dev)
@@@ -419,128 -783,482 +419,128 @@@ void drm_crtc_cleanup(struct drm_crtc *
  }
  EXPORT_SYMBOL(drm_crtc_cleanup);
  
 -/*
 - * drm_mode_remove - remove and free a mode
 - * @connector: connector list to modify
 - * @mode: mode to remove
 - *
 - * Remove @mode from @connector's mode list, then free it.
 - */
 -static void drm_mode_remove(struct drm_connector *connector,
 -                          struct drm_display_mode *mode)
 -{
 -      list_del(&mode->head);
 -      drm_mode_destroy(connector->dev, mode);
 -}
 -
 -/**
 - * drm_display_info_set_bus_formats - set the supported bus formats
 - * @info: display info to store bus formats in
 - * @formats: array containing the supported bus formats
 - * @num_formats: the number of entries in the fmts array
 - *
 - * Store the supported bus formats in display info structure.
 - * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for
 - * a full list of available formats.
 - */
 -int drm_display_info_set_bus_formats(struct drm_display_info *info,
 -                                   const u32 *formats,
 -                                   unsigned int num_formats)
 +static int drm_encoder_register_all(struct drm_device *dev)
  {
 -      u32 *fmts = NULL;
 -
 -      if (!formats && num_formats)
 -              return -EINVAL;
 +      struct drm_encoder *encoder;
 +      int ret = 0;
  
 -      if (formats && num_formats) {
 -              fmts = kmemdup(formats, sizeof(*formats) * num_formats,
 -                             GFP_KERNEL);
 -              if (!fmts)
 -                      return -ENOMEM;
 +      drm_for_each_encoder(encoder, dev) {
 +              if (encoder->funcs->late_register)
 +                      ret = encoder->funcs->late_register(encoder);
 +              if (ret)
 +                      return ret;
        }
  
 -      kfree(info->bus_formats);
 -      info->bus_formats = fmts;
 -      info->num_bus_formats = num_formats;
 -
        return 0;
  }
 -EXPORT_SYMBOL(drm_display_info_set_bus_formats);
  
 -/**
 - * drm_connector_get_cmdline_mode - reads the user's cmdline mode
 - * @connector: connector to quwery
 - *
 - * The kernel supports per-connector configration of its consoles through
 - * use of the video= parameter. This function parses that option and
 - * extracts the user's specified mode (or enable/disable status) for a
 - * particular connector. This is typically only used during the early fbdev
 - * setup.
 - */
 -static void drm_connector_get_cmdline_mode(struct drm_connector *connector)
 +static void drm_encoder_unregister_all(struct drm_device *dev)
  {
 -      struct drm_cmdline_mode *mode = &connector->cmdline_mode;
 -      char *option = NULL;
 -
 -      if (fb_get_options(connector->name, &option))
 -              return;
 -
 -      if (!drm_mode_parse_command_line_for_connector(option,
 -                                                     connector,
 -                                                     mode))
 -              return;
 -
 -      if (mode->force) {
 -              const char *s;
 -
 -              switch (mode->force) {
 -              case DRM_FORCE_OFF:
 -                      s = "OFF";
 -                      break;
 -              case DRM_FORCE_ON_DIGITAL:
 -                      s = "ON - dig";
 -                      break;
 -              default:
 -              case DRM_FORCE_ON:
 -                      s = "ON";
 -                      break;
 -              }
 +      struct drm_encoder *encoder;
  
 -              DRM_INFO("forcing %s connector %s\n", connector->name, s);
 -              connector->force = mode->force;
 +      drm_for_each_encoder(encoder, dev) {
 +              if (encoder->funcs->early_unregister)
 +                      encoder->funcs->early_unregister(encoder);
        }
 -
 -      DRM_DEBUG_KMS("cmdline mode for connector %s %dx%d@%dHz%s%s%s\n",
 -                    connector->name,
 -                    mode->xres, mode->yres,
 -                    mode->refresh_specified ? mode->refresh : 60,
 -                    mode->rb ? " reduced blanking" : "",
 -                    mode->margins ? " with margins" : "",
 -                    mode->interlace ?  " interlaced" : "");
 -}
 -
 -static void drm_connector_free(struct kref *kref)
 -{
 -      struct drm_connector *connector =
 -              container_of(kref, struct drm_connector, base.refcount);
 -      struct drm_device *dev = connector->dev;
 -
 -      drm_mode_object_unregister(dev, &connector->base);
 -      connector->funcs->destroy(connector);
  }
  
  /**
 - * drm_connector_init - Init a preallocated connector
 - * @dev: DRM device
 - * @connector: the connector to init
 - * @funcs: callbacks for this connector
 - * @connector_type: user visible type of the connector
 + * drm_encoder_init - Init a preallocated encoder
 + * @dev: drm device
 + * @encoder: the encoder to init
 + * @funcs: callbacks for this encoder
 + * @encoder_type: user visible type of the encoder
 + * @name: printf style format string for the encoder name, or NULL for default name
   *
 - * Initialises a preallocated connector. Connectors should be
 - * subclassed as part of driver connector objects.
 + * Initialises a preallocated encoder. Encoder should be
 + * subclassed as part of driver encoder objects.
   *
   * Returns:
   * Zero on success, error code on failure.
   */
 -int drm_connector_init(struct drm_device *dev,
 -                     struct drm_connector *connector,
 -                     const struct drm_connector_funcs *funcs,
 -                     int connector_type)
 +int drm_encoder_init(struct drm_device *dev,
 +                    struct drm_encoder *encoder,
 +                    const struct drm_encoder_funcs *funcs,
 +                    int encoder_type, const char *name, ...)
  {
 -      struct drm_mode_config *config = &dev->mode_config;
        int ret;
 -      struct ida *connector_ida =
 -              &drm_connector_enum_list[connector_type].ida;
  
        drm_modeset_lock_all(dev);
  
 -      ret = drm_mode_object_get_reg(dev, &connector->base,
 -                                    DRM_MODE_OBJECT_CONNECTOR,
 -                                    false, drm_connector_free);
 +      ret = drm_mode_object_get(dev, &encoder->base, DRM_MODE_OBJECT_ENCODER);
        if (ret)
                goto out_unlock;
  
 -      connector->base.properties = &connector->properties;
 -      connector->dev = dev;
 -      connector->funcs = funcs;
 +      encoder->dev = dev;
 +      encoder->encoder_type = encoder_type;
 +      encoder->funcs = funcs;
 +      if (name) {
 +              va_list ap;
  
 -      ret = ida_simple_get(&config->connector_ida, 0, 0, GFP_KERNEL);
 -      if (ret < 0)
 -              goto out_put;
 -      connector->index = ret;
 -      ret = 0;
 -
 -      connector->connector_type = connector_type;
 -      connector->connector_type_id =
 -              ida_simple_get(connector_ida, 1, 0, GFP_KERNEL);
 -      if (connector->connector_type_id < 0) {
 -              ret = connector->connector_type_id;
 -              goto out_put_id;
 +              va_start(ap, name);
 +              encoder->name = kvasprintf(GFP_KERNEL, name, ap);
 +              va_end(ap);
 +      } else {
 +              encoder->name = kasprintf(GFP_KERNEL, "%s-%d",
 +                                        drm_encoder_enum_list[encoder_type].name,
 +                                        encoder->base.id);
        }
 -      connector->name =
 -              kasprintf(GFP_KERNEL, "%s-%d",
 -                        drm_connector_enum_list[connector_type].name,
 -                        connector->connector_type_id);
 -      if (!connector->name) {
 +      if (!encoder->name) {
                ret = -ENOMEM;
 -              goto out_put_type_id;
 +              goto out_put;
        }
  
 -      INIT_LIST_HEAD(&connector->probed_modes);
 -      INIT_LIST_HEAD(&connector->modes);
 -      connector->edid_blob_ptr = NULL;
 -      connector->status = connector_status_unknown;
 -
 -      drm_connector_get_cmdline_mode(connector);
 -
 -      /* We should add connectors at the end to avoid upsetting the connector
 -       * index too much. */
 -      list_add_tail(&connector->head, &config->connector_list);
 -      config->num_connector++;
 -
 -      if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL)
 -              drm_object_attach_property(&connector->base,
 -                                            config->edid_property,
 -                                            0);
 -
 -      drm_object_attach_property(&connector->base,
 -                                    config->dpms_property, 0);
 -
 -      if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
 -              drm_object_attach_property(&connector->base, config->prop_crtc_id, 0);
 -      }
 +      list_add_tail(&encoder->head, &dev->mode_config.encoder_list);
 +      encoder->index = dev->mode_config.num_encoder++;
  
 -      connector->debugfs_entry = NULL;
 -out_put_type_id:
 -      if (ret)
 -              ida_remove(connector_ida, connector->connector_type_id);
 -out_put_id:
 -      if (ret)
 -              ida_remove(&config->connector_ida, connector->index);
  out_put:
        if (ret)
 -              drm_mode_object_unregister(dev, &connector->base);
 +              drm_mode_object_unregister(dev, &encoder->base);
  
  out_unlock:
        drm_modeset_unlock_all(dev);
  
        return ret;
  }
 -EXPORT_SYMBOL(drm_connector_init);
 +EXPORT_SYMBOL(drm_encoder_init);
  
  /**
 - * drm_connector_cleanup - cleans up an initialised connector
 - * @connector: connector to cleanup
 + * drm_encoder_cleanup - cleans up an initialised encoder
 + * @encoder: encoder to cleanup
   *
 - * Cleans up the connector but doesn't free the object.
 + * Cleans up the encoder but doesn't free the object.
   */
 -void drm_connector_cleanup(struct drm_connector *connector)
 +void drm_encoder_cleanup(struct drm_encoder *encoder)
  {
 -      struct drm_device *dev = connector->dev;
 -      struct drm_display_mode *mode, *t;
 +      struct drm_device *dev = encoder->dev;
  
 -      /* The connector should have been removed from userspace long before
 -       * it is finally destroyed.
 +      /* Note that the encoder_list is considered to be static; should we
 +       * remove the drm_encoder at runtime we would have to decrement all
 +       * the indices on the drm_encoder after us in the encoder_list.
         */
 -      if (WARN_ON(connector->registered))
 -              drm_connector_unregister(connector);
  
 -      if (connector->tile_group) {
 -              drm_mode_put_tile_group(dev, connector->tile_group);
 -              connector->tile_group = NULL;
 -      }
 +      drm_modeset_lock_all(dev);
 +      drm_mode_object_unregister(dev, &encoder->base);
 +      kfree(encoder->name);
 +      list_del(&encoder->head);
 +      dev->mode_config.num_encoder--;
 +      drm_modeset_unlock_all(dev);
  
 -      list_for_each_entry_safe(mode, t, &connector->probed_modes, head)
 -              drm_mode_remove(connector, mode);
 +      memset(encoder, 0, sizeof(*encoder));
 +}
 +EXPORT_SYMBOL(drm_encoder_cleanup);
  
 -      list_for_each_entry_safe(mode, t, &connector->modes, head)
 -              drm_mode_remove(connector, mode);
 +static unsigned int drm_num_planes(struct drm_device *dev)
 +{
 +      unsigned int num = 0;
 +      struct drm_plane *tmp;
  
 -      ida_remove(&drm_connector_enum_list[connector->connector_type].ida,
 -                 connector->connector_type_id);
 +      drm_for_each_plane(tmp, dev) {
 +              num++;
 +      }
  
 -      ida_remove(&dev->mode_config.connector_ida,
 -                 connector->index);
 -
 -      kfree(connector->display_info.bus_formats);
 -      drm_mode_object_unregister(dev, &connector->base);
 -      kfree(connector->name);
 -      connector->name = NULL;
 -      list_del(&connector->head);
 -      dev->mode_config.num_connector--;
 -
 -      WARN_ON(connector->state && !connector->funcs->atomic_destroy_state);
 -      if (connector->state && connector->funcs->atomic_destroy_state)
 -              connector->funcs->atomic_destroy_state(connector,
 -                                                     connector->state);
 -
 -      memset(connector, 0, sizeof(*connector));
 -}
 -EXPORT_SYMBOL(drm_connector_cleanup);
 -
 -/**
 - * drm_connector_register - register a connector
 - * @connector: the connector to register
 - *
 - * Register userspace interfaces for a connector
 - *
 - * Returns:
 - * Zero on success, error code on failure.
 - */
 -int drm_connector_register(struct drm_connector *connector)
 -{
 -      int ret;
 -
 -      if (connector->registered)
 -              return 0;
 -
 -      ret = drm_sysfs_connector_add(connector);
 -      if (ret)
 -              return ret;
 -
 -      ret = drm_debugfs_connector_add(connector);
 -      if (ret) {
 -              goto err_sysfs;
 -      }
 -
 -      if (connector->funcs->late_register) {
 -              ret = connector->funcs->late_register(connector);
 -              if (ret)
 -                      goto err_debugfs;
 -      }
 -
 -      drm_mode_object_register(connector->dev, &connector->base);
 -
 -      connector->registered = true;
 -      return 0;
 -
 -err_debugfs:
 -      drm_debugfs_connector_remove(connector);
 -err_sysfs:
 -      drm_sysfs_connector_remove(connector);
 -      return ret;
 -}
 -EXPORT_SYMBOL(drm_connector_register);
 -
 -/**
 - * drm_connector_unregister - unregister a connector
 - * @connector: the connector to unregister
 - *
 - * Unregister userspace interfaces for a connector
 - */
 -void drm_connector_unregister(struct drm_connector *connector)
 -{
 -      if (!connector->registered)
 -              return;
 -
 -      if (connector->funcs->early_unregister)
 -              connector->funcs->early_unregister(connector);
 -
 -      drm_sysfs_connector_remove(connector);
 -      drm_debugfs_connector_remove(connector);
 -
 -      connector->registered = false;
 -}
 -EXPORT_SYMBOL(drm_connector_unregister);
 -
 -static void drm_connector_unregister_all(struct drm_device *dev)
 -{
 -      struct drm_connector *connector;
 -
 -      /* FIXME: taking the mode config mutex ends up in a clash with sysfs */
 -      list_for_each_entry(connector, &dev->mode_config.connector_list, head)
 -              drm_connector_unregister(connector);
 -}
 -
 -static int drm_connector_register_all(struct drm_device *dev)
 -{
 -      struct drm_connector *connector;
 -      int ret;
 -
 -      /* FIXME: taking the mode config mutex ends up in a clash with
 -       * fbcon/backlight registration */
 -      list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
 -              ret = drm_connector_register(connector);
 -              if (ret)
 -                      goto err;
 -      }
 -
 -      return 0;
 -
 -err:
 -      mutex_unlock(&dev->mode_config.mutex);
 -      drm_connector_unregister_all(dev);
 -      return ret;
 -}
 -
 -static int drm_encoder_register_all(struct drm_device *dev)
 -{
 -      struct drm_encoder *encoder;
 -      int ret = 0;
 -
 -      drm_for_each_encoder(encoder, dev) {
 -              if (encoder->funcs->late_register)
 -                      ret = encoder->funcs->late_register(encoder);
 -              if (ret)
 -                      return ret;
 -      }
 -
 -      return 0;
 -}
 -
 -static void drm_encoder_unregister_all(struct drm_device *dev)
 -{
 -      struct drm_encoder *encoder;
 -
 -      drm_for_each_encoder(encoder, dev) {
 -              if (encoder->funcs->early_unregister)
 -                      encoder->funcs->early_unregister(encoder);
 -      }
 -}
 -
 -/**
 - * drm_encoder_init - Init a preallocated encoder
 - * @dev: drm device
 - * @encoder: the encoder to init
 - * @funcs: callbacks for this encoder
 - * @encoder_type: user visible type of the encoder
 - * @name: printf style format string for the encoder name, or NULL for default name
 - *
 - * Initialises a preallocated encoder. Encoder should be
 - * subclassed as part of driver encoder objects.
 - *
 - * Returns:
 - * Zero on success, error code on failure.
 - */
 -int drm_encoder_init(struct drm_device *dev,
 -                    struct drm_encoder *encoder,
 -                    const struct drm_encoder_funcs *funcs,
 -                    int encoder_type, const char *name, ...)
 -{
 -      int ret;
 -
 -      drm_modeset_lock_all(dev);
 -
 -      ret = drm_mode_object_get(dev, &encoder->base, DRM_MODE_OBJECT_ENCODER);
 -      if (ret)
 -              goto out_unlock;
 -
 -      encoder->dev = dev;
 -      encoder->encoder_type = encoder_type;
 -      encoder->funcs = funcs;
 -      if (name) {
 -              va_list ap;
 -
 -              va_start(ap, name);
 -              encoder->name = kvasprintf(GFP_KERNEL, name, ap);
 -              va_end(ap);
 -      } else {
 -              encoder->name = kasprintf(GFP_KERNEL, "%s-%d",
 -                                        drm_encoder_enum_list[encoder_type].name,
 -                                        encoder->base.id);
 -      }
 -      if (!encoder->name) {
 -              ret = -ENOMEM;
 -              goto out_put;
 -      }
 -
 -      list_add_tail(&encoder->head, &dev->mode_config.encoder_list);
 -      encoder->index = dev->mode_config.num_encoder++;
 -
 -out_put:
 -      if (ret)
 -              drm_mode_object_unregister(dev, &encoder->base);
 -
 -out_unlock:
 -      drm_modeset_unlock_all(dev);
 -
 -      return ret;
 -}
 -EXPORT_SYMBOL(drm_encoder_init);
 -
 -/**
 - * drm_encoder_cleanup - cleans up an initialised encoder
 - * @encoder: encoder to cleanup
 - *
 - * Cleans up the encoder but doesn't free the object.
 - */
 -void drm_encoder_cleanup(struct drm_encoder *encoder)
 -{
 -      struct drm_device *dev = encoder->dev;
 -
 -      /* Note that the encoder_list is considered to be static; should we
 -       * remove the drm_encoder at runtime we would have to decrement all
 -       * the indices on the drm_encoder after us in the encoder_list.
 -       */
 -
 -      drm_modeset_lock_all(dev);
 -      drm_mode_object_unregister(dev, &encoder->base);
 -      kfree(encoder->name);
 -      list_del(&encoder->head);
 -      dev->mode_config.num_encoder--;
 -      drm_modeset_unlock_all(dev);
 -
 -      memset(encoder, 0, sizeof(*encoder));
 -}
 -EXPORT_SYMBOL(drm_encoder_cleanup);
 -
 -static unsigned int drm_num_planes(struct drm_device *dev)
 -{
 -      unsigned int num = 0;
 -      struct drm_plane *tmp;
 -
 -      drm_for_each_plane(tmp, dev) {
 -              num++;
 -      }
 -
 -      return num;
 -}
 +      return num;
 +}
  
  /**
   * drm_universal_plane_init - Initialize a new universal plane object
   * @plane: plane object to init
   * @possible_crtcs: bitmask of possible CRTCs
   * @funcs: callbacks for the new plane
 - * @formats: array of supported formats (%DRM_FORMAT_*)
 + * @formats: array of supported formats (DRM_FORMAT\_\*)
   * @format_count: number of elements in @formats
   * @type: type of plane (overlay, primary, cursor)
   * @name: printf style format string for the plane name, or NULL for default name
@@@ -663,7 -1381,7 +663,7 @@@ static void drm_plane_unregister_all(st
   * @plane: plane object to init
   * @possible_crtcs: bitmask of possible CRTCs
   * @funcs: callbacks for the new plane
 - * @formats: array of supported formats (%DRM_FORMAT_*)
 + * @formats: array of supported formats (DRM_FORMAT\_\*)
   * @format_count: number of elements in @formats
   * @is_primary: plane type (primary vs overlay)
   *
@@@ -822,11 -1540,39 +822,11 @@@ void drm_modeset_unregister_all(struct 
  static int drm_mode_create_standard_properties(struct drm_device *dev)
  {
        struct drm_property *prop;
 +      int ret;
  
 -      /*
 -       * Standard properties (apply to all connectors)
 -       */
 -      prop = drm_property_create(dev, DRM_MODE_PROP_BLOB |
 -                                 DRM_MODE_PROP_IMMUTABLE,
 -                                 "EDID", 0);
 -      if (!prop)
 -              return -ENOMEM;
 -      dev->mode_config.edid_property = prop;
 -
 -      prop = drm_property_create_enum(dev, 0,
 -                                 "DPMS", drm_dpms_enum_list,
 -                                 ARRAY_SIZE(drm_dpms_enum_list));
 -      if (!prop)
 -              return -ENOMEM;
 -      dev->mode_config.dpms_property = prop;
 -
 -      prop = drm_property_create(dev,
 -                                 DRM_MODE_PROP_BLOB |
 -                                 DRM_MODE_PROP_IMMUTABLE,
 -                                 "PATH", 0);
 -      if (!prop)
 -              return -ENOMEM;
 -      dev->mode_config.path_property = prop;
 -
 -      prop = drm_property_create(dev,
 -                                 DRM_MODE_PROP_BLOB |
 -                                 DRM_MODE_PROP_IMMUTABLE,
 -                                 "TILE", 0);
 -      if (!prop)
 -              return -ENOMEM;
 -      dev->mode_config.tile_property = prop;
 +      ret = drm_connector_create_standard_properties(dev);
 +      if (ret)
 +              return ret;
  
        prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
                                        "type", drm_plane_type_enum_list,
  }
  
  /**
 - * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
 - * @dev: DRM device
 + * drm_mode_getresources - get graphics configuration
 + * @dev: drm device for the ioctl
 + * @data: data pointer for the ioctl
 + * @file_priv: drm file for the ioctl call
   *
 - * Called by a driver the first time a DVI-I connector is made.
 - */
 -int drm_mode_create_dvi_i_properties(struct drm_device *dev)
 -{
 -      struct drm_property *dvi_i_selector;
 -      struct drm_property *dvi_i_subconnector;
 -
 -      if (dev->mode_config.dvi_i_select_subconnector_property)
 -              return 0;
 -
 -      dvi_i_selector =
 -              drm_property_create_enum(dev, 0,
 -                                  "select subconnector",
 -                                  drm_dvi_i_select_enum_list,
 -                                  ARRAY_SIZE(drm_dvi_i_select_enum_list));
 -      dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector;
 -
 -      dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
 -                                  "subconnector",
 -                                  drm_dvi_i_subconnector_enum_list,
 -                                  ARRAY_SIZE(drm_dvi_i_subconnector_enum_list));
 -      dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector;
 -
 -      return 0;
 -}
 -EXPORT_SYMBOL(drm_mode_create_dvi_i_properties);
 -
 -/**
 - * drm_create_tv_properties - create TV specific connector properties
 - * @dev: DRM device
 - * @num_modes: number of different TV formats (modes) supported
 - * @modes: array of pointers to strings containing name of each format
 + * Construct a set of configuration description structures and return
 + * them to the user, including CRTC, connector and framebuffer configuration.
 + *
 + * Called by the user via ioctl.
   *
 - * Called by a driver's TV initialization routine, this function creates
 - * the TV specific connector properties for a given device.  Caller is
 - * responsible for allocating a list of format names and passing them to
 - * this routine.
 + * Returns:
 + * Zero on success, negative errno on failure.
   */
 -int drm_mode_create_tv_properties(struct drm_device *dev,
 -                                unsigned int num_modes,
 -                                const char * const modes[])
 +int drm_mode_getresources(struct drm_device *dev, void *data,
 +                        struct drm_file *file_priv)
  {
 -      struct drm_property *tv_selector;
 -      struct drm_property *tv_subconnector;
 -      unsigned int i;
 +      struct drm_mode_card_res *card_res = data;
 +      struct list_head *lh;
 +      struct drm_framebuffer *fb;
 +      struct drm_connector *connector;
 +      struct drm_crtc *crtc;
 +      struct drm_encoder *encoder;
 +      int ret = 0;
 +      int connector_count = 0;
 +      int crtc_count = 0;
 +      int fb_count = 0;
 +      int encoder_count = 0;
 +      int copied = 0;
 +      uint32_t __user *fb_id;
 +      uint32_t __user *crtc_id;
 +      uint32_t __user *connector_id;
 +      uint32_t __user *encoder_id;
  
 -      if (dev->mode_config.tv_select_subconnector_property)
 -              return 0;
 +      if (!drm_core_check_feature(dev, DRIVER_MODESET))
 +              return -EINVAL;
  
 -      /*
 -       * Basic connector properties
 -       */
 -      tv_selector = drm_property_create_enum(dev, 0,
 -                                        "select subconnector",
 -                                        drm_tv_select_enum_list,
 -                                        ARRAY_SIZE(drm_tv_select_enum_list));
 -      if (!tv_selector)
 -              goto nomem;
 -
 -      dev->mode_config.tv_select_subconnector_property = tv_selector;
 -
 -      tv_subconnector =
 -              drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
 -                                  "subconnector",
 -                                  drm_tv_subconnector_enum_list,
 -                                  ARRAY_SIZE(drm_tv_subconnector_enum_list));
 -      if (!tv_subconnector)
 -              goto nomem;
 -      dev->mode_config.tv_subconnector_property = tv_subconnector;
  
 +      mutex_lock(&file_priv->fbs_lock);
        /*
 -       * Other, TV specific properties: margins & TV modes.
 +       * For the non-control nodes we need to limit the list of resources
 +       * by IDs in the group list for this node
         */
 -      dev->mode_config.tv_left_margin_property =
 -              drm_property_create_range(dev, 0, "left margin", 0, 100);
 -      if (!dev->mode_config.tv_left_margin_property)
 -              goto nomem;
 -
 -      dev->mode_config.tv_right_margin_property =
 -              drm_property_create_range(dev, 0, "right margin", 0, 100);
 -      if (!dev->mode_config.tv_right_margin_property)
 -              goto nomem;
 -
 -      dev->mode_config.tv_top_margin_property =
 -              drm_property_create_range(dev, 0, "top margin", 0, 100);
 -      if (!dev->mode_config.tv_top_margin_property)
 -              goto nomem;
 -
 -      dev->mode_config.tv_bottom_margin_property =
 -              drm_property_create_range(dev, 0, "bottom margin", 0, 100);
 -      if (!dev->mode_config.tv_bottom_margin_property)
 -              goto nomem;
 -
 -      dev->mode_config.tv_mode_property =
 -              drm_property_create(dev, DRM_MODE_PROP_ENUM,
 -                                  "mode", num_modes);
 -      if (!dev->mode_config.tv_mode_property)
 -              goto nomem;
 -
 -      for (i = 0; i < num_modes; i++)
 -              drm_property_add_enum(dev->mode_config.tv_mode_property, i,
 -                                    i, modes[i]);
 -
 -      dev->mode_config.tv_brightness_property =
 -              drm_property_create_range(dev, 0, "brightness", 0, 100);
 -      if (!dev->mode_config.tv_brightness_property)
 -              goto nomem;
 -
 -      dev->mode_config.tv_contrast_property =
 -              drm_property_create_range(dev, 0, "contrast", 0, 100);
 -      if (!dev->mode_config.tv_contrast_property)
 -              goto nomem;
 -
 -      dev->mode_config.tv_flicker_reduction_property =
 -              drm_property_create_range(dev, 0, "flicker reduction", 0, 100);
 -      if (!dev->mode_config.tv_flicker_reduction_property)
 -              goto nomem;
 -
 -      dev->mode_config.tv_overscan_property =
 -              drm_property_create_range(dev, 0, "overscan", 0, 100);
 -      if (!dev->mode_config.tv_overscan_property)
 -              goto nomem;
 -
 -      dev->mode_config.tv_saturation_property =
 -              drm_property_create_range(dev, 0, "saturation", 0, 100);
 -      if (!dev->mode_config.tv_saturation_property)
 -              goto nomem;
 -
 -      dev->mode_config.tv_hue_property =
 -              drm_property_create_range(dev, 0, "hue", 0, 100);
 -      if (!dev->mode_config.tv_hue_property)
 -              goto nomem;
 -
 -      return 0;
 -nomem:
 -      return -ENOMEM;
 -}
 -EXPORT_SYMBOL(drm_mode_create_tv_properties);
 -
 -/**
 - * drm_mode_create_scaling_mode_property - create scaling mode property
 - * @dev: DRM device
 - *
 - * Called by a driver the first time it's needed, must be attached to desired
 - * connectors.
 - */
 -int drm_mode_create_scaling_mode_property(struct drm_device *dev)
 -{
 -      struct drm_property *scaling_mode;
 -
 -      if (dev->mode_config.scaling_mode_property)
 -              return 0;
 -
 -      scaling_mode =
 -              drm_property_create_enum(dev, 0, "scaling mode",
 -                              drm_scaling_mode_enum_list,
 -                                  ARRAY_SIZE(drm_scaling_mode_enum_list));
 -
 -      dev->mode_config.scaling_mode_property = scaling_mode;
 -
 -      return 0;
 -}
 -EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);
 -
 -/**
 - * drm_mode_create_aspect_ratio_property - create aspect ratio property
 - * @dev: DRM device
 - *
 - * Called by a driver the first time it's needed, must be attached to desired
 - * connectors.
 - *
 - * Returns:
 - * Zero on success, negative errno on failure.
 - */
 -int drm_mode_create_aspect_ratio_property(struct drm_device *dev)
 -{
 -      if (dev->mode_config.aspect_ratio_property)
 -              return 0;
 -
 -      dev->mode_config.aspect_ratio_property =
 -              drm_property_create_enum(dev, 0, "aspect ratio",
 -                              drm_aspect_ratio_enum_list,
 -                              ARRAY_SIZE(drm_aspect_ratio_enum_list));
 -
 -      if (dev->mode_config.aspect_ratio_property == NULL)
 -              return -ENOMEM;
 -
 -      return 0;
 -}
 -EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property);
 -
 -/**
 - * drm_mode_create_dirty_property - create dirty property
 - * @dev: DRM device
 - *
 - * Called by a driver the first time it's needed, must be attached to desired
 - * connectors.
 - */
 -int drm_mode_create_dirty_info_property(struct drm_device *dev)
 -{
 -      struct drm_property *dirty_info;
 -
 -      if (dev->mode_config.dirty_info_property)
 -              return 0;
 -
 -      dirty_info =
 -              drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
 -                                  "dirty",
 -                                  drm_dirty_info_enum_list,
 -                                  ARRAY_SIZE(drm_dirty_info_enum_list));
 -      dev->mode_config.dirty_info_property = dirty_info;
 -
 -      return 0;
 -}
 -EXPORT_SYMBOL(drm_mode_create_dirty_info_property);
 -
 -/**
 - * drm_mode_create_suggested_offset_properties - create suggests offset properties
 - * @dev: DRM device
 - *
 - * Create the the suggested x/y offset property for connectors.
 - */
 -int drm_mode_create_suggested_offset_properties(struct drm_device *dev)
 -{
 -      if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property)
 -              return 0;
 -
 -      dev->mode_config.suggested_x_property =
 -              drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff);
 -
 -      dev->mode_config.suggested_y_property =
 -              drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff);
 -
 -      if (dev->mode_config.suggested_x_property == NULL ||
 -          dev->mode_config.suggested_y_property == NULL)
 -              return -ENOMEM;
 -      return 0;
 -}
 -EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties);
 -
 -/**
 - * drm_mode_getresources - get graphics configuration
 - * @dev: drm device for the ioctl
 - * @data: data pointer for the ioctl
 - * @file_priv: drm file for the ioctl call
 - *
 - * Construct a set of configuration description structures and return
 - * them to the user, including CRTC, connector and framebuffer configuration.
 - *
 - * Called by the user via ioctl.
 - *
 - * Returns:
 - * Zero on success, negative errno on failure.
 - */
 -int drm_mode_getresources(struct drm_device *dev, void *data,
 -                        struct drm_file *file_priv)
 -{
 -      struct drm_mode_card_res *card_res = data;
 -      struct list_head *lh;
 -      struct drm_framebuffer *fb;
 -      struct drm_connector *connector;
 -      struct drm_crtc *crtc;
 -      struct drm_encoder *encoder;
 -      int ret = 0;
 -      int connector_count = 0;
 -      int crtc_count = 0;
 -      int fb_count = 0;
 -      int encoder_count = 0;
 -      int copied = 0;
 -      uint32_t __user *fb_id;
 -      uint32_t __user *crtc_id;
 -      uint32_t __user *connector_id;
 -      uint32_t __user *encoder_id;
 -
 -      if (!drm_core_check_feature(dev, DRIVER_MODESET))
 -              return -EINVAL;
 -
 -
 -      mutex_lock(&file_priv->fbs_lock);
 -      /*
 -       * For the non-control nodes we need to limit the list of resources
 -       * by IDs in the group list for this node
 -       */
 -      list_for_each(lh, &file_priv->fbs)
 -              fb_count++;
 +      list_for_each(lh, &file_priv->fbs)
 +              fb_count++;
  
        /* handle this in 4 parts */
        /* FBs */
@@@ -1133,11 -2123,32 +1133,11 @@@ int drm_mode_getcrtc(struct drm_device 
        return 0;
  }
  
 -static bool drm_mode_expose_to_userspace(const struct drm_display_mode *mode,
 -                                       const struct drm_file *file_priv)
 -{
 -      /*
 -       * If user-space hasn't configured the driver to expose the stereo 3D
 -       * modes, don't expose them.
 -       */
 -      if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode))
 -              return false;
 -
 -      return true;
 -}
 -
 -static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector)
 -{
 -      /* For atomic drivers only state objects are synchronously updated and
 -       * protected by modeset locks, so check those first. */
 -      if (connector->state)
 -              return connector->state->best_encoder;
 -      return connector->encoder;
 -}
 -
  /* helper for getconnector and getproperties ioctls */
 -static int get_properties(struct drm_mode_object *obj, bool atomic,
 -              uint32_t __user *prop_ptr, uint64_t __user *prop_values,
 -              uint32_t *arg_count_props)
 +int drm_mode_object_get_properties(struct drm_mode_object *obj, bool atomic,
 +                                 uint32_t __user *prop_ptr,
 +                                 uint64_t __user *prop_values,
 +                                 uint32_t *arg_count_props)
  {
        int props_count;
        int i, ret, copied;
        return 0;
  }
  
 -/**
 - * drm_mode_getconnector - get connector configuration
 - * @dev: drm device for the ioctl
 - * @data: data pointer for the ioctl
 - * @file_priv: drm file for the ioctl call
 - *
 - * Construct a connector configuration structure to return to the user.
 - *
 - * Called by the user via ioctl.
 - *
 - * Returns:
 - * Zero on success, negative errno on failure.
 - */
 -int drm_mode_getconnector(struct drm_device *dev, void *data,
 -                        struct drm_file *file_priv)
 -{
 -      struct drm_mode_get_connector *out_resp = data;
 -      struct drm_connector *connector;
 -      struct drm_encoder *encoder;
 -      struct drm_display_mode *mode;
 -      int mode_count = 0;
 -      int encoders_count = 0;
 -      int ret = 0;
 -      int copied = 0;
 -      int i;
 -      struct drm_mode_modeinfo u_mode;
 -      struct drm_mode_modeinfo __user *mode_ptr;
 -      uint32_t __user *encoder_ptr;
 -
 -      if (!drm_core_check_feature(dev, DRIVER_MODESET))
 -              return -EINVAL;
 -
 -      memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo));
 -
 -      mutex_lock(&dev->mode_config.mutex);
 -
 -      connector = drm_connector_lookup(dev, out_resp->connector_id);
 -      if (!connector) {
 -              ret = -ENOENT;
 -              goto out_unlock;
 -      }
 -
 -      for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++)
 -              if (connector->encoder_ids[i] != 0)
 -                      encoders_count++;
 -
 -      if (out_resp->count_modes == 0) {
 -              connector->funcs->fill_modes(connector,
 -                                           dev->mode_config.max_width,
 -                                           dev->mode_config.max_height);
 -      }
 -
 -      /* delayed so we get modes regardless of pre-fill_modes state */
 -      list_for_each_entry(mode, &connector->modes, head)
 -              if (drm_mode_expose_to_userspace(mode, file_priv))
 -                      mode_count++;
 -
 -      out_resp->connector_id = connector->base.id;
 -      out_resp->connector_type = connector->connector_type;
 -      out_resp->connector_type_id = connector->connector_type_id;
 -      out_resp->mm_width = connector->display_info.width_mm;
 -      out_resp->mm_height = connector->display_info.height_mm;
 -      out_resp->subpixel = connector->display_info.subpixel_order;
 -      out_resp->connection = connector->status;
 -
 -      drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
 -      encoder = drm_connector_get_encoder(connector);
 -      if (encoder)
 -              out_resp->encoder_id = encoder->base.id;
 -      else
 -              out_resp->encoder_id = 0;
 -
 -      /*
 -       * This ioctl is called twice, once to determine how much space is
 -       * needed, and the 2nd time to fill it.
 -       */
 -      if ((out_resp->count_modes >= mode_count) && mode_count) {
 -              copied = 0;
 -              mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
 -              list_for_each_entry(mode, &connector->modes, head) {
 -                      if (!drm_mode_expose_to_userspace(mode, file_priv))
 -                              continue;
 -
 -                      drm_mode_convert_to_umode(&u_mode, mode);
 -                      if (copy_to_user(mode_ptr + copied,
 -                                       &u_mode, sizeof(u_mode))) {
 -                              ret = -EFAULT;
 -                              goto out;
 -                      }
 -                      copied++;
 -              }
 -      }
 -      out_resp->count_modes = mode_count;
 -
 -      ret = get_properties(&connector->base, file_priv->atomic,
 -                      (uint32_t __user *)(unsigned long)(out_resp->props_ptr),
 -                      (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr),
 -                      &out_resp->count_props);
 -      if (ret)
 -              goto out;
 -
 -      if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
 -              copied = 0;
 -              encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
 -              for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
 -                      if (connector->encoder_ids[i] != 0) {
 -                              if (put_user(connector->encoder_ids[i],
 -                                           encoder_ptr + copied)) {
 -                                      ret = -EFAULT;
 -                                      goto out;
 -                              }
 -                              copied++;
 -                      }
 -              }
 -      }
 -      out_resp->count_encoders = encoders_count;
 -
 -out:
 -      drm_modeset_unlock(&dev->mode_config.connection_mutex);
 -
 -      drm_connector_unreference(connector);
 -out_unlock:
 -      mutex_unlock(&dev->mode_config.mutex);
 -
 -      return ret;
 -}
 -
  static struct drm_crtc *drm_encoder_get_crtc(struct drm_encoder *encoder)
  {
        struct drm_connector *connector;
@@@ -1454,9 -2592,8 +1454,9 @@@ static int __setplane_internal(struct d
        /* Check whether this plane supports the fb pixel format. */
        ret = drm_plane_check_pixel_format(plane, fb->pixel_format);
        if (ret) {
 -              DRM_DEBUG_KMS("Invalid pixel format %s\n",
 -                            drm_get_format_name(fb->pixel_format));
 +              char *format_name = drm_get_format_name(fb->pixel_format);
 +              DRM_DEBUG_KMS("Invalid pixel format %s\n", format_name);
 +              kfree(format_name);
                goto out;
        }
  
@@@ -1665,8 -2802,8 +1665,8 @@@ int drm_crtc_check_viewport(const struc
        drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay);
  
        if (crtc->state &&
 -          crtc->primary->state->rotation & (BIT(DRM_ROTATE_90) |
 -                                            BIT(DRM_ROTATE_270)))
 +          crtc->primary->state->rotation & (DRM_ROTATE_90 |
 +                                            DRM_ROTATE_270))
                swap(hdisplay, vdisplay);
  
        return check_src_coords(x << 16, y << 16,
@@@ -1765,9 -2902,8 +1765,9 @@@ int drm_mode_setcrtc(struct drm_device 
                        ret = drm_plane_check_pixel_format(crtc->primary,
                                                           fb->pixel_format);
                        if (ret) {
 -                              DRM_DEBUG_KMS("Invalid pixel format %s\n",
 -                                      drm_get_format_name(fb->pixel_format));
 +                              char *format_name = drm_get_format_name(fb->pixel_format);
 +                              DRM_DEBUG_KMS("Invalid pixel format %s\n", format_name);
 +                              kfree(format_name);
                                goto out;
                        }
                }
@@@ -1904,7 -3040,7 +1904,7 @@@ static int drm_mode_cursor_universal(st
         */
        if (req->flags & DRM_MODE_CURSOR_BO) {
                if (req->handle) {
 -                      fb = internal_framebuffer_create(dev, &fbreq, file_priv);
 +                      fb = drm_internal_framebuffer_create(dev, &fbreq, file_priv);
                        if (IS_ERR(fb)) {
                                DRM_DEBUG_KMS("failed to wrap cursor buffer in drm framebuffer\n");
                                return PTR_ERR(fb);
        return ret;
  }
  
 -static int drm_mode_cursor_common(struct drm_device *dev,
 -                                struct drm_mode_cursor2 *req,
 -                                struct drm_file *file_priv)
 -{
 -      struct drm_crtc *crtc;
 -      int ret = 0;
 -
 -      if (!drm_core_check_feature(dev, DRIVER_MODESET))
 -              return -EINVAL;
 -
 -      if (!req->flags || (~DRM_MODE_CURSOR_FLAGS & req->flags))
 -              return -EINVAL;
 -
 -      crtc = drm_crtc_find(dev, req->crtc_id);
 -      if (!crtc) {
 -              DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req->crtc_id);
 -              return -ENOENT;
 -      }
 -
 -      /*
 -       * If this crtc has a universal cursor plane, call that plane's update
 -       * handler rather than using legacy cursor handlers.
 -       */
 -      drm_modeset_lock_crtc(crtc, crtc->cursor);
 -      if (crtc->cursor) {
 -              ret = drm_mode_cursor_universal(crtc, req, file_priv);
 -              goto out;
 -      }
 -
 -      if (req->flags & DRM_MODE_CURSOR_BO) {
 -              if (!crtc->funcs->cursor_set && !crtc->funcs->cursor_set2) {
 -                      ret = -ENXIO;
 -                      goto out;
 -              }
 -              /* Turns off the cursor if handle is 0 */
 -              if (crtc->funcs->cursor_set2)
 -                      ret = crtc->funcs->cursor_set2(crtc, file_priv, req->handle,
 -                                                    req->width, req->height, req->hot_x, req->hot_y);
 -              else
 -                      ret = crtc->funcs->cursor_set(crtc, file_priv, req->handle,
 -                                                    req->width, req->height);
 -      }
 -
 -      if (req->flags & DRM_MODE_CURSOR_MOVE) {
 -              if (crtc->funcs->cursor_move) {
 -                      ret = crtc->funcs->cursor_move(crtc, req->x, req->y);
 -              } else {
 -                      ret = -EFAULT;
 -                      goto out;
 -              }
 -      }
 -out:
 -      drm_modeset_unlock_crtc(crtc);
 -
 -      return ret;
 -
 -}
 -
 -
 -/**
 - * drm_mode_cursor_ioctl - set CRTC's cursor configuration
 - * @dev: drm device for the ioctl
 - * @data: data pointer for the ioctl
 - * @file_priv: drm file for the ioctl call
 - *
 - * Set the cursor configuration based on user request.
 - *
 - * Called by the user via ioctl.
 - *
 - * Returns:
 - * Zero on success, negative errno on failure.
 - */
 -int drm_mode_cursor_ioctl(struct drm_device *dev,
 -                        void *data, struct drm_file *file_priv)
 -{
 -      struct drm_mode_cursor *req = data;
 -      struct drm_mode_cursor2 new_req;
 -
 -      memcpy(&new_req, req, sizeof(struct drm_mode_cursor));
 -      new_req.hot_x = new_req.hot_y = 0;
 -
 -      return drm_mode_cursor_common(dev, &new_req, file_priv);
 -}
 -
 -/**
 - * drm_mode_cursor2_ioctl - set CRTC's cursor configuration
 - * @dev: drm device for the ioctl
 - * @data: data pointer for the ioctl
 - * @file_priv: drm file for the ioctl call
 - *
 - * Set the cursor configuration based on user request. This implements the 2nd
 - * version of the cursor ioctl, which allows userspace to additionally specify
 - * the hotspot of the pointer.
 - *
 - * Called by the user via ioctl.
 - *
 - * Returns:
 - * Zero on success, negative errno on failure.
 - */
 -int drm_mode_cursor2_ioctl(struct drm_device *dev,
 -                         void *data, struct drm_file *file_priv)
 -{
 -      struct drm_mode_cursor2 *req = data;
 -
 -      return drm_mode_cursor_common(dev, req, file_priv);
 -}
 -
 -/**
 - * drm_mode_legacy_fb_format - compute drm fourcc code from legacy description
 - * @bpp: bits per pixels
 - * @depth: bit depth per pixel
 - *
 - * Computes a drm fourcc pixel format code for the given @bpp/@depth values.
 - * Useful in fbdev emulation code, since that deals in those values.
 - */
 -uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth)
 -{
 -      uint32_t fmt;
 -
 -      switch (bpp) {
 -      case 8:
 -              fmt = DRM_FORMAT_C8;
 -              break;
 -      case 16:
 -              if (depth == 15)
 -                      fmt = DRM_FORMAT_XRGB1555;
 -              else
 -                      fmt = DRM_FORMAT_RGB565;
 -              break;
 -      case 24:
 -              fmt = DRM_FORMAT_RGB888;
 -              break;
 -      case 32:
 -              if (depth == 24)
 -                      fmt = DRM_FORMAT_XRGB8888;
 -              else if (depth == 30)
 -                      fmt = DRM_FORMAT_XRGB2101010;
 -              else
 -                      fmt = DRM_FORMAT_ARGB8888;
 -              break;
 -      default:
 -              DRM_ERROR("bad bpp, assuming x8r8g8b8 pixel format\n");
 -              fmt = DRM_FORMAT_XRGB8888;
 -              break;
 -      }
 -
 -      return fmt;
 -}
 -EXPORT_SYMBOL(drm_mode_legacy_fb_format);
 -
 -/**
 - * drm_mode_addfb - add an FB to the graphics configuration
 - * @dev: drm device for the ioctl
 - * @data: data pointer for the ioctl
 - * @file_priv: drm file for the ioctl call
 - *
 - * Add a new FB to the specified CRTC, given a user request. This is the
 - * original addfb ioctl which only supported RGB formats.
 - *
 - * Called by the user via ioctl.
 - *
 - * Returns:
 - * Zero on success, negative errno on failure.
 - */
 -int drm_mode_addfb(struct drm_device *dev,
 -                 void *data, struct drm_file *file_priv)
 -{
 -      struct drm_mode_fb_cmd *or = data;
 -      struct drm_mode_fb_cmd2 r = {};
 -      int ret;
 -
 -      /* convert to new format and call new ioctl */
 -      r.fb_id = or->fb_id;
 -      r.width = or->width;
 -      r.height = or->height;
 -      r.pitches[0] = or->pitch;
 -      r.pixel_format = drm_mode_legacy_fb_format(or->bpp, or->depth);
 -      r.handles[0] = or->handle;
 -
 -      ret = drm_mode_addfb2(dev, &r, file_priv);
 -      if (ret)
 -              return ret;
 -
 -      or->fb_id = r.fb_id;
 -
 -      return 0;
 -}
 -
 -static int format_check(const struct drm_mode_fb_cmd2 *r)
 -{
 -      uint32_t format = r->pixel_format & ~DRM_FORMAT_BIG_ENDIAN;
 -
 -      switch (format) {
 -      case DRM_FORMAT_C8:
 -      case DRM_FORMAT_RGB332:
 -      case DRM_FORMAT_BGR233:
 -      case DRM_FORMAT_XRGB4444:
 -      case DRM_FORMAT_XBGR4444:
 -      case DRM_FORMAT_RGBX4444:
 -      case DRM_FORMAT_BGRX4444:
 -      case DRM_FORMAT_ARGB4444:
 -      case DRM_FORMAT_ABGR4444:
 -      case DRM_FORMAT_RGBA4444:
 -      case DRM_FORMAT_BGRA4444:
 -      case DRM_FORMAT_XRGB1555:
 -      case DRM_FORMAT_XBGR1555:
 -      case DRM_FORMAT_RGBX5551:
 -      case DRM_FORMAT_BGRX5551:
 -      case DRM_FORMAT_ARGB1555:
 -      case DRM_FORMAT_ABGR1555:
 -      case DRM_FORMAT_RGBA5551:
 -      case DRM_FORMAT_BGRA5551:
 -      case DRM_FORMAT_RGB565:
 -      case DRM_FORMAT_BGR565:
 -      case DRM_FORMAT_RGB888:
 -      case DRM_FORMAT_BGR888:
 -      case DRM_FORMAT_XRGB8888:
 -      case DRM_FORMAT_XBGR8888:
 -      case DRM_FORMAT_RGBX8888:
 -      case DRM_FORMAT_BGRX8888:
 -      case DRM_FORMAT_ARGB8888:
 -      case DRM_FORMAT_ABGR8888:
 -      case DRM_FORMAT_RGBA8888:
 -      case DRM_FORMAT_BGRA8888:
 -      case DRM_FORMAT_XRGB2101010:
 -      case DRM_FORMAT_XBGR2101010:
 -      case DRM_FORMAT_RGBX1010102:
 -      case DRM_FORMAT_BGRX1010102:
 -      case DRM_FORMAT_ARGB2101010:
 -      case DRM_FORMAT_ABGR2101010:
 -      case DRM_FORMAT_RGBA1010102:
 -      case DRM_FORMAT_BGRA1010102:
 -      case DRM_FORMAT_YUYV:
 -      case DRM_FORMAT_YVYU:
 -      case DRM_FORMAT_UYVY:
 -      case DRM_FORMAT_VYUY:
 -      case DRM_FORMAT_AYUV:
 -      case DRM_FORMAT_NV12:
 -      case DRM_FORMAT_NV21:
 -      case DRM_FORMAT_NV16:
 -      case DRM_FORMAT_NV61:
 -      case DRM_FORMAT_NV24:
 -      case DRM_FORMAT_NV42:
 -      case DRM_FORMAT_YUV410:
 -      case DRM_FORMAT_YVU410:
 -      case DRM_FORMAT_YUV411:
 -      case DRM_FORMAT_YVU411:
 -      case DRM_FORMAT_YUV420:
 -      case DRM_FORMAT_YVU420:
 -      case DRM_FORMAT_YUV422:
 -      case DRM_FORMAT_YVU422:
 -      case DRM_FORMAT_YUV444:
 -      case DRM_FORMAT_YVU444:
 -              return 0;
 -      default:
 -              DRM_DEBUG_KMS("invalid pixel format %s\n",
 -                            drm_get_format_name(r->pixel_format));
 -              return -EINVAL;
 -      }
 -}
 -
 -static int framebuffer_check(const struct drm_mode_fb_cmd2 *r)
 -{
 -      int ret, hsub, vsub, num_planes, i;
 -
 -      ret = format_check(r);
 -      if (ret) {
 -              DRM_DEBUG_KMS("bad framebuffer format %s\n",
 -                            drm_get_format_name(r->pixel_format));
 -              return ret;
 -      }
 -
 -      hsub = drm_format_horz_chroma_subsampling(r->pixel_format);
 -      vsub = drm_format_vert_chroma_subsampling(r->pixel_format);
 -      num_planes = drm_format_num_planes(r->pixel_format);
 -
 -      if (r->width == 0 || r->width % hsub) {
 -              DRM_DEBUG_KMS("bad framebuffer width %u\n", r->width);
 -              return -EINVAL;
 -      }
 -
 -      if (r->height == 0 || r->height % vsub) {
 -              DRM_DEBUG_KMS("bad framebuffer height %u\n", r->height);
 -              return -EINVAL;
 -      }
 -
 -      for (i = 0; i < num_planes; i++) {
 -              unsigned int width = r->width / (i != 0 ? hsub : 1);
 -              unsigned int height = r->height / (i != 0 ? vsub : 1);
 -              unsigned int cpp = drm_format_plane_cpp(r->pixel_format, i);
 -
 -              if (!r->handles[i]) {
 -                      DRM_DEBUG_KMS("no buffer object handle for plane %d\n", i);
 -                      return -EINVAL;
 -              }
 -
 -              if ((uint64_t) width * cpp > UINT_MAX)
 -                      return -ERANGE;
 -
 -              if ((uint64_t) height * r->pitches[i] + r->offsets[i] > UINT_MAX)
 -                      return -ERANGE;
 -
 -              if (r->pitches[i] < width * cpp) {
 -                      DRM_DEBUG_KMS("bad pitch %u for plane %d\n", r->pitches[i], i);
 -                      return -EINVAL;
 -              }
 -
 -              if (r->modifier[i] && !(r->flags & DRM_MODE_FB_MODIFIERS)) {
 -                      DRM_DEBUG_KMS("bad fb modifier %llu for plane %d\n",
 -                                    r->modifier[i], i);
 -                      return -EINVAL;
 -              }
 -
 -              /* modifier specific checks: */
 -              switch (r->modifier[i]) {
 -              case DRM_FORMAT_MOD_SAMSUNG_64_32_TILE:
 -                      /* NOTE: the pitch restriction may be lifted later if it turns
 -                       * out that no hw has this restriction:
 -                       */
 -                      if (r->pixel_format != DRM_FORMAT_NV12 ||
 -                                      width % 128 || height % 32 ||
 -                                      r->pitches[i] % 128) {
 -                              DRM_DEBUG_KMS("bad modifier data for plane %d\n", i);
 -                              return -EINVAL;
 -                      }
 -                      break;
 -
 -              default:
 -                      break;
 -              }
 -      }
 -
 -      for (i = num_planes; i < 4; i++) {
 -              if (r->modifier[i]) {
 -                      DRM_DEBUG_KMS("non-zero modifier for unused plane %d\n", i);
 -                      return -EINVAL;
 -              }
 -
 -              /* Pre-FB_MODIFIERS userspace didn't clear the structs properly. */
 -              if (!(r->flags & DRM_MODE_FB_MODIFIERS))
 -                      continue;
 -
 -              if (r->handles[i]) {
 -                      DRM_DEBUG_KMS("buffer object handle for unused plane %d\n", i);
 -                      return -EINVAL;
 -              }
 -
 -              if (r->pitches[i]) {
 -                      DRM_DEBUG_KMS("non-zero pitch for unused plane %d\n", i);
 -                      return -EINVAL;
 -              }
 -
 -              if (r->offsets[i]) {
 -                      DRM_DEBUG_KMS("non-zero offset for unused plane %d\n", i);
 -                      return -EINVAL;
 -              }
 -      }
 -
 -      return 0;
 -}
 -
 -static struct drm_framebuffer *
 -internal_framebuffer_create(struct drm_device *dev,
 -                          const struct drm_mode_fb_cmd2 *r,
 -                          struct drm_file *file_priv)
 -{
 -      struct drm_mode_config *config = &dev->mode_config;
 -      struct drm_framebuffer *fb;
 -      int ret;
 -
 -      if (r->flags & ~(DRM_MODE_FB_INTERLACED | DRM_MODE_FB_MODIFIERS)) {
 -              DRM_DEBUG_KMS("bad framebuffer flags 0x%08x\n", r->flags);
 -              return ERR_PTR(-EINVAL);
 -      }
 -
 -      if ((config->min_width > r->width) || (r->width > config->max_width)) {
 -              DRM_DEBUG_KMS("bad framebuffer width %d, should be >= %d && <= %d\n",
 -                        r->width, config->min_width, config->max_width);
 -              return ERR_PTR(-EINVAL);
 -      }
 -      if ((config->min_height > r->height) || (r->height > config->max_height)) {
 -              DRM_DEBUG_KMS("bad framebuffer height %d, should be >= %d && <= %d\n",
 -                        r->height, config->min_height, config->max_height);
 -              return ERR_PTR(-EINVAL);
 -      }
 -
 -      if (r->flags & DRM_MODE_FB_MODIFIERS &&
 -          !dev->mode_config.allow_fb_modifiers) {
 -              DRM_DEBUG_KMS("driver does not support fb modifiers\n");
 -              return ERR_PTR(-EINVAL);
 -      }
 -
 -      ret = framebuffer_check(r);
 -      if (ret)
 -              return ERR_PTR(ret);
 -
 -      fb = dev->mode_config.funcs->fb_create(dev, file_priv, r);
 -      if (IS_ERR(fb)) {
 -              DRM_DEBUG_KMS("could not create framebuffer\n");
 -              return fb;
 -      }
 -
 -      return fb;
 -}
 -
 -/**
 - * drm_mode_addfb2 - add an FB to the graphics configuration
 - * @dev: drm device for the ioctl
 - * @data: data pointer for the ioctl
 - * @file_priv: drm file for the ioctl call
 - *
 - * Add a new FB to the specified CRTC, given a user request with format. This is
 - * the 2nd version of the addfb ioctl, which supports multi-planar framebuffers
 - * and uses fourcc codes as pixel format specifiers.
 - *
 - * Called by the user via ioctl.
 - *
 - * Returns:
 - * Zero on success, negative errno on failure.
 - */
 -int drm_mode_addfb2(struct drm_device *dev,
 -                  void *data, struct drm_file *file_priv)
 -{
 -      struct drm_mode_fb_cmd2 *r = data;
 -      struct drm_framebuffer *fb;
 -
 -      if (!drm_core_check_feature(dev, DRIVER_MODESET))
 -              return -EINVAL;
 -
 -      fb = internal_framebuffer_create(dev, r, file_priv);
 -      if (IS_ERR(fb))
 -              return PTR_ERR(fb);
 -
 -      DRM_DEBUG_KMS("[FB:%d]\n", fb->base.id);
 -      r->fb_id = fb->base.id;
 -
 -      /* Transfer ownership to the filp for reaping on close */
 -      mutex_lock(&file_priv->fbs_lock);
 -      list_add(&fb->filp_head, &file_priv->fbs);
 -      mutex_unlock(&file_priv->fbs_lock);
 -
 -      return 0;
 -}
 -
 -struct drm_mode_rmfb_work {
 -      struct work_struct work;
 -      struct list_head fbs;
 -};
 -
 -static void drm_mode_rmfb_work_fn(struct work_struct *w)
 -{
 -      struct drm_mode_rmfb_work *arg = container_of(w, typeof(*arg), work);
 -
 -      while (!list_empty(&arg->fbs)) {
 -              struct drm_framebuffer *fb =
 -                      list_first_entry(&arg->fbs, typeof(*fb), filp_head);
 -
 -              list_del_init(&fb->filp_head);
 -              drm_framebuffer_remove(fb);
 -      }
 -}
 -
 -/**
 - * drm_mode_rmfb - remove an FB from the configuration
 - * @dev: drm device for the ioctl
 - * @data: data pointer for the ioctl
 - * @file_priv: drm file for the ioctl call
 - *
 - * Remove the FB specified by the user.
 - *
 - * Called by the user via ioctl.
 - *
 - * Returns:
 - * Zero on success, negative errno on failure.
 - */
 -int drm_mode_rmfb(struct drm_device *dev,
 -                 void *data, struct drm_file *file_priv)
 +static int drm_mode_cursor_common(struct drm_device *dev,
 +                                struct drm_mode_cursor2 *req,
 +                                struct drm_file *file_priv)
  {
 -      struct drm_framebuffer *fb = NULL;
 -      struct drm_framebuffer *fbl = NULL;
 -      uint32_t *id = data;
 -      int found = 0;
 +      struct drm_crtc *crtc;
 +      int ret = 0;
  
        if (!drm_core_check_feature(dev, DRIVER_MODESET))
                return -EINVAL;
  
 -      fb = drm_framebuffer_lookup(dev, *id);
 -      if (!fb)
 -              return -ENOENT;
 +      if (!req->flags || (~DRM_MODE_CURSOR_FLAGS & req->flags))
 +              return -EINVAL;
  
 -      mutex_lock(&file_priv->fbs_lock);
 -      list_for_each_entry(fbl, &file_priv->fbs, filp_head)
 -              if (fb == fbl)
 -                      found = 1;
 -      if (!found) {
 -              mutex_unlock(&file_priv->fbs_lock);
 -              goto fail_unref;
 +      crtc = drm_crtc_find(dev, req->crtc_id);
 +      if (!crtc) {
 +              DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req->crtc_id);
 +              return -ENOENT;
        }
  
 -      list_del_init(&fb->filp_head);
 -      mutex_unlock(&file_priv->fbs_lock);
 -
 -      /* drop the reference we picked up in framebuffer lookup */
 -      drm_framebuffer_unreference(fb);
 -
        /*
 -       * we now own the reference that was stored in the fbs list
 -       *
 -       * drm_framebuffer_remove may fail with -EINTR on pending signals,
 -       * so run this in a separate stack as there's no way to correctly
 -       * handle this after the fb is already removed from the lookup table.
 +       * If this crtc has a universal cursor plane, call that plane's update
 +       * handler rather than using legacy cursor handlers.
         */
 -      if (drm_framebuffer_read_refcount(fb) > 1) {
 -              struct drm_mode_rmfb_work arg;
 +      drm_modeset_lock_crtc(crtc, crtc->cursor);
 +      if (crtc->cursor) {
 +              ret = drm_mode_cursor_universal(crtc, req, file_priv);
 +              goto out;
 +      }
  
 -              INIT_WORK_ONSTACK(&arg.work, drm_mode_rmfb_work_fn);
 -              INIT_LIST_HEAD(&arg.fbs);
 -              list_add_tail(&fb->filp_head, &arg.fbs);
 +      if (req->flags & DRM_MODE_CURSOR_BO) {
 +              if (!crtc->funcs->cursor_set && !crtc->funcs->cursor_set2) {
 +                      ret = -ENXIO;
 +                      goto out;
 +              }
 +              /* Turns off the cursor if handle is 0 */
 +              if (crtc->funcs->cursor_set2)
 +                      ret = crtc->funcs->cursor_set2(crtc, file_priv, req->handle,
 +                                                    req->width, req->height, req->hot_x, req->hot_y);
 +              else
 +                      ret = crtc->funcs->cursor_set(crtc, file_priv, req->handle,
 +                                                    req->width, req->height);
 +      }
  
 -              schedule_work(&arg.work);
 -              flush_work(&arg.work);
 -              destroy_work_on_stack(&arg.work);
 -      } else
 -              drm_framebuffer_unreference(fb);
 +      if (req->flags & DRM_MODE_CURSOR_MOVE) {
 +              if (crtc->funcs->cursor_move) {
 +                      ret = crtc->funcs->cursor_move(crtc, req->x, req->y);
 +              } else {
 +                      ret = -EFAULT;
 +                      goto out;
 +              }
 +      }
 +out:
 +      drm_modeset_unlock_crtc(crtc);
  
 -      return 0;
 +      return ret;
  
 -fail_unref:
 -      drm_framebuffer_unreference(fb);
 -      return -ENOENT;
  }
  
 +
  /**
 - * drm_mode_getfb - get FB info
 + * drm_mode_cursor_ioctl - set CRTC's cursor configuration
   * @dev: drm device for the ioctl
   * @data: data pointer for the ioctl
   * @file_priv: drm file for the ioctl call
   *
 - * Lookup the FB given its ID and return info about it.
 + * Set the cursor configuration based on user request.
   *
   * Called by the user via ioctl.
   *
   * Returns:
   * Zero on success, negative errno on failure.
   */
 -int drm_mode_getfb(struct drm_device *dev,
 -                 void *data, struct drm_file *file_priv)
 +int drm_mode_cursor_ioctl(struct drm_device *dev,
 +                        void *data, struct drm_file *file_priv)
  {
 -      struct drm_mode_fb_cmd *r = data;
 -      struct drm_framebuffer *fb;
 -      int ret;
 -
 -      if (!drm_core_check_feature(dev, DRIVER_MODESET))
 -              return -EINVAL;
 -
 -      fb = drm_framebuffer_lookup(dev, r->fb_id);
 -      if (!fb)
 -              return -ENOENT;
 -
 -      r->height = fb->height;
 -      r->width = fb->width;
 -      r->depth = fb->depth;
 -      r->bpp = fb->bits_per_pixel;
 -      r->pitch = fb->pitches[0];
 -      if (fb->funcs->create_handle) {
 -              if (drm_is_current_master(file_priv) || capable(CAP_SYS_ADMIN) ||
 -                  drm_is_control_client(file_priv)) {
 -                      ret = fb->funcs->create_handle(fb, file_priv,
 -                                                     &r->handle);
 -              } else {
 -                      /* GET_FB() is an unprivileged ioctl so we must not
 -                       * return a buffer-handle to non-master processes! For
 -                       * backwards-compatibility reasons, we cannot make
 -                       * GET_FB() privileged, so just return an invalid handle
 -                       * for non-masters. */
 -                      r->handle = 0;
 -                      ret = 0;
 -              }
 -      } else {
 -              ret = -ENODEV;
 -      }
 +      struct drm_mode_cursor *req = data;
 +      struct drm_mode_cursor2 new_req;
  
 -      drm_framebuffer_unreference(fb);
 +      memcpy(&new_req, req, sizeof(struct drm_mode_cursor));
 +      new_req.hot_x = new_req.hot_y = 0;
  
 -      return ret;
 +      return drm_mode_cursor_common(dev, &new_req, file_priv);
  }
  
  /**
 - * drm_mode_dirtyfb_ioctl - flush frontbuffer rendering on an FB
 + * drm_mode_cursor2_ioctl - set CRTC's cursor configuration
   * @dev: drm device for the ioctl
   * @data: data pointer for the ioctl
   * @file_priv: drm file for the ioctl call
   *
 - * Lookup the FB and flush out the damaged area supplied by userspace as a clip
 - * rectangle list. Generic userspace which does frontbuffer rendering must call
 - * this ioctl to flush out the changes on manual-update display outputs, e.g.
 - * usb display-link, mipi manual update panels or edp panel self refresh modes.
 - *
 - * Modesetting drivers which always update the frontbuffer do not need to
 - * implement the corresponding ->dirty framebuffer callback.
 + * Set the cursor configuration based on user request. This implements the 2nd
 + * version of the cursor ioctl, which allows userspace to additionally specify
 + * the hotspot of the pointer.
   *
   * Called by the user via ioctl.
   *
   * Returns:
   * Zero on success, negative errno on failure.
   */
 -int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
 +int drm_mode_cursor2_ioctl(struct drm_device *dev,
                           void *data, struct drm_file *file_priv)
  {
 -      struct drm_clip_rect __user *clips_ptr;
 -      struct drm_clip_rect *clips = NULL;
 -      struct drm_mode_fb_dirty_cmd *r = data;
 -      struct drm_framebuffer *fb;
 -      unsigned flags;
 -      int num_clips;
 -      int ret;
 -
 -      if (!drm_core_check_feature(dev, DRIVER_MODESET))
 -              return -EINVAL;
 -
 -      fb = drm_framebuffer_lookup(dev, r->fb_id);
 -      if (!fb)
 -              return -ENOENT;
 -
 -      num_clips = r->num_clips;
 -      clips_ptr = (struct drm_clip_rect __user *)(unsigned long)r->clips_ptr;
 -
 -      if (!num_clips != !clips_ptr) {
 -              ret = -EINVAL;
 -              goto out_err1;
 -      }
 -
 -      flags = DRM_MODE_FB_DIRTY_FLAGS & r->flags;
 -
 -      /* If userspace annotates copy, clips must come in pairs */
 -      if (flags & DRM_MODE_FB_DIRTY_ANNOTATE_COPY && (num_clips % 2)) {
 -              ret = -EINVAL;
 -              goto out_err1;
 -      }
 -
 -      if (num_clips && clips_ptr) {
 -              if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
 -                      ret = -EINVAL;
 -                      goto out_err1;
 -              }
 -              clips = kcalloc(num_clips, sizeof(*clips), GFP_KERNEL);
 -              if (!clips) {
 -                      ret = -ENOMEM;
 -                      goto out_err1;
 -              }
 -
 -              ret = copy_from_user(clips, clips_ptr,
 -                                   num_clips * sizeof(*clips));
 -              if (ret) {
 -                      ret = -EFAULT;
 -                      goto out_err2;
 -              }
 -      }
 -
 -      if (fb->funcs->dirty) {
 -              ret = fb->funcs->dirty(fb, file_priv, flags, r->color,
 -                                     clips, num_clips);
 -      } else {
 -              ret = -ENOSYS;
 -      }
 -
 -out_err2:
 -      kfree(clips);
 -out_err1:
 -      drm_framebuffer_unreference(fb);
 +      struct drm_mode_cursor2 *req = data;
  
 -      return ret;
 +      return drm_mode_cursor_common(dev, req, file_priv);
  }
  
  /**
 - * drm_fb_release - remove and free the FBs on this file
 - * @priv: drm file for the ioctl
 - *
 - * Destroy all the FBs associated with @filp.
 - *
 - * Called by the user via ioctl.
 + * drm_mode_legacy_fb_format - compute drm fourcc code from legacy description
 + * @bpp: bits per pixels
 + * @depth: bit depth per pixel
   *
 - * Returns:
 - * Zero on success, negative errno on failure.
 + * Computes a drm fourcc pixel format code for the given @bpp/@depth values.
 + * Useful in fbdev emulation code, since that deals in those values.
   */
 -void drm_fb_release(struct drm_file *priv)
 +uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth)
  {
 -      struct drm_framebuffer *fb, *tfb;
 -      struct drm_mode_rmfb_work arg;
 -
 -      INIT_LIST_HEAD(&arg.fbs);
 -
 -      /*
 -       * When the file gets released that means no one else can access the fb
 -       * list any more, so no need to grab fpriv->fbs_lock. And we need to
 -       * avoid upsetting lockdep since the universal cursor code adds a
 -       * framebuffer while holding mutex locks.
 -       *
 -       * Note that a real deadlock between fpriv->fbs_lock and the modeset
 -       * locks is impossible here since no one else but this function can get
 -       * at it any more.
 -       */
 -      list_for_each_entry_safe(fb, tfb, &priv->fbs, filp_head) {
 -              if (drm_framebuffer_read_refcount(fb) > 1) {
 -                      list_move_tail(&fb->filp_head, &arg.fbs);
 -              } else {
 -                      list_del_init(&fb->filp_head);
 +      uint32_t fmt;
  
 -                      /* This drops the fpriv->fbs reference. */
 -                      drm_framebuffer_unreference(fb);
 -              }
 +      switch (bpp) {
 +      case 8:
 +              fmt = DRM_FORMAT_C8;
 +              break;
 +      case 16:
 +              if (depth == 15)
 +                      fmt = DRM_FORMAT_XRGB1555;
 +              else
 +                      fmt = DRM_FORMAT_RGB565;
 +              break;
 +      case 24:
 +              fmt = DRM_FORMAT_RGB888;
 +              break;
 +      case 32:
 +              if (depth == 24)
 +                      fmt = DRM_FORMAT_XRGB8888;
 +              else if (depth == 30)
 +                      fmt = DRM_FORMAT_XRGB2101010;
 +              else
 +                      fmt = DRM_FORMAT_ARGB8888;
 +              break;
 +      default:
 +              DRM_ERROR("bad bpp, assuming x8r8g8b8 pixel format\n");
 +              fmt = DRM_FORMAT_XRGB8888;
 +              break;
        }
  
 -      if (!list_empty(&arg.fbs)) {
 -              INIT_WORK_ONSTACK(&arg.work, drm_mode_rmfb_work_fn);
 -
 -              schedule_work(&arg.work);
 -              flush_work(&arg.work);
 -              destroy_work_on_stack(&arg.work);
 -      }
 +      return fmt;
  }
 +EXPORT_SYMBOL(drm_mode_legacy_fb_format);
  
  static bool drm_property_type_valid(struct drm_property *property)
  {
@@@ -2814,7 -4522,7 +2814,7 @@@ struct drm_property_blob *drm_property_
        struct drm_mode_object *obj;
        struct drm_property_blob *blob = NULL;
  
 -      obj = _object_find(dev, id, DRM_MODE_OBJECT_BLOB);
 +      obj = __drm_mode_object_find(dev, id, DRM_MODE_OBJECT_BLOB);
        if (obj)
                blob = obj_to_blob(obj);
        return blob;
@@@ -2851,12 -4559,12 +2851,12 @@@ EXPORT_SYMBOL(drm_property_lookup_blob)
   * a completely atomic update. The access to path_blob_ptr is protected by the
   * caller holding a lock on the connector.
   */
 -static int drm_property_replace_global_blob(struct drm_device *dev,
 -                                            struct drm_property_blob **replace,
 -                                            size_t length,
 -                                            const void *data,
 -                                            struct drm_mode_object *obj_holds_id,
 -                                            struct drm_property *prop_holds_id)
 +int drm_property_replace_global_blob(struct drm_device *dev,
 +                                   struct drm_property_blob **replace,
 +                                   size_t length,
 +                                   const void *data,
 +                                   struct drm_mode_object *obj_holds_id,
 +                                   struct drm_property *prop_holds_id)
  {
        struct drm_property_blob *new_blob = NULL;
        struct drm_property_blob *old_blob = NULL;
@@@ -2895,7 -4603,6 +2895,7 @@@ err_created
        drm_property_unreference_blob(new_blob);
        return ret;
  }
 +EXPORT_SYMBOL(drm_property_replace_global_blob);
  
  /**
   * drm_mode_getblob_ioctl - get the contents of a blob property value
        return ret;
  }
  
 -/**
 - * drm_mode_connector_set_path_property - set tile property on connector
 - * @connector: connector to set property on.
 - * @path: path to use for property; must not be NULL.
 - *
 - * This creates a property to expose to userspace to specify a
 - * connector path. This is mainly used for DisplayPort MST where
 - * connectors have a topology and we want to allow userspace to give
 - * them more meaningful names.
 - *
 - * Returns:
 - * Zero on success, negative errno on failure.
 - */
 -int drm_mode_connector_set_path_property(struct drm_connector *connector,
 -                                       const char *path)
 -{
 -      struct drm_device *dev = connector->dev;
 -      int ret;
 -
 -      ret = drm_property_replace_global_blob(dev,
 -                                             &connector->path_blob_ptr,
 -                                             strlen(path) + 1,
 -                                             path,
 -                                             &connector->base,
 -                                             dev->mode_config.path_property);
 -      return ret;
 -}
 -EXPORT_SYMBOL(drm_mode_connector_set_path_property);
 -
 -/**
 - * drm_mode_connector_set_tile_property - set tile property on connector
 - * @connector: connector to set property on.
 - *
 - * This looks up the tile information for a connector, and creates a
 - * property for userspace to parse if it exists. The property is of
 - * the form of 8 integers using ':' as a separator.
 - *
 - * Returns:
 - * Zero on success, errno on failure.
 - */
 -int drm_mode_connector_set_tile_property(struct drm_connector *connector)
 -{
 -      struct drm_device *dev = connector->dev;
 -      char tile[256];
 -      int ret;
 -
 -      if (!connector->has_tile) {
 -              ret  = drm_property_replace_global_blob(dev,
 -                                                      &connector->tile_blob_ptr,
 -                                                      0,
 -                                                      NULL,
 -                                                      &connector->base,
 -                                                      dev->mode_config.tile_property);
 -              return ret;
 -      }
 -
 -      snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d",
 -               connector->tile_group->id, connector->tile_is_single_monitor,
 -               connector->num_h_tile, connector->num_v_tile,
 -               connector->tile_h_loc, connector->tile_v_loc,
 -               connector->tile_h_size, connector->tile_v_size);
 -
 -      ret = drm_property_replace_global_blob(dev,
 -                                             &connector->tile_blob_ptr,
 -                                             strlen(tile) + 1,
 -                                             tile,
 -                                             &connector->base,
 -                                             dev->mode_config.tile_property);
 -      return ret;
 -}
 -EXPORT_SYMBOL(drm_mode_connector_set_tile_property);
 -
 -/**
 - * drm_mode_connector_update_edid_property - update the edid property of a connector
 - * @connector: drm connector
 - * @edid: new value of the edid property
 - *
 - * This function creates a new blob modeset object and assigns its id to the
 - * connector's edid property.
 - *
 - * Returns:
 - * Zero on success, negative errno on failure.
 - */
 -int drm_mode_connector_update_edid_property(struct drm_connector *connector,
 -                                          const struct edid *edid)
 -{
 -      struct drm_device *dev = connector->dev;
 -      size_t size = 0;
 -      int ret;
 -
 -      /* ignore requests to set edid when overridden */
 -      if (connector->override_edid)
 -              return 0;
 -
 -      if (edid)
 -              size = EDID_LENGTH * (1 + edid->extensions);
 -
 -      ret = drm_property_replace_global_blob(dev,
 -                                             &connector->edid_blob_ptr,
 -                                             size,
 -                                             edid,
 -                                             &connector->base,
 -                                             dev->mode_config.edid_property);
 -      return ret;
 -}
 -EXPORT_SYMBOL(drm_mode_connector_update_edid_property);
 -
  /* Some properties could refer to dynamic refcnt'd objects, or things that
   * need special locking to handle lifetime issues (ie. to ensure the prop
   * value doesn't become invalid part way through the property update due to
@@@ -3104,8 -4918,7 +3104,8 @@@ bool drm_property_change_valid_get(stru
                if (value == 0)
                        return true;
  
 -              *ref = _object_find(property->dev, value, property->values[0]);
 +              *ref = __drm_mode_object_find(property->dev, value,
 +                                            property->values[0]);
                return *ref != NULL;
        }
  
@@@ -3127,6 -4940,54 +3127,6 @@@ void drm_property_change_valid_put(stru
                drm_property_unreference_blob(obj_to_blob(ref));
  }
  
 -/**
 - * drm_mode_connector_property_set_ioctl - set the current value of a connector property
 - * @dev: DRM device
 - * @data: ioctl data
 - * @file_priv: DRM file info
 - *
 - * This function sets the current value for a connectors's property. It also
 - * calls into a driver's ->set_property callback to update the hardware state
 - *
 - * Called by the user via ioctl.
 - *
 - * Returns:
 - * Zero on success, negative errno on failure.
 - */
 -int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
 -                                     void *data, struct drm_file *file_priv)
 -{
 -      struct drm_mode_connector_set_property *conn_set_prop = data;
 -      struct drm_mode_obj_set_property obj_set_prop = {
 -              .value = conn_set_prop->value,
 -              .prop_id = conn_set_prop->prop_id,
 -              .obj_id = conn_set_prop->connector_id,
 -              .obj_type = DRM_MODE_OBJECT_CONNECTOR
 -      };
 -
 -      /* It does all the locking and checking we need */
 -      return drm_mode_obj_set_property_ioctl(dev, &obj_set_prop, file_priv);
 -}
 -
 -static int drm_mode_connector_set_obj_prop(struct drm_mode_object *obj,
 -                                         struct drm_property *property,
 -                                         uint64_t value)
 -{
 -      int ret = -EINVAL;
 -      struct drm_connector *connector = obj_to_connector(obj);
 -
 -      /* Do DPMS ourselves */
 -      if (property == connector->dev->mode_config.dpms_property) {
 -              ret = (*connector->funcs->dpms)(connector, (int)value);
 -      } else if (connector->funcs->set_property)
 -              ret = connector->funcs->set_property(connector, property, value);
 -
 -      /* store the property value if successful */
 -      if (!ret)
 -              drm_object_property_set_value(&connector->base, property, value);
 -      return ret;
 -}
 -
  static int drm_mode_crtc_set_obj_prop(struct drm_mode_object *obj,
                                      struct drm_property *property,
                                      uint64_t value)
@@@ -3208,7 -5069,7 +3208,7 @@@ int drm_mode_obj_get_properties_ioctl(s
                goto out_unref;
        }
  
 -      ret = get_properties(obj, file_priv->atomic,
 +      ret = drm_mode_object_get_properties(obj, file_priv->atomic,
                        (uint32_t __user *)(unsigned long)(arg->props_ptr),
                        (uint64_t __user *)(unsigned long)(arg->prop_values_ptr),
                        &arg->count_props);
@@@ -3220,6 -5081,22 +3220,6 @@@ out
        return ret;
  }
  
 -/**
 - * drm_mode_obj_set_property_ioctl - set the current value of an object's property
 - * @dev: DRM device
 - * @data: ioctl data
 - * @file_priv: DRM file info
 - *
 - * This function sets the current value for an object's property. It also calls
 - * into a driver's ->set_property callback to update the hardware state.
 - * Compared to the connector specific ioctl this one is extended to also work on
 - * crtc and plane objects.
 - *
 - * Called by the user via ioctl.
 - *
 - * Returns:
 - * Zero on success, negative errno on failure.
 - */
  int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
                                    struct drm_file *file_priv)
  {
@@@ -3284,6 -5161,47 +3284,6 @@@ out
        return ret;
  }
  
 -/**
 - * drm_mode_connector_attach_encoder - attach a connector to an encoder
 - * @connector: connector to attach
 - * @encoder: encoder to attach @connector to
 - *
 - * This function links up a connector to an encoder. Note that the routing
 - * restrictions between encoders and crtcs are exposed to userspace through the
 - * possible_clones and possible_crtcs bitmasks.
 - *
 - * Returns:
 - * Zero on success, negative errno on failure.
 - */
 -int drm_mode_connector_attach_encoder(struct drm_connector *connector,
 -                                    struct drm_encoder *encoder)
 -{
 -      int i;
 -
 -      /*
 -       * In the past, drivers have attempted to model the static association
 -       * of connector to encoder in simple connector/encoder devices using a
 -       * direct assignment of connector->encoder = encoder. This connection
 -       * is a logical one and the responsibility of the core, so drivers are
 -       * expected not to mess with this.
 -       *
 -       * Note that the error return should've been enough here, but a large
 -       * majority of drivers ignores the return value, so add in a big WARN
 -       * to get people's attention.
 -       */
 -      if (WARN_ON(connector->encoder))
 -              return -EINVAL;
 -
 -      for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
 -              if (connector->encoder_ids[i] == 0) {
 -                      connector->encoder_ids[i] = encoder->base.id;
 -                      return 0;
 -              }
 -      }
 -      return -ENOMEM;
 -}
 -EXPORT_SYMBOL(drm_mode_connector_attach_encoder);
 -
  /**
   * drm_mode_crtc_set_gamma_size - set the gamma table size
   * @crtc: CRTC to set the gamma table size for
  int drm_mode_page_flip_ioctl(struct drm_device *dev,
                             void *data, struct drm_file *file_priv)
  {
-       struct drm_mode_crtc_page_flip *page_flip = data;
+       struct drm_mode_crtc_page_flip_target *page_flip = data;
        struct drm_crtc *crtc;
        struct drm_framebuffer *fb = NULL;
        struct drm_pending_vblank_event *e = NULL;
+       u32 target_vblank = page_flip->sequence;
        int ret = -EINVAL;
  
-       if (page_flip->flags & ~DRM_MODE_PAGE_FLIP_FLAGS ||
-           page_flip->reserved != 0)
+       if (page_flip->flags & ~DRM_MODE_PAGE_FLIP_FLAGS)
+               return -EINVAL;
+       if (page_flip->sequence != 0 && !(page_flip->flags & DRM_MODE_PAGE_FLIP_TARGET))
+               return -EINVAL;
+       /* Only one of the DRM_MODE_PAGE_FLIP_TARGET_ABSOLUTE/RELATIVE flags
+        * can be specified
+        */
+       if ((page_flip->flags & DRM_MODE_PAGE_FLIP_TARGET) == DRM_MODE_PAGE_FLIP_TARGET)
                return -EINVAL;
  
        if ((page_flip->flags & DRM_MODE_PAGE_FLIP_ASYNC) && !dev->mode_config.async_page_flip)
        if (!crtc)
                return -ENOENT;
  
+       if (crtc->funcs->page_flip_target) {
+               u32 current_vblank;
+               int r;
+               r = drm_crtc_vblank_get(crtc);
+               if (r)
+                       return r;
+               current_vblank = drm_crtc_vblank_count(crtc);
+               switch (page_flip->flags & DRM_MODE_PAGE_FLIP_TARGET) {
+               case DRM_MODE_PAGE_FLIP_TARGET_ABSOLUTE:
+                       if ((int)(target_vblank - current_vblank) > 1) {
+                               DRM_DEBUG("Invalid absolute flip target %u, "
+                                         "must be <= %u\n", target_vblank,
+                                         current_vblank + 1);
+                               drm_crtc_vblank_put(crtc);
+                               return -EINVAL;
+                       }
+                       break;
+               case DRM_MODE_PAGE_FLIP_TARGET_RELATIVE:
+                       if (target_vblank != 0 && target_vblank != 1) {
+                               DRM_DEBUG("Invalid relative flip target %u, "
+                                         "must be 0 or 1\n", target_vblank);
+                               drm_crtc_vblank_put(crtc);
+                               return -EINVAL;
+                       }
+                       target_vblank += current_vblank;
+                       break;
+               default:
+                       target_vblank = current_vblank +
+                               !(page_flip->flags & DRM_MODE_PAGE_FLIP_ASYNC);
+                       break;
+               }
+       } else if (crtc->funcs->page_flip == NULL ||
+                  (page_flip->flags & DRM_MODE_PAGE_FLIP_TARGET)) {
+               return -EINVAL;
+       }
        drm_modeset_lock_crtc(crtc, crtc->primary);
        if (crtc->primary->fb == NULL) {
                /* The framebuffer is currently unbound, presumably
                goto out;
        }
  
-       if (crtc->funcs->page_flip == NULL)
-               goto out;
        fb = drm_framebuffer_lookup(dev, page_flip->fb_id);
        if (!fb) {
                ret = -ENOENT;
        }
  
        crtc->primary->old_fb = crtc->primary->fb;
-       ret = crtc->funcs->page_flip(crtc, fb, e, page_flip->flags);
+       if (crtc->funcs->page_flip_target)
+               ret = crtc->funcs->page_flip_target(crtc, fb, e,
+                                                   page_flip->flags,
+                                                   target_vblank);
+       else
+               ret = crtc->funcs->page_flip(crtc, fb, e, page_flip->flags);
        if (ret) {
                if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT)
                        drm_event_cancel_free(dev, &e->base);
        }
  
  out:
+       if (ret)
+               drm_crtc_vblank_put(crtc);
        if (fb)
                drm_framebuffer_unreference(fb);
        if (crtc->primary->old_fb)
@@@ -3726,9 -5696,9 +3778,9 @@@ int drm_mode_destroy_dumb_ioctl(struct 
   * Eg. if the hardware supports everything except DRM_REFLECT_X
   * one could call this function like this:
   *
 - * drm_rotation_simplify(rotation, BIT(DRM_ROTATE_0) |
 - *                       BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_180) |
 - *                       BIT(DRM_ROTATE_270) | BIT(DRM_REFLECT_Y));
 + * drm_rotation_simplify(rotation, DRM_ROTATE_0 |
 + *                       DRM_ROTATE_90 | DRM_ROTATE_180 |
 + *                       DRM_ROTATE_270 | DRM_REFLECT_Y);
   *
   * to eliminate the DRM_ROTATE_X flag. Depending on what kind of
   * transforms the hardware supports, this function may not
@@@ -3739,7 -5709,7 +3791,7 @@@ unsigned int drm_rotation_simplify(unsi
                                   unsigned int supported_rotations)
  {
        if (rotation & ~supported_rotations) {
 -              rotation ^= BIT(DRM_REFLECT_X) | BIT(DRM_REFLECT_Y);
 +              rotation ^= DRM_REFLECT_X | DRM_REFLECT_Y;
                rotation = (rotation & DRM_REFLECT_MASK) |
                           BIT((ffs(rotation & DRM_ROTATE_MASK) + 1) % 4);
        }
@@@ -3868,12 -5838,12 +3920,12 @@@ struct drm_property *drm_mode_create_ro
                                                       unsigned int supported_rotations)
  {
        static const struct drm_prop_enum_list props[] = {
 -              { DRM_ROTATE_0,   "rotate-0" },
 -              { DRM_ROTATE_90,  "rotate-90" },
 -              { DRM_ROTATE_180, "rotate-180" },
 -              { DRM_ROTATE_270, "rotate-270" },
 -              { DRM_REFLECT_X,  "reflect-x" },
 -              { DRM_REFLECT_Y,  "reflect-y" },
 +              { __builtin_ffs(DRM_ROTATE_0) - 1,   "rotate-0" },
 +              { __builtin_ffs(DRM_ROTATE_90) - 1,  "rotate-90" },
 +              { __builtin_ffs(DRM_ROTATE_180) - 1, "rotate-180" },
 +              { __builtin_ffs(DRM_ROTATE_270) - 1, "rotate-270" },
 +              { __builtin_ffs(DRM_REFLECT_X) - 1,  "reflect-x" },
 +              { __builtin_ffs(DRM_REFLECT_Y) - 1,  "reflect-y" },
        };
  
        return drm_property_create_bitmask(dev, 0, "rotation",
index bb51ee97956d912482768ae74f95f7c00de304df,0099d2a4d6180d2f6025250e5cb933cf360a236e..12b7753a0d27b619f65663c6edb84fb0c38dd45c
@@@ -228,6 -228,7 +228,7 @@@ static int drm_getstats(struct drm_devi
  static int drm_getcap(struct drm_device *dev, void *data, struct drm_file *file_priv)
  {
        struct drm_get_cap *req = data;
+       struct drm_crtc *crtc;
  
        req->value = 0;
        switch (req->capability) {
        case DRM_CAP_ASYNC_PAGE_FLIP:
                req->value = dev->mode_config.async_page_flip;
                break;
+       case DRM_CAP_PAGE_FLIP_TARGET:
+               req->value = 1;
+               drm_for_each_crtc(crtc, dev) {
+                       if (!crtc->funcs->page_flip_target)
+                               req->value = 0;
+               }
+               break;
        case DRM_CAP_CURSOR_WIDTH:
                if (dev->mode_config.cursor_width)
                        req->value = dev->mode_config.cursor_width;
@@@ -714,9 -722,9 +722,9 @@@ long drm_ioctl(struct file *filp
        if (ksize > in_size)
                memset(kdata + in_size, 0, ksize - in_size);
  
 -      /* Enforce sane locking for kms driver ioctls. Core ioctls are
 +      /* Enforce sane locking for modern driver ioctls. Core ioctls are
         * too messy still. */
 -      if ((drm_core_check_feature(dev, DRIVER_MODESET) && is_driver_ioctl) ||
 +      if ((!drm_core_check_feature(dev, DRIVER_LEGACY) && is_driver_ioctl) ||
            (ioctl->flags & DRM_UNLOCKED))
                retcode = func(dev, kdata, file_priv);
        else {
index a89c4803aced8039cc53d7f60136ef990c899291,2029e35d50a4f4dbeaaddb687a5be7fd9a6e12b0..4824f70b0258e856f1d613867de1627af70eda34
@@@ -1154,7 -1154,6 +1154,7 @@@ static int dce4_crtc_do_set_base(struc
        u32 tmp, viewport_w, viewport_h;
        int r;
        bool bypass_lut = false;
 +      char *format_name;
  
        /* no fb bound */
        if (!atomic && !crtc->primary->fb) {
                bypass_lut = true;
                break;
        default:
 -              DRM_ERROR("Unsupported screen format %s\n",
 -                        drm_get_format_name(target_fb->pixel_format));
 +              format_name = drm_get_format_name(target_fb->pixel_format);
 +              DRM_ERROR("Unsupported screen format %s\n", format_name);
 +              kfree(format_name);
                return -EINVAL;
        }
  
        WREG32(EVERGREEN_VIEWPORT_SIZE + radeon_crtc->crtc_offset,
               (viewport_w << 16) | viewport_h);
  
-       /* set pageflip to happen only at start of vblank interval (front porch) */
-       WREG32(EVERGREEN_MASTER_UPDATE_MODE + radeon_crtc->crtc_offset, 3);
+       /* set pageflip to happen anywhere in vblank interval */
+       WREG32(EVERGREEN_MASTER_UPDATE_MODE + radeon_crtc->crtc_offset, 0);
  
        if (!atomic && fb && fb != crtc->primary->fb) {
                radeon_fb = to_radeon_framebuffer(fb);
@@@ -1471,7 -1469,6 +1471,7 @@@ static int avivo_crtc_do_set_base(struc
        u32 viewport_w, viewport_h;
        int r;
        bool bypass_lut = false;
 +      char *format_name;
  
        /* no fb bound */
        if (!atomic && !crtc->primary->fb) {
                bypass_lut = true;
                break;
        default:
 -              DRM_ERROR("Unsupported screen format %s\n",
 -                        drm_get_format_name(target_fb->pixel_format));
 +              format_name = drm_get_format_name(target_fb->pixel_format);
 +              DRM_ERROR("Unsupported screen format %s\n", format_name);
 +              kfree(format_name);
                return -EINVAL;
        }
  
        WREG32(AVIVO_D1MODE_VIEWPORT_SIZE + radeon_crtc->crtc_offset,
               (viewport_w << 16) | viewport_h);
  
-       /* set pageflip to happen only at start of vblank interval (front porch) */
-       WREG32(AVIVO_D1MODE_MASTER_UPDATE_MODE + radeon_crtc->crtc_offset, 3);
+       /* set pageflip to happen anywhere in vblank interval */
+       WREG32(AVIVO_D1MODE_MASTER_UPDATE_MODE + radeon_crtc->crtc_offset, 0);
  
        if (!atomic && fb && fb != crtc->primary->fb) {
                radeon_fb = to_radeon_framebuffer(fb);
index 90f2ff217b3123e70ed17b6d0ed34c17eadd527e,8faa4d55d0600e534092bfb1dd87f4d034d6a932..07e44931f1f1a2ba20769c4a64f3e9cdb592e854
@@@ -39,7 -39,6 +39,7 @@@
  #include <linux/pm_runtime.h>
  #include <linux/vga_switcheroo.h>
  #include <drm/drm_gem.h>
 +#include <drm/drm_fb_helper.h>
  
  #include "drm_crtc_helper.h"
  #include "radeon_kfd.h"
   *   2.44.0 - SET_APPEND_CNT packet3 support
   *   2.45.0 - Allow setting shader registers using DMA/COPY packet3 on SI
   *   2.46.0 - Add PFP_SYNC_ME support on evergreen
+  *   2.47.0 - Add UVD_NO_OP register support
   */
  #define KMS_DRIVER_MAJOR      2
- #define KMS_DRIVER_MINOR      46
+ #define KMS_DRIVER_MINOR      47
  #define KMS_DRIVER_PATCHLEVEL 0
  int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags);
  int radeon_driver_unload_kms(struct drm_device *dev);
@@@ -325,7 -325,7 +326,7 @@@ static int radeon_kick_out_firmware_fb(
  #ifdef CONFIG_X86
        primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
  #endif
 -      remove_conflicting_framebuffers(ap, "radeondrmfb", primary);
 +      drm_fb_helper_remove_conflicting_framebuffers(ap, "radeondrmfb", primary);
        kfree(ap);
  
        return 0;
diff --combined include/drm/drm_crtc.h
index 3fa0275e509f8ddfb9f7bb2a591f07a0572d9e43,3c90563e1a546ffc13a1e6e55202eb84c17d59e9..7c8a77b181c2e0f14801eeba4a851877ca49ae77
  #include <uapi/drm/drm_mode.h>
  #include <uapi/drm/drm_fourcc.h>
  #include <drm/drm_modeset_lock.h>
 +#include <drm/drm_rect.h>
 +#include <drm/drm_modeset.h>
 +#include <drm/drm_framebuffer.h>
 +#include <drm/drm_modes.h>
 +#include <drm/drm_connector.h>
  
  struct drm_device;
  struct drm_mode_set;
 -struct drm_framebuffer;
 -struct drm_object_properties;
  struct drm_file;
  struct drm_clip_rect;
  struct device_node;
  struct fence;
  struct edid;
  
 -struct drm_mode_object {
 -      uint32_t id;
 -      uint32_t type;
 -      struct drm_object_properties *properties;
 -      struct kref refcount;
 -      void (*free_cb)(struct kref *kref);
 -};
 -
 -#define DRM_OBJECT_MAX_PROPERTY 24
 -struct drm_object_properties {
 -      int count, atomic_count;
 -      /* NOTE: if we ever start dynamically destroying properties (ie.
 -       * not at drm_mode_config_cleanup() time), then we'd have to do
 -       * a better job of detaching property from mode objects to avoid
 -       * dangling property pointers:
 -       */
 -      struct drm_property *properties[DRM_OBJECT_MAX_PROPERTY];
 -      /* do not read/write values directly, but use drm_object_property_get_value()
 -       * and drm_object_property_set_value():
 -       */
 -      uint64_t values[DRM_OBJECT_MAX_PROPERTY];
 -};
 -
  static inline int64_t U642I64(uint64_t val)
  {
        return (int64_t)*((int64_t *)&val);
@@@ -63,15 -83,78 +63,15 @@@ static inline uint64_t I642U64(int64_t 
   * specified amount in degrees in counter clockwise direction. DRM_REFLECT_X and
   * DRM_REFLECT_Y reflects the image along the specified axis prior to rotation
   */
 -#define DRM_ROTATE_MASK 0x0f
 -#define DRM_ROTATE_0  0
 -#define DRM_ROTATE_90 1
 -#define DRM_ROTATE_180        2
 -#define DRM_ROTATE_270        3
 -#define DRM_REFLECT_MASK (~DRM_ROTATE_MASK)
 -#define DRM_REFLECT_X 4
 -#define DRM_REFLECT_Y 5
 -
 -enum drm_connector_force {
 -      DRM_FORCE_UNSPECIFIED,
 -      DRM_FORCE_OFF,
 -      DRM_FORCE_ON,         /* force on analog part normally */
 -      DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
 -};
 -
 -#include <drm/drm_modes.h>
 -
 -enum drm_connector_status {
 -      connector_status_connected = 1,
 -      connector_status_disconnected = 2,
 -      connector_status_unknown = 3,
 -};
 -
 -enum subpixel_order {
 -      SubPixelUnknown = 0,
 -      SubPixelHorizontalRGB,
 -      SubPixelHorizontalBGR,
 -      SubPixelVerticalRGB,
 -      SubPixelVerticalBGR,
 -      SubPixelNone,
 -};
 -
 -#define DRM_COLOR_FORMAT_RGB444               (1<<0)
 -#define DRM_COLOR_FORMAT_YCRCB444     (1<<1)
 -#define DRM_COLOR_FORMAT_YCRCB422     (1<<2)
 -
 -#define DRM_BUS_FLAG_DE_LOW           (1<<0)
 -#define DRM_BUS_FLAG_DE_HIGH          (1<<1)
 -/* drive data on pos. edge */
 -#define DRM_BUS_FLAG_PIXDATA_POSEDGE  (1<<2)
 -/* drive data on neg. edge */
 -#define DRM_BUS_FLAG_PIXDATA_NEGEDGE  (1<<3)
 -
 -/*
 - * Describes a given display (e.g. CRT or flat panel) and its limitations.
 - */
 -struct drm_display_info {
 -      char name[DRM_DISPLAY_INFO_LEN];
 -
 -      /* Physical size */
 -        unsigned int width_mm;
 -      unsigned int height_mm;
 -
 -      /* Clock limits FIXME: storage format */
 -      unsigned int min_vfreq, max_vfreq;
 -      unsigned int min_hfreq, max_hfreq;
 -      unsigned int pixel_clock;
 -      unsigned int bpc;
 -
 -      enum subpixel_order subpixel_order;
 -      u32 color_formats;
 -
 -      const u32 *bus_formats;
 -      unsigned int num_bus_formats;
 -      u32 bus_flags;
 -
 -      /* Mask of supported hdmi deep color modes */
 -      u8 edid_hdmi_dc_modes;
 -
 -      u8 cea_rev;
 -};
 +#define DRM_ROTATE_0  BIT(0)
 +#define DRM_ROTATE_90 BIT(1)
 +#define DRM_ROTATE_180        BIT(2)
 +#define DRM_ROTATE_270        BIT(3)
 +#define DRM_ROTATE_MASK (DRM_ROTATE_0   | DRM_ROTATE_90 | \
 +                       DRM_ROTATE_180 | DRM_ROTATE_270)
 +#define DRM_REFLECT_X BIT(4)
 +#define DRM_REFLECT_Y BIT(5)
 +#define DRM_REFLECT_MASK (DRM_REFLECT_X | DRM_REFLECT_Y)
  
  /* data corresponds to displayid vend/prod/serial */
  struct drm_tile_group {
        u8 group_data[8];
  };
  
 -/**
 - * struct drm_framebuffer_funcs - framebuffer hooks
 - */
 -struct drm_framebuffer_funcs {
 -      /**
 -       * @destroy:
 -       *
 -       * Clean up framebuffer resources, specifically also unreference the
 -       * backing storage. The core guarantees to call this function for every
 -       * framebuffer successfully created by ->fb_create() in
 -       * &drm_mode_config_funcs. Drivers must also call
 -       * drm_framebuffer_cleanup() to release DRM core resources for this
 -       * framebuffer.
 -       */
 -      void (*destroy)(struct drm_framebuffer *framebuffer);
 -
 -      /**
 -       * @create_handle:
 -       *
 -       * Create a buffer handle in the driver-specific buffer manager (either
 -       * GEM or TTM) valid for the passed-in struct &drm_file. This is used by
 -       * the core to implement the GETFB IOCTL, which returns (for
 -       * sufficiently priviledged user) also a native buffer handle. This can
 -       * be used for seamless transitions between modesetting clients by
 -       * copying the current screen contents to a private buffer and blending
 -       * between that and the new contents.
 -       *
 -       * GEM based drivers should call drm_gem_handle_create() to create the
 -       * handle.
 -       *
 -       * RETURNS:
 -       *
 -       * 0 on success or a negative error code on failure.
 -       */
 -      int (*create_handle)(struct drm_framebuffer *fb,
 -                           struct drm_file *file_priv,
 -                           unsigned int *handle);
 -      /**
 -       * @dirty:
 -       *
 -       * Optional callback for the dirty fb IOCTL.
 -       *
 -       * Userspace can notify the driver via this callback that an area of the
 -       * framebuffer has changed and should be flushed to the display
 -       * hardware. This can also be used internally, e.g. by the fbdev
 -       * emulation, though that's not the case currently.
 -       *
 -       * See documentation in drm_mode.h for the struct drm_mode_fb_dirty_cmd
 -       * for more information as all the semantics and arguments have a one to
 -       * one mapping on this function.
 -       *
 -       * RETURNS:
 -       *
 -       * 0 on success or a negative error code on failure.
 -       */
 -      int (*dirty)(struct drm_framebuffer *framebuffer,
 -                   struct drm_file *file_priv, unsigned flags,
 -                   unsigned color, struct drm_clip_rect *clips,
 -                   unsigned num_clips);
 -};
 -
 -struct drm_framebuffer {
 -      struct drm_device *dev;
 -      /*
 -       * Note that the fb is refcounted for the benefit of driver internals,
 -       * for example some hw, disabling a CRTC/plane is asynchronous, and
 -       * scanout does not actually complete until the next vblank.  So some
 -       * cleanup (like releasing the reference(s) on the backing GEM bo(s))
 -       * should be deferred.  In cases like this, the driver would like to
 -       * hold a ref to the fb even though it has already been removed from
 -       * userspace perspective.
 -       * The refcount is stored inside the mode object.
 -       */
 -      /*
 -       * Place on the dev->mode_config.fb_list, access protected by
 -       * dev->mode_config.fb_lock.
 -       */
 -      struct list_head head;
 -      struct drm_mode_object base;
 -      const struct drm_framebuffer_funcs *funcs;
 -      unsigned int pitches[4];
 -      unsigned int offsets[4];
 -      uint64_t modifier[4];
 -      unsigned int width;
 -      unsigned int height;
 -      /* depth can be 15 or 16 */
 -      unsigned int depth;
 -      int bits_per_pixel;
 -      int flags;
 -      uint32_t pixel_format; /* fourcc format */
 -      int hot_x;
 -      int hot_y;
 -      struct list_head filp_head;
 -};
 -
  struct drm_property_blob {
        struct drm_mode_object base;
        struct drm_device *dev;
@@@ -109,6 -287,7 +109,6 @@@ struct drm_property 
  };
  
  struct drm_crtc;
 -struct drm_connector;
  struct drm_encoder;
  struct drm_pending_vblank_event;
  struct drm_plane;
@@@ -117,6 -296,7 +117,6 @@@ struct drm_atomic_state
  
  struct drm_crtc_helper_funcs;
  struct drm_encoder_helper_funcs;
 -struct drm_connector_helper_funcs;
  struct drm_plane_helper_funcs;
  
  /**
@@@ -365,6 -545,16 +365,6 @@@ struct drm_crtc_funcs 
         * counter and timestamp tracking though, e.g. if they have accurate
         * timestamp registers in hardware.
         *
 -       * FIXME:
 -       *
 -       * Up to that point drivers need to manage events themselves and can use
 -       * even->base.list freely for that. Specifically they need to ensure
 -       * that they don't send out page flip (or vblank) events for which the
 -       * corresponding drm file has been closed already. The drm core
 -       * unfortunately does not (yet) take care of that. Therefore drivers
 -       * currently must clean up and release pending events in their
 -       * ->preclose driver function.
 -       *
         * This callback is optional.
         *
         * NOTE:
                         struct drm_pending_vblank_event *event,
                         uint32_t flags);
  
+       /**
+        * @page_flip_target:
+        *
+        * Same as @page_flip but with an additional parameter specifying the
+        * absolute target vertical blank period (as reported by
+        * drm_crtc_vblank_count()) when the flip should take effect.
+        *
+        * Note that the core code calls drm_crtc_vblank_get before this entry
+        * point, and will call drm_crtc_vblank_put if this entry point returns
+        * any non-0 error code. It's the driver's responsibility to call
+        * drm_crtc_vblank_put after this entry point returns 0, typically when
+        * the flip completes.
+        */
+       int (*page_flip_target)(struct drm_crtc *crtc,
+                               struct drm_framebuffer *fb,
+                               struct drm_pending_vblank_event *event,
+                               uint32_t flags, uint32_t target);
        /**
         * @set_property:
         *
@@@ -661,6 -869,291 +679,6 @@@ struct drm_crtc 
        struct drm_modeset_acquire_ctx *acquire_ctx;
  };
  
 -/**
 - * struct drm_connector_state - mutable connector state
 - * @connector: backpointer to the connector
 - * @crtc: CRTC to connect connector to, NULL if disabled
 - * @best_encoder: can be used by helpers and drivers to select the encoder
 - * @state: backpointer to global drm_atomic_state
 - */
 -struct drm_connector_state {
 -      struct drm_connector *connector;
 -
 -      struct drm_crtc *crtc;  /* do not write directly, use drm_atomic_set_crtc_for_connector() */
 -
 -      struct drm_encoder *best_encoder;
 -
 -      struct drm_atomic_state *state;
 -};
 -
 -/**
 - * struct drm_connector_funcs - control connectors on a given device
 - *
 - * Each CRTC may have one or more connectors attached to it.  The functions
 - * below allow the core DRM code to control connectors, enumerate available modes,
 - * etc.
 - */
 -struct drm_connector_funcs {
 -      /**
 -       * @dpms:
 -       *
 -       * Legacy entry point to set the per-connector DPMS state. Legacy DPMS
 -       * is exposed as a standard property on the connector, but diverted to
 -       * this callback in the drm core. Note that atomic drivers don't
 -       * implement the 4 level DPMS support on the connector any more, but
 -       * instead only have an on/off "ACTIVE" property on the CRTC object.
 -       *
 -       * Drivers implementing atomic modeset should use
 -       * drm_atomic_helper_connector_dpms() to implement this hook.
 -       *
 -       * RETURNS:
 -       *
 -       * 0 on success or a negative error code on failure.
 -       */
 -      int (*dpms)(struct drm_connector *connector, int mode);
 -
 -      /**
 -       * @reset:
 -       *
 -       * Reset connector hardware and software state to off. This function isn't
 -       * called by the core directly, only through drm_mode_config_reset().
 -       * It's not a helper hook only for historical reasons.
 -       *
 -       * Atomic drivers can use drm_atomic_helper_connector_reset() to reset
 -       * atomic state using this hook.
 -       */
 -      void (*reset)(struct drm_connector *connector);
 -
 -      /**
 -       * @detect:
 -       *
 -       * Check to see if anything is attached to the connector. The parameter
 -       * force is set to false whilst polling, true when checking the
 -       * connector due to a user request. force can be used by the driver to
 -       * avoid expensive, destructive operations during automated probing.
 -       *
 -       * FIXME:
 -       *
 -       * Note that this hook is only called by the probe helper. It's not in
 -       * the helper library vtable purely for historical reasons. The only DRM
 -       * core entry point to probe connector state is @fill_modes.
 -       *
 -       * RETURNS:
 -       *
 -       * drm_connector_status indicating the connector's status.
 -       */
 -      enum drm_connector_status (*detect)(struct drm_connector *connector,
 -                                          bool force);
 -
 -      /**
 -       * @force:
 -       *
 -       * This function is called to update internal encoder state when the
 -       * connector is forced to a certain state by userspace, either through
 -       * the sysfs interfaces or on the kernel cmdline. In that case the
 -       * @detect callback isn't called.
 -       *
 -       * FIXME:
 -       *
 -       * Note that this hook is only called by the probe helper. It's not in
 -       * the helper library vtable purely for historical reasons. The only DRM
 -       * core entry point to probe connector state is @fill_modes.
 -       */
 -      void (*force)(struct drm_connector *connector);
 -
 -      /**
 -       * @fill_modes:
 -       *
 -       * Entry point for output detection and basic mode validation. The
 -       * driver should reprobe the output if needed (e.g. when hotplug
 -       * handling is unreliable), add all detected modes to connector->modes
 -       * and filter out any the device can't support in any configuration. It
 -       * also needs to filter out any modes wider or higher than the
 -       * parameters max_width and max_height indicate.
 -       *
 -       * The drivers must also prune any modes no longer valid from
 -       * connector->modes. Furthermore it must update connector->status and
 -       * connector->edid.  If no EDID has been received for this output
 -       * connector->edid must be NULL.
 -       *
 -       * Drivers using the probe helpers should use
 -       * drm_helper_probe_single_connector_modes() or
 -       * drm_helper_probe_single_connector_modes_nomerge() to implement this
 -       * function.
 -       *
 -       * RETURNS:
 -       *
 -       * The number of modes detected and filled into connector->modes.
 -       */
 -      int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
 -
 -      /**
 -       * @set_property:
 -       *
 -       * This is the legacy entry point to update a property attached to the
 -       * connector.
 -       *
 -       * Drivers implementing atomic modeset should use
 -       * drm_atomic_helper_connector_set_property() to implement this hook.
 -       *
 -       * This callback is optional if the driver does not support any legacy
 -       * driver-private properties.
 -       *
 -       * RETURNS:
 -       *
 -       * 0 on success or a negative error code on failure.
 -       */
 -      int (*set_property)(struct drm_connector *connector, struct drm_property *property,
 -                           uint64_t val);
 -
 -      /**
 -       * @late_register:
 -       *
 -       * This optional hook can be used to register additional userspace
 -       * interfaces attached to the connector, light backlight control, i2c,
 -       * DP aux or similar interfaces. It is called late in the driver load
 -       * sequence from drm_connector_register() when registering all the
 -       * core drm connector interfaces. Everything added from this callback
 -       * should be unregistered in the early_unregister callback.
 -       *
 -       * Returns:
 -       *
 -       * 0 on success, or a negative error code on failure.
 -       */
 -      int (*late_register)(struct drm_connector *connector);
 -
 -      /**
 -       * @early_unregister:
 -       *
 -       * This optional hook should be used to unregister the additional
 -       * userspace interfaces attached to the connector from
 -       * late_unregister(). It is called from drm_connector_unregister(),
 -       * early in the driver unload sequence to disable userspace access
 -       * before data structures are torndown.
 -       */
 -      void (*early_unregister)(struct drm_connector *connector);
 -
 -      /**
 -       * @destroy:
 -       *
 -       * Clean up connector resources. This is called at driver unload time
 -       * through drm_mode_config_cleanup(). It can also be called at runtime
 -       * when a connector is being hot-unplugged for drivers that support
 -       * connector hotplugging (e.g. DisplayPort MST).
 -       */
 -      void (*destroy)(struct drm_connector *connector);
 -
 -      /**
 -       * @atomic_duplicate_state:
 -       *
 -       * Duplicate the current atomic state for this connector and return it.
 -       * The core and helpers gurantee that any atomic state duplicated with
 -       * this hook and still owned by the caller (i.e. not transferred to the
 -       * driver by calling ->atomic_commit() from struct
 -       * &drm_mode_config_funcs) will be cleaned up by calling the
 -       * @atomic_destroy_state hook in this structure.
 -       *
 -       * Atomic drivers which don't subclass struct &drm_connector_state should use
 -       * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the
 -       * state structure to extend it with driver-private state should use
 -       * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is
 -       * duplicated in a consistent fashion across drivers.
 -       *
 -       * It is an error to call this hook before connector->state has been
 -       * initialized correctly.
 -       *
 -       * NOTE:
 -       *
 -       * If the duplicate state references refcounted resources this hook must
 -       * acquire a reference for each of them. The driver must release these
 -       * references again in @atomic_destroy_state.
 -       *
 -       * RETURNS:
 -       *
 -       * Duplicated atomic state or NULL when the allocation failed.
 -       */
 -      struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
 -
 -      /**
 -       * @atomic_destroy_state:
 -       *
 -       * Destroy a state duplicated with @atomic_duplicate_state and release
 -       * or unreference all resources it references
 -       */
 -      void (*atomic_destroy_state)(struct drm_connector *connector,
 -                                   struct drm_connector_state *state);
 -
 -      /**
 -       * @atomic_set_property:
 -       *
 -       * Decode a driver-private property value and store the decoded value
 -       * into the passed-in state structure. Since the atomic core decodes all
 -       * standardized properties (even for extensions beyond the core set of
 -       * properties which might not be implemented by all drivers) this
 -       * requires drivers to subclass the state structure.
 -       *
 -       * Such driver-private properties should really only be implemented for
 -       * truly hardware/vendor specific state. Instead it is preferred to
 -       * standardize atomic extension and decode the properties used to expose
 -       * such an extension in the core.
 -       *
 -       * Do not call this function directly, use
 -       * drm_atomic_connector_set_property() instead.
 -       *
 -       * This callback is optional if the driver does not support any
 -       * driver-private atomic properties.
 -       *
 -       * NOTE:
 -       *
 -       * This function is called in the state assembly phase of atomic
 -       * modesets, which can be aborted for any reason (including on
 -       * userspace's request to just check whether a configuration would be
 -       * possible). Drivers MUST NOT touch any persistent state (hardware or
 -       * software) or data structures except the passed in @state parameter.
 -       *
 -       * Also since userspace controls in which order properties are set this
 -       * function must not do any input validation (since the state update is
 -       * incomplete and hence likely inconsistent). Instead any such input
 -       * validation must be done in the various atomic_check callbacks.
 -       *
 -       * RETURNS:
 -       *
 -       * 0 if the property has been found, -EINVAL if the property isn't
 -       * implemented by the driver (which shouldn't ever happen, the core only
 -       * asks for properties attached to this connector). No other validation
 -       * is allowed by the driver. The core already checks that the property
 -       * value is within the range (integer, valid enum value, ...) the driver
 -       * set when registering the property.
 -       */
 -      int (*atomic_set_property)(struct drm_connector *connector,
 -                                 struct drm_connector_state *state,
 -                                 struct drm_property *property,
 -                                 uint64_t val);
 -
 -      /**
 -       * @atomic_get_property:
 -       *
 -       * Reads out the decoded driver-private property. This is used to
 -       * implement the GETCONNECTOR IOCTL.
 -       *
 -       * Do not call this function directly, use
 -       * drm_atomic_connector_get_property() instead.
 -       *
 -       * This callback is optional if the driver does not support any
 -       * driver-private atomic properties.
 -       *
 -       * RETURNS:
 -       *
 -       * 0 on success, -EINVAL if the property isn't implemented by the
 -       * driver (which shouldn't ever happen, the core only asks for
 -       * properties attached to this connector).
 -       */
 -      int (*atomic_get_property)(struct drm_connector *connector,
 -                                 const struct drm_connector_state *state,
 -                                 struct drm_property *property,
 -                                 uint64_t *val);
 -};
 -
  /**
   * struct drm_encoder_funcs - encoder controls
   *
@@@ -712,13 -1205,15 +730,13 @@@ struct drm_encoder_funcs 
        void (*early_unregister)(struct drm_encoder *encoder);
  };
  
 -#define DRM_CONNECTOR_MAX_ENCODER 3
 -
  /**
   * struct drm_encoder - central DRM encoder structure
   * @dev: parent DRM device
   * @head: list management
   * @base: base KMS object
   * @name: human readable name, can be overwritten by the driver
 - * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
 + * @encoder_type: one of the DRM_MODE_ENCODER_<foo> types in drm_mode.h
   * @possible_crtcs: bitmask of potential CRTC bindings
   * @possible_clones: bitmask of potential sibling encoders for cloning
   * @crtc: currently bound CRTC
@@@ -752,6 -1247,171 +770,6 @@@ struct drm_encoder 
        const struct drm_encoder_helper_funcs *helper_private;
  };
  
 -/* should we poll this connector for connects and disconnects */
 -/* hot plug detectable */
 -#define DRM_CONNECTOR_POLL_HPD (1 << 0)
 -/* poll for connections */
 -#define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
 -/* can cleanly poll for disconnections without flickering the screen */
 -/* DACs should rarely do this without a lot of testing */
 -#define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
 -
 -#define MAX_ELD_BYTES 128
 -
 -/**
 - * struct drm_connector - central DRM connector control structure
 - * @dev: parent DRM device
 - * @kdev: kernel device for sysfs attributes
 - * @attr: sysfs attributes
 - * @head: list management
 - * @base: base KMS object
 - * @name: human readable name, can be overwritten by the driver
 - * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
 - * @connector_type_id: index into connector type enum
 - * @interlace_allowed: can this connector handle interlaced modes?
 - * @doublescan_allowed: can this connector handle doublescan?
 - * @stereo_allowed: can this connector handle stereo modes?
 - * @registered: is this connector exposed (registered) with userspace?
 - * @modes: modes available on this connector (from fill_modes() + user)
 - * @status: one of the drm_connector_status enums (connected, not, or unknown)
 - * @probed_modes: list of modes derived directly from the display
 - * @display_info: information about attached display (e.g. from EDID)
 - * @funcs: connector control functions
 - * @edid_blob_ptr: DRM property containing EDID if present
 - * @properties: property tracking for this connector
 - * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
 - * @dpms: current dpms state
 - * @helper_private: mid-layer private data
 - * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
 - * @force: a %DRM_FORCE_<foo> state for forced mode sets
 - * @override_edid: has the EDID been overwritten through debugfs for testing?
 - * @encoder_ids: valid encoders for this connector
 - * @encoder: encoder driving this connector, if any
 - * @eld: EDID-like data, if present
 - * @dvi_dual: dual link DVI, if found
 - * @max_tmds_clock: max clock rate, if found
 - * @latency_present: AV delay info from ELD, if found
 - * @video_latency: video latency info from ELD, if found
 - * @audio_latency: audio latency info from ELD, if found
 - * @null_edid_counter: track sinks that give us all zeros for the EDID
 - * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
 - * @edid_corrupt: indicates whether the last read EDID was corrupt
 - * @debugfs_entry: debugfs directory for this connector
 - * @state: current atomic state for this connector
 - * @has_tile: is this connector connected to a tiled monitor
 - * @tile_group: tile group for the connected monitor
 - * @tile_is_single_monitor: whether the tile is one monitor housing
 - * @num_h_tile: number of horizontal tiles in the tile group
 - * @num_v_tile: number of vertical tiles in the tile group
 - * @tile_h_loc: horizontal location of this tile
 - * @tile_v_loc: vertical location of this tile
 - * @tile_h_size: horizontal size of this tile.
 - * @tile_v_size: vertical size of this tile.
 - *
 - * Each connector may be connected to one or more CRTCs, or may be clonable by
 - * another connector if they can share a CRTC.  Each connector also has a specific
 - * position in the broader display (referred to as a 'screen' though it could
 - * span multiple monitors).
 - */
 -struct drm_connector {
 -      struct drm_device *dev;
 -      struct device *kdev;
 -      struct device_attribute *attr;
 -      struct list_head head;
 -
 -      struct drm_mode_object base;
 -
 -      char *name;
 -
 -      /**
 -       * @index: Compacted connector index, which matches the position inside
 -       * the mode_config.list for drivers not supporting hot-add/removing. Can
 -       * be used as an array index. It is invariant over the lifetime of the
 -       * connector.
 -       */
 -      unsigned index;
 -
 -      int connector_type;
 -      int connector_type_id;
 -      bool interlace_allowed;
 -      bool doublescan_allowed;
 -      bool stereo_allowed;
 -      bool registered;
 -      struct list_head modes; /* list of modes on this connector */
 -
 -      enum drm_connector_status status;
 -
 -      /* these are modes added by probing with DDC or the BIOS */
 -      struct list_head probed_modes;
 -
 -      struct drm_display_info display_info;
 -      const struct drm_connector_funcs *funcs;
 -
 -      struct drm_property_blob *edid_blob_ptr;
 -      struct drm_object_properties properties;
 -
 -      /**
 -       * @path_blob_ptr:
 -       *
 -       * DRM blob property data for the DP MST path property.
 -       */
 -      struct drm_property_blob *path_blob_ptr;
 -
 -      /**
 -       * @tile_blob_ptr:
 -       *
 -       * DRM blob property data for the tile property (used mostly by DP MST).
 -       * This is meant for screens which are driven through separate display
 -       * pipelines represented by &drm_crtc, which might not be running with
 -       * genlocked clocks. For tiled panels which are genlocked, like
 -       * dual-link LVDS or dual-link DSI, the driver should try to not expose
 -       * the tiling and virtualize both &drm_crtc and &drm_plane if needed.
 -       */
 -      struct drm_property_blob *tile_blob_ptr;
 -
 -      uint8_t polled; /* DRM_CONNECTOR_POLL_* */
 -
 -      /* requested DPMS state */
 -      int dpms;
 -
 -      const struct drm_connector_helper_funcs *helper_private;
 -
 -      /* forced on connector */
 -      struct drm_cmdline_mode cmdline_mode;
 -      enum drm_connector_force force;
 -      bool override_edid;
 -      uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
 -      struct drm_encoder *encoder; /* currently active encoder */
 -
 -      /* EDID bits */
 -      uint8_t eld[MAX_ELD_BYTES];
 -      bool dvi_dual;
 -      int max_tmds_clock;     /* in MHz */
 -      bool latency_present[2];
 -      int video_latency[2];   /* [0]: progressive, [1]: interlaced */
 -      int audio_latency[2];
 -      int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
 -      unsigned bad_edid_counter;
 -
 -      /* Flag for raw EDID header corruption - used in Displayport
 -       * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6
 -       */
 -      bool edid_corrupt;
 -
 -      struct dentry *debugfs_entry;
 -
 -      struct drm_connector_state *state;
 -
 -      /* DisplayID bits */
 -      bool has_tile;
 -      struct drm_tile_group *tile_group;
 -      bool tile_is_single_monitor;
 -
 -      uint8_t num_h_tile, num_v_tile;
 -      uint8_t tile_h_loc, tile_v_loc;
 -      uint16_t tile_h_size, tile_v_size;
 -};
 -
  /**
   * struct drm_plane_state - mutable plane state
   * @plane: backpointer to the plane
   * @zpos: priority of the given plane on crtc (optional)
   * @normalized_zpos: normalized value of zpos: unique, range from 0 to N-1
   *    where N is the number of active planes for given crtc
 + * @src: clipped source coordinates of the plane (in 16.16)
 + * @dst: clipped destination coordinates of the plane
 + * @visible: visibility of the plane
   * @state: backpointer to global drm_atomic_state
   */
  struct drm_plane_state {
        unsigned int zpos;
        unsigned int normalized_zpos;
  
 +      /* Clipped coordinates */
 +      struct drm_rect src, dst;
 +
 +      /*
 +       * Is the plane actually visible? Can be false even
 +       * if fb!=NULL and crtc!=NULL, due to clipping.
 +       */
 +      bool visible;
 +
        struct drm_atomic_state *state;
  };
  
@@@ -2005,6 -2653,12 +2023,6 @@@ struct drm_mode_config 
         * HDMI infoframe aspect ratio setting.
         */
        struct drm_property *aspect_ratio_property;
 -      /**
 -       * @dirty_info_property: Optional connector property to give userspace a
 -       * hint that the DIRTY_FB ioctl should be used.
 -       */
 -      struct drm_property *dirty_info_property;
 -
        /**
         * @degamma_lut_property: Optional CRTC property to set the LUT used to
         * convert the framebuffer's colors to linear gamma.
                for_each_if ((encoder_mask) & (1 << drm_encoder_index(encoder)))
  
  #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
 -#define obj_to_connector(x) container_of(x, struct drm_connector, base)
  #define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
  #define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
  #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
@@@ -2136,6 -2791,19 +2154,6 @@@ static inline uint32_t drm_crtc_mask(st
        return 1 << drm_crtc_index(crtc);
  }
  
 -int drm_connector_init(struct drm_device *dev,
 -                     struct drm_connector *connector,
 -                     const struct drm_connector_funcs *funcs,
 -                     int connector_type);
 -int drm_connector_register(struct drm_connector *connector);
 -void drm_connector_unregister(struct drm_connector *connector);
 -
 -extern void drm_connector_cleanup(struct drm_connector *connector);
 -static inline unsigned drm_connector_index(struct drm_connector *connector)
 -{
 -      return connector->index;
 -}
 -
  extern __printf(5, 6)
  int drm_encoder_init(struct drm_device *dev,
                     struct drm_encoder *encoder,
@@@ -2204,10 -2872,27 +2222,10 @@@ extern int drm_crtc_force_disable_all(s
  
  extern void drm_encoder_cleanup(struct drm_encoder *encoder);
  
 -extern const char *drm_get_connector_status_name(enum drm_connector_status status);
 -extern const char *drm_get_subpixel_order_name(enum subpixel_order order);
 -extern const char *drm_get_dpms_name(int val);
 -extern const char *drm_get_dvi_i_subconnector_name(int val);
 -extern const char *drm_get_dvi_i_select_name(int val);
 -extern const char *drm_get_tv_subconnector_name(int val);
 -extern const char *drm_get_tv_select_name(int val);
  extern void drm_mode_config_init(struct drm_device *dev);
  extern void drm_mode_config_reset(struct drm_device *dev);
  extern void drm_mode_config_cleanup(struct drm_device *dev);
  
 -extern int drm_mode_connector_set_path_property(struct drm_connector *connector,
 -                                              const char *path);
 -int drm_mode_connector_set_tile_property(struct drm_connector *connector);
 -extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
 -                                                 const struct edid *edid);
 -
 -extern int drm_display_info_set_bus_formats(struct drm_display_info *info,
 -                                          const u32 *formats,
 -                                          unsigned int num_formats);
 -
  static inline bool drm_property_type_is(struct drm_property *property,
                uint32_t type)
  {
@@@ -2223,6 -2908,14 +2241,6 @@@ extern int drm_object_property_set_valu
  extern int drm_object_property_get_value(struct drm_mode_object *obj,
                                         struct drm_property *property,
                                         uint64_t *value);
 -extern int drm_framebuffer_init(struct drm_device *dev,
 -                              struct drm_framebuffer *fb,
 -                              const struct drm_framebuffer_funcs *funcs);
 -extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
 -                                                    uint32_t id);
 -extern void drm_framebuffer_remove(struct drm_framebuffer *fb);
 -extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
 -extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);
  
  extern void drm_object_attach_property(struct drm_mode_object *obj,
                                       struct drm_property *property,
@@@ -2253,17 -2946,22 +2271,17 @@@ struct drm_property_blob *drm_property_
                                                     const void *data);
  struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,
                                                     uint32_t id);
 +int drm_property_replace_global_blob(struct drm_device *dev,
 +                                   struct drm_property_blob **replace,
 +                                   size_t length,
 +                                   const void *data,
 +                                   struct drm_mode_object *obj_holds_id,
 +                                   struct drm_property *prop_holds_id);
  struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob);
  void drm_property_unreference_blob(struct drm_property_blob *blob);
  extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
  extern int drm_property_add_enum(struct drm_property *property, int index,
                                 uint64_t value, const char *name);
 -extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
 -extern int drm_mode_create_tv_properties(struct drm_device *dev,
 -                                       unsigned int num_modes,
 -                                       const char * const modes[]);
 -extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
 -extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
 -extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
 -extern int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
 -
 -extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
 -                                           struct drm_encoder *encoder);
  extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
                                         int gamma_size);
  
@@@ -2299,6 -2997,11 +2317,6 @@@ int drm_plane_create_zpos_immutable_pro
                                             unsigned int zpos);
  
  /* Helpers */
 -struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
 -                                           uint32_t id, uint32_t type);
 -void drm_mode_object_reference(struct drm_mode_object *obj);
 -void drm_mode_object_unreference(struct drm_mode_object *obj);
 -
  static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
                uint32_t id)
  {
@@@ -2323,6 -3026,22 +2341,6 @@@ static inline struct drm_encoder *drm_e
        return mo ? obj_to_encoder(mo) : NULL;
  }
  
 -/**
 - * drm_connector_lookup - lookup connector object
 - * @dev: DRM device
 - * @id: connector object id
 - *
 - * This function looks up the connector object specified by id
 - * add takes a reference to it.
 - */
 -static inline struct drm_connector *drm_connector_lookup(struct drm_device *dev,
 -              uint32_t id)
 -{
 -      struct drm_mode_object *mo;
 -      mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
 -      return mo ? obj_to_connector(mo) : NULL;
 -}
 -
  static inline struct drm_property *drm_property_find(struct drm_device *dev,
                uint32_t id)
  {
@@@ -2350,6 -3069,61 +2368,6 @@@ static inline uint32_t drm_color_lut_ex
        return clamp_val(val, 0, max);
  }
  
 -/**
 - * drm_framebuffer_reference - incr the fb refcnt
 - * @fb: framebuffer
 - *
 - * This functions increments the fb's refcount.
 - */
 -static inline void drm_framebuffer_reference(struct drm_framebuffer *fb)
 -{
 -      drm_mode_object_reference(&fb->base);
 -}
 -
 -/**
 - * drm_framebuffer_unreference - unref a framebuffer
 - * @fb: framebuffer to unref
 - *
 - * This functions decrements the fb's refcount and frees it if it drops to zero.
 - */
 -static inline void drm_framebuffer_unreference(struct drm_framebuffer *fb)
 -{
 -      drm_mode_object_unreference(&fb->base);
 -}
 -
 -/**
 - * drm_framebuffer_read_refcount - read the framebuffer reference count.
 - * @fb: framebuffer
 - *
 - * This functions returns the framebuffer's reference count.
 - */
 -static inline uint32_t drm_framebuffer_read_refcount(struct drm_framebuffer *fb)
 -{
 -      return atomic_read(&fb->base.refcount.refcount);
 -}
 -
 -/**
 - * drm_connector_reference - incr the connector refcnt
 - * @connector: connector
 - *
 - * This function increments the connector's refcount.
 - */
 -static inline void drm_connector_reference(struct drm_connector *connector)
 -{
 -      drm_mode_object_reference(&connector->base);
 -}
 -
 -/**
 - * drm_connector_unreference - unref a connector
 - * @connector: connector to unref
 - *
 - * This function decrements the connector's refcount and frees it if it drops to zero.
 - */
 -static inline void drm_connector_unreference(struct drm_connector *connector)
 -{
 -      drm_mode_object_unreference(&connector->base);
 -}
 -
  /* Plane list iterator for legacy (overlay only) planes. */
  #define drm_for_each_legacy_plane(plane, dev) \
        list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \