aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/amd/amdgpu
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2016-05-06 00:17:22 -0400
committerDave Airlie <airlied@redhat.com>2016-05-06 00:17:22 -0400
commita64424d722504926f3375bc4887976e3bfe3a01d (patch)
treeabf5419151be98a8520e30b1ae7935127a678796 /drivers/gpu/drm/amd/amdgpu
parent0552f7651bc233e5407ab06ba97a9d7c25e19580 (diff)
parent84fae133f0ccc974a425eee21101f5644bd8d14d (diff)
Merge branch 'drm-next-4.7' of git://people.freedesktop.org/~agd5f/linux into drm-next
This is the first big radeon/amdgpu pull request for 4.7. Highlights: - Polaris support in amdgpu Current display stack on par with other asics, for advanced features DAL is required Power management support Support for GFX, Compute, SDMA, UVD, VCE - VCE and UVD init/fini cleanup in radeon - GPUVM improvements - Scheduler improvements - Clockgating improvements - Powerplay improvements - TTM changes to support driver specific LRU update mechanism - Radeon support for new Mesa features - ASYNC pageflip support for radeon - Lots of bug fixes and code cleanups * 'drm-next-4.7' of git://people.freedesktop.org/~agd5f/linux: (180 commits) drm/amdgpu: Replace rcu_assign_pointer() with RCU_INIT_POINTER() drm/amdgpu: use drm_mode_vrefresh() rather than mode->vrefresh drm/amdgpu/uvd6: add bypass support for fiji (v3) drm/amdgpu/fiji: set UVD CG state when enabling UVD DPM (v2) drm/powerplay: add missing clockgating callback for tonga drm/amdgpu: Constify some tables drm/amd/powerplay: Delete dead struct declaration drm/amd/powerplay/hwmgr: don't add invalid voltage drm/amd/powerplay/hwmgr: prevent VDDC from exceeding 2V MAINTAINERS: Remove unneded wildcard for the Radeon/AMDGPU drivers drm/radeon: add cayman VM support for append packet. drm/amd/amdgpu: Add debugfs entries for smc/didt/pcie drm/amd/amdgpu: Drop print_status callbacks. drm/amd/powerplay: revise reading/writing pptable on Polaris10 drm/amd/powerplay: revise reading/writing pptable on Tonga drm/amd/powerplay: revise reading/writing pptable on Fiji drm/amd/powerplay: revise caching the soft pptable and add it's size drm/amd/powerplay: add dpm force multiple levels on cz/tonga/fiji/polaris (v2) drm/amd/powerplay: fix fan speed percent setting error on Polaris10 drm/amd/powerplay: fix bug dpm can't work when resume back on Polaris ...
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu')
-rw-r--r--drivers/gpu/drm/amd/amdgpu/Kconfig10
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu.h117
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c8
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_acp.h2
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c45
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.h2
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c2
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c8
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c162
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c2
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c48
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_device.c259
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_display.c20
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c2
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c12
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c8
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c53
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c2
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c26
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c2
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_job.c49
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c2
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h6
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_object.h2
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c53
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_powerplay.c14
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c84
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c105
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c70
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c40
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c10
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c335
-rw-r--r--drivers/gpu/drm/amd/amdgpu/atombios_crtc.c98
-rw-r--r--drivers/gpu/drm/amd/amdgpu/atombios_crtc.h2
-rw-r--r--drivers/gpu/drm/amd/amdgpu/atombios_encoders.c93
-rw-r--r--drivers/gpu/drm/amd/amdgpu/ci_dpm.c210
-rw-r--r--drivers/gpu/drm/amd/amdgpu/cik.c8
-rw-r--r--drivers/gpu/drm/amd/amdgpu/cik_ih.c34
-rw-r--r--drivers/gpu/drm/amd/amdgpu/cik_sdma.c58
-rw-r--r--drivers/gpu/drm/amd/amdgpu/cz_dpm.c1
-rw-r--r--drivers/gpu/drm/amd/amdgpu/cz_ih.c34
-rw-r--r--drivers/gpu/drm/amd/amdgpu/dce_v10_0.c12
-rw-r--r--drivers/gpu/drm/amd/amdgpu/dce_v11_0.c207
-rw-r--r--drivers/gpu/drm/amd/amdgpu/dce_v8_0.c12
-rw-r--r--drivers/gpu/drm/amd/amdgpu/fiji_dpm.c1
-rw-r--r--drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c259
-rw-r--r--drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c1563
-rw-r--r--drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c113
-rw-r--r--drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c153
-rw-r--r--drivers/gpu/drm/amd/amdgpu/iceland_dpm.c1
-rw-r--r--drivers/gpu/drm/amd/amdgpu/iceland_ih.c34
-rw-r--r--drivers/gpu/drm/amd/amdgpu/kv_dpm.c57
-rw-r--r--drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c56
-rw-r--r--drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c238
-rw-r--r--drivers/gpu/drm/amd/amdgpu/smu_ucode_xfer_vi.h1
-rw-r--r--drivers/gpu/drm/amd/amdgpu/tonga_dpm.c1
-rw-r--r--drivers/gpu/drm/amd/amdgpu/tonga_ih.c34
-rw-r--r--drivers/gpu/drm/amd/amdgpu/uvd_v4_2.c119
-rw-r--r--drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c237
-rw-r--r--drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c416
-rw-r--r--drivers/gpu/drm/amd/amdgpu/vce_v2_0.c97
-rw-r--r--drivers/gpu/drm/amd/amdgpu/vce_v3_0.c78
-rw-r--r--drivers/gpu/drm/amd/amdgpu/vi.c196
63 files changed, 3324 insertions, 2659 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/Kconfig b/drivers/gpu/drm/amd/amdgpu/Kconfig
index b30fcfa4b1f2..7335c0420c70 100644
--- a/drivers/gpu/drm/amd/amdgpu/Kconfig
+++ b/drivers/gpu/drm/amd/amdgpu/Kconfig
@@ -15,3 +15,13 @@ config DRM_AMDGPU_USERPTR
15 help 15 help
16 This option selects CONFIG_MMU_NOTIFIER if it isn't already 16 This option selects CONFIG_MMU_NOTIFIER if it isn't already
17 selected to enabled full userptr support. 17 selected to enabled full userptr support.
18
19config DRM_AMDGPU_GART_DEBUGFS
20 bool "Allow GART access through debugfs"
21 depends on DRM_AMDGPU
22 depends on DEBUG_FS
23 default n
24 help
25 Selecting this option creates a debugfs file to inspect the mapped
26 pages. Uses more memory for housekeeping, enable only for debugging.
27
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 62a778012fe0..1012bd3f3482 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -302,6 +302,8 @@ struct amdgpu_ring_funcs {
302 void (*insert_nop)(struct amdgpu_ring *ring, uint32_t count); 302 void (*insert_nop)(struct amdgpu_ring *ring, uint32_t count);
303 /* pad the indirect buffer to the necessary number of dw */ 303 /* pad the indirect buffer to the necessary number of dw */
304 void (*pad_ib)(struct amdgpu_ring *ring, struct amdgpu_ib *ib); 304 void (*pad_ib)(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
305 unsigned (*init_cond_exec)(struct amdgpu_ring *ring);
306 void (*patch_cond_exec)(struct amdgpu_ring *ring, unsigned offset);
305}; 307};
306 308
307/* 309/*
@@ -391,6 +393,14 @@ unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring);
391/* 393/*
392 * TTM. 394 * TTM.
393 */ 395 */
396
397#define AMDGPU_TTM_LRU_SIZE 20
398
399struct amdgpu_mman_lru {
400 struct list_head *lru[TTM_NUM_MEM_TYPES];
401 struct list_head *swap_lru;
402};
403
394struct amdgpu_mman { 404struct amdgpu_mman {
395 struct ttm_bo_global_ref bo_global_ref; 405 struct ttm_bo_global_ref bo_global_ref;
396 struct drm_global_reference mem_global_ref; 406 struct drm_global_reference mem_global_ref;
@@ -408,6 +418,9 @@ struct amdgpu_mman {
408 struct amdgpu_ring *buffer_funcs_ring; 418 struct amdgpu_ring *buffer_funcs_ring;
409 /* Scheduler entity for buffer moves */ 419 /* Scheduler entity for buffer moves */
410 struct amd_sched_entity entity; 420 struct amd_sched_entity entity;
421
422 /* custom LRU management */
423 struct amdgpu_mman_lru log2_size[AMDGPU_TTM_LRU_SIZE];
411}; 424};
412 425
413int amdgpu_copy_buffer(struct amdgpu_ring *ring, 426int amdgpu_copy_buffer(struct amdgpu_ring *ring,
@@ -586,6 +599,9 @@ int amdgpu_sync_resv(struct amdgpu_device *adev,
586 struct amdgpu_sync *sync, 599 struct amdgpu_sync *sync,
587 struct reservation_object *resv, 600 struct reservation_object *resv,
588 void *owner); 601 void *owner);
602bool amdgpu_sync_is_idle(struct amdgpu_sync *sync);
603int amdgpu_sync_cycle_fences(struct amdgpu_sync *dst, struct amdgpu_sync *src,
604 struct fence *fence);
589struct fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync); 605struct fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync);
590int amdgpu_sync_wait(struct amdgpu_sync *sync); 606int amdgpu_sync_wait(struct amdgpu_sync *sync);
591void amdgpu_sync_free(struct amdgpu_sync *sync); 607void amdgpu_sync_free(struct amdgpu_sync *sync);
@@ -609,8 +625,9 @@ struct amdgpu_gart {
609 unsigned num_gpu_pages; 625 unsigned num_gpu_pages;
610 unsigned num_cpu_pages; 626 unsigned num_cpu_pages;
611 unsigned table_size; 627 unsigned table_size;
628#ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
612 struct page **pages; 629 struct page **pages;
613 dma_addr_t *pages_addr; 630#endif
614 bool ready; 631 bool ready;
615 const struct amdgpu_gart_funcs *gart_funcs; 632 const struct amdgpu_gart_funcs *gart_funcs;
616}; 633};
@@ -742,16 +759,19 @@ enum amdgpu_ring_type {
742 AMDGPU_RING_TYPE_VCE 759 AMDGPU_RING_TYPE_VCE
743}; 760};
744 761
745extern struct amd_sched_backend_ops amdgpu_sched_ops; 762extern const struct amd_sched_backend_ops amdgpu_sched_ops;
746 763
747int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs, 764int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs,
748 struct amdgpu_job **job); 765 struct amdgpu_job **job);
749int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size, 766int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size,
750 struct amdgpu_job **job); 767 struct amdgpu_job **job);
768
751void amdgpu_job_free(struct amdgpu_job *job); 769void amdgpu_job_free(struct amdgpu_job *job);
770void amdgpu_job_free_func(struct kref *refcount);
752int amdgpu_job_submit(struct amdgpu_job *job, struct amdgpu_ring *ring, 771int amdgpu_job_submit(struct amdgpu_job *job, struct amdgpu_ring *ring,
753 struct amd_sched_entity *entity, void *owner, 772 struct amd_sched_entity *entity, void *owner,
754 struct fence **f); 773 struct fence **f);
774void amdgpu_job_timeout_func(struct work_struct *work);
755 775
756struct amdgpu_ring { 776struct amdgpu_ring {
757 struct amdgpu_device *adev; 777 struct amdgpu_device *adev;
@@ -788,6 +808,9 @@ struct amdgpu_ring {
788 struct amdgpu_ctx *current_ctx; 808 struct amdgpu_ctx *current_ctx;
789 enum amdgpu_ring_type type; 809 enum amdgpu_ring_type type;
790 char name[16]; 810 char name[16];
811 unsigned cond_exe_offs;
812 u64 cond_exe_gpu_addr;
813 volatile u32 *cond_exe_cpu_addr;
791}; 814};
792 815
793/* 816/*
@@ -830,13 +853,6 @@ struct amdgpu_vm_pt {
830 uint64_t addr; 853 uint64_t addr;
831}; 854};
832 855
833struct amdgpu_vm_id {
834 struct amdgpu_vm_manager_id *mgr_id;
835 uint64_t pd_gpu_addr;
836 /* last flushed PD/PT update */
837 struct fence *flushed_updates;
838};
839
840struct amdgpu_vm { 856struct amdgpu_vm {
841 /* tree of virtual addresses mapped */ 857 /* tree of virtual addresses mapped */
842 struct rb_root va; 858 struct rb_root va;
@@ -862,7 +878,7 @@ struct amdgpu_vm {
862 struct amdgpu_vm_pt *page_tables; 878 struct amdgpu_vm_pt *page_tables;
863 879
864 /* for id and flush management per ring */ 880 /* for id and flush management per ring */
865 struct amdgpu_vm_id ids[AMDGPU_MAX_RINGS]; 881 struct amdgpu_vm_id *ids[AMDGPU_MAX_RINGS];
866 882
867 /* protecting freed */ 883 /* protecting freed */
868 spinlock_t freed_lock; 884 spinlock_t freed_lock;
@@ -871,11 +887,18 @@ struct amdgpu_vm {
871 struct amd_sched_entity entity; 887 struct amd_sched_entity entity;
872}; 888};
873 889
874struct amdgpu_vm_manager_id { 890struct amdgpu_vm_id {
875 struct list_head list; 891 struct list_head list;
876 struct fence *active; 892 struct fence *first;
893 struct amdgpu_sync active;
894 struct fence *last_flush;
895 struct amdgpu_ring *last_user;
877 atomic_long_t owner; 896 atomic_long_t owner;
878 897
898 uint64_t pd_gpu_addr;
899 /* last flushed PD/PT update */
900 struct fence *flushed_updates;
901
879 uint32_t gds_base; 902 uint32_t gds_base;
880 uint32_t gds_size; 903 uint32_t gds_size;
881 uint32_t gws_base; 904 uint32_t gws_base;
@@ -889,7 +912,7 @@ struct amdgpu_vm_manager {
889 struct mutex lock; 912 struct mutex lock;
890 unsigned num_ids; 913 unsigned num_ids;
891 struct list_head ids_lru; 914 struct list_head ids_lru;
892 struct amdgpu_vm_manager_id ids[AMDGPU_NUM_VM]; 915 struct amdgpu_vm_id ids[AMDGPU_NUM_VM];
893 916
894 uint32_t max_pfn; 917 uint32_t max_pfn;
895 /* vram base address for page table entry */ 918 /* vram base address for page table entry */
@@ -916,11 +939,11 @@ void amdgpu_vm_move_pt_bos_in_lru(struct amdgpu_device *adev,
916int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring, 939int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
917 struct amdgpu_sync *sync, struct fence *fence, 940 struct amdgpu_sync *sync, struct fence *fence,
918 unsigned *vm_id, uint64_t *vm_pd_addr); 941 unsigned *vm_id, uint64_t *vm_pd_addr);
919void amdgpu_vm_flush(struct amdgpu_ring *ring, 942int amdgpu_vm_flush(struct amdgpu_ring *ring,
920 unsigned vm_id, uint64_t pd_addr, 943 unsigned vm_id, uint64_t pd_addr,
921 uint32_t gds_base, uint32_t gds_size, 944 uint32_t gds_base, uint32_t gds_size,
922 uint32_t gws_base, uint32_t gws_size, 945 uint32_t gws_base, uint32_t gws_size,
923 uint32_t oa_base, uint32_t oa_size); 946 uint32_t oa_base, uint32_t oa_size);
924void amdgpu_vm_reset_id(struct amdgpu_device *adev, unsigned vm_id); 947void amdgpu_vm_reset_id(struct amdgpu_device *adev, unsigned vm_id);
925uint64_t amdgpu_vm_map_gart(const dma_addr_t *pages_addr, uint64_t addr); 948uint64_t amdgpu_vm_map_gart(const dma_addr_t *pages_addr, uint64_t addr);
926int amdgpu_vm_update_page_directory(struct amdgpu_device *adev, 949int amdgpu_vm_update_page_directory(struct amdgpu_device *adev,
@@ -1026,6 +1049,11 @@ void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
1026 */ 1049 */
1027#include "clearstate_defs.h" 1050#include "clearstate_defs.h"
1028 1051
1052struct amdgpu_rlc_funcs {
1053 void (*enter_safe_mode)(struct amdgpu_device *adev);
1054 void (*exit_safe_mode)(struct amdgpu_device *adev);
1055};
1056
1029struct amdgpu_rlc { 1057struct amdgpu_rlc {
1030 /* for power gating */ 1058 /* for power gating */
1031 struct amdgpu_bo *save_restore_obj; 1059 struct amdgpu_bo *save_restore_obj;
@@ -1044,6 +1072,24 @@ struct amdgpu_rlc {
1044 uint64_t cp_table_gpu_addr; 1072 uint64_t cp_table_gpu_addr;
1045 volatile uint32_t *cp_table_ptr; 1073 volatile uint32_t *cp_table_ptr;
1046 u32 cp_table_size; 1074 u32 cp_table_size;
1075
1076 /* safe mode for updating CG/PG state */
1077 bool in_safe_mode;
1078 const struct amdgpu_rlc_funcs *funcs;
1079
1080 /* for firmware data */
1081 u32 save_and_restore_offset;
1082 u32 clear_state_descriptor_offset;
1083 u32 avail_scratch_ram_locations;
1084 u32 reg_restore_list_size;
1085 u32 reg_list_format_start;
1086 u32 reg_list_format_separate_start;
1087 u32 starting_offsets_start;
1088 u32 reg_list_format_size_bytes;
1089 u32 reg_list_size_bytes;
1090
1091 u32 *register_list_format;
1092 u32 *register_restore;
1047}; 1093};
1048 1094
1049struct amdgpu_mec { 1095struct amdgpu_mec {
@@ -1582,16 +1628,19 @@ void amdgpu_get_pcie_info(struct amdgpu_device *adev);
1582/* 1628/*
1583 * UVD 1629 * UVD
1584 */ 1630 */
1585#define AMDGPU_MAX_UVD_HANDLES 10 1631#define AMDGPU_DEFAULT_UVD_HANDLES 10
1586#define AMDGPU_UVD_STACK_SIZE (1024*1024) 1632#define AMDGPU_MAX_UVD_HANDLES 40
1587#define AMDGPU_UVD_HEAP_SIZE (1024*1024) 1633#define AMDGPU_UVD_STACK_SIZE (200*1024)
1588#define AMDGPU_UVD_FIRMWARE_OFFSET 256 1634#define AMDGPU_UVD_HEAP_SIZE (256*1024)
1635#define AMDGPU_UVD_SESSION_SIZE (50*1024)
1636#define AMDGPU_UVD_FIRMWARE_OFFSET 256
1589 1637
1590struct amdgpu_uvd { 1638struct amdgpu_uvd {
1591 struct amdgpu_bo *vcpu_bo; 1639 struct amdgpu_bo *vcpu_bo;
1592 void *cpu_addr; 1640 void *cpu_addr;
1593 uint64_t gpu_addr; 1641 uint64_t gpu_addr;
1594 void *saved_bo; 1642 void *saved_bo;
1643 unsigned max_handles;
1595 atomic_t handles[AMDGPU_MAX_UVD_HANDLES]; 1644 atomic_t handles[AMDGPU_MAX_UVD_HANDLES];
1596 struct drm_file *filp[AMDGPU_MAX_UVD_HANDLES]; 1645 struct drm_file *filp[AMDGPU_MAX_UVD_HANDLES];
1597 struct delayed_work idle_work; 1646 struct delayed_work idle_work;
@@ -1690,12 +1739,12 @@ static inline void amdgpu_mn_unregister(struct amdgpu_bo *bo) {}
1690 * Debugfs 1739 * Debugfs
1691 */ 1740 */
1692struct amdgpu_debugfs { 1741struct amdgpu_debugfs {
1693 struct drm_info_list *files; 1742 const struct drm_info_list *files;
1694 unsigned num_files; 1743 unsigned num_files;
1695}; 1744};
1696 1745
1697int amdgpu_debugfs_add_files(struct amdgpu_device *adev, 1746int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
1698 struct drm_info_list *files, 1747 const struct drm_info_list *files,
1699 unsigned nfiles); 1748 unsigned nfiles);
1700int amdgpu_debugfs_fence_init(struct amdgpu_device *adev); 1749int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
1701 1750
@@ -1854,15 +1903,8 @@ struct amdgpu_atcs {
1854/* 1903/*
1855 * CGS 1904 * CGS
1856 */ 1905 */
1857void *amdgpu_cgs_create_device(struct amdgpu_device *adev); 1906struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1858void amdgpu_cgs_destroy_device(void *cgs_device); 1907void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device);
1859
1860
1861/*
1862 * CGS
1863 */
1864void *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1865void amdgpu_cgs_destroy_device(void *cgs_device);
1866 1908
1867 1909
1868/* GPU virtualization */ 1910/* GPU virtualization */
@@ -1903,7 +1945,6 @@ struct amdgpu_device {
1903 int usec_timeout; 1945 int usec_timeout;
1904 const struct amdgpu_asic_funcs *asic_funcs; 1946 const struct amdgpu_asic_funcs *asic_funcs;
1905 bool shutdown; 1947 bool shutdown;
1906 bool suspend;
1907 bool need_dma32; 1948 bool need_dma32;
1908 bool accel_working; 1949 bool accel_working;
1909 struct work_struct reset_work; 1950 struct work_struct reset_work;
@@ -1912,7 +1953,7 @@ struct amdgpu_device {
1912 struct amdgpu_debugfs debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS]; 1953 struct amdgpu_debugfs debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
1913 unsigned debugfs_count; 1954 unsigned debugfs_count;
1914#if defined(CONFIG_DEBUG_FS) 1955#if defined(CONFIG_DEBUG_FS)
1915 struct dentry *debugfs_regs; 1956 struct dentry *debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
1916#endif 1957#endif
1917 struct amdgpu_atif atif; 1958 struct amdgpu_atif atif;
1918 struct amdgpu_atcs atcs; 1959 struct amdgpu_atcs atcs;
@@ -1925,7 +1966,6 @@ struct amdgpu_device {
1925 /* BIOS */ 1966 /* BIOS */
1926 uint8_t *bios; 1967 uint8_t *bios;
1927 bool is_atom_bios; 1968 bool is_atom_bios;
1928 uint16_t bios_header_start;
1929 struct amdgpu_bo *stollen_vga_memory; 1969 struct amdgpu_bo *stollen_vga_memory;
1930 uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH]; 1970 uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
1931 1971
@@ -2181,6 +2221,8 @@ amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
2181#define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r)) 2221#define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
2182#define amdgpu_ring_emit_hdp_invalidate(r) (r)->funcs->emit_hdp_invalidate((r)) 2222#define amdgpu_ring_emit_hdp_invalidate(r) (r)->funcs->emit_hdp_invalidate((r))
2183#define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib))) 2223#define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib)))
2224#define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r))
2225#define amdgpu_ring_patch_cond_exec(r,o) (r)->funcs->patch_cond_exec((r),(o))
2184#define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev)) 2226#define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev))
2185#define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv)) 2227#define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv))
2186#define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev)) 2228#define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev))
@@ -2337,7 +2379,7 @@ static inline void amdgpu_unregister_atpx_handler(void) {}
2337 * KMS 2379 * KMS
2338 */ 2380 */
2339extern const struct drm_ioctl_desc amdgpu_ioctls_kms[]; 2381extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
2340extern int amdgpu_max_kms_ioctl; 2382extern const int amdgpu_max_kms_ioctl;
2341 2383
2342int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags); 2384int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
2343int amdgpu_driver_unload_kms(struct drm_device *dev); 2385int amdgpu_driver_unload_kms(struct drm_device *dev);
@@ -2396,5 +2438,4 @@ amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
2396 uint64_t addr, struct amdgpu_bo **bo); 2438 uint64_t addr, struct amdgpu_bo **bo);
2397 2439
2398#include "amdgpu_object.h" 2440#include "amdgpu_object.h"
2399
2400#endif 2441#endif
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c
index d6b0bff510aa..da764e193fb9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c
@@ -463,13 +463,6 @@ static int acp_soft_reset(void *handle)
463 return 0; 463 return 0;
464} 464}
465 465
466static void acp_print_status(void *handle)
467{
468 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
469
470 dev_info(adev->dev, "ACP STATUS\n");
471}
472
473static int acp_set_clockgating_state(void *handle, 466static int acp_set_clockgating_state(void *handle,
474 enum amd_clockgating_state state) 467 enum amd_clockgating_state state)
475{ 468{
@@ -494,7 +487,6 @@ const struct amd_ip_funcs acp_ip_funcs = {
494 .is_idle = acp_is_idle, 487 .is_idle = acp_is_idle,
495 .wait_for_idle = acp_wait_for_idle, 488 .wait_for_idle = acp_wait_for_idle,
496 .soft_reset = acp_soft_reset, 489 .soft_reset = acp_soft_reset,
497 .print_status = acp_print_status,
498 .set_clockgating_state = acp_set_clockgating_state, 490 .set_clockgating_state = acp_set_clockgating_state,
499 .set_powergating_state = acp_set_powergating_state, 491 .set_powergating_state = acp_set_powergating_state,
500}; 492};
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_acp.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_acp.h
index f6e32a639107..8a396313c86f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_acp.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_acp.h
@@ -30,7 +30,7 @@
30 30
31struct amdgpu_acp { 31struct amdgpu_acp {
32 struct device *parent; 32 struct device *parent;
33 void *cgs_device; 33 struct cgs_device *cgs_device;
34 struct amd_acp_private *private; 34 struct amd_acp_private *private;
35 struct mfd_cell *acp_cell; 35 struct mfd_cell *acp_cell;
36 struct resource *acp_res; 36 struct resource *acp_res;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c
index 84b0ce39ee14..9df1bcb35bf0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c
@@ -234,16 +234,6 @@ amdgpu_atombios_get_hpd_info_from_gpio(struct amdgpu_device *adev,
234 return hpd; 234 return hpd;
235} 235}
236 236
237static bool amdgpu_atombios_apply_quirks(struct amdgpu_device *adev,
238 uint32_t supported_device,
239 int *connector_type,
240 struct amdgpu_i2c_bus_rec *i2c_bus,
241 uint16_t *line_mux,
242 struct amdgpu_hpd *hpd)
243{
244 return true;
245}
246
247static const int object_connector_convert[] = { 237static const int object_connector_convert[] = {
248 DRM_MODE_CONNECTOR_Unknown, 238 DRM_MODE_CONNECTOR_Unknown,
249 DRM_MODE_CONNECTOR_DVII, 239 DRM_MODE_CONNECTOR_DVII,
@@ -514,11 +504,6 @@ bool amdgpu_atombios_get_connector_info_from_object_table(struct amdgpu_device *
514 504
515 conn_id = le16_to_cpu(path->usConnObjectId); 505 conn_id = le16_to_cpu(path->usConnObjectId);
516 506
517 if (!amdgpu_atombios_apply_quirks
518 (adev, le16_to_cpu(path->usDeviceTag), &connector_type,
519 &ddc_bus, &conn_id, &hpd))
520 continue;
521
522 amdgpu_display_add_connector(adev, 507 amdgpu_display_add_connector(adev,
523 conn_id, 508 conn_id,
524 le16_to_cpu(path->usDeviceTag), 509 le16_to_cpu(path->usDeviceTag),
@@ -699,6 +684,36 @@ int amdgpu_atombios_get_clock_info(struct amdgpu_device *adev)
699 return ret; 684 return ret;
700} 685}
701 686
687union gfx_info {
688 ATOM_GFX_INFO_V2_1 info;
689};
690
691int amdgpu_atombios_get_gfx_info(struct amdgpu_device *adev)
692{
693 struct amdgpu_mode_info *mode_info = &adev->mode_info;
694 int index = GetIndexIntoMasterTable(DATA, GFX_Info);
695 uint8_t frev, crev;
696 uint16_t data_offset;
697 int ret = -EINVAL;
698
699 if (amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
700 &frev, &crev, &data_offset)) {
701 union gfx_info *gfx_info = (union gfx_info *)
702 (mode_info->atom_context->bios + data_offset);
703
704 adev->gfx.config.max_shader_engines = gfx_info->info.max_shader_engines;
705 adev->gfx.config.max_tile_pipes = gfx_info->info.max_tile_pipes;
706 adev->gfx.config.max_cu_per_sh = gfx_info->info.max_cu_per_sh;
707 adev->gfx.config.max_sh_per_se = gfx_info->info.max_sh_per_se;
708 adev->gfx.config.max_backends_per_se = gfx_info->info.max_backends_per_se;
709 adev->gfx.config.max_texture_channel_caches =
710 gfx_info->info.max_texture_channel_caches;
711
712 ret = 0;
713 }
714 return ret;
715}
716
702union igp_info { 717union igp_info {
703 struct _ATOM_INTEGRATED_SYSTEM_INFO info; 718 struct _ATOM_INTEGRATED_SYSTEM_INFO info;
704 struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2; 719 struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.h
index 9e1442053fe4..8c2e69661799 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.h
@@ -144,6 +144,8 @@ bool amdgpu_atombios_get_connector_info_from_object_table(struct amdgpu_device *
144 144
145int amdgpu_atombios_get_clock_info(struct amdgpu_device *adev); 145int amdgpu_atombios_get_clock_info(struct amdgpu_device *adev);
146 146
147int amdgpu_atombios_get_gfx_info(struct amdgpu_device *adev);
148
147bool amdgpu_atombios_get_asic_ss_info(struct amdgpu_device *adev, 149bool amdgpu_atombios_get_asic_ss_info(struct amdgpu_device *adev,
148 struct amdgpu_atom_ss *ss, 150 struct amdgpu_atom_ss *ss,
149 int id, u32 clock); 151 int id, u32 clock);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c
index cd639c362df3..33e47a43ae32 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c
@@ -141,7 +141,7 @@ out_cleanup:
141void amdgpu_benchmark(struct amdgpu_device *adev, int test_number) 141void amdgpu_benchmark(struct amdgpu_device *adev, int test_number)
142{ 142{
143 int i; 143 int i;
144 int common_modes[AMDGPU_BENCHMARK_COMMON_MODES_N] = { 144 static const int common_modes[AMDGPU_BENCHMARK_COMMON_MODES_N] = {
145 640 * 480 * 4, 145 640 * 480 * 4,
146 720 * 480 * 4, 146 720 * 480 * 4,
147 800 * 600 * 4, 147 800 * 600 * 4,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c
index 80add22375ee..99ca75baa47d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c
@@ -349,7 +349,7 @@ static inline bool amdgpu_acpi_vfct_bios(struct amdgpu_device *adev)
349bool amdgpu_get_bios(struct amdgpu_device *adev) 349bool amdgpu_get_bios(struct amdgpu_device *adev)
350{ 350{
351 bool r; 351 bool r;
352 uint16_t tmp; 352 uint16_t tmp, bios_header_start;
353 353
354 r = amdgpu_atrm_get_bios(adev); 354 r = amdgpu_atrm_get_bios(adev);
355 if (r == false) 355 if (r == false)
@@ -383,11 +383,11 @@ bool amdgpu_get_bios(struct amdgpu_device *adev)
383 goto free_bios; 383 goto free_bios;
384 } 384 }
385 385
386 adev->bios_header_start = RBIOS16(0x48); 386 bios_header_start = RBIOS16(0x48);
387 if (!adev->bios_header_start) { 387 if (!bios_header_start) {
388 goto free_bios; 388 goto free_bios;
389 } 389 }
390 tmp = adev->bios_header_start + 4; 390 tmp = bios_header_start + 4;
391 if (!memcmp(adev->bios + tmp, "ATOM", 4) || 391 if (!memcmp(adev->bios + tmp, "ATOM", 4) ||
392 !memcmp(adev->bios + tmp, "MOTA", 4)) { 392 !memcmp(adev->bios + tmp, "MOTA", 4)) {
393 adev->is_atom_bios = true; 393 adev->is_atom_bios = true;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c
index 6043dc7c3a94..490464e39322 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c
@@ -42,7 +42,7 @@ struct amdgpu_cgs_device {
42 struct amdgpu_device *adev = \ 42 struct amdgpu_device *adev = \
43 ((struct amdgpu_cgs_device *)cgs_device)->adev 43 ((struct amdgpu_cgs_device *)cgs_device)->adev
44 44
45static int amdgpu_cgs_gpu_mem_info(void *cgs_device, enum cgs_gpu_mem_type type, 45static int amdgpu_cgs_gpu_mem_info(struct cgs_device *cgs_device, enum cgs_gpu_mem_type type,
46 uint64_t *mc_start, uint64_t *mc_size, 46 uint64_t *mc_start, uint64_t *mc_size,
47 uint64_t *mem_size) 47 uint64_t *mem_size)
48{ 48{
@@ -73,7 +73,7 @@ static int amdgpu_cgs_gpu_mem_info(void *cgs_device, enum cgs_gpu_mem_type type,
73 return 0; 73 return 0;
74} 74}
75 75
76static int amdgpu_cgs_gmap_kmem(void *cgs_device, void *kmem, 76static int amdgpu_cgs_gmap_kmem(struct cgs_device *cgs_device, void *kmem,
77 uint64_t size, 77 uint64_t size,
78 uint64_t min_offset, uint64_t max_offset, 78 uint64_t min_offset, uint64_t max_offset,
79 cgs_handle_t *kmem_handle, uint64_t *mcaddr) 79 cgs_handle_t *kmem_handle, uint64_t *mcaddr)
@@ -102,7 +102,7 @@ static int amdgpu_cgs_gmap_kmem(void *cgs_device, void *kmem,
102 return ret; 102 return ret;
103} 103}
104 104
105static int amdgpu_cgs_gunmap_kmem(void *cgs_device, cgs_handle_t kmem_handle) 105static int amdgpu_cgs_gunmap_kmem(struct cgs_device *cgs_device, cgs_handle_t kmem_handle)
106{ 106{
107 struct amdgpu_bo *obj = (struct amdgpu_bo *)kmem_handle; 107 struct amdgpu_bo *obj = (struct amdgpu_bo *)kmem_handle;
108 108
@@ -118,7 +118,7 @@ static int amdgpu_cgs_gunmap_kmem(void *cgs_device, cgs_handle_t kmem_handle)
118 return 0; 118 return 0;
119} 119}
120 120
121static int amdgpu_cgs_alloc_gpu_mem(void *cgs_device, 121static int amdgpu_cgs_alloc_gpu_mem(struct cgs_device *cgs_device,
122 enum cgs_gpu_mem_type type, 122 enum cgs_gpu_mem_type type,
123 uint64_t size, uint64_t align, 123 uint64_t size, uint64_t align,
124 uint64_t min_offset, uint64_t max_offset, 124 uint64_t min_offset, uint64_t max_offset,
@@ -208,7 +208,7 @@ static int amdgpu_cgs_alloc_gpu_mem(void *cgs_device,
208 return ret; 208 return ret;
209} 209}
210 210
211static int amdgpu_cgs_free_gpu_mem(void *cgs_device, cgs_handle_t handle) 211static int amdgpu_cgs_free_gpu_mem(struct cgs_device *cgs_device, cgs_handle_t handle)
212{ 212{
213 struct amdgpu_bo *obj = (struct amdgpu_bo *)handle; 213 struct amdgpu_bo *obj = (struct amdgpu_bo *)handle;
214 214
@@ -225,7 +225,7 @@ static int amdgpu_cgs_free_gpu_mem(void *cgs_device, cgs_handle_t handle)
225 return 0; 225 return 0;
226} 226}
227 227
228static int amdgpu_cgs_gmap_gpu_mem(void *cgs_device, cgs_handle_t handle, 228static int amdgpu_cgs_gmap_gpu_mem(struct cgs_device *cgs_device, cgs_handle_t handle,
229 uint64_t *mcaddr) 229 uint64_t *mcaddr)
230{ 230{
231 int r; 231 int r;
@@ -246,7 +246,7 @@ static int amdgpu_cgs_gmap_gpu_mem(void *cgs_device, cgs_handle_t handle,
246 return r; 246 return r;
247} 247}
248 248
249static int amdgpu_cgs_gunmap_gpu_mem(void *cgs_device, cgs_handle_t handle) 249static int amdgpu_cgs_gunmap_gpu_mem(struct cgs_device *cgs_device, cgs_handle_t handle)
250{ 250{
251 int r; 251 int r;
252 struct amdgpu_bo *obj = (struct amdgpu_bo *)handle; 252 struct amdgpu_bo *obj = (struct amdgpu_bo *)handle;
@@ -258,7 +258,7 @@ static int amdgpu_cgs_gunmap_gpu_mem(void *cgs_device, cgs_handle_t handle)
258 return r; 258 return r;
259} 259}
260 260
261static int amdgpu_cgs_kmap_gpu_mem(void *cgs_device, cgs_handle_t handle, 261static int amdgpu_cgs_kmap_gpu_mem(struct cgs_device *cgs_device, cgs_handle_t handle,
262 void **map) 262 void **map)
263{ 263{
264 int r; 264 int r;
@@ -271,7 +271,7 @@ static int amdgpu_cgs_kmap_gpu_mem(void *cgs_device, cgs_handle_t handle,
271 return r; 271 return r;
272} 272}
273 273
274static int amdgpu_cgs_kunmap_gpu_mem(void *cgs_device, cgs_handle_t handle) 274static int amdgpu_cgs_kunmap_gpu_mem(struct cgs_device *cgs_device, cgs_handle_t handle)
275{ 275{
276 int r; 276 int r;
277 struct amdgpu_bo *obj = (struct amdgpu_bo *)handle; 277 struct amdgpu_bo *obj = (struct amdgpu_bo *)handle;
@@ -283,20 +283,20 @@ static int amdgpu_cgs_kunmap_gpu_mem(void *cgs_device, cgs_handle_t handle)
283 return r; 283 return r;
284} 284}
285 285
286static uint32_t amdgpu_cgs_read_register(void *cgs_device, unsigned offset) 286static uint32_t amdgpu_cgs_read_register(struct cgs_device *cgs_device, unsigned offset)
287{ 287{
288 CGS_FUNC_ADEV; 288 CGS_FUNC_ADEV;
289 return RREG32(offset); 289 return RREG32(offset);
290} 290}
291 291
292static void amdgpu_cgs_write_register(void *cgs_device, unsigned offset, 292static void amdgpu_cgs_write_register(struct cgs_device *cgs_device, unsigned offset,
293 uint32_t value) 293 uint32_t value)
294{ 294{
295 CGS_FUNC_ADEV; 295 CGS_FUNC_ADEV;
296 WREG32(offset, value); 296 WREG32(offset, value);
297} 297}
298 298
299static uint32_t amdgpu_cgs_read_ind_register(void *cgs_device, 299static uint32_t amdgpu_cgs_read_ind_register(struct cgs_device *cgs_device,
300 enum cgs_ind_reg space, 300 enum cgs_ind_reg space,
301 unsigned index) 301 unsigned index)
302{ 302{
@@ -320,7 +320,7 @@ static uint32_t amdgpu_cgs_read_ind_register(void *cgs_device,
320 return 0; 320 return 0;
321} 321}
322 322
323static void amdgpu_cgs_write_ind_register(void *cgs_device, 323static void amdgpu_cgs_write_ind_register(struct cgs_device *cgs_device,
324 enum cgs_ind_reg space, 324 enum cgs_ind_reg space,
325 unsigned index, uint32_t value) 325 unsigned index, uint32_t value)
326{ 326{
@@ -343,7 +343,7 @@ static void amdgpu_cgs_write_ind_register(void *cgs_device,
343 WARN(1, "Invalid indirect register space"); 343 WARN(1, "Invalid indirect register space");
344} 344}
345 345
346static uint8_t amdgpu_cgs_read_pci_config_byte(void *cgs_device, unsigned addr) 346static uint8_t amdgpu_cgs_read_pci_config_byte(struct cgs_device *cgs_device, unsigned addr)
347{ 347{
348 CGS_FUNC_ADEV; 348 CGS_FUNC_ADEV;
349 uint8_t val; 349 uint8_t val;
@@ -353,7 +353,7 @@ static uint8_t amdgpu_cgs_read_pci_config_byte(void *cgs_device, unsigned addr)
353 return val; 353 return val;
354} 354}
355 355
356static uint16_t amdgpu_cgs_read_pci_config_word(void *cgs_device, unsigned addr) 356static uint16_t amdgpu_cgs_read_pci_config_word(struct cgs_device *cgs_device, unsigned addr)
357{ 357{
358 CGS_FUNC_ADEV; 358 CGS_FUNC_ADEV;
359 uint16_t val; 359 uint16_t val;
@@ -363,7 +363,7 @@ static uint16_t amdgpu_cgs_read_pci_config_word(void *cgs_device, unsigned addr)
363 return val; 363 return val;
364} 364}
365 365
366static uint32_t amdgpu_cgs_read_pci_config_dword(void *cgs_device, 366static uint32_t amdgpu_cgs_read_pci_config_dword(struct cgs_device *cgs_device,
367 unsigned addr) 367 unsigned addr)
368{ 368{
369 CGS_FUNC_ADEV; 369 CGS_FUNC_ADEV;
@@ -374,7 +374,7 @@ static uint32_t amdgpu_cgs_read_pci_config_dword(void *cgs_device,
374 return val; 374 return val;
375} 375}
376 376
377static void amdgpu_cgs_write_pci_config_byte(void *cgs_device, unsigned addr, 377static void amdgpu_cgs_write_pci_config_byte(struct cgs_device *cgs_device, unsigned addr,
378 uint8_t value) 378 uint8_t value)
379{ 379{
380 CGS_FUNC_ADEV; 380 CGS_FUNC_ADEV;
@@ -382,7 +382,7 @@ static void amdgpu_cgs_write_pci_config_byte(void *cgs_device, unsigned addr,
382 WARN(ret, "pci_write_config_byte error"); 382 WARN(ret, "pci_write_config_byte error");
383} 383}
384 384
385static void amdgpu_cgs_write_pci_config_word(void *cgs_device, unsigned addr, 385static void amdgpu_cgs_write_pci_config_word(struct cgs_device *cgs_device, unsigned addr,
386 uint16_t value) 386 uint16_t value)
387{ 387{
388 CGS_FUNC_ADEV; 388 CGS_FUNC_ADEV;
@@ -390,7 +390,7 @@ static void amdgpu_cgs_write_pci_config_word(void *cgs_device, unsigned addr,
390 WARN(ret, "pci_write_config_word error"); 390 WARN(ret, "pci_write_config_word error");
391} 391}
392 392
393static void amdgpu_cgs_write_pci_config_dword(void *cgs_device, unsigned addr, 393static void amdgpu_cgs_write_pci_config_dword(struct cgs_device *cgs_device, unsigned addr,
394 uint32_t value) 394 uint32_t value)
395{ 395{
396 CGS_FUNC_ADEV; 396 CGS_FUNC_ADEV;
@@ -399,7 +399,7 @@ static void amdgpu_cgs_write_pci_config_dword(void *cgs_device, unsigned addr,
399} 399}
400 400
401 401
402static int amdgpu_cgs_get_pci_resource(void *cgs_device, 402static int amdgpu_cgs_get_pci_resource(struct cgs_device *cgs_device,
403 enum cgs_resource_type resource_type, 403 enum cgs_resource_type resource_type,
404 uint64_t size, 404 uint64_t size,
405 uint64_t offset, 405 uint64_t offset,
@@ -433,7 +433,7 @@ static int amdgpu_cgs_get_pci_resource(void *cgs_device,
433 } 433 }
434} 434}
435 435
436static const void *amdgpu_cgs_atom_get_data_table(void *cgs_device, 436static const void *amdgpu_cgs_atom_get_data_table(struct cgs_device *cgs_device,
437 unsigned table, uint16_t *size, 437 unsigned table, uint16_t *size,
438 uint8_t *frev, uint8_t *crev) 438 uint8_t *frev, uint8_t *crev)
439{ 439{
@@ -449,7 +449,7 @@ static const void *amdgpu_cgs_atom_get_data_table(void *cgs_device,
449 return NULL; 449 return NULL;
450} 450}
451 451
452static int amdgpu_cgs_atom_get_cmd_table_revs(void *cgs_device, unsigned table, 452static int amdgpu_cgs_atom_get_cmd_table_revs(struct cgs_device *cgs_device, unsigned table,
453 uint8_t *frev, uint8_t *crev) 453 uint8_t *frev, uint8_t *crev)
454{ 454{
455 CGS_FUNC_ADEV; 455 CGS_FUNC_ADEV;
@@ -462,7 +462,7 @@ static int amdgpu_cgs_atom_get_cmd_table_revs(void *cgs_device, unsigned table,
462 return -EINVAL; 462 return -EINVAL;
463} 463}
464 464
465static int amdgpu_cgs_atom_exec_cmd_table(void *cgs_device, unsigned table, 465static int amdgpu_cgs_atom_exec_cmd_table(struct cgs_device *cgs_device, unsigned table,
466 void *args) 466 void *args)
467{ 467{
468 CGS_FUNC_ADEV; 468 CGS_FUNC_ADEV;
@@ -471,33 +471,33 @@ static int amdgpu_cgs_atom_exec_cmd_table(void *cgs_device, unsigned table,
471 adev->mode_info.atom_context, table, args); 471 adev->mode_info.atom_context, table, args);
472} 472}
473 473
474static int amdgpu_cgs_create_pm_request(void *cgs_device, cgs_handle_t *request) 474static int amdgpu_cgs_create_pm_request(struct cgs_device *cgs_device, cgs_handle_t *request)
475{ 475{
476 /* TODO */ 476 /* TODO */
477 return 0; 477 return 0;
478} 478}
479 479
480static int amdgpu_cgs_destroy_pm_request(void *cgs_device, cgs_handle_t request) 480static int amdgpu_cgs_destroy_pm_request(struct cgs_device *cgs_device, cgs_handle_t request)
481{ 481{
482 /* TODO */ 482 /* TODO */
483 return 0; 483 return 0;
484} 484}
485 485
486static int amdgpu_cgs_set_pm_request(void *cgs_device, cgs_handle_t request, 486static int amdgpu_cgs_set_pm_request(struct cgs_device *cgs_device, cgs_handle_t request,
487 int active) 487 int active)
488{ 488{
489 /* TODO */ 489 /* TODO */
490 return 0; 490 return 0;
491} 491}
492 492
493static int amdgpu_cgs_pm_request_clock(void *cgs_device, cgs_handle_t request, 493static int amdgpu_cgs_pm_request_clock(struct cgs_device *cgs_device, cgs_handle_t request,
494 enum cgs_clock clock, unsigned freq) 494 enum cgs_clock clock, unsigned freq)
495{ 495{
496 /* TODO */ 496 /* TODO */
497 return 0; 497 return 0;
498} 498}
499 499
500static int amdgpu_cgs_pm_request_engine(void *cgs_device, cgs_handle_t request, 500static int amdgpu_cgs_pm_request_engine(struct cgs_device *cgs_device, cgs_handle_t request,
501 enum cgs_engine engine, int powered) 501 enum cgs_engine engine, int powered)
502{ 502{
503 /* TODO */ 503 /* TODO */
@@ -506,7 +506,7 @@ static int amdgpu_cgs_pm_request_engine(void *cgs_device, cgs_handle_t request,
506 506
507 507
508 508
509static int amdgpu_cgs_pm_query_clock_limits(void *cgs_device, 509static int amdgpu_cgs_pm_query_clock_limits(struct cgs_device *cgs_device,
510 enum cgs_clock clock, 510 enum cgs_clock clock,
511 struct cgs_clock_limits *limits) 511 struct cgs_clock_limits *limits)
512{ 512{
@@ -514,7 +514,7 @@ static int amdgpu_cgs_pm_query_clock_limits(void *cgs_device,
514 return 0; 514 return 0;
515} 515}
516 516
517static int amdgpu_cgs_set_camera_voltages(void *cgs_device, uint32_t mask, 517static int amdgpu_cgs_set_camera_voltages(struct cgs_device *cgs_device, uint32_t mask,
518 const uint32_t *voltages) 518 const uint32_t *voltages)
519{ 519{
520 DRM_ERROR("not implemented"); 520 DRM_ERROR("not implemented");
@@ -565,7 +565,7 @@ static const struct amdgpu_irq_src_funcs cgs_irq_funcs = {
565 .process = cgs_process_irq, 565 .process = cgs_process_irq,
566}; 566};
567 567
568static int amdgpu_cgs_add_irq_source(void *cgs_device, unsigned src_id, 568static int amdgpu_cgs_add_irq_source(struct cgs_device *cgs_device, unsigned src_id,
569 unsigned num_types, 569 unsigned num_types,
570 cgs_irq_source_set_func_t set, 570 cgs_irq_source_set_func_t set,
571 cgs_irq_handler_func_t handler, 571 cgs_irq_handler_func_t handler,
@@ -600,19 +600,19 @@ static int amdgpu_cgs_add_irq_source(void *cgs_device, unsigned src_id,
600 return ret; 600 return ret;
601} 601}
602 602
603static int amdgpu_cgs_irq_get(void *cgs_device, unsigned src_id, unsigned type) 603static int amdgpu_cgs_irq_get(struct cgs_device *cgs_device, unsigned src_id, unsigned type)
604{ 604{
605 CGS_FUNC_ADEV; 605 CGS_FUNC_ADEV;
606 return amdgpu_irq_get(adev, adev->irq.sources[src_id], type); 606 return amdgpu_irq_get(adev, adev->irq.sources[src_id], type);
607} 607}
608 608
609static int amdgpu_cgs_irq_put(void *cgs_device, unsigned src_id, unsigned type) 609static int amdgpu_cgs_irq_put(struct cgs_device *cgs_device, unsigned src_id, unsigned type)
610{ 610{
611 CGS_FUNC_ADEV; 611 CGS_FUNC_ADEV;
612 return amdgpu_irq_put(adev, adev->irq.sources[src_id], type); 612 return amdgpu_irq_put(adev, adev->irq.sources[src_id], type);
613} 613}
614 614
615int amdgpu_cgs_set_clockgating_state(void *cgs_device, 615int amdgpu_cgs_set_clockgating_state(struct cgs_device *cgs_device,
616 enum amd_ip_block_type block_type, 616 enum amd_ip_block_type block_type,
617 enum amd_clockgating_state state) 617 enum amd_clockgating_state state)
618{ 618{
@@ -633,7 +633,7 @@ int amdgpu_cgs_set_clockgating_state(void *cgs_device,
633 return r; 633 return r;
634} 634}
635 635
636int amdgpu_cgs_set_powergating_state(void *cgs_device, 636int amdgpu_cgs_set_powergating_state(struct cgs_device *cgs_device,
637 enum amd_ip_block_type block_type, 637 enum amd_ip_block_type block_type,
638 enum amd_powergating_state state) 638 enum amd_powergating_state state)
639{ 639{
@@ -655,7 +655,7 @@ int amdgpu_cgs_set_powergating_state(void *cgs_device,
655} 655}
656 656
657 657
658static uint32_t fw_type_convert(void *cgs_device, uint32_t fw_type) 658static uint32_t fw_type_convert(struct cgs_device *cgs_device, uint32_t fw_type)
659{ 659{
660 CGS_FUNC_ADEV; 660 CGS_FUNC_ADEV;
661 enum AMDGPU_UCODE_ID result = AMDGPU_UCODE_ID_MAXIMUM; 661 enum AMDGPU_UCODE_ID result = AMDGPU_UCODE_ID_MAXIMUM;
@@ -681,9 +681,10 @@ static uint32_t fw_type_convert(void *cgs_device, uint32_t fw_type)
681 result = AMDGPU_UCODE_ID_CP_MEC1; 681 result = AMDGPU_UCODE_ID_CP_MEC1;
682 break; 682 break;
683 case CGS_UCODE_ID_CP_MEC_JT2: 683 case CGS_UCODE_ID_CP_MEC_JT2:
684 if (adev->asic_type == CHIP_TONGA) 684 if (adev->asic_type == CHIP_TONGA || adev->asic_type == CHIP_POLARIS11
685 || adev->asic_type == CHIP_POLARIS10)
685 result = AMDGPU_UCODE_ID_CP_MEC2; 686 result = AMDGPU_UCODE_ID_CP_MEC2;
686 else if (adev->asic_type == CHIP_CARRIZO) 687 else
687 result = AMDGPU_UCODE_ID_CP_MEC1; 688 result = AMDGPU_UCODE_ID_CP_MEC1;
688 break; 689 break;
689 case CGS_UCODE_ID_RLC_G: 690 case CGS_UCODE_ID_RLC_G:
@@ -695,13 +696,13 @@ static uint32_t fw_type_convert(void *cgs_device, uint32_t fw_type)
695 return result; 696 return result;
696} 697}
697 698
698static int amdgpu_cgs_get_firmware_info(void *cgs_device, 699static int amdgpu_cgs_get_firmware_info(struct cgs_device *cgs_device,
699 enum cgs_ucode_id type, 700 enum cgs_ucode_id type,
700 struct cgs_firmware_info *info) 701 struct cgs_firmware_info *info)
701{ 702{
702 CGS_FUNC_ADEV; 703 CGS_FUNC_ADEV;
703 704
704 if (CGS_UCODE_ID_SMU != type) { 705 if ((CGS_UCODE_ID_SMU != type) && (CGS_UCODE_ID_SMU_SK != type)) {
705 uint64_t gpu_addr; 706 uint64_t gpu_addr;
706 uint32_t data_size; 707 uint32_t data_size;
707 const struct gfx_firmware_header_v1_0 *header; 708 const struct gfx_firmware_header_v1_0 *header;
@@ -734,30 +735,44 @@ static int amdgpu_cgs_get_firmware_info(void *cgs_device,
734 const uint8_t *src; 735 const uint8_t *src;
735 const struct smc_firmware_header_v1_0 *hdr; 736 const struct smc_firmware_header_v1_0 *hdr;
736 737
737 switch (adev->asic_type) { 738 if (!adev->pm.fw) {
738 case CHIP_TONGA: 739 switch (adev->asic_type) {
739 strcpy(fw_name, "amdgpu/tonga_smc.bin"); 740 case CHIP_TONGA:
740 break; 741 strcpy(fw_name, "amdgpu/tonga_smc.bin");
741 case CHIP_FIJI: 742 break;
742 strcpy(fw_name, "amdgpu/fiji_smc.bin"); 743 case CHIP_FIJI:
743 break; 744 strcpy(fw_name, "amdgpu/fiji_smc.bin");
744 default: 745 break;
745 DRM_ERROR("SMC firmware not supported\n"); 746 case CHIP_POLARIS11:
746 return -EINVAL; 747 if (type == CGS_UCODE_ID_SMU)
747 } 748 strcpy(fw_name, "amdgpu/polaris11_smc.bin");
749 else if (type == CGS_UCODE_ID_SMU_SK)
750 strcpy(fw_name, "amdgpu/polaris11_smc_sk.bin");
751 break;
752 case CHIP_POLARIS10:
753 if (type == CGS_UCODE_ID_SMU)
754 strcpy(fw_name, "amdgpu/polaris10_smc.bin");
755 else if (type == CGS_UCODE_ID_SMU_SK)
756 strcpy(fw_name, "amdgpu/polaris10_smc_sk.bin");
757 break;
758 default:
759 DRM_ERROR("SMC firmware not supported\n");
760 return -EINVAL;
761 }
748 762
749 err = request_firmware(&adev->pm.fw, fw_name, adev->dev); 763 err = request_firmware(&adev->pm.fw, fw_name, adev->dev);
750 if (err) { 764 if (err) {
751 DRM_ERROR("Failed to request firmware\n"); 765 DRM_ERROR("Failed to request firmware\n");
752 return err; 766 return err;
753 } 767 }
754 768
755 err = amdgpu_ucode_validate(adev->pm.fw); 769 err = amdgpu_ucode_validate(adev->pm.fw);
756 if (err) { 770 if (err) {
757 DRM_ERROR("Failed to load firmware \"%s\"", fw_name); 771 DRM_ERROR("Failed to load firmware \"%s\"", fw_name);
758 release_firmware(adev->pm.fw); 772 release_firmware(adev->pm.fw);
759 adev->pm.fw = NULL; 773 adev->pm.fw = NULL;
760 return err; 774 return err;
775 }
761 } 776 }
762 777
763 hdr = (const struct smc_firmware_header_v1_0 *) adev->pm.fw->data; 778 hdr = (const struct smc_firmware_header_v1_0 *) adev->pm.fw->data;
@@ -774,10 +789,11 @@ static int amdgpu_cgs_get_firmware_info(void *cgs_device,
774 return 0; 789 return 0;
775} 790}
776 791
777static int amdgpu_cgs_query_system_info(void *cgs_device, 792static int amdgpu_cgs_query_system_info(struct cgs_device *cgs_device,
778 struct cgs_system_info *sys_info) 793 struct cgs_system_info *sys_info)
779{ 794{
780 CGS_FUNC_ADEV; 795 CGS_FUNC_ADEV;
796 struct amdgpu_cu_info cu_info;
781 797
782 if (NULL == sys_info) 798 if (NULL == sys_info)
783 return -ENODEV; 799 return -ENODEV;
@@ -801,6 +817,10 @@ static int amdgpu_cgs_query_system_info(void *cgs_device,
801 case CGS_SYSTEM_INFO_PG_FLAGS: 817 case CGS_SYSTEM_INFO_PG_FLAGS:
802 sys_info->value = adev->pg_flags; 818 sys_info->value = adev->pg_flags;
803 break; 819 break;
820 case CGS_SYSTEM_INFO_GFX_CU_INFO:
821 amdgpu_asic_get_cu_info(adev, &cu_info);
822 sys_info->value = cu_info.number;
823 break;
804 default: 824 default:
805 return -ENODEV; 825 return -ENODEV;
806 } 826 }
@@ -808,7 +828,7 @@ static int amdgpu_cgs_query_system_info(void *cgs_device,
808 return 0; 828 return 0;
809} 829}
810 830
811static int amdgpu_cgs_get_active_displays_info(void *cgs_device, 831static int amdgpu_cgs_get_active_displays_info(struct cgs_device *cgs_device,
812 struct cgs_display_info *info) 832 struct cgs_display_info *info)
813{ 833{
814 CGS_FUNC_ADEV; 834 CGS_FUNC_ADEV;
@@ -851,7 +871,7 @@ static int amdgpu_cgs_get_active_displays_info(void *cgs_device,
851} 871}
852 872
853 873
854static int amdgpu_cgs_notify_dpm_enabled(void *cgs_device, bool enabled) 874static int amdgpu_cgs_notify_dpm_enabled(struct cgs_device *cgs_device, bool enabled)
855{ 875{
856 CGS_FUNC_ADEV; 876 CGS_FUNC_ADEV;
857 877
@@ -867,7 +887,7 @@ static int amdgpu_cgs_notify_dpm_enabled(void *cgs_device, bool enabled)
867 */ 887 */
868 888
869#if defined(CONFIG_ACPI) 889#if defined(CONFIG_ACPI)
870static int amdgpu_cgs_acpi_eval_object(void *cgs_device, 890static int amdgpu_cgs_acpi_eval_object(struct cgs_device *cgs_device,
871 struct cgs_acpi_method_info *info) 891 struct cgs_acpi_method_info *info)
872{ 892{
873 CGS_FUNC_ADEV; 893 CGS_FUNC_ADEV;
@@ -1030,14 +1050,14 @@ error:
1030 return result; 1050 return result;
1031} 1051}
1032#else 1052#else
1033static int amdgpu_cgs_acpi_eval_object(void *cgs_device, 1053static int amdgpu_cgs_acpi_eval_object(struct cgs_device *cgs_device,
1034 struct cgs_acpi_method_info *info) 1054 struct cgs_acpi_method_info *info)
1035{ 1055{
1036 return -EIO; 1056 return -EIO;
1037} 1057}
1038#endif 1058#endif
1039 1059
1040int amdgpu_cgs_call_acpi_method(void *cgs_device, 1060int amdgpu_cgs_call_acpi_method(struct cgs_device *cgs_device,
1041 uint32_t acpi_method, 1061 uint32_t acpi_method,
1042 uint32_t acpi_function, 1062 uint32_t acpi_function,
1043 void *pinput, void *poutput, 1063 void *pinput, void *poutput,
@@ -1121,7 +1141,7 @@ static const struct cgs_os_ops amdgpu_cgs_os_ops = {
1121 amdgpu_cgs_irq_put 1141 amdgpu_cgs_irq_put
1122}; 1142};
1123 1143
1124void *amdgpu_cgs_create_device(struct amdgpu_device *adev) 1144struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev)
1125{ 1145{
1126 struct amdgpu_cgs_device *cgs_device = 1146 struct amdgpu_cgs_device *cgs_device =
1127 kmalloc(sizeof(*cgs_device), GFP_KERNEL); 1147 kmalloc(sizeof(*cgs_device), GFP_KERNEL);
@@ -1135,10 +1155,10 @@ void *amdgpu_cgs_create_device(struct amdgpu_device *adev)
1135 cgs_device->base.os_ops = &amdgpu_cgs_os_ops; 1155 cgs_device->base.os_ops = &amdgpu_cgs_os_ops;
1136 cgs_device->adev = adev; 1156 cgs_device->adev = adev;
1137 1157
1138 return cgs_device; 1158 return (struct cgs_device *)cgs_device;
1139} 1159}
1140 1160
1141void amdgpu_cgs_destroy_device(void *cgs_device) 1161void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device)
1142{ 1162{
1143 kfree(cgs_device); 1163 kfree(cgs_device);
1144} 1164}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
index 119cdc2c43e7..60a0c9ac11b2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
@@ -439,7 +439,7 @@ static void amdgpu_connector_add_common_modes(struct drm_encoder *encoder,
439 struct drm_display_mode *mode = NULL; 439 struct drm_display_mode *mode = NULL;
440 struct drm_display_mode *native_mode = &amdgpu_encoder->native_mode; 440 struct drm_display_mode *native_mode = &amdgpu_encoder->native_mode;
441 int i; 441 int i;
442 struct mode_size { 442 static const struct mode_size {
443 int w; 443 int w;
444 int h; 444 int h;
445 } common_modes[17] = { 445 } common_modes[17] = {
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 9392e50a7ba4..2ebba295d0e4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -24,7 +24,6 @@
24 * Authors: 24 * Authors:
25 * Jerome Glisse <glisse@freedesktop.org> 25 * Jerome Glisse <glisse@freedesktop.org>
26 */ 26 */
27#include <linux/list_sort.h>
28#include <linux/pagemap.h> 27#include <linux/pagemap.h>
29#include <drm/drmP.h> 28#include <drm/drmP.h>
30#include <drm/amdgpu_drm.h> 29#include <drm/amdgpu_drm.h>
@@ -527,16 +526,6 @@ static int amdgpu_cs_sync_rings(struct amdgpu_cs_parser *p)
527 return 0; 526 return 0;
528} 527}
529 528
530static int cmp_size_smaller_first(void *priv, struct list_head *a,
531 struct list_head *b)
532{
533 struct amdgpu_bo_list_entry *la = list_entry(a, struct amdgpu_bo_list_entry, tv.head);
534 struct amdgpu_bo_list_entry *lb = list_entry(b, struct amdgpu_bo_list_entry, tv.head);
535
536 /* Sort A before B if A is smaller. */
537 return (int)la->robj->tbo.num_pages - (int)lb->robj->tbo.num_pages;
538}
539
540/** 529/**
541 * cs_parser_fini() - clean parser states 530 * cs_parser_fini() - clean parser states
542 * @parser: parser structure holding parsing context. 531 * @parser: parser structure holding parsing context.
@@ -553,18 +542,6 @@ static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser *parser, int error, bo
553 if (!error) { 542 if (!error) {
554 amdgpu_vm_move_pt_bos_in_lru(parser->adev, &fpriv->vm); 543 amdgpu_vm_move_pt_bos_in_lru(parser->adev, &fpriv->vm);
555 544
556 /* Sort the buffer list from the smallest to largest buffer,
557 * which affects the order of buffers in the LRU list.
558 * This assures that the smallest buffers are added first
559 * to the LRU list, so they are likely to be later evicted
560 * first, instead of large buffers whose eviction is more
561 * expensive.
562 *
563 * This slightly lowers the number of bytes moved by TTM
564 * per frame under memory pressure.
565 */
566 list_sort(NULL, &parser->validated, cmp_size_smaller_first);
567
568 ttm_eu_fence_buffer_objects(&parser->ticket, 545 ttm_eu_fence_buffer_objects(&parser->ticket,
569 &parser->validated, 546 &parser->validated,
570 parser->fence); 547 parser->fence);
@@ -862,27 +839,26 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
862 union drm_amdgpu_cs *cs) 839 union drm_amdgpu_cs *cs)
863{ 840{
864 struct amdgpu_ring *ring = p->job->ring; 841 struct amdgpu_ring *ring = p->job->ring;
865 struct amd_sched_fence *fence; 842 struct fence *fence;
866 struct amdgpu_job *job; 843 struct amdgpu_job *job;
844 int r;
867 845
868 job = p->job; 846 job = p->job;
869 p->job = NULL; 847 p->job = NULL;
870 848
871 job->base.sched = &ring->sched; 849 r = amd_sched_job_init(&job->base, &ring->sched,
872 job->base.s_entity = &p->ctx->rings[ring->idx].entity; 850 &p->ctx->rings[ring->idx].entity,
873 job->owner = p->filp; 851 amdgpu_job_timeout_func,
874 852 amdgpu_job_free_func,
875 fence = amd_sched_fence_create(job->base.s_entity, p->filp); 853 p->filp, &fence);
876 if (!fence) { 854 if (r) {
877 amdgpu_job_free(job); 855 amdgpu_job_free(job);
878 return -ENOMEM; 856 return r;
879 } 857 }
880 858
881 job->base.s_fence = fence; 859 job->owner = p->filp;
882 p->fence = fence_get(&fence->base); 860 p->fence = fence_get(fence);
883 861 cs->out.handle = amdgpu_ctx_add_fence(p->ctx, ring, fence);
884 cs->out.handle = amdgpu_ctx_add_fence(p->ctx, ring,
885 &fence->base);
886 job->ibs[job->num_ibs - 1].sequence = cs->out.handle; 862 job->ibs[job->num_ibs - 1].sequence = cs->out.handle;
887 863
888 trace_amdgpu_cs_ioctl(job); 864 trace_amdgpu_cs_ioctl(job);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 612117478b57..8f037e5e08fa 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -59,6 +59,8 @@ static const char *amdgpu_asic_name[] = {
59 "FIJI", 59 "FIJI",
60 "CARRIZO", 60 "CARRIZO",
61 "STONEY", 61 "STONEY",
62 "POLARIS10",
63 "POLARIS11",
62 "LAST", 64 "LAST",
63}; 65};
64 66
@@ -942,15 +944,11 @@ static void amdgpu_check_arguments(struct amdgpu_device *adev)
942 } 944 }
943 945
944 if (amdgpu_gart_size != -1) { 946 if (amdgpu_gart_size != -1) {
945 /* gtt size must be power of two and greater or equal to 32M */ 947 /* gtt size must be greater or equal to 32M */
946 if (amdgpu_gart_size < 32) { 948 if (amdgpu_gart_size < 32) {
947 dev_warn(adev->dev, "gart size (%d) too small\n", 949 dev_warn(adev->dev, "gart size (%d) too small\n",
948 amdgpu_gart_size); 950 amdgpu_gart_size);
949 amdgpu_gart_size = -1; 951 amdgpu_gart_size = -1;
950 } else if (!amdgpu_check_pot_argument(amdgpu_gart_size)) {
951 dev_warn(adev->dev, "gart size (%d) must be a power of 2\n",
952 amdgpu_gart_size);
953 amdgpu_gart_size = -1;
954 } 952 }
955 } 953 }
956 954
@@ -1150,6 +1148,8 @@ static int amdgpu_early_init(struct amdgpu_device *adev)
1150 case CHIP_TOPAZ: 1148 case CHIP_TOPAZ:
1151 case CHIP_TONGA: 1149 case CHIP_TONGA:
1152 case CHIP_FIJI: 1150 case CHIP_FIJI:
1151 case CHIP_POLARIS11:
1152 case CHIP_POLARIS10:
1153 case CHIP_CARRIZO: 1153 case CHIP_CARRIZO:
1154 case CHIP_STONEY: 1154 case CHIP_STONEY:
1155 if (adev->asic_type == CHIP_CARRIZO || adev->asic_type == CHIP_STONEY) 1155 if (adev->asic_type == CHIP_CARRIZO || adev->asic_type == CHIP_STONEY)
@@ -1338,14 +1338,23 @@ static int amdgpu_suspend(struct amdgpu_device *adev)
1338{ 1338{
1339 int i, r; 1339 int i, r;
1340 1340
1341 /* ungate SMC block first */
1342 r = amdgpu_set_clockgating_state(adev, AMD_IP_BLOCK_TYPE_SMC,
1343 AMD_CG_STATE_UNGATE);
1344 if (r) {
1345 DRM_ERROR("set_clockgating_state(ungate) SMC failed %d\n",r);
1346 }
1347
1341 for (i = adev->num_ip_blocks - 1; i >= 0; i--) { 1348 for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
1342 if (!adev->ip_block_status[i].valid) 1349 if (!adev->ip_block_status[i].valid)
1343 continue; 1350 continue;
1344 /* ungate blocks so that suspend can properly shut them down */ 1351 /* ungate blocks so that suspend can properly shut them down */
1345 r = adev->ip_blocks[i].funcs->set_clockgating_state((void *)adev, 1352 if (i != AMD_IP_BLOCK_TYPE_SMC) {
1346 AMD_CG_STATE_UNGATE); 1353 r = adev->ip_blocks[i].funcs->set_clockgating_state((void *)adev,
1347 if (r) { 1354 AMD_CG_STATE_UNGATE);
1348 DRM_ERROR("set_clockgating_state(ungate) %d failed %d\n", i, r); 1355 if (r) {
1356 DRM_ERROR("set_clockgating_state(ungate) %d failed %d\n", i, r);
1357 }
1349 } 1358 }
1350 /* XXX handle errors */ 1359 /* XXX handle errors */
1351 r = adev->ip_blocks[i].funcs->suspend(adev); 1360 r = adev->ip_blocks[i].funcs->suspend(adev);
@@ -2013,7 +2022,7 @@ void amdgpu_get_pcie_info(struct amdgpu_device *adev)
2013 * Debugfs 2022 * Debugfs
2014 */ 2023 */
2015int amdgpu_debugfs_add_files(struct amdgpu_device *adev, 2024int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
2016 struct drm_info_list *files, 2025 const struct drm_info_list *files,
2017 unsigned nfiles) 2026 unsigned nfiles)
2018{ 2027{
2019 unsigned i; 2028 unsigned i;
@@ -2125,32 +2134,246 @@ static ssize_t amdgpu_debugfs_regs_write(struct file *f, const char __user *buf,
2125 return result; 2134 return result;
2126} 2135}
2127 2136
2137static ssize_t amdgpu_debugfs_regs_pcie_read(struct file *f, char __user *buf,
2138 size_t size, loff_t *pos)
2139{
2140 struct amdgpu_device *adev = f->f_inode->i_private;
2141 ssize_t result = 0;
2142 int r;
2143
2144 if (size & 0x3 || *pos & 0x3)
2145 return -EINVAL;
2146
2147 while (size) {
2148 uint32_t value;
2149
2150 value = RREG32_PCIE(*pos >> 2);
2151 r = put_user(value, (uint32_t *)buf);
2152 if (r)
2153 return r;
2154
2155 result += 4;
2156 buf += 4;
2157 *pos += 4;
2158 size -= 4;
2159 }
2160
2161 return result;
2162}
2163
2164static ssize_t amdgpu_debugfs_regs_pcie_write(struct file *f, const char __user *buf,
2165 size_t size, loff_t *pos)
2166{
2167 struct amdgpu_device *adev = f->f_inode->i_private;
2168 ssize_t result = 0;
2169 int r;
2170
2171 if (size & 0x3 || *pos & 0x3)
2172 return -EINVAL;
2173
2174 while (size) {
2175 uint32_t value;
2176
2177 r = get_user(value, (uint32_t *)buf);
2178 if (r)
2179 return r;
2180
2181 WREG32_PCIE(*pos >> 2, value);
2182
2183 result += 4;
2184 buf += 4;
2185 *pos += 4;
2186 size -= 4;
2187 }
2188
2189 return result;
2190}
2191
2192static ssize_t amdgpu_debugfs_regs_didt_read(struct file *f, char __user *buf,
2193 size_t size, loff_t *pos)
2194{
2195 struct amdgpu_device *adev = f->f_inode->i_private;
2196 ssize_t result = 0;
2197 int r;
2198
2199 if (size & 0x3 || *pos & 0x3)
2200 return -EINVAL;
2201
2202 while (size) {
2203 uint32_t value;
2204
2205 value = RREG32_DIDT(*pos >> 2);
2206 r = put_user(value, (uint32_t *)buf);
2207 if (r)
2208 return r;
2209
2210 result += 4;
2211 buf += 4;
2212 *pos += 4;
2213 size -= 4;
2214 }
2215
2216 return result;
2217}
2218
2219static ssize_t amdgpu_debugfs_regs_didt_write(struct file *f, const char __user *buf,
2220 size_t size, loff_t *pos)
2221{
2222 struct amdgpu_device *adev = f->f_inode->i_private;
2223 ssize_t result = 0;
2224 int r;
2225
2226 if (size & 0x3 || *pos & 0x3)
2227 return -EINVAL;
2228
2229 while (size) {
2230 uint32_t value;
2231
2232 r = get_user(value, (uint32_t *)buf);
2233 if (r)
2234 return r;
2235
2236 WREG32_DIDT(*pos >> 2, value);
2237
2238 result += 4;
2239 buf += 4;
2240 *pos += 4;
2241 size -= 4;
2242 }
2243
2244 return result;
2245}
2246
2247static ssize_t amdgpu_debugfs_regs_smc_read(struct file *f, char __user *buf,
2248 size_t size, loff_t *pos)
2249{
2250 struct amdgpu_device *adev = f->f_inode->i_private;
2251 ssize_t result = 0;
2252 int r;
2253
2254 if (size & 0x3 || *pos & 0x3)
2255 return -EINVAL;
2256
2257 while (size) {
2258 uint32_t value;
2259
2260 value = RREG32_SMC(*pos >> 2);
2261 r = put_user(value, (uint32_t *)buf);
2262 if (r)
2263 return r;
2264
2265 result += 4;
2266 buf += 4;
2267 *pos += 4;
2268 size -= 4;
2269 }
2270
2271 return result;
2272}
2273
2274static ssize_t amdgpu_debugfs_regs_smc_write(struct file *f, const char __user *buf,
2275 size_t size, loff_t *pos)
2276{
2277 struct amdgpu_device *adev = f->f_inode->i_private;
2278 ssize_t result = 0;
2279 int r;
2280
2281 if (size & 0x3 || *pos & 0x3)
2282 return -EINVAL;
2283
2284 while (size) {
2285 uint32_t value;
2286
2287 r = get_user(value, (uint32_t *)buf);
2288 if (r)
2289 return r;
2290
2291 WREG32_SMC(*pos >> 2, value);
2292
2293 result += 4;
2294 buf += 4;
2295 *pos += 4;
2296 size -= 4;
2297 }
2298
2299 return result;
2300}
2301
2128static const struct file_operations amdgpu_debugfs_regs_fops = { 2302static const struct file_operations amdgpu_debugfs_regs_fops = {
2129 .owner = THIS_MODULE, 2303 .owner = THIS_MODULE,
2130 .read = amdgpu_debugfs_regs_read, 2304 .read = amdgpu_debugfs_regs_read,
2131 .write = amdgpu_debugfs_regs_write, 2305 .write = amdgpu_debugfs_regs_write,
2132 .llseek = default_llseek 2306 .llseek = default_llseek
2133}; 2307};
2308static const struct file_operations amdgpu_debugfs_regs_didt_fops = {
2309 .owner = THIS_MODULE,
2310 .read = amdgpu_debugfs_regs_didt_read,
2311 .write = amdgpu_debugfs_regs_didt_write,
2312 .llseek = default_llseek
2313};
2314static const struct file_operations amdgpu_debugfs_regs_pcie_fops = {
2315 .owner = THIS_MODULE,
2316 .read = amdgpu_debugfs_regs_pcie_read,
2317 .write = amdgpu_debugfs_regs_pcie_write,
2318 .llseek = default_llseek
2319};
2320static const struct file_operations amdgpu_debugfs_regs_smc_fops = {
2321 .owner = THIS_MODULE,
2322 .read = amdgpu_debugfs_regs_smc_read,
2323 .write = amdgpu_debugfs_regs_smc_write,
2324 .llseek = default_llseek
2325};
2326
2327static const struct file_operations *debugfs_regs[] = {
2328 &amdgpu_debugfs_regs_fops,
2329 &amdgpu_debugfs_regs_didt_fops,
2330 &amdgpu_debugfs_regs_pcie_fops,
2331 &amdgpu_debugfs_regs_smc_fops,
2332};
2333
2334static const char *debugfs_regs_names[] = {
2335 "amdgpu_regs",
2336 "amdgpu_regs_didt",
2337 "amdgpu_regs_pcie",
2338 "amdgpu_regs_smc",
2339};
2134 2340
2135static int amdgpu_debugfs_regs_init(struct amdgpu_device *adev) 2341static int amdgpu_debugfs_regs_init(struct amdgpu_device *adev)
2136{ 2342{
2137 struct drm_minor *minor = adev->ddev->primary; 2343 struct drm_minor *minor = adev->ddev->primary;
2138 struct dentry *ent, *root = minor->debugfs_root; 2344 struct dentry *ent, *root = minor->debugfs_root;
2345 unsigned i, j;
2346
2347 for (i = 0; i < ARRAY_SIZE(debugfs_regs); i++) {
2348 ent = debugfs_create_file(debugfs_regs_names[i],
2349 S_IFREG | S_IRUGO, root,
2350 adev, debugfs_regs[i]);
2351 if (IS_ERR(ent)) {
2352 for (j = 0; j < i; j++) {
2353 debugfs_remove(adev->debugfs_regs[i]);
2354 adev->debugfs_regs[i] = NULL;
2355 }
2356 return PTR_ERR(ent);
2357 }
2139 2358
2140 ent = debugfs_create_file("amdgpu_regs", S_IFREG | S_IRUGO, root, 2359 if (!i)
2141 adev, &amdgpu_debugfs_regs_fops); 2360 i_size_write(ent->d_inode, adev->rmmio_size);
2142 if (IS_ERR(ent)) 2361 adev->debugfs_regs[i] = ent;
2143 return PTR_ERR(ent); 2362 }
2144 i_size_write(ent->d_inode, adev->rmmio_size);
2145 adev->debugfs_regs = ent;
2146 2363
2147 return 0; 2364 return 0;
2148} 2365}
2149 2366
2150static void amdgpu_debugfs_regs_cleanup(struct amdgpu_device *adev) 2367static void amdgpu_debugfs_regs_cleanup(struct amdgpu_device *adev)
2151{ 2368{
2152 debugfs_remove(adev->debugfs_regs); 2369 unsigned i;
2153 adev->debugfs_regs = NULL; 2370
2371 for (i = 0; i < ARRAY_SIZE(debugfs_regs); i++) {
2372 if (adev->debugfs_regs[i]) {
2373 debugfs_remove(adev->debugfs_regs[i]);
2374 adev->debugfs_regs[i] = NULL;
2375 }
2376 }
2154} 2377}
2155 2378
2156int amdgpu_debugfs_init(struct drm_minor *minor) 2379int amdgpu_debugfs_init(struct drm_minor *minor)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
index 3fb405b3a614..c835abe65df3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
@@ -131,12 +131,17 @@ static void amdgpu_flip_work_func(struct work_struct *__work)
131 vblank->framedur_ns / 1000, 131 vblank->framedur_ns / 1000,
132 vblank->linedur_ns / 1000, stat, vpos, hpos); 132 vblank->linedur_ns / 1000, stat, vpos, hpos);
133 133
134 /* set the flip status */ 134 /* Do the flip (mmio) */
135 adev->mode_info.funcs->page_flip(adev, work->crtc_id, work->base);
136
137 /* Set the flip status */
135 amdgpuCrtc->pflip_status = AMDGPU_FLIP_SUBMITTED; 138 amdgpuCrtc->pflip_status = AMDGPU_FLIP_SUBMITTED;
136 spin_unlock_irqrestore(&crtc->dev->event_lock, flags); 139 spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
137 140
138 /* Do the flip (mmio) */ 141
139 adev->mode_info.funcs->page_flip(adev, work->crtc_id, work->base); 142 DRM_DEBUG_DRIVER("crtc:%d[%p], pflip_stat:AMDGPU_FLIP_SUBMITTED, work: %p,\n",
143 amdgpuCrtc->crtc_id, amdgpuCrtc, work);
144
140} 145}
141 146
142/* 147/*
@@ -252,6 +257,9 @@ int amdgpu_crtc_page_flip(struct drm_crtc *crtc,
252 amdgpu_crtc->pflip_status = AMDGPU_FLIP_PENDING; 257 amdgpu_crtc->pflip_status = AMDGPU_FLIP_PENDING;
253 amdgpu_crtc->pflip_works = work; 258 amdgpu_crtc->pflip_works = work;
254 259
260
261 DRM_DEBUG_DRIVER("crtc:%d[%p], pflip_stat:AMDGPU_FLIP_PENDING, work: %p,\n",
262 amdgpu_crtc->crtc_id, amdgpu_crtc, work);
255 /* update crtc fb */ 263 /* update crtc fb */
256 crtc->primary->fb = fb; 264 crtc->primary->fb = fb;
257 spin_unlock_irqrestore(&crtc->dev->event_lock, flags); 265 spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
@@ -588,20 +596,20 @@ const struct drm_mode_config_funcs amdgpu_mode_funcs = {
588 .output_poll_changed = amdgpu_output_poll_changed 596 .output_poll_changed = amdgpu_output_poll_changed
589}; 597};
590 598
591static struct drm_prop_enum_list amdgpu_underscan_enum_list[] = 599static const struct drm_prop_enum_list amdgpu_underscan_enum_list[] =
592{ { UNDERSCAN_OFF, "off" }, 600{ { UNDERSCAN_OFF, "off" },
593 { UNDERSCAN_ON, "on" }, 601 { UNDERSCAN_ON, "on" },
594 { UNDERSCAN_AUTO, "auto" }, 602 { UNDERSCAN_AUTO, "auto" },
595}; 603};
596 604
597static struct drm_prop_enum_list amdgpu_audio_enum_list[] = 605static const struct drm_prop_enum_list amdgpu_audio_enum_list[] =
598{ { AMDGPU_AUDIO_DISABLE, "off" }, 606{ { AMDGPU_AUDIO_DISABLE, "off" },
599 { AMDGPU_AUDIO_ENABLE, "on" }, 607 { AMDGPU_AUDIO_ENABLE, "on" },
600 { AMDGPU_AUDIO_AUTO, "auto" }, 608 { AMDGPU_AUDIO_AUTO, "auto" },
601}; 609};
602 610
603/* XXX support different dither options? spatial, temporal, both, etc. */ 611/* XXX support different dither options? spatial, temporal, both, etc. */
604static struct drm_prop_enum_list amdgpu_dither_enum_list[] = 612static const struct drm_prop_enum_list amdgpu_dither_enum_list[] =
605{ { AMDGPU_FMT_DITHER_DISABLE, "off" }, 613{ { AMDGPU_FMT_DITHER_DISABLE, "off" },
606 { AMDGPU_FMT_DITHER_ENABLE, "on" }, 614 { AMDGPU_FMT_DITHER_ENABLE, "on" },
607}; 615};
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c
index 7b7f4aba60c0..fe36caf1b7d7 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c
@@ -150,7 +150,7 @@ u32 amdgpu_dpm_get_vrefresh(struct amdgpu_device *adev)
150 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { 150 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
151 amdgpu_crtc = to_amdgpu_crtc(crtc); 151 amdgpu_crtc = to_amdgpu_crtc(crtc);
152 if (crtc->enabled && amdgpu_crtc->enabled && amdgpu_crtc->hw_mode.clock) { 152 if (crtc->enabled && amdgpu_crtc->enabled && amdgpu_crtc->hw_mode.clock) {
153 vrefresh = amdgpu_crtc->hw_mode.vrefresh; 153 vrefresh = drm_mode_vrefresh(&amdgpu_crtc->hw_mode);
154 break; 154 break;
155 } 155 }
156 } 156 }
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 44955f0f32d0..1dab5f2b725b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -166,7 +166,7 @@ module_param_named(pcie_gen_cap, amdgpu_pcie_gen_cap, uint, 0444);
166MODULE_PARM_DESC(pcie_lane_cap, "PCIE Lane Caps (0: autodetect (default))"); 166MODULE_PARM_DESC(pcie_lane_cap, "PCIE Lane Caps (0: autodetect (default))");
167module_param_named(pcie_lane_cap, amdgpu_pcie_lane_cap, uint, 0444); 167module_param_named(pcie_lane_cap, amdgpu_pcie_lane_cap, uint, 0444);
168 168
169static struct pci_device_id pciidlist[] = { 169static const struct pci_device_id pciidlist[] = {
170#ifdef CONFIG_DRM_AMDGPU_CIK 170#ifdef CONFIG_DRM_AMDGPU_CIK
171 /* Kaveri */ 171 /* Kaveri */
172 {0x1002, 0x1304, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU}, 172 {0x1002, 0x1304, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
@@ -277,6 +277,16 @@ static struct pci_device_id pciidlist[] = {
277 {0x1002, 0x9877, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CARRIZO|AMD_IS_APU}, 277 {0x1002, 0x9877, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CARRIZO|AMD_IS_APU},
278 /* stoney */ 278 /* stoney */
279 {0x1002, 0x98E4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_STONEY|AMD_IS_APU}, 279 {0x1002, 0x98E4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_STONEY|AMD_IS_APU},
280 /* Polaris11 */
281 {0x1002, 0x67E0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS11},
282 {0x1002, 0x67E1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS11},
283 {0x1002, 0x67E8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS11},
284 {0x1002, 0x67E9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS11},
285 {0x1002, 0x67EB, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS11},
286 {0x1002, 0x67FF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS11},
287 /* Polaris10 */
288 {0x1002, 0x67C0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS10},
289 {0x1002, 0x67DF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS10},
280 290
281 {0, 0, 0} 291 {0, 0, 0}
282}; 292};
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
index d81f1f4883a6..ba9c04283d01 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
@@ -198,7 +198,7 @@ void amdgpu_fence_process(struct amdgpu_ring *ring)
198 198
199 /* There is always exactly one thread signaling this fence slot */ 199 /* There is always exactly one thread signaling this fence slot */
200 fence = rcu_dereference_protected(*ptr, 1); 200 fence = rcu_dereference_protected(*ptr, 1);
201 rcu_assign_pointer(*ptr, NULL); 201 RCU_INIT_POINTER(*ptr, NULL);
202 202
203 BUG_ON(!fence); 203 BUG_ON(!fence);
204 204
@@ -352,9 +352,9 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
352 setup_timer(&ring->fence_drv.fallback_timer, amdgpu_fence_fallback, 352 setup_timer(&ring->fence_drv.fallback_timer, amdgpu_fence_fallback,
353 (unsigned long)ring); 353 (unsigned long)ring);
354 354
355 ring->fence_drv.num_fences_mask = num_hw_submission - 1; 355 ring->fence_drv.num_fences_mask = num_hw_submission * 2 - 1;
356 spin_lock_init(&ring->fence_drv.lock); 356 spin_lock_init(&ring->fence_drv.lock);
357 ring->fence_drv.fences = kcalloc(num_hw_submission, sizeof(void *), 357 ring->fence_drv.fences = kcalloc(num_hw_submission * 2, sizeof(void *),
358 GFP_KERNEL); 358 GFP_KERNEL);
359 if (!ring->fence_drv.fences) 359 if (!ring->fence_drv.fences)
360 return -ENOMEM; 360 return -ENOMEM;
@@ -639,7 +639,7 @@ static int amdgpu_debugfs_gpu_reset(struct seq_file *m, void *data)
639 return 0; 639 return 0;
640} 640}
641 641
642static struct drm_info_list amdgpu_debugfs_fence_list[] = { 642static const struct drm_info_list amdgpu_debugfs_fence_list[] = {
643 {"amdgpu_fence_info", &amdgpu_debugfs_fence_info, 0, NULL}, 643 {"amdgpu_fence_info", &amdgpu_debugfs_fence_info, 0, NULL},
644 {"amdgpu_gpu_reset", &amdgpu_debugfs_gpu_reset, 0, NULL} 644 {"amdgpu_gpu_reset", &amdgpu_debugfs_gpu_reset, 0, NULL}
645}; 645};
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
index 7312d729d300..921bce2df0b0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
@@ -238,18 +238,17 @@ void amdgpu_gart_unbind(struct amdgpu_device *adev, unsigned offset,
238 t = offset / AMDGPU_GPU_PAGE_SIZE; 238 t = offset / AMDGPU_GPU_PAGE_SIZE;
239 p = t / (PAGE_SIZE / AMDGPU_GPU_PAGE_SIZE); 239 p = t / (PAGE_SIZE / AMDGPU_GPU_PAGE_SIZE);
240 for (i = 0; i < pages; i++, p++) { 240 for (i = 0; i < pages; i++, p++) {
241 if (adev->gart.pages[p]) { 241#ifdef CONFIG_AMDGPU_GART_DEBUGFS
242 adev->gart.pages[p] = NULL; 242 adev->gart.pages[p] = NULL;
243 adev->gart.pages_addr[p] = adev->dummy_page.addr; 243#endif
244 page_base = adev->gart.pages_addr[p]; 244 page_base = adev->dummy_page.addr;
245 if (!adev->gart.ptr) 245 if (!adev->gart.ptr)
246 continue; 246 continue;
247 247
248 for (j = 0; j < (PAGE_SIZE / AMDGPU_GPU_PAGE_SIZE); j++, t++) { 248 for (j = 0; j < (PAGE_SIZE / AMDGPU_GPU_PAGE_SIZE); j++, t++) {
249 amdgpu_gart_set_pte_pde(adev, adev->gart.ptr, 249 amdgpu_gart_set_pte_pde(adev, adev->gart.ptr,
250 t, page_base, flags); 250 t, page_base, flags);
251 page_base += AMDGPU_GPU_PAGE_SIZE; 251 page_base += AMDGPU_GPU_PAGE_SIZE;
252 }
253 } 252 }
254 } 253 }
255 mb(); 254 mb();
@@ -287,10 +286,11 @@ int amdgpu_gart_bind(struct amdgpu_device *adev, unsigned offset,
287 p = t / (PAGE_SIZE / AMDGPU_GPU_PAGE_SIZE); 286 p = t / (PAGE_SIZE / AMDGPU_GPU_PAGE_SIZE);
288 287
289 for (i = 0; i < pages; i++, p++) { 288 for (i = 0; i < pages; i++, p++) {
290 adev->gart.pages_addr[p] = dma_addr[i]; 289#ifdef CONFIG_AMDGPU_GART_DEBUGFS
291 adev->gart.pages[p] = pagelist[i]; 290 adev->gart.pages[p] = pagelist[i];
291#endif
292 if (adev->gart.ptr) { 292 if (adev->gart.ptr) {
293 page_base = adev->gart.pages_addr[p]; 293 page_base = dma_addr[i];
294 for (j = 0; j < (PAGE_SIZE / AMDGPU_GPU_PAGE_SIZE); j++, t++) { 294 for (j = 0; j < (PAGE_SIZE / AMDGPU_GPU_PAGE_SIZE); j++, t++) {
295 amdgpu_gart_set_pte_pde(adev, adev->gart.ptr, t, page_base, flags); 295 amdgpu_gart_set_pte_pde(adev, adev->gart.ptr, t, page_base, flags);
296 page_base += AMDGPU_GPU_PAGE_SIZE; 296 page_base += AMDGPU_GPU_PAGE_SIZE;
@@ -312,11 +312,11 @@ int amdgpu_gart_bind(struct amdgpu_device *adev, unsigned offset,
312 */ 312 */
313int amdgpu_gart_init(struct amdgpu_device *adev) 313int amdgpu_gart_init(struct amdgpu_device *adev)
314{ 314{
315 int r, i; 315 int r;
316 316
317 if (adev->gart.pages) { 317 if (adev->dummy_page.page)
318 return 0; 318 return 0;
319 } 319
320 /* We need PAGE_SIZE >= AMDGPU_GPU_PAGE_SIZE */ 320 /* We need PAGE_SIZE >= AMDGPU_GPU_PAGE_SIZE */
321 if (PAGE_SIZE < AMDGPU_GPU_PAGE_SIZE) { 321 if (PAGE_SIZE < AMDGPU_GPU_PAGE_SIZE) {
322 DRM_ERROR("Page size is smaller than GPU page size!\n"); 322 DRM_ERROR("Page size is smaller than GPU page size!\n");
@@ -330,22 +330,16 @@ int amdgpu_gart_init(struct amdgpu_device *adev)
330 adev->gart.num_gpu_pages = adev->mc.gtt_size / AMDGPU_GPU_PAGE_SIZE; 330 adev->gart.num_gpu_pages = adev->mc.gtt_size / AMDGPU_GPU_PAGE_SIZE;
331 DRM_INFO("GART: num cpu pages %u, num gpu pages %u\n", 331 DRM_INFO("GART: num cpu pages %u, num gpu pages %u\n",
332 adev->gart.num_cpu_pages, adev->gart.num_gpu_pages); 332 adev->gart.num_cpu_pages, adev->gart.num_gpu_pages);
333
334#ifdef CONFIG_AMDGPU_GART_DEBUGFS
333 /* Allocate pages table */ 335 /* Allocate pages table */
334 adev->gart.pages = vzalloc(sizeof(void *) * adev->gart.num_cpu_pages); 336 adev->gart.pages = vzalloc(sizeof(void *) * adev->gart.num_cpu_pages);
335 if (adev->gart.pages == NULL) { 337 if (adev->gart.pages == NULL) {
336 amdgpu_gart_fini(adev); 338 amdgpu_gart_fini(adev);
337 return -ENOMEM; 339 return -ENOMEM;
338 } 340 }
339 adev->gart.pages_addr = vzalloc(sizeof(dma_addr_t) * 341#endif
340 adev->gart.num_cpu_pages); 342
341 if (adev->gart.pages_addr == NULL) {
342 amdgpu_gart_fini(adev);
343 return -ENOMEM;
344 }
345 /* set GART entry to point to the dummy page by default */
346 for (i = 0; i < adev->gart.num_cpu_pages; i++) {
347 adev->gart.pages_addr[i] = adev->dummy_page.addr;
348 }
349 return 0; 343 return 0;
350} 344}
351 345
@@ -358,15 +352,14 @@ int amdgpu_gart_init(struct amdgpu_device *adev)
358 */ 352 */
359void amdgpu_gart_fini(struct amdgpu_device *adev) 353void amdgpu_gart_fini(struct amdgpu_device *adev)
360{ 354{
361 if (adev->gart.pages && adev->gart.pages_addr && adev->gart.ready) { 355 if (adev->gart.ready) {
362 /* unbind pages */ 356 /* unbind pages */
363 amdgpu_gart_unbind(adev, 0, adev->gart.num_cpu_pages); 357 amdgpu_gart_unbind(adev, 0, adev->gart.num_cpu_pages);
364 } 358 }
365 adev->gart.ready = false; 359 adev->gart.ready = false;
360#ifdef CONFIG_AMDGPU_GART_DEBUGFS
366 vfree(adev->gart.pages); 361 vfree(adev->gart.pages);
367 vfree(adev->gart.pages_addr);
368 adev->gart.pages = NULL; 362 adev->gart.pages = NULL;
369 adev->gart.pages_addr = NULL; 363#endif
370
371 amdgpu_dummy_page_fini(adev); 364 amdgpu_dummy_page_fini(adev);
372} 365}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index a087b9638cde..c68f4cacaa85 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -797,7 +797,7 @@ static int amdgpu_debugfs_gem_info(struct seq_file *m, void *data)
797 return 0; 797 return 0;
798} 798}
799 799
800static struct drm_info_list amdgpu_debugfs_gem_list[] = { 800static const struct drm_info_list amdgpu_debugfs_gem_list[] = {
801 {"amdgpu_gem_info", &amdgpu_debugfs_gem_info, 0, NULL}, 801 {"amdgpu_gem_info", &amdgpu_debugfs_gem_info, 0, NULL},
802}; 802};
803#endif 803#endif
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
index 8443cea6821a..0129617a7962 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
@@ -124,7 +124,8 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
124 struct amdgpu_ctx *ctx, *old_ctx; 124 struct amdgpu_ctx *ctx, *old_ctx;
125 struct amdgpu_vm *vm; 125 struct amdgpu_vm *vm;
126 struct fence *hwf; 126 struct fence *hwf;
127 unsigned i; 127 unsigned i, patch_offset = ~0;
128
128 int r = 0; 129 int r = 0;
129 130
130 if (num_ibs == 0) 131 if (num_ibs == 0)
@@ -149,17 +150,27 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
149 return r; 150 return r;
150 } 151 }
151 152
153 if (ring->type == AMDGPU_RING_TYPE_SDMA && ring->funcs->init_cond_exec)
154 patch_offset = amdgpu_ring_init_cond_exec(ring);
155
152 if (vm) { 156 if (vm) {
153 /* do context switch */ 157 /* do context switch */
154 amdgpu_vm_flush(ring, ib->vm_id, ib->vm_pd_addr, 158 r = amdgpu_vm_flush(ring, ib->vm_id, ib->vm_pd_addr,
155 ib->gds_base, ib->gds_size, 159 ib->gds_base, ib->gds_size,
156 ib->gws_base, ib->gws_size, 160 ib->gws_base, ib->gws_size,
157 ib->oa_base, ib->oa_size); 161 ib->oa_base, ib->oa_size);
162 if (r) {
163 amdgpu_ring_undo(ring);
164 return r;
165 }
158 166
159 if (ring->funcs->emit_hdp_flush) 167 if (ring->funcs->emit_hdp_flush)
160 amdgpu_ring_emit_hdp_flush(ring); 168 amdgpu_ring_emit_hdp_flush(ring);
161 } 169 }
162 170
171 /* always set cond_exec_polling to CONTINUE */
172 *ring->cond_exe_cpu_addr = 1;
173
163 old_ctx = ring->current_ctx; 174 old_ctx = ring->current_ctx;
164 for (i = 0; i < num_ibs; ++i) { 175 for (i = 0; i < num_ibs; ++i) {
165 ib = &ibs[i]; 176 ib = &ibs[i];
@@ -201,6 +212,9 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
201 if (f) 212 if (f)
202 *f = fence_get(hwf); 213 *f = fence_get(hwf);
203 214
215 if (patch_offset != ~0 && ring->funcs->patch_cond_exec)
216 amdgpu_ring_patch_cond_exec(ring, patch_offset);
217
204 amdgpu_ring_commit(ring); 218 amdgpu_ring_commit(ring);
205 return 0; 219 return 0;
206} 220}
@@ -315,7 +329,7 @@ static int amdgpu_debugfs_sa_info(struct seq_file *m, void *data)
315 329
316} 330}
317 331
318static struct drm_info_list amdgpu_debugfs_sa_list[] = { 332static const struct drm_info_list amdgpu_debugfs_sa_list[] = {
319 {"amdgpu_sa_info", &amdgpu_debugfs_sa_info, 0, NULL}, 333 {"amdgpu_sa_info", &amdgpu_debugfs_sa_info, 0, NULL},
320}; 334};
321 335
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c
index 762cfdb85147..9266c7b69808 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c
@@ -498,7 +498,7 @@ static int amdgpu_irqdomain_map(struct irq_domain *d,
498 return 0; 498 return 0;
499} 499}
500 500
501static struct irq_domain_ops amdgpu_hw_irqdomain_ops = { 501static const struct irq_domain_ops amdgpu_hw_irqdomain_ops = {
502 .map = amdgpu_irqdomain_map, 502 .map = amdgpu_irqdomain_map,
503}; 503};
504 504
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
index 9c9b19e2f353..4eea2a18d8bb 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
@@ -28,6 +28,23 @@
28#include "amdgpu.h" 28#include "amdgpu.h"
29#include "amdgpu_trace.h" 29#include "amdgpu_trace.h"
30 30
31static void amdgpu_job_free_handler(struct work_struct *ws)
32{
33 struct amdgpu_job *job = container_of(ws, struct amdgpu_job, base.work_free_job);
34 amd_sched_job_put(&job->base);
35}
36
37void amdgpu_job_timeout_func(struct work_struct *work)
38{
39 struct amdgpu_job *job = container_of(work, struct amdgpu_job, base.work_tdr.work);
40 DRM_ERROR("ring %s timeout, last signaled seq=%u, last emitted seq=%u\n",
41 job->base.sched->name,
42 (uint32_t)atomic_read(&job->ring->fence_drv.last_seq),
43 job->ring->fence_drv.sync_seq);
44
45 amd_sched_job_put(&job->base);
46}
47
31int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs, 48int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs,
32 struct amdgpu_job **job) 49 struct amdgpu_job **job)
33{ 50{
@@ -45,6 +62,7 @@ int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs,
45 (*job)->adev = adev; 62 (*job)->adev = adev;
46 (*job)->ibs = (void *)&(*job)[1]; 63 (*job)->ibs = (void *)&(*job)[1];
47 (*job)->num_ibs = num_ibs; 64 (*job)->num_ibs = num_ibs;
65 INIT_WORK(&(*job)->base.work_free_job, amdgpu_job_free_handler);
48 66
49 amdgpu_sync_create(&(*job)->sync); 67 amdgpu_sync_create(&(*job)->sync);
50 68
@@ -80,6 +98,14 @@ void amdgpu_job_free(struct amdgpu_job *job)
80 98
81 amdgpu_bo_unref(&job->uf.bo); 99 amdgpu_bo_unref(&job->uf.bo);
82 amdgpu_sync_free(&job->sync); 100 amdgpu_sync_free(&job->sync);
101
102 if (!job->base.use_sched)
103 kfree(job);
104}
105
106void amdgpu_job_free_func(struct kref *refcount)
107{
108 struct amdgpu_job *job = container_of(refcount, struct amdgpu_job, base.refcount);
83 kfree(job); 109 kfree(job);
84} 110}
85 111
@@ -87,16 +113,23 @@ int amdgpu_job_submit(struct amdgpu_job *job, struct amdgpu_ring *ring,
87 struct amd_sched_entity *entity, void *owner, 113 struct amd_sched_entity *entity, void *owner,
88 struct fence **f) 114 struct fence **f)
89{ 115{
116 struct fence *fence;
117 int r;
90 job->ring = ring; 118 job->ring = ring;
91 job->base.sched = &ring->sched;
92 job->base.s_entity = entity;
93 job->base.s_fence = amd_sched_fence_create(job->base.s_entity, owner);
94 if (!job->base.s_fence)
95 return -ENOMEM;
96 119
97 *f = fence_get(&job->base.s_fence->base); 120 if (!f)
121 return -EINVAL;
122
123 r = amd_sched_job_init(&job->base, &ring->sched,
124 entity,
125 amdgpu_job_timeout_func,
126 amdgpu_job_free_func,
127 owner, &fence);
128 if (r)
129 return r;
98 130
99 job->owner = owner; 131 job->owner = owner;
132 *f = fence_get(fence);
100 amd_sched_entity_push_job(&job->base); 133 amd_sched_entity_push_job(&job->base);
101 134
102 return 0; 135 return 0;
@@ -165,7 +198,9 @@ err:
165 return fence; 198 return fence;
166} 199}
167 200
168struct amd_sched_backend_ops amdgpu_sched_ops = { 201const struct amd_sched_backend_ops amdgpu_sched_ops = {
169 .dependency = amdgpu_job_dependency, 202 .dependency = amdgpu_job_dependency,
170 .run_job = amdgpu_job_run, 203 .run_job = amdgpu_job_run,
204 .begin_job = amd_sched_job_begin,
205 .finish_job = amd_sched_job_finish,
171}; 206};
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index 598eb0cd5aab..4ac83c8b40d9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -755,4 +755,4 @@ const struct drm_ioctl_desc amdgpu_ioctls_kms[] = {
755 DRM_IOCTL_DEF_DRV(AMDGPU_GEM_OP, amdgpu_gem_op_ioctl, DRM_AUTH|DRM_RENDER_ALLOW), 755 DRM_IOCTL_DEF_DRV(AMDGPU_GEM_OP, amdgpu_gem_op_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
756 DRM_IOCTL_DEF_DRV(AMDGPU_GEM_USERPTR, amdgpu_gem_userptr_ioctl, DRM_AUTH|DRM_RENDER_ALLOW), 756 DRM_IOCTL_DEF_DRV(AMDGPU_GEM_USERPTR, amdgpu_gem_userptr_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
757}; 757};
758int amdgpu_max_kms_ioctl = ARRAY_SIZE(amdgpu_ioctls_kms); 758const int amdgpu_max_kms_ioctl = ARRAY_SIZE(amdgpu_ioctls_kms);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h
index 8d432e6901af..81bd964d3dfc 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h
@@ -53,7 +53,7 @@ struct amdgpu_hpd;
53 53
54#define AMDGPU_MAX_HPD_PINS 6 54#define AMDGPU_MAX_HPD_PINS 6
55#define AMDGPU_MAX_CRTCS 6 55#define AMDGPU_MAX_CRTCS 6
56#define AMDGPU_MAX_AFMT_BLOCKS 7 56#define AMDGPU_MAX_AFMT_BLOCKS 9
57 57
58enum amdgpu_rmx_type { 58enum amdgpu_rmx_type {
59 RMX_OFF, 59 RMX_OFF,
@@ -309,8 +309,8 @@ struct amdgpu_mode_info {
309 struct atom_context *atom_context; 309 struct atom_context *atom_context;
310 struct card_info *atom_card_info; 310 struct card_info *atom_card_info;
311 bool mode_config_initialized; 311 bool mode_config_initialized;
312 struct amdgpu_crtc *crtcs[6]; 312 struct amdgpu_crtc *crtcs[AMDGPU_MAX_CRTCS];
313 struct amdgpu_afmt *afmt[7]; 313 struct amdgpu_afmt *afmt[AMDGPU_MAX_AFMT_BLOCKS];
314 /* DVI-I properties */ 314 /* DVI-I properties */
315 struct drm_property *coherent_mode_property; 315 struct drm_property *coherent_mode_property;
316 /* DAC enable load detect */ 316 /* DAC enable load detect */
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
index acc08018c6cc..bdb01d932548 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
@@ -71,7 +71,7 @@ static inline int amdgpu_bo_reserve(struct amdgpu_bo *bo, bool no_intr)
71{ 71{
72 int r; 72 int r;
73 73
74 r = ttm_bo_reserve(&bo->tbo, !no_intr, false, false, 0); 74 r = ttm_bo_reserve(&bo->tbo, !no_intr, false, NULL);
75 if (unlikely(r != 0)) { 75 if (unlikely(r != 0)) {
76 if (r != -ERESTARTSYS) 76 if (r != -ERESTARTSYS)
77 dev_err(bo->adev->dev, "%p reserve failed\n", bo); 77 dev_err(bo->adev->dev, "%p reserve failed\n", bo);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
index ff9597ce268c..589b36e8c5cf 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
@@ -362,16 +362,23 @@ static ssize_t amdgpu_set_pp_dpm_sclk(struct device *dev,
362 struct amdgpu_device *adev = ddev->dev_private; 362 struct amdgpu_device *adev = ddev->dev_private;
363 int ret; 363 int ret;
364 long level; 364 long level;
365 uint32_t i, mask = 0;
366 char sub_str[2];
365 367
366 ret = kstrtol(buf, 0, &level); 368 for (i = 0; i < strlen(buf) - 1; i++) {
369 sub_str[0] = *(buf + i);
370 sub_str[1] = '\0';
371 ret = kstrtol(sub_str, 0, &level);
367 372
368 if (ret) { 373 if (ret) {
369 count = -EINVAL; 374 count = -EINVAL;
370 goto fail; 375 goto fail;
376 }
377 mask |= 1 << level;
371 } 378 }
372 379
373 if (adev->pp_enabled) 380 if (adev->pp_enabled)
374 amdgpu_dpm_force_clock_level(adev, PP_SCLK, level); 381 amdgpu_dpm_force_clock_level(adev, PP_SCLK, mask);
375fail: 382fail:
376 return count; 383 return count;
377} 384}
@@ -399,16 +406,23 @@ static ssize_t amdgpu_set_pp_dpm_mclk(struct device *dev,
399 struct amdgpu_device *adev = ddev->dev_private; 406 struct amdgpu_device *adev = ddev->dev_private;
400 int ret; 407 int ret;
401 long level; 408 long level;
409 uint32_t i, mask = 0;
410 char sub_str[2];
402 411
403 ret = kstrtol(buf, 0, &level); 412 for (i = 0; i < strlen(buf) - 1; i++) {
413 sub_str[0] = *(buf + i);
414 sub_str[1] = '\0';
415 ret = kstrtol(sub_str, 0, &level);
404 416
405 if (ret) { 417 if (ret) {
406 count = -EINVAL; 418 count = -EINVAL;
407 goto fail; 419 goto fail;
420 }
421 mask |= 1 << level;
408 } 422 }
409 423
410 if (adev->pp_enabled) 424 if (adev->pp_enabled)
411 amdgpu_dpm_force_clock_level(adev, PP_MCLK, level); 425 amdgpu_dpm_force_clock_level(adev, PP_MCLK, mask);
412fail: 426fail:
413 return count; 427 return count;
414} 428}
@@ -436,16 +450,23 @@ static ssize_t amdgpu_set_pp_dpm_pcie(struct device *dev,
436 struct amdgpu_device *adev = ddev->dev_private; 450 struct amdgpu_device *adev = ddev->dev_private;
437 int ret; 451 int ret;
438 long level; 452 long level;
453 uint32_t i, mask = 0;
454 char sub_str[2];
439 455
440 ret = kstrtol(buf, 0, &level); 456 for (i = 0; i < strlen(buf) - 1; i++) {
457 sub_str[0] = *(buf + i);
458 sub_str[1] = '\0';
459 ret = kstrtol(sub_str, 0, &level);
441 460
442 if (ret) { 461 if (ret) {
443 count = -EINVAL; 462 count = -EINVAL;
444 goto fail; 463 goto fail;
464 }
465 mask |= 1 << level;
445 } 466 }
446 467
447 if (adev->pp_enabled) 468 if (adev->pp_enabled)
448 amdgpu_dpm_force_clock_level(adev, PP_PCIE, level); 469 amdgpu_dpm_force_clock_level(adev, PP_PCIE, mask);
449fail: 470fail:
450 return count; 471 return count;
451} 472}
@@ -1212,7 +1233,7 @@ static int amdgpu_debugfs_pm_info(struct seq_file *m, void *data)
1212 return 0; 1233 return 0;
1213} 1234}
1214 1235
1215static struct drm_info_list amdgpu_pm_info_list[] = { 1236static const struct drm_info_list amdgpu_pm_info_list[] = {
1216 {"amdgpu_pm_info", amdgpu_debugfs_pm_info, 0, NULL}, 1237 {"amdgpu_pm_info", amdgpu_debugfs_pm_info, 0, NULL},
1217}; 1238};
1218#endif 1239#endif
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_powerplay.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_powerplay.c
index e9c6ae6ed2f7..be565955bcc7 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_powerplay.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_powerplay.c
@@ -99,6 +99,10 @@ static int amdgpu_pp_early_init(void *handle)
99 99
100#ifdef CONFIG_DRM_AMD_POWERPLAY 100#ifdef CONFIG_DRM_AMD_POWERPLAY
101 switch (adev->asic_type) { 101 switch (adev->asic_type) {
102 case CHIP_POLARIS11:
103 case CHIP_POLARIS10:
104 adev->pp_enabled = true;
105 break;
102 case CHIP_TONGA: 106 case CHIP_TONGA:
103 case CHIP_FIJI: 107 case CHIP_FIJI:
104 adev->pp_enabled = (amdgpu_powerplay == 0) ? false : true; 108 adev->pp_enabled = (amdgpu_powerplay == 0) ? false : true;
@@ -299,15 +303,6 @@ static int amdgpu_pp_soft_reset(void *handle)
299 return ret; 303 return ret;
300} 304}
301 305
302static void amdgpu_pp_print_status(void *handle)
303{
304 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
305
306 if (adev->powerplay.ip_funcs->print_status)
307 adev->powerplay.ip_funcs->print_status(
308 adev->powerplay.pp_handle);
309}
310
311const struct amd_ip_funcs amdgpu_pp_ip_funcs = { 306const struct amd_ip_funcs amdgpu_pp_ip_funcs = {
312 .early_init = amdgpu_pp_early_init, 307 .early_init = amdgpu_pp_early_init,
313 .late_init = amdgpu_pp_late_init, 308 .late_init = amdgpu_pp_late_init,
@@ -320,7 +315,6 @@ const struct amd_ip_funcs amdgpu_pp_ip_funcs = {
320 .is_idle = amdgpu_pp_is_idle, 315 .is_idle = amdgpu_pp_is_idle,
321 .wait_for_idle = amdgpu_pp_wait_for_idle, 316 .wait_for_idle = amdgpu_pp_wait_for_idle,
322 .soft_reset = amdgpu_pp_soft_reset, 317 .soft_reset = amdgpu_pp_soft_reset,
323 .print_status = amdgpu_pp_print_status,
324 .set_clockgating_state = amdgpu_pp_set_clockgating_state, 318 .set_clockgating_state = amdgpu_pp_set_clockgating_state,
325 .set_powergating_state = amdgpu_pp_set_powergating_state, 319 .set_powergating_state = amdgpu_pp_set_powergating_state,
326}; 320};
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
index 972eed2ef787..3b02272db678 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
@@ -46,7 +46,8 @@
46 * wptr. The GPU then starts fetching commands and executes 46 * wptr. The GPU then starts fetching commands and executes
47 * them until the pointers are equal again. 47 * them until the pointers are equal again.
48 */ 48 */
49static int amdgpu_debugfs_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring); 49static int amdgpu_debugfs_ring_init(struct amdgpu_device *adev,
50 struct amdgpu_ring *ring);
50 51
51/** 52/**
52 * amdgpu_ring_alloc - allocate space on the ring buffer 53 * amdgpu_ring_alloc - allocate space on the ring buffer
@@ -215,18 +216,17 @@ int amdgpu_ring_restore(struct amdgpu_ring *ring,
215 * 216 *
216 * @adev: amdgpu_device pointer 217 * @adev: amdgpu_device pointer
217 * @ring: amdgpu_ring structure holding ring information 218 * @ring: amdgpu_ring structure holding ring information
218 * @ring_size: size of the ring 219 * @max_ndw: maximum number of dw for ring alloc
219 * @nop: nop packet for this ring 220 * @nop: nop packet for this ring
220 * 221 *
221 * Initialize the driver information for the selected ring (all asics). 222 * Initialize the driver information for the selected ring (all asics).
222 * Returns 0 on success, error on failure. 223 * Returns 0 on success, error on failure.
223 */ 224 */
224int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring, 225int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
225 unsigned ring_size, u32 nop, u32 align_mask, 226 unsigned max_dw, u32 nop, u32 align_mask,
226 struct amdgpu_irq_src *irq_src, unsigned irq_type, 227 struct amdgpu_irq_src *irq_src, unsigned irq_type,
227 enum amdgpu_ring_type ring_type) 228 enum amdgpu_ring_type ring_type)
228{ 229{
229 u32 rb_bufsz;
230 int r; 230 int r;
231 231
232 if (ring->adev == NULL) { 232 if (ring->adev == NULL) {
@@ -265,8 +265,17 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
265 dev_err(adev->dev, "(%d) ring next_rptr wb alloc failed\n", r); 265 dev_err(adev->dev, "(%d) ring next_rptr wb alloc failed\n", r);
266 return r; 266 return r;
267 } 267 }
268 ring->next_rptr_gpu_addr = adev->wb.gpu_addr + (ring->next_rptr_offs * 4); 268 ring->next_rptr_gpu_addr = adev->wb.gpu_addr + ring->next_rptr_offs * 4;
269 ring->next_rptr_cpu_addr = &adev->wb.wb[ring->next_rptr_offs]; 269 ring->next_rptr_cpu_addr = &adev->wb.wb[ring->next_rptr_offs];
270
271 r = amdgpu_wb_get(adev, &ring->cond_exe_offs);
272 if (r) {
273 dev_err(adev->dev, "(%d) ring cond_exec_polling wb alloc failed\n", r);
274 return r;
275 }
276 ring->cond_exe_gpu_addr = adev->wb.gpu_addr + (ring->cond_exe_offs * 4);
277 ring->cond_exe_cpu_addr = &adev->wb.wb[ring->cond_exe_offs];
278
270 spin_lock_init(&ring->fence_lock); 279 spin_lock_init(&ring->fence_lock);
271 r = amdgpu_fence_driver_start_ring(ring, irq_src, irq_type); 280 r = amdgpu_fence_driver_start_ring(ring, irq_src, irq_type);
272 if (r) { 281 if (r) {
@@ -274,10 +283,8 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
274 return r; 283 return r;
275 } 284 }
276 285
277 /* Align ring size */ 286 ring->ring_size = roundup_pow_of_two(max_dw * 4 *
278 rb_bufsz = order_base_2(ring_size / 8); 287 amdgpu_sched_hw_submission);
279 ring_size = (1 << (rb_bufsz + 1)) * 4;
280 ring->ring_size = ring_size;
281 ring->align_mask = align_mask; 288 ring->align_mask = align_mask;
282 ring->nop = nop; 289 ring->nop = nop;
283 ring->type = ring_type; 290 ring->type = ring_type;
@@ -310,8 +317,7 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
310 } 317 }
311 } 318 }
312 ring->ptr_mask = (ring->ring_size / 4) - 1; 319 ring->ptr_mask = (ring->ring_size / 4) - 1;
313 ring->max_dw = DIV_ROUND_UP(ring->ring_size / 4, 320 ring->max_dw = max_dw;
314 amdgpu_sched_hw_submission);
315 321
316 if (amdgpu_debugfs_ring_init(adev, ring)) { 322 if (amdgpu_debugfs_ring_init(adev, ring)) {
317 DRM_ERROR("Failed to register debugfs file for rings !\n"); 323 DRM_ERROR("Failed to register debugfs file for rings !\n");
@@ -363,9 +369,8 @@ static int amdgpu_debugfs_ring_info(struct seq_file *m, void *data)
363 struct drm_info_node *node = (struct drm_info_node *) m->private; 369 struct drm_info_node *node = (struct drm_info_node *) m->private;
364 struct drm_device *dev = node->minor->dev; 370 struct drm_device *dev = node->minor->dev;
365 struct amdgpu_device *adev = dev->dev_private; 371 struct amdgpu_device *adev = dev->dev_private;
366 int roffset = *(int*)node->info_ent->data; 372 int roffset = (unsigned long)node->info_ent->data;
367 struct amdgpu_ring *ring = (void *)(((uint8_t*)adev) + roffset); 373 struct amdgpu_ring *ring = (void *)(((uint8_t*)adev) + roffset);
368
369 uint32_t rptr, wptr, rptr_next; 374 uint32_t rptr, wptr, rptr_next;
370 unsigned i; 375 unsigned i;
371 376
@@ -408,46 +413,37 @@ static int amdgpu_debugfs_ring_info(struct seq_file *m, void *data)
408 return 0; 413 return 0;
409} 414}
410 415
411/* TODO: clean this up !*/ 416static struct drm_info_list amdgpu_debugfs_ring_info_list[AMDGPU_MAX_RINGS];
412static int amdgpu_gfx_index = offsetof(struct amdgpu_device, gfx.gfx_ring[0]); 417static char amdgpu_debugfs_ring_names[AMDGPU_MAX_RINGS][32];
413static int cayman_cp1_index = offsetof(struct amdgpu_device, gfx.compute_ring[0]);
414static int cayman_cp2_index = offsetof(struct amdgpu_device, gfx.compute_ring[1]);
415static int amdgpu_dma1_index = offsetof(struct amdgpu_device, sdma.instance[0].ring);
416static int amdgpu_dma2_index = offsetof(struct amdgpu_device, sdma.instance[1].ring);
417static int r600_uvd_index = offsetof(struct amdgpu_device, uvd.ring);
418static int si_vce1_index = offsetof(struct amdgpu_device, vce.ring[0]);
419static int si_vce2_index = offsetof(struct amdgpu_device, vce.ring[1]);
420
421static struct drm_info_list amdgpu_debugfs_ring_info_list[] = {
422 {"amdgpu_ring_gfx", amdgpu_debugfs_ring_info, 0, &amdgpu_gfx_index},
423 {"amdgpu_ring_cp1", amdgpu_debugfs_ring_info, 0, &cayman_cp1_index},
424 {"amdgpu_ring_cp2", amdgpu_debugfs_ring_info, 0, &cayman_cp2_index},
425 {"amdgpu_ring_dma1", amdgpu_debugfs_ring_info, 0, &amdgpu_dma1_index},
426 {"amdgpu_ring_dma2", amdgpu_debugfs_ring_info, 0, &amdgpu_dma2_index},
427 {"amdgpu_ring_uvd", amdgpu_debugfs_ring_info, 0, &r600_uvd_index},
428 {"amdgpu_ring_vce1", amdgpu_debugfs_ring_info, 0, &si_vce1_index},
429 {"amdgpu_ring_vce2", amdgpu_debugfs_ring_info, 0, &si_vce2_index},
430};
431 418
432#endif 419#endif
433 420
434static int amdgpu_debugfs_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring) 421static int amdgpu_debugfs_ring_init(struct amdgpu_device *adev,
422 struct amdgpu_ring *ring)
435{ 423{
436#if defined(CONFIG_DEBUG_FS) 424#if defined(CONFIG_DEBUG_FS)
425 unsigned offset = (uint8_t*)ring - (uint8_t*)adev;
437 unsigned i; 426 unsigned i;
427 struct drm_info_list *info;
428 char *name;
429
438 for (i = 0; i < ARRAY_SIZE(amdgpu_debugfs_ring_info_list); ++i) { 430 for (i = 0; i < ARRAY_SIZE(amdgpu_debugfs_ring_info_list); ++i) {
439 struct drm_info_list *info = &amdgpu_debugfs_ring_info_list[i]; 431 info = &amdgpu_debugfs_ring_info_list[i];
440 int roffset = *(int*)amdgpu_debugfs_ring_info_list[i].data; 432 if (!info->data)
441 struct amdgpu_ring *other = (void *)(((uint8_t*)adev) + roffset); 433 break;
442 unsigned r; 434 }
443 435
444 if (other != ring) 436 if (i == ARRAY_SIZE(amdgpu_debugfs_ring_info_list))
445 continue; 437 return -ENOSPC;
446 438
447 r = amdgpu_debugfs_add_files(adev, info, 1); 439 name = &amdgpu_debugfs_ring_names[i][0];
448 if (r) 440 sprintf(name, "amdgpu_ring_%s", ring->name);
449 return r; 441 info->name = name;
450 } 442 info->show = amdgpu_debugfs_ring_info;
443 info->driver_features = 0;
444 info->data = (void*)(uintptr_t)offset;
445
446 return amdgpu_debugfs_add_files(adev, info, 1);
451#endif 447#endif
452 return 0; 448 return 0;
453} 449}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c
index c48b4fce5e57..34a92808bbd4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c
@@ -109,6 +109,29 @@ static void amdgpu_sync_keep_later(struct fence **keep, struct fence *fence)
109} 109}
110 110
111/** 111/**
112 * amdgpu_sync_add_later - add the fence to the hash
113 *
114 * @sync: sync object to add the fence to
115 * @f: fence to add
116 *
117 * Tries to add the fence to an existing hash entry. Returns true when an entry
118 * was found, false otherwise.
119 */
120static bool amdgpu_sync_add_later(struct amdgpu_sync *sync, struct fence *f)
121{
122 struct amdgpu_sync_entry *e;
123
124 hash_for_each_possible(sync->fences, e, node, f->context) {
125 if (unlikely(e->fence->context != f->context))
126 continue;
127
128 amdgpu_sync_keep_later(&e->fence, f);
129 return true;
130 }
131 return false;
132}
133
134/**
112 * amdgpu_sync_fence - remember to sync to this fence 135 * amdgpu_sync_fence - remember to sync to this fence
113 * 136 *
114 * @sync: sync object to add fence to 137 * @sync: sync object to add fence to
@@ -127,13 +150,8 @@ int amdgpu_sync_fence(struct amdgpu_device *adev, struct amdgpu_sync *sync,
127 amdgpu_sync_get_owner(f) == AMDGPU_FENCE_OWNER_VM) 150 amdgpu_sync_get_owner(f) == AMDGPU_FENCE_OWNER_VM)
128 amdgpu_sync_keep_later(&sync->last_vm_update, f); 151 amdgpu_sync_keep_later(&sync->last_vm_update, f);
129 152
130 hash_for_each_possible(sync->fences, e, node, f->context) { 153 if (amdgpu_sync_add_later(sync, f))
131 if (unlikely(e->fence->context != f->context))
132 continue;
133
134 amdgpu_sync_keep_later(&e->fence, f);
135 return 0; 154 return 0;
136 }
137 155
138 e = kmem_cache_alloc(amdgpu_sync_slab, GFP_KERNEL); 156 e = kmem_cache_alloc(amdgpu_sync_slab, GFP_KERNEL);
139 if (!e) 157 if (!e)
@@ -204,6 +222,81 @@ int amdgpu_sync_resv(struct amdgpu_device *adev,
204 return r; 222 return r;
205} 223}
206 224
225/**
226 * amdgpu_sync_is_idle - test if all fences are signaled
227 *
228 * @sync: the sync object
229 *
230 * Returns true if all fences in the sync object are signaled.
231 */
232bool amdgpu_sync_is_idle(struct amdgpu_sync *sync)
233{
234 struct amdgpu_sync_entry *e;
235 struct hlist_node *tmp;
236 int i;
237
238 hash_for_each_safe(sync->fences, i, tmp, e, node) {
239 struct fence *f = e->fence;
240
241 if (fence_is_signaled(f)) {
242 hash_del(&e->node);
243 fence_put(f);
244 kmem_cache_free(amdgpu_sync_slab, e);
245 continue;
246 }
247
248 return false;
249 }
250
251 return true;
252}
253
254/**
255 * amdgpu_sync_cycle_fences - move fences from one sync object into another
256 *
257 * @dst: the destination sync object
258 * @src: the source sync object
259 * @fence: fence to add to source
260 *
261 * Remove all fences from source and put them into destination and add
262 * fence as new one into source.
263 */
264int amdgpu_sync_cycle_fences(struct amdgpu_sync *dst, struct amdgpu_sync *src,
265 struct fence *fence)
266{
267 struct amdgpu_sync_entry *e, *newone;
268 struct hlist_node *tmp;
269 int i;
270
271 /* Allocate the new entry before moving the old ones */
272 newone = kmem_cache_alloc(amdgpu_sync_slab, GFP_KERNEL);
273 if (!newone)
274 return -ENOMEM;
275
276 hash_for_each_safe(src->fences, i, tmp, e, node) {
277 struct fence *f = e->fence;
278
279 hash_del(&e->node);
280 if (fence_is_signaled(f)) {
281 fence_put(f);
282 kmem_cache_free(amdgpu_sync_slab, e);
283 continue;
284 }
285
286 if (amdgpu_sync_add_later(dst, f)) {
287 kmem_cache_free(amdgpu_sync_slab, e);
288 continue;
289 }
290
291 hash_add(dst->fences, &e->node, f->context);
292 }
293
294 hash_add(src->fences, &newone->node, fence->context);
295 newone->fence = fence_get(fence);
296
297 return 0;
298}
299
207struct fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync) 300struct fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync)
208{ 301{
209 struct amdgpu_sync_entry *e; 302 struct amdgpu_sync_entry *e;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 6f3369de232f..a0065765ed2d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -909,6 +909,52 @@ uint32_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm,
909 return flags; 909 return flags;
910} 910}
911 911
912static void amdgpu_ttm_lru_removal(struct ttm_buffer_object *tbo)
913{
914 struct amdgpu_device *adev = amdgpu_get_adev(tbo->bdev);
915 unsigned i, j;
916
917 for (i = 0; i < AMDGPU_TTM_LRU_SIZE; ++i) {
918 struct amdgpu_mman_lru *lru = &adev->mman.log2_size[i];
919
920 for (j = 0; j < TTM_NUM_MEM_TYPES; ++j)
921 if (&tbo->lru == lru->lru[j])
922 lru->lru[j] = tbo->lru.prev;
923
924 if (&tbo->swap == lru->swap_lru)
925 lru->swap_lru = tbo->swap.prev;
926 }
927}
928
929static struct amdgpu_mman_lru *amdgpu_ttm_lru(struct ttm_buffer_object *tbo)
930{
931 struct amdgpu_device *adev = amdgpu_get_adev(tbo->bdev);
932 unsigned log2_size = min(ilog2(tbo->num_pages),
933 AMDGPU_TTM_LRU_SIZE - 1);
934
935 return &adev->mman.log2_size[log2_size];
936}
937
938static struct list_head *amdgpu_ttm_lru_tail(struct ttm_buffer_object *tbo)
939{
940 struct amdgpu_mman_lru *lru = amdgpu_ttm_lru(tbo);
941 struct list_head *res = lru->lru[tbo->mem.mem_type];
942
943 lru->lru[tbo->mem.mem_type] = &tbo->lru;
944
945 return res;
946}
947
948static struct list_head *amdgpu_ttm_swap_lru_tail(struct ttm_buffer_object *tbo)
949{
950 struct amdgpu_mman_lru *lru = amdgpu_ttm_lru(tbo);
951 struct list_head *res = lru->swap_lru;
952
953 lru->swap_lru = &tbo->swap;
954
955 return res;
956}
957
912static struct ttm_bo_driver amdgpu_bo_driver = { 958static struct ttm_bo_driver amdgpu_bo_driver = {
913 .ttm_tt_create = &amdgpu_ttm_tt_create, 959 .ttm_tt_create = &amdgpu_ttm_tt_create,
914 .ttm_tt_populate = &amdgpu_ttm_tt_populate, 960 .ttm_tt_populate = &amdgpu_ttm_tt_populate,
@@ -922,10 +968,14 @@ static struct ttm_bo_driver amdgpu_bo_driver = {
922 .fault_reserve_notify = &amdgpu_bo_fault_reserve_notify, 968 .fault_reserve_notify = &amdgpu_bo_fault_reserve_notify,
923 .io_mem_reserve = &amdgpu_ttm_io_mem_reserve, 969 .io_mem_reserve = &amdgpu_ttm_io_mem_reserve,
924 .io_mem_free = &amdgpu_ttm_io_mem_free, 970 .io_mem_free = &amdgpu_ttm_io_mem_free,
971 .lru_removal = &amdgpu_ttm_lru_removal,
972 .lru_tail = &amdgpu_ttm_lru_tail,
973 .swap_lru_tail = &amdgpu_ttm_swap_lru_tail,
925}; 974};
926 975
927int amdgpu_ttm_init(struct amdgpu_device *adev) 976int amdgpu_ttm_init(struct amdgpu_device *adev)
928{ 977{
978 unsigned i, j;
929 int r; 979 int r;
930 980
931 r = amdgpu_ttm_global_init(adev); 981 r = amdgpu_ttm_global_init(adev);
@@ -943,6 +993,15 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
943 DRM_ERROR("failed initializing buffer object driver(%d).\n", r); 993 DRM_ERROR("failed initializing buffer object driver(%d).\n", r);
944 return r; 994 return r;
945 } 995 }
996
997 for (i = 0; i < AMDGPU_TTM_LRU_SIZE; ++i) {
998 struct amdgpu_mman_lru *lru = &adev->mman.log2_size[i];
999
1000 for (j = 0; j < TTM_NUM_MEM_TYPES; ++j)
1001 lru->lru[j] = &adev->mman.bdev.man[j].lru;
1002 lru->swap_lru = &adev->mman.bdev.glob->swap_lru;
1003 }
1004
946 adev->mman.initialized = true; 1005 adev->mman.initialized = true;
947 r = ttm_bo_init_mm(&adev->mman.bdev, TTM_PL_VRAM, 1006 r = ttm_bo_init_mm(&adev->mman.bdev, TTM_PL_VRAM,
948 adev->mc.real_vram_size >> PAGE_SHIFT); 1007 adev->mc.real_vram_size >> PAGE_SHIFT);
@@ -1165,7 +1224,7 @@ static int amdgpu_mm_dump_table(struct seq_file *m, void *data)
1165static int ttm_pl_vram = TTM_PL_VRAM; 1224static int ttm_pl_vram = TTM_PL_VRAM;
1166static int ttm_pl_tt = TTM_PL_TT; 1225static int ttm_pl_tt = TTM_PL_TT;
1167 1226
1168static struct drm_info_list amdgpu_ttm_debugfs_list[] = { 1227static const struct drm_info_list amdgpu_ttm_debugfs_list[] = {
1169 {"amdgpu_vram_mm", amdgpu_mm_dump_table, 0, &ttm_pl_vram}, 1228 {"amdgpu_vram_mm", amdgpu_mm_dump_table, 0, &ttm_pl_vram},
1170 {"amdgpu_gtt_mm", amdgpu_mm_dump_table, 0, &ttm_pl_tt}, 1229 {"amdgpu_gtt_mm", amdgpu_mm_dump_table, 0, &ttm_pl_tt},
1171 {"ttm_page_pool", ttm_page_alloc_debugfs, 0, NULL}, 1230 {"ttm_page_pool", ttm_page_alloc_debugfs, 0, NULL},
@@ -1216,6 +1275,8 @@ static const struct file_operations amdgpu_ttm_vram_fops = {
1216 .llseek = default_llseek 1275 .llseek = default_llseek
1217}; 1276};
1218 1277
1278#ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
1279
1219static ssize_t amdgpu_ttm_gtt_read(struct file *f, char __user *buf, 1280static ssize_t amdgpu_ttm_gtt_read(struct file *f, char __user *buf,
1220 size_t size, loff_t *pos) 1281 size_t size, loff_t *pos)
1221{ 1282{
@@ -1263,6 +1324,8 @@ static const struct file_operations amdgpu_ttm_gtt_fops = {
1263 1324
1264#endif 1325#endif
1265 1326
1327#endif
1328
1266static int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev) 1329static int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev)
1267{ 1330{
1268#if defined(CONFIG_DEBUG_FS) 1331#if defined(CONFIG_DEBUG_FS)
@@ -1278,6 +1341,7 @@ static int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev)
1278 i_size_write(ent->d_inode, adev->mc.mc_vram_size); 1341 i_size_write(ent->d_inode, adev->mc.mc_vram_size);
1279 adev->mman.vram = ent; 1342 adev->mman.vram = ent;
1280 1343
1344#ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
1281 ent = debugfs_create_file("amdgpu_gtt", S_IFREG | S_IRUGO, root, 1345 ent = debugfs_create_file("amdgpu_gtt", S_IFREG | S_IRUGO, root,
1282 adev, &amdgpu_ttm_gtt_fops); 1346 adev, &amdgpu_ttm_gtt_fops);
1283 if (IS_ERR(ent)) 1347 if (IS_ERR(ent))
@@ -1285,6 +1349,7 @@ static int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev)
1285 i_size_write(ent->d_inode, adev->mc.gtt_size); 1349 i_size_write(ent->d_inode, adev->mc.gtt_size);
1286 adev->mman.gtt = ent; 1350 adev->mman.gtt = ent;
1287 1351
1352#endif
1288 count = ARRAY_SIZE(amdgpu_ttm_debugfs_list); 1353 count = ARRAY_SIZE(amdgpu_ttm_debugfs_list);
1289 1354
1290#ifdef CONFIG_SWIOTLB 1355#ifdef CONFIG_SWIOTLB
@@ -1306,7 +1371,10 @@ static void amdgpu_ttm_debugfs_fini(struct amdgpu_device *adev)
1306 debugfs_remove(adev->mman.vram); 1371 debugfs_remove(adev->mman.vram);
1307 adev->mman.vram = NULL; 1372 adev->mman.vram = NULL;
1308 1373
1374#ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
1309 debugfs_remove(adev->mman.gtt); 1375 debugfs_remove(adev->mman.gtt);
1310 adev->mman.gtt = NULL; 1376 adev->mman.gtt = NULL;
1311#endif 1377#endif
1378
1379#endif
1312} 1380}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
index 338da80006b6..db86012deb67 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
@@ -54,6 +54,8 @@
54#define FIRMWARE_CARRIZO "amdgpu/carrizo_uvd.bin" 54#define FIRMWARE_CARRIZO "amdgpu/carrizo_uvd.bin"
55#define FIRMWARE_FIJI "amdgpu/fiji_uvd.bin" 55#define FIRMWARE_FIJI "amdgpu/fiji_uvd.bin"
56#define FIRMWARE_STONEY "amdgpu/stoney_uvd.bin" 56#define FIRMWARE_STONEY "amdgpu/stoney_uvd.bin"
57#define FIRMWARE_POLARIS10 "amdgpu/polaris10_uvd.bin"
58#define FIRMWARE_POLARIS11 "amdgpu/polaris11_uvd.bin"
57 59
58/** 60/**
59 * amdgpu_uvd_cs_ctx - Command submission parser context 61 * amdgpu_uvd_cs_ctx - Command submission parser context
@@ -85,6 +87,8 @@ MODULE_FIRMWARE(FIRMWARE_TONGA);
85MODULE_FIRMWARE(FIRMWARE_CARRIZO); 87MODULE_FIRMWARE(FIRMWARE_CARRIZO);
86MODULE_FIRMWARE(FIRMWARE_FIJI); 88MODULE_FIRMWARE(FIRMWARE_FIJI);
87MODULE_FIRMWARE(FIRMWARE_STONEY); 89MODULE_FIRMWARE(FIRMWARE_STONEY);
90MODULE_FIRMWARE(FIRMWARE_POLARIS10);
91MODULE_FIRMWARE(FIRMWARE_POLARIS11);
88 92
89static void amdgpu_uvd_note_usage(struct amdgpu_device *adev); 93static void amdgpu_uvd_note_usage(struct amdgpu_device *adev);
90static void amdgpu_uvd_idle_work_handler(struct work_struct *work); 94static void amdgpu_uvd_idle_work_handler(struct work_struct *work);
@@ -131,6 +135,12 @@ int amdgpu_uvd_sw_init(struct amdgpu_device *adev)
131 case CHIP_STONEY: 135 case CHIP_STONEY:
132 fw_name = FIRMWARE_STONEY; 136 fw_name = FIRMWARE_STONEY;
133 break; 137 break;
138 case CHIP_POLARIS10:
139 fw_name = FIRMWARE_POLARIS10;
140 break;
141 case CHIP_POLARIS11:
142 fw_name = FIRMWARE_POLARIS11;
143 break;
134 default: 144 default:
135 return -EINVAL; 145 return -EINVAL;
136 } 146 }
@@ -151,6 +161,9 @@ int amdgpu_uvd_sw_init(struct amdgpu_device *adev)
151 return r; 161 return r;
152 } 162 }
153 163
164 /* Set the default UVD handles that the firmware can handle */
165 adev->uvd.max_handles = AMDGPU_DEFAULT_UVD_HANDLES;
166
154 hdr = (const struct common_firmware_header *)adev->uvd.fw->data; 167 hdr = (const struct common_firmware_header *)adev->uvd.fw->data;
155 family_id = le32_to_cpu(hdr->ucode_version) & 0xff; 168 family_id = le32_to_cpu(hdr->ucode_version) & 0xff;
156 version_major = (le32_to_cpu(hdr->ucode_version) >> 24) & 0xff; 169 version_major = (le32_to_cpu(hdr->ucode_version) >> 24) & 0xff;
@@ -158,8 +171,19 @@ int amdgpu_uvd_sw_init(struct amdgpu_device *adev)
158 DRM_INFO("Found UVD firmware Version: %hu.%hu Family ID: %hu\n", 171 DRM_INFO("Found UVD firmware Version: %hu.%hu Family ID: %hu\n",
159 version_major, version_minor, family_id); 172 version_major, version_minor, family_id);
160 173
174 /*
175 * Limit the number of UVD handles depending on microcode major
176 * and minor versions. The firmware version which has 40 UVD
177 * instances support is 1.80. So all subsequent versions should
178 * also have the same support.
179 */
180 if ((version_major > 0x01) ||
181 ((version_major == 0x01) && (version_minor >= 0x50)))
182 adev->uvd.max_handles = AMDGPU_MAX_UVD_HANDLES;
183
161 bo_size = AMDGPU_GPU_PAGE_ALIGN(le32_to_cpu(hdr->ucode_size_bytes) + 8) 184 bo_size = AMDGPU_GPU_PAGE_ALIGN(le32_to_cpu(hdr->ucode_size_bytes) + 8)
162 + AMDGPU_UVD_STACK_SIZE + AMDGPU_UVD_HEAP_SIZE; 185 + AMDGPU_UVD_STACK_SIZE + AMDGPU_UVD_HEAP_SIZE
186 + AMDGPU_UVD_SESSION_SIZE * adev->uvd.max_handles;
163 r = amdgpu_bo_create(adev, bo_size, PAGE_SIZE, true, 187 r = amdgpu_bo_create(adev, bo_size, PAGE_SIZE, true,
164 AMDGPU_GEM_DOMAIN_VRAM, 188 AMDGPU_GEM_DOMAIN_VRAM,
165 AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED, 189 AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED,
@@ -202,7 +226,7 @@ int amdgpu_uvd_sw_init(struct amdgpu_device *adev)
202 return r; 226 return r;
203 } 227 }
204 228
205 for (i = 0; i < AMDGPU_MAX_UVD_HANDLES; ++i) { 229 for (i = 0; i < adev->uvd.max_handles; ++i) {
206 atomic_set(&adev->uvd.handles[i], 0); 230 atomic_set(&adev->uvd.handles[i], 0);
207 adev->uvd.filp[i] = NULL; 231 adev->uvd.filp[i] = NULL;
208 } 232 }
@@ -248,7 +272,7 @@ int amdgpu_uvd_suspend(struct amdgpu_device *adev)
248 if (adev->uvd.vcpu_bo == NULL) 272 if (adev->uvd.vcpu_bo == NULL)
249 return 0; 273 return 0;
250 274
251 for (i = 0; i < AMDGPU_MAX_UVD_HANDLES; ++i) 275 for (i = 0; i < adev->uvd.max_handles; ++i)
252 if (atomic_read(&adev->uvd.handles[i])) 276 if (atomic_read(&adev->uvd.handles[i]))
253 break; 277 break;
254 278
@@ -303,7 +327,7 @@ void amdgpu_uvd_free_handles(struct amdgpu_device *adev, struct drm_file *filp)
303 struct amdgpu_ring *ring = &adev->uvd.ring; 327 struct amdgpu_ring *ring = &adev->uvd.ring;
304 int i, r; 328 int i, r;
305 329
306 for (i = 0; i < AMDGPU_MAX_UVD_HANDLES; ++i) { 330 for (i = 0; i < adev->uvd.max_handles; ++i) {
307 uint32_t handle = atomic_read(&adev->uvd.handles[i]); 331 uint32_t handle = atomic_read(&adev->uvd.handles[i]);
308 if (handle != 0 && adev->uvd.filp[i] == filp) { 332 if (handle != 0 && adev->uvd.filp[i] == filp) {
309 struct fence *fence; 333 struct fence *fence;
@@ -563,7 +587,7 @@ static int amdgpu_uvd_cs_msg(struct amdgpu_uvd_cs_ctx *ctx,
563 amdgpu_bo_kunmap(bo); 587 amdgpu_bo_kunmap(bo);
564 588
565 /* try to alloc a new handle */ 589 /* try to alloc a new handle */
566 for (i = 0; i < AMDGPU_MAX_UVD_HANDLES; ++i) { 590 for (i = 0; i < adev->uvd.max_handles; ++i) {
567 if (atomic_read(&adev->uvd.handles[i]) == handle) { 591 if (atomic_read(&adev->uvd.handles[i]) == handle) {
568 DRM_ERROR("Handle 0x%x already in use!\n", handle); 592 DRM_ERROR("Handle 0x%x already in use!\n", handle);
569 return -EINVAL; 593 return -EINVAL;
@@ -586,7 +610,7 @@ static int amdgpu_uvd_cs_msg(struct amdgpu_uvd_cs_ctx *ctx,
586 return r; 610 return r;
587 611
588 /* validate the handle */ 612 /* validate the handle */
589 for (i = 0; i < AMDGPU_MAX_UVD_HANDLES; ++i) { 613 for (i = 0; i < adev->uvd.max_handles; ++i) {
590 if (atomic_read(&adev->uvd.handles[i]) == handle) { 614 if (atomic_read(&adev->uvd.handles[i]) == handle) {
591 if (adev->uvd.filp[i] != ctx->parser->filp) { 615 if (adev->uvd.filp[i] != ctx->parser->filp) {
592 DRM_ERROR("UVD handle collision detected!\n"); 616 DRM_ERROR("UVD handle collision detected!\n");
@@ -601,7 +625,7 @@ static int amdgpu_uvd_cs_msg(struct amdgpu_uvd_cs_ctx *ctx,
601 625
602 case 2: 626 case 2:
603 /* it's a destroy msg, free the handle */ 627 /* it's a destroy msg, free the handle */
604 for (i = 0; i < AMDGPU_MAX_UVD_HANDLES; ++i) 628 for (i = 0; i < adev->uvd.max_handles; ++i)
605 atomic_cmpxchg(&adev->uvd.handles[i], handle, 0); 629 atomic_cmpxchg(&adev->uvd.handles[i], handle, 0);
606 amdgpu_bo_kunmap(bo); 630 amdgpu_bo_kunmap(bo);
607 return 0; 631 return 0;
@@ -1013,7 +1037,7 @@ static void amdgpu_uvd_idle_work_handler(struct work_struct *work)
1013 1037
1014 fences = amdgpu_fence_count_emitted(&adev->uvd.ring); 1038 fences = amdgpu_fence_count_emitted(&adev->uvd.ring);
1015 1039
1016 for (i = 0; i < AMDGPU_MAX_UVD_HANDLES; ++i) 1040 for (i = 0; i < adev->uvd.max_handles; ++i)
1017 if (atomic_read(&adev->uvd.handles[i])) 1041 if (atomic_read(&adev->uvd.handles[i]))
1018 ++handles; 1042 ++handles;
1019 1043
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c
index 4bec0c108cea..80c1048f3324 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c
@@ -50,6 +50,8 @@
50#define FIRMWARE_CARRIZO "amdgpu/carrizo_vce.bin" 50#define FIRMWARE_CARRIZO "amdgpu/carrizo_vce.bin"
51#define FIRMWARE_FIJI "amdgpu/fiji_vce.bin" 51#define FIRMWARE_FIJI "amdgpu/fiji_vce.bin"
52#define FIRMWARE_STONEY "amdgpu/stoney_vce.bin" 52#define FIRMWARE_STONEY "amdgpu/stoney_vce.bin"
53#define FIRMWARE_POLARIS10 "amdgpu/polaris10_vce.bin"
54#define FIRMWARE_POLARIS11 "amdgpu/polaris11_vce.bin"
53 55
54#ifdef CONFIG_DRM_AMDGPU_CIK 56#ifdef CONFIG_DRM_AMDGPU_CIK
55MODULE_FIRMWARE(FIRMWARE_BONAIRE); 57MODULE_FIRMWARE(FIRMWARE_BONAIRE);
@@ -62,6 +64,8 @@ MODULE_FIRMWARE(FIRMWARE_TONGA);
62MODULE_FIRMWARE(FIRMWARE_CARRIZO); 64MODULE_FIRMWARE(FIRMWARE_CARRIZO);
63MODULE_FIRMWARE(FIRMWARE_FIJI); 65MODULE_FIRMWARE(FIRMWARE_FIJI);
64MODULE_FIRMWARE(FIRMWARE_STONEY); 66MODULE_FIRMWARE(FIRMWARE_STONEY);
67MODULE_FIRMWARE(FIRMWARE_POLARIS10);
68MODULE_FIRMWARE(FIRMWARE_POLARIS11);
65 69
66static void amdgpu_vce_idle_work_handler(struct work_struct *work); 70static void amdgpu_vce_idle_work_handler(struct work_struct *work);
67 71
@@ -113,6 +117,12 @@ int amdgpu_vce_sw_init(struct amdgpu_device *adev, unsigned long size)
113 case CHIP_STONEY: 117 case CHIP_STONEY:
114 fw_name = FIRMWARE_STONEY; 118 fw_name = FIRMWARE_STONEY;
115 break; 119 break;
120 case CHIP_POLARIS10:
121 fw_name = FIRMWARE_POLARIS10;
122 break;
123 case CHIP_POLARIS11:
124 fw_name = FIRMWARE_POLARIS11;
125 break;
116 126
117 default: 127 default:
118 return -EINVAL; 128 return -EINVAL;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index b6c011b83641..856116a874bb 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -166,74 +166,109 @@ int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
166{ 166{
167 uint64_t pd_addr = amdgpu_bo_gpu_offset(vm->page_directory); 167 uint64_t pd_addr = amdgpu_bo_gpu_offset(vm->page_directory);
168 struct amdgpu_device *adev = ring->adev; 168 struct amdgpu_device *adev = ring->adev;
169 struct amdgpu_vm_id *id = &vm->ids[ring->idx];
170 struct fence *updates = sync->last_vm_update; 169 struct fence *updates = sync->last_vm_update;
170 struct amdgpu_vm_id *id;
171 unsigned i = ring->idx;
171 int r; 172 int r;
172 173
173 mutex_lock(&adev->vm_manager.lock); 174 mutex_lock(&adev->vm_manager.lock);
174 175
175 /* check if the id is still valid */ 176 /* Check if we can use a VMID already assigned to this VM */
176 if (id->mgr_id) { 177 do {
177 struct fence *flushed = id->flushed_updates; 178 struct fence *flushed;
178 bool is_later;
179 long owner;
180 179
181 if (!flushed) 180 id = vm->ids[i++];
182 is_later = true; 181 if (i == AMDGPU_MAX_RINGS)
183 else if (!updates) 182 i = 0;
184 is_later = false; 183
185 else 184 /* Check all the prerequisites to using this VMID */
186 is_later = fence_is_later(updates, flushed); 185 if (!id)
186 continue;
187
188 if (atomic_long_read(&id->owner) != (long)vm)
189 continue;
190
191 if (pd_addr != id->pd_gpu_addr)
192 continue;
187 193
188 owner = atomic_long_read(&id->mgr_id->owner); 194 if (id->last_user != ring &&
189 if (!is_later && owner == (long)id && 195 (!id->last_flush || !fence_is_signaled(id->last_flush)))
190 pd_addr == id->pd_gpu_addr) { 196 continue;
197
198 flushed = id->flushed_updates;
199 if (updates && (!flushed || fence_is_later(updates, flushed)))
200 continue;
191 201
202 /* Good we can use this VMID */
203 if (id->last_user == ring) {
192 r = amdgpu_sync_fence(ring->adev, sync, 204 r = amdgpu_sync_fence(ring->adev, sync,
193 id->mgr_id->active); 205 id->first);
194 if (r) { 206 if (r)
195 mutex_unlock(&adev->vm_manager.lock); 207 goto error;
196 return r; 208 }
197 } 209
210 /* And remember this submission as user of the VMID */
211 r = amdgpu_sync_fence(ring->adev, &id->active, fence);
212 if (r)
213 goto error;
214
215 list_move_tail(&id->list, &adev->vm_manager.ids_lru);
216 vm->ids[ring->idx] = id;
217
218 *vm_id = id - adev->vm_manager.ids;
219 *vm_pd_addr = AMDGPU_VM_NO_FLUSH;
220 trace_amdgpu_vm_grab_id(vm, ring->idx, *vm_id, *vm_pd_addr);
221
222 mutex_unlock(&adev->vm_manager.lock);
223 return 0;
198 224
199 fence_put(id->mgr_id->active); 225 } while (i != ring->idx);
200 id->mgr_id->active = fence_get(fence);
201 226
202 list_move_tail(&id->mgr_id->list, 227 id = list_first_entry(&adev->vm_manager.ids_lru,
203 &adev->vm_manager.ids_lru); 228 struct amdgpu_vm_id,
229 list);
204 230
205 *vm_id = id->mgr_id - adev->vm_manager.ids; 231 if (!amdgpu_sync_is_idle(&id->active)) {
206 *vm_pd_addr = AMDGPU_VM_NO_FLUSH; 232 struct list_head *head = &adev->vm_manager.ids_lru;
207 trace_amdgpu_vm_grab_id(vm, ring->idx, *vm_id, 233 struct amdgpu_vm_id *tmp;
208 *vm_pd_addr);
209 234
210 mutex_unlock(&adev->vm_manager.lock); 235 list_for_each_entry_safe(id, tmp, &adev->vm_manager.ids_lru,
211 return 0; 236 list) {
237 if (amdgpu_sync_is_idle(&id->active)) {
238 list_move(&id->list, head);
239 head = &id->list;
240 }
212 } 241 }
242 id = list_first_entry(&adev->vm_manager.ids_lru,
243 struct amdgpu_vm_id,
244 list);
213 } 245 }
214 246
215 id->mgr_id = list_first_entry(&adev->vm_manager.ids_lru, 247 r = amdgpu_sync_cycle_fences(sync, &id->active, fence);
216 struct amdgpu_vm_manager_id, 248 if (r)
217 list); 249 goto error;
218 250
219 r = amdgpu_sync_fence(ring->adev, sync, id->mgr_id->active); 251 fence_put(id->first);
220 if (!r) { 252 id->first = fence_get(fence);
221 fence_put(id->mgr_id->active);
222 id->mgr_id->active = fence_get(fence);
223 253
224 fence_put(id->flushed_updates); 254 fence_put(id->last_flush);
225 id->flushed_updates = fence_get(updates); 255 id->last_flush = NULL;
226 256
227 id->pd_gpu_addr = pd_addr; 257 fence_put(id->flushed_updates);
258 id->flushed_updates = fence_get(updates);
228 259
229 list_move_tail(&id->mgr_id->list, &adev->vm_manager.ids_lru); 260 id->pd_gpu_addr = pd_addr;
230 atomic_long_set(&id->mgr_id->owner, (long)id);
231 261
232 *vm_id = id->mgr_id - adev->vm_manager.ids; 262 list_move_tail(&id->list, &adev->vm_manager.ids_lru);
233 *vm_pd_addr = pd_addr; 263 id->last_user = ring;
234 trace_amdgpu_vm_grab_id(vm, ring->idx, *vm_id, *vm_pd_addr); 264 atomic_long_set(&id->owner, (long)vm);
235 } 265 vm->ids[ring->idx] = id;
266
267 *vm_id = id - adev->vm_manager.ids;
268 *vm_pd_addr = pd_addr;
269 trace_amdgpu_vm_grab_id(vm, ring->idx, *vm_id, *vm_pd_addr);
236 270
271error:
237 mutex_unlock(&adev->vm_manager.lock); 272 mutex_unlock(&adev->vm_manager.lock);
238 return r; 273 return r;
239} 274}
@@ -247,43 +282,60 @@ int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
247 * 282 *
248 * Emit a VM flush when it is necessary. 283 * Emit a VM flush when it is necessary.
249 */ 284 */
250void amdgpu_vm_flush(struct amdgpu_ring *ring, 285int amdgpu_vm_flush(struct amdgpu_ring *ring,
251 unsigned vm_id, uint64_t pd_addr, 286 unsigned vm_id, uint64_t pd_addr,
252 uint32_t gds_base, uint32_t gds_size, 287 uint32_t gds_base, uint32_t gds_size,
253 uint32_t gws_base, uint32_t gws_size, 288 uint32_t gws_base, uint32_t gws_size,
254 uint32_t oa_base, uint32_t oa_size) 289 uint32_t oa_base, uint32_t oa_size)
255{ 290{
256 struct amdgpu_device *adev = ring->adev; 291 struct amdgpu_device *adev = ring->adev;
257 struct amdgpu_vm_manager_id *mgr_id = &adev->vm_manager.ids[vm_id]; 292 struct amdgpu_vm_id *id = &adev->vm_manager.ids[vm_id];
258 bool gds_switch_needed = ring->funcs->emit_gds_switch && ( 293 bool gds_switch_needed = ring->funcs->emit_gds_switch && (
259 mgr_id->gds_base != gds_base || 294 id->gds_base != gds_base ||
260 mgr_id->gds_size != gds_size || 295 id->gds_size != gds_size ||
261 mgr_id->gws_base != gws_base || 296 id->gws_base != gws_base ||
262 mgr_id->gws_size != gws_size || 297 id->gws_size != gws_size ||
263 mgr_id->oa_base != oa_base || 298 id->oa_base != oa_base ||
264 mgr_id->oa_size != oa_size); 299 id->oa_size != oa_size);
300 int r;
265 301
266 if (ring->funcs->emit_pipeline_sync && ( 302 if (ring->funcs->emit_pipeline_sync && (
267 pd_addr != AMDGPU_VM_NO_FLUSH || gds_switch_needed)) 303 pd_addr != AMDGPU_VM_NO_FLUSH || gds_switch_needed))
268 amdgpu_ring_emit_pipeline_sync(ring); 304 amdgpu_ring_emit_pipeline_sync(ring);
269 305
270 if (pd_addr != AMDGPU_VM_NO_FLUSH) { 306 if (pd_addr != AMDGPU_VM_NO_FLUSH) {
307 struct fence *fence;
308
271 trace_amdgpu_vm_flush(pd_addr, ring->idx, vm_id); 309 trace_amdgpu_vm_flush(pd_addr, ring->idx, vm_id);
272 amdgpu_ring_emit_vm_flush(ring, vm_id, pd_addr); 310 amdgpu_ring_emit_vm_flush(ring, vm_id, pd_addr);
311
312 mutex_lock(&adev->vm_manager.lock);
313 if ((id->pd_gpu_addr == pd_addr) && (id->last_user == ring)) {
314 r = amdgpu_fence_emit(ring, &fence);
315 if (r) {
316 mutex_unlock(&adev->vm_manager.lock);
317 return r;
318 }
319 fence_put(id->last_flush);
320 id->last_flush = fence;
321 }
322 mutex_unlock(&adev->vm_manager.lock);
273 } 323 }
274 324
275 if (gds_switch_needed) { 325 if (gds_switch_needed) {
276 mgr_id->gds_base = gds_base; 326 id->gds_base = gds_base;
277 mgr_id->gds_size = gds_size; 327 id->gds_size = gds_size;
278 mgr_id->gws_base = gws_base; 328 id->gws_base = gws_base;
279 mgr_id->gws_size = gws_size; 329 id->gws_size = gws_size;
280 mgr_id->oa_base = oa_base; 330 id->oa_base = oa_base;
281 mgr_id->oa_size = oa_size; 331 id->oa_size = oa_size;
282 amdgpu_ring_emit_gds_switch(ring, vm_id, 332 amdgpu_ring_emit_gds_switch(ring, vm_id,
283 gds_base, gds_size, 333 gds_base, gds_size,
284 gws_base, gws_size, 334 gws_base, gws_size,
285 oa_base, oa_size); 335 oa_base, oa_size);
286 } 336 }
337
338 return 0;
287} 339}
288 340
289/** 341/**
@@ -296,14 +348,14 @@ void amdgpu_vm_flush(struct amdgpu_ring *ring,
296 */ 348 */
297void amdgpu_vm_reset_id(struct amdgpu_device *adev, unsigned vm_id) 349void amdgpu_vm_reset_id(struct amdgpu_device *adev, unsigned vm_id)
298{ 350{
299 struct amdgpu_vm_manager_id *mgr_id = &adev->vm_manager.ids[vm_id]; 351 struct amdgpu_vm_id *id = &adev->vm_manager.ids[vm_id];
300 352
301 mgr_id->gds_base = 0; 353 id->gds_base = 0;
302 mgr_id->gds_size = 0; 354 id->gds_size = 0;
303 mgr_id->gws_base = 0; 355 id->gws_base = 0;
304 mgr_id->gws_size = 0; 356 id->gws_size = 0;
305 mgr_id->oa_base = 0; 357 id->oa_base = 0;
306 mgr_id->oa_size = 0; 358 id->oa_size = 0;
307} 359}
308 360
309/** 361/**
@@ -335,8 +387,8 @@ struct amdgpu_bo_va *amdgpu_vm_bo_find(struct amdgpu_vm *vm,
335 * amdgpu_vm_update_pages - helper to call the right asic function 387 * amdgpu_vm_update_pages - helper to call the right asic function
336 * 388 *
337 * @adev: amdgpu_device pointer 389 * @adev: amdgpu_device pointer
338 * @gtt: GART instance to use for mapping 390 * @src: address where to copy page table entries from
339 * @gtt_flags: GTT hw access flags 391 * @pages_addr: DMA addresses to use for mapping
340 * @ib: indirect buffer to fill with commands 392 * @ib: indirect buffer to fill with commands
341 * @pe: addr of the page entry 393 * @pe: addr of the page entry
342 * @addr: dst addr to write into pe 394 * @addr: dst addr to write into pe
@@ -348,8 +400,8 @@ struct amdgpu_bo_va *amdgpu_vm_bo_find(struct amdgpu_vm *vm,
348 * to setup the page table using the DMA. 400 * to setup the page table using the DMA.
349 */ 401 */
350static void amdgpu_vm_update_pages(struct amdgpu_device *adev, 402static void amdgpu_vm_update_pages(struct amdgpu_device *adev,
351 struct amdgpu_gart *gtt, 403 uint64_t src,
352 uint32_t gtt_flags, 404 dma_addr_t *pages_addr,
353 struct amdgpu_ib *ib, 405 struct amdgpu_ib *ib,
354 uint64_t pe, uint64_t addr, 406 uint64_t pe, uint64_t addr,
355 unsigned count, uint32_t incr, 407 unsigned count, uint32_t incr,
@@ -357,12 +409,11 @@ static void amdgpu_vm_update_pages(struct amdgpu_device *adev,
357{ 409{
358 trace_amdgpu_vm_set_page(pe, addr, count, incr, flags); 410 trace_amdgpu_vm_set_page(pe, addr, count, incr, flags);
359 411
360 if ((gtt == &adev->gart) && (flags == gtt_flags)) { 412 if (src) {
361 uint64_t src = gtt->table_addr + (addr >> 12) * 8; 413 src += (addr >> 12) * 8;
362 amdgpu_vm_copy_pte(adev, ib, pe, src, count); 414 amdgpu_vm_copy_pte(adev, ib, pe, src, count);
363 415
364 } else if (gtt) { 416 } else if (pages_addr) {
365 dma_addr_t *pages_addr = gtt->pages_addr;
366 amdgpu_vm_write_pte(adev, ib, pages_addr, pe, addr, 417 amdgpu_vm_write_pte(adev, ib, pages_addr, pe, addr,
367 count, incr, flags); 418 count, incr, flags);
368 419
@@ -412,7 +463,7 @@ static int amdgpu_vm_clear_bo(struct amdgpu_device *adev,
412 if (r) 463 if (r)
413 goto error; 464 goto error;
414 465
415 amdgpu_vm_update_pages(adev, NULL, 0, &job->ibs[0], addr, 0, entries, 466 amdgpu_vm_update_pages(adev, 0, NULL, &job->ibs[0], addr, 0, entries,
416 0, 0); 467 0, 0);
417 amdgpu_ring_pad_ib(ring, &job->ibs[0]); 468 amdgpu_ring_pad_ib(ring, &job->ibs[0]);
418 469
@@ -522,7 +573,7 @@ int amdgpu_vm_update_page_directory(struct amdgpu_device *adev,
522 ((last_pt + incr * count) != pt)) { 573 ((last_pt + incr * count) != pt)) {
523 574
524 if (count) { 575 if (count) {
525 amdgpu_vm_update_pages(adev, NULL, 0, ib, 576 amdgpu_vm_update_pages(adev, 0, NULL, ib,
526 last_pde, last_pt, 577 last_pde, last_pt,
527 count, incr, 578 count, incr,
528 AMDGPU_PTE_VALID); 579 AMDGPU_PTE_VALID);
@@ -537,7 +588,7 @@ int amdgpu_vm_update_page_directory(struct amdgpu_device *adev,
537 } 588 }
538 589
539 if (count) 590 if (count)
540 amdgpu_vm_update_pages(adev, NULL, 0, ib, last_pde, last_pt, 591 amdgpu_vm_update_pages(adev, 0, NULL, ib, last_pde, last_pt,
541 count, incr, AMDGPU_PTE_VALID); 592 count, incr, AMDGPU_PTE_VALID);
542 593
543 if (ib->length_dw != 0) { 594 if (ib->length_dw != 0) {
@@ -570,8 +621,8 @@ error_free:
570 * amdgpu_vm_frag_ptes - add fragment information to PTEs 621 * amdgpu_vm_frag_ptes - add fragment information to PTEs
571 * 622 *
572 * @adev: amdgpu_device pointer 623 * @adev: amdgpu_device pointer
573 * @gtt: GART instance to use for mapping 624 * @src: address where to copy page table entries from
574 * @gtt_flags: GTT hw mapping flags 625 * @pages_addr: DMA addresses to use for mapping
575 * @ib: IB for the update 626 * @ib: IB for the update
576 * @pe_start: first PTE to handle 627 * @pe_start: first PTE to handle
577 * @pe_end: last PTE to handle 628 * @pe_end: last PTE to handle
@@ -579,8 +630,8 @@ error_free:
579 * @flags: hw mapping flags 630 * @flags: hw mapping flags
580 */ 631 */
581static void amdgpu_vm_frag_ptes(struct amdgpu_device *adev, 632static void amdgpu_vm_frag_ptes(struct amdgpu_device *adev,
582 struct amdgpu_gart *gtt, 633 uint64_t src,
583 uint32_t gtt_flags, 634 dma_addr_t *pages_addr,
584 struct amdgpu_ib *ib, 635 struct amdgpu_ib *ib,
585 uint64_t pe_start, uint64_t pe_end, 636 uint64_t pe_start, uint64_t pe_end,
586 uint64_t addr, uint32_t flags) 637 uint64_t addr, uint32_t flags)
@@ -618,10 +669,11 @@ static void amdgpu_vm_frag_ptes(struct amdgpu_device *adev,
618 return; 669 return;
619 670
620 /* system pages are non continuously */ 671 /* system pages are non continuously */
621 if (gtt || !(flags & AMDGPU_PTE_VALID) || (frag_start >= frag_end)) { 672 if (src || pages_addr || !(flags & AMDGPU_PTE_VALID) ||
673 (frag_start >= frag_end)) {
622 674
623 count = (pe_end - pe_start) / 8; 675 count = (pe_end - pe_start) / 8;
624 amdgpu_vm_update_pages(adev, gtt, gtt_flags, ib, pe_start, 676 amdgpu_vm_update_pages(adev, src, pages_addr, ib, pe_start,
625 addr, count, AMDGPU_GPU_PAGE_SIZE, 677 addr, count, AMDGPU_GPU_PAGE_SIZE,
626 flags); 678 flags);
627 return; 679 return;
@@ -630,21 +682,21 @@ static void amdgpu_vm_frag_ptes(struct amdgpu_device *adev,
630 /* handle the 4K area at the beginning */ 682 /* handle the 4K area at the beginning */
631 if (pe_start != frag_start) { 683 if (pe_start != frag_start) {
632 count = (frag_start - pe_start) / 8; 684 count = (frag_start - pe_start) / 8;
633 amdgpu_vm_update_pages(adev, NULL, 0, ib, pe_start, addr, 685 amdgpu_vm_update_pages(adev, 0, NULL, ib, pe_start, addr,
634 count, AMDGPU_GPU_PAGE_SIZE, flags); 686 count, AMDGPU_GPU_PAGE_SIZE, flags);
635 addr += AMDGPU_GPU_PAGE_SIZE * count; 687 addr += AMDGPU_GPU_PAGE_SIZE * count;
636 } 688 }
637 689
638 /* handle the area in the middle */ 690 /* handle the area in the middle */
639 count = (frag_end - frag_start) / 8; 691 count = (frag_end - frag_start) / 8;
640 amdgpu_vm_update_pages(adev, NULL, 0, ib, frag_start, addr, count, 692 amdgpu_vm_update_pages(adev, 0, NULL, ib, frag_start, addr, count,
641 AMDGPU_GPU_PAGE_SIZE, flags | frag_flags); 693 AMDGPU_GPU_PAGE_SIZE, flags | frag_flags);
642 694
643 /* handle the 4K area at the end */ 695 /* handle the 4K area at the end */
644 if (frag_end != pe_end) { 696 if (frag_end != pe_end) {
645 addr += AMDGPU_GPU_PAGE_SIZE * count; 697 addr += AMDGPU_GPU_PAGE_SIZE * count;
646 count = (pe_end - frag_end) / 8; 698 count = (pe_end - frag_end) / 8;
647 amdgpu_vm_update_pages(adev, NULL, 0, ib, frag_end, addr, 699 amdgpu_vm_update_pages(adev, 0, NULL, ib, frag_end, addr,
648 count, AMDGPU_GPU_PAGE_SIZE, flags); 700 count, AMDGPU_GPU_PAGE_SIZE, flags);
649 } 701 }
650} 702}
@@ -653,8 +705,8 @@ static void amdgpu_vm_frag_ptes(struct amdgpu_device *adev,
653 * amdgpu_vm_update_ptes - make sure that page tables are valid 705 * amdgpu_vm_update_ptes - make sure that page tables are valid
654 * 706 *
655 * @adev: amdgpu_device pointer 707 * @adev: amdgpu_device pointer
656 * @gtt: GART instance to use for mapping 708 * @src: address where to copy page table entries from
657 * @gtt_flags: GTT hw mapping flags 709 * @pages_addr: DMA addresses to use for mapping
658 * @vm: requested vm 710 * @vm: requested vm
659 * @start: start of GPU address range 711 * @start: start of GPU address range
660 * @end: end of GPU address range 712 * @end: end of GPU address range
@@ -664,8 +716,8 @@ static void amdgpu_vm_frag_ptes(struct amdgpu_device *adev,
664 * Update the page tables in the range @start - @end. 716 * Update the page tables in the range @start - @end.
665 */ 717 */
666static void amdgpu_vm_update_ptes(struct amdgpu_device *adev, 718static void amdgpu_vm_update_ptes(struct amdgpu_device *adev,
667 struct amdgpu_gart *gtt, 719 uint64_t src,
668 uint32_t gtt_flags, 720 dma_addr_t *pages_addr,
669 struct amdgpu_vm *vm, 721 struct amdgpu_vm *vm,
670 struct amdgpu_ib *ib, 722 struct amdgpu_ib *ib,
671 uint64_t start, uint64_t end, 723 uint64_t start, uint64_t end,
@@ -693,7 +745,7 @@ static void amdgpu_vm_update_ptes(struct amdgpu_device *adev,
693 745
694 if (last_pe_end != pe_start) { 746 if (last_pe_end != pe_start) {
695 747
696 amdgpu_vm_frag_ptes(adev, gtt, gtt_flags, ib, 748 amdgpu_vm_frag_ptes(adev, src, pages_addr, ib,
697 last_pe_start, last_pe_end, 749 last_pe_start, last_pe_end,
698 last_dst, flags); 750 last_dst, flags);
699 751
@@ -708,17 +760,16 @@ static void amdgpu_vm_update_ptes(struct amdgpu_device *adev,
708 dst += nptes * AMDGPU_GPU_PAGE_SIZE; 760 dst += nptes * AMDGPU_GPU_PAGE_SIZE;
709 } 761 }
710 762
711 amdgpu_vm_frag_ptes(adev, gtt, gtt_flags, ib, 763 amdgpu_vm_frag_ptes(adev, src, pages_addr, ib, last_pe_start,
712 last_pe_start, last_pe_end, 764 last_pe_end, last_dst, flags);
713 last_dst, flags);
714} 765}
715 766
716/** 767/**
717 * amdgpu_vm_bo_update_mapping - update a mapping in the vm page table 768 * amdgpu_vm_bo_update_mapping - update a mapping in the vm page table
718 * 769 *
719 * @adev: amdgpu_device pointer 770 * @adev: amdgpu_device pointer
720 * @gtt: GART instance to use for mapping 771 * @src: address where to copy page table entries from
721 * @gtt_flags: flags as they are used for GTT 772 * @pages_addr: DMA addresses to use for mapping
722 * @vm: requested vm 773 * @vm: requested vm
723 * @start: start of mapped range 774 * @start: start of mapped range
724 * @last: last mapped entry 775 * @last: last mapped entry
@@ -730,8 +781,8 @@ static void amdgpu_vm_update_ptes(struct amdgpu_device *adev,
730 * Returns 0 for success, -EINVAL for failure. 781 * Returns 0 for success, -EINVAL for failure.
731 */ 782 */
732static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev, 783static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev,
733 struct amdgpu_gart *gtt, 784 uint64_t src,
734 uint32_t gtt_flags, 785 dma_addr_t *pages_addr,
735 struct amdgpu_vm *vm, 786 struct amdgpu_vm *vm,
736 uint64_t start, uint64_t last, 787 uint64_t start, uint64_t last,
737 uint32_t flags, uint64_t addr, 788 uint32_t flags, uint64_t addr,
@@ -762,11 +813,11 @@ static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev,
762 /* padding, etc. */ 813 /* padding, etc. */
763 ndw = 64; 814 ndw = 64;
764 815
765 if ((gtt == &adev->gart) && (flags == gtt_flags)) { 816 if (src) {
766 /* only copy commands needed */ 817 /* only copy commands needed */
767 ndw += ncmds * 7; 818 ndw += ncmds * 7;
768 819
769 } else if (gtt) { 820 } else if (pages_addr) {
770 /* header for write data commands */ 821 /* header for write data commands */
771 ndw += ncmds * 4; 822 ndw += ncmds * 4;
772 823
@@ -796,8 +847,8 @@ static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev,
796 if (r) 847 if (r)
797 goto error_free; 848 goto error_free;
798 849
799 amdgpu_vm_update_ptes(adev, gtt, gtt_flags, vm, ib, start, last + 1, 850 amdgpu_vm_update_ptes(adev, src, pages_addr, vm, ib, start,
800 addr, flags); 851 last + 1, addr, flags);
801 852
802 amdgpu_ring_pad_ib(ring, ib); 853 amdgpu_ring_pad_ib(ring, ib);
803 WARN_ON(ib->length_dw > ndw); 854 WARN_ON(ib->length_dw > ndw);
@@ -823,11 +874,12 @@ error_free:
823 * amdgpu_vm_bo_split_mapping - split a mapping into smaller chunks 874 * amdgpu_vm_bo_split_mapping - split a mapping into smaller chunks
824 * 875 *
825 * @adev: amdgpu_device pointer 876 * @adev: amdgpu_device pointer
826 * @gtt: GART instance to use for mapping 877 * @gtt_flags: flags as they are used for GTT
878 * @pages_addr: DMA addresses to use for mapping
827 * @vm: requested vm 879 * @vm: requested vm
828 * @mapping: mapped range and flags to use for the update 880 * @mapping: mapped range and flags to use for the update
829 * @addr: addr to set the area to 881 * @addr: addr to set the area to
830 * @gtt_flags: flags as they are used for GTT 882 * @flags: HW flags for the mapping
831 * @fence: optional resulting fence 883 * @fence: optional resulting fence
832 * 884 *
833 * Split the mapping into smaller chunks so that each update fits 885 * Split the mapping into smaller chunks so that each update fits
@@ -835,16 +887,16 @@ error_free:
835 * Returns 0 for success, -EINVAL for failure. 887 * Returns 0 for success, -EINVAL for failure.
836 */ 888 */
837static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev, 889static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev,
838 struct amdgpu_gart *gtt,
839 uint32_t gtt_flags, 890 uint32_t gtt_flags,
891 dma_addr_t *pages_addr,
840 struct amdgpu_vm *vm, 892 struct amdgpu_vm *vm,
841 struct amdgpu_bo_va_mapping *mapping, 893 struct amdgpu_bo_va_mapping *mapping,
842 uint64_t addr, struct fence **fence) 894 uint32_t flags, uint64_t addr,
895 struct fence **fence)
843{ 896{
844 const uint64_t max_size = 64ULL * 1024ULL * 1024ULL / AMDGPU_GPU_PAGE_SIZE; 897 const uint64_t max_size = 64ULL * 1024ULL * 1024ULL / AMDGPU_GPU_PAGE_SIZE;
845 898
846 uint64_t start = mapping->it.start; 899 uint64_t src = 0, start = mapping->it.start;
847 uint32_t flags = gtt_flags;
848 int r; 900 int r;
849 901
850 /* normally,bo_va->flags only contians READABLE and WIRTEABLE bit go here 902 /* normally,bo_va->flags only contians READABLE and WIRTEABLE bit go here
@@ -857,10 +909,15 @@ static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev,
857 909
858 trace_amdgpu_vm_bo_update(mapping); 910 trace_amdgpu_vm_bo_update(mapping);
859 911
912 if (pages_addr) {
913 if (flags == gtt_flags)
914 src = adev->gart.table_addr + (addr >> 12) * 8;
915 addr = 0;
916 }
860 addr += mapping->offset; 917 addr += mapping->offset;
861 918
862 if (!gtt || ((gtt == &adev->gart) && (flags == gtt_flags))) 919 if (!pages_addr || src)
863 return amdgpu_vm_bo_update_mapping(adev, gtt, gtt_flags, vm, 920 return amdgpu_vm_bo_update_mapping(adev, src, pages_addr, vm,
864 start, mapping->it.last, 921 start, mapping->it.last,
865 flags, addr, fence); 922 flags, addr, fence);
866 923
@@ -868,7 +925,7 @@ static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev,
868 uint64_t last; 925 uint64_t last;
869 926
870 last = min((uint64_t)mapping->it.last, start + max_size - 1); 927 last = min((uint64_t)mapping->it.last, start + max_size - 1);
871 r = amdgpu_vm_bo_update_mapping(adev, gtt, gtt_flags, vm, 928 r = amdgpu_vm_bo_update_mapping(adev, src, pages_addr, vm,
872 start, last, flags, addr, 929 start, last, flags, addr,
873 fence); 930 fence);
874 if (r) 931 if (r)
@@ -899,16 +956,20 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev,
899{ 956{
900 struct amdgpu_vm *vm = bo_va->vm; 957 struct amdgpu_vm *vm = bo_va->vm;
901 struct amdgpu_bo_va_mapping *mapping; 958 struct amdgpu_bo_va_mapping *mapping;
902 struct amdgpu_gart *gtt = NULL; 959 dma_addr_t *pages_addr = NULL;
903 uint32_t flags; 960 uint32_t gtt_flags, flags;
904 uint64_t addr; 961 uint64_t addr;
905 int r; 962 int r;
906 963
907 if (mem) { 964 if (mem) {
965 struct ttm_dma_tt *ttm;
966
908 addr = (u64)mem->start << PAGE_SHIFT; 967 addr = (u64)mem->start << PAGE_SHIFT;
909 switch (mem->mem_type) { 968 switch (mem->mem_type) {
910 case TTM_PL_TT: 969 case TTM_PL_TT:
911 gtt = &bo_va->bo->adev->gart; 970 ttm = container_of(bo_va->bo->tbo.ttm, struct
971 ttm_dma_tt, ttm);
972 pages_addr = ttm->dma_address;
912 break; 973 break;
913 974
914 case TTM_PL_VRAM: 975 case TTM_PL_VRAM:
@@ -923,6 +984,7 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev,
923 } 984 }
924 985
925 flags = amdgpu_ttm_tt_pte_flags(adev, bo_va->bo->tbo.ttm, mem); 986 flags = amdgpu_ttm_tt_pte_flags(adev, bo_va->bo->tbo.ttm, mem);
987 gtt_flags = (adev == bo_va->bo->adev) ? flags : 0;
926 988
927 spin_lock(&vm->status_lock); 989 spin_lock(&vm->status_lock);
928 if (!list_empty(&bo_va->vm_status)) 990 if (!list_empty(&bo_va->vm_status))
@@ -930,7 +992,8 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev,
930 spin_unlock(&vm->status_lock); 992 spin_unlock(&vm->status_lock);
931 993
932 list_for_each_entry(mapping, &bo_va->invalids, list) { 994 list_for_each_entry(mapping, &bo_va->invalids, list) {
933 r = amdgpu_vm_bo_split_mapping(adev, gtt, flags, vm, mapping, addr, 995 r = amdgpu_vm_bo_split_mapping(adev, gtt_flags, pages_addr, vm,
996 mapping, flags, addr,
934 &bo_va->last_pt_update); 997 &bo_va->last_pt_update);
935 if (r) 998 if (r)
936 return r; 999 return r;
@@ -976,8 +1039,8 @@ int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
976 struct amdgpu_bo_va_mapping, list); 1039 struct amdgpu_bo_va_mapping, list);
977 list_del(&mapping->list); 1040 list_del(&mapping->list);
978 1041
979 r = amdgpu_vm_bo_split_mapping(adev, NULL, 0, vm, mapping, 1042 r = amdgpu_vm_bo_split_mapping(adev, 0, NULL, vm, mapping,
980 0, NULL); 1043 0, 0, NULL);
981 kfree(mapping); 1044 kfree(mapping);
982 if (r) 1045 if (r)
983 return r; 1046 return r;
@@ -1320,10 +1383,8 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm)
1320 struct amd_sched_rq *rq; 1383 struct amd_sched_rq *rq;
1321 int i, r; 1384 int i, r;
1322 1385
1323 for (i = 0; i < AMDGPU_MAX_RINGS; ++i) { 1386 for (i = 0; i < AMDGPU_MAX_RINGS; ++i)
1324 vm->ids[i].mgr_id = NULL; 1387 vm->ids[i] = NULL;
1325 vm->ids[i].flushed_updates = NULL;
1326 }
1327 vm->va = RB_ROOT; 1388 vm->va = RB_ROOT;
1328 spin_lock_init(&vm->status_lock); 1389 spin_lock_init(&vm->status_lock);
1329 INIT_LIST_HEAD(&vm->invalidated); 1390 INIT_LIST_HEAD(&vm->invalidated);
@@ -1418,12 +1479,12 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
1418 fence_put(vm->page_directory_fence); 1479 fence_put(vm->page_directory_fence);
1419 1480
1420 for (i = 0; i < AMDGPU_MAX_RINGS; ++i) { 1481 for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
1421 struct amdgpu_vm_id *id = &vm->ids[i]; 1482 struct amdgpu_vm_id *id = vm->ids[i];
1422 1483
1423 if (id->mgr_id) 1484 if (!id)
1424 atomic_long_cmpxchg(&id->mgr_id->owner, 1485 continue;
1425 (long)id, 0); 1486
1426 fence_put(id->flushed_updates); 1487 atomic_long_cmpxchg(&id->owner, (long)vm, 0);
1427 } 1488 }
1428} 1489}
1429 1490
@@ -1443,6 +1504,7 @@ void amdgpu_vm_manager_init(struct amdgpu_device *adev)
1443 /* skip over VMID 0, since it is the system VM */ 1504 /* skip over VMID 0, since it is the system VM */
1444 for (i = 1; i < adev->vm_manager.num_ids; ++i) { 1505 for (i = 1; i < adev->vm_manager.num_ids; ++i) {
1445 amdgpu_vm_reset_id(adev, i); 1506 amdgpu_vm_reset_id(adev, i);
1507 amdgpu_sync_create(&adev->vm_manager.ids[i].active);
1446 list_add_tail(&adev->vm_manager.ids[i].list, 1508 list_add_tail(&adev->vm_manager.ids[i].list,
1447 &adev->vm_manager.ids_lru); 1509 &adev->vm_manager.ids_lru);
1448 } 1510 }
@@ -1461,6 +1523,11 @@ void amdgpu_vm_manager_fini(struct amdgpu_device *adev)
1461{ 1523{
1462 unsigned i; 1524 unsigned i;
1463 1525
1464 for (i = 0; i < AMDGPU_NUM_VM; ++i) 1526 for (i = 0; i < AMDGPU_NUM_VM; ++i) {
1465 fence_put(adev->vm_manager.ids[i].active); 1527 struct amdgpu_vm_id *id = &adev->vm_manager.ids[i];
1528
1529 fence_put(adev->vm_manager.ids[i].first);
1530 amdgpu_sync_free(&adev->vm_manager.ids[i].active);
1531 fence_put(id->flushed_updates);
1532 }
1466} 1533}
diff --git a/drivers/gpu/drm/amd/amdgpu/atombios_crtc.c b/drivers/gpu/drm/amd/amdgpu/atombios_crtc.c
index 49aa35016653..49a39b1a0a96 100644
--- a/drivers/gpu/drm/amd/amdgpu/atombios_crtc.c
+++ b/drivers/gpu/drm/amd/amdgpu/atombios_crtc.c
@@ -461,13 +461,14 @@ union set_pixel_clock {
461 PIXEL_CLOCK_PARAMETERS_V3 v3; 461 PIXEL_CLOCK_PARAMETERS_V3 v3;
462 PIXEL_CLOCK_PARAMETERS_V5 v5; 462 PIXEL_CLOCK_PARAMETERS_V5 v5;
463 PIXEL_CLOCK_PARAMETERS_V6 v6; 463 PIXEL_CLOCK_PARAMETERS_V6 v6;
464 PIXEL_CLOCK_PARAMETERS_V7 v7;
464}; 465};
465 466
466/* on DCE5, make sure the voltage is high enough to support the 467/* on DCE5, make sure the voltage is high enough to support the
467 * required disp clk. 468 * required disp clk.
468 */ 469 */
469void amdgpu_atombios_crtc_set_disp_eng_pll(struct amdgpu_device *adev, 470void amdgpu_atombios_crtc_set_disp_eng_pll(struct amdgpu_device *adev,
470 u32 dispclk) 471 u32 dispclk)
471{ 472{
472 u8 frev, crev; 473 u8 frev, crev;
473 int index; 474 int index;
@@ -510,6 +511,49 @@ void amdgpu_atombios_crtc_set_disp_eng_pll(struct amdgpu_device *adev,
510 amdgpu_atom_execute_table(adev->mode_info.atom_context, index, (uint32_t *)&args); 511 amdgpu_atom_execute_table(adev->mode_info.atom_context, index, (uint32_t *)&args);
511} 512}
512 513
514union set_dce_clock {
515 SET_DCE_CLOCK_PS_ALLOCATION_V1_1 v1_1;
516 SET_DCE_CLOCK_PS_ALLOCATION_V2_1 v2_1;
517};
518
519u32 amdgpu_atombios_crtc_set_dce_clock(struct amdgpu_device *adev,
520 u32 freq, u8 clk_type, u8 clk_src)
521{
522 u8 frev, crev;
523 int index;
524 union set_dce_clock args;
525 u32 ret_freq = 0;
526
527 memset(&args, 0, sizeof(args));
528
529 index = GetIndexIntoMasterTable(COMMAND, SetDCEClock);
530 if (!amdgpu_atom_parse_cmd_header(adev->mode_info.atom_context, index, &frev,
531 &crev))
532 return 0;
533
534 switch (frev) {
535 case 2:
536 switch (crev) {
537 case 1:
538 args.v2_1.asParam.ulDCEClkFreq = cpu_to_le32(freq); /* 10kHz units */
539 args.v2_1.asParam.ucDCEClkType = clk_type;
540 args.v2_1.asParam.ucDCEClkSrc = clk_src;
541 amdgpu_atom_execute_table(adev->mode_info.atom_context, index, (uint32_t *)&args);
542 ret_freq = le32_to_cpu(args.v2_1.asParam.ulDCEClkFreq) * 10;
543 break;
544 default:
545 DRM_ERROR("Unknown table version %d %d\n", frev, crev);
546 return 0;
547 }
548 break;
549 default:
550 DRM_ERROR("Unknown table version %d %d\n", frev, crev);
551 return 0;
552 }
553
554 return ret_freq;
555}
556
513static bool is_pixel_clock_source_from_pll(u32 encoder_mode, int pll_id) 557static bool is_pixel_clock_source_from_pll(u32 encoder_mode, int pll_id)
514{ 558{
515 if (ENCODER_MODE_IS_DP(encoder_mode)) { 559 if (ENCODER_MODE_IS_DP(encoder_mode)) {
@@ -523,18 +567,18 @@ static bool is_pixel_clock_source_from_pll(u32 encoder_mode, int pll_id)
523} 567}
524 568
525void amdgpu_atombios_crtc_program_pll(struct drm_crtc *crtc, 569void amdgpu_atombios_crtc_program_pll(struct drm_crtc *crtc,
526 u32 crtc_id, 570 u32 crtc_id,
527 int pll_id, 571 int pll_id,
528 u32 encoder_mode, 572 u32 encoder_mode,
529 u32 encoder_id, 573 u32 encoder_id,
530 u32 clock, 574 u32 clock,
531 u32 ref_div, 575 u32 ref_div,
532 u32 fb_div, 576 u32 fb_div,
533 u32 frac_fb_div, 577 u32 frac_fb_div,
534 u32 post_div, 578 u32 post_div,
535 int bpc, 579 int bpc,
536 bool ss_enabled, 580 bool ss_enabled,
537 struct amdgpu_atom_ss *ss) 581 struct amdgpu_atom_ss *ss)
538{ 582{
539 struct drm_device *dev = crtc->dev; 583 struct drm_device *dev = crtc->dev;
540 struct amdgpu_device *adev = dev->dev_private; 584 struct amdgpu_device *adev = dev->dev_private;
@@ -652,6 +696,34 @@ void amdgpu_atombios_crtc_program_pll(struct drm_crtc *crtc,
652 args.v6.ucEncoderMode = encoder_mode; 696 args.v6.ucEncoderMode = encoder_mode;
653 args.v6.ucPpll = pll_id; 697 args.v6.ucPpll = pll_id;
654 break; 698 break;
699 case 7:
700 args.v7.ulPixelClock = cpu_to_le32(clock * 10); /* 100 hz units */
701 args.v7.ucMiscInfo = 0;
702 if ((encoder_mode == ATOM_ENCODER_MODE_DVI) &&
703 (clock > 165000))
704 args.v7.ucMiscInfo |= PIXEL_CLOCK_V7_MISC_DVI_DUALLINK_EN;
705 args.v7.ucCRTC = crtc_id;
706 if (encoder_mode == ATOM_ENCODER_MODE_HDMI) {
707 switch (bpc) {
708 case 8:
709 default:
710 args.v7.ucDeepColorRatio = PIXEL_CLOCK_V7_DEEPCOLOR_RATIO_DIS;
711 break;
712 case 10:
713 args.v7.ucDeepColorRatio = PIXEL_CLOCK_V7_DEEPCOLOR_RATIO_5_4;
714 break;
715 case 12:
716 args.v7.ucDeepColorRatio = PIXEL_CLOCK_V7_DEEPCOLOR_RATIO_3_2;
717 break;
718 case 16:
719 args.v7.ucDeepColorRatio = PIXEL_CLOCK_V7_DEEPCOLOR_RATIO_2_1;
720 break;
721 }
722 }
723 args.v7.ucTransmitterID = encoder_id;
724 args.v7.ucEncoderMode = encoder_mode;
725 args.v7.ucPpll = pll_id;
726 break;
655 default: 727 default:
656 DRM_ERROR("Unknown table version %d %d\n", frev, crev); 728 DRM_ERROR("Unknown table version %d %d\n", frev, crev);
657 return; 729 return;
diff --git a/drivers/gpu/drm/amd/amdgpu/atombios_crtc.h b/drivers/gpu/drm/amd/amdgpu/atombios_crtc.h
index c67083335b13..0eeda8e3bf5c 100644
--- a/drivers/gpu/drm/amd/amdgpu/atombios_crtc.h
+++ b/drivers/gpu/drm/amd/amdgpu/atombios_crtc.h
@@ -37,6 +37,8 @@ void amdgpu_atombios_crtc_set_dtd_timing(struct drm_crtc *crtc,
37 struct drm_display_mode *mode); 37 struct drm_display_mode *mode);
38void amdgpu_atombios_crtc_set_disp_eng_pll(struct amdgpu_device *adev, 38void amdgpu_atombios_crtc_set_disp_eng_pll(struct amdgpu_device *adev,
39 u32 dispclk); 39 u32 dispclk);
40u32 amdgpu_atombios_crtc_set_dce_clock(struct amdgpu_device *adev,
41 u32 freq, u8 clk_type, u8 clk_src);
40void amdgpu_atombios_crtc_program_pll(struct drm_crtc *crtc, 42void amdgpu_atombios_crtc_program_pll(struct drm_crtc *crtc,
41 u32 crtc_id, 43 u32 crtc_id,
42 int pll_id, 44 int pll_id,
diff --git a/drivers/gpu/drm/amd/amdgpu/atombios_encoders.c b/drivers/gpu/drm/amd/amdgpu/atombios_encoders.c
index 1e0bba29e167..a873780183d5 100644
--- a/drivers/gpu/drm/amd/amdgpu/atombios_encoders.c
+++ b/drivers/gpu/drm/amd/amdgpu/atombios_encoders.c
@@ -563,6 +563,7 @@ union dig_encoder_control {
563 DIG_ENCODER_CONTROL_PARAMETERS_V2 v2; 563 DIG_ENCODER_CONTROL_PARAMETERS_V2 v2;
564 DIG_ENCODER_CONTROL_PARAMETERS_V3 v3; 564 DIG_ENCODER_CONTROL_PARAMETERS_V3 v3;
565 DIG_ENCODER_CONTROL_PARAMETERS_V4 v4; 565 DIG_ENCODER_CONTROL_PARAMETERS_V4 v4;
566 DIG_ENCODER_CONTROL_PARAMETERS_V5 v5;
566}; 567};
567 568
568void 569void
@@ -690,6 +691,47 @@ amdgpu_atombios_encoder_setup_dig_encoder(struct drm_encoder *encoder,
690 else 691 else
691 args.v4.ucHPD_ID = hpd_id + 1; 692 args.v4.ucHPD_ID = hpd_id + 1;
692 break; 693 break;
694 case 5:
695 switch (action) {
696 case ATOM_ENCODER_CMD_SETUP_PANEL_MODE:
697 args.v5.asDPPanelModeParam.ucAction = action;
698 args.v5.asDPPanelModeParam.ucPanelMode = panel_mode;
699 args.v5.asDPPanelModeParam.ucDigId = dig->dig_encoder;
700 break;
701 case ATOM_ENCODER_CMD_STREAM_SETUP:
702 args.v5.asStreamParam.ucAction = action;
703 args.v5.asStreamParam.ucDigId = dig->dig_encoder;
704 args.v5.asStreamParam.ucDigMode =
705 amdgpu_atombios_encoder_get_encoder_mode(encoder);
706 if (ENCODER_MODE_IS_DP(args.v5.asStreamParam.ucDigMode))
707 args.v5.asStreamParam.ucLaneNum = dp_lane_count;
708 else if (amdgpu_dig_monitor_is_duallink(encoder,
709 amdgpu_encoder->pixel_clock))
710 args.v5.asStreamParam.ucLaneNum = 8;
711 else
712 args.v5.asStreamParam.ucLaneNum = 4;
713 args.v5.asStreamParam.ulPixelClock =
714 cpu_to_le32(amdgpu_encoder->pixel_clock / 10);
715 args.v5.asStreamParam.ucBitPerColor =
716 amdgpu_atombios_encoder_get_bpc(encoder);
717 args.v5.asStreamParam.ucLinkRateIn270Mhz = dp_clock / 27000;
718 break;
719 case ATOM_ENCODER_CMD_DP_LINK_TRAINING_START:
720 case ATOM_ENCODER_CMD_DP_LINK_TRAINING_PATTERN1:
721 case ATOM_ENCODER_CMD_DP_LINK_TRAINING_PATTERN2:
722 case ATOM_ENCODER_CMD_DP_LINK_TRAINING_PATTERN3:
723 case ATOM_ENCODER_CMD_DP_LINK_TRAINING_PATTERN4:
724 case ATOM_ENCODER_CMD_DP_LINK_TRAINING_COMPLETE:
725 case ATOM_ENCODER_CMD_DP_VIDEO_OFF:
726 case ATOM_ENCODER_CMD_DP_VIDEO_ON:
727 args.v5.asCmdParam.ucAction = action;
728 args.v5.asCmdParam.ucDigId = dig->dig_encoder;
729 break;
730 default:
731 DRM_ERROR("Unsupported action 0x%x\n", action);
732 break;
733 }
734 break;
693 default: 735 default:
694 DRM_ERROR("Unknown table version %d, %d\n", frev, crev); 736 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
695 break; 737 break;
@@ -710,11 +752,12 @@ union dig_transmitter_control {
710 DIG_TRANSMITTER_CONTROL_PARAMETERS_V3 v3; 752 DIG_TRANSMITTER_CONTROL_PARAMETERS_V3 v3;
711 DIG_TRANSMITTER_CONTROL_PARAMETERS_V4 v4; 753 DIG_TRANSMITTER_CONTROL_PARAMETERS_V4 v4;
712 DIG_TRANSMITTER_CONTROL_PARAMETERS_V1_5 v5; 754 DIG_TRANSMITTER_CONTROL_PARAMETERS_V1_5 v5;
755 DIG_TRANSMITTER_CONTROL_PARAMETERS_V1_6 v6;
713}; 756};
714 757
715void 758void
716amdgpu_atombios_encoder_setup_dig_transmitter(struct drm_encoder *encoder, int action, 759amdgpu_atombios_encoder_setup_dig_transmitter(struct drm_encoder *encoder, int action,
717 uint8_t lane_num, uint8_t lane_set) 760 uint8_t lane_num, uint8_t lane_set)
718{ 761{
719 struct drm_device *dev = encoder->dev; 762 struct drm_device *dev = encoder->dev;
720 struct amdgpu_device *adev = dev->dev_private; 763 struct amdgpu_device *adev = dev->dev_private;
@@ -1066,6 +1109,54 @@ amdgpu_atombios_encoder_setup_dig_transmitter(struct drm_encoder *encoder, int a
1066 args.v5.ucDigEncoderSel = 1 << dig_encoder; 1109 args.v5.ucDigEncoderSel = 1 << dig_encoder;
1067 args.v5.ucDPLaneSet = lane_set; 1110 args.v5.ucDPLaneSet = lane_set;
1068 break; 1111 break;
1112 case 6:
1113 args.v6.ucAction = action;
1114 if (is_dp)
1115 args.v6.ulSymClock = cpu_to_le32(dp_clock / 10);
1116 else
1117 args.v6.ulSymClock = cpu_to_le32(amdgpu_encoder->pixel_clock / 10);
1118
1119 switch (amdgpu_encoder->encoder_id) {
1120 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
1121 if (dig->linkb)
1122 args.v6.ucPhyId = ATOM_PHY_ID_UNIPHYB;
1123 else
1124 args.v6.ucPhyId = ATOM_PHY_ID_UNIPHYA;
1125 break;
1126 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
1127 if (dig->linkb)
1128 args.v6.ucPhyId = ATOM_PHY_ID_UNIPHYD;
1129 else
1130 args.v6.ucPhyId = ATOM_PHY_ID_UNIPHYC;
1131 break;
1132 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
1133 if (dig->linkb)
1134 args.v6.ucPhyId = ATOM_PHY_ID_UNIPHYF;
1135 else
1136 args.v6.ucPhyId = ATOM_PHY_ID_UNIPHYE;
1137 break;
1138 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3:
1139 args.v6.ucPhyId = ATOM_PHY_ID_UNIPHYG;
1140 break;
1141 }
1142 if (is_dp)
1143 args.v6.ucLaneNum = dp_lane_count;
1144 else if (amdgpu_dig_monitor_is_duallink(encoder, amdgpu_encoder->pixel_clock))
1145 args.v6.ucLaneNum = 8;
1146 else
1147 args.v6.ucLaneNum = 4;
1148 args.v6.ucConnObjId = connector_object_id;
1149 if (action == ATOM_TRANSMITTER_ACTION_SETUP_VSEMPH)
1150 args.v6.ucDPLaneSet = lane_set;
1151 else
1152 args.v6.ucDigMode = amdgpu_atombios_encoder_get_encoder_mode(encoder);
1153
1154 if (hpd_id == AMDGPU_HPD_NONE)
1155 args.v6.ucHPDSel = 0;
1156 else
1157 args.v6.ucHPDSel = hpd_id + 1;
1158 args.v6.ucDigEncoderSel = 1 << dig_encoder;
1159 break;
1069 default: 1160 default:
1070 DRM_ERROR("Unknown table version %d, %d\n", frev, crev); 1161 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
1071 break; 1162 break;
diff --git a/drivers/gpu/drm/amd/amdgpu/ci_dpm.c b/drivers/gpu/drm/amd/amdgpu/ci_dpm.c
index 1f9109d3348b..90f83b21b38c 100644
--- a/drivers/gpu/drm/amd/amdgpu/ci_dpm.c
+++ b/drivers/gpu/drm/amd/amdgpu/ci_dpm.c
@@ -6309,215 +6309,6 @@ static int ci_dpm_wait_for_idle(void *handle)
6309 return 0; 6309 return 0;
6310} 6310}
6311 6311
6312static void ci_dpm_print_status(void *handle)
6313{
6314 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
6315
6316 dev_info(adev->dev, "CIK DPM registers\n");
6317 dev_info(adev->dev, " BIOS_SCRATCH_4=0x%08X\n",
6318 RREG32(mmBIOS_SCRATCH_4));
6319 dev_info(adev->dev, " MC_ARB_DRAM_TIMING=0x%08X\n",
6320 RREG32(mmMC_ARB_DRAM_TIMING));
6321 dev_info(adev->dev, " MC_ARB_DRAM_TIMING2=0x%08X\n",
6322 RREG32(mmMC_ARB_DRAM_TIMING2));
6323 dev_info(adev->dev, " MC_ARB_BURST_TIME=0x%08X\n",
6324 RREG32(mmMC_ARB_BURST_TIME));
6325 dev_info(adev->dev, " MC_ARB_DRAM_TIMING_1=0x%08X\n",
6326 RREG32(mmMC_ARB_DRAM_TIMING_1));
6327 dev_info(adev->dev, " MC_ARB_DRAM_TIMING2_1=0x%08X\n",
6328 RREG32(mmMC_ARB_DRAM_TIMING2_1));
6329 dev_info(adev->dev, " MC_CG_CONFIG=0x%08X\n",
6330 RREG32(mmMC_CG_CONFIG));
6331 dev_info(adev->dev, " MC_ARB_CG=0x%08X\n",
6332 RREG32(mmMC_ARB_CG));
6333 dev_info(adev->dev, " DIDT_SQ_CTRL0=0x%08X\n",
6334 RREG32_DIDT(ixDIDT_SQ_CTRL0));
6335 dev_info(adev->dev, " DIDT_DB_CTRL0=0x%08X\n",
6336 RREG32_DIDT(ixDIDT_DB_CTRL0));
6337 dev_info(adev->dev, " DIDT_TD_CTRL0=0x%08X\n",
6338 RREG32_DIDT(ixDIDT_TD_CTRL0));
6339 dev_info(adev->dev, " DIDT_TCP_CTRL0=0x%08X\n",
6340 RREG32_DIDT(ixDIDT_TCP_CTRL0));
6341 dev_info(adev->dev, " CG_THERMAL_INT=0x%08X\n",
6342 RREG32_SMC(ixCG_THERMAL_INT));
6343 dev_info(adev->dev, " CG_THERMAL_CTRL=0x%08X\n",
6344 RREG32_SMC(ixCG_THERMAL_CTRL));
6345 dev_info(adev->dev, " GENERAL_PWRMGT=0x%08X\n",
6346 RREG32_SMC(ixGENERAL_PWRMGT));
6347 dev_info(adev->dev, " MC_SEQ_CNTL_3=0x%08X\n",
6348 RREG32(mmMC_SEQ_CNTL_3));
6349 dev_info(adev->dev, " LCAC_MC0_CNTL=0x%08X\n",
6350 RREG32_SMC(ixLCAC_MC0_CNTL));
6351 dev_info(adev->dev, " LCAC_MC1_CNTL=0x%08X\n",
6352 RREG32_SMC(ixLCAC_MC1_CNTL));
6353 dev_info(adev->dev, " LCAC_CPL_CNTL=0x%08X\n",
6354 RREG32_SMC(ixLCAC_CPL_CNTL));
6355 dev_info(adev->dev, " SCLK_PWRMGT_CNTL=0x%08X\n",
6356 RREG32_SMC(ixSCLK_PWRMGT_CNTL));
6357 dev_info(adev->dev, " BIF_LNCNT_RESET=0x%08X\n",
6358 RREG32(mmBIF_LNCNT_RESET));
6359 dev_info(adev->dev, " FIRMWARE_FLAGS=0x%08X\n",
6360 RREG32_SMC(ixFIRMWARE_FLAGS));
6361 dev_info(adev->dev, " CG_SPLL_FUNC_CNTL=0x%08X\n",
6362 RREG32_SMC(ixCG_SPLL_FUNC_CNTL));
6363 dev_info(adev->dev, " CG_SPLL_FUNC_CNTL_2=0x%08X\n",
6364 RREG32_SMC(ixCG_SPLL_FUNC_CNTL_2));
6365 dev_info(adev->dev, " CG_SPLL_FUNC_CNTL_3=0x%08X\n",
6366 RREG32_SMC(ixCG_SPLL_FUNC_CNTL_3));
6367 dev_info(adev->dev, " CG_SPLL_FUNC_CNTL_4=0x%08X\n",
6368 RREG32_SMC(ixCG_SPLL_FUNC_CNTL_4));
6369 dev_info(adev->dev, " CG_SPLL_SPREAD_SPECTRUM=0x%08X\n",
6370 RREG32_SMC(ixCG_SPLL_SPREAD_SPECTRUM));
6371 dev_info(adev->dev, " CG_SPLL_SPREAD_SPECTRUM_2=0x%08X\n",
6372 RREG32_SMC(ixCG_SPLL_SPREAD_SPECTRUM_2));
6373 dev_info(adev->dev, " DLL_CNTL=0x%08X\n",
6374 RREG32(mmDLL_CNTL));
6375 dev_info(adev->dev, " MCLK_PWRMGT_CNTL=0x%08X\n",
6376 RREG32(mmMCLK_PWRMGT_CNTL));
6377 dev_info(adev->dev, " MPLL_AD_FUNC_CNTL=0x%08X\n",
6378 RREG32(mmMPLL_AD_FUNC_CNTL));
6379 dev_info(adev->dev, " MPLL_DQ_FUNC_CNTL=0x%08X\n",
6380 RREG32(mmMPLL_DQ_FUNC_CNTL));
6381 dev_info(adev->dev, " MPLL_FUNC_CNTL=0x%08X\n",
6382 RREG32(mmMPLL_FUNC_CNTL));
6383 dev_info(adev->dev, " MPLL_FUNC_CNTL_1=0x%08X\n",
6384 RREG32(mmMPLL_FUNC_CNTL_1));
6385 dev_info(adev->dev, " MPLL_FUNC_CNTL_2=0x%08X\n",
6386 RREG32(mmMPLL_FUNC_CNTL_2));
6387 dev_info(adev->dev, " MPLL_SS1=0x%08X\n",
6388 RREG32(mmMPLL_SS1));
6389 dev_info(adev->dev, " MPLL_SS2=0x%08X\n",
6390 RREG32(mmMPLL_SS2));
6391 dev_info(adev->dev, " CG_DISPLAY_GAP_CNTL=0x%08X\n",
6392 RREG32_SMC(ixCG_DISPLAY_GAP_CNTL));
6393 dev_info(adev->dev, " CG_DISPLAY_GAP_CNTL2=0x%08X\n",
6394 RREG32_SMC(ixCG_DISPLAY_GAP_CNTL2));
6395 dev_info(adev->dev, " CG_STATIC_SCREEN_PARAMETER=0x%08X\n",
6396 RREG32_SMC(ixCG_STATIC_SCREEN_PARAMETER));
6397 dev_info(adev->dev, " CG_FREQ_TRAN_VOTING_0=0x%08X\n",
6398 RREG32_SMC(ixCG_FREQ_TRAN_VOTING_0));
6399 dev_info(adev->dev, " CG_FREQ_TRAN_VOTING_1=0x%08X\n",
6400 RREG32_SMC(ixCG_FREQ_TRAN_VOTING_1));
6401 dev_info(adev->dev, " CG_FREQ_TRAN_VOTING_2=0x%08X\n",
6402 RREG32_SMC(ixCG_FREQ_TRAN_VOTING_2));
6403 dev_info(adev->dev, " CG_FREQ_TRAN_VOTING_3=0x%08X\n",
6404 RREG32_SMC(ixCG_FREQ_TRAN_VOTING_3));
6405 dev_info(adev->dev, " CG_FREQ_TRAN_VOTING_4=0x%08X\n",
6406 RREG32_SMC(ixCG_FREQ_TRAN_VOTING_4));
6407 dev_info(adev->dev, " CG_FREQ_TRAN_VOTING_5=0x%08X\n",
6408 RREG32_SMC(ixCG_FREQ_TRAN_VOTING_5));
6409 dev_info(adev->dev, " CG_FREQ_TRAN_VOTING_6=0x%08X\n",
6410 RREG32_SMC(ixCG_FREQ_TRAN_VOTING_6));
6411 dev_info(adev->dev, " CG_FREQ_TRAN_VOTING_7=0x%08X\n",
6412 RREG32_SMC(ixCG_FREQ_TRAN_VOTING_7));
6413 dev_info(adev->dev, " RCU_UC_EVENTS=0x%08X\n",
6414 RREG32_SMC(ixRCU_UC_EVENTS));
6415 dev_info(adev->dev, " DPM_TABLE_475=0x%08X\n",
6416 RREG32_SMC(ixDPM_TABLE_475));
6417 dev_info(adev->dev, " MC_SEQ_RAS_TIMING_LP=0x%08X\n",
6418 RREG32(mmMC_SEQ_RAS_TIMING_LP));
6419 dev_info(adev->dev, " MC_SEQ_RAS_TIMING=0x%08X\n",
6420 RREG32(mmMC_SEQ_RAS_TIMING));
6421 dev_info(adev->dev, " MC_SEQ_CAS_TIMING_LP=0x%08X\n",
6422 RREG32(mmMC_SEQ_CAS_TIMING_LP));
6423 dev_info(adev->dev, " MC_SEQ_CAS_TIMING=0x%08X\n",
6424 RREG32(mmMC_SEQ_CAS_TIMING));
6425 dev_info(adev->dev, " MC_SEQ_DLL_STBY_LP=0x%08X\n",
6426 RREG32(mmMC_SEQ_DLL_STBY_LP));
6427 dev_info(adev->dev, " MC_SEQ_DLL_STBY=0x%08X\n",
6428 RREG32(mmMC_SEQ_DLL_STBY));
6429 dev_info(adev->dev, " MC_SEQ_G5PDX_CMD0_LP=0x%08X\n",
6430 RREG32(mmMC_SEQ_G5PDX_CMD0_LP));
6431 dev_info(adev->dev, " MC_SEQ_G5PDX_CMD0=0x%08X\n",
6432 RREG32(mmMC_SEQ_G5PDX_CMD0));
6433 dev_info(adev->dev, " MC_SEQ_G5PDX_CMD1_LP=0x%08X\n",
6434 RREG32(mmMC_SEQ_G5PDX_CMD1_LP));
6435 dev_info(adev->dev, " MC_SEQ_G5PDX_CMD1=0x%08X\n",
6436 RREG32(mmMC_SEQ_G5PDX_CMD1));
6437 dev_info(adev->dev, " MC_SEQ_G5PDX_CTRL_LP=0x%08X\n",
6438 RREG32(mmMC_SEQ_G5PDX_CTRL_LP));
6439 dev_info(adev->dev, " MC_SEQ_G5PDX_CTRL=0x%08X\n",
6440 RREG32(mmMC_SEQ_G5PDX_CTRL));
6441 dev_info(adev->dev, " MC_SEQ_PMG_DVS_CMD_LP=0x%08X\n",
6442 RREG32(mmMC_SEQ_PMG_DVS_CMD_LP));
6443 dev_info(adev->dev, " MC_SEQ_PMG_DVS_CMD=0x%08X\n",
6444 RREG32(mmMC_SEQ_PMG_DVS_CMD));
6445 dev_info(adev->dev, " MC_SEQ_PMG_DVS_CTL_LP=0x%08X\n",
6446 RREG32(mmMC_SEQ_PMG_DVS_CTL_LP));
6447 dev_info(adev->dev, " MC_SEQ_PMG_DVS_CTL=0x%08X\n",
6448 RREG32(mmMC_SEQ_PMG_DVS_CTL));
6449 dev_info(adev->dev, " MC_SEQ_MISC_TIMING_LP=0x%08X\n",
6450 RREG32(mmMC_SEQ_MISC_TIMING_LP));
6451 dev_info(adev->dev, " MC_SEQ_MISC_TIMING=0x%08X\n",
6452 RREG32(mmMC_SEQ_MISC_TIMING));
6453 dev_info(adev->dev, " MC_SEQ_MISC_TIMING2_LP=0x%08X\n",
6454 RREG32(mmMC_SEQ_MISC_TIMING2_LP));
6455 dev_info(adev->dev, " MC_SEQ_MISC_TIMING2=0x%08X\n",
6456 RREG32(mmMC_SEQ_MISC_TIMING2));
6457 dev_info(adev->dev, " MC_SEQ_PMG_CMD_EMRS_LP=0x%08X\n",
6458 RREG32(mmMC_SEQ_PMG_CMD_EMRS_LP));
6459 dev_info(adev->dev, " MC_PMG_CMD_EMRS=0x%08X\n",
6460 RREG32(mmMC_PMG_CMD_EMRS));
6461 dev_info(adev->dev, " MC_SEQ_PMG_CMD_MRS_LP=0x%08X\n",
6462 RREG32(mmMC_SEQ_PMG_CMD_MRS_LP));
6463 dev_info(adev->dev, " MC_PMG_CMD_MRS=0x%08X\n",
6464 RREG32(mmMC_PMG_CMD_MRS));
6465 dev_info(adev->dev, " MC_SEQ_PMG_CMD_MRS1_LP=0x%08X\n",
6466 RREG32(mmMC_SEQ_PMG_CMD_MRS1_LP));
6467 dev_info(adev->dev, " MC_PMG_CMD_MRS1=0x%08X\n",
6468 RREG32(mmMC_PMG_CMD_MRS1));
6469 dev_info(adev->dev, " MC_SEQ_WR_CTL_D0_LP=0x%08X\n",
6470 RREG32(mmMC_SEQ_WR_CTL_D0_LP));
6471 dev_info(adev->dev, " MC_SEQ_WR_CTL_D0=0x%08X\n",
6472 RREG32(mmMC_SEQ_WR_CTL_D0));
6473 dev_info(adev->dev, " MC_SEQ_WR_CTL_D1_LP=0x%08X\n",
6474 RREG32(mmMC_SEQ_WR_CTL_D1_LP));
6475 dev_info(adev->dev, " MC_SEQ_WR_CTL_D1=0x%08X\n",
6476 RREG32(mmMC_SEQ_WR_CTL_D1));
6477 dev_info(adev->dev, " MC_SEQ_RD_CTL_D0_LP=0x%08X\n",
6478 RREG32(mmMC_SEQ_RD_CTL_D0_LP));
6479 dev_info(adev->dev, " MC_SEQ_RD_CTL_D0=0x%08X\n",
6480 RREG32(mmMC_SEQ_RD_CTL_D0));
6481 dev_info(adev->dev, " MC_SEQ_RD_CTL_D1_LP=0x%08X\n",
6482 RREG32(mmMC_SEQ_RD_CTL_D1_LP));
6483 dev_info(adev->dev, " MC_SEQ_RD_CTL_D1=0x%08X\n",
6484 RREG32(mmMC_SEQ_RD_CTL_D1));
6485 dev_info(adev->dev, " MC_SEQ_PMG_TIMING_LP=0x%08X\n",
6486 RREG32(mmMC_SEQ_PMG_TIMING_LP));
6487 dev_info(adev->dev, " MC_SEQ_PMG_TIMING=0x%08X\n",
6488 RREG32(mmMC_SEQ_PMG_TIMING));
6489 dev_info(adev->dev, " MC_SEQ_PMG_CMD_MRS2_LP=0x%08X\n",
6490 RREG32(mmMC_SEQ_PMG_CMD_MRS2_LP));
6491 dev_info(adev->dev, " MC_PMG_CMD_MRS2=0x%08X\n",
6492 RREG32(mmMC_PMG_CMD_MRS2));
6493 dev_info(adev->dev, " MC_SEQ_WR_CTL_2_LP=0x%08X\n",
6494 RREG32(mmMC_SEQ_WR_CTL_2_LP));
6495 dev_info(adev->dev, " MC_SEQ_WR_CTL_2=0x%08X\n",
6496 RREG32(mmMC_SEQ_WR_CTL_2));
6497 dev_info(adev->dev, " PCIE_LC_SPEED_CNTL=0x%08X\n",
6498 RREG32_PCIE(ixPCIE_LC_SPEED_CNTL));
6499 dev_info(adev->dev, " PCIE_LC_LINK_WIDTH_CNTL=0x%08X\n",
6500 RREG32_PCIE(ixPCIE_LC_LINK_WIDTH_CNTL));
6501 dev_info(adev->dev, " SMC_IND_INDEX_0=0x%08X\n",
6502 RREG32(mmSMC_IND_INDEX_0));
6503 dev_info(adev->dev, " SMC_IND_DATA_0=0x%08X\n",
6504 RREG32(mmSMC_IND_DATA_0));
6505 dev_info(adev->dev, " SMC_IND_ACCESS_CNTL=0x%08X\n",
6506 RREG32(mmSMC_IND_ACCESS_CNTL));
6507 dev_info(adev->dev, " SMC_RESP_0=0x%08X\n",
6508 RREG32(mmSMC_RESP_0));
6509 dev_info(adev->dev, " SMC_MESSAGE_0=0x%08X\n",
6510 RREG32(mmSMC_MESSAGE_0));
6511 dev_info(adev->dev, " SMC_SYSCON_RESET_CNTL=0x%08X\n",
6512 RREG32_SMC(ixSMC_SYSCON_RESET_CNTL));
6513 dev_info(adev->dev, " SMC_SYSCON_CLOCK_CNTL_0=0x%08X\n",
6514 RREG32_SMC(ixSMC_SYSCON_CLOCK_CNTL_0));
6515 dev_info(adev->dev, " SMC_SYSCON_MISC_CNTL=0x%08X\n",
6516 RREG32_SMC(ixSMC_SYSCON_MISC_CNTL));
6517 dev_info(adev->dev, " SMC_PC_C=0x%08X\n",
6518 RREG32_SMC(ixSMC_PC_C));
6519}
6520
6521static int ci_dpm_soft_reset(void *handle) 6312static int ci_dpm_soft_reset(void *handle)
6522{ 6313{
6523 return 0; 6314 return 0;
@@ -6625,7 +6416,6 @@ const struct amd_ip_funcs ci_dpm_ip_funcs = {
6625 .is_idle = ci_dpm_is_idle, 6416 .is_idle = ci_dpm_is_idle,
6626 .wait_for_idle = ci_dpm_wait_for_idle, 6417 .wait_for_idle = ci_dpm_wait_for_idle,
6627 .soft_reset = ci_dpm_soft_reset, 6418 .soft_reset = ci_dpm_soft_reset,
6628 .print_status = ci_dpm_print_status,
6629 .set_clockgating_state = ci_dpm_set_clockgating_state, 6419 .set_clockgating_state = ci_dpm_set_clockgating_state,
6630 .set_powergating_state = ci_dpm_set_powergating_state, 6420 .set_powergating_state = ci_dpm_set_powergating_state,
6631}; 6421};
diff --git a/drivers/gpu/drm/amd/amdgpu/cik.c b/drivers/gpu/drm/amd/amdgpu/cik.c
index bddc9ba11495..c6127d66de11 100644
--- a/drivers/gpu/drm/amd/amdgpu/cik.c
+++ b/drivers/gpu/drm/amd/amdgpu/cik.c
@@ -962,7 +962,7 @@ static bool cik_read_bios_from_rom(struct amdgpu_device *adev,
962 return true; 962 return true;
963} 963}
964 964
965static struct amdgpu_allowed_register_entry cik_allowed_read_registers[] = { 965static const struct amdgpu_allowed_register_entry cik_allowed_read_registers[] = {
966 {mmGRBM_STATUS, false}, 966 {mmGRBM_STATUS, false},
967 {mmGB_ADDR_CONFIG, false}, 967 {mmGB_ADDR_CONFIG, false},
968 {mmMC_ARB_RAMCFG, false}, 968 {mmMC_ARB_RAMCFG, false},
@@ -2214,11 +2214,6 @@ static int cik_common_wait_for_idle(void *handle)
2214 return 0; 2214 return 0;
2215} 2215}
2216 2216
2217static void cik_common_print_status(void *handle)
2218{
2219
2220}
2221
2222static int cik_common_soft_reset(void *handle) 2217static int cik_common_soft_reset(void *handle)
2223{ 2218{
2224 /* XXX hard reset?? */ 2219 /* XXX hard reset?? */
@@ -2249,7 +2244,6 @@ const struct amd_ip_funcs cik_common_ip_funcs = {
2249 .is_idle = cik_common_is_idle, 2244 .is_idle = cik_common_is_idle,
2250 .wait_for_idle = cik_common_wait_for_idle, 2245 .wait_for_idle = cik_common_wait_for_idle,
2251 .soft_reset = cik_common_soft_reset, 2246 .soft_reset = cik_common_soft_reset,
2252 .print_status = cik_common_print_status,
2253 .set_clockgating_state = cik_common_set_clockgating_state, 2247 .set_clockgating_state = cik_common_set_clockgating_state,
2254 .set_powergating_state = cik_common_set_powergating_state, 2248 .set_powergating_state = cik_common_set_powergating_state,
2255}; 2249};
diff --git a/drivers/gpu/drm/amd/amdgpu/cik_ih.c b/drivers/gpu/drm/amd/amdgpu/cik_ih.c
index 30c9b3beeef9..f2f14fe26784 100644
--- a/drivers/gpu/drm/amd/amdgpu/cik_ih.c
+++ b/drivers/gpu/drm/amd/amdgpu/cik_ih.c
@@ -372,35 +372,6 @@ static int cik_ih_wait_for_idle(void *handle)
372 return -ETIMEDOUT; 372 return -ETIMEDOUT;
373} 373}
374 374
375static void cik_ih_print_status(void *handle)
376{
377 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
378
379 dev_info(adev->dev, "CIK IH registers\n");
380 dev_info(adev->dev, " SRBM_STATUS=0x%08X\n",
381 RREG32(mmSRBM_STATUS));
382 dev_info(adev->dev, " SRBM_STATUS2=0x%08X\n",
383 RREG32(mmSRBM_STATUS2));
384 dev_info(adev->dev, " INTERRUPT_CNTL=0x%08X\n",
385 RREG32(mmINTERRUPT_CNTL));
386 dev_info(adev->dev, " INTERRUPT_CNTL2=0x%08X\n",
387 RREG32(mmINTERRUPT_CNTL2));
388 dev_info(adev->dev, " IH_CNTL=0x%08X\n",
389 RREG32(mmIH_CNTL));
390 dev_info(adev->dev, " IH_RB_CNTL=0x%08X\n",
391 RREG32(mmIH_RB_CNTL));
392 dev_info(adev->dev, " IH_RB_BASE=0x%08X\n",
393 RREG32(mmIH_RB_BASE));
394 dev_info(adev->dev, " IH_RB_WPTR_ADDR_LO=0x%08X\n",
395 RREG32(mmIH_RB_WPTR_ADDR_LO));
396 dev_info(adev->dev, " IH_RB_WPTR_ADDR_HI=0x%08X\n",
397 RREG32(mmIH_RB_WPTR_ADDR_HI));
398 dev_info(adev->dev, " IH_RB_RPTR=0x%08X\n",
399 RREG32(mmIH_RB_RPTR));
400 dev_info(adev->dev, " IH_RB_WPTR=0x%08X\n",
401 RREG32(mmIH_RB_WPTR));
402}
403
404static int cik_ih_soft_reset(void *handle) 375static int cik_ih_soft_reset(void *handle)
405{ 376{
406 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 377 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
@@ -412,8 +383,6 @@ static int cik_ih_soft_reset(void *handle)
412 srbm_soft_reset |= SRBM_SOFT_RESET__SOFT_RESET_IH_MASK; 383 srbm_soft_reset |= SRBM_SOFT_RESET__SOFT_RESET_IH_MASK;
413 384
414 if (srbm_soft_reset) { 385 if (srbm_soft_reset) {
415 cik_ih_print_status((void *)adev);
416
417 tmp = RREG32(mmSRBM_SOFT_RESET); 386 tmp = RREG32(mmSRBM_SOFT_RESET);
418 tmp |= srbm_soft_reset; 387 tmp |= srbm_soft_reset;
419 dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp); 388 dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
@@ -428,8 +397,6 @@ static int cik_ih_soft_reset(void *handle)
428 397
429 /* Wait a little for things to settle down */ 398 /* Wait a little for things to settle down */
430 udelay(50); 399 udelay(50);
431
432 cik_ih_print_status((void *)adev);
433 } 400 }
434 401
435 return 0; 402 return 0;
@@ -459,7 +426,6 @@ const struct amd_ip_funcs cik_ih_ip_funcs = {
459 .is_idle = cik_ih_is_idle, 426 .is_idle = cik_ih_is_idle,
460 .wait_for_idle = cik_ih_wait_for_idle, 427 .wait_for_idle = cik_ih_wait_for_idle,
461 .soft_reset = cik_ih_soft_reset, 428 .soft_reset = cik_ih_soft_reset,
462 .print_status = cik_ih_print_status,
463 .set_clockgating_state = cik_ih_set_clockgating_state, 429 .set_clockgating_state = cik_ih_set_clockgating_state,
464 .set_powergating_state = cik_ih_set_powergating_state, 430 .set_powergating_state = cik_ih_set_powergating_state,
465}; 431};
diff --git a/drivers/gpu/drm/amd/amdgpu/cik_sdma.c b/drivers/gpu/drm/amd/amdgpu/cik_sdma.c
index d3ac3298fba8..b7ed9d376001 100644
--- a/drivers/gpu/drm/amd/amdgpu/cik_sdma.c
+++ b/drivers/gpu/drm/amd/amdgpu/cik_sdma.c
@@ -976,7 +976,7 @@ static int cik_sdma_sw_init(void *handle)
976 ring = &adev->sdma.instance[i].ring; 976 ring = &adev->sdma.instance[i].ring;
977 ring->ring_obj = NULL; 977 ring->ring_obj = NULL;
978 sprintf(ring->name, "sdma%d", i); 978 sprintf(ring->name, "sdma%d", i);
979 r = amdgpu_ring_init(adev, ring, 256 * 1024, 979 r = amdgpu_ring_init(adev, ring, 1024,
980 SDMA_PACKET(SDMA_OPCODE_NOP, 0, 0), 0xf, 980 SDMA_PACKET(SDMA_OPCODE_NOP, 0, 0), 0xf,
981 &adev->sdma.trap_irq, 981 &adev->sdma.trap_irq,
982 (i == 0) ? 982 (i == 0) ?
@@ -1064,57 +1064,6 @@ static int cik_sdma_wait_for_idle(void *handle)
1064 return -ETIMEDOUT; 1064 return -ETIMEDOUT;
1065} 1065}
1066 1066
1067static void cik_sdma_print_status(void *handle)
1068{
1069 int i, j;
1070 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1071
1072 dev_info(adev->dev, "CIK SDMA registers\n");
1073 dev_info(adev->dev, " SRBM_STATUS2=0x%08X\n",
1074 RREG32(mmSRBM_STATUS2));
1075 for (i = 0; i < adev->sdma.num_instances; i++) {
1076 dev_info(adev->dev, " SDMA%d_STATUS_REG=0x%08X\n",
1077 i, RREG32(mmSDMA0_STATUS_REG + sdma_offsets[i]));
1078 dev_info(adev->dev, " SDMA%d_ME_CNTL=0x%08X\n",
1079 i, RREG32(mmSDMA0_F32_CNTL + sdma_offsets[i]));
1080 dev_info(adev->dev, " SDMA%d_CNTL=0x%08X\n",
1081 i, RREG32(mmSDMA0_CNTL + sdma_offsets[i]));
1082 dev_info(adev->dev, " SDMA%d_SEM_INCOMPLETE_TIMER_CNTL=0x%08X\n",
1083 i, RREG32(mmSDMA0_SEM_INCOMPLETE_TIMER_CNTL + sdma_offsets[i]));
1084 dev_info(adev->dev, " SDMA%d_SEM_WAIT_FAIL_TIMER_CNTL=0x%08X\n",
1085 i, RREG32(mmSDMA0_SEM_WAIT_FAIL_TIMER_CNTL + sdma_offsets[i]));
1086 dev_info(adev->dev, " SDMA%d_GFX_IB_CNTL=0x%08X\n",
1087 i, RREG32(mmSDMA0_GFX_IB_CNTL + sdma_offsets[i]));
1088 dev_info(adev->dev, " SDMA%d_GFX_RB_CNTL=0x%08X\n",
1089 i, RREG32(mmSDMA0_GFX_RB_CNTL + sdma_offsets[i]));
1090 dev_info(adev->dev, " SDMA%d_GFX_RB_RPTR=0x%08X\n",
1091 i, RREG32(mmSDMA0_GFX_RB_RPTR + sdma_offsets[i]));
1092 dev_info(adev->dev, " SDMA%d_GFX_RB_WPTR=0x%08X\n",
1093 i, RREG32(mmSDMA0_GFX_RB_WPTR + sdma_offsets[i]));
1094 dev_info(adev->dev, " SDMA%d_GFX_RB_RPTR_ADDR_HI=0x%08X\n",
1095 i, RREG32(mmSDMA0_GFX_RB_RPTR_ADDR_HI + sdma_offsets[i]));
1096 dev_info(adev->dev, " SDMA%d_GFX_RB_RPTR_ADDR_LO=0x%08X\n",
1097 i, RREG32(mmSDMA0_GFX_RB_RPTR_ADDR_LO + sdma_offsets[i]));
1098 dev_info(adev->dev, " SDMA%d_GFX_RB_BASE=0x%08X\n",
1099 i, RREG32(mmSDMA0_GFX_RB_BASE + sdma_offsets[i]));
1100 dev_info(adev->dev, " SDMA%d_GFX_RB_BASE_HI=0x%08X\n",
1101 i, RREG32(mmSDMA0_GFX_RB_BASE_HI + sdma_offsets[i]));
1102 dev_info(adev->dev, " SDMA%d_TILING_CONFIG=0x%08X\n",
1103 i, RREG32(mmSDMA0_TILING_CONFIG + sdma_offsets[i]));
1104 mutex_lock(&adev->srbm_mutex);
1105 for (j = 0; j < 16; j++) {
1106 cik_srbm_select(adev, 0, 0, 0, j);
1107 dev_info(adev->dev, " VM %d:\n", j);
1108 dev_info(adev->dev, " SDMA0_GFX_VIRTUAL_ADDR=0x%08X\n",
1109 RREG32(mmSDMA0_GFX_VIRTUAL_ADDR + sdma_offsets[i]));
1110 dev_info(adev->dev, " SDMA0_GFX_APE1_CNTL=0x%08X\n",
1111 RREG32(mmSDMA0_GFX_APE1_CNTL + sdma_offsets[i]));
1112 }
1113 cik_srbm_select(adev, 0, 0, 0, 0);
1114 mutex_unlock(&adev->srbm_mutex);
1115 }
1116}
1117
1118static int cik_sdma_soft_reset(void *handle) 1067static int cik_sdma_soft_reset(void *handle)
1119{ 1068{
1120 u32 srbm_soft_reset = 0; 1069 u32 srbm_soft_reset = 0;
@@ -1137,8 +1086,6 @@ static int cik_sdma_soft_reset(void *handle)
1137 } 1086 }
1138 1087
1139 if (srbm_soft_reset) { 1088 if (srbm_soft_reset) {
1140 cik_sdma_print_status((void *)adev);
1141
1142 tmp = RREG32(mmSRBM_SOFT_RESET); 1089 tmp = RREG32(mmSRBM_SOFT_RESET);
1143 tmp |= srbm_soft_reset; 1090 tmp |= srbm_soft_reset;
1144 dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp); 1091 dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
@@ -1153,8 +1100,6 @@ static int cik_sdma_soft_reset(void *handle)
1153 1100
1154 /* Wait a little for things to settle down */ 1101 /* Wait a little for things to settle down */
1155 udelay(50); 1102 udelay(50);
1156
1157 cik_sdma_print_status((void *)adev);
1158 } 1103 }
1159 1104
1160 return 0; 1105 return 0;
@@ -1289,7 +1234,6 @@ const struct amd_ip_funcs cik_sdma_ip_funcs = {
1289 .is_idle = cik_sdma_is_idle, 1234 .is_idle = cik_sdma_is_idle,
1290 .wait_for_idle = cik_sdma_wait_for_idle, 1235 .wait_for_idle = cik_sdma_wait_for_idle,
1291 .soft_reset = cik_sdma_soft_reset, 1236 .soft_reset = cik_sdma_soft_reset,
1292 .print_status = cik_sdma_print_status,
1293 .set_clockgating_state = cik_sdma_set_clockgating_state, 1237 .set_clockgating_state = cik_sdma_set_clockgating_state,
1294 .set_powergating_state = cik_sdma_set_powergating_state, 1238 .set_powergating_state = cik_sdma_set_powergating_state,
1295}; 1239};
diff --git a/drivers/gpu/drm/amd/amdgpu/cz_dpm.c b/drivers/gpu/drm/amd/amdgpu/cz_dpm.c
index e7ef2261ff4a..bf1847b28d9c 100644
--- a/drivers/gpu/drm/amd/amdgpu/cz_dpm.c
+++ b/drivers/gpu/drm/amd/amdgpu/cz_dpm.c
@@ -2241,7 +2241,6 @@ const struct amd_ip_funcs cz_dpm_ip_funcs = {
2241 .is_idle = NULL, 2241 .is_idle = NULL,
2242 .wait_for_idle = NULL, 2242 .wait_for_idle = NULL,
2243 .soft_reset = NULL, 2243 .soft_reset = NULL,
2244 .print_status = NULL,
2245 .set_clockgating_state = cz_dpm_set_clockgating_state, 2244 .set_clockgating_state = cz_dpm_set_clockgating_state,
2246 .set_powergating_state = cz_dpm_set_powergating_state, 2245 .set_powergating_state = cz_dpm_set_powergating_state,
2247}; 2246};
diff --git a/drivers/gpu/drm/amd/amdgpu/cz_ih.c b/drivers/gpu/drm/amd/amdgpu/cz_ih.c
index c79638f8e732..23bd9122b15d 100644
--- a/drivers/gpu/drm/amd/amdgpu/cz_ih.c
+++ b/drivers/gpu/drm/amd/amdgpu/cz_ih.c
@@ -351,35 +351,6 @@ static int cz_ih_wait_for_idle(void *handle)
351 return -ETIMEDOUT; 351 return -ETIMEDOUT;
352} 352}
353 353
354static void cz_ih_print_status(void *handle)
355{
356 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
357
358 dev_info(adev->dev, "CZ IH registers\n");
359 dev_info(adev->dev, " SRBM_STATUS=0x%08X\n",
360 RREG32(mmSRBM_STATUS));
361 dev_info(adev->dev, " SRBM_STATUS2=0x%08X\n",
362 RREG32(mmSRBM_STATUS2));
363 dev_info(adev->dev, " INTERRUPT_CNTL=0x%08X\n",
364 RREG32(mmINTERRUPT_CNTL));
365 dev_info(adev->dev, " INTERRUPT_CNTL2=0x%08X\n",
366 RREG32(mmINTERRUPT_CNTL2));
367 dev_info(adev->dev, " IH_CNTL=0x%08X\n",
368 RREG32(mmIH_CNTL));
369 dev_info(adev->dev, " IH_RB_CNTL=0x%08X\n",
370 RREG32(mmIH_RB_CNTL));
371 dev_info(adev->dev, " IH_RB_BASE=0x%08X\n",
372 RREG32(mmIH_RB_BASE));
373 dev_info(adev->dev, " IH_RB_WPTR_ADDR_LO=0x%08X\n",
374 RREG32(mmIH_RB_WPTR_ADDR_LO));
375 dev_info(adev->dev, " IH_RB_WPTR_ADDR_HI=0x%08X\n",
376 RREG32(mmIH_RB_WPTR_ADDR_HI));
377 dev_info(adev->dev, " IH_RB_RPTR=0x%08X\n",
378 RREG32(mmIH_RB_RPTR));
379 dev_info(adev->dev, " IH_RB_WPTR=0x%08X\n",
380 RREG32(mmIH_RB_WPTR));
381}
382
383static int cz_ih_soft_reset(void *handle) 354static int cz_ih_soft_reset(void *handle)
384{ 355{
385 u32 srbm_soft_reset = 0; 356 u32 srbm_soft_reset = 0;
@@ -391,8 +362,6 @@ static int cz_ih_soft_reset(void *handle)
391 SOFT_RESET_IH, 1); 362 SOFT_RESET_IH, 1);
392 363
393 if (srbm_soft_reset) { 364 if (srbm_soft_reset) {
394 cz_ih_print_status((void *)adev);
395
396 tmp = RREG32(mmSRBM_SOFT_RESET); 365 tmp = RREG32(mmSRBM_SOFT_RESET);
397 tmp |= srbm_soft_reset; 366 tmp |= srbm_soft_reset;
398 dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp); 367 dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
@@ -407,8 +376,6 @@ static int cz_ih_soft_reset(void *handle)
407 376
408 /* Wait a little for things to settle down */ 377 /* Wait a little for things to settle down */
409 udelay(50); 378 udelay(50);
410
411 cz_ih_print_status((void *)adev);
412 } 379 }
413 380
414 return 0; 381 return 0;
@@ -440,7 +407,6 @@ const struct amd_ip_funcs cz_ih_ip_funcs = {
440 .is_idle = cz_ih_is_idle, 407 .is_idle = cz_ih_is_idle,
441 .wait_for_idle = cz_ih_wait_for_idle, 408 .wait_for_idle = cz_ih_wait_for_idle,
442 .soft_reset = cz_ih_soft_reset, 409 .soft_reset = cz_ih_soft_reset,
443 .print_status = cz_ih_print_status,
444 .set_clockgating_state = cz_ih_set_clockgating_state, 410 .set_clockgating_state = cz_ih_set_clockgating_state,
445 .set_powergating_state = cz_ih_set_powergating_state, 411 .set_powergating_state = cz_ih_set_powergating_state,
446}; 412};
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
index 92c5a71a7da7..8af5fbc60e5b 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
@@ -3130,14 +3130,6 @@ static int dce_v10_0_wait_for_idle(void *handle)
3130 return 0; 3130 return 0;
3131} 3131}
3132 3132
3133static void dce_v10_0_print_status(void *handle)
3134{
3135 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
3136
3137 dev_info(adev->dev, "DCE 10.x registers\n");
3138 /* XXX todo */
3139}
3140
3141static int dce_v10_0_soft_reset(void *handle) 3133static int dce_v10_0_soft_reset(void *handle)
3142{ 3134{
3143 u32 srbm_soft_reset = 0, tmp; 3135 u32 srbm_soft_reset = 0, tmp;
@@ -3147,8 +3139,6 @@ static int dce_v10_0_soft_reset(void *handle)
3147 srbm_soft_reset |= SRBM_SOFT_RESET__SOFT_RESET_DC_MASK; 3139 srbm_soft_reset |= SRBM_SOFT_RESET__SOFT_RESET_DC_MASK;
3148 3140
3149 if (srbm_soft_reset) { 3141 if (srbm_soft_reset) {
3150 dce_v10_0_print_status((void *)adev);
3151
3152 tmp = RREG32(mmSRBM_SOFT_RESET); 3142 tmp = RREG32(mmSRBM_SOFT_RESET);
3153 tmp |= srbm_soft_reset; 3143 tmp |= srbm_soft_reset;
3154 dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp); 3144 dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
@@ -3163,7 +3153,6 @@ static int dce_v10_0_soft_reset(void *handle)
3163 3153
3164 /* Wait a little for things to settle down */ 3154 /* Wait a little for things to settle down */
3165 udelay(50); 3155 udelay(50);
3166 dce_v10_0_print_status((void *)adev);
3167 } 3156 }
3168 return 0; 3157 return 0;
3169} 3158}
@@ -3512,7 +3501,6 @@ const struct amd_ip_funcs dce_v10_0_ip_funcs = {
3512 .is_idle = dce_v10_0_is_idle, 3501 .is_idle = dce_v10_0_is_idle,
3513 .wait_for_idle = dce_v10_0_wait_for_idle, 3502 .wait_for_idle = dce_v10_0_wait_for_idle,
3514 .soft_reset = dce_v10_0_soft_reset, 3503 .soft_reset = dce_v10_0_soft_reset,
3515 .print_status = dce_v10_0_print_status,
3516 .set_clockgating_state = dce_v10_0_set_clockgating_state, 3504 .set_clockgating_state = dce_v10_0_set_clockgating_state,
3517 .set_powergating_state = dce_v10_0_set_powergating_state, 3505 .set_powergating_state = dce_v10_0_set_powergating_state,
3518}; 3506};
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
index 2f784f2d9233..dda9ffb68df8 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
@@ -132,6 +132,22 @@ static const u32 stoney_golden_settings_a11[] =
132 mmFBC_MISC, 0x1f311fff, 0x14302000, 132 mmFBC_MISC, 0x1f311fff, 0x14302000,
133}; 133};
134 134
135static const u32 polaris11_golden_settings_a11[] =
136{
137 mmDCI_CLK_CNTL, 0x00000080, 0x00000000,
138 mmFBC_DEBUG_COMP, 0x000000f0, 0x00000070,
139 mmFBC_DEBUG1, 0xffffffff, 0x00000008,
140 mmFBC_MISC, 0x9f313fff, 0x14300008,
141 mmHDMI_CONTROL, 0x313f031f, 0x00000011,
142};
143
144static const u32 polaris10_golden_settings_a11[] =
145{
146 mmDCI_CLK_CNTL, 0x00000080, 0x00000000,
147 mmFBC_DEBUG_COMP, 0x000000f0, 0x00000070,
148 mmFBC_MISC, 0x9f313fff, 0x14300008,
149 mmHDMI_CONTROL, 0x313f031f, 0x00000011,
150};
135 151
136static void dce_v11_0_init_golden_registers(struct amdgpu_device *adev) 152static void dce_v11_0_init_golden_registers(struct amdgpu_device *adev)
137{ 153{
@@ -149,6 +165,16 @@ static void dce_v11_0_init_golden_registers(struct amdgpu_device *adev)
149 stoney_golden_settings_a11, 165 stoney_golden_settings_a11,
150 (const u32)ARRAY_SIZE(stoney_golden_settings_a11)); 166 (const u32)ARRAY_SIZE(stoney_golden_settings_a11));
151 break; 167 break;
168 case CHIP_POLARIS11:
169 amdgpu_program_register_sequence(adev,
170 polaris11_golden_settings_a11,
171 (const u32)ARRAY_SIZE(polaris11_golden_settings_a11));
172 break;
173 case CHIP_POLARIS10:
174 amdgpu_program_register_sequence(adev,
175 polaris10_golden_settings_a11,
176 (const u32)ARRAY_SIZE(polaris10_golden_settings_a11));
177 break;
152 default: 178 default:
153 break; 179 break;
154 } 180 }
@@ -565,35 +591,14 @@ static void dce_v11_0_stop_mc_access(struct amdgpu_device *adev,
565 crtc_enabled = REG_GET_FIELD(RREG32(mmCRTC_CONTROL + crtc_offsets[i]), 591 crtc_enabled = REG_GET_FIELD(RREG32(mmCRTC_CONTROL + crtc_offsets[i]),
566 CRTC_CONTROL, CRTC_MASTER_EN); 592 CRTC_CONTROL, CRTC_MASTER_EN);
567 if (crtc_enabled) { 593 if (crtc_enabled) {
568#if 0 594#if 1
569 u32 frame_count;
570 int j;
571
572 save->crtc_enabled[i] = true; 595 save->crtc_enabled[i] = true;
573 tmp = RREG32(mmCRTC_BLANK_CONTROL + crtc_offsets[i]); 596 tmp = RREG32(mmCRTC_BLANK_CONTROL + crtc_offsets[i]);
574 if (REG_GET_FIELD(tmp, CRTC_BLANK_CONTROL, CRTC_BLANK_DATA_EN) == 0) { 597 if (REG_GET_FIELD(tmp, CRTC_BLANK_CONTROL, CRTC_BLANK_DATA_EN) == 0) {
575 amdgpu_display_vblank_wait(adev, i); 598 /*it is correct only for RGB ; black is 0*/
576 WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 1); 599 WREG32(mmCRTC_BLANK_DATA_COLOR + crtc_offsets[i], 0);
577 tmp = REG_SET_FIELD(tmp, CRTC_BLANK_CONTROL, CRTC_BLANK_DATA_EN, 1); 600 tmp = REG_SET_FIELD(tmp, CRTC_BLANK_CONTROL, CRTC_BLANK_DATA_EN, 1);
578 WREG32(mmCRTC_BLANK_CONTROL + crtc_offsets[i], tmp); 601 WREG32(mmCRTC_BLANK_CONTROL + crtc_offsets[i], tmp);
579 WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 0);
580 }
581 /* wait for the next frame */
582 frame_count = amdgpu_display_vblank_get_counter(adev, i);
583 for (j = 0; j < adev->usec_timeout; j++) {
584 if (amdgpu_display_vblank_get_counter(adev, i) != frame_count)
585 break;
586 udelay(1);
587 }
588 tmp = RREG32(mmGRPH_UPDATE + crtc_offsets[i]);
589 if (REG_GET_FIELD(tmp, GRPH_UPDATE, GRPH_UPDATE_LOCK) == 0) {
590 tmp = REG_SET_FIELD(tmp, GRPH_UPDATE, GRPH_UPDATE_LOCK, 1);
591 WREG32(mmGRPH_UPDATE + crtc_offsets[i], tmp);
592 }
593 tmp = RREG32(mmCRTC_MASTER_UPDATE_LOCK + crtc_offsets[i]);
594 if (REG_GET_FIELD(tmp, CRTC_MASTER_UPDATE_LOCK, MASTER_UPDATE_LOCK) == 0) {
595 tmp = REG_SET_FIELD(tmp, CRTC_MASTER_UPDATE_LOCK, MASTER_UPDATE_LOCK, 1);
596 WREG32(mmCRTC_MASTER_UPDATE_LOCK + crtc_offsets[i], tmp);
597 } 602 }
598#else 603#else
599 /* XXX this is a hack to avoid strange behavior with EFI on certain systems */ 604 /* XXX this is a hack to avoid strange behavior with EFI on certain systems */
@@ -614,54 +619,20 @@ static void dce_v11_0_stop_mc_access(struct amdgpu_device *adev,
614static void dce_v11_0_resume_mc_access(struct amdgpu_device *adev, 619static void dce_v11_0_resume_mc_access(struct amdgpu_device *adev,
615 struct amdgpu_mode_mc_save *save) 620 struct amdgpu_mode_mc_save *save)
616{ 621{
617 u32 tmp, frame_count; 622 u32 tmp;
618 int i, j; 623 int i;
619 624
620 /* update crtc base addresses */ 625 /* update crtc base addresses */
621 for (i = 0; i < adev->mode_info.num_crtc; i++) { 626 for (i = 0; i < adev->mode_info.num_crtc; i++) {
622 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH + crtc_offsets[i], 627 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH + crtc_offsets[i],
623 upper_32_bits(adev->mc.vram_start)); 628 upper_32_bits(adev->mc.vram_start));
624 WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS_HIGH + crtc_offsets[i],
625 upper_32_bits(adev->mc.vram_start));
626 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + crtc_offsets[i], 629 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + crtc_offsets[i],
627 (u32)adev->mc.vram_start); 630 (u32)adev->mc.vram_start);
628 WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS + crtc_offsets[i],
629 (u32)adev->mc.vram_start);
630 631
631 if (save->crtc_enabled[i]) { 632 if (save->crtc_enabled[i]) {
632 tmp = RREG32(mmCRTC_MASTER_UPDATE_MODE + crtc_offsets[i]);
633 if (REG_GET_FIELD(tmp, CRTC_MASTER_UPDATE_MODE, MASTER_UPDATE_MODE) != 3) {
634 tmp = REG_SET_FIELD(tmp, CRTC_MASTER_UPDATE_MODE, MASTER_UPDATE_MODE, 3);
635 WREG32(mmCRTC_MASTER_UPDATE_MODE + crtc_offsets[i], tmp);
636 }
637 tmp = RREG32(mmGRPH_UPDATE + crtc_offsets[i]);
638 if (REG_GET_FIELD(tmp, GRPH_UPDATE, GRPH_UPDATE_LOCK)) {
639 tmp = REG_SET_FIELD(tmp, GRPH_UPDATE, GRPH_UPDATE_LOCK, 0);
640 WREG32(mmGRPH_UPDATE + crtc_offsets[i], tmp);
641 }
642 tmp = RREG32(mmCRTC_MASTER_UPDATE_LOCK + crtc_offsets[i]);
643 if (REG_GET_FIELD(tmp, CRTC_MASTER_UPDATE_LOCK, MASTER_UPDATE_LOCK)) {
644 tmp = REG_SET_FIELD(tmp, CRTC_MASTER_UPDATE_LOCK, MASTER_UPDATE_LOCK, 0);
645 WREG32(mmCRTC_MASTER_UPDATE_LOCK + crtc_offsets[i], tmp);
646 }
647 for (j = 0; j < adev->usec_timeout; j++) {
648 tmp = RREG32(mmGRPH_UPDATE + crtc_offsets[i]);
649 if (REG_GET_FIELD(tmp, GRPH_UPDATE, GRPH_SURFACE_UPDATE_PENDING) == 0)
650 break;
651 udelay(1);
652 }
653 tmp = RREG32(mmCRTC_BLANK_CONTROL + crtc_offsets[i]); 633 tmp = RREG32(mmCRTC_BLANK_CONTROL + crtc_offsets[i]);
654 tmp = REG_SET_FIELD(tmp, CRTC_BLANK_CONTROL, CRTC_BLANK_DATA_EN, 0); 634 tmp = REG_SET_FIELD(tmp, CRTC_BLANK_CONTROL, CRTC_BLANK_DATA_EN, 0);
655 WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 1);
656 WREG32(mmCRTC_BLANK_CONTROL + crtc_offsets[i], tmp); 635 WREG32(mmCRTC_BLANK_CONTROL + crtc_offsets[i], tmp);
657 WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 0);
658 /* wait for the next frame */
659 frame_count = amdgpu_display_vblank_get_counter(adev, i);
660 for (j = 0; j < adev->usec_timeout; j++) {
661 if (amdgpu_display_vblank_get_counter(adev, i) != frame_count)
662 break;
663 udelay(1);
664 }
665 } 636 }
666 } 637 }
667 638
@@ -1635,7 +1606,20 @@ static int dce_v11_0_audio_init(struct amdgpu_device *adev)
1635 1606
1636 adev->mode_info.audio.enabled = true; 1607 adev->mode_info.audio.enabled = true;
1637 1608
1638 adev->mode_info.audio.num_pins = 7; 1609 switch (adev->asic_type) {
1610 case CHIP_CARRIZO:
1611 case CHIP_STONEY:
1612 adev->mode_info.audio.num_pins = 7;
1613 break;
1614 case CHIP_POLARIS10:
1615 adev->mode_info.audio.num_pins = 8;
1616 break;
1617 case CHIP_POLARIS11:
1618 adev->mode_info.audio.num_pins = 6;
1619 break;
1620 default:
1621 return -EINVAL;
1622 }
1639 1623
1640 for (i = 0; i < adev->mode_info.audio.num_pins; i++) { 1624 for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
1641 adev->mode_info.audio.pin[i].channels = -1; 1625 adev->mode_info.audio.pin[i].channels = -1;
@@ -2427,6 +2411,44 @@ static u32 dce_v11_0_pick_pll(struct drm_crtc *crtc)
2427 u32 pll_in_use; 2411 u32 pll_in_use;
2428 int pll; 2412 int pll;
2429 2413
2414 if ((adev->asic_type == CHIP_POLARIS10) ||
2415 (adev->asic_type == CHIP_POLARIS11)) {
2416 struct amdgpu_encoder *amdgpu_encoder =
2417 to_amdgpu_encoder(amdgpu_crtc->encoder);
2418 struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
2419
2420 if (ENCODER_MODE_IS_DP(amdgpu_atombios_encoder_get_encoder_mode(amdgpu_crtc->encoder)))
2421 return ATOM_DP_DTO;
2422 /* use the same PPLL for all monitors with the same clock */
2423 pll = amdgpu_pll_get_shared_nondp_ppll(crtc);
2424 if (pll != ATOM_PPLL_INVALID)
2425 return pll;
2426
2427 switch (amdgpu_encoder->encoder_id) {
2428 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
2429 if (dig->linkb)
2430 return ATOM_COMBOPHY_PLL1;
2431 else
2432 return ATOM_COMBOPHY_PLL0;
2433 break;
2434 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
2435 if (dig->linkb)
2436 return ATOM_COMBOPHY_PLL3;
2437 else
2438 return ATOM_COMBOPHY_PLL2;
2439 break;
2440 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
2441 if (dig->linkb)
2442 return ATOM_COMBOPHY_PLL5;
2443 else
2444 return ATOM_COMBOPHY_PLL4;
2445 break;
2446 default:
2447 DRM_ERROR("invalid encoder_id: 0x%x\n", amdgpu_encoder->encoder_id);
2448 return ATOM_PPLL_INVALID;
2449 }
2450 }
2451
2430 if (ENCODER_MODE_IS_DP(amdgpu_atombios_encoder_get_encoder_mode(amdgpu_crtc->encoder))) { 2452 if (ENCODER_MODE_IS_DP(amdgpu_atombios_encoder_get_encoder_mode(amdgpu_crtc->encoder))) {
2431 if (adev->clock.dp_extclk) 2453 if (adev->clock.dp_extclk)
2432 /* skip PPLL programming if using ext clock */ 2454 /* skip PPLL programming if using ext clock */
@@ -2782,7 +2804,17 @@ static void dce_v11_0_crtc_disable(struct drm_crtc *crtc)
2782 case ATOM_PPLL2: 2804 case ATOM_PPLL2:
2783 /* disable the ppll */ 2805 /* disable the ppll */
2784 amdgpu_atombios_crtc_program_pll(crtc, amdgpu_crtc->crtc_id, amdgpu_crtc->pll_id, 2806 amdgpu_atombios_crtc_program_pll(crtc, amdgpu_crtc->crtc_id, amdgpu_crtc->pll_id,
2785 0, 0, ATOM_DISABLE, 0, 0, 0, 0, 0, false, &ss); 2807 0, 0, ATOM_DISABLE, 0, 0, 0, 0, 0, false, &ss);
2808 break;
2809 case ATOM_COMBOPHY_PLL0:
2810 case ATOM_COMBOPHY_PLL1:
2811 case ATOM_COMBOPHY_PLL2:
2812 case ATOM_COMBOPHY_PLL3:
2813 case ATOM_COMBOPHY_PLL4:
2814 case ATOM_COMBOPHY_PLL5:
2815 /* disable the ppll */
2816 amdgpu_atombios_crtc_program_pll(crtc, ATOM_CRTC_INVALID, amdgpu_crtc->pll_id,
2817 0, 0, ATOM_DISABLE, 0, 0, 0, 0, 0, false, &ss);
2786 break; 2818 break;
2787 default: 2819 default:
2788 break; 2820 break;
@@ -2800,11 +2832,28 @@ static int dce_v11_0_crtc_mode_set(struct drm_crtc *crtc,
2800 int x, int y, struct drm_framebuffer *old_fb) 2832 int x, int y, struct drm_framebuffer *old_fb)
2801{ 2833{
2802 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); 2834 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
2835 struct drm_device *dev = crtc->dev;
2836 struct amdgpu_device *adev = dev->dev_private;
2803 2837
2804 if (!amdgpu_crtc->adjusted_clock) 2838 if (!amdgpu_crtc->adjusted_clock)
2805 return -EINVAL; 2839 return -EINVAL;
2806 2840
2807 amdgpu_atombios_crtc_set_pll(crtc, adjusted_mode); 2841 if ((adev->asic_type == CHIP_POLARIS10) ||
2842 (adev->asic_type == CHIP_POLARIS11)) {
2843 struct amdgpu_encoder *amdgpu_encoder =
2844 to_amdgpu_encoder(amdgpu_crtc->encoder);
2845 int encoder_mode =
2846 amdgpu_atombios_encoder_get_encoder_mode(amdgpu_crtc->encoder);
2847
2848 /* SetPixelClock calculates the plls and ss values now */
2849 amdgpu_atombios_crtc_program_pll(crtc, amdgpu_crtc->crtc_id,
2850 amdgpu_crtc->pll_id,
2851 encoder_mode, amdgpu_encoder->encoder_id,
2852 adjusted_mode->clock, 0, 0, 0, 0,
2853 amdgpu_crtc->bpc, amdgpu_crtc->ss_enabled, &amdgpu_crtc->ss);
2854 } else {
2855 amdgpu_atombios_crtc_set_pll(crtc, adjusted_mode);
2856 }
2808 amdgpu_atombios_crtc_set_dtd_timing(crtc, adjusted_mode); 2857 amdgpu_atombios_crtc_set_dtd_timing(crtc, adjusted_mode);
2809 dce_v11_0_crtc_do_set_base(crtc, old_fb, x, y, 0); 2858 dce_v11_0_crtc_do_set_base(crtc, old_fb, x, y, 0);
2810 amdgpu_atombios_crtc_overscan_setup(crtc, mode, adjusted_mode); 2859 amdgpu_atombios_crtc_overscan_setup(crtc, mode, adjusted_mode);
@@ -2955,6 +3004,16 @@ static int dce_v11_0_early_init(void *handle)
2955 adev->mode_info.num_hpd = 6; 3004 adev->mode_info.num_hpd = 6;
2956 adev->mode_info.num_dig = 9; 3005 adev->mode_info.num_dig = 9;
2957 break; 3006 break;
3007 case CHIP_POLARIS10:
3008 adev->mode_info.num_crtc = 6;
3009 adev->mode_info.num_hpd = 6;
3010 adev->mode_info.num_dig = 6;
3011 break;
3012 case CHIP_POLARIS11:
3013 adev->mode_info.num_crtc = 5;
3014 adev->mode_info.num_hpd = 5;
3015 adev->mode_info.num_dig = 5;
3016 break;
2958 default: 3017 default:
2959 /* FIXME: not supported yet */ 3018 /* FIXME: not supported yet */
2960 return -EINVAL; 3019 return -EINVAL;
@@ -3057,7 +3116,15 @@ static int dce_v11_0_hw_init(void *handle)
3057 /* init dig PHYs, disp eng pll */ 3116 /* init dig PHYs, disp eng pll */
3058 amdgpu_atombios_crtc_powergate_init(adev); 3117 amdgpu_atombios_crtc_powergate_init(adev);
3059 amdgpu_atombios_encoder_init_dig(adev); 3118 amdgpu_atombios_encoder_init_dig(adev);
3060 amdgpu_atombios_crtc_set_disp_eng_pll(adev, adev->clock.default_dispclk); 3119 if ((adev->asic_type == CHIP_POLARIS10) ||
3120 (adev->asic_type == CHIP_POLARIS11)) {
3121 amdgpu_atombios_crtc_set_dce_clock(adev, adev->clock.default_dispclk,
3122 DCE_CLOCK_TYPE_DISPCLK, ATOM_GCK_DFS);
3123 amdgpu_atombios_crtc_set_dce_clock(adev, 0,
3124 DCE_CLOCK_TYPE_DPREFCLK, ATOM_GCK_DFS);
3125 } else {
3126 amdgpu_atombios_crtc_set_disp_eng_pll(adev, adev->clock.default_dispclk);
3127 }
3061 3128
3062 /* initialize hpd */ 3129 /* initialize hpd */
3063 dce_v11_0_hpd_init(adev); 3130 dce_v11_0_hpd_init(adev);
@@ -3126,14 +3193,6 @@ static int dce_v11_0_wait_for_idle(void *handle)
3126 return 0; 3193 return 0;
3127} 3194}
3128 3195
3129static void dce_v11_0_print_status(void *handle)
3130{
3131 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
3132
3133 dev_info(adev->dev, "DCE 10.x registers\n");
3134 /* XXX todo */
3135}
3136
3137static int dce_v11_0_soft_reset(void *handle) 3196static int dce_v11_0_soft_reset(void *handle)
3138{ 3197{
3139 u32 srbm_soft_reset = 0, tmp; 3198 u32 srbm_soft_reset = 0, tmp;
@@ -3143,8 +3202,6 @@ static int dce_v11_0_soft_reset(void *handle)
3143 srbm_soft_reset |= SRBM_SOFT_RESET__SOFT_RESET_DC_MASK; 3202 srbm_soft_reset |= SRBM_SOFT_RESET__SOFT_RESET_DC_MASK;
3144 3203
3145 if (srbm_soft_reset) { 3204 if (srbm_soft_reset) {
3146 dce_v11_0_print_status((void *)adev);
3147
3148 tmp = RREG32(mmSRBM_SOFT_RESET); 3205 tmp = RREG32(mmSRBM_SOFT_RESET);
3149 tmp |= srbm_soft_reset; 3206 tmp |= srbm_soft_reset;
3150 dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp); 3207 dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
@@ -3159,7 +3216,6 @@ static int dce_v11_0_soft_reset(void *handle)
3159 3216
3160 /* Wait a little for things to settle down */ 3217 /* Wait a little for things to settle down */
3161 udelay(50); 3218 udelay(50);
3162 dce_v11_0_print_status((void *)adev);
3163 } 3219 }
3164 return 0; 3220 return 0;
3165} 3221}
@@ -3508,7 +3564,6 @@ const struct amd_ip_funcs dce_v11_0_ip_funcs = {
3508 .is_idle = dce_v11_0_is_idle, 3564 .is_idle = dce_v11_0_is_idle,
3509 .wait_for_idle = dce_v11_0_wait_for_idle, 3565 .wait_for_idle = dce_v11_0_wait_for_idle,
3510 .soft_reset = dce_v11_0_soft_reset, 3566 .soft_reset = dce_v11_0_soft_reset,
3511 .print_status = dce_v11_0_print_status,
3512 .set_clockgating_state = dce_v11_0_set_clockgating_state, 3567 .set_clockgating_state = dce_v11_0_set_clockgating_state,
3513 .set_powergating_state = dce_v11_0_set_powergating_state, 3568 .set_powergating_state = dce_v11_0_set_powergating_state,
3514}; 3569};
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
index 9155e3b1d782..25e6af03c406 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
@@ -3038,14 +3038,6 @@ static int dce_v8_0_wait_for_idle(void *handle)
3038 return 0; 3038 return 0;
3039} 3039}
3040 3040
3041static void dce_v8_0_print_status(void *handle)
3042{
3043 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
3044
3045 dev_info(adev->dev, "DCE 8.x registers\n");
3046 /* XXX todo */
3047}
3048
3049static int dce_v8_0_soft_reset(void *handle) 3041static int dce_v8_0_soft_reset(void *handle)
3050{ 3042{
3051 u32 srbm_soft_reset = 0, tmp; 3043 u32 srbm_soft_reset = 0, tmp;
@@ -3055,8 +3047,6 @@ static int dce_v8_0_soft_reset(void *handle)
3055 srbm_soft_reset |= SRBM_SOFT_RESET__SOFT_RESET_DC_MASK; 3047 srbm_soft_reset |= SRBM_SOFT_RESET__SOFT_RESET_DC_MASK;
3056 3048
3057 if (srbm_soft_reset) { 3049 if (srbm_soft_reset) {
3058 dce_v8_0_print_status((void *)adev);
3059
3060 tmp = RREG32(mmSRBM_SOFT_RESET); 3050 tmp = RREG32(mmSRBM_SOFT_RESET);
3061 tmp |= srbm_soft_reset; 3051 tmp |= srbm_soft_reset;
3062 dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp); 3052 dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
@@ -3071,7 +3061,6 @@ static int dce_v8_0_soft_reset(void *handle)
3071 3061
3072 /* Wait a little for things to settle down */ 3062 /* Wait a little for things to settle down */
3073 udelay(50); 3063 udelay(50);
3074 dce_v8_0_print_status((void *)adev);
3075 } 3064 }
3076 return 0; 3065 return 0;
3077} 3066}
@@ -3442,7 +3431,6 @@ const struct amd_ip_funcs dce_v8_0_ip_funcs = {
3442 .is_idle = dce_v8_0_is_idle, 3431 .is_idle = dce_v8_0_is_idle,
3443 .wait_for_idle = dce_v8_0_wait_for_idle, 3432 .wait_for_idle = dce_v8_0_wait_for_idle,
3444 .soft_reset = dce_v8_0_soft_reset, 3433 .soft_reset = dce_v8_0_soft_reset,
3445 .print_status = dce_v8_0_print_status,
3446 .set_clockgating_state = dce_v8_0_set_clockgating_state, 3434 .set_clockgating_state = dce_v8_0_set_clockgating_state,
3447 .set_powergating_state = dce_v8_0_set_powergating_state, 3435 .set_powergating_state = dce_v8_0_set_powergating_state,
3448}; 3436};
diff --git a/drivers/gpu/drm/amd/amdgpu/fiji_dpm.c b/drivers/gpu/drm/amd/amdgpu/fiji_dpm.c
index 4b0e45a27129..6d133450d3cc 100644
--- a/drivers/gpu/drm/amd/amdgpu/fiji_dpm.c
+++ b/drivers/gpu/drm/amd/amdgpu/fiji_dpm.c
@@ -154,7 +154,6 @@ const struct amd_ip_funcs fiji_dpm_ip_funcs = {
154 .is_idle = NULL, 154 .is_idle = NULL,
155 .wait_for_idle = NULL, 155 .wait_for_idle = NULL,
156 .soft_reset = NULL, 156 .soft_reset = NULL,
157 .print_status = NULL,
158 .set_clockgating_state = fiji_dpm_set_clockgating_state, 157 .set_clockgating_state = fiji_dpm_set_clockgating_state,
159 .set_powergating_state = fiji_dpm_set_powergating_state, 158 .set_powergating_state = fiji_dpm_set_powergating_state,
160}; 159};
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
index bb8709066fd8..6686c9c3005d 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
@@ -4414,7 +4414,7 @@ static int gfx_v7_0_sw_init(void *handle)
4414 ring = &adev->gfx.gfx_ring[i]; 4414 ring = &adev->gfx.gfx_ring[i];
4415 ring->ring_obj = NULL; 4415 ring->ring_obj = NULL;
4416 sprintf(ring->name, "gfx"); 4416 sprintf(ring->name, "gfx");
4417 r = amdgpu_ring_init(adev, ring, 1024 * 1024, 4417 r = amdgpu_ring_init(adev, ring, 1024,
4418 PACKET3(PACKET3_NOP, 0x3FFF), 0xf, 4418 PACKET3(PACKET3_NOP, 0x3FFF), 0xf,
4419 &adev->gfx.eop_irq, AMDGPU_CP_IRQ_GFX_EOP, 4419 &adev->gfx.eop_irq, AMDGPU_CP_IRQ_GFX_EOP,
4420 AMDGPU_RING_TYPE_GFX); 4420 AMDGPU_RING_TYPE_GFX);
@@ -4438,10 +4438,10 @@ static int gfx_v7_0_sw_init(void *handle)
4438 ring->me = 1; /* first MEC */ 4438 ring->me = 1; /* first MEC */
4439 ring->pipe = i / 8; 4439 ring->pipe = i / 8;
4440 ring->queue = i % 8; 4440 ring->queue = i % 8;
4441 sprintf(ring->name, "comp %d.%d.%d", ring->me, ring->pipe, ring->queue); 4441 sprintf(ring->name, "comp_%d.%d.%d", ring->me, ring->pipe, ring->queue);
4442 irq_type = AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP + ring->pipe; 4442 irq_type = AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP + ring->pipe;
4443 /* type-2 packets are deprecated on MEC, use type-3 instead */ 4443 /* type-2 packets are deprecated on MEC, use type-3 instead */
4444 r = amdgpu_ring_init(adev, ring, 1024 * 1024, 4444 r = amdgpu_ring_init(adev, ring, 1024,
4445 PACKET3(PACKET3_NOP, 0x3FFF), 0xf, 4445 PACKET3(PACKET3_NOP, 0x3FFF), 0xf,
4446 &adev->gfx.eop_irq, irq_type, 4446 &adev->gfx.eop_irq, irq_type,
4447 AMDGPU_RING_TYPE_COMPUTE); 4447 AMDGPU_RING_TYPE_COMPUTE);
@@ -4572,256 +4572,6 @@ static int gfx_v7_0_wait_for_idle(void *handle)
4572 return -ETIMEDOUT; 4572 return -ETIMEDOUT;
4573} 4573}
4574 4574
4575static void gfx_v7_0_print_status(void *handle)
4576{
4577 int i;
4578 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
4579
4580 dev_info(adev->dev, "GFX 7.x registers\n");
4581 dev_info(adev->dev, " GRBM_STATUS=0x%08X\n",
4582 RREG32(mmGRBM_STATUS));
4583 dev_info(adev->dev, " GRBM_STATUS2=0x%08X\n",
4584 RREG32(mmGRBM_STATUS2));
4585 dev_info(adev->dev, " GRBM_STATUS_SE0=0x%08X\n",
4586 RREG32(mmGRBM_STATUS_SE0));
4587 dev_info(adev->dev, " GRBM_STATUS_SE1=0x%08X\n",
4588 RREG32(mmGRBM_STATUS_SE1));
4589 dev_info(adev->dev, " GRBM_STATUS_SE2=0x%08X\n",
4590 RREG32(mmGRBM_STATUS_SE2));
4591 dev_info(adev->dev, " GRBM_STATUS_SE3=0x%08X\n",
4592 RREG32(mmGRBM_STATUS_SE3));
4593 dev_info(adev->dev, " CP_STAT = 0x%08x\n", RREG32(mmCP_STAT));
4594 dev_info(adev->dev, " CP_STALLED_STAT1 = 0x%08x\n",
4595 RREG32(mmCP_STALLED_STAT1));
4596 dev_info(adev->dev, " CP_STALLED_STAT2 = 0x%08x\n",
4597 RREG32(mmCP_STALLED_STAT2));
4598 dev_info(adev->dev, " CP_STALLED_STAT3 = 0x%08x\n",
4599 RREG32(mmCP_STALLED_STAT3));
4600 dev_info(adev->dev, " CP_CPF_BUSY_STAT = 0x%08x\n",
4601 RREG32(mmCP_CPF_BUSY_STAT));
4602 dev_info(adev->dev, " CP_CPF_STALLED_STAT1 = 0x%08x\n",
4603 RREG32(mmCP_CPF_STALLED_STAT1));
4604 dev_info(adev->dev, " CP_CPF_STATUS = 0x%08x\n", RREG32(mmCP_CPF_STATUS));
4605 dev_info(adev->dev, " CP_CPC_BUSY_STAT = 0x%08x\n", RREG32(mmCP_CPC_BUSY_STAT));
4606 dev_info(adev->dev, " CP_CPC_STALLED_STAT1 = 0x%08x\n",
4607 RREG32(mmCP_CPC_STALLED_STAT1));
4608 dev_info(adev->dev, " CP_CPC_STATUS = 0x%08x\n", RREG32(mmCP_CPC_STATUS));
4609
4610 for (i = 0; i < 32; i++) {
4611 dev_info(adev->dev, " GB_TILE_MODE%d=0x%08X\n",
4612 i, RREG32(mmGB_TILE_MODE0 + (i * 4)));
4613 }
4614 for (i = 0; i < 16; i++) {
4615 dev_info(adev->dev, " GB_MACROTILE_MODE%d=0x%08X\n",
4616 i, RREG32(mmGB_MACROTILE_MODE0 + (i * 4)));
4617 }
4618 for (i = 0; i < adev->gfx.config.max_shader_engines; i++) {
4619 dev_info(adev->dev, " se: %d\n", i);
4620 gfx_v7_0_select_se_sh(adev, i, 0xffffffff);
4621 dev_info(adev->dev, " PA_SC_RASTER_CONFIG=0x%08X\n",
4622 RREG32(mmPA_SC_RASTER_CONFIG));
4623 dev_info(adev->dev, " PA_SC_RASTER_CONFIG_1=0x%08X\n",
4624 RREG32(mmPA_SC_RASTER_CONFIG_1));
4625 }
4626 gfx_v7_0_select_se_sh(adev, 0xffffffff, 0xffffffff);
4627
4628 dev_info(adev->dev, " GB_ADDR_CONFIG=0x%08X\n",
4629 RREG32(mmGB_ADDR_CONFIG));
4630 dev_info(adev->dev, " HDP_ADDR_CONFIG=0x%08X\n",
4631 RREG32(mmHDP_ADDR_CONFIG));
4632 dev_info(adev->dev, " DMIF_ADDR_CALC=0x%08X\n",
4633 RREG32(mmDMIF_ADDR_CALC));
4634
4635 dev_info(adev->dev, " CP_MEQ_THRESHOLDS=0x%08X\n",
4636 RREG32(mmCP_MEQ_THRESHOLDS));
4637 dev_info(adev->dev, " SX_DEBUG_1=0x%08X\n",
4638 RREG32(mmSX_DEBUG_1));
4639 dev_info(adev->dev, " TA_CNTL_AUX=0x%08X\n",
4640 RREG32(mmTA_CNTL_AUX));
4641 dev_info(adev->dev, " SPI_CONFIG_CNTL=0x%08X\n",
4642 RREG32(mmSPI_CONFIG_CNTL));
4643 dev_info(adev->dev, " SQ_CONFIG=0x%08X\n",
4644 RREG32(mmSQ_CONFIG));
4645 dev_info(adev->dev, " DB_DEBUG=0x%08X\n",
4646 RREG32(mmDB_DEBUG));
4647 dev_info(adev->dev, " DB_DEBUG2=0x%08X\n",
4648 RREG32(mmDB_DEBUG2));
4649 dev_info(adev->dev, " DB_DEBUG3=0x%08X\n",
4650 RREG32(mmDB_DEBUG3));
4651 dev_info(adev->dev, " CB_HW_CONTROL=0x%08X\n",
4652 RREG32(mmCB_HW_CONTROL));
4653 dev_info(adev->dev, " SPI_CONFIG_CNTL_1=0x%08X\n",
4654 RREG32(mmSPI_CONFIG_CNTL_1));
4655 dev_info(adev->dev, " PA_SC_FIFO_SIZE=0x%08X\n",
4656 RREG32(mmPA_SC_FIFO_SIZE));
4657 dev_info(adev->dev, " VGT_NUM_INSTANCES=0x%08X\n",
4658 RREG32(mmVGT_NUM_INSTANCES));
4659 dev_info(adev->dev, " CP_PERFMON_CNTL=0x%08X\n",
4660 RREG32(mmCP_PERFMON_CNTL));
4661 dev_info(adev->dev, " PA_SC_FORCE_EOV_MAX_CNTS=0x%08X\n",
4662 RREG32(mmPA_SC_FORCE_EOV_MAX_CNTS));
4663 dev_info(adev->dev, " VGT_CACHE_INVALIDATION=0x%08X\n",
4664 RREG32(mmVGT_CACHE_INVALIDATION));
4665 dev_info(adev->dev, " VGT_GS_VERTEX_REUSE=0x%08X\n",
4666 RREG32(mmVGT_GS_VERTEX_REUSE));
4667 dev_info(adev->dev, " PA_SC_LINE_STIPPLE_STATE=0x%08X\n",
4668 RREG32(mmPA_SC_LINE_STIPPLE_STATE));
4669 dev_info(adev->dev, " PA_CL_ENHANCE=0x%08X\n",
4670 RREG32(mmPA_CL_ENHANCE));
4671 dev_info(adev->dev, " PA_SC_ENHANCE=0x%08X\n",
4672 RREG32(mmPA_SC_ENHANCE));
4673
4674 dev_info(adev->dev, " CP_ME_CNTL=0x%08X\n",
4675 RREG32(mmCP_ME_CNTL));
4676 dev_info(adev->dev, " CP_MAX_CONTEXT=0x%08X\n",
4677 RREG32(mmCP_MAX_CONTEXT));
4678 dev_info(adev->dev, " CP_ENDIAN_SWAP=0x%08X\n",
4679 RREG32(mmCP_ENDIAN_SWAP));
4680 dev_info(adev->dev, " CP_DEVICE_ID=0x%08X\n",
4681 RREG32(mmCP_DEVICE_ID));
4682
4683 dev_info(adev->dev, " CP_SEM_WAIT_TIMER=0x%08X\n",
4684 RREG32(mmCP_SEM_WAIT_TIMER));
4685 if (adev->asic_type != CHIP_HAWAII)
4686 dev_info(adev->dev, " CP_SEM_INCOMPLETE_TIMER_CNTL=0x%08X\n",
4687 RREG32(mmCP_SEM_INCOMPLETE_TIMER_CNTL));
4688
4689 dev_info(adev->dev, " CP_RB_WPTR_DELAY=0x%08X\n",
4690 RREG32(mmCP_RB_WPTR_DELAY));
4691 dev_info(adev->dev, " CP_RB_VMID=0x%08X\n",
4692 RREG32(mmCP_RB_VMID));
4693 dev_info(adev->dev, " CP_RB0_CNTL=0x%08X\n",
4694 RREG32(mmCP_RB0_CNTL));
4695 dev_info(adev->dev, " CP_RB0_WPTR=0x%08X\n",
4696 RREG32(mmCP_RB0_WPTR));
4697 dev_info(adev->dev, " CP_RB0_RPTR_ADDR=0x%08X\n",
4698 RREG32(mmCP_RB0_RPTR_ADDR));
4699 dev_info(adev->dev, " CP_RB0_RPTR_ADDR_HI=0x%08X\n",
4700 RREG32(mmCP_RB0_RPTR_ADDR_HI));
4701 dev_info(adev->dev, " CP_RB0_CNTL=0x%08X\n",
4702 RREG32(mmCP_RB0_CNTL));
4703 dev_info(adev->dev, " CP_RB0_BASE=0x%08X\n",
4704 RREG32(mmCP_RB0_BASE));
4705 dev_info(adev->dev, " CP_RB0_BASE_HI=0x%08X\n",
4706 RREG32(mmCP_RB0_BASE_HI));
4707 dev_info(adev->dev, " CP_MEC_CNTL=0x%08X\n",
4708 RREG32(mmCP_MEC_CNTL));
4709 dev_info(adev->dev, " CP_CPF_DEBUG=0x%08X\n",
4710 RREG32(mmCP_CPF_DEBUG));
4711
4712 dev_info(adev->dev, " SCRATCH_ADDR=0x%08X\n",
4713 RREG32(mmSCRATCH_ADDR));
4714 dev_info(adev->dev, " SCRATCH_UMSK=0x%08X\n",
4715 RREG32(mmSCRATCH_UMSK));
4716
4717 /* init the pipes */
4718 mutex_lock(&adev->srbm_mutex);
4719 for (i = 0; i < (adev->gfx.mec.num_pipe * adev->gfx.mec.num_mec); i++) {
4720 int me = (i < 4) ? 1 : 2;
4721 int pipe = (i < 4) ? i : (i - 4);
4722 int queue;
4723
4724 dev_info(adev->dev, " me: %d, pipe: %d\n", me, pipe);
4725 cik_srbm_select(adev, me, pipe, 0, 0);
4726 dev_info(adev->dev, " CP_HPD_EOP_BASE_ADDR=0x%08X\n",
4727 RREG32(mmCP_HPD_EOP_BASE_ADDR));
4728 dev_info(adev->dev, " CP_HPD_EOP_BASE_ADDR_HI=0x%08X\n",
4729 RREG32(mmCP_HPD_EOP_BASE_ADDR_HI));
4730 dev_info(adev->dev, " CP_HPD_EOP_VMID=0x%08X\n",
4731 RREG32(mmCP_HPD_EOP_VMID));
4732 dev_info(adev->dev, " CP_HPD_EOP_CONTROL=0x%08X\n",
4733 RREG32(mmCP_HPD_EOP_CONTROL));
4734
4735 for (queue = 0; queue < 8; queue++) {
4736 cik_srbm_select(adev, me, pipe, queue, 0);
4737 dev_info(adev->dev, " queue: %d\n", queue);
4738 dev_info(adev->dev, " CP_PQ_WPTR_POLL_CNTL=0x%08X\n",
4739 RREG32(mmCP_PQ_WPTR_POLL_CNTL));
4740 dev_info(adev->dev, " CP_HQD_PQ_DOORBELL_CONTROL=0x%08X\n",
4741 RREG32(mmCP_HQD_PQ_DOORBELL_CONTROL));
4742 dev_info(adev->dev, " CP_HQD_ACTIVE=0x%08X\n",
4743 RREG32(mmCP_HQD_ACTIVE));
4744 dev_info(adev->dev, " CP_HQD_DEQUEUE_REQUEST=0x%08X\n",
4745 RREG32(mmCP_HQD_DEQUEUE_REQUEST));
4746 dev_info(adev->dev, " CP_HQD_PQ_RPTR=0x%08X\n",
4747 RREG32(mmCP_HQD_PQ_RPTR));
4748 dev_info(adev->dev, " CP_HQD_PQ_WPTR=0x%08X\n",
4749 RREG32(mmCP_HQD_PQ_WPTR));
4750 dev_info(adev->dev, " CP_HQD_PQ_BASE=0x%08X\n",
4751 RREG32(mmCP_HQD_PQ_BASE));
4752 dev_info(adev->dev, " CP_HQD_PQ_BASE_HI=0x%08X\n",
4753 RREG32(mmCP_HQD_PQ_BASE_HI));
4754 dev_info(adev->dev, " CP_HQD_PQ_CONTROL=0x%08X\n",
4755 RREG32(mmCP_HQD_PQ_CONTROL));
4756 dev_info(adev->dev, " CP_HQD_PQ_WPTR_POLL_ADDR=0x%08X\n",
4757 RREG32(mmCP_HQD_PQ_WPTR_POLL_ADDR));
4758 dev_info(adev->dev, " CP_HQD_PQ_WPTR_POLL_ADDR_HI=0x%08X\n",
4759 RREG32(mmCP_HQD_PQ_WPTR_POLL_ADDR_HI));
4760 dev_info(adev->dev, " CP_HQD_PQ_RPTR_REPORT_ADDR=0x%08X\n",
4761 RREG32(mmCP_HQD_PQ_RPTR_REPORT_ADDR));
4762 dev_info(adev->dev, " CP_HQD_PQ_RPTR_REPORT_ADDR_HI=0x%08X\n",
4763 RREG32(mmCP_HQD_PQ_RPTR_REPORT_ADDR_HI));
4764 dev_info(adev->dev, " CP_HQD_PQ_DOORBELL_CONTROL=0x%08X\n",
4765 RREG32(mmCP_HQD_PQ_DOORBELL_CONTROL));
4766 dev_info(adev->dev, " CP_HQD_PQ_WPTR=0x%08X\n",
4767 RREG32(mmCP_HQD_PQ_WPTR));
4768 dev_info(adev->dev, " CP_HQD_VMID=0x%08X\n",
4769 RREG32(mmCP_HQD_VMID));
4770 dev_info(adev->dev, " CP_MQD_BASE_ADDR=0x%08X\n",
4771 RREG32(mmCP_MQD_BASE_ADDR));
4772 dev_info(adev->dev, " CP_MQD_BASE_ADDR_HI=0x%08X\n",
4773 RREG32(mmCP_MQD_BASE_ADDR_HI));
4774 dev_info(adev->dev, " CP_MQD_CONTROL=0x%08X\n",
4775 RREG32(mmCP_MQD_CONTROL));
4776 }
4777 }
4778 cik_srbm_select(adev, 0, 0, 0, 0);
4779 mutex_unlock(&adev->srbm_mutex);
4780
4781 dev_info(adev->dev, " CP_INT_CNTL_RING0=0x%08X\n",
4782 RREG32(mmCP_INT_CNTL_RING0));
4783 dev_info(adev->dev, " RLC_LB_CNTL=0x%08X\n",
4784 RREG32(mmRLC_LB_CNTL));
4785 dev_info(adev->dev, " RLC_CNTL=0x%08X\n",
4786 RREG32(mmRLC_CNTL));
4787 dev_info(adev->dev, " RLC_CGCG_CGLS_CTRL=0x%08X\n",
4788 RREG32(mmRLC_CGCG_CGLS_CTRL));
4789 dev_info(adev->dev, " RLC_LB_CNTR_INIT=0x%08X\n",
4790 RREG32(mmRLC_LB_CNTR_INIT));
4791 dev_info(adev->dev, " RLC_LB_CNTR_MAX=0x%08X\n",
4792 RREG32(mmRLC_LB_CNTR_MAX));
4793 dev_info(adev->dev, " RLC_LB_INIT_CU_MASK=0x%08X\n",
4794 RREG32(mmRLC_LB_INIT_CU_MASK));
4795 dev_info(adev->dev, " RLC_LB_PARAMS=0x%08X\n",
4796 RREG32(mmRLC_LB_PARAMS));
4797 dev_info(adev->dev, " RLC_LB_CNTL=0x%08X\n",
4798 RREG32(mmRLC_LB_CNTL));
4799 dev_info(adev->dev, " RLC_MC_CNTL=0x%08X\n",
4800 RREG32(mmRLC_MC_CNTL));
4801 dev_info(adev->dev, " RLC_UCODE_CNTL=0x%08X\n",
4802 RREG32(mmRLC_UCODE_CNTL));
4803
4804 if (adev->asic_type == CHIP_BONAIRE)
4805 dev_info(adev->dev, " RLC_DRIVER_CPDMA_STATUS=0x%08X\n",
4806 RREG32(mmRLC_DRIVER_CPDMA_STATUS));
4807
4808 mutex_lock(&adev->srbm_mutex);
4809 for (i = 0; i < 16; i++) {
4810 cik_srbm_select(adev, 0, 0, 0, i);
4811 dev_info(adev->dev, " VM %d:\n", i);
4812 dev_info(adev->dev, " SH_MEM_CONFIG=0x%08X\n",
4813 RREG32(mmSH_MEM_CONFIG));
4814 dev_info(adev->dev, " SH_MEM_APE1_BASE=0x%08X\n",
4815 RREG32(mmSH_MEM_APE1_BASE));
4816 dev_info(adev->dev, " SH_MEM_APE1_LIMIT=0x%08X\n",
4817 RREG32(mmSH_MEM_APE1_LIMIT));
4818 dev_info(adev->dev, " SH_MEM_BASES=0x%08X\n",
4819 RREG32(mmSH_MEM_BASES));
4820 }
4821 cik_srbm_select(adev, 0, 0, 0, 0);
4822 mutex_unlock(&adev->srbm_mutex);
4823}
4824
4825static int gfx_v7_0_soft_reset(void *handle) 4575static int gfx_v7_0_soft_reset(void *handle)
4826{ 4576{
4827 u32 grbm_soft_reset = 0, srbm_soft_reset = 0; 4577 u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
@@ -4855,7 +4605,6 @@ static int gfx_v7_0_soft_reset(void *handle)
4855 srbm_soft_reset |= SRBM_SOFT_RESET__SOFT_RESET_GRBM_MASK; 4605 srbm_soft_reset |= SRBM_SOFT_RESET__SOFT_RESET_GRBM_MASK;
4856 4606
4857 if (grbm_soft_reset || srbm_soft_reset) { 4607 if (grbm_soft_reset || srbm_soft_reset) {
4858 gfx_v7_0_print_status((void *)adev);
4859 /* disable CG/PG */ 4608 /* disable CG/PG */
4860 gfx_v7_0_fini_pg(adev); 4609 gfx_v7_0_fini_pg(adev);
4861 gfx_v7_0_update_cg(adev, false); 4610 gfx_v7_0_update_cg(adev, false);
@@ -4898,7 +4647,6 @@ static int gfx_v7_0_soft_reset(void *handle)
4898 } 4647 }
4899 /* Wait a little for things to settle down */ 4648 /* Wait a little for things to settle down */
4900 udelay(50); 4649 udelay(50);
4901 gfx_v7_0_print_status((void *)adev);
4902 } 4650 }
4903 return 0; 4651 return 0;
4904} 4652}
@@ -5161,7 +4909,6 @@ const struct amd_ip_funcs gfx_v7_0_ip_funcs = {
5161 .is_idle = gfx_v7_0_is_idle, 4909 .is_idle = gfx_v7_0_is_idle,
5162 .wait_for_idle = gfx_v7_0_wait_for_idle, 4910 .wait_for_idle = gfx_v7_0_wait_for_idle,
5163 .soft_reset = gfx_v7_0_soft_reset, 4911 .soft_reset = gfx_v7_0_soft_reset,
5164 .print_status = gfx_v7_0_print_status,
5165 .set_clockgating_state = gfx_v7_0_set_clockgating_state, 4912 .set_clockgating_state = gfx_v7_0_set_clockgating_state,
5166 .set_powergating_state = gfx_v7_0_set_powergating_state, 4913 .set_powergating_state = gfx_v7_0_set_powergating_state,
5167}; 4914};
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
index f0c7b3596480..021c17e50d51 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
@@ -27,6 +27,7 @@
27#include "vi.h" 27#include "vi.h"
28#include "vid.h" 28#include "vid.h"
29#include "amdgpu_ucode.h" 29#include "amdgpu_ucode.h"
30#include "amdgpu_atombios.h"
30#include "clearstate_vi.h" 31#include "clearstate_vi.h"
31 32
32#include "gmc/gmc_8_2_d.h" 33#include "gmc/gmc_8_2_d.h"
@@ -51,6 +52,7 @@
51 52
52#define TOPAZ_GB_ADDR_CONFIG_GOLDEN 0x22010001 53#define TOPAZ_GB_ADDR_CONFIG_GOLDEN 0x22010001
53#define CARRIZO_GB_ADDR_CONFIG_GOLDEN 0x22010001 54#define CARRIZO_GB_ADDR_CONFIG_GOLDEN 0x22010001
55#define POLARIS11_GB_ADDR_CONFIG_GOLDEN 0x22011002
54#define TONGA_GB_ADDR_CONFIG_GOLDEN 0x22011003 56#define TONGA_GB_ADDR_CONFIG_GOLDEN 0x22011003
55 57
56#define ARRAY_MODE(x) ((x) << GB_TILE_MODE0__ARRAY_MODE__SHIFT) 58#define ARRAY_MODE(x) ((x) << GB_TILE_MODE0__ARRAY_MODE__SHIFT)
@@ -84,6 +86,8 @@ enum {
84 BPM_REG_FGCG_MAX 86 BPM_REG_FGCG_MAX
85}; 87};
86 88
89#define RLC_FormatDirectRegListLength 14
90
87MODULE_FIRMWARE("amdgpu/carrizo_ce.bin"); 91MODULE_FIRMWARE("amdgpu/carrizo_ce.bin");
88MODULE_FIRMWARE("amdgpu/carrizo_pfp.bin"); 92MODULE_FIRMWARE("amdgpu/carrizo_pfp.bin");
89MODULE_FIRMWARE("amdgpu/carrizo_me.bin"); 93MODULE_FIRMWARE("amdgpu/carrizo_me.bin");
@@ -117,6 +121,20 @@ MODULE_FIRMWARE("amdgpu/fiji_mec.bin");
117MODULE_FIRMWARE("amdgpu/fiji_mec2.bin"); 121MODULE_FIRMWARE("amdgpu/fiji_mec2.bin");
118MODULE_FIRMWARE("amdgpu/fiji_rlc.bin"); 122MODULE_FIRMWARE("amdgpu/fiji_rlc.bin");
119 123
124MODULE_FIRMWARE("amdgpu/polaris11_ce.bin");
125MODULE_FIRMWARE("amdgpu/polaris11_pfp.bin");
126MODULE_FIRMWARE("amdgpu/polaris11_me.bin");
127MODULE_FIRMWARE("amdgpu/polaris11_mec.bin");
128MODULE_FIRMWARE("amdgpu/polaris11_mec2.bin");
129MODULE_FIRMWARE("amdgpu/polaris11_rlc.bin");
130
131MODULE_FIRMWARE("amdgpu/polaris10_ce.bin");
132MODULE_FIRMWARE("amdgpu/polaris10_pfp.bin");
133MODULE_FIRMWARE("amdgpu/polaris10_me.bin");
134MODULE_FIRMWARE("amdgpu/polaris10_mec.bin");
135MODULE_FIRMWARE("amdgpu/polaris10_mec2.bin");
136MODULE_FIRMWARE("amdgpu/polaris10_rlc.bin");
137
120static const struct amdgpu_gds_reg_offset amdgpu_gds_reg_offset[] = 138static const struct amdgpu_gds_reg_offset amdgpu_gds_reg_offset[] =
121{ 139{
122 {mmGDS_VMID0_BASE, mmGDS_VMID0_SIZE, mmGDS_GWS_VMID0, mmGDS_OA_VMID0}, 140 {mmGDS_VMID0_BASE, mmGDS_VMID0_SIZE, mmGDS_GWS_VMID0, mmGDS_OA_VMID0},
@@ -247,6 +265,64 @@ static const u32 tonga_mgcg_cgcg_init[] =
247 mmCP_MEM_SLP_CNTL, 0x00000001, 0x00000001, 265 mmCP_MEM_SLP_CNTL, 0x00000001, 0x00000001,
248}; 266};
249 267
268static const u32 golden_settings_polaris11_a11[] =
269{
270 mmCB_HW_CONTROL_3, 0x000001ff, 0x00000040,
271 mmDB_DEBUG2, 0xf00fffff, 0x00000400,
272 mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
273 mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
274 mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0001003c,
275 mmRLC_CGCG_CGLS_CTRL_3D, 0xffffffff, 0x0001003c,
276 mmSQ_CONFIG, 0x07f80000, 0x07180000,
277 mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
278 mmTCC_CTRL, 0x00100000, 0xf31fff7f,
279 mmTCP_ADDR_CONFIG, 0x000003ff, 0x000000f3,
280 mmTCP_CHAN_STEER_HI, 0xffffffff, 0x00000000,
281 mmTCP_CHAN_STEER_LO, 0xffffffff, 0x00003210,
282};
283
284static const u32 polaris11_golden_common_all[] =
285{
286 mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
287 mmPA_SC_RASTER_CONFIG, 0xffffffff, 0x16000012,
288 mmPA_SC_RASTER_CONFIG_1, 0xffffffff, 0x00000000,
289 mmGB_ADDR_CONFIG, 0xffffffff, 0x22011002,
290 mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
291 mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
292 mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00007FBF,
293 mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00007FAF,
294};
295
296static const u32 golden_settings_polaris10_a11[] =
297{
298 mmATC_MISC_CG, 0x000c0fc0, 0x000c0200,
299 mmCB_HW_CONTROL_3, 0x000001ff, 0x00000040,
300 mmDB_DEBUG2, 0xf00fffff, 0x00000400,
301 mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
302 mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
303 mmPA_SC_RASTER_CONFIG, 0x3f3fffff, 0x16000012,
304 mmPA_SC_RASTER_CONFIG_1, 0x0000003f, 0x0000002a,
305 mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0001003c,
306 mmRLC_CGCG_CGLS_CTRL_3D, 0xffffffff, 0x0001003c,
307 mmSQ_CONFIG, 0x07f80000, 0x07180000,
308 mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
309 mmTCC_CTRL, 0x00100000, 0xf31fff7f,
310 mmTCP_ADDR_CONFIG, 0x000003ff, 0x000000f7,
311 mmTCP_CHAN_STEER_HI, 0xffffffff, 0x00000000,
312};
313
314static const u32 polaris10_golden_common_all[] =
315{
316 mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
317 mmPA_SC_RASTER_CONFIG, 0xffffffff, 0x16000012,
318 mmPA_SC_RASTER_CONFIG_1, 0xffffffff, 0x0000002A,
319 mmGB_ADDR_CONFIG, 0xffffffff, 0x22011003,
320 mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
321 mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
322 mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00007FBF,
323 mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00007FAF,
324};
325
250static const u32 fiji_golden_common_all[] = 326static const u32 fiji_golden_common_all[] =
251{ 327{
252 mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000, 328 mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
@@ -558,6 +634,8 @@ static const u32 stoney_mgcg_cgcg_init[] =
558static void gfx_v8_0_set_ring_funcs(struct amdgpu_device *adev); 634static void gfx_v8_0_set_ring_funcs(struct amdgpu_device *adev);
559static void gfx_v8_0_set_irq_funcs(struct amdgpu_device *adev); 635static void gfx_v8_0_set_irq_funcs(struct amdgpu_device *adev);
560static void gfx_v8_0_set_gds_init(struct amdgpu_device *adev); 636static void gfx_v8_0_set_gds_init(struct amdgpu_device *adev);
637static void gfx_v8_0_set_rlc_funcs(struct amdgpu_device *adev);
638static u32 gfx_v8_0_get_csb_size(struct amdgpu_device *adev);
561 639
562static void gfx_v8_0_init_golden_registers(struct amdgpu_device *adev) 640static void gfx_v8_0_init_golden_registers(struct amdgpu_device *adev)
563{ 641{
@@ -596,6 +674,22 @@ static void gfx_v8_0_init_golden_registers(struct amdgpu_device *adev)
596 tonga_golden_common_all, 674 tonga_golden_common_all,
597 (const u32)ARRAY_SIZE(tonga_golden_common_all)); 675 (const u32)ARRAY_SIZE(tonga_golden_common_all));
598 break; 676 break;
677 case CHIP_POLARIS11:
678 amdgpu_program_register_sequence(adev,
679 golden_settings_polaris11_a11,
680 (const u32)ARRAY_SIZE(golden_settings_polaris11_a11));
681 amdgpu_program_register_sequence(adev,
682 polaris11_golden_common_all,
683 (const u32)ARRAY_SIZE(polaris11_golden_common_all));
684 break;
685 case CHIP_POLARIS10:
686 amdgpu_program_register_sequence(adev,
687 golden_settings_polaris10_a11,
688 (const u32)ARRAY_SIZE(golden_settings_polaris10_a11));
689 amdgpu_program_register_sequence(adev,
690 polaris10_golden_common_all,
691 (const u32)ARRAY_SIZE(polaris10_golden_common_all));
692 break;
599 case CHIP_CARRIZO: 693 case CHIP_CARRIZO:
600 amdgpu_program_register_sequence(adev, 694 amdgpu_program_register_sequence(adev,
601 cz_mgcg_cgcg_init, 695 cz_mgcg_cgcg_init,
@@ -747,6 +841,8 @@ static int gfx_v8_0_init_microcode(struct amdgpu_device *adev)
747 struct amdgpu_firmware_info *info = NULL; 841 struct amdgpu_firmware_info *info = NULL;
748 const struct common_firmware_header *header = NULL; 842 const struct common_firmware_header *header = NULL;
749 const struct gfx_firmware_header_v1_0 *cp_hdr; 843 const struct gfx_firmware_header_v1_0 *cp_hdr;
844 const struct rlc_firmware_header_v2_0 *rlc_hdr;
845 unsigned int *tmp = NULL, i;
750 846
751 DRM_DEBUG("\n"); 847 DRM_DEBUG("\n");
752 848
@@ -763,6 +859,12 @@ static int gfx_v8_0_init_microcode(struct amdgpu_device *adev)
763 case CHIP_FIJI: 859 case CHIP_FIJI:
764 chip_name = "fiji"; 860 chip_name = "fiji";
765 break; 861 break;
862 case CHIP_POLARIS11:
863 chip_name = "polaris11";
864 break;
865 case CHIP_POLARIS10:
866 chip_name = "polaris10";
867 break;
766 case CHIP_STONEY: 868 case CHIP_STONEY:
767 chip_name = "stoney"; 869 chip_name = "stoney";
768 break; 870 break;
@@ -808,9 +910,49 @@ static int gfx_v8_0_init_microcode(struct amdgpu_device *adev)
808 if (err) 910 if (err)
809 goto out; 911 goto out;
810 err = amdgpu_ucode_validate(adev->gfx.rlc_fw); 912 err = amdgpu_ucode_validate(adev->gfx.rlc_fw);
811 cp_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.rlc_fw->data; 913 rlc_hdr = (const struct rlc_firmware_header_v2_0 *)adev->gfx.rlc_fw->data;
812 adev->gfx.rlc_fw_version = le32_to_cpu(cp_hdr->header.ucode_version); 914 adev->gfx.rlc_fw_version = le32_to_cpu(rlc_hdr->header.ucode_version);
813 adev->gfx.rlc_feature_version = le32_to_cpu(cp_hdr->ucode_feature_version); 915 adev->gfx.rlc_feature_version = le32_to_cpu(rlc_hdr->ucode_feature_version);
916
917 adev->gfx.rlc.save_and_restore_offset =
918 le32_to_cpu(rlc_hdr->save_and_restore_offset);
919 adev->gfx.rlc.clear_state_descriptor_offset =
920 le32_to_cpu(rlc_hdr->clear_state_descriptor_offset);
921 adev->gfx.rlc.avail_scratch_ram_locations =
922 le32_to_cpu(rlc_hdr->avail_scratch_ram_locations);
923 adev->gfx.rlc.reg_restore_list_size =
924 le32_to_cpu(rlc_hdr->reg_restore_list_size);
925 adev->gfx.rlc.reg_list_format_start =
926 le32_to_cpu(rlc_hdr->reg_list_format_start);
927 adev->gfx.rlc.reg_list_format_separate_start =
928 le32_to_cpu(rlc_hdr->reg_list_format_separate_start);
929 adev->gfx.rlc.starting_offsets_start =
930 le32_to_cpu(rlc_hdr->starting_offsets_start);
931 adev->gfx.rlc.reg_list_format_size_bytes =
932 le32_to_cpu(rlc_hdr->reg_list_format_size_bytes);
933 adev->gfx.rlc.reg_list_size_bytes =
934 le32_to_cpu(rlc_hdr->reg_list_size_bytes);
935
936 adev->gfx.rlc.register_list_format =
937 kmalloc(adev->gfx.rlc.reg_list_format_size_bytes +
938 adev->gfx.rlc.reg_list_size_bytes, GFP_KERNEL);
939
940 if (!adev->gfx.rlc.register_list_format) {
941 err = -ENOMEM;
942 goto out;
943 }
944
945 tmp = (unsigned int *)((uintptr_t)rlc_hdr +
946 le32_to_cpu(rlc_hdr->reg_list_format_array_offset_bytes));
947 for (i = 0 ; i < (rlc_hdr->reg_list_format_size_bytes >> 2); i++)
948 adev->gfx.rlc.register_list_format[i] = le32_to_cpu(tmp[i]);
949
950 adev->gfx.rlc.register_restore = adev->gfx.rlc.register_list_format + i;
951
952 tmp = (unsigned int *)((uintptr_t)rlc_hdr +
953 le32_to_cpu(rlc_hdr->reg_list_array_offset_bytes));
954 for (i = 0 ; i < (rlc_hdr->reg_list_size_bytes >> 2); i++)
955 adev->gfx.rlc.register_restore[i] = le32_to_cpu(tmp[i]);
814 956
815 snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_mec.bin", chip_name); 957 snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_mec.bin", chip_name);
816 err = request_firmware(&adev->gfx.mec_fw, fw_name, adev->dev); 958 err = request_firmware(&adev->gfx.mec_fw, fw_name, adev->dev);
@@ -911,6 +1053,153 @@ out:
911 return err; 1053 return err;
912} 1054}
913 1055
1056static void gfx_v8_0_get_csb_buffer(struct amdgpu_device *adev,
1057 volatile u32 *buffer)
1058{
1059 u32 count = 0, i;
1060 const struct cs_section_def *sect = NULL;
1061 const struct cs_extent_def *ext = NULL;
1062
1063 if (adev->gfx.rlc.cs_data == NULL)
1064 return;
1065 if (buffer == NULL)
1066 return;
1067
1068 buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
1069 buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
1070
1071 buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CONTEXT_CONTROL, 1));
1072 buffer[count++] = cpu_to_le32(0x80000000);
1073 buffer[count++] = cpu_to_le32(0x80000000);
1074
1075 for (sect = adev->gfx.rlc.cs_data; sect->section != NULL; ++sect) {
1076 for (ext = sect->section; ext->extent != NULL; ++ext) {
1077 if (sect->id == SECT_CONTEXT) {
1078 buffer[count++] =
1079 cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, ext->reg_count));
1080 buffer[count++] = cpu_to_le32(ext->reg_index -
1081 PACKET3_SET_CONTEXT_REG_START);
1082 for (i = 0; i < ext->reg_count; i++)
1083 buffer[count++] = cpu_to_le32(ext->extent[i]);
1084 } else {
1085 return;
1086 }
1087 }
1088 }
1089
1090 buffer[count++] = cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, 2));
1091 buffer[count++] = cpu_to_le32(mmPA_SC_RASTER_CONFIG -
1092 PACKET3_SET_CONTEXT_REG_START);
1093 switch (adev->asic_type) {
1094 case CHIP_TONGA:
1095 case CHIP_POLARIS10:
1096 buffer[count++] = cpu_to_le32(0x16000012);
1097 buffer[count++] = cpu_to_le32(0x0000002A);
1098 break;
1099 case CHIP_POLARIS11:
1100 buffer[count++] = cpu_to_le32(0x16000012);
1101 buffer[count++] = cpu_to_le32(0x00000000);
1102 break;
1103 case CHIP_FIJI:
1104 buffer[count++] = cpu_to_le32(0x3a00161a);
1105 buffer[count++] = cpu_to_le32(0x0000002e);
1106 break;
1107 case CHIP_TOPAZ:
1108 case CHIP_CARRIZO:
1109 buffer[count++] = cpu_to_le32(0x00000002);
1110 buffer[count++] = cpu_to_le32(0x00000000);
1111 break;
1112 case CHIP_STONEY:
1113 buffer[count++] = cpu_to_le32(0x00000000);
1114 buffer[count++] = cpu_to_le32(0x00000000);
1115 break;
1116 default:
1117 buffer[count++] = cpu_to_le32(0x00000000);
1118 buffer[count++] = cpu_to_le32(0x00000000);
1119 break;
1120 }
1121
1122 buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
1123 buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_END_CLEAR_STATE);
1124
1125 buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CLEAR_STATE, 0));
1126 buffer[count++] = cpu_to_le32(0);
1127}
1128
1129static void gfx_v8_0_rlc_fini(struct amdgpu_device *adev)
1130{
1131 int r;
1132
1133 /* clear state block */
1134 if (adev->gfx.rlc.clear_state_obj) {
1135 r = amdgpu_bo_reserve(adev->gfx.rlc.clear_state_obj, false);
1136 if (unlikely(r != 0))
1137 dev_warn(adev->dev, "(%d) reserve RLC c bo failed\n", r);
1138 amdgpu_bo_unpin(adev->gfx.rlc.clear_state_obj);
1139 amdgpu_bo_unreserve(adev->gfx.rlc.clear_state_obj);
1140
1141 amdgpu_bo_unref(&adev->gfx.rlc.clear_state_obj);
1142 adev->gfx.rlc.clear_state_obj = NULL;
1143 }
1144}
1145
1146static int gfx_v8_0_rlc_init(struct amdgpu_device *adev)
1147{
1148 volatile u32 *dst_ptr;
1149 u32 dws;
1150 const struct cs_section_def *cs_data;
1151 int r;
1152
1153 adev->gfx.rlc.cs_data = vi_cs_data;
1154
1155 cs_data = adev->gfx.rlc.cs_data;
1156
1157 if (cs_data) {
1158 /* clear state block */
1159 adev->gfx.rlc.clear_state_size = dws = gfx_v8_0_get_csb_size(adev);
1160
1161 if (adev->gfx.rlc.clear_state_obj == NULL) {
1162 r = amdgpu_bo_create(adev, dws * 4, PAGE_SIZE, true,
1163 AMDGPU_GEM_DOMAIN_VRAM,
1164 AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED,
1165 NULL, NULL,
1166 &adev->gfx.rlc.clear_state_obj);
1167 if (r) {
1168 dev_warn(adev->dev, "(%d) create RLC c bo failed\n", r);
1169 gfx_v8_0_rlc_fini(adev);
1170 return r;
1171 }
1172 }
1173 r = amdgpu_bo_reserve(adev->gfx.rlc.clear_state_obj, false);
1174 if (unlikely(r != 0)) {
1175 gfx_v8_0_rlc_fini(adev);
1176 return r;
1177 }
1178 r = amdgpu_bo_pin(adev->gfx.rlc.clear_state_obj, AMDGPU_GEM_DOMAIN_VRAM,
1179 &adev->gfx.rlc.clear_state_gpu_addr);
1180 if (r) {
1181 amdgpu_bo_unreserve(adev->gfx.rlc.clear_state_obj);
1182 dev_warn(adev->dev, "(%d) pin RLC c bo failed\n", r);
1183 gfx_v8_0_rlc_fini(adev);
1184 return r;
1185 }
1186
1187 r = amdgpu_bo_kmap(adev->gfx.rlc.clear_state_obj, (void **)&adev->gfx.rlc.cs_ptr);
1188 if (r) {
1189 dev_warn(adev->dev, "(%d) map RLC c bo failed\n", r);
1190 gfx_v8_0_rlc_fini(adev);
1191 return r;
1192 }
1193 /* set up the cs buffer */
1194 dst_ptr = adev->gfx.rlc.cs_ptr;
1195 gfx_v8_0_get_csb_buffer(adev, dst_ptr);
1196 amdgpu_bo_kunmap(adev->gfx.rlc.clear_state_obj);
1197 amdgpu_bo_unreserve(adev->gfx.rlc.clear_state_obj);
1198 }
1199
1200 return 0;
1201}
1202
914static void gfx_v8_0_mec_fini(struct amdgpu_device *adev) 1203static void gfx_v8_0_mec_fini(struct amdgpu_device *adev)
915{ 1204{
916 int r; 1205 int r;
@@ -1296,12 +1585,13 @@ fail:
1296 return r; 1585 return r;
1297} 1586}
1298 1587
1299static void gfx_v8_0_gpu_early_init(struct amdgpu_device *adev) 1588static int gfx_v8_0_gpu_early_init(struct amdgpu_device *adev)
1300{ 1589{
1301 u32 gb_addr_config; 1590 u32 gb_addr_config;
1302 u32 mc_shared_chmap, mc_arb_ramcfg; 1591 u32 mc_shared_chmap, mc_arb_ramcfg;
1303 u32 dimm00_addr_map, dimm01_addr_map, dimm10_addr_map, dimm11_addr_map; 1592 u32 dimm00_addr_map, dimm01_addr_map, dimm10_addr_map, dimm11_addr_map;
1304 u32 tmp; 1593 u32 tmp;
1594 int ret;
1305 1595
1306 switch (adev->asic_type) { 1596 switch (adev->asic_type) {
1307 case CHIP_TOPAZ: 1597 case CHIP_TOPAZ:
@@ -1338,6 +1628,34 @@ static void gfx_v8_0_gpu_early_init(struct amdgpu_device *adev)
1338 adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130; 1628 adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
1339 gb_addr_config = TONGA_GB_ADDR_CONFIG_GOLDEN; 1629 gb_addr_config = TONGA_GB_ADDR_CONFIG_GOLDEN;
1340 break; 1630 break;
1631 case CHIP_POLARIS11:
1632 ret = amdgpu_atombios_get_gfx_info(adev);
1633 if (ret)
1634 return ret;
1635 adev->gfx.config.max_gprs = 256;
1636 adev->gfx.config.max_gs_threads = 32;
1637 adev->gfx.config.max_hw_contexts = 8;
1638
1639 adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
1640 adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
1641 adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
1642 adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
1643 gb_addr_config = POLARIS11_GB_ADDR_CONFIG_GOLDEN;
1644 break;
1645 case CHIP_POLARIS10:
1646 ret = amdgpu_atombios_get_gfx_info(adev);
1647 if (ret)
1648 return ret;
1649 adev->gfx.config.max_gprs = 256;
1650 adev->gfx.config.max_gs_threads = 32;
1651 adev->gfx.config.max_hw_contexts = 8;
1652
1653 adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
1654 adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
1655 adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
1656 adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
1657 gb_addr_config = TONGA_GB_ADDR_CONFIG_GOLDEN;
1658 break;
1341 case CHIP_TONGA: 1659 case CHIP_TONGA:
1342 adev->gfx.config.max_shader_engines = 4; 1660 adev->gfx.config.max_shader_engines = 4;
1343 adev->gfx.config.max_tile_pipes = 8; 1661 adev->gfx.config.max_tile_pipes = 8;
@@ -1520,6 +1838,8 @@ static void gfx_v8_0_gpu_early_init(struct amdgpu_device *adev)
1520 break; 1838 break;
1521 } 1839 }
1522 adev->gfx.config.gb_addr_config = gb_addr_config; 1840 adev->gfx.config.gb_addr_config = gb_addr_config;
1841
1842 return 0;
1523} 1843}
1524 1844
1525static int gfx_v8_0_sw_init(void *handle) 1845static int gfx_v8_0_sw_init(void *handle)
@@ -1553,6 +1873,12 @@ static int gfx_v8_0_sw_init(void *handle)
1553 return r; 1873 return r;
1554 } 1874 }
1555 1875
1876 r = gfx_v8_0_rlc_init(adev);
1877 if (r) {
1878 DRM_ERROR("Failed to init rlc BOs!\n");
1879 return r;
1880 }
1881
1556 r = gfx_v8_0_mec_init(adev); 1882 r = gfx_v8_0_mec_init(adev);
1557 if (r) { 1883 if (r) {
1558 DRM_ERROR("Failed to init MEC BOs!\n"); 1884 DRM_ERROR("Failed to init MEC BOs!\n");
@@ -1570,7 +1896,7 @@ static int gfx_v8_0_sw_init(void *handle)
1570 ring->doorbell_index = AMDGPU_DOORBELL_GFX_RING0; 1896 ring->doorbell_index = AMDGPU_DOORBELL_GFX_RING0;
1571 } 1897 }
1572 1898
1573 r = amdgpu_ring_init(adev, ring, 1024 * 1024, 1899 r = amdgpu_ring_init(adev, ring, 1024,
1574 PACKET3(PACKET3_NOP, 0x3FFF), 0xf, 1900 PACKET3(PACKET3_NOP, 0x3FFF), 0xf,
1575 &adev->gfx.eop_irq, AMDGPU_CP_IRQ_GFX_EOP, 1901 &adev->gfx.eop_irq, AMDGPU_CP_IRQ_GFX_EOP,
1576 AMDGPU_RING_TYPE_GFX); 1902 AMDGPU_RING_TYPE_GFX);
@@ -1594,10 +1920,10 @@ static int gfx_v8_0_sw_init(void *handle)
1594 ring->me = 1; /* first MEC */ 1920 ring->me = 1; /* first MEC */
1595 ring->pipe = i / 8; 1921 ring->pipe = i / 8;
1596 ring->queue = i % 8; 1922 ring->queue = i % 8;
1597 sprintf(ring->name, "comp %d.%d.%d", ring->me, ring->pipe, ring->queue); 1923 sprintf(ring->name, "comp_%d.%d.%d", ring->me, ring->pipe, ring->queue);
1598 irq_type = AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP + ring->pipe; 1924 irq_type = AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP + ring->pipe;
1599 /* type-2 packets are deprecated on MEC, use type-3 instead */ 1925 /* type-2 packets are deprecated on MEC, use type-3 instead */
1600 r = amdgpu_ring_init(adev, ring, 1024 * 1024, 1926 r = amdgpu_ring_init(adev, ring, 1024,
1601 PACKET3(PACKET3_NOP, 0x3FFF), 0xf, 1927 PACKET3(PACKET3_NOP, 0x3FFF), 0xf,
1602 &adev->gfx.eop_irq, irq_type, 1928 &adev->gfx.eop_irq, irq_type,
1603 AMDGPU_RING_TYPE_COMPUTE); 1929 AMDGPU_RING_TYPE_COMPUTE);
@@ -1629,7 +1955,9 @@ static int gfx_v8_0_sw_init(void *handle)
1629 1955
1630 adev->gfx.ce_ram_size = 0x8000; 1956 adev->gfx.ce_ram_size = 0x8000;
1631 1957
1632 gfx_v8_0_gpu_early_init(adev); 1958 r = gfx_v8_0_gpu_early_init(adev);
1959 if (r)
1960 return r;
1633 1961
1634 return 0; 1962 return 0;
1635} 1963}
@@ -1650,6 +1978,10 @@ static int gfx_v8_0_sw_fini(void *handle)
1650 1978
1651 gfx_v8_0_mec_fini(adev); 1979 gfx_v8_0_mec_fini(adev);
1652 1980
1981 gfx_v8_0_rlc_fini(adev);
1982
1983 kfree(adev->gfx.rlc.register_list_format);
1984
1653 return 0; 1985 return 0;
1654} 1986}
1655 1987
@@ -2219,6 +2551,410 @@ static void gfx_v8_0_tiling_mode_table_init(struct amdgpu_device *adev)
2219 WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]); 2551 WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]);
2220 2552
2221 break; 2553 break;
2554 case CHIP_POLARIS11:
2555 modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2556 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2557 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2558 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2559 modearray[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2560 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2561 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
2562 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2563 modearray[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2564 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2565 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2566 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2567 modearray[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2568 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2569 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
2570 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2571 modearray[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2572 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2573 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2574 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2575 modearray[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2576 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2577 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2578 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2579 modearray[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2580 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2581 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2582 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2583 modearray[7] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2584 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2585 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2586 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2587 modearray[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2588 PIPE_CONFIG(ADDR_SURF_P4_16x16));
2589 modearray[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2590 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2591 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2592 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2593 modearray[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2594 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2595 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2596 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2597 modearray[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2598 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2599 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2600 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2601 modearray[12] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2602 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2603 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2604 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2605 modearray[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2606 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2607 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2608 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2609 modearray[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2610 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2611 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2612 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2613 modearray[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
2614 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2615 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2616 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2617 modearray[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2618 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2619 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2620 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2621 modearray[17] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2622 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2623 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2624 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2625 modearray[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
2626 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2627 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2628 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2629 modearray[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
2630 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2631 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2632 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2633 modearray[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
2634 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2635 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2636 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2637 modearray[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
2638 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2639 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2640 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2641 modearray[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
2642 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2643 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2644 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2645 modearray[23] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
2646 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2647 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2648 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2649 modearray[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
2650 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2651 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2652 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2653 modearray[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
2654 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2655 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2656 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2657 modearray[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
2658 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2659 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2660 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2661 modearray[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2662 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2663 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2664 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2665 modearray[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2666 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2667 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2668 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2669 modearray[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2670 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2671 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2672 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2673 modearray[30] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2674 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2675 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2676 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2677
2678 mod2array[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2679 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2680 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2681 NUM_BANKS(ADDR_SURF_16_BANK));
2682
2683 mod2array[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2684 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2685 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2686 NUM_BANKS(ADDR_SURF_16_BANK));
2687
2688 mod2array[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2689 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2690 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2691 NUM_BANKS(ADDR_SURF_16_BANK));
2692
2693 mod2array[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2694 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2695 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2696 NUM_BANKS(ADDR_SURF_16_BANK));
2697
2698 mod2array[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2699 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2700 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2701 NUM_BANKS(ADDR_SURF_16_BANK));
2702
2703 mod2array[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2704 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2705 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2706 NUM_BANKS(ADDR_SURF_16_BANK));
2707
2708 mod2array[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2709 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2710 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2711 NUM_BANKS(ADDR_SURF_16_BANK));
2712
2713 mod2array[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
2714 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
2715 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2716 NUM_BANKS(ADDR_SURF_16_BANK));
2717
2718 mod2array[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
2719 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2720 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2721 NUM_BANKS(ADDR_SURF_16_BANK));
2722
2723 mod2array[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2724 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2725 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2726 NUM_BANKS(ADDR_SURF_16_BANK));
2727
2728 mod2array[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2729 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2730 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2731 NUM_BANKS(ADDR_SURF_16_BANK));
2732
2733 mod2array[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2734 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2735 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2736 NUM_BANKS(ADDR_SURF_16_BANK));
2737
2738 mod2array[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2739 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2740 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2741 NUM_BANKS(ADDR_SURF_8_BANK));
2742
2743 mod2array[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2744 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2745 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2746 NUM_BANKS(ADDR_SURF_4_BANK));
2747
2748 for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
2749 WREG32(mmGB_TILE_MODE0 + reg_offset, modearray[reg_offset]);
2750
2751 for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
2752 if (reg_offset != 7)
2753 WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]);
2754
2755 break;
2756 case CHIP_POLARIS10:
2757 modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2758 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2759 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2760 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2761 modearray[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2762 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2763 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
2764 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2765 modearray[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2766 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2767 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2768 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2769 modearray[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2770 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2771 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
2772 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2773 modearray[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2774 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2775 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2776 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2777 modearray[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2778 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2779 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2780 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2781 modearray[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2782 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2783 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2784 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2785 modearray[7] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2786 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2787 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2788 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2789 modearray[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2790 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16));
2791 modearray[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2792 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2793 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2794 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2795 modearray[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2796 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2797 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2798 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2799 modearray[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2800 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2801 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2802 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2803 modearray[12] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2804 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2805 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2806 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2807 modearray[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2808 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2809 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2810 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2811 modearray[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2812 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2813 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2814 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2815 modearray[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
2816 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2817 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2818 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2819 modearray[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2820 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2821 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2822 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2823 modearray[17] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2824 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2825 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2826 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2827 modearray[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
2828 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2829 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2830 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2831 modearray[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
2832 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2833 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2834 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2835 modearray[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
2836 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2837 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2838 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2839 modearray[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
2840 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2841 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2842 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2843 modearray[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
2844 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2845 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2846 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2847 modearray[23] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
2848 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2849 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2850 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2851 modearray[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
2852 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2853 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2854 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2855 modearray[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
2856 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2857 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2858 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2859 modearray[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
2860 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2861 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2862 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2863 modearray[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2864 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2865 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2866 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2867 modearray[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2868 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2869 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2870 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2871 modearray[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2872 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2873 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2874 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2875 modearray[30] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2876 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2877 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2878 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2879
2880 mod2array[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2881 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2882 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2883 NUM_BANKS(ADDR_SURF_16_BANK));
2884
2885 mod2array[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2886 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2887 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2888 NUM_BANKS(ADDR_SURF_16_BANK));
2889
2890 mod2array[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2891 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2892 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2893 NUM_BANKS(ADDR_SURF_16_BANK));
2894
2895 mod2array[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2896 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2897 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2898 NUM_BANKS(ADDR_SURF_16_BANK));
2899
2900 mod2array[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2901 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2902 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2903 NUM_BANKS(ADDR_SURF_16_BANK));
2904
2905 mod2array[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2906 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2907 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2908 NUM_BANKS(ADDR_SURF_16_BANK));
2909
2910 mod2array[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2911 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2912 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2913 NUM_BANKS(ADDR_SURF_16_BANK));
2914
2915 mod2array[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2916 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
2917 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2918 NUM_BANKS(ADDR_SURF_16_BANK));
2919
2920 mod2array[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2921 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2922 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2923 NUM_BANKS(ADDR_SURF_16_BANK));
2924
2925 mod2array[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2926 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2927 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2928 NUM_BANKS(ADDR_SURF_16_BANK));
2929
2930 mod2array[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2931 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2932 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2933 NUM_BANKS(ADDR_SURF_16_BANK));
2934
2935 mod2array[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2936 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2937 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2938 NUM_BANKS(ADDR_SURF_8_BANK));
2939
2940 mod2array[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2941 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2942 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2943 NUM_BANKS(ADDR_SURF_4_BANK));
2944
2945 mod2array[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2946 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2947 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2948 NUM_BANKS(ADDR_SURF_4_BANK));
2949
2950 for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
2951 WREG32(mmGB_TILE_MODE0 + reg_offset, modearray[reg_offset]);
2952
2953 for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
2954 if (reg_offset != 7)
2955 WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]);
2956
2957 break;
2222 case CHIP_STONEY: 2958 case CHIP_STONEY:
2223 modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) | 2959 modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2224 PIPE_CONFIG(ADDR_SURF_P2) | 2960 PIPE_CONFIG(ADDR_SURF_P2) |
@@ -2788,6 +3524,188 @@ static void gfx_v8_0_enable_gui_idle_interrupt(struct amdgpu_device *adev,
2788 WREG32(mmCP_INT_CNTL_RING0, tmp); 3524 WREG32(mmCP_INT_CNTL_RING0, tmp);
2789} 3525}
2790 3526
3527static void gfx_v8_0_init_csb(struct amdgpu_device *adev)
3528{
3529 /* csib */
3530 WREG32(mmRLC_CSIB_ADDR_HI,
3531 adev->gfx.rlc.clear_state_gpu_addr >> 32);
3532 WREG32(mmRLC_CSIB_ADDR_LO,
3533 adev->gfx.rlc.clear_state_gpu_addr & 0xfffffffc);
3534 WREG32(mmRLC_CSIB_LENGTH,
3535 adev->gfx.rlc.clear_state_size);
3536}
3537
3538static void gfx_v8_0_parse_ind_reg_list(int *register_list_format,
3539 int ind_offset,
3540 int list_size,
3541 int *unique_indices,
3542 int *indices_count,
3543 int max_indices,
3544 int *ind_start_offsets,
3545 int *offset_count,
3546 int max_offset)
3547{
3548 int indices;
3549 bool new_entry = true;
3550
3551 for (; ind_offset < list_size; ind_offset++) {
3552
3553 if (new_entry) {
3554 new_entry = false;
3555 ind_start_offsets[*offset_count] = ind_offset;
3556 *offset_count = *offset_count + 1;
3557 BUG_ON(*offset_count >= max_offset);
3558 }
3559
3560 if (register_list_format[ind_offset] == 0xFFFFFFFF) {
3561 new_entry = true;
3562 continue;
3563 }
3564
3565 ind_offset += 2;
3566
3567 /* look for the matching indice */
3568 for (indices = 0;
3569 indices < *indices_count;
3570 indices++) {
3571 if (unique_indices[indices] ==
3572 register_list_format[ind_offset])
3573 break;
3574 }
3575
3576 if (indices >= *indices_count) {
3577 unique_indices[*indices_count] =
3578 register_list_format[ind_offset];
3579 indices = *indices_count;
3580 *indices_count = *indices_count + 1;
3581 BUG_ON(*indices_count >= max_indices);
3582 }
3583
3584 register_list_format[ind_offset] = indices;
3585 }
3586}
3587
3588static int gfx_v8_0_init_save_restore_list(struct amdgpu_device *adev)
3589{
3590 int i, temp, data;
3591 int unique_indices[] = {0, 0, 0, 0, 0, 0, 0, 0};
3592 int indices_count = 0;
3593 int indirect_start_offsets[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3594 int offset_count = 0;
3595
3596 int list_size;
3597 unsigned int *register_list_format =
3598 kmalloc(adev->gfx.rlc.reg_list_format_size_bytes, GFP_KERNEL);
3599 if (register_list_format == NULL)
3600 return -ENOMEM;
3601 memcpy(register_list_format, adev->gfx.rlc.register_list_format,
3602 adev->gfx.rlc.reg_list_format_size_bytes);
3603
3604 gfx_v8_0_parse_ind_reg_list(register_list_format,
3605 RLC_FormatDirectRegListLength,
3606 adev->gfx.rlc.reg_list_format_size_bytes >> 2,
3607 unique_indices,
3608 &indices_count,
3609 sizeof(unique_indices) / sizeof(int),
3610 indirect_start_offsets,
3611 &offset_count,
3612 sizeof(indirect_start_offsets)/sizeof(int));
3613
3614 /* save and restore list */
3615 temp = RREG32(mmRLC_SRM_CNTL);
3616 temp |= RLC_SRM_CNTL__AUTO_INCR_ADDR_MASK;
3617 WREG32(mmRLC_SRM_CNTL, temp);
3618
3619 WREG32(mmRLC_SRM_ARAM_ADDR, 0);
3620 for (i = 0; i < adev->gfx.rlc.reg_list_size_bytes >> 2; i++)
3621 WREG32(mmRLC_SRM_ARAM_DATA, adev->gfx.rlc.register_restore[i]);
3622
3623 /* indirect list */
3624 WREG32(mmRLC_GPM_SCRATCH_ADDR, adev->gfx.rlc.reg_list_format_start);
3625 for (i = 0; i < adev->gfx.rlc.reg_list_format_size_bytes >> 2; i++)
3626 WREG32(mmRLC_GPM_SCRATCH_DATA, register_list_format[i]);
3627
3628 list_size = adev->gfx.rlc.reg_list_size_bytes >> 2;
3629 list_size = list_size >> 1;
3630 WREG32(mmRLC_GPM_SCRATCH_ADDR, adev->gfx.rlc.reg_restore_list_size);
3631 WREG32(mmRLC_GPM_SCRATCH_DATA, list_size);
3632
3633 /* starting offsets starts */
3634 WREG32(mmRLC_GPM_SCRATCH_ADDR,
3635 adev->gfx.rlc.starting_offsets_start);
3636 for (i = 0; i < sizeof(indirect_start_offsets)/sizeof(int); i++)
3637 WREG32(mmRLC_GPM_SCRATCH_DATA,
3638 indirect_start_offsets[i]);
3639
3640 /* unique indices */
3641 temp = mmRLC_SRM_INDEX_CNTL_ADDR_0;
3642 data = mmRLC_SRM_INDEX_CNTL_DATA_0;
3643 for (i = 0; i < sizeof(unique_indices) / sizeof(int); i++) {
3644 amdgpu_mm_wreg(adev, temp + i, unique_indices[i] & 0x3FFFF, false);
3645 amdgpu_mm_wreg(adev, data + i, unique_indices[i] >> 20, false);
3646 }
3647 kfree(register_list_format);
3648
3649 return 0;
3650}
3651
3652static void gfx_v8_0_enable_save_restore_machine(struct amdgpu_device *adev)
3653{
3654 uint32_t data;
3655
3656 data = RREG32(mmRLC_SRM_CNTL);
3657 data |= RLC_SRM_CNTL__SRM_ENABLE_MASK;
3658 WREG32(mmRLC_SRM_CNTL, data);
3659}
3660
3661static void polaris11_init_power_gating(struct amdgpu_device *adev)
3662{
3663 uint32_t data;
3664
3665 if (adev->pg_flags & (AMD_PG_SUPPORT_GFX_PG |
3666 AMD_PG_SUPPORT_GFX_SMG |
3667 AMD_PG_SUPPORT_GFX_DMG)) {
3668 data = RREG32(mmCP_RB_WPTR_POLL_CNTL);
3669 data &= ~CP_RB_WPTR_POLL_CNTL__IDLE_POLL_COUNT_MASK;
3670 data |= (0x60 << CP_RB_WPTR_POLL_CNTL__IDLE_POLL_COUNT__SHIFT);
3671 WREG32(mmCP_RB_WPTR_POLL_CNTL, data);
3672
3673 data = 0;
3674 data |= (0x10 << RLC_PG_DELAY__POWER_UP_DELAY__SHIFT);
3675 data |= (0x10 << RLC_PG_DELAY__POWER_DOWN_DELAY__SHIFT);
3676 data |= (0x10 << RLC_PG_DELAY__CMD_PROPAGATE_DELAY__SHIFT);
3677 data |= (0x10 << RLC_PG_DELAY__MEM_SLEEP_DELAY__SHIFT);
3678 WREG32(mmRLC_PG_DELAY, data);
3679
3680 data = RREG32(mmRLC_PG_DELAY_2);
3681 data &= ~RLC_PG_DELAY_2__SERDES_CMD_DELAY_MASK;
3682 data |= (0x3 << RLC_PG_DELAY_2__SERDES_CMD_DELAY__SHIFT);
3683 WREG32(mmRLC_PG_DELAY_2, data);
3684
3685 data = RREG32(mmRLC_AUTO_PG_CTRL);
3686 data &= ~RLC_AUTO_PG_CTRL__GRBM_REG_SAVE_GFX_IDLE_THRESHOLD_MASK;
3687 data |= (0x55f0 << RLC_AUTO_PG_CTRL__GRBM_REG_SAVE_GFX_IDLE_THRESHOLD__SHIFT);
3688 WREG32(mmRLC_AUTO_PG_CTRL, data);
3689 }
3690}
3691
3692static void gfx_v8_0_init_pg(struct amdgpu_device *adev)
3693{
3694 if (adev->pg_flags & (AMD_PG_SUPPORT_GFX_PG |
3695 AMD_PG_SUPPORT_GFX_SMG |
3696 AMD_PG_SUPPORT_GFX_DMG |
3697 AMD_PG_SUPPORT_CP |
3698 AMD_PG_SUPPORT_GDS |
3699 AMD_PG_SUPPORT_RLC_SMU_HS)) {
3700 gfx_v8_0_init_csb(adev);
3701 gfx_v8_0_init_save_restore_list(adev);
3702 gfx_v8_0_enable_save_restore_machine(adev);
3703
3704 if (adev->asic_type == CHIP_POLARIS11)
3705 polaris11_init_power_gating(adev);
3706 }
3707}
3708
2791void gfx_v8_0_rlc_stop(struct amdgpu_device *adev) 3709void gfx_v8_0_rlc_stop(struct amdgpu_device *adev)
2792{ 3710{
2793 u32 tmp = RREG32(mmRLC_CNTL); 3711 u32 tmp = RREG32(mmRLC_CNTL);
@@ -2858,12 +3776,17 @@ static int gfx_v8_0_rlc_resume(struct amdgpu_device *adev)
2858 3776
2859 /* disable CG */ 3777 /* disable CG */
2860 WREG32(mmRLC_CGCG_CGLS_CTRL, 0); 3778 WREG32(mmRLC_CGCG_CGLS_CTRL, 0);
3779 if (adev->asic_type == CHIP_POLARIS11 ||
3780 adev->asic_type == CHIP_POLARIS10)
3781 WREG32(mmRLC_CGCG_CGLS_CTRL_3D, 0);
2861 3782
2862 /* disable PG */ 3783 /* disable PG */
2863 WREG32(mmRLC_PG_CNTL, 0); 3784 WREG32(mmRLC_PG_CNTL, 0);
2864 3785
2865 gfx_v8_0_rlc_reset(adev); 3786 gfx_v8_0_rlc_reset(adev);
2866 3787
3788 gfx_v8_0_init_pg(adev);
3789
2867 if (!adev->pp_enabled) { 3790 if (!adev->pp_enabled) {
2868 if (!adev->firmware.smu_load) { 3791 if (!adev->firmware.smu_load) {
2869 /* legacy rlc firmware loading */ 3792 /* legacy rlc firmware loading */
@@ -3035,9 +3958,14 @@ static int gfx_v8_0_cp_gfx_start(struct amdgpu_device *adev)
3035 amdgpu_ring_write(ring, mmPA_SC_RASTER_CONFIG - PACKET3_SET_CONTEXT_REG_START); 3958 amdgpu_ring_write(ring, mmPA_SC_RASTER_CONFIG - PACKET3_SET_CONTEXT_REG_START);
3036 switch (adev->asic_type) { 3959 switch (adev->asic_type) {
3037 case CHIP_TONGA: 3960 case CHIP_TONGA:
3961 case CHIP_POLARIS10:
3038 amdgpu_ring_write(ring, 0x16000012); 3962 amdgpu_ring_write(ring, 0x16000012);
3039 amdgpu_ring_write(ring, 0x0000002A); 3963 amdgpu_ring_write(ring, 0x0000002A);
3040 break; 3964 break;
3965 case CHIP_POLARIS11:
3966 amdgpu_ring_write(ring, 0x16000012);
3967 amdgpu_ring_write(ring, 0x00000000);
3968 break;
3041 case CHIP_FIJI: 3969 case CHIP_FIJI:
3042 amdgpu_ring_write(ring, 0x3a00161a); 3970 amdgpu_ring_write(ring, 0x3a00161a);
3043 amdgpu_ring_write(ring, 0x0000002e); 3971 amdgpu_ring_write(ring, 0x0000002e);
@@ -3122,6 +4050,8 @@ static int gfx_v8_0_cp_gfx_resume(struct amdgpu_device *adev)
3122 tmp = REG_SET_FIELD(tmp, CP_RB_DOORBELL_CONTROL, 4050 tmp = REG_SET_FIELD(tmp, CP_RB_DOORBELL_CONTROL,
3123 DOORBELL_OFFSET, ring->doorbell_index); 4051 DOORBELL_OFFSET, ring->doorbell_index);
3124 tmp = REG_SET_FIELD(tmp, CP_RB_DOORBELL_CONTROL, 4052 tmp = REG_SET_FIELD(tmp, CP_RB_DOORBELL_CONTROL,
4053 DOORBELL_HIT, 0);
4054 tmp = REG_SET_FIELD(tmp, CP_RB_DOORBELL_CONTROL,
3125 DOORBELL_EN, 1); 4055 DOORBELL_EN, 1);
3126 } else { 4056 } else {
3127 tmp = REG_SET_FIELD(tmp, CP_RB_DOORBELL_CONTROL, 4057 tmp = REG_SET_FIELD(tmp, CP_RB_DOORBELL_CONTROL,
@@ -3679,7 +4609,9 @@ static int gfx_v8_0_cp_compute_resume(struct amdgpu_device *adev)
3679 if (use_doorbell) { 4609 if (use_doorbell) {
3680 if ((adev->asic_type == CHIP_CARRIZO) || 4610 if ((adev->asic_type == CHIP_CARRIZO) ||
3681 (adev->asic_type == CHIP_FIJI) || 4611 (adev->asic_type == CHIP_FIJI) ||
3682 (adev->asic_type == CHIP_STONEY)) { 4612 (adev->asic_type == CHIP_STONEY) ||
4613 (adev->asic_type == CHIP_POLARIS11) ||
4614 (adev->asic_type == CHIP_POLARIS10)) {
3683 WREG32(mmCP_MEC_DOORBELL_RANGE_LOWER, 4615 WREG32(mmCP_MEC_DOORBELL_RANGE_LOWER,
3684 AMDGPU_DOORBELL_KIQ << 2); 4616 AMDGPU_DOORBELL_KIQ << 2);
3685 WREG32(mmCP_MEC_DOORBELL_RANGE_UPPER, 4617 WREG32(mmCP_MEC_DOORBELL_RANGE_UPPER,
@@ -3713,7 +4645,9 @@ static int gfx_v8_0_cp_compute_resume(struct amdgpu_device *adev)
3713 tmp = REG_SET_FIELD(tmp, CP_HQD_PERSISTENT_STATE, PRELOAD_SIZE, 0x53); 4645 tmp = REG_SET_FIELD(tmp, CP_HQD_PERSISTENT_STATE, PRELOAD_SIZE, 0x53);
3714 WREG32(mmCP_HQD_PERSISTENT_STATE, tmp); 4646 WREG32(mmCP_HQD_PERSISTENT_STATE, tmp);
3715 mqd->cp_hqd_persistent_state = tmp; 4647 mqd->cp_hqd_persistent_state = tmp;
3716 if (adev->asic_type == CHIP_STONEY) { 4648 if (adev->asic_type == CHIP_STONEY ||
4649 adev->asic_type == CHIP_POLARIS11 ||
4650 adev->asic_type == CHIP_POLARIS10) {
3717 tmp = RREG32(mmCP_ME1_PIPE3_INT_CNTL); 4651 tmp = RREG32(mmCP_ME1_PIPE3_INT_CNTL);
3718 tmp = REG_SET_FIELD(tmp, CP_ME1_PIPE3_INT_CNTL, GENERIC2_INT_ENABLE, 1); 4652 tmp = REG_SET_FIELD(tmp, CP_ME1_PIPE3_INT_CNTL, GENERIC2_INT_ENABLE, 1);
3719 WREG32(mmCP_ME1_PIPE3_INT_CNTL, tmp); 4653 WREG32(mmCP_ME1_PIPE3_INT_CNTL, tmp);
@@ -3845,6 +4779,9 @@ static int gfx_v8_0_hw_fini(void *handle)
3845 gfx_v8_0_rlc_stop(adev); 4779 gfx_v8_0_rlc_stop(adev);
3846 gfx_v8_0_cp_compute_fini(adev); 4780 gfx_v8_0_cp_compute_fini(adev);
3847 4781
4782 amdgpu_set_powergating_state(adev,
4783 AMD_IP_BLOCK_TYPE_GFX, AMD_PG_STATE_UNGATE);
4784
3848 return 0; 4785 return 0;
3849} 4786}
3850 4787
@@ -3889,185 +4826,6 @@ static int gfx_v8_0_wait_for_idle(void *handle)
3889 return -ETIMEDOUT; 4826 return -ETIMEDOUT;
3890} 4827}
3891 4828
3892static void gfx_v8_0_print_status(void *handle)
3893{
3894 int i;
3895 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
3896
3897 dev_info(adev->dev, "GFX 8.x registers\n");
3898 dev_info(adev->dev, " GRBM_STATUS=0x%08X\n",
3899 RREG32(mmGRBM_STATUS));
3900 dev_info(adev->dev, " GRBM_STATUS2=0x%08X\n",
3901 RREG32(mmGRBM_STATUS2));
3902 dev_info(adev->dev, " GRBM_STATUS_SE0=0x%08X\n",
3903 RREG32(mmGRBM_STATUS_SE0));
3904 dev_info(adev->dev, " GRBM_STATUS_SE1=0x%08X\n",
3905 RREG32(mmGRBM_STATUS_SE1));
3906 dev_info(adev->dev, " GRBM_STATUS_SE2=0x%08X\n",
3907 RREG32(mmGRBM_STATUS_SE2));
3908 dev_info(adev->dev, " GRBM_STATUS_SE3=0x%08X\n",
3909 RREG32(mmGRBM_STATUS_SE3));
3910 dev_info(adev->dev, " CP_STAT = 0x%08x\n", RREG32(mmCP_STAT));
3911 dev_info(adev->dev, " CP_STALLED_STAT1 = 0x%08x\n",
3912 RREG32(mmCP_STALLED_STAT1));
3913 dev_info(adev->dev, " CP_STALLED_STAT2 = 0x%08x\n",
3914 RREG32(mmCP_STALLED_STAT2));
3915 dev_info(adev->dev, " CP_STALLED_STAT3 = 0x%08x\n",
3916 RREG32(mmCP_STALLED_STAT3));
3917 dev_info(adev->dev, " CP_CPF_BUSY_STAT = 0x%08x\n",
3918 RREG32(mmCP_CPF_BUSY_STAT));
3919 dev_info(adev->dev, " CP_CPF_STALLED_STAT1 = 0x%08x\n",
3920 RREG32(mmCP_CPF_STALLED_STAT1));
3921 dev_info(adev->dev, " CP_CPF_STATUS = 0x%08x\n", RREG32(mmCP_CPF_STATUS));
3922 dev_info(adev->dev, " CP_CPC_BUSY_STAT = 0x%08x\n", RREG32(mmCP_CPC_BUSY_STAT));
3923 dev_info(adev->dev, " CP_CPC_STALLED_STAT1 = 0x%08x\n",
3924 RREG32(mmCP_CPC_STALLED_STAT1));
3925 dev_info(adev->dev, " CP_CPC_STATUS = 0x%08x\n", RREG32(mmCP_CPC_STATUS));
3926
3927 for (i = 0; i < 32; i++) {
3928 dev_info(adev->dev, " GB_TILE_MODE%d=0x%08X\n",
3929 i, RREG32(mmGB_TILE_MODE0 + (i * 4)));
3930 }
3931 for (i = 0; i < 16; i++) {
3932 dev_info(adev->dev, " GB_MACROTILE_MODE%d=0x%08X\n",
3933 i, RREG32(mmGB_MACROTILE_MODE0 + (i * 4)));
3934 }
3935 for (i = 0; i < adev->gfx.config.max_shader_engines; i++) {
3936 dev_info(adev->dev, " se: %d\n", i);
3937 gfx_v8_0_select_se_sh(adev, i, 0xffffffff);
3938 dev_info(adev->dev, " PA_SC_RASTER_CONFIG=0x%08X\n",
3939 RREG32(mmPA_SC_RASTER_CONFIG));
3940 dev_info(adev->dev, " PA_SC_RASTER_CONFIG_1=0x%08X\n",
3941 RREG32(mmPA_SC_RASTER_CONFIG_1));
3942 }
3943 gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff);
3944
3945 dev_info(adev->dev, " GB_ADDR_CONFIG=0x%08X\n",
3946 RREG32(mmGB_ADDR_CONFIG));
3947 dev_info(adev->dev, " HDP_ADDR_CONFIG=0x%08X\n",
3948 RREG32(mmHDP_ADDR_CONFIG));
3949 dev_info(adev->dev, " DMIF_ADDR_CALC=0x%08X\n",
3950 RREG32(mmDMIF_ADDR_CALC));
3951
3952 dev_info(adev->dev, " CP_MEQ_THRESHOLDS=0x%08X\n",
3953 RREG32(mmCP_MEQ_THRESHOLDS));
3954 dev_info(adev->dev, " SX_DEBUG_1=0x%08X\n",
3955 RREG32(mmSX_DEBUG_1));
3956 dev_info(adev->dev, " TA_CNTL_AUX=0x%08X\n",
3957 RREG32(mmTA_CNTL_AUX));
3958 dev_info(adev->dev, " SPI_CONFIG_CNTL=0x%08X\n",
3959 RREG32(mmSPI_CONFIG_CNTL));
3960 dev_info(adev->dev, " SQ_CONFIG=0x%08X\n",
3961 RREG32(mmSQ_CONFIG));
3962 dev_info(adev->dev, " DB_DEBUG=0x%08X\n",
3963 RREG32(mmDB_DEBUG));
3964 dev_info(adev->dev, " DB_DEBUG2=0x%08X\n",
3965 RREG32(mmDB_DEBUG2));
3966 dev_info(adev->dev, " DB_DEBUG3=0x%08X\n",
3967 RREG32(mmDB_DEBUG3));
3968 dev_info(adev->dev, " CB_HW_CONTROL=0x%08X\n",
3969 RREG32(mmCB_HW_CONTROL));
3970 dev_info(adev->dev, " SPI_CONFIG_CNTL_1=0x%08X\n",
3971 RREG32(mmSPI_CONFIG_CNTL_1));
3972 dev_info(adev->dev, " PA_SC_FIFO_SIZE=0x%08X\n",
3973 RREG32(mmPA_SC_FIFO_SIZE));
3974 dev_info(adev->dev, " VGT_NUM_INSTANCES=0x%08X\n",
3975 RREG32(mmVGT_NUM_INSTANCES));
3976 dev_info(adev->dev, " CP_PERFMON_CNTL=0x%08X\n",
3977 RREG32(mmCP_PERFMON_CNTL));
3978 dev_info(adev->dev, " PA_SC_FORCE_EOV_MAX_CNTS=0x%08X\n",
3979 RREG32(mmPA_SC_FORCE_EOV_MAX_CNTS));
3980 dev_info(adev->dev, " VGT_CACHE_INVALIDATION=0x%08X\n",
3981 RREG32(mmVGT_CACHE_INVALIDATION));
3982 dev_info(adev->dev, " VGT_GS_VERTEX_REUSE=0x%08X\n",
3983 RREG32(mmVGT_GS_VERTEX_REUSE));
3984 dev_info(adev->dev, " PA_SC_LINE_STIPPLE_STATE=0x%08X\n",
3985 RREG32(mmPA_SC_LINE_STIPPLE_STATE));
3986 dev_info(adev->dev, " PA_CL_ENHANCE=0x%08X\n",
3987 RREG32(mmPA_CL_ENHANCE));
3988 dev_info(adev->dev, " PA_SC_ENHANCE=0x%08X\n",
3989 RREG32(mmPA_SC_ENHANCE));
3990
3991 dev_info(adev->dev, " CP_ME_CNTL=0x%08X\n",
3992 RREG32(mmCP_ME_CNTL));
3993 dev_info(adev->dev, " CP_MAX_CONTEXT=0x%08X\n",
3994 RREG32(mmCP_MAX_CONTEXT));
3995 dev_info(adev->dev, " CP_ENDIAN_SWAP=0x%08X\n",
3996 RREG32(mmCP_ENDIAN_SWAP));
3997 dev_info(adev->dev, " CP_DEVICE_ID=0x%08X\n",
3998 RREG32(mmCP_DEVICE_ID));
3999
4000 dev_info(adev->dev, " CP_SEM_WAIT_TIMER=0x%08X\n",
4001 RREG32(mmCP_SEM_WAIT_TIMER));
4002
4003 dev_info(adev->dev, " CP_RB_WPTR_DELAY=0x%08X\n",
4004 RREG32(mmCP_RB_WPTR_DELAY));
4005 dev_info(adev->dev, " CP_RB_VMID=0x%08X\n",
4006 RREG32(mmCP_RB_VMID));
4007 dev_info(adev->dev, " CP_RB0_CNTL=0x%08X\n",
4008 RREG32(mmCP_RB0_CNTL));
4009 dev_info(adev->dev, " CP_RB0_WPTR=0x%08X\n",
4010 RREG32(mmCP_RB0_WPTR));
4011 dev_info(adev->dev, " CP_RB0_RPTR_ADDR=0x%08X\n",
4012 RREG32(mmCP_RB0_RPTR_ADDR));
4013 dev_info(adev->dev, " CP_RB0_RPTR_ADDR_HI=0x%08X\n",
4014 RREG32(mmCP_RB0_RPTR_ADDR_HI));
4015 dev_info(adev->dev, " CP_RB0_CNTL=0x%08X\n",
4016 RREG32(mmCP_RB0_CNTL));
4017 dev_info(adev->dev, " CP_RB0_BASE=0x%08X\n",
4018 RREG32(mmCP_RB0_BASE));
4019 dev_info(adev->dev, " CP_RB0_BASE_HI=0x%08X\n",
4020 RREG32(mmCP_RB0_BASE_HI));
4021 dev_info(adev->dev, " CP_MEC_CNTL=0x%08X\n",
4022 RREG32(mmCP_MEC_CNTL));
4023 dev_info(adev->dev, " CP_CPF_DEBUG=0x%08X\n",
4024 RREG32(mmCP_CPF_DEBUG));
4025
4026 dev_info(adev->dev, " SCRATCH_ADDR=0x%08X\n",
4027 RREG32(mmSCRATCH_ADDR));
4028 dev_info(adev->dev, " SCRATCH_UMSK=0x%08X\n",
4029 RREG32(mmSCRATCH_UMSK));
4030
4031 dev_info(adev->dev, " CP_INT_CNTL_RING0=0x%08X\n",
4032 RREG32(mmCP_INT_CNTL_RING0));
4033 dev_info(adev->dev, " RLC_LB_CNTL=0x%08X\n",
4034 RREG32(mmRLC_LB_CNTL));
4035 dev_info(adev->dev, " RLC_CNTL=0x%08X\n",
4036 RREG32(mmRLC_CNTL));
4037 dev_info(adev->dev, " RLC_CGCG_CGLS_CTRL=0x%08X\n",
4038 RREG32(mmRLC_CGCG_CGLS_CTRL));
4039 dev_info(adev->dev, " RLC_LB_CNTR_INIT=0x%08X\n",
4040 RREG32(mmRLC_LB_CNTR_INIT));
4041 dev_info(adev->dev, " RLC_LB_CNTR_MAX=0x%08X\n",
4042 RREG32(mmRLC_LB_CNTR_MAX));
4043 dev_info(adev->dev, " RLC_LB_INIT_CU_MASK=0x%08X\n",
4044 RREG32(mmRLC_LB_INIT_CU_MASK));
4045 dev_info(adev->dev, " RLC_LB_PARAMS=0x%08X\n",
4046 RREG32(mmRLC_LB_PARAMS));
4047 dev_info(adev->dev, " RLC_LB_CNTL=0x%08X\n",
4048 RREG32(mmRLC_LB_CNTL));
4049 dev_info(adev->dev, " RLC_MC_CNTL=0x%08X\n",
4050 RREG32(mmRLC_MC_CNTL));
4051 dev_info(adev->dev, " RLC_UCODE_CNTL=0x%08X\n",
4052 RREG32(mmRLC_UCODE_CNTL));
4053
4054 mutex_lock(&adev->srbm_mutex);
4055 for (i = 0; i < 16; i++) {
4056 vi_srbm_select(adev, 0, 0, 0, i);
4057 dev_info(adev->dev, " VM %d:\n", i);
4058 dev_info(adev->dev, " SH_MEM_CONFIG=0x%08X\n",
4059 RREG32(mmSH_MEM_CONFIG));
4060 dev_info(adev->dev, " SH_MEM_APE1_BASE=0x%08X\n",
4061 RREG32(mmSH_MEM_APE1_BASE));
4062 dev_info(adev->dev, " SH_MEM_APE1_LIMIT=0x%08X\n",
4063 RREG32(mmSH_MEM_APE1_LIMIT));
4064 dev_info(adev->dev, " SH_MEM_BASES=0x%08X\n",
4065 RREG32(mmSH_MEM_BASES));
4066 }
4067 vi_srbm_select(adev, 0, 0, 0, 0);
4068 mutex_unlock(&adev->srbm_mutex);
4069}
4070
4071static int gfx_v8_0_soft_reset(void *handle) 4829static int gfx_v8_0_soft_reset(void *handle)
4072{ 4830{
4073 u32 grbm_soft_reset = 0, srbm_soft_reset = 0; 4831 u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
@@ -4108,7 +4866,6 @@ static int gfx_v8_0_soft_reset(void *handle)
4108 SRBM_SOFT_RESET, SOFT_RESET_GRBM, 1); 4866 SRBM_SOFT_RESET, SOFT_RESET_GRBM, 1);
4109 4867
4110 if (grbm_soft_reset || srbm_soft_reset) { 4868 if (grbm_soft_reset || srbm_soft_reset) {
4111 gfx_v8_0_print_status((void *)adev);
4112 /* stop the rlc */ 4869 /* stop the rlc */
4113 gfx_v8_0_rlc_stop(adev); 4870 gfx_v8_0_rlc_stop(adev);
4114 4871
@@ -4168,7 +4925,6 @@ static int gfx_v8_0_soft_reset(void *handle)
4168 4925
4169 /* Wait a little for things to settle down */ 4926 /* Wait a little for things to settle down */
4170 udelay(50); 4927 udelay(50);
4171 gfx_v8_0_print_status((void *)adev);
4172 } 4928 }
4173 return 0; 4929 return 0;
4174} 4930}
@@ -4250,6 +5006,7 @@ static int gfx_v8_0_early_init(void *handle)
4250 gfx_v8_0_set_ring_funcs(adev); 5006 gfx_v8_0_set_ring_funcs(adev);
4251 gfx_v8_0_set_irq_funcs(adev); 5007 gfx_v8_0_set_irq_funcs(adev);
4252 gfx_v8_0_set_gds_init(adev); 5008 gfx_v8_0_set_gds_init(adev);
5009 gfx_v8_0_set_rlc_funcs(adev);
4253 5010
4254 return 0; 5011 return 0;
4255} 5012}
@@ -4272,17 +5029,109 @@ static int gfx_v8_0_late_init(void *handle)
4272 if (r) 5029 if (r)
4273 return r; 5030 return r;
4274 5031
5032 amdgpu_set_powergating_state(adev,
5033 AMD_IP_BLOCK_TYPE_GFX, AMD_PG_STATE_GATE);
5034
4275 return 0; 5035 return 0;
4276} 5036}
4277 5037
5038static void polaris11_enable_gfx_static_mg_power_gating(struct amdgpu_device *adev,
5039 bool enable)
5040{
5041 uint32_t data, temp;
5042
5043 /* Send msg to SMU via Powerplay */
5044 amdgpu_set_powergating_state(adev,
5045 AMD_IP_BLOCK_TYPE_SMC,
5046 enable ? AMD_PG_STATE_GATE : AMD_PG_STATE_UNGATE);
5047
5048 if (enable) {
5049 /* Enable static MGPG */
5050 temp = data = RREG32(mmRLC_PG_CNTL);
5051 data |= RLC_PG_CNTL__STATIC_PER_CU_PG_ENABLE_MASK;
5052
5053 if (temp != data)
5054 WREG32(mmRLC_PG_CNTL, data);
5055 } else {
5056 temp = data = RREG32(mmRLC_PG_CNTL);
5057 data &= ~RLC_PG_CNTL__STATIC_PER_CU_PG_ENABLE_MASK;
5058
5059 if (temp != data)
5060 WREG32(mmRLC_PG_CNTL, data);
5061 }
5062}
5063
5064static void polaris11_enable_gfx_dynamic_mg_power_gating(struct amdgpu_device *adev,
5065 bool enable)
5066{
5067 uint32_t data, temp;
5068
5069 if (enable) {
5070 /* Enable dynamic MGPG */
5071 temp = data = RREG32(mmRLC_PG_CNTL);
5072 data |= RLC_PG_CNTL__DYN_PER_CU_PG_ENABLE_MASK;
5073
5074 if (temp != data)
5075 WREG32(mmRLC_PG_CNTL, data);
5076 } else {
5077 temp = data = RREG32(mmRLC_PG_CNTL);
5078 data &= ~RLC_PG_CNTL__DYN_PER_CU_PG_ENABLE_MASK;
5079
5080 if (temp != data)
5081 WREG32(mmRLC_PG_CNTL, data);
5082 }
5083}
5084
5085static void polaris11_enable_gfx_quick_mg_power_gating(struct amdgpu_device *adev,
5086 bool enable)
5087{
5088 uint32_t data, temp;
5089
5090 if (enable) {
5091 /* Enable quick PG */
5092 temp = data = RREG32(mmRLC_PG_CNTL);
5093 data |= 0x100000;
5094
5095 if (temp != data)
5096 WREG32(mmRLC_PG_CNTL, data);
5097 } else {
5098 temp = data = RREG32(mmRLC_PG_CNTL);
5099 data &= ~0x100000;
5100
5101 if (temp != data)
5102 WREG32(mmRLC_PG_CNTL, data);
5103 }
5104}
5105
4278static int gfx_v8_0_set_powergating_state(void *handle, 5106static int gfx_v8_0_set_powergating_state(void *handle,
4279 enum amd_powergating_state state) 5107 enum amd_powergating_state state)
4280{ 5108{
5109 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
5110
5111 if (!(adev->pg_flags & AMD_PG_SUPPORT_GFX_PG))
5112 return 0;
5113
5114 switch (adev->asic_type) {
5115 case CHIP_POLARIS11:
5116 if (adev->pg_flags & AMD_PG_SUPPORT_GFX_SMG)
5117 polaris11_enable_gfx_static_mg_power_gating(adev,
5118 state == AMD_PG_STATE_GATE ? true : false);
5119 else if (adev->pg_flags & AMD_PG_SUPPORT_GFX_DMG)
5120 polaris11_enable_gfx_dynamic_mg_power_gating(adev,
5121 state == AMD_PG_STATE_GATE ? true : false);
5122 else
5123 polaris11_enable_gfx_quick_mg_power_gating(adev,
5124 state == AMD_PG_STATE_GATE ? true : false);
5125 break;
5126 default:
5127 break;
5128 }
5129
4281 return 0; 5130 return 0;
4282} 5131}
4283 5132
4284static void fiji_send_serdes_cmd(struct amdgpu_device *adev, 5133static void gfx_v8_0_send_serdes_cmd(struct amdgpu_device *adev,
4285 uint32_t reg_addr, uint32_t cmd) 5134 uint32_t reg_addr, uint32_t cmd)
4286{ 5135{
4287 uint32_t data; 5136 uint32_t data;
4288 5137
@@ -4292,7 +5141,8 @@ static void fiji_send_serdes_cmd(struct amdgpu_device *adev,
4292 WREG32(mmRLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff); 5141 WREG32(mmRLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
4293 5142
4294 data = RREG32(mmRLC_SERDES_WR_CTRL); 5143 data = RREG32(mmRLC_SERDES_WR_CTRL);
4295 data &= ~(RLC_SERDES_WR_CTRL__WRITE_COMMAND_MASK | 5144 if (adev->asic_type == CHIP_STONEY)
5145 data &= ~(RLC_SERDES_WR_CTRL__WRITE_COMMAND_MASK |
4296 RLC_SERDES_WR_CTRL__READ_COMMAND_MASK | 5146 RLC_SERDES_WR_CTRL__READ_COMMAND_MASK |
4297 RLC_SERDES_WR_CTRL__P1_SELECT_MASK | 5147 RLC_SERDES_WR_CTRL__P1_SELECT_MASK |
4298 RLC_SERDES_WR_CTRL__P2_SELECT_MASK | 5148 RLC_SERDES_WR_CTRL__P2_SELECT_MASK |
@@ -4300,42 +5150,218 @@ static void fiji_send_serdes_cmd(struct amdgpu_device *adev,
4300 RLC_SERDES_WR_CTRL__POWER_DOWN_MASK | 5150 RLC_SERDES_WR_CTRL__POWER_DOWN_MASK |
4301 RLC_SERDES_WR_CTRL__POWER_UP_MASK | 5151 RLC_SERDES_WR_CTRL__POWER_UP_MASK |
4302 RLC_SERDES_WR_CTRL__SHORT_FORMAT_MASK | 5152 RLC_SERDES_WR_CTRL__SHORT_FORMAT_MASK |
4303 RLC_SERDES_WR_CTRL__BPM_DATA_MASK |
4304 RLC_SERDES_WR_CTRL__REG_ADDR_MASK |
4305 RLC_SERDES_WR_CTRL__SRBM_OVERRIDE_MASK); 5153 RLC_SERDES_WR_CTRL__SRBM_OVERRIDE_MASK);
5154 else
5155 data &= ~(RLC_SERDES_WR_CTRL__WRITE_COMMAND_MASK |
5156 RLC_SERDES_WR_CTRL__READ_COMMAND_MASK |
5157 RLC_SERDES_WR_CTRL__P1_SELECT_MASK |
5158 RLC_SERDES_WR_CTRL__P2_SELECT_MASK |
5159 RLC_SERDES_WR_CTRL__RDDATA_RESET_MASK |
5160 RLC_SERDES_WR_CTRL__POWER_DOWN_MASK |
5161 RLC_SERDES_WR_CTRL__POWER_UP_MASK |
5162 RLC_SERDES_WR_CTRL__SHORT_FORMAT_MASK |
5163 RLC_SERDES_WR_CTRL__BPM_DATA_MASK |
5164 RLC_SERDES_WR_CTRL__REG_ADDR_MASK |
5165 RLC_SERDES_WR_CTRL__SRBM_OVERRIDE_MASK);
4306 data |= (RLC_SERDES_WR_CTRL__RSVD_BPM_ADDR_MASK | 5166 data |= (RLC_SERDES_WR_CTRL__RSVD_BPM_ADDR_MASK |
4307 (cmd << RLC_SERDES_WR_CTRL__BPM_DATA__SHIFT) | 5167 (cmd << RLC_SERDES_WR_CTRL__BPM_DATA__SHIFT) |
4308 (reg_addr << RLC_SERDES_WR_CTRL__REG_ADDR__SHIFT) | 5168 (reg_addr << RLC_SERDES_WR_CTRL__REG_ADDR__SHIFT) |
4309 (0xff << RLC_SERDES_WR_CTRL__BPM_ADDR__SHIFT)); 5169 (0xff << RLC_SERDES_WR_CTRL__BPM_ADDR__SHIFT));
4310 5170
4311 WREG32(mmRLC_SERDES_WR_CTRL, data); 5171 WREG32(mmRLC_SERDES_WR_CTRL, data);
4312} 5172}
4313 5173
4314static void fiji_update_medium_grain_clock_gating(struct amdgpu_device *adev, 5174#define MSG_ENTER_RLC_SAFE_MODE 1
4315 bool enable) 5175#define MSG_EXIT_RLC_SAFE_MODE 0
5176
5177#define RLC_GPR_REG2__REQ_MASK 0x00000001
5178#define RLC_GPR_REG2__MESSAGE__SHIFT 0x00000001
5179#define RLC_GPR_REG2__MESSAGE_MASK 0x0000001e
5180
5181static void cz_enter_rlc_safe_mode(struct amdgpu_device *adev)
5182{
5183 u32 data = 0;
5184 unsigned i;
5185
5186 data = RREG32(mmRLC_CNTL);
5187 if ((data & RLC_CNTL__RLC_ENABLE_F32_MASK) == 0)
5188 return;
5189
5190 if ((adev->cg_flags & (AMD_CG_SUPPORT_GFX_CGCG | AMD_CG_SUPPORT_GFX_MGCG)) ||
5191 (adev->pg_flags & (AMD_PG_SUPPORT_GFX_PG | AMD_PG_SUPPORT_GFX_SMG |
5192 AMD_PG_SUPPORT_GFX_DMG))) {
5193 data |= RLC_GPR_REG2__REQ_MASK;
5194 data &= ~RLC_GPR_REG2__MESSAGE_MASK;
5195 data |= (MSG_ENTER_RLC_SAFE_MODE << RLC_GPR_REG2__MESSAGE__SHIFT);
5196 WREG32(mmRLC_GPR_REG2, data);
5197
5198 for (i = 0; i < adev->usec_timeout; i++) {
5199 if ((RREG32(mmRLC_GPM_STAT) &
5200 (RLC_GPM_STAT__GFX_CLOCK_STATUS_MASK |
5201 RLC_GPM_STAT__GFX_POWER_STATUS_MASK)) ==
5202 (RLC_GPM_STAT__GFX_CLOCK_STATUS_MASK |
5203 RLC_GPM_STAT__GFX_POWER_STATUS_MASK))
5204 break;
5205 udelay(1);
5206 }
5207
5208 for (i = 0; i < adev->usec_timeout; i++) {
5209 if ((RREG32(mmRLC_GPR_REG2) & RLC_GPR_REG2__REQ_MASK) == 0)
5210 break;
5211 udelay(1);
5212 }
5213 adev->gfx.rlc.in_safe_mode = true;
5214 }
5215}
5216
5217static void cz_exit_rlc_safe_mode(struct amdgpu_device *adev)
5218{
5219 u32 data;
5220 unsigned i;
5221
5222 data = RREG32(mmRLC_CNTL);
5223 if ((data & RLC_CNTL__RLC_ENABLE_F32_MASK) == 0)
5224 return;
5225
5226 if ((adev->cg_flags & (AMD_CG_SUPPORT_GFX_CGCG | AMD_CG_SUPPORT_GFX_MGCG)) ||
5227 (adev->pg_flags & (AMD_PG_SUPPORT_GFX_PG | AMD_PG_SUPPORT_GFX_SMG |
5228 AMD_PG_SUPPORT_GFX_DMG))) {
5229 data |= RLC_GPR_REG2__REQ_MASK;
5230 data &= ~RLC_GPR_REG2__MESSAGE_MASK;
5231 data |= (MSG_EXIT_RLC_SAFE_MODE << RLC_GPR_REG2__MESSAGE__SHIFT);
5232 WREG32(mmRLC_GPR_REG2, data);
5233 adev->gfx.rlc.in_safe_mode = false;
5234 }
5235
5236 for (i = 0; i < adev->usec_timeout; i++) {
5237 if ((RREG32(mmRLC_GPR_REG2) & RLC_GPR_REG2__REQ_MASK) == 0)
5238 break;
5239 udelay(1);
5240 }
5241}
5242
5243static void iceland_enter_rlc_safe_mode(struct amdgpu_device *adev)
5244{
5245 u32 data;
5246 unsigned i;
5247
5248 data = RREG32(mmRLC_CNTL);
5249 if (!(data & RLC_CNTL__RLC_ENABLE_F32_MASK))
5250 return;
5251
5252 if (adev->cg_flags & (AMD_CG_SUPPORT_GFX_CGCG | AMD_CG_SUPPORT_GFX_MGCG)) {
5253 data |= RLC_SAFE_MODE__CMD_MASK;
5254 data &= ~RLC_SAFE_MODE__MESSAGE_MASK;
5255 data |= (1 << RLC_SAFE_MODE__MESSAGE__SHIFT);
5256 WREG32(mmRLC_SAFE_MODE, data);
5257
5258 for (i = 0; i < adev->usec_timeout; i++) {
5259 if ((RREG32(mmRLC_GPM_STAT) &
5260 (RLC_GPM_STAT__GFX_CLOCK_STATUS_MASK |
5261 RLC_GPM_STAT__GFX_POWER_STATUS_MASK)) ==
5262 (RLC_GPM_STAT__GFX_CLOCK_STATUS_MASK |
5263 RLC_GPM_STAT__GFX_POWER_STATUS_MASK))
5264 break;
5265 udelay(1);
5266 }
5267
5268 for (i = 0; i < adev->usec_timeout; i++) {
5269 if ((RREG32(mmRLC_SAFE_MODE) & RLC_SAFE_MODE__CMD_MASK) == 0)
5270 break;
5271 udelay(1);
5272 }
5273 adev->gfx.rlc.in_safe_mode = true;
5274 }
5275}
5276
5277static void iceland_exit_rlc_safe_mode(struct amdgpu_device *adev)
5278{
5279 u32 data = 0;
5280 unsigned i;
5281
5282 data = RREG32(mmRLC_CNTL);
5283 if (!(data & RLC_CNTL__RLC_ENABLE_F32_MASK))
5284 return;
5285
5286 if (adev->cg_flags & (AMD_CG_SUPPORT_GFX_CGCG | AMD_CG_SUPPORT_GFX_MGCG)) {
5287 if (adev->gfx.rlc.in_safe_mode) {
5288 data |= RLC_SAFE_MODE__CMD_MASK;
5289 data &= ~RLC_SAFE_MODE__MESSAGE_MASK;
5290 WREG32(mmRLC_SAFE_MODE, data);
5291 adev->gfx.rlc.in_safe_mode = false;
5292 }
5293 }
5294
5295 for (i = 0; i < adev->usec_timeout; i++) {
5296 if ((RREG32(mmRLC_SAFE_MODE) & RLC_SAFE_MODE__CMD_MASK) == 0)
5297 break;
5298 udelay(1);
5299 }
5300}
5301
5302static void gfx_v8_0_nop_enter_rlc_safe_mode(struct amdgpu_device *adev)
5303{
5304 adev->gfx.rlc.in_safe_mode = true;
5305}
5306
5307static void gfx_v8_0_nop_exit_rlc_safe_mode(struct amdgpu_device *adev)
5308{
5309 adev->gfx.rlc.in_safe_mode = false;
5310}
5311
5312static const struct amdgpu_rlc_funcs cz_rlc_funcs = {
5313 .enter_safe_mode = cz_enter_rlc_safe_mode,
5314 .exit_safe_mode = cz_exit_rlc_safe_mode
5315};
5316
5317static const struct amdgpu_rlc_funcs iceland_rlc_funcs = {
5318 .enter_safe_mode = iceland_enter_rlc_safe_mode,
5319 .exit_safe_mode = iceland_exit_rlc_safe_mode
5320};
5321
5322static const struct amdgpu_rlc_funcs gfx_v8_0_nop_rlc_funcs = {
5323 .enter_safe_mode = gfx_v8_0_nop_enter_rlc_safe_mode,
5324 .exit_safe_mode = gfx_v8_0_nop_exit_rlc_safe_mode
5325};
5326
5327static void gfx_v8_0_update_medium_grain_clock_gating(struct amdgpu_device *adev,
5328 bool enable)
4316{ 5329{
4317 uint32_t temp, data; 5330 uint32_t temp, data;
4318 5331
5332 adev->gfx.rlc.funcs->enter_safe_mode(adev);
5333
4319 /* It is disabled by HW by default */ 5334 /* It is disabled by HW by default */
4320 if (enable) { 5335 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_GFX_MGCG)) {
4321 /* 1 - RLC memory Light sleep */ 5336 if (adev->cg_flags & AMD_CG_SUPPORT_GFX_MGLS) {
4322 temp = data = RREG32(mmRLC_MEM_SLP_CNTL); 5337 if (adev->cg_flags & AMD_CG_SUPPORT_GFX_RLC_LS) {
4323 data |= RLC_MEM_SLP_CNTL__RLC_MEM_LS_EN_MASK; 5338 /* 1 - RLC memory Light sleep */
4324 if (temp != data) 5339 temp = data = RREG32(mmRLC_MEM_SLP_CNTL);
4325 WREG32(mmRLC_MEM_SLP_CNTL, data); 5340 data |= RLC_MEM_SLP_CNTL__RLC_MEM_LS_EN_MASK;
5341 if (temp != data)
5342 WREG32(mmRLC_MEM_SLP_CNTL, data);
5343 }
4326 5344
4327 /* 2 - CP memory Light sleep */ 5345 if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CP_LS) {
4328 temp = data = RREG32(mmCP_MEM_SLP_CNTL); 5346 /* 2 - CP memory Light sleep */
4329 data |= CP_MEM_SLP_CNTL__CP_MEM_LS_EN_MASK; 5347 temp = data = RREG32(mmCP_MEM_SLP_CNTL);
4330 if (temp != data) 5348 data |= CP_MEM_SLP_CNTL__CP_MEM_LS_EN_MASK;
4331 WREG32(mmCP_MEM_SLP_CNTL, data); 5349 if (temp != data)
5350 WREG32(mmCP_MEM_SLP_CNTL, data);
5351 }
5352 }
4332 5353
4333 /* 3 - RLC_CGTT_MGCG_OVERRIDE */ 5354 /* 3 - RLC_CGTT_MGCG_OVERRIDE */
4334 temp = data = RREG32(mmRLC_CGTT_MGCG_OVERRIDE); 5355 temp = data = RREG32(mmRLC_CGTT_MGCG_OVERRIDE);
4335 data &= ~(RLC_CGTT_MGCG_OVERRIDE__CPF_MASK | 5356 if (adev->flags & AMD_IS_APU)
4336 RLC_CGTT_MGCG_OVERRIDE__RLC_MASK | 5357 data &= ~(RLC_CGTT_MGCG_OVERRIDE__CPF_MASK |
4337 RLC_CGTT_MGCG_OVERRIDE__MGCG_MASK | 5358 RLC_CGTT_MGCG_OVERRIDE__RLC_MASK |
4338 RLC_CGTT_MGCG_OVERRIDE__GRBM_MASK); 5359 RLC_CGTT_MGCG_OVERRIDE__MGCG_MASK);
5360 else
5361 data &= ~(RLC_CGTT_MGCG_OVERRIDE__CPF_MASK |
5362 RLC_CGTT_MGCG_OVERRIDE__RLC_MASK |
5363 RLC_CGTT_MGCG_OVERRIDE__MGCG_MASK |
5364 RLC_CGTT_MGCG_OVERRIDE__GRBM_MASK);
4339 5365
4340 if (temp != data) 5366 if (temp != data)
4341 WREG32(mmRLC_CGTT_MGCG_OVERRIDE, data); 5367 WREG32(mmRLC_CGTT_MGCG_OVERRIDE, data);
@@ -4344,19 +5370,23 @@ static void fiji_update_medium_grain_clock_gating(struct amdgpu_device *adev,
4344 gfx_v8_0_wait_for_rlc_serdes(adev); 5370 gfx_v8_0_wait_for_rlc_serdes(adev);
4345 5371
4346 /* 5 - clear mgcg override */ 5372 /* 5 - clear mgcg override */
4347 fiji_send_serdes_cmd(adev, BPM_REG_MGCG_OVERRIDE, CLE_BPM_SERDES_CMD); 5373 gfx_v8_0_send_serdes_cmd(adev, BPM_REG_MGCG_OVERRIDE, CLE_BPM_SERDES_CMD);
4348 5374
4349 /* 6 - Enable CGTS(Tree Shade) MGCG /MGLS */ 5375 if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGTS) {
4350 temp = data = RREG32(mmCGTS_SM_CTRL_REG); 5376 /* 6 - Enable CGTS(Tree Shade) MGCG /MGLS */
4351 data &= ~(CGTS_SM_CTRL_REG__SM_MODE_MASK); 5377 temp = data = RREG32(mmCGTS_SM_CTRL_REG);
4352 data |= (0x2 << CGTS_SM_CTRL_REG__SM_MODE__SHIFT); 5378 data &= ~(CGTS_SM_CTRL_REG__SM_MODE_MASK);
4353 data |= CGTS_SM_CTRL_REG__SM_MODE_ENABLE_MASK; 5379 data |= (0x2 << CGTS_SM_CTRL_REG__SM_MODE__SHIFT);
4354 data &= ~CGTS_SM_CTRL_REG__OVERRIDE_MASK; 5380 data |= CGTS_SM_CTRL_REG__SM_MODE_ENABLE_MASK;
4355 data &= ~CGTS_SM_CTRL_REG__LS_OVERRIDE_MASK; 5381 data &= ~CGTS_SM_CTRL_REG__OVERRIDE_MASK;
4356 data |= CGTS_SM_CTRL_REG__ON_MONITOR_ADD_EN_MASK; 5382 if ((adev->cg_flags & AMD_CG_SUPPORT_GFX_MGLS) &&
4357 data |= (0x96 << CGTS_SM_CTRL_REG__ON_MONITOR_ADD__SHIFT); 5383 (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGTS_LS))
4358 if (temp != data) 5384 data &= ~CGTS_SM_CTRL_REG__LS_OVERRIDE_MASK;
4359 WREG32(mmCGTS_SM_CTRL_REG, data); 5385 data |= CGTS_SM_CTRL_REG__ON_MONITOR_ADD_EN_MASK;
5386 data |= (0x96 << CGTS_SM_CTRL_REG__ON_MONITOR_ADD__SHIFT);
5387 if (temp != data)
5388 WREG32(mmCGTS_SM_CTRL_REG, data);
5389 }
4360 udelay(50); 5390 udelay(50);
4361 5391
4362 /* 7 - wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */ 5392 /* 7 - wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
@@ -4396,23 +5426,27 @@ static void fiji_update_medium_grain_clock_gating(struct amdgpu_device *adev,
4396 gfx_v8_0_wait_for_rlc_serdes(adev); 5426 gfx_v8_0_wait_for_rlc_serdes(adev);
4397 5427
4398 /* 6 - set mgcg override */ 5428 /* 6 - set mgcg override */
4399 fiji_send_serdes_cmd(adev, BPM_REG_MGCG_OVERRIDE, SET_BPM_SERDES_CMD); 5429 gfx_v8_0_send_serdes_cmd(adev, BPM_REG_MGCG_OVERRIDE, SET_BPM_SERDES_CMD);
4400 5430
4401 udelay(50); 5431 udelay(50);
4402 5432
4403 /* 7- wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */ 5433 /* 7- wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
4404 gfx_v8_0_wait_for_rlc_serdes(adev); 5434 gfx_v8_0_wait_for_rlc_serdes(adev);
4405 } 5435 }
5436
5437 adev->gfx.rlc.funcs->exit_safe_mode(adev);
4406} 5438}
4407 5439
4408static void fiji_update_coarse_grain_clock_gating(struct amdgpu_device *adev, 5440static void gfx_v8_0_update_coarse_grain_clock_gating(struct amdgpu_device *adev,
4409 bool enable) 5441 bool enable)
4410{ 5442{
4411 uint32_t temp, temp1, data, data1; 5443 uint32_t temp, temp1, data, data1;
4412 5444
4413 temp = data = RREG32(mmRLC_CGCG_CGLS_CTRL); 5445 temp = data = RREG32(mmRLC_CGCG_CGLS_CTRL);
4414 5446
4415 if (enable) { 5447 adev->gfx.rlc.funcs->enter_safe_mode(adev);
5448
5449 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGCG)) {
4416 /* 1 enable cntx_empty_int_enable/cntx_busy_int_enable/ 5450 /* 1 enable cntx_empty_int_enable/cntx_busy_int_enable/
4417 * Cmp_busy/GFX_Idle interrupts 5451 * Cmp_busy/GFX_Idle interrupts
4418 */ 5452 */
@@ -4427,25 +5461,29 @@ static void fiji_update_coarse_grain_clock_gating(struct amdgpu_device *adev,
4427 gfx_v8_0_wait_for_rlc_serdes(adev); 5461 gfx_v8_0_wait_for_rlc_serdes(adev);
4428 5462
4429 /* 3 - clear cgcg override */ 5463 /* 3 - clear cgcg override */
4430 fiji_send_serdes_cmd(adev, BPM_REG_CGCG_OVERRIDE, CLE_BPM_SERDES_CMD); 5464 gfx_v8_0_send_serdes_cmd(adev, BPM_REG_CGCG_OVERRIDE, CLE_BPM_SERDES_CMD);
4431 5465
4432 /* wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */ 5466 /* wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
4433 gfx_v8_0_wait_for_rlc_serdes(adev); 5467 gfx_v8_0_wait_for_rlc_serdes(adev);
4434 5468
4435 /* 4 - write cmd to set CGLS */ 5469 /* 4 - write cmd to set CGLS */
4436 fiji_send_serdes_cmd(adev, BPM_REG_CGLS_EN, SET_BPM_SERDES_CMD); 5470 gfx_v8_0_send_serdes_cmd(adev, BPM_REG_CGLS_EN, SET_BPM_SERDES_CMD);
4437 5471
4438 /* 5 - enable cgcg */ 5472 /* 5 - enable cgcg */
4439 data |= RLC_CGCG_CGLS_CTRL__CGCG_EN_MASK; 5473 data |= RLC_CGCG_CGLS_CTRL__CGCG_EN_MASK;
4440 5474
4441 /* enable cgls*/ 5475 if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGLS) {
4442 data |= RLC_CGCG_CGLS_CTRL__CGLS_EN_MASK; 5476 /* enable cgls*/
5477 data |= RLC_CGCG_CGLS_CTRL__CGLS_EN_MASK;
4443 5478
4444 temp1 = data1 = RREG32(mmRLC_CGTT_MGCG_OVERRIDE); 5479 temp1 = data1 = RREG32(mmRLC_CGTT_MGCG_OVERRIDE);
4445 data1 &= ~RLC_CGTT_MGCG_OVERRIDE__CGLS_MASK; 5480 data1 &= ~RLC_CGTT_MGCG_OVERRIDE__CGLS_MASK;
4446 5481
4447 if (temp1 != data1) 5482 if (temp1 != data1)
4448 WREG32(mmRLC_CGTT_MGCG_OVERRIDE, data1); 5483 WREG32(mmRLC_CGTT_MGCG_OVERRIDE, data1);
5484 } else {
5485 data &= ~RLC_CGCG_CGLS_CTRL__CGLS_EN_MASK;
5486 }
4449 5487
4450 if (temp != data) 5488 if (temp != data)
4451 WREG32(mmRLC_CGCG_CGLS_CTRL, data); 5489 WREG32(mmRLC_CGCG_CGLS_CTRL, data);
@@ -4470,36 +5508,38 @@ static void fiji_update_coarse_grain_clock_gating(struct amdgpu_device *adev,
4470 gfx_v8_0_wait_for_rlc_serdes(adev); 5508 gfx_v8_0_wait_for_rlc_serdes(adev);
4471 5509
4472 /* write cmd to Set CGCG Overrride */ 5510 /* write cmd to Set CGCG Overrride */
4473 fiji_send_serdes_cmd(adev, BPM_REG_CGCG_OVERRIDE, SET_BPM_SERDES_CMD); 5511 gfx_v8_0_send_serdes_cmd(adev, BPM_REG_CGCG_OVERRIDE, SET_BPM_SERDES_CMD);
4474 5512
4475 /* wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */ 5513 /* wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
4476 gfx_v8_0_wait_for_rlc_serdes(adev); 5514 gfx_v8_0_wait_for_rlc_serdes(adev);
4477 5515
4478 /* write cmd to Clear CGLS */ 5516 /* write cmd to Clear CGLS */
4479 fiji_send_serdes_cmd(adev, BPM_REG_CGLS_EN, CLE_BPM_SERDES_CMD); 5517 gfx_v8_0_send_serdes_cmd(adev, BPM_REG_CGLS_EN, CLE_BPM_SERDES_CMD);
4480 5518
4481 /* disable cgcg, cgls should be disabled too. */ 5519 /* disable cgcg, cgls should be disabled too. */
4482 data &= ~(RLC_CGCG_CGLS_CTRL__CGCG_EN_MASK | 5520 data &= ~(RLC_CGCG_CGLS_CTRL__CGCG_EN_MASK |
4483 RLC_CGCG_CGLS_CTRL__CGLS_EN_MASK); 5521 RLC_CGCG_CGLS_CTRL__CGLS_EN_MASK);
4484 if (temp != data) 5522 if (temp != data)
4485 WREG32(mmRLC_CGCG_CGLS_CTRL, data); 5523 WREG32(mmRLC_CGCG_CGLS_CTRL, data);
4486 } 5524 }
5525
5526 adev->gfx.rlc.funcs->exit_safe_mode(adev);
4487} 5527}
4488static int fiji_update_gfx_clock_gating(struct amdgpu_device *adev, 5528static int gfx_v8_0_update_gfx_clock_gating(struct amdgpu_device *adev,
4489 bool enable) 5529 bool enable)
4490{ 5530{
4491 if (enable) { 5531 if (enable) {
4492 /* CGCG/CGLS should be enabled after MGCG/MGLS/TS(CG/LS) 5532 /* CGCG/CGLS should be enabled after MGCG/MGLS/TS(CG/LS)
4493 * === MGCG + MGLS + TS(CG/LS) === 5533 * === MGCG + MGLS + TS(CG/LS) ===
4494 */ 5534 */
4495 fiji_update_medium_grain_clock_gating(adev, enable); 5535 gfx_v8_0_update_medium_grain_clock_gating(adev, enable);
4496 fiji_update_coarse_grain_clock_gating(adev, enable); 5536 gfx_v8_0_update_coarse_grain_clock_gating(adev, enable);
4497 } else { 5537 } else {
4498 /* CGCG/CGLS should be disabled before MGCG/MGLS/TS(CG/LS) 5538 /* CGCG/CGLS should be disabled before MGCG/MGLS/TS(CG/LS)
4499 * === CGCG + CGLS === 5539 * === CGCG + CGLS ===
4500 */ 5540 */
4501 fiji_update_coarse_grain_clock_gating(adev, enable); 5541 gfx_v8_0_update_coarse_grain_clock_gating(adev, enable);
4502 fiji_update_medium_grain_clock_gating(adev, enable); 5542 gfx_v8_0_update_medium_grain_clock_gating(adev, enable);
4503 } 5543 }
4504 return 0; 5544 return 0;
4505} 5545}
@@ -4511,8 +5551,10 @@ static int gfx_v8_0_set_clockgating_state(void *handle,
4511 5551
4512 switch (adev->asic_type) { 5552 switch (adev->asic_type) {
4513 case CHIP_FIJI: 5553 case CHIP_FIJI:
4514 fiji_update_gfx_clock_gating(adev, 5554 case CHIP_CARRIZO:
4515 state == AMD_CG_STATE_GATE ? true : false); 5555 case CHIP_STONEY:
5556 gfx_v8_0_update_gfx_clock_gating(adev,
5557 state == AMD_CG_STATE_GATE ? true : false);
4516 break; 5558 break;
4517 default: 5559 default:
4518 break; 5560 break;
@@ -5033,7 +6075,6 @@ const struct amd_ip_funcs gfx_v8_0_ip_funcs = {
5033 .is_idle = gfx_v8_0_is_idle, 6075 .is_idle = gfx_v8_0_is_idle,
5034 .wait_for_idle = gfx_v8_0_wait_for_idle, 6076 .wait_for_idle = gfx_v8_0_wait_for_idle,
5035 .soft_reset = gfx_v8_0_soft_reset, 6077 .soft_reset = gfx_v8_0_soft_reset,
5036 .print_status = gfx_v8_0_print_status,
5037 .set_clockgating_state = gfx_v8_0_set_clockgating_state, 6078 .set_clockgating_state = gfx_v8_0_set_clockgating_state,
5038 .set_powergating_state = gfx_v8_0_set_powergating_state, 6079 .set_powergating_state = gfx_v8_0_set_powergating_state,
5039}; 6080};
@@ -5112,6 +6153,22 @@ static void gfx_v8_0_set_irq_funcs(struct amdgpu_device *adev)
5112 adev->gfx.priv_inst_irq.funcs = &gfx_v8_0_priv_inst_irq_funcs; 6153 adev->gfx.priv_inst_irq.funcs = &gfx_v8_0_priv_inst_irq_funcs;
5113} 6154}
5114 6155
6156static void gfx_v8_0_set_rlc_funcs(struct amdgpu_device *adev)
6157{
6158 switch (adev->asic_type) {
6159 case CHIP_TOPAZ:
6160 case CHIP_STONEY:
6161 adev->gfx.rlc.funcs = &iceland_rlc_funcs;
6162 break;
6163 case CHIP_CARRIZO:
6164 adev->gfx.rlc.funcs = &cz_rlc_funcs;
6165 break;
6166 default:
6167 adev->gfx.rlc.funcs = &gfx_v8_0_nop_rlc_funcs;
6168 break;
6169 }
6170}
6171
5115static void gfx_v8_0_set_gds_init(struct amdgpu_device *adev) 6172static void gfx_v8_0_set_gds_init(struct amdgpu_device *adev)
5116{ 6173{
5117 /* init asci gds info */ 6174 /* init asci gds info */
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
index 05b0353d3880..3b620a8e8682 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
@@ -1114,114 +1114,6 @@ static int gmc_v7_0_wait_for_idle(void *handle)
1114 1114
1115} 1115}
1116 1116
1117static void gmc_v7_0_print_status(void *handle)
1118{
1119 int i, j;
1120 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1121
1122 dev_info(adev->dev, "GMC 8.x registers\n");
1123 dev_info(adev->dev, " SRBM_STATUS=0x%08X\n",
1124 RREG32(mmSRBM_STATUS));
1125 dev_info(adev->dev, " SRBM_STATUS2=0x%08X\n",
1126 RREG32(mmSRBM_STATUS2));
1127
1128 dev_info(adev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
1129 RREG32(mmVM_CONTEXT1_PROTECTION_FAULT_ADDR));
1130 dev_info(adev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
1131 RREG32(mmVM_CONTEXT1_PROTECTION_FAULT_STATUS));
1132 dev_info(adev->dev, " MC_VM_MX_L1_TLB_CNTL=0x%08X\n",
1133 RREG32(mmMC_VM_MX_L1_TLB_CNTL));
1134 dev_info(adev->dev, " VM_L2_CNTL=0x%08X\n",
1135 RREG32(mmVM_L2_CNTL));
1136 dev_info(adev->dev, " VM_L2_CNTL2=0x%08X\n",
1137 RREG32(mmVM_L2_CNTL2));
1138 dev_info(adev->dev, " VM_L2_CNTL3=0x%08X\n",
1139 RREG32(mmVM_L2_CNTL3));
1140 dev_info(adev->dev, " VM_CONTEXT0_PAGE_TABLE_START_ADDR=0x%08X\n",
1141 RREG32(mmVM_CONTEXT0_PAGE_TABLE_START_ADDR));
1142 dev_info(adev->dev, " VM_CONTEXT0_PAGE_TABLE_END_ADDR=0x%08X\n",
1143 RREG32(mmVM_CONTEXT0_PAGE_TABLE_END_ADDR));
1144 dev_info(adev->dev, " VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR=0x%08X\n",
1145 RREG32(mmVM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR));
1146 dev_info(adev->dev, " VM_CONTEXT0_CNTL2=0x%08X\n",
1147 RREG32(mmVM_CONTEXT0_CNTL2));
1148 dev_info(adev->dev, " VM_CONTEXT0_CNTL=0x%08X\n",
1149 RREG32(mmVM_CONTEXT0_CNTL));
1150 dev_info(adev->dev, " 0x15D4=0x%08X\n",
1151 RREG32(0x575));
1152 dev_info(adev->dev, " 0x15D8=0x%08X\n",
1153 RREG32(0x576));
1154 dev_info(adev->dev, " 0x15DC=0x%08X\n",
1155 RREG32(0x577));
1156 dev_info(adev->dev, " VM_CONTEXT1_PAGE_TABLE_START_ADDR=0x%08X\n",
1157 RREG32(mmVM_CONTEXT1_PAGE_TABLE_START_ADDR));
1158 dev_info(adev->dev, " VM_CONTEXT1_PAGE_TABLE_END_ADDR=0x%08X\n",
1159 RREG32(mmVM_CONTEXT1_PAGE_TABLE_END_ADDR));
1160 dev_info(adev->dev, " VM_CONTEXT1_PROTECTION_FAULT_DEFAULT_ADDR=0x%08X\n",
1161 RREG32(mmVM_CONTEXT1_PROTECTION_FAULT_DEFAULT_ADDR));
1162 dev_info(adev->dev, " VM_CONTEXT1_CNTL2=0x%08X\n",
1163 RREG32(mmVM_CONTEXT1_CNTL2));
1164 dev_info(adev->dev, " VM_CONTEXT1_CNTL=0x%08X\n",
1165 RREG32(mmVM_CONTEXT1_CNTL));
1166 for (i = 0; i < 16; i++) {
1167 if (i < 8)
1168 dev_info(adev->dev, " VM_CONTEXT%d_PAGE_TABLE_BASE_ADDR=0x%08X\n",
1169 i, RREG32(mmVM_CONTEXT0_PAGE_TABLE_BASE_ADDR + i));
1170 else
1171 dev_info(adev->dev, " VM_CONTEXT%d_PAGE_TABLE_BASE_ADDR=0x%08X\n",
1172 i, RREG32(mmVM_CONTEXT8_PAGE_TABLE_BASE_ADDR + i - 8));
1173 }
1174 dev_info(adev->dev, " MC_VM_SYSTEM_APERTURE_LOW_ADDR=0x%08X\n",
1175 RREG32(mmMC_VM_SYSTEM_APERTURE_LOW_ADDR));
1176 dev_info(adev->dev, " MC_VM_SYSTEM_APERTURE_HIGH_ADDR=0x%08X\n",
1177 RREG32(mmMC_VM_SYSTEM_APERTURE_HIGH_ADDR));
1178 dev_info(adev->dev, " MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR=0x%08X\n",
1179 RREG32(mmMC_VM_SYSTEM_APERTURE_DEFAULT_ADDR));
1180 dev_info(adev->dev, " MC_VM_FB_LOCATION=0x%08X\n",
1181 RREG32(mmMC_VM_FB_LOCATION));
1182 dev_info(adev->dev, " MC_VM_AGP_BASE=0x%08X\n",
1183 RREG32(mmMC_VM_AGP_BASE));
1184 dev_info(adev->dev, " MC_VM_AGP_TOP=0x%08X\n",
1185 RREG32(mmMC_VM_AGP_TOP));
1186 dev_info(adev->dev, " MC_VM_AGP_BOT=0x%08X\n",
1187 RREG32(mmMC_VM_AGP_BOT));
1188
1189 if (adev->asic_type == CHIP_KAVERI) {
1190 dev_info(adev->dev, " CHUB_CONTROL=0x%08X\n",
1191 RREG32(mmCHUB_CONTROL));
1192 }
1193
1194 dev_info(adev->dev, " HDP_REG_COHERENCY_FLUSH_CNTL=0x%08X\n",
1195 RREG32(mmHDP_REG_COHERENCY_FLUSH_CNTL));
1196 dev_info(adev->dev, " HDP_NONSURFACE_BASE=0x%08X\n",
1197 RREG32(mmHDP_NONSURFACE_BASE));
1198 dev_info(adev->dev, " HDP_NONSURFACE_INFO=0x%08X\n",
1199 RREG32(mmHDP_NONSURFACE_INFO));
1200 dev_info(adev->dev, " HDP_NONSURFACE_SIZE=0x%08X\n",
1201 RREG32(mmHDP_NONSURFACE_SIZE));
1202 dev_info(adev->dev, " HDP_MISC_CNTL=0x%08X\n",
1203 RREG32(mmHDP_MISC_CNTL));
1204 dev_info(adev->dev, " HDP_HOST_PATH_CNTL=0x%08X\n",
1205 RREG32(mmHDP_HOST_PATH_CNTL));
1206
1207 for (i = 0, j = 0; i < 32; i++, j += 0x6) {
1208 dev_info(adev->dev, " %d:\n", i);
1209 dev_info(adev->dev, " 0x%04X=0x%08X\n",
1210 0xb05 + j, RREG32(0xb05 + j));
1211 dev_info(adev->dev, " 0x%04X=0x%08X\n",
1212 0xb06 + j, RREG32(0xb06 + j));
1213 dev_info(adev->dev, " 0x%04X=0x%08X\n",
1214 0xb07 + j, RREG32(0xb07 + j));
1215 dev_info(adev->dev, " 0x%04X=0x%08X\n",
1216 0xb08 + j, RREG32(0xb08 + j));
1217 dev_info(adev->dev, " 0x%04X=0x%08X\n",
1218 0xb09 + j, RREG32(0xb09 + j));
1219 }
1220
1221 dev_info(adev->dev, " BIF_FB_EN=0x%08X\n",
1222 RREG32(mmBIF_FB_EN));
1223}
1224
1225static int gmc_v7_0_soft_reset(void *handle) 1117static int gmc_v7_0_soft_reset(void *handle)
1226{ 1118{
1227 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 1119 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
@@ -1241,8 +1133,6 @@ static int gmc_v7_0_soft_reset(void *handle)
1241 } 1133 }
1242 1134
1243 if (srbm_soft_reset) { 1135 if (srbm_soft_reset) {
1244 gmc_v7_0_print_status((void *)adev);
1245
1246 gmc_v7_0_mc_stop(adev, &save); 1136 gmc_v7_0_mc_stop(adev, &save);
1247 if (gmc_v7_0_wait_for_idle(adev)) { 1137 if (gmc_v7_0_wait_for_idle(adev)) {
1248 dev_warn(adev->dev, "Wait for GMC idle timed out !\n"); 1138 dev_warn(adev->dev, "Wait for GMC idle timed out !\n");
@@ -1266,8 +1156,6 @@ static int gmc_v7_0_soft_reset(void *handle)
1266 1156
1267 gmc_v7_0_mc_resume(adev, &save); 1157 gmc_v7_0_mc_resume(adev, &save);
1268 udelay(50); 1158 udelay(50);
1269
1270 gmc_v7_0_print_status((void *)adev);
1271 } 1159 }
1272 1160
1273 return 0; 1161 return 0;
@@ -1381,7 +1269,6 @@ const struct amd_ip_funcs gmc_v7_0_ip_funcs = {
1381 .is_idle = gmc_v7_0_is_idle, 1269 .is_idle = gmc_v7_0_is_idle,
1382 .wait_for_idle = gmc_v7_0_wait_for_idle, 1270 .wait_for_idle = gmc_v7_0_wait_for_idle,
1383 .soft_reset = gmc_v7_0_soft_reset, 1271 .soft_reset = gmc_v7_0_soft_reset,
1384 .print_status = gmc_v7_0_print_status,
1385 .set_clockgating_state = gmc_v7_0_set_clockgating_state, 1272 .set_clockgating_state = gmc_v7_0_set_clockgating_state,
1386 .set_powergating_state = gmc_v7_0_set_powergating_state, 1273 .set_powergating_state = gmc_v7_0_set_powergating_state,
1387}; 1274};
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
index 02deb3229405..c0de22f7311d 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
@@ -43,6 +43,8 @@ static void gmc_v8_0_set_gart_funcs(struct amdgpu_device *adev);
43static void gmc_v8_0_set_irq_funcs(struct amdgpu_device *adev); 43static void gmc_v8_0_set_irq_funcs(struct amdgpu_device *adev);
44 44
45MODULE_FIRMWARE("amdgpu/tonga_mc.bin"); 45MODULE_FIRMWARE("amdgpu/tonga_mc.bin");
46MODULE_FIRMWARE("amdgpu/polaris11_mc.bin");
47MODULE_FIRMWARE("amdgpu/polaris10_mc.bin");
46 48
47static const u32 golden_settings_tonga_a11[] = 49static const u32 golden_settings_tonga_a11[] =
48{ 50{
@@ -73,6 +75,23 @@ static const u32 fiji_mgcg_cgcg_init[] =
73 mmMC_MEM_POWER_LS, 0xffffffff, 0x00000104 75 mmMC_MEM_POWER_LS, 0xffffffff, 0x00000104
74}; 76};
75 77
78static const u32 golden_settings_polaris11_a11[] =
79{
80 mmVM_PRT_APERTURE0_LOW_ADDR, 0x0fffffff, 0x0fffffff,
81 mmVM_PRT_APERTURE1_LOW_ADDR, 0x0fffffff, 0x0fffffff,
82 mmVM_PRT_APERTURE2_LOW_ADDR, 0x0fffffff, 0x0fffffff,
83 mmVM_PRT_APERTURE3_LOW_ADDR, 0x0fffffff, 0x0fffffff
84};
85
86static const u32 golden_settings_polaris10_a11[] =
87{
88 mmMC_ARB_WTM_GRPWT_RD, 0x00000003, 0x00000000,
89 mmVM_PRT_APERTURE0_LOW_ADDR, 0x0fffffff, 0x0fffffff,
90 mmVM_PRT_APERTURE1_LOW_ADDR, 0x0fffffff, 0x0fffffff,
91 mmVM_PRT_APERTURE2_LOW_ADDR, 0x0fffffff, 0x0fffffff,
92 mmVM_PRT_APERTURE3_LOW_ADDR, 0x0fffffff, 0x0fffffff
93};
94
76static const u32 cz_mgcg_cgcg_init[] = 95static const u32 cz_mgcg_cgcg_init[] =
77{ 96{
78 mmMC_MEM_POWER_LS, 0xffffffff, 0x00000104 97 mmMC_MEM_POWER_LS, 0xffffffff, 0x00000104
@@ -103,6 +122,16 @@ static void gmc_v8_0_init_golden_registers(struct amdgpu_device *adev)
103 golden_settings_tonga_a11, 122 golden_settings_tonga_a11,
104 (const u32)ARRAY_SIZE(golden_settings_tonga_a11)); 123 (const u32)ARRAY_SIZE(golden_settings_tonga_a11));
105 break; 124 break;
125 case CHIP_POLARIS11:
126 amdgpu_program_register_sequence(adev,
127 golden_settings_polaris11_a11,
128 (const u32)ARRAY_SIZE(golden_settings_polaris11_a11));
129 break;
130 case CHIP_POLARIS10:
131 amdgpu_program_register_sequence(adev,
132 golden_settings_polaris10_a11,
133 (const u32)ARRAY_SIZE(golden_settings_polaris10_a11));
134 break;
106 case CHIP_CARRIZO: 135 case CHIP_CARRIZO:
107 amdgpu_program_register_sequence(adev, 136 amdgpu_program_register_sequence(adev,
108 cz_mgcg_cgcg_init, 137 cz_mgcg_cgcg_init,
@@ -209,6 +238,12 @@ static int gmc_v8_0_init_microcode(struct amdgpu_device *adev)
209 case CHIP_TONGA: 238 case CHIP_TONGA:
210 chip_name = "tonga"; 239 chip_name = "tonga";
211 break; 240 break;
241 case CHIP_POLARIS11:
242 chip_name = "polaris11";
243 break;
244 case CHIP_POLARIS10:
245 chip_name = "polaris10";
246 break;
212 case CHIP_FIJI: 247 case CHIP_FIJI:
213 case CHIP_CARRIZO: 248 case CHIP_CARRIZO:
214 case CHIP_STONEY: 249 case CHIP_STONEY:
@@ -1082,111 +1117,6 @@ static int gmc_v8_0_wait_for_idle(void *handle)
1082 1117
1083} 1118}
1084 1119
1085static void gmc_v8_0_print_status(void *handle)
1086{
1087 int i, j;
1088 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1089
1090 dev_info(adev->dev, "GMC 8.x registers\n");
1091 dev_info(adev->dev, " SRBM_STATUS=0x%08X\n",
1092 RREG32(mmSRBM_STATUS));
1093 dev_info(adev->dev, " SRBM_STATUS2=0x%08X\n",
1094 RREG32(mmSRBM_STATUS2));
1095
1096 dev_info(adev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
1097 RREG32(mmVM_CONTEXT1_PROTECTION_FAULT_ADDR));
1098 dev_info(adev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
1099 RREG32(mmVM_CONTEXT1_PROTECTION_FAULT_STATUS));
1100 dev_info(adev->dev, " MC_VM_MX_L1_TLB_CNTL=0x%08X\n",
1101 RREG32(mmMC_VM_MX_L1_TLB_CNTL));
1102 dev_info(adev->dev, " VM_L2_CNTL=0x%08X\n",
1103 RREG32(mmVM_L2_CNTL));
1104 dev_info(adev->dev, " VM_L2_CNTL2=0x%08X\n",
1105 RREG32(mmVM_L2_CNTL2));
1106 dev_info(adev->dev, " VM_L2_CNTL3=0x%08X\n",
1107 RREG32(mmVM_L2_CNTL3));
1108 dev_info(adev->dev, " VM_L2_CNTL4=0x%08X\n",
1109 RREG32(mmVM_L2_CNTL4));
1110 dev_info(adev->dev, " VM_CONTEXT0_PAGE_TABLE_START_ADDR=0x%08X\n",
1111 RREG32(mmVM_CONTEXT0_PAGE_TABLE_START_ADDR));
1112 dev_info(adev->dev, " VM_CONTEXT0_PAGE_TABLE_END_ADDR=0x%08X\n",
1113 RREG32(mmVM_CONTEXT0_PAGE_TABLE_END_ADDR));
1114 dev_info(adev->dev, " VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR=0x%08X\n",
1115 RREG32(mmVM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR));
1116 dev_info(adev->dev, " VM_CONTEXT0_CNTL2=0x%08X\n",
1117 RREG32(mmVM_CONTEXT0_CNTL2));
1118 dev_info(adev->dev, " VM_CONTEXT0_CNTL=0x%08X\n",
1119 RREG32(mmVM_CONTEXT0_CNTL));
1120 dev_info(adev->dev, " VM_L2_CONTEXT1_IDENTITY_APERTURE_LOW_ADDR=0x%08X\n",
1121 RREG32(mmVM_L2_CONTEXT1_IDENTITY_APERTURE_LOW_ADDR));
1122 dev_info(adev->dev, " VM_L2_CONTEXT1_IDENTITY_APERTURE_HIGH_ADDR=0x%08X\n",
1123 RREG32(mmVM_L2_CONTEXT1_IDENTITY_APERTURE_HIGH_ADDR));
1124 dev_info(adev->dev, " mmVM_L2_CONTEXT_IDENTITY_PHYSICAL_OFFSET=0x%08X\n",
1125 RREG32(mmVM_L2_CONTEXT_IDENTITY_PHYSICAL_OFFSET));
1126 dev_info(adev->dev, " VM_CONTEXT1_PAGE_TABLE_START_ADDR=0x%08X\n",
1127 RREG32(mmVM_CONTEXT1_PAGE_TABLE_START_ADDR));
1128 dev_info(adev->dev, " VM_CONTEXT1_PAGE_TABLE_END_ADDR=0x%08X\n",
1129 RREG32(mmVM_CONTEXT1_PAGE_TABLE_END_ADDR));
1130 dev_info(adev->dev, " VM_CONTEXT1_PROTECTION_FAULT_DEFAULT_ADDR=0x%08X\n",
1131 RREG32(mmVM_CONTEXT1_PROTECTION_FAULT_DEFAULT_ADDR));
1132 dev_info(adev->dev, " VM_CONTEXT1_CNTL2=0x%08X\n",
1133 RREG32(mmVM_CONTEXT1_CNTL2));
1134 dev_info(adev->dev, " VM_CONTEXT1_CNTL=0x%08X\n",
1135 RREG32(mmVM_CONTEXT1_CNTL));
1136 for (i = 0; i < 16; i++) {
1137 if (i < 8)
1138 dev_info(adev->dev, " VM_CONTEXT%d_PAGE_TABLE_BASE_ADDR=0x%08X\n",
1139 i, RREG32(mmVM_CONTEXT0_PAGE_TABLE_BASE_ADDR + i));
1140 else
1141 dev_info(adev->dev, " VM_CONTEXT%d_PAGE_TABLE_BASE_ADDR=0x%08X\n",
1142 i, RREG32(mmVM_CONTEXT8_PAGE_TABLE_BASE_ADDR + i - 8));
1143 }
1144 dev_info(adev->dev, " MC_VM_SYSTEM_APERTURE_LOW_ADDR=0x%08X\n",
1145 RREG32(mmMC_VM_SYSTEM_APERTURE_LOW_ADDR));
1146 dev_info(adev->dev, " MC_VM_SYSTEM_APERTURE_HIGH_ADDR=0x%08X\n",
1147 RREG32(mmMC_VM_SYSTEM_APERTURE_HIGH_ADDR));
1148 dev_info(adev->dev, " MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR=0x%08X\n",
1149 RREG32(mmMC_VM_SYSTEM_APERTURE_DEFAULT_ADDR));
1150 dev_info(adev->dev, " MC_VM_FB_LOCATION=0x%08X\n",
1151 RREG32(mmMC_VM_FB_LOCATION));
1152 dev_info(adev->dev, " MC_VM_AGP_BASE=0x%08X\n",
1153 RREG32(mmMC_VM_AGP_BASE));
1154 dev_info(adev->dev, " MC_VM_AGP_TOP=0x%08X\n",
1155 RREG32(mmMC_VM_AGP_TOP));
1156 dev_info(adev->dev, " MC_VM_AGP_BOT=0x%08X\n",
1157 RREG32(mmMC_VM_AGP_BOT));
1158
1159 dev_info(adev->dev, " HDP_REG_COHERENCY_FLUSH_CNTL=0x%08X\n",
1160 RREG32(mmHDP_REG_COHERENCY_FLUSH_CNTL));
1161 dev_info(adev->dev, " HDP_NONSURFACE_BASE=0x%08X\n",
1162 RREG32(mmHDP_NONSURFACE_BASE));
1163 dev_info(adev->dev, " HDP_NONSURFACE_INFO=0x%08X\n",
1164 RREG32(mmHDP_NONSURFACE_INFO));
1165 dev_info(adev->dev, " HDP_NONSURFACE_SIZE=0x%08X\n",
1166 RREG32(mmHDP_NONSURFACE_SIZE));
1167 dev_info(adev->dev, " HDP_MISC_CNTL=0x%08X\n",
1168 RREG32(mmHDP_MISC_CNTL));
1169 dev_info(adev->dev, " HDP_HOST_PATH_CNTL=0x%08X\n",
1170 RREG32(mmHDP_HOST_PATH_CNTL));
1171
1172 for (i = 0, j = 0; i < 32; i++, j += 0x6) {
1173 dev_info(adev->dev, " %d:\n", i);
1174 dev_info(adev->dev, " 0x%04X=0x%08X\n",
1175 0xb05 + j, RREG32(0xb05 + j));
1176 dev_info(adev->dev, " 0x%04X=0x%08X\n",
1177 0xb06 + j, RREG32(0xb06 + j));
1178 dev_info(adev->dev, " 0x%04X=0x%08X\n",
1179 0xb07 + j, RREG32(0xb07 + j));
1180 dev_info(adev->dev, " 0x%04X=0x%08X\n",
1181 0xb08 + j, RREG32(0xb08 + j));
1182 dev_info(adev->dev, " 0x%04X=0x%08X\n",
1183 0xb09 + j, RREG32(0xb09 + j));
1184 }
1185
1186 dev_info(adev->dev, " BIF_FB_EN=0x%08X\n",
1187 RREG32(mmBIF_FB_EN));
1188}
1189
1190static int gmc_v8_0_soft_reset(void *handle) 1120static int gmc_v8_0_soft_reset(void *handle)
1191{ 1121{
1192 struct amdgpu_mode_mc_save save; 1122 struct amdgpu_mode_mc_save save;
@@ -1206,8 +1136,6 @@ static int gmc_v8_0_soft_reset(void *handle)
1206 } 1136 }
1207 1137
1208 if (srbm_soft_reset) { 1138 if (srbm_soft_reset) {
1209 gmc_v8_0_print_status((void *)adev);
1210
1211 gmc_v8_0_mc_stop(adev, &save); 1139 gmc_v8_0_mc_stop(adev, &save);
1212 if (gmc_v8_0_wait_for_idle(adev)) { 1140 if (gmc_v8_0_wait_for_idle(adev)) {
1213 dev_warn(adev->dev, "Wait for GMC idle timed out !\n"); 1141 dev_warn(adev->dev, "Wait for GMC idle timed out !\n");
@@ -1231,8 +1159,6 @@ static int gmc_v8_0_soft_reset(void *handle)
1231 1159
1232 gmc_v8_0_mc_resume(adev, &save); 1160 gmc_v8_0_mc_resume(adev, &save);
1233 udelay(50); 1161 udelay(50);
1234
1235 gmc_v8_0_print_status((void *)adev);
1236 } 1162 }
1237 1163
1238 return 0; 1164 return 0;
@@ -1310,11 +1236,11 @@ static int gmc_v8_0_process_interrupt(struct amdgpu_device *adev,
1310} 1236}
1311 1237
1312static void fiji_update_mc_medium_grain_clock_gating(struct amdgpu_device *adev, 1238static void fiji_update_mc_medium_grain_clock_gating(struct amdgpu_device *adev,
1313 bool enable) 1239 bool enable)
1314{ 1240{
1315 uint32_t data; 1241 uint32_t data;
1316 1242
1317 if (enable) { 1243 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_MC_MGCG)) {
1318 data = RREG32(mmMC_HUB_MISC_HUB_CG); 1244 data = RREG32(mmMC_HUB_MISC_HUB_CG);
1319 data |= MC_HUB_MISC_HUB_CG__ENABLE_MASK; 1245 data |= MC_HUB_MISC_HUB_CG__ENABLE_MASK;
1320 WREG32(mmMC_HUB_MISC_HUB_CG, data); 1246 WREG32(mmMC_HUB_MISC_HUB_CG, data);
@@ -1390,11 +1316,11 @@ static void fiji_update_mc_medium_grain_clock_gating(struct amdgpu_device *adev,
1390} 1316}
1391 1317
1392static void fiji_update_mc_light_sleep(struct amdgpu_device *adev, 1318static void fiji_update_mc_light_sleep(struct amdgpu_device *adev,
1393 bool enable) 1319 bool enable)
1394{ 1320{
1395 uint32_t data; 1321 uint32_t data;
1396 1322
1397 if (enable) { 1323 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_MC_LS)) {
1398 data = RREG32(mmMC_HUB_MISC_HUB_CG); 1324 data = RREG32(mmMC_HUB_MISC_HUB_CG);
1399 data |= MC_HUB_MISC_HUB_CG__MEM_LS_ENABLE_MASK; 1325 data |= MC_HUB_MISC_HUB_CG__MEM_LS_ENABLE_MASK;
1400 WREG32(mmMC_HUB_MISC_HUB_CG, data); 1326 WREG32(mmMC_HUB_MISC_HUB_CG, data);
@@ -1505,7 +1431,6 @@ const struct amd_ip_funcs gmc_v8_0_ip_funcs = {
1505 .is_idle = gmc_v8_0_is_idle, 1431 .is_idle = gmc_v8_0_is_idle,
1506 .wait_for_idle = gmc_v8_0_wait_for_idle, 1432 .wait_for_idle = gmc_v8_0_wait_for_idle,
1507 .soft_reset = gmc_v8_0_soft_reset, 1433 .soft_reset = gmc_v8_0_soft_reset,
1508 .print_status = gmc_v8_0_print_status,
1509 .set_clockgating_state = gmc_v8_0_set_clockgating_state, 1434 .set_clockgating_state = gmc_v8_0_set_clockgating_state,
1510 .set_powergating_state = gmc_v8_0_set_powergating_state, 1435 .set_powergating_state = gmc_v8_0_set_powergating_state,
1511}; 1436};
diff --git a/drivers/gpu/drm/amd/amdgpu/iceland_dpm.c b/drivers/gpu/drm/amd/amdgpu/iceland_dpm.c
index 208d55f41c7f..57a96132a8a2 100644
--- a/drivers/gpu/drm/amd/amdgpu/iceland_dpm.c
+++ b/drivers/gpu/drm/amd/amdgpu/iceland_dpm.c
@@ -168,7 +168,6 @@ const struct amd_ip_funcs iceland_dpm_ip_funcs = {
168 .is_idle = NULL, 168 .is_idle = NULL,
169 .wait_for_idle = NULL, 169 .wait_for_idle = NULL,
170 .soft_reset = NULL, 170 .soft_reset = NULL,
171 .print_status = NULL,
172 .set_clockgating_state = iceland_dpm_set_clockgating_state, 171 .set_clockgating_state = iceland_dpm_set_clockgating_state,
173 .set_powergating_state = iceland_dpm_set_powergating_state, 172 .set_powergating_state = iceland_dpm_set_powergating_state,
174}; 173};
diff --git a/drivers/gpu/drm/amd/amdgpu/iceland_ih.c b/drivers/gpu/drm/amd/amdgpu/iceland_ih.c
index 679e7394a495..5c4001e2538e 100644
--- a/drivers/gpu/drm/amd/amdgpu/iceland_ih.c
+++ b/drivers/gpu/drm/amd/amdgpu/iceland_ih.c
@@ -351,35 +351,6 @@ static int iceland_ih_wait_for_idle(void *handle)
351 return -ETIMEDOUT; 351 return -ETIMEDOUT;
352} 352}
353 353
354static void iceland_ih_print_status(void *handle)
355{
356 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
357
358 dev_info(adev->dev, "ICELAND IH registers\n");
359 dev_info(adev->dev, " SRBM_STATUS=0x%08X\n",
360 RREG32(mmSRBM_STATUS));
361 dev_info(adev->dev, " SRBM_STATUS2=0x%08X\n",
362 RREG32(mmSRBM_STATUS2));
363 dev_info(adev->dev, " INTERRUPT_CNTL=0x%08X\n",
364 RREG32(mmINTERRUPT_CNTL));
365 dev_info(adev->dev, " INTERRUPT_CNTL2=0x%08X\n",
366 RREG32(mmINTERRUPT_CNTL2));
367 dev_info(adev->dev, " IH_CNTL=0x%08X\n",
368 RREG32(mmIH_CNTL));
369 dev_info(adev->dev, " IH_RB_CNTL=0x%08X\n",
370 RREG32(mmIH_RB_CNTL));
371 dev_info(adev->dev, " IH_RB_BASE=0x%08X\n",
372 RREG32(mmIH_RB_BASE));
373 dev_info(adev->dev, " IH_RB_WPTR_ADDR_LO=0x%08X\n",
374 RREG32(mmIH_RB_WPTR_ADDR_LO));
375 dev_info(adev->dev, " IH_RB_WPTR_ADDR_HI=0x%08X\n",
376 RREG32(mmIH_RB_WPTR_ADDR_HI));
377 dev_info(adev->dev, " IH_RB_RPTR=0x%08X\n",
378 RREG32(mmIH_RB_RPTR));
379 dev_info(adev->dev, " IH_RB_WPTR=0x%08X\n",
380 RREG32(mmIH_RB_WPTR));
381}
382
383static int iceland_ih_soft_reset(void *handle) 354static int iceland_ih_soft_reset(void *handle)
384{ 355{
385 u32 srbm_soft_reset = 0; 356 u32 srbm_soft_reset = 0;
@@ -391,8 +362,6 @@ static int iceland_ih_soft_reset(void *handle)
391 SOFT_RESET_IH, 1); 362 SOFT_RESET_IH, 1);
392 363
393 if (srbm_soft_reset) { 364 if (srbm_soft_reset) {
394 iceland_ih_print_status((void *)adev);
395
396 tmp = RREG32(mmSRBM_SOFT_RESET); 365 tmp = RREG32(mmSRBM_SOFT_RESET);
397 tmp |= srbm_soft_reset; 366 tmp |= srbm_soft_reset;
398 dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp); 367 dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
@@ -407,8 +376,6 @@ static int iceland_ih_soft_reset(void *handle)
407 376
408 /* Wait a little for things to settle down */ 377 /* Wait a little for things to settle down */
409 udelay(50); 378 udelay(50);
410
411 iceland_ih_print_status((void *)adev);
412 } 379 }
413 380
414 return 0; 381 return 0;
@@ -438,7 +405,6 @@ const struct amd_ip_funcs iceland_ih_ip_funcs = {
438 .is_idle = iceland_ih_is_idle, 405 .is_idle = iceland_ih_is_idle,
439 .wait_for_idle = iceland_ih_wait_for_idle, 406 .wait_for_idle = iceland_ih_wait_for_idle,
440 .soft_reset = iceland_ih_soft_reset, 407 .soft_reset = iceland_ih_soft_reset,
441 .print_status = iceland_ih_print_status,
442 .set_clockgating_state = iceland_ih_set_clockgating_state, 408 .set_clockgating_state = iceland_ih_set_clockgating_state,
443 .set_powergating_state = iceland_ih_set_powergating_state, 409 .set_powergating_state = iceland_ih_set_powergating_state,
444}; 410};
diff --git a/drivers/gpu/drm/amd/amdgpu/kv_dpm.c b/drivers/gpu/drm/amd/amdgpu/kv_dpm.c
index 654d76723bc3..4bd1e551cccd 100644
--- a/drivers/gpu/drm/amd/amdgpu/kv_dpm.c
+++ b/drivers/gpu/drm/amd/amdgpu/kv_dpm.c
@@ -3147,62 +3147,6 @@ static int kv_dpm_wait_for_idle(void *handle)
3147 return 0; 3147 return 0;
3148} 3148}
3149 3149
3150static void kv_dpm_print_status(void *handle)
3151{
3152 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
3153
3154 dev_info(adev->dev, "KV/KB DPM registers\n");
3155 dev_info(adev->dev, " DIDT_SQ_CTRL0=0x%08X\n",
3156 RREG32_DIDT(ixDIDT_SQ_CTRL0));
3157 dev_info(adev->dev, " DIDT_DB_CTRL0=0x%08X\n",
3158 RREG32_DIDT(ixDIDT_DB_CTRL0));
3159 dev_info(adev->dev, " DIDT_TD_CTRL0=0x%08X\n",
3160 RREG32_DIDT(ixDIDT_TD_CTRL0));
3161 dev_info(adev->dev, " DIDT_TCP_CTRL0=0x%08X\n",
3162 RREG32_DIDT(ixDIDT_TCP_CTRL0));
3163 dev_info(adev->dev, " LCAC_SX0_OVR_SEL=0x%08X\n",
3164 RREG32_SMC(ixLCAC_SX0_OVR_SEL));
3165 dev_info(adev->dev, " LCAC_SX0_OVR_VAL=0x%08X\n",
3166 RREG32_SMC(ixLCAC_SX0_OVR_VAL));
3167 dev_info(adev->dev, " LCAC_MC0_OVR_SEL=0x%08X\n",
3168 RREG32_SMC(ixLCAC_MC0_OVR_SEL));
3169 dev_info(adev->dev, " LCAC_MC0_OVR_VAL=0x%08X\n",
3170 RREG32_SMC(ixLCAC_MC0_OVR_VAL));
3171 dev_info(adev->dev, " LCAC_MC1_OVR_SEL=0x%08X\n",
3172 RREG32_SMC(ixLCAC_MC1_OVR_SEL));
3173 dev_info(adev->dev, " LCAC_MC1_OVR_VAL=0x%08X\n",
3174 RREG32_SMC(ixLCAC_MC1_OVR_VAL));
3175 dev_info(adev->dev, " LCAC_MC2_OVR_SEL=0x%08X\n",
3176 RREG32_SMC(ixLCAC_MC2_OVR_SEL));
3177 dev_info(adev->dev, " LCAC_MC2_OVR_VAL=0x%08X\n",
3178 RREG32_SMC(ixLCAC_MC2_OVR_VAL));
3179 dev_info(adev->dev, " LCAC_MC3_OVR_SEL=0x%08X\n",
3180 RREG32_SMC(ixLCAC_MC3_OVR_SEL));
3181 dev_info(adev->dev, " LCAC_MC3_OVR_VAL=0x%08X\n",
3182 RREG32_SMC(ixLCAC_MC3_OVR_VAL));
3183 dev_info(adev->dev, " LCAC_CPL_OVR_SEL=0x%08X\n",
3184 RREG32_SMC(ixLCAC_CPL_OVR_SEL));
3185 dev_info(adev->dev, " LCAC_CPL_OVR_VAL=0x%08X\n",
3186 RREG32_SMC(ixLCAC_CPL_OVR_VAL));
3187 dev_info(adev->dev, " CG_FREQ_TRAN_VOTING_0=0x%08X\n",
3188 RREG32_SMC(ixCG_FREQ_TRAN_VOTING_0));
3189 dev_info(adev->dev, " GENERAL_PWRMGT=0x%08X\n",
3190 RREG32_SMC(ixGENERAL_PWRMGT));
3191 dev_info(adev->dev, " SCLK_PWRMGT_CNTL=0x%08X\n",
3192 RREG32_SMC(ixSCLK_PWRMGT_CNTL));
3193 dev_info(adev->dev, " SMC_MESSAGE_0=0x%08X\n",
3194 RREG32(mmSMC_MESSAGE_0));
3195 dev_info(adev->dev, " SMC_RESP_0=0x%08X\n",
3196 RREG32(mmSMC_RESP_0));
3197 dev_info(adev->dev, " SMC_MSG_ARG_0=0x%08X\n",
3198 RREG32(mmSMC_MSG_ARG_0));
3199 dev_info(adev->dev, " SMC_IND_INDEX_0=0x%08X\n",
3200 RREG32(mmSMC_IND_INDEX_0));
3201 dev_info(adev->dev, " SMC_IND_DATA_0=0x%08X\n",
3202 RREG32(mmSMC_IND_DATA_0));
3203 dev_info(adev->dev, " SMC_IND_ACCESS_CNTL=0x%08X\n",
3204 RREG32(mmSMC_IND_ACCESS_CNTL));
3205}
3206 3150
3207static int kv_dpm_soft_reset(void *handle) 3151static int kv_dpm_soft_reset(void *handle)
3208{ 3152{
@@ -3311,7 +3255,6 @@ const struct amd_ip_funcs kv_dpm_ip_funcs = {
3311 .is_idle = kv_dpm_is_idle, 3255 .is_idle = kv_dpm_is_idle,
3312 .wait_for_idle = kv_dpm_wait_for_idle, 3256 .wait_for_idle = kv_dpm_wait_for_idle,
3313 .soft_reset = kv_dpm_soft_reset, 3257 .soft_reset = kv_dpm_soft_reset,
3314 .print_status = kv_dpm_print_status,
3315 .set_clockgating_state = kv_dpm_set_clockgating_state, 3258 .set_clockgating_state = kv_dpm_set_clockgating_state,
3316 .set_powergating_state = kv_dpm_set_powergating_state, 3259 .set_powergating_state = kv_dpm_set_powergating_state,
3317}; 3260};
diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c b/drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c
index 6e0a86a563f3..e6d3544fda06 100644
--- a/drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c
+++ b/drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c
@@ -990,7 +990,7 @@ static int sdma_v2_4_sw_init(void *handle)
990 ring->ring_obj = NULL; 990 ring->ring_obj = NULL;
991 ring->use_doorbell = false; 991 ring->use_doorbell = false;
992 sprintf(ring->name, "sdma%d", i); 992 sprintf(ring->name, "sdma%d", i);
993 r = amdgpu_ring_init(adev, ring, 256 * 1024, 993 r = amdgpu_ring_init(adev, ring, 1024,
994 SDMA_PKT_NOP_HEADER_OP(SDMA_OP_NOP), 0xf, 994 SDMA_PKT_NOP_HEADER_OP(SDMA_OP_NOP), 0xf,
995 &adev->sdma.trap_irq, 995 &adev->sdma.trap_irq,
996 (i == 0) ? 996 (i == 0) ?
@@ -1080,55 +1080,6 @@ static int sdma_v2_4_wait_for_idle(void *handle)
1080 return -ETIMEDOUT; 1080 return -ETIMEDOUT;
1081} 1081}
1082 1082
1083static void sdma_v2_4_print_status(void *handle)
1084{
1085 int i, j;
1086 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1087
1088 dev_info(adev->dev, "VI SDMA registers\n");
1089 dev_info(adev->dev, " SRBM_STATUS2=0x%08X\n",
1090 RREG32(mmSRBM_STATUS2));
1091 for (i = 0; i < adev->sdma.num_instances; i++) {
1092 dev_info(adev->dev, " SDMA%d_STATUS_REG=0x%08X\n",
1093 i, RREG32(mmSDMA0_STATUS_REG + sdma_offsets[i]));
1094 dev_info(adev->dev, " SDMA%d_F32_CNTL=0x%08X\n",
1095 i, RREG32(mmSDMA0_F32_CNTL + sdma_offsets[i]));
1096 dev_info(adev->dev, " SDMA%d_CNTL=0x%08X\n",
1097 i, RREG32(mmSDMA0_CNTL + sdma_offsets[i]));
1098 dev_info(adev->dev, " SDMA%d_SEM_WAIT_FAIL_TIMER_CNTL=0x%08X\n",
1099 i, RREG32(mmSDMA0_SEM_WAIT_FAIL_TIMER_CNTL + sdma_offsets[i]));
1100 dev_info(adev->dev, " SDMA%d_GFX_IB_CNTL=0x%08X\n",
1101 i, RREG32(mmSDMA0_GFX_IB_CNTL + sdma_offsets[i]));
1102 dev_info(adev->dev, " SDMA%d_GFX_RB_CNTL=0x%08X\n",
1103 i, RREG32(mmSDMA0_GFX_RB_CNTL + sdma_offsets[i]));
1104 dev_info(adev->dev, " SDMA%d_GFX_RB_RPTR=0x%08X\n",
1105 i, RREG32(mmSDMA0_GFX_RB_RPTR + sdma_offsets[i]));
1106 dev_info(adev->dev, " SDMA%d_GFX_RB_WPTR=0x%08X\n",
1107 i, RREG32(mmSDMA0_GFX_RB_WPTR + sdma_offsets[i]));
1108 dev_info(adev->dev, " SDMA%d_GFX_RB_RPTR_ADDR_HI=0x%08X\n",
1109 i, RREG32(mmSDMA0_GFX_RB_RPTR_ADDR_HI + sdma_offsets[i]));
1110 dev_info(adev->dev, " SDMA%d_GFX_RB_RPTR_ADDR_LO=0x%08X\n",
1111 i, RREG32(mmSDMA0_GFX_RB_RPTR_ADDR_LO + sdma_offsets[i]));
1112 dev_info(adev->dev, " SDMA%d_GFX_RB_BASE=0x%08X\n",
1113 i, RREG32(mmSDMA0_GFX_RB_BASE + sdma_offsets[i]));
1114 dev_info(adev->dev, " SDMA%d_GFX_RB_BASE_HI=0x%08X\n",
1115 i, RREG32(mmSDMA0_GFX_RB_BASE_HI + sdma_offsets[i]));
1116 dev_info(adev->dev, " SDMA%d_TILING_CONFIG=0x%08X\n",
1117 i, RREG32(mmSDMA0_TILING_CONFIG + sdma_offsets[i]));
1118 mutex_lock(&adev->srbm_mutex);
1119 for (j = 0; j < 16; j++) {
1120 vi_srbm_select(adev, 0, 0, 0, j);
1121 dev_info(adev->dev, " VM %d:\n", j);
1122 dev_info(adev->dev, " SDMA%d_GFX_VIRTUAL_ADDR=0x%08X\n",
1123 i, RREG32(mmSDMA0_GFX_VIRTUAL_ADDR + sdma_offsets[i]));
1124 dev_info(adev->dev, " SDMA%d_GFX_APE1_CNTL=0x%08X\n",
1125 i, RREG32(mmSDMA0_GFX_APE1_CNTL + sdma_offsets[i]));
1126 }
1127 vi_srbm_select(adev, 0, 0, 0, 0);
1128 mutex_unlock(&adev->srbm_mutex);
1129 }
1130}
1131
1132static int sdma_v2_4_soft_reset(void *handle) 1083static int sdma_v2_4_soft_reset(void *handle)
1133{ 1084{
1134 u32 srbm_soft_reset = 0; 1085 u32 srbm_soft_reset = 0;
@@ -1151,8 +1102,6 @@ static int sdma_v2_4_soft_reset(void *handle)
1151 } 1102 }
1152 1103
1153 if (srbm_soft_reset) { 1104 if (srbm_soft_reset) {
1154 sdma_v2_4_print_status((void *)adev);
1155
1156 tmp = RREG32(mmSRBM_SOFT_RESET); 1105 tmp = RREG32(mmSRBM_SOFT_RESET);
1157 tmp |= srbm_soft_reset; 1106 tmp |= srbm_soft_reset;
1158 dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp); 1107 dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
@@ -1167,8 +1116,6 @@ static int sdma_v2_4_soft_reset(void *handle)
1167 1116
1168 /* Wait a little for things to settle down */ 1117 /* Wait a little for things to settle down */
1169 udelay(50); 1118 udelay(50);
1170
1171 sdma_v2_4_print_status((void *)adev);
1172 } 1119 }
1173 1120
1174 return 0; 1121 return 0;
@@ -1294,7 +1241,6 @@ const struct amd_ip_funcs sdma_v2_4_ip_funcs = {
1294 .is_idle = sdma_v2_4_is_idle, 1241 .is_idle = sdma_v2_4_is_idle,
1295 .wait_for_idle = sdma_v2_4_wait_for_idle, 1242 .wait_for_idle = sdma_v2_4_wait_for_idle,
1296 .soft_reset = sdma_v2_4_soft_reset, 1243 .soft_reset = sdma_v2_4_soft_reset,
1297 .print_status = sdma_v2_4_print_status,
1298 .set_clockgating_state = sdma_v2_4_set_clockgating_state, 1244 .set_clockgating_state = sdma_v2_4_set_clockgating_state,
1299 .set_powergating_state = sdma_v2_4_set_powergating_state, 1245 .set_powergating_state = sdma_v2_4_set_powergating_state,
1300}; 1246};
diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c b/drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c
index 8c8ca98dd129..00b43700c956 100644
--- a/drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c
@@ -56,6 +56,11 @@ MODULE_FIRMWARE("amdgpu/carrizo_sdma1.bin");
56MODULE_FIRMWARE("amdgpu/fiji_sdma.bin"); 56MODULE_FIRMWARE("amdgpu/fiji_sdma.bin");
57MODULE_FIRMWARE("amdgpu/fiji_sdma1.bin"); 57MODULE_FIRMWARE("amdgpu/fiji_sdma1.bin");
58MODULE_FIRMWARE("amdgpu/stoney_sdma.bin"); 58MODULE_FIRMWARE("amdgpu/stoney_sdma.bin");
59MODULE_FIRMWARE("amdgpu/polaris10_sdma.bin");
60MODULE_FIRMWARE("amdgpu/polaris10_sdma1.bin");
61MODULE_FIRMWARE("amdgpu/polaris11_sdma.bin");
62MODULE_FIRMWARE("amdgpu/polaris11_sdma1.bin");
63
59 64
60static const u32 sdma_offsets[SDMA_MAX_INSTANCE] = 65static const u32 sdma_offsets[SDMA_MAX_INSTANCE] =
61{ 66{
@@ -101,6 +106,32 @@ static const u32 fiji_mgcg_cgcg_init[] =
101 mmSDMA1_CLK_CTRL, 0xff000ff0, 0x00000100 106 mmSDMA1_CLK_CTRL, 0xff000ff0, 0x00000100
102}; 107};
103 108
109static const u32 golden_settings_polaris11_a11[] =
110{
111 mmSDMA0_CHICKEN_BITS, 0xfc910007, 0x00810007,
112 mmSDMA0_GFX_IB_CNTL, 0x800f0111, 0x00000100,
113 mmSDMA0_RLC0_IB_CNTL, 0x800f0111, 0x00000100,
114 mmSDMA0_RLC1_IB_CNTL, 0x800f0111, 0x00000100,
115 mmSDMA1_CHICKEN_BITS, 0xfc910007, 0x00810007,
116 mmSDMA1_GFX_IB_CNTL, 0x800f0111, 0x00000100,
117 mmSDMA1_RLC0_IB_CNTL, 0x800f0111, 0x00000100,
118 mmSDMA1_RLC1_IB_CNTL, 0x800f0111, 0x00000100,
119};
120
121static const u32 golden_settings_polaris10_a11[] =
122{
123 mmSDMA0_CHICKEN_BITS, 0xfc910007, 0x00810007,
124 mmSDMA0_CLK_CTRL, 0xff000fff, 0x00000000,
125 mmSDMA0_GFX_IB_CNTL, 0x800f0111, 0x00000100,
126 mmSDMA0_RLC0_IB_CNTL, 0x800f0111, 0x00000100,
127 mmSDMA0_RLC1_IB_CNTL, 0x800f0111, 0x00000100,
128 mmSDMA1_CHICKEN_BITS, 0xfc910007, 0x00810007,
129 mmSDMA1_CLK_CTRL, 0xff000fff, 0x00000000,
130 mmSDMA1_GFX_IB_CNTL, 0x800f0111, 0x00000100,
131 mmSDMA1_RLC0_IB_CNTL, 0x800f0111, 0x00000100,
132 mmSDMA1_RLC1_IB_CNTL, 0x800f0111, 0x00000100,
133};
134
104static const u32 cz_golden_settings_a11[] = 135static const u32 cz_golden_settings_a11[] =
105{ 136{
106 mmSDMA0_CHICKEN_BITS, 0xfc910007, 0x00810007, 137 mmSDMA0_CHICKEN_BITS, 0xfc910007, 0x00810007,
@@ -172,6 +203,16 @@ static void sdma_v3_0_init_golden_registers(struct amdgpu_device *adev)
172 golden_settings_tonga_a11, 203 golden_settings_tonga_a11,
173 (const u32)ARRAY_SIZE(golden_settings_tonga_a11)); 204 (const u32)ARRAY_SIZE(golden_settings_tonga_a11));
174 break; 205 break;
206 case CHIP_POLARIS11:
207 amdgpu_program_register_sequence(adev,
208 golden_settings_polaris11_a11,
209 (const u32)ARRAY_SIZE(golden_settings_polaris11_a11));
210 break;
211 case CHIP_POLARIS10:
212 amdgpu_program_register_sequence(adev,
213 golden_settings_polaris10_a11,
214 (const u32)ARRAY_SIZE(golden_settings_polaris10_a11));
215 break;
175 case CHIP_CARRIZO: 216 case CHIP_CARRIZO:
176 amdgpu_program_register_sequence(adev, 217 amdgpu_program_register_sequence(adev,
177 cz_mgcg_cgcg_init, 218 cz_mgcg_cgcg_init,
@@ -220,6 +261,12 @@ static int sdma_v3_0_init_microcode(struct amdgpu_device *adev)
220 case CHIP_FIJI: 261 case CHIP_FIJI:
221 chip_name = "fiji"; 262 chip_name = "fiji";
222 break; 263 break;
264 case CHIP_POLARIS11:
265 chip_name = "polaris11";
266 break;
267 case CHIP_POLARIS10:
268 chip_name = "polaris10";
269 break;
223 case CHIP_CARRIZO: 270 case CHIP_CARRIZO:
224 chip_name = "carrizo"; 271 chip_name = "carrizo";
225 break; 272 break;
@@ -452,6 +499,31 @@ static void sdma_v3_0_ring_emit_fence(struct amdgpu_ring *ring, u64 addr, u64 se
452 amdgpu_ring_write(ring, SDMA_PKT_TRAP_INT_CONTEXT_INT_CONTEXT(0)); 499 amdgpu_ring_write(ring, SDMA_PKT_TRAP_INT_CONTEXT_INT_CONTEXT(0));
453} 500}
454 501
502unsigned init_cond_exec(struct amdgpu_ring *ring)
503{
504 unsigned ret;
505 amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_COND_EXE));
506 amdgpu_ring_write(ring, lower_32_bits(ring->cond_exe_gpu_addr));
507 amdgpu_ring_write(ring, upper_32_bits(ring->cond_exe_gpu_addr));
508 amdgpu_ring_write(ring, 1);
509 ret = ring->wptr;/* this is the offset we need patch later */
510 amdgpu_ring_write(ring, 0x55aa55aa);/* insert dummy here and patch it later */
511 return ret;
512}
513
514void patch_cond_exec(struct amdgpu_ring *ring, unsigned offset)
515{
516 unsigned cur;
517 BUG_ON(ring->ring[offset] != 0x55aa55aa);
518
519 cur = ring->wptr - 1;
520 if (likely(cur > offset))
521 ring->ring[offset] = cur - offset;
522 else
523 ring->ring[offset] = (ring->ring_size>>2) - offset + cur;
524}
525
526
455/** 527/**
456 * sdma_v3_0_gfx_stop - stop the gfx async dma engines 528 * sdma_v3_0_gfx_stop - stop the gfx async dma engines
457 * 529 *
@@ -1151,7 +1223,7 @@ static int sdma_v3_0_sw_init(void *handle)
1151 AMDGPU_DOORBELL_sDMA_ENGINE0 : AMDGPU_DOORBELL_sDMA_ENGINE1; 1223 AMDGPU_DOORBELL_sDMA_ENGINE0 : AMDGPU_DOORBELL_sDMA_ENGINE1;
1152 1224
1153 sprintf(ring->name, "sdma%d", i); 1225 sprintf(ring->name, "sdma%d", i);
1154 r = amdgpu_ring_init(adev, ring, 256 * 1024, 1226 r = amdgpu_ring_init(adev, ring, 1024,
1155 SDMA_PKT_NOP_HEADER_OP(SDMA_OP_NOP), 0xf, 1227 SDMA_PKT_NOP_HEADER_OP(SDMA_OP_NOP), 0xf,
1156 &adev->sdma.trap_irq, 1228 &adev->sdma.trap_irq,
1157 (i == 0) ? 1229 (i == 0) ?
@@ -1242,57 +1314,6 @@ static int sdma_v3_0_wait_for_idle(void *handle)
1242 return -ETIMEDOUT; 1314 return -ETIMEDOUT;
1243} 1315}
1244 1316
1245static void sdma_v3_0_print_status(void *handle)
1246{
1247 int i, j;
1248 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1249
1250 dev_info(adev->dev, "VI SDMA registers\n");
1251 dev_info(adev->dev, " SRBM_STATUS2=0x%08X\n",
1252 RREG32(mmSRBM_STATUS2));
1253 for (i = 0; i < adev->sdma.num_instances; i++) {
1254 dev_info(adev->dev, " SDMA%d_STATUS_REG=0x%08X\n",
1255 i, RREG32(mmSDMA0_STATUS_REG + sdma_offsets[i]));
1256 dev_info(adev->dev, " SDMA%d_F32_CNTL=0x%08X\n",
1257 i, RREG32(mmSDMA0_F32_CNTL + sdma_offsets[i]));
1258 dev_info(adev->dev, " SDMA%d_CNTL=0x%08X\n",
1259 i, RREG32(mmSDMA0_CNTL + sdma_offsets[i]));
1260 dev_info(adev->dev, " SDMA%d_SEM_WAIT_FAIL_TIMER_CNTL=0x%08X\n",
1261 i, RREG32(mmSDMA0_SEM_WAIT_FAIL_TIMER_CNTL + sdma_offsets[i]));
1262 dev_info(adev->dev, " SDMA%d_GFX_IB_CNTL=0x%08X\n",
1263 i, RREG32(mmSDMA0_GFX_IB_CNTL + sdma_offsets[i]));
1264 dev_info(adev->dev, " SDMA%d_GFX_RB_CNTL=0x%08X\n",
1265 i, RREG32(mmSDMA0_GFX_RB_CNTL + sdma_offsets[i]));
1266 dev_info(adev->dev, " SDMA%d_GFX_RB_RPTR=0x%08X\n",
1267 i, RREG32(mmSDMA0_GFX_RB_RPTR + sdma_offsets[i]));
1268 dev_info(adev->dev, " SDMA%d_GFX_RB_WPTR=0x%08X\n",
1269 i, RREG32(mmSDMA0_GFX_RB_WPTR + sdma_offsets[i]));
1270 dev_info(adev->dev, " SDMA%d_GFX_RB_RPTR_ADDR_HI=0x%08X\n",
1271 i, RREG32(mmSDMA0_GFX_RB_RPTR_ADDR_HI + sdma_offsets[i]));
1272 dev_info(adev->dev, " SDMA%d_GFX_RB_RPTR_ADDR_LO=0x%08X\n",
1273 i, RREG32(mmSDMA0_GFX_RB_RPTR_ADDR_LO + sdma_offsets[i]));
1274 dev_info(adev->dev, " SDMA%d_GFX_RB_BASE=0x%08X\n",
1275 i, RREG32(mmSDMA0_GFX_RB_BASE + sdma_offsets[i]));
1276 dev_info(adev->dev, " SDMA%d_GFX_RB_BASE_HI=0x%08X\n",
1277 i, RREG32(mmSDMA0_GFX_RB_BASE_HI + sdma_offsets[i]));
1278 dev_info(adev->dev, " SDMA%d_GFX_DOORBELL=0x%08X\n",
1279 i, RREG32(mmSDMA0_GFX_DOORBELL + sdma_offsets[i]));
1280 dev_info(adev->dev, " SDMA%d_TILING_CONFIG=0x%08X\n",
1281 i, RREG32(mmSDMA0_TILING_CONFIG + sdma_offsets[i]));
1282 mutex_lock(&adev->srbm_mutex);
1283 for (j = 0; j < 16; j++) {
1284 vi_srbm_select(adev, 0, 0, 0, j);
1285 dev_info(adev->dev, " VM %d:\n", j);
1286 dev_info(adev->dev, " SDMA%d_GFX_VIRTUAL_ADDR=0x%08X\n",
1287 i, RREG32(mmSDMA0_GFX_VIRTUAL_ADDR + sdma_offsets[i]));
1288 dev_info(adev->dev, " SDMA%d_GFX_APE1_CNTL=0x%08X\n",
1289 i, RREG32(mmSDMA0_GFX_APE1_CNTL + sdma_offsets[i]));
1290 }
1291 vi_srbm_select(adev, 0, 0, 0, 0);
1292 mutex_unlock(&adev->srbm_mutex);
1293 }
1294}
1295
1296static int sdma_v3_0_soft_reset(void *handle) 1317static int sdma_v3_0_soft_reset(void *handle)
1297{ 1318{
1298 u32 srbm_soft_reset = 0; 1319 u32 srbm_soft_reset = 0;
@@ -1315,8 +1336,6 @@ static int sdma_v3_0_soft_reset(void *handle)
1315 } 1336 }
1316 1337
1317 if (srbm_soft_reset) { 1338 if (srbm_soft_reset) {
1318 sdma_v3_0_print_status((void *)adev);
1319
1320 tmp = RREG32(mmSRBM_SOFT_RESET); 1339 tmp = RREG32(mmSRBM_SOFT_RESET);
1321 tmp |= srbm_soft_reset; 1340 tmp |= srbm_soft_reset;
1322 dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp); 1341 dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
@@ -1331,8 +1350,6 @@ static int sdma_v3_0_soft_reset(void *handle)
1331 1350
1332 /* Wait a little for things to settle down */ 1351 /* Wait a little for things to settle down */
1333 udelay(50); 1352 udelay(50);
1334
1335 sdma_v3_0_print_status((void *)adev);
1336 } 1353 }
1337 1354
1338 return 0; 1355 return 0;
@@ -1433,40 +1450,31 @@ static int sdma_v3_0_process_illegal_inst_irq(struct amdgpu_device *adev,
1433 return 0; 1450 return 0;
1434} 1451}
1435 1452
1436static void fiji_update_sdma_medium_grain_clock_gating( 1453static void sdma_v3_0_update_sdma_medium_grain_clock_gating(
1437 struct amdgpu_device *adev, 1454 struct amdgpu_device *adev,
1438 bool enable) 1455 bool enable)
1439{ 1456{
1440 uint32_t temp, data; 1457 uint32_t temp, data;
1458 int i;
1441 1459
1442 if (enable) { 1460 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_SDMA_MGCG)) {
1443 temp = data = RREG32(mmSDMA0_CLK_CTRL); 1461 for (i = 0; i < adev->sdma.num_instances; i++) {
1444 data &= ~(SDMA0_CLK_CTRL__SOFT_OVERRIDE7_MASK | 1462 temp = data = RREG32(mmSDMA0_CLK_CTRL + sdma_offsets[i]);
1445 SDMA0_CLK_CTRL__SOFT_OVERRIDE6_MASK | 1463 data &= ~(SDMA0_CLK_CTRL__SOFT_OVERRIDE7_MASK |
1446 SDMA0_CLK_CTRL__SOFT_OVERRIDE5_MASK | 1464 SDMA0_CLK_CTRL__SOFT_OVERRIDE6_MASK |
1447 SDMA0_CLK_CTRL__SOFT_OVERRIDE4_MASK | 1465 SDMA0_CLK_CTRL__SOFT_OVERRIDE5_MASK |
1448 SDMA0_CLK_CTRL__SOFT_OVERRIDE3_MASK | 1466 SDMA0_CLK_CTRL__SOFT_OVERRIDE4_MASK |
1449 SDMA0_CLK_CTRL__SOFT_OVERRIDE2_MASK | 1467 SDMA0_CLK_CTRL__SOFT_OVERRIDE3_MASK |
1450 SDMA0_CLK_CTRL__SOFT_OVERRIDE1_MASK | 1468 SDMA0_CLK_CTRL__SOFT_OVERRIDE2_MASK |
1451 SDMA0_CLK_CTRL__SOFT_OVERRIDE0_MASK); 1469 SDMA0_CLK_CTRL__SOFT_OVERRIDE1_MASK |
1452 if (data != temp) 1470 SDMA0_CLK_CTRL__SOFT_OVERRIDE0_MASK);
1453 WREG32(mmSDMA0_CLK_CTRL, data); 1471 if (data != temp)
1454 1472 WREG32(mmSDMA0_CLK_CTRL + sdma_offsets[i], data);
1455 temp = data = RREG32(mmSDMA1_CLK_CTRL); 1473 }
1456 data &= ~(SDMA1_CLK_CTRL__SOFT_OVERRIDE7_MASK |
1457 SDMA1_CLK_CTRL__SOFT_OVERRIDE6_MASK |
1458 SDMA1_CLK_CTRL__SOFT_OVERRIDE5_MASK |
1459 SDMA1_CLK_CTRL__SOFT_OVERRIDE4_MASK |
1460 SDMA1_CLK_CTRL__SOFT_OVERRIDE3_MASK |
1461 SDMA1_CLK_CTRL__SOFT_OVERRIDE2_MASK |
1462 SDMA1_CLK_CTRL__SOFT_OVERRIDE1_MASK |
1463 SDMA1_CLK_CTRL__SOFT_OVERRIDE0_MASK);
1464
1465 if (data != temp)
1466 WREG32(mmSDMA1_CLK_CTRL, data);
1467 } else { 1474 } else {
1468 temp = data = RREG32(mmSDMA0_CLK_CTRL); 1475 for (i = 0; i < adev->sdma.num_instances; i++) {
1469 data |= SDMA0_CLK_CTRL__SOFT_OVERRIDE7_MASK | 1476 temp = data = RREG32(mmSDMA0_CLK_CTRL + sdma_offsets[i]);
1477 data |= SDMA0_CLK_CTRL__SOFT_OVERRIDE7_MASK |
1470 SDMA0_CLK_CTRL__SOFT_OVERRIDE6_MASK | 1478 SDMA0_CLK_CTRL__SOFT_OVERRIDE6_MASK |
1471 SDMA0_CLK_CTRL__SOFT_OVERRIDE5_MASK | 1479 SDMA0_CLK_CTRL__SOFT_OVERRIDE5_MASK |
1472 SDMA0_CLK_CTRL__SOFT_OVERRIDE4_MASK | 1480 SDMA0_CLK_CTRL__SOFT_OVERRIDE4_MASK |
@@ -1475,54 +1483,35 @@ static void fiji_update_sdma_medium_grain_clock_gating(
1475 SDMA0_CLK_CTRL__SOFT_OVERRIDE1_MASK | 1483 SDMA0_CLK_CTRL__SOFT_OVERRIDE1_MASK |
1476 SDMA0_CLK_CTRL__SOFT_OVERRIDE0_MASK; 1484 SDMA0_CLK_CTRL__SOFT_OVERRIDE0_MASK;
1477 1485
1478 if (data != temp) 1486 if (data != temp)
1479 WREG32(mmSDMA0_CLK_CTRL, data); 1487 WREG32(mmSDMA0_CLK_CTRL + sdma_offsets[i], data);
1480 1488 }
1481 temp = data = RREG32(mmSDMA1_CLK_CTRL);
1482 data |= SDMA1_CLK_CTRL__SOFT_OVERRIDE7_MASK |
1483 SDMA1_CLK_CTRL__SOFT_OVERRIDE6_MASK |
1484 SDMA1_CLK_CTRL__SOFT_OVERRIDE5_MASK |
1485 SDMA1_CLK_CTRL__SOFT_OVERRIDE4_MASK |
1486 SDMA1_CLK_CTRL__SOFT_OVERRIDE3_MASK |
1487 SDMA1_CLK_CTRL__SOFT_OVERRIDE2_MASK |
1488 SDMA1_CLK_CTRL__SOFT_OVERRIDE1_MASK |
1489 SDMA1_CLK_CTRL__SOFT_OVERRIDE0_MASK;
1490
1491 if (data != temp)
1492 WREG32(mmSDMA1_CLK_CTRL, data);
1493 } 1489 }
1494} 1490}
1495 1491
1496static void fiji_update_sdma_medium_grain_light_sleep( 1492static void sdma_v3_0_update_sdma_medium_grain_light_sleep(
1497 struct amdgpu_device *adev, 1493 struct amdgpu_device *adev,
1498 bool enable) 1494 bool enable)
1499{ 1495{
1500 uint32_t temp, data; 1496 uint32_t temp, data;
1497 int i;
1501 1498
1502 if (enable) { 1499 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_SDMA_LS)) {
1503 temp = data = RREG32(mmSDMA0_POWER_CNTL); 1500 for (i = 0; i < adev->sdma.num_instances; i++) {
1504 data |= SDMA0_POWER_CNTL__MEM_POWER_OVERRIDE_MASK; 1501 temp = data = RREG32(mmSDMA0_POWER_CNTL + sdma_offsets[i]);
1505 1502 data |= SDMA0_POWER_CNTL__MEM_POWER_OVERRIDE_MASK;
1506 if (temp != data)
1507 WREG32(mmSDMA0_POWER_CNTL, data);
1508
1509 temp = data = RREG32(mmSDMA1_POWER_CNTL);
1510 data |= SDMA1_POWER_CNTL__MEM_POWER_OVERRIDE_MASK;
1511 1503
1512 if (temp != data) 1504 if (temp != data)
1513 WREG32(mmSDMA1_POWER_CNTL, data); 1505 WREG32(mmSDMA0_POWER_CNTL + sdma_offsets[i], data);
1506 }
1514 } else { 1507 } else {
1515 temp = data = RREG32(mmSDMA0_POWER_CNTL); 1508 for (i = 0; i < adev->sdma.num_instances; i++) {
1516 data &= ~SDMA0_POWER_CNTL__MEM_POWER_OVERRIDE_MASK; 1509 temp = data = RREG32(mmSDMA0_POWER_CNTL + sdma_offsets[i]);
1517 1510 data &= ~SDMA0_POWER_CNTL__MEM_POWER_OVERRIDE_MASK;
1518 if (temp != data)
1519 WREG32(mmSDMA0_POWER_CNTL, data);
1520
1521 temp = data = RREG32(mmSDMA1_POWER_CNTL);
1522 data &= ~SDMA1_POWER_CNTL__MEM_POWER_OVERRIDE_MASK;
1523 1511
1524 if (temp != data) 1512 if (temp != data)
1525 WREG32(mmSDMA1_POWER_CNTL, data); 1513 WREG32(mmSDMA0_POWER_CNTL + sdma_offsets[i], data);
1514 }
1526 } 1515 }
1527} 1516}
1528 1517
@@ -1533,9 +1522,11 @@ static int sdma_v3_0_set_clockgating_state(void *handle,
1533 1522
1534 switch (adev->asic_type) { 1523 switch (adev->asic_type) {
1535 case CHIP_FIJI: 1524 case CHIP_FIJI:
1536 fiji_update_sdma_medium_grain_clock_gating(adev, 1525 case CHIP_CARRIZO:
1526 case CHIP_STONEY:
1527 sdma_v3_0_update_sdma_medium_grain_clock_gating(adev,
1537 state == AMD_CG_STATE_GATE ? true : false); 1528 state == AMD_CG_STATE_GATE ? true : false);
1538 fiji_update_sdma_medium_grain_light_sleep(adev, 1529 sdma_v3_0_update_sdma_medium_grain_light_sleep(adev,
1539 state == AMD_CG_STATE_GATE ? true : false); 1530 state == AMD_CG_STATE_GATE ? true : false);
1540 break; 1531 break;
1541 default: 1532 default:
@@ -1562,7 +1553,6 @@ const struct amd_ip_funcs sdma_v3_0_ip_funcs = {
1562 .is_idle = sdma_v3_0_is_idle, 1553 .is_idle = sdma_v3_0_is_idle,
1563 .wait_for_idle = sdma_v3_0_wait_for_idle, 1554 .wait_for_idle = sdma_v3_0_wait_for_idle,
1564 .soft_reset = sdma_v3_0_soft_reset, 1555 .soft_reset = sdma_v3_0_soft_reset,
1565 .print_status = sdma_v3_0_print_status,
1566 .set_clockgating_state = sdma_v3_0_set_clockgating_state, 1556 .set_clockgating_state = sdma_v3_0_set_clockgating_state,
1567 .set_powergating_state = sdma_v3_0_set_powergating_state, 1557 .set_powergating_state = sdma_v3_0_set_powergating_state,
1568}; 1558};
diff --git a/drivers/gpu/drm/amd/amdgpu/smu_ucode_xfer_vi.h b/drivers/gpu/drm/amd/amdgpu/smu_ucode_xfer_vi.h
index c24a81eebc7c..880152c0f775 100644
--- a/drivers/gpu/drm/amd/amdgpu/smu_ucode_xfer_vi.h
+++ b/drivers/gpu/drm/amd/amdgpu/smu_ucode_xfer_vi.h
@@ -44,6 +44,7 @@
44#define UCODE_ID_IH_REG_RESTORE 11 44#define UCODE_ID_IH_REG_RESTORE 11
45#define UCODE_ID_VBIOS 12 45#define UCODE_ID_VBIOS 12
46#define UCODE_ID_MISC_METADATA 13 46#define UCODE_ID_MISC_METADATA 13
47#define UCODE_ID_SMU_SK 14
47#define UCODE_ID_RLC_SCRATCH 32 48#define UCODE_ID_RLC_SCRATCH 32
48#define UCODE_ID_RLC_SRM_ARAM 33 49#define UCODE_ID_RLC_SRM_ARAM 33
49#define UCODE_ID_RLC_SRM_DRAM 34 50#define UCODE_ID_RLC_SRM_DRAM 34
diff --git a/drivers/gpu/drm/amd/amdgpu/tonga_dpm.c b/drivers/gpu/drm/amd/amdgpu/tonga_dpm.c
index 0497784b3652..552f0f42a39f 100644
--- a/drivers/gpu/drm/amd/amdgpu/tonga_dpm.c
+++ b/drivers/gpu/drm/amd/amdgpu/tonga_dpm.c
@@ -154,7 +154,6 @@ const struct amd_ip_funcs tonga_dpm_ip_funcs = {
154 .is_idle = NULL, 154 .is_idle = NULL,
155 .wait_for_idle = NULL, 155 .wait_for_idle = NULL,
156 .soft_reset = NULL, 156 .soft_reset = NULL,
157 .print_status = NULL,
158 .set_clockgating_state = tonga_dpm_set_clockgating_state, 157 .set_clockgating_state = tonga_dpm_set_clockgating_state,
159 .set_powergating_state = tonga_dpm_set_powergating_state, 158 .set_powergating_state = tonga_dpm_set_powergating_state,
160}; 159};
diff --git a/drivers/gpu/drm/amd/amdgpu/tonga_ih.c b/drivers/gpu/drm/amd/amdgpu/tonga_ih.c
index b6f7d7bff929..dd9e5e36fec9 100644
--- a/drivers/gpu/drm/amd/amdgpu/tonga_ih.c
+++ b/drivers/gpu/drm/amd/amdgpu/tonga_ih.c
@@ -374,35 +374,6 @@ static int tonga_ih_wait_for_idle(void *handle)
374 return -ETIMEDOUT; 374 return -ETIMEDOUT;
375} 375}
376 376
377static void tonga_ih_print_status(void *handle)
378{
379 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
380
381 dev_info(adev->dev, "TONGA IH registers\n");
382 dev_info(adev->dev, " SRBM_STATUS=0x%08X\n",
383 RREG32(mmSRBM_STATUS));
384 dev_info(adev->dev, " SRBM_STATUS2=0x%08X\n",
385 RREG32(mmSRBM_STATUS2));
386 dev_info(adev->dev, " INTERRUPT_CNTL=0x%08X\n",
387 RREG32(mmINTERRUPT_CNTL));
388 dev_info(adev->dev, " INTERRUPT_CNTL2=0x%08X\n",
389 RREG32(mmINTERRUPT_CNTL2));
390 dev_info(adev->dev, " IH_CNTL=0x%08X\n",
391 RREG32(mmIH_CNTL));
392 dev_info(adev->dev, " IH_RB_CNTL=0x%08X\n",
393 RREG32(mmIH_RB_CNTL));
394 dev_info(adev->dev, " IH_RB_BASE=0x%08X\n",
395 RREG32(mmIH_RB_BASE));
396 dev_info(adev->dev, " IH_RB_WPTR_ADDR_LO=0x%08X\n",
397 RREG32(mmIH_RB_WPTR_ADDR_LO));
398 dev_info(adev->dev, " IH_RB_WPTR_ADDR_HI=0x%08X\n",
399 RREG32(mmIH_RB_WPTR_ADDR_HI));
400 dev_info(adev->dev, " IH_RB_RPTR=0x%08X\n",
401 RREG32(mmIH_RB_RPTR));
402 dev_info(adev->dev, " IH_RB_WPTR=0x%08X\n",
403 RREG32(mmIH_RB_WPTR));
404}
405
406static int tonga_ih_soft_reset(void *handle) 377static int tonga_ih_soft_reset(void *handle)
407{ 378{
408 u32 srbm_soft_reset = 0; 379 u32 srbm_soft_reset = 0;
@@ -414,8 +385,6 @@ static int tonga_ih_soft_reset(void *handle)
414 SOFT_RESET_IH, 1); 385 SOFT_RESET_IH, 1);
415 386
416 if (srbm_soft_reset) { 387 if (srbm_soft_reset) {
417 tonga_ih_print_status(adev);
418
419 tmp = RREG32(mmSRBM_SOFT_RESET); 388 tmp = RREG32(mmSRBM_SOFT_RESET);
420 tmp |= srbm_soft_reset; 389 tmp |= srbm_soft_reset;
421 dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp); 390 dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
@@ -430,8 +399,6 @@ static int tonga_ih_soft_reset(void *handle)
430 399
431 /* Wait a little for things to settle down */ 400 /* Wait a little for things to settle down */
432 udelay(50); 401 udelay(50);
433
434 tonga_ih_print_status(adev);
435 } 402 }
436 403
437 return 0; 404 return 0;
@@ -461,7 +428,6 @@ const struct amd_ip_funcs tonga_ih_ip_funcs = {
461 .is_idle = tonga_ih_is_idle, 428 .is_idle = tonga_ih_is_idle,
462 .wait_for_idle = tonga_ih_wait_for_idle, 429 .wait_for_idle = tonga_ih_wait_for_idle,
463 .soft_reset = tonga_ih_soft_reset, 430 .soft_reset = tonga_ih_soft_reset,
464 .print_status = tonga_ih_print_status,
465 .set_clockgating_state = tonga_ih_set_clockgating_state, 431 .set_clockgating_state = tonga_ih_set_clockgating_state,
466 .set_powergating_state = tonga_ih_set_powergating_state, 432 .set_powergating_state = tonga_ih_set_powergating_state,
467}; 433};
diff --git a/drivers/gpu/drm/amd/amdgpu/uvd_v4_2.c b/drivers/gpu/drm/amd/amdgpu/uvd_v4_2.c
index cb463753115b..abd37a7eb4c6 100644
--- a/drivers/gpu/drm/amd/amdgpu/uvd_v4_2.c
+++ b/drivers/gpu/drm/amd/amdgpu/uvd_v4_2.c
@@ -114,7 +114,7 @@ static int uvd_v4_2_sw_init(void *handle)
114 114
115 ring = &adev->uvd.ring; 115 ring = &adev->uvd.ring;
116 sprintf(ring->name, "uvd"); 116 sprintf(ring->name, "uvd");
117 r = amdgpu_ring_init(adev, ring, 4096, CP_PACKET2, 0xf, 117 r = amdgpu_ring_init(adev, ring, 512, CP_PACKET2, 0xf,
118 &adev->uvd.irq, 0, AMDGPU_RING_TYPE_UVD); 118 &adev->uvd.irq, 0, AMDGPU_RING_TYPE_UVD);
119 119
120 return r; 120 return r;
@@ -559,12 +559,13 @@ static void uvd_v4_2_mc_resume(struct amdgpu_device *adev)
559 WREG32(mmUVD_VCPU_CACHE_SIZE0, size); 559 WREG32(mmUVD_VCPU_CACHE_SIZE0, size);
560 560
561 addr += size; 561 addr += size;
562 size = AMDGPU_UVD_STACK_SIZE >> 3; 562 size = AMDGPU_UVD_HEAP_SIZE >> 3;
563 WREG32(mmUVD_VCPU_CACHE_OFFSET1, addr); 563 WREG32(mmUVD_VCPU_CACHE_OFFSET1, addr);
564 WREG32(mmUVD_VCPU_CACHE_SIZE1, size); 564 WREG32(mmUVD_VCPU_CACHE_SIZE1, size);
565 565
566 addr += size; 566 addr += size;
567 size = AMDGPU_UVD_HEAP_SIZE >> 3; 567 size = (AMDGPU_UVD_STACK_SIZE +
568 (AMDGPU_UVD_SESSION_SIZE * adev->uvd.max_handles)) >> 3;
568 WREG32(mmUVD_VCPU_CACHE_OFFSET2, addr); 569 WREG32(mmUVD_VCPU_CACHE_OFFSET2, addr);
569 WREG32(mmUVD_VCPU_CACHE_SIZE2, size); 570 WREG32(mmUVD_VCPU_CACHE_SIZE2, size);
570 571
@@ -679,117 +680,6 @@ static int uvd_v4_2_soft_reset(void *handle)
679 return uvd_v4_2_start(adev); 680 return uvd_v4_2_start(adev);
680} 681}
681 682
682static void uvd_v4_2_print_status(void *handle)
683{
684 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
685 dev_info(adev->dev, "UVD 4.2 registers\n");
686 dev_info(adev->dev, " UVD_SEMA_ADDR_LOW=0x%08X\n",
687 RREG32(mmUVD_SEMA_ADDR_LOW));
688 dev_info(adev->dev, " UVD_SEMA_ADDR_HIGH=0x%08X\n",
689 RREG32(mmUVD_SEMA_ADDR_HIGH));
690 dev_info(adev->dev, " UVD_SEMA_CMD=0x%08X\n",
691 RREG32(mmUVD_SEMA_CMD));
692 dev_info(adev->dev, " UVD_GPCOM_VCPU_CMD=0x%08X\n",
693 RREG32(mmUVD_GPCOM_VCPU_CMD));
694 dev_info(adev->dev, " UVD_GPCOM_VCPU_DATA0=0x%08X\n",
695 RREG32(mmUVD_GPCOM_VCPU_DATA0));
696 dev_info(adev->dev, " UVD_GPCOM_VCPU_DATA1=0x%08X\n",
697 RREG32(mmUVD_GPCOM_VCPU_DATA1));
698 dev_info(adev->dev, " UVD_ENGINE_CNTL=0x%08X\n",
699 RREG32(mmUVD_ENGINE_CNTL));
700 dev_info(adev->dev, " UVD_UDEC_ADDR_CONFIG=0x%08X\n",
701 RREG32(mmUVD_UDEC_ADDR_CONFIG));
702 dev_info(adev->dev, " UVD_UDEC_DB_ADDR_CONFIG=0x%08X\n",
703 RREG32(mmUVD_UDEC_DB_ADDR_CONFIG));
704 dev_info(adev->dev, " UVD_UDEC_DBW_ADDR_CONFIG=0x%08X\n",
705 RREG32(mmUVD_UDEC_DBW_ADDR_CONFIG));
706 dev_info(adev->dev, " UVD_SEMA_CNTL=0x%08X\n",
707 RREG32(mmUVD_SEMA_CNTL));
708 dev_info(adev->dev, " UVD_LMI_EXT40_ADDR=0x%08X\n",
709 RREG32(mmUVD_LMI_EXT40_ADDR));
710 dev_info(adev->dev, " UVD_CTX_INDEX=0x%08X\n",
711 RREG32(mmUVD_CTX_INDEX));
712 dev_info(adev->dev, " UVD_CTX_DATA=0x%08X\n",
713 RREG32(mmUVD_CTX_DATA));
714 dev_info(adev->dev, " UVD_CGC_GATE=0x%08X\n",
715 RREG32(mmUVD_CGC_GATE));
716 dev_info(adev->dev, " UVD_CGC_CTRL=0x%08X\n",
717 RREG32(mmUVD_CGC_CTRL));
718 dev_info(adev->dev, " UVD_LMI_CTRL2=0x%08X\n",
719 RREG32(mmUVD_LMI_CTRL2));
720 dev_info(adev->dev, " UVD_MASTINT_EN=0x%08X\n",
721 RREG32(mmUVD_MASTINT_EN));
722 dev_info(adev->dev, " UVD_LMI_ADDR_EXT=0x%08X\n",
723 RREG32(mmUVD_LMI_ADDR_EXT));
724 dev_info(adev->dev, " UVD_LMI_CTRL=0x%08X\n",
725 RREG32(mmUVD_LMI_CTRL));
726 dev_info(adev->dev, " UVD_LMI_SWAP_CNTL=0x%08X\n",
727 RREG32(mmUVD_LMI_SWAP_CNTL));
728 dev_info(adev->dev, " UVD_MP_SWAP_CNTL=0x%08X\n",
729 RREG32(mmUVD_MP_SWAP_CNTL));
730 dev_info(adev->dev, " UVD_MPC_SET_MUXA0=0x%08X\n",
731 RREG32(mmUVD_MPC_SET_MUXA0));
732 dev_info(adev->dev, " UVD_MPC_SET_MUXA1=0x%08X\n",
733 RREG32(mmUVD_MPC_SET_MUXA1));
734 dev_info(adev->dev, " UVD_MPC_SET_MUXB0=0x%08X\n",
735 RREG32(mmUVD_MPC_SET_MUXB0));
736 dev_info(adev->dev, " UVD_MPC_SET_MUXB1=0x%08X\n",
737 RREG32(mmUVD_MPC_SET_MUXB1));
738 dev_info(adev->dev, " UVD_MPC_SET_MUX=0x%08X\n",
739 RREG32(mmUVD_MPC_SET_MUX));
740 dev_info(adev->dev, " UVD_MPC_SET_ALU=0x%08X\n",
741 RREG32(mmUVD_MPC_SET_ALU));
742 dev_info(adev->dev, " UVD_VCPU_CACHE_OFFSET0=0x%08X\n",
743 RREG32(mmUVD_VCPU_CACHE_OFFSET0));
744 dev_info(adev->dev, " UVD_VCPU_CACHE_SIZE0=0x%08X\n",
745 RREG32(mmUVD_VCPU_CACHE_SIZE0));
746 dev_info(adev->dev, " UVD_VCPU_CACHE_OFFSET1=0x%08X\n",
747 RREG32(mmUVD_VCPU_CACHE_OFFSET1));
748 dev_info(adev->dev, " UVD_VCPU_CACHE_SIZE1=0x%08X\n",
749 RREG32(mmUVD_VCPU_CACHE_SIZE1));
750 dev_info(adev->dev, " UVD_VCPU_CACHE_OFFSET2=0x%08X\n",
751 RREG32(mmUVD_VCPU_CACHE_OFFSET2));
752 dev_info(adev->dev, " UVD_VCPU_CACHE_SIZE2=0x%08X\n",
753 RREG32(mmUVD_VCPU_CACHE_SIZE2));
754 dev_info(adev->dev, " UVD_VCPU_CNTL=0x%08X\n",
755 RREG32(mmUVD_VCPU_CNTL));
756 dev_info(adev->dev, " UVD_SOFT_RESET=0x%08X\n",
757 RREG32(mmUVD_SOFT_RESET));
758 dev_info(adev->dev, " UVD_RBC_IB_BASE=0x%08X\n",
759 RREG32(mmUVD_RBC_IB_BASE));
760 dev_info(adev->dev, " UVD_RBC_IB_SIZE=0x%08X\n",
761 RREG32(mmUVD_RBC_IB_SIZE));
762 dev_info(adev->dev, " UVD_RBC_RB_BASE=0x%08X\n",
763 RREG32(mmUVD_RBC_RB_BASE));
764 dev_info(adev->dev, " UVD_RBC_RB_RPTR=0x%08X\n",
765 RREG32(mmUVD_RBC_RB_RPTR));
766 dev_info(adev->dev, " UVD_RBC_RB_WPTR=0x%08X\n",
767 RREG32(mmUVD_RBC_RB_WPTR));
768 dev_info(adev->dev, " UVD_RBC_RB_WPTR_CNTL=0x%08X\n",
769 RREG32(mmUVD_RBC_RB_WPTR_CNTL));
770 dev_info(adev->dev, " UVD_RBC_RB_CNTL=0x%08X\n",
771 RREG32(mmUVD_RBC_RB_CNTL));
772 dev_info(adev->dev, " UVD_STATUS=0x%08X\n",
773 RREG32(mmUVD_STATUS));
774 dev_info(adev->dev, " UVD_SEMA_TIMEOUT_STATUS=0x%08X\n",
775 RREG32(mmUVD_SEMA_TIMEOUT_STATUS));
776 dev_info(adev->dev, " UVD_SEMA_WAIT_INCOMPLETE_TIMEOUT_CNTL=0x%08X\n",
777 RREG32(mmUVD_SEMA_WAIT_INCOMPLETE_TIMEOUT_CNTL));
778 dev_info(adev->dev, " UVD_SEMA_WAIT_FAULT_TIMEOUT_CNTL=0x%08X\n",
779 RREG32(mmUVD_SEMA_WAIT_FAULT_TIMEOUT_CNTL));
780 dev_info(adev->dev, " UVD_SEMA_SIGNAL_INCOMPLETE_TIMEOUT_CNTL=0x%08X\n",
781 RREG32(mmUVD_SEMA_SIGNAL_INCOMPLETE_TIMEOUT_CNTL));
782 dev_info(adev->dev, " UVD_CONTEXT_ID=0x%08X\n",
783 RREG32(mmUVD_CONTEXT_ID));
784 dev_info(adev->dev, " UVD_UDEC_ADDR_CONFIG=0x%08X\n",
785 RREG32(mmUVD_UDEC_ADDR_CONFIG));
786 dev_info(adev->dev, " UVD_UDEC_DB_ADDR_CONFIG=0x%08X\n",
787 RREG32(mmUVD_UDEC_DB_ADDR_CONFIG));
788 dev_info(adev->dev, " UVD_UDEC_DBW_ADDR_CONFIG=0x%08X\n",
789 RREG32(mmUVD_UDEC_DBW_ADDR_CONFIG));
790
791}
792
793static int uvd_v4_2_set_interrupt_state(struct amdgpu_device *adev, 683static int uvd_v4_2_set_interrupt_state(struct amdgpu_device *adev,
794 struct amdgpu_irq_src *source, 684 struct amdgpu_irq_src *source,
795 unsigned type, 685 unsigned type,
@@ -860,7 +750,6 @@ const struct amd_ip_funcs uvd_v4_2_ip_funcs = {
860 .is_idle = uvd_v4_2_is_idle, 750 .is_idle = uvd_v4_2_is_idle,
861 .wait_for_idle = uvd_v4_2_wait_for_idle, 751 .wait_for_idle = uvd_v4_2_wait_for_idle,
862 .soft_reset = uvd_v4_2_soft_reset, 752 .soft_reset = uvd_v4_2_soft_reset,
863 .print_status = uvd_v4_2_print_status,
864 .set_clockgating_state = uvd_v4_2_set_clockgating_state, 753 .set_clockgating_state = uvd_v4_2_set_clockgating_state,
865 .set_powergating_state = uvd_v4_2_set_powergating_state, 754 .set_powergating_state = uvd_v4_2_set_powergating_state,
866}; 755};
diff --git a/drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c b/drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c
index 16476d80f475..1c1a0e2c7e0f 100644
--- a/drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c
@@ -31,6 +31,7 @@
31#include "uvd/uvd_5_0_sh_mask.h" 31#include "uvd/uvd_5_0_sh_mask.h"
32#include "oss/oss_2_0_d.h" 32#include "oss/oss_2_0_d.h"
33#include "oss/oss_2_0_sh_mask.h" 33#include "oss/oss_2_0_sh_mask.h"
34#include "vi.h"
34 35
35static void uvd_v5_0_set_ring_funcs(struct amdgpu_device *adev); 36static void uvd_v5_0_set_ring_funcs(struct amdgpu_device *adev);
36static void uvd_v5_0_set_irq_funcs(struct amdgpu_device *adev); 37static void uvd_v5_0_set_irq_funcs(struct amdgpu_device *adev);
@@ -110,7 +111,7 @@ static int uvd_v5_0_sw_init(void *handle)
110 111
111 ring = &adev->uvd.ring; 112 ring = &adev->uvd.ring;
112 sprintf(ring->name, "uvd"); 113 sprintf(ring->name, "uvd");
113 r = amdgpu_ring_init(adev, ring, 4096, CP_PACKET2, 0xf, 114 r = amdgpu_ring_init(adev, ring, 512, CP_PACKET2, 0xf,
114 &adev->uvd.irq, 0, AMDGPU_RING_TYPE_UVD); 115 &adev->uvd.irq, 0, AMDGPU_RING_TYPE_UVD);
115 116
116 return r; 117 return r;
@@ -271,12 +272,13 @@ static void uvd_v5_0_mc_resume(struct amdgpu_device *adev)
271 WREG32(mmUVD_VCPU_CACHE_SIZE0, size); 272 WREG32(mmUVD_VCPU_CACHE_SIZE0, size);
272 273
273 offset += size; 274 offset += size;
274 size = AMDGPU_UVD_STACK_SIZE; 275 size = AMDGPU_UVD_HEAP_SIZE;
275 WREG32(mmUVD_VCPU_CACHE_OFFSET1, offset >> 3); 276 WREG32(mmUVD_VCPU_CACHE_OFFSET1, offset >> 3);
276 WREG32(mmUVD_VCPU_CACHE_SIZE1, size); 277 WREG32(mmUVD_VCPU_CACHE_SIZE1, size);
277 278
278 offset += size; 279 offset += size;
279 size = AMDGPU_UVD_HEAP_SIZE; 280 size = AMDGPU_UVD_STACK_SIZE +
281 (AMDGPU_UVD_SESSION_SIZE * adev->uvd.max_handles);
280 WREG32(mmUVD_VCPU_CACHE_OFFSET2, offset >> 3); 282 WREG32(mmUVD_VCPU_CACHE_OFFSET2, offset >> 3);
281 WREG32(mmUVD_VCPU_CACHE_SIZE2, size); 283 WREG32(mmUVD_VCPU_CACHE_SIZE2, size);
282 284
@@ -622,120 +624,6 @@ static int uvd_v5_0_soft_reset(void *handle)
622 return uvd_v5_0_start(adev); 624 return uvd_v5_0_start(adev);
623} 625}
624 626
625static void uvd_v5_0_print_status(void *handle)
626{
627 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
628 dev_info(adev->dev, "UVD 5.0 registers\n");
629 dev_info(adev->dev, " UVD_SEMA_ADDR_LOW=0x%08X\n",
630 RREG32(mmUVD_SEMA_ADDR_LOW));
631 dev_info(adev->dev, " UVD_SEMA_ADDR_HIGH=0x%08X\n",
632 RREG32(mmUVD_SEMA_ADDR_HIGH));
633 dev_info(adev->dev, " UVD_SEMA_CMD=0x%08X\n",
634 RREG32(mmUVD_SEMA_CMD));
635 dev_info(adev->dev, " UVD_GPCOM_VCPU_CMD=0x%08X\n",
636 RREG32(mmUVD_GPCOM_VCPU_CMD));
637 dev_info(adev->dev, " UVD_GPCOM_VCPU_DATA0=0x%08X\n",
638 RREG32(mmUVD_GPCOM_VCPU_DATA0));
639 dev_info(adev->dev, " UVD_GPCOM_VCPU_DATA1=0x%08X\n",
640 RREG32(mmUVD_GPCOM_VCPU_DATA1));
641 dev_info(adev->dev, " UVD_ENGINE_CNTL=0x%08X\n",
642 RREG32(mmUVD_ENGINE_CNTL));
643 dev_info(adev->dev, " UVD_UDEC_ADDR_CONFIG=0x%08X\n",
644 RREG32(mmUVD_UDEC_ADDR_CONFIG));
645 dev_info(adev->dev, " UVD_UDEC_DB_ADDR_CONFIG=0x%08X\n",
646 RREG32(mmUVD_UDEC_DB_ADDR_CONFIG));
647 dev_info(adev->dev, " UVD_UDEC_DBW_ADDR_CONFIG=0x%08X\n",
648 RREG32(mmUVD_UDEC_DBW_ADDR_CONFIG));
649 dev_info(adev->dev, " UVD_SEMA_CNTL=0x%08X\n",
650 RREG32(mmUVD_SEMA_CNTL));
651 dev_info(adev->dev, " UVD_LMI_EXT40_ADDR=0x%08X\n",
652 RREG32(mmUVD_LMI_EXT40_ADDR));
653 dev_info(adev->dev, " UVD_CTX_INDEX=0x%08X\n",
654 RREG32(mmUVD_CTX_INDEX));
655 dev_info(adev->dev, " UVD_CTX_DATA=0x%08X\n",
656 RREG32(mmUVD_CTX_DATA));
657 dev_info(adev->dev, " UVD_CGC_GATE=0x%08X\n",
658 RREG32(mmUVD_CGC_GATE));
659 dev_info(adev->dev, " UVD_CGC_CTRL=0x%08X\n",
660 RREG32(mmUVD_CGC_CTRL));
661 dev_info(adev->dev, " UVD_LMI_CTRL2=0x%08X\n",
662 RREG32(mmUVD_LMI_CTRL2));
663 dev_info(adev->dev, " UVD_MASTINT_EN=0x%08X\n",
664 RREG32(mmUVD_MASTINT_EN));
665 dev_info(adev->dev, " UVD_LMI_ADDR_EXT=0x%08X\n",
666 RREG32(mmUVD_LMI_ADDR_EXT));
667 dev_info(adev->dev, " UVD_LMI_CTRL=0x%08X\n",
668 RREG32(mmUVD_LMI_CTRL));
669 dev_info(adev->dev, " UVD_LMI_SWAP_CNTL=0x%08X\n",
670 RREG32(mmUVD_LMI_SWAP_CNTL));
671 dev_info(adev->dev, " UVD_MP_SWAP_CNTL=0x%08X\n",
672 RREG32(mmUVD_MP_SWAP_CNTL));
673 dev_info(adev->dev, " UVD_MPC_SET_MUXA0=0x%08X\n",
674 RREG32(mmUVD_MPC_SET_MUXA0));
675 dev_info(adev->dev, " UVD_MPC_SET_MUXA1=0x%08X\n",
676 RREG32(mmUVD_MPC_SET_MUXA1));
677 dev_info(adev->dev, " UVD_MPC_SET_MUXB0=0x%08X\n",
678 RREG32(mmUVD_MPC_SET_MUXB0));
679 dev_info(adev->dev, " UVD_MPC_SET_MUXB1=0x%08X\n",
680 RREG32(mmUVD_MPC_SET_MUXB1));
681 dev_info(adev->dev, " UVD_MPC_SET_MUX=0x%08X\n",
682 RREG32(mmUVD_MPC_SET_MUX));
683 dev_info(adev->dev, " UVD_MPC_SET_ALU=0x%08X\n",
684 RREG32(mmUVD_MPC_SET_ALU));
685 dev_info(adev->dev, " UVD_VCPU_CACHE_OFFSET0=0x%08X\n",
686 RREG32(mmUVD_VCPU_CACHE_OFFSET0));
687 dev_info(adev->dev, " UVD_VCPU_CACHE_SIZE0=0x%08X\n",
688 RREG32(mmUVD_VCPU_CACHE_SIZE0));
689 dev_info(adev->dev, " UVD_VCPU_CACHE_OFFSET1=0x%08X\n",
690 RREG32(mmUVD_VCPU_CACHE_OFFSET1));
691 dev_info(adev->dev, " UVD_VCPU_CACHE_SIZE1=0x%08X\n",
692 RREG32(mmUVD_VCPU_CACHE_SIZE1));
693 dev_info(adev->dev, " UVD_VCPU_CACHE_OFFSET2=0x%08X\n",
694 RREG32(mmUVD_VCPU_CACHE_OFFSET2));
695 dev_info(adev->dev, " UVD_VCPU_CACHE_SIZE2=0x%08X\n",
696 RREG32(mmUVD_VCPU_CACHE_SIZE2));
697 dev_info(adev->dev, " UVD_VCPU_CNTL=0x%08X\n",
698 RREG32(mmUVD_VCPU_CNTL));
699 dev_info(adev->dev, " UVD_SOFT_RESET=0x%08X\n",
700 RREG32(mmUVD_SOFT_RESET));
701 dev_info(adev->dev, " UVD_LMI_RBC_IB_64BIT_BAR_LOW=0x%08X\n",
702 RREG32(mmUVD_LMI_RBC_IB_64BIT_BAR_LOW));
703 dev_info(adev->dev, " UVD_LMI_RBC_IB_64BIT_BAR_HIGH=0x%08X\n",
704 RREG32(mmUVD_LMI_RBC_IB_64BIT_BAR_HIGH));
705 dev_info(adev->dev, " UVD_RBC_IB_SIZE=0x%08X\n",
706 RREG32(mmUVD_RBC_IB_SIZE));
707 dev_info(adev->dev, " UVD_LMI_RBC_RB_64BIT_BAR_LOW=0x%08X\n",
708 RREG32(mmUVD_LMI_RBC_RB_64BIT_BAR_LOW));
709 dev_info(adev->dev, " UVD_LMI_RBC_RB_64BIT_BAR_HIGH=0x%08X\n",
710 RREG32(mmUVD_LMI_RBC_RB_64BIT_BAR_HIGH));
711 dev_info(adev->dev, " UVD_RBC_RB_RPTR=0x%08X\n",
712 RREG32(mmUVD_RBC_RB_RPTR));
713 dev_info(adev->dev, " UVD_RBC_RB_WPTR=0x%08X\n",
714 RREG32(mmUVD_RBC_RB_WPTR));
715 dev_info(adev->dev, " UVD_RBC_RB_WPTR_CNTL=0x%08X\n",
716 RREG32(mmUVD_RBC_RB_WPTR_CNTL));
717 dev_info(adev->dev, " UVD_RBC_RB_CNTL=0x%08X\n",
718 RREG32(mmUVD_RBC_RB_CNTL));
719 dev_info(adev->dev, " UVD_STATUS=0x%08X\n",
720 RREG32(mmUVD_STATUS));
721 dev_info(adev->dev, " UVD_SEMA_TIMEOUT_STATUS=0x%08X\n",
722 RREG32(mmUVD_SEMA_TIMEOUT_STATUS));
723 dev_info(adev->dev, " UVD_SEMA_WAIT_INCOMPLETE_TIMEOUT_CNTL=0x%08X\n",
724 RREG32(mmUVD_SEMA_WAIT_INCOMPLETE_TIMEOUT_CNTL));
725 dev_info(adev->dev, " UVD_SEMA_WAIT_FAULT_TIMEOUT_CNTL=0x%08X\n",
726 RREG32(mmUVD_SEMA_WAIT_FAULT_TIMEOUT_CNTL));
727 dev_info(adev->dev, " UVD_SEMA_SIGNAL_INCOMPLETE_TIMEOUT_CNTL=0x%08X\n",
728 RREG32(mmUVD_SEMA_SIGNAL_INCOMPLETE_TIMEOUT_CNTL));
729 dev_info(adev->dev, " UVD_CONTEXT_ID=0x%08X\n",
730 RREG32(mmUVD_CONTEXT_ID));
731 dev_info(adev->dev, " UVD_UDEC_ADDR_CONFIG=0x%08X\n",
732 RREG32(mmUVD_UDEC_ADDR_CONFIG));
733 dev_info(adev->dev, " UVD_UDEC_DB_ADDR_CONFIG=0x%08X\n",
734 RREG32(mmUVD_UDEC_DB_ADDR_CONFIG));
735 dev_info(adev->dev, " UVD_UDEC_DBW_ADDR_CONFIG=0x%08X\n",
736 RREG32(mmUVD_UDEC_DBW_ADDR_CONFIG));
737}
738
739static int uvd_v5_0_set_interrupt_state(struct amdgpu_device *adev, 627static int uvd_v5_0_set_interrupt_state(struct amdgpu_device *adev,
740 struct amdgpu_irq_src *source, 628 struct amdgpu_irq_src *source,
741 unsigned type, 629 unsigned type,
@@ -754,14 +642,128 @@ static int uvd_v5_0_process_interrupt(struct amdgpu_device *adev,
754 return 0; 642 return 0;
755} 643}
756 644
645static void uvd_v5_0_set_sw_clock_gating(struct amdgpu_device *adev)
646{
647 uint32_t data, data1, data2, suvd_flags;
648
649 data = RREG32(mmUVD_CGC_CTRL);
650 data1 = RREG32(mmUVD_SUVD_CGC_GATE);
651 data2 = RREG32(mmUVD_SUVD_CGC_CTRL);
652
653 data &= ~(UVD_CGC_CTRL__CLK_OFF_DELAY_MASK |
654 UVD_CGC_CTRL__CLK_GATE_DLY_TIMER_MASK);
655
656 suvd_flags = UVD_SUVD_CGC_GATE__SRE_MASK |
657 UVD_SUVD_CGC_GATE__SIT_MASK |
658 UVD_SUVD_CGC_GATE__SMP_MASK |
659 UVD_SUVD_CGC_GATE__SCM_MASK |
660 UVD_SUVD_CGC_GATE__SDB_MASK;
661
662 data |= UVD_CGC_CTRL__DYN_CLOCK_MODE_MASK |
663 (1 << REG_FIELD_SHIFT(UVD_CGC_CTRL, CLK_GATE_DLY_TIMER)) |
664 (4 << REG_FIELD_SHIFT(UVD_CGC_CTRL, CLK_OFF_DELAY));
665
666 data &= ~(UVD_CGC_CTRL__UDEC_RE_MODE_MASK |
667 UVD_CGC_CTRL__UDEC_CM_MODE_MASK |
668 UVD_CGC_CTRL__UDEC_IT_MODE_MASK |
669 UVD_CGC_CTRL__UDEC_DB_MODE_MASK |
670 UVD_CGC_CTRL__UDEC_MP_MODE_MASK |
671 UVD_CGC_CTRL__SYS_MODE_MASK |
672 UVD_CGC_CTRL__UDEC_MODE_MASK |
673 UVD_CGC_CTRL__MPEG2_MODE_MASK |
674 UVD_CGC_CTRL__REGS_MODE_MASK |
675 UVD_CGC_CTRL__RBC_MODE_MASK |
676 UVD_CGC_CTRL__LMI_MC_MODE_MASK |
677 UVD_CGC_CTRL__LMI_UMC_MODE_MASK |
678 UVD_CGC_CTRL__IDCT_MODE_MASK |
679 UVD_CGC_CTRL__MPRD_MODE_MASK |
680 UVD_CGC_CTRL__MPC_MODE_MASK |
681 UVD_CGC_CTRL__LBSI_MODE_MASK |
682 UVD_CGC_CTRL__LRBBM_MODE_MASK |
683 UVD_CGC_CTRL__WCB_MODE_MASK |
684 UVD_CGC_CTRL__VCPU_MODE_MASK |
685 UVD_CGC_CTRL__JPEG_MODE_MASK |
686 UVD_CGC_CTRL__SCPU_MODE_MASK);
687 data2 &= ~(UVD_SUVD_CGC_CTRL__SRE_MODE_MASK |
688 UVD_SUVD_CGC_CTRL__SIT_MODE_MASK |
689 UVD_SUVD_CGC_CTRL__SMP_MODE_MASK |
690 UVD_SUVD_CGC_CTRL__SCM_MODE_MASK |
691 UVD_SUVD_CGC_CTRL__SDB_MODE_MASK);
692 data1 |= suvd_flags;
693
694 WREG32(mmUVD_CGC_CTRL, data);
695 WREG32(mmUVD_CGC_GATE, 0);
696 WREG32(mmUVD_SUVD_CGC_GATE, data1);
697 WREG32(mmUVD_SUVD_CGC_CTRL, data2);
698}
699
700#if 0
701static void uvd_v5_0_set_hw_clock_gating(struct amdgpu_device *adev)
702{
703 uint32_t data, data1, cgc_flags, suvd_flags;
704
705 data = RREG32(mmUVD_CGC_GATE);
706 data1 = RREG32(mmUVD_SUVD_CGC_GATE);
707
708 cgc_flags = UVD_CGC_GATE__SYS_MASK |
709 UVD_CGC_GATE__UDEC_MASK |
710 UVD_CGC_GATE__MPEG2_MASK |
711 UVD_CGC_GATE__RBC_MASK |
712 UVD_CGC_GATE__LMI_MC_MASK |
713 UVD_CGC_GATE__IDCT_MASK |
714 UVD_CGC_GATE__MPRD_MASK |
715 UVD_CGC_GATE__MPC_MASK |
716 UVD_CGC_GATE__LBSI_MASK |
717 UVD_CGC_GATE__LRBBM_MASK |
718 UVD_CGC_GATE__UDEC_RE_MASK |
719 UVD_CGC_GATE__UDEC_CM_MASK |
720 UVD_CGC_GATE__UDEC_IT_MASK |
721 UVD_CGC_GATE__UDEC_DB_MASK |
722 UVD_CGC_GATE__UDEC_MP_MASK |
723 UVD_CGC_GATE__WCB_MASK |
724 UVD_CGC_GATE__VCPU_MASK |
725 UVD_CGC_GATE__SCPU_MASK;
726
727 suvd_flags = UVD_SUVD_CGC_GATE__SRE_MASK |
728 UVD_SUVD_CGC_GATE__SIT_MASK |
729 UVD_SUVD_CGC_GATE__SMP_MASK |
730 UVD_SUVD_CGC_GATE__SCM_MASK |
731 UVD_SUVD_CGC_GATE__SDB_MASK;
732
733 data |= cgc_flags;
734 data1 |= suvd_flags;
735
736 WREG32(mmUVD_CGC_GATE, data);
737 WREG32(mmUVD_SUVD_CGC_GATE, data1);
738}
739#endif
740
757static int uvd_v5_0_set_clockgating_state(void *handle, 741static int uvd_v5_0_set_clockgating_state(void *handle,
758 enum amd_clockgating_state state) 742 enum amd_clockgating_state state)
759{ 743{
760 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 744 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
745 bool enable = (state == AMD_CG_STATE_GATE) ? true : false;
746 static int curstate = -1;
761 747
762 if (!(adev->cg_flags & AMD_CG_SUPPORT_UVD_MGCG)) 748 if (!(adev->cg_flags & AMD_CG_SUPPORT_UVD_MGCG))
763 return 0; 749 return 0;
764 750
751 if (curstate == state)
752 return 0;
753
754 curstate = state;
755 if (enable) {
756 /* disable HW gating and enable Sw gating */
757 uvd_v5_0_set_sw_clock_gating(adev);
758 } else {
759 /* wait for STATUS to clear */
760 if (uvd_v5_0_wait_for_idle(handle))
761 return -EBUSY;
762
763 /* enable HW gates because UVD is idle */
764/* uvd_v5_0_set_hw_clock_gating(adev); */
765 }
766
765 return 0; 767 return 0;
766} 768}
767 769
@@ -800,7 +802,6 @@ const struct amd_ip_funcs uvd_v5_0_ip_funcs = {
800 .is_idle = uvd_v5_0_is_idle, 802 .is_idle = uvd_v5_0_is_idle,
801 .wait_for_idle = uvd_v5_0_wait_for_idle, 803 .wait_for_idle = uvd_v5_0_wait_for_idle,
802 .soft_reset = uvd_v5_0_soft_reset, 804 .soft_reset = uvd_v5_0_soft_reset,
803 .print_status = uvd_v5_0_print_status,
804 .set_clockgating_state = uvd_v5_0_set_clockgating_state, 805 .set_clockgating_state = uvd_v5_0_set_clockgating_state,
805 .set_powergating_state = uvd_v5_0_set_powergating_state, 806 .set_powergating_state = uvd_v5_0_set_powergating_state,
806}; 807};
diff --git a/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c b/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c
index d49379145ef2..d015cb0c9eb5 100644
--- a/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c
@@ -31,11 +31,15 @@
31#include "uvd/uvd_6_0_sh_mask.h" 31#include "uvd/uvd_6_0_sh_mask.h"
32#include "oss/oss_2_0_d.h" 32#include "oss/oss_2_0_d.h"
33#include "oss/oss_2_0_sh_mask.h" 33#include "oss/oss_2_0_sh_mask.h"
34#include "smu/smu_7_1_3_d.h"
35#include "smu/smu_7_1_3_sh_mask.h"
36#include "vi.h"
34 37
35static void uvd_v6_0_set_ring_funcs(struct amdgpu_device *adev); 38static void uvd_v6_0_set_ring_funcs(struct amdgpu_device *adev);
36static void uvd_v6_0_set_irq_funcs(struct amdgpu_device *adev); 39static void uvd_v6_0_set_irq_funcs(struct amdgpu_device *adev);
37static int uvd_v6_0_start(struct amdgpu_device *adev); 40static int uvd_v6_0_start(struct amdgpu_device *adev);
38static void uvd_v6_0_stop(struct amdgpu_device *adev); 41static void uvd_v6_0_stop(struct amdgpu_device *adev);
42static void uvd_v6_0_set_sw_clock_gating(struct amdgpu_device *adev);
39 43
40/** 44/**
41 * uvd_v6_0_ring_get_rptr - get read pointer 45 * uvd_v6_0_ring_get_rptr - get read pointer
@@ -110,7 +114,7 @@ static int uvd_v6_0_sw_init(void *handle)
110 114
111 ring = &adev->uvd.ring; 115 ring = &adev->uvd.ring;
112 sprintf(ring->name, "uvd"); 116 sprintf(ring->name, "uvd");
113 r = amdgpu_ring_init(adev, ring, 4096, CP_PACKET2, 0xf, 117 r = amdgpu_ring_init(adev, ring, 512, CP_PACKET2, 0xf,
114 &adev->uvd.irq, 0, AMDGPU_RING_TYPE_UVD); 118 &adev->uvd.irq, 0, AMDGPU_RING_TYPE_UVD);
115 119
116 return r; 120 return r;
@@ -270,20 +274,24 @@ static void uvd_v6_0_mc_resume(struct amdgpu_device *adev)
270 WREG32(mmUVD_VCPU_CACHE_SIZE0, size); 274 WREG32(mmUVD_VCPU_CACHE_SIZE0, size);
271 275
272 offset += size; 276 offset += size;
273 size = AMDGPU_UVD_STACK_SIZE; 277 size = AMDGPU_UVD_HEAP_SIZE;
274 WREG32(mmUVD_VCPU_CACHE_OFFSET1, offset >> 3); 278 WREG32(mmUVD_VCPU_CACHE_OFFSET1, offset >> 3);
275 WREG32(mmUVD_VCPU_CACHE_SIZE1, size); 279 WREG32(mmUVD_VCPU_CACHE_SIZE1, size);
276 280
277 offset += size; 281 offset += size;
278 size = AMDGPU_UVD_HEAP_SIZE; 282 size = AMDGPU_UVD_STACK_SIZE +
283 (AMDGPU_UVD_SESSION_SIZE * adev->uvd.max_handles);
279 WREG32(mmUVD_VCPU_CACHE_OFFSET2, offset >> 3); 284 WREG32(mmUVD_VCPU_CACHE_OFFSET2, offset >> 3);
280 WREG32(mmUVD_VCPU_CACHE_SIZE2, size); 285 WREG32(mmUVD_VCPU_CACHE_SIZE2, size);
281 286
282 WREG32(mmUVD_UDEC_ADDR_CONFIG, adev->gfx.config.gb_addr_config); 287 WREG32(mmUVD_UDEC_ADDR_CONFIG, adev->gfx.config.gb_addr_config);
283 WREG32(mmUVD_UDEC_DB_ADDR_CONFIG, adev->gfx.config.gb_addr_config); 288 WREG32(mmUVD_UDEC_DB_ADDR_CONFIG, adev->gfx.config.gb_addr_config);
284 WREG32(mmUVD_UDEC_DBW_ADDR_CONFIG, adev->gfx.config.gb_addr_config); 289 WREG32(mmUVD_UDEC_DBW_ADDR_CONFIG, adev->gfx.config.gb_addr_config);
290
291 WREG32(mmUVD_GP_SCRATCH4, adev->uvd.max_handles);
285} 292}
286 293
294#if 0
287static void cz_set_uvd_clock_gating_branches(struct amdgpu_device *adev, 295static void cz_set_uvd_clock_gating_branches(struct amdgpu_device *adev,
288 bool enable) 296 bool enable)
289{ 297{
@@ -360,157 +368,7 @@ static void cz_set_uvd_clock_gating_branches(struct amdgpu_device *adev,
360 WREG32(mmUVD_CGC_GATE, data); 368 WREG32(mmUVD_CGC_GATE, data);
361 WREG32(mmUVD_SUVD_CGC_GATE, data1); 369 WREG32(mmUVD_SUVD_CGC_GATE, data1);
362} 370}
363 371#endif
364static void tonga_set_uvd_clock_gating_branches(struct amdgpu_device *adev,
365 bool enable)
366{
367 u32 data, data1;
368
369 data = RREG32(mmUVD_CGC_GATE);
370 data1 = RREG32(mmUVD_SUVD_CGC_GATE);
371 if (enable) {
372 data |= UVD_CGC_GATE__SYS_MASK |
373 UVD_CGC_GATE__UDEC_MASK |
374 UVD_CGC_GATE__MPEG2_MASK |
375 UVD_CGC_GATE__RBC_MASK |
376 UVD_CGC_GATE__LMI_MC_MASK |
377 UVD_CGC_GATE__IDCT_MASK |
378 UVD_CGC_GATE__MPRD_MASK |
379 UVD_CGC_GATE__MPC_MASK |
380 UVD_CGC_GATE__LBSI_MASK |
381 UVD_CGC_GATE__LRBBM_MASK |
382 UVD_CGC_GATE__UDEC_RE_MASK |
383 UVD_CGC_GATE__UDEC_CM_MASK |
384 UVD_CGC_GATE__UDEC_IT_MASK |
385 UVD_CGC_GATE__UDEC_DB_MASK |
386 UVD_CGC_GATE__UDEC_MP_MASK |
387 UVD_CGC_GATE__WCB_MASK |
388 UVD_CGC_GATE__VCPU_MASK |
389 UVD_CGC_GATE__SCPU_MASK;
390 data1 |= UVD_SUVD_CGC_GATE__SRE_MASK |
391 UVD_SUVD_CGC_GATE__SIT_MASK |
392 UVD_SUVD_CGC_GATE__SMP_MASK |
393 UVD_SUVD_CGC_GATE__SCM_MASK |
394 UVD_SUVD_CGC_GATE__SDB_MASK;
395 } else {
396 data &= ~(UVD_CGC_GATE__SYS_MASK |
397 UVD_CGC_GATE__UDEC_MASK |
398 UVD_CGC_GATE__MPEG2_MASK |
399 UVD_CGC_GATE__RBC_MASK |
400 UVD_CGC_GATE__LMI_MC_MASK |
401 UVD_CGC_GATE__LMI_UMC_MASK |
402 UVD_CGC_GATE__IDCT_MASK |
403 UVD_CGC_GATE__MPRD_MASK |
404 UVD_CGC_GATE__MPC_MASK |
405 UVD_CGC_GATE__LBSI_MASK |
406 UVD_CGC_GATE__LRBBM_MASK |
407 UVD_CGC_GATE__UDEC_RE_MASK |
408 UVD_CGC_GATE__UDEC_CM_MASK |
409 UVD_CGC_GATE__UDEC_IT_MASK |
410 UVD_CGC_GATE__UDEC_DB_MASK |
411 UVD_CGC_GATE__UDEC_MP_MASK |
412 UVD_CGC_GATE__WCB_MASK |
413 UVD_CGC_GATE__VCPU_MASK |
414 UVD_CGC_GATE__SCPU_MASK);
415 data1 &= ~(UVD_SUVD_CGC_GATE__SRE_MASK |
416 UVD_SUVD_CGC_GATE__SIT_MASK |
417 UVD_SUVD_CGC_GATE__SMP_MASK |
418 UVD_SUVD_CGC_GATE__SCM_MASK |
419 UVD_SUVD_CGC_GATE__SDB_MASK);
420 }
421 WREG32(mmUVD_CGC_GATE, data);
422 WREG32(mmUVD_SUVD_CGC_GATE, data1);
423}
424
425static void uvd_v6_0_set_uvd_dynamic_clock_mode(struct amdgpu_device *adev,
426 bool swmode)
427{
428 u32 data, data1 = 0, data2;
429
430 /* Always un-gate UVD REGS bit */
431 data = RREG32(mmUVD_CGC_GATE);
432 data &= ~(UVD_CGC_GATE__REGS_MASK);
433 WREG32(mmUVD_CGC_GATE, data);
434
435 data = RREG32(mmUVD_CGC_CTRL);
436 data &= ~(UVD_CGC_CTRL__CLK_OFF_DELAY_MASK |
437 UVD_CGC_CTRL__CLK_GATE_DLY_TIMER_MASK);
438 data |= UVD_CGC_CTRL__DYN_CLOCK_MODE_MASK |
439 1 << REG_FIELD_SHIFT(UVD_CGC_CTRL, CLK_GATE_DLY_TIMER) |
440 4 << REG_FIELD_SHIFT(UVD_CGC_CTRL, CLK_OFF_DELAY);
441
442 data2 = RREG32(mmUVD_SUVD_CGC_CTRL);
443 if (swmode) {
444 data &= ~(UVD_CGC_CTRL__UDEC_RE_MODE_MASK |
445 UVD_CGC_CTRL__UDEC_CM_MODE_MASK |
446 UVD_CGC_CTRL__UDEC_IT_MODE_MASK |
447 UVD_CGC_CTRL__UDEC_DB_MODE_MASK |
448 UVD_CGC_CTRL__UDEC_MP_MODE_MASK |
449 UVD_CGC_CTRL__SYS_MODE_MASK |
450 UVD_CGC_CTRL__UDEC_MODE_MASK |
451 UVD_CGC_CTRL__MPEG2_MODE_MASK |
452 UVD_CGC_CTRL__REGS_MODE_MASK |
453 UVD_CGC_CTRL__RBC_MODE_MASK |
454 UVD_CGC_CTRL__LMI_MC_MODE_MASK |
455 UVD_CGC_CTRL__LMI_UMC_MODE_MASK |
456 UVD_CGC_CTRL__IDCT_MODE_MASK |
457 UVD_CGC_CTRL__MPRD_MODE_MASK |
458 UVD_CGC_CTRL__MPC_MODE_MASK |
459 UVD_CGC_CTRL__LBSI_MODE_MASK |
460 UVD_CGC_CTRL__LRBBM_MODE_MASK |
461 UVD_CGC_CTRL__WCB_MODE_MASK |
462 UVD_CGC_CTRL__VCPU_MODE_MASK |
463 UVD_CGC_CTRL__JPEG_MODE_MASK |
464 UVD_CGC_CTRL__SCPU_MODE_MASK);
465 data1 |= UVD_CGC_CTRL2__DYN_OCLK_RAMP_EN_MASK |
466 UVD_CGC_CTRL2__DYN_RCLK_RAMP_EN_MASK;
467 data1 &= ~UVD_CGC_CTRL2__GATER_DIV_ID_MASK;
468 data1 |= 7 << REG_FIELD_SHIFT(UVD_CGC_CTRL2, GATER_DIV_ID);
469 data2 &= ~(UVD_SUVD_CGC_CTRL__SRE_MODE_MASK |
470 UVD_SUVD_CGC_CTRL__SIT_MODE_MASK |
471 UVD_SUVD_CGC_CTRL__SMP_MODE_MASK |
472 UVD_SUVD_CGC_CTRL__SCM_MODE_MASK |
473 UVD_SUVD_CGC_CTRL__SDB_MODE_MASK);
474 } else {
475 data |= UVD_CGC_CTRL__UDEC_RE_MODE_MASK |
476 UVD_CGC_CTRL__UDEC_CM_MODE_MASK |
477 UVD_CGC_CTRL__UDEC_IT_MODE_MASK |
478 UVD_CGC_CTRL__UDEC_DB_MODE_MASK |
479 UVD_CGC_CTRL__UDEC_MP_MODE_MASK |
480 UVD_CGC_CTRL__SYS_MODE_MASK |
481 UVD_CGC_CTRL__UDEC_MODE_MASK |
482 UVD_CGC_CTRL__MPEG2_MODE_MASK |
483 UVD_CGC_CTRL__REGS_MODE_MASK |
484 UVD_CGC_CTRL__RBC_MODE_MASK |
485 UVD_CGC_CTRL__LMI_MC_MODE_MASK |
486 UVD_CGC_CTRL__LMI_UMC_MODE_MASK |
487 UVD_CGC_CTRL__IDCT_MODE_MASK |
488 UVD_CGC_CTRL__MPRD_MODE_MASK |
489 UVD_CGC_CTRL__MPC_MODE_MASK |
490 UVD_CGC_CTRL__LBSI_MODE_MASK |
491 UVD_CGC_CTRL__LRBBM_MODE_MASK |
492 UVD_CGC_CTRL__WCB_MODE_MASK |
493 UVD_CGC_CTRL__VCPU_MODE_MASK |
494 UVD_CGC_CTRL__SCPU_MODE_MASK;
495 data2 |= UVD_SUVD_CGC_CTRL__SRE_MODE_MASK |
496 UVD_SUVD_CGC_CTRL__SIT_MODE_MASK |
497 UVD_SUVD_CGC_CTRL__SMP_MODE_MASK |
498 UVD_SUVD_CGC_CTRL__SCM_MODE_MASK |
499 UVD_SUVD_CGC_CTRL__SDB_MODE_MASK;
500 }
501 WREG32(mmUVD_CGC_CTRL, data);
502 WREG32(mmUVD_SUVD_CGC_CTRL, data2);
503
504 data = RREG32_UVD_CTX(ixUVD_CGC_CTRL2);
505 data &= ~(REG_FIELD_MASK(UVD_CGC_CTRL2, DYN_OCLK_RAMP_EN) |
506 REG_FIELD_MASK(UVD_CGC_CTRL2, DYN_RCLK_RAMP_EN) |
507 REG_FIELD_MASK(UVD_CGC_CTRL2, GATER_DIV_ID));
508 data1 &= (REG_FIELD_MASK(UVD_CGC_CTRL2, DYN_OCLK_RAMP_EN) |
509 REG_FIELD_MASK(UVD_CGC_CTRL2, DYN_RCLK_RAMP_EN) |
510 REG_FIELD_MASK(UVD_CGC_CTRL2, GATER_DIV_ID));
511 data |= data1;
512 WREG32_UVD_CTX(ixUVD_CGC_CTRL2, data);
513}
514 372
515/** 373/**
516 * uvd_v6_0_start - start UVD block 374 * uvd_v6_0_start - start UVD block
@@ -538,11 +396,7 @@ static int uvd_v6_0_start(struct amdgpu_device *adev)
538 396
539 /* Set dynamic clock gating in S/W control mode */ 397 /* Set dynamic clock gating in S/W control mode */
540 if (adev->cg_flags & AMD_CG_SUPPORT_UVD_MGCG) { 398 if (adev->cg_flags & AMD_CG_SUPPORT_UVD_MGCG) {
541 if (adev->flags & AMD_IS_APU) 399 uvd_v6_0_set_sw_clock_gating(adev);
542 cz_set_uvd_clock_gating_branches(adev, false);
543 else
544 tonga_set_uvd_clock_gating_branches(adev, false);
545 uvd_v6_0_set_uvd_dynamic_clock_mode(adev, true);
546 } else { 400 } else {
547 /* disable clock gating */ 401 /* disable clock gating */
548 uint32_t data = RREG32(mmUVD_CGC_CTRL); 402 uint32_t data = RREG32(mmUVD_CGC_CTRL);
@@ -854,112 +708,6 @@ static int uvd_v6_0_soft_reset(void *handle)
854 return uvd_v6_0_start(adev); 708 return uvd_v6_0_start(adev);
855} 709}
856 710
857static void uvd_v6_0_print_status(void *handle)
858{
859 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
860 dev_info(adev->dev, "UVD 6.0 registers\n");
861 dev_info(adev->dev, " UVD_SEMA_ADDR_LOW=0x%08X\n",
862 RREG32(mmUVD_SEMA_ADDR_LOW));
863 dev_info(adev->dev, " UVD_SEMA_ADDR_HIGH=0x%08X\n",
864 RREG32(mmUVD_SEMA_ADDR_HIGH));
865 dev_info(adev->dev, " UVD_SEMA_CMD=0x%08X\n",
866 RREG32(mmUVD_SEMA_CMD));
867 dev_info(adev->dev, " UVD_GPCOM_VCPU_CMD=0x%08X\n",
868 RREG32(mmUVD_GPCOM_VCPU_CMD));
869 dev_info(adev->dev, " UVD_GPCOM_VCPU_DATA0=0x%08X\n",
870 RREG32(mmUVD_GPCOM_VCPU_DATA0));
871 dev_info(adev->dev, " UVD_GPCOM_VCPU_DATA1=0x%08X\n",
872 RREG32(mmUVD_GPCOM_VCPU_DATA1));
873 dev_info(adev->dev, " UVD_ENGINE_CNTL=0x%08X\n",
874 RREG32(mmUVD_ENGINE_CNTL));
875 dev_info(adev->dev, " UVD_UDEC_ADDR_CONFIG=0x%08X\n",
876 RREG32(mmUVD_UDEC_ADDR_CONFIG));
877 dev_info(adev->dev, " UVD_UDEC_DB_ADDR_CONFIG=0x%08X\n",
878 RREG32(mmUVD_UDEC_DB_ADDR_CONFIG));
879 dev_info(adev->dev, " UVD_UDEC_DBW_ADDR_CONFIG=0x%08X\n",
880 RREG32(mmUVD_UDEC_DBW_ADDR_CONFIG));
881 dev_info(adev->dev, " UVD_SEMA_CNTL=0x%08X\n",
882 RREG32(mmUVD_SEMA_CNTL));
883 dev_info(adev->dev, " UVD_LMI_EXT40_ADDR=0x%08X\n",
884 RREG32(mmUVD_LMI_EXT40_ADDR));
885 dev_info(adev->dev, " UVD_CTX_INDEX=0x%08X\n",
886 RREG32(mmUVD_CTX_INDEX));
887 dev_info(adev->dev, " UVD_CTX_DATA=0x%08X\n",
888 RREG32(mmUVD_CTX_DATA));
889 dev_info(adev->dev, " UVD_CGC_GATE=0x%08X\n",
890 RREG32(mmUVD_CGC_GATE));
891 dev_info(adev->dev, " UVD_CGC_CTRL=0x%08X\n",
892 RREG32(mmUVD_CGC_CTRL));
893 dev_info(adev->dev, " UVD_LMI_CTRL2=0x%08X\n",
894 RREG32(mmUVD_LMI_CTRL2));
895 dev_info(adev->dev, " UVD_MASTINT_EN=0x%08X\n",
896 RREG32(mmUVD_MASTINT_EN));
897 dev_info(adev->dev, " UVD_LMI_ADDR_EXT=0x%08X\n",
898 RREG32(mmUVD_LMI_ADDR_EXT));
899 dev_info(adev->dev, " UVD_LMI_CTRL=0x%08X\n",
900 RREG32(mmUVD_LMI_CTRL));
901 dev_info(adev->dev, " UVD_LMI_SWAP_CNTL=0x%08X\n",
902 RREG32(mmUVD_LMI_SWAP_CNTL));
903 dev_info(adev->dev, " UVD_MP_SWAP_CNTL=0x%08X\n",
904 RREG32(mmUVD_MP_SWAP_CNTL));
905 dev_info(adev->dev, " UVD_MPC_SET_MUXA0=0x%08X\n",
906 RREG32(mmUVD_MPC_SET_MUXA0));
907 dev_info(adev->dev, " UVD_MPC_SET_MUXA1=0x%08X\n",
908 RREG32(mmUVD_MPC_SET_MUXA1));
909 dev_info(adev->dev, " UVD_MPC_SET_MUXB0=0x%08X\n",
910 RREG32(mmUVD_MPC_SET_MUXB0));
911 dev_info(adev->dev, " UVD_MPC_SET_MUXB1=0x%08X\n",
912 RREG32(mmUVD_MPC_SET_MUXB1));
913 dev_info(adev->dev, " UVD_MPC_SET_MUX=0x%08X\n",
914 RREG32(mmUVD_MPC_SET_MUX));
915 dev_info(adev->dev, " UVD_MPC_SET_ALU=0x%08X\n",
916 RREG32(mmUVD_MPC_SET_ALU));
917 dev_info(adev->dev, " UVD_VCPU_CACHE_OFFSET0=0x%08X\n",
918 RREG32(mmUVD_VCPU_CACHE_OFFSET0));
919 dev_info(adev->dev, " UVD_VCPU_CACHE_SIZE0=0x%08X\n",
920 RREG32(mmUVD_VCPU_CACHE_SIZE0));
921 dev_info(adev->dev, " UVD_VCPU_CACHE_OFFSET1=0x%08X\n",
922 RREG32(mmUVD_VCPU_CACHE_OFFSET1));
923 dev_info(adev->dev, " UVD_VCPU_CACHE_SIZE1=0x%08X\n",
924 RREG32(mmUVD_VCPU_CACHE_SIZE1));
925 dev_info(adev->dev, " UVD_VCPU_CACHE_OFFSET2=0x%08X\n",
926 RREG32(mmUVD_VCPU_CACHE_OFFSET2));
927 dev_info(adev->dev, " UVD_VCPU_CACHE_SIZE2=0x%08X\n",
928 RREG32(mmUVD_VCPU_CACHE_SIZE2));
929 dev_info(adev->dev, " UVD_VCPU_CNTL=0x%08X\n",
930 RREG32(mmUVD_VCPU_CNTL));
931 dev_info(adev->dev, " UVD_SOFT_RESET=0x%08X\n",
932 RREG32(mmUVD_SOFT_RESET));
933 dev_info(adev->dev, " UVD_RBC_IB_SIZE=0x%08X\n",
934 RREG32(mmUVD_RBC_IB_SIZE));
935 dev_info(adev->dev, " UVD_RBC_RB_RPTR=0x%08X\n",
936 RREG32(mmUVD_RBC_RB_RPTR));
937 dev_info(adev->dev, " UVD_RBC_RB_WPTR=0x%08X\n",
938 RREG32(mmUVD_RBC_RB_WPTR));
939 dev_info(adev->dev, " UVD_RBC_RB_WPTR_CNTL=0x%08X\n",
940 RREG32(mmUVD_RBC_RB_WPTR_CNTL));
941 dev_info(adev->dev, " UVD_RBC_RB_CNTL=0x%08X\n",
942 RREG32(mmUVD_RBC_RB_CNTL));
943 dev_info(adev->dev, " UVD_STATUS=0x%08X\n",
944 RREG32(mmUVD_STATUS));
945 dev_info(adev->dev, " UVD_SEMA_TIMEOUT_STATUS=0x%08X\n",
946 RREG32(mmUVD_SEMA_TIMEOUT_STATUS));
947 dev_info(adev->dev, " UVD_SEMA_WAIT_INCOMPLETE_TIMEOUT_CNTL=0x%08X\n",
948 RREG32(mmUVD_SEMA_WAIT_INCOMPLETE_TIMEOUT_CNTL));
949 dev_info(adev->dev, " UVD_SEMA_WAIT_FAULT_TIMEOUT_CNTL=0x%08X\n",
950 RREG32(mmUVD_SEMA_WAIT_FAULT_TIMEOUT_CNTL));
951 dev_info(adev->dev, " UVD_SEMA_SIGNAL_INCOMPLETE_TIMEOUT_CNTL=0x%08X\n",
952 RREG32(mmUVD_SEMA_SIGNAL_INCOMPLETE_TIMEOUT_CNTL));
953 dev_info(adev->dev, " UVD_CONTEXT_ID=0x%08X\n",
954 RREG32(mmUVD_CONTEXT_ID));
955 dev_info(adev->dev, " UVD_UDEC_ADDR_CONFIG=0x%08X\n",
956 RREG32(mmUVD_UDEC_ADDR_CONFIG));
957 dev_info(adev->dev, " UVD_UDEC_DB_ADDR_CONFIG=0x%08X\n",
958 RREG32(mmUVD_UDEC_DB_ADDR_CONFIG));
959 dev_info(adev->dev, " UVD_UDEC_DBW_ADDR_CONFIG=0x%08X\n",
960 RREG32(mmUVD_UDEC_DBW_ADDR_CONFIG));
961}
962
963static int uvd_v6_0_set_interrupt_state(struct amdgpu_device *adev, 711static int uvd_v6_0_set_interrupt_state(struct amdgpu_device *adev,
964 struct amdgpu_irq_src *source, 712 struct amdgpu_irq_src *source,
965 unsigned type, 713 unsigned type,
@@ -978,25 +726,146 @@ static int uvd_v6_0_process_interrupt(struct amdgpu_device *adev,
978 return 0; 726 return 0;
979} 727}
980 728
729static void uvd_v6_0_set_sw_clock_gating(struct amdgpu_device *adev)
730{
731 uint32_t data, data1, data2, suvd_flags;
732
733 data = RREG32(mmUVD_CGC_CTRL);
734 data1 = RREG32(mmUVD_SUVD_CGC_GATE);
735 data2 = RREG32(mmUVD_SUVD_CGC_CTRL);
736
737 data &= ~(UVD_CGC_CTRL__CLK_OFF_DELAY_MASK |
738 UVD_CGC_CTRL__CLK_GATE_DLY_TIMER_MASK);
739
740 suvd_flags = UVD_SUVD_CGC_GATE__SRE_MASK |
741 UVD_SUVD_CGC_GATE__SIT_MASK |
742 UVD_SUVD_CGC_GATE__SMP_MASK |
743 UVD_SUVD_CGC_GATE__SCM_MASK |
744 UVD_SUVD_CGC_GATE__SDB_MASK;
745
746 data |= UVD_CGC_CTRL__DYN_CLOCK_MODE_MASK |
747 (1 << REG_FIELD_SHIFT(UVD_CGC_CTRL, CLK_GATE_DLY_TIMER)) |
748 (4 << REG_FIELD_SHIFT(UVD_CGC_CTRL, CLK_OFF_DELAY));
749
750 data &= ~(UVD_CGC_CTRL__UDEC_RE_MODE_MASK |
751 UVD_CGC_CTRL__UDEC_CM_MODE_MASK |
752 UVD_CGC_CTRL__UDEC_IT_MODE_MASK |
753 UVD_CGC_CTRL__UDEC_DB_MODE_MASK |
754 UVD_CGC_CTRL__UDEC_MP_MODE_MASK |
755 UVD_CGC_CTRL__SYS_MODE_MASK |
756 UVD_CGC_CTRL__UDEC_MODE_MASK |
757 UVD_CGC_CTRL__MPEG2_MODE_MASK |
758 UVD_CGC_CTRL__REGS_MODE_MASK |
759 UVD_CGC_CTRL__RBC_MODE_MASK |
760 UVD_CGC_CTRL__LMI_MC_MODE_MASK |
761 UVD_CGC_CTRL__LMI_UMC_MODE_MASK |
762 UVD_CGC_CTRL__IDCT_MODE_MASK |
763 UVD_CGC_CTRL__MPRD_MODE_MASK |
764 UVD_CGC_CTRL__MPC_MODE_MASK |
765 UVD_CGC_CTRL__LBSI_MODE_MASK |
766 UVD_CGC_CTRL__LRBBM_MODE_MASK |
767 UVD_CGC_CTRL__WCB_MODE_MASK |
768 UVD_CGC_CTRL__VCPU_MODE_MASK |
769 UVD_CGC_CTRL__JPEG_MODE_MASK |
770 UVD_CGC_CTRL__SCPU_MODE_MASK |
771 UVD_CGC_CTRL__JPEG2_MODE_MASK);
772 data2 &= ~(UVD_SUVD_CGC_CTRL__SRE_MODE_MASK |
773 UVD_SUVD_CGC_CTRL__SIT_MODE_MASK |
774 UVD_SUVD_CGC_CTRL__SMP_MODE_MASK |
775 UVD_SUVD_CGC_CTRL__SCM_MODE_MASK |
776 UVD_SUVD_CGC_CTRL__SDB_MODE_MASK);
777 data1 |= suvd_flags;
778
779 WREG32(mmUVD_CGC_CTRL, data);
780 WREG32(mmUVD_CGC_GATE, 0);
781 WREG32(mmUVD_SUVD_CGC_GATE, data1);
782 WREG32(mmUVD_SUVD_CGC_CTRL, data2);
783}
784
785#if 0
786static void uvd_v6_0_set_hw_clock_gating(struct amdgpu_device *adev)
787{
788 uint32_t data, data1, cgc_flags, suvd_flags;
789
790 data = RREG32(mmUVD_CGC_GATE);
791 data1 = RREG32(mmUVD_SUVD_CGC_GATE);
792
793 cgc_flags = UVD_CGC_GATE__SYS_MASK |
794 UVD_CGC_GATE__UDEC_MASK |
795 UVD_CGC_GATE__MPEG2_MASK |
796 UVD_CGC_GATE__RBC_MASK |
797 UVD_CGC_GATE__LMI_MC_MASK |
798 UVD_CGC_GATE__IDCT_MASK |
799 UVD_CGC_GATE__MPRD_MASK |
800 UVD_CGC_GATE__MPC_MASK |
801 UVD_CGC_GATE__LBSI_MASK |
802 UVD_CGC_GATE__LRBBM_MASK |
803 UVD_CGC_GATE__UDEC_RE_MASK |
804 UVD_CGC_GATE__UDEC_CM_MASK |
805 UVD_CGC_GATE__UDEC_IT_MASK |
806 UVD_CGC_GATE__UDEC_DB_MASK |
807 UVD_CGC_GATE__UDEC_MP_MASK |
808 UVD_CGC_GATE__WCB_MASK |
809 UVD_CGC_GATE__VCPU_MASK |
810 UVD_CGC_GATE__SCPU_MASK |
811 UVD_CGC_GATE__JPEG_MASK |
812 UVD_CGC_GATE__JPEG2_MASK;
813
814 suvd_flags = UVD_SUVD_CGC_GATE__SRE_MASK |
815 UVD_SUVD_CGC_GATE__SIT_MASK |
816 UVD_SUVD_CGC_GATE__SMP_MASK |
817 UVD_SUVD_CGC_GATE__SCM_MASK |
818 UVD_SUVD_CGC_GATE__SDB_MASK;
819
820 data |= cgc_flags;
821 data1 |= suvd_flags;
822
823 WREG32(mmUVD_CGC_GATE, data);
824 WREG32(mmUVD_SUVD_CGC_GATE, data1);
825}
826#endif
827
828static void uvd_v6_set_bypass_mode(struct amdgpu_device *adev, bool enable)
829{
830 u32 tmp = RREG32_SMC(ixGCK_DFS_BYPASS_CNTL);
831
832 if (enable)
833 tmp |= (GCK_DFS_BYPASS_CNTL__BYPASSDCLK_MASK |
834 GCK_DFS_BYPASS_CNTL__BYPASSVCLK_MASK);
835 else
836 tmp &= ~(GCK_DFS_BYPASS_CNTL__BYPASSDCLK_MASK |
837 GCK_DFS_BYPASS_CNTL__BYPASSVCLK_MASK);
838
839 WREG32_SMC(ixGCK_DFS_BYPASS_CNTL, tmp);
840}
841
981static int uvd_v6_0_set_clockgating_state(void *handle, 842static int uvd_v6_0_set_clockgating_state(void *handle,
982 enum amd_clockgating_state state) 843 enum amd_clockgating_state state)
983{ 844{
984 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 845 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
985 bool enable = (state == AMD_CG_STATE_GATE) ? true : false; 846 bool enable = (state == AMD_CG_STATE_GATE) ? true : false;
847 static int curstate = -1;
848
849 if (adev->asic_type == CHIP_FIJI)
850 uvd_v6_set_bypass_mode(adev, enable);
986 851
987 if (!(adev->cg_flags & AMD_CG_SUPPORT_UVD_MGCG)) 852 if (!(adev->cg_flags & AMD_CG_SUPPORT_UVD_MGCG))
988 return 0; 853 return 0;
989 854
855 if (curstate == state)
856 return 0;
857
858 curstate = state;
990 if (enable) { 859 if (enable) {
991 if (adev->flags & AMD_IS_APU) 860 /* disable HW gating and enable Sw gating */
992 cz_set_uvd_clock_gating_branches(adev, enable); 861 uvd_v6_0_set_sw_clock_gating(adev);
993 else
994 tonga_set_uvd_clock_gating_branches(adev, enable);
995 uvd_v6_0_set_uvd_dynamic_clock_mode(adev, true);
996 } else { 862 } else {
997 uint32_t data = RREG32(mmUVD_CGC_CTRL); 863 /* wait for STATUS to clear */
998 data &= ~UVD_CGC_CTRL__DYN_CLOCK_MODE_MASK; 864 if (uvd_v6_0_wait_for_idle(handle))
999 WREG32(mmUVD_CGC_CTRL, data); 865 return -EBUSY;
866
867 /* enable HW gates because UVD is idle */
868/* uvd_v6_0_set_hw_clock_gating(adev); */
1000 } 869 }
1001 870
1002 return 0; 871 return 0;
@@ -1037,7 +906,6 @@ const struct amd_ip_funcs uvd_v6_0_ip_funcs = {
1037 .is_idle = uvd_v6_0_is_idle, 906 .is_idle = uvd_v6_0_is_idle,
1038 .wait_for_idle = uvd_v6_0_wait_for_idle, 907 .wait_for_idle = uvd_v6_0_wait_for_idle,
1039 .soft_reset = uvd_v6_0_soft_reset, 908 .soft_reset = uvd_v6_0_soft_reset,
1040 .print_status = uvd_v6_0_print_status,
1041 .set_clockgating_state = uvd_v6_0_set_clockgating_state, 909 .set_clockgating_state = uvd_v6_0_set_clockgating_state,
1042 .set_powergating_state = uvd_v6_0_set_powergating_state, 910 .set_powergating_state = uvd_v6_0_set_powergating_state,
1043}; 911};
diff --git a/drivers/gpu/drm/amd/amdgpu/vce_v2_0.c b/drivers/gpu/drm/amd/amdgpu/vce_v2_0.c
index c7e885bcfd41..95f6e579427d 100644
--- a/drivers/gpu/drm/amd/amdgpu/vce_v2_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/vce_v2_0.c
@@ -44,7 +44,7 @@
44static void vce_v2_0_mc_resume(struct amdgpu_device *adev); 44static void vce_v2_0_mc_resume(struct amdgpu_device *adev);
45static void vce_v2_0_set_ring_funcs(struct amdgpu_device *adev); 45static void vce_v2_0_set_ring_funcs(struct amdgpu_device *adev);
46static void vce_v2_0_set_irq_funcs(struct amdgpu_device *adev); 46static void vce_v2_0_set_irq_funcs(struct amdgpu_device *adev);
47 47static int vce_v2_0_wait_for_idle(void *handle);
48/** 48/**
49 * vce_v2_0_ring_get_rptr - get read pointer 49 * vce_v2_0_ring_get_rptr - get read pointer
50 * 50 *
@@ -201,14 +201,14 @@ static int vce_v2_0_sw_init(void *handle)
201 201
202 ring = &adev->vce.ring[0]; 202 ring = &adev->vce.ring[0];
203 sprintf(ring->name, "vce0"); 203 sprintf(ring->name, "vce0");
204 r = amdgpu_ring_init(adev, ring, 4096, VCE_CMD_NO_OP, 0xf, 204 r = amdgpu_ring_init(adev, ring, 512, VCE_CMD_NO_OP, 0xf,
205 &adev->vce.irq, 0, AMDGPU_RING_TYPE_VCE); 205 &adev->vce.irq, 0, AMDGPU_RING_TYPE_VCE);
206 if (r) 206 if (r)
207 return r; 207 return r;
208 208
209 ring = &adev->vce.ring[1]; 209 ring = &adev->vce.ring[1];
210 sprintf(ring->name, "vce1"); 210 sprintf(ring->name, "vce1");
211 r = amdgpu_ring_init(adev, ring, 4096, VCE_CMD_NO_OP, 0xf, 211 r = amdgpu_ring_init(adev, ring, 512, VCE_CMD_NO_OP, 0xf,
212 &adev->vce.irq, 0, AMDGPU_RING_TYPE_VCE); 212 &adev->vce.irq, 0, AMDGPU_RING_TYPE_VCE);
213 if (r) 213 if (r)
214 return r; 214 return r;
@@ -240,7 +240,8 @@ static int vce_v2_0_hw_init(void *handle)
240 240
241 r = vce_v2_0_start(adev); 241 r = vce_v2_0_start(adev);
242 if (r) 242 if (r)
243 return r; 243/* this error mean vcpu not in running state, so just skip ring test, not stop driver initialize */
244 return 0;
244 245
245 ring = &adev->vce.ring[0]; 246 ring = &adev->vce.ring[0];
246 ring->ready = true; 247 ring->ready = true;
@@ -318,7 +319,7 @@ static void vce_v2_0_set_sw_cg(struct amdgpu_device *adev, bool gated)
318 WREG32(mmVCE_UENC_REG_CLOCK_GATING, tmp); 319 WREG32(mmVCE_UENC_REG_CLOCK_GATING, tmp);
319 320
320 WREG32(mmVCE_CGTT_CLK_OVERRIDE, 0); 321 WREG32(mmVCE_CGTT_CLK_OVERRIDE, 0);
321 } else { 322 } else {
322 tmp = RREG32(mmVCE_CLOCK_GATING_B); 323 tmp = RREG32(mmVCE_CLOCK_GATING_B);
323 tmp |= 0xe7; 324 tmp |= 0xe7;
324 tmp &= ~0xe70000; 325 tmp &= ~0xe70000;
@@ -339,6 +340,21 @@ static void vce_v2_0_set_dyn_cg(struct amdgpu_device *adev, bool gated)
339{ 340{
340 u32 orig, tmp; 341 u32 orig, tmp;
341 342
343 if (gated) {
344 if (vce_v2_0_wait_for_idle(adev)) {
345 DRM_INFO("VCE is busy, Can't set clock gateing");
346 return;
347 }
348 WREG32_P(mmVCE_VCPU_CNTL, 0, ~VCE_VCPU_CNTL__CLK_EN_MASK);
349 WREG32_P(mmVCE_SOFT_RESET, VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK, ~VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK);
350 mdelay(100);
351 WREG32(mmVCE_STATUS, 0);
352 } else {
353 WREG32_P(mmVCE_VCPU_CNTL, VCE_VCPU_CNTL__CLK_EN_MASK, ~VCE_VCPU_CNTL__CLK_EN_MASK);
354 WREG32_P(mmVCE_SOFT_RESET, VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK, ~VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK);
355 mdelay(100);
356 }
357
342 tmp = RREG32(mmVCE_CLOCK_GATING_B); 358 tmp = RREG32(mmVCE_CLOCK_GATING_B);
343 tmp &= ~0x00060006; 359 tmp &= ~0x00060006;
344 if (gated) { 360 if (gated) {
@@ -362,6 +378,7 @@ static void vce_v2_0_set_dyn_cg(struct amdgpu_device *adev, bool gated)
362 378
363 if (gated) 379 if (gated)
364 WREG32(mmVCE_CGTT_CLK_OVERRIDE, 0); 380 WREG32(mmVCE_CGTT_CLK_OVERRIDE, 0);
381 WREG32_P(mmVCE_SOFT_RESET, 0, ~VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK);
365} 382}
366 383
367static void vce_v2_0_disable_cg(struct amdgpu_device *adev) 384static void vce_v2_0_disable_cg(struct amdgpu_device *adev)
@@ -478,75 +495,6 @@ static int vce_v2_0_soft_reset(void *handle)
478 return vce_v2_0_start(adev); 495 return vce_v2_0_start(adev);
479} 496}
480 497
481static void vce_v2_0_print_status(void *handle)
482{
483 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
484
485 dev_info(adev->dev, "VCE 2.0 registers\n");
486 dev_info(adev->dev, " VCE_STATUS=0x%08X\n",
487 RREG32(mmVCE_STATUS));
488 dev_info(adev->dev, " VCE_VCPU_CNTL=0x%08X\n",
489 RREG32(mmVCE_VCPU_CNTL));
490 dev_info(adev->dev, " VCE_VCPU_CACHE_OFFSET0=0x%08X\n",
491 RREG32(mmVCE_VCPU_CACHE_OFFSET0));
492 dev_info(adev->dev, " VCE_VCPU_CACHE_SIZE0=0x%08X\n",
493 RREG32(mmVCE_VCPU_CACHE_SIZE0));
494 dev_info(adev->dev, " VCE_VCPU_CACHE_OFFSET1=0x%08X\n",
495 RREG32(mmVCE_VCPU_CACHE_OFFSET1));
496 dev_info(adev->dev, " VCE_VCPU_CACHE_SIZE1=0x%08X\n",
497 RREG32(mmVCE_VCPU_CACHE_SIZE1));
498 dev_info(adev->dev, " VCE_VCPU_CACHE_OFFSET2=0x%08X\n",
499 RREG32(mmVCE_VCPU_CACHE_OFFSET2));
500 dev_info(adev->dev, " VCE_VCPU_CACHE_SIZE2=0x%08X\n",
501 RREG32(mmVCE_VCPU_CACHE_SIZE2));
502 dev_info(adev->dev, " VCE_SOFT_RESET=0x%08X\n",
503 RREG32(mmVCE_SOFT_RESET));
504 dev_info(adev->dev, " VCE_RB_BASE_LO2=0x%08X\n",
505 RREG32(mmVCE_RB_BASE_LO2));
506 dev_info(adev->dev, " VCE_RB_BASE_HI2=0x%08X\n",
507 RREG32(mmVCE_RB_BASE_HI2));
508 dev_info(adev->dev, " VCE_RB_SIZE2=0x%08X\n",
509 RREG32(mmVCE_RB_SIZE2));
510 dev_info(adev->dev, " VCE_RB_RPTR2=0x%08X\n",
511 RREG32(mmVCE_RB_RPTR2));
512 dev_info(adev->dev, " VCE_RB_WPTR2=0x%08X\n",
513 RREG32(mmVCE_RB_WPTR2));
514 dev_info(adev->dev, " VCE_RB_BASE_LO=0x%08X\n",
515 RREG32(mmVCE_RB_BASE_LO));
516 dev_info(adev->dev, " VCE_RB_BASE_HI=0x%08X\n",
517 RREG32(mmVCE_RB_BASE_HI));
518 dev_info(adev->dev, " VCE_RB_SIZE=0x%08X\n",
519 RREG32(mmVCE_RB_SIZE));
520 dev_info(adev->dev, " VCE_RB_RPTR=0x%08X\n",
521 RREG32(mmVCE_RB_RPTR));
522 dev_info(adev->dev, " VCE_RB_WPTR=0x%08X\n",
523 RREG32(mmVCE_RB_WPTR));
524 dev_info(adev->dev, " VCE_CLOCK_GATING_A=0x%08X\n",
525 RREG32(mmVCE_CLOCK_GATING_A));
526 dev_info(adev->dev, " VCE_CLOCK_GATING_B=0x%08X\n",
527 RREG32(mmVCE_CLOCK_GATING_B));
528 dev_info(adev->dev, " VCE_CGTT_CLK_OVERRIDE=0x%08X\n",
529 RREG32(mmVCE_CGTT_CLK_OVERRIDE));
530 dev_info(adev->dev, " VCE_UENC_CLOCK_GATING=0x%08X\n",
531 RREG32(mmVCE_UENC_CLOCK_GATING));
532 dev_info(adev->dev, " VCE_UENC_REG_CLOCK_GATING=0x%08X\n",
533 RREG32(mmVCE_UENC_REG_CLOCK_GATING));
534 dev_info(adev->dev, " VCE_SYS_INT_EN=0x%08X\n",
535 RREG32(mmVCE_SYS_INT_EN));
536 dev_info(adev->dev, " VCE_LMI_CTRL2=0x%08X\n",
537 RREG32(mmVCE_LMI_CTRL2));
538 dev_info(adev->dev, " VCE_LMI_CTRL=0x%08X\n",
539 RREG32(mmVCE_LMI_CTRL));
540 dev_info(adev->dev, " VCE_LMI_VM_CTRL=0x%08X\n",
541 RREG32(mmVCE_LMI_VM_CTRL));
542 dev_info(adev->dev, " VCE_LMI_SWAP_CNTL=0x%08X\n",
543 RREG32(mmVCE_LMI_SWAP_CNTL));
544 dev_info(adev->dev, " VCE_LMI_SWAP_CNTL1=0x%08X\n",
545 RREG32(mmVCE_LMI_SWAP_CNTL1));
546 dev_info(adev->dev, " VCE_LMI_CACHE_CTRL=0x%08X\n",
547 RREG32(mmVCE_LMI_CACHE_CTRL));
548}
549
550static int vce_v2_0_set_interrupt_state(struct amdgpu_device *adev, 498static int vce_v2_0_set_interrupt_state(struct amdgpu_device *adev,
551 struct amdgpu_irq_src *source, 499 struct amdgpu_irq_src *source,
552 unsigned type, 500 unsigned type,
@@ -630,7 +578,6 @@ const struct amd_ip_funcs vce_v2_0_ip_funcs = {
630 .is_idle = vce_v2_0_is_idle, 578 .is_idle = vce_v2_0_is_idle,
631 .wait_for_idle = vce_v2_0_wait_for_idle, 579 .wait_for_idle = vce_v2_0_wait_for_idle,
632 .soft_reset = vce_v2_0_soft_reset, 580 .soft_reset = vce_v2_0_soft_reset,
633 .print_status = vce_v2_0_print_status,
634 .set_clockgating_state = vce_v2_0_set_clockgating_state, 581 .set_clockgating_state = vce_v2_0_set_clockgating_state,
635 .set_powergating_state = vce_v2_0_set_powergating_state, 582 .set_powergating_state = vce_v2_0_set_powergating_state,
636}; 583};
diff --git a/drivers/gpu/drm/amd/amdgpu/vce_v3_0.c b/drivers/gpu/drm/amd/amdgpu/vce_v3_0.c
index ce468ee5da2a..e1d6ae7e1629 100644
--- a/drivers/gpu/drm/amd/amdgpu/vce_v3_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/vce_v3_0.c
@@ -315,9 +315,11 @@ static unsigned vce_v3_0_get_harvest_config(struct amdgpu_device *adev)
315{ 315{
316 u32 tmp; 316 u32 tmp;
317 317
318 /* Fiji, Stoney are single pipe */ 318 /* Fiji, Stoney, Polaris10, Polaris11 are single pipe */
319 if ((adev->asic_type == CHIP_FIJI) || 319 if ((adev->asic_type == CHIP_FIJI) ||
320 (adev->asic_type == CHIP_STONEY)) 320 (adev->asic_type == CHIP_STONEY) ||
321 (adev->asic_type == CHIP_POLARIS10) ||
322 (adev->asic_type == CHIP_POLARIS11))
321 return AMDGPU_VCE_HARVEST_VCE1; 323 return AMDGPU_VCE_HARVEST_VCE1;
322 324
323 /* Tonga and CZ are dual or single pipe */ 325 /* Tonga and CZ are dual or single pipe */
@@ -381,14 +383,14 @@ static int vce_v3_0_sw_init(void *handle)
381 383
382 ring = &adev->vce.ring[0]; 384 ring = &adev->vce.ring[0];
383 sprintf(ring->name, "vce0"); 385 sprintf(ring->name, "vce0");
384 r = amdgpu_ring_init(adev, ring, 4096, VCE_CMD_NO_OP, 0xf, 386 r = amdgpu_ring_init(adev, ring, 512, VCE_CMD_NO_OP, 0xf,
385 &adev->vce.irq, 0, AMDGPU_RING_TYPE_VCE); 387 &adev->vce.irq, 0, AMDGPU_RING_TYPE_VCE);
386 if (r) 388 if (r)
387 return r; 389 return r;
388 390
389 ring = &adev->vce.ring[1]; 391 ring = &adev->vce.ring[1];
390 sprintf(ring->name, "vce1"); 392 sprintf(ring->name, "vce1");
391 r = amdgpu_ring_init(adev, ring, 4096, VCE_CMD_NO_OP, 0xf, 393 r = amdgpu_ring_init(adev, ring, 512, VCE_CMD_NO_OP, 0xf,
392 &adev->vce.irq, 0, AMDGPU_RING_TYPE_VCE); 394 &adev->vce.irq, 0, AMDGPU_RING_TYPE_VCE);
393 if (r) 395 if (r)
394 return r; 396 return r;
@@ -564,73 +566,6 @@ static int vce_v3_0_soft_reset(void *handle)
564 return vce_v3_0_start(adev); 566 return vce_v3_0_start(adev);
565} 567}
566 568
567static void vce_v3_0_print_status(void *handle)
568{
569 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
570
571 dev_info(adev->dev, "VCE 3.0 registers\n");
572 dev_info(adev->dev, " VCE_STATUS=0x%08X\n",
573 RREG32(mmVCE_STATUS));
574 dev_info(adev->dev, " VCE_VCPU_CNTL=0x%08X\n",
575 RREG32(mmVCE_VCPU_CNTL));
576 dev_info(adev->dev, " VCE_VCPU_CACHE_OFFSET0=0x%08X\n",
577 RREG32(mmVCE_VCPU_CACHE_OFFSET0));
578 dev_info(adev->dev, " VCE_VCPU_CACHE_SIZE0=0x%08X\n",
579 RREG32(mmVCE_VCPU_CACHE_SIZE0));
580 dev_info(adev->dev, " VCE_VCPU_CACHE_OFFSET1=0x%08X\n",
581 RREG32(mmVCE_VCPU_CACHE_OFFSET1));
582 dev_info(adev->dev, " VCE_VCPU_CACHE_SIZE1=0x%08X\n",
583 RREG32(mmVCE_VCPU_CACHE_SIZE1));
584 dev_info(adev->dev, " VCE_VCPU_CACHE_OFFSET2=0x%08X\n",
585 RREG32(mmVCE_VCPU_CACHE_OFFSET2));
586 dev_info(adev->dev, " VCE_VCPU_CACHE_SIZE2=0x%08X\n",
587 RREG32(mmVCE_VCPU_CACHE_SIZE2));
588 dev_info(adev->dev, " VCE_SOFT_RESET=0x%08X\n",
589 RREG32(mmVCE_SOFT_RESET));
590 dev_info(adev->dev, " VCE_RB_BASE_LO2=0x%08X\n",
591 RREG32(mmVCE_RB_BASE_LO2));
592 dev_info(adev->dev, " VCE_RB_BASE_HI2=0x%08X\n",
593 RREG32(mmVCE_RB_BASE_HI2));
594 dev_info(adev->dev, " VCE_RB_SIZE2=0x%08X\n",
595 RREG32(mmVCE_RB_SIZE2));
596 dev_info(adev->dev, " VCE_RB_RPTR2=0x%08X\n",
597 RREG32(mmVCE_RB_RPTR2));
598 dev_info(adev->dev, " VCE_RB_WPTR2=0x%08X\n",
599 RREG32(mmVCE_RB_WPTR2));
600 dev_info(adev->dev, " VCE_RB_BASE_LO=0x%08X\n",
601 RREG32(mmVCE_RB_BASE_LO));
602 dev_info(adev->dev, " VCE_RB_BASE_HI=0x%08X\n",
603 RREG32(mmVCE_RB_BASE_HI));
604 dev_info(adev->dev, " VCE_RB_SIZE=0x%08X\n",
605 RREG32(mmVCE_RB_SIZE));
606 dev_info(adev->dev, " VCE_RB_RPTR=0x%08X\n",
607 RREG32(mmVCE_RB_RPTR));
608 dev_info(adev->dev, " VCE_RB_WPTR=0x%08X\n",
609 RREG32(mmVCE_RB_WPTR));
610 dev_info(adev->dev, " VCE_CLOCK_GATING_A=0x%08X\n",
611 RREG32(mmVCE_CLOCK_GATING_A));
612 dev_info(adev->dev, " VCE_CLOCK_GATING_B=0x%08X\n",
613 RREG32(mmVCE_CLOCK_GATING_B));
614 dev_info(adev->dev, " VCE_UENC_CLOCK_GATING=0x%08X\n",
615 RREG32(mmVCE_UENC_CLOCK_GATING));
616 dev_info(adev->dev, " VCE_UENC_REG_CLOCK_GATING=0x%08X\n",
617 RREG32(mmVCE_UENC_REG_CLOCK_GATING));
618 dev_info(adev->dev, " VCE_SYS_INT_EN=0x%08X\n",
619 RREG32(mmVCE_SYS_INT_EN));
620 dev_info(adev->dev, " VCE_LMI_CTRL2=0x%08X\n",
621 RREG32(mmVCE_LMI_CTRL2));
622 dev_info(adev->dev, " VCE_LMI_CTRL=0x%08X\n",
623 RREG32(mmVCE_LMI_CTRL));
624 dev_info(adev->dev, " VCE_LMI_VM_CTRL=0x%08X\n",
625 RREG32(mmVCE_LMI_VM_CTRL));
626 dev_info(adev->dev, " VCE_LMI_SWAP_CNTL=0x%08X\n",
627 RREG32(mmVCE_LMI_SWAP_CNTL));
628 dev_info(adev->dev, " VCE_LMI_SWAP_CNTL1=0x%08X\n",
629 RREG32(mmVCE_LMI_SWAP_CNTL1));
630 dev_info(adev->dev, " VCE_LMI_CACHE_CTRL=0x%08X\n",
631 RREG32(mmVCE_LMI_CACHE_CTRL));
632}
633
634static int vce_v3_0_set_interrupt_state(struct amdgpu_device *adev, 569static int vce_v3_0_set_interrupt_state(struct amdgpu_device *adev,
635 struct amdgpu_irq_src *source, 570 struct amdgpu_irq_src *source,
636 unsigned type, 571 unsigned type,
@@ -750,7 +685,6 @@ const struct amd_ip_funcs vce_v3_0_ip_funcs = {
750 .is_idle = vce_v3_0_is_idle, 685 .is_idle = vce_v3_0_is_idle,
751 .wait_for_idle = vce_v3_0_wait_for_idle, 686 .wait_for_idle = vce_v3_0_wait_for_idle,
752 .soft_reset = vce_v3_0_soft_reset, 687 .soft_reset = vce_v3_0_soft_reset,
753 .print_status = vce_v3_0_print_status,
754 .set_clockgating_state = vce_v3_0_set_clockgating_state, 688 .set_clockgating_state = vce_v3_0_set_clockgating_state,
755 .set_powergating_state = vce_v3_0_set_powergating_state, 689 .set_powergating_state = vce_v3_0_set_powergating_state,
756}; 690};
diff --git a/drivers/gpu/drm/amd/amdgpu/vi.c b/drivers/gpu/drm/amd/amdgpu/vi.c
index 1c120efa292c..340a166da911 100644
--- a/drivers/gpu/drm/amd/amdgpu/vi.c
+++ b/drivers/gpu/drm/amd/amdgpu/vi.c
@@ -78,6 +78,11 @@
78#include "amdgpu_acp.h" 78#include "amdgpu_acp.h"
79#endif 79#endif
80 80
81MODULE_FIRMWARE("amdgpu/polaris10_smc.bin");
82MODULE_FIRMWARE("amdgpu/polaris10_smc_sk.bin");
83MODULE_FIRMWARE("amdgpu/polaris11_smc.bin");
84MODULE_FIRMWARE("amdgpu/polaris11_smc_sk.bin");
85
81/* 86/*
82 * Indirect registers accessor 87 * Indirect registers accessor
83 */ 88 */
@@ -276,6 +281,8 @@ static void vi_init_golden_registers(struct amdgpu_device *adev)
276 stoney_mgcg_cgcg_init, 281 stoney_mgcg_cgcg_init,
277 (const u32)ARRAY_SIZE(stoney_mgcg_cgcg_init)); 282 (const u32)ARRAY_SIZE(stoney_mgcg_cgcg_init));
278 break; 283 break;
284 case CHIP_POLARIS11:
285 case CHIP_POLARIS10:
279 default: 286 default:
280 break; 287 break;
281 } 288 }
@@ -414,11 +421,11 @@ static bool vi_read_bios_from_rom(struct amdgpu_device *adev,
414 return true; 421 return true;
415} 422}
416 423
417static struct amdgpu_allowed_register_entry tonga_allowed_read_registers[] = { 424static const struct amdgpu_allowed_register_entry tonga_allowed_read_registers[] = {
418 {mmGB_MACROTILE_MODE7, true}, 425 {mmGB_MACROTILE_MODE7, true},
419}; 426};
420 427
421static struct amdgpu_allowed_register_entry cz_allowed_read_registers[] = { 428static const struct amdgpu_allowed_register_entry cz_allowed_read_registers[] = {
422 {mmGB_TILE_MODE7, true}, 429 {mmGB_TILE_MODE7, true},
423 {mmGB_TILE_MODE12, true}, 430 {mmGB_TILE_MODE12, true},
424 {mmGB_TILE_MODE17, true}, 431 {mmGB_TILE_MODE17, true},
@@ -426,7 +433,7 @@ static struct amdgpu_allowed_register_entry cz_allowed_read_registers[] = {
426 {mmGB_MACROTILE_MODE7, true}, 433 {mmGB_MACROTILE_MODE7, true},
427}; 434};
428 435
429static struct amdgpu_allowed_register_entry vi_allowed_read_registers[] = { 436static const struct amdgpu_allowed_register_entry vi_allowed_read_registers[] = {
430 {mmGRBM_STATUS, false}, 437 {mmGRBM_STATUS, false},
431 {mmGRBM_STATUS2, false}, 438 {mmGRBM_STATUS2, false},
432 {mmGRBM_STATUS_SE0, false}, 439 {mmGRBM_STATUS_SE0, false},
@@ -525,8 +532,8 @@ static uint32_t vi_read_indexed_register(struct amdgpu_device *adev, u32 se_num,
525static int vi_read_register(struct amdgpu_device *adev, u32 se_num, 532static int vi_read_register(struct amdgpu_device *adev, u32 se_num,
526 u32 sh_num, u32 reg_offset, u32 *value) 533 u32 sh_num, u32 reg_offset, u32 *value)
527{ 534{
528 struct amdgpu_allowed_register_entry *asic_register_table = NULL; 535 const struct amdgpu_allowed_register_entry *asic_register_table = NULL;
529 struct amdgpu_allowed_register_entry *asic_register_entry; 536 const struct amdgpu_allowed_register_entry *asic_register_entry;
530 uint32_t size, i; 537 uint32_t size, i;
531 538
532 *value = 0; 539 *value = 0;
@@ -537,6 +544,8 @@ static int vi_read_register(struct amdgpu_device *adev, u32 se_num,
537 break; 544 break;
538 case CHIP_FIJI: 545 case CHIP_FIJI:
539 case CHIP_TONGA: 546 case CHIP_TONGA:
547 case CHIP_POLARIS11:
548 case CHIP_POLARIS10:
540 case CHIP_CARRIZO: 549 case CHIP_CARRIZO:
541 case CHIP_STONEY: 550 case CHIP_STONEY:
542 asic_register_table = cz_allowed_read_registers; 551 asic_register_table = cz_allowed_read_registers;
@@ -907,6 +916,74 @@ static const struct amdgpu_ip_block_version fiji_ip_blocks[] =
907 }, 916 },
908}; 917};
909 918
919static const struct amdgpu_ip_block_version polaris11_ip_blocks[] =
920{
921 /* ORDER MATTERS! */
922 {
923 .type = AMD_IP_BLOCK_TYPE_COMMON,
924 .major = 2,
925 .minor = 0,
926 .rev = 0,
927 .funcs = &vi_common_ip_funcs,
928 },
929 {
930 .type = AMD_IP_BLOCK_TYPE_GMC,
931 .major = 8,
932 .minor = 1,
933 .rev = 0,
934 .funcs = &gmc_v8_0_ip_funcs,
935 },
936 {
937 .type = AMD_IP_BLOCK_TYPE_IH,
938 .major = 3,
939 .minor = 1,
940 .rev = 0,
941 .funcs = &tonga_ih_ip_funcs,
942 },
943 {
944 .type = AMD_IP_BLOCK_TYPE_SMC,
945 .major = 7,
946 .minor = 2,
947 .rev = 0,
948 .funcs = &amdgpu_pp_ip_funcs,
949 },
950 {
951 .type = AMD_IP_BLOCK_TYPE_DCE,
952 .major = 11,
953 .minor = 2,
954 .rev = 0,
955 .funcs = &dce_v11_0_ip_funcs,
956 },
957 {
958 .type = AMD_IP_BLOCK_TYPE_GFX,
959 .major = 8,
960 .minor = 0,
961 .rev = 0,
962 .funcs = &gfx_v8_0_ip_funcs,
963 },
964 {
965 .type = AMD_IP_BLOCK_TYPE_SDMA,
966 .major = 3,
967 .minor = 1,
968 .rev = 0,
969 .funcs = &sdma_v3_0_ip_funcs,
970 },
971 {
972 .type = AMD_IP_BLOCK_TYPE_UVD,
973 .major = 6,
974 .minor = 3,
975 .rev = 0,
976 .funcs = &uvd_v6_0_ip_funcs,
977 },
978 {
979 .type = AMD_IP_BLOCK_TYPE_VCE,
980 .major = 3,
981 .minor = 4,
982 .rev = 0,
983 .funcs = &vce_v3_0_ip_funcs,
984 },
985};
986
910static const struct amdgpu_ip_block_version cz_ip_blocks[] = 987static const struct amdgpu_ip_block_version cz_ip_blocks[] =
911{ 988{
912 /* ORDER MATTERS! */ 989 /* ORDER MATTERS! */
@@ -999,6 +1076,11 @@ int vi_set_ip_blocks(struct amdgpu_device *adev)
999 adev->ip_blocks = tonga_ip_blocks; 1076 adev->ip_blocks = tonga_ip_blocks;
1000 adev->num_ip_blocks = ARRAY_SIZE(tonga_ip_blocks); 1077 adev->num_ip_blocks = ARRAY_SIZE(tonga_ip_blocks);
1001 break; 1078 break;
1079 case CHIP_POLARIS11:
1080 case CHIP_POLARIS10:
1081 adev->ip_blocks = polaris11_ip_blocks;
1082 adev->num_ip_blocks = ARRAY_SIZE(polaris11_ip_blocks);
1083 break;
1002 case CHIP_CARRIZO: 1084 case CHIP_CARRIZO:
1003 case CHIP_STONEY: 1085 case CHIP_STONEY:
1004 adev->ip_blocks = cz_ip_blocks; 1086 adev->ip_blocks = cz_ip_blocks;
@@ -1076,18 +1158,67 @@ static int vi_common_early_init(void *handle)
1076 adev->external_rev_id = 0x1; 1158 adev->external_rev_id = 0x1;
1077 break; 1159 break;
1078 case CHIP_FIJI: 1160 case CHIP_FIJI:
1079 adev->cg_flags = 0; 1161 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1162 AMD_CG_SUPPORT_GFX_MGLS |
1163 AMD_CG_SUPPORT_GFX_RLC_LS |
1164 AMD_CG_SUPPORT_GFX_CP_LS |
1165 AMD_CG_SUPPORT_GFX_CGTS |
1166 AMD_CG_SUPPORT_GFX_CGTS_LS |
1167 AMD_CG_SUPPORT_GFX_CGCG |
1168 AMD_CG_SUPPORT_GFX_CGLS |
1169 AMD_CG_SUPPORT_SDMA_MGCG |
1170 AMD_CG_SUPPORT_SDMA_LS |
1171 AMD_CG_SUPPORT_BIF_LS |
1172 AMD_CG_SUPPORT_HDP_MGCG |
1173 AMD_CG_SUPPORT_HDP_LS |
1174 AMD_CG_SUPPORT_ROM_MGCG |
1175 AMD_CG_SUPPORT_MC_MGCG |
1176 AMD_CG_SUPPORT_MC_LS;
1080 adev->pg_flags = 0; 1177 adev->pg_flags = 0;
1081 adev->external_rev_id = adev->rev_id + 0x3c; 1178 adev->external_rev_id = adev->rev_id + 0x3c;
1082 break; 1179 break;
1083 case CHIP_TONGA: 1180 case CHIP_TONGA:
1084 adev->cg_flags = 0; 1181 adev->cg_flags = AMD_CG_SUPPORT_UVD_MGCG;
1085 adev->pg_flags = 0; 1182 adev->pg_flags = 0;
1086 adev->external_rev_id = adev->rev_id + 0x14; 1183 adev->external_rev_id = adev->rev_id + 0x14;
1087 break; 1184 break;
1185 case CHIP_POLARIS11:
1186 adev->cg_flags = 0;
1187 adev->pg_flags = 0;
1188 adev->external_rev_id = adev->rev_id + 0x5A;
1189 break;
1190 case CHIP_POLARIS10:
1191 adev->cg_flags = 0;
1192 adev->pg_flags = 0;
1193 adev->external_rev_id = adev->rev_id + 0x50;
1194 break;
1088 case CHIP_CARRIZO: 1195 case CHIP_CARRIZO:
1196 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1197 AMD_CG_SUPPORT_GFX_MGLS |
1198 AMD_CG_SUPPORT_GFX_RLC_LS |
1199 AMD_CG_SUPPORT_GFX_CP_LS |
1200 AMD_CG_SUPPORT_GFX_CGTS |
1201 AMD_CG_SUPPORT_GFX_MGLS |
1202 AMD_CG_SUPPORT_GFX_CGTS_LS |
1203 AMD_CG_SUPPORT_GFX_CGCG |
1204 AMD_CG_SUPPORT_GFX_CGLS |
1205 AMD_CG_SUPPORT_BIF_LS |
1206 AMD_CG_SUPPORT_HDP_MGCG |
1207 AMD_CG_SUPPORT_HDP_LS |
1208 AMD_CG_SUPPORT_SDMA_MGCG |
1209 AMD_CG_SUPPORT_SDMA_LS;
1210 adev->pg_flags = 0;
1211 adev->external_rev_id = adev->rev_id + 0x1;
1212 break;
1089 case CHIP_STONEY: 1213 case CHIP_STONEY:
1090 adev->cg_flags = 0; 1214 adev->cg_flags = AMD_CG_SUPPORT_UVD_MGCG |
1215 AMD_CG_SUPPORT_GFX_MGCG |
1216 AMD_CG_SUPPORT_GFX_MGLS |
1217 AMD_CG_SUPPORT_BIF_LS |
1218 AMD_CG_SUPPORT_HDP_MGCG |
1219 AMD_CG_SUPPORT_HDP_LS |
1220 AMD_CG_SUPPORT_SDMA_MGCG |
1221 AMD_CG_SUPPORT_SDMA_LS;
1091 adev->pg_flags = 0; 1222 adev->pg_flags = 0;
1092 adev->external_rev_id = adev->rev_id + 0x1; 1223 adev->external_rev_id = adev->rev_id + 0x1;
1093 break; 1224 break;
@@ -1164,24 +1295,19 @@ static int vi_common_wait_for_idle(void *handle)
1164 return 0; 1295 return 0;
1165} 1296}
1166 1297
1167static void vi_common_print_status(void *handle)
1168{
1169 return;
1170}
1171
1172static int vi_common_soft_reset(void *handle) 1298static int vi_common_soft_reset(void *handle)
1173{ 1299{
1174 return 0; 1300 return 0;
1175} 1301}
1176 1302
1177static void fiji_update_bif_medium_grain_light_sleep(struct amdgpu_device *adev, 1303static void vi_update_bif_medium_grain_light_sleep(struct amdgpu_device *adev,
1178 bool enable) 1304 bool enable)
1179{ 1305{
1180 uint32_t temp, data; 1306 uint32_t temp, data;
1181 1307
1182 temp = data = RREG32_PCIE(ixPCIE_CNTL2); 1308 temp = data = RREG32_PCIE(ixPCIE_CNTL2);
1183 1309
1184 if (enable) 1310 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_BIF_LS))
1185 data |= PCIE_CNTL2__SLV_MEM_LS_EN_MASK | 1311 data |= PCIE_CNTL2__SLV_MEM_LS_EN_MASK |
1186 PCIE_CNTL2__MST_MEM_LS_EN_MASK | 1312 PCIE_CNTL2__MST_MEM_LS_EN_MASK |
1187 PCIE_CNTL2__REPLAY_MEM_LS_EN_MASK; 1313 PCIE_CNTL2__REPLAY_MEM_LS_EN_MASK;
@@ -1194,14 +1320,14 @@ static void fiji_update_bif_medium_grain_light_sleep(struct amdgpu_device *adev,
1194 WREG32_PCIE(ixPCIE_CNTL2, data); 1320 WREG32_PCIE(ixPCIE_CNTL2, data);
1195} 1321}
1196 1322
1197static void fiji_update_hdp_medium_grain_clock_gating(struct amdgpu_device *adev, 1323static void vi_update_hdp_medium_grain_clock_gating(struct amdgpu_device *adev,
1198 bool enable) 1324 bool enable)
1199{ 1325{
1200 uint32_t temp, data; 1326 uint32_t temp, data;
1201 1327
1202 temp = data = RREG32(mmHDP_HOST_PATH_CNTL); 1328 temp = data = RREG32(mmHDP_HOST_PATH_CNTL);
1203 1329
1204 if (enable) 1330 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_MGCG))
1205 data &= ~HDP_HOST_PATH_CNTL__CLOCK_GATING_DIS_MASK; 1331 data &= ~HDP_HOST_PATH_CNTL__CLOCK_GATING_DIS_MASK;
1206 else 1332 else
1207 data |= HDP_HOST_PATH_CNTL__CLOCK_GATING_DIS_MASK; 1333 data |= HDP_HOST_PATH_CNTL__CLOCK_GATING_DIS_MASK;
@@ -1210,14 +1336,14 @@ static void fiji_update_hdp_medium_grain_clock_gating(struct amdgpu_device *adev
1210 WREG32(mmHDP_HOST_PATH_CNTL, data); 1336 WREG32(mmHDP_HOST_PATH_CNTL, data);
1211} 1337}
1212 1338
1213static void fiji_update_hdp_light_sleep(struct amdgpu_device *adev, 1339static void vi_update_hdp_light_sleep(struct amdgpu_device *adev,
1214 bool enable) 1340 bool enable)
1215{ 1341{
1216 uint32_t temp, data; 1342 uint32_t temp, data;
1217 1343
1218 temp = data = RREG32(mmHDP_MEM_POWER_LS); 1344 temp = data = RREG32(mmHDP_MEM_POWER_LS);
1219 1345
1220 if (enable) 1346 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS))
1221 data |= HDP_MEM_POWER_LS__LS_ENABLE_MASK; 1347 data |= HDP_MEM_POWER_LS__LS_ENABLE_MASK;
1222 else 1348 else
1223 data &= ~HDP_MEM_POWER_LS__LS_ENABLE_MASK; 1349 data &= ~HDP_MEM_POWER_LS__LS_ENABLE_MASK;
@@ -1226,14 +1352,14 @@ static void fiji_update_hdp_light_sleep(struct amdgpu_device *adev,
1226 WREG32(mmHDP_MEM_POWER_LS, data); 1352 WREG32(mmHDP_MEM_POWER_LS, data);
1227} 1353}
1228 1354
1229static void fiji_update_rom_medium_grain_clock_gating(struct amdgpu_device *adev, 1355static void vi_update_rom_medium_grain_clock_gating(struct amdgpu_device *adev,
1230 bool enable) 1356 bool enable)
1231{ 1357{
1232 uint32_t temp, data; 1358 uint32_t temp, data;
1233 1359
1234 temp = data = RREG32_SMC(ixCGTT_ROM_CLK_CTRL0); 1360 temp = data = RREG32_SMC(ixCGTT_ROM_CLK_CTRL0);
1235 1361
1236 if (enable) 1362 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_ROM_MGCG))
1237 data &= ~(CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK | 1363 data &= ~(CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
1238 CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK); 1364 CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK);
1239 else 1365 else
@@ -1245,19 +1371,28 @@ static void fiji_update_rom_medium_grain_clock_gating(struct amdgpu_device *adev
1245} 1371}
1246 1372
1247static int vi_common_set_clockgating_state(void *handle, 1373static int vi_common_set_clockgating_state(void *handle,
1248 enum amd_clockgating_state state) 1374 enum amd_clockgating_state state)
1249{ 1375{
1250 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 1376 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1251 1377
1252 switch (adev->asic_type) { 1378 switch (adev->asic_type) {
1253 case CHIP_FIJI: 1379 case CHIP_FIJI:
1254 fiji_update_bif_medium_grain_light_sleep(adev, 1380 vi_update_bif_medium_grain_light_sleep(adev,
1381 state == AMD_CG_STATE_GATE ? true : false);
1382 vi_update_hdp_medium_grain_clock_gating(adev,
1255 state == AMD_CG_STATE_GATE ? true : false); 1383 state == AMD_CG_STATE_GATE ? true : false);
1256 fiji_update_hdp_medium_grain_clock_gating(adev, 1384 vi_update_hdp_light_sleep(adev,
1385 state == AMD_CG_STATE_GATE ? true : false);
1386 vi_update_rom_medium_grain_clock_gating(adev,
1387 state == AMD_CG_STATE_GATE ? true : false);
1388 break;
1389 case CHIP_CARRIZO:
1390 case CHIP_STONEY:
1391 vi_update_bif_medium_grain_light_sleep(adev,
1257 state == AMD_CG_STATE_GATE ? true : false); 1392 state == AMD_CG_STATE_GATE ? true : false);
1258 fiji_update_hdp_light_sleep(adev, 1393 vi_update_hdp_medium_grain_clock_gating(adev,
1259 state == AMD_CG_STATE_GATE ? true : false); 1394 state == AMD_CG_STATE_GATE ? true : false);
1260 fiji_update_rom_medium_grain_clock_gating(adev, 1395 vi_update_hdp_light_sleep(adev,
1261 state == AMD_CG_STATE_GATE ? true : false); 1396 state == AMD_CG_STATE_GATE ? true : false);
1262 break; 1397 break;
1263 default: 1398 default:
@@ -1284,7 +1419,6 @@ const struct amd_ip_funcs vi_common_ip_funcs = {
1284 .is_idle = vi_common_is_idle, 1419 .is_idle = vi_common_is_idle,
1285 .wait_for_idle = vi_common_wait_for_idle, 1420 .wait_for_idle = vi_common_wait_for_idle,
1286 .soft_reset = vi_common_soft_reset, 1421 .soft_reset = vi_common_soft_reset,
1287 .print_status = vi_common_print_status,
1288 .set_clockgating_state = vi_common_set_clockgating_state, 1422 .set_clockgating_state = vi_common_set_clockgating_state,
1289 .set_powergating_state = vi_common_set_powergating_state, 1423 .set_powergating_state = vi_common_set_powergating_state,
1290}; 1424};