History

Merge branch 'drm-next-4.9' of git://people.freedesktop.org/~agd5f/linux into drm-next

Last set of radeon and amdgpu changes for 4.9. This is mostly just the powerplay cleanup for dGPUs. Beyond that, just misc code cleanups and bug fixes. * 'drm-next-4.9' of git://people.freedesktop.org/~agd5f/linux: (49 commits) drm/amd/amdgpu: Clean up afmt allocation in DCEv6. (v2) drm/amd/amdgpu: Remove division from vblank_wait drm/radeon/atif: Send a hotplug event when we get dgpu display request drm/radeon/atpx: check for ATIF dGPU wake for display events support drm/amdgpu/atif: Send a hotplug event when we get dgpu display request drm/amdgpu/atpx: check for ATIF dGPU wake for display events support drm/amdgpu: bump version for new vce packet support drm/amdgpu/vce: allow the clock table packet drm/amdgpu:cleanup virt related define drm/amdgpu: use powerplay module for dgpu in Vi. drm/amdgpu: set gfx clock gating for tonga/polaris. drm/amdgpu: set system clock gating for tonga/polaris. drm/amd/powerplay: export function to help to set cg by smu. drm/amdgpu: avoid out of bounds access on array interrupt_status_offsets drm/amdgpu: mark symbols static where possible drm/amdgpu: remove unused functions drm/amd/powerplay: Replace per-asic print_performance with generic drm/radeon: narrow asic_init for virtualization drm/amdgpu:add fw version entry to info drm/amdgpu:determine if vPost is needed indeed ...

Dave Airlie committed 10 years ago

Commit 9f4ef052 parents 81c5d6a beb86f2106 files · +18603 −35882Browse files

Unified · Split

106 files
  1. drivers/gpu/drm/amd/amdgpu/Makefile +1 −4
  2. drivers/gpu/drm/amd/amdgpu/amdgpu.h +10 −18
  3. drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c +11 −0
  4. drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +0 −8
  5. drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c +9 −0
  6. drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c +42 −0
  7. drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c +4 −2
  8. drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +92 −26
  9. drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +3 −2
  10. drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +60 −2
  11. drivers/gpu/drm/amd/amdgpu/amdgpu_powerplay.c +2 −11
  12. drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +1 −0
  13. drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h +31 −14
  14. drivers/gpu/drm/amd/amdgpu/cik.c +7 −7
  15. drivers/gpu/drm/amd/amdgpu/cikd.h +36 −0
  16. drivers/gpu/drm/amd/amdgpu/cz_smc.c +0 −7
  17. drivers/gpu/drm/amd/amdgpu/dce_v10_0.c +5 −3
  18. drivers/gpu/drm/amd/amdgpu/dce_v6_0.c +22 −10
  19. drivers/gpu/drm/amd/amdgpu/dce_v8_0.c +5 −3
  20. drivers/gpu/drm/amd/amdgpu/dce_virtual.c +3 −3
  21. drivers/gpu/drm/amd/amdgpu/fiji_dpm.c +0 −186
  22. drivers/gpu/drm/amd/amdgpu/fiji_smc.c +0 −863
  23. drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c +130 −1
  24. drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c +159 −1
  25. drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +244 −1
  26. drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +3 −1
  27. drivers/gpu/drm/amd/amdgpu/iceland_dpm.c +0 −200
  28. drivers/gpu/drm/amd/amdgpu/iceland_smc.c +0 −677
  29. drivers/gpu/drm/amd/amdgpu/si.c +7 −7
  30. drivers/gpu/drm/amd/amdgpu/tonga_dpm.c +0 −186
  31. drivers/gpu/drm/amd/amdgpu/tonga_smc.c +0 −862
  32. drivers/gpu/drm/amd/amdgpu/vi.c +81 −10
  33. drivers/gpu/drm/amd/amdgpu/vid.h +37 −0
  34. drivers/gpu/drm/amd/include/asic_reg/si/sid.h +35 −0
  35. drivers/gpu/drm/amd/include/cgs_common.h +1 −0
  36. drivers/gpu/drm/amd/powerplay/amd_powerplay.c +23 −97
  37. drivers/gpu/drm/amd/powerplay/eventmgr/eventactionchains.c +2 −0
  38. drivers/gpu/drm/amd/powerplay/eventmgr/psm.c +2 −1
  39. drivers/gpu/drm/amd/powerplay/hwmgr/Makefile +6 −10
  40. drivers/gpu/drm/amd/powerplay/hwmgr/cz_hwmgr.c +102 −73
  41. drivers/gpu/drm/amd/powerplay/hwmgr/fiji_clockpowergating.c +0 −121
  42. drivers/gpu/drm/amd/powerplay/hwmgr/fiji_dyn_defaults.h +0 −105
  43. drivers/gpu/drm/amd/powerplay/hwmgr/fiji_hwmgr.c +0 −5600
  44. drivers/gpu/drm/amd/powerplay/hwmgr/fiji_hwmgr.h +0 −350
  45. drivers/gpu/drm/amd/powerplay/hwmgr/fiji_powertune.c +0 −610
  46. drivers/gpu/drm/amd/powerplay/hwmgr/fiji_powertune.h +0 −81
  47. drivers/gpu/drm/amd/powerplay/hwmgr/fiji_thermal.h +0 −62
  48. drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c +113 −13
  49. drivers/gpu/drm/amd/powerplay/hwmgr/iceland_clockpowergating.c +0 −119
  50. drivers/gpu/drm/amd/powerplay/hwmgr/iceland_clockpowergating.h +0 −38
  51. drivers/gpu/drm/amd/powerplay/hwmgr/iceland_dyn_defaults.h +0 −41
  52. drivers/gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.c +0 −5684
  53. drivers/gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.h +0 −424
  54. drivers/gpu/drm/amd/powerplay/hwmgr/iceland_powertune.c +0 −490
  55. drivers/gpu/drm/amd/powerplay/hwmgr/iceland_powertune.h +0 −74
  56. drivers/gpu/drm/amd/powerplay/hwmgr/iceland_thermal.c +0 −595
  57. drivers/gpu/drm/amd/powerplay/hwmgr/iceland_thermal.h +0 −58
  58. drivers/gpu/drm/amd/powerplay/hwmgr/polaris10_dyn_defaults.h +0 −62
  59. drivers/gpu/drm/amd/powerplay/hwmgr/polaris10_hwmgr.c +0 −5289
  60. drivers/gpu/drm/amd/powerplay/hwmgr/polaris10_thermal.c +0 −716
  61. drivers/gpu/drm/amd/powerplay/hwmgr/polaris10_thermal.h +0 −62
  62. drivers/gpu/drm/amd/powerplay/hwmgr/smu7_clockpowergating.c +102 −58
  63. drivers/gpu/drm/amd/powerplay/hwmgr/smu7_clockpowergating.h +15 −10
  64. drivers/gpu/drm/amd/powerplay/hwmgr/smu7_dyn_defaults.h +55 −0
  65. drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c +4359 −0
  66. drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.h +120 −121
  67. drivers/gpu/drm/amd/powerplay/hwmgr/smu7_powertune.c +363 −622
  68. drivers/gpu/drm/amd/powerplay/hwmgr/smu7_powertune.h +12 −31
  69. drivers/gpu/drm/amd/powerplay/hwmgr/smu7_thermal.c +74 −184
  70. drivers/gpu/drm/amd/powerplay/hwmgr/smu7_thermal.h +58 −0
  71. drivers/gpu/drm/amd/powerplay/hwmgr/tonga_clockpowergating.c +0 −350
  72. drivers/gpu/drm/amd/powerplay/hwmgr/tonga_dyn_defaults.h +0 −107
  73. drivers/gpu/drm/amd/powerplay/hwmgr/tonga_hwmgr.c +0 −6370
  74. drivers/gpu/drm/amd/powerplay/hwmgr/tonga_hwmgr.h +0 −402
  75. drivers/gpu/drm/amd/powerplay/hwmgr/tonga_powertune.c +0 −495
  76. drivers/gpu/drm/amd/powerplay/hwmgr/tonga_thermal.c +0 −590
  77. drivers/gpu/drm/amd/powerplay/hwmgr/tonga_thermal.h +0 −61
  78. drivers/gpu/drm/amd/powerplay/inc/amd_powerplay.h +17 −2
  79. drivers/gpu/drm/amd/powerplay/inc/hwmgr.h +2 −2
  80. drivers/gpu/drm/amd/powerplay/inc/polaris10_pwrvirus.h +1 −2
  81. drivers/gpu/drm/amd/powerplay/inc/smu7_common.h +30 −13
  82. drivers/gpu/drm/amd/powerplay/inc/smu7_ppsmc.h +412 −0
  83. drivers/gpu/drm/amd/powerplay/inc/smumgr.h +70 −0
  84. drivers/gpu/drm/amd/powerplay/smumgr/Makefile +3 −2
  85. drivers/gpu/drm/amd/powerplay/smumgr/fiji_smc.c +2374 −0
  86. drivers/gpu/drm/amd/powerplay/smumgr/fiji_smc.h +25 −16
  87. drivers/gpu/drm/amd/powerplay/smumgr/fiji_smumgr.c +45 −567
  88. drivers/gpu/drm/amd/powerplay/smumgr/fiji_smumgr.h +13 −19
  89. drivers/gpu/drm/amd/powerplay/smumgr/iceland_smc.c +2576 −0
  90. drivers/gpu/drm/amd/powerplay/smumgr/iceland_smc.h +15 −11
  91. drivers/gpu/drm/amd/powerplay/smumgr/iceland_smumgr.c +75 −538
  92. drivers/gpu/drm/amd/powerplay/smumgr/iceland_smumgr.h +35 −28
  93. drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smc.c +2287 −0
  94. drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smc.h +16 −16
  95. drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smumgr.c +58 −645
  96. drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smumgr.h +14 −27
  97. drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c +589 −0
  98. drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.h +87 −0
  99. drivers/gpu/drm/amd/powerplay/smumgr/smumgr.c +100 −1
  100. drivers/gpu/drm/amd/powerplay/smumgr/tonga_smc.c +3207 −0
  101. drivers/gpu/drm/amd/powerplay/smumgr/tonga_smc.h +18 −38
  102. drivers/gpu/drm/amd/powerplay/smumgr/tonga_smumgr.c +34 −638
  103. drivers/gpu/drm/amd/powerplay/smumgr/tonga_smumgr.h +26 −20
  104. drivers/gpu/drm/radeon/radeon_acpi.c +17 −0
  105. drivers/gpu/drm/radeon/radeon_atpx_handler.c +5 −0
  106. drivers/gpu/drm/radeon/radeon_device.c +5 −6
drivers/gpu/drm/amd/amdgpu/Makefile+1−4
@@ -52,10 +52,7 @@ amdgpu-y += \ · 51 unmodified lines
5252 amdgpu-y += \
5353 amdgpu_dpm.o \
5454 amdgpu_powerplay.o \
55− cz_smc.o cz_dpm.o \
56− tonga_smc.o tonga_dpm.o \
57− fiji_smc.o fiji_dpm.o \
58− iceland_smc.o iceland_dpm.o
55+ cz_smc.o cz_dpm.o
5956
6057 # add DCE block
6158 amdgpu-y += \
drivers/gpu/drm/amd/amdgpu/amdgpu.h+10−18
@@ -57,6 +57,7 @@ · 56 unmodified lines
5757 #include "amdgpu_acp.h"
5858
5959 #include "gpu_scheduler.h"
60+#include "amdgpu_virt.h"
6061
6162 /*
6263 * Modules parameters.
@@ -1827,6 +1828,7 @@ struct amdgpu_asic_funcs { · 1764 unmodified lines
18271828 bool (*read_disabled_bios)(struct amdgpu_device *adev);
18281829 bool (*read_bios_from_rom)(struct amdgpu_device *adev,
18291830 u8 *bios, u32 length_bytes);
1831+ void (*detect_hw_virtualization) (struct amdgpu_device *adev);
18301832 int (*read_register)(struct amdgpu_device *adev, u32 se_num,
18311833 u32 sh_num, u32 reg_offset, u32 *value);
18321834 void (*set_vga_state)(struct amdgpu_device *adev, bool state);
@@ -1836,8 +1838,6 @@ struct amdgpu_asic_funcs { · 3 unmodified lines
18361838 /* MM block clocks */
18371839 int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
18381840 int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
1839− /* query virtual capabilities */
1840− u32 (*get_virtual_caps)(struct amdgpu_device *adev);
18411841 /* static power management */
18421842 int (*get_pcie_lanes)(struct amdgpu_device *adev);
18431843 void (*set_pcie_lanes)(struct amdgpu_device *adev, int lanes);
@@ -1933,16 +1933,6 @@ struct amdgpu_atcs { · 89 unmodified lines
19331933 struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
19341934 void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device);
19351935
1936−
1937−/* GPU virtualization */
1938−#define AMDGPU_VIRT_CAPS_SRIOV_EN (1 << 0)
1939−#define AMDGPU_VIRT_CAPS_IS_VF (1 << 1)
1940−struct amdgpu_virtualization {
1941− bool supports_sr_iov;
1942− bool is_virtual;
1943− u32 caps;
1944−};
1945−
19461936 /*
19471937 * Core structure, functions and helpers.
19481938 */
@@ -2260,12 +2250,12 @@ amdgpu_get_sdma_instance(struct amdgpu_ring *ring) · 311 unmodified lines
22602250 #define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
22612251 #define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
22622252 #define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec))
2263−#define amdgpu_asic_get_virtual_caps(adev) ((adev)->asic_funcs->get_virtual_caps((adev)))
22642253 #define amdgpu_get_pcie_lanes(adev) (adev)->asic_funcs->get_pcie_lanes((adev))
22652254 #define amdgpu_set_pcie_lanes(adev, l) (adev)->asic_funcs->set_pcie_lanes((adev), (l))
22662255 #define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
22672256 #define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
22682257 #define amdgpu_asic_read_bios_from_rom(adev, b, l) (adev)->asic_funcs->read_bios_from_rom((adev), (b), (l))
2258+#define amdgpu_asic_detect_hw_virtualization(adev) (adev)->asic_funcs->detect_hw_virtualization((adev))
22692259 #define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v)))
22702260 #define amdgpu_gart_flush_gpu_tlb(adev, vmid) (adev)->gart.gart_funcs->flush_gpu_tlb((adev), (vmid))
22712261 #define amdgpu_gart_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gart.gart_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
@@ -2323,6 +2313,11 @@ amdgpu_get_sdma_instance(struct amdgpu_ring *ring) · 51 unmodified lines
23232313 #define amdgpu_gfx_get_gpu_clock_counter(adev) (adev)->gfx.funcs->get_gpu_clock_counter((adev))
23242314 #define amdgpu_gfx_select_se_sh(adev, se, sh, instance) (adev)->gfx.funcs->select_se_sh((adev), (se), (sh), (instance))
23252315
2316+#define amdgpu_dpm_read_sensor(adev, idx, value) \
2317+ ((adev)->pp_enabled ? \
2318+ (adev)->powerplay.pp_funcs->read_sensor(adev->powerplay.pp_handle, (idx), (value)) : \
2319+ -EINVAL)
2320+
23262321 #define amdgpu_dpm_get_temperature(adev) \
23272322 ((adev)->pp_enabled ? \
23282323 (adev)->powerplay.pp_funcs->get_temperature((adev)->powerplay.pp_handle) : \
@@ -2374,11 +2369,6 @@ amdgpu_get_sdma_instance(struct amdgpu_ring *ring) · 45 unmodified lines
23742369 (adev)->powerplay.pp_funcs->powergate_vce((adev)->powerplay.pp_handle, (g)) : \
23752370 (adev)->pm.funcs->powergate_vce((adev), (g)))
23762371
2377−#define amdgpu_dpm_debugfs_print_current_performance_level(adev, m) \
2378− ((adev)->pp_enabled ? \
2379− (adev)->powerplay.pp_funcs->print_current_performance_level((adev)->powerplay.pp_handle, (m)) : \
2380− (adev)->pm.funcs->debugfs_print_current_performance_level((adev), (m)))
2381−
23822372 #define amdgpu_dpm_get_current_power_state(adev) \
23832373 (adev)->powerplay.pp_funcs->get_current_power_state((adev)->powerplay.pp_handle)
23842374
@@ -2460,11 +2450,13 @@ void amdgpu_register_atpx_handler(void); · 75 unmodified lines
24602450 void amdgpu_unregister_atpx_handler(void);
24612451 bool amdgpu_has_atpx_dgpu_power_cntl(void);
24622452 bool amdgpu_is_atpx_hybrid(void);
2453+bool amdgpu_atpx_dgpu_req_power_for_displays(void);
24632454 #else
24642455 static inline void amdgpu_register_atpx_handler(void) {}
24652456 static inline void amdgpu_unregister_atpx_handler(void) {}
24662457 static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; }
24672458 static inline bool amdgpu_is_atpx_hybrid(void) { return false; }
2459+static inline bool amdgpu_atpx_dgpu_req_power_for_displays(void) { return false; }
24682460 #endif
24692461
24702462 /*
drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c+11−0
@@ -25,6 +25,7 @@ · 24 unmodified lines
2525 #include <linux/acpi.h>
2626 #include <linux/slab.h>
2727 #include <linux/power_supply.h>
28+#include <linux/pm_runtime.h>
2829 #include <acpi/video.h>
2930 #include <drm/drmP.h>
3031 #include <drm/drm_crtc_helper.h>
@@ -333,6 +334,16 @@ int amdgpu_atif_handler(struct amdgpu_device *adev, · 302 unmodified lines
333334 #endif
334335 }
335336 }
337+ if (req.pending & ATIF_DGPU_DISPLAY_EVENT) {
338+ if ((adev->flags & AMD_IS_PX) &&
339+ amdgpu_atpx_dgpu_req_power_for_displays()) {
340+ pm_runtime_get_sync(adev->ddev->dev);
341+ /* Just fire off a uevent and let userspace tell us what to do */
342+ drm_helper_hpd_irq_event(adev->ddev);
343+ pm_runtime_mark_last_busy(adev->ddev->dev);
344+ pm_runtime_put_autosuspend(adev->ddev->dev);
345+ }
346+ }
336347 /* TODO: check other events */
337348
338349 /* We've handled the event, stop the notifier chain. The ACPI interface
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c+0−8
@@ -143,14 +143,6 @@ int amdgpu_amdkfd_resume(struct amdgpu_device *rdev) · 142 unmodified lines
143143 return r;
144144 }
145145
146−u32 pool_to_domain(enum kgd_memory_pool p)
147−{
148− switch (p) {
149− case KGD_POOL_FRAMEBUFFER: return AMDGPU_GEM_DOMAIN_VRAM;
150− default: return AMDGPU_GEM_DOMAIN_GTT;
151− }
152−}
153−
154146 int alloc_gtt_mem(struct kgd_dev *kgd, size_t size,
155147 void **mem_obj, uint64_t *gpu_addr,
156148 void **cpu_ptr)
drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c+9−0
@@ -29,6 +29,7 @@ struct amdgpu_atpx { · 28 unmodified lines
2929 acpi_handle handle;
3030 struct amdgpu_atpx_functions functions;
3131 bool is_hybrid;
32+ bool dgpu_req_power_for_displays;
3233 };
3334
3435 static struct amdgpu_atpx_priv {
@@ -73,6 +74,10 @@ bool amdgpu_is_atpx_hybrid(void) { · 38 unmodified lines
7374 return amdgpu_atpx_priv.atpx.is_hybrid;
7475 }
7576
77+bool amdgpu_atpx_dgpu_req_power_for_displays(void) {
78+ return amdgpu_atpx_priv.atpx.dgpu_req_power_for_displays;
79+}
80+
7681 /**
7782 * amdgpu_atpx_call - call an ATPX method
7883 *
@@ -213,6 +218,10 @@ static int amdgpu_atpx_validate(struct amdgpu_atpx *atpx) · 134 unmodified lines
213218 atpx->is_hybrid = true;
214219 }
215220
221+ atpx->dgpu_req_power_for_displays = false;
222+ if (valid_bits & ATPX_DGPU_REQ_POWER_FOR_DISPLAYS)
223+ atpx->dgpu_req_power_for_displays = true;
224+
216225 return 0;
217226 }
218227
drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c+42−0
@@ -711,6 +711,47 @@ static int amdgpu_cgs_rel_firmware(struct cgs_device *cgs_device, enum cgs_ucode · 710 unmodified lines
711711 return -EINVAL;
712712 }
713713
714+static uint16_t amdgpu_get_firmware_version(struct cgs_device *cgs_device,
715+ enum cgs_ucode_id type)
716+{
717+ CGS_FUNC_ADEV;
718+ uint16_t fw_version;
719+
720+ switch (type) {
721+ case CGS_UCODE_ID_SDMA0:
722+ fw_version = adev->sdma.instance[0].fw_version;
723+ break;
724+ case CGS_UCODE_ID_SDMA1:
725+ fw_version = adev->sdma.instance[1].fw_version;
726+ break;
727+ case CGS_UCODE_ID_CP_CE:
728+ fw_version = adev->gfx.ce_fw_version;
729+ break;
730+ case CGS_UCODE_ID_CP_PFP:
731+ fw_version = adev->gfx.pfp_fw_version;
732+ break;
733+ case CGS_UCODE_ID_CP_ME:
734+ fw_version = adev->gfx.me_fw_version;
735+ break;
736+ case CGS_UCODE_ID_CP_MEC:
737+ fw_version = adev->gfx.mec_fw_version;
738+ break;
739+ case CGS_UCODE_ID_CP_MEC_JT1:
740+ fw_version = adev->gfx.mec_fw_version;
741+ break;
742+ case CGS_UCODE_ID_CP_MEC_JT2:
743+ fw_version = adev->gfx.mec_fw_version;
744+ break;
745+ case CGS_UCODE_ID_RLC_G:
746+ fw_version = adev->gfx.rlc_fw_version;
747+ break;
748+ default:
749+ DRM_ERROR("firmware type %d do not have version\n", type);
750+ fw_version = 0;
751+ }
752+ return fw_version;
753+}
754+
714755 static int amdgpu_cgs_get_firmware_info(struct cgs_device *cgs_device,
715756 enum cgs_ucode_id type,
716757 struct cgs_firmware_info *info)
@@ -741,6 +782,7 @@ static int amdgpu_cgs_get_firmware_info(struct cgs_device *cgs_device, · 24 unmodified lines
741782 info->mc_addr = gpu_addr;
742783 info->image_size = data_size;
743784 info->version = (uint16_t)le32_to_cpu(header->header.ucode_version);
785+ info->fw_version = amdgpu_get_firmware_version(cgs_device, type);
744786 info->feature_version = (uint16_t)le32_to_cpu(header->ucode_feature_version);
745787 } else {
746788 char fw_name[30] = {0};
drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c+4−2
@@ -1545,7 +1545,8 @@ static int amdgpu_connector_virtual_mode_valid(struct drm_connector *connector, · 1544 unmodified lines
15451545 return MODE_OK;
15461546 }
15471547
1548−int amdgpu_connector_virtual_dpms(struct drm_connector *connector, int mode)
1548+static int
1549+amdgpu_connector_virtual_dpms(struct drm_connector *connector, int mode)
15491550 {
15501551 return 0;
15511552 }
@@ -1557,7 +1558,8 @@ amdgpu_connector_virtual_detect(struct drm_connector *connector, bool force) · 5 unmodified lines
15571558 return connector_status_connected;
15581559 }
15591560
1560−int amdgpu_connector_virtual_set_property(struct drm_connector *connector,
1561+static int
1562+amdgpu_connector_virtual_set_property(struct drm_connector *connector,
15611563 struct drm_property *property,
15621564 uint64_t val)
15631565 {
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c+92−26
@@ -50,6 +50,7 @@ · 49 unmodified lines
5050 #include "vi.h"
5151 #include "bif/bif_4_1_d.h"
5252 #include <linux/pci.h>
53+#include <linux/firmware.h>
5354
5455 static int amdgpu_debugfs_regs_init(struct amdgpu_device *adev);
5556 static void amdgpu_debugfs_regs_cleanup(struct amdgpu_device *adev);
@@ -110,7 +111,7 @@ void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v, · 54 unmodified lines
110111 bool always_indirect)
111112 {
112113 trace_amdgpu_mm_wreg(adev->pdev->device, reg, v);
113−
114+
114115 if ((reg * 4) < adev->rmmio_size && !always_indirect)
115116 writel(v, ((void __iomem *)adev->rmmio) + (reg * 4));
116117 else {
@@ -651,6 +652,46 @@ bool amdgpu_card_posted(struct amdgpu_device *adev) · 534 unmodified lines
651652
652653 }
653654
655+static bool amdgpu_vpost_needed(struct amdgpu_device *adev)
656+{
657+ if (amdgpu_sriov_vf(adev))
658+ return false;
659+
660+ if (amdgpu_passthrough(adev)) {
661+ /* for FIJI: In whole GPU pass-through virtualization case
662+ * old smc fw won't clear some registers (e.g. MEM_SIZE, BIOS_SCRATCH)
663+ * so amdgpu_card_posted return false and driver will incorrectly skip vPost.
664+ * but if we force vPost do in pass-through case, the driver reload will hang.
665+ * whether doing vPost depends on amdgpu_card_posted if smc version is above
666+ * 00160e00 for FIJI.
667+ */
668+ if (adev->asic_type == CHIP_FIJI) {
669+ int err;
670+ uint32_t fw_ver;
671+ err = request_firmware(&adev->pm.fw, "amdgpu/fiji_smc.bin", adev->dev);
672+ /* force vPost if error occured */
673+ if (err)
674+ return true;
675+
676+ fw_ver = *((uint32_t *)adev->pm.fw->data + 69);
677+ if (fw_ver >= 0x00160e00)
678+ return !amdgpu_card_posted(adev);
679+ }
680+ } else {
681+ /* in bare-metal case, amdgpu_card_posted return false
682+ * after system reboot/boot, and return true if driver
683+ * reloaded.
684+ * we shouldn't do vPost after driver reload otherwise GPU
685+ * could hang.
686+ */
687+ if (amdgpu_card_posted(adev))
688+ return false;
689+ }
690+
691+ /* we assume vPost is neede for all other cases */
692+ return true;
693+}
694+
654695 /**
655696 * amdgpu_dummy_page_init - init dummy page used by the driver
656697 *
@@ -1485,13 +1526,10 @@ static int amdgpu_resume(struct amdgpu_device *adev) · 828 unmodified lines
14851526 return 0;
14861527 }
14871528
1488−static bool amdgpu_device_is_virtual(void)
1529+static void amdgpu_device_detect_sriov_bios(struct amdgpu_device *adev)
14891530 {
1490−#ifdef CONFIG_X86
1491− return boot_cpu_has(X86_FEATURE_HYPERVISOR);
1492−#else
1493− return false;
1494−#endif
1531+ if (amdgpu_atombios_has_gpu_virtualization_table(adev))
1532+ adev->virtualization.virtual_caps |= AMDGPU_SRIOV_CAPS_SRIOV_VBIOS;
14951533 }
14961534
14971535 /**
@@ -1648,25 +1686,24 @@ int amdgpu_device_init(struct amdgpu_device *adev, · 150 unmodified lines
16481686 goto failed;
16491687 }
16501688
1651− /* See if the asic supports SR-IOV */
1652− adev->virtualization.supports_sr_iov =
1653− amdgpu_atombios_has_gpu_virtualization_table(adev);
1654−
1655− /* Check if we are executing in a virtualized environment */
1656− adev->virtualization.is_virtual = amdgpu_device_is_virtual();
1657− adev->virtualization.caps = amdgpu_asic_get_virtual_caps(adev);
1689+ /* detect if we are with an SRIOV vbios */
1690+ amdgpu_device_detect_sriov_bios(adev);
16581691
16591692 /* Post card if necessary */
1660− if (!amdgpu_card_posted(adev) ||
1661− (adev->virtualization.is_virtual &&
1662− !(adev->virtualization.caps & AMDGPU_VIRT_CAPS_SRIOV_EN))) {
1693+ if (amdgpu_vpost_needed(adev)) {
16631694 if (!adev->bios) {
1664− dev_err(adev->dev, "Card not posted and no BIOS - ignoring\n");
1695+ dev_err(adev->dev, "no vBIOS found\n");
16651696 r = -EINVAL;
16661697 goto failed;
16671698 }
1668− DRM_INFO("GPU not posted. posting now...\n");
1669− amdgpu_atom_asic_init(adev->mode_info.atom_context);
1699+ DRM_INFO("GPU posting now...\n");
1700+ r = amdgpu_atom_asic_init(adev->mode_info.atom_context);
1701+ if (r) {
1702+ dev_err(adev->dev, "gpu post error!\n");
1703+ goto failed;
1704+ }
1705+ } else {
1706+ DRM_INFO("GPU post is not needed\n");
16701707 }
16711708
16721709 /* Initialize clocks */
@@ -1842,8 +1879,7 @@ int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon) · 169 unmodified lines
18421879
18431880 adev = dev->dev_private;
18441881
1845− if (dev->switch_power_state == DRM_SWITCH_POWER_OFF ||
1846− dev->switch_power_state == DRM_SWITCH_POWER_DYNAMIC_OFF)
1882+ if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
18471883 return 0;
18481884
18491885 drm_kms_helper_poll_disable(dev);
@@ -1928,8 +1964,7 @@ int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon) · 78 unmodified lines
19281964 struct drm_crtc *crtc;
19291965 int r;
19301966
1931− if (dev->switch_power_state == DRM_SWITCH_POWER_OFF ||
1932− dev->switch_power_state == DRM_SWITCH_POWER_DYNAMIC_OFF)
1967+ if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
19331968 return 0;
19341969
19351970 if (fbcon)
@@ -2043,7 +2078,7 @@ static bool amdgpu_check_soft_reset(struct amdgpu_device *adev) · 107 unmodified lines
20432078 return asic_hang;
20442079 }
20452080
2046−int amdgpu_pre_soft_reset(struct amdgpu_device *adev)
2081+static int amdgpu_pre_soft_reset(struct amdgpu_device *adev)
20472082 {
20482083 int i, r = 0;
20492084
@@ -2714,7 +2749,7 @@ static ssize_t amdgpu_debugfs_gca_config_read(struct file *f, char __user *buf, · 664 unmodified lines
27142749 if (size & 0x3 || *pos & 0x3)
27152750 return -EINVAL;
27162751
2717− config = kmalloc(256 * sizeof(*config), GFP_KERNEL);
2752+ config = kmalloc_array(256, sizeof(*config), GFP_KERNEL);
27182753 if (!config)
27192754 return -ENOMEM;
27202755
@@ -2773,6 +2808,29 @@ static ssize_t amdgpu_debugfs_gca_config_read(struct file *f, char __user *buf, · 52 unmodified lines
27732808 return result;
27742809 }
27752810
2811+static ssize_t amdgpu_debugfs_sensor_read(struct file *f, char __user *buf,
2812+ size_t size, loff_t *pos)
2813+{
2814+ struct amdgpu_device *adev = f->f_inode->i_private;
2815+ int idx, r;
2816+ int32_t value;
2817+
2818+ if (size != 4 || *pos & 0x3)
2819+ return -EINVAL;
2820+
2821+ /* convert offset to sensor number */
2822+ idx = *pos >> 2;
2823+
2824+ if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->read_sensor)
2825+ r = adev->powerplay.pp_funcs->read_sensor(adev->powerplay.pp_handle, idx, &value);
2826+ else
2827+ return -EINVAL;
2828+
2829+ if (!r)
2830+ r = put_user(value, (int32_t *)buf);
2831+
2832+ return !r ? 4 : r;
2833+}
27762834
27772835 static const struct file_operations amdgpu_debugfs_regs_fops = {
27782836 .owner = THIS_MODULE,
@@ -2805,12 +2863,19 @@ static const struct file_operations amdgpu_debugfs_gca_config_fops = { · 26 unmodified lines
28052863 .llseek = default_llseek
28062864 };
28072865
2866+static const struct file_operations amdgpu_debugfs_sensors_fops = {
2867+ .owner = THIS_MODULE,
2868+ .read = amdgpu_debugfs_sensor_read,
2869+ .llseek = default_llseek
2870+};
2871+
28082872 static const struct file_operations *debugfs_regs[] = {
28092873 &amdgpu_debugfs_regs_fops,
28102874 &amdgpu_debugfs_regs_didt_fops,
28112875 &amdgpu_debugfs_regs_pcie_fops,
28122876 &amdgpu_debugfs_regs_smc_fops,
28132877 &amdgpu_debugfs_gca_config_fops,
2878+ &amdgpu_debugfs_sensors_fops,
28142879 };
28152880
28162881 static const char *debugfs_regs_names[] = {
@@ -2819,6 +2884,7 @@ static const char *debugfs_regs_names[] = { · 2 unmodified lines
28192884 "amdgpu_regs_pcie",
28202885 "amdgpu_regs_smc",
28212886 "amdgpu_gca_config",
2887+ "amdgpu_sensors",
28222888 };
28232889
28242890 static int amdgpu_debugfs_regs_init(struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c+3−2
@@ -56,9 +56,10 @@ · 55 unmodified lines
5656 * - 3.4.0 - Add AMDGPU_INFO_NUM_EVICTIONS.
5757 * - 3.5.0 - Add support for new UVD_NO_OP register.
5858 * - 3.6.0 - kmd involves use CONTEXT_CONTROL in ring buffer.
59+ * - 3.7.0 - Add support for VCE clock list packet
5960 */
6061 #define KMS_DRIVER_MAJOR 3
61−#define KMS_DRIVER_MINOR 6
62+#define KMS_DRIVER_MINOR 7
6263 #define KMS_DRIVER_PATCHLEVEL 0
6364
6465 int amdgpu_vram_limit = 0;
@@ -485,7 +486,7 @@ amdgpu_pci_shutdown(struct pci_dev *pdev) · 420 unmodified lines
485486 /* if we are running in a VM, make sure the device
486487 * torn down properly on reboot/shutdown
487488 */
488− if (adev->virtualization.is_virtual)
489+ if (amdgpu_passthrough(adev))
489490 amdgpu_pci_remove(pdev);
490491 }
491492
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c+60−2
@@ -1322,6 +1322,64 @@ void amdgpu_pm_compute_clocks(struct amdgpu_device *adev) · 1321 unmodified lines
13221322 */
13231323 #if defined(CONFIG_DEBUG_FS)
13241324
1325+static int amdgpu_debugfs_pm_info_pp(struct seq_file *m, struct amdgpu_device *adev)
1326+{
1327+ int32_t value;
1328+
1329+ /* sanity check PP is enabled */
1330+ if (!(adev->powerplay.pp_funcs &&
1331+ adev->powerplay.pp_funcs->read_sensor))
1332+ return -EINVAL;
1333+
1334+ /* GPU Clocks */
1335+ seq_printf(m, "GFX Clocks and Power:\n");
1336+ if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_MCLK, &value))
1337+ seq_printf(m, "\t%u MHz (MCLK)\n", value/100);
1338+ if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_SCLK, &value))
1339+ seq_printf(m, "\t%u MHz (SCLK)\n", value/100);
1340+ if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDGFX, &value))
1341+ seq_printf(m, "\t%u mV (VDDGFX)\n", value);
1342+ if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDNB, &value))
1343+ seq_printf(m, "\t%u mV (VDDNB)\n", value);
1344+ seq_printf(m, "\n");
1345+
1346+ /* GPU Temp */
1347+ if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_TEMP, &value))
1348+ seq_printf(m, "GPU Temperature: %u C\n", value/1000);
1349+
1350+ /* GPU Load */
1351+ if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_LOAD, &value))
1352+ seq_printf(m, "GPU Load: %u %%\n", value);
1353+ seq_printf(m, "\n");
1354+
1355+ /* UVD clocks */
1356+ if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_POWER, &value)) {
1357+ if (!value) {
1358+ seq_printf(m, "UVD: Disabled\n");
1359+ } else {
1360+ seq_printf(m, "UVD: Enabled\n");
1361+ if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_DCLK, &value))
1362+ seq_printf(m, "\t%u MHz (DCLK)\n", value/100);
1363+ if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_VCLK, &value))
1364+ seq_printf(m, "\t%u MHz (VCLK)\n", value/100);
1365+ }
1366+ }
1367+ seq_printf(m, "\n");
1368+
1369+ /* VCE clocks */
1370+ if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCE_POWER, &value)) {
1371+ if (!value) {
1372+ seq_printf(m, "VCE: Disabled\n");
1373+ } else {
1374+ seq_printf(m, "VCE: Enabled\n");
1375+ if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCE_ECCLK, &value))
1376+ seq_printf(m, "\t%u MHz (ECCLK)\n", value/100);
1377+ }
1378+ }
1379+
1380+ return 0;
1381+}
1382+
13251383 static int amdgpu_debugfs_pm_info(struct seq_file *m, void *data)
13261384 {
13271385 struct drm_info_node *node = (struct drm_info_node *) m->private;
@@ -1337,11 +1395,11 @@ static int amdgpu_debugfs_pm_info(struct seq_file *m, void *data) · 9 unmodified lines
13371395 (ddev->switch_power_state != DRM_SWITCH_POWER_ON)) {
13381396 seq_printf(m, "PX asic powered off\n");
13391397 } else if (adev->pp_enabled) {
1340− amdgpu_dpm_debugfs_print_current_performance_level(adev, m);
1398+ return amdgpu_debugfs_pm_info_pp(m, adev);
13411399 } else {
13421400 mutex_lock(&adev->pm.mutex);
13431401 if (adev->pm.funcs->debugfs_print_current_performance_level)
1344− amdgpu_dpm_debugfs_print_current_performance_level(adev, m);
1402+ adev->pm.funcs->debugfs_print_current_performance_level(adev, m);
13451403 else
13461404 seq_printf(m, "Debugfs support not implemented for this asic\n");
13471405 mutex_unlock(&adev->pm.mutex);
drivers/gpu/drm/amd/amdgpu/amdgpu_powerplay.c+2−11
@@ -80,15 +80,6 @@ static int amdgpu_powerplay_init(struct amdgpu_device *adev) · 79 unmodified lines
8080 amd_pp->ip_funcs = &kv_dpm_ip_funcs;
8181 break;
8282 #endif
83− case CHIP_TOPAZ:
84− amd_pp->ip_funcs = &iceland_dpm_ip_funcs;
85− break;
86− case CHIP_TONGA:
87− amd_pp->ip_funcs = &tonga_dpm_ip_funcs;
88− break;
89− case CHIP_FIJI:
90− amd_pp->ip_funcs = &fiji_dpm_ip_funcs;
91− break;
9283 case CHIP_CARRIZO:
9384 case CHIP_STONEY:
9485 amd_pp->ip_funcs = &cz_dpm_ip_funcs;
@@ -110,11 +101,11 @@ static int amdgpu_pp_early_init(void *handle) · 15 unmodified lines
110101 switch (adev->asic_type) {
111102 case CHIP_POLARIS11:
112103 case CHIP_POLARIS10:
113− adev->pp_enabled = true;
114− break;
115104 case CHIP_TONGA:
116105 case CHIP_FIJI:
117106 case CHIP_TOPAZ:
107+ adev->pp_enabled = true;
108+ break;
118109 case CHIP_CARRIZO:
119110 case CHIP_STONEY:
120111 adev->pp_enabled = (amdgpu_powerplay == 0) ? false : true;
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c+1−0
@@ -691,6 +691,7 @@ int amdgpu_vce_ring_parse_cs(struct amdgpu_cs_parser *p, uint32_t ib_idx) · 690 unmodified lines
691691 case 0x04000008: /* rdo */
692692 case 0x04000009: /* vui */
693693 case 0x05000002: /* auxiliary buffer */
694+ case 0x05000009: /* clock table */
694695 break;
695696
696697 case 0x03000001: /* encode */
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.hrenamed from drivers/gpu/drm/amd/powerplay/hwmgr/polaris10_clockpowergating.h+31−14
@@ -19,22 +19,39 @@ · 18 unmodified lines
1919 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2020 * OTHER DEALINGS IN THE SOFTWARE.
2121 *
22+ * Author: Monk.liu@amd.com
2223 */
24+#ifndef AMDGPU_VIRT_H
25+#define AMDGPU_VIRT_H
2326
24−#ifndef _POLARIS10_CLOCK_POWER_GATING_H_
25−#define _POLARIS10_CLOCK_POWER_GATING_H_
27+#define AMDGPU_SRIOV_CAPS_SRIOV_VBIOS (1 << 0) /* vBIOS is sr-iov ready */
28+#define AMDGPU_SRIOV_CAPS_ENABLE_IOV (1 << 1) /* sr-iov is enabled on this GPU */
29+#define AMDGPU_SRIOV_CAPS_IS_VF (1 << 2) /* this GPU is a virtual function */
30+#define AMDGPU_PASSTHROUGH_MODE (1 << 3) /* thw whole GPU is pass through for VM */
31+/* GPU virtualization */
32+struct amdgpu_virtualization {
33+ uint32_t virtual_caps;
34+};
2635
27−#include "polaris10_hwmgr.h"
28−#include "pp_asicblocks.h"
36+#define amdgpu_sriov_enabled(adev) \
37+((adev)->virtualization.virtual_caps & AMDGPU_SRIOV_CAPS_ENABLE_IOV)
2938
30−int polaris10_phm_powergate_vce(struct pp_hwmgr *hwmgr, bool bgate);
31−int polaris10_phm_powergate_uvd(struct pp_hwmgr *hwmgr, bool bgate);
32−int polaris10_phm_powerdown_uvd(struct pp_hwmgr *hwmgr);
33−int polaris10_phm_powergate_samu(struct pp_hwmgr *hwmgr, bool bgate);
34−int polaris10_phm_powergate_acp(struct pp_hwmgr *hwmgr, bool bgate);
35−int polaris10_phm_disable_clock_power_gating(struct pp_hwmgr *hwmgr);
36−int polaris10_phm_update_clock_gatings(struct pp_hwmgr *hwmgr,
37− const uint32_t *msg_id);
38−int polaris10_phm_enable_per_cu_power_gating(struct pp_hwmgr *hwmgr, bool enable);
39+#define amdgpu_sriov_vf(adev) \
40+((adev)->virtualization.virtual_caps & AMDGPU_SRIOV_CAPS_IS_VF)
3941
40−#endif /* _POLARIS10_CLOCK_POWER_GATING_H_ */
42+#define amdgpu_sriov_bios(adev) \
43+((adev)->virtualization.virtual_caps & AMDGPU_SRIOV_CAPS_SRIOV_VBIOS)
44+
45+#define amdgpu_passthrough(adev) \
46+((adev)->virtualization.virtual_caps & AMDGPU_PASSTHROUGH_MODE)
47+
48+static inline bool is_virtual_machine(void)
49+{
50+#ifdef CONFIG_X86
51+ return boot_cpu_has(X86_FEATURE_HYPERVISOR);
52+#else
53+ return false;
54+#endif
55+}
56+
57+#endif
drivers/gpu/drm/amd/amdgpu/cik.c+7−7
@@ -963,12 +963,6 @@ static bool cik_read_bios_from_rom(struct amdgpu_device *adev, · 962 unmodified lines
963963 return true;
964964 }
965965
966−static u32 cik_get_virtual_caps(struct amdgpu_device *adev)
967−{
968− /* CIK does not support SR-IOV */
969− return 0;
970−}
971−
972966 static const struct amdgpu_allowed_register_entry cik_allowed_read_registers[] = {
973967 {mmGRBM_STATUS, false},
974968 {mmGB_ADDR_CONFIG, false},
@@ -1641,6 +1635,12 @@ static uint32_t cik_get_rev_id(struct amdgpu_device *adev) · 666 unmodified lines
16411635 >> CC_DRM_ID_STRAPS__ATI_REV_ID__SHIFT;
16421636 }
16431637
1638+static void cik_detect_hw_virtualization(struct amdgpu_device *adev)
1639+{
1640+ if (is_virtual_machine()) /* passthrough mode */
1641+ adev->virtualization.virtual_caps |= AMDGPU_PASSTHROUGH_MODE;
1642+}
1643+
16441644 static const struct amdgpu_ip_block_version bonaire_ip_blocks[] =
16451645 {
16461646 /* ORDER MATTERS! */
@@ -2384,13 +2384,13 @@ static const struct amdgpu_asic_funcs cik_asic_funcs = · 737 unmodified lines
23842384 {
23852385 .read_disabled_bios = &cik_read_disabled_bios,
23862386 .read_bios_from_rom = &cik_read_bios_from_rom,
2387+ .detect_hw_virtualization = cik_detect_hw_virtualization,
23872388 .read_register = &cik_read_register,
23882389 .reset = &cik_asic_reset,
23892390 .set_vga_state = &cik_vga_set_state,
23902391 .get_xclk = &cik_get_xclk,
23912392 .set_uvd_clocks = &cik_set_uvd_clocks,
23922393 .set_vce_clocks = &cik_set_vce_clocks,
2393− .get_virtual_caps = &cik_get_virtual_caps,
23942394 };
23952395
23962396 static int cik_common_early_init(void *handle)
drivers/gpu/drm/amd/amdgpu/cikd.h+36−0
@@ -562,4 +562,40 @@ enum { · 561 unmodified lines
562562 MTYPE_NONCACHED = 3
563563 };
564564
565+/* mmPA_SC_RASTER_CONFIG mask */
566+#define RB_MAP_PKR0(x) ((x) << 0)
567+#define RB_MAP_PKR0_MASK (0x3 << 0)
568+#define RB_MAP_PKR1(x) ((x) << 2)
569+#define RB_MAP_PKR1_MASK (0x3 << 2)
570+#define RB_XSEL2(x) ((x) << 4)
571+#define RB_XSEL2_MASK (0x3 << 4)
572+#define RB_XSEL (1 << 6)
573+#define RB_YSEL (1 << 7)
574+#define PKR_MAP(x) ((x) << 8)
575+#define PKR_MAP_MASK (0x3 << 8)
576+#define PKR_XSEL(x) ((x) << 10)
577+#define PKR_XSEL_MASK (0x3 << 10)
578+#define PKR_YSEL(x) ((x) << 12)
579+#define PKR_YSEL_MASK (0x3 << 12)
580+#define SC_MAP(x) ((x) << 16)
581+#define SC_MAP_MASK (0x3 << 16)
582+#define SC_XSEL(x) ((x) << 18)
583+#define SC_XSEL_MASK (0x3 << 18)
584+#define SC_YSEL(x) ((x) << 20)
585+#define SC_YSEL_MASK (0x3 << 20)
586+#define SE_MAP(x) ((x) << 24)
587+#define SE_MAP_MASK (0x3 << 24)
588+#define SE_XSEL(x) ((x) << 26)
589+#define SE_XSEL_MASK (0x3 << 26)
590+#define SE_YSEL(x) ((x) << 28)
591+#define SE_YSEL_MASK (0x3 << 28)
592+
593+/* mmPA_SC_RASTER_CONFIG_1 mask */
594+#define SE_PAIR_MAP(x) ((x) << 0)
595+#define SE_PAIR_MAP_MASK (0x3 << 0)
596+#define SE_PAIR_XSEL(x) ((x) << 2)
597+#define SE_PAIR_XSEL_MASK (0x3 << 2)
598+#define SE_PAIR_YSEL(x) ((x) << 4)
599+#define SE_PAIR_YSEL_MASK (0x3 << 4)
600+
565601 #endif
drivers/gpu/drm/amd/amdgpu/cz_smc.c+0−7
@@ -101,13 +101,6 @@ int cz_send_msg_to_smc(struct amdgpu_device *adev, u16 msg) · 100 unmodified lines
101101 return 0;
102102 }
103103
104−int cz_send_msg_to_smc_with_parameter_async(struct amdgpu_device *adev,
105− u16 msg, u32 parameter)
106−{
107− WREG32(mmSMU_MP1_SRBM2P_ARG_0, parameter);
108− return cz_send_msg_to_smc_async(adev, msg);
109−}
110−
111104 int cz_send_msg_to_smc_with_parameter(struct amdgpu_device *adev,
112105 u16 msg, u32 parameter)
113106 {
drivers/gpu/drm/amd/amdgpu/dce_v10_0.c+5−3
@@ -221,7 +221,7 @@ static bool dce_v10_0_is_counter_moving(struct amdgpu_device *adev, int crtc) · 220 unmodified lines
221221 */
222222 static void dce_v10_0_vblank_wait(struct amdgpu_device *adev, int crtc)
223223 {
224− unsigned i = 0;
224+ unsigned i = 100;
225225
226226 if (crtc >= adev->mode_info.num_crtc)
227227 return;
@@ -233,14 +233,16 @@ static void dce_v10_0_vblank_wait(struct amdgpu_device *adev, int crtc) · 5 unmodified lines
233233 * wait for another frame.
234234 */
235235 while (dce_v10_0_is_in_vblank(adev, crtc)) {
236− if (i++ % 100 == 0) {
236+ if (i++ == 100) {
237+ i = 0;
237238 if (!dce_v10_0_is_counter_moving(adev, crtc))
238239 break;
239240 }
240241 }
241242
242243 while (!dce_v10_0_is_in_vblank(adev, crtc)) {
243− if (i++ % 100 == 0) {
244+ if (i++ == 100) {
245+ i = 0;
244246 if (!dce_v10_0_is_counter_moving(adev, crtc))
245247 break;
246248 }
drivers/gpu/drm/amd/amdgpu/dce_v6_0.c+22−10
@@ -146,7 +146,7 @@ static bool dce_v6_0_is_counter_moving(struct amdgpu_device *adev, int crtc) · 145 unmodified lines
146146 */
147147 static void dce_v6_0_vblank_wait(struct amdgpu_device *adev, int crtc)
148148 {
149− unsigned i = 0;
149+ unsigned i = 100;
150150
151151 if (crtc >= adev->mode_info.num_crtc)
152152 return;
@@ -158,14 +158,16 @@ static void dce_v6_0_vblank_wait(struct amdgpu_device *adev, int crtc) · 5 unmodified lines
158158 * wait for another frame.
159159 */
160160 while (dce_v6_0_is_in_vblank(adev, crtc)) {
161− if (i++ % 100 == 0) {
161+ if (i++ == 100) {
162+ i = 0;
162163 if (!dce_v6_0_is_counter_moving(adev, crtc))
163164 break;
164165 }
165166 }
166167
167168 while (!dce_v6_0_is_in_vblank(adev, crtc)) {
168− if (i++ % 100 == 0) {
169+ if (i++ == 100) {
170+ i = 0;
169171 if (!dce_v6_0_is_counter_moving(adev, crtc))
170172 break;
171173 }
@@ -185,7 +187,7 @@ static void dce_v6_0_pageflip_interrupt_init(struct amdgpu_device *adev) · 13 unmodified lines
185187 unsigned i;
186188
187189 /* Enable pflip interrupts */
188− for (i = 0; i <= adev->mode_info.num_crtc; i++)
190+ for (i = 0; i < adev->mode_info.num_crtc; i++)
189191 amdgpu_irq_get(adev, &adev->pageflip_irq, i);
190192 }
191193
@@ -194,7 +196,7 @@ static void dce_v6_0_pageflip_interrupt_fini(struct amdgpu_device *adev) · 2 unmodified lines
194196 unsigned i;
195197
196198 /* Disable pflip interrupts */
197− for (i = 0; i <= adev->mode_info.num_crtc; i++)
199+ for (i = 0; i < adev->mode_info.num_crtc; i++)
198200 amdgpu_irq_put(adev, &adev->pageflip_irq, i);
199201 }
200202
@@ -1420,21 +1422,29 @@ static void dce_v6_0_afmt_enable(struct drm_encoder *encoder, bool enable) · 1219 unmodified lines
14201422 enable ? "En" : "Dis", dig->afmt->offset, amdgpu_encoder->encoder_id);
14211423 }
14221424
1423−static void dce_v6_0_afmt_init(struct amdgpu_device *adev)
1425+static int dce_v6_0_afmt_init(struct amdgpu_device *adev)
14241426 {
1425− int i;
1427+ int i, j;
14261428
14271429 for (i = 0; i < adev->mode_info.num_dig; i++)
14281430 adev->mode_info.afmt[i] = NULL;
14291431
1430− /* DCE8 has audio blocks tied to DIG encoders */
1432+ /* DCE6 has audio blocks tied to DIG encoders */
14311433 for (i = 0; i < adev->mode_info.num_dig; i++) {
14321434 adev->mode_info.afmt[i] = kzalloc(sizeof(struct amdgpu_afmt), GFP_KERNEL);
14331435 if (adev->mode_info.afmt[i]) {
14341436 adev->mode_info.afmt[i]->offset = dig_offsets[i];
14351437 adev->mode_info.afmt[i]->id = i;
1438+ } else {
1439+ for (j = 0; j < i; j++) {
1440+ kfree(adev->mode_info.afmt[j]);
1441+ adev->mode_info.afmt[j] = NULL;
1442+ }
1443+ DRM_ERROR("Out of memory allocating afmt table\n");
1444+ return -ENOMEM;
14361445 }
14371446 }
1447+ return 0;
14381448 }
14391449
14401450 static void dce_v6_0_afmt_fini(struct amdgpu_device *adev)
@@ -2397,7 +2407,9 @@ static int dce_v6_0_sw_init(void *handle) · 956 unmodified lines
23972407 return -EINVAL;
23982408
23992409 /* setup afmt */
2400− dce_v6_0_afmt_init(adev);
2410+ r = dce_v6_0_afmt_init(adev);
2411+ if (r)
2412+ return r;
24012413
24022414 r = dce_v6_0_audio_init(adev);
24032415 if (r)
@@ -2782,7 +2794,7 @@ static int dce_v6_0_hpd_irq(struct amdgpu_device *adev, · 378 unmodified lines
27822794 uint32_t disp_int, mask, int_control, tmp;
27832795 unsigned hpd;
27842796
2785− if (entry->src_data > 6) {
2797+ if (entry->src_data >= adev->mode_info.num_hpd) {
27862798 DRM_DEBUG("Unhandled interrupt: %d %d\n", entry->src_id, entry->src_data);
27872799 return 0;
27882800 }
drivers/gpu/drm/amd/amdgpu/dce_v8_0.c+5−3
@@ -170,7 +170,7 @@ static bool dce_v8_0_is_counter_moving(struct amdgpu_device *adev, int crtc) · 169 unmodified lines
170170 */
171171 static void dce_v8_0_vblank_wait(struct amdgpu_device *adev, int crtc)
172172 {
173− unsigned i = 0;
173+ unsigned i = 100;
174174
175175 if (crtc >= adev->mode_info.num_crtc)
176176 return;
@@ -182,14 +182,16 @@ static void dce_v8_0_vblank_wait(struct amdgpu_device *adev, int crtc) · 5 unmodified lines
182182 * wait for another frame.
183183 */
184184 while (dce_v8_0_is_in_vblank(adev, crtc)) {
185− if (i++ % 100 == 0) {
185+ if (i++ == 100) {
186+ i = 0;
186187 if (!dce_v8_0_is_counter_moving(adev, crtc))
187188 break;
188189 }
189190 }
190191
191192 while (!dce_v8_0_is_in_vblank(adev, crtc)) {
192− if (i++ % 100 == 0) {
193+ if (i++ == 100) {
194+ i = 0;
193195 if (!dce_v8_0_is_counter_moving(adev, crtc))
194196 break;
195197 }
drivers/gpu/drm/amd/amdgpu/dce_virtual.c+3−3
@@ -95,7 +95,7 @@ static bool dce_virtual_is_display_hung(struct amdgpu_device *adev) · 94 unmodified lines
9595 return false;
9696 }
9797
98−void dce_virtual_stop_mc_access(struct amdgpu_device *adev,
98+static void dce_virtual_stop_mc_access(struct amdgpu_device *adev,
9999 struct amdgpu_mode_mc_save *save)
100100 {
101101 switch (adev->asic_type) {
@@ -127,13 +127,13 @@ void dce_virtual_stop_mc_access(struct amdgpu_device *adev, · 25 unmodified lines
127127
128128 return;
129129 }
130−void dce_virtual_resume_mc_access(struct amdgpu_device *adev,
130+static void dce_virtual_resume_mc_access(struct amdgpu_device *adev,
131131 struct amdgpu_mode_mc_save *save)
132132 {
133133 return;
134134 }
135135
136−void dce_virtual_set_vga_render_state(struct amdgpu_device *adev,
136+static void dce_virtual_set_vga_render_state(struct amdgpu_device *adev,
137137 bool render)
138138 {
139139 return;
drivers/gpu/drm/amd/amdgpu/fiji_dpm.c+0−186
@@ -1,186 +0,0 @@
1−/*
2− * Copyright 2014 Advanced Micro Devices, Inc.
3− *
4− * Permission is hereby granted, free of charge, to any person obtaining a
5− * copy of this software and associated documentation files (the "Software"),
6− * to deal in the Software without restriction, including without limitation
7− * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8− * and/or sell copies of the Software, and to permit persons to whom the
9− * Software is furnished to do so, subject to the following conditions:
10− *
11− * The above copyright notice and this permission notice shall be included in
12− * all copies or substantial portions of the Software.
13− *
14− * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15− * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16− * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17− * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18− * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19− * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20− * OTHER DEALINGS IN THE SOFTWARE.
21− *
22− */
23−
24−#include <linux/firmware.h>
25−#include "drmP.h"
26−#include "amdgpu.h"
27−#include "fiji_smum.h"
28−
29−MODULE_FIRMWARE("amdgpu/fiji_smc.bin");
30−
31−static void fiji_dpm_set_funcs(struct amdgpu_device *adev);
32−
33−static int fiji_dpm_early_init(void *handle)
34−{
35− struct amdgpu_device *adev = (struct amdgpu_device *)handle;
36−
37− fiji_dpm_set_funcs(adev);
38−
39− return 0;
40−}
41−
42−static int fiji_dpm_init_microcode(struct amdgpu_device *adev)
43−{
44− char fw_name[30] = "amdgpu/fiji_smc.bin";
45− int err;
46−
47− err = request_firmware(&adev->pm.fw, fw_name, adev->dev);
48− if (err)
49− goto out;
50− err = amdgpu_ucode_validate(adev->pm.fw);
51−
52−out:
53− if (err) {
54− DRM_ERROR("Failed to load firmware \"%s\"", fw_name);
55− release_firmware(adev->pm.fw);
56− adev->pm.fw = NULL;
57− }
58− return err;
59−}
60−
61−static int fiji_dpm_sw_init(void *handle)
62−{
63− int ret;
64− struct amdgpu_device *adev = (struct amdgpu_device *)handle;
65−
66− ret = fiji_dpm_init_microcode(adev);
67− if (ret)
68− return ret;
69−
70− return 0;
71−}
72−
73−static int fiji_dpm_sw_fini(void *handle)
74−{
75− struct amdgpu_device *adev = (struct amdgpu_device *)handle;
76−
77− release_firmware(adev->pm.fw);
78− adev->pm.fw = NULL;
79−
80− return 0;
81−}
82−
83−static int fiji_dpm_hw_init(void *handle)
84−{
85− int ret;
86− struct amdgpu_device *adev = (struct amdgpu_device *)handle;
87−
88− mutex_lock(&adev->pm.mutex);
89−
90− ret = fiji_smu_init(adev);
91− if (ret) {
92− DRM_ERROR("SMU initialization failed\n");
93− goto fail;
94− }
95−
96− ret = fiji_smu_start(adev);
97− if (ret) {
98− DRM_ERROR("SMU start failed\n");
99− goto fail;
100− }
101−
102− mutex_unlock(&adev->pm.mutex);
103− return 0;
104−
105−fail:
106− adev->firmware.smu_load = false;
107− mutex_unlock(&adev->pm.mutex);
108− return -EINVAL;
109−}
110−
111−static int fiji_dpm_hw_fini(void *handle)
112−{
113− struct amdgpu_device *adev = (struct amdgpu_device *)handle;
114− mutex_lock(&adev->pm.mutex);
115− fiji_smu_fini(adev);
116− mutex_unlock(&adev->pm.mutex);
117− return 0;
118−}
119−
120−static int fiji_dpm_suspend(void *handle)
121−{
122− struct amdgpu_device *adev = (struct amdgpu_device *)handle;
123−
124− fiji_dpm_hw_fini(adev);
125−
126− return 0;
127−}
128−
129−static int fiji_dpm_resume(void *handle)
130−{
131− struct amdgpu_device *adev = (struct amdgpu_device *)handle;
132−
133− fiji_dpm_hw_init(adev);
134−
135− return 0;
136−}
137−
138−static int fiji_dpm_set_clockgating_state(void *handle,
139− enum amd_clockgating_state state)
140−{
141− return 0;
142−}
143−
144−static int fiji_dpm_set_powergating_state(void *handle,
145− enum amd_powergating_state state)
146−{
147− return 0;
148−}
149−
150−const struct amd_ip_funcs fiji_dpm_ip_funcs = {
151− .name = "fiji_dpm",
152− .early_init = fiji_dpm_early_init,
153− .late_init = NULL,
154− .sw_init = fiji_dpm_sw_init,
155− .sw_fini = fiji_dpm_sw_fini,
156− .hw_init = fiji_dpm_hw_init,
157− .hw_fini = fiji_dpm_hw_fini,
158− .suspend = fiji_dpm_suspend,
159− .resume = fiji_dpm_resume,
160− .is_idle = NULL,
161− .wait_for_idle = NULL,
162− .soft_reset = NULL,
163− .set_clockgating_state = fiji_dpm_set_clockgating_state,
164− .set_powergating_state = fiji_dpm_set_powergating_state,
165−};
166−
167−static const struct amdgpu_dpm_funcs fiji_dpm_funcs = {
168− .get_temperature = NULL,
169− .pre_set_power_state = NULL,
170− .set_power_state = NULL,
171− .post_set_power_state = NULL,
172− .display_configuration_changed = NULL,
173− .get_sclk = NULL,
174− .get_mclk = NULL,
175− .print_power_state = NULL,
176− .debugfs_print_current_performance_level = NULL,
177− .force_performance_level = NULL,
178− .vblank_too_short = NULL,
179− .powergate_uvd = NULL,
180−};
181−
182−static void fiji_dpm_set_funcs(struct amdgpu_device *adev)
183−{
184− if (NULL == adev->pm.funcs)
185− adev->pm.funcs = &fiji_dpm_funcs;
186−}
drivers/gpu/drm/amd/amdgpu/fiji_smc.c+0−863
@@ -1,863 +0,0 @@
1−/*
2− * Copyright 2014 Advanced Micro Devices, Inc.
3− *
4− * Permission is hereby granted, free of charge, to any person obtaining a
5− * copy of this software and associated documentation files (the "Software"),
6− * to deal in the Software without restriction, including without limitation
7− * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8− * and/or sell copies of the Software, and to permit persons to whom the
9− * Software is furnished to do so, subject to the following conditions:
10− *
11− * The above copyright notice and this permission notice shall be included in
12− * all copies or substantial portions of the Software.
13− *
14− * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15− * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16− * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17− * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18− * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19− * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20− * OTHER DEALINGS IN THE SOFTWARE.
21− *
22− */
23−
24−#include <linux/firmware.h>
25−#include "drmP.h"
26−#include "amdgpu.h"
27−#include "fiji_ppsmc.h"
28−#include "fiji_smum.h"
29−#include "smu_ucode_xfer_vi.h"
30−#include "amdgpu_ucode.h"
31−
32−#include "smu/smu_7_1_3_d.h"
33−#include "smu/smu_7_1_3_sh_mask.h"
34−
35−#define FIJI_SMC_SIZE 0x20000
36−
37−static int fiji_set_smc_sram_address(struct amdgpu_device *adev, uint32_t smc_address, uint32_t limit)
38−{
39− uint32_t val;
40−
41− if (smc_address & 3)
42− return -EINVAL;
43−
44− if ((smc_address + 3) > limit)
45− return -EINVAL;
46−
47− WREG32(mmSMC_IND_INDEX_0, smc_address);
48−
49− val = RREG32(mmSMC_IND_ACCESS_CNTL);
50− val = REG_SET_FIELD(val, SMC_IND_ACCESS_CNTL, AUTO_INCREMENT_IND_0, 0);
51− WREG32(mmSMC_IND_ACCESS_CNTL, val);
52−
53− return 0;
54−}
55−
56−static int fiji_copy_bytes_to_smc(struct amdgpu_device *adev, uint32_t smc_start_address, const uint8_t *src, uint32_t byte_count, uint32_t limit)
57−{
58− uint32_t addr;
59− uint32_t data, orig_data;
60− int result = 0;
61− uint32_t extra_shift;
62− unsigned long flags;
63−
64− if (smc_start_address & 3)
65− return -EINVAL;
66−
67− if ((smc_start_address + byte_count) > limit)
68− return -EINVAL;
69−
70− addr = smc_start_address;
71−
72− spin_lock_irqsave(&adev->smc_idx_lock, flags);
73− while (byte_count >= 4) {
74− /* Bytes are written into the SMC addres space with the MSB first */
75− data = (src[0] << 24) + (src[1] << 16) + (src[2] << 8) + src[3];
76−
77− result = fiji_set_smc_sram_address(adev, addr, limit);
78−
79− if (result)
80− goto out;
81−
82− WREG32(mmSMC_IND_DATA_0, data);
83−
84− src += 4;
85− byte_count -= 4;
86− addr += 4;
87− }
88−
89− if (0 != byte_count) {
90− /* Now write odd bytes left, do a read modify write cycle */
91− data = 0;
92−
93− result = fiji_set_smc_sram_address(adev, addr, limit);
94− if (result)
95− goto out;
96−
97− orig_data = RREG32(mmSMC_IND_DATA_0);
98− extra_shift = 8 * (4 - byte_count);
99−
100− while (byte_count > 0) {
101− data = (data << 8) + *src++;
102− byte_count--;
103− }
104−
105− data <<= extra_shift;
106− data |= (orig_data & ~((~0UL) << extra_shift));
107−
108− result = fiji_set_smc_sram_address(adev, addr, limit);
109− if (result)
110− goto out;
111−
112− WREG32(mmSMC_IND_DATA_0, data);
113− }
114−
115−out:
116− spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
117− return result;
118−}
119−
120−static int fiji_program_jump_on_start(struct amdgpu_device *adev)
121−{
122− static unsigned char data[] = {0xE0, 0x00, 0x80, 0x40};
123− fiji_copy_bytes_to_smc(adev, 0x0, data, 4, sizeof(data)+1);
124−
125− return 0;
126−}
127−
128−static bool fiji_is_smc_ram_running(struct amdgpu_device *adev)
129−{
130− uint32_t val = RREG32_SMC(ixSMC_SYSCON_CLOCK_CNTL_0);
131− val = REG_GET_FIELD(val, SMC_SYSCON_CLOCK_CNTL_0, ck_disable);
132−
133− return ((0 == val) && (0x20100 <= RREG32_SMC(ixSMC_PC_C)));
134−}
135−
136−static int wait_smu_response(struct amdgpu_device *adev)
137−{
138− int i;
139− uint32_t val;
140−
141− for (i = 0; i < adev->usec_timeout; i++) {
142− val = RREG32(mmSMC_RESP_0);
143− if (REG_GET_FIELD(val, SMC_RESP_0, SMC_RESP))
144− break;
145− udelay(1);
146− }
147−
148− if (i == adev->usec_timeout)
149− return -EINVAL;
150−
151− return 0;
152−}
153−
154−static int fiji_send_msg_to_smc_offset(struct amdgpu_device *adev)
155−{
156− if (wait_smu_response(adev)) {
157− DRM_ERROR("Failed to send previous message\n");
158− return -EINVAL;
159− }
160−
161− WREG32(mmSMC_MSG_ARG_0, 0x20000);
162− WREG32(mmSMC_MESSAGE_0, PPSMC_MSG_Test);
163−
164− if (wait_smu_response(adev)) {
165− DRM_ERROR("Failed to send message\n");
166− return -EINVAL;
167− }
168−
169− return 0;
170−}
171−
172−static int fiji_send_msg_to_smc(struct amdgpu_device *adev, PPSMC_Msg msg)
173−{
174− if (!fiji_is_smc_ram_running(adev))
175− {
176− return -EINVAL;
177− }
178−
179− if (wait_smu_response(adev)) {
180− DRM_ERROR("Failed to send previous message\n");
181− return -EINVAL;
182− }
183−
184− WREG32(mmSMC_MESSAGE_0, msg);
185−
186− if (wait_smu_response(adev)) {
187− DRM_ERROR("Failed to send message\n");
188− return -EINVAL;
189− }
190−
191− return 0;
192−}
193−
194−static int fiji_send_msg_to_smc_without_waiting(struct amdgpu_device *adev,
195− PPSMC_Msg msg)
196−{
197− if (wait_smu_response(adev)) {
198− DRM_ERROR("Failed to send previous message\n");
199− return -EINVAL;
200− }
201−
202− WREG32(mmSMC_MESSAGE_0, msg);
203−
204− return 0;
205−}
206−
207−static int fiji_send_msg_to_smc_with_parameter(struct amdgpu_device *adev,
208− PPSMC_Msg msg,
209− uint32_t parameter)
210−{
211− if (!fiji_is_smc_ram_running(adev))
212− return -EINVAL;
213−
214− if (wait_smu_response(adev)) {
215− DRM_ERROR("Failed to send previous message\n");
216− return -EINVAL;
217− }
218−
219− WREG32(mmSMC_MSG_ARG_0, parameter);
220−
221− return fiji_send_msg_to_smc(adev, msg);
222−}
223−
224−static int fiji_send_msg_to_smc_with_parameter_without_waiting(
225− struct amdgpu_device *adev,
226− PPSMC_Msg msg, uint32_t parameter)
227−{
228− if (wait_smu_response(adev)) {
229− DRM_ERROR("Failed to send previous message\n");
230− return -EINVAL;
231− }
232−
233− WREG32(mmSMC_MSG_ARG_0, parameter);
234−
235− return fiji_send_msg_to_smc_without_waiting(adev, msg);
236−}
237−
238−#if 0 /* not used yet */
239−static int fiji_wait_for_smc_inactive(struct amdgpu_device *adev)
240−{
241− int i;
242− uint32_t val;
243−
244− if (!fiji_is_smc_ram_running(adev))
245− return -EINVAL;
246−
247− for (i = 0; i < adev->usec_timeout; i++) {
248− val = RREG32_SMC(ixSMC_SYSCON_CLOCK_CNTL_0);
249− if (REG_GET_FIELD(val, SMC_SYSCON_CLOCK_CNTL_0, cken) == 0)
250− break;
251− udelay(1);
252− }
253−
254− if (i == adev->usec_timeout)
255− return -EINVAL;
256−
257− return 0;
258−}
259−#endif
260−
261−static int fiji_smu_upload_firmware_image(struct amdgpu_device *adev)
262−{
263− const struct smc_firmware_header_v1_0 *hdr;
264− uint32_t ucode_size;
265− uint32_t ucode_start_address;
266− const uint8_t *src;
267− uint32_t val;
268− uint32_t byte_count;
269− uint32_t *data;
270− unsigned long flags;
271−
272− if (!adev->pm.fw)
273− return -EINVAL;
274−
275− /* Skip SMC ucode loading on SR-IOV capable boards.
276− * vbios does this for us in asic_init in that case.
277− */
278− if (adev->virtualization.supports_sr_iov)
279− return 0;
280−
281− hdr = (const struct smc_firmware_header_v1_0 *)adev->pm.fw->data;
282− amdgpu_ucode_print_smc_hdr(&hdr->header);
283−
284− adev->pm.fw_version = le32_to_cpu(hdr->header.ucode_version);
285− ucode_size = le32_to_cpu(hdr->header.ucode_size_bytes);
286− ucode_start_address = le32_to_cpu(hdr->ucode_start_addr);
287− src = (const uint8_t *)
288− (adev->pm.fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
289−
290− if (ucode_size & 3) {
291− DRM_ERROR("SMC ucode is not 4 bytes aligned\n");
292− return -EINVAL;
293− }
294−
295− if (ucode_size > FIJI_SMC_SIZE) {
296− DRM_ERROR("SMC address is beyond the SMC RAM area\n");
297− return -EINVAL;
298− }
299−
300− spin_lock_irqsave(&adev->smc_idx_lock, flags);
301− WREG32(mmSMC_IND_INDEX_0, ucode_start_address);
302−
303− val = RREG32(mmSMC_IND_ACCESS_CNTL);
304− val = REG_SET_FIELD(val, SMC_IND_ACCESS_CNTL, AUTO_INCREMENT_IND_0, 1);
305− WREG32(mmSMC_IND_ACCESS_CNTL, val);
306−
307− byte_count = ucode_size;
308− data = (uint32_t *)src;
309− for (; byte_count >= 4; data++, byte_count -= 4)
310− WREG32(mmSMC_IND_DATA_0, data[0]);
311−
312− val = RREG32(mmSMC_IND_ACCESS_CNTL);
313− val = REG_SET_FIELD(val, SMC_IND_ACCESS_CNTL, AUTO_INCREMENT_IND_0, 0);
314− WREG32(mmSMC_IND_ACCESS_CNTL, val);
315− spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
316−
317− return 0;
318−}
319−
320−#if 0 /* not used yet */
321−static int fiji_read_smc_sram_dword(struct amdgpu_device *adev,
322− uint32_t smc_address,
323− uint32_t *value,
324− uint32_t limit)
325−{
326− int result;
327− unsigned long flags;
328−
329− spin_lock_irqsave(&adev->smc_idx_lock, flags);
330− result = fiji_set_smc_sram_address(adev, smc_address, limit);
331− if (result == 0)
332− *value = RREG32(mmSMC_IND_DATA_0);
333− spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
334− return result;
335−}
336−
337−static int fiji_write_smc_sram_dword(struct amdgpu_device *adev,
338− uint32_t smc_address,
339− uint32_t value,
340− uint32_t limit)
341−{
342− int result;
343− unsigned long flags;
344−
345− spin_lock_irqsave(&adev->smc_idx_lock, flags);
346− result = fiji_set_smc_sram_address(adev, smc_address, limit);
347− if (result == 0)
348− WREG32(mmSMC_IND_DATA_0, value);
349− spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
350− return result;
351−}
352−
353−static int fiji_smu_stop_smc(struct amdgpu_device *adev)
354−{
355− uint32_t val = RREG32_SMC(ixSMC_SYSCON_RESET_CNTL);
356− val = REG_SET_FIELD(val, SMC_SYSCON_RESET_CNTL, rst_reg, 1);
357− WREG32_SMC(ixSMC_SYSCON_RESET_CNTL, val);
358−
359− val = RREG32_SMC(ixSMC_SYSCON_CLOCK_CNTL_0);
360− val = REG_SET_FIELD(val, SMC_SYSCON_CLOCK_CNTL_0, ck_disable, 1);
361− WREG32_SMC(ixSMC_SYSCON_CLOCK_CNTL_0, val);
362−
363− return 0;
364−}
365−#endif
366−
367−static enum AMDGPU_UCODE_ID fiji_convert_fw_type(uint32_t fw_type)
368−{
369− switch (fw_type) {
370− case UCODE_ID_SDMA0:
371− return AMDGPU_UCODE_ID_SDMA0;
372− case UCODE_ID_SDMA1:
373− return AMDGPU_UCODE_ID_SDMA1;
374− case UCODE_ID_CP_CE:
375− return AMDGPU_UCODE_ID_CP_CE;
376− case UCODE_ID_CP_PFP:
377− return AMDGPU_UCODE_ID_CP_PFP;
378− case UCODE_ID_CP_ME:
379− return AMDGPU_UCODE_ID_CP_ME;
380− case UCODE_ID_CP_MEC:
381− case UCODE_ID_CP_MEC_JT1:
382− case UCODE_ID_CP_MEC_JT2:
383− return AMDGPU_UCODE_ID_CP_MEC1;
384− case UCODE_ID_RLC_G:
385− return AMDGPU_UCODE_ID_RLC_G;
386− default:
387− DRM_ERROR("ucode type is out of range!\n");
388− return AMDGPU_UCODE_ID_MAXIMUM;
389− }
390−}
391−
392−static int fiji_smu_populate_single_firmware_entry(struct amdgpu_device *adev,
393− uint32_t fw_type,
394− struct SMU_Entry *entry)
395−{
396− enum AMDGPU_UCODE_ID id = fiji_convert_fw_type(fw_type);
397− struct amdgpu_firmware_info *ucode = &adev->firmware.ucode[id];
398− const struct gfx_firmware_header_v1_0 *header = NULL;
399− uint64_t gpu_addr;
400− uint32_t data_size;
401−
402− if (ucode->fw == NULL)
403− return -EINVAL;
404− gpu_addr = ucode->mc_addr;
405− header = (const struct gfx_firmware_header_v1_0 *)ucode->fw->data;
406− data_size = le32_to_cpu(header->header.ucode_size_bytes);
407−
408− if ((fw_type == UCODE_ID_CP_MEC_JT1) ||
409− (fw_type == UCODE_ID_CP_MEC_JT2)) {
410− gpu_addr += le32_to_cpu(header->jt_offset) << 2;
411− data_size = le32_to_cpu(header->jt_size) << 2;
412− }
413−
414− entry->version = (uint16_t)le32_to_cpu(header->header.ucode_version);
415− entry->id = (uint16_t)fw_type;
416− entry->image_addr_high = upper_32_bits(gpu_addr);
417− entry->image_addr_low = lower_32_bits(gpu_addr);
418− entry->meta_data_addr_high = 0;
419− entry->meta_data_addr_low = 0;
420− entry->data_size_byte = data_size;
421− entry->num_register_entries = 0;
422−
423− if (fw_type == UCODE_ID_RLC_G)
424− entry->flags = 1;
425− else
426− entry->flags = 0;
427−
428− return 0;
429−}
430−
431−static int fiji_smu_request_load_fw(struct amdgpu_device *adev)
432−{
433− struct fiji_smu_private_data *private = (struct fiji_smu_private_data *)adev->smu.priv;
434− struct SMU_DRAMData_TOC *toc;
435− uint32_t fw_to_load;
436−
437− WREG32_SMC(ixSOFT_REGISTERS_TABLE_28, 0);
438−
439− fiji_send_msg_to_smc_with_parameter(adev, PPSMC_MSG_SMU_DRAM_ADDR_HI, private->smu_buffer_addr_high);
440− fiji_send_msg_to_smc_with_parameter(adev, PPSMC_MSG_SMU_DRAM_ADDR_LO, private->smu_buffer_addr_low);
441−
442− toc = (struct SMU_DRAMData_TOC *)private->header;
443− toc->num_entries = 0;
444− toc->structure_version = 1;
445−
446− if (!adev->firmware.smu_load)
447− return 0;
448−
449− if (fiji_smu_populate_single_firmware_entry(adev, UCODE_ID_RLC_G,
450− &toc->entry[toc->num_entries++])) {
451− DRM_ERROR("Failed to get firmware entry for RLC\n");
452− return -EINVAL;
453− }
454−
455− if (fiji_smu_populate_single_firmware_entry(adev, UCODE_ID_CP_CE,
456− &toc->entry[toc->num_entries++])) {
457− DRM_ERROR("Failed to get firmware entry for CE\n");
458− return -EINVAL;
459− }
460−
461− if (fiji_smu_populate_single_firmware_entry(adev, UCODE_ID_CP_PFP,
462− &toc->entry[toc->num_entries++])) {
463− DRM_ERROR("Failed to get firmware entry for PFP\n");
464− return -EINVAL;
465− }
466−
467− if (fiji_smu_populate_single_firmware_entry(adev, UCODE_ID_CP_ME,
468− &toc->entry[toc->num_entries++])) {
469− DRM_ERROR("Failed to get firmware entry for ME\n");
470− return -EINVAL;
471− }
472−
473− if (fiji_smu_populate_single_firmware_entry(adev, UCODE_ID_CP_MEC,
474− &toc->entry[toc->num_entries++])) {
475− DRM_ERROR("Failed to get firmware entry for MEC\n");
476− return -EINVAL;
477− }
478−
479− if (fiji_smu_populate_single_firmware_entry(adev, UCODE_ID_CP_MEC_JT1,
480− &toc->entry[toc->num_entries++])) {
481− DRM_ERROR("Failed to get firmware entry for MEC_JT1\n");
482− return -EINVAL;
483− }
484−
485− if (fiji_smu_populate_single_firmware_entry(adev, UCODE_ID_CP_MEC_JT2,
486− &toc->entry[toc->num_entries++])) {
487− DRM_ERROR("Failed to get firmware entry for MEC_JT2\n");
488− return -EINVAL;
489− }
490−
491− if (fiji_smu_populate_single_firmware_entry(adev, UCODE_ID_SDMA0,
492− &toc->entry[toc->num_entries++])) {
493− DRM_ERROR("Failed to get firmware entry for SDMA0\n");
494− return -EINVAL;
495− }
496−
497− if (fiji_smu_populate_single_firmware_entry(adev, UCODE_ID_SDMA1,
498− &toc->entry[toc->num_entries++])) {
499− DRM_ERROR("Failed to get firmware entry for SDMA1\n");
500− return -EINVAL;
501− }
502−
503− fiji_send_msg_to_smc_with_parameter(adev, PPSMC_MSG_DRV_DRAM_ADDR_HI, private->header_addr_high);
504− fiji_send_msg_to_smc_with_parameter(adev, PPSMC_MSG_DRV_DRAM_ADDR_LO, private->header_addr_low);
505−
506− fw_to_load = UCODE_ID_RLC_G_MASK |
507− UCODE_ID_SDMA0_MASK |
508− UCODE_ID_SDMA1_MASK |
509− UCODE_ID_CP_CE_MASK |
510− UCODE_ID_CP_ME_MASK |
511− UCODE_ID_CP_PFP_MASK |
512− UCODE_ID_CP_MEC_MASK;
513−
514− if (fiji_send_msg_to_smc_with_parameter_without_waiting(adev, PPSMC_MSG_LoadUcodes, fw_to_load)) {
515− DRM_ERROR("Fail to request SMU load ucode\n");
516− return -EINVAL;
517− }
518−
519− return 0;
520−}
521−
522−static uint32_t fiji_smu_get_mask_for_fw_type(uint32_t fw_type)
523−{
524− switch (fw_type) {
525− case AMDGPU_UCODE_ID_SDMA0:
526− return UCODE_ID_SDMA0_MASK;
527− case AMDGPU_UCODE_ID_SDMA1:
528− return UCODE_ID_SDMA1_MASK;
529− case AMDGPU_UCODE_ID_CP_CE:
530− return UCODE_ID_CP_CE_MASK;
531− case AMDGPU_UCODE_ID_CP_PFP:
532− return UCODE_ID_CP_PFP_MASK;
533− case AMDGPU_UCODE_ID_CP_ME:
534− return UCODE_ID_CP_ME_MASK;
535− case AMDGPU_UCODE_ID_CP_MEC1:
536− return UCODE_ID_CP_MEC_MASK;
537− case AMDGPU_UCODE_ID_CP_MEC2:
538− return UCODE_ID_CP_MEC_MASK;
539− case AMDGPU_UCODE_ID_RLC_G:
540− return UCODE_ID_RLC_G_MASK;
541− default:
542− DRM_ERROR("ucode type is out of range!\n");
543− return 0;
544− }
545−}
546−
547−static int fiji_smu_check_fw_load_finish(struct amdgpu_device *adev,
548− uint32_t fw_type)
549−{
550− uint32_t fw_mask = fiji_smu_get_mask_for_fw_type(fw_type);
551− int i;
552−
553− for (i = 0; i < adev->usec_timeout; i++) {
554− if (fw_mask == (RREG32_SMC(ixSOFT_REGISTERS_TABLE_28) & fw_mask))
555− break;
556− udelay(1);
557− }
558−
559− if (i == adev->usec_timeout) {
560− DRM_ERROR("check firmware loading failed\n");
561− return -EINVAL;
562− }
563−
564− return 0;
565−}
566−
567−static int fiji_smu_start_in_protection_mode(struct amdgpu_device *adev)
568−{
569− int result;
570− uint32_t val;
571− int i;
572−
573− /* Assert reset */
574− val = RREG32_SMC(ixSMC_SYSCON_RESET_CNTL);
575− val = REG_SET_FIELD(val, SMC_SYSCON_RESET_CNTL, rst_reg, 1);
576− WREG32_SMC(ixSMC_SYSCON_RESET_CNTL, val);
577−
578− result = fiji_smu_upload_firmware_image(adev);
579− if (result)
580− return result;
581−
582− /* Clear status */
583− WREG32_SMC(ixSMU_STATUS, 0);
584−
585− /* Enable clock */
586− val = RREG32_SMC(ixSMC_SYSCON_CLOCK_CNTL_0);
587− val = REG_SET_FIELD(val, SMC_SYSCON_CLOCK_CNTL_0, ck_disable, 0);
588− WREG32_SMC(ixSMC_SYSCON_CLOCK_CNTL_0, val);
589−
590− /* De-assert reset */
591− val = RREG32_SMC(ixSMC_SYSCON_RESET_CNTL);
592− val = REG_SET_FIELD(val, SMC_SYSCON_RESET_CNTL, rst_reg, 0);
593− WREG32_SMC(ixSMC_SYSCON_RESET_CNTL, val);
594−
595− /* Set SMU Auto Start */
596− val = RREG32_SMC(ixSMU_INPUT_DATA);
597− val = REG_SET_FIELD(val, SMU_INPUT_DATA, AUTO_START, 1);
598− WREG32_SMC(ixSMU_INPUT_DATA, val);
599−
600− /* Clear firmware interrupt enable flag */
601− WREG32_SMC(ixFIRMWARE_FLAGS, 0);
602−
603− for (i = 0; i < adev->usec_timeout; i++) {
604− val = RREG32_SMC(ixRCU_UC_EVENTS);
605− if (REG_GET_FIELD(val, RCU_UC_EVENTS, INTERRUPTS_ENABLED))
606− break;
607− udelay(1);
608− }
609−
610− if (i == adev->usec_timeout) {
611− DRM_ERROR("Interrupt is not enabled by firmware\n");
612− return -EINVAL;
613− }
614−
615− /* Call Test SMU message with 0x20000 offset
616− * to trigger SMU start
617− */
618− fiji_send_msg_to_smc_offset(adev);
619− DRM_INFO("[FM]try triger smu start\n");
620− /* Wait for done bit to be set */
621− for (i = 0; i < adev->usec_timeout; i++) {
622− val = RREG32_SMC(ixSMU_STATUS);
623− if (REG_GET_FIELD(val, SMU_STATUS, SMU_DONE))
624− break;
625− udelay(1);
626− }
627−
628− if (i == adev->usec_timeout) {
629− DRM_ERROR("Timeout for SMU start\n");
630− return -EINVAL;
631− }
632−
633− /* Check pass/failed indicator */
634− val = RREG32_SMC(ixSMU_STATUS);
635− if (!REG_GET_FIELD(val, SMU_STATUS, SMU_PASS)) {
636− DRM_ERROR("SMU Firmware start failed\n");
637− return -EINVAL;
638− }
639− DRM_INFO("[FM]smu started\n");
640− /* Wait for firmware to initialize */
641− for (i = 0; i < adev->usec_timeout; i++) {
642− val = RREG32_SMC(ixFIRMWARE_FLAGS);
643− if(REG_GET_FIELD(val, FIRMWARE_FLAGS, INTERRUPTS_ENABLED))
644− break;
645− udelay(1);
646− }
647−
648− if (i == adev->usec_timeout) {
649− DRM_ERROR("SMU firmware initialization failed\n");
650− return -EINVAL;
651− }
652− DRM_INFO("[FM]smu initialized\n");
653−
654− return 0;
655−}
656−
657−static int fiji_smu_start_in_non_protection_mode(struct amdgpu_device *adev)
658−{
659− int i, result;
660− uint32_t val;
661−
662− /* wait for smc boot up */
663− for (i = 0; i < adev->usec_timeout; i++) {
664− val = RREG32_SMC(ixRCU_UC_EVENTS);
665− val = REG_GET_FIELD(val, RCU_UC_EVENTS, boot_seq_done);
666− if (val)
667− break;
668− udelay(1);
669− }
670−
671− if (i == adev->usec_timeout) {
672− DRM_ERROR("SMC boot sequence is not completed\n");
673− return -EINVAL;
674− }
675−
676− /* Clear firmware interrupt enable flag */
677− WREG32_SMC(ixFIRMWARE_FLAGS, 0);
678−
679− /* Assert reset */
680− val = RREG32_SMC(ixSMC_SYSCON_RESET_CNTL);
681− val = REG_SET_FIELD(val, SMC_SYSCON_RESET_CNTL, rst_reg, 1);
682− WREG32_SMC(ixSMC_SYSCON_RESET_CNTL, val);
683−
684− result = fiji_smu_upload_firmware_image(adev);
685− if (result)
686− return result;
687−
688− /* Set smc instruct start point at 0x0 */
689− fiji_program_jump_on_start(adev);
690−
691− /* Enable clock */
692− val = RREG32_SMC(ixSMC_SYSCON_CLOCK_CNTL_0);
693− val = REG_SET_FIELD(val, SMC_SYSCON_CLOCK_CNTL_0, ck_disable, 0);
694− WREG32_SMC(ixSMC_SYSCON_CLOCK_CNTL_0, val);
695−
696− /* De-assert reset */
697− val = RREG32_SMC(ixSMC_SYSCON_RESET_CNTL);
698− val = REG_SET_FIELD(val, SMC_SYSCON_RESET_CNTL, rst_reg, 0);
699− WREG32_SMC(ixSMC_SYSCON_RESET_CNTL, val);
700−
701− /* Wait for firmware to initialize */
702− for (i = 0; i < adev->usec_timeout; i++) {
703− val = RREG32_SMC(ixFIRMWARE_FLAGS);
704− if (REG_GET_FIELD(val, FIRMWARE_FLAGS, INTERRUPTS_ENABLED))
705− break;
706− udelay(1);
707− }
708−
709− if (i == adev->usec_timeout) {
710− DRM_ERROR("Timeout for SMC firmware initialization\n");
711− return -EINVAL;
712− }
713−
714− return 0;
715−}
716−
717−int fiji_smu_start(struct amdgpu_device *adev)
718−{
719− int result;
720− uint32_t val;
721−
722− if (!fiji_is_smc_ram_running(adev)) {
723− val = RREG32_SMC(ixSMU_FIRMWARE);
724− if (!REG_GET_FIELD(val, SMU_FIRMWARE, SMU_MODE)) {
725− DRM_INFO("[FM]start smu in nonprotection mode\n");
726− result = fiji_smu_start_in_non_protection_mode(adev);
727− if (result)
728− return result;
729− } else {
730− DRM_INFO("[FM]start smu in protection mode\n");
731− result = fiji_smu_start_in_protection_mode(adev);
732− if (result)
733− return result;
734− }
735− }
736−
737− return fiji_smu_request_load_fw(adev);
738−}
739−
740−static const struct amdgpu_smumgr_funcs fiji_smumgr_funcs = {
741− .check_fw_load_finish = fiji_smu_check_fw_load_finish,
742− .request_smu_load_fw = NULL,
743− .request_smu_specific_fw = NULL,
744−};
745−
746−int fiji_smu_init(struct amdgpu_device *adev)
747−{
748− struct fiji_smu_private_data *private;
749− uint32_t image_size = ((sizeof(struct SMU_DRAMData_TOC) / 4096) + 1) * 4096;
750− uint32_t smu_internal_buffer_size = 200*4096;
751− struct amdgpu_bo **toc_buf = &adev->smu.toc_buf;
752− struct amdgpu_bo **smu_buf = &adev->smu.smu_buf;
753− uint64_t mc_addr;
754− void *toc_buf_ptr;
755− void *smu_buf_ptr;
756− int ret;
757−
758− private = kzalloc(sizeof(struct fiji_smu_private_data), GFP_KERNEL);
759− if (NULL == private)
760− return -ENOMEM;
761−
762− /* allocate firmware buffers */
763− if (adev->firmware.smu_load)
764− amdgpu_ucode_init_bo(adev);
765−
766− adev->smu.priv = private;
767− adev->smu.fw_flags = 0;
768−
769− /* Allocate FW image data structure and header buffer */
770− ret = amdgpu_bo_create(adev, image_size, PAGE_SIZE,
771− true, AMDGPU_GEM_DOMAIN_VRAM,
772− AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED,
773− NULL, NULL, toc_buf);
774− if (ret) {
775− DRM_ERROR("Failed to allocate memory for TOC buffer\n");
776− return -ENOMEM;
777− }
778−
779− /* Allocate buffer for SMU internal buffer */
780− ret = amdgpu_bo_create(adev, smu_internal_buffer_size, PAGE_SIZE,
781− true, AMDGPU_GEM_DOMAIN_VRAM,
782− AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED,
783− NULL, NULL, smu_buf);
784− if (ret) {
785− DRM_ERROR("Failed to allocate memory for SMU internal buffer\n");
786− return -ENOMEM;
787− }
788−
789− /* Retrieve GPU address for header buffer and internal buffer */
790− ret = amdgpu_bo_reserve(adev->smu.toc_buf, false);
791− if (ret) {
792− amdgpu_bo_unref(&adev->smu.toc_buf);
793− DRM_ERROR("Failed to reserve the TOC buffer\n");
794− return -EINVAL;
795− }
796−
797− ret = amdgpu_bo_pin(adev->smu.toc_buf, AMDGPU_GEM_DOMAIN_VRAM, &mc_addr);
798− if (ret) {
799− amdgpu_bo_unreserve(adev->smu.toc_buf);
800− amdgpu_bo_unref(&adev->smu.toc_buf);
801− DRM_ERROR("Failed to pin the TOC buffer\n");
802− return -EINVAL;
803− }
804−
805− ret = amdgpu_bo_kmap(*toc_buf, &toc_buf_ptr);
806− if (ret) {
807− amdgpu_bo_unreserve(adev->smu.toc_buf);
808− amdgpu_bo_unref(&adev->smu.toc_buf);
809− DRM_ERROR("Failed to map the TOC buffer\n");
810− return -EINVAL;
811− }
812−
813− amdgpu_bo_unreserve(adev->smu.toc_buf);
814− private->header_addr_low = lower_32_bits(mc_addr);
815− private->header_addr_high = upper_32_bits(mc_addr);
816− private->header = toc_buf_ptr;
817−
818− ret = amdgpu_bo_reserve(adev->smu.smu_buf, false);
819− if (ret) {
820− amdgpu_bo_unref(&adev->smu.smu_buf);
821− amdgpu_bo_unref(&adev->smu.toc_buf);
822− DRM_ERROR("Failed to reserve the SMU internal buffer\n");
823− return -EINVAL;
824− }
825−
826− ret = amdgpu_bo_pin(adev->smu.smu_buf, AMDGPU_GEM_DOMAIN_VRAM, &mc_addr);
827− if (ret) {
828− amdgpu_bo_unreserve(adev->smu.smu_buf);
829− amdgpu_bo_unref(&adev->smu.smu_buf);
830− amdgpu_bo_unref(&adev->smu.toc_buf);
831− DRM_ERROR("Failed to pin the SMU internal buffer\n");
832− return -EINVAL;
833− }
834−
835− ret = amdgpu_bo_kmap(*smu_buf, &smu_buf_ptr);
836− if (ret) {
837− amdgpu_bo_unreserve(adev->smu.smu_buf);
838− amdgpu_bo_unref(&adev->smu.smu_buf);
839− amdgpu_bo_unref(&adev->smu.toc_buf);
840− DRM_ERROR("Failed to map the SMU internal buffer\n");
841− return -EINVAL;
842− }
843−
844− amdgpu_bo_unreserve(adev->smu.smu_buf);
845− private->smu_buffer_addr_low = lower_32_bits(mc_addr);
846− private->smu_buffer_addr_high = upper_32_bits(mc_addr);
847−
848− adev->smu.smumgr_funcs = &fiji_smumgr_funcs;
849−
850− return 0;
851−}
852−
853−int fiji_smu_fini(struct amdgpu_device *adev)
854−{
855− amdgpu_bo_unref(&adev->smu.toc_buf);
856− amdgpu_bo_unref(&adev->smu.smu_buf);
857− kfree(adev->smu.priv);
858− adev->smu.priv = NULL;
859− if (adev->firmware.fw_buf)
860− amdgpu_ucode_fini_bo(adev);
861−
862− return 0;
863−}
drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c+130−1
@@ -931,6 +931,123 @@ static u32 gfx_v6_0_get_rb_disabled(struct amdgpu_device *adev, · 930 unmodified lines
931931 return data & mask;
932932 }
933933
934+static void gfx_v6_0_raster_config(struct amdgpu_device *adev, u32 *rconf)
935+{
936+ switch (adev->asic_type) {
937+ case CHIP_TAHITI:
938+ case CHIP_PITCAIRN:
939+ *rconf |= RB_XSEL2(2) | RB_XSEL | PKR_MAP(2) | PKR_YSEL(1) |
940+ SE_MAP(2) | SE_XSEL(2) | SE_YSEL(2);
941+ break;
942+ case CHIP_VERDE:
943+ *rconf |= RB_XSEL | PKR_MAP(2) | PKR_YSEL(1);
944+ break;
945+ case CHIP_OLAND:
946+ *rconf |= RB_YSEL;
947+ break;
948+ case CHIP_HAINAN:
949+ *rconf |= 0x0;
950+ break;
951+ default:
952+ DRM_ERROR("unknown asic: 0x%x\n", adev->asic_type);
953+ break;
954+ }
955+}
956+
957+static void gfx_v6_0_write_harvested_raster_configs(struct amdgpu_device *adev,
958+ u32 raster_config, unsigned rb_mask,
959+ unsigned num_rb)
960+{
961+ unsigned sh_per_se = max_t(unsigned, adev->gfx.config.max_sh_per_se, 1);
962+ unsigned num_se = max_t(unsigned, adev->gfx.config.max_shader_engines, 1);
963+ unsigned rb_per_pkr = min_t(unsigned, num_rb / num_se / sh_per_se, 2);
964+ unsigned rb_per_se = num_rb / num_se;
965+ unsigned se_mask[4];
966+ unsigned se;
967+
968+ se_mask[0] = ((1 << rb_per_se) - 1) & rb_mask;
969+ se_mask[1] = (se_mask[0] << rb_per_se) & rb_mask;
970+ se_mask[2] = (se_mask[1] << rb_per_se) & rb_mask;
971+ se_mask[3] = (se_mask[2] << rb_per_se) & rb_mask;
972+
973+ WARN_ON(!(num_se == 1 || num_se == 2 || num_se == 4));
974+ WARN_ON(!(sh_per_se == 1 || sh_per_se == 2));
975+ WARN_ON(!(rb_per_pkr == 1 || rb_per_pkr == 2));
976+
977+ for (se = 0; se < num_se; se++) {
978+ unsigned raster_config_se = raster_config;
979+ unsigned pkr0_mask = ((1 << rb_per_pkr) - 1) << (se * rb_per_se);
980+ unsigned pkr1_mask = pkr0_mask << rb_per_pkr;
981+ int idx = (se / 2) * 2;
982+
983+ if ((num_se > 1) && (!se_mask[idx] || !se_mask[idx + 1])) {
984+ raster_config_se &= ~SE_MAP_MASK;
985+
986+ if (!se_mask[idx]) {
987+ raster_config_se |= SE_MAP(RASTER_CONFIG_SE_MAP_3);
988+ } else {
989+ raster_config_se |= SE_MAP(RASTER_CONFIG_SE_MAP_0);
990+ }
991+ }
992+
993+ pkr0_mask &= rb_mask;
994+ pkr1_mask &= rb_mask;
995+ if (rb_per_se > 2 && (!pkr0_mask || !pkr1_mask)) {
996+ raster_config_se &= ~PKR_MAP_MASK;
997+
998+ if (!pkr0_mask) {
999+ raster_config_se |= PKR_MAP(RASTER_CONFIG_PKR_MAP_3);
1000+ } else {
1001+ raster_config_se |= PKR_MAP(RASTER_CONFIG_PKR_MAP_0);
1002+ }
1003+ }
1004+
1005+ if (rb_per_se >= 2) {
1006+ unsigned rb0_mask = 1 << (se * rb_per_se);
1007+ unsigned rb1_mask = rb0_mask << 1;
1008+
1009+ rb0_mask &= rb_mask;
1010+ rb1_mask &= rb_mask;
1011+ if (!rb0_mask || !rb1_mask) {
1012+ raster_config_se &= ~RB_MAP_PKR0_MASK;
1013+
1014+ if (!rb0_mask) {
1015+ raster_config_se |=
1016+ RB_MAP_PKR0(RASTER_CONFIG_RB_MAP_3);
1017+ } else {
1018+ raster_config_se |=
1019+ RB_MAP_PKR0(RASTER_CONFIG_RB_MAP_0);
1020+ }
1021+ }
1022+
1023+ if (rb_per_se > 2) {
1024+ rb0_mask = 1 << (se * rb_per_se + rb_per_pkr);
1025+ rb1_mask = rb0_mask << 1;
1026+ rb0_mask &= rb_mask;
1027+ rb1_mask &= rb_mask;
1028+ if (!rb0_mask || !rb1_mask) {
1029+ raster_config_se &= ~RB_MAP_PKR1_MASK;
1030+
1031+ if (!rb0_mask) {
1032+ raster_config_se |=
1033+ RB_MAP_PKR1(RASTER_CONFIG_RB_MAP_3);
1034+ } else {
1035+ raster_config_se |=
1036+ RB_MAP_PKR1(RASTER_CONFIG_RB_MAP_0);
1037+ }
1038+ }
1039+ }
1040+ }
1041+
1042+ /* GRBM_GFX_INDEX has a different offset on SI */
1043+ gfx_v6_0_select_se_sh(adev, se, 0xffffffff, 0xffffffff);
1044+ WREG32(PA_SC_RASTER_CONFIG, raster_config_se);
1045+ }
1046+
1047+ /* GRBM_GFX_INDEX has a different offset on SI */
1048+ gfx_v6_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
1049+}
1050+
9341051 static void gfx_v6_0_setup_rb(struct amdgpu_device *adev,
9351052 u32 se_num, u32 sh_per_se,
9361053 u32 max_rb_num_per_se)
@@ -939,6 +1056,7 @@ static void gfx_v6_0_setup_rb(struct amdgpu_device *adev, · 2 unmodified lines
9391056 u32 data, mask;
9401057 u32 disabled_rbs = 0;
9411058 u32 enabled_rbs = 0;
1059+ unsigned num_rb_pipes;
9421060
9431061 mutex_lock(&adev->grbm_idx_mutex);
9441062 for (i = 0; i < se_num; i++) {
@@ -961,6 +1079,9 @@ static void gfx_v6_0_setup_rb(struct amdgpu_device *adev, · 16 unmodified lines
9611079 adev->gfx.config.backend_enable_mask = enabled_rbs;
9621080 adev->gfx.config.num_rbs = hweight32(enabled_rbs);
9631081
1082+ num_rb_pipes = min_t(unsigned, adev->gfx.config.max_backends_per_se *
1083+ adev->gfx.config.max_shader_engines, 16);
1084+
9641085 mutex_lock(&adev->grbm_idx_mutex);
9651086 for (i = 0; i < se_num; i++) {
9661087 gfx_v6_0_select_se_sh(adev, i, 0xffffffff, 0xffffffff);
@@ -980,7 +1101,15 @@ static void gfx_v6_0_setup_rb(struct amdgpu_device *adev, · 13 unmodified lines
9801101 }
9811102 enabled_rbs >>= 2;
9821103 }
983− WREG32(PA_SC_RASTER_CONFIG, data);
1104+ gfx_v6_0_raster_config(adev, &data);
1105+
1106+ if (!adev->gfx.config.backend_enable_mask ||
1107+ adev->gfx.config.num_rbs >= num_rb_pipes)
1108+ WREG32(PA_SC_RASTER_CONFIG, data);
1109+ else
1110+ gfx_v6_0_write_harvested_raster_configs(adev, data,
1111+ adev->gfx.config.backend_enable_mask,
1112+ num_rb_pipes);
9841113 }
9851114 gfx_v6_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
9861115 mutex_unlock(&adev->grbm_idx_mutex);
drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c+159−1
@@ -1645,6 +1645,147 @@ static u32 gfx_v7_0_get_rb_active_bitmap(struct amdgpu_device *adev) · 1644 unmodified lines
16451645 return (~data) & mask;
16461646 }
16471647
1648+static void
1649+gfx_v7_0_raster_config(struct amdgpu_device *adev, u32 *rconf, u32 *rconf1)
1650+{
1651+ switch (adev->asic_type) {
1652+ case CHIP_BONAIRE:
1653+ *rconf |= RB_MAP_PKR0(2) | RB_XSEL2(1) | SE_MAP(2) |
1654+ SE_XSEL(1) | SE_YSEL(1);
1655+ *rconf1 |= 0x0;
1656+ break;
1657+ case CHIP_HAWAII:
1658+ *rconf |= RB_MAP_PKR0(2) | RB_MAP_PKR1(2) |
1659+ RB_XSEL2(1) | PKR_MAP(2) | PKR_XSEL(1) |
1660+ PKR_YSEL(1) | SE_MAP(2) | SE_XSEL(2) |
1661+ SE_YSEL(3);
1662+ *rconf1 |= SE_PAIR_MAP(2) | SE_PAIR_XSEL(3) |
1663+ SE_PAIR_YSEL(2);
1664+ break;
1665+ case CHIP_KAVERI:
1666+ *rconf |= RB_MAP_PKR0(2);
1667+ *rconf1 |= 0x0;
1668+ break;
1669+ case CHIP_KABINI:
1670+ case CHIP_MULLINS:
1671+ *rconf |= 0x0;
1672+ *rconf1 |= 0x0;
1673+ break;
1674+ default:
1675+ DRM_ERROR("unknown asic: 0x%x\n", adev->asic_type);
1676+ break;
1677+ }
1678+}
1679+
1680+static void
1681+gfx_v7_0_write_harvested_raster_configs(struct amdgpu_device *adev,
1682+ u32 raster_config, u32 raster_config_1,
1683+ unsigned rb_mask, unsigned num_rb)
1684+{
1685+ unsigned sh_per_se = max_t(unsigned, adev->gfx.config.max_sh_per_se, 1);
1686+ unsigned num_se = max_t(unsigned, adev->gfx.config.max_shader_engines, 1);
1687+ unsigned rb_per_pkr = min_t(unsigned, num_rb / num_se / sh_per_se, 2);
1688+ unsigned rb_per_se = num_rb / num_se;
1689+ unsigned se_mask[4];
1690+ unsigned se;
1691+
1692+ se_mask[0] = ((1 << rb_per_se) - 1) & rb_mask;
1693+ se_mask[1] = (se_mask[0] << rb_per_se) & rb_mask;
1694+ se_mask[2] = (se_mask[1] << rb_per_se) & rb_mask;
1695+ se_mask[3] = (se_mask[2] << rb_per_se) & rb_mask;
1696+
1697+ WARN_ON(!(num_se == 1 || num_se == 2 || num_se == 4));
1698+ WARN_ON(!(sh_per_se == 1 || sh_per_se == 2));
1699+ WARN_ON(!(rb_per_pkr == 1 || rb_per_pkr == 2));
1700+
1701+ if ((num_se > 2) && ((!se_mask[0] && !se_mask[1]) ||
1702+ (!se_mask[2] && !se_mask[3]))) {
1703+ raster_config_1 &= ~SE_PAIR_MAP_MASK;
1704+
1705+ if (!se_mask[0] && !se_mask[1]) {
1706+ raster_config_1 |=
1707+ SE_PAIR_MAP(RASTER_CONFIG_SE_PAIR_MAP_3);
1708+ } else {
1709+ raster_config_1 |=
1710+ SE_PAIR_MAP(RASTER_CONFIG_SE_PAIR_MAP_0);
1711+ }
1712+ }
1713+
1714+ for (se = 0; se < num_se; se++) {
1715+ unsigned raster_config_se = raster_config;
1716+ unsigned pkr0_mask = ((1 << rb_per_pkr) - 1) << (se * rb_per_se);
1717+ unsigned pkr1_mask = pkr0_mask << rb_per_pkr;
1718+ int idx = (se / 2) * 2;
1719+
1720+ if ((num_se > 1) && (!se_mask[idx] || !se_mask[idx + 1])) {
1721+ raster_config_se &= ~SE_MAP_MASK;
1722+
1723+ if (!se_mask[idx]) {
1724+ raster_config_se |= SE_MAP(RASTER_CONFIG_SE_MAP_3);
1725+ } else {
1726+ raster_config_se |= SE_MAP(RASTER_CONFIG_SE_MAP_0);
1727+ }
1728+ }
1729+
1730+ pkr0_mask &= rb_mask;
1731+ pkr1_mask &= rb_mask;
1732+ if (rb_per_se > 2 && (!pkr0_mask || !pkr1_mask)) {
1733+ raster_config_se &= ~PKR_MAP_MASK;
1734+
1735+ if (!pkr0_mask) {
1736+ raster_config_se |= PKR_MAP(RASTER_CONFIG_PKR_MAP_3);
1737+ } else {
1738+ raster_config_se |= PKR_MAP(RASTER_CONFIG_PKR_MAP_0);
1739+ }
1740+ }
1741+
1742+ if (rb_per_se >= 2) {
1743+ unsigned rb0_mask = 1 << (se * rb_per_se);
1744+ unsigned rb1_mask = rb0_mask << 1;
1745+
1746+ rb0_mask &= rb_mask;
1747+ rb1_mask &= rb_mask;
1748+ if (!rb0_mask || !rb1_mask) {
1749+ raster_config_se &= ~RB_MAP_PKR0_MASK;
1750+
1751+ if (!rb0_mask) {
1752+ raster_config_se |=
1753+ RB_MAP_PKR0(RASTER_CONFIG_RB_MAP_3);
1754+ } else {
1755+ raster_config_se |=
1756+ RB_MAP_PKR0(RASTER_CONFIG_RB_MAP_0);
1757+ }
1758+ }
1759+
1760+ if (rb_per_se > 2) {
1761+ rb0_mask = 1 << (se * rb_per_se + rb_per_pkr);
1762+ rb1_mask = rb0_mask << 1;
1763+ rb0_mask &= rb_mask;
1764+ rb1_mask &= rb_mask;
1765+ if (!rb0_mask || !rb1_mask) {
1766+ raster_config_se &= ~RB_MAP_PKR1_MASK;
1767+
1768+ if (!rb0_mask) {
1769+ raster_config_se |=
1770+ RB_MAP_PKR1(RASTER_CONFIG_RB_MAP_3);
1771+ } else {
1772+ raster_config_se |=
1773+ RB_MAP_PKR1(RASTER_CONFIG_RB_MAP_0);
1774+ }
1775+ }
1776+ }
1777+ }
1778+
1779+ /* GRBM_GFX_INDEX has a different offset on CI+ */
1780+ gfx_v7_0_select_se_sh(adev, se, 0xffffffff, 0xffffffff);
1781+ WREG32(mmPA_SC_RASTER_CONFIG, raster_config_se);
1782+ WREG32(mmPA_SC_RASTER_CONFIG_1, raster_config_1);
1783+ }
1784+
1785+ /* GRBM_GFX_INDEX has a different offset on CI+ */
1786+ gfx_v7_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
1787+}
1788+
16481789 /**
16491790 * gfx_v7_0_setup_rb - setup the RBs on the asic
16501791 *
@@ -1658,9 +1799,11 @@ static void gfx_v7_0_setup_rb(struct amdgpu_device *adev) · 7 unmodified lines
16581799 {
16591800 int i, j;
16601801 u32 data;
1802+ u32 raster_config = 0, raster_config_1 = 0;
16611803 u32 active_rbs = 0;
16621804 u32 rb_bitmap_width_per_sh = adev->gfx.config.max_backends_per_se /
16631805 adev->gfx.config.max_sh_per_se;
1806+ unsigned num_rb_pipes;
16641807
16651808 mutex_lock(&adev->grbm_idx_mutex);
16661809 for (i = 0; i < adev->gfx.config.max_shader_engines; i++) {
@@ -1672,10 +1815,25 @@ static void gfx_v7_0_setup_rb(struct amdgpu_device *adev) · 5 unmodified lines
16721815 }
16731816 }
16741817 gfx_v7_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
1675− mutex_unlock(&adev->grbm_idx_mutex);
16761818
16771819 adev->gfx.config.backend_enable_mask = active_rbs;
16781820 adev->gfx.config.num_rbs = hweight32(active_rbs);
1821+
1822+ num_rb_pipes = min_t(unsigned, adev->gfx.config.max_backends_per_se *
1823+ adev->gfx.config.max_shader_engines, 16);
1824+
1825+ gfx_v7_0_raster_config(adev, &raster_config, &raster_config_1);
1826+
1827+ if (!adev->gfx.config.backend_enable_mask ||
1828+ adev->gfx.config.num_rbs >= num_rb_pipes) {
1829+ WREG32(mmPA_SC_RASTER_CONFIG, raster_config);
1830+ WREG32(mmPA_SC_RASTER_CONFIG_1, raster_config_1);
1831+ } else {
1832+ gfx_v7_0_write_harvested_raster_configs(adev, raster_config, raster_config_1,
1833+ adev->gfx.config.backend_enable_mask,
1834+ num_rb_pipes);
1835+ }
1836+ mutex_unlock(&adev->grbm_idx_mutex);
16791837 }
16801838
16811839 /**
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c+244−1
@@ -3492,13 +3492,163 @@ static u32 gfx_v8_0_get_rb_active_bitmap(struct amdgpu_device *adev) · 3491 unmodified lines
34923492 return (~data) & mask;
34933493 }
34943494
3495+static void
3496+gfx_v8_0_raster_config(struct amdgpu_device *adev, u32 *rconf, u32 *rconf1)
3497+{
3498+ switch (adev->asic_type) {
3499+ case CHIP_FIJI:
3500+ *rconf |= RB_MAP_PKR0(2) | RB_MAP_PKR1(2) |
3501+ RB_XSEL2(1) | PKR_MAP(2) |
3502+ PKR_XSEL(1) | PKR_YSEL(1) |
3503+ SE_MAP(2) | SE_XSEL(2) | SE_YSEL(3);
3504+ *rconf1 |= SE_PAIR_MAP(2) | SE_PAIR_XSEL(3) |
3505+ SE_PAIR_YSEL(2);
3506+ break;
3507+ case CHIP_TONGA:
3508+ case CHIP_POLARIS10:
3509+ *rconf |= RB_MAP_PKR0(2) | RB_XSEL2(1) | SE_MAP(2) |
3510+ SE_XSEL(1) | SE_YSEL(1);
3511+ *rconf1 |= SE_PAIR_MAP(2) | SE_PAIR_XSEL(2) |
3512+ SE_PAIR_YSEL(2);
3513+ break;
3514+ case CHIP_TOPAZ:
3515+ case CHIP_CARRIZO:
3516+ *rconf |= RB_MAP_PKR0(2);
3517+ *rconf1 |= 0x0;
3518+ break;
3519+ case CHIP_POLARIS11:
3520+ *rconf |= RB_MAP_PKR0(2) | RB_XSEL2(1) | SE_MAP(2) |
3521+ SE_XSEL(1) | SE_YSEL(1);
3522+ *rconf1 |= 0x0;
3523+ break;
3524+ case CHIP_STONEY:
3525+ *rconf |= 0x0;
3526+ *rconf1 |= 0x0;
3527+ break;
3528+ default:
3529+ DRM_ERROR("unknown asic: 0x%x\n", adev->asic_type);
3530+ break;
3531+ }
3532+}
3533+
3534+static void
3535+gfx_v8_0_write_harvested_raster_configs(struct amdgpu_device *adev,
3536+ u32 raster_config, u32 raster_config_1,
3537+ unsigned rb_mask, unsigned num_rb)
3538+{
3539+ unsigned sh_per_se = max_t(unsigned, adev->gfx.config.max_sh_per_se, 1);
3540+ unsigned num_se = max_t(unsigned, adev->gfx.config.max_shader_engines, 1);
3541+ unsigned rb_per_pkr = min_t(unsigned, num_rb / num_se / sh_per_se, 2);
3542+ unsigned rb_per_se = num_rb / num_se;
3543+ unsigned se_mask[4];
3544+ unsigned se;
3545+
3546+ se_mask[0] = ((1 << rb_per_se) - 1) & rb_mask;
3547+ se_mask[1] = (se_mask[0] << rb_per_se) & rb_mask;
3548+ se_mask[2] = (se_mask[1] << rb_per_se) & rb_mask;
3549+ se_mask[3] = (se_mask[2] << rb_per_se) & rb_mask;
3550+
3551+ WARN_ON(!(num_se == 1 || num_se == 2 || num_se == 4));
3552+ WARN_ON(!(sh_per_se == 1 || sh_per_se == 2));
3553+ WARN_ON(!(rb_per_pkr == 1 || rb_per_pkr == 2));
3554+
3555+ if ((num_se > 2) && ((!se_mask[0] && !se_mask[1]) ||
3556+ (!se_mask[2] && !se_mask[3]))) {
3557+ raster_config_1 &= ~SE_PAIR_MAP_MASK;
3558+
3559+ if (!se_mask[0] && !se_mask[1]) {
3560+ raster_config_1 |=
3561+ SE_PAIR_MAP(RASTER_CONFIG_SE_PAIR_MAP_3);
3562+ } else {
3563+ raster_config_1 |=
3564+ SE_PAIR_MAP(RASTER_CONFIG_SE_PAIR_MAP_0);
3565+ }
3566+ }
3567+
3568+ for (se = 0; se < num_se; se++) {
3569+ unsigned raster_config_se = raster_config;
3570+ unsigned pkr0_mask = ((1 << rb_per_pkr) - 1) << (se * rb_per_se);
3571+ unsigned pkr1_mask = pkr0_mask << rb_per_pkr;
3572+ int idx = (se / 2) * 2;
3573+
3574+ if ((num_se > 1) && (!se_mask[idx] || !se_mask[idx + 1])) {
3575+ raster_config_se &= ~SE_MAP_MASK;
3576+
3577+ if (!se_mask[idx]) {
3578+ raster_config_se |= SE_MAP(RASTER_CONFIG_SE_MAP_3);
3579+ } else {
3580+ raster_config_se |= SE_MAP(RASTER_CONFIG_SE_MAP_0);
3581+ }
3582+ }
3583+
3584+ pkr0_mask &= rb_mask;
3585+ pkr1_mask &= rb_mask;
3586+ if (rb_per_se > 2 && (!pkr0_mask || !pkr1_mask)) {
3587+ raster_config_se &= ~PKR_MAP_MASK;
3588+
3589+ if (!pkr0_mask) {
3590+ raster_config_se |= PKR_MAP(RASTER_CONFIG_PKR_MAP_3);
3591+ } else {
3592+ raster_config_se |= PKR_MAP(RASTER_CONFIG_PKR_MAP_0);
3593+ }
3594+ }
3595+
3596+ if (rb_per_se >= 2) {
3597+ unsigned rb0_mask = 1 << (se * rb_per_se);
3598+ unsigned rb1_mask = rb0_mask << 1;
3599+
3600+ rb0_mask &= rb_mask;
3601+ rb1_mask &= rb_mask;
3602+ if (!rb0_mask || !rb1_mask) {
3603+ raster_config_se &= ~RB_MAP_PKR0_MASK;
3604+
3605+ if (!rb0_mask) {
3606+ raster_config_se |=
3607+ RB_MAP_PKR0(RASTER_CONFIG_RB_MAP_3);
3608+ } else {
3609+ raster_config_se |=
3610+ RB_MAP_PKR0(RASTER_CONFIG_RB_MAP_0);
3611+ }
3612+ }
3613+
3614+ if (rb_per_se > 2) {
3615+ rb0_mask = 1 << (se * rb_per_se + rb_per_pkr);
3616+ rb1_mask = rb0_mask << 1;
3617+ rb0_mask &= rb_mask;
3618+ rb1_mask &= rb_mask;
3619+ if (!rb0_mask || !rb1_mask) {
3620+ raster_config_se &= ~RB_MAP_PKR1_MASK;
3621+
3622+ if (!rb0_mask) {
3623+ raster_config_se |=
3624+ RB_MAP_PKR1(RASTER_CONFIG_RB_MAP_3);
3625+ } else {
3626+ raster_config_se |=
3627+ RB_MAP_PKR1(RASTER_CONFIG_RB_MAP_0);
3628+ }
3629+ }
3630+ }
3631+ }
3632+
3633+ /* GRBM_GFX_INDEX has a different offset on VI */
3634+ gfx_v8_0_select_se_sh(adev, se, 0xffffffff, 0xffffffff);
3635+ WREG32(mmPA_SC_RASTER_CONFIG, raster_config_se);
3636+ WREG32(mmPA_SC_RASTER_CONFIG_1, raster_config_1);
3637+ }
3638+
3639+ /* GRBM_GFX_INDEX has a different offset on VI */
3640+ gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
3641+}
3642+
34953643 static void gfx_v8_0_setup_rb(struct amdgpu_device *adev)
34963644 {
34973645 int i, j;
34983646 u32 data;
3647+ u32 raster_config = 0, raster_config_1 = 0;
34993648 u32 active_rbs = 0;
35003649 u32 rb_bitmap_width_per_sh = adev->gfx.config.max_backends_per_se /
35013650 adev->gfx.config.max_sh_per_se;
3651+ unsigned num_rb_pipes;
35023652
35033653 mutex_lock(&adev->grbm_idx_mutex);
35043654 for (i = 0; i < adev->gfx.config.max_shader_engines; i++) {
@@ -3510,10 +3660,26 @@ static void gfx_v8_0_setup_rb(struct amdgpu_device *adev) · 5 unmodified lines
35103660 }
35113661 }
35123662 gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
3513− mutex_unlock(&adev->grbm_idx_mutex);
35143663
35153664 adev->gfx.config.backend_enable_mask = active_rbs;
35163665 adev->gfx.config.num_rbs = hweight32(active_rbs);
3666+
3667+ num_rb_pipes = min_t(unsigned, adev->gfx.config.max_backends_per_se *
3668+ adev->gfx.config.max_shader_engines, 16);
3669+
3670+ gfx_v8_0_raster_config(adev, &raster_config, &raster_config_1);
3671+
3672+ if (!adev->gfx.config.backend_enable_mask ||
3673+ adev->gfx.config.num_rbs >= num_rb_pipes) {
3674+ WREG32(mmPA_SC_RASTER_CONFIG, raster_config);
3675+ WREG32(mmPA_SC_RASTER_CONFIG_1, raster_config_1);
3676+ } else {
3677+ gfx_v8_0_write_harvested_raster_configs(adev, raster_config, raster_config_1,
3678+ adev->gfx.config.backend_enable_mask,
3679+ num_rb_pipes);
3680+ }
3681+
3682+ mutex_unlock(&adev->grbm_idx_mutex);
35173683 }
35183684
35193685 /**
@@ -5817,6 +5983,76 @@ static int gfx_v8_0_update_gfx_clock_gating(struct amdgpu_device *adev, · 2297 unmodified lines
58175983 return 0;
58185984 }
58195985
5986+static int gfx_v8_0_tonga_update_gfx_clock_gating(struct amdgpu_device *adev,
5987+ enum amd_clockgating_state state)
5988+{
5989+ uint32_t msg_id, pp_state;
5990+ void *pp_handle = adev->powerplay.pp_handle;
5991+
5992+ if (state == AMD_CG_STATE_UNGATE)
5993+ pp_state = 0;
5994+ else
5995+ pp_state = PP_STATE_CG | PP_STATE_LS;
5996+
5997+ msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
5998+ PP_BLOCK_GFX_CG,
5999+ PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS,
6000+ pp_state);
6001+ amd_set_clockgating_by_smu(pp_handle, msg_id);
6002+
6003+ msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
6004+ PP_BLOCK_GFX_MG,
6005+ PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS,
6006+ pp_state);
6007+ amd_set_clockgating_by_smu(pp_handle, msg_id);
6008+
6009+ return 0;
6010+}
6011+
6012+static int gfx_v8_0_polaris_update_gfx_clock_gating(struct amdgpu_device *adev,
6013+ enum amd_clockgating_state state)
6014+{
6015+ uint32_t msg_id, pp_state;
6016+ void *pp_handle = adev->powerplay.pp_handle;
6017+
6018+ if (state == AMD_CG_STATE_UNGATE)
6019+ pp_state = 0;
6020+ else
6021+ pp_state = PP_STATE_CG | PP_STATE_LS;
6022+
6023+ msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
6024+ PP_BLOCK_GFX_CG,
6025+ PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS,
6026+ pp_state);
6027+ amd_set_clockgating_by_smu(pp_handle, msg_id);
6028+
6029+ msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
6030+ PP_BLOCK_GFX_3D,
6031+ PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS,
6032+ pp_state);
6033+ amd_set_clockgating_by_smu(pp_handle, msg_id);
6034+
6035+ msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
6036+ PP_BLOCK_GFX_MG,
6037+ PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS,
6038+ pp_state);
6039+ amd_set_clockgating_by_smu(pp_handle, msg_id);
6040+
6041+ msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
6042+ PP_BLOCK_GFX_RLC,
6043+ PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS,
6044+ pp_state);
6045+ amd_set_clockgating_by_smu(pp_handle, msg_id);
6046+
6047+ msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
6048+ PP_BLOCK_GFX_CP,
6049+ PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS,
6050+ pp_state);
6051+ amd_set_clockgating_by_smu(pp_handle, msg_id);
6052+
6053+ return 0;
6054+}
6055+
58206056 static int gfx_v8_0_set_clockgating_state(void *handle,
58216057 enum amd_clockgating_state state)
58226058 {
@@ -5829,6 +6065,13 @@ static int gfx_v8_0_set_clockgating_state(void *handle, · 6 unmodified lines
58296065 gfx_v8_0_update_gfx_clock_gating(adev,
58306066 state == AMD_CG_STATE_GATE ? true : false);
58316067 break;
6068+ case CHIP_TONGA:
6069+ gfx_v8_0_tonga_update_gfx_clock_gating(adev, state);
6070+ break;
6071+ case CHIP_POLARIS10:
6072+ case CHIP_POLARIS11:
6073+ gfx_v8_0_polaris_update_gfx_clock_gating(adev, state);
6074+ break;
58326075 default:
58336076 break;
58346077 }
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c+3−1
@@ -269,8 +269,10 @@ static int gmc_v8_0_mc_load_microcode(struct amdgpu_device *adev) · 268 unmodified lines
269269
270270 /* Skip MC ucode loading on SR-IOV capable boards.
271271 * vbios does this for us in asic_init in that case.
272+ * Skip MC ucode loading on VF, because hypervisor will do that
273+ * for this adaptor.
272274 */
273− if (adev->virtualization.supports_sr_iov)
275+ if (amdgpu_sriov_bios(adev))
274276 return 0;
275277
276278 hdr = (const struct mc_firmware_header_v1_0 *)adev->mc.fw->data;
drivers/gpu/drm/amd/amdgpu/iceland_dpm.c+0−200
@@ -1,200 +0,0 @@
1−/*
2− * Copyright 2014 Advanced Micro Devices, Inc.
3− *
4− * Permission is hereby granted, free of charge, to any person obtaining a
5− * copy of this software and associated documentation files (the "Software"),
6− * to deal in the Software without restriction, including without limitation
7− * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8− * and/or sell copies of the Software, and to permit persons to whom the
9− * Software is furnished to do so, subject to the following conditions:
10− *
11− * The above copyright notice and this permission notice shall be included in
12− * all copies or substantial portions of the Software.
13− *
14− * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15− * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16− * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17− * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18− * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19− * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20− * OTHER DEALINGS IN THE SOFTWARE.
21− *
22− */
23−
24−#include <linux/firmware.h>
25−#include "drmP.h"
26−#include "amdgpu.h"
27−#include "iceland_smum.h"
28−
29−MODULE_FIRMWARE("amdgpu/topaz_smc.bin");
30−
31−static void iceland_dpm_set_funcs(struct amdgpu_device *adev);
32−
33−static int iceland_dpm_early_init(void *handle)
34−{
35− struct amdgpu_device *adev = (struct amdgpu_device *)handle;
36−
37− iceland_dpm_set_funcs(adev);
38−
39− return 0;
40−}
41−
42−static int iceland_dpm_init_microcode(struct amdgpu_device *adev)
43−{
44− char fw_name[30] = "amdgpu/topaz_smc.bin";
45− int err;
46−
47− err = request_firmware(&adev->pm.fw, fw_name, adev->dev);
48− if (err)
49− goto out;
50− err = amdgpu_ucode_validate(adev->pm.fw);
51−
52−out:
53− if (err) {
54− DRM_ERROR("Failed to load firmware \"%s\"", fw_name);
55− release_firmware(adev->pm.fw);
56− adev->pm.fw = NULL;
57− }
58− return err;
59−}
60−
61−static int iceland_dpm_sw_init(void *handle)
62−{
63− int ret;
64− struct amdgpu_device *adev = (struct amdgpu_device *)handle;
65−
66− ret = iceland_dpm_init_microcode(adev);
67− if (ret)
68− return ret;
69−
70− return 0;
71−}
72−
73−static int iceland_dpm_sw_fini(void *handle)
74−{
75− struct amdgpu_device *adev = (struct amdgpu_device *)handle;
76−
77− release_firmware(adev->pm.fw);
78− adev->pm.fw = NULL;
79−
80− return 0;
81−}
82−
83−static int iceland_dpm_hw_init(void *handle)
84−{
85− int ret;
86− struct amdgpu_device *adev = (struct amdgpu_device *)handle;
87−
88− mutex_lock(&adev->pm.mutex);
89−
90− /* smu init only needs to be called at startup, not resume.
91− * It should be in sw_init, but requires the fw info gathered
92− * in sw_init from other IP modules.
93− */
94− ret = iceland_smu_init(adev);
95− if (ret) {
96− DRM_ERROR("SMU initialization failed\n");
97− goto fail;
98− }
99−
100− ret = iceland_smu_start(adev);
101− if (ret) {
102− DRM_ERROR("SMU start failed\n");
103− goto fail;
104− }
105−
106− mutex_unlock(&adev->pm.mutex);
107− return 0;
108−
109−fail:
110− adev->firmware.smu_load = false;
111− mutex_unlock(&adev->pm.mutex);
112− return -EINVAL;
113−}
114−
115−static int iceland_dpm_hw_fini(void *handle)
116−{
117− struct amdgpu_device *adev = (struct amdgpu_device *)handle;
118−
119− mutex_lock(&adev->pm.mutex);
120− /* smu fini only needs to be called at teardown, not suspend.
121− * It should be in sw_fini, but we put it here for symmetry
122− * with smu init.
123− */
124− iceland_smu_fini(adev);
125− mutex_unlock(&adev->pm.mutex);
126− return 0;
127−}
128−
129−static int iceland_dpm_suspend(void *handle)
130−{
131− return 0;
132−}
133−
134−static int iceland_dpm_resume(void *handle)
135−{
136− int ret;
137− struct amdgpu_device *adev = (struct amdgpu_device *)handle;
138−
139− mutex_lock(&adev->pm.mutex);
140−
141− ret = iceland_smu_start(adev);
142− if (ret) {
143− DRM_ERROR("SMU start failed\n");
144− goto fail;
145− }
146−
147−fail:
148− mutex_unlock(&adev->pm.mutex);
149− return ret;
150−}
151−
152−static int iceland_dpm_set_clockgating_state(void *handle,
153− enum amd_clockgating_state state)
154−{
155− return 0;
156−}
157−
158−static int iceland_dpm_set_powergating_state(void *handle,
159− enum amd_powergating_state state)
160−{
161− return 0;
162−}
163−
164−const struct amd_ip_funcs iceland_dpm_ip_funcs = {
165− .name = "iceland_dpm",
166− .early_init = iceland_dpm_early_init,
167− .late_init = NULL,
168− .sw_init = iceland_dpm_sw_init,
169− .sw_fini = iceland_dpm_sw_fini,
170− .hw_init = iceland_dpm_hw_init,
171− .hw_fini = iceland_dpm_hw_fini,
172− .suspend = iceland_dpm_suspend,
173− .resume = iceland_dpm_resume,
174− .is_idle = NULL,
175− .wait_for_idle = NULL,
176− .soft_reset = NULL,
177− .set_clockgating_state = iceland_dpm_set_clockgating_state,
178− .set_powergating_state = iceland_dpm_set_powergating_state,
179−};
180−
181−static const struct amdgpu_dpm_funcs iceland_dpm_funcs = {
182− .get_temperature = NULL,
183− .pre_set_power_state = NULL,
184− .set_power_state = NULL,
185− .post_set_power_state = NULL,
186− .display_configuration_changed = NULL,
187− .get_sclk = NULL,
188− .get_mclk = NULL,
189− .print_power_state = NULL,
190− .debugfs_print_current_performance_level = NULL,
191− .force_performance_level = NULL,
192− .vblank_too_short = NULL,
193− .powergate_uvd = NULL,
194−};
195−
196−static void iceland_dpm_set_funcs(struct amdgpu_device *adev)
197−{
198− if (NULL == adev->pm.funcs)
199− adev->pm.funcs = &iceland_dpm_funcs;
200−}
drivers/gpu/drm/amd/amdgpu/iceland_smc.c+0−677
@@ -1,677 +0,0 @@
1−/*
2− * Copyright 2014 Advanced Micro Devices, Inc.
3− *
4− * Permission is hereby granted, free of charge, to any person obtaining a
5− * copy of this software and associated documentation files (the "Software"),
6− * to deal in the Software without restriction, including without limitation
7− * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8− * and/or sell copies of the Software, and to permit persons to whom the
9− * Software is furnished to do so, subject to the following conditions:
10− *
11− * The above copyright notice and this permission notice shall be included in
12− * all copies or substantial portions of the Software.
13− *
14− * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15− * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16− * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17− * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18− * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19− * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20− * OTHER DEALINGS IN THE SOFTWARE.
21− *
22− */
23−
24−#include <linux/firmware.h>
25−#include "drmP.h"
26−#include "amdgpu.h"
27−#include "ppsmc.h"
28−#include "iceland_smum.h"
29−#include "smu_ucode_xfer_vi.h"
30−#include "amdgpu_ucode.h"
31−
32−#include "smu/smu_7_1_1_d.h"
33−#include "smu/smu_7_1_1_sh_mask.h"
34−
35−#define ICELAND_SMC_SIZE 0x20000
36−
37−static int iceland_set_smc_sram_address(struct amdgpu_device *adev,
38− uint32_t smc_address, uint32_t limit)
39−{
40− uint32_t val;
41−
42− if (smc_address & 3)
43− return -EINVAL;
44−
45− if ((smc_address + 3) > limit)
46− return -EINVAL;
47−
48− WREG32(mmSMC_IND_INDEX_0, smc_address);
49−
50− val = RREG32(mmSMC_IND_ACCESS_CNTL);
51− val = REG_SET_FIELD(val, SMC_IND_ACCESS_CNTL, AUTO_INCREMENT_IND_0, 0);
52− WREG32(mmSMC_IND_ACCESS_CNTL, val);
53−
54− return 0;
55−}
56−
57−static int iceland_copy_bytes_to_smc(struct amdgpu_device *adev,
58− uint32_t smc_start_address,
59− const uint8_t *src,
60− uint32_t byte_count, uint32_t limit)
61−{
62− uint32_t addr;
63− uint32_t data, orig_data;
64− int result = 0;
65− uint32_t extra_shift;
66− unsigned long flags;
67−
68− if (smc_start_address & 3)
69− return -EINVAL;
70−
71− if ((smc_start_address + byte_count) > limit)
72− return -EINVAL;
73−
74− addr = smc_start_address;
75−
76− spin_lock_irqsave(&adev->smc_idx_lock, flags);
77− while (byte_count >= 4) {
78− /* Bytes are written into the SMC addres space with the MSB first */
79− data = (src[0] << 24) + (src[1] << 16) + (src[2] << 8) + src[3];
80−
81− result = iceland_set_smc_sram_address(adev, addr, limit);
82−
83− if (result)
84− goto out;
85−
86− WREG32(mmSMC_IND_DATA_0, data);
87−
88− src += 4;
89− byte_count -= 4;
90− addr += 4;
91− }
92−
93− if (0 != byte_count) {
94− /* Now write odd bytes left, do a read modify write cycle */
95− data = 0;
96−
97− result = iceland_set_smc_sram_address(adev, addr, limit);
98− if (result)
99− goto out;
100−
101− orig_data = RREG32(mmSMC_IND_DATA_0);
102− extra_shift = 8 * (4 - byte_count);
103−
104− while (byte_count > 0) {
105− data = (data << 8) + *src++;
106− byte_count--;
107− }
108−
109− data <<= extra_shift;
110− data |= (orig_data & ~((~0UL) << extra_shift));
111−
112− result = iceland_set_smc_sram_address(adev, addr, limit);
113− if (result)
114− goto out;
115−
116− WREG32(mmSMC_IND_DATA_0, data);
117− }
118−
119−out:
120− spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
121− return result;
122−}
123−
124−static void iceland_start_smc(struct amdgpu_device *adev)
125−{
126− uint32_t val = RREG32_SMC(ixSMC_SYSCON_RESET_CNTL);
127−
128− val = REG_SET_FIELD(val, SMC_SYSCON_RESET_CNTL, rst_reg, 0);
129− WREG32_SMC(ixSMC_SYSCON_RESET_CNTL, val);
130−}
131−
132−static void iceland_reset_smc(struct amdgpu_device *adev)
133−{
134− uint32_t val = RREG32_SMC(ixSMC_SYSCON_RESET_CNTL);
135−
136− val = REG_SET_FIELD(val, SMC_SYSCON_RESET_CNTL, rst_reg, 1);
137− WREG32_SMC(ixSMC_SYSCON_RESET_CNTL, val);
138−}
139−
140−static int iceland_program_jump_on_start(struct amdgpu_device *adev)
141−{
142− static unsigned char data[] = {0xE0, 0x00, 0x80, 0x40};
143− iceland_copy_bytes_to_smc(adev, 0x0, data, 4, sizeof(data)+1);
144−
145− return 0;
146−}
147−
148−static void iceland_stop_smc_clock(struct amdgpu_device *adev)
149−{
150− uint32_t val = RREG32_SMC(ixSMC_SYSCON_CLOCK_CNTL_0);
151−
152− val = REG_SET_FIELD(val, SMC_SYSCON_CLOCK_CNTL_0, ck_disable, 1);
153− WREG32_SMC(ixSMC_SYSCON_CLOCK_CNTL_0, val);
154−}
155−
156−static void iceland_start_smc_clock(struct amdgpu_device *adev)
157−{
158− uint32_t val = RREG32_SMC(ixSMC_SYSCON_CLOCK_CNTL_0);
159−
160− val = REG_SET_FIELD(val, SMC_SYSCON_CLOCK_CNTL_0, ck_disable, 0);
161− WREG32_SMC(ixSMC_SYSCON_CLOCK_CNTL_0, val);
162−}
163−
164−static bool iceland_is_smc_ram_running(struct amdgpu_device *adev)
165−{
166− uint32_t val = RREG32_SMC(ixSMC_SYSCON_CLOCK_CNTL_0);
167− val = REG_GET_FIELD(val, SMC_SYSCON_CLOCK_CNTL_0, ck_disable);
168−
169− return ((0 == val) && (0x20100 <= RREG32_SMC(ixSMC_PC_C)));
170−}
171−
172−static int wait_smu_response(struct amdgpu_device *adev)
173−{
174− int i;
175− uint32_t val;
176−
177− for (i = 0; i < adev->usec_timeout; i++) {
178− val = RREG32(mmSMC_RESP_0);
179− if (REG_GET_FIELD(val, SMC_RESP_0, SMC_RESP))
180− break;
181− udelay(1);
182− }
183−
184− if (i == adev->usec_timeout)
185− return -EINVAL;
186−
187− return 0;
188−}
189−
190−static int iceland_send_msg_to_smc(struct amdgpu_device *adev, PPSMC_Msg msg)
191−{
192− if (!iceland_is_smc_ram_running(adev))
193− return -EINVAL;
194−
195− if (wait_smu_response(adev)) {
196− DRM_ERROR("Failed to send previous message\n");
197− return -EINVAL;
198− }
199−
200− WREG32(mmSMC_MESSAGE_0, msg);
201−
202− if (wait_smu_response(adev)) {
203− DRM_ERROR("Failed to send message\n");
204− return -EINVAL;
205− }
206−
207− return 0;
208−}
209−
210−static int iceland_send_msg_to_smc_without_waiting(struct amdgpu_device *adev,
211− PPSMC_Msg msg)
212−{
213− if (!iceland_is_smc_ram_running(adev))
214− return -EINVAL;
215−
216− if (wait_smu_response(adev)) {
217− DRM_ERROR("Failed to send previous message\n");
218− return -EINVAL;
219− }
220−
221− WREG32(mmSMC_MESSAGE_0, msg);
222−
223− return 0;
224−}
225−
226−static int iceland_send_msg_to_smc_with_parameter(struct amdgpu_device *adev,
227− PPSMC_Msg msg,
228− uint32_t parameter)
229−{
230− WREG32(mmSMC_MSG_ARG_0, parameter);
231−
232− return iceland_send_msg_to_smc(adev, msg);
233−}
234−
235−static int iceland_send_msg_to_smc_with_parameter_without_waiting(
236− struct amdgpu_device *adev,
237− PPSMC_Msg msg, uint32_t parameter)
238−{
239− WREG32(mmSMC_MSG_ARG_0, parameter);
240−
241− return iceland_send_msg_to_smc_without_waiting(adev, msg);
242−}
243−
244−#if 0 /* not used yet */
245−static int iceland_wait_for_smc_inactive(struct amdgpu_device *adev)
246−{
247− int i;
248− uint32_t val;
249−
250− if (!iceland_is_smc_ram_running(adev))
251− return -EINVAL;
252−
253− for (i = 0; i < adev->usec_timeout; i++) {
254− val = RREG32_SMC(ixSMC_SYSCON_CLOCK_CNTL_0);
255− if (REG_GET_FIELD(val, SMC_SYSCON_CLOCK_CNTL_0, cken) == 0)
256− break;
257− udelay(1);
258− }
259−
260− if (i == adev->usec_timeout)
261− return -EINVAL;
262−
263− return 0;
264−}
265−#endif
266−
267−static int iceland_smu_upload_firmware_image(struct amdgpu_device *adev)
268−{
269− const struct smc_firmware_header_v1_0 *hdr;
270− uint32_t ucode_size;
271− uint32_t ucode_start_address;
272− const uint8_t *src;
273− uint32_t val;
274− uint32_t byte_count;
275− uint32_t data;
276− unsigned long flags;
277− int i;
278−
279− if (!adev->pm.fw)
280− return -EINVAL;
281−
282− /* Skip SMC ucode loading on SR-IOV capable boards.
283− * vbios does this for us in asic_init in that case.
284− */
285− if (adev->virtualization.supports_sr_iov)
286− return 0;
287−
288− hdr = (const struct smc_firmware_header_v1_0 *)adev->pm.fw->data;
289− amdgpu_ucode_print_smc_hdr(&hdr->header);
290−
291− adev->pm.fw_version = le32_to_cpu(hdr->header.ucode_version);
292− ucode_size = le32_to_cpu(hdr->header.ucode_size_bytes);
293− ucode_start_address = le32_to_cpu(hdr->ucode_start_addr);
294− src = (const uint8_t *)
295− (adev->pm.fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
296−
297− if (ucode_size & 3) {
298− DRM_ERROR("SMC ucode is not 4 bytes aligned\n");
299− return -EINVAL;
300− }
301−
302− if (ucode_size > ICELAND_SMC_SIZE) {
303− DRM_ERROR("SMC address is beyond the SMC RAM area\n");
304− return -EINVAL;
305− }
306−
307− for (i = 0; i < adev->usec_timeout; i++) {
308− val = RREG32_SMC(ixRCU_UC_EVENTS);
309− if (REG_GET_FIELD(val, RCU_UC_EVENTS, boot_seq_done) == 0)
310− break;
311− udelay(1);
312− }
313− val = RREG32_SMC(ixSMC_SYSCON_MISC_CNTL);
314− WREG32_SMC(ixSMC_SYSCON_MISC_CNTL, val | 1);
315−
316− iceland_stop_smc_clock(adev);
317− iceland_reset_smc(adev);
318−
319− spin_lock_irqsave(&adev->smc_idx_lock, flags);
320− WREG32(mmSMC_IND_INDEX_0, ucode_start_address);
321−
322− val = RREG32(mmSMC_IND_ACCESS_CNTL);
323− val = REG_SET_FIELD(val, SMC_IND_ACCESS_CNTL, AUTO_INCREMENT_IND_0, 1);
324− WREG32(mmSMC_IND_ACCESS_CNTL, val);
325−
326− byte_count = ucode_size;
327− while (byte_count >= 4) {
328− data = (src[0] << 24) + (src[1] << 16) + (src[2] << 8) + src[3];
329− WREG32(mmSMC_IND_DATA_0, data);
330− src += 4;
331− byte_count -= 4;
332− }
333− val = RREG32(mmSMC_IND_ACCESS_CNTL);
334− val = REG_SET_FIELD(val, SMC_IND_ACCESS_CNTL, AUTO_INCREMENT_IND_0, 0);
335− WREG32(mmSMC_IND_ACCESS_CNTL, val);
336− spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
337−
338− return 0;
339−}
340−
341−#if 0 /* not used yet */
342−static int iceland_read_smc_sram_dword(struct amdgpu_device *adev,
343− uint32_t smc_address,
344− uint32_t *value,
345− uint32_t limit)
346−{
347− int result;
348− unsigned long flags;
349−
350− spin_lock_irqsave(&adev->smc_idx_lock, flags);
351− result = iceland_set_smc_sram_address(adev, smc_address, limit);
352− if (result == 0)
353− *value = RREG32(mmSMC_IND_DATA_0);
354− spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
355− return result;
356−}
357−
358−static int iceland_write_smc_sram_dword(struct amdgpu_device *adev,
359− uint32_t smc_address,
360− uint32_t value,
361− uint32_t limit)
362−{
363− int result;
364− unsigned long flags;
365−
366− spin_lock_irqsave(&adev->smc_idx_lock, flags);
367− result = iceland_set_smc_sram_address(adev, smc_address, limit);
368− if (result == 0)
369− WREG32(mmSMC_IND_DATA_0, value);
370− spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
371− return result;
372−}
373−
374−static int iceland_smu_stop_smc(struct amdgpu_device *adev)
375−{
376− iceland_reset_smc(adev);
377− iceland_stop_smc_clock(adev);
378−
379− return 0;
380−}
381−#endif
382−
383−static int iceland_smu_start_smc(struct amdgpu_device *adev)
384−{
385− int i;
386− uint32_t val;
387−
388− iceland_program_jump_on_start(adev);
389− iceland_start_smc_clock(adev);
390− iceland_start_smc(adev);
391−
392− for (i = 0; i < adev->usec_timeout; i++) {
393− val = RREG32_SMC(ixFIRMWARE_FLAGS);
394− if (REG_GET_FIELD(val, FIRMWARE_FLAGS, INTERRUPTS_ENABLED) == 1)
395− break;
396− udelay(1);
397− }
398− return 0;
399−}
400−
401−static enum AMDGPU_UCODE_ID iceland_convert_fw_type(uint32_t fw_type)
402−{
403− switch (fw_type) {
404− case UCODE_ID_SDMA0:
405− return AMDGPU_UCODE_ID_SDMA0;
406− case UCODE_ID_SDMA1:
407− return AMDGPU_UCODE_ID_SDMA1;
408− case UCODE_ID_CP_CE:
409− return AMDGPU_UCODE_ID_CP_CE;
410− case UCODE_ID_CP_PFP:
411− return AMDGPU_UCODE_ID_CP_PFP;
412− case UCODE_ID_CP_ME:
413− return AMDGPU_UCODE_ID_CP_ME;
414− case UCODE_ID_CP_MEC:
415− case UCODE_ID_CP_MEC_JT1:
416− return AMDGPU_UCODE_ID_CP_MEC1;
417− case UCODE_ID_CP_MEC_JT2:
418− return AMDGPU_UCODE_ID_CP_MEC2;
419− case UCODE_ID_RLC_G:
420− return AMDGPU_UCODE_ID_RLC_G;
421− default:
422− DRM_ERROR("ucode type is out of range!\n");
423− return AMDGPU_UCODE_ID_MAXIMUM;
424− }
425−}
426−
427−static uint32_t iceland_smu_get_mask_for_fw_type(uint32_t fw_type)
428−{
429− switch (fw_type) {
430− case AMDGPU_UCODE_ID_SDMA0:
431− return UCODE_ID_SDMA0_MASK;
432− case AMDGPU_UCODE_ID_SDMA1:
433− return UCODE_ID_SDMA1_MASK;
434− case AMDGPU_UCODE_ID_CP_CE:
435− return UCODE_ID_CP_CE_MASK;
436− case AMDGPU_UCODE_ID_CP_PFP:
437− return UCODE_ID_CP_PFP_MASK;
438− case AMDGPU_UCODE_ID_CP_ME:
439− return UCODE_ID_CP_ME_MASK;
440− case AMDGPU_UCODE_ID_CP_MEC1:
441− return UCODE_ID_CP_MEC_MASK | UCODE_ID_CP_MEC_JT1_MASK;
442− case AMDGPU_UCODE_ID_CP_MEC2:
443− return UCODE_ID_CP_MEC_MASK;
444− case AMDGPU_UCODE_ID_RLC_G:
445− return UCODE_ID_RLC_G_MASK;
446− default:
447− DRM_ERROR("ucode type is out of range!\n");
448− return 0;
449− }
450−}
451−
452−static int iceland_smu_populate_single_firmware_entry(struct amdgpu_device *adev,
453− uint32_t fw_type,
454− struct SMU_Entry *entry)
455−{
456− enum AMDGPU_UCODE_ID id = iceland_convert_fw_type(fw_type);
457− struct amdgpu_firmware_info *ucode = &adev->firmware.ucode[id];
458− const struct gfx_firmware_header_v1_0 *header = NULL;
459− uint64_t gpu_addr;
460− uint32_t data_size;
461−
462− if (ucode->fw == NULL)
463− return -EINVAL;
464−
465− gpu_addr = ucode->mc_addr;
466− header = (const struct gfx_firmware_header_v1_0 *)ucode->fw->data;
467− data_size = le32_to_cpu(header->header.ucode_size_bytes);
468−
469− entry->version = (uint16_t)le32_to_cpu(header->header.ucode_version);
470− entry->id = (uint16_t)fw_type;
471− entry->image_addr_high = upper_32_bits(gpu_addr);
472− entry->image_addr_low = lower_32_bits(gpu_addr);
473− entry->meta_data_addr_high = 0;
474− entry->meta_data_addr_low = 0;
475− entry->data_size_byte = data_size;
476− entry->num_register_entries = 0;
477− entry->flags = 0;
478−
479− return 0;
480−}
481−
482−static int iceland_smu_request_load_fw(struct amdgpu_device *adev)
483−{
484− struct iceland_smu_private_data *private = (struct iceland_smu_private_data *)adev->smu.priv;
485− struct SMU_DRAMData_TOC *toc;
486− uint32_t fw_to_load;
487−
488− toc = (struct SMU_DRAMData_TOC *)private->header;
489− toc->num_entries = 0;
490− toc->structure_version = 1;
491−
492− if (!adev->firmware.smu_load)
493− return 0;
494−
495− if (iceland_smu_populate_single_firmware_entry(adev, UCODE_ID_RLC_G,
496− &toc->entry[toc->num_entries++])) {
497− DRM_ERROR("Failed to get firmware entry for RLC\n");
498− return -EINVAL;
499− }
500−
501− if (iceland_smu_populate_single_firmware_entry(adev, UCODE_ID_CP_CE,
502− &toc->entry[toc->num_entries++])) {
503− DRM_ERROR("Failed to get firmware entry for CE\n");
504− return -EINVAL;
505− }
506−
507− if (iceland_smu_populate_single_firmware_entry(adev, UCODE_ID_CP_PFP,
508− &toc->entry[toc->num_entries++])) {
509− DRM_ERROR("Failed to get firmware entry for PFP\n");
510− return -EINVAL;
511− }
512−
513− if (iceland_smu_populate_single_firmware_entry(adev, UCODE_ID_CP_ME,
514− &toc->entry[toc->num_entries++])) {
515− DRM_ERROR("Failed to get firmware entry for ME\n");
516− return -EINVAL;
517− }
518−
519− if (iceland_smu_populate_single_firmware_entry(adev, UCODE_ID_CP_MEC,
520− &toc->entry[toc->num_entries++])) {
521− DRM_ERROR("Failed to get firmware entry for MEC\n");
522− return -EINVAL;
523− }
524−
525− if (iceland_smu_populate_single_firmware_entry(adev, UCODE_ID_CP_MEC_JT1,
526− &toc->entry[toc->num_entries++])) {
527− DRM_ERROR("Failed to get firmware entry for MEC_JT1\n");
528− return -EINVAL;
529− }
530−
531− if (iceland_smu_populate_single_firmware_entry(adev, UCODE_ID_SDMA0,
532− &toc->entry[toc->num_entries++])) {
533− DRM_ERROR("Failed to get firmware entry for SDMA0\n");
534− return -EINVAL;
535− }
536−
537− if (iceland_smu_populate_single_firmware_entry(adev, UCODE_ID_SDMA1,
538− &toc->entry[toc->num_entries++])) {
539− DRM_ERROR("Failed to get firmware entry for SDMA1\n");
540− return -EINVAL;
541− }
542−
543− iceland_send_msg_to_smc_with_parameter(adev, PPSMC_MSG_DRV_DRAM_ADDR_HI, private->header_addr_high);
544− iceland_send_msg_to_smc_with_parameter(adev, PPSMC_MSG_DRV_DRAM_ADDR_LO, private->header_addr_low);
545−
546− fw_to_load = UCODE_ID_RLC_G_MASK |
547− UCODE_ID_SDMA0_MASK |
548− UCODE_ID_SDMA1_MASK |
549− UCODE_ID_CP_CE_MASK |
550− UCODE_ID_CP_ME_MASK |
551− UCODE_ID_CP_PFP_MASK |
552− UCODE_ID_CP_MEC_MASK |
553− UCODE_ID_CP_MEC_JT1_MASK;
554−
555−
556− if (iceland_send_msg_to_smc_with_parameter_without_waiting(adev, PPSMC_MSG_LoadUcodes, fw_to_load)) {
557− DRM_ERROR("Fail to request SMU load ucode\n");
558− return -EINVAL;
559− }
560−
561− return 0;
562−}
563−
564−static int iceland_smu_check_fw_load_finish(struct amdgpu_device *adev,
565− uint32_t fw_type)
566−{
567− uint32_t fw_mask = iceland_smu_get_mask_for_fw_type(fw_type);
568− int i;
569−
570− for (i = 0; i < adev->usec_timeout; i++) {
571− if (fw_mask == (RREG32_SMC(ixSOFT_REGISTERS_TABLE_27) & fw_mask))
572− break;
573− udelay(1);
574− }
575−
576− if (i == adev->usec_timeout) {
577− DRM_ERROR("check firmware loading failed\n");
578− return -EINVAL;
579− }
580−
581− return 0;
582−}
583−
584−int iceland_smu_start(struct amdgpu_device *adev)
585−{
586− int result;
587−
588− result = iceland_smu_upload_firmware_image(adev);
589− if (result)
590− return result;
591− result = iceland_smu_start_smc(adev);
592− if (result)
593− return result;
594−
595− return iceland_smu_request_load_fw(adev);
596−}
597−
598−static const struct amdgpu_smumgr_funcs iceland_smumgr_funcs = {
599− .check_fw_load_finish = iceland_smu_check_fw_load_finish,
600− .request_smu_load_fw = NULL,
601− .request_smu_specific_fw = NULL,
602−};
603−
604−int iceland_smu_init(struct amdgpu_device *adev)
605−{
606− struct iceland_smu_private_data *private;
607− uint32_t image_size = ((sizeof(struct SMU_DRAMData_TOC) / 4096) + 1) * 4096;
608− struct amdgpu_bo **toc_buf = &adev->smu.toc_buf;
609− uint64_t mc_addr;
610− void *toc_buf_ptr;
611− int ret;
612−
613− private = kzalloc(sizeof(struct iceland_smu_private_data), GFP_KERNEL);
614− if (NULL == private)
615− return -ENOMEM;
616−
617− /* allocate firmware buffers */
618− if (adev->firmware.smu_load)
619− amdgpu_ucode_init_bo(adev);
620−
621− adev->smu.priv = private;
622− adev->smu.fw_flags = 0;
623−
624− /* Allocate FW image data structure and header buffer */
625− ret = amdgpu_bo_create(adev, image_size, PAGE_SIZE,
626− true, AMDGPU_GEM_DOMAIN_VRAM,
627− AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED,
628− NULL, NULL, toc_buf);
629− if (ret) {
630− DRM_ERROR("Failed to allocate memory for TOC buffer\n");
631− return -ENOMEM;
632− }
633−
634− /* Retrieve GPU address for header buffer and internal buffer */
635− ret = amdgpu_bo_reserve(adev->smu.toc_buf, false);
636− if (ret) {
637− amdgpu_bo_unref(&adev->smu.toc_buf);
638− DRM_ERROR("Failed to reserve the TOC buffer\n");
639− return -EINVAL;
640− }
641−
642− ret = amdgpu_bo_pin(adev->smu.toc_buf, AMDGPU_GEM_DOMAIN_VRAM, &mc_addr);
643− if (ret) {
644− amdgpu_bo_unreserve(adev->smu.toc_buf);
645− amdgpu_bo_unref(&adev->smu.toc_buf);
646− DRM_ERROR("Failed to pin the TOC buffer\n");
647− return -EINVAL;
648− }
649−
650− ret = amdgpu_bo_kmap(*toc_buf, &toc_buf_ptr);
651− if (ret) {
652− amdgpu_bo_unreserve(adev->smu.toc_buf);
653− amdgpu_bo_unref(&adev->smu.toc_buf);
654− DRM_ERROR("Failed to map the TOC buffer\n");
655− return -EINVAL;
656− }
657−
658− amdgpu_bo_unreserve(adev->smu.toc_buf);
659− private->header_addr_low = lower_32_bits(mc_addr);
660− private->header_addr_high = upper_32_bits(mc_addr);
661− private->header = toc_buf_ptr;
662−
663− adev->smu.smumgr_funcs = &iceland_smumgr_funcs;
664−
665− return 0;
666−}
667−
668−int iceland_smu_fini(struct amdgpu_device *adev)
669−{
670− amdgpu_bo_unref(&adev->smu.toc_buf);
671− kfree(adev->smu.priv);
672− adev->smu.priv = NULL;
673− if (adev->firmware.fw_buf)
674− amdgpu_ucode_fini_bo(adev);
675−
676− return 0;
677−}
drivers/gpu/drm/amd/amdgpu/si.c+7−7
@@ -952,12 +952,6 @@ static void si_smc_wreg(struct amdgpu_device *adev, u32 reg, u32 v) · 951 unmodified lines
952952 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
953953 }
954954
955−static u32 si_get_virtual_caps(struct amdgpu_device *adev)
956−{
957− /* SI does not support SR-IOV */
958− return 0;
959−}
960−
961955 static struct amdgpu_allowed_register_entry si_allowed_read_registers[] = {
962956 {GRBM_STATUS, false},
963957 {GB_ADDR_CONFIG, false},
@@ -1124,16 +1118,22 @@ static int si_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk) · 160 unmodified lines
11241118 return 0;
11251119 }
11261120
1121+static void si_detect_hw_virtualization(struct amdgpu_device *adev)
1122+{
1123+ if (is_virtual_machine()) /* passthrough mode */
1124+ adev->virtualization.virtual_caps |= AMDGPU_PASSTHROUGH_MODE;
1125+}
1126+
11271127 static const struct amdgpu_asic_funcs si_asic_funcs =
11281128 {
11291129 .read_disabled_bios = &si_read_disabled_bios,
1130+ .detect_hw_virtualization = si_detect_hw_virtualization,
11301131 .read_register = &si_read_register,
11311132 .reset = &si_asic_reset,
11321133 .set_vga_state = &si_vga_set_state,
11331134 .get_xclk = &si_get_xclk,
11341135 .set_uvd_clocks = &si_set_uvd_clocks,
11351136 .set_vce_clocks = NULL,
1136− .get_virtual_caps = &si_get_virtual_caps,
11371137 };
11381138
11391139 static uint32_t si_get_rev_id(struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/tonga_dpm.c+0−186
@@ -1,186 +0,0 @@
1−/*
2− * Copyright 2014 Advanced Micro Devices, Inc.
3− *
4− * Permission is hereby granted, free of charge, to any person obtaining a
5− * copy of this software and associated documentation files (the "Software"),
6− * to deal in the Software without restriction, including without limitation
7− * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8− * and/or sell copies of the Software, and to permit persons to whom the
9− * Software is furnished to do so, subject to the following conditions:
10− *
11− * The above copyright notice and this permission notice shall be included in
12− * all copies or substantial portions of the Software.
13− *
14− * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15− * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16− * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17− * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18− * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19− * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20− * OTHER DEALINGS IN THE SOFTWARE.
21− *
22− */
23−
24−#include <linux/firmware.h>
25−#include "drmP.h"
26−#include "amdgpu.h"
27−#include "tonga_smum.h"
28−
29−MODULE_FIRMWARE("amdgpu/tonga_smc.bin");
30−
31−static void tonga_dpm_set_funcs(struct amdgpu_device *adev);
32−
33−static int tonga_dpm_early_init(void *handle)
34−{
35− struct amdgpu_device *adev = (struct amdgpu_device *)handle;
36−
37− tonga_dpm_set_funcs(adev);
38−
39− return 0;
40−}
41−
42−static int tonga_dpm_init_microcode(struct amdgpu_device *adev)
43−{
44− char fw_name[30] = "amdgpu/tonga_smc.bin";
45− int err;
46− err = request_firmware(&adev->pm.fw, fw_name, adev->dev);
47− if (err)
48− goto out;
49− err = amdgpu_ucode_validate(adev->pm.fw);
50−
51−out:
52− if (err) {
53− DRM_ERROR("Failed to load firmware \"%s\"", fw_name);
54− release_firmware(adev->pm.fw);
55− adev->pm.fw = NULL;
56− }
57− return err;
58−}
59−
60−static int tonga_dpm_sw_init(void *handle)
61−{
62− int ret;
63− struct amdgpu_device *adev = (struct amdgpu_device *)handle;
64−
65− ret = tonga_dpm_init_microcode(adev);
66− if (ret)
67− return ret;
68−
69− return 0;
70−}
71−
72−static int tonga_dpm_sw_fini(void *handle)
73−{
74− struct amdgpu_device *adev = (struct amdgpu_device *)handle;
75−
76− release_firmware(adev->pm.fw);
77− adev->pm.fw = NULL;
78−
79− return 0;
80−}
81−
82−static int tonga_dpm_hw_init(void *handle)
83−{
84− int ret;
85− struct amdgpu_device *adev = (struct amdgpu_device *)handle;
86−
87− mutex_lock(&adev->pm.mutex);
88−
89− /* smu init only needs to be called at startup, not resume.
90− * It should be in sw_init, but requires the fw info gathered
91− * in sw_init from other IP modules.
92− */
93− ret = tonga_smu_init(adev);
94− if (ret) {
95− DRM_ERROR("SMU initialization failed\n");
96− goto fail;
97− }
98−
99− ret = tonga_smu_start(adev);
100− if (ret) {
101− DRM_ERROR("SMU start failed\n");
102− goto fail;
103− }
104−
105− mutex_unlock(&adev->pm.mutex);
106− return 0;
107−
108−fail:
109− adev->firmware.smu_load = false;
110− mutex_unlock(&adev->pm.mutex);
111− return -EINVAL;
112−}
113−
114−static int tonga_dpm_hw_fini(void *handle)
115−{
116− struct amdgpu_device *adev = (struct amdgpu_device *)handle;
117−
118− mutex_lock(&adev->pm.mutex);
119− /* smu fini only needs to be called at teardown, not suspend.
120− * It should be in sw_fini, but we put it here for symmetry
121− * with smu init.
122− */
123− tonga_smu_fini(adev);
124− mutex_unlock(&adev->pm.mutex);
125− return 0;
126−}
127−
128−static int tonga_dpm_suspend(void *handle)
129−{
130− return tonga_dpm_hw_fini(handle);
131−}
132−
133−static int tonga_dpm_resume(void *handle)
134−{
135− return tonga_dpm_hw_init(handle);
136−}
137−
138−static int tonga_dpm_set_clockgating_state(void *handle,
139− enum amd_clockgating_state state)
140−{
141− return 0;
142−}
143−
144−static int tonga_dpm_set_powergating_state(void *handle,
145− enum amd_powergating_state state)
146−{
147− return 0;
148−}
149−
150−const struct amd_ip_funcs tonga_dpm_ip_funcs = {
151− .name = "tonga_dpm",
152− .early_init = tonga_dpm_early_init,
153− .late_init = NULL,
154− .sw_init = tonga_dpm_sw_init,
155− .sw_fini = tonga_dpm_sw_fini,
156− .hw_init = tonga_dpm_hw_init,
157− .hw_fini = tonga_dpm_hw_fini,
158− .suspend = tonga_dpm_suspend,
159− .resume = tonga_dpm_resume,
160− .is_idle = NULL,
161− .wait_for_idle = NULL,
162− .soft_reset = NULL,
163− .set_clockgating_state = tonga_dpm_set_clockgating_state,
164− .set_powergating_state = tonga_dpm_set_powergating_state,
165−};
166−
167−static const struct amdgpu_dpm_funcs tonga_dpm_funcs = {
168− .get_temperature = NULL,
169− .pre_set_power_state = NULL,
170− .set_power_state = NULL,
171− .post_set_power_state = NULL,
172− .display_configuration_changed = NULL,
173− .get_sclk = NULL,
174− .get_mclk = NULL,
175− .print_power_state = NULL,
176− .debugfs_print_current_performance_level = NULL,
177− .force_performance_level = NULL,
178− .vblank_too_short = NULL,
179− .powergate_uvd = NULL,
180−};
181−
182−static void tonga_dpm_set_funcs(struct amdgpu_device *adev)
183−{
184− if (NULL == adev->pm.funcs)
185− adev->pm.funcs = &tonga_dpm_funcs;
186−}
drivers/gpu/drm/amd/amdgpu/tonga_smc.c+0−862
@@ -1,862 +0,0 @@
1−/*
2− * Copyright 2014 Advanced Micro Devices, Inc.
3− *
4− * Permission is hereby granted, free of charge, to any person obtaining a
5− * copy of this software and associated documentation files (the "Software"),
6− * to deal in the Software without restriction, including without limitation
7− * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8− * and/or sell copies of the Software, and to permit persons to whom the
9− * Software is furnished to do so, subject to the following conditions:
10− *
11− * The above copyright notice and this permission notice shall be included in
12− * all copies or substantial portions of the Software.
13− *
14− * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15− * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16− * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17− * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18− * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19− * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20− * OTHER DEALINGS IN THE SOFTWARE.
21− *
22− */
23−
24−#include <linux/firmware.h>
25−#include "drmP.h"
26−#include "amdgpu.h"
27−#include "tonga_ppsmc.h"
28−#include "tonga_smum.h"
29−#include "smu_ucode_xfer_vi.h"
30−#include "amdgpu_ucode.h"
31−
32−#include "smu/smu_7_1_2_d.h"
33−#include "smu/smu_7_1_2_sh_mask.h"
34−
35−#define TONGA_SMC_SIZE 0x20000
36−
37−static int tonga_set_smc_sram_address(struct amdgpu_device *adev, uint32_t smc_address, uint32_t limit)
38−{
39− uint32_t val;
40−
41− if (smc_address & 3)
42− return -EINVAL;
43−
44− if ((smc_address + 3) > limit)
45− return -EINVAL;
46−
47− WREG32(mmSMC_IND_INDEX_0, smc_address);
48−
49− val = RREG32(mmSMC_IND_ACCESS_CNTL);
50− val = REG_SET_FIELD(val, SMC_IND_ACCESS_CNTL, AUTO_INCREMENT_IND_0, 0);
51− WREG32(mmSMC_IND_ACCESS_CNTL, val);
52−
53− return 0;
54−}
55−
56−static int tonga_copy_bytes_to_smc(struct amdgpu_device *adev, uint32_t smc_start_address, const uint8_t *src, uint32_t byte_count, uint32_t limit)
57−{
58− uint32_t addr;
59− uint32_t data, orig_data;
60− int result = 0;
61− uint32_t extra_shift;
62− unsigned long flags;
63−
64− if (smc_start_address & 3)
65− return -EINVAL;
66−
67− if ((smc_start_address + byte_count) > limit)
68− return -EINVAL;
69−
70− addr = smc_start_address;
71−
72− spin_lock_irqsave(&adev->smc_idx_lock, flags);
73− while (byte_count >= 4) {
74− /* Bytes are written into the SMC addres space with the MSB first */
75− data = (src[0] << 24) + (src[1] << 16) + (src[2] << 8) + src[3];
76−
77− result = tonga_set_smc_sram_address(adev, addr, limit);
78−
79− if (result)
80− goto out;
81−
82− WREG32(mmSMC_IND_DATA_0, data);
83−
84− src += 4;
85− byte_count -= 4;
86− addr += 4;
87− }
88−
89− if (0 != byte_count) {
90− /* Now write odd bytes left, do a read modify write cycle */
91− data = 0;
92−
93− result = tonga_set_smc_sram_address(adev, addr, limit);
94− if (result)
95− goto out;
96−
97− orig_data = RREG32(mmSMC_IND_DATA_0);
98− extra_shift = 8 * (4 - byte_count);
99−
100− while (byte_count > 0) {
101− data = (data << 8) + *src++;
102− byte_count--;
103− }
104−
105− data <<= extra_shift;
106− data |= (orig_data & ~((~0UL) << extra_shift));
107−
108− result = tonga_set_smc_sram_address(adev, addr, limit);
109− if (result)
110− goto out;
111−
112− WREG32(mmSMC_IND_DATA_0, data);
113− }
114−
115−out:
116− spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
117− return result;
118−}
119−
120−static int tonga_program_jump_on_start(struct amdgpu_device *adev)
121−{
122− static unsigned char data[] = {0xE0, 0x00, 0x80, 0x40};
123− tonga_copy_bytes_to_smc(adev, 0x0, data, 4, sizeof(data)+1);
124−
125− return 0;
126−}
127−
128−static bool tonga_is_smc_ram_running(struct amdgpu_device *adev)
129−{
130− uint32_t val = RREG32_SMC(ixSMC_SYSCON_CLOCK_CNTL_0);
131− val = REG_GET_FIELD(val, SMC_SYSCON_CLOCK_CNTL_0, ck_disable);
132−
133− return ((0 == val) && (0x20100 <= RREG32_SMC(ixSMC_PC_C)));
134−}
135−
136−static int wait_smu_response(struct amdgpu_device *adev)
137−{
138− int i;
139− uint32_t val;
140−
141− for (i = 0; i < adev->usec_timeout; i++) {
142− val = RREG32(mmSMC_RESP_0);
143− if (REG_GET_FIELD(val, SMC_RESP_0, SMC_RESP))
144− break;
145− udelay(1);
146− }
147−
148− if (i == adev->usec_timeout)
149− return -EINVAL;
150−
151− return 0;
152−}
153−
154−static int tonga_send_msg_to_smc_offset(struct amdgpu_device *adev)
155−{
156− if (wait_smu_response(adev)) {
157− DRM_ERROR("Failed to send previous message\n");
158− return -EINVAL;
159− }
160−
161− WREG32(mmSMC_MSG_ARG_0, 0x20000);
162− WREG32(mmSMC_MESSAGE_0, PPSMC_MSG_Test);
163−
164− if (wait_smu_response(adev)) {
165− DRM_ERROR("Failed to send message\n");
166− return -EINVAL;
167− }
168−
169− return 0;
170−}
171−
172−static int tonga_send_msg_to_smc(struct amdgpu_device *adev, PPSMC_Msg msg)
173−{
174− if (!tonga_is_smc_ram_running(adev))
175− {
176− return -EINVAL;
177− }
178−
179− if (wait_smu_response(adev)) {
180− DRM_ERROR("Failed to send previous message\n");
181− return -EINVAL;
182− }
183−
184− WREG32(mmSMC_MESSAGE_0, msg);
185−
186− if (wait_smu_response(adev)) {
187− DRM_ERROR("Failed to send message\n");
188− return -EINVAL;
189− }
190−
191− return 0;
192−}
193−
194−static int tonga_send_msg_to_smc_without_waiting(struct amdgpu_device *adev,
195− PPSMC_Msg msg)
196−{
197− if (wait_smu_response(adev)) {
198− DRM_ERROR("Failed to send previous message\n");
199− return -EINVAL;
200− }
201−
202− WREG32(mmSMC_MESSAGE_0, msg);
203−
204− return 0;
205−}
206−
207−static int tonga_send_msg_to_smc_with_parameter(struct amdgpu_device *adev,
208− PPSMC_Msg msg,
209− uint32_t parameter)
210−{
211− if (!tonga_is_smc_ram_running(adev))
212− return -EINVAL;
213−
214− if (wait_smu_response(adev)) {
215− DRM_ERROR("Failed to send previous message\n");
216− return -EINVAL;
217− }
218−
219− WREG32(mmSMC_MSG_ARG_0, parameter);
220−
221− return tonga_send_msg_to_smc(adev, msg);
222−}
223−
224−static int tonga_send_msg_to_smc_with_parameter_without_waiting(
225− struct amdgpu_device *adev,
226− PPSMC_Msg msg, uint32_t parameter)
227−{
228− if (wait_smu_response(adev)) {
229− DRM_ERROR("Failed to send previous message\n");
230− return -EINVAL;
231− }
232−
233− WREG32(mmSMC_MSG_ARG_0, parameter);
234−
235− return tonga_send_msg_to_smc_without_waiting(adev, msg);
236−}
237−
238−#if 0 /* not used yet */
239−static int tonga_wait_for_smc_inactive(struct amdgpu_device *adev)
240−{
241− int i;
242− uint32_t val;
243−
244− if (!tonga_is_smc_ram_running(adev))
245− return -EINVAL;
246−
247− for (i = 0; i < adev->usec_timeout; i++) {
248− val = RREG32_SMC(ixSMC_SYSCON_CLOCK_CNTL_0);
249− if (REG_GET_FIELD(val, SMC_SYSCON_CLOCK_CNTL_0, cken) == 0)
250− break;
251− udelay(1);
252− }
253−
254− if (i == adev->usec_timeout)
255− return -EINVAL;
256−
257− return 0;
258−}
259−#endif
260−
261−static int tonga_smu_upload_firmware_image(struct amdgpu_device *adev)
262−{
263− const struct smc_firmware_header_v1_0 *hdr;
264− uint32_t ucode_size;
265− uint32_t ucode_start_address;
266− const uint8_t *src;
267− uint32_t val;
268− uint32_t byte_count;
269− uint32_t *data;
270− unsigned long flags;
271−
272− if (!adev->pm.fw)
273− return -EINVAL;
274−
275− /* Skip SMC ucode loading on SR-IOV capable boards.
276− * vbios does this for us in asic_init in that case.
277− */
278− if (adev->virtualization.supports_sr_iov)
279− return 0;
280−
281− hdr = (const struct smc_firmware_header_v1_0 *)adev->pm.fw->data;
282− amdgpu_ucode_print_smc_hdr(&hdr->header);
283−
284− adev->pm.fw_version = le32_to_cpu(hdr->header.ucode_version);
285− ucode_size = le32_to_cpu(hdr->header.ucode_size_bytes);
286− ucode_start_address = le32_to_cpu(hdr->ucode_start_addr);
287− src = (const uint8_t *)
288− (adev->pm.fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
289−
290− if (ucode_size & 3) {
291− DRM_ERROR("SMC ucode is not 4 bytes aligned\n");
292− return -EINVAL;
293− }
294−
295− if (ucode_size > TONGA_SMC_SIZE) {
296− DRM_ERROR("SMC address is beyond the SMC RAM area\n");
297− return -EINVAL;
298− }
299−
300− spin_lock_irqsave(&adev->smc_idx_lock, flags);
301− WREG32(mmSMC_IND_INDEX_0, ucode_start_address);
302−
303− val = RREG32(mmSMC_IND_ACCESS_CNTL);
304− val = REG_SET_FIELD(val, SMC_IND_ACCESS_CNTL, AUTO_INCREMENT_IND_0, 1);
305− WREG32(mmSMC_IND_ACCESS_CNTL, val);
306−
307− byte_count = ucode_size;
308− data = (uint32_t *)src;
309− for (; byte_count >= 4; data++, byte_count -= 4)
310− WREG32(mmSMC_IND_DATA_0, data[0]);
311−
312− val = RREG32(mmSMC_IND_ACCESS_CNTL);
313− val = REG_SET_FIELD(val, SMC_IND_ACCESS_CNTL, AUTO_INCREMENT_IND_0, 0);
314− WREG32(mmSMC_IND_ACCESS_CNTL, val);
315− spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
316−
317− return 0;
318−}
319−
320−#if 0 /* not used yet */
321−static int tonga_read_smc_sram_dword(struct amdgpu_device *adev,
322− uint32_t smc_address,
323− uint32_t *value,
324− uint32_t limit)
325−{
326− int result;
327− unsigned long flags;
328−
329− spin_lock_irqsave(&adev->smc_idx_lock, flags);
330− result = tonga_set_smc_sram_address(adev, smc_address, limit);
331− if (result == 0)
332− *value = RREG32(mmSMC_IND_DATA_0);
333− spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
334− return result;
335−}
336−
337−static int tonga_write_smc_sram_dword(struct amdgpu_device *adev,
338− uint32_t smc_address,
339− uint32_t value,
340− uint32_t limit)
341−{
342− int result;
343− unsigned long flags;
344−
345− spin_lock_irqsave(&adev->smc_idx_lock, flags);
346− result = tonga_set_smc_sram_address(adev, smc_address, limit);
347− if (result == 0)
348− WREG32(mmSMC_IND_DATA_0, value);
349− spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
350− return result;
351−}
352−
353−static int tonga_smu_stop_smc(struct amdgpu_device *adev)
354−{
355− uint32_t val = RREG32_SMC(ixSMC_SYSCON_RESET_CNTL);
356− val = REG_SET_FIELD(val, SMC_SYSCON_RESET_CNTL, rst_reg, 1);
357− WREG32_SMC(ixSMC_SYSCON_RESET_CNTL, val);
358−
359− val = RREG32_SMC(ixSMC_SYSCON_CLOCK_CNTL_0);
360− val = REG_SET_FIELD(val, SMC_SYSCON_CLOCK_CNTL_0, ck_disable, 1);
361− WREG32_SMC(ixSMC_SYSCON_CLOCK_CNTL_0, val);
362−
363− return 0;
364−}
365−#endif
366−
367−static enum AMDGPU_UCODE_ID tonga_convert_fw_type(uint32_t fw_type)
368−{
369− switch (fw_type) {
370− case UCODE_ID_SDMA0:
371− return AMDGPU_UCODE_ID_SDMA0;
372− case UCODE_ID_SDMA1:
373− return AMDGPU_UCODE_ID_SDMA1;
374− case UCODE_ID_CP_CE:
375− return AMDGPU_UCODE_ID_CP_CE;
376− case UCODE_ID_CP_PFP:
377− return AMDGPU_UCODE_ID_CP_PFP;
378− case UCODE_ID_CP_ME:
379− return AMDGPU_UCODE_ID_CP_ME;
380− case UCODE_ID_CP_MEC:
381− case UCODE_ID_CP_MEC_JT1:
382− return AMDGPU_UCODE_ID_CP_MEC1;
383− case UCODE_ID_CP_MEC_JT2:
384− return AMDGPU_UCODE_ID_CP_MEC2;
385− case UCODE_ID_RLC_G:
386− return AMDGPU_UCODE_ID_RLC_G;
387− default:
388− DRM_ERROR("ucode type is out of range!\n");
389− return AMDGPU_UCODE_ID_MAXIMUM;
390− }
391−}
392−
393−static int tonga_smu_populate_single_firmware_entry(struct amdgpu_device *adev,
394− uint32_t fw_type,
395− struct SMU_Entry *entry)
396−{
397− enum AMDGPU_UCODE_ID id = tonga_convert_fw_type(fw_type);
398− struct amdgpu_firmware_info *ucode = &adev->firmware.ucode[id];
399− const struct gfx_firmware_header_v1_0 *header = NULL;
400− uint64_t gpu_addr;
401− uint32_t data_size;
402−
403− if (ucode->fw == NULL)
404− return -EINVAL;
405−
406− gpu_addr = ucode->mc_addr;
407− header = (const struct gfx_firmware_header_v1_0 *)ucode->fw->data;
408− data_size = le32_to_cpu(header->header.ucode_size_bytes);
409−
410− if ((fw_type == UCODE_ID_CP_MEC_JT1) ||
411− (fw_type == UCODE_ID_CP_MEC_JT2)) {
412− gpu_addr += le32_to_cpu(header->jt_offset) << 2;
413− data_size = le32_to_cpu(header->jt_size) << 2;
414− }
415−
416− entry->version = (uint16_t)le32_to_cpu(header->header.ucode_version);
417− entry->id = (uint16_t)fw_type;
418− entry->image_addr_high = upper_32_bits(gpu_addr);
419− entry->image_addr_low = lower_32_bits(gpu_addr);
420− entry->meta_data_addr_high = 0;
421− entry->meta_data_addr_low = 0;
422− entry->data_size_byte = data_size;
423− entry->num_register_entries = 0;
424−
425− if (fw_type == UCODE_ID_RLC_G)
426− entry->flags = 1;
427− else
428− entry->flags = 0;
429−
430− return 0;
431−}
432−
433−static int tonga_smu_request_load_fw(struct amdgpu_device *adev)
434−{
435− struct tonga_smu_private_data *private = (struct tonga_smu_private_data *)adev->smu.priv;
436− struct SMU_DRAMData_TOC *toc;
437− uint32_t fw_to_load;
438−
439− WREG32_SMC(ixSOFT_REGISTERS_TABLE_28, 0);
440−
441− tonga_send_msg_to_smc_with_parameter(adev, PPSMC_MSG_SMU_DRAM_ADDR_HI, private->smu_buffer_addr_high);
442− tonga_send_msg_to_smc_with_parameter(adev, PPSMC_MSG_SMU_DRAM_ADDR_LO, private->smu_buffer_addr_low);
443−
444− toc = (struct SMU_DRAMData_TOC *)private->header;
445− toc->num_entries = 0;
446− toc->structure_version = 1;
447−
448− if (!adev->firmware.smu_load)
449− return 0;
450−
451− if (tonga_smu_populate_single_firmware_entry(adev, UCODE_ID_RLC_G,
452− &toc->entry[toc->num_entries++])) {
453− DRM_ERROR("Failed to get firmware entry for RLC\n");
454− return -EINVAL;
455− }
456−
457− if (tonga_smu_populate_single_firmware_entry(adev, UCODE_ID_CP_CE,
458− &toc->entry[toc->num_entries++])) {
459− DRM_ERROR("Failed to get firmware entry for CE\n");
460− return -EINVAL;
461− }
462−
463− if (tonga_smu_populate_single_firmware_entry(adev, UCODE_ID_CP_PFP,
464− &toc->entry[toc->num_entries++])) {
465− DRM_ERROR("Failed to get firmware entry for PFP\n");
466− return -EINVAL;
467− }
468−
469− if (tonga_smu_populate_single_firmware_entry(adev, UCODE_ID_CP_ME,
470− &toc->entry[toc->num_entries++])) {
471− DRM_ERROR("Failed to get firmware entry for ME\n");
472− return -EINVAL;
473− }
474−
475− if (tonga_smu_populate_single_firmware_entry(adev, UCODE_ID_CP_MEC,
476− &toc->entry[toc->num_entries++])) {
477− DRM_ERROR("Failed to get firmware entry for MEC\n");
478− return -EINVAL;
479− }
480−
481− if (tonga_smu_populate_single_firmware_entry(adev, UCODE_ID_CP_MEC_JT1,
482− &toc->entry[toc->num_entries++])) {
483− DRM_ERROR("Failed to get firmware entry for MEC_JT1\n");
484− return -EINVAL;
485− }
486−
487− if (tonga_smu_populate_single_firmware_entry(adev, UCODE_ID_CP_MEC_JT2,
488− &toc->entry[toc->num_entries++])) {
489− DRM_ERROR("Failed to get firmware entry for MEC_JT2\n");
490− return -EINVAL;
491− }
492−
493− if (tonga_smu_populate_single_firmware_entry(adev, UCODE_ID_SDMA0,
494− &toc->entry[toc->num_entries++])) {
495− DRM_ERROR("Failed to get firmware entry for SDMA0\n");
496− return -EINVAL;
497− }
498−
499− if (tonga_smu_populate_single_firmware_entry(adev, UCODE_ID_SDMA1,
500− &toc->entry[toc->num_entries++])) {
501− DRM_ERROR("Failed to get firmware entry for SDMA1\n");
502− return -EINVAL;
503− }
504−
505− tonga_send_msg_to_smc_with_parameter(adev, PPSMC_MSG_DRV_DRAM_ADDR_HI, private->header_addr_high);
506− tonga_send_msg_to_smc_with_parameter(adev, PPSMC_MSG_DRV_DRAM_ADDR_LO, private->header_addr_low);
507−
508− fw_to_load = UCODE_ID_RLC_G_MASK |
509− UCODE_ID_SDMA0_MASK |
510− UCODE_ID_SDMA1_MASK |
511− UCODE_ID_CP_CE_MASK |
512− UCODE_ID_CP_ME_MASK |
513− UCODE_ID_CP_PFP_MASK |
514− UCODE_ID_CP_MEC_MASK;
515−
516− if (tonga_send_msg_to_smc_with_parameter_without_waiting(adev, PPSMC_MSG_LoadUcodes, fw_to_load)) {
517− DRM_ERROR("Fail to request SMU load ucode\n");
518− return -EINVAL;
519− }
520−
521− return 0;
522−}
523−
524−static uint32_t tonga_smu_get_mask_for_fw_type(uint32_t fw_type)
525−{
526− switch (fw_type) {
527− case AMDGPU_UCODE_ID_SDMA0:
528− return UCODE_ID_SDMA0_MASK;
529− case AMDGPU_UCODE_ID_SDMA1:
530− return UCODE_ID_SDMA1_MASK;
531− case AMDGPU_UCODE_ID_CP_CE:
532− return UCODE_ID_CP_CE_MASK;
533− case AMDGPU_UCODE_ID_CP_PFP:
534− return UCODE_ID_CP_PFP_MASK;
535− case AMDGPU_UCODE_ID_CP_ME:
536− return UCODE_ID_CP_ME_MASK;
537− case AMDGPU_UCODE_ID_CP_MEC1:
538− return UCODE_ID_CP_MEC_MASK;
539− case AMDGPU_UCODE_ID_CP_MEC2:
540− return UCODE_ID_CP_MEC_MASK;
541− case AMDGPU_UCODE_ID_RLC_G:
542− return UCODE_ID_RLC_G_MASK;
543− default:
544− DRM_ERROR("ucode type is out of range!\n");
545− return 0;
546− }
547−}
548−
549−static int tonga_smu_check_fw_load_finish(struct amdgpu_device *adev,
550− uint32_t fw_type)
551−{
552− uint32_t fw_mask = tonga_smu_get_mask_for_fw_type(fw_type);
553− int i;
554−
555− for (i = 0; i < adev->usec_timeout; i++) {
556− if (fw_mask == (RREG32_SMC(ixSOFT_REGISTERS_TABLE_28) & fw_mask))
557− break;
558− udelay(1);
559− }
560−
561− if (i == adev->usec_timeout) {
562− DRM_ERROR("check firmware loading failed\n");
563− return -EINVAL;
564− }
565−
566− return 0;
567−}
568−
569−static int tonga_smu_start_in_protection_mode(struct amdgpu_device *adev)
570−{
571− int result;
572− uint32_t val;
573− int i;
574−
575− /* Assert reset */
576− val = RREG32_SMC(ixSMC_SYSCON_RESET_CNTL);
577− val = REG_SET_FIELD(val, SMC_SYSCON_RESET_CNTL, rst_reg, 1);
578− WREG32_SMC(ixSMC_SYSCON_RESET_CNTL, val);
579−
580− result = tonga_smu_upload_firmware_image(adev);
581− if (result)
582− return result;
583−
584− /* Clear status */
585− WREG32_SMC(ixSMU_STATUS, 0);
586−
587− /* Enable clock */
588− val = RREG32_SMC(ixSMC_SYSCON_CLOCK_CNTL_0);
589− val = REG_SET_FIELD(val, SMC_SYSCON_CLOCK_CNTL_0, ck_disable, 0);
590− WREG32_SMC(ixSMC_SYSCON_CLOCK_CNTL_0, val);
591−
592− /* De-assert reset */
593− val = RREG32_SMC(ixSMC_SYSCON_RESET_CNTL);
594− val = REG_SET_FIELD(val, SMC_SYSCON_RESET_CNTL, rst_reg, 0);
595− WREG32_SMC(ixSMC_SYSCON_RESET_CNTL, val);
596−
597− /* Set SMU Auto Start */
598− val = RREG32_SMC(ixSMU_INPUT_DATA);
599− val = REG_SET_FIELD(val, SMU_INPUT_DATA, AUTO_START, 1);
600− WREG32_SMC(ixSMU_INPUT_DATA, val);
601−
602− /* Clear firmware interrupt enable flag */
603− WREG32_SMC(ixFIRMWARE_FLAGS, 0);
604−
605− for (i = 0; i < adev->usec_timeout; i++) {
606− val = RREG32_SMC(ixRCU_UC_EVENTS);
607− if (REG_GET_FIELD(val, RCU_UC_EVENTS, INTERRUPTS_ENABLED))
608− break;
609− udelay(1);
610− }
611−
612− if (i == adev->usec_timeout) {
613− DRM_ERROR("Interrupt is not enabled by firmware\n");
614− return -EINVAL;
615− }
616−
617− /* Call Test SMU message with 0x20000 offset
618− * to trigger SMU start
619− */
620− tonga_send_msg_to_smc_offset(adev);
621−
622− /* Wait for done bit to be set */
623− for (i = 0; i < adev->usec_timeout; i++) {
624− val = RREG32_SMC(ixSMU_STATUS);
625− if (REG_GET_FIELD(val, SMU_STATUS, SMU_DONE))
626− break;
627− udelay(1);
628− }
629−
630− if (i == adev->usec_timeout) {
631− DRM_ERROR("Timeout for SMU start\n");
632− return -EINVAL;
633− }
634−
635− /* Check pass/failed indicator */
636− val = RREG32_SMC(ixSMU_STATUS);
637− if (!REG_GET_FIELD(val, SMU_STATUS, SMU_PASS)) {
638− DRM_ERROR("SMU Firmware start failed\n");
639− return -EINVAL;
640− }
641−
642− /* Wait for firmware to initialize */
643− for (i = 0; i < adev->usec_timeout; i++) {
644− val = RREG32_SMC(ixFIRMWARE_FLAGS);
645− if(REG_GET_FIELD(val, FIRMWARE_FLAGS, INTERRUPTS_ENABLED))
646− break;
647− udelay(1);
648− }
649−
650− if (i == adev->usec_timeout) {
651− DRM_ERROR("SMU firmware initialization failed\n");
652− return -EINVAL;
653− }
654−
655− return 0;
656−}
657−
658−static int tonga_smu_start_in_non_protection_mode(struct amdgpu_device *adev)
659−{
660− int i, result;
661− uint32_t val;
662−
663− /* wait for smc boot up */
664− for (i = 0; i < adev->usec_timeout; i++) {
665− val = RREG32_SMC(ixRCU_UC_EVENTS);
666− val = REG_GET_FIELD(val, RCU_UC_EVENTS, boot_seq_done);
667− if (val)
668− break;
669− udelay(1);
670− }
671−
672− if (i == adev->usec_timeout) {
673− DRM_ERROR("SMC boot sequence is not completed\n");
674− return -EINVAL;
675− }
676−
677− /* Clear firmware interrupt enable flag */
678− WREG32_SMC(ixFIRMWARE_FLAGS, 0);
679−
680− /* Assert reset */
681− val = RREG32_SMC(ixSMC_SYSCON_RESET_CNTL);
682− val = REG_SET_FIELD(val, SMC_SYSCON_RESET_CNTL, rst_reg, 1);
683− WREG32_SMC(ixSMC_SYSCON_RESET_CNTL, val);
684−
685− result = tonga_smu_upload_firmware_image(adev);
686− if (result)
687− return result;
688−
689− /* Set smc instruct start point at 0x0 */
690− tonga_program_jump_on_start(adev);
691−
692− /* Enable clock */
693− val = RREG32_SMC(ixSMC_SYSCON_CLOCK_CNTL_0);
694− val = REG_SET_FIELD(val, SMC_SYSCON_CLOCK_CNTL_0, ck_disable, 0);
695− WREG32_SMC(ixSMC_SYSCON_CLOCK_CNTL_0, val);
696−
697− /* De-assert reset */
698− val = RREG32_SMC(ixSMC_SYSCON_RESET_CNTL);
699− val = REG_SET_FIELD(val, SMC_SYSCON_RESET_CNTL, rst_reg, 0);
700− WREG32_SMC(ixSMC_SYSCON_RESET_CNTL, val);
701−
702− /* Wait for firmware to initialize */
703− for (i = 0; i < adev->usec_timeout; i++) {
704− val = RREG32_SMC(ixFIRMWARE_FLAGS);
705− if (REG_GET_FIELD(val, FIRMWARE_FLAGS, INTERRUPTS_ENABLED))
706− break;
707− udelay(1);
708− }
709−
710− if (i == adev->usec_timeout) {
711− DRM_ERROR("Timeout for SMC firmware initialization\n");
712− return -EINVAL;
713− }
714−
715− return 0;
716−}
717−
718−int tonga_smu_start(struct amdgpu_device *adev)
719−{
720− int result;
721− uint32_t val;
722−
723− if (!tonga_is_smc_ram_running(adev)) {
724− val = RREG32_SMC(ixSMU_FIRMWARE);
725− if (!REG_GET_FIELD(val, SMU_FIRMWARE, SMU_MODE)) {
726− result = tonga_smu_start_in_non_protection_mode(adev);
727− if (result)
728− return result;
729− } else {
730− result = tonga_smu_start_in_protection_mode(adev);
731− if (result)
732− return result;
733− }
734− }
735−
736− return tonga_smu_request_load_fw(adev);
737−}
738−
739−static const struct amdgpu_smumgr_funcs tonga_smumgr_funcs = {
740− .check_fw_load_finish = tonga_smu_check_fw_load_finish,
741− .request_smu_load_fw = NULL,
742− .request_smu_specific_fw = NULL,
743−};
744−
745−int tonga_smu_init(struct amdgpu_device *adev)
746−{
747− struct tonga_smu_private_data *private;
748− uint32_t image_size = ((sizeof(struct SMU_DRAMData_TOC) / 4096) + 1) * 4096;
749− uint32_t smu_internal_buffer_size = 200*4096;
750− struct amdgpu_bo **toc_buf = &adev->smu.toc_buf;
751− struct amdgpu_bo **smu_buf = &adev->smu.smu_buf;
752− uint64_t mc_addr;
753− void *toc_buf_ptr;
754− void *smu_buf_ptr;
755− int ret;
756−
757− private = kzalloc(sizeof(struct tonga_smu_private_data), GFP_KERNEL);
758− if (NULL == private)
759− return -ENOMEM;
760−
761− /* allocate firmware buffers */
762− if (adev->firmware.smu_load)
763− amdgpu_ucode_init_bo(adev);
764−
765− adev->smu.priv = private;
766− adev->smu.fw_flags = 0;
767−
768− /* Allocate FW image data structure and header buffer */
769− ret = amdgpu_bo_create(adev, image_size, PAGE_SIZE,
770− true, AMDGPU_GEM_DOMAIN_VRAM,
771− AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED,
772− NULL, NULL, toc_buf);
773− if (ret) {
774− DRM_ERROR("Failed to allocate memory for TOC buffer\n");
775− return -ENOMEM;
776− }
777−
778− /* Allocate buffer for SMU internal buffer */
779− ret = amdgpu_bo_create(adev, smu_internal_buffer_size, PAGE_SIZE,
780− true, AMDGPU_GEM_DOMAIN_VRAM,
781− AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED,
782− NULL, NULL, smu_buf);
783− if (ret) {
784− DRM_ERROR("Failed to allocate memory for SMU internal buffer\n");
785− return -ENOMEM;
786− }
787−
788− /* Retrieve GPU address for header buffer and internal buffer */
789− ret = amdgpu_bo_reserve(adev->smu.toc_buf, false);
790− if (ret) {
791− amdgpu_bo_unref(&adev->smu.toc_buf);
792− DRM_ERROR("Failed to reserve the TOC buffer\n");
793− return -EINVAL;
794− }
795−
796− ret = amdgpu_bo_pin(adev->smu.toc_buf, AMDGPU_GEM_DOMAIN_VRAM, &mc_addr);
797− if (ret) {
798− amdgpu_bo_unreserve(adev->smu.toc_buf);
799− amdgpu_bo_unref(&adev->smu.toc_buf);
800− DRM_ERROR("Failed to pin the TOC buffer\n");
801− return -EINVAL;
802− }
803−
804− ret = amdgpu_bo_kmap(*toc_buf, &toc_buf_ptr);
805− if (ret) {
806− amdgpu_bo_unreserve(adev->smu.toc_buf);
807− amdgpu_bo_unref(&adev->smu.toc_buf);
808− DRM_ERROR("Failed to map the TOC buffer\n");
809− return -EINVAL;
810− }
811−
812− amdgpu_bo_unreserve(adev->smu.toc_buf);
813− private->header_addr_low = lower_32_bits(mc_addr);
814− private->header_addr_high = upper_32_bits(mc_addr);
815− private->header = toc_buf_ptr;
816−
817− ret = amdgpu_bo_reserve(adev->smu.smu_buf, false);
818− if (ret) {
819− amdgpu_bo_unref(&adev->smu.smu_buf);
820− amdgpu_bo_unref(&adev->smu.toc_buf);
821− DRM_ERROR("Failed to reserve the SMU internal buffer\n");
822− return -EINVAL;
823− }
824−
825− ret = amdgpu_bo_pin(adev->smu.smu_buf, AMDGPU_GEM_DOMAIN_VRAM, &mc_addr);
826− if (ret) {
827− amdgpu_bo_unreserve(adev->smu.smu_buf);
828− amdgpu_bo_unref(&adev->smu.smu_buf);
829− amdgpu_bo_unref(&adev->smu.toc_buf);
830− DRM_ERROR("Failed to pin the SMU internal buffer\n");
831− return -EINVAL;
832− }
833−
834− ret = amdgpu_bo_kmap(*smu_buf, &smu_buf_ptr);
835− if (ret) {
836− amdgpu_bo_unreserve(adev->smu.smu_buf);
837− amdgpu_bo_unref(&adev->smu.smu_buf);
838− amdgpu_bo_unref(&adev->smu.toc_buf);
839− DRM_ERROR("Failed to map the SMU internal buffer\n");
840− return -EINVAL;
841− }
842−
843− amdgpu_bo_unreserve(adev->smu.smu_buf);
844− private->smu_buffer_addr_low = lower_32_bits(mc_addr);
845− private->smu_buffer_addr_high = upper_32_bits(mc_addr);
846−
847− adev->smu.smumgr_funcs = &tonga_smumgr_funcs;
848−
849− return 0;
850−}
851−
852−int tonga_smu_fini(struct amdgpu_device *adev)
853−{
854− amdgpu_bo_unref(&adev->smu.toc_buf);
855− amdgpu_bo_unref(&adev->smu.smu_buf);
856− kfree(adev->smu.priv);
857− adev->smu.priv = NULL;
858− if (adev->firmware.fw_buf)
859− amdgpu_ucode_fini_bo(adev);
860−
861− return 0;
862−}
drivers/gpu/drm/amd/amdgpu/vi.c+81−10
@@ -79,6 +79,9 @@ · 78 unmodified lines
7979 #endif
8080 #include "dce_virtual.h"
8181
82+MODULE_FIRMWARE("amdgpu/topaz_smc.bin");
83+MODULE_FIRMWARE("amdgpu/tonga_smc.bin");
84+MODULE_FIRMWARE("amdgpu/fiji_smc.bin");
8285 MODULE_FIRMWARE("amdgpu/polaris10_smc.bin");
8386 MODULE_FIRMWARE("amdgpu/polaris10_smc_sk.bin");
8487 MODULE_FIRMWARE("amdgpu/polaris11_smc.bin");
@@ -445,18 +448,21 @@ static bool vi_read_bios_from_rom(struct amdgpu_device *adev, · 360 unmodified lines
445448 return true;
446449 }
447450
448−static u32 vi_get_virtual_caps(struct amdgpu_device *adev)
451+static void vi_detect_hw_virtualization(struct amdgpu_device *adev)
449452 {
450− u32 caps = 0;
451− u32 reg = RREG32(mmBIF_IOV_FUNC_IDENTIFIER);
453+ uint32_t reg = RREG32(mmBIF_IOV_FUNC_IDENTIFIER);
454+ /* bit0: 0 means pf and 1 means vf */
455+ /* bit31: 0 means disable IOV and 1 means enable */
456+ if (reg & 1)
457+ adev->virtualization.virtual_caps |= AMDGPU_SRIOV_CAPS_IS_VF;
452458
453− if (REG_GET_FIELD(reg, BIF_IOV_FUNC_IDENTIFIER, IOV_ENABLE))
454− caps |= AMDGPU_VIRT_CAPS_SRIOV_EN;
459+ if (reg & 0x80000000)
460+ adev->virtualization.virtual_caps |= AMDGPU_SRIOV_CAPS_ENABLE_IOV;
455461
456− if (REG_GET_FIELD(reg, BIF_IOV_FUNC_IDENTIFIER, FUNC_IDENTIFIER))
457− caps |= AMDGPU_VIRT_CAPS_IS_VF;
458−
459− return caps;
462+ if (reg == 0) {
463+ if (is_virtual_machine()) /* passthrough mode exclus sr-iov mode */
464+ adev->virtualization.virtual_caps |= AMDGPU_PASSTHROUGH_MODE;
465+ }
460466 }
461467
462468 static const struct amdgpu_allowed_register_entry tonga_allowed_read_registers[] = {
@@ -1521,13 +1527,13 @@ static const struct amdgpu_asic_funcs vi_asic_funcs = · 1058 unmodified lines
15211527 {
15221528 .read_disabled_bios = &vi_read_disabled_bios,
15231529 .read_bios_from_rom = &vi_read_bios_from_rom,
1530+ .detect_hw_virtualization = vi_detect_hw_virtualization,
15241531 .read_register = &vi_read_register,
15251532 .reset = &vi_asic_reset,
15261533 .set_vga_state = &vi_vga_set_state,
15271534 .get_xclk = &vi_get_xclk,
15281535 .set_uvd_clocks = &vi_set_uvd_clocks,
15291536 .set_vce_clocks = &vi_set_vce_clocks,
1530− .get_virtual_caps = &vi_get_virtual_caps,
15311537 };
15321538
15331539 static int vi_common_early_init(void *handle)
@@ -1657,6 +1663,10 @@ static int vi_common_early_init(void *handle) · 123 unmodified lines
16571663 return -EINVAL;
16581664 }
16591665
1666+ /* in early init stage, vbios code won't work */
1667+ if (adev->asic_funcs->detect_hw_virtualization)
1668+ amdgpu_asic_detect_hw_virtualization(adev);
1669+
16601670 if (amdgpu_smc_load_fw && smc_enabled)
16611671 adev->firmware.smu_load = true;
16621672
@@ -1800,6 +1810,63 @@ static void vi_update_rom_medium_grain_clock_gating(struct amdgpu_device *adev, · 137 unmodified lines
18001810 WREG32_SMC(ixCGTT_ROM_CLK_CTRL0, data);
18011811 }
18021812
1813+static int vi_common_set_clockgating_state_by_smu(void *handle,
1814+ enum amd_clockgating_state state)
1815+{
1816+ uint32_t msg_id, pp_state;
1817+ struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1818+ void *pp_handle = adev->powerplay.pp_handle;
1819+
1820+ if (state == AMD_CG_STATE_UNGATE)
1821+ pp_state = 0;
1822+ else
1823+ pp_state = PP_STATE_CG | PP_STATE_LS;
1824+
1825+ msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1826+ PP_BLOCK_SYS_MC,
1827+ PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS,
1828+ pp_state);
1829+ amd_set_clockgating_by_smu(pp_handle, msg_id);
1830+
1831+ msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1832+ PP_BLOCK_SYS_SDMA,
1833+ PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS,
1834+ pp_state);
1835+ amd_set_clockgating_by_smu(pp_handle, msg_id);
1836+
1837+ msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1838+ PP_BLOCK_SYS_HDP,
1839+ PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS,
1840+ pp_state);
1841+ amd_set_clockgating_by_smu(pp_handle, msg_id);
1842+
1843+ msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1844+ PP_BLOCK_SYS_BIF,
1845+ PP_STATE_SUPPORT_LS,
1846+ pp_state);
1847+ amd_set_clockgating_by_smu(pp_handle, msg_id);
1848+
1849+ msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1850+ PP_BLOCK_SYS_BIF,
1851+ PP_STATE_SUPPORT_CG,
1852+ pp_state);
1853+ amd_set_clockgating_by_smu(pp_handle, msg_id);
1854+
1855+ msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1856+ PP_BLOCK_SYS_DRM,
1857+ PP_STATE_SUPPORT_LS,
1858+ pp_state);
1859+ amd_set_clockgating_by_smu(pp_handle, msg_id);
1860+
1861+ msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
1862+ PP_BLOCK_SYS_ROM,
1863+ PP_STATE_SUPPORT_CG,
1864+ pp_state);
1865+ amd_set_clockgating_by_smu(pp_handle, msg_id);
1866+
1867+ return 0;
1868+}
1869+
18031870 static int vi_common_set_clockgating_state(void *handle,
18041871 enum amd_clockgating_state state)
18051872 {
@@ -1825,6 +1892,10 @@ static int vi_common_set_clockgating_state(void *handle, · 19 unmodified lines
18251892 vi_update_hdp_light_sleep(adev,
18261893 state == AMD_CG_STATE_GATE ? true : false);
18271894 break;
1895+ case CHIP_TONGA:
1896+ case CHIP_POLARIS10:
1897+ case CHIP_POLARIS11:
1898+ vi_common_set_clockgating_state_by_smu(adev, state);
18281899 default:
18291900 break;
18301901 }
drivers/gpu/drm/amd/amdgpu/vid.h+37−0
@@ -373,4 +373,41 @@ · 372 unmodified lines
373373 #define VCE_CMD_WAIT_GE 0x00000106
374374 #define VCE_CMD_UPDATE_PTB 0x00000107
375375 #define VCE_CMD_FLUSH_TLB 0x00000108
376+
377+/* mmPA_SC_RASTER_CONFIG mask */
378+#define RB_MAP_PKR0(x) ((x) << 0)
379+#define RB_MAP_PKR0_MASK (0x3 << 0)
380+#define RB_MAP_PKR1(x) ((x) << 2)
381+#define RB_MAP_PKR1_MASK (0x3 << 2)
382+#define RB_XSEL2(x) ((x) << 4)
383+#define RB_XSEL2_MASK (0x3 << 4)
384+#define RB_XSEL (1 << 6)
385+#define RB_YSEL (1 << 7)
386+#define PKR_MAP(x) ((x) << 8)
387+#define PKR_MAP_MASK (0x3 << 8)
388+#define PKR_XSEL(x) ((x) << 10)
389+#define PKR_XSEL_MASK (0x3 << 10)
390+#define PKR_YSEL(x) ((x) << 12)
391+#define PKR_YSEL_MASK (0x3 << 12)
392+#define SC_MAP(x) ((x) << 16)
393+#define SC_MAP_MASK (0x3 << 16)
394+#define SC_XSEL(x) ((x) << 18)
395+#define SC_XSEL_MASK (0x3 << 18)
396+#define SC_YSEL(x) ((x) << 20)
397+#define SC_YSEL_MASK (0x3 << 20)
398+#define SE_MAP(x) ((x) << 24)
399+#define SE_MAP_MASK (0x3 << 24)
400+#define SE_XSEL(x) ((x) << 26)
401+#define SE_XSEL_MASK (0x3 << 26)
402+#define SE_YSEL(x) ((x) << 28)
403+#define SE_YSEL_MASK (0x3 << 28)
404+
405+/* mmPA_SC_RASTER_CONFIG_1 mask */
406+#define SE_PAIR_MAP(x) ((x) << 0)
407+#define SE_PAIR_MAP_MASK (0x3 << 0)
408+#define SE_PAIR_XSEL(x) ((x) << 2)
409+#define SE_PAIR_XSEL_MASK (0x3 << 2)
410+#define SE_PAIR_YSEL(x) ((x) << 4)
411+#define SE_PAIR_YSEL_MASK (0x3 << 4)
412+
376413 #endif
drivers/gpu/drm/amd/include/asic_reg/si/sid.h+35−0
@@ -1398,10 +1398,45 @@ · 1397 unmodified lines
13981398 #define DB_DEPTH_INFO 0xA00F
13991399
14001400 #define PA_SC_RASTER_CONFIG 0xA0D4
1401+# define RB_MAP_PKR0(x) ((x) << 0)
1402+# define RB_MAP_PKR0_MASK (0x3 << 0)
1403+# define RB_MAP_PKR1(x) ((x) << 2)
1404+# define RB_MAP_PKR1_MASK (0x3 << 2)
14011405 # define RASTER_CONFIG_RB_MAP_0 0
14021406 # define RASTER_CONFIG_RB_MAP_1 1
14031407 # define RASTER_CONFIG_RB_MAP_2 2
14041408 # define RASTER_CONFIG_RB_MAP_3 3
1409+# define RB_XSEL2(x) ((x) << 4)
1410+# define RB_XSEL2_MASK (0x3 << 4)
1411+# define RB_XSEL (1 << 6)
1412+# define RB_YSEL (1 << 7)
1413+# define PKR_MAP(x) ((x) << 8)
1414+# define PKR_MAP_MASK (0x3 << 8)
1415+# define RASTER_CONFIG_PKR_MAP_0 0
1416+# define RASTER_CONFIG_PKR_MAP_1 1
1417+# define RASTER_CONFIG_PKR_MAP_2 2
1418+# define RASTER_CONFIG_PKR_MAP_3 3
1419+# define PKR_XSEL(x) ((x) << 10)
1420+# define PKR_XSEL_MASK (0x3 << 10)
1421+# define PKR_YSEL(x) ((x) << 12)
1422+# define PKR_YSEL_MASK (0x3 << 12)
1423+# define SC_MAP(x) ((x) << 16)
1424+# define SC_MAP_MASK (0x3 << 16)
1425+# define SC_XSEL(x) ((x) << 18)
1426+# define SC_XSEL_MASK (0x3 << 18)
1427+# define SC_YSEL(x) ((x) << 20)
1428+# define SC_YSEL_MASK (0x3 << 20)
1429+# define SE_MAP(x) ((x) << 24)
1430+# define SE_MAP_MASK (0x3 << 24)
1431+# define RASTER_CONFIG_SE_MAP_0 0
1432+# define RASTER_CONFIG_SE_MAP_1 1
1433+# define RASTER_CONFIG_SE_MAP_2 2
1434+# define RASTER_CONFIG_SE_MAP_3 3
1435+# define SE_XSEL(x) ((x) << 26)
1436+# define SE_XSEL_MASK (0x3 << 26)
1437+# define SE_YSEL(x) ((x) << 28)
1438+# define SE_YSEL_MASK (0x3 << 28)
1439+
14051440
14061441 #define VGT_EVENT_INITIATOR 0xA2A4
14071442 # define SAMPLE_STREAMOUTSTATS1 (1 << 0)
drivers/gpu/drm/amd/include/cgs_common.h+1−0
@@ -161,6 +161,7 @@ struct cgs_clock_limits { · 160 unmodified lines
161161 */
162162 struct cgs_firmware_info {
163163 uint16_t version;
164+ uint16_t fw_version;
164165 uint16_t feature_version;
165166 uint32_t image_size;
166167 uint64_t mc_addr;
drivers/gpu/drm/amd/powerplay/amd_powerplay.c+23−97
@@ -191,11 +191,9 @@ static int pp_sw_reset(void *handle) · 190 unmodified lines
191191 }
192192
193193
194−static int pp_set_clockgating_state(void *handle,
195− enum amd_clockgating_state state)
194+int amd_set_clockgating_by_smu(void *handle, uint32_t msg_id)
196195 {
197196 struct pp_hwmgr *hwmgr;
198− uint32_t msg_id, pp_state;
199197
200198 if (handle == NULL)
201199 return -EINVAL;
@@ -209,76 +207,7 @@ static int pp_set_clockgating_state(void *handle, · 7 unmodified lines
209207 return 0;
210208 }
211209
212− if (state == AMD_CG_STATE_UNGATE)
213− pp_state = 0;
214− else
215− pp_state = PP_STATE_CG | PP_STATE_LS;
216−
217− /* Enable/disable GFX blocks clock gating through SMU */
218− msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
219− PP_BLOCK_GFX_CG,
220− PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS,
221− pp_state);
222− hwmgr->hwmgr_func->update_clock_gatings(hwmgr, &msg_id);
223− msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
224− PP_BLOCK_GFX_3D,
225− PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS,
226− pp_state);
227− hwmgr->hwmgr_func->update_clock_gatings(hwmgr, &msg_id);
228− msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
229− PP_BLOCK_GFX_RLC,
230− PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS,
231− pp_state);
232− hwmgr->hwmgr_func->update_clock_gatings(hwmgr, &msg_id);
233− msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
234− PP_BLOCK_GFX_CP,
235− PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS,
236− pp_state);
237− hwmgr->hwmgr_func->update_clock_gatings(hwmgr, &msg_id);
238− msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
239− PP_BLOCK_GFX_MG,
240− PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS,
241− pp_state);
242− hwmgr->hwmgr_func->update_clock_gatings(hwmgr, &msg_id);
243−
244− /* Enable/disable System blocks clock gating through SMU */
245− msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
246− PP_BLOCK_SYS_BIF,
247− PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS,
248− pp_state);
249− hwmgr->hwmgr_func->update_clock_gatings(hwmgr, &msg_id);
250− msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
251− PP_BLOCK_SYS_BIF,
252− PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS,
253− pp_state);
254− hwmgr->hwmgr_func->update_clock_gatings(hwmgr, &msg_id);
255− msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
256− PP_BLOCK_SYS_MC,
257− PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS,
258− pp_state);
259− hwmgr->hwmgr_func->update_clock_gatings(hwmgr, &msg_id);
260− msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
261− PP_BLOCK_SYS_ROM,
262− PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS,
263− pp_state);
264− hwmgr->hwmgr_func->update_clock_gatings(hwmgr, &msg_id);
265− msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
266− PP_BLOCK_SYS_DRM,
267− PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS,
268− pp_state);
269− hwmgr->hwmgr_func->update_clock_gatings(hwmgr, &msg_id);
270− msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
271− PP_BLOCK_SYS_HDP,
272− PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS,
273− pp_state);
274− hwmgr->hwmgr_func->update_clock_gatings(hwmgr, &msg_id);
275− msg_id = PP_CG_MSG_ID(PP_GROUP_SYS,
276− PP_BLOCK_SYS_SDMA,
277− PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS,
278− pp_state);
279− hwmgr->hwmgr_func->update_clock_gatings(hwmgr, &msg_id);
280−
281− return 0;
210+ return hwmgr->hwmgr_func->update_clock_gatings(hwmgr, &msg_id);
282211 }
283212
284213 static int pp_set_powergating_state(void *handle,
@@ -362,7 +291,7 @@ const struct amd_ip_funcs pp_ip_funcs = { · 77 unmodified lines
362291 .is_idle = pp_is_idle,
363292 .wait_for_idle = pp_wait_for_idle,
364293 .soft_reset = pp_sw_reset,
365− .set_clockgating_state = pp_set_clockgating_state,
294+ .set_clockgating_state = NULL,
366295 .set_powergating_state = pp_set_powergating_state,
367296 };
368297
@@ -576,28 +505,6 @@ enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle) · 207 unmodified lines
576505 }
577506 }
578507
579−static void
580−pp_debugfs_print_current_performance_level(void *handle,
581− struct seq_file *m)
582−{
583− struct pp_hwmgr *hwmgr;
584−
585− if (handle == NULL)
586− return;
587−
588− hwmgr = ((struct pp_instance *)handle)->hwmgr;
589−
590− if (hwmgr == NULL || hwmgr->hwmgr_func == NULL)
591− return;
592−
593− if (hwmgr->hwmgr_func->print_current_perforce_level == NULL) {
594− printk(KERN_INFO "%s was not implemented.\n", __func__);
595− return;
596− }
597−
598− hwmgr->hwmgr_func->print_current_perforce_level(hwmgr, m);
599−}
600−
601508 static int pp_dpm_set_fan_control_mode(void *handle, uint32_t mode)
602509 {
603510 struct pp_hwmgr *hwmgr;
@@ -894,6 +801,25 @@ static int pp_dpm_set_mclk_od(void *handle, uint32_t value) · 290 unmodified lines
894801 return hwmgr->hwmgr_func->set_mclk_od(hwmgr, value);
895802 }
896803
804+static int pp_dpm_read_sensor(void *handle, int idx, int32_t *value)
805+{
806+ struct pp_hwmgr *hwmgr;
807+
808+ if (!handle)
809+ return -EINVAL;
810+
811+ hwmgr = ((struct pp_instance *)handle)->hwmgr;
812+
813+ PP_CHECK_HW(hwmgr);
814+
815+ if (hwmgr->hwmgr_func->read_sensor == NULL) {
816+ printk(KERN_INFO "%s was not implemented.\n", __func__);
817+ return 0;
818+ }
819+
820+ return hwmgr->hwmgr_func->read_sensor(hwmgr, idx, value);
821+}
822+
897823 const struct amd_powerplay_funcs pp_dpm_funcs = {
898824 .get_temperature = pp_dpm_get_temperature,
899825 .load_firmware = pp_dpm_load_fw,
@@ -906,7 +832,6 @@ const struct amd_powerplay_funcs pp_dpm_funcs = { · 6 unmodified lines
906832 .powergate_vce = pp_dpm_powergate_vce,
907833 .powergate_uvd = pp_dpm_powergate_uvd,
908834 .dispatch_tasks = pp_dpm_dispatch_tasks,
909− .print_current_performance_level = pp_debugfs_print_current_performance_level,
910835 .set_fan_control_mode = pp_dpm_set_fan_control_mode,
911836 .get_fan_control_mode = pp_dpm_get_fan_control_mode,
912837 .set_fan_speed_percent = pp_dpm_set_fan_speed_percent,
@@ -920,6 +845,7 @@ const struct amd_powerplay_funcs pp_dpm_funcs = { · 7 unmodified lines
920845 .set_sclk_od = pp_dpm_set_sclk_od,
921846 .get_mclk_od = pp_dpm_get_mclk_od,
922847 .set_mclk_od = pp_dpm_set_mclk_od,
848+ .read_sensor = pp_dpm_read_sensor,
923849 };
924850
925851 static int amd_pp_instance_init(struct amd_pp_init *pp_init,
drivers/gpu/drm/amd/powerplay/eventmgr/eventactionchains.c+2−0
@@ -262,6 +262,8 @@ static const pem_event_action * const display_config_change_event[] = { · 261 unmodified lines
262262 unblock_adjust_power_state_tasks,
263263 set_cpu_power_state,
264264 notify_hw_power_source_tasks,
265+ get_2d_performance_state_tasks,
266+ set_performance_state_tasks,
265267 /* updateDALConfigurationTasks,
266268 variBrightDisplayConfigurationChangeTasks, */
267269 adjust_power_state_tasks,
drivers/gpu/drm/amd/powerplay/eventmgr/psm.c+2−1
@@ -101,11 +101,12 @@ int psm_adjust_power_state_dynamic(struct pp_eventmgr *eventmgr, bool skip) · 100 unmodified lines
101101 if (requested == NULL)
102102 return 0;
103103
104+ phm_apply_state_adjust_rules(hwmgr, requested, pcurrent);
105+
104106 if (pcurrent == NULL || (0 != phm_check_states_equal(hwmgr, &pcurrent->hardware, &requested->hardware, &equal)))
105107 equal = false;
106108
107109 if (!equal || phm_check_smc_update_required_for_display_configuration(hwmgr)) {
108− phm_apply_state_adjust_rules(hwmgr, requested, pcurrent);
109110 phm_set_power_state(hwmgr, &pcurrent->hardware, &requested->hardware);
110111 memcpy(hwmgr->current_ps, hwmgr->request_ps, hwmgr->ps_size);
111112 }
drivers/gpu/drm/amd/powerplay/hwmgr/Makefile+6−10
@@ -3,16 +3,12 @@ · 2 unmodified lines
33 # It provides the hardware management services for the driver.
44
55 HARDWARE_MGR = hwmgr.o processpptables.o functiontables.o \
6− hardwaremanager.o pp_acpi.o cz_hwmgr.o \
7− cz_clockpowergating.o tonga_powertune.o\
8− process_pptables_v1_0.o ppatomctrl.o \
9− tonga_hwmgr.o pppcielanes.o tonga_thermal.o\
10− fiji_powertune.o fiji_hwmgr.o tonga_clockpowergating.o \
11− fiji_clockpowergating.o fiji_thermal.o \
12− polaris10_hwmgr.o polaris10_powertune.o polaris10_thermal.o \
13− polaris10_clockpowergating.o iceland_hwmgr.o \
14− iceland_clockpowergating.o iceland_thermal.o \
15− iceland_powertune.o
6+ hardwaremanager.o pp_acpi.o cz_hwmgr.o \
7+ cz_clockpowergating.o pppcielanes.o\
8+ process_pptables_v1_0.o ppatomctrl.o \
9+ smu7_hwmgr.o smu7_powertune.o smu7_thermal.o \
10+ smu7_clockpowergating.o
11+
1612
1713 AMD_PP_HWMGR = $(addprefix $(AMD_PP_PATH)/hwmgr/,$(HARDWARE_MGR))
1814
drivers/gpu/drm/amd/powerplay/hwmgr/cz_hwmgr.c+102−73
@@ -1538,78 +1538,6 @@ int cz_get_power_state_size(struct pp_hwmgr *hwmgr) · 1537 unmodified lines
15381538 return sizeof(struct cz_power_state);
15391539 }
15401540
1541−static void
1542−cz_print_current_perforce_level(struct pp_hwmgr *hwmgr, struct seq_file *m)
1543−{
1544− struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
1545−
1546− struct phm_clock_voltage_dependency_table *table =
1547− hwmgr->dyn_state.vddc_dependency_on_sclk;
1548−
1549− struct phm_vce_clock_voltage_dependency_table *vce_table =
1550− hwmgr->dyn_state.vce_clock_voltage_dependency_table;
1551−
1552− struct phm_uvd_clock_voltage_dependency_table *uvd_table =
1553− hwmgr->dyn_state.uvd_clock_voltage_dependency_table;
1554−
1555− uint32_t sclk_index = PHM_GET_FIELD(cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixTARGET_AND_CURRENT_PROFILE_INDEX),
1556− TARGET_AND_CURRENT_PROFILE_INDEX, CURR_SCLK_INDEX);
1557− uint32_t uvd_index = PHM_GET_FIELD(cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixTARGET_AND_CURRENT_PROFILE_INDEX_2),
1558− TARGET_AND_CURRENT_PROFILE_INDEX_2, CURR_UVD_INDEX);
1559− uint32_t vce_index = PHM_GET_FIELD(cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixTARGET_AND_CURRENT_PROFILE_INDEX_2),
1560− TARGET_AND_CURRENT_PROFILE_INDEX_2, CURR_VCE_INDEX);
1561−
1562− uint32_t sclk, vclk, dclk, ecclk, tmp, activity_percent;
1563− uint16_t vddnb, vddgfx;
1564− int result;
1565−
1566− if (sclk_index >= NUM_SCLK_LEVELS) {
1567− seq_printf(m, "\n invalid sclk dpm profile %d\n", sclk_index);
1568− } else {
1569− sclk = table->entries[sclk_index].clk;
1570− seq_printf(m, "\n index: %u sclk: %u MHz\n", sclk_index, sclk/100);
1571− }
1572−
1573− tmp = (cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixSMUSVI_NB_CURRENTVID) &
1574− CURRENT_NB_VID_MASK) >> CURRENT_NB_VID__SHIFT;
1575− vddnb = cz_convert_8Bit_index_to_voltage(hwmgr, tmp);
1576− tmp = (cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixSMUSVI_GFX_CURRENTVID) &
1577− CURRENT_GFX_VID_MASK) >> CURRENT_GFX_VID__SHIFT;
1578− vddgfx = cz_convert_8Bit_index_to_voltage(hwmgr, (u16)tmp);
1579− seq_printf(m, "\n vddnb: %u vddgfx: %u\n", vddnb, vddgfx);
1580−
1581− seq_printf(m, "\n uvd %sabled\n", cz_hwmgr->uvd_power_gated ? "dis" : "en");
1582− if (!cz_hwmgr->uvd_power_gated) {
1583− if (uvd_index >= CZ_MAX_HARDWARE_POWERLEVELS) {
1584− seq_printf(m, "\n invalid uvd dpm level %d\n", uvd_index);
1585− } else {
1586− vclk = uvd_table->entries[uvd_index].vclk;
1587− dclk = uvd_table->entries[uvd_index].dclk;
1588− seq_printf(m, "\n index: %u uvd vclk: %u MHz dclk: %u MHz\n", uvd_index, vclk/100, dclk/100);
1589− }
1590− }
1591−
1592− seq_printf(m, "\n vce %sabled\n", cz_hwmgr->vce_power_gated ? "dis" : "en");
1593− if (!cz_hwmgr->vce_power_gated) {
1594− if (vce_index >= CZ_MAX_HARDWARE_POWERLEVELS) {
1595− seq_printf(m, "\n invalid vce dpm level %d\n", vce_index);
1596− } else {
1597− ecclk = vce_table->entries[vce_index].ecclk;
1598− seq_printf(m, "\n index: %u vce ecclk: %u MHz\n", vce_index, ecclk/100);
1599− }
1600− }
1601−
1602− result = smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_GetAverageGraphicsActivity);
1603− if (0 == result) {
1604− activity_percent = cgs_read_register(hwmgr->device, mmSMU_MP1_SRBM2P_ARG_0);
1605− activity_percent = activity_percent > 100 ? 100 : activity_percent;
1606− } else {
1607− activity_percent = 50;
1608− }
1609−
1610− seq_printf(m, "\n [GPU load]: %u %%\n\n", activity_percent);
1611−}
1612−
16131541 static void cz_hw_print_display_cfg(
16141542 const struct cc6_settings *cc6_settings)
16151543 {
@@ -1857,6 +1785,107 @@ static int cz_get_max_high_clocks(struct pp_hwmgr *hwmgr, struct amd_pp_simple_c · 241 unmodified lines
18571785 return 0;
18581786 }
18591787
1788+static int cz_read_sensor(struct pp_hwmgr *hwmgr, int idx, int32_t *value)
1789+{
1790+ struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
1791+
1792+ struct phm_clock_voltage_dependency_table *table =
1793+ hwmgr->dyn_state.vddc_dependency_on_sclk;
1794+
1795+ struct phm_vce_clock_voltage_dependency_table *vce_table =
1796+ hwmgr->dyn_state.vce_clock_voltage_dependency_table;
1797+
1798+ struct phm_uvd_clock_voltage_dependency_table *uvd_table =
1799+ hwmgr->dyn_state.uvd_clock_voltage_dependency_table;
1800+
1801+ uint32_t sclk_index = PHM_GET_FIELD(cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixTARGET_AND_CURRENT_PROFILE_INDEX),
1802+ TARGET_AND_CURRENT_PROFILE_INDEX, CURR_SCLK_INDEX);
1803+ uint32_t uvd_index = PHM_GET_FIELD(cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixTARGET_AND_CURRENT_PROFILE_INDEX_2),
1804+ TARGET_AND_CURRENT_PROFILE_INDEX_2, CURR_UVD_INDEX);
1805+ uint32_t vce_index = PHM_GET_FIELD(cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixTARGET_AND_CURRENT_PROFILE_INDEX_2),
1806+ TARGET_AND_CURRENT_PROFILE_INDEX_2, CURR_VCE_INDEX);
1807+
1808+ uint32_t sclk, vclk, dclk, ecclk, tmp, activity_percent;
1809+ uint16_t vddnb, vddgfx;
1810+ int result;
1811+
1812+ switch (idx) {
1813+ case AMDGPU_PP_SENSOR_GFX_SCLK:
1814+ if (sclk_index < NUM_SCLK_LEVELS) {
1815+ sclk = table->entries[sclk_index].clk;
1816+ *value = sclk;
1817+ return 0;
1818+ }
1819+ return -EINVAL;
1820+ case AMDGPU_PP_SENSOR_VDDNB:
1821+ tmp = (cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixSMUSVI_NB_CURRENTVID) &
1822+ CURRENT_NB_VID_MASK) >> CURRENT_NB_VID__SHIFT;
1823+ vddnb = cz_convert_8Bit_index_to_voltage(hwmgr, tmp);
1824+ *value = vddnb;
1825+ return 0;
1826+ case AMDGPU_PP_SENSOR_VDDGFX:
1827+ tmp = (cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixSMUSVI_GFX_CURRENTVID) &
1828+ CURRENT_GFX_VID_MASK) >> CURRENT_GFX_VID__SHIFT;
1829+ vddgfx = cz_convert_8Bit_index_to_voltage(hwmgr, (u16)tmp);
1830+ *value = vddgfx;
1831+ return 0;
1832+ case AMDGPU_PP_SENSOR_UVD_VCLK:
1833+ if (!cz_hwmgr->uvd_power_gated) {
1834+ if (uvd_index >= CZ_MAX_HARDWARE_POWERLEVELS) {
1835+ return -EINVAL;
1836+ } else {
1837+ vclk = uvd_table->entries[uvd_index].vclk;
1838+ *value = vclk;
1839+ return 0;
1840+ }
1841+ }
1842+ *value = 0;
1843+ return 0;
1844+ case AMDGPU_PP_SENSOR_UVD_DCLK:
1845+ if (!cz_hwmgr->uvd_power_gated) {
1846+ if (uvd_index >= CZ_MAX_HARDWARE_POWERLEVELS) {
1847+ return -EINVAL;
1848+ } else {
1849+ dclk = uvd_table->entries[uvd_index].dclk;
1850+ *value = dclk;
1851+ return 0;
1852+ }
1853+ }
1854+ *value = 0;
1855+ return 0;
1856+ case AMDGPU_PP_SENSOR_VCE_ECCLK:
1857+ if (!cz_hwmgr->vce_power_gated) {
1858+ if (vce_index >= CZ_MAX_HARDWARE_POWERLEVELS) {
1859+ return -EINVAL;
1860+ } else {
1861+ ecclk = vce_table->entries[vce_index].ecclk;
1862+ *value = ecclk;
1863+ return 0;
1864+ }
1865+ }
1866+ *value = 0;
1867+ return 0;
1868+ case AMDGPU_PP_SENSOR_GPU_LOAD:
1869+ result = smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_GetAverageGraphicsActivity);
1870+ if (0 == result) {
1871+ activity_percent = cgs_read_register(hwmgr->device, mmSMU_MP1_SRBM2P_ARG_0);
1872+ activity_percent = activity_percent > 100 ? 100 : activity_percent;
1873+ } else {
1874+ activity_percent = 50;
1875+ }
1876+ *value = activity_percent;
1877+ return 0;
1878+ case AMDGPU_PP_SENSOR_UVD_POWER:
1879+ *value = cz_hwmgr->uvd_power_gated ? 0 : 1;
1880+ return 0;
1881+ case AMDGPU_PP_SENSOR_VCE_POWER:
1882+ *value = cz_hwmgr->vce_power_gated ? 0 : 1;
1883+ return 0;
1884+ default:
1885+ return -EINVAL;
1886+ }
1887+}
1888+
18601889 static const struct pp_hwmgr_func cz_hwmgr_funcs = {
18611890 .backend_init = cz_hwmgr_backend_init,
18621891 .backend_fini = cz_hwmgr_backend_fini,
@@ -1872,7 +1901,6 @@ static const struct pp_hwmgr_func cz_hwmgr_funcs = { · 9 unmodified lines
18721901 .patch_boot_state = cz_dpm_patch_boot_state,
18731902 .get_pp_table_entry = cz_dpm_get_pp_table_entry,
18741903 .get_num_of_pp_table_entries = cz_dpm_get_num_of_pp_table_entries,
1875− .print_current_perforce_level = cz_print_current_perforce_level,
18761904 .set_cpu_power_state = cz_set_cpu_power_state,
18771905 .store_cc6_data = cz_store_cc6_data,
18781906 .force_clock_level = cz_force_clock_level,
@@ -1882,6 +1910,7 @@ static const struct pp_hwmgr_func cz_hwmgr_funcs = { · 3 unmodified lines
18821910 .get_current_shallow_sleep_clocks = cz_get_current_shallow_sleep_clocks,
18831911 .get_clock_by_type = cz_get_clock_by_type,
18841912 .get_max_high_clocks = cz_get_max_high_clocks,
1913+ .read_sensor = cz_read_sensor,
18851914 };
18861915
18871916 int cz_hwmgr_init(struct pp_hwmgr *hwmgr)
drivers/gpu/drm/amd/powerplay/hwmgr/fiji_clockpowergating.c+0−121
@@ -1,121 +0,0 @@
1−/*
2− * Copyright 2015 Advanced Micro Devices, Inc.
3− *
4− * Permission is hereby granted, free of charge, to any person obtaining a
5− * copy of this software and associated documentation files (the "Software"),
6− * to deal in the Software without restriction, including without limitation
7− * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8− * and/or sell copies of the Software, and to permit persons to whom the
9− * Software is furnished to do so, subject to the following conditions:
10− *
11− * The above copyright notice and this permission notice shall be included in
12− * all copies or substantial portions of the Software.
13− *
14− * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15− * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16− * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17− * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18− * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19− * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20− * OTHER DEALINGS IN THE SOFTWARE.
21− *
22− */
23−
24−#include "hwmgr.h"
25−#include "fiji_clockpowergating.h"
26−#include "fiji_ppsmc.h"
27−#include "fiji_hwmgr.h"
28−
29−int fiji_phm_disable_clock_power_gating(struct pp_hwmgr *hwmgr)
30−{
31− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
32−
33− data->uvd_power_gated = false;
34− data->vce_power_gated = false;
35− data->samu_power_gated = false;
36− data->acp_power_gated = false;
37−
38− return 0;
39−}
40−
41−int fiji_phm_powergate_uvd(struct pp_hwmgr *hwmgr, bool bgate)
42−{
43− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
44−
45− if (data->uvd_power_gated == bgate)
46− return 0;
47−
48− data->uvd_power_gated = bgate;
49−
50− if (bgate) {
51− cgs_set_clockgating_state(hwmgr->device,
52− AMD_IP_BLOCK_TYPE_UVD,
53− AMD_CG_STATE_GATE);
54− fiji_update_uvd_dpm(hwmgr, true);
55− } else {
56− fiji_update_uvd_dpm(hwmgr, false);
57− cgs_set_clockgating_state(hwmgr->device,
58− AMD_IP_BLOCK_TYPE_UVD,
59− AMD_CG_STATE_UNGATE);
60− }
61−
62− return 0;
63−}
64−
65−int fiji_phm_powergate_vce(struct pp_hwmgr *hwmgr, bool bgate)
66−{
67− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
68− struct phm_set_power_state_input states;
69− const struct pp_power_state *pcurrent;
70− struct pp_power_state *requested;
71−
72− if (data->vce_power_gated == bgate)
73− return 0;
74−
75− data->vce_power_gated = bgate;
76−
77− pcurrent = hwmgr->current_ps;
78− requested = hwmgr->request_ps;
79−
80− states.pcurrent_state = &(pcurrent->hardware);
81− states.pnew_state = &(requested->hardware);
82−
83− fiji_update_vce_dpm(hwmgr, &states);
84− fiji_enable_disable_vce_dpm(hwmgr, !bgate);
85−
86− return 0;
87−}
88−
89−int fiji_phm_powergate_samu(struct pp_hwmgr *hwmgr, bool bgate)
90−{
91− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
92−
93− if (data->samu_power_gated == bgate)
94− return 0;
95−
96− data->samu_power_gated = bgate;
97−
98− if (bgate)
99− fiji_update_samu_dpm(hwmgr, true);
100− else
101− fiji_update_samu_dpm(hwmgr, false);
102−
103− return 0;
104−}
105−
106−int fiji_phm_powergate_acp(struct pp_hwmgr *hwmgr, bool bgate)
107−{
108− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
109−
110− if (data->acp_power_gated == bgate)
111− return 0;
112−
113− data->acp_power_gated = bgate;
114−
115− if (bgate)
116− fiji_update_acp_dpm(hwmgr, true);
117− else
118− fiji_update_acp_dpm(hwmgr, false);
119−
120− return 0;
121−}
drivers/gpu/drm/amd/powerplay/hwmgr/fiji_dyn_defaults.h+0−105
@@ -1,105 +0,0 @@
1−/*
2− * Copyright 2015 Advanced Micro Devices, Inc.
3− *
4− * Permission is hereby granted, free of charge, to any person obtaining a
5− * copy of this software and associated documentation files (the "Software"),
6− * to deal in the Software without restriction, including without limitation
7− * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8− * and/or sell copies of the Software, and to permit persons to whom the
9− * Software is furnished to do so, subject to the following conditions:
10− *
11− * The above copyright notice and this permission notice shall be included in
12− * all copies or substantial portions of the Software.
13− *
14− * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15− * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16− * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17− * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18− * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19− * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20− * OTHER DEALINGS IN THE SOFTWARE.
21− *
22− */
23−
24−#ifndef FIJI_DYN_DEFAULTS_H
25−#define FIJI_DYN_DEFAULTS_H
26−
27−/** \file
28−* Volcanic Islands Dynamic default parameters.
29−*/
30−
31−enum FIJIdpm_TrendDetection
32−{
33− FIJIAdpm_TrendDetection_AUTO,
34− FIJIAdpm_TrendDetection_UP,
35− FIJIAdpm_TrendDetection_DOWN
36−};
37−typedef enum FIJIdpm_TrendDetection FIJIdpm_TrendDetection;
38−
39−/* We need to fill in the default values!!!!!!!!!!!!!!!!!!!!!!! */
40−
41−/* Bit vector representing same fields as hardware register. */
42−#define PPFIJI_VOTINGRIGHTSCLIENTS_DFLT0 0x3FFFC102 /* CP_Gfx_busy ????
43− * HDP_busy
44− * IH_busy
45− * UVD_busy
46− * VCE_busy
47− * ACP_busy
48− * SAMU_busy
49− * SDMA enabled */
50−#define PPFIJI_VOTINGRIGHTSCLIENTS_DFLT1 0x000400 /* FE_Gfx_busy - Intended for primary usage. Rest are for flexibility. ????
51− * SH_Gfx_busy
52− * RB_Gfx_busy
53− * VCE_busy */
54−
55−#define PPFIJI_VOTINGRIGHTSCLIENTS_DFLT2 0xC00080 /* SH_Gfx_busy - Intended for primary usage. Rest are for flexibility.
56− * FE_Gfx_busy
57− * RB_Gfx_busy
58− * ACP_busy */
59−
60−#define PPFIJI_VOTINGRIGHTSCLIENTS_DFLT3 0xC00200 /* RB_Gfx_busy - Intended for primary usage. Rest are for flexibility.
61− * FE_Gfx_busy
62− * SH_Gfx_busy
63− * UVD_busy */
64−
65−#define PPFIJI_VOTINGRIGHTSCLIENTS_DFLT4 0xC01680 /* UVD_busy
66− * VCE_busy
67− * ACP_busy
68− * SAMU_busy */
69−
70−#define PPFIJI_VOTINGRIGHTSCLIENTS_DFLT5 0xC00033 /* GFX, HDP */
71−#define PPFIJI_VOTINGRIGHTSCLIENTS_DFLT6 0xC00033 /* GFX, HDP */
72−#define PPFIJI_VOTINGRIGHTSCLIENTS_DFLT7 0x3FFFC000 /* GFX, HDP */
73−
74−
75−/* thermal protection counter (units). */
76−#define PPFIJI_THERMALPROTECTCOUNTER_DFLT 0x200 /* ~19us */
77−
78−/* static screen threshold unit */
79−#define PPFIJI_STATICSCREENTHRESHOLDUNIT_DFLT 0
80−
81−/* static screen threshold */
82−#define PPFIJI_STATICSCREENTHRESHOLD_DFLT 0x00C8
83−
84−/* gfx idle clock stop threshold */
85−#define PPFIJI_GFXIDLECLOCKSTOPTHRESHOLD_DFLT 0x200 /* ~19us with static screen threshold unit of 0 */
86−
87−/* Fixed reference divider to use when building baby stepping tables. */
88−#define PPFIJI_REFERENCEDIVIDER_DFLT 4
89−
90−/* ULV voltage change delay time
91− * Used to be delay_vreg in N.I. split for S.I.
92− * Using N.I. delay_vreg value as default
93− * ReferenceClock = 2700
94− * VoltageResponseTime = 1000
95− * VDDCDelayTime = (VoltageResponseTime * ReferenceClock) / 1600 = 1687
96− */
97−#define PPFIJI_ULVVOLTAGECHANGEDELAY_DFLT 1687
98−
99−#define PPFIJI_CGULVPARAMETER_DFLT 0x00040035
100−#define PPFIJI_CGULVCONTROL_DFLT 0x00007450
101−#define PPFIJI_TARGETACTIVITY_DFLT 30 /* 30%*/
102−#define PPFIJI_MCLK_TARGETACTIVITY_DFLT 10 /* 10% */
103−
104−#endif
105−
drivers/gpu/drm/amd/powerplay/hwmgr/fiji_hwmgr.c+0−5600
@@ -1,5600 +0,0 @@
1−/*
2− * Copyright 2015 Advanced Micro Devices, Inc.
3− *
4− * Permission is hereby granted, free of charge, to any person obtaining a
5− * copy of this software and associated documentation files (the "Software"),
6− * to deal in the Software without restriction, including without limitation
7− * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8− * and/or sell copies of the Software, and to permit persons to whom the
9− * Software is furnished to do so, subject to the following conditions:
10− *
11− * The above copyright notice and this permission notice shall be included in
12− * all copies or substantial portions of the Software.
13− *
14− * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15− * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16− * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17− * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18− * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19− * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20− * OTHER DEALINGS IN THE SOFTWARE.
21− *
22− */
23−#include <linux/module.h>
24−#include <linux/slab.h>
25−#include "linux/delay.h"
26−
27−#include "hwmgr.h"
28−#include "fiji_smumgr.h"
29−#include "atombios.h"
30−#include "hardwaremanager.h"
31−#include "ppatomctrl.h"
32−#include "atombios.h"
33−#include "cgs_common.h"
34−#include "fiji_dyn_defaults.h"
35−#include "fiji_powertune.h"
36−#include "smu73.h"
37−#include "smu/smu_7_1_3_d.h"
38−#include "smu/smu_7_1_3_sh_mask.h"
39−#include "gmc/gmc_8_1_d.h"
40−#include "gmc/gmc_8_1_sh_mask.h"
41−#include "bif/bif_5_0_d.h"
42−#include "bif/bif_5_0_sh_mask.h"
43−#include "dce/dce_10_0_d.h"
44−#include "dce/dce_10_0_sh_mask.h"
45−#include "pppcielanes.h"
46−#include "fiji_hwmgr.h"
47−#include "process_pptables_v1_0.h"
48−#include "pptable_v1_0.h"
49−#include "pp_debug.h"
50−#include "pp_acpi.h"
51−#include "amd_pcie_helpers.h"
52−#include "cgs_linux.h"
53−#include "ppinterrupt.h"
54−
55−#include "fiji_clockpowergating.h"
56−#include "fiji_thermal.h"
57−
58−#define VOLTAGE_SCALE 4
59−#define SMC_RAM_END 0x40000
60−#define VDDC_VDDCI_DELTA 300
61−
62−#define MC_SEQ_MISC0_GDDR5_SHIFT 28
63−#define MC_SEQ_MISC0_GDDR5_MASK 0xf0000000
64−#define MC_SEQ_MISC0_GDDR5_VALUE 5
65−
66−#define MC_CG_ARB_FREQ_F0 0x0a /* boot-up default */
67−#define MC_CG_ARB_FREQ_F1 0x0b
68−#define MC_CG_ARB_FREQ_F2 0x0c
69−#define MC_CG_ARB_FREQ_F3 0x0d
70−
71−/* From smc_reg.h */
72−#define SMC_CG_IND_START 0xc0030000
73−#define SMC_CG_IND_END 0xc0040000 /* First byte after SMC_CG_IND */
74−
75−#define VOLTAGE_SCALE 4
76−#define VOLTAGE_VID_OFFSET_SCALE1 625
77−#define VOLTAGE_VID_OFFSET_SCALE2 100
78−
79−#define VDDC_VDDCI_DELTA 300
80−
81−#define ixSWRST_COMMAND_1 0x1400103
82−#define MC_SEQ_CNTL__CAC_EN_MASK 0x40000000
83−
84−/** Values for the CG_THERMAL_CTRL::DPM_EVENT_SRC field. */
85−enum DPM_EVENT_SRC {
86− DPM_EVENT_SRC_ANALOG = 0, /* Internal analog trip point */
87− DPM_EVENT_SRC_EXTERNAL = 1, /* External (GPIO 17) signal */
88− DPM_EVENT_SRC_DIGITAL = 2, /* Internal digital trip point (DIG_THERM_DPM) */
89− DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3, /* Internal analog or external */
90− DPM_EVENT_SRC_DIGITAL_OR_EXTERNAL = 4 /* Internal digital or external */
91−};
92−
93−
94−/* [2.5%,~2.5%] Clock stretched is multiple of 2.5% vs
95− * not and [Fmin, Fmax, LDO_REFSEL, USE_FOR_LOW_FREQ]
96− */
97−static const uint16_t fiji_clock_stretcher_lookup_table[2][4] =
98−{ {600, 1050, 3, 0}, {600, 1050, 6, 1} };
99−
100−/* [FF, SS] type, [] 4 voltage ranges, and
101− * [Floor Freq, Boundary Freq, VID min , VID max]
102− */
103−static const uint32_t fiji_clock_stretcher_ddt_table[2][4][4] =
104−{ { {265, 529, 120, 128}, {325, 650, 96, 119}, {430, 860, 32, 95}, {0, 0, 0, 31} },
105− { {275, 550, 104, 112}, {319, 638, 96, 103}, {360, 720, 64, 95}, {384, 768, 32, 63} } };
106−
107−/* [Use_For_Low_freq] value, [0%, 5%, 10%, 7.14%, 14.28%, 20%]
108− * (coming from PWR_CKS_CNTL.stretch_amount reg spec)
109− */
110−static const uint8_t fiji_clock_stretch_amount_conversion[2][6] =
111−{ {0, 1, 3, 2, 4, 5}, {0, 2, 4, 5, 6, 5} };
112−
113−static const unsigned long PhwFiji_Magic = (unsigned long)(PHM_VIslands_Magic);
114−
115−static struct fiji_power_state *cast_phw_fiji_power_state(
116− struct pp_hw_power_state *hw_ps)
117−{
118− PP_ASSERT_WITH_CODE((PhwFiji_Magic == hw_ps->magic),
119− "Invalid Powerstate Type!",
120− return NULL;);
121−
122− return (struct fiji_power_state *)hw_ps;
123−}
124−
125−static const struct
126−fiji_power_state *cast_const_phw_fiji_power_state(
127− const struct pp_hw_power_state *hw_ps)
128−{
129− PP_ASSERT_WITH_CODE((PhwFiji_Magic == hw_ps->magic),
130− "Invalid Powerstate Type!",
131− return NULL;);
132−
133− return (const struct fiji_power_state *)hw_ps;
134−}
135−
136−static bool fiji_is_dpm_running(struct pp_hwmgr *hwmgr)
137−{
138− return (1 == PHM_READ_INDIRECT_FIELD(hwmgr->device,
139− CGS_IND_REG__SMC, FEATURE_STATUS, VOLTAGE_CONTROLLER_ON))
140− ? true : false;
141−}
142−
143−static void fiji_init_dpm_defaults(struct pp_hwmgr *hwmgr)
144−{
145− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
146− struct fiji_ulv_parm *ulv = &data->ulv;
147−
148− ulv->cg_ulv_parameter = PPFIJI_CGULVPARAMETER_DFLT;
149− data->voting_rights_clients0 = PPFIJI_VOTINGRIGHTSCLIENTS_DFLT0;
150− data->voting_rights_clients1 = PPFIJI_VOTINGRIGHTSCLIENTS_DFLT1;
151− data->voting_rights_clients2 = PPFIJI_VOTINGRIGHTSCLIENTS_DFLT2;
152− data->voting_rights_clients3 = PPFIJI_VOTINGRIGHTSCLIENTS_DFLT3;
153− data->voting_rights_clients4 = PPFIJI_VOTINGRIGHTSCLIENTS_DFLT4;
154− data->voting_rights_clients5 = PPFIJI_VOTINGRIGHTSCLIENTS_DFLT5;
155− data->voting_rights_clients6 = PPFIJI_VOTINGRIGHTSCLIENTS_DFLT6;
156− data->voting_rights_clients7 = PPFIJI_VOTINGRIGHTSCLIENTS_DFLT7;
157−
158− data->static_screen_threshold_unit =
159− PPFIJI_STATICSCREENTHRESHOLDUNIT_DFLT;
160− data->static_screen_threshold =
161− PPFIJI_STATICSCREENTHRESHOLD_DFLT;
162−
163− /* Unset ABM cap as it moved to DAL.
164− * Add PHM_PlatformCaps_NonABMSupportInPPLib
165− * for re-direct ABM related request to DAL
166− */
167− phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
168− PHM_PlatformCaps_ABM);
169− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
170− PHM_PlatformCaps_NonABMSupportInPPLib);
171−
172− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
173− PHM_PlatformCaps_DynamicACTiming);
174−
175− fiji_initialize_power_tune_defaults(hwmgr);
176−
177− data->mclk_stutter_mode_threshold = 60000;
178− data->pcie_gen_performance.max = PP_PCIEGen1;
179− data->pcie_gen_performance.min = PP_PCIEGen3;
180− data->pcie_gen_power_saving.max = PP_PCIEGen1;
181− data->pcie_gen_power_saving.min = PP_PCIEGen3;
182− data->pcie_lane_performance.max = 0;
183− data->pcie_lane_performance.min = 16;
184− data->pcie_lane_power_saving.max = 0;
185− data->pcie_lane_power_saving.min = 16;
186−
187− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
188− PHM_PlatformCaps_DynamicUVDState);
189−}
190−
191−static int fiji_get_sclk_for_voltage_evv(struct pp_hwmgr *hwmgr,
192− phm_ppt_v1_voltage_lookup_table *lookup_table,
193− uint16_t virtual_voltage_id, int32_t *sclk)
194−{
195− uint8_t entryId;
196− uint8_t voltageId;
197− struct phm_ppt_v1_information *table_info =
198− (struct phm_ppt_v1_information *)(hwmgr->pptable);
199−
200− PP_ASSERT_WITH_CODE(lookup_table->count != 0, "Lookup table is empty", return -EINVAL);
201−
202− /* search for leakage voltage ID 0xff01 ~ 0xff08 and sckl */
203− for (entryId = 0; entryId < table_info->vdd_dep_on_sclk->count; entryId++) {
204− voltageId = table_info->vdd_dep_on_sclk->entries[entryId].vddInd;
205− if (lookup_table->entries[voltageId].us_vdd == virtual_voltage_id)
206− break;
207− }
208−
209− PP_ASSERT_WITH_CODE(entryId < table_info->vdd_dep_on_sclk->count,
210− "Can't find requested voltage id in vdd_dep_on_sclk table!",
211− return -EINVAL;
212− );
213−
214− *sclk = table_info->vdd_dep_on_sclk->entries[entryId].clk;
215−
216− return 0;
217−}
218−
219−/**
220−* Get Leakage VDDC based on leakage ID.
221−*
222−* @param hwmgr the address of the powerplay hardware manager.
223−* @return always 0
224−*/
225−static int fiji_get_evv_voltages(struct pp_hwmgr *hwmgr)
226−{
227− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
228− uint16_t vv_id;
229− uint16_t vddc = 0;
230− uint16_t evv_default = 1150;
231− uint16_t i, j;
232− uint32_t sclk = 0;
233− struct phm_ppt_v1_information *table_info =
234− (struct phm_ppt_v1_information *)hwmgr->pptable;
235− struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table =
236− table_info->vdd_dep_on_sclk;
237− int result;
238−
239− for (i = 0; i < FIJI_MAX_LEAKAGE_COUNT; i++) {
240− vv_id = ATOM_VIRTUAL_VOLTAGE_ID0 + i;
241− if (!fiji_get_sclk_for_voltage_evv(hwmgr,
242− table_info->vddc_lookup_table, vv_id, &sclk)) {
243− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
244− PHM_PlatformCaps_ClockStretcher)) {
245− for (j = 1; j < sclk_table->count; j++) {
246− if (sclk_table->entries[j].clk == sclk &&
247− sclk_table->entries[j].cks_enable == 0) {
248− sclk += 5000;
249− break;
250− }
251− }
252− }
253−
254− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
255− PHM_PlatformCaps_EnableDriverEVV))
256− result = atomctrl_calculate_voltage_evv_on_sclk(hwmgr,
257− VOLTAGE_TYPE_VDDC, sclk, vv_id, &vddc, i, true);
258− else
259− result = -EINVAL;
260−
261− if (result)
262− result = atomctrl_get_voltage_evv_on_sclk(hwmgr,
263− VOLTAGE_TYPE_VDDC, sclk,vv_id, &vddc);
264−
265− /* need to make sure vddc is less than 2v or else, it could burn the ASIC. */
266− PP_ASSERT_WITH_CODE((vddc < 2000),
267− "Invalid VDDC value, greater than 2v!", result = -EINVAL;);
268−
269− if (result)
270− /* 1.15V is the default safe value for Fiji */
271− vddc = evv_default;
272−
273− /* the voltage should not be zero nor equal to leakage ID */
274− if (vddc != 0 && vddc != vv_id) {
275− data->vddc_leakage.actual_voltage
276− [data->vddc_leakage.count] = vddc;
277− data->vddc_leakage.leakage_id
278− [data->vddc_leakage.count] = vv_id;
279− data->vddc_leakage.count++;
280− }
281− }
282− }
283− return 0;
284−}
285−
286−/**
287− * Change virtual leakage voltage to actual value.
288− *
289− * @param hwmgr the address of the powerplay hardware manager.
290− * @param pointer to changing voltage
291− * @param pointer to leakage table
292− */
293−static void fiji_patch_with_vdd_leakage(struct pp_hwmgr *hwmgr,
294− uint16_t *voltage, struct fiji_leakage_voltage *leakage_table)
295−{
296− uint32_t index;
297−
298− /* search for leakage voltage ID 0xff01 ~ 0xff08 */
299− for (index = 0; index < leakage_table->count; index++) {
300− /* if this voltage matches a leakage voltage ID */
301− /* patch with actual leakage voltage */
302− if (leakage_table->leakage_id[index] == *voltage) {
303− *voltage = leakage_table->actual_voltage[index];
304− break;
305− }
306− }
307−
308− if (*voltage > ATOM_VIRTUAL_VOLTAGE_ID0)
309− printk(KERN_ERR "Voltage value looks like a Leakage ID but it's not patched \n");
310−}
311−
312−/**
313−* Patch voltage lookup table by EVV leakages.
314−*
315−* @param hwmgr the address of the powerplay hardware manager.
316−* @param pointer to voltage lookup table
317−* @param pointer to leakage table
318−* @return always 0
319−*/
320−static int fiji_patch_lookup_table_with_leakage(struct pp_hwmgr *hwmgr,
321− phm_ppt_v1_voltage_lookup_table *lookup_table,
322− struct fiji_leakage_voltage *leakage_table)
323−{
324− uint32_t i;
325−
326− for (i = 0; i < lookup_table->count; i++)
327− fiji_patch_with_vdd_leakage(hwmgr,
328− &lookup_table->entries[i].us_vdd, leakage_table);
329−
330− return 0;
331−}
332−
333−static int fiji_patch_clock_voltage_limits_with_vddc_leakage(
334− struct pp_hwmgr *hwmgr, struct fiji_leakage_voltage *leakage_table,
335− uint16_t *vddc)
336−{
337− struct phm_ppt_v1_information *table_info =
338− (struct phm_ppt_v1_information *)(hwmgr->pptable);
339− fiji_patch_with_vdd_leakage(hwmgr, (uint16_t *)vddc, leakage_table);
340− hwmgr->dyn_state.max_clock_voltage_on_dc.vddc =
341− table_info->max_clock_voltage_on_dc.vddc;
342− return 0;
343−}
344−
345−static int fiji_patch_voltage_dependency_tables_with_lookup_table(
346− struct pp_hwmgr *hwmgr)
347−{
348− uint8_t entryId;
349− uint8_t voltageId;
350− struct phm_ppt_v1_information *table_info =
351− (struct phm_ppt_v1_information *)(hwmgr->pptable);
352−
353− struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table =
354− table_info->vdd_dep_on_sclk;
355− struct phm_ppt_v1_clock_voltage_dependency_table *mclk_table =
356− table_info->vdd_dep_on_mclk;
357− struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
358− table_info->mm_dep_table;
359−
360− for (entryId = 0; entryId < sclk_table->count; ++entryId) {
361− voltageId = sclk_table->entries[entryId].vddInd;
362− sclk_table->entries[entryId].vddc =
363− table_info->vddc_lookup_table->entries[voltageId].us_vdd;
364− }
365−
366− for (entryId = 0; entryId < mclk_table->count; ++entryId) {
367− voltageId = mclk_table->entries[entryId].vddInd;
368− mclk_table->entries[entryId].vddc =
369− table_info->vddc_lookup_table->entries[voltageId].us_vdd;
370− }
371−
372− for (entryId = 0; entryId < mm_table->count; ++entryId) {
373− voltageId = mm_table->entries[entryId].vddcInd;
374− mm_table->entries[entryId].vddc =
375− table_info->vddc_lookup_table->entries[voltageId].us_vdd;
376− }
377−
378− return 0;
379−
380−}
381−
382−static int fiji_calc_voltage_dependency_tables(struct pp_hwmgr *hwmgr)
383−{
384− /* Need to determine if we need calculated voltage. */
385− return 0;
386−}
387−
388−static int fiji_calc_mm_voltage_dependency_table(struct pp_hwmgr *hwmgr)
389−{
390− /* Need to determine if we need calculated voltage from mm table. */
391− return 0;
392−}
393−
394−static int fiji_sort_lookup_table(struct pp_hwmgr *hwmgr,
395− struct phm_ppt_v1_voltage_lookup_table *lookup_table)
396−{
397− uint32_t table_size, i, j;
398− struct phm_ppt_v1_voltage_lookup_record tmp_voltage_lookup_record;
399− table_size = lookup_table->count;
400−
401− PP_ASSERT_WITH_CODE(0 != lookup_table->count,
402− "Lookup table is empty", return -EINVAL);
403−
404− /* Sorting voltages */
405− for (i = 0; i < table_size - 1; i++) {
406− for (j = i + 1; j > 0; j--) {
407− if (lookup_table->entries[j].us_vdd <
408− lookup_table->entries[j - 1].us_vdd) {
409− tmp_voltage_lookup_record = lookup_table->entries[j - 1];
410− lookup_table->entries[j - 1] = lookup_table->entries[j];
411− lookup_table->entries[j] = tmp_voltage_lookup_record;
412− }
413− }
414− }
415−
416− return 0;
417−}
418−
419−static int fiji_complete_dependency_tables(struct pp_hwmgr *hwmgr)
420−{
421− int result = 0;
422− int tmp_result;
423− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
424− struct phm_ppt_v1_information *table_info =
425− (struct phm_ppt_v1_information *)(hwmgr->pptable);
426−
427− tmp_result = fiji_patch_lookup_table_with_leakage(hwmgr,
428− table_info->vddc_lookup_table, &(data->vddc_leakage));
429− if (tmp_result)
430− result = tmp_result;
431−
432− tmp_result = fiji_patch_clock_voltage_limits_with_vddc_leakage(hwmgr,
433− &(data->vddc_leakage), &table_info->max_clock_voltage_on_dc.vddc);
434− if (tmp_result)
435− result = tmp_result;
436−
437− tmp_result = fiji_patch_voltage_dependency_tables_with_lookup_table(hwmgr);
438− if (tmp_result)
439− result = tmp_result;
440−
441− tmp_result = fiji_calc_voltage_dependency_tables(hwmgr);
442− if (tmp_result)
443− result = tmp_result;
444−
445− tmp_result = fiji_calc_mm_voltage_dependency_table(hwmgr);
446− if (tmp_result)
447− result = tmp_result;
448−
449− tmp_result = fiji_sort_lookup_table(hwmgr, table_info->vddc_lookup_table);
450− if(tmp_result)
451− result = tmp_result;
452−
453− return result;
454−}
455−
456−static int fiji_set_private_data_based_on_pptable(struct pp_hwmgr *hwmgr)
457−{
458− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
459− struct phm_ppt_v1_information *table_info =
460− (struct phm_ppt_v1_information *)(hwmgr->pptable);
461−
462− struct phm_ppt_v1_clock_voltage_dependency_table *allowed_sclk_vdd_table =
463− table_info->vdd_dep_on_sclk;
464− struct phm_ppt_v1_clock_voltage_dependency_table *allowed_mclk_vdd_table =
465− table_info->vdd_dep_on_mclk;
466−
467− PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table != NULL,
468− "VDD dependency on SCLK table is missing. \
469− This table is mandatory", return -EINVAL);
470− PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table->count >= 1,
471− "VDD dependency on SCLK table has to have is missing. \
472− This table is mandatory", return -EINVAL);
473−
474− PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table != NULL,
475− "VDD dependency on MCLK table is missing. \
476− This table is mandatory", return -EINVAL);
477− PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table->count >= 1,
478− "VDD dependency on MCLK table has to have is missing. \
479− This table is mandatory", return -EINVAL);
480−
481− data->min_vddc_in_pptable = (uint16_t)allowed_sclk_vdd_table->entries[0].vddc;
482− data->max_vddc_in_pptable = (uint16_t)allowed_sclk_vdd_table->
483− entries[allowed_sclk_vdd_table->count - 1].vddc;
484−
485− table_info->max_clock_voltage_on_ac.sclk =
486− allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].clk;
487− table_info->max_clock_voltage_on_ac.mclk =
488− allowed_mclk_vdd_table->entries[allowed_mclk_vdd_table->count - 1].clk;
489− table_info->max_clock_voltage_on_ac.vddc =
490− allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].vddc;
491− table_info->max_clock_voltage_on_ac.vddci =
492− allowed_mclk_vdd_table->entries[allowed_mclk_vdd_table->count - 1].vddci;
493−
494− hwmgr->dyn_state.max_clock_voltage_on_ac.sclk =
495− table_info->max_clock_voltage_on_ac.sclk;
496− hwmgr->dyn_state.max_clock_voltage_on_ac.mclk =
497− table_info->max_clock_voltage_on_ac.mclk;
498− hwmgr->dyn_state.max_clock_voltage_on_ac.vddc =
499− table_info->max_clock_voltage_on_ac.vddc;
500− hwmgr->dyn_state.max_clock_voltage_on_ac.vddci =
501− table_info->max_clock_voltage_on_ac.vddci;
502−
503− return 0;
504−}
505−
506−static uint16_t fiji_get_current_pcie_speed(struct pp_hwmgr *hwmgr)
507−{
508− uint32_t speedCntl = 0;
509−
510− /* mmPCIE_PORT_INDEX rename as mmPCIE_INDEX */
511− speedCntl = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__PCIE,
512− ixPCIE_LC_SPEED_CNTL);
513− return((uint16_t)PHM_GET_FIELD(speedCntl,
514− PCIE_LC_SPEED_CNTL, LC_CURRENT_DATA_RATE));
515−}
516−
517−static int fiji_get_current_pcie_lane_number(struct pp_hwmgr *hwmgr)
518−{
519− uint32_t link_width;
520−
521− /* mmPCIE_PORT_INDEX rename as mmPCIE_INDEX */
522− link_width = PHM_READ_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__PCIE,
523− PCIE_LC_LINK_WIDTH_CNTL, LC_LINK_WIDTH_RD);
524−
525− PP_ASSERT_WITH_CODE((7 >= link_width),
526− "Invalid PCIe lane width!", return 0);
527−
528− return decode_pcie_lane_width(link_width);
529−}
530−
531−/** Patch the Boot State to match VBIOS boot clocks and voltage.
532−*
533−* @param hwmgr Pointer to the hardware manager.
534−* @param pPowerState The address of the PowerState instance being created.
535−*
536−*/
537−static int fiji_patch_boot_state(struct pp_hwmgr *hwmgr,
538− struct pp_hw_power_state *hw_ps)
539−{
540− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
541− struct fiji_power_state *ps = (struct fiji_power_state *)hw_ps;
542− ATOM_FIRMWARE_INFO_V2_2 *fw_info;
543− uint16_t size;
544− uint8_t frev, crev;
545− int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
546−
547− /* First retrieve the Boot clocks and VDDC from the firmware info table.
548− * We assume here that fw_info is unchanged if this call fails.
549− */
550− fw_info = (ATOM_FIRMWARE_INFO_V2_2 *)cgs_atom_get_data_table(
551− hwmgr->device, index,
552− &size, &frev, &crev);
553− if (!fw_info)
554− /* During a test, there is no firmware info table. */
555− return 0;
556−
557− /* Patch the state. */
558− data->vbios_boot_state.sclk_bootup_value =
559− le32_to_cpu(fw_info->ulDefaultEngineClock);
560− data->vbios_boot_state.mclk_bootup_value =
561− le32_to_cpu(fw_info->ulDefaultMemoryClock);
562− data->vbios_boot_state.mvdd_bootup_value =
563− le16_to_cpu(fw_info->usBootUpMVDDCVoltage);
564− data->vbios_boot_state.vddc_bootup_value =
565− le16_to_cpu(fw_info->usBootUpVDDCVoltage);
566− data->vbios_boot_state.vddci_bootup_value =
567− le16_to_cpu(fw_info->usBootUpVDDCIVoltage);
568− data->vbios_boot_state.pcie_gen_bootup_value =
569− fiji_get_current_pcie_speed(hwmgr);
570− data->vbios_boot_state.pcie_lane_bootup_value =
571− (uint16_t)fiji_get_current_pcie_lane_number(hwmgr);
572−
573− /* set boot power state */
574− ps->performance_levels[0].memory_clock = data->vbios_boot_state.mclk_bootup_value;
575− ps->performance_levels[0].engine_clock = data->vbios_boot_state.sclk_bootup_value;
576− ps->performance_levels[0].pcie_gen = data->vbios_boot_state.pcie_gen_bootup_value;
577− ps->performance_levels[0].pcie_lane = data->vbios_boot_state.pcie_lane_bootup_value;
578−
579− return 0;
580−}
581−
582−static int fiji_hwmgr_backend_fini(struct pp_hwmgr *hwmgr)
583−{
584− return phm_hwmgr_backend_fini(hwmgr);
585−}
586−
587−static int fiji_hwmgr_backend_init(struct pp_hwmgr *hwmgr)
588−{
589− struct fiji_hwmgr *data;
590− uint32_t i;
591− struct phm_ppt_v1_information *table_info =
592− (struct phm_ppt_v1_information *)(hwmgr->pptable);
593− bool stay_in_boot;
594− int result;
595−
596− data = kzalloc(sizeof(struct fiji_hwmgr), GFP_KERNEL);
597− if (data == NULL)
598− return -ENOMEM;
599−
600− hwmgr->backend = data;
601−
602− data->dll_default_on = false;
603− data->sram_end = SMC_RAM_END;
604−
605− for (i = 0; i < SMU73_MAX_LEVELS_GRAPHICS; i++)
606− data->activity_target[i] = FIJI_AT_DFLT;
607−
608− data->vddc_vddci_delta = VDDC_VDDCI_DELTA;
609−
610− data->mclk_activity_target = PPFIJI_MCLK_TARGETACTIVITY_DFLT;
611− data->mclk_dpm0_activity_target = 0xa;
612−
613− data->sclk_dpm_key_disabled = 0;
614− data->mclk_dpm_key_disabled = 0;
615− data->pcie_dpm_key_disabled = 0;
616−
617− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
618− PHM_PlatformCaps_UnTabledHardwareInterface);
619− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
620− PHM_PlatformCaps_TablelessHardwareInterface);
621−
622− data->gpio_debug = 0;
623−
624− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
625− PHM_PlatformCaps_DynamicPatchPowerState);
626−
627− /* need to set voltage control types before EVV patching */
628− data->voltage_control = FIJI_VOLTAGE_CONTROL_NONE;
629− data->vddci_control = FIJI_VOLTAGE_CONTROL_NONE;
630− data->mvdd_control = FIJI_VOLTAGE_CONTROL_NONE;
631−
632− data->force_pcie_gen = PP_PCIEGenInvalid;
633−
634− if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
635− VOLTAGE_TYPE_VDDC, VOLTAGE_OBJ_SVID2))
636− data->voltage_control = FIJI_VOLTAGE_CONTROL_BY_SVID2;
637−
638− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
639− PHM_PlatformCaps_EnableMVDDControl))
640− if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
641− VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_GPIO_LUT))
642− data->mvdd_control = FIJI_VOLTAGE_CONTROL_BY_GPIO;
643−
644− if (data->mvdd_control == FIJI_VOLTAGE_CONTROL_NONE)
645− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
646− PHM_PlatformCaps_EnableMVDDControl);
647−
648− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
649− PHM_PlatformCaps_ControlVDDCI)) {
650− if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
651− VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT))
652− data->vddci_control = FIJI_VOLTAGE_CONTROL_BY_GPIO;
653− else if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
654− VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_SVID2))
655− data->vddci_control = FIJI_VOLTAGE_CONTROL_BY_SVID2;
656− }
657−
658− if (data->vddci_control == FIJI_VOLTAGE_CONTROL_NONE)
659− phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
660− PHM_PlatformCaps_ControlVDDCI);
661−
662− if (table_info && table_info->cac_dtp_table->usClockStretchAmount)
663− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
664− PHM_PlatformCaps_ClockStretcher);
665−
666− fiji_init_dpm_defaults(hwmgr);
667−
668− /* Get leakage voltage based on leakage ID. */
669− fiji_get_evv_voltages(hwmgr);
670−
671− /* Patch our voltage dependency table with actual leakage voltage
672− * We need to perform leakage translation before it's used by other functions
673− */
674− fiji_complete_dependency_tables(hwmgr);
675−
676− /* Parse pptable data read from VBIOS */
677− fiji_set_private_data_based_on_pptable(hwmgr);
678−
679− /* ULV Support */
680− data->ulv.ulv_supported = true; /* ULV feature is enabled by default */
681−
682− /* Initalize Dynamic State Adjustment Rule Settings */
683− result = tonga_initializa_dynamic_state_adjustment_rule_settings(hwmgr);
684−
685− if (!result) {
686− data->uvd_enabled = false;
687− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
688− PHM_PlatformCaps_EnableSMU7ThermalManagement);
689− data->vddc_phase_shed_control = false;
690− }
691−
692− stay_in_boot = phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
693− PHM_PlatformCaps_StayInBootState);
694−
695− if (0 == result) {
696− struct cgs_system_info sys_info = {0};
697−
698− data->is_tlu_enabled = false;
699− hwmgr->platform_descriptor.hardwareActivityPerformanceLevels =
700− FIJI_MAX_HARDWARE_POWERLEVELS;
701− hwmgr->platform_descriptor.hardwarePerformanceLevels = 2;
702− hwmgr->platform_descriptor.minimumClocksReductionPercentage = 50;
703−
704− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
705− PHM_PlatformCaps_FanSpeedInTableIsRPM);
706−
707− if (table_info->cac_dtp_table->usDefaultTargetOperatingTemp &&
708− hwmgr->thermal_controller.
709− advanceFanControlParameters.ucFanControlMode) {
710− hwmgr->thermal_controller.advanceFanControlParameters.usMaxFanPWM =
711− hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanPWM;
712− hwmgr->thermal_controller.advanceFanControlParameters.usMaxFanRPM =
713− hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanRPM;
714− hwmgr->dyn_state.cac_dtp_table->usOperatingTempMinLimit =
715− table_info->cac_dtp_table->usOperatingTempMinLimit;
716− hwmgr->dyn_state.cac_dtp_table->usOperatingTempMaxLimit =
717− table_info->cac_dtp_table->usOperatingTempMaxLimit;
718− hwmgr->dyn_state.cac_dtp_table->usDefaultTargetOperatingTemp =
719− table_info->cac_dtp_table->usDefaultTargetOperatingTemp;
720− hwmgr->dyn_state.cac_dtp_table->usOperatingTempStep =
721− table_info->cac_dtp_table->usOperatingTempStep;
722− hwmgr->dyn_state.cac_dtp_table->usTargetOperatingTemp =
723− table_info->cac_dtp_table->usTargetOperatingTemp;
724−
725− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
726− PHM_PlatformCaps_ODFuzzyFanControlSupport);
727− }
728−
729− sys_info.size = sizeof(struct cgs_system_info);
730− sys_info.info_id = CGS_SYSTEM_INFO_PCIE_GEN_INFO;
731− result = cgs_query_system_info(hwmgr->device, &sys_info);
732− if (result)
733− data->pcie_gen_cap = AMDGPU_DEFAULT_PCIE_GEN_MASK;
734− else
735− data->pcie_gen_cap = (uint32_t)sys_info.value;
736− if (data->pcie_gen_cap & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)
737− data->pcie_spc_cap = 20;
738− sys_info.size = sizeof(struct cgs_system_info);
739− sys_info.info_id = CGS_SYSTEM_INFO_PCIE_MLW;
740− result = cgs_query_system_info(hwmgr->device, &sys_info);
741− if (result)
742− data->pcie_lane_cap = AMDGPU_DEFAULT_PCIE_MLW_MASK;
743− else
744− data->pcie_lane_cap = (uint32_t)sys_info.value;
745− } else {
746− /* Ignore return value in here, we are cleaning up a mess. */
747− fiji_hwmgr_backend_fini(hwmgr);
748− }
749−
750− return 0;
751−}
752−
753−/**
754− * Read clock related registers.
755− *
756− * @param hwmgr the address of the powerplay hardware manager.
757− * @return always 0
758− */
759−static int fiji_read_clock_registers(struct pp_hwmgr *hwmgr)
760−{
761− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
762−
763− data->clock_registers.vCG_SPLL_FUNC_CNTL =
764− cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
765− ixCG_SPLL_FUNC_CNTL);
766− data->clock_registers.vCG_SPLL_FUNC_CNTL_2 =
767− cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
768− ixCG_SPLL_FUNC_CNTL_2);
769− data->clock_registers.vCG_SPLL_FUNC_CNTL_3 =
770− cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
771− ixCG_SPLL_FUNC_CNTL_3);
772− data->clock_registers.vCG_SPLL_FUNC_CNTL_4 =
773− cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
774− ixCG_SPLL_FUNC_CNTL_4);
775− data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM =
776− cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
777− ixCG_SPLL_SPREAD_SPECTRUM);
778− data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM_2 =
779− cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
780− ixCG_SPLL_SPREAD_SPECTRUM_2);
781−
782− return 0;
783−}
784−
785−/**
786− * Find out if memory is GDDR5.
787− *
788− * @param hwmgr the address of the powerplay hardware manager.
789− * @return always 0
790− */
791−static int fiji_get_memory_type(struct pp_hwmgr *hwmgr)
792−{
793− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
794− uint32_t temp;
795−
796− temp = cgs_read_register(hwmgr->device, mmMC_SEQ_MISC0);
797−
798− data->is_memory_gddr5 = (MC_SEQ_MISC0_GDDR5_VALUE ==
799− ((temp & MC_SEQ_MISC0_GDDR5_MASK) >>
800− MC_SEQ_MISC0_GDDR5_SHIFT));
801−
802− return 0;
803−}
804−
805−/**
806− * Enables Dynamic Power Management by SMC
807− *
808− * @param hwmgr the address of the powerplay hardware manager.
809− * @return always 0
810− */
811−static int fiji_enable_acpi_power_management(struct pp_hwmgr *hwmgr)
812−{
813− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
814− GENERAL_PWRMGT, STATIC_PM_EN, 1);
815−
816− return 0;
817−}
818−
819−/**
820− * Initialize PowerGating States for different engines
821− *
822− * @param hwmgr the address of the powerplay hardware manager.
823− * @return always 0
824− */
825−static int fiji_init_power_gate_state(struct pp_hwmgr *hwmgr)
826−{
827− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
828−
829− data->uvd_power_gated = false;
830− data->vce_power_gated = false;
831− data->samu_power_gated = false;
832− data->acp_power_gated = false;
833− data->pg_acp_init = true;
834−
835− return 0;
836−}
837−
838−static int fiji_init_sclk_threshold(struct pp_hwmgr *hwmgr)
839−{
840− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
841− data->low_sclk_interrupt_threshold = 0;
842−
843− return 0;
844−}
845−
846−static int fiji_setup_asic_task(struct pp_hwmgr *hwmgr)
847−{
848− int tmp_result, result = 0;
849−
850− tmp_result = fiji_read_clock_registers(hwmgr);
851− PP_ASSERT_WITH_CODE((0 == tmp_result),
852− "Failed to read clock registers!", result = tmp_result);
853−
854− tmp_result = fiji_get_memory_type(hwmgr);
855− PP_ASSERT_WITH_CODE((0 == tmp_result),
856− "Failed to get memory type!", result = tmp_result);
857−
858− tmp_result = fiji_enable_acpi_power_management(hwmgr);
859− PP_ASSERT_WITH_CODE((0 == tmp_result),
860− "Failed to enable ACPI power management!", result = tmp_result);
861−
862− tmp_result = fiji_init_power_gate_state(hwmgr);
863− PP_ASSERT_WITH_CODE((0 == tmp_result),
864− "Failed to init power gate state!", result = tmp_result);
865−
866− tmp_result = tonga_get_mc_microcode_version(hwmgr);
867− PP_ASSERT_WITH_CODE((0 == tmp_result),
868− "Failed to get MC microcode version!", result = tmp_result);
869−
870− tmp_result = fiji_init_sclk_threshold(hwmgr);
871− PP_ASSERT_WITH_CODE((0 == tmp_result),
872− "Failed to init sclk threshold!", result = tmp_result);
873−
874− return result;
875−}
876−
877−/**
878−* Checks if we want to support voltage control
879−*
880−* @param hwmgr the address of the powerplay hardware manager.
881−*/
882−static bool fiji_voltage_control(const struct pp_hwmgr *hwmgr)
883−{
884− const struct fiji_hwmgr *data =
885− (const struct fiji_hwmgr *)(hwmgr->backend);
886−
887− return (FIJI_VOLTAGE_CONTROL_NONE != data->voltage_control);
888−}
889−
890−/**
891−* Enable voltage control
892−*
893−* @param hwmgr the address of the powerplay hardware manager.
894−* @return always 0
895−*/
896−static int fiji_enable_voltage_control(struct pp_hwmgr *hwmgr)
897−{
898− /* enable voltage control */
899− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
900− GENERAL_PWRMGT, VOLT_PWRMGT_EN, 1);
901−
902− return 0;
903−}
904−
905−/**
906−* Remove repeated voltage values and create table with unique values.
907−*
908−* @param hwmgr the address of the powerplay hardware manager.
909−* @param vol_table the pointer to changing voltage table
910−* @return 0 in success
911−*/
912−
913−static int fiji_trim_voltage_table(struct pp_hwmgr *hwmgr,
914− struct pp_atomctrl_voltage_table *vol_table)
915−{
916− uint32_t i, j;
917− uint16_t vvalue;
918− bool found = false;
919− struct pp_atomctrl_voltage_table *table;
920−
921− PP_ASSERT_WITH_CODE((NULL != vol_table),
922− "Voltage Table empty.", return -EINVAL);
923− table = kzalloc(sizeof(struct pp_atomctrl_voltage_table),
924− GFP_KERNEL);
925−
926− if (NULL == table)
927− return -ENOMEM;
928−
929− table->mask_low = vol_table->mask_low;
930− table->phase_delay = vol_table->phase_delay;
931−
932− for (i = 0; i < vol_table->count; i++) {
933− vvalue = vol_table->entries[i].value;
934− found = false;
935−
936− for (j = 0; j < table->count; j++) {
937− if (vvalue == table->entries[j].value) {
938− found = true;
939− break;
940− }
941− }
942−
943− if (!found) {
944− table->entries[table->count].value = vvalue;
945− table->entries[table->count].smio_low =
946− vol_table->entries[i].smio_low;
947− table->count++;
948− }
949− }
950−
951− memcpy(vol_table, table, sizeof(struct pp_atomctrl_voltage_table));
952− kfree(table);
953−
954− return 0;
955−}
956−
957−static int fiji_get_svi2_mvdd_voltage_table(struct pp_hwmgr *hwmgr,
958− phm_ppt_v1_clock_voltage_dependency_table *dep_table)
959−{
960− uint32_t i;
961− int result;
962− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
963− struct pp_atomctrl_voltage_table *vol_table = &(data->mvdd_voltage_table);
964−
965− PP_ASSERT_WITH_CODE((0 != dep_table->count),
966− "Voltage Dependency Table empty.", return -EINVAL);
967−
968− vol_table->mask_low = 0;
969− vol_table->phase_delay = 0;
970− vol_table->count = dep_table->count;
971−
972− for (i = 0; i < dep_table->count; i++) {
973− vol_table->entries[i].value = dep_table->entries[i].mvdd;
974− vol_table->entries[i].smio_low = 0;
975− }
976−
977− result = fiji_trim_voltage_table(hwmgr, vol_table);
978− PP_ASSERT_WITH_CODE((0 == result),
979− "Failed to trim MVDD table.", return result);
980−
981− return 0;
982−}
983−
984−static int fiji_get_svi2_vddci_voltage_table(struct pp_hwmgr *hwmgr,
985− phm_ppt_v1_clock_voltage_dependency_table *dep_table)
986−{
987− uint32_t i;
988− int result;
989− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
990− struct pp_atomctrl_voltage_table *vol_table = &(data->vddci_voltage_table);
991−
992− PP_ASSERT_WITH_CODE((0 != dep_table->count),
993− "Voltage Dependency Table empty.", return -EINVAL);
994−
995− vol_table->mask_low = 0;
996− vol_table->phase_delay = 0;
997− vol_table->count = dep_table->count;
998−
999− for (i = 0; i < dep_table->count; i++) {
1000− vol_table->entries[i].value = dep_table->entries[i].vddci;
1001− vol_table->entries[i].smio_low = 0;
1002− }
1003−
1004− result = fiji_trim_voltage_table(hwmgr, vol_table);
1005− PP_ASSERT_WITH_CODE((0 == result),
1006− "Failed to trim VDDCI table.", return result);
1007−
1008− return 0;
1009−}
1010−
1011−static int fiji_get_svi2_vdd_voltage_table(struct pp_hwmgr *hwmgr,
1012− phm_ppt_v1_voltage_lookup_table *lookup_table)
1013−{
1014− int i = 0;
1015− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1016− struct pp_atomctrl_voltage_table *vol_table = &(data->vddc_voltage_table);
1017−
1018− PP_ASSERT_WITH_CODE((0 != lookup_table->count),
1019− "Voltage Lookup Table empty.", return -EINVAL);
1020−
1021− vol_table->mask_low = 0;
1022− vol_table->phase_delay = 0;
1023−
1024− vol_table->count = lookup_table->count;
1025−
1026− for (i = 0; i < vol_table->count; i++) {
1027− vol_table->entries[i].value = lookup_table->entries[i].us_vdd;
1028− vol_table->entries[i].smio_low = 0;
1029− }
1030−
1031− return 0;
1032−}
1033−
1034−/* ---- Voltage Tables ----
1035− * If the voltage table would be bigger than
1036− * what will fit into the state table on
1037− * the SMC keep only the higher entries.
1038− */
1039−static void fiji_trim_voltage_table_to_fit_state_table(struct pp_hwmgr *hwmgr,
1040− uint32_t max_vol_steps, struct pp_atomctrl_voltage_table *vol_table)
1041−{
1042− unsigned int i, diff;
1043−
1044− if (vol_table->count <= max_vol_steps)
1045− return;
1046−
1047− diff = vol_table->count - max_vol_steps;
1048−
1049− for (i = 0; i < max_vol_steps; i++)
1050− vol_table->entries[i] = vol_table->entries[i + diff];
1051−
1052− vol_table->count = max_vol_steps;
1053−
1054− return;
1055−}
1056−
1057−/**
1058−* Create Voltage Tables.
1059−*
1060−* @param hwmgr the address of the powerplay hardware manager.
1061−* @return always 0
1062−*/
1063−static int fiji_construct_voltage_tables(struct pp_hwmgr *hwmgr)
1064−{
1065− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1066− struct phm_ppt_v1_information *table_info =
1067− (struct phm_ppt_v1_information *)hwmgr->pptable;
1068− int result;
1069−
1070− if (FIJI_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) {
1071− result = atomctrl_get_voltage_table_v3(hwmgr,
1072− VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_GPIO_LUT,
1073− &(data->mvdd_voltage_table));
1074− PP_ASSERT_WITH_CODE((0 == result),
1075− "Failed to retrieve MVDD table.",
1076− return result);
1077− } else if (FIJI_VOLTAGE_CONTROL_BY_SVID2 == data->mvdd_control) {
1078− result = fiji_get_svi2_mvdd_voltage_table(hwmgr,
1079− table_info->vdd_dep_on_mclk);
1080− PP_ASSERT_WITH_CODE((0 == result),
1081− "Failed to retrieve SVI2 MVDD table from dependancy table.",
1082− return result;);
1083− }
1084−
1085− if (FIJI_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control) {
1086− result = atomctrl_get_voltage_table_v3(hwmgr,
1087− VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT,
1088− &(data->vddci_voltage_table));
1089− PP_ASSERT_WITH_CODE((0 == result),
1090− "Failed to retrieve VDDCI table.",
1091− return result);
1092− } else if (FIJI_VOLTAGE_CONTROL_BY_SVID2 == data->vddci_control) {
1093− result = fiji_get_svi2_vddci_voltage_table(hwmgr,
1094− table_info->vdd_dep_on_mclk);
1095− PP_ASSERT_WITH_CODE((0 == result),
1096− "Failed to retrieve SVI2 VDDCI table from dependancy table.",
1097− return result);
1098− }
1099−
1100− if(FIJI_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) {
1101− result = fiji_get_svi2_vdd_voltage_table(hwmgr,
1102− table_info->vddc_lookup_table);
1103− PP_ASSERT_WITH_CODE((0 == result),
1104− "Failed to retrieve SVI2 VDDC table from lookup table.",
1105− return result);
1106− }
1107−
1108− PP_ASSERT_WITH_CODE(
1109− (data->vddc_voltage_table.count <= (SMU73_MAX_LEVELS_VDDC)),
1110− "Too many voltage values for VDDC. Trimming to fit state table.",
1111− fiji_trim_voltage_table_to_fit_state_table(hwmgr,
1112− SMU73_MAX_LEVELS_VDDC, &(data->vddc_voltage_table)));
1113−
1114− PP_ASSERT_WITH_CODE(
1115− (data->vddci_voltage_table.count <= (SMU73_MAX_LEVELS_VDDCI)),
1116− "Too many voltage values for VDDCI. Trimming to fit state table.",
1117− fiji_trim_voltage_table_to_fit_state_table(hwmgr,
1118− SMU73_MAX_LEVELS_VDDCI, &(data->vddci_voltage_table)));
1119−
1120− PP_ASSERT_WITH_CODE(
1121− (data->mvdd_voltage_table.count <= (SMU73_MAX_LEVELS_MVDD)),
1122− "Too many voltage values for MVDD. Trimming to fit state table.",
1123− fiji_trim_voltage_table_to_fit_state_table(hwmgr,
1124− SMU73_MAX_LEVELS_MVDD, &(data->mvdd_voltage_table)));
1125−
1126− return 0;
1127−}
1128−
1129−static int fiji_initialize_mc_reg_table(struct pp_hwmgr *hwmgr)
1130−{
1131− /* Program additional LP registers
1132− * that are no longer programmed by VBIOS
1133− */
1134− cgs_write_register(hwmgr->device, mmMC_SEQ_RAS_TIMING_LP,
1135− cgs_read_register(hwmgr->device, mmMC_SEQ_RAS_TIMING));
1136− cgs_write_register(hwmgr->device, mmMC_SEQ_CAS_TIMING_LP,
1137− cgs_read_register(hwmgr->device, mmMC_SEQ_CAS_TIMING));
1138− cgs_write_register(hwmgr->device, mmMC_SEQ_MISC_TIMING2_LP,
1139− cgs_read_register(hwmgr->device, mmMC_SEQ_MISC_TIMING2));
1140− cgs_write_register(hwmgr->device, mmMC_SEQ_WR_CTL_D1_LP,
1141− cgs_read_register(hwmgr->device, mmMC_SEQ_WR_CTL_D1));
1142− cgs_write_register(hwmgr->device, mmMC_SEQ_RD_CTL_D0_LP,
1143− cgs_read_register(hwmgr->device, mmMC_SEQ_RD_CTL_D0));
1144− cgs_write_register(hwmgr->device, mmMC_SEQ_RD_CTL_D1_LP,
1145− cgs_read_register(hwmgr->device, mmMC_SEQ_RD_CTL_D1));
1146− cgs_write_register(hwmgr->device, mmMC_SEQ_PMG_TIMING_LP,
1147− cgs_read_register(hwmgr->device, mmMC_SEQ_PMG_TIMING));
1148−
1149− return 0;
1150−}
1151−
1152−/**
1153−* Programs static screed detection parameters
1154−*
1155−* @param hwmgr the address of the powerplay hardware manager.
1156−* @return always 0
1157−*/
1158−static int fiji_program_static_screen_threshold_parameters(
1159− struct pp_hwmgr *hwmgr)
1160−{
1161− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1162−
1163− /* Set static screen threshold unit */
1164− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1165− CG_STATIC_SCREEN_PARAMETER, STATIC_SCREEN_THRESHOLD_UNIT,
1166− data->static_screen_threshold_unit);
1167− /* Set static screen threshold */
1168− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1169− CG_STATIC_SCREEN_PARAMETER, STATIC_SCREEN_THRESHOLD,
1170− data->static_screen_threshold);
1171−
1172− return 0;
1173−}
1174−
1175−/**
1176−* Setup display gap for glitch free memory clock switching.
1177−*
1178−* @param hwmgr the address of the powerplay hardware manager.
1179−* @return always 0
1180−*/
1181−static int fiji_enable_display_gap(struct pp_hwmgr *hwmgr)
1182−{
1183− uint32_t displayGap =
1184− cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1185− ixCG_DISPLAY_GAP_CNTL);
1186−
1187− displayGap = PHM_SET_FIELD(displayGap, CG_DISPLAY_GAP_CNTL,
1188− DISP_GAP, DISPLAY_GAP_IGNORE);
1189−
1190− displayGap = PHM_SET_FIELD(displayGap, CG_DISPLAY_GAP_CNTL,
1191− DISP_GAP_MCHG, DISPLAY_GAP_VBLANK);
1192−
1193− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1194− ixCG_DISPLAY_GAP_CNTL, displayGap);
1195−
1196− return 0;
1197−}
1198−
1199−/**
1200−* Programs activity state transition voting clients
1201−*
1202−* @param hwmgr the address of the powerplay hardware manager.
1203−* @return always 0
1204−*/
1205−static int fiji_program_voting_clients(struct pp_hwmgr *hwmgr)
1206−{
1207− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1208−
1209− /* Clear reset for voting clients before enabling DPM */
1210− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1211− SCLK_PWRMGT_CNTL, RESET_SCLK_CNT, 0);
1212− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1213− SCLK_PWRMGT_CNTL, RESET_BUSY_CNT, 0);
1214−
1215− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1216− ixCG_FREQ_TRAN_VOTING_0, data->voting_rights_clients0);
1217− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1218− ixCG_FREQ_TRAN_VOTING_1, data->voting_rights_clients1);
1219− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1220− ixCG_FREQ_TRAN_VOTING_2, data->voting_rights_clients2);
1221− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1222− ixCG_FREQ_TRAN_VOTING_3, data->voting_rights_clients3);
1223− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1224− ixCG_FREQ_TRAN_VOTING_4, data->voting_rights_clients4);
1225− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1226− ixCG_FREQ_TRAN_VOTING_5, data->voting_rights_clients5);
1227− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1228− ixCG_FREQ_TRAN_VOTING_6, data->voting_rights_clients6);
1229− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1230− ixCG_FREQ_TRAN_VOTING_7, data->voting_rights_clients7);
1231−
1232− return 0;
1233−}
1234−
1235−static int fiji_clear_voting_clients(struct pp_hwmgr *hwmgr)
1236−{
1237− /* Reset voting clients before disabling DPM */
1238− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1239− SCLK_PWRMGT_CNTL, RESET_SCLK_CNT, 1);
1240− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1241− SCLK_PWRMGT_CNTL, RESET_BUSY_CNT, 1);
1242−
1243− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1244− ixCG_FREQ_TRAN_VOTING_0, 0);
1245− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1246− ixCG_FREQ_TRAN_VOTING_1, 0);
1247− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1248− ixCG_FREQ_TRAN_VOTING_2, 0);
1249− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1250− ixCG_FREQ_TRAN_VOTING_3, 0);
1251− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1252− ixCG_FREQ_TRAN_VOTING_4, 0);
1253− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1254− ixCG_FREQ_TRAN_VOTING_5, 0);
1255− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1256− ixCG_FREQ_TRAN_VOTING_6, 0);
1257− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1258− ixCG_FREQ_TRAN_VOTING_7, 0);
1259−
1260− return 0;
1261−}
1262−
1263−/**
1264−* Get the location of various tables inside the FW image.
1265−*
1266−* @param hwmgr the address of the powerplay hardware manager.
1267−* @return always 0
1268−*/
1269−static int fiji_process_firmware_header(struct pp_hwmgr *hwmgr)
1270−{
1271− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1272− struct fiji_smumgr *smu_data = (struct fiji_smumgr *)(hwmgr->smumgr->backend);
1273− uint32_t tmp;
1274− int result;
1275− bool error = false;
1276−
1277− result = fiji_read_smc_sram_dword(hwmgr->smumgr,
1278− SMU7_FIRMWARE_HEADER_LOCATION +
1279− offsetof(SMU73_Firmware_Header, DpmTable),
1280− &tmp, data->sram_end);
1281−
1282− if (0 == result)
1283− data->dpm_table_start = tmp;
1284−
1285− error |= (0 != result);
1286−
1287− result = fiji_read_smc_sram_dword(hwmgr->smumgr,
1288− SMU7_FIRMWARE_HEADER_LOCATION +
1289− offsetof(SMU73_Firmware_Header, SoftRegisters),
1290− &tmp, data->sram_end);
1291−
1292− if (!result) {
1293− data->soft_regs_start = tmp;
1294− smu_data->soft_regs_start = tmp;
1295− }
1296−
1297− error |= (0 != result);
1298−
1299− result = fiji_read_smc_sram_dword(hwmgr->smumgr,
1300− SMU7_FIRMWARE_HEADER_LOCATION +
1301− offsetof(SMU73_Firmware_Header, mcRegisterTable),
1302− &tmp, data->sram_end);
1303−
1304− if (!result)
1305− data->mc_reg_table_start = tmp;
1306−
1307− result = fiji_read_smc_sram_dword(hwmgr->smumgr,
1308− SMU7_FIRMWARE_HEADER_LOCATION +
1309− offsetof(SMU73_Firmware_Header, FanTable),
1310− &tmp, data->sram_end);
1311−
1312− if (!result)
1313− data->fan_table_start = tmp;
1314−
1315− error |= (0 != result);
1316−
1317− result = fiji_read_smc_sram_dword(hwmgr->smumgr,
1318− SMU7_FIRMWARE_HEADER_LOCATION +
1319− offsetof(SMU73_Firmware_Header, mcArbDramTimingTable),
1320− &tmp, data->sram_end);
1321−
1322− if (!result)
1323− data->arb_table_start = tmp;
1324−
1325− error |= (0 != result);
1326−
1327− result = fiji_read_smc_sram_dword(hwmgr->smumgr,
1328− SMU7_FIRMWARE_HEADER_LOCATION +
1329− offsetof(SMU73_Firmware_Header, Version),
1330− &tmp, data->sram_end);
1331−
1332− if (!result)
1333− hwmgr->microcode_version_info.SMC = tmp;
1334−
1335− error |= (0 != result);
1336−
1337− return error ? -1 : 0;
1338−}
1339−
1340−/* Copy one arb setting to another and then switch the active set.
1341− * arb_src and arb_dest is one of the MC_CG_ARB_FREQ_Fx constants.
1342− */
1343−static int fiji_copy_and_switch_arb_sets(struct pp_hwmgr *hwmgr,
1344− uint32_t arb_src, uint32_t arb_dest)
1345−{
1346− uint32_t mc_arb_dram_timing;
1347− uint32_t mc_arb_dram_timing2;
1348− uint32_t burst_time;
1349− uint32_t mc_cg_config;
1350−
1351− switch (arb_src) {
1352− case MC_CG_ARB_FREQ_F0:
1353− mc_arb_dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING);
1354− mc_arb_dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2);
1355− burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0);
1356− break;
1357− case MC_CG_ARB_FREQ_F1:
1358− mc_arb_dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING_1);
1359− mc_arb_dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2_1);
1360− burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE1);
1361− break;
1362− default:
1363− return -EINVAL;
1364− }
1365−
1366− switch (arb_dest) {
1367− case MC_CG_ARB_FREQ_F0:
1368− cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING, mc_arb_dram_timing);
1369− cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2, mc_arb_dram_timing2);
1370− PHM_WRITE_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0, burst_time);
1371− break;
1372− case MC_CG_ARB_FREQ_F1:
1373− cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING_1, mc_arb_dram_timing);
1374− cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2_1, mc_arb_dram_timing2);
1375− PHM_WRITE_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE1, burst_time);
1376− break;
1377− default:
1378− return -EINVAL;
1379− }
1380−
1381− mc_cg_config = cgs_read_register(hwmgr->device, mmMC_CG_CONFIG);
1382− mc_cg_config |= 0x0000000F;
1383− cgs_write_register(hwmgr->device, mmMC_CG_CONFIG, mc_cg_config);
1384− PHM_WRITE_FIELD(hwmgr->device, MC_ARB_CG, CG_ARB_REQ, arb_dest);
1385−
1386− return 0;
1387−}
1388−
1389−/**
1390−* Call SMC to reset S0/S1 to S1 and Reset SMIO to initial value
1391−*
1392−* @param hwmgr the address of the powerplay hardware manager.
1393−* @return if success then 0;
1394−*/
1395−static int fiji_reset_to_default(struct pp_hwmgr *hwmgr)
1396−{
1397− return smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_ResetToDefaults);
1398−}
1399−
1400−/**
1401−* Initial switch from ARB F0->F1
1402−*
1403−* @param hwmgr the address of the powerplay hardware manager.
1404−* @return always 0
1405−* This function is to be called from the SetPowerState table.
1406−*/
1407−static int fiji_initial_switch_from_arbf0_to_f1(struct pp_hwmgr *hwmgr)
1408−{
1409− return fiji_copy_and_switch_arb_sets(hwmgr,
1410− MC_CG_ARB_FREQ_F0, MC_CG_ARB_FREQ_F1);
1411−}
1412−
1413−static int fiji_force_switch_to_arbf0(struct pp_hwmgr *hwmgr)
1414−{
1415− uint32_t tmp;
1416−
1417− tmp = (cgs_read_ind_register(hwmgr->device,
1418− CGS_IND_REG__SMC, ixSMC_SCRATCH9) &
1419− 0x0000ff00) >> 8;
1420−
1421− if (tmp == MC_CG_ARB_FREQ_F0)
1422− return 0;
1423−
1424− return fiji_copy_and_switch_arb_sets(hwmgr,
1425− tmp, MC_CG_ARB_FREQ_F0);
1426−}
1427−
1428−static int fiji_reset_single_dpm_table(struct pp_hwmgr *hwmgr,
1429− struct fiji_single_dpm_table *dpm_table, uint32_t count)
1430−{
1431− int i;
1432− PP_ASSERT_WITH_CODE(count <= MAX_REGULAR_DPM_NUMBER,
1433− "Fatal error, can not set up single DPM table entries "
1434− "to exceed max number!",);
1435−
1436− dpm_table->count = count;
1437− for (i = 0; i < MAX_REGULAR_DPM_NUMBER; i++)
1438− dpm_table->dpm_levels[i].enabled = false;
1439−
1440− return 0;
1441−}
1442−
1443−static void fiji_setup_pcie_table_entry(
1444− struct fiji_single_dpm_table *dpm_table,
1445− uint32_t index, uint32_t pcie_gen,
1446− uint32_t pcie_lanes)
1447−{
1448− dpm_table->dpm_levels[index].value = pcie_gen;
1449− dpm_table->dpm_levels[index].param1 = pcie_lanes;
1450− dpm_table->dpm_levels[index].enabled = true;
1451−}
1452−
1453−static int fiji_setup_default_pcie_table(struct pp_hwmgr *hwmgr)
1454−{
1455− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1456− struct phm_ppt_v1_information *table_info =
1457− (struct phm_ppt_v1_information *)(hwmgr->pptable);
1458− struct phm_ppt_v1_pcie_table *pcie_table = table_info->pcie_table;
1459− uint32_t i, max_entry;
1460−
1461− PP_ASSERT_WITH_CODE((data->use_pcie_performance_levels ||
1462− data->use_pcie_power_saving_levels), "No pcie performance levels!",
1463− return -EINVAL);
1464−
1465− if (data->use_pcie_performance_levels &&
1466− !data->use_pcie_power_saving_levels) {
1467− data->pcie_gen_power_saving = data->pcie_gen_performance;
1468− data->pcie_lane_power_saving = data->pcie_lane_performance;
1469− } else if (!data->use_pcie_performance_levels &&
1470− data->use_pcie_power_saving_levels) {
1471− data->pcie_gen_performance = data->pcie_gen_power_saving;
1472− data->pcie_lane_performance = data->pcie_lane_power_saving;
1473− }
1474−
1475− fiji_reset_single_dpm_table(hwmgr,
1476− &data->dpm_table.pcie_speed_table, SMU73_MAX_LEVELS_LINK);
1477−
1478− if (pcie_table != NULL) {
1479− /* max_entry is used to make sure we reserve one PCIE level
1480− * for boot level (fix for A+A PSPP issue).
1481− * If PCIE table from PPTable have ULV entry + 8 entries,
1482− * then ignore the last entry.*/
1483− max_entry = (SMU73_MAX_LEVELS_LINK < pcie_table->count) ?
1484− SMU73_MAX_LEVELS_LINK : pcie_table->count;
1485− for (i = 1; i < max_entry; i++) {
1486− fiji_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, i - 1,
1487− get_pcie_gen_support(data->pcie_gen_cap,
1488− pcie_table->entries[i].gen_speed),
1489− get_pcie_lane_support(data->pcie_lane_cap,
1490− pcie_table->entries[i].lane_width));
1491− }
1492− data->dpm_table.pcie_speed_table.count = max_entry - 1;
1493− } else {
1494− /* Hardcode Pcie Table */
1495− fiji_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 0,
1496− get_pcie_gen_support(data->pcie_gen_cap,
1497− PP_Min_PCIEGen),
1498− get_pcie_lane_support(data->pcie_lane_cap,
1499− PP_Max_PCIELane));
1500− fiji_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 1,
1501− get_pcie_gen_support(data->pcie_gen_cap,
1502− PP_Min_PCIEGen),
1503− get_pcie_lane_support(data->pcie_lane_cap,
1504− PP_Max_PCIELane));
1505− fiji_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 2,
1506− get_pcie_gen_support(data->pcie_gen_cap,
1507− PP_Max_PCIEGen),
1508− get_pcie_lane_support(data->pcie_lane_cap,
1509− PP_Max_PCIELane));
1510− fiji_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 3,
1511− get_pcie_gen_support(data->pcie_gen_cap,
1512− PP_Max_PCIEGen),
1513− get_pcie_lane_support(data->pcie_lane_cap,
1514− PP_Max_PCIELane));
1515− fiji_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 4,
1516− get_pcie_gen_support(data->pcie_gen_cap,
1517− PP_Max_PCIEGen),
1518− get_pcie_lane_support(data->pcie_lane_cap,
1519− PP_Max_PCIELane));
1520− fiji_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 5,
1521− get_pcie_gen_support(data->pcie_gen_cap,
1522− PP_Max_PCIEGen),
1523− get_pcie_lane_support(data->pcie_lane_cap,
1524− PP_Max_PCIELane));
1525−
1526− data->dpm_table.pcie_speed_table.count = 6;
1527− }
1528− /* Populate last level for boot PCIE level, but do not increment count. */
1529− fiji_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table,
1530− data->dpm_table.pcie_speed_table.count,
1531− get_pcie_gen_support(data->pcie_gen_cap,
1532− PP_Min_PCIEGen),
1533− get_pcie_lane_support(data->pcie_lane_cap,
1534− PP_Max_PCIELane));
1535−
1536− return 0;
1537−}
1538−
1539−/*
1540− * This function is to initalize all DPM state tables
1541− * for SMU7 based on the dependency table.
1542− * Dynamic state patching function will then trim these
1543− * state tables to the allowed range based
1544− * on the power policy or external client requests,
1545− * such as UVD request, etc.
1546− */
1547−static int fiji_setup_default_dpm_tables(struct pp_hwmgr *hwmgr)
1548−{
1549− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1550− struct phm_ppt_v1_information *table_info =
1551− (struct phm_ppt_v1_information *)(hwmgr->pptable);
1552− uint32_t i;
1553−
1554− struct phm_ppt_v1_clock_voltage_dependency_table *dep_sclk_table =
1555− table_info->vdd_dep_on_sclk;
1556− struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table =
1557− table_info->vdd_dep_on_mclk;
1558−
1559− PP_ASSERT_WITH_CODE(dep_sclk_table != NULL,
1560− "SCLK dependency table is missing. This table is mandatory",
1561− return -EINVAL);
1562− PP_ASSERT_WITH_CODE(dep_sclk_table->count >= 1,
1563− "SCLK dependency table has to have is missing. "
1564− "This table is mandatory",
1565− return -EINVAL);
1566−
1567− PP_ASSERT_WITH_CODE(dep_mclk_table != NULL,
1568− "MCLK dependency table is missing. This table is mandatory",
1569− return -EINVAL);
1570− PP_ASSERT_WITH_CODE(dep_mclk_table->count >= 1,
1571− "MCLK dependency table has to have is missing. "
1572− "This table is mandatory",
1573− return -EINVAL);
1574−
1575− /* clear the state table to reset everything to default */
1576− fiji_reset_single_dpm_table(hwmgr,
1577− &data->dpm_table.sclk_table, SMU73_MAX_LEVELS_GRAPHICS);
1578− fiji_reset_single_dpm_table(hwmgr,
1579− &data->dpm_table.mclk_table, SMU73_MAX_LEVELS_MEMORY);
1580−
1581− /* Initialize Sclk DPM table based on allow Sclk values */
1582− data->dpm_table.sclk_table.count = 0;
1583− for (i = 0; i < dep_sclk_table->count; i++) {
1584− if (i == 0 || data->dpm_table.sclk_table.dpm_levels
1585− [data->dpm_table.sclk_table.count - 1].value !=
1586− dep_sclk_table->entries[i].clk) {
1587− data->dpm_table.sclk_table.dpm_levels
1588− [data->dpm_table.sclk_table.count].value =
1589− dep_sclk_table->entries[i].clk;
1590− data->dpm_table.sclk_table.dpm_levels
1591− [data->dpm_table.sclk_table.count].enabled =
1592− (i == 0) ? true : false;
1593− data->dpm_table.sclk_table.count++;
1594− }
1595− }
1596−
1597− /* Initialize Mclk DPM table based on allow Mclk values */
1598− data->dpm_table.mclk_table.count = 0;
1599− for (i=0; i<dep_mclk_table->count; i++) {
1600− if ( i==0 || data->dpm_table.mclk_table.dpm_levels
1601− [data->dpm_table.mclk_table.count - 1].value !=
1602− dep_mclk_table->entries[i].clk) {
1603− data->dpm_table.mclk_table.dpm_levels
1604− [data->dpm_table.mclk_table.count].value =
1605− dep_mclk_table->entries[i].clk;
1606− data->dpm_table.mclk_table.dpm_levels
1607− [data->dpm_table.mclk_table.count].enabled =
1608− (i == 0) ? true : false;
1609− data->dpm_table.mclk_table.count++;
1610− }
1611− }
1612−
1613− /* setup PCIE gen speed levels */
1614− fiji_setup_default_pcie_table(hwmgr);
1615−
1616− /* save a copy of the default DPM table */
1617− memcpy(&(data->golden_dpm_table), &(data->dpm_table),
1618− sizeof(struct fiji_dpm_table));
1619−
1620− return 0;
1621−}
1622−
1623−/**
1624− * @brief PhwFiji_GetVoltageOrder
1625− * Returns index of requested voltage record in lookup(table)
1626− * @param lookup_table - lookup list to search in
1627− * @param voltage - voltage to look for
1628− * @return 0 on success
1629− */
1630−static uint8_t fiji_get_voltage_index(
1631− struct phm_ppt_v1_voltage_lookup_table *lookup_table, uint16_t voltage)
1632−{
1633− uint8_t count = (uint8_t) (lookup_table->count);
1634− uint8_t i;
1635−
1636− PP_ASSERT_WITH_CODE((NULL != lookup_table),
1637− "Lookup Table empty.", return 0);
1638− PP_ASSERT_WITH_CODE((0 != count),
1639− "Lookup Table empty.", return 0);
1640−
1641− for (i = 0; i < lookup_table->count; i++) {
1642− /* find first voltage equal or bigger than requested */
1643− if (lookup_table->entries[i].us_vdd >= voltage)
1644− return i;
1645− }
1646− /* voltage is bigger than max voltage in the table */
1647− return i - 1;
1648−}
1649−
1650−/**
1651−* Preparation of vddc and vddgfx CAC tables for SMC.
1652−*
1653−* @param hwmgr the address of the hardware manager
1654−* @param table the SMC DPM table structure to be populated
1655−* @return always 0
1656−*/
1657−static int fiji_populate_cac_table(struct pp_hwmgr *hwmgr,
1658− struct SMU73_Discrete_DpmTable *table)
1659−{
1660− uint32_t count;
1661− uint8_t index;
1662− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1663− struct phm_ppt_v1_information *table_info =
1664− (struct phm_ppt_v1_information *)(hwmgr->pptable);
1665− struct phm_ppt_v1_voltage_lookup_table *lookup_table =
1666− table_info->vddc_lookup_table;
1667− /* tables is already swapped, so in order to use the value from it,
1668− * we need to swap it back.
1669− * We are populating vddc CAC data to BapmVddc table
1670− * in split and merged mode
1671− */
1672− for( count = 0; count<lookup_table->count; count++) {
1673− index = fiji_get_voltage_index(lookup_table,
1674− data->vddc_voltage_table.entries[count].value);
1675− table->BapmVddcVidLoSidd[count] = (uint8_t) ((6200 -
1676− (lookup_table->entries[index].us_cac_low *
1677− VOLTAGE_SCALE)) / 25);
1678− table->BapmVddcVidHiSidd[count] = (uint8_t) ((6200 -
1679− (lookup_table->entries[index].us_cac_high *
1680− VOLTAGE_SCALE)) / 25);
1681− }
1682−
1683− return 0;
1684−}
1685−
1686−/**
1687−* Preparation of voltage tables for SMC.
1688−*
1689−* @param hwmgr the address of the hardware manager
1690−* @param table the SMC DPM table structure to be populated
1691−* @return always 0
1692−*/
1693−
1694−static int fiji_populate_smc_voltage_tables(struct pp_hwmgr *hwmgr,
1695− struct SMU73_Discrete_DpmTable *table)
1696−{
1697− int result;
1698−
1699− result = fiji_populate_cac_table(hwmgr, table);
1700− PP_ASSERT_WITH_CODE(0 == result,
1701− "can not populate CAC voltage tables to SMC",
1702− return -EINVAL);
1703−
1704− return 0;
1705−}
1706−
1707−static int fiji_populate_ulv_level(struct pp_hwmgr *hwmgr,
1708− struct SMU73_Discrete_Ulv *state)
1709−{
1710− int result = 0;
1711− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1712− struct phm_ppt_v1_information *table_info =
1713− (struct phm_ppt_v1_information *)(hwmgr->pptable);
1714−
1715− state->CcPwrDynRm = 0;
1716− state->CcPwrDynRm1 = 0;
1717−
1718− state->VddcOffset = (uint16_t) table_info->us_ulv_voltage_offset;
1719− state->VddcOffsetVid = (uint8_t)( table_info->us_ulv_voltage_offset *
1720− VOLTAGE_VID_OFFSET_SCALE2 / VOLTAGE_VID_OFFSET_SCALE1 );
1721−
1722− state->VddcPhase = (data->vddc_phase_shed_control) ? 0 : 1;
1723−
1724− if (!result) {
1725− CONVERT_FROM_HOST_TO_SMC_UL(state->CcPwrDynRm);
1726− CONVERT_FROM_HOST_TO_SMC_UL(state->CcPwrDynRm1);
1727− CONVERT_FROM_HOST_TO_SMC_US(state->VddcOffset);
1728− }
1729− return result;
1730−}
1731−
1732−static int fiji_populate_ulv_state(struct pp_hwmgr *hwmgr,
1733− struct SMU73_Discrete_DpmTable *table)
1734−{
1735− return fiji_populate_ulv_level(hwmgr, &table->Ulv);
1736−}
1737−
1738−static int32_t fiji_get_dpm_level_enable_mask_value(
1739− struct fiji_single_dpm_table* dpm_table)
1740−{
1741− int32_t i;
1742− int32_t mask = 0;
1743−
1744− for (i = dpm_table->count; i > 0; i--) {
1745− mask = mask << 1;
1746− if (dpm_table->dpm_levels[i - 1].enabled)
1747− mask |= 0x1;
1748− else
1749− mask &= 0xFFFFFFFE;
1750− }
1751− return mask;
1752−}
1753−
1754−static int fiji_populate_smc_link_level(struct pp_hwmgr *hwmgr,
1755− struct SMU73_Discrete_DpmTable *table)
1756−{
1757− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1758− struct fiji_dpm_table *dpm_table = &data->dpm_table;
1759− int i;
1760−
1761− /* Index (dpm_table->pcie_speed_table.count)
1762− * is reserved for PCIE boot level. */
1763− for (i = 0; i <= dpm_table->pcie_speed_table.count; i++) {
1764− table->LinkLevel[i].PcieGenSpeed =
1765− (uint8_t)dpm_table->pcie_speed_table.dpm_levels[i].value;
1766− table->LinkLevel[i].PcieLaneCount = (uint8_t)encode_pcie_lane_width(
1767− dpm_table->pcie_speed_table.dpm_levels[i].param1);
1768− table->LinkLevel[i].EnabledForActivity = 1;
1769− table->LinkLevel[i].SPC = (uint8_t)(data->pcie_spc_cap & 0xff);
1770− table->LinkLevel[i].DownThreshold = PP_HOST_TO_SMC_UL(5);
1771− table->LinkLevel[i].UpThreshold = PP_HOST_TO_SMC_UL(30);
1772− }
1773−
1774− data->smc_state_table.LinkLevelCount =
1775− (uint8_t)dpm_table->pcie_speed_table.count;
1776− data->dpm_level_enable_mask.pcie_dpm_enable_mask =
1777− fiji_get_dpm_level_enable_mask_value(&dpm_table->pcie_speed_table);
1778−
1779− return 0;
1780−}
1781−
1782−/**
1783−* Calculates the SCLK dividers using the provided engine clock
1784−*
1785−* @param hwmgr the address of the hardware manager
1786−* @param clock the engine clock to use to populate the structure
1787−* @param sclk the SMC SCLK structure to be populated
1788−*/
1789−static int fiji_calculate_sclk_params(struct pp_hwmgr *hwmgr,
1790− uint32_t clock, struct SMU73_Discrete_GraphicsLevel *sclk)
1791−{
1792− const struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1793− struct pp_atomctrl_clock_dividers_vi dividers;
1794− uint32_t spll_func_cntl = data->clock_registers.vCG_SPLL_FUNC_CNTL;
1795− uint32_t spll_func_cntl_3 = data->clock_registers.vCG_SPLL_FUNC_CNTL_3;
1796− uint32_t spll_func_cntl_4 = data->clock_registers.vCG_SPLL_FUNC_CNTL_4;
1797− uint32_t cg_spll_spread_spectrum = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM;
1798− uint32_t cg_spll_spread_spectrum_2 = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM_2;
1799− uint32_t ref_clock;
1800− uint32_t ref_divider;
1801− uint32_t fbdiv;
1802− int result;
1803−
1804− /* get the engine clock dividers for this clock value */
1805− result = atomctrl_get_engine_pll_dividers_vi(hwmgr, clock, &dividers);
1806−
1807− PP_ASSERT_WITH_CODE(result == 0,
1808− "Error retrieving Engine Clock dividers from VBIOS.",
1809− return result);
1810−
1811− /* To get FBDIV we need to multiply this by 16384 and divide it by Fref. */
1812− ref_clock = atomctrl_get_reference_clock(hwmgr);
1813− ref_divider = 1 + dividers.uc_pll_ref_div;
1814−
1815− /* low 14 bits is fraction and high 12 bits is divider */
1816− fbdiv = dividers.ul_fb_div.ul_fb_divider & 0x3FFFFFF;
1817−
1818− /* SPLL_FUNC_CNTL setup */
1819− spll_func_cntl = PHM_SET_FIELD(spll_func_cntl, CG_SPLL_FUNC_CNTL,
1820− SPLL_REF_DIV, dividers.uc_pll_ref_div);
1821− spll_func_cntl = PHM_SET_FIELD(spll_func_cntl, CG_SPLL_FUNC_CNTL,
1822− SPLL_PDIV_A, dividers.uc_pll_post_div);
1823−
1824− /* SPLL_FUNC_CNTL_3 setup*/
1825− spll_func_cntl_3 = PHM_SET_FIELD(spll_func_cntl_3, CG_SPLL_FUNC_CNTL_3,
1826− SPLL_FB_DIV, fbdiv);
1827−
1828− /* set to use fractional accumulation*/
1829− spll_func_cntl_3 = PHM_SET_FIELD(spll_func_cntl_3, CG_SPLL_FUNC_CNTL_3,
1830− SPLL_DITHEN, 1);
1831−
1832− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1833− PHM_PlatformCaps_EngineSpreadSpectrumSupport)) {
1834− struct pp_atomctrl_internal_ss_info ssInfo;
1835−
1836− uint32_t vco_freq = clock * dividers.uc_pll_post_div;
1837− if (!atomctrl_get_engine_clock_spread_spectrum(hwmgr,
1838− vco_freq, &ssInfo)) {
1839− /*
1840− * ss_info.speed_spectrum_percentage -- in unit of 0.01%
1841− * ss_info.speed_spectrum_rate -- in unit of khz
1842− *
1843− * clks = reference_clock * 10 / (REFDIV + 1) / speed_spectrum_rate / 2
1844− */
1845− uint32_t clk_s = ref_clock * 5 /
1846− (ref_divider * ssInfo.speed_spectrum_rate);
1847− /* clkv = 2 * D * fbdiv / NS */
1848− uint32_t clk_v = 4 * ssInfo.speed_spectrum_percentage *
1849− fbdiv / (clk_s * 10000);
1850−
1851− cg_spll_spread_spectrum = PHM_SET_FIELD(cg_spll_spread_spectrum,
1852− CG_SPLL_SPREAD_SPECTRUM, CLKS, clk_s);
1853− cg_spll_spread_spectrum = PHM_SET_FIELD(cg_spll_spread_spectrum,
1854− CG_SPLL_SPREAD_SPECTRUM, SSEN, 1);
1855− cg_spll_spread_spectrum_2 = PHM_SET_FIELD(cg_spll_spread_spectrum_2,
1856− CG_SPLL_SPREAD_SPECTRUM_2, CLKV, clk_v);
1857− }
1858− }
1859−
1860− sclk->SclkFrequency = clock;
1861− sclk->CgSpllFuncCntl3 = spll_func_cntl_3;
1862− sclk->CgSpllFuncCntl4 = spll_func_cntl_4;
1863− sclk->SpllSpreadSpectrum = cg_spll_spread_spectrum;
1864− sclk->SpllSpreadSpectrum2 = cg_spll_spread_spectrum_2;
1865− sclk->SclkDid = (uint8_t)dividers.pll_post_divider;
1866−
1867− return 0;
1868−}
1869−
1870−static uint16_t fiji_find_closest_vddci(struct pp_hwmgr *hwmgr, uint16_t vddci)
1871−{
1872− uint32_t i;
1873− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1874− struct pp_atomctrl_voltage_table *vddci_table =
1875− &(data->vddci_voltage_table);
1876−
1877− for (i = 0; i < vddci_table->count; i++) {
1878− if (vddci_table->entries[i].value >= vddci)
1879− return vddci_table->entries[i].value;
1880− }
1881−
1882− PP_ASSERT_WITH_CODE(false,
1883− "VDDCI is larger than max VDDCI in VDDCI Voltage Table!",
1884− return vddci_table->entries[i-1].value);
1885−}
1886−
1887−static int fiji_get_dependency_volt_by_clk(struct pp_hwmgr *hwmgr,
1888− struct phm_ppt_v1_clock_voltage_dependency_table* dep_table,
1889− uint32_t clock, SMU_VoltageLevel *voltage, uint32_t *mvdd)
1890−{
1891− uint32_t i;
1892− uint16_t vddci;
1893− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1894−
1895− *voltage = *mvdd = 0;
1896−
1897− /* clock - voltage dependency table is empty table */
1898− if (dep_table->count == 0)
1899− return -EINVAL;
1900−
1901− for (i = 0; i < dep_table->count; i++) {
1902− /* find first sclk bigger than request */
1903− if (dep_table->entries[i].clk >= clock) {
1904− *voltage |= (dep_table->entries[i].vddc *
1905− VOLTAGE_SCALE) << VDDC_SHIFT;
1906− if (FIJI_VOLTAGE_CONTROL_NONE == data->vddci_control)
1907− *voltage |= (data->vbios_boot_state.vddci_bootup_value *
1908− VOLTAGE_SCALE) << VDDCI_SHIFT;
1909− else if (dep_table->entries[i].vddci)
1910− *voltage |= (dep_table->entries[i].vddci *
1911− VOLTAGE_SCALE) << VDDCI_SHIFT;
1912− else {
1913− vddci = fiji_find_closest_vddci(hwmgr,
1914− (dep_table->entries[i].vddc -
1915− (uint16_t)data->vddc_vddci_delta));
1916− *voltage |= (vddci * VOLTAGE_SCALE) << VDDCI_SHIFT;
1917− }
1918−
1919− if (FIJI_VOLTAGE_CONTROL_NONE == data->mvdd_control)
1920− *mvdd = data->vbios_boot_state.mvdd_bootup_value *
1921− VOLTAGE_SCALE;
1922− else if (dep_table->entries[i].mvdd)
1923− *mvdd = (uint32_t) dep_table->entries[i].mvdd *
1924− VOLTAGE_SCALE;
1925−
1926− *voltage |= 1 << PHASES_SHIFT;
1927− return 0;
1928− }
1929− }
1930−
1931− /* sclk is bigger than max sclk in the dependence table */
1932− *voltage |= (dep_table->entries[i - 1].vddc * VOLTAGE_SCALE) << VDDC_SHIFT;
1933−
1934− if (FIJI_VOLTAGE_CONTROL_NONE == data->vddci_control)
1935− *voltage |= (data->vbios_boot_state.vddci_bootup_value *
1936− VOLTAGE_SCALE) << VDDCI_SHIFT;
1937− else if (dep_table->entries[i-1].vddci) {
1938− vddci = fiji_find_closest_vddci(hwmgr,
1939− (dep_table->entries[i].vddc -
1940− (uint16_t)data->vddc_vddci_delta));
1941− *voltage |= (vddci * VOLTAGE_SCALE) << VDDCI_SHIFT;
1942− }
1943−
1944− if (FIJI_VOLTAGE_CONTROL_NONE == data->mvdd_control)
1945− *mvdd = data->vbios_boot_state.mvdd_bootup_value * VOLTAGE_SCALE;
1946− else if (dep_table->entries[i].mvdd)
1947− *mvdd = (uint32_t) dep_table->entries[i - 1].mvdd * VOLTAGE_SCALE;
1948−
1949− return 0;
1950−}
1951−
1952−static uint8_t fiji_get_sleep_divider_id_from_clock(uint32_t clock,
1953− uint32_t clock_insr)
1954−{
1955− uint8_t i;
1956− uint32_t temp;
1957− uint32_t min = max(clock_insr, (uint32_t)FIJI_MINIMUM_ENGINE_CLOCK);
1958−
1959− PP_ASSERT_WITH_CODE((clock >= min), "Engine clock can't satisfy stutter requirement!", return 0);
1960− for (i = FIJI_MAX_DEEPSLEEP_DIVIDER_ID; ; i--) {
1961− temp = clock >> i;
1962−
1963− if (temp >= min || i == 0)
1964− break;
1965− }
1966− return i;
1967−}
1968−/**
1969−* Populates single SMC SCLK structure using the provided engine clock
1970−*
1971−* @param hwmgr the address of the hardware manager
1972−* @param clock the engine clock to use to populate the structure
1973−* @param sclk the SMC SCLK structure to be populated
1974−*/
1975−
1976−static int fiji_populate_single_graphic_level(struct pp_hwmgr *hwmgr,
1977− uint32_t clock, uint16_t sclk_al_threshold,
1978− struct SMU73_Discrete_GraphicsLevel *level)
1979−{
1980− int result;
1981− /* PP_Clocks minClocks; */
1982− uint32_t threshold, mvdd;
1983− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1984− struct phm_ppt_v1_information *table_info =
1985− (struct phm_ppt_v1_information *)(hwmgr->pptable);
1986−
1987− result = fiji_calculate_sclk_params(hwmgr, clock, level);
1988−
1989− /* populate graphics levels */
1990− result = fiji_get_dependency_volt_by_clk(hwmgr,
1991− table_info->vdd_dep_on_sclk, clock,
1992− &level->MinVoltage, &mvdd);
1993− PP_ASSERT_WITH_CODE((0 == result),
1994− "can not find VDDC voltage value for "
1995− "VDDC engine clock dependency table",
1996− return result);
1997−
1998− level->SclkFrequency = clock;
1999− level->ActivityLevel = sclk_al_threshold;
2000− level->CcPwrDynRm = 0;
2001− level->CcPwrDynRm1 = 0;
2002− level->EnabledForActivity = 0;
2003− level->EnabledForThrottle = 1;
2004− level->UpHyst = 10;
2005− level->DownHyst = 0;
2006− level->VoltageDownHyst = 0;
2007− level->PowerThrottle = 0;
2008−
2009− threshold = clock * data->fast_watermark_threshold / 100;
2010−
2011−
2012− data->display_timing.min_clock_in_sr = hwmgr->display_config.min_core_set_clock_in_sr;
2013−
2014− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_SclkDeepSleep))
2015− level->DeepSleepDivId = fiji_get_sleep_divider_id_from_clock(clock,
2016− hwmgr->display_config.min_core_set_clock_in_sr);
2017−
2018−
2019− /* Default to slow, highest DPM level will be
2020− * set to PPSMC_DISPLAY_WATERMARK_LOW later.
2021− */
2022− level->DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW;
2023−
2024− CONVERT_FROM_HOST_TO_SMC_UL(level->MinVoltage);
2025− CONVERT_FROM_HOST_TO_SMC_UL(level->SclkFrequency);
2026− CONVERT_FROM_HOST_TO_SMC_US(level->ActivityLevel);
2027− CONVERT_FROM_HOST_TO_SMC_UL(level->CgSpllFuncCntl3);
2028− CONVERT_FROM_HOST_TO_SMC_UL(level->CgSpllFuncCntl4);
2029− CONVERT_FROM_HOST_TO_SMC_UL(level->SpllSpreadSpectrum);
2030− CONVERT_FROM_HOST_TO_SMC_UL(level->SpllSpreadSpectrum2);
2031− CONVERT_FROM_HOST_TO_SMC_UL(level->CcPwrDynRm);
2032− CONVERT_FROM_HOST_TO_SMC_UL(level->CcPwrDynRm1);
2033−
2034− return 0;
2035−}
2036−/**
2037−* Populates all SMC SCLK levels' structure based on the trimmed allowed dpm engine clock states
2038−*
2039−* @param hwmgr the address of the hardware manager
2040−*/
2041−static int fiji_populate_all_graphic_levels(struct pp_hwmgr *hwmgr)
2042−{
2043− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2044− struct fiji_dpm_table *dpm_table = &data->dpm_table;
2045− struct phm_ppt_v1_information *table_info =
2046− (struct phm_ppt_v1_information *)(hwmgr->pptable);
2047− struct phm_ppt_v1_pcie_table *pcie_table = table_info->pcie_table;
2048− uint8_t pcie_entry_cnt = (uint8_t) data->dpm_table.pcie_speed_table.count;
2049− int result = 0;
2050− uint32_t array = data->dpm_table_start +
2051− offsetof(SMU73_Discrete_DpmTable, GraphicsLevel);
2052− uint32_t array_size = sizeof(struct SMU73_Discrete_GraphicsLevel) *
2053− SMU73_MAX_LEVELS_GRAPHICS;
2054− struct SMU73_Discrete_GraphicsLevel *levels =
2055− data->smc_state_table.GraphicsLevel;
2056− uint32_t i, max_entry;
2057− uint8_t hightest_pcie_level_enabled = 0,
2058− lowest_pcie_level_enabled = 0,
2059− mid_pcie_level_enabled = 0,
2060− count = 0;
2061−
2062− for (i = 0; i < dpm_table->sclk_table.count; i++) {
2063− result = fiji_populate_single_graphic_level(hwmgr,
2064− dpm_table->sclk_table.dpm_levels[i].value,
2065− (uint16_t)data->activity_target[i],
2066− &levels[i]);
2067− if (result)
2068− return result;
2069−
2070− /* Making sure only DPM level 0-1 have Deep Sleep Div ID populated. */
2071− if (i > 1)
2072− levels[i].DeepSleepDivId = 0;
2073− }
2074−
2075− /* Only enable level 0 for now.*/
2076− levels[0].EnabledForActivity = 1;
2077−
2078− /* set highest level watermark to high */
2079− levels[dpm_table->sclk_table.count - 1].DisplayWatermark =
2080− PPSMC_DISPLAY_WATERMARK_HIGH;
2081−
2082− data->smc_state_table.GraphicsDpmLevelCount =
2083− (uint8_t)dpm_table->sclk_table.count;
2084− data->dpm_level_enable_mask.sclk_dpm_enable_mask =
2085− fiji_get_dpm_level_enable_mask_value(&dpm_table->sclk_table);
2086−
2087− if (pcie_table != NULL) {
2088− PP_ASSERT_WITH_CODE((1 <= pcie_entry_cnt),
2089− "There must be 1 or more PCIE levels defined in PPTable.",
2090− return -EINVAL);
2091− max_entry = pcie_entry_cnt - 1;
2092− for (i = 0; i < dpm_table->sclk_table.count; i++)
2093− levels[i].pcieDpmLevel =
2094− (uint8_t) ((i < max_entry)? i : max_entry);
2095− } else {
2096− while (data->dpm_level_enable_mask.pcie_dpm_enable_mask &&
2097− ((data->dpm_level_enable_mask.pcie_dpm_enable_mask &
2098− (1 << (hightest_pcie_level_enabled + 1))) != 0 ))
2099− hightest_pcie_level_enabled++;
2100−
2101− while (data->dpm_level_enable_mask.pcie_dpm_enable_mask &&
2102− ((data->dpm_level_enable_mask.pcie_dpm_enable_mask &
2103− (1 << lowest_pcie_level_enabled)) == 0 ))
2104− lowest_pcie_level_enabled++;
2105−
2106− while ((count < hightest_pcie_level_enabled) &&
2107− ((data->dpm_level_enable_mask.pcie_dpm_enable_mask &
2108− (1 << (lowest_pcie_level_enabled + 1 + count))) == 0 ))
2109− count++;
2110−
2111− mid_pcie_level_enabled = (lowest_pcie_level_enabled + 1+ count) <
2112− hightest_pcie_level_enabled?
2113− (lowest_pcie_level_enabled + 1 + count) :
2114− hightest_pcie_level_enabled;
2115−
2116− /* set pcieDpmLevel to hightest_pcie_level_enabled */
2117− for(i = 2; i < dpm_table->sclk_table.count; i++)
2118− levels[i].pcieDpmLevel = hightest_pcie_level_enabled;
2119−
2120− /* set pcieDpmLevel to lowest_pcie_level_enabled */
2121− levels[0].pcieDpmLevel = lowest_pcie_level_enabled;
2122−
2123− /* set pcieDpmLevel to mid_pcie_level_enabled */
2124− levels[1].pcieDpmLevel = mid_pcie_level_enabled;
2125− }
2126− /* level count will send to smc once at init smc table and never change */
2127− result = fiji_copy_bytes_to_smc(hwmgr->smumgr, array, (uint8_t *)levels,
2128− (uint32_t)array_size, data->sram_end);
2129−
2130− return result;
2131−}
2132−
2133−/**
2134− * MCLK Frequency Ratio
2135− * SEQ_CG_RESP Bit[31:24] - 0x0
2136− * Bit[27:24] \96 DDR3 Frequency ratio
2137− * 0x0 <= 100MHz, 450 < 0x8 <= 500MHz
2138− * 100 < 0x1 <= 150MHz, 500 < 0x9 <= 550MHz
2139− * 150 < 0x2 <= 200MHz, 550 < 0xA <= 600MHz
2140− * 200 < 0x3 <= 250MHz, 600 < 0xB <= 650MHz
2141− * 250 < 0x4 <= 300MHz, 650 < 0xC <= 700MHz
2142− * 300 < 0x5 <= 350MHz, 700 < 0xD <= 750MHz
2143− * 350 < 0x6 <= 400MHz, 750 < 0xE <= 800MHz
2144− * 400 < 0x7 <= 450MHz, 800 < 0xF
2145− */
2146−static uint8_t fiji_get_mclk_frequency_ratio(uint32_t mem_clock)
2147−{
2148− if (mem_clock <= 10000) return 0x0;
2149− if (mem_clock <= 15000) return 0x1;
2150− if (mem_clock <= 20000) return 0x2;
2151− if (mem_clock <= 25000) return 0x3;
2152− if (mem_clock <= 30000) return 0x4;
2153− if (mem_clock <= 35000) return 0x5;
2154− if (mem_clock <= 40000) return 0x6;
2155− if (mem_clock <= 45000) return 0x7;
2156− if (mem_clock <= 50000) return 0x8;
2157− if (mem_clock <= 55000) return 0x9;
2158− if (mem_clock <= 60000) return 0xa;
2159− if (mem_clock <= 65000) return 0xb;
2160− if (mem_clock <= 70000) return 0xc;
2161− if (mem_clock <= 75000) return 0xd;
2162− if (mem_clock <= 80000) return 0xe;
2163− /* mem_clock > 800MHz */
2164− return 0xf;
2165−}
2166−
2167−/**
2168−* Populates the SMC MCLK structure using the provided memory clock
2169−*
2170−* @param hwmgr the address of the hardware manager
2171−* @param clock the memory clock to use to populate the structure
2172−* @param sclk the SMC SCLK structure to be populated
2173−*/
2174−static int fiji_calculate_mclk_params(struct pp_hwmgr *hwmgr,
2175− uint32_t clock, struct SMU73_Discrete_MemoryLevel *mclk)
2176−{
2177− struct pp_atomctrl_memory_clock_param mem_param;
2178− int result;
2179−
2180− result = atomctrl_get_memory_pll_dividers_vi(hwmgr, clock, &mem_param);
2181− PP_ASSERT_WITH_CODE((0 == result),
2182− "Failed to get Memory PLL Dividers.",);
2183−
2184− /* Save the result data to outpupt memory level structure */
2185− mclk->MclkFrequency = clock;
2186− mclk->MclkDivider = (uint8_t)mem_param.mpll_post_divider;
2187− mclk->FreqRange = fiji_get_mclk_frequency_ratio(clock);
2188−
2189− return result;
2190−}
2191−
2192−static int fiji_populate_single_memory_level(struct pp_hwmgr *hwmgr,
2193− uint32_t clock, struct SMU73_Discrete_MemoryLevel *mem_level)
2194−{
2195− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2196− struct phm_ppt_v1_information *table_info =
2197− (struct phm_ppt_v1_information *)(hwmgr->pptable);
2198− int result = 0;
2199−
2200− if (table_info->vdd_dep_on_mclk) {
2201− result = fiji_get_dependency_volt_by_clk(hwmgr,
2202− table_info->vdd_dep_on_mclk, clock,
2203− &mem_level->MinVoltage, &mem_level->MinMvdd);
2204− PP_ASSERT_WITH_CODE((0 == result),
2205− "can not find MinVddc voltage value from memory "
2206− "VDDC voltage dependency table", return result);
2207− }
2208−
2209− mem_level->EnabledForThrottle = 1;
2210− mem_level->EnabledForActivity = 0;
2211− mem_level->UpHyst = 0;
2212− mem_level->DownHyst = 100;
2213− mem_level->VoltageDownHyst = 0;
2214− mem_level->ActivityLevel = (uint16_t)data->mclk_activity_target;
2215− mem_level->StutterEnable = false;
2216−
2217− mem_level->DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW;
2218−
2219− /* enable stutter mode if all the follow condition applied
2220− * PECI_GetNumberOfActiveDisplays(hwmgr->pPECI,
2221− * &(data->DisplayTiming.numExistingDisplays));
2222− */
2223− data->display_timing.num_existing_displays = 1;
2224−
2225− if ((data->mclk_stutter_mode_threshold) &&
2226− (clock <= data->mclk_stutter_mode_threshold) &&
2227− (!data->is_uvd_enabled) &&
2228− (PHM_READ_FIELD(hwmgr->device, DPG_PIPE_STUTTER_CONTROL,
2229− STUTTER_ENABLE) & 0x1))
2230− mem_level->StutterEnable = true;
2231−
2232− result = fiji_calculate_mclk_params(hwmgr, clock, mem_level);
2233− if (!result) {
2234− CONVERT_FROM_HOST_TO_SMC_UL(mem_level->MinMvdd);
2235− CONVERT_FROM_HOST_TO_SMC_UL(mem_level->MclkFrequency);
2236− CONVERT_FROM_HOST_TO_SMC_US(mem_level->ActivityLevel);
2237− CONVERT_FROM_HOST_TO_SMC_UL(mem_level->MinVoltage);
2238− }
2239− return result;
2240−}
2241−
2242−/**
2243−* Populates all SMC MCLK levels' structure based on the trimmed allowed dpm memory clock states
2244−*
2245−* @param hwmgr the address of the hardware manager
2246−*/
2247−static int fiji_populate_all_memory_levels(struct pp_hwmgr *hwmgr)
2248−{
2249− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2250− struct fiji_dpm_table *dpm_table = &data->dpm_table;
2251− int result;
2252− /* populate MCLK dpm table to SMU7 */
2253− uint32_t array = data->dpm_table_start +
2254− offsetof(SMU73_Discrete_DpmTable, MemoryLevel);
2255− uint32_t array_size = sizeof(SMU73_Discrete_MemoryLevel) *
2256− SMU73_MAX_LEVELS_MEMORY;
2257− struct SMU73_Discrete_MemoryLevel *levels =
2258− data->smc_state_table.MemoryLevel;
2259− uint32_t i;
2260−
2261− for (i = 0; i < dpm_table->mclk_table.count; i++) {
2262− PP_ASSERT_WITH_CODE((0 != dpm_table->mclk_table.dpm_levels[i].value),
2263− "can not populate memory level as memory clock is zero",
2264− return -EINVAL);
2265− result = fiji_populate_single_memory_level(hwmgr,
2266− dpm_table->mclk_table.dpm_levels[i].value,
2267− &levels[i]);
2268− if (result)
2269− return result;
2270− }
2271−
2272− /* Only enable level 0 for now. */
2273− levels[0].EnabledForActivity = 1;
2274−
2275− /* in order to prevent MC activity from stutter mode to push DPM up.
2276− * the UVD change complements this by putting the MCLK in
2277− * a higher state by default such that we are not effected by
2278− * up threshold or and MCLK DPM latency.
2279− */
2280− levels[0].ActivityLevel = (uint16_t)data->mclk_dpm0_activity_target;
2281− CONVERT_FROM_HOST_TO_SMC_US(levels[0].ActivityLevel);
2282−
2283− data->smc_state_table.MemoryDpmLevelCount =
2284− (uint8_t)dpm_table->mclk_table.count;
2285− data->dpm_level_enable_mask.mclk_dpm_enable_mask =
2286− fiji_get_dpm_level_enable_mask_value(&dpm_table->mclk_table);
2287− /* set highest level watermark to high */
2288− levels[dpm_table->mclk_table.count - 1].DisplayWatermark =
2289− PPSMC_DISPLAY_WATERMARK_HIGH;
2290−
2291− /* level count will send to smc once at init smc table and never change */
2292− result = fiji_copy_bytes_to_smc(hwmgr->smumgr, array, (uint8_t *)levels,
2293− (uint32_t)array_size, data->sram_end);
2294−
2295− return result;
2296−}
2297−
2298−/**
2299−* Populates the SMC MVDD structure using the provided memory clock.
2300−*
2301−* @param hwmgr the address of the hardware manager
2302−* @param mclk the MCLK value to be used in the decision if MVDD should be high or low.
2303−* @param voltage the SMC VOLTAGE structure to be populated
2304−*/
2305−static int fiji_populate_mvdd_value(struct pp_hwmgr *hwmgr,
2306− uint32_t mclk, SMIO_Pattern *smio_pat)
2307−{
2308− const struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2309− struct phm_ppt_v1_information *table_info =
2310− (struct phm_ppt_v1_information *)(hwmgr->pptable);
2311− uint32_t i = 0;
2312−
2313− if (FIJI_VOLTAGE_CONTROL_NONE != data->mvdd_control) {
2314− /* find mvdd value which clock is more than request */
2315− for (i = 0; i < table_info->vdd_dep_on_mclk->count; i++) {
2316− if (mclk <= table_info->vdd_dep_on_mclk->entries[i].clk) {
2317− smio_pat->Voltage = data->mvdd_voltage_table.entries[i].value;
2318− break;
2319− }
2320− }
2321− PP_ASSERT_WITH_CODE(i < table_info->vdd_dep_on_mclk->count,
2322− "MVDD Voltage is outside the supported range.",
2323− return -EINVAL);
2324− } else
2325− return -EINVAL;
2326−
2327− return 0;
2328−}
2329−
2330−static int fiji_populate_smc_acpi_level(struct pp_hwmgr *hwmgr,
2331− SMU73_Discrete_DpmTable *table)
2332−{
2333− int result = 0;
2334− const struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2335− struct phm_ppt_v1_information *table_info =
2336− (struct phm_ppt_v1_information *)(hwmgr->pptable);
2337− struct pp_atomctrl_clock_dividers_vi dividers;
2338− SMIO_Pattern vol_level;
2339− uint32_t mvdd;
2340− uint16_t us_mvdd;
2341− uint32_t spll_func_cntl = data->clock_registers.vCG_SPLL_FUNC_CNTL;
2342− uint32_t spll_func_cntl_2 = data->clock_registers.vCG_SPLL_FUNC_CNTL_2;
2343−
2344− table->ACPILevel.Flags &= ~PPSMC_SWSTATE_FLAG_DC;
2345−
2346− if (!data->sclk_dpm_key_disabled) {
2347− /* Get MinVoltage and Frequency from DPM0,
2348− * already converted to SMC_UL */
2349− table->ACPILevel.SclkFrequency =
2350− data->dpm_table.sclk_table.dpm_levels[0].value;
2351− result = fiji_get_dependency_volt_by_clk(hwmgr,
2352− table_info->vdd_dep_on_sclk,
2353− table->ACPILevel.SclkFrequency,
2354− &table->ACPILevel.MinVoltage, &mvdd);
2355− PP_ASSERT_WITH_CODE((0 == result),
2356− "Cannot find ACPI VDDC voltage value "
2357− "in Clock Dependency Table",);
2358− } else {
2359− table->ACPILevel.SclkFrequency =
2360− data->vbios_boot_state.sclk_bootup_value;
2361− table->ACPILevel.MinVoltage =
2362− data->vbios_boot_state.vddc_bootup_value * VOLTAGE_SCALE;
2363− }
2364−
2365− /* get the engine clock dividers for this clock value */
2366− result = atomctrl_get_engine_pll_dividers_vi(hwmgr,
2367− table->ACPILevel.SclkFrequency, &dividers);
2368− PP_ASSERT_WITH_CODE(result == 0,
2369− "Error retrieving Engine Clock dividers from VBIOS.",
2370− return result);
2371−
2372− table->ACPILevel.SclkDid = (uint8_t)dividers.pll_post_divider;
2373− table->ACPILevel.DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW;
2374− table->ACPILevel.DeepSleepDivId = 0;
2375−
2376− spll_func_cntl = PHM_SET_FIELD(spll_func_cntl, CG_SPLL_FUNC_CNTL,
2377− SPLL_PWRON, 0);
2378− spll_func_cntl = PHM_SET_FIELD(spll_func_cntl, CG_SPLL_FUNC_CNTL,
2379− SPLL_RESET, 1);
2380− spll_func_cntl_2 = PHM_SET_FIELD(spll_func_cntl_2, CG_SPLL_FUNC_CNTL_2,
2381− SCLK_MUX_SEL, 4);
2382−
2383− table->ACPILevel.CgSpllFuncCntl = spll_func_cntl;
2384− table->ACPILevel.CgSpllFuncCntl2 = spll_func_cntl_2;
2385− table->ACPILevel.CgSpllFuncCntl3 = data->clock_registers.vCG_SPLL_FUNC_CNTL_3;
2386− table->ACPILevel.CgSpllFuncCntl4 = data->clock_registers.vCG_SPLL_FUNC_CNTL_4;
2387− table->ACPILevel.SpllSpreadSpectrum = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM;
2388− table->ACPILevel.SpllSpreadSpectrum2 = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM_2;
2389− table->ACPILevel.CcPwrDynRm = 0;
2390− table->ACPILevel.CcPwrDynRm1 = 0;
2391−
2392− CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.Flags);
2393− CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.SclkFrequency);
2394− CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.MinVoltage);
2395− CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CgSpllFuncCntl);
2396− CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CgSpllFuncCntl2);
2397− CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CgSpllFuncCntl3);
2398− CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CgSpllFuncCntl4);
2399− CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.SpllSpreadSpectrum);
2400− CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.SpllSpreadSpectrum2);
2401− CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CcPwrDynRm);
2402− CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CcPwrDynRm1);
2403−
2404− if (!data->mclk_dpm_key_disabled) {
2405− /* Get MinVoltage and Frequency from DPM0, already converted to SMC_UL */
2406− table->MemoryACPILevel.MclkFrequency =
2407− data->dpm_table.mclk_table.dpm_levels[0].value;
2408− result = fiji_get_dependency_volt_by_clk(hwmgr,
2409− table_info->vdd_dep_on_mclk,
2410− table->MemoryACPILevel.MclkFrequency,
2411− &table->MemoryACPILevel.MinVoltage, &mvdd);
2412− PP_ASSERT_WITH_CODE((0 == result),
2413− "Cannot find ACPI VDDCI voltage value "
2414− "in Clock Dependency Table",);
2415− } else {
2416− table->MemoryACPILevel.MclkFrequency =
2417− data->vbios_boot_state.mclk_bootup_value;
2418− table->MemoryACPILevel.MinVoltage =
2419− data->vbios_boot_state.vddci_bootup_value * VOLTAGE_SCALE;
2420− }
2421−
2422− us_mvdd = 0;
2423− if ((FIJI_VOLTAGE_CONTROL_NONE == data->mvdd_control) ||
2424− (data->mclk_dpm_key_disabled))
2425− us_mvdd = data->vbios_boot_state.mvdd_bootup_value;
2426− else {
2427− if (!fiji_populate_mvdd_value(hwmgr,
2428− data->dpm_table.mclk_table.dpm_levels[0].value,
2429− &vol_level))
2430− us_mvdd = vol_level.Voltage;
2431− }
2432−
2433− table->MemoryACPILevel.MinMvdd =
2434− PP_HOST_TO_SMC_UL(us_mvdd * VOLTAGE_SCALE);
2435−
2436− table->MemoryACPILevel.EnabledForThrottle = 0;
2437− table->MemoryACPILevel.EnabledForActivity = 0;
2438− table->MemoryACPILevel.UpHyst = 0;
2439− table->MemoryACPILevel.DownHyst = 100;
2440− table->MemoryACPILevel.VoltageDownHyst = 0;
2441− table->MemoryACPILevel.ActivityLevel =
2442− PP_HOST_TO_SMC_US((uint16_t)data->mclk_activity_target);
2443−
2444− table->MemoryACPILevel.StutterEnable = false;
2445− CONVERT_FROM_HOST_TO_SMC_UL(table->MemoryACPILevel.MclkFrequency);
2446− CONVERT_FROM_HOST_TO_SMC_UL(table->MemoryACPILevel.MinVoltage);
2447−
2448− return result;
2449−}
2450−
2451−static int fiji_populate_smc_vce_level(struct pp_hwmgr *hwmgr,
2452− SMU73_Discrete_DpmTable *table)
2453−{
2454− int result = -EINVAL;
2455− uint8_t count;
2456− struct pp_atomctrl_clock_dividers_vi dividers;
2457− struct phm_ppt_v1_information *table_info =
2458− (struct phm_ppt_v1_information *)(hwmgr->pptable);
2459− struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
2460− table_info->mm_dep_table;
2461− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2462−
2463− table->VceLevelCount = (uint8_t)(mm_table->count);
2464− table->VceBootLevel = 0;
2465−
2466− for(count = 0; count < table->VceLevelCount; count++) {
2467− table->VceLevel[count].Frequency = mm_table->entries[count].eclk;
2468− table->VceLevel[count].MinVoltage = 0;
2469− table->VceLevel[count].MinVoltage |=
2470− (mm_table->entries[count].vddc * VOLTAGE_SCALE) << VDDC_SHIFT;
2471− table->VceLevel[count].MinVoltage |=
2472− ((mm_table->entries[count].vddc - data->vddc_vddci_delta) *
2473− VOLTAGE_SCALE) << VDDCI_SHIFT;
2474− table->VceLevel[count].MinVoltage |= 1 << PHASES_SHIFT;
2475−
2476− /*retrieve divider value for VBIOS */
2477− result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
2478− table->VceLevel[count].Frequency, &dividers);
2479− PP_ASSERT_WITH_CODE((0 == result),
2480− "can not find divide id for VCE engine clock",
2481− return result);
2482−
2483− table->VceLevel[count].Divider = (uint8_t)dividers.pll_post_divider;
2484−
2485− CONVERT_FROM_HOST_TO_SMC_UL(table->VceLevel[count].Frequency);
2486− CONVERT_FROM_HOST_TO_SMC_UL(table->VceLevel[count].MinVoltage);
2487− }
2488− return result;
2489−}
2490−
2491−static int fiji_populate_smc_acp_level(struct pp_hwmgr *hwmgr,
2492− SMU73_Discrete_DpmTable *table)
2493−{
2494− int result = -EINVAL;
2495− uint8_t count;
2496− struct pp_atomctrl_clock_dividers_vi dividers;
2497− struct phm_ppt_v1_information *table_info =
2498− (struct phm_ppt_v1_information *)(hwmgr->pptable);
2499− struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
2500− table_info->mm_dep_table;
2501− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2502−
2503− table->AcpLevelCount = (uint8_t)(mm_table->count);
2504− table->AcpBootLevel = 0;
2505−
2506− for (count = 0; count < table->AcpLevelCount; count++) {
2507− table->AcpLevel[count].Frequency = mm_table->entries[count].aclk;
2508− table->AcpLevel[count].MinVoltage |= (mm_table->entries[count].vddc *
2509− VOLTAGE_SCALE) << VDDC_SHIFT;
2510− table->AcpLevel[count].MinVoltage |= ((mm_table->entries[count].vddc -
2511− data->vddc_vddci_delta) * VOLTAGE_SCALE) << VDDCI_SHIFT;
2512− table->AcpLevel[count].MinVoltage |= 1 << PHASES_SHIFT;
2513−
2514− /* retrieve divider value for VBIOS */
2515− result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
2516− table->AcpLevel[count].Frequency, &dividers);
2517− PP_ASSERT_WITH_CODE((0 == result),
2518− "can not find divide id for engine clock", return result);
2519−
2520− table->AcpLevel[count].Divider = (uint8_t)dividers.pll_post_divider;
2521−
2522− CONVERT_FROM_HOST_TO_SMC_UL(table->AcpLevel[count].Frequency);
2523− CONVERT_FROM_HOST_TO_SMC_UL(table->AcpLevel[count].MinVoltage);
2524− }
2525− return result;
2526−}
2527−
2528−static int fiji_populate_smc_samu_level(struct pp_hwmgr *hwmgr,
2529− SMU73_Discrete_DpmTable *table)
2530−{
2531− int result = -EINVAL;
2532− uint8_t count;
2533− struct pp_atomctrl_clock_dividers_vi dividers;
2534− struct phm_ppt_v1_information *table_info =
2535− (struct phm_ppt_v1_information *)(hwmgr->pptable);
2536− struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
2537− table_info->mm_dep_table;
2538− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2539−
2540− table->SamuBootLevel = 0;
2541− table->SamuLevelCount = (uint8_t)(mm_table->count);
2542−
2543− for (count = 0; count < table->SamuLevelCount; count++) {
2544− /* not sure whether we need evclk or not */
2545− table->SamuLevel[count].MinVoltage = 0;
2546− table->SamuLevel[count].Frequency = mm_table->entries[count].samclock;
2547− table->SamuLevel[count].MinVoltage |= (mm_table->entries[count].vddc *
2548− VOLTAGE_SCALE) << VDDC_SHIFT;
2549− table->SamuLevel[count].MinVoltage |= ((mm_table->entries[count].vddc -
2550− data->vddc_vddci_delta) * VOLTAGE_SCALE) << VDDCI_SHIFT;
2551− table->SamuLevel[count].MinVoltage |= 1 << PHASES_SHIFT;
2552−
2553− /* retrieve divider value for VBIOS */
2554− result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
2555− table->SamuLevel[count].Frequency, &dividers);
2556− PP_ASSERT_WITH_CODE((0 == result),
2557− "can not find divide id for samu clock", return result);
2558−
2559− table->SamuLevel[count].Divider = (uint8_t)dividers.pll_post_divider;
2560−
2561− CONVERT_FROM_HOST_TO_SMC_UL(table->SamuLevel[count].Frequency);
2562− CONVERT_FROM_HOST_TO_SMC_UL(table->SamuLevel[count].MinVoltage);
2563− }
2564− return result;
2565−}
2566−
2567−static int fiji_populate_memory_timing_parameters(struct pp_hwmgr *hwmgr,
2568− int32_t eng_clock, int32_t mem_clock,
2569− struct SMU73_Discrete_MCArbDramTimingTableEntry *arb_regs)
2570−{
2571− uint32_t dram_timing;
2572− uint32_t dram_timing2;
2573− uint32_t burstTime;
2574− ULONG state, trrds, trrdl;
2575− int result;
2576−
2577− result = atomctrl_set_engine_dram_timings_rv770(hwmgr,
2578− eng_clock, mem_clock);
2579− PP_ASSERT_WITH_CODE(result == 0,
2580− "Error calling VBIOS to set DRAM_TIMING.", return result);
2581−
2582− dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING);
2583− dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2);
2584− burstTime = cgs_read_register(hwmgr->device, mmMC_ARB_BURST_TIME);
2585−
2586− state = PHM_GET_FIELD(burstTime, MC_ARB_BURST_TIME, STATE0);
2587− trrds = PHM_GET_FIELD(burstTime, MC_ARB_BURST_TIME, TRRDS0);
2588− trrdl = PHM_GET_FIELD(burstTime, MC_ARB_BURST_TIME, TRRDL0);
2589−
2590− arb_regs->McArbDramTiming = PP_HOST_TO_SMC_UL(dram_timing);
2591− arb_regs->McArbDramTiming2 = PP_HOST_TO_SMC_UL(dram_timing2);
2592− arb_regs->McArbBurstTime = (uint8_t)burstTime;
2593− arb_regs->TRRDS = (uint8_t)trrds;
2594− arb_regs->TRRDL = (uint8_t)trrdl;
2595−
2596− return 0;
2597−}
2598−
2599−static int fiji_program_memory_timing_parameters(struct pp_hwmgr *hwmgr)
2600−{
2601− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2602− struct SMU73_Discrete_MCArbDramTimingTable arb_regs;
2603− uint32_t i, j;
2604− int result = 0;
2605−
2606− for (i = 0; i < data->dpm_table.sclk_table.count; i++) {
2607− for (j = 0; j < data->dpm_table.mclk_table.count; j++) {
2608− result = fiji_populate_memory_timing_parameters(hwmgr,
2609− data->dpm_table.sclk_table.dpm_levels[i].value,
2610− data->dpm_table.mclk_table.dpm_levels[j].value,
2611− &arb_regs.entries[i][j]);
2612− if (result)
2613− break;
2614− }
2615− }
2616−
2617− if (!result)
2618− result = fiji_copy_bytes_to_smc(
2619− hwmgr->smumgr,
2620− data->arb_table_start,
2621− (uint8_t *)&arb_regs,
2622− sizeof(SMU73_Discrete_MCArbDramTimingTable),
2623− data->sram_end);
2624− return result;
2625−}
2626−
2627−static int fiji_populate_smc_uvd_level(struct pp_hwmgr *hwmgr,
2628− struct SMU73_Discrete_DpmTable *table)
2629−{
2630− int result = -EINVAL;
2631− uint8_t count;
2632− struct pp_atomctrl_clock_dividers_vi dividers;
2633− struct phm_ppt_v1_information *table_info =
2634− (struct phm_ppt_v1_information *)(hwmgr->pptable);
2635− struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
2636− table_info->mm_dep_table;
2637− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2638−
2639− table->UvdLevelCount = (uint8_t)(mm_table->count);
2640− table->UvdBootLevel = 0;
2641−
2642− for (count = 0; count < table->UvdLevelCount; count++) {
2643− table->UvdLevel[count].MinVoltage = 0;
2644− table->UvdLevel[count].VclkFrequency = mm_table->entries[count].vclk;
2645− table->UvdLevel[count].DclkFrequency = mm_table->entries[count].dclk;
2646− table->UvdLevel[count].MinVoltage |= (mm_table->entries[count].vddc *
2647− VOLTAGE_SCALE) << VDDC_SHIFT;
2648− table->UvdLevel[count].MinVoltage |= ((mm_table->entries[count].vddc -
2649− data->vddc_vddci_delta) * VOLTAGE_SCALE) << VDDCI_SHIFT;
2650− table->UvdLevel[count].MinVoltage |= 1 << PHASES_SHIFT;
2651−
2652− /* retrieve divider value for VBIOS */
2653− result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
2654− table->UvdLevel[count].VclkFrequency, &dividers);
2655− PP_ASSERT_WITH_CODE((0 == result),
2656− "can not find divide id for Vclk clock", return result);
2657−
2658− table->UvdLevel[count].VclkDivider = (uint8_t)dividers.pll_post_divider;
2659−
2660− result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
2661− table->UvdLevel[count].DclkFrequency, &dividers);
2662− PP_ASSERT_WITH_CODE((0 == result),
2663− "can not find divide id for Dclk clock", return result);
2664−
2665− table->UvdLevel[count].DclkDivider = (uint8_t)dividers.pll_post_divider;
2666−
2667− CONVERT_FROM_HOST_TO_SMC_UL(table->UvdLevel[count].VclkFrequency);
2668− CONVERT_FROM_HOST_TO_SMC_UL(table->UvdLevel[count].DclkFrequency);
2669− CONVERT_FROM_HOST_TO_SMC_UL(table->UvdLevel[count].MinVoltage);
2670−
2671− }
2672− return result;
2673−}
2674−
2675−static int fiji_find_boot_level(struct fiji_single_dpm_table *table,
2676− uint32_t value, uint32_t *boot_level)
2677−{
2678− int result = -EINVAL;
2679− uint32_t i;
2680−
2681− for (i = 0; i < table->count; i++) {
2682− if (value == table->dpm_levels[i].value) {
2683− *boot_level = i;
2684− result = 0;
2685− }
2686− }
2687− return result;
2688−}
2689−
2690−static int fiji_populate_smc_boot_level(struct pp_hwmgr *hwmgr,
2691− struct SMU73_Discrete_DpmTable *table)
2692−{
2693− int result = 0;
2694− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2695−
2696− table->GraphicsBootLevel = 0;
2697− table->MemoryBootLevel = 0;
2698−
2699− /* find boot level from dpm table */
2700− result = fiji_find_boot_level(&(data->dpm_table.sclk_table),
2701− data->vbios_boot_state.sclk_bootup_value,
2702− (uint32_t *)&(table->GraphicsBootLevel));
2703−
2704− result = fiji_find_boot_level(&(data->dpm_table.mclk_table),
2705− data->vbios_boot_state.mclk_bootup_value,
2706− (uint32_t *)&(table->MemoryBootLevel));
2707−
2708− table->BootVddc = data->vbios_boot_state.vddc_bootup_value *
2709− VOLTAGE_SCALE;
2710− table->BootVddci = data->vbios_boot_state.vddci_bootup_value *
2711− VOLTAGE_SCALE;
2712− table->BootMVdd = data->vbios_boot_state.mvdd_bootup_value *
2713− VOLTAGE_SCALE;
2714−
2715− CONVERT_FROM_HOST_TO_SMC_US(table->BootVddc);
2716− CONVERT_FROM_HOST_TO_SMC_US(table->BootVddci);
2717− CONVERT_FROM_HOST_TO_SMC_US(table->BootMVdd);
2718−
2719− return 0;
2720−}
2721−
2722−static int fiji_populate_smc_initailial_state(struct pp_hwmgr *hwmgr)
2723−{
2724− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2725− struct phm_ppt_v1_information *table_info =
2726− (struct phm_ppt_v1_information *)(hwmgr->pptable);
2727− uint8_t count, level;
2728−
2729− count = (uint8_t)(table_info->vdd_dep_on_sclk->count);
2730− for (level = 0; level < count; level++) {
2731− if(table_info->vdd_dep_on_sclk->entries[level].clk >=
2732− data->vbios_boot_state.sclk_bootup_value) {
2733− data->smc_state_table.GraphicsBootLevel = level;
2734− break;
2735− }
2736− }
2737−
2738− count = (uint8_t)(table_info->vdd_dep_on_mclk->count);
2739− for (level = 0; level < count; level++) {
2740− if(table_info->vdd_dep_on_mclk->entries[level].clk >=
2741− data->vbios_boot_state.mclk_bootup_value) {
2742− data->smc_state_table.MemoryBootLevel = level;
2743− break;
2744− }
2745− }
2746−
2747− return 0;
2748−}
2749−
2750−static int fiji_populate_clock_stretcher_data_table(struct pp_hwmgr *hwmgr)
2751−{
2752− uint32_t ro, efuse, efuse2, clock_freq, volt_without_cks,
2753− volt_with_cks, value;
2754− uint16_t clock_freq_u16;
2755− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2756− uint8_t type, i, j, cks_setting, stretch_amount, stretch_amount2,
2757− volt_offset = 0;
2758− struct phm_ppt_v1_information *table_info =
2759− (struct phm_ppt_v1_information *)(hwmgr->pptable);
2760− struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table =
2761− table_info->vdd_dep_on_sclk;
2762−
2763− stretch_amount = (uint8_t)table_info->cac_dtp_table->usClockStretchAmount;
2764−
2765− /* Read SMU_Eefuse to read and calculate RO and determine
2766− * if the part is SS or FF. if RO >= 1660MHz, part is FF.
2767− */
2768− efuse = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
2769− ixSMU_EFUSE_0 + (146 * 4));
2770− efuse2 = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
2771− ixSMU_EFUSE_0 + (148 * 4));
2772− efuse &= 0xFF000000;
2773− efuse = efuse >> 24;
2774− efuse2 &= 0xF;
2775−
2776− if (efuse2 == 1)
2777− ro = (2300 - 1350) * efuse / 255 + 1350;
2778− else
2779− ro = (2500 - 1000) * efuse / 255 + 1000;
2780−
2781− if (ro >= 1660)
2782− type = 0;
2783− else
2784− type = 1;
2785−
2786− /* Populate Stretch amount */
2787− data->smc_state_table.ClockStretcherAmount = stretch_amount;
2788−
2789− /* Populate Sclk_CKS_masterEn0_7 and Sclk_voltageOffset */
2790− for (i = 0; i < sclk_table->count; i++) {
2791− data->smc_state_table.Sclk_CKS_masterEn0_7 |=
2792− sclk_table->entries[i].cks_enable << i;
2793− volt_without_cks = (uint32_t)((14041 *
2794− (sclk_table->entries[i].clk/100) / 10000 + 3571 + 75 - ro) * 1000 /
2795− (4026 - (13924 * (sclk_table->entries[i].clk/100) / 10000)));
2796− volt_with_cks = (uint32_t)((13946 *
2797− (sclk_table->entries[i].clk/100) / 10000 + 3320 + 45 - ro) * 1000 /
2798− (3664 - (11454 * (sclk_table->entries[i].clk/100) / 10000)));
2799− if (volt_without_cks >= volt_with_cks)
2800− volt_offset = (uint8_t)(((volt_without_cks - volt_with_cks +
2801− sclk_table->entries[i].cks_voffset) * 100 / 625) + 1);
2802− data->smc_state_table.Sclk_voltageOffset[i] = volt_offset;
2803− }
2804−
2805− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, PWR_CKS_ENABLE,
2806− STRETCH_ENABLE, 0x0);
2807− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, PWR_CKS_ENABLE,
2808− masterReset, 0x1);
2809− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, PWR_CKS_ENABLE,
2810− staticEnable, 0x1);
2811− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, PWR_CKS_ENABLE,
2812− masterReset, 0x0);
2813−
2814− /* Populate CKS Lookup Table */
2815− if (stretch_amount == 1 || stretch_amount == 2 || stretch_amount == 5)
2816− stretch_amount2 = 0;
2817− else if (stretch_amount == 3 || stretch_amount == 4)
2818− stretch_amount2 = 1;
2819− else {
2820− phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
2821− PHM_PlatformCaps_ClockStretcher);
2822− PP_ASSERT_WITH_CODE(false,
2823− "Stretch Amount in PPTable not supported\n",
2824− return -EINVAL);
2825− }
2826−
2827− value = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
2828− ixPWR_CKS_CNTL);
2829− value &= 0xFFC2FF87;
2830− data->smc_state_table.CKS_LOOKUPTable.CKS_LOOKUPTableEntry[0].minFreq =
2831− fiji_clock_stretcher_lookup_table[stretch_amount2][0];
2832− data->smc_state_table.CKS_LOOKUPTable.CKS_LOOKUPTableEntry[0].maxFreq =
2833− fiji_clock_stretcher_lookup_table[stretch_amount2][1];
2834− clock_freq_u16 = (uint16_t)(PP_SMC_TO_HOST_UL(data->smc_state_table.
2835− GraphicsLevel[data->smc_state_table.GraphicsDpmLevelCount - 1].
2836− SclkFrequency) / 100);
2837− if (fiji_clock_stretcher_lookup_table[stretch_amount2][0] <
2838− clock_freq_u16 &&
2839− fiji_clock_stretcher_lookup_table[stretch_amount2][1] >
2840− clock_freq_u16) {
2841− /* Program PWR_CKS_CNTL. CKS_USE_FOR_LOW_FREQ */
2842− value |= (fiji_clock_stretcher_lookup_table[stretch_amount2][3]) << 16;
2843− /* Program PWR_CKS_CNTL. CKS_LDO_REFSEL */
2844− value |= (fiji_clock_stretcher_lookup_table[stretch_amount2][2]) << 18;
2845− /* Program PWR_CKS_CNTL. CKS_STRETCH_AMOUNT */
2846− value |= (fiji_clock_stretch_amount_conversion
2847− [fiji_clock_stretcher_lookup_table[stretch_amount2][3]]
2848− [stretch_amount]) << 3;
2849− }
2850− CONVERT_FROM_HOST_TO_SMC_US(data->smc_state_table.CKS_LOOKUPTable.
2851− CKS_LOOKUPTableEntry[0].minFreq);
2852− CONVERT_FROM_HOST_TO_SMC_US(data->smc_state_table.CKS_LOOKUPTable.
2853− CKS_LOOKUPTableEntry[0].maxFreq);
2854− data->smc_state_table.CKS_LOOKUPTable.CKS_LOOKUPTableEntry[0].setting =
2855− fiji_clock_stretcher_lookup_table[stretch_amount2][2] & 0x7F;
2856− data->smc_state_table.CKS_LOOKUPTable.CKS_LOOKUPTableEntry[0].setting |=
2857− (fiji_clock_stretcher_lookup_table[stretch_amount2][3]) << 7;
2858−
2859− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
2860− ixPWR_CKS_CNTL, value);
2861−
2862− /* Populate DDT Lookup Table */
2863− for (i = 0; i < 4; i++) {
2864− /* Assign the minimum and maximum VID stored
2865− * in the last row of Clock Stretcher Voltage Table.
2866− */
2867− data->smc_state_table.ClockStretcherDataTable.
2868− ClockStretcherDataTableEntry[i].minVID =
2869− (uint8_t) fiji_clock_stretcher_ddt_table[type][i][2];
2870− data->smc_state_table.ClockStretcherDataTable.
2871− ClockStretcherDataTableEntry[i].maxVID =
2872− (uint8_t) fiji_clock_stretcher_ddt_table[type][i][3];
2873− /* Loop through each SCLK and check the frequency
2874− * to see if it lies within the frequency for clock stretcher.
2875− */
2876− for (j = 0; j < data->smc_state_table.GraphicsDpmLevelCount; j++) {
2877− cks_setting = 0;
2878− clock_freq = PP_SMC_TO_HOST_UL(
2879− data->smc_state_table.GraphicsLevel[j].SclkFrequency);
2880− /* Check the allowed frequency against the sclk level[j].
2881− * Sclk's endianness has already been converted,
2882− * and it's in 10Khz unit,
2883− * as opposed to Data table, which is in Mhz unit.
2884− */
2885− if (clock_freq >=
2886− (fiji_clock_stretcher_ddt_table[type][i][0]) * 100) {
2887− cks_setting |= 0x2;
2888− if (clock_freq <
2889− (fiji_clock_stretcher_ddt_table[type][i][1]) * 100)
2890− cks_setting |= 0x1;
2891− }
2892− data->smc_state_table.ClockStretcherDataTable.
2893− ClockStretcherDataTableEntry[i].setting |= cks_setting << (j * 2);
2894− }
2895− CONVERT_FROM_HOST_TO_SMC_US(data->smc_state_table.
2896− ClockStretcherDataTable.
2897− ClockStretcherDataTableEntry[i].setting);
2898− }
2899−
2900− value = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixPWR_CKS_CNTL);
2901− value &= 0xFFFFFFFE;
2902− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixPWR_CKS_CNTL, value);
2903−
2904− return 0;
2905−}
2906−
2907−/**
2908−* Populates the SMC VRConfig field in DPM table.
2909−*
2910−* @param hwmgr the address of the hardware manager
2911−* @param table the SMC DPM table structure to be populated
2912−* @return always 0
2913−*/
2914−static int fiji_populate_vr_config(struct pp_hwmgr *hwmgr,
2915− struct SMU73_Discrete_DpmTable *table)
2916−{
2917− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2918− uint16_t config;
2919−
2920− config = VR_MERGED_WITH_VDDC;
2921− table->VRConfig |= (config << VRCONF_VDDGFX_SHIFT);
2922−
2923− /* Set Vddc Voltage Controller */
2924− if(FIJI_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) {
2925− config = VR_SVI2_PLANE_1;
2926− table->VRConfig |= config;
2927− } else {
2928− PP_ASSERT_WITH_CODE(false,
2929− "VDDC should be on SVI2 control in merged mode!",);
2930− }
2931− /* Set Vddci Voltage Controller */
2932− if(FIJI_VOLTAGE_CONTROL_BY_SVID2 == data->vddci_control) {
2933− config = VR_SVI2_PLANE_2; /* only in merged mode */
2934− table->VRConfig |= (config << VRCONF_VDDCI_SHIFT);
2935− } else if (FIJI_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control) {
2936− config = VR_SMIO_PATTERN_1;
2937− table->VRConfig |= (config << VRCONF_VDDCI_SHIFT);
2938− } else {
2939− config = VR_STATIC_VOLTAGE;
2940− table->VRConfig |= (config << VRCONF_VDDCI_SHIFT);
2941− }
2942− /* Set Mvdd Voltage Controller */
2943− if(FIJI_VOLTAGE_CONTROL_BY_SVID2 == data->mvdd_control) {
2944− config = VR_SVI2_PLANE_2;
2945− table->VRConfig |= (config << VRCONF_MVDD_SHIFT);
2946− } else if(FIJI_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) {
2947− config = VR_SMIO_PATTERN_2;
2948− table->VRConfig |= (config << VRCONF_MVDD_SHIFT);
2949− } else {
2950− config = VR_STATIC_VOLTAGE;
2951− table->VRConfig |= (config << VRCONF_MVDD_SHIFT);
2952− }
2953−
2954− return 0;
2955−}
2956−
2957−/**
2958−* Initializes the SMC table and uploads it
2959−*
2960−* @param hwmgr the address of the powerplay hardware manager.
2961−* @param pInput the pointer to input data (PowerState)
2962−* @return always 0
2963−*/
2964−static int fiji_init_smc_table(struct pp_hwmgr *hwmgr)
2965−{
2966− int result;
2967− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2968− struct phm_ppt_v1_information *table_info =
2969− (struct phm_ppt_v1_information *)(hwmgr->pptable);
2970− struct SMU73_Discrete_DpmTable *table = &(data->smc_state_table);
2971− const struct fiji_ulv_parm *ulv = &(data->ulv);
2972− uint8_t i;
2973− struct pp_atomctrl_gpio_pin_assignment gpio_pin;
2974−
2975− result = fiji_setup_default_dpm_tables(hwmgr);
2976− PP_ASSERT_WITH_CODE(0 == result,
2977− "Failed to setup default DPM tables!", return result);
2978−
2979− if(FIJI_VOLTAGE_CONTROL_NONE != data->voltage_control)
2980− fiji_populate_smc_voltage_tables(hwmgr, table);
2981−
2982− table->SystemFlags = 0;
2983−
2984− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2985− PHM_PlatformCaps_AutomaticDCTransition))
2986− table->SystemFlags |= PPSMC_SYSTEMFLAG_GPIO_DC;
2987−
2988− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2989− PHM_PlatformCaps_StepVddc))
2990− table->SystemFlags |= PPSMC_SYSTEMFLAG_STEPVDDC;
2991−
2992− if (data->is_memory_gddr5)
2993− table->SystemFlags |= PPSMC_SYSTEMFLAG_GDDR5;
2994−
2995− if (ulv->ulv_supported && table_info->us_ulv_voltage_offset) {
2996− result = fiji_populate_ulv_state(hwmgr, table);
2997− PP_ASSERT_WITH_CODE(0 == result,
2998− "Failed to initialize ULV state!", return result);
2999− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3000− ixCG_ULV_PARAMETER, ulv->cg_ulv_parameter);
3001− }
3002−
3003− result = fiji_populate_smc_link_level(hwmgr, table);
3004− PP_ASSERT_WITH_CODE(0 == result,
3005− "Failed to initialize Link Level!", return result);
3006−
3007− result = fiji_populate_all_graphic_levels(hwmgr);
3008− PP_ASSERT_WITH_CODE(0 == result,
3009− "Failed to initialize Graphics Level!", return result);
3010−
3011− result = fiji_populate_all_memory_levels(hwmgr);
3012− PP_ASSERT_WITH_CODE(0 == result,
3013− "Failed to initialize Memory Level!", return result);
3014−
3015− result = fiji_populate_smc_acpi_level(hwmgr, table);
3016− PP_ASSERT_WITH_CODE(0 == result,
3017− "Failed to initialize ACPI Level!", return result);
3018−
3019− result = fiji_populate_smc_vce_level(hwmgr, table);
3020− PP_ASSERT_WITH_CODE(0 == result,
3021− "Failed to initialize VCE Level!", return result);
3022−
3023− result = fiji_populate_smc_acp_level(hwmgr, table);
3024− PP_ASSERT_WITH_CODE(0 == result,
3025− "Failed to initialize ACP Level!", return result);
3026−
3027− result = fiji_populate_smc_samu_level(hwmgr, table);
3028− PP_ASSERT_WITH_CODE(0 == result,
3029− "Failed to initialize SAMU Level!", return result);
3030−
3031− /* Since only the initial state is completely set up at this point
3032− * (the other states are just copies of the boot state) we only
3033− * need to populate the ARB settings for the initial state.
3034− */
3035− result = fiji_program_memory_timing_parameters(hwmgr);
3036− PP_ASSERT_WITH_CODE(0 == result,
3037− "Failed to Write ARB settings for the initial state.", return result);
3038−
3039− result = fiji_populate_smc_uvd_level(hwmgr, table);
3040− PP_ASSERT_WITH_CODE(0 == result,
3041− "Failed to initialize UVD Level!", return result);
3042−
3043− result = fiji_populate_smc_boot_level(hwmgr, table);
3044− PP_ASSERT_WITH_CODE(0 == result,
3045− "Failed to initialize Boot Level!", return result);
3046−
3047− result = fiji_populate_smc_initailial_state(hwmgr);
3048− PP_ASSERT_WITH_CODE(0 == result,
3049− "Failed to initialize Boot State!", return result);
3050−
3051− result = fiji_populate_bapm_parameters_in_dpm_table(hwmgr);
3052− PP_ASSERT_WITH_CODE(0 == result,
3053− "Failed to populate BAPM Parameters!", return result);
3054−
3055− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3056− PHM_PlatformCaps_ClockStretcher)) {
3057− result = fiji_populate_clock_stretcher_data_table(hwmgr);
3058− PP_ASSERT_WITH_CODE(0 == result,
3059− "Failed to populate Clock Stretcher Data Table!",
3060− return result);
3061− }
3062−
3063− table->GraphicsVoltageChangeEnable = 1;
3064− table->GraphicsThermThrottleEnable = 1;
3065− table->GraphicsInterval = 1;
3066− table->VoltageInterval = 1;
3067− table->ThermalInterval = 1;
3068− table->TemperatureLimitHigh =
3069− table_info->cac_dtp_table->usTargetOperatingTemp *
3070− FIJI_Q88_FORMAT_CONVERSION_UNIT;
3071− table->TemperatureLimitLow =
3072− (table_info->cac_dtp_table->usTargetOperatingTemp - 1) *
3073− FIJI_Q88_FORMAT_CONVERSION_UNIT;
3074− table->MemoryVoltageChangeEnable = 1;
3075− table->MemoryInterval = 1;
3076− table->VoltageResponseTime = 0;
3077− table->PhaseResponseTime = 0;
3078− table->MemoryThermThrottleEnable = 1;
3079− table->PCIeBootLinkLevel = 0; /* 0:Gen1 1:Gen2 2:Gen3*/
3080− table->PCIeGenInterval = 1;
3081− table->VRConfig = 0;
3082−
3083− result = fiji_populate_vr_config(hwmgr, table);
3084− PP_ASSERT_WITH_CODE(0 == result,
3085− "Failed to populate VRConfig setting!", return result);
3086−
3087− table->ThermGpio = 17;
3088− table->SclkStepSize = 0x4000;
3089−
3090− if (atomctrl_get_pp_assign_pin(hwmgr, VDDC_VRHOT_GPIO_PINID, &gpio_pin)) {
3091− table->VRHotGpio = gpio_pin.uc_gpio_pin_bit_shift;
3092− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3093− PHM_PlatformCaps_RegulatorHot);
3094− } else {
3095− table->VRHotGpio = FIJI_UNUSED_GPIO_PIN;
3096− phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
3097− PHM_PlatformCaps_RegulatorHot);
3098− }
3099−
3100− if (atomctrl_get_pp_assign_pin(hwmgr, PP_AC_DC_SWITCH_GPIO_PINID,
3101− &gpio_pin)) {
3102− table->AcDcGpio = gpio_pin.uc_gpio_pin_bit_shift;
3103− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3104− PHM_PlatformCaps_AutomaticDCTransition);
3105− } else {
3106− table->AcDcGpio = FIJI_UNUSED_GPIO_PIN;
3107− phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
3108− PHM_PlatformCaps_AutomaticDCTransition);
3109− }
3110−
3111− /* Thermal Output GPIO */
3112− if (atomctrl_get_pp_assign_pin(hwmgr, THERMAL_INT_OUTPUT_GPIO_PINID,
3113− &gpio_pin)) {
3114− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3115− PHM_PlatformCaps_ThermalOutGPIO);
3116−
3117− table->ThermOutGpio = gpio_pin.uc_gpio_pin_bit_shift;
3118−
3119− /* For porlarity read GPIOPAD_A with assigned Gpio pin
3120− * since VBIOS will program this register to set 'inactive state',
3121− * driver can then determine 'active state' from this and
3122− * program SMU with correct polarity
3123− */
3124− table->ThermOutPolarity = (0 == (cgs_read_register(hwmgr->device, mmGPIOPAD_A) &
3125− (1 << gpio_pin.uc_gpio_pin_bit_shift))) ? 1:0;
3126− table->ThermOutMode = SMU7_THERM_OUT_MODE_THERM_ONLY;
3127−
3128− /* if required, combine VRHot/PCC with thermal out GPIO */
3129− if(phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3130− PHM_PlatformCaps_RegulatorHot) &&
3131− phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3132− PHM_PlatformCaps_CombinePCCWithThermalSignal))
3133− table->ThermOutMode = SMU7_THERM_OUT_MODE_THERM_VRHOT;
3134− } else {
3135− phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
3136− PHM_PlatformCaps_ThermalOutGPIO);
3137− table->ThermOutGpio = 17;
3138− table->ThermOutPolarity = 1;
3139− table->ThermOutMode = SMU7_THERM_OUT_MODE_DISABLE;
3140− }
3141−
3142− for (i = 0; i < SMU73_MAX_ENTRIES_SMIO; i++)
3143− table->Smio[i] = PP_HOST_TO_SMC_UL(table->Smio[i]);
3144−
3145− CONVERT_FROM_HOST_TO_SMC_UL(table->SystemFlags);
3146− CONVERT_FROM_HOST_TO_SMC_UL(table->VRConfig);
3147− CONVERT_FROM_HOST_TO_SMC_UL(table->SmioMask1);
3148− CONVERT_FROM_HOST_TO_SMC_UL(table->SmioMask2);
3149− CONVERT_FROM_HOST_TO_SMC_UL(table->SclkStepSize);
3150− CONVERT_FROM_HOST_TO_SMC_US(table->TemperatureLimitHigh);
3151− CONVERT_FROM_HOST_TO_SMC_US(table->TemperatureLimitLow);
3152− CONVERT_FROM_HOST_TO_SMC_US(table->VoltageResponseTime);
3153− CONVERT_FROM_HOST_TO_SMC_US(table->PhaseResponseTime);
3154−
3155− /* Upload all dpm data to SMC memory.(dpm level, dpm level count etc) */
3156− result = fiji_copy_bytes_to_smc(hwmgr->smumgr,
3157− data->dpm_table_start +
3158− offsetof(SMU73_Discrete_DpmTable, SystemFlags),
3159− (uint8_t *)&(table->SystemFlags),
3160− sizeof(SMU73_Discrete_DpmTable) - 3 * sizeof(SMU73_PIDController),
3161− data->sram_end);
3162− PP_ASSERT_WITH_CODE(0 == result,
3163− "Failed to upload dpm data to SMC memory!", return result);
3164−
3165− return 0;
3166−}
3167−
3168−/**
3169−* Initialize the ARB DRAM timing table's index field.
3170−*
3171−* @param hwmgr the address of the powerplay hardware manager.
3172−* @return always 0
3173−*/
3174−static int fiji_init_arb_table_index(struct pp_hwmgr *hwmgr)
3175−{
3176− const struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3177− uint32_t tmp;
3178− int result;
3179−
3180− /* This is a read-modify-write on the first byte of the ARB table.
3181− * The first byte in the SMU73_Discrete_MCArbDramTimingTable structure
3182− * is the field 'current'.
3183− * This solution is ugly, but we never write the whole table only
3184− * individual fields in it.
3185− * In reality this field should not be in that structure
3186− * but in a soft register.
3187− */
3188− result = fiji_read_smc_sram_dword(hwmgr->smumgr,
3189− data->arb_table_start, &tmp, data->sram_end);
3190−
3191− if (result)
3192− return result;
3193−
3194− tmp &= 0x00FFFFFF;
3195− tmp |= ((uint32_t)MC_CG_ARB_FREQ_F1) << 24;
3196−
3197− return fiji_write_smc_sram_dword(hwmgr->smumgr,
3198− data->arb_table_start, tmp, data->sram_end);
3199−}
3200−
3201−static int fiji_enable_vrhot_gpio_interrupt(struct pp_hwmgr *hwmgr)
3202−{
3203− if(phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3204− PHM_PlatformCaps_RegulatorHot))
3205− return smum_send_msg_to_smc(hwmgr->smumgr,
3206− PPSMC_MSG_EnableVRHotGPIOInterrupt);
3207−
3208− return 0;
3209−}
3210−
3211−static int fiji_enable_sclk_control(struct pp_hwmgr *hwmgr)
3212−{
3213− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL,
3214− SCLK_PWRMGT_OFF, 0);
3215− return 0;
3216−}
3217−
3218−static int fiji_enable_ulv(struct pp_hwmgr *hwmgr)
3219−{
3220− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3221− struct fiji_ulv_parm *ulv = &(data->ulv);
3222−
3223− if (ulv->ulv_supported)
3224− return smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_EnableULV);
3225−
3226− return 0;
3227−}
3228−
3229−static int fiji_disable_ulv(struct pp_hwmgr *hwmgr)
3230−{
3231− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3232− struct fiji_ulv_parm *ulv = &(data->ulv);
3233−
3234− if (ulv->ulv_supported)
3235− return smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_DisableULV);
3236−
3237− return 0;
3238−}
3239−
3240−static int fiji_enable_deep_sleep_master_switch(struct pp_hwmgr *hwmgr)
3241−{
3242− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3243− PHM_PlatformCaps_SclkDeepSleep)) {
3244− if (smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_MASTER_DeepSleep_ON))
3245− PP_ASSERT_WITH_CODE(false,
3246− "Attempt to enable Master Deep Sleep switch failed!",
3247− return -1);
3248− } else {
3249− if (smum_send_msg_to_smc(hwmgr->smumgr,
3250− PPSMC_MSG_MASTER_DeepSleep_OFF)) {
3251− PP_ASSERT_WITH_CODE(false,
3252− "Attempt to disable Master Deep Sleep switch failed!",
3253− return -1);
3254− }
3255− }
3256−
3257− return 0;
3258−}
3259−
3260−static int fiji_disable_deep_sleep_master_switch(struct pp_hwmgr *hwmgr)
3261−{
3262− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3263− PHM_PlatformCaps_SclkDeepSleep)) {
3264− if (smum_send_msg_to_smc(hwmgr->smumgr,
3265− PPSMC_MSG_MASTER_DeepSleep_OFF)) {
3266− PP_ASSERT_WITH_CODE(false,
3267− "Attempt to disable Master Deep Sleep switch failed!",
3268− return -1);
3269− }
3270− }
3271−
3272− return 0;
3273−}
3274−
3275−static int fiji_enable_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
3276−{
3277− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3278− uint32_t val, val0, val2;
3279− uint32_t i, cpl_cntl, cpl_threshold, mc_threshold;
3280−
3281− /* enable SCLK dpm */
3282− if(!data->sclk_dpm_key_disabled)
3283− PP_ASSERT_WITH_CODE(
3284− (0 == smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_DPM_Enable)),
3285− "Failed to enable SCLK DPM during DPM Start Function!",
3286− return -1);
3287−
3288− /* enable MCLK dpm */
3289− if(0 == data->mclk_dpm_key_disabled) {
3290− cpl_threshold = 0;
3291− mc_threshold = 0;
3292−
3293− /* Read per MCD tile (0 - 7) */
3294− for (i = 0; i < 8; i++) {
3295− PHM_WRITE_FIELD(hwmgr->device, MC_CONFIG_MCD, MC_RD_ENABLE, i);
3296− val = cgs_read_register(hwmgr->device, mmMC_SEQ_RESERVE_0_S) & 0xf0000000;
3297− if (0xf0000000 != val) {
3298− /* count number of MCQ that has channel(s) enabled */
3299− cpl_threshold++;
3300− /* only harvest 3 or full 4 supported */
3301− mc_threshold = val ? 3 : 4;
3302− }
3303− }
3304− PP_ASSERT_WITH_CODE(0 != cpl_threshold,
3305− "Number of MCQ is zero!", return -EINVAL;);
3306−
3307− mc_threshold = ((mc_threshold & LCAC_MC0_CNTL__MC0_THRESHOLD_MASK) <<
3308− LCAC_MC0_CNTL__MC0_THRESHOLD__SHIFT) |
3309− LCAC_MC0_CNTL__MC0_ENABLE_MASK;
3310− cpl_cntl = ((cpl_threshold & LCAC_CPL_CNTL__CPL_THRESHOLD_MASK) <<
3311− LCAC_CPL_CNTL__CPL_THRESHOLD__SHIFT) |
3312− LCAC_CPL_CNTL__CPL_ENABLE_MASK;
3313− cpl_cntl = (cpl_cntl | (8 << LCAC_CPL_CNTL__CPL_BLOCK_ID__SHIFT));
3314− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3315− ixLCAC_MC0_CNTL, mc_threshold);
3316− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3317− ixLCAC_MC1_CNTL, mc_threshold);
3318− if (8 == cpl_threshold) {
3319− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3320− ixLCAC_MC2_CNTL, mc_threshold);
3321− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3322− ixLCAC_MC3_CNTL, mc_threshold);
3323− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3324− ixLCAC_MC4_CNTL, mc_threshold);
3325− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3326− ixLCAC_MC5_CNTL, mc_threshold);
3327− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3328− ixLCAC_MC6_CNTL, mc_threshold);
3329− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3330− ixLCAC_MC7_CNTL, mc_threshold);
3331− }
3332− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3333− ixLCAC_CPL_CNTL, cpl_cntl);
3334−
3335− udelay(5);
3336−
3337− mc_threshold = mc_threshold |
3338− (1 << LCAC_MC0_CNTL__MC0_SIGNAL_ID__SHIFT);
3339− cpl_cntl = cpl_cntl | (1 << LCAC_CPL_CNTL__CPL_SIGNAL_ID__SHIFT);
3340− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3341− ixLCAC_MC0_CNTL, mc_threshold);
3342− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3343− ixLCAC_MC1_CNTL, mc_threshold);
3344− if (8 == cpl_threshold) {
3345− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3346− ixLCAC_MC2_CNTL, mc_threshold);
3347− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3348− ixLCAC_MC3_CNTL, mc_threshold);
3349− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3350− ixLCAC_MC4_CNTL, mc_threshold);
3351− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3352− ixLCAC_MC5_CNTL, mc_threshold);
3353− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3354− ixLCAC_MC6_CNTL, mc_threshold);
3355− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3356− ixLCAC_MC7_CNTL, mc_threshold);
3357− }
3358− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3359− ixLCAC_CPL_CNTL, cpl_cntl);
3360−
3361− /* Program CAC_EN per MCD (0-7) Tile */
3362− val0 = val = cgs_read_register(hwmgr->device, mmMC_CONFIG_MCD);
3363− val &= ~(MC_CONFIG_MCD__MCD0_WR_ENABLE_MASK |
3364− MC_CONFIG_MCD__MCD1_WR_ENABLE_MASK |
3365− MC_CONFIG_MCD__MCD2_WR_ENABLE_MASK |
3366− MC_CONFIG_MCD__MCD3_WR_ENABLE_MASK |
3367− MC_CONFIG_MCD__MCD4_WR_ENABLE_MASK |
3368− MC_CONFIG_MCD__MCD5_WR_ENABLE_MASK |
3369− MC_CONFIG_MCD__MCD6_WR_ENABLE_MASK |
3370− MC_CONFIG_MCD__MCD7_WR_ENABLE_MASK |
3371− MC_CONFIG_MCD__MC_RD_ENABLE_MASK);
3372−
3373− for (i = 0; i < 8; i++) {
3374− /* Enable MCD i Tile read & write */
3375− val2 = (val | (i << MC_CONFIG_MCD__MC_RD_ENABLE__SHIFT) |
3376− (1 << i));
3377− cgs_write_register(hwmgr->device, mmMC_CONFIG_MCD, val2);
3378− /* Enbale CAC_ON MCD i Tile */
3379− val2 = cgs_read_register(hwmgr->device, mmMC_SEQ_CNTL);
3380− val2 |= MC_SEQ_CNTL__CAC_EN_MASK;
3381− cgs_write_register(hwmgr->device, mmMC_SEQ_CNTL, val2);
3382− }
3383− /* Set MC_CONFIG_MCD back to its default setting val0 */
3384− cgs_write_register(hwmgr->device, mmMC_CONFIG_MCD, val0);
3385−
3386− PP_ASSERT_WITH_CODE(
3387− (0 == smum_send_msg_to_smc(hwmgr->smumgr,
3388− PPSMC_MSG_MCLKDPM_Enable)),
3389− "Failed to enable MCLK DPM during DPM Start Function!",
3390− return -1);
3391− }
3392− return 0;
3393−}
3394−
3395−static int fiji_start_dpm(struct pp_hwmgr *hwmgr)
3396−{
3397− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3398−
3399− /*enable general power management */
3400− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
3401− GLOBAL_PWRMGT_EN, 1);
3402− /* enable sclk deep sleep */
3403− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL,
3404− DYNAMIC_PM_EN, 1);
3405− /* prepare for PCIE DPM */
3406− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3407− data->soft_regs_start + offsetof(SMU73_SoftRegisters,
3408− VoltageChangeTimeout), 0x1000);
3409− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__PCIE,
3410− SWRST_COMMAND_1, RESETLC, 0x0);
3411−
3412− PP_ASSERT_WITH_CODE(
3413− (0 == smum_send_msg_to_smc(hwmgr->smumgr,
3414− PPSMC_MSG_Voltage_Cntl_Enable)),
3415− "Failed to enable voltage DPM during DPM Start Function!",
3416− return -1);
3417−
3418− if (fiji_enable_sclk_mclk_dpm(hwmgr)) {
3419− printk(KERN_ERR "Failed to enable Sclk DPM and Mclk DPM!");
3420− return -1;
3421− }
3422−
3423− /* enable PCIE dpm */
3424− if(!data->pcie_dpm_key_disabled) {
3425− PP_ASSERT_WITH_CODE(
3426− (0 == smum_send_msg_to_smc(hwmgr->smumgr,
3427− PPSMC_MSG_PCIeDPM_Enable)),
3428− "Failed to enable pcie DPM during DPM Start Function!",
3429− return -1);
3430− }
3431−
3432− return 0;
3433−}
3434−
3435−static int fiji_disable_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
3436−{
3437− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3438−
3439− /* disable SCLK dpm */
3440− if (!data->sclk_dpm_key_disabled)
3441− PP_ASSERT_WITH_CODE(
3442− (smum_send_msg_to_smc(hwmgr->smumgr,
3443− PPSMC_MSG_DPM_Disable) == 0),
3444− "Failed to disable SCLK DPM!",
3445− return -1);
3446−
3447− /* disable MCLK dpm */
3448− if (!data->mclk_dpm_key_disabled) {
3449− PP_ASSERT_WITH_CODE(
3450− (smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3451− PPSMC_MSG_MCLKDPM_SetEnabledMask, 1) == 0),
3452− "Failed to force MCLK DPM0!",
3453− return -1);
3454−
3455− PP_ASSERT_WITH_CODE(
3456− (smum_send_msg_to_smc(hwmgr->smumgr,
3457− PPSMC_MSG_MCLKDPM_Disable) == 0),
3458− "Failed to disable MCLK DPM!",
3459− return -1);
3460− }
3461−
3462− return 0;
3463−}
3464−
3465−static int fiji_stop_dpm(struct pp_hwmgr *hwmgr)
3466−{
3467− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3468−
3469− /* disable general power management */
3470− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
3471− GLOBAL_PWRMGT_EN, 0);
3472− /* disable sclk deep sleep */
3473− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL,
3474− DYNAMIC_PM_EN, 0);
3475−
3476− /* disable PCIE dpm */
3477− if (!data->pcie_dpm_key_disabled) {
3478− PP_ASSERT_WITH_CODE(
3479− (smum_send_msg_to_smc(hwmgr->smumgr,
3480− PPSMC_MSG_PCIeDPM_Disable) == 0),
3481− "Failed to disable pcie DPM during DPM Stop Function!",
3482− return -1);
3483− }
3484−
3485− if (fiji_disable_sclk_mclk_dpm(hwmgr)) {
3486− printk(KERN_ERR "Failed to disable Sclk DPM and Mclk DPM!");
3487− return -1;
3488− }
3489−
3490− PP_ASSERT_WITH_CODE(
3491− (smum_send_msg_to_smc(hwmgr->smumgr,
3492− PPSMC_MSG_Voltage_Cntl_Disable) == 0),
3493− "Failed to disable voltage DPM during DPM Stop Function!",
3494− return -1);
3495−
3496− return 0;
3497−}
3498−
3499−static void fiji_set_dpm_event_sources(struct pp_hwmgr *hwmgr,
3500− uint32_t sources)
3501−{
3502− bool protection;
3503− enum DPM_EVENT_SRC src;
3504−
3505− switch (sources) {
3506− default:
3507− printk(KERN_ERR "Unknown throttling event sources.");
3508− /* fall through */
3509− case 0:
3510− protection = false;
3511− /* src is unused */
3512− break;
3513− case (1 << PHM_AutoThrottleSource_Thermal):
3514− protection = true;
3515− src = DPM_EVENT_SRC_DIGITAL;
3516− break;
3517− case (1 << PHM_AutoThrottleSource_External):
3518− protection = true;
3519− src = DPM_EVENT_SRC_EXTERNAL;
3520− break;
3521− case (1 << PHM_AutoThrottleSource_External) |
3522− (1 << PHM_AutoThrottleSource_Thermal):
3523− protection = true;
3524− src = DPM_EVENT_SRC_DIGITAL_OR_EXTERNAL;
3525− break;
3526− }
3527− /* Order matters - don't enable thermal protection for the wrong source. */
3528− if (protection) {
3529− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_THERMAL_CTRL,
3530− DPM_EVENT_SRC, src);
3531− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
3532− THERMAL_PROTECTION_DIS,
3533− !phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3534− PHM_PlatformCaps_ThermalController));
3535− } else
3536− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
3537− THERMAL_PROTECTION_DIS, 1);
3538−}
3539−
3540−static int fiji_enable_auto_throttle_source(struct pp_hwmgr *hwmgr,
3541− PHM_AutoThrottleSource source)
3542−{
3543− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3544−
3545− if (!(data->active_auto_throttle_sources & (1 << source))) {
3546− data->active_auto_throttle_sources |= 1 << source;
3547− fiji_set_dpm_event_sources(hwmgr, data->active_auto_throttle_sources);
3548− }
3549− return 0;
3550−}
3551−
3552−static int fiji_enable_thermal_auto_throttle(struct pp_hwmgr *hwmgr)
3553−{
3554− return fiji_enable_auto_throttle_source(hwmgr, PHM_AutoThrottleSource_Thermal);
3555−}
3556−
3557−static int fiji_disable_auto_throttle_source(struct pp_hwmgr *hwmgr,
3558− PHM_AutoThrottleSource source)
3559−{
3560− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3561−
3562− if (data->active_auto_throttle_sources & (1 << source)) {
3563− data->active_auto_throttle_sources &= ~(1 << source);
3564− fiji_set_dpm_event_sources(hwmgr, data->active_auto_throttle_sources);
3565− }
3566− return 0;
3567−}
3568−
3569−static int fiji_disable_thermal_auto_throttle(struct pp_hwmgr *hwmgr)
3570−{
3571− return fiji_disable_auto_throttle_source(hwmgr, PHM_AutoThrottleSource_Thermal);
3572−}
3573−
3574−static int fiji_enable_dpm_tasks(struct pp_hwmgr *hwmgr)
3575−{
3576− int tmp_result, result = 0;
3577−
3578− tmp_result = (!fiji_is_dpm_running(hwmgr))? 0 : -1;
3579− PP_ASSERT_WITH_CODE(result == 0,
3580− "DPM is already running right now, no need to enable DPM!",
3581− return 0);
3582−
3583− if (fiji_voltage_control(hwmgr)) {
3584− tmp_result = fiji_enable_voltage_control(hwmgr);
3585− PP_ASSERT_WITH_CODE(tmp_result == 0,
3586− "Failed to enable voltage control!",
3587− result = tmp_result);
3588− }
3589−
3590− if (fiji_voltage_control(hwmgr)) {
3591− tmp_result = fiji_construct_voltage_tables(hwmgr);
3592− PP_ASSERT_WITH_CODE((0 == tmp_result),
3593− "Failed to contruct voltage tables!",
3594− result = tmp_result);
3595− }
3596−
3597− tmp_result = fiji_initialize_mc_reg_table(hwmgr);
3598− PP_ASSERT_WITH_CODE((0 == tmp_result),
3599− "Failed to initialize MC reg table!", result = tmp_result);
3600−
3601− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3602− PHM_PlatformCaps_EngineSpreadSpectrumSupport))
3603− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
3604− GENERAL_PWRMGT, DYN_SPREAD_SPECTRUM_EN, 1);
3605−
3606− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3607− PHM_PlatformCaps_ThermalController))
3608− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
3609− GENERAL_PWRMGT, THERMAL_PROTECTION_DIS, 0);
3610−
3611− tmp_result = fiji_program_static_screen_threshold_parameters(hwmgr);
3612− PP_ASSERT_WITH_CODE((0 == tmp_result),
3613− "Failed to program static screen threshold parameters!",
3614− result = tmp_result);
3615−
3616− tmp_result = fiji_enable_display_gap(hwmgr);
3617− PP_ASSERT_WITH_CODE((0 == tmp_result),
3618− "Failed to enable display gap!", result = tmp_result);
3619−
3620− tmp_result = fiji_program_voting_clients(hwmgr);
3621− PP_ASSERT_WITH_CODE((0 == tmp_result),
3622− "Failed to program voting clients!", result = tmp_result);
3623−
3624− tmp_result = fiji_process_firmware_header(hwmgr);
3625− PP_ASSERT_WITH_CODE((0 == tmp_result),
3626− "Failed to process firmware header!", result = tmp_result);
3627−
3628− tmp_result = fiji_initial_switch_from_arbf0_to_f1(hwmgr);
3629− PP_ASSERT_WITH_CODE((0 == tmp_result),
3630− "Failed to initialize switch from ArbF0 to F1!",
3631− result = tmp_result);
3632−
3633− tmp_result = fiji_init_smc_table(hwmgr);
3634− PP_ASSERT_WITH_CODE((0 == tmp_result),
3635− "Failed to initialize SMC table!", result = tmp_result);
3636−
3637− tmp_result = fiji_init_arb_table_index(hwmgr);
3638− PP_ASSERT_WITH_CODE((0 == tmp_result),
3639− "Failed to initialize ARB table index!", result = tmp_result);
3640−
3641− tmp_result = fiji_populate_pm_fuses(hwmgr);
3642− PP_ASSERT_WITH_CODE((0 == tmp_result),
3643− "Failed to populate PM fuses!", result = tmp_result);
3644−
3645− tmp_result = fiji_enable_vrhot_gpio_interrupt(hwmgr);
3646− PP_ASSERT_WITH_CODE((0 == tmp_result),
3647− "Failed to enable VR hot GPIO interrupt!", result = tmp_result);
3648−
3649− tmp_result = tonga_notify_smc_display_change(hwmgr, false);
3650− PP_ASSERT_WITH_CODE((0 == tmp_result),
3651− "Failed to notify no display!", result = tmp_result);
3652−
3653− tmp_result = fiji_enable_sclk_control(hwmgr);
3654− PP_ASSERT_WITH_CODE((0 == tmp_result),
3655− "Failed to enable SCLK control!", result = tmp_result);
3656−
3657− tmp_result = fiji_enable_ulv(hwmgr);
3658− PP_ASSERT_WITH_CODE((0 == tmp_result),
3659− "Failed to enable ULV!", result = tmp_result);
3660−
3661− tmp_result = fiji_enable_deep_sleep_master_switch(hwmgr);
3662− PP_ASSERT_WITH_CODE((0 == tmp_result),
3663− "Failed to enable deep sleep master switch!", result = tmp_result);
3664−
3665− tmp_result = fiji_start_dpm(hwmgr);
3666− PP_ASSERT_WITH_CODE((0 == tmp_result),
3667− "Failed to start DPM!", result = tmp_result);
3668−
3669− tmp_result = fiji_enable_smc_cac(hwmgr);
3670− PP_ASSERT_WITH_CODE((0 == tmp_result),
3671− "Failed to enable SMC CAC!", result = tmp_result);
3672−
3673− tmp_result = fiji_enable_power_containment(hwmgr);
3674− PP_ASSERT_WITH_CODE((0 == tmp_result),
3675− "Failed to enable power containment!", result = tmp_result);
3676−
3677− tmp_result = fiji_power_control_set_level(hwmgr);
3678− PP_ASSERT_WITH_CODE((0 == tmp_result),
3679− "Failed to power control set level!", result = tmp_result);
3680−
3681− tmp_result = fiji_enable_thermal_auto_throttle(hwmgr);
3682− PP_ASSERT_WITH_CODE((0 == tmp_result),
3683− "Failed to enable thermal auto throttle!", result = tmp_result);
3684−
3685− return result;
3686−}
3687−
3688−static int fiji_disable_dpm_tasks(struct pp_hwmgr *hwmgr)
3689−{
3690− int tmp_result, result = 0;
3691−
3692− tmp_result = (fiji_is_dpm_running(hwmgr)) ? 0 : -1;
3693− PP_ASSERT_WITH_CODE(tmp_result == 0,
3694− "DPM is not running right now, no need to disable DPM!",
3695− return 0);
3696−
3697− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3698− PHM_PlatformCaps_ThermalController))
3699− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
3700− GENERAL_PWRMGT, THERMAL_PROTECTION_DIS, 1);
3701−
3702− tmp_result = fiji_disable_power_containment(hwmgr);
3703− PP_ASSERT_WITH_CODE((tmp_result == 0),
3704− "Failed to disable power containment!", result = tmp_result);
3705−
3706− tmp_result = fiji_disable_smc_cac(hwmgr);
3707− PP_ASSERT_WITH_CODE((tmp_result == 0),
3708− "Failed to disable SMC CAC!", result = tmp_result);
3709−
3710− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
3711− CG_SPLL_SPREAD_SPECTRUM, SSEN, 0);
3712− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
3713− GENERAL_PWRMGT, DYN_SPREAD_SPECTRUM_EN, 0);
3714−
3715− tmp_result = fiji_disable_thermal_auto_throttle(hwmgr);
3716− PP_ASSERT_WITH_CODE((tmp_result == 0),
3717− "Failed to disable thermal auto throttle!", result = tmp_result);
3718−
3719− tmp_result = fiji_stop_dpm(hwmgr);
3720− PP_ASSERT_WITH_CODE((tmp_result == 0),
3721− "Failed to stop DPM!", result = tmp_result);
3722−
3723− tmp_result = fiji_disable_deep_sleep_master_switch(hwmgr);
3724− PP_ASSERT_WITH_CODE((tmp_result == 0),
3725− "Failed to disable deep sleep master switch!", result = tmp_result);
3726−
3727− tmp_result = fiji_disable_ulv(hwmgr);
3728− PP_ASSERT_WITH_CODE((tmp_result == 0),
3729− "Failed to disable ULV!", result = tmp_result);
3730−
3731− tmp_result = fiji_clear_voting_clients(hwmgr);
3732− PP_ASSERT_WITH_CODE((tmp_result == 0),
3733− "Failed to clear voting clients!", result = tmp_result);
3734−
3735− tmp_result = fiji_reset_to_default(hwmgr);
3736− PP_ASSERT_WITH_CODE((tmp_result == 0),
3737− "Failed to reset to default!", result = tmp_result);
3738−
3739− tmp_result = fiji_force_switch_to_arbf0(hwmgr);
3740− PP_ASSERT_WITH_CODE((tmp_result == 0),
3741− "Failed to force to switch arbf0!", result = tmp_result);
3742−
3743− return result;
3744−}
3745−
3746−static int fiji_force_dpm_highest(struct pp_hwmgr *hwmgr)
3747−{
3748− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3749− uint32_t level, tmp;
3750−
3751− if (!data->sclk_dpm_key_disabled) {
3752− if (data->dpm_level_enable_mask.sclk_dpm_enable_mask) {
3753− level = 0;
3754− tmp = data->dpm_level_enable_mask.sclk_dpm_enable_mask;
3755− while (tmp >>= 1)
3756− level++;
3757− if (level)
3758− smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3759− PPSMC_MSG_SCLKDPM_SetEnabledMask,
3760− (1 << level));
3761− }
3762− }
3763−
3764− if (!data->mclk_dpm_key_disabled) {
3765− if (data->dpm_level_enable_mask.mclk_dpm_enable_mask) {
3766− level = 0;
3767− tmp = data->dpm_level_enable_mask.mclk_dpm_enable_mask;
3768− while (tmp >>= 1)
3769− level++;
3770− if (level)
3771− smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3772− PPSMC_MSG_MCLKDPM_SetEnabledMask,
3773− (1 << level));
3774− }
3775− }
3776−
3777− if (!data->pcie_dpm_key_disabled) {
3778− if (data->dpm_level_enable_mask.pcie_dpm_enable_mask) {
3779− level = 0;
3780− tmp = data->dpm_level_enable_mask.pcie_dpm_enable_mask;
3781− while (tmp >>= 1)
3782− level++;
3783− if (level)
3784− smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3785− PPSMC_MSG_PCIeDPM_ForceLevel,
3786− (1 << level));
3787− }
3788− }
3789− return 0;
3790−}
3791−
3792−static int fiji_upload_dpmlevel_enable_mask(struct pp_hwmgr *hwmgr)
3793−{
3794− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3795−
3796− phm_apply_dal_min_voltage_request(hwmgr);
3797−
3798− if (!data->sclk_dpm_key_disabled) {
3799− if (data->dpm_level_enable_mask.sclk_dpm_enable_mask)
3800− smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3801− PPSMC_MSG_SCLKDPM_SetEnabledMask,
3802− data->dpm_level_enable_mask.sclk_dpm_enable_mask);
3803− }
3804− return 0;
3805−}
3806−
3807−static int fiji_unforce_dpm_levels(struct pp_hwmgr *hwmgr)
3808−{
3809− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3810−
3811− if (!fiji_is_dpm_running(hwmgr))
3812− return -EINVAL;
3813−
3814− if (!data->pcie_dpm_key_disabled) {
3815− smum_send_msg_to_smc(hwmgr->smumgr,
3816− PPSMC_MSG_PCIeDPM_UnForceLevel);
3817− }
3818−
3819− return fiji_upload_dpmlevel_enable_mask(hwmgr);
3820−}
3821−
3822−static uint32_t fiji_get_lowest_enabled_level(
3823− struct pp_hwmgr *hwmgr, uint32_t mask)
3824−{
3825− uint32_t level = 0;
3826−
3827− while(0 == (mask & (1 << level)))
3828− level++;
3829−
3830− return level;
3831−}
3832−
3833−static int fiji_force_dpm_lowest(struct pp_hwmgr *hwmgr)
3834−{
3835− struct fiji_hwmgr *data =
3836− (struct fiji_hwmgr *)(hwmgr->backend);
3837− uint32_t level;
3838−
3839− if (!data->sclk_dpm_key_disabled)
3840− if (data->dpm_level_enable_mask.sclk_dpm_enable_mask) {
3841− level = fiji_get_lowest_enabled_level(hwmgr,
3842− data->dpm_level_enable_mask.sclk_dpm_enable_mask);
3843− smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3844− PPSMC_MSG_SCLKDPM_SetEnabledMask,
3845− (1 << level));
3846−
3847− }
3848−
3849− if (!data->mclk_dpm_key_disabled) {
3850− if (data->dpm_level_enable_mask.mclk_dpm_enable_mask) {
3851− level = fiji_get_lowest_enabled_level(hwmgr,
3852− data->dpm_level_enable_mask.mclk_dpm_enable_mask);
3853− smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3854− PPSMC_MSG_MCLKDPM_SetEnabledMask,
3855− (1 << level));
3856− }
3857− }
3858−
3859− if (!data->pcie_dpm_key_disabled) {
3860− if (data->dpm_level_enable_mask.pcie_dpm_enable_mask) {
3861− level = fiji_get_lowest_enabled_level(hwmgr,
3862− data->dpm_level_enable_mask.pcie_dpm_enable_mask);
3863− smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3864− PPSMC_MSG_PCIeDPM_ForceLevel,
3865− (1 << level));
3866− }
3867− }
3868−
3869− return 0;
3870−
3871−}
3872−static int fiji_dpm_force_dpm_level(struct pp_hwmgr *hwmgr,
3873− enum amd_dpm_forced_level level)
3874−{
3875− int ret = 0;
3876−
3877− switch (level) {
3878− case AMD_DPM_FORCED_LEVEL_HIGH:
3879− ret = fiji_force_dpm_highest(hwmgr);
3880− if (ret)
3881− return ret;
3882− break;
3883− case AMD_DPM_FORCED_LEVEL_LOW:
3884− ret = fiji_force_dpm_lowest(hwmgr);
3885− if (ret)
3886− return ret;
3887− break;
3888− case AMD_DPM_FORCED_LEVEL_AUTO:
3889− ret = fiji_unforce_dpm_levels(hwmgr);
3890− if (ret)
3891− return ret;
3892− break;
3893− default:
3894− break;
3895− }
3896−
3897− hwmgr->dpm_level = level;
3898−
3899− return ret;
3900−}
3901−
3902−static int fiji_get_power_state_size(struct pp_hwmgr *hwmgr)
3903−{
3904− return sizeof(struct fiji_power_state);
3905−}
3906−
3907−static int fiji_get_pp_table_entry_callback_func(struct pp_hwmgr *hwmgr,
3908− void *state, struct pp_power_state *power_state,
3909− void *pp_table, uint32_t classification_flag)
3910−{
3911− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3912− struct fiji_power_state *fiji_power_state =
3913− (struct fiji_power_state *)(&(power_state->hardware));
3914− struct fiji_performance_level *performance_level;
3915− ATOM_Tonga_State *state_entry = (ATOM_Tonga_State *)state;
3916− ATOM_Tonga_POWERPLAYTABLE *powerplay_table =
3917− (ATOM_Tonga_POWERPLAYTABLE *)pp_table;
3918− ATOM_Tonga_SCLK_Dependency_Table *sclk_dep_table =
3919− (ATOM_Tonga_SCLK_Dependency_Table *)
3920− (((unsigned long)powerplay_table) +
3921− le16_to_cpu(powerplay_table->usSclkDependencyTableOffset));
3922− ATOM_Tonga_MCLK_Dependency_Table *mclk_dep_table =
3923− (ATOM_Tonga_MCLK_Dependency_Table *)
3924− (((unsigned long)powerplay_table) +
3925− le16_to_cpu(powerplay_table->usMclkDependencyTableOffset));
3926−
3927− /* The following fields are not initialized here: id orderedList allStatesList */
3928− power_state->classification.ui_label =
3929− (le16_to_cpu(state_entry->usClassification) &
3930− ATOM_PPLIB_CLASSIFICATION_UI_MASK) >>
3931− ATOM_PPLIB_CLASSIFICATION_UI_SHIFT;
3932− power_state->classification.flags = classification_flag;
3933− /* NOTE: There is a classification2 flag in BIOS that is not being used right now */
3934−
3935− power_state->classification.temporary_state = false;
3936− power_state->classification.to_be_deleted = false;
3937−
3938− power_state->validation.disallowOnDC =
3939− (0 != (le32_to_cpu(state_entry->ulCapsAndSettings) &
3940− ATOM_Tonga_DISALLOW_ON_DC));
3941−
3942− power_state->pcie.lanes = 0;
3943−
3944− power_state->display.disableFrameModulation = false;
3945− power_state->display.limitRefreshrate = false;
3946− power_state->display.enableVariBright =
3947− (0 != (le32_to_cpu(state_entry->ulCapsAndSettings) &
3948− ATOM_Tonga_ENABLE_VARIBRIGHT));
3949−
3950− power_state->validation.supportedPowerLevels = 0;
3951− power_state->uvd_clocks.VCLK = 0;
3952− power_state->uvd_clocks.DCLK = 0;
3953− power_state->temperatures.min = 0;
3954− power_state->temperatures.max = 0;
3955−
3956− performance_level = &(fiji_power_state->performance_levels
3957− [fiji_power_state->performance_level_count++]);
3958−
3959− PP_ASSERT_WITH_CODE(
3960− (fiji_power_state->performance_level_count < SMU73_MAX_LEVELS_GRAPHICS),
3961− "Performance levels exceeds SMC limit!",
3962− return -1);
3963−
3964− PP_ASSERT_WITH_CODE(
3965− (fiji_power_state->performance_level_count <=
3966− hwmgr->platform_descriptor.hardwareActivityPerformanceLevels),
3967− "Performance levels exceeds Driver limit!",
3968− return -1);
3969−
3970− /* Performance levels are arranged from low to high. */
3971− performance_level->memory_clock = mclk_dep_table->entries
3972− [state_entry->ucMemoryClockIndexLow].ulMclk;
3973− performance_level->engine_clock = sclk_dep_table->entries
3974− [state_entry->ucEngineClockIndexLow].ulSclk;
3975− performance_level->pcie_gen = get_pcie_gen_support(data->pcie_gen_cap,
3976− state_entry->ucPCIEGenLow);
3977− performance_level->pcie_lane = get_pcie_lane_support(data->pcie_lane_cap,
3978− state_entry->ucPCIELaneHigh);
3979−
3980− performance_level = &(fiji_power_state->performance_levels
3981− [fiji_power_state->performance_level_count++]);
3982− performance_level->memory_clock = mclk_dep_table->entries
3983− [state_entry->ucMemoryClockIndexHigh].ulMclk;
3984− performance_level->engine_clock = sclk_dep_table->entries
3985− [state_entry->ucEngineClockIndexHigh].ulSclk;
3986− performance_level->pcie_gen = get_pcie_gen_support(data->pcie_gen_cap,
3987− state_entry->ucPCIEGenHigh);
3988− performance_level->pcie_lane = get_pcie_lane_support(data->pcie_lane_cap,
3989− state_entry->ucPCIELaneHigh);
3990−
3991− return 0;
3992−}
3993−
3994−static int fiji_get_pp_table_entry(struct pp_hwmgr *hwmgr,
3995− unsigned long entry_index, struct pp_power_state *state)
3996−{
3997− int result;
3998− struct fiji_power_state *ps;
3999− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4000− struct phm_ppt_v1_information *table_info =
4001− (struct phm_ppt_v1_information *)(hwmgr->pptable);
4002− struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table =
4003− table_info->vdd_dep_on_mclk;
4004−
4005− state->hardware.magic = PHM_VIslands_Magic;
4006−
4007− ps = (struct fiji_power_state *)(&state->hardware);
4008−
4009− result = get_powerplay_table_entry_v1_0(hwmgr, entry_index, state,
4010− fiji_get_pp_table_entry_callback_func);
4011−
4012− /* This is the earliest time we have all the dependency table and the VBIOS boot state
4013− * as PP_Tables_GetPowerPlayTableEntry retrieves the VBIOS boot state
4014− * if there is only one VDDCI/MCLK level, check if it's the same as VBIOS boot state
4015− */
4016− if (dep_mclk_table != NULL && dep_mclk_table->count == 1) {
4017− if (dep_mclk_table->entries[0].clk !=
4018− data->vbios_boot_state.mclk_bootup_value)
4019− printk(KERN_ERR "Single MCLK entry VDDCI/MCLK dependency table "
4020− "does not match VBIOS boot MCLK level");
4021− if (dep_mclk_table->entries[0].vddci !=
4022− data->vbios_boot_state.vddci_bootup_value)
4023− printk(KERN_ERR "Single VDDCI entry VDDCI/MCLK dependency table "
4024− "does not match VBIOS boot VDDCI level");
4025− }
4026−
4027− /* set DC compatible flag if this state supports DC */
4028− if (!state->validation.disallowOnDC)
4029− ps->dc_compatible = true;
4030−
4031− if (state->classification.flags & PP_StateClassificationFlag_ACPI)
4032− data->acpi_pcie_gen = ps->performance_levels[0].pcie_gen;
4033−
4034− ps->uvd_clks.vclk = state->uvd_clocks.VCLK;
4035− ps->uvd_clks.dclk = state->uvd_clocks.DCLK;
4036−
4037− if (!result) {
4038− uint32_t i;
4039−
4040− switch (state->classification.ui_label) {
4041− case PP_StateUILabel_Performance:
4042− data->use_pcie_performance_levels = true;
4043−
4044− for (i = 0; i < ps->performance_level_count; i++) {
4045− if (data->pcie_gen_performance.max <
4046− ps->performance_levels[i].pcie_gen)
4047− data->pcie_gen_performance.max =
4048− ps->performance_levels[i].pcie_gen;
4049−
4050− if (data->pcie_gen_performance.min >
4051− ps->performance_levels[i].pcie_gen)
4052− data->pcie_gen_performance.min =
4053− ps->performance_levels[i].pcie_gen;
4054−
4055− if (data->pcie_lane_performance.max <
4056− ps->performance_levels[i].pcie_lane)
4057− data->pcie_lane_performance.max =
4058− ps->performance_levels[i].pcie_lane;
4059−
4060− if (data->pcie_lane_performance.min >
4061− ps->performance_levels[i].pcie_lane)
4062− data->pcie_lane_performance.min =
4063− ps->performance_levels[i].pcie_lane;
4064− }
4065− break;
4066− case PP_StateUILabel_Battery:
4067− data->use_pcie_power_saving_levels = true;
4068−
4069− for (i = 0; i < ps->performance_level_count; i++) {
4070− if (data->pcie_gen_power_saving.max <
4071− ps->performance_levels[i].pcie_gen)
4072− data->pcie_gen_power_saving.max =
4073− ps->performance_levels[i].pcie_gen;
4074−
4075− if (data->pcie_gen_power_saving.min >
4076− ps->performance_levels[i].pcie_gen)
4077− data->pcie_gen_power_saving.min =
4078− ps->performance_levels[i].pcie_gen;
4079−
4080− if (data->pcie_lane_power_saving.max <
4081− ps->performance_levels[i].pcie_lane)
4082− data->pcie_lane_power_saving.max =
4083− ps->performance_levels[i].pcie_lane;
4084−
4085− if (data->pcie_lane_power_saving.min >
4086− ps->performance_levels[i].pcie_lane)
4087− data->pcie_lane_power_saving.min =
4088− ps->performance_levels[i].pcie_lane;
4089− }
4090− break;
4091− default:
4092− break;
4093− }
4094− }
4095− return 0;
4096−}
4097−
4098−static int fiji_apply_state_adjust_rules(struct pp_hwmgr *hwmgr,
4099− struct pp_power_state *request_ps,
4100− const struct pp_power_state *current_ps)
4101−{
4102− struct fiji_power_state *fiji_ps =
4103− cast_phw_fiji_power_state(&request_ps->hardware);
4104− uint32_t sclk;
4105− uint32_t mclk;
4106− struct PP_Clocks minimum_clocks = {0};
4107− bool disable_mclk_switching;
4108− bool disable_mclk_switching_for_frame_lock;
4109− struct cgs_display_info info = {0};
4110− const struct phm_clock_and_voltage_limits *max_limits;
4111− uint32_t i;
4112− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4113− struct phm_ppt_v1_information *table_info =
4114− (struct phm_ppt_v1_information *)(hwmgr->pptable);
4115− int32_t count;
4116− int32_t stable_pstate_sclk = 0, stable_pstate_mclk = 0;
4117−
4118− data->battery_state = (PP_StateUILabel_Battery ==
4119− request_ps->classification.ui_label);
4120−
4121− PP_ASSERT_WITH_CODE(fiji_ps->performance_level_count == 2,
4122− "VI should always have 2 performance levels",);
4123−
4124− max_limits = (PP_PowerSource_AC == hwmgr->power_source) ?
4125− &(hwmgr->dyn_state.max_clock_voltage_on_ac) :
4126− &(hwmgr->dyn_state.max_clock_voltage_on_dc);
4127−
4128− /* Cap clock DPM tables at DC MAX if it is in DC. */
4129− if (PP_PowerSource_DC == hwmgr->power_source) {
4130− for (i = 0; i < fiji_ps->performance_level_count; i++) {
4131− if (fiji_ps->performance_levels[i].memory_clock > max_limits->mclk)
4132− fiji_ps->performance_levels[i].memory_clock = max_limits->mclk;
4133− if (fiji_ps->performance_levels[i].engine_clock > max_limits->sclk)
4134− fiji_ps->performance_levels[i].engine_clock = max_limits->sclk;
4135− }
4136− }
4137−
4138− fiji_ps->vce_clks.evclk = hwmgr->vce_arbiter.evclk;
4139− fiji_ps->vce_clks.ecclk = hwmgr->vce_arbiter.ecclk;
4140−
4141− fiji_ps->acp_clk = hwmgr->acp_arbiter.acpclk;
4142−
4143− cgs_get_active_displays_info(hwmgr->device, &info);
4144−
4145− /*TO DO result = PHM_CheckVBlankTime(hwmgr, &vblankTooShort);*/
4146−
4147− /* TO DO GetMinClockSettings(hwmgr->pPECI, &minimum_clocks); */
4148−
4149− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4150− PHM_PlatformCaps_StablePState)) {
4151− max_limits = &(hwmgr->dyn_state.max_clock_voltage_on_ac);
4152− stable_pstate_sclk = (max_limits->sclk * 75) / 100;
4153−
4154− for (count = table_info->vdd_dep_on_sclk->count - 1;
4155− count >= 0; count--) {
4156− if (stable_pstate_sclk >=
4157− table_info->vdd_dep_on_sclk->entries[count].clk) {
4158− stable_pstate_sclk =
4159− table_info->vdd_dep_on_sclk->entries[count].clk;
4160− break;
4161− }
4162− }
4163−
4164− if (count < 0)
4165− stable_pstate_sclk = table_info->vdd_dep_on_sclk->entries[0].clk;
4166−
4167− stable_pstate_mclk = max_limits->mclk;
4168−
4169− minimum_clocks.engineClock = stable_pstate_sclk;
4170− minimum_clocks.memoryClock = stable_pstate_mclk;
4171− }
4172−
4173− if (minimum_clocks.engineClock < hwmgr->gfx_arbiter.sclk)
4174− minimum_clocks.engineClock = hwmgr->gfx_arbiter.sclk;
4175−
4176− if (minimum_clocks.memoryClock < hwmgr->gfx_arbiter.mclk)
4177− minimum_clocks.memoryClock = hwmgr->gfx_arbiter.mclk;
4178−
4179− fiji_ps->sclk_threshold = hwmgr->gfx_arbiter.sclk_threshold;
4180−
4181− if (0 != hwmgr->gfx_arbiter.sclk_over_drive) {
4182− PP_ASSERT_WITH_CODE((hwmgr->gfx_arbiter.sclk_over_drive <=
4183− hwmgr->platform_descriptor.overdriveLimit.engineClock),
4184− "Overdrive sclk exceeds limit",
4185− hwmgr->gfx_arbiter.sclk_over_drive =
4186− hwmgr->platform_descriptor.overdriveLimit.engineClock);
4187−
4188− if (hwmgr->gfx_arbiter.sclk_over_drive >= hwmgr->gfx_arbiter.sclk)
4189− fiji_ps->performance_levels[1].engine_clock =
4190− hwmgr->gfx_arbiter.sclk_over_drive;
4191− }
4192−
4193− if (0 != hwmgr->gfx_arbiter.mclk_over_drive) {
4194− PP_ASSERT_WITH_CODE((hwmgr->gfx_arbiter.mclk_over_drive <=
4195− hwmgr->platform_descriptor.overdriveLimit.memoryClock),
4196− "Overdrive mclk exceeds limit",
4197− hwmgr->gfx_arbiter.mclk_over_drive =
4198− hwmgr->platform_descriptor.overdriveLimit.memoryClock);
4199−
4200− if (hwmgr->gfx_arbiter.mclk_over_drive >= hwmgr->gfx_arbiter.mclk)
4201− fiji_ps->performance_levels[1].memory_clock =
4202− hwmgr->gfx_arbiter.mclk_over_drive;
4203− }
4204−
4205− disable_mclk_switching_for_frame_lock = phm_cap_enabled(
4206− hwmgr->platform_descriptor.platformCaps,
4207− PHM_PlatformCaps_DisableMclkSwitchingForFrameLock);
4208−
4209− disable_mclk_switching = (1 < info.display_count) ||
4210− disable_mclk_switching_for_frame_lock;
4211−
4212− sclk = fiji_ps->performance_levels[0].engine_clock;
4213− mclk = fiji_ps->performance_levels[0].memory_clock;
4214−
4215− if (disable_mclk_switching)
4216− mclk = fiji_ps->performance_levels
4217− [fiji_ps->performance_level_count - 1].memory_clock;
4218−
4219− if (sclk < minimum_clocks.engineClock)
4220− sclk = (minimum_clocks.engineClock > max_limits->sclk) ?
4221− max_limits->sclk : minimum_clocks.engineClock;
4222−
4223− if (mclk < minimum_clocks.memoryClock)
4224− mclk = (minimum_clocks.memoryClock > max_limits->mclk) ?
4225− max_limits->mclk : minimum_clocks.memoryClock;
4226−
4227− fiji_ps->performance_levels[0].engine_clock = sclk;
4228− fiji_ps->performance_levels[0].memory_clock = mclk;
4229−
4230− fiji_ps->performance_levels[1].engine_clock =
4231− (fiji_ps->performance_levels[1].engine_clock >=
4232− fiji_ps->performance_levels[0].engine_clock) ?
4233− fiji_ps->performance_levels[1].engine_clock :
4234− fiji_ps->performance_levels[0].engine_clock;
4235−
4236− if (disable_mclk_switching) {
4237− if (mclk < fiji_ps->performance_levels[1].memory_clock)
4238− mclk = fiji_ps->performance_levels[1].memory_clock;
4239−
4240− fiji_ps->performance_levels[0].memory_clock = mclk;
4241− fiji_ps->performance_levels[1].memory_clock = mclk;
4242− } else {
4243− if (fiji_ps->performance_levels[1].memory_clock <
4244− fiji_ps->performance_levels[0].memory_clock)
4245− fiji_ps->performance_levels[1].memory_clock =
4246− fiji_ps->performance_levels[0].memory_clock;
4247− }
4248−
4249− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4250− PHM_PlatformCaps_StablePState)) {
4251− for (i = 0; i < fiji_ps->performance_level_count; i++) {
4252− fiji_ps->performance_levels[i].engine_clock = stable_pstate_sclk;
4253− fiji_ps->performance_levels[i].memory_clock = stable_pstate_mclk;
4254− fiji_ps->performance_levels[i].pcie_gen = data->pcie_gen_performance.max;
4255− fiji_ps->performance_levels[i].pcie_lane = data->pcie_gen_performance.max;
4256− }
4257− }
4258−
4259− return 0;
4260−}
4261−
4262−static int fiji_find_dpm_states_clocks_in_dpm_table(struct pp_hwmgr *hwmgr, const void *input)
4263−{
4264− const struct phm_set_power_state_input *states =
4265− (const struct phm_set_power_state_input *)input;
4266− const struct fiji_power_state *fiji_ps =
4267− cast_const_phw_fiji_power_state(states->pnew_state);
4268− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4269− struct fiji_single_dpm_table *sclk_table = &(data->dpm_table.sclk_table);
4270− uint32_t sclk = fiji_ps->performance_levels
4271− [fiji_ps->performance_level_count - 1].engine_clock;
4272− struct fiji_single_dpm_table *mclk_table = &(data->dpm_table.mclk_table);
4273− uint32_t mclk = fiji_ps->performance_levels
4274− [fiji_ps->performance_level_count - 1].memory_clock;
4275− uint32_t i;
4276− struct cgs_display_info info = {0};
4277−
4278− data->need_update_smu7_dpm_table = 0;
4279−
4280− for (i = 0; i < sclk_table->count; i++) {
4281− if (sclk == sclk_table->dpm_levels[i].value)
4282− break;
4283− }
4284−
4285− if (i >= sclk_table->count)
4286− data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_SCLK;
4287− else {
4288− if(data->display_timing.min_clock_in_sr !=
4289− hwmgr->display_config.min_core_set_clock_in_sr)
4290− data->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_SCLK;
4291− }
4292−
4293− for (i = 0; i < mclk_table->count; i++) {
4294− if (mclk == mclk_table->dpm_levels[i].value)
4295− break;
4296− }
4297−
4298− if (i >= mclk_table->count)
4299− data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_MCLK;
4300−
4301− cgs_get_active_displays_info(hwmgr->device, &info);
4302−
4303− if (data->display_timing.num_existing_displays != info.display_count)
4304− data->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_MCLK;
4305−
4306− return 0;
4307−}
4308−
4309−static uint16_t fiji_get_maximum_link_speed(struct pp_hwmgr *hwmgr,
4310− const struct fiji_power_state *fiji_ps)
4311−{
4312− uint32_t i;
4313− uint32_t sclk, max_sclk = 0;
4314− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4315− struct fiji_dpm_table *dpm_table = &data->dpm_table;
4316−
4317− for (i = 0; i < fiji_ps->performance_level_count; i++) {
4318− sclk = fiji_ps->performance_levels[i].engine_clock;
4319− if (max_sclk < sclk)
4320− max_sclk = sclk;
4321− }
4322−
4323− for (i = 0; i < dpm_table->sclk_table.count; i++) {
4324− if (dpm_table->sclk_table.dpm_levels[i].value == max_sclk)
4325− return (uint16_t) ((i >= dpm_table->pcie_speed_table.count) ?
4326− dpm_table->pcie_speed_table.dpm_levels
4327− [dpm_table->pcie_speed_table.count - 1].value :
4328− dpm_table->pcie_speed_table.dpm_levels[i].value);
4329− }
4330−
4331− return 0;
4332−}
4333−
4334−static int fiji_request_link_speed_change_before_state_change(
4335− struct pp_hwmgr *hwmgr, const void *input)
4336−{
4337− const struct phm_set_power_state_input *states =
4338− (const struct phm_set_power_state_input *)input;
4339− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4340− const struct fiji_power_state *fiji_nps =
4341− cast_const_phw_fiji_power_state(states->pnew_state);
4342− const struct fiji_power_state *fiji_cps =
4343− cast_const_phw_fiji_power_state(states->pcurrent_state);
4344−
4345− uint16_t target_link_speed = fiji_get_maximum_link_speed(hwmgr, fiji_nps);
4346− uint16_t current_link_speed;
4347−
4348− if (data->force_pcie_gen == PP_PCIEGenInvalid)
4349− current_link_speed = fiji_get_maximum_link_speed(hwmgr, fiji_cps);
4350− else
4351− current_link_speed = data->force_pcie_gen;
4352−
4353− data->force_pcie_gen = PP_PCIEGenInvalid;
4354− data->pspp_notify_required = false;
4355− if (target_link_speed > current_link_speed) {
4356− switch(target_link_speed) {
4357− case PP_PCIEGen3:
4358− if (0 == acpi_pcie_perf_request(hwmgr->device, PCIE_PERF_REQ_GEN3, false))
4359− break;
4360− data->force_pcie_gen = PP_PCIEGen2;
4361− if (current_link_speed == PP_PCIEGen2)
4362− break;
4363− case PP_PCIEGen2:
4364− if (0 == acpi_pcie_perf_request(hwmgr->device, PCIE_PERF_REQ_GEN2, false))
4365− break;
4366− default:
4367− data->force_pcie_gen = fiji_get_current_pcie_speed(hwmgr);
4368− break;
4369− }
4370− } else {
4371− if (target_link_speed < current_link_speed)
4372− data->pspp_notify_required = true;
4373− }
4374−
4375− return 0;
4376−}
4377−
4378−static int fiji_freeze_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
4379−{
4380− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4381−
4382− if (0 == data->need_update_smu7_dpm_table)
4383− return 0;
4384−
4385− if ((0 == data->sclk_dpm_key_disabled) &&
4386− (data->need_update_smu7_dpm_table &
4387− (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK))) {
4388− PP_ASSERT_WITH_CODE(fiji_is_dpm_running(hwmgr),
4389− "Trying to freeze SCLK DPM when DPM is disabled",
4390− );
4391− PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr,
4392− PPSMC_MSG_SCLKDPM_FreezeLevel),
4393− "Failed to freeze SCLK DPM during FreezeSclkMclkDPM Function!",
4394− return -1);
4395− }
4396−
4397− if ((0 == data->mclk_dpm_key_disabled) &&
4398− (data->need_update_smu7_dpm_table &
4399− DPMTABLE_OD_UPDATE_MCLK)) {
4400− PP_ASSERT_WITH_CODE(fiji_is_dpm_running(hwmgr),
4401− "Trying to freeze MCLK DPM when DPM is disabled",
4402− );
4403− PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr,
4404− PPSMC_MSG_MCLKDPM_FreezeLevel),
4405− "Failed to freeze MCLK DPM during FreezeSclkMclkDPM Function!",
4406− return -1);
4407− }
4408−
4409− return 0;
4410−}
4411−
4412−static int fiji_populate_and_upload_sclk_mclk_dpm_levels(
4413− struct pp_hwmgr *hwmgr, const void *input)
4414−{
4415− int result = 0;
4416− const struct phm_set_power_state_input *states =
4417− (const struct phm_set_power_state_input *)input;
4418− const struct fiji_power_state *fiji_ps =
4419− cast_const_phw_fiji_power_state(states->pnew_state);
4420− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4421− uint32_t sclk = fiji_ps->performance_levels
4422− [fiji_ps->performance_level_count - 1].engine_clock;
4423− uint32_t mclk = fiji_ps->performance_levels
4424− [fiji_ps->performance_level_count - 1].memory_clock;
4425− struct fiji_dpm_table *dpm_table = &data->dpm_table;
4426−
4427− struct fiji_dpm_table *golden_dpm_table = &data->golden_dpm_table;
4428− uint32_t dpm_count, clock_percent;
4429− uint32_t i;
4430−
4431− if (0 == data->need_update_smu7_dpm_table)
4432− return 0;
4433−
4434− if (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_SCLK) {
4435− dpm_table->sclk_table.dpm_levels
4436− [dpm_table->sclk_table.count - 1].value = sclk;
4437−
4438− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4439− PHM_PlatformCaps_OD6PlusinACSupport) ||
4440− phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4441− PHM_PlatformCaps_OD6PlusinDCSupport)) {
4442− /* Need to do calculation based on the golden DPM table
4443− * as the Heatmap GPU Clock axis is also based on the default values
4444− */
4445− PP_ASSERT_WITH_CODE(
4446− (golden_dpm_table->sclk_table.dpm_levels
4447− [golden_dpm_table->sclk_table.count - 1].value != 0),
4448− "Divide by 0!",
4449− return -1);
4450− dpm_count = dpm_table->sclk_table.count < 2 ?
4451− 0 : dpm_table->sclk_table.count - 2;
4452− for (i = dpm_count; i > 1; i--) {
4453− if (sclk > golden_dpm_table->sclk_table.dpm_levels
4454− [golden_dpm_table->sclk_table.count-1].value) {
4455− clock_percent =
4456− ((sclk - golden_dpm_table->sclk_table.dpm_levels
4457− [golden_dpm_table->sclk_table.count-1].value) * 100) /
4458− golden_dpm_table->sclk_table.dpm_levels
4459− [golden_dpm_table->sclk_table.count-1].value;
4460−
4461− dpm_table->sclk_table.dpm_levels[i].value =
4462− golden_dpm_table->sclk_table.dpm_levels[i].value +
4463− (golden_dpm_table->sclk_table.dpm_levels[i].value *
4464− clock_percent)/100;
4465−
4466− } else if (golden_dpm_table->sclk_table.dpm_levels
4467− [dpm_table->sclk_table.count-1].value > sclk) {
4468− clock_percent =
4469− ((golden_dpm_table->sclk_table.dpm_levels
4470− [golden_dpm_table->sclk_table.count - 1].value - sclk) *
4471− 100) /
4472− golden_dpm_table->sclk_table.dpm_levels
4473− [golden_dpm_table->sclk_table.count-1].value;
4474−
4475− dpm_table->sclk_table.dpm_levels[i].value =
4476− golden_dpm_table->sclk_table.dpm_levels[i].value -
4477− (golden_dpm_table->sclk_table.dpm_levels[i].value *
4478− clock_percent) / 100;
4479− } else
4480− dpm_table->sclk_table.dpm_levels[i].value =
4481− golden_dpm_table->sclk_table.dpm_levels[i].value;
4482− }
4483− }
4484− }
4485−
4486− if (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK) {
4487− dpm_table->mclk_table.dpm_levels
4488− [dpm_table->mclk_table.count - 1].value = mclk;
4489− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4490− PHM_PlatformCaps_OD6PlusinACSupport) ||
4491− phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4492− PHM_PlatformCaps_OD6PlusinDCSupport)) {
4493−
4494− PP_ASSERT_WITH_CODE(
4495− (golden_dpm_table->mclk_table.dpm_levels
4496− [golden_dpm_table->mclk_table.count-1].value != 0),
4497− "Divide by 0!",
4498− return -1);
4499− dpm_count = dpm_table->mclk_table.count < 2 ?
4500− 0 : dpm_table->mclk_table.count - 2;
4501− for (i = dpm_count; i > 1; i--) {
4502− if (mclk > golden_dpm_table->mclk_table.dpm_levels
4503− [golden_dpm_table->mclk_table.count-1].value) {
4504− clock_percent = ((mclk -
4505− golden_dpm_table->mclk_table.dpm_levels
4506− [golden_dpm_table->mclk_table.count-1].value) * 100) /
4507− golden_dpm_table->mclk_table.dpm_levels
4508− [golden_dpm_table->mclk_table.count-1].value;
4509−
4510− dpm_table->mclk_table.dpm_levels[i].value =
4511− golden_dpm_table->mclk_table.dpm_levels[i].value +
4512− (golden_dpm_table->mclk_table.dpm_levels[i].value *
4513− clock_percent) / 100;
4514−
4515− } else if (golden_dpm_table->mclk_table.dpm_levels
4516− [dpm_table->mclk_table.count-1].value > mclk) {
4517− clock_percent = ((golden_dpm_table->mclk_table.dpm_levels
4518− [golden_dpm_table->mclk_table.count-1].value - mclk) * 100) /
4519− golden_dpm_table->mclk_table.dpm_levels
4520− [golden_dpm_table->mclk_table.count-1].value;
4521−
4522− dpm_table->mclk_table.dpm_levels[i].value =
4523− golden_dpm_table->mclk_table.dpm_levels[i].value -
4524− (golden_dpm_table->mclk_table.dpm_levels[i].value *
4525− clock_percent) / 100;
4526− } else
4527− dpm_table->mclk_table.dpm_levels[i].value =
4528− golden_dpm_table->mclk_table.dpm_levels[i].value;
4529− }
4530− }
4531− }
4532−
4533− if (data->need_update_smu7_dpm_table &
4534− (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK)) {
4535− result = fiji_populate_all_graphic_levels(hwmgr);
4536− PP_ASSERT_WITH_CODE((0 == result),
4537− "Failed to populate SCLK during PopulateNewDPMClocksStates Function!",
4538− return result);
4539− }
4540−
4541− if (data->need_update_smu7_dpm_table &
4542− (DPMTABLE_OD_UPDATE_MCLK + DPMTABLE_UPDATE_MCLK)) {
4543− /*populate MCLK dpm table to SMU7 */
4544− result = fiji_populate_all_memory_levels(hwmgr);
4545− PP_ASSERT_WITH_CODE((0 == result),
4546− "Failed to populate MCLK during PopulateNewDPMClocksStates Function!",
4547− return result);
4548− }
4549−
4550− return result;
4551−}
4552−
4553−static int fiji_trim_single_dpm_states(struct pp_hwmgr *hwmgr,
4554− struct fiji_single_dpm_table * dpm_table,
4555− uint32_t low_limit, uint32_t high_limit)
4556−{
4557− uint32_t i;
4558−
4559− for (i = 0; i < dpm_table->count; i++) {
4560− if ((dpm_table->dpm_levels[i].value < low_limit) ||
4561− (dpm_table->dpm_levels[i].value > high_limit))
4562− dpm_table->dpm_levels[i].enabled = false;
4563− else
4564− dpm_table->dpm_levels[i].enabled = true;
4565− }
4566− return 0;
4567−}
4568−
4569−static int fiji_trim_dpm_states(struct pp_hwmgr *hwmgr,
4570− const struct fiji_power_state *fiji_ps)
4571−{
4572− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4573− uint32_t high_limit_count;
4574−
4575− PP_ASSERT_WITH_CODE((fiji_ps->performance_level_count >= 1),
4576− "power state did not have any performance level",
4577− return -1);
4578−
4579− high_limit_count = (1 == fiji_ps->performance_level_count) ? 0 : 1;
4580−
4581− fiji_trim_single_dpm_states(hwmgr,
4582− &(data->dpm_table.sclk_table),
4583− fiji_ps->performance_levels[0].engine_clock,
4584− fiji_ps->performance_levels[high_limit_count].engine_clock);
4585−
4586− fiji_trim_single_dpm_states(hwmgr,
4587− &(data->dpm_table.mclk_table),
4588− fiji_ps->performance_levels[0].memory_clock,
4589− fiji_ps->performance_levels[high_limit_count].memory_clock);
4590−
4591− return 0;
4592−}
4593−
4594−static int fiji_generate_dpm_level_enable_mask(
4595− struct pp_hwmgr *hwmgr, const void *input)
4596−{
4597− int result;
4598− const struct phm_set_power_state_input *states =
4599− (const struct phm_set_power_state_input *)input;
4600− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4601− const struct fiji_power_state *fiji_ps =
4602− cast_const_phw_fiji_power_state(states->pnew_state);
4603−
4604− result = fiji_trim_dpm_states(hwmgr, fiji_ps);
4605− if (result)
4606− return result;
4607−
4608− data->dpm_level_enable_mask.sclk_dpm_enable_mask =
4609− fiji_get_dpm_level_enable_mask_value(&data->dpm_table.sclk_table);
4610− data->dpm_level_enable_mask.mclk_dpm_enable_mask =
4611− fiji_get_dpm_level_enable_mask_value(&data->dpm_table.mclk_table);
4612− data->last_mclk_dpm_enable_mask =
4613− data->dpm_level_enable_mask.mclk_dpm_enable_mask;
4614−
4615− if (data->uvd_enabled) {
4616− if (data->dpm_level_enable_mask.mclk_dpm_enable_mask & 1)
4617− data->dpm_level_enable_mask.mclk_dpm_enable_mask &= 0xFFFFFFFE;
4618− }
4619−
4620− data->dpm_level_enable_mask.pcie_dpm_enable_mask =
4621− fiji_get_dpm_level_enable_mask_value(&data->dpm_table.pcie_speed_table);
4622−
4623− return 0;
4624−}
4625−
4626−static int fiji_enable_disable_uvd_dpm(struct pp_hwmgr *hwmgr, bool enable)
4627−{
4628− return smum_send_msg_to_smc(hwmgr->smumgr, enable ?
4629− (PPSMC_Msg)PPSMC_MSG_UVDDPM_Enable :
4630− (PPSMC_Msg)PPSMC_MSG_UVDDPM_Disable);
4631−}
4632−
4633−int fiji_enable_disable_vce_dpm(struct pp_hwmgr *hwmgr, bool enable)
4634−{
4635− return smum_send_msg_to_smc(hwmgr->smumgr, enable?
4636− PPSMC_MSG_VCEDPM_Enable :
4637− PPSMC_MSG_VCEDPM_Disable);
4638−}
4639−
4640−static int fiji_enable_disable_samu_dpm(struct pp_hwmgr *hwmgr, bool enable)
4641−{
4642− return smum_send_msg_to_smc(hwmgr->smumgr, enable?
4643− PPSMC_MSG_SAMUDPM_Enable :
4644− PPSMC_MSG_SAMUDPM_Disable);
4645−}
4646−
4647−static int fiji_enable_disable_acp_dpm(struct pp_hwmgr *hwmgr, bool enable)
4648−{
4649− return smum_send_msg_to_smc(hwmgr->smumgr, enable?
4650− PPSMC_MSG_ACPDPM_Enable :
4651− PPSMC_MSG_ACPDPM_Disable);
4652−}
4653−
4654−int fiji_update_uvd_dpm(struct pp_hwmgr *hwmgr, bool bgate)
4655−{
4656− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4657− uint32_t mm_boot_level_offset, mm_boot_level_value;
4658− struct phm_ppt_v1_information *table_info =
4659− (struct phm_ppt_v1_information *)(hwmgr->pptable);
4660−
4661− if (!bgate) {
4662− data->smc_state_table.UvdBootLevel = 0;
4663− if (table_info->mm_dep_table->count > 0)
4664− data->smc_state_table.UvdBootLevel =
4665− (uint8_t) (table_info->mm_dep_table->count - 1);
4666− mm_boot_level_offset = data->dpm_table_start +
4667− offsetof(SMU73_Discrete_DpmTable, UvdBootLevel);
4668− mm_boot_level_offset /= 4;
4669− mm_boot_level_offset *= 4;
4670− mm_boot_level_value = cgs_read_ind_register(hwmgr->device,
4671− CGS_IND_REG__SMC, mm_boot_level_offset);
4672− mm_boot_level_value &= 0x00FFFFFF;
4673− mm_boot_level_value |= data->smc_state_table.UvdBootLevel << 24;
4674− cgs_write_ind_register(hwmgr->device,
4675− CGS_IND_REG__SMC, mm_boot_level_offset, mm_boot_level_value);
4676−
4677− if (!phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4678− PHM_PlatformCaps_UVDDPM) ||
4679− phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4680− PHM_PlatformCaps_StablePState))
4681− smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4682− PPSMC_MSG_UVDDPM_SetEnabledMask,
4683− (uint32_t)(1 << data->smc_state_table.UvdBootLevel));
4684− }
4685−
4686− return fiji_enable_disable_uvd_dpm(hwmgr, !bgate);
4687−}
4688−
4689−int fiji_update_vce_dpm(struct pp_hwmgr *hwmgr, const void *input)
4690−{
4691− const struct phm_set_power_state_input *states =
4692− (const struct phm_set_power_state_input *)input;
4693− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4694− const struct fiji_power_state *fiji_nps =
4695− cast_const_phw_fiji_power_state(states->pnew_state);
4696− const struct fiji_power_state *fiji_cps =
4697− cast_const_phw_fiji_power_state(states->pcurrent_state);
4698−
4699− uint32_t mm_boot_level_offset, mm_boot_level_value;
4700− struct phm_ppt_v1_information *table_info =
4701− (struct phm_ppt_v1_information *)(hwmgr->pptable);
4702−
4703− if (fiji_nps->vce_clks.evclk >0 &&
4704− (fiji_cps == NULL || fiji_cps->vce_clks.evclk == 0)) {
4705− data->smc_state_table.VceBootLevel =
4706− (uint8_t) (table_info->mm_dep_table->count - 1);
4707−
4708− mm_boot_level_offset = data->dpm_table_start +
4709− offsetof(SMU73_Discrete_DpmTable, VceBootLevel);
4710− mm_boot_level_offset /= 4;
4711− mm_boot_level_offset *= 4;
4712− mm_boot_level_value = cgs_read_ind_register(hwmgr->device,
4713− CGS_IND_REG__SMC, mm_boot_level_offset);
4714− mm_boot_level_value &= 0xFF00FFFF;
4715− mm_boot_level_value |= data->smc_state_table.VceBootLevel << 16;
4716− cgs_write_ind_register(hwmgr->device,
4717− CGS_IND_REG__SMC, mm_boot_level_offset, mm_boot_level_value);
4718−
4719− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4720− PHM_PlatformCaps_StablePState)) {
4721− smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4722− PPSMC_MSG_VCEDPM_SetEnabledMask,
4723− (uint32_t)1 << data->smc_state_table.VceBootLevel);
4724−
4725− fiji_enable_disable_vce_dpm(hwmgr, true);
4726− } else if (fiji_nps->vce_clks.evclk == 0 &&
4727− fiji_cps != NULL &&
4728− fiji_cps->vce_clks.evclk > 0)
4729− fiji_enable_disable_vce_dpm(hwmgr, false);
4730− }
4731−
4732− return 0;
4733−}
4734−
4735−int fiji_update_samu_dpm(struct pp_hwmgr *hwmgr, bool bgate)
4736−{
4737− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4738− uint32_t mm_boot_level_offset, mm_boot_level_value;
4739− struct phm_ppt_v1_information *table_info =
4740− (struct phm_ppt_v1_information *)(hwmgr->pptable);
4741−
4742− if (!bgate) {
4743− data->smc_state_table.SamuBootLevel =
4744− (uint8_t) (table_info->mm_dep_table->count - 1);
4745− mm_boot_level_offset = data->dpm_table_start +
4746− offsetof(SMU73_Discrete_DpmTable, SamuBootLevel);
4747− mm_boot_level_offset /= 4;
4748− mm_boot_level_offset *= 4;
4749− mm_boot_level_value = cgs_read_ind_register(hwmgr->device,
4750− CGS_IND_REG__SMC, mm_boot_level_offset);
4751− mm_boot_level_value &= 0xFFFFFF00;
4752− mm_boot_level_value |= data->smc_state_table.SamuBootLevel << 0;
4753− cgs_write_ind_register(hwmgr->device,
4754− CGS_IND_REG__SMC, mm_boot_level_offset, mm_boot_level_value);
4755−
4756− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4757− PHM_PlatformCaps_StablePState))
4758− smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4759− PPSMC_MSG_SAMUDPM_SetEnabledMask,
4760− (uint32_t)(1 << data->smc_state_table.SamuBootLevel));
4761− }
4762−
4763− return fiji_enable_disable_samu_dpm(hwmgr, !bgate);
4764−}
4765−
4766−int fiji_update_acp_dpm(struct pp_hwmgr *hwmgr, bool bgate)
4767−{
4768− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4769− uint32_t mm_boot_level_offset, mm_boot_level_value;
4770− struct phm_ppt_v1_information *table_info =
4771− (struct phm_ppt_v1_information *)(hwmgr->pptable);
4772−
4773− if (!bgate) {
4774− data->smc_state_table.AcpBootLevel =
4775− (uint8_t) (table_info->mm_dep_table->count - 1);
4776− mm_boot_level_offset = data->dpm_table_start +
4777− offsetof(SMU73_Discrete_DpmTable, AcpBootLevel);
4778− mm_boot_level_offset /= 4;
4779− mm_boot_level_offset *= 4;
4780− mm_boot_level_value = cgs_read_ind_register(hwmgr->device,
4781− CGS_IND_REG__SMC, mm_boot_level_offset);
4782− mm_boot_level_value &= 0xFFFF00FF;
4783− mm_boot_level_value |= data->smc_state_table.AcpBootLevel << 8;
4784− cgs_write_ind_register(hwmgr->device,
4785− CGS_IND_REG__SMC, mm_boot_level_offset, mm_boot_level_value);
4786−
4787− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4788− PHM_PlatformCaps_StablePState))
4789− smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4790− PPSMC_MSG_ACPDPM_SetEnabledMask,
4791− (uint32_t)(1 << data->smc_state_table.AcpBootLevel));
4792− }
4793−
4794− return fiji_enable_disable_acp_dpm(hwmgr, !bgate);
4795−}
4796−
4797−static int fiji_update_sclk_threshold(struct pp_hwmgr *hwmgr)
4798−{
4799− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4800−
4801− int result = 0;
4802− uint32_t low_sclk_interrupt_threshold = 0;
4803−
4804− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4805− PHM_PlatformCaps_SclkThrottleLowNotification)
4806− && (hwmgr->gfx_arbiter.sclk_threshold !=
4807− data->low_sclk_interrupt_threshold)) {
4808− data->low_sclk_interrupt_threshold =
4809− hwmgr->gfx_arbiter.sclk_threshold;
4810− low_sclk_interrupt_threshold =
4811− data->low_sclk_interrupt_threshold;
4812−
4813− CONVERT_FROM_HOST_TO_SMC_UL(low_sclk_interrupt_threshold);
4814−
4815− result = fiji_copy_bytes_to_smc(
4816− hwmgr->smumgr,
4817− data->dpm_table_start +
4818− offsetof(SMU73_Discrete_DpmTable,
4819− LowSclkInterruptThreshold),
4820− (uint8_t *)&low_sclk_interrupt_threshold,
4821− sizeof(uint32_t),
4822− data->sram_end);
4823− }
4824−
4825− return result;
4826−}
4827−
4828−static int fiji_program_mem_timing_parameters(struct pp_hwmgr *hwmgr)
4829−{
4830− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4831−
4832− if (data->need_update_smu7_dpm_table &
4833− (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_OD_UPDATE_MCLK))
4834− return fiji_program_memory_timing_parameters(hwmgr);
4835−
4836− return 0;
4837−}
4838−
4839−static int fiji_unfreeze_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
4840−{
4841− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4842−
4843− if (0 == data->need_update_smu7_dpm_table)
4844− return 0;
4845−
4846− if ((0 == data->sclk_dpm_key_disabled) &&
4847− (data->need_update_smu7_dpm_table &
4848− (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK))) {
4849−
4850− PP_ASSERT_WITH_CODE(fiji_is_dpm_running(hwmgr),
4851− "Trying to Unfreeze SCLK DPM when DPM is disabled",
4852− );
4853− PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr,
4854− PPSMC_MSG_SCLKDPM_UnfreezeLevel),
4855− "Failed to unfreeze SCLK DPM during UnFreezeSclkMclkDPM Function!",
4856− return -1);
4857− }
4858−
4859− if ((0 == data->mclk_dpm_key_disabled) &&
4860− (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK)) {
4861−
4862− PP_ASSERT_WITH_CODE(fiji_is_dpm_running(hwmgr),
4863− "Trying to Unfreeze MCLK DPM when DPM is disabled",
4864− );
4865− PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr,
4866− PPSMC_MSG_SCLKDPM_UnfreezeLevel),
4867− "Failed to unfreeze MCLK DPM during UnFreezeSclkMclkDPM Function!",
4868− return -1);
4869− }
4870−
4871− data->need_update_smu7_dpm_table = 0;
4872−
4873− return 0;
4874−}
4875−
4876−/* Look up the voltaged based on DAL's requested level.
4877− * and then send the requested VDDC voltage to SMC
4878− */
4879−static void fiji_apply_dal_minimum_voltage_request(struct pp_hwmgr *hwmgr)
4880−{
4881− return;
4882−}
4883−
4884−static int fiji_upload_dpm_level_enable_mask(struct pp_hwmgr *hwmgr)
4885−{
4886− int result;
4887− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4888−
4889− /* Apply minimum voltage based on DAL's request level */
4890− fiji_apply_dal_minimum_voltage_request(hwmgr);
4891−
4892− if (0 == data->sclk_dpm_key_disabled) {
4893− /* Checking if DPM is running. If we discover hang because of this,
4894− * we should skip this message.
4895− */
4896− if (!fiji_is_dpm_running(hwmgr))
4897− printk(KERN_ERR "[ powerplay ] "
4898− "Trying to set Enable Mask when DPM is disabled \n");
4899−
4900− if (data->dpm_level_enable_mask.sclk_dpm_enable_mask) {
4901− result = smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4902− PPSMC_MSG_SCLKDPM_SetEnabledMask,
4903− data->dpm_level_enable_mask.sclk_dpm_enable_mask);
4904− PP_ASSERT_WITH_CODE((0 == result),
4905− "Set Sclk Dpm enable Mask failed", return -1);
4906− }
4907− }
4908−
4909− if (0 == data->mclk_dpm_key_disabled) {
4910− /* Checking if DPM is running. If we discover hang because of this,
4911− * we should skip this message.
4912− */
4913− if (!fiji_is_dpm_running(hwmgr))
4914− printk(KERN_ERR "[ powerplay ]"
4915− " Trying to set Enable Mask when DPM is disabled \n");
4916−
4917− if (data->dpm_level_enable_mask.mclk_dpm_enable_mask) {
4918− result = smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4919− PPSMC_MSG_MCLKDPM_SetEnabledMask,
4920− data->dpm_level_enable_mask.mclk_dpm_enable_mask);
4921− PP_ASSERT_WITH_CODE((0 == result),
4922− "Set Mclk Dpm enable Mask failed", return -1);
4923− }
4924− }
4925−
4926− return 0;
4927−}
4928−
4929−static int fiji_notify_link_speed_change_after_state_change(
4930− struct pp_hwmgr *hwmgr, const void *input)
4931−{
4932− const struct phm_set_power_state_input *states =
4933− (const struct phm_set_power_state_input *)input;
4934− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4935− const struct fiji_power_state *fiji_ps =
4936− cast_const_phw_fiji_power_state(states->pnew_state);
4937− uint16_t target_link_speed = fiji_get_maximum_link_speed(hwmgr, fiji_ps);
4938− uint8_t request;
4939−
4940− if (data->pspp_notify_required) {
4941− if (target_link_speed == PP_PCIEGen3)
4942− request = PCIE_PERF_REQ_GEN3;
4943− else if (target_link_speed == PP_PCIEGen2)
4944− request = PCIE_PERF_REQ_GEN2;
4945− else
4946− request = PCIE_PERF_REQ_GEN1;
4947−
4948− if(request == PCIE_PERF_REQ_GEN1 &&
4949− fiji_get_current_pcie_speed(hwmgr) > 0)
4950− return 0;
4951−
4952− if (acpi_pcie_perf_request(hwmgr->device, request, false)) {
4953− if (PP_PCIEGen2 == target_link_speed)
4954− printk("PSPP request to switch to Gen2 from Gen3 Failed!");
4955− else
4956− printk("PSPP request to switch to Gen1 from Gen2 Failed!");
4957− }
4958− }
4959−
4960− return 0;
4961−}
4962−
4963−static int fiji_set_power_state_tasks(struct pp_hwmgr *hwmgr,
4964− const void *input)
4965−{
4966− int tmp_result, result = 0;
4967−
4968− tmp_result = fiji_find_dpm_states_clocks_in_dpm_table(hwmgr, input);
4969− PP_ASSERT_WITH_CODE((0 == tmp_result),
4970− "Failed to find DPM states clocks in DPM table!",
4971− result = tmp_result);
4972−
4973− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4974− PHM_PlatformCaps_PCIEPerformanceRequest)) {
4975− tmp_result =
4976− fiji_request_link_speed_change_before_state_change(hwmgr, input);
4977− PP_ASSERT_WITH_CODE((0 == tmp_result),
4978− "Failed to request link speed change before state change!",
4979− result = tmp_result);
4980− }
4981−
4982− tmp_result = fiji_freeze_sclk_mclk_dpm(hwmgr);
4983− PP_ASSERT_WITH_CODE((0 == tmp_result),
4984− "Failed to freeze SCLK MCLK DPM!", result = tmp_result);
4985−
4986− tmp_result = fiji_populate_and_upload_sclk_mclk_dpm_levels(hwmgr, input);
4987− PP_ASSERT_WITH_CODE((0 == tmp_result),
4988− "Failed to populate and upload SCLK MCLK DPM levels!",
4989− result = tmp_result);
4990−
4991− tmp_result = fiji_generate_dpm_level_enable_mask(hwmgr, input);
4992− PP_ASSERT_WITH_CODE((0 == tmp_result),
4993− "Failed to generate DPM level enabled mask!",
4994− result = tmp_result);
4995−
4996− tmp_result = fiji_update_vce_dpm(hwmgr, input);
4997− PP_ASSERT_WITH_CODE((0 == tmp_result),
4998− "Failed to update VCE DPM!",
4999− result = tmp_result);

601 more lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/hwmgr/fiji_hwmgr.h+0−350
@@ -1,350 +0,0 @@
1−/*
2− * Copyright 2015 Advanced Micro Devices, Inc.
3− *
4− * Permission is hereby granted, free of charge, to any person obtaining a
5− * copy of this software and associated documentation files (the "Software"),
6− * to deal in the Software without restriction, including without limitation
7− * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8− * and/or sell copies of the Software, and to permit persons to whom the
9− * Software is furnished to do so, subject to the following conditions:
10− *
11− * The above copyright notice and this permission notice shall be included in
12− * all copies or substantial portions of the Software.
13− *
14− * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15− * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16− * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17− * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18− * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19− * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20− * OTHER DEALINGS IN THE SOFTWARE.
21− *
22− */
23−
24−#ifndef _FIJI_HWMGR_H_
25−#define _FIJI_HWMGR_H_
26−
27−#include "hwmgr.h"
28−#include "smu73.h"
29−#include "smu73_discrete.h"
30−#include "ppatomctrl.h"
31−#include "fiji_ppsmc.h"
32−#include "pp_endian.h"
33−
34−#define FIJI_MAX_HARDWARE_POWERLEVELS 2
35−#define FIJI_AT_DFLT 30
36−
37−#define FIJI_VOLTAGE_CONTROL_NONE 0x0
38−#define FIJI_VOLTAGE_CONTROL_BY_GPIO 0x1
39−#define FIJI_VOLTAGE_CONTROL_BY_SVID2 0x2
40−#define FIJI_VOLTAGE_CONTROL_MERGED 0x3
41−
42−#define DPMTABLE_OD_UPDATE_SCLK 0x00000001
43−#define DPMTABLE_OD_UPDATE_MCLK 0x00000002
44−#define DPMTABLE_UPDATE_SCLK 0x00000004
45−#define DPMTABLE_UPDATE_MCLK 0x00000008
46−
47−struct fiji_performance_level {
48− uint32_t memory_clock;
49− uint32_t engine_clock;
50− uint16_t pcie_gen;
51− uint16_t pcie_lane;
52−};
53−
54−struct fiji_uvd_clocks {
55− uint32_t vclk;
56− uint32_t dclk;
57−};
58−
59−struct fiji_vce_clocks {
60− uint32_t evclk;
61− uint32_t ecclk;
62−};
63−
64−struct fiji_power_state {
65− uint32_t magic;
66− struct fiji_uvd_clocks uvd_clks;
67− struct fiji_vce_clocks vce_clks;
68− uint32_t sam_clk;
69− uint32_t acp_clk;
70− uint16_t performance_level_count;
71− bool dc_compatible;
72− uint32_t sclk_threshold;
73− struct fiji_performance_level performance_levels[FIJI_MAX_HARDWARE_POWERLEVELS];
74−};
75−
76−struct fiji_dpm_level {
77− bool enabled;
78− uint32_t value;
79− uint32_t param1;
80−};
81−
82−#define FIJI_MAX_DEEPSLEEP_DIVIDER_ID 5
83−#define MAX_REGULAR_DPM_NUMBER 8
84−#define FIJI_MINIMUM_ENGINE_CLOCK 2500
85−
86−struct fiji_single_dpm_table {
87− uint32_t count;
88− struct fiji_dpm_level dpm_levels[MAX_REGULAR_DPM_NUMBER];
89−};
90−
91−struct fiji_dpm_table {
92− struct fiji_single_dpm_table sclk_table;
93− struct fiji_single_dpm_table mclk_table;
94− struct fiji_single_dpm_table pcie_speed_table;
95− struct fiji_single_dpm_table vddc_table;
96− struct fiji_single_dpm_table vddci_table;
97− struct fiji_single_dpm_table mvdd_table;
98−};
99−
100−struct fiji_clock_registers {
101− uint32_t vCG_SPLL_FUNC_CNTL;
102− uint32_t vCG_SPLL_FUNC_CNTL_2;
103− uint32_t vCG_SPLL_FUNC_CNTL_3;
104− uint32_t vCG_SPLL_FUNC_CNTL_4;
105− uint32_t vCG_SPLL_SPREAD_SPECTRUM;
106− uint32_t vCG_SPLL_SPREAD_SPECTRUM_2;
107− uint32_t vDLL_CNTL;
108− uint32_t vMCLK_PWRMGT_CNTL;
109− uint32_t vMPLL_AD_FUNC_CNTL;
110− uint32_t vMPLL_DQ_FUNC_CNTL;
111− uint32_t vMPLL_FUNC_CNTL;
112− uint32_t vMPLL_FUNC_CNTL_1;
113− uint32_t vMPLL_FUNC_CNTL_2;
114− uint32_t vMPLL_SS1;
115− uint32_t vMPLL_SS2;
116−};
117−
118−struct fiji_voltage_smio_registers {
119− uint32_t vS0_VID_LOWER_SMIO_CNTL;
120−};
121−
122−#define FIJI_MAX_LEAKAGE_COUNT 8
123−struct fiji_leakage_voltage {
124− uint16_t count;
125− uint16_t leakage_id[FIJI_MAX_LEAKAGE_COUNT];
126− uint16_t actual_voltage[FIJI_MAX_LEAKAGE_COUNT];
127−};
128−
129−struct fiji_vbios_boot_state {
130− uint16_t mvdd_bootup_value;
131− uint16_t vddc_bootup_value;
132− uint16_t vddci_bootup_value;
133− uint32_t sclk_bootup_value;
134− uint32_t mclk_bootup_value;
135− uint16_t pcie_gen_bootup_value;
136− uint16_t pcie_lane_bootup_value;
137−};
138−
139−struct fiji_bacos {
140− uint32_t best_match;
141− uint32_t baco_flags;
142− struct fiji_performance_level performance_level;
143−};
144−
145−/* Ultra Low Voltage parameter structure */
146−struct fiji_ulv_parm {
147− bool ulv_supported;
148− uint32_t cg_ulv_parameter;
149− uint32_t ulv_volt_change_delay;
150− struct fiji_performance_level ulv_power_level;
151−};
152−
153−struct fiji_display_timing {
154− uint32_t min_clock_in_sr;
155− uint32_t num_existing_displays;
156−};
157−
158−struct fiji_dpmlevel_enable_mask {
159− uint32_t uvd_dpm_enable_mask;
160− uint32_t vce_dpm_enable_mask;
161− uint32_t acp_dpm_enable_mask;
162− uint32_t samu_dpm_enable_mask;
163− uint32_t sclk_dpm_enable_mask;
164− uint32_t mclk_dpm_enable_mask;
165− uint32_t pcie_dpm_enable_mask;
166−};
167−
168−struct fiji_pcie_perf_range {
169− uint16_t max;
170− uint16_t min;
171−};
172−
173−struct fiji_hwmgr {
174− struct fiji_dpm_table dpm_table;
175− struct fiji_dpm_table golden_dpm_table;
176−
177− uint32_t voting_rights_clients0;
178− uint32_t voting_rights_clients1;
179− uint32_t voting_rights_clients2;
180− uint32_t voting_rights_clients3;
181− uint32_t voting_rights_clients4;
182− uint32_t voting_rights_clients5;
183− uint32_t voting_rights_clients6;
184− uint32_t voting_rights_clients7;
185− uint32_t static_screen_threshold_unit;
186− uint32_t static_screen_threshold;
187− uint32_t voltage_control;
188− uint32_t vddc_vddci_delta;
189−
190− uint32_t active_auto_throttle_sources;
191−
192− struct fiji_clock_registers clock_registers;
193− struct fiji_voltage_smio_registers voltage_smio_registers;
194−
195− bool is_memory_gddr5;
196− uint16_t acpi_vddc;
197− bool pspp_notify_required;
198− uint16_t force_pcie_gen;
199− uint16_t acpi_pcie_gen;
200− uint32_t pcie_gen_cap;
201− uint32_t pcie_lane_cap;
202− uint32_t pcie_spc_cap;
203− struct fiji_leakage_voltage vddc_leakage;
204− struct fiji_leakage_voltage Vddci_leakage;
205−
206− uint32_t mvdd_control;
207− uint32_t vddc_mask_low;
208− uint32_t mvdd_mask_low;
209− uint16_t max_vddc_in_pptable;
210− uint16_t min_vddc_in_pptable;
211− uint16_t max_vddci_in_pptable;
212− uint16_t min_vddci_in_pptable;
213− uint32_t mclk_strobe_mode_threshold;
214− uint32_t mclk_stutter_mode_threshold;
215− uint32_t mclk_edc_enable_threshold;
216− uint32_t mclk_edcwr_enable_threshold;
217− bool is_uvd_enabled;
218− struct fiji_vbios_boot_state vbios_boot_state;
219−
220− bool battery_state;
221− bool is_tlu_enabled;
222−
223− /* ---- SMC SRAM Address of firmware header tables ---- */
224− uint32_t sram_end;
225− uint32_t dpm_table_start;
226− uint32_t soft_regs_start;
227− uint32_t mc_reg_table_start;
228− uint32_t fan_table_start;
229− uint32_t arb_table_start;
230− struct SMU73_Discrete_DpmTable smc_state_table;
231− struct SMU73_Discrete_Ulv ulv_setting;
232−
233− /* ---- Stuff originally coming from Evergreen ---- */
234− uint32_t vddci_control;
235− struct pp_atomctrl_voltage_table vddc_voltage_table;
236− struct pp_atomctrl_voltage_table vddci_voltage_table;
237− struct pp_atomctrl_voltage_table mvdd_voltage_table;
238−
239− uint32_t mgcg_cgtt_local2;
240− uint32_t mgcg_cgtt_local3;
241− uint32_t gpio_debug;
242− uint32_t mc_micro_code_feature;
243− uint32_t highest_mclk;
244− uint16_t acpi_vddci;
245− uint8_t mvdd_high_index;
246− uint8_t mvdd_low_index;
247− bool dll_default_on;
248− bool performance_request_registered;
249−
250− /* ---- Low Power Features ---- */
251− struct fiji_bacos bacos;
252− struct fiji_ulv_parm ulv;
253−
254− /* ---- CAC Stuff ---- */
255− uint32_t cac_table_start;
256− bool cac_configuration_required;
257− bool driver_calculate_cac_leakage;
258− bool cac_enabled;
259−
260− /* ---- DPM2 Parameters ---- */
261− uint32_t power_containment_features;
262− bool enable_dte_feature;
263− bool enable_tdc_limit_feature;
264− bool enable_pkg_pwr_tracking_feature;
265− bool disable_uvd_power_tune_feature;
266− const struct fiji_pt_defaults *power_tune_defaults;
267− struct SMU73_Discrete_PmFuses power_tune_table;
268− uint32_t dte_tj_offset;
269− uint32_t fast_watermark_threshold;
270−
271− /* ---- Phase Shedding ---- */
272− bool vddc_phase_shed_control;
273−
274− /* ---- DI/DT ---- */
275− struct fiji_display_timing display_timing;
276−
277− /* ---- Thermal Temperature Setting ---- */
278− struct fiji_dpmlevel_enable_mask dpm_level_enable_mask;
279− uint32_t need_update_smu7_dpm_table;
280− uint32_t sclk_dpm_key_disabled;
281− uint32_t mclk_dpm_key_disabled;
282− uint32_t pcie_dpm_key_disabled;
283− uint32_t min_engine_clocks;
284− struct fiji_pcie_perf_range pcie_gen_performance;
285− struct fiji_pcie_perf_range pcie_lane_performance;
286− struct fiji_pcie_perf_range pcie_gen_power_saving;
287− struct fiji_pcie_perf_range pcie_lane_power_saving;
288− bool use_pcie_performance_levels;
289− bool use_pcie_power_saving_levels;
290− uint32_t activity_target[SMU73_MAX_LEVELS_GRAPHICS];
291− uint32_t mclk_activity_target;
292− uint32_t mclk_dpm0_activity_target;
293− uint32_t low_sclk_interrupt_threshold;
294− uint32_t last_mclk_dpm_enable_mask;
295− bool uvd_enabled;
296−
297− /* ---- Power Gating States ---- */
298− bool uvd_power_gated;
299− bool vce_power_gated;
300− bool samu_power_gated;
301− bool acp_power_gated;
302− bool pg_acp_init;
303− bool frtc_enabled;
304− bool frtc_status_changed;
305−};
306−
307−/* To convert to Q8.8 format for firmware */
308−#define FIJI_Q88_FORMAT_CONVERSION_UNIT 256
309−
310−enum Fiji_I2CLineID {
311− Fiji_I2CLineID_DDC1 = 0x90,
312− Fiji_I2CLineID_DDC2 = 0x91,
313− Fiji_I2CLineID_DDC3 = 0x92,
314− Fiji_I2CLineID_DDC4 = 0x93,
315− Fiji_I2CLineID_DDC5 = 0x94,
316− Fiji_I2CLineID_DDC6 = 0x95,
317− Fiji_I2CLineID_SCLSDA = 0x96,
318− Fiji_I2CLineID_DDCVGA = 0x97
319−};
320−
321−#define Fiji_I2C_DDC1DATA 0
322−#define Fiji_I2C_DDC1CLK 1
323−#define Fiji_I2C_DDC2DATA 2
324−#define Fiji_I2C_DDC2CLK 3
325−#define Fiji_I2C_DDC3DATA 4
326−#define Fiji_I2C_DDC3CLK 5
327−#define Fiji_I2C_SDA 40
328−#define Fiji_I2C_SCL 41
329−#define Fiji_I2C_DDC4DATA 65
330−#define Fiji_I2C_DDC4CLK 66
331−#define Fiji_I2C_DDC5DATA 0x48
332−#define Fiji_I2C_DDC5CLK 0x49
333−#define Fiji_I2C_DDC6DATA 0x4a
334−#define Fiji_I2C_DDC6CLK 0x4b
335−#define Fiji_I2C_DDCVGADATA 0x4c
336−#define Fiji_I2C_DDCVGACLK 0x4d
337−
338−#define FIJI_UNUSED_GPIO_PIN 0x7F
339−
340−extern int tonga_initializa_dynamic_state_adjustment_rule_settings(struct pp_hwmgr *hwmgr);
341−extern int tonga_get_mc_microcode_version (struct pp_hwmgr *hwmgr);
342−extern int tonga_notify_smc_display_config_after_ps_adjustment(struct pp_hwmgr *hwmgr);
343−extern int tonga_notify_smc_display_change(struct pp_hwmgr *hwmgr, bool has_display);
344−int fiji_update_vce_dpm(struct pp_hwmgr *hwmgr, const void *input);
345−int fiji_update_uvd_dpm(struct pp_hwmgr *hwmgr, bool bgate);
346−int fiji_update_samu_dpm(struct pp_hwmgr *hwmgr, bool bgate);
347−int fiji_update_acp_dpm(struct pp_hwmgr *hwmgr, bool bgate);
348−int fiji_enable_disable_vce_dpm(struct pp_hwmgr *hwmgr, bool enable);
349−
350−#endif /* _FIJI_HWMGR_H_ */
drivers/gpu/drm/amd/powerplay/hwmgr/fiji_powertune.c+0−610
@@ -1,610 +0,0 @@
1−/*
2− * Copyright 2015 Advanced Micro Devices, Inc.
3− *
4− * Permission is hereby granted, free of charge, to any person obtaining a
5− * copy of this software and associated documentation files (the "Software"),
6− * to deal in the Software without restriction, including without limitation
7− * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8− * and/or sell copies of the Software, and to permit persons to whom the
9− * Software is furnished to do so, subject to the following conditions:
10− *
11− * The above copyright notice and this permission notice shall be included in
12− * all copies or substantial portions of the Software.
13− *
14− * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15− * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16− * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17− * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18− * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19− * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20− * OTHER DEALINGS IN THE SOFTWARE.
21− *
22− */
23−
24−#include "hwmgr.h"
25−#include "smumgr.h"
26−#include "fiji_hwmgr.h"
27−#include "fiji_powertune.h"
28−#include "fiji_smumgr.h"
29−#include "smu73_discrete.h"
30−#include "pp_debug.h"
31−
32−#define VOLTAGE_SCALE 4
33−#define POWERTUNE_DEFAULT_SET_MAX 1
34−
35−const struct fiji_pt_defaults fiji_power_tune_data_set_array[POWERTUNE_DEFAULT_SET_MAX] = {
36− /*sviLoadLIneEn, SviLoadLineVddC, TDC_VDDC_ThrottleReleaseLimitPerc */
37− {1, 0xF, 0xFD,
38− /* TDC_MAWt, TdcWaterfallCtl, DTEAmbientTempBase */
39− 0x19, 5, 45}
40−};
41−
42−void fiji_initialize_power_tune_defaults(struct pp_hwmgr *hwmgr)
43−{
44− struct fiji_hwmgr *fiji_hwmgr = (struct fiji_hwmgr *)(hwmgr->backend);
45− struct phm_ppt_v1_information *table_info =
46− (struct phm_ppt_v1_information *)(hwmgr->pptable);
47− uint32_t tmp = 0;
48−
49− if(table_info &&
50− table_info->cac_dtp_table->usPowerTuneDataSetID <= POWERTUNE_DEFAULT_SET_MAX &&
51− table_info->cac_dtp_table->usPowerTuneDataSetID)
52− fiji_hwmgr->power_tune_defaults =
53− &fiji_power_tune_data_set_array
54− [table_info->cac_dtp_table->usPowerTuneDataSetID - 1];
55− else
56− fiji_hwmgr->power_tune_defaults = &fiji_power_tune_data_set_array[0];
57−
58− /* Assume disabled */
59− phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
60− PHM_PlatformCaps_CAC);
61− phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
62− PHM_PlatformCaps_SQRamping);
63− phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
64− PHM_PlatformCaps_DBRamping);
65− phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
66− PHM_PlatformCaps_TDRamping);
67− phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
68− PHM_PlatformCaps_TCPRamping);
69−
70− fiji_hwmgr->dte_tj_offset = tmp;
71−
72− if (!tmp) {
73− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
74− PHM_PlatformCaps_CAC);
75−
76− fiji_hwmgr->fast_watermark_threshold = 100;
77−
78− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
79− PHM_PlatformCaps_PowerContainment)) {
80− tmp = 1;
81− fiji_hwmgr->enable_dte_feature = tmp ? false : true;
82− fiji_hwmgr->enable_tdc_limit_feature = tmp ? true : false;
83− fiji_hwmgr->enable_pkg_pwr_tracking_feature = tmp ? true : false;
84− }
85− }
86−}
87−
88−/* PPGen has the gain setting generated in x * 100 unit
89− * This function is to convert the unit to x * 4096(0x1000) unit.
90− * This is the unit expected by SMC firmware
91− */
92−static uint16_t scale_fan_gain_settings(uint16_t raw_setting)
93−{
94− uint32_t tmp;
95− tmp = raw_setting * 4096 / 100;
96− return (uint16_t)tmp;
97−}
98−
99−static void get_scl_sda_value(uint8_t line, uint8_t *scl, uint8_t* sda)
100−{
101− switch (line) {
102− case Fiji_I2CLineID_DDC1 :
103− *scl = Fiji_I2C_DDC1CLK;
104− *sda = Fiji_I2C_DDC1DATA;
105− break;
106− case Fiji_I2CLineID_DDC2 :
107− *scl = Fiji_I2C_DDC2CLK;
108− *sda = Fiji_I2C_DDC2DATA;
109− break;
110− case Fiji_I2CLineID_DDC3 :
111− *scl = Fiji_I2C_DDC3CLK;
112− *sda = Fiji_I2C_DDC3DATA;
113− break;
114− case Fiji_I2CLineID_DDC4 :
115− *scl = Fiji_I2C_DDC4CLK;
116− *sda = Fiji_I2C_DDC4DATA;
117− break;
118− case Fiji_I2CLineID_DDC5 :
119− *scl = Fiji_I2C_DDC5CLK;
120− *sda = Fiji_I2C_DDC5DATA;
121− break;
122− case Fiji_I2CLineID_DDC6 :
123− *scl = Fiji_I2C_DDC6CLK;
124− *sda = Fiji_I2C_DDC6DATA;
125− break;
126− case Fiji_I2CLineID_SCLSDA :
127− *scl = Fiji_I2C_SCL;
128− *sda = Fiji_I2C_SDA;
129− break;
130− case Fiji_I2CLineID_DDCVGA :
131− *scl = Fiji_I2C_DDCVGACLK;
132− *sda = Fiji_I2C_DDCVGADATA;
133− break;
134− default:
135− *scl = 0;
136− *sda = 0;
137− break;
138− }
139−}
140−
141−int fiji_populate_bapm_parameters_in_dpm_table(struct pp_hwmgr *hwmgr)
142−{
143− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
144− const struct fiji_pt_defaults *defaults = data->power_tune_defaults;
145− SMU73_Discrete_DpmTable *dpm_table = &(data->smc_state_table);
146− struct phm_ppt_v1_information *table_info =
147− (struct phm_ppt_v1_information *)(hwmgr->pptable);
148− struct phm_cac_tdp_table *cac_dtp_table = table_info->cac_dtp_table;
149− struct pp_advance_fan_control_parameters *fan_table=
150− &hwmgr->thermal_controller.advanceFanControlParameters;
151− uint8_t uc_scl, uc_sda;
152−
153− /* TDP number of fraction bits are changed from 8 to 7 for Fiji
154− * as requested by SMC team
155− */
156− dpm_table->DefaultTdp = PP_HOST_TO_SMC_US(
157− (uint16_t)(cac_dtp_table->usTDP * 128));
158− dpm_table->TargetTdp = PP_HOST_TO_SMC_US(
159− (uint16_t)(cac_dtp_table->usTDP * 128));
160−
161− PP_ASSERT_WITH_CODE(cac_dtp_table->usTargetOperatingTemp <= 255,
162− "Target Operating Temp is out of Range!",);
163−
164− dpm_table->GpuTjMax = (uint8_t)(cac_dtp_table->usTargetOperatingTemp);
165− dpm_table->GpuTjHyst = 8;
166−
167− dpm_table->DTEAmbientTempBase = defaults->DTEAmbientTempBase;
168−
169− /* The following are for new Fiji Multi-input fan/thermal control */
170− dpm_table->TemperatureLimitEdge = PP_HOST_TO_SMC_US(
171− cac_dtp_table->usTargetOperatingTemp * 256);
172− dpm_table->TemperatureLimitHotspot = PP_HOST_TO_SMC_US(
173− cac_dtp_table->usTemperatureLimitHotspot * 256);
174− dpm_table->TemperatureLimitLiquid1 = PP_HOST_TO_SMC_US(
175− cac_dtp_table->usTemperatureLimitLiquid1 * 256);
176− dpm_table->TemperatureLimitLiquid2 = PP_HOST_TO_SMC_US(
177− cac_dtp_table->usTemperatureLimitLiquid2 * 256);
178− dpm_table->TemperatureLimitVrVddc = PP_HOST_TO_SMC_US(
179− cac_dtp_table->usTemperatureLimitVrVddc * 256);
180− dpm_table->TemperatureLimitVrMvdd = PP_HOST_TO_SMC_US(
181− cac_dtp_table->usTemperatureLimitVrMvdd * 256);
182− dpm_table->TemperatureLimitPlx = PP_HOST_TO_SMC_US(
183− cac_dtp_table->usTemperatureLimitPlx * 256);
184−
185− dpm_table->FanGainEdge = PP_HOST_TO_SMC_US(
186− scale_fan_gain_settings(fan_table->usFanGainEdge));
187− dpm_table->FanGainHotspot = PP_HOST_TO_SMC_US(
188− scale_fan_gain_settings(fan_table->usFanGainHotspot));
189− dpm_table->FanGainLiquid = PP_HOST_TO_SMC_US(
190− scale_fan_gain_settings(fan_table->usFanGainLiquid));
191− dpm_table->FanGainVrVddc = PP_HOST_TO_SMC_US(
192− scale_fan_gain_settings(fan_table->usFanGainVrVddc));
193− dpm_table->FanGainVrMvdd = PP_HOST_TO_SMC_US(
194− scale_fan_gain_settings(fan_table->usFanGainVrMvdd));
195− dpm_table->FanGainPlx = PP_HOST_TO_SMC_US(
196− scale_fan_gain_settings(fan_table->usFanGainPlx));
197− dpm_table->FanGainHbm = PP_HOST_TO_SMC_US(
198− scale_fan_gain_settings(fan_table->usFanGainHbm));
199−
200− dpm_table->Liquid1_I2C_address = cac_dtp_table->ucLiquid1_I2C_address;
201− dpm_table->Liquid2_I2C_address = cac_dtp_table->ucLiquid2_I2C_address;
202− dpm_table->Vr_I2C_address = cac_dtp_table->ucVr_I2C_address;
203− dpm_table->Plx_I2C_address = cac_dtp_table->ucPlx_I2C_address;
204−
205− get_scl_sda_value(cac_dtp_table->ucLiquid_I2C_Line, &uc_scl, &uc_sda);
206− dpm_table->Liquid_I2C_LineSCL = uc_scl;
207− dpm_table->Liquid_I2C_LineSDA = uc_sda;
208−
209− get_scl_sda_value(cac_dtp_table->ucVr_I2C_Line, &uc_scl, &uc_sda);
210− dpm_table->Vr_I2C_LineSCL = uc_scl;
211− dpm_table->Vr_I2C_LineSDA = uc_sda;
212−
213− get_scl_sda_value(cac_dtp_table->ucPlx_I2C_Line, &uc_scl, &uc_sda);
214− dpm_table->Plx_I2C_LineSCL = uc_scl;
215− dpm_table->Plx_I2C_LineSDA = uc_sda;
216−
217− return 0;
218−}
219−
220−static int fiji_populate_svi_load_line(struct pp_hwmgr *hwmgr)
221−{
222− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
223− const struct fiji_pt_defaults *defaults = data->power_tune_defaults;
224−
225− data->power_tune_table.SviLoadLineEn = defaults->SviLoadLineEn;
226− data->power_tune_table.SviLoadLineVddC = defaults->SviLoadLineVddC;
227− data->power_tune_table.SviLoadLineTrimVddC = 3;
228− data->power_tune_table.SviLoadLineOffsetVddC = 0;
229−
230− return 0;
231−}
232−
233−static int fiji_populate_tdc_limit(struct pp_hwmgr *hwmgr)
234−{
235− uint16_t tdc_limit;
236− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
237− struct phm_ppt_v1_information *table_info =
238− (struct phm_ppt_v1_information *)(hwmgr->pptable);
239− const struct fiji_pt_defaults *defaults = data->power_tune_defaults;
240−
241− /* TDC number of fraction bits are changed from 8 to 7
242− * for Fiji as requested by SMC team
243− */
244− tdc_limit = (uint16_t)(table_info->cac_dtp_table->usTDC * 128);
245− data->power_tune_table.TDC_VDDC_PkgLimit =
246− CONVERT_FROM_HOST_TO_SMC_US(tdc_limit);
247− data->power_tune_table.TDC_VDDC_ThrottleReleaseLimitPerc =
248− defaults->TDC_VDDC_ThrottleReleaseLimitPerc;
249− data->power_tune_table.TDC_MAWt = defaults->TDC_MAWt;
250−
251− return 0;
252−}
253−
254−static int fiji_populate_dw8(struct pp_hwmgr *hwmgr, uint32_t fuse_table_offset)
255−{
256− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
257− const struct fiji_pt_defaults *defaults = data->power_tune_defaults;
258− uint32_t temp;
259−
260− if (fiji_read_smc_sram_dword(hwmgr->smumgr,
261− fuse_table_offset +
262− offsetof(SMU73_Discrete_PmFuses, TdcWaterfallCtl),
263− (uint32_t *)&temp, data->sram_end))
264− PP_ASSERT_WITH_CODE(false,
265− "Attempt to read PmFuses.DW6 (SviLoadLineEn) from SMC Failed!",
266− return -EINVAL);
267− else {
268− data->power_tune_table.TdcWaterfallCtl = defaults->TdcWaterfallCtl;
269− data->power_tune_table.LPMLTemperatureMin =
270− (uint8_t)((temp >> 16) & 0xff);
271− data->power_tune_table.LPMLTemperatureMax =
272− (uint8_t)((temp >> 8) & 0xff);
273− data->power_tune_table.Reserved = (uint8_t)(temp & 0xff);
274− }
275− return 0;
276−}
277−
278−static int fiji_populate_temperature_scaler(struct pp_hwmgr *hwmgr)
279−{
280− int i;
281− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
282−
283− /* Currently not used. Set all to zero. */
284− for (i = 0; i < 16; i++)
285− data->power_tune_table.LPMLTemperatureScaler[i] = 0;
286−
287− return 0;
288−}
289−
290−static int fiji_populate_fuzzy_fan(struct pp_hwmgr *hwmgr)
291−{
292− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
293−
294− if( (hwmgr->thermal_controller.advanceFanControlParameters.
295− usFanOutputSensitivity & (1 << 15)) ||
296− 0 == hwmgr->thermal_controller.advanceFanControlParameters.
297− usFanOutputSensitivity )
298− hwmgr->thermal_controller.advanceFanControlParameters.
299− usFanOutputSensitivity = hwmgr->thermal_controller.
300− advanceFanControlParameters.usDefaultFanOutputSensitivity;
301−
302− data->power_tune_table.FuzzyFan_PwmSetDelta =
303− PP_HOST_TO_SMC_US(hwmgr->thermal_controller.
304− advanceFanControlParameters.usFanOutputSensitivity);
305− return 0;
306−}
307−
308−static int fiji_populate_gnb_lpml(struct pp_hwmgr *hwmgr)
309−{
310− int i;
311− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
312−
313− /* Currently not used. Set all to zero. */
314− for (i = 0; i < 16; i++)
315− data->power_tune_table.GnbLPML[i] = 0;
316−
317− return 0;
318−}
319−
320−static int fiji_min_max_vgnb_lpml_id_from_bapm_vddc(struct pp_hwmgr *hwmgr)
321−{
322− /* int i, min, max;
323− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
324− uint8_t * pHiVID = data->power_tune_table.BapmVddCVidHiSidd;
325− uint8_t * pLoVID = data->power_tune_table.BapmVddCVidLoSidd;
326−
327− min = max = pHiVID[0];
328− for (i = 0; i < 8; i++) {
329− if (0 != pHiVID[i]) {
330− if (min > pHiVID[i])
331− min = pHiVID[i];
332− if (max < pHiVID[i])
333− max = pHiVID[i];
334− }
335−
336− if (0 != pLoVID[i]) {
337− if (min > pLoVID[i])
338− min = pLoVID[i];
339− if (max < pLoVID[i])
340− max = pLoVID[i];
341− }
342− }
343−
344− PP_ASSERT_WITH_CODE((0 != min) && (0 != max), "BapmVddcVidSidd table does not exist!", return int_Failed);
345− data->power_tune_table.GnbLPMLMaxVid = (uint8_t)max;
346− data->power_tune_table.GnbLPMLMinVid = (uint8_t)min;
347−*/
348− return 0;
349−}
350−
351−static int fiji_populate_bapm_vddc_base_leakage_sidd(struct pp_hwmgr *hwmgr)
352−{
353− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
354− struct phm_ppt_v1_information *table_info =
355− (struct phm_ppt_v1_information *)(hwmgr->pptable);
356− uint16_t HiSidd = data->power_tune_table.BapmVddCBaseLeakageHiSidd;
357− uint16_t LoSidd = data->power_tune_table.BapmVddCBaseLeakageLoSidd;
358− struct phm_cac_tdp_table *cac_table = table_info->cac_dtp_table;
359−
360− HiSidd = (uint16_t)(cac_table->usHighCACLeakage / 100 * 256);
361− LoSidd = (uint16_t)(cac_table->usLowCACLeakage / 100 * 256);
362−
363− data->power_tune_table.BapmVddCBaseLeakageHiSidd =
364− CONVERT_FROM_HOST_TO_SMC_US(HiSidd);
365− data->power_tune_table.BapmVddCBaseLeakageLoSidd =
366− CONVERT_FROM_HOST_TO_SMC_US(LoSidd);
367−
368− return 0;
369−}
370−
371−int fiji_populate_pm_fuses(struct pp_hwmgr *hwmgr)
372−{
373− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
374− uint32_t pm_fuse_table_offset;
375−
376− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
377− PHM_PlatformCaps_PowerContainment)) {
378− if (fiji_read_smc_sram_dword(hwmgr->smumgr,
379− SMU7_FIRMWARE_HEADER_LOCATION +
380− offsetof(SMU73_Firmware_Header, PmFuseTable),
381− &pm_fuse_table_offset, data->sram_end))
382− PP_ASSERT_WITH_CODE(false,
383− "Attempt to get pm_fuse_table_offset Failed!",
384− return -EINVAL);
385−
386− /* DW6 */
387− if (fiji_populate_svi_load_line(hwmgr))
388− PP_ASSERT_WITH_CODE(false,
389− "Attempt to populate SviLoadLine Failed!",
390− return -EINVAL);
391− /* DW7 */
392− if (fiji_populate_tdc_limit(hwmgr))
393− PP_ASSERT_WITH_CODE(false,
394− "Attempt to populate TDCLimit Failed!", return -EINVAL);
395− /* DW8 */
396− if (fiji_populate_dw8(hwmgr, pm_fuse_table_offset))
397− PP_ASSERT_WITH_CODE(false,
398− "Attempt to populate TdcWaterfallCtl, "
399− "LPMLTemperature Min and Max Failed!",
400− return -EINVAL);
401−
402− /* DW9-DW12 */
403− if (0 != fiji_populate_temperature_scaler(hwmgr))
404− PP_ASSERT_WITH_CODE(false,
405− "Attempt to populate LPMLTemperatureScaler Failed!",
406− return -EINVAL);
407−
408− /* DW13-DW14 */
409− if(fiji_populate_fuzzy_fan(hwmgr))
410− PP_ASSERT_WITH_CODE(false,
411− "Attempt to populate Fuzzy Fan Control parameters Failed!",
412− return -EINVAL);
413−
414− /* DW15-DW18 */
415− if (fiji_populate_gnb_lpml(hwmgr))
416− PP_ASSERT_WITH_CODE(false,
417− "Attempt to populate GnbLPML Failed!",
418− return -EINVAL);
419−
420− /* DW19 */
421− if (fiji_min_max_vgnb_lpml_id_from_bapm_vddc(hwmgr))
422− PP_ASSERT_WITH_CODE(false,
423− "Attempt to populate GnbLPML Min and Max Vid Failed!",
424− return -EINVAL);
425−
426− /* DW20 */
427− if (fiji_populate_bapm_vddc_base_leakage_sidd(hwmgr))
428− PP_ASSERT_WITH_CODE(false,
429− "Attempt to populate BapmVddCBaseLeakage Hi and Lo "
430− "Sidd Failed!", return -EINVAL);
431−
432− if (fiji_copy_bytes_to_smc(hwmgr->smumgr, pm_fuse_table_offset,
433− (uint8_t *)&data->power_tune_table,
434− sizeof(struct SMU73_Discrete_PmFuses), data->sram_end))
435− PP_ASSERT_WITH_CODE(false,
436− "Attempt to download PmFuseTable Failed!",
437− return -EINVAL);
438− }
439− return 0;
440−}
441−
442−int fiji_enable_smc_cac(struct pp_hwmgr *hwmgr)
443−{
444− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
445− int result = 0;
446−
447− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
448− PHM_PlatformCaps_CAC)) {
449− int smc_result;
450− smc_result = smum_send_msg_to_smc(hwmgr->smumgr,
451− (uint16_t)(PPSMC_MSG_EnableCac));
452− PP_ASSERT_WITH_CODE((0 == smc_result),
453− "Failed to enable CAC in SMC.", result = -1);
454−
455− data->cac_enabled = (0 == smc_result) ? true : false;
456− }
457− return result;
458−}
459−
460−int fiji_disable_smc_cac(struct pp_hwmgr *hwmgr)
461−{
462− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
463− int result = 0;
464−
465− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
466− PHM_PlatformCaps_CAC) && data->cac_enabled) {
467− int smc_result = smum_send_msg_to_smc(hwmgr->smumgr,
468− (uint16_t)(PPSMC_MSG_DisableCac));
469− PP_ASSERT_WITH_CODE((smc_result == 0),
470− "Failed to disable CAC in SMC.", result = -1);
471−
472− data->cac_enabled = false;
473− }
474− return result;
475−}
476−
477−int fiji_set_power_limit(struct pp_hwmgr *hwmgr, uint32_t n)
478−{
479− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
480−
481− if(data->power_containment_features &
482− POWERCONTAINMENT_FEATURE_PkgPwrLimit)
483− return smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
484− PPSMC_MSG_PkgPwrSetLimit, n);
485− return 0;
486−}
487−
488−static int fiji_set_overdriver_target_tdp(struct pp_hwmgr *pHwMgr, uint32_t target_tdp)
489−{
490− return smum_send_msg_to_smc_with_parameter(pHwMgr->smumgr,
491− PPSMC_MSG_OverDriveSetTargetTdp, target_tdp);
492−}
493−
494−int fiji_enable_power_containment(struct pp_hwmgr *hwmgr)
495−{
496− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
497− struct phm_ppt_v1_information *table_info =
498− (struct phm_ppt_v1_information *)(hwmgr->pptable);
499− int smc_result;
500− int result = 0;
501−
502− data->power_containment_features = 0;
503− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
504− PHM_PlatformCaps_PowerContainment)) {
505− if (data->enable_dte_feature) {
506− smc_result = smum_send_msg_to_smc(hwmgr->smumgr,
507− (uint16_t)(PPSMC_MSG_EnableDTE));
508− PP_ASSERT_WITH_CODE((0 == smc_result),
509− "Failed to enable DTE in SMC.", result = -1;);
510− if (0 == smc_result)
511− data->power_containment_features |= POWERCONTAINMENT_FEATURE_DTE;
512− }
513−
514− if (data->enable_tdc_limit_feature) {
515− smc_result = smum_send_msg_to_smc(hwmgr->smumgr,
516− (uint16_t)(PPSMC_MSG_TDCLimitEnable));
517− PP_ASSERT_WITH_CODE((0 == smc_result),
518− "Failed to enable TDCLimit in SMC.", result = -1;);
519− if (0 == smc_result)
520− data->power_containment_features |=
521− POWERCONTAINMENT_FEATURE_TDCLimit;
522− }
523−
524− if (data->enable_pkg_pwr_tracking_feature) {
525− smc_result = smum_send_msg_to_smc(hwmgr->smumgr,
526− (uint16_t)(PPSMC_MSG_PkgPwrLimitEnable));
527− PP_ASSERT_WITH_CODE((0 == smc_result),
528− "Failed to enable PkgPwrTracking in SMC.", result = -1;);
529− if (0 == smc_result) {
530− struct phm_cac_tdp_table *cac_table =
531− table_info->cac_dtp_table;
532− uint32_t default_limit =
533− (uint32_t)(cac_table->usMaximumPowerDeliveryLimit * 256);
534−
535− data->power_containment_features |=
536− POWERCONTAINMENT_FEATURE_PkgPwrLimit;
537−
538− if (fiji_set_power_limit(hwmgr, default_limit))
539− printk(KERN_ERR "Failed to set Default Power Limit in SMC!");
540− }
541− }
542− }
543− return result;
544−}
545−
546−int fiji_disable_power_containment(struct pp_hwmgr *hwmgr)
547−{
548− struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
549− int result = 0;
550−
551− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
552− PHM_PlatformCaps_PowerContainment) &&
553− data->power_containment_features) {
554− int smc_result;
555−
556− if (data->power_containment_features &
557− POWERCONTAINMENT_FEATURE_TDCLimit) {
558− smc_result = smum_send_msg_to_smc(hwmgr->smumgr,
559− (uint16_t)(PPSMC_MSG_TDCLimitDisable));
560− PP_ASSERT_WITH_CODE((smc_result == 0),
561− "Failed to disable TDCLimit in SMC.",
562− result = smc_result);
563− }
564−
565− if (data->power_containment_features &
566− POWERCONTAINMENT_FEATURE_DTE) {
567− smc_result = smum_send_msg_to_smc(hwmgr->smumgr,
568− (uint16_t)(PPSMC_MSG_DisableDTE));
569− PP_ASSERT_WITH_CODE((smc_result == 0),
570− "Failed to disable DTE in SMC.",
571− result = smc_result);
572− }
573−
574− if (data->power_containment_features &
575− POWERCONTAINMENT_FEATURE_PkgPwrLimit) {
576− smc_result = smum_send_msg_to_smc(hwmgr->smumgr,
577− (uint16_t)(PPSMC_MSG_PkgPwrLimitDisable));
578− PP_ASSERT_WITH_CODE((smc_result == 0),
579− "Failed to disable PkgPwrTracking in SMC.",
580− result = smc_result);
581− }
582− data->power_containment_features = 0;
583− }
584−
585− return result;
586−}
587−
588−int fiji_power_control_set_level(struct pp_hwmgr *hwmgr)
589−{
590− struct phm_ppt_v1_information *table_info =
591− (struct phm_ppt_v1_information *)(hwmgr->pptable);
592− struct phm_cac_tdp_table *cac_table = table_info->cac_dtp_table;
593− int adjust_percent, target_tdp;
594− int result = 0;
595−
596− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
597− PHM_PlatformCaps_PowerContainment)) {
598− /* adjustment percentage has already been validated */
599− adjust_percent = hwmgr->platform_descriptor.TDPAdjustmentPolarity ?
600− hwmgr->platform_descriptor.TDPAdjustment :
601− (-1 * hwmgr->platform_descriptor.TDPAdjustment);
602− /* SMC requested that target_tdp to be 7 bit fraction in DPM table
603− * but message to be 8 bit fraction for messages
604− */
605− target_tdp = ((100 + adjust_percent) * (int)(cac_table->usTDP * 256)) / 100;
606− result = fiji_set_overdriver_target_tdp(hwmgr, (uint32_t)target_tdp);
607− }
608−
609− return result;
610−}
drivers/gpu/drm/amd/powerplay/hwmgr/fiji_powertune.h+0−81
@@ -1,81 +0,0 @@
1−/*
2− * Copyright 2015 Advanced Micro Devices, Inc.
3− *
4− * Permission is hereby granted, free of charge, to any person obtaining a
5− * copy of this software and associated documentation files (the "Software"),
6− * to deal in the Software without restriction, including without limitation
7− * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8− * and/or sell copies of the Software, and to permit persons to whom the
9− * Software is furnished to do so, subject to the following conditions:
10− *
11− * The above copyright notice and this permission notice shall be included in
12− * all copies or substantial portions of the Software.
13− *
14− * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15− * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16− * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17− * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18− * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19− * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20− * OTHER DEALINGS IN THE SOFTWARE.
21− *
22− */
23−#ifndef FIJI_POWERTUNE_H
24−#define FIJI_POWERTUNE_H
25−
26−enum fiji_pt_config_reg_type {
27− FIJI_CONFIGREG_MMR = 0,
28− FIJI_CONFIGREG_SMC_IND,
29− FIJI_CONFIGREG_DIDT_IND,
30− FIJI_CONFIGREG_CACHE,
31− FIJI_CONFIGREG_MAX
32−};
33−
34−/* PowerContainment Features */
35−#define POWERCONTAINMENT_FEATURE_DTE 0x00000001
36−#define POWERCONTAINMENT_FEATURE_TDCLimit 0x00000002
37−#define POWERCONTAINMENT_FEATURE_PkgPwrLimit 0x00000004
38−
39−#define DIDT_SQ_CTRL0__UNUSED_0_MASK 0xffffffc0
40−#define DIDT_SQ_CTRL0__UNUSED_0__SHIFT 0x6
41−#define DIDT_TD_CTRL0__UNUSED_0_MASK 0xffffffc0
42−#define DIDT_TD_CTRL0__UNUSED_0__SHIFT 0x6
43−#define DIDT_TCP_CTRL0__UNUSED_0_MASK 0xffffffc0
44−#define DIDT_TCP_CTRL0__UNUSED_0__SHIFT 0x6
45−#define DIDT_SQ_TUNING_CTRL__UNUSED_0_MASK 0xe0000000
46−#define DIDT_SQ_TUNING_CTRL__UNUSED_0__SHIFT 0x0000001d
47−#define DIDT_TD_TUNING_CTRL__UNUSED_0_MASK 0xe0000000
48−#define DIDT_TD_TUNING_CTRL__UNUSED_0__SHIFT 0x0000001d
49−#define DIDT_TCP_TUNING_CTRL__UNUSED_0_MASK 0xe0000000
50−#define DIDT_TCP_TUNING_CTRL__UNUSED_0__SHIFT 0x0000001d
51−
52−struct fiji_pt_config_reg {
53− uint32_t offset;
54− uint32_t mask;
55− uint32_t shift;
56− uint32_t value;
57− enum fiji_pt_config_reg_type type;
58−};
59−
60−struct fiji_pt_defaults
61−{
62− uint8_t SviLoadLineEn;
63− uint8_t SviLoadLineVddC;
64− uint8_t TDC_VDDC_ThrottleReleaseLimitPerc;
65− uint8_t TDC_MAWt;
66− uint8_t TdcWaterfallCtl;
67− uint8_t DTEAmbientTempBase;
68−};
69−
70−void fiji_initialize_power_tune_defaults(struct pp_hwmgr *hwmgr);
71−int fiji_populate_bapm_parameters_in_dpm_table(struct pp_hwmgr *hwmgr);
72−int fiji_populate_pm_fuses(struct pp_hwmgr *hwmgr);
73−int fiji_enable_smc_cac(struct pp_hwmgr *hwmgr);
74−int fiji_disable_smc_cac(struct pp_hwmgr *hwmgr);
75−int fiji_enable_power_containment(struct pp_hwmgr *hwmgr);
76−int fiji_disable_power_containment(struct pp_hwmgr *hwmgr);
77−int fiji_set_power_limit(struct pp_hwmgr *hwmgr, uint32_t n);
78−int fiji_power_control_set_level(struct pp_hwmgr *hwmgr);
79−
80−#endif /* FIJI_POWERTUNE_H */
81−
drivers/gpu/drm/amd/powerplay/hwmgr/fiji_thermal.h+0−62
@@ -1,62 +0,0 @@
1−/*
2− * Copyright 2015 Advanced Micro Devices, Inc.
3− *
4− * Permission is hereby granted, free of charge, to any person obtaining a
5− * copy of this software and associated documentation files (the "Software"),
6− * to deal in the Software without restriction, including without limitation
7− * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8− * and/or sell copies of the Software, and to permit persons to whom the
9− * Software is furnished to do so, subject to the following conditions:
10− *
11− * The above copyright notice and this permission notice shall be included in
12− * all copies or substantial portions of the Software.
13− *
14− * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15− * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16− * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17− * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18− * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19− * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20− * OTHER DEALINGS IN THE SOFTWARE.
21− *
22− */
23−
24−#ifndef FIJI_THERMAL_H
25−#define FIJI_THERMAL_H
26−
27−#include "hwmgr.h"
28−
29−#define FIJI_THERMAL_HIGH_ALERT_MASK 0x1
30−#define FIJI_THERMAL_LOW_ALERT_MASK 0x2
31−
32−#define FIJI_THERMAL_MINIMUM_TEMP_READING -256
33−#define FIJI_THERMAL_MAXIMUM_TEMP_READING 255
34−
35−#define FIJI_THERMAL_MINIMUM_ALERT_TEMP 0
36−#define FIJI_THERMAL_MAXIMUM_ALERT_TEMP 255
37−
38−#define FDO_PWM_MODE_STATIC 1
39−#define FDO_PWM_MODE_STATIC_RPM 5
40−
41−
42−extern int tf_fiji_thermal_initialize(struct pp_hwmgr *hwmgr, void *input, void *output, void *storage, int result);
43−extern int tf_fiji_thermal_set_temperature_range(struct pp_hwmgr *hwmgr, void *input, void *output, void *storage, int result);
44−extern int tf_fiji_thermal_enable_alert(struct pp_hwmgr *hwmgr, void *input, void *output, void *storage, int result);
45−
46−extern int fiji_thermal_get_temperature(struct pp_hwmgr *hwmgr);
47−extern int fiji_thermal_stop_thermal_controller(struct pp_hwmgr *hwmgr);
48−extern int fiji_fan_ctrl_get_fan_speed_info(struct pp_hwmgr *hwmgr, struct phm_fan_speed_info *fan_speed_info);
49−extern int fiji_fan_ctrl_get_fan_speed_percent(struct pp_hwmgr *hwmgr, uint32_t *speed);
50−extern int fiji_fan_ctrl_set_default_mode(struct pp_hwmgr *hwmgr);
51−extern int fiji_fan_ctrl_set_static_mode(struct pp_hwmgr *hwmgr, uint32_t mode);
52−extern int fiji_fan_ctrl_set_fan_speed_percent(struct pp_hwmgr *hwmgr, uint32_t speed);
53−extern int fiji_fan_ctrl_reset_fan_speed_to_default(struct pp_hwmgr *hwmgr);
54−extern int pp_fiji_thermal_initialize(struct pp_hwmgr *hwmgr);
55−extern int fiji_thermal_ctrl_uninitialize_thermal_controller(struct pp_hwmgr *hwmgr);
56−extern int fiji_fan_ctrl_set_fan_speed_rpm(struct pp_hwmgr *hwmgr, uint32_t speed);
57−extern int fiji_fan_ctrl_get_fan_speed_rpm(struct pp_hwmgr *hwmgr, uint32_t *speed);
58−extern int fiji_fan_ctrl_stop_smc_fan_control(struct pp_hwmgr *hwmgr);
59−extern uint32_t tonga_get_xclk(struct pp_hwmgr *hwmgr);
60−
61−#endif
62−
drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c+113−13
@@ -36,13 +36,13 @@ · 35 unmodified lines
3636 #include "amd_acpi.h"
3737
3838 extern int cz_hwmgr_init(struct pp_hwmgr *hwmgr);
39−extern int tonga_hwmgr_init(struct pp_hwmgr *hwmgr);
40−extern int fiji_hwmgr_init(struct pp_hwmgr *hwmgr);
41−extern int polaris10_hwmgr_init(struct pp_hwmgr *hwmgr);
42−extern int iceland_hwmgr_init(struct pp_hwmgr *hwmgr);
4339
40+static int polaris_set_asic_special_caps(struct pp_hwmgr *hwmgr);
4441 static void hwmgr_init_default_caps(struct pp_hwmgr *hwmgr);
4542 static int hwmgr_set_user_specify_caps(struct pp_hwmgr *hwmgr);
43+static int fiji_set_asic_special_caps(struct pp_hwmgr *hwmgr);
44+static int tonga_set_asic_special_caps(struct pp_hwmgr *hwmgr);
45+static int topaz_set_asic_special_caps(struct pp_hwmgr *hwmgr);
4646
4747 uint8_t convert_to_vid(uint16_t vddc)
4848 {
@@ -79,21 +79,32 @@ int hwmgr_init(struct amd_pp_init *pp_init, struct pp_instance *handle) · 30 unmodified lines
7979 case AMDGPU_FAMILY_VI:
8080 switch (hwmgr->chip_id) {
8181 case CHIP_TOPAZ:
82− iceland_hwmgr_init(hwmgr);
82+ topaz_set_asic_special_caps(hwmgr);
83+ hwmgr->feature_mask &= ~(PP_SMC_VOLTAGE_CONTROL_MASK |
84+ PP_VBI_TIME_SUPPORT_MASK |
85+ PP_ENABLE_GFX_CG_THRU_SMU);
86+ hwmgr->pp_table_version = PP_TABLE_V0;
8387 break;
8488 case CHIP_TONGA:
85− tonga_hwmgr_init(hwmgr);
89+ tonga_set_asic_special_caps(hwmgr);
90+ hwmgr->feature_mask &= ~(PP_SMC_VOLTAGE_CONTROL_MASK |
91+ PP_VBI_TIME_SUPPORT_MASK);
8692 break;
8793 case CHIP_FIJI:
88− fiji_hwmgr_init(hwmgr);
94+ fiji_set_asic_special_caps(hwmgr);
95+ hwmgr->feature_mask &= ~(PP_SMC_VOLTAGE_CONTROL_MASK |
96+ PP_VBI_TIME_SUPPORT_MASK |
97+ PP_ENABLE_GFX_CG_THRU_SMU);
8998 break;
9099 case CHIP_POLARIS11:
91100 case CHIP_POLARIS10:
92− polaris10_hwmgr_init(hwmgr);
101+ polaris_set_asic_special_caps(hwmgr);
102+ hwmgr->feature_mask &= ~(PP_UVD_HANDSHAKE_MASK);
93103 break;
94104 default:
95105 return -EINVAL;
96106 }
107+ smu7_hwmgr_init(hwmgr);
97108 break;
98109 default:
99110 return -EINVAL;
@@ -388,12 +399,9 @@ int phm_reset_single_dpm_table(void *table, · 288 unmodified lines
388399
389400 struct vi_dpm_table *dpm_table = (struct vi_dpm_table *)table;
390401
391− PP_ASSERT_WITH_CODE(count <= max,
392− "Fatal error, can not set up single DPM table entries to exceed max number!",
393− );
402+ dpm_table->count = count > max ? max : count;
394403
395− dpm_table->count = count;
396− for (i = 0; i < max; i++)
404+ for (i = 0; i < dpm_table->count; i++)
397405 dpm_table->dpm_level[i].enabled = false;
398406
399407 return 0;
@@ -713,3 +721,95 @@ int phm_get_voltage_evv_on_sclk(struct pp_hwmgr *hwmgr, uint8_t voltage_type, · 313 unmodified lines
713721 return ret;
714722 }
715723
724+int polaris_set_asic_special_caps(struct pp_hwmgr *hwmgr)
725+{
726+ /* power tune caps Assume disabled */
727+ phm_cap_set(hwmgr->platform_descriptor.platformCaps,
728+ PHM_PlatformCaps_SQRamping);
729+ phm_cap_set(hwmgr->platform_descriptor.platformCaps,
730+ PHM_PlatformCaps_DBRamping);
731+ phm_cap_set(hwmgr->platform_descriptor.platformCaps,
732+ PHM_PlatformCaps_TDRamping);
733+ phm_cap_set(hwmgr->platform_descriptor.platformCaps,
734+ PHM_PlatformCaps_TCPRamping);
735+
736+ phm_cap_set(hwmgr->platform_descriptor.platformCaps,
737+ PHM_PlatformCaps_CAC);
738+
739+ phm_cap_set(hwmgr->platform_descriptor.platformCaps,
740+ PHM_PlatformCaps_RegulatorHot);
741+
742+ phm_cap_set(hwmgr->platform_descriptor.platformCaps,
743+ PHM_PlatformCaps_AutomaticDCTransition);
744+
745+ phm_cap_set(hwmgr->platform_descriptor.platformCaps,
746+ PHM_PlatformCaps_TablelessHardwareInterface);
747+
748+ if (hwmgr->chip_id == CHIP_POLARIS11)
749+ phm_cap_set(hwmgr->platform_descriptor.platformCaps,
750+ PHM_PlatformCaps_SPLLShutdownSupport);
751+ return 0;
752+}
753+
754+int fiji_set_asic_special_caps(struct pp_hwmgr *hwmgr)
755+{
756+ phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
757+ PHM_PlatformCaps_SQRamping);
758+ phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
759+ PHM_PlatformCaps_DBRamping);
760+ phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
761+ PHM_PlatformCaps_TDRamping);
762+ phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
763+ PHM_PlatformCaps_TCPRamping);
764+
765+ phm_cap_set(hwmgr->platform_descriptor.platformCaps,
766+ PHM_PlatformCaps_TablelessHardwareInterface);
767+
768+ phm_cap_set(hwmgr->platform_descriptor.platformCaps,
769+ PHM_PlatformCaps_CAC);
770+ return 0;
771+}
772+
773+int tonga_set_asic_special_caps(struct pp_hwmgr *hwmgr)
774+{
775+ phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
776+ PHM_PlatformCaps_SQRamping);
777+ phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
778+ PHM_PlatformCaps_DBRamping);
779+ phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
780+ PHM_PlatformCaps_TDRamping);
781+ phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
782+ PHM_PlatformCaps_TCPRamping);
783+
784+ phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
785+ PHM_PlatformCaps_UVDPowerGating);
786+ phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
787+ PHM_PlatformCaps_VCEPowerGating);
788+
789+ phm_cap_set(hwmgr->platform_descriptor.platformCaps,
790+ PHM_PlatformCaps_TablelessHardwareInterface);
791+
792+ phm_cap_set(hwmgr->platform_descriptor.platformCaps,
793+ PHM_PlatformCaps_CAC);
794+
795+ return 0;
796+}
797+
798+int topaz_set_asic_special_caps(struct pp_hwmgr *hwmgr)
799+{
800+ phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
801+ PHM_PlatformCaps_SQRamping);
802+ phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
803+ PHM_PlatformCaps_DBRamping);
804+ phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
805+ PHM_PlatformCaps_TDRamping);
806+ phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
807+ PHM_PlatformCaps_TCPRamping);
808+ phm_cap_set(hwmgr->platform_descriptor.platformCaps,
809+ PHM_PlatformCaps_TablelessHardwareInterface);
810+ phm_cap_set(hwmgr->platform_descriptor.platformCaps,
811+ PHM_PlatformCaps_CAC);
812+ phm_cap_set(hwmgr->platform_descriptor.platformCaps,
813+ PHM_PlatformCaps_EVV);
814+ return 0;
815+}
drivers/gpu/drm/amd/powerplay/hwmgr/iceland_clockpowergating.c+0−119
@@ -1,119 +0,0 @@
1−/*
2− * Copyright 2016 Advanced Micro Devices, Inc.
3− *
4− * Permission is hereby granted, free of charge, to any person obtaining a
5− * copy of this software and associated documentation files (the "Software"),
6− * to deal in the Software without restriction, including without limitation
7− * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8− * and/or sell copies of the Software, and to permit persons to whom the
9− * Software is furnished to do so, subject to the following conditions:
10− *
11− * The above copyright notice and this permission notice shall be included in
12− * all copies or substantial portions of the Software.
13− *
14− * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15− * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16− * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17− * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18− * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19− * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20− * OTHER DEALINGS IN THE SOFTWARE.
21− *
22− * Author: Huang Rui <ray.huang@amd.com>
23− *
24− */
25−
26−#include "hwmgr.h"
27−#include "iceland_clockpowergating.h"
28−#include "ppsmc.h"
29−#include "iceland_hwmgr.h"
30−
31−int iceland_phm_powerdown_uvd(struct pp_hwmgr *hwmgr)
32−{
33− /* iceland does not have MM hardware block */
34− return 0;
35−}
36−
37−static int iceland_phm_powerup_uvd(struct pp_hwmgr *hwmgr)
38−{
39− /* iceland does not have MM hardware block */
40− return 0;
41−}
42−
43−static int iceland_phm_powerdown_vce(struct pp_hwmgr *hwmgr)
44−{
45− /* iceland does not have MM hardware block */
46− return 0;
47−}
48−
49−static int iceland_phm_powerup_vce(struct pp_hwmgr *hwmgr)
50−{
51− /* iceland does not have MM hardware block */
52− return 0;
53−}
54−
55−int iceland_phm_set_asic_block_gating(struct pp_hwmgr *hwmgr, enum
56− PHM_AsicBlock block, enum PHM_ClockGateSetting gating)
57−{
58− int ret = 0;
59−
60− switch (block) {
61− case PHM_AsicBlock_UVD_MVC:
62− case PHM_AsicBlock_UVD:
63− case PHM_AsicBlock_UVD_HD:
64− case PHM_AsicBlock_UVD_SD:
65− if (gating == PHM_ClockGateSetting_StaticOff)
66− ret = iceland_phm_powerdown_uvd(hwmgr);
67− else
68− ret = iceland_phm_powerup_uvd(hwmgr);
69− break;
70− case PHM_AsicBlock_GFX:
71− default:
72− break;
73− }
74−
75− return ret;
76−}
77−
78−int iceland_phm_disable_clock_power_gating(struct pp_hwmgr *hwmgr)
79−{
80− struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
81−
82− data->uvd_power_gated = false;
83− data->vce_power_gated = false;
84−
85− iceland_phm_powerup_uvd(hwmgr);
86− iceland_phm_powerup_vce(hwmgr);
87−
88− return 0;
89−}
90−
91−int iceland_phm_powergate_uvd(struct pp_hwmgr *hwmgr, bool bgate)
92−{
93− if (bgate) {
94− iceland_update_uvd_dpm(hwmgr, true);
95− iceland_phm_powerdown_uvd(hwmgr);
96− } else {
97− iceland_phm_powerup_uvd(hwmgr);
98− iceland_update_uvd_dpm(hwmgr, false);
99− }
100−
101− return 0;
102−}
103−
104−int iceland_phm_powergate_vce(struct pp_hwmgr *hwmgr, bool bgate)
105−{
106− if (bgate)
107− return iceland_phm_powerdown_vce(hwmgr);
108− else
109− return iceland_phm_powerup_vce(hwmgr);
110−
111− return 0;
112−}
113−
114−int iceland_phm_update_clock_gatings(struct pp_hwmgr *hwmgr,
115− const uint32_t *msg_id)
116−{
117− /* iceland does not have MM hardware block */
118− return 0;
119−}
drivers/gpu/drm/amd/powerplay/hwmgr/iceland_clockpowergating.h+0−38
@@ -1,38 +0,0 @@
1−/*
2− * Copyright 2016 Advanced Micro Devices, Inc.
3− *
4− * Permission is hereby granted, free of charge, to any person obtaining a
5− * copy of this software and associated documentation files (the "Software"),
6− * to deal in the Software without restriction, including without limitation
7− * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8− * and/or sell copies of the Software, and to permit persons to whom the
9− * Software is furnished to do so, subject to the following conditions:
10− *
11− * The above copyright notice and this permission notice shall be included in
12− * all copies or substantial portions of the Software.
13− *
14− * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15− * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16− * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17− * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18− * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19− * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20− * OTHER DEALINGS IN THE SOFTWARE.
21− *
22− * Author: Huang Rui <ray.huang@amd.com>
23− *
24− */
25−
26−#ifndef _ICELAND_CLOCK_POWER_GATING_H_
27−#define _ICELAND_CLOCK_POWER_GATING_H_
28−
29−#include "iceland_hwmgr.h"
30−#include "pp_asicblocks.h"
31−
32−extern int iceland_phm_set_asic_block_gating(struct pp_hwmgr *hwmgr, enum PHM_AsicBlock block, enum PHM_ClockGateSetting gating);
33−extern int iceland_phm_powergate_vce(struct pp_hwmgr *hwmgr, bool bgate);
34−extern int iceland_phm_powergate_uvd(struct pp_hwmgr *hwmgr, bool bgate);
35−extern int iceland_phm_powerdown_uvd(struct pp_hwmgr *hwmgr);
36−extern int iceland_phm_disable_clock_power_gating(struct pp_hwmgr *hwmgr);
37−extern int iceland_phm_update_clock_gatings(struct pp_hwmgr *hwmgr, const uint32_t *msg_id);
38−#endif /* _ICELAND_CLOCK_POWER_GATING_H_ */
drivers/gpu/drm/amd/powerplay/hwmgr/iceland_dyn_defaults.h+0−41
@@ -1,41 +0,0 @@
1−#ifndef ICELAND_DYN_DEFAULTS_H
2−#define ICELAND_DYN_DEFAULTS_H
3−
4−enum ICELANDdpm_TrendDetection
5−{
6− ICELANDdpm_TrendDetection_AUTO,
7− ICELANDdpm_TrendDetection_UP,
8− ICELANDdpm_TrendDetection_DOWN
9−};
10−typedef enum ICELANDdpm_TrendDetection ICELANDdpm_TrendDetection;
11−
12−
13−#define PPICELAND_VOTINGRIGHTSCLIENTS_DFLT0 0x3FFFC102
14−#define PPICELAND_VOTINGRIGHTSCLIENTS_DFLT1 0x000400
15−#define PPICELAND_VOTINGRIGHTSCLIENTS_DFLT2 0xC00080
16−#define PPICELAND_VOTINGRIGHTSCLIENTS_DFLT3 0xC00200
17−#define PPICELAND_VOTINGRIGHTSCLIENTS_DFLT4 0xC01680
18−#define PPICELAND_VOTINGRIGHTSCLIENTS_DFLT5 0xC00033
19−#define PPICELAND_VOTINGRIGHTSCLIENTS_DFLT6 0xC00033
20−#define PPICELAND_VOTINGRIGHTSCLIENTS_DFLT7 0x3FFFC000
21−
22−
23−#define PPICELAND_THERMALPROTECTCOUNTER_DFLT 0x200
24−
25−#define PPICELAND_STATICSCREENTHRESHOLDUNIT_DFLT 0
26−
27−#define PPICELAND_STATICSCREENTHRESHOLD_DFLT 0x00C8
28−
29−#define PPICELAND_GFXIDLECLOCKSTOPTHRESHOLD_DFLT 0x200
30−
31−#define PPICELAND_REFERENCEDIVIDER_DFLT 4
32−
33−#define PPICELAND_ULVVOLTAGECHANGEDELAY_DFLT 1687
34−
35−#define PPICELAND_CGULVPARAMETER_DFLT 0x00040035
36−#define PPICELAND_CGULVCONTROL_DFLT 0x00007450
37−#define PPICELAND_TARGETACTIVITY_DFLT 30
38−#define PPICELAND_MCLK_TARGETACTIVITY_DFLT 10
39−
40−#endif
41−
drivers/gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.c+0−5684
@@ -1,5684 +0,0 @@
1−/*
2− * Copyright 2016 Advanced Micro Devices, Inc.
3− *
4− * Permission is hereby granted, free of charge, to any person obtaining a
5− * copy of this software and associated documentation files (the "Software"),
6− * to deal in the Software without restriction, including without limitation
7− * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8− * and/or sell copies of the Software, and to permit persons to whom the
9− * Software is furnished to do so, subject to the following conditions:
10− *
11− * The above copyright notice and this permission notice shall be included in
12− * all copies or substantial portions of the Software.
13− *
14− * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15− * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16− * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17− * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18− * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19− * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20− * OTHER DEALINGS IN THE SOFTWARE.
21− *
22− * Author: Huang Rui <ray.huang@amd.com>
23− *
24− */
25−#include <linux/module.h>
26−#include <linux/slab.h>
27−#include <linux/fb.h>
28−#include "linux/delay.h"
29−#include "pp_acpi.h"
30−#include "hwmgr.h"
31−#include <atombios.h>
32−#include "iceland_hwmgr.h"
33−#include "pptable.h"
34−#include "processpptables.h"
35−#include "pp_debug.h"
36−#include "ppsmc.h"
37−#include "cgs_common.h"
38−#include "pppcielanes.h"
39−#include "iceland_dyn_defaults.h"
40−#include "smumgr.h"
41−#include "iceland_smumgr.h"
42−#include "iceland_clockpowergating.h"
43−#include "iceland_thermal.h"
44−#include "iceland_powertune.h"
45−
46−#include "gmc/gmc_8_1_d.h"
47−#include "gmc/gmc_8_1_sh_mask.h"
48−
49−#include "bif/bif_5_0_d.h"
50−#include "bif/bif_5_0_sh_mask.h"
51−
52−#include "smu/smu_7_1_1_d.h"
53−#include "smu/smu_7_1_1_sh_mask.h"
54−
55−#include "cgs_linux.h"
56−#include "eventmgr.h"
57−#include "amd_pcie_helpers.h"
58−
59−#define MC_CG_ARB_FREQ_F0 0x0a
60−#define MC_CG_ARB_FREQ_F1 0x0b
61−#define MC_CG_ARB_FREQ_F2 0x0c
62−#define MC_CG_ARB_FREQ_F3 0x0d
63−
64−#define MC_CG_SEQ_DRAMCONF_S0 0x05
65−#define MC_CG_SEQ_DRAMCONF_S1 0x06
66−#define MC_CG_SEQ_YCLK_SUSPEND 0x04
67−#define MC_CG_SEQ_YCLK_RESUME 0x0a
68−
69−#define PCIE_BUS_CLK 10000
70−#define TCLK (PCIE_BUS_CLK / 10)
71−
72−#define SMC_RAM_END 0x40000
73−#define SMC_CG_IND_START 0xc0030000
74−#define SMC_CG_IND_END 0xc0040000 /* First byte after SMC_CG_IND*/
75−
76−#define VOLTAGE_SCALE 4
77−#define VOLTAGE_VID_OFFSET_SCALE1 625
78−#define VOLTAGE_VID_OFFSET_SCALE2 100
79−
80−const uint32_t iceland_magic = (uint32_t)(PHM_VIslands_Magic);
81−
82−#define MC_SEQ_MISC0_GDDR5_SHIFT 28
83−#define MC_SEQ_MISC0_GDDR5_MASK 0xf0000000
84−#define MC_SEQ_MISC0_GDDR5_VALUE 5
85−
86−/** Values for the CG_THERMAL_CTRL::DPM_EVENT_SRC field. */
87−enum DPM_EVENT_SRC {
88− DPM_EVENT_SRC_ANALOG = 0, /* Internal analog trip point */
89− DPM_EVENT_SRC_EXTERNAL = 1, /* External (GPIO 17) signal */
90− DPM_EVENT_SRC_DIGITAL = 2, /* Internal digital trip point (DIG_THERM_DPM) */
91− DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3, /* Internal analog or external */
92− DPM_EVENT_SRC_DIGITAL_OR_EXTERNAL = 4 /* Internal digital or external */
93−};
94−
95−static int iceland_read_clock_registers(struct pp_hwmgr *hwmgr)
96−{
97− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
98−
99− data->clock_registers.vCG_SPLL_FUNC_CNTL =
100− cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL);
101− data->clock_registers.vCG_SPLL_FUNC_CNTL_2 =
102− cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL_2);
103− data->clock_registers.vCG_SPLL_FUNC_CNTL_3 =
104− cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL_3);
105− data->clock_registers.vCG_SPLL_FUNC_CNTL_4 =
106− cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL_4);
107− data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM =
108− cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_SPREAD_SPECTRUM);
109− data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM_2 =
110− cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_SPREAD_SPECTRUM_2);
111− data->clock_registers.vDLL_CNTL =
112− cgs_read_register(hwmgr->device, mmDLL_CNTL);
113− data->clock_registers.vMCLK_PWRMGT_CNTL =
114− cgs_read_register(hwmgr->device, mmMCLK_PWRMGT_CNTL);
115− data->clock_registers.vMPLL_AD_FUNC_CNTL =
116− cgs_read_register(hwmgr->device, mmMPLL_AD_FUNC_CNTL);
117− data->clock_registers.vMPLL_DQ_FUNC_CNTL =
118− cgs_read_register(hwmgr->device, mmMPLL_DQ_FUNC_CNTL);
119− data->clock_registers.vMPLL_FUNC_CNTL =
120− cgs_read_register(hwmgr->device, mmMPLL_FUNC_CNTL);
121− data->clock_registers.vMPLL_FUNC_CNTL_1 =
122− cgs_read_register(hwmgr->device, mmMPLL_FUNC_CNTL_1);
123− data->clock_registers.vMPLL_FUNC_CNTL_2 =
124− cgs_read_register(hwmgr->device, mmMPLL_FUNC_CNTL_2);
125− data->clock_registers.vMPLL_SS1 =
126− cgs_read_register(hwmgr->device, mmMPLL_SS1);
127− data->clock_registers.vMPLL_SS2 =
128− cgs_read_register(hwmgr->device, mmMPLL_SS2);
129−
130− return 0;
131−}
132−
133−/**
134− * Find out if memory is GDDR5.
135− *
136− * @param hwmgr the address of the powerplay hardware manager.
137− * @return always 0
138− */
139−int iceland_get_memory_type(struct pp_hwmgr *hwmgr)
140−{
141− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
142− uint32_t temp;
143−
144− temp = cgs_read_register(hwmgr->device, mmMC_SEQ_MISC0);
145−
146− data->is_memory_GDDR5 = (MC_SEQ_MISC0_GDDR5_VALUE ==
147− ((temp & MC_SEQ_MISC0_GDDR5_MASK) >>
148− MC_SEQ_MISC0_GDDR5_SHIFT));
149−
150− return 0;
151−}
152−
153−int iceland_update_uvd_dpm(struct pp_hwmgr *hwmgr, bool bgate)
154−{
155− /* iceland does not have MM hardware blocks */
156− return 0;
157−}
158−
159−/**
160− * Enables Dynamic Power Management by SMC
161− *
162− * @param hwmgr the address of the powerplay hardware manager.
163− * @return always 0
164− */
165−int iceland_enable_acpi_power_management(struct pp_hwmgr *hwmgr)
166−{
167− PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT, STATIC_PM_EN, 1);
168−
169− return 0;
170−}
171−
172−/**
173− * Find the MC microcode version and store it in the HwMgr struct
174− *
175− * @param hwmgr the address of the powerplay hardware manager.
176− * @return always 0
177− */
178−int iceland_get_mc_microcode_version(struct pp_hwmgr *hwmgr)
179−{
180− cgs_write_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_INDEX, 0x9F);
181−
182− hwmgr->microcode_version_info.MC = cgs_read_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_DATA);
183−
184− return 0;
185−}
186−
187−static int iceland_init_sclk_threshold(struct pp_hwmgr *hwmgr)
188−{
189− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
190−
191− data->low_sclk_interrupt_threshold = 0;
192−
193− return 0;
194−}
195−
196−
197−static int iceland_setup_asic_task(struct pp_hwmgr *hwmgr)
198−{
199− int tmp_result, result = 0;
200−
201− tmp_result = iceland_read_clock_registers(hwmgr);
202− PP_ASSERT_WITH_CODE((0 == tmp_result),
203− "Failed to read clock registers!", result = tmp_result);
204−
205− tmp_result = iceland_get_memory_type(hwmgr);
206− PP_ASSERT_WITH_CODE((0 == tmp_result),
207− "Failed to get memory type!", result = tmp_result);
208−
209− tmp_result = iceland_enable_acpi_power_management(hwmgr);
210− PP_ASSERT_WITH_CODE((0 == tmp_result),
211− "Failed to enable ACPI power management!", result = tmp_result);
212−
213− tmp_result = iceland_get_mc_microcode_version(hwmgr);
214− PP_ASSERT_WITH_CODE((0 == tmp_result),
215− "Failed to get MC microcode version!", result = tmp_result);
216−
217− tmp_result = iceland_init_sclk_threshold(hwmgr);
218− PP_ASSERT_WITH_CODE((0 == tmp_result),
219− "Failed to init sclk threshold!", result = tmp_result);
220−
221− return result;
222−}
223−
224−static bool cf_iceland_voltage_control(struct pp_hwmgr *hwmgr)
225−{
226− struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
227−
228− return ICELAND_VOLTAGE_CONTROL_NONE != data->voltage_control;
229−}
230−
231−/*
232− * -------------- Voltage Tables ----------------------
233− * If the voltage table would be bigger than what will fit into the
234− * state table on the SMC keep only the higher entries.
235− */
236−
237−static void iceland_trim_voltage_table_to_fit_state_table(
238− struct pp_hwmgr *hwmgr,
239− uint32_t max_voltage_steps,
240− pp_atomctrl_voltage_table *voltage_table)
241−{
242− unsigned int i, diff;
243−
244− if (voltage_table->count <= max_voltage_steps) {
245− return;
246− }
247−
248− diff = voltage_table->count - max_voltage_steps;
249−
250− for (i = 0; i < max_voltage_steps; i++) {
251− voltage_table->entries[i] = voltage_table->entries[i + diff];
252− }
253−
254− voltage_table->count = max_voltage_steps;
255−
256− return;
257−}
258−
259−/**
260− * Enable voltage control
261− *
262− * @param hwmgr the address of the powerplay hardware manager.
263− * @return always 0
264− */
265−int iceland_enable_voltage_control(struct pp_hwmgr *hwmgr)
266−{
267− /* enable voltage control */
268− PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT, VOLT_PWRMGT_EN, 1);
269−
270− return 0;
271−}
272−
273−static int iceland_get_svi2_voltage_table(struct pp_hwmgr *hwmgr,
274− struct phm_clock_voltage_dependency_table *voltage_dependency_table,
275− pp_atomctrl_voltage_table *voltage_table)
276−{
277− uint32_t i;
278−
279− PP_ASSERT_WITH_CODE((NULL != voltage_table),
280− "Voltage Dependency Table empty.", return -EINVAL;);
281−
282− voltage_table->mask_low = 0;
283− voltage_table->phase_delay = 0;
284− voltage_table->count = voltage_dependency_table->count;
285−
286− for (i = 0; i < voltage_dependency_table->count; i++) {
287− voltage_table->entries[i].value =
288− voltage_dependency_table->entries[i].v;
289− voltage_table->entries[i].smio_low = 0;
290− }
291−
292− return 0;
293−}
294−
295−/**
296− * Create Voltage Tables.
297− *
298− * @param hwmgr the address of the powerplay hardware manager.
299− * @return always 0
300− */
301−int iceland_construct_voltage_tables(struct pp_hwmgr *hwmgr)
302−{
303− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
304− int result;
305−
306− /* GPIO voltage */
307− if (ICELAND_VOLTAGE_CONTROL_BY_GPIO == data->voltage_control) {
308− result = atomctrl_get_voltage_table_v3(hwmgr,
309− VOLTAGE_TYPE_VDDC, VOLTAGE_OBJ_GPIO_LUT,
310− &data->vddc_voltage_table);
311− PP_ASSERT_WITH_CODE((0 == result),
312− "Failed to retrieve VDDC table.", return result;);
313− } else if (ICELAND_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) {
314− /* SVI2 VDDC voltage */
315− result = iceland_get_svi2_voltage_table(hwmgr,
316− hwmgr->dyn_state.vddc_dependency_on_mclk,
317− &data->vddc_voltage_table);
318− PP_ASSERT_WITH_CODE((0 == result),
319− "Failed to retrieve SVI2 VDDC table from dependancy table.", return result;);
320− }
321−
322− PP_ASSERT_WITH_CODE(
323− (data->vddc_voltage_table.count <= (SMU71_MAX_LEVELS_VDDC)),
324− "Too many voltage values for VDDC. Trimming to fit state table.",
325− iceland_trim_voltage_table_to_fit_state_table(hwmgr,
326− SMU71_MAX_LEVELS_VDDC, &(data->vddc_voltage_table));
327− );
328−
329− /* GPIO */
330− if (ICELAND_VOLTAGE_CONTROL_BY_GPIO == data->vdd_ci_control) {
331− result = atomctrl_get_voltage_table_v3(hwmgr,
332− VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT, &(data->vddci_voltage_table));
333− PP_ASSERT_WITH_CODE((0 == result),
334− "Failed to retrieve VDDCI table.", return result;);
335− }
336−
337− /* SVI2 VDDCI voltage */
338− if (ICELAND_VOLTAGE_CONTROL_BY_SVID2 == data->vdd_ci_control) {
339− result = iceland_get_svi2_voltage_table(hwmgr,
340− hwmgr->dyn_state.vddci_dependency_on_mclk,
341− &data->vddci_voltage_table);
342− PP_ASSERT_WITH_CODE((0 == result),
343− "Failed to retrieve SVI2 VDDCI table from dependancy table.", return result;);
344− }
345−
346− PP_ASSERT_WITH_CODE(
347− (data->vddci_voltage_table.count <= (SMU71_MAX_LEVELS_VDDCI)),
348− "Too many voltage values for VDDCI. Trimming to fit state table.",
349− iceland_trim_voltage_table_to_fit_state_table(hwmgr,
350− SMU71_MAX_LEVELS_VDDCI, &(data->vddci_voltage_table));
351− );
352−
353−
354− /* GPIO */
355− if (ICELAND_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) {
356− result = atomctrl_get_voltage_table_v3(hwmgr,
357− VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_GPIO_LUT, &(data->mvdd_voltage_table));
358− PP_ASSERT_WITH_CODE((0 == result),
359− "Failed to retrieve table.", return result;);
360− }
361−
362− /* SVI2 voltage control */
363− if (ICELAND_VOLTAGE_CONTROL_BY_SVID2 == data->mvdd_control) {
364− result = iceland_get_svi2_voltage_table(hwmgr,
365− hwmgr->dyn_state.mvdd_dependency_on_mclk,
366− &data->mvdd_voltage_table);
367− PP_ASSERT_WITH_CODE((0 == result),
368− "Failed to retrieve SVI2 MVDD table from dependancy table.", return result;);
369− }
370−
371− PP_ASSERT_WITH_CODE(
372− (data->mvdd_voltage_table.count <= (SMU71_MAX_LEVELS_MVDD)),
373− "Too many voltage values for MVDD. Trimming to fit state table.",
374− iceland_trim_voltage_table_to_fit_state_table(hwmgr,
375− SMU71_MAX_LEVELS_MVDD, &(data->mvdd_voltage_table));
376− );
377−
378− return 0;
379−}
380−
381−/*---------------------------MC----------------------------*/
382−
383−uint8_t iceland_get_memory_module_index(struct pp_hwmgr *hwmgr)
384−{
385− return (uint8_t) (0xFF & (cgs_read_register(hwmgr->device, mmBIOS_SCRATCH_4) >> 16));
386−}
387−
388−bool iceland_check_s0_mc_reg_index(uint16_t inReg, uint16_t *outReg)
389−{
390− bool result = true;
391−
392− switch (inReg) {
393− case mmMC_SEQ_RAS_TIMING:
394− *outReg = mmMC_SEQ_RAS_TIMING_LP;
395− break;
396−
397− case mmMC_SEQ_DLL_STBY:
398− *outReg = mmMC_SEQ_DLL_STBY_LP;
399− break;
400−
401− case mmMC_SEQ_G5PDX_CMD0:
402− *outReg = mmMC_SEQ_G5PDX_CMD0_LP;
403− break;
404−
405− case mmMC_SEQ_G5PDX_CMD1:
406− *outReg = mmMC_SEQ_G5PDX_CMD1_LP;
407− break;
408−
409− case mmMC_SEQ_G5PDX_CTRL:
410− *outReg = mmMC_SEQ_G5PDX_CTRL_LP;
411− break;
412−
413− case mmMC_SEQ_CAS_TIMING:
414− *outReg = mmMC_SEQ_CAS_TIMING_LP;
415− break;
416−
417− case mmMC_SEQ_MISC_TIMING:
418− *outReg = mmMC_SEQ_MISC_TIMING_LP;
419− break;
420−
421− case mmMC_SEQ_MISC_TIMING2:
422− *outReg = mmMC_SEQ_MISC_TIMING2_LP;
423− break;
424−
425− case mmMC_SEQ_PMG_DVS_CMD:
426− *outReg = mmMC_SEQ_PMG_DVS_CMD_LP;
427− break;
428−
429− case mmMC_SEQ_PMG_DVS_CTL:
430− *outReg = mmMC_SEQ_PMG_DVS_CTL_LP;
431− break;
432−
433− case mmMC_SEQ_RD_CTL_D0:
434− *outReg = mmMC_SEQ_RD_CTL_D0_LP;
435− break;
436−
437− case mmMC_SEQ_RD_CTL_D1:
438− *outReg = mmMC_SEQ_RD_CTL_D1_LP;
439− break;
440−
441− case mmMC_SEQ_WR_CTL_D0:
442− *outReg = mmMC_SEQ_WR_CTL_D0_LP;
443− break;
444−
445− case mmMC_SEQ_WR_CTL_D1:
446− *outReg = mmMC_SEQ_WR_CTL_D1_LP;
447− break;
448−
449− case mmMC_PMG_CMD_EMRS:
450− *outReg = mmMC_SEQ_PMG_CMD_EMRS_LP;
451− break;
452−
453− case mmMC_PMG_CMD_MRS:
454− *outReg = mmMC_SEQ_PMG_CMD_MRS_LP;
455− break;
456−
457− case mmMC_PMG_CMD_MRS1:
458− *outReg = mmMC_SEQ_PMG_CMD_MRS1_LP;
459− break;
460−
461− case mmMC_SEQ_PMG_TIMING:
462− *outReg = mmMC_SEQ_PMG_TIMING_LP;
463− break;
464−
465− case mmMC_PMG_CMD_MRS2:
466− *outReg = mmMC_SEQ_PMG_CMD_MRS2_LP;
467− break;
468−
469− case mmMC_SEQ_WR_CTL_2:
470− *outReg = mmMC_SEQ_WR_CTL_2_LP;
471− break;
472−
473− default:
474− result = false;
475− break;
476− }
477−
478− return result;
479−}
480−
481−int iceland_set_s0_mc_reg_index(phw_iceland_mc_reg_table *table)
482−{
483− uint32_t i;
484− uint16_t address;
485−
486− for (i = 0; i < table->last; i++) {
487− table->mc_reg_address[i].s0 =
488− iceland_check_s0_mc_reg_index(table->mc_reg_address[i].s1, &address)
489− ? address : table->mc_reg_address[i].s1;
490− }
491− return 0;
492−}
493−
494−int iceland_copy_vbios_smc_reg_table(const pp_atomctrl_mc_reg_table *table, phw_iceland_mc_reg_table *ni_table)
495−{
496− uint8_t i, j;
497−
498− PP_ASSERT_WITH_CODE((table->last <= SMU71_DISCRETE_MC_REGISTER_ARRAY_SIZE),
499− "Invalid VramInfo table.", return -1);
500− PP_ASSERT_WITH_CODE((table->num_entries <= MAX_AC_TIMING_ENTRIES),
501− "Invalid VramInfo table.", return -1);
502−
503− for (i = 0; i < table->last; i++) {
504− ni_table->mc_reg_address[i].s1 = table->mc_reg_address[i].s1;
505− }
506− ni_table->last = table->last;
507−
508− for (i = 0; i < table->num_entries; i++) {
509− ni_table->mc_reg_table_entry[i].mclk_max =
510− table->mc_reg_table_entry[i].mclk_max;
511− for (j = 0; j < table->last; j++) {
512− ni_table->mc_reg_table_entry[i].mc_data[j] =
513− table->mc_reg_table_entry[i].mc_data[j];
514− }
515− }
516−
517− ni_table->num_entries = table->num_entries;
518−
519− return 0;
520−}
521−
522−/**
523− * VBIOS omits some information to reduce size, we need to recover them here.
524− * 1. when we see mmMC_SEQ_MISC1, bit[31:16] EMRS1, need to be write to mmMC_PMG_CMD_EMRS /_LP[15:0].
525− * Bit[15:0] MRS, need to be update mmMC_PMG_CMD_MRS/_LP[15:0]
526− * 2. when we see mmMC_SEQ_RESERVE_M, bit[15:0] EMRS2, need to be write to mmMC_PMG_CMD_MRS1/_LP[15:0].
527− * 3. need to set these data for each clock range
528− *
529− * @param hwmgr the address of the powerplay hardware manager.
530− * @param table the address of MCRegTable
531− * @return always 0
532− */
533−static int iceland_set_mc_special_registers(struct pp_hwmgr *hwmgr, phw_iceland_mc_reg_table *table)
534−{
535− uint8_t i, j, k;
536− uint32_t temp_reg;
537− const iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
538−
539− for (i = 0, j = table->last; i < table->last; i++) {
540− PP_ASSERT_WITH_CODE((j < SMU71_DISCRETE_MC_REGISTER_ARRAY_SIZE),
541− "Invalid VramInfo table.", return -1);
542− switch (table->mc_reg_address[i].s1) {
543− /*
544− * mmMC_SEQ_MISC1, bit[31:16] EMRS1, need to be write
545− * to mmMC_PMG_CMD_EMRS/_LP[15:0]. Bit[15:0] MRS, need
546− * to be update mmMC_PMG_CMD_MRS/_LP[15:0]
547− */
548− case mmMC_SEQ_MISC1:
549− temp_reg = cgs_read_register(hwmgr->device, mmMC_PMG_CMD_EMRS);
550− table->mc_reg_address[j].s1 = mmMC_PMG_CMD_EMRS;
551− table->mc_reg_address[j].s0 = mmMC_SEQ_PMG_CMD_EMRS_LP;
552− for (k = 0; k < table->num_entries; k++) {
553− table->mc_reg_table_entry[k].mc_data[j] =
554− ((temp_reg & 0xffff0000)) |
555− ((table->mc_reg_table_entry[k].mc_data[i] & 0xffff0000) >> 16);
556− }
557− j++;
558− PP_ASSERT_WITH_CODE((j < SMU71_DISCRETE_MC_REGISTER_ARRAY_SIZE),
559− "Invalid VramInfo table.", return -1);
560−
561− temp_reg = cgs_read_register(hwmgr->device, mmMC_PMG_CMD_MRS);
562− table->mc_reg_address[j].s1 = mmMC_PMG_CMD_MRS;
563− table->mc_reg_address[j].s0 = mmMC_SEQ_PMG_CMD_MRS_LP;
564− for (k = 0; k < table->num_entries; k++) {
565− table->mc_reg_table_entry[k].mc_data[j] =
566− (temp_reg & 0xffff0000) |
567− (table->mc_reg_table_entry[k].mc_data[i] & 0x0000ffff);
568−
569− if (!data->is_memory_GDDR5) {
570− table->mc_reg_table_entry[k].mc_data[j] |= 0x100;
571− }
572− }
573− j++;
574− PP_ASSERT_WITH_CODE((j <= SMU71_DISCRETE_MC_REGISTER_ARRAY_SIZE),
575− "Invalid VramInfo table.", return -1);
576−
577− if (!data->is_memory_GDDR5) {
578− table->mc_reg_address[j].s1 = mmMC_PMG_AUTO_CMD;
579− table->mc_reg_address[j].s0 = mmMC_PMG_AUTO_CMD;
580− for (k = 0; k < table->num_entries; k++) {
581− table->mc_reg_table_entry[k].mc_data[j] =
582− (table->mc_reg_table_entry[k].mc_data[i] & 0xffff0000) >> 16;
583− }
584− j++;
585− PP_ASSERT_WITH_CODE((j <= SMU71_DISCRETE_MC_REGISTER_ARRAY_SIZE),
586− "Invalid VramInfo table.", return -1);
587− }
588−
589− break;
590−
591− case mmMC_SEQ_RESERVE_M:
592− temp_reg = cgs_read_register(hwmgr->device, mmMC_PMG_CMD_MRS1);
593− table->mc_reg_address[j].s1 = mmMC_PMG_CMD_MRS1;
594− table->mc_reg_address[j].s0 = mmMC_SEQ_PMG_CMD_MRS1_LP;
595− for (k = 0; k < table->num_entries; k++) {
596− table->mc_reg_table_entry[k].mc_data[j] =
597− (temp_reg & 0xffff0000) |
598− (table->mc_reg_table_entry[k].mc_data[i] & 0x0000ffff);
599− }
600− j++;
601− PP_ASSERT_WITH_CODE((j <= SMU71_DISCRETE_MC_REGISTER_ARRAY_SIZE),
602− "Invalid VramInfo table.", return -1);
603− break;
604−
605− default:
606− break;
607− }
608−
609− }
610−
611− table->last = j;
612−
613− return 0;
614−}
615−
616−
617−static int iceland_set_valid_flag(phw_iceland_mc_reg_table *table)
618−{
619− uint8_t i, j;
620− for (i = 0; i < table->last; i++) {
621− for (j = 1; j < table->num_entries; j++) {
622− if (table->mc_reg_table_entry[j-1].mc_data[i] !=
623− table->mc_reg_table_entry[j].mc_data[i]) {
624− table->validflag |= (1<<i);
625− break;
626− }
627− }
628− }
629−
630− return 0;
631−}
632−
633−static int iceland_initialize_mc_reg_table(struct pp_hwmgr *hwmgr)
634−{
635− int result;
636− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
637− pp_atomctrl_mc_reg_table *table;
638− phw_iceland_mc_reg_table *ni_table = &data->iceland_mc_reg_table;
639− uint8_t module_index = iceland_get_memory_module_index(hwmgr);
640−
641− table = kzalloc(sizeof(pp_atomctrl_mc_reg_table), GFP_KERNEL);
642−
643− if (NULL == table)
644− return -ENOMEM;
645−
646− /* Program additional LP registers that are no longer programmed by VBIOS */
647− cgs_write_register(hwmgr->device, mmMC_SEQ_RAS_TIMING_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_RAS_TIMING));
648− cgs_write_register(hwmgr->device, mmMC_SEQ_CAS_TIMING_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_CAS_TIMING));
649− cgs_write_register(hwmgr->device, mmMC_SEQ_DLL_STBY_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_DLL_STBY));
650− cgs_write_register(hwmgr->device, mmMC_SEQ_G5PDX_CMD0_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_G5PDX_CMD0));
651− cgs_write_register(hwmgr->device, mmMC_SEQ_G5PDX_CMD1_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_G5PDX_CMD1));
652− cgs_write_register(hwmgr->device, mmMC_SEQ_G5PDX_CTRL_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_G5PDX_CTRL));
653− cgs_write_register(hwmgr->device, mmMC_SEQ_PMG_DVS_CMD_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_PMG_DVS_CMD));
654− cgs_write_register(hwmgr->device, mmMC_SEQ_PMG_DVS_CTL_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_PMG_DVS_CTL));
655− cgs_write_register(hwmgr->device, mmMC_SEQ_MISC_TIMING_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_MISC_TIMING));
656− cgs_write_register(hwmgr->device, mmMC_SEQ_MISC_TIMING2_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_MISC_TIMING2));
657− cgs_write_register(hwmgr->device, mmMC_SEQ_PMG_CMD_EMRS_LP, cgs_read_register(hwmgr->device, mmMC_PMG_CMD_EMRS));
658− cgs_write_register(hwmgr->device, mmMC_SEQ_PMG_CMD_MRS_LP, cgs_read_register(hwmgr->device, mmMC_PMG_CMD_MRS));
659− cgs_write_register(hwmgr->device, mmMC_SEQ_PMG_CMD_MRS1_LP, cgs_read_register(hwmgr->device, mmMC_PMG_CMD_MRS1));
660− cgs_write_register(hwmgr->device, mmMC_SEQ_WR_CTL_D0_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_WR_CTL_D0));
661− cgs_write_register(hwmgr->device, mmMC_SEQ_WR_CTL_D1_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_WR_CTL_D1));
662− cgs_write_register(hwmgr->device, mmMC_SEQ_RD_CTL_D0_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_RD_CTL_D0));
663− cgs_write_register(hwmgr->device, mmMC_SEQ_RD_CTL_D1_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_RD_CTL_D1));
664− cgs_write_register(hwmgr->device, mmMC_SEQ_PMG_TIMING_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_PMG_TIMING));
665− cgs_write_register(hwmgr->device, mmMC_SEQ_PMG_CMD_MRS2_LP, cgs_read_register(hwmgr->device, mmMC_PMG_CMD_MRS2));
666− cgs_write_register(hwmgr->device, mmMC_SEQ_WR_CTL_2_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_WR_CTL_2));
667−
668− memset(table, 0x00, sizeof(pp_atomctrl_mc_reg_table));
669−
670− result = atomctrl_initialize_mc_reg_table(hwmgr, module_index, table);
671−
672− if (0 == result)
673− result = iceland_copy_vbios_smc_reg_table(table, ni_table);
674−
675− if (0 == result) {
676− iceland_set_s0_mc_reg_index(ni_table);
677− result = iceland_set_mc_special_registers(hwmgr, ni_table);
678− }
679−
680− if (0 == result)
681− iceland_set_valid_flag(ni_table);
682−
683− kfree(table);
684− return result;
685−}
686−
687−/**
688− * Programs static screed detection parameters
689− *
690− * @param hwmgr the address of the powerplay hardware manager.
691− * @return always 0
692− */
693−int iceland_program_static_screen_threshold_parameters(struct pp_hwmgr *hwmgr)
694−{
695− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
696−
697− /* Set static screen threshold unit*/
698− PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device,
699− CGS_IND_REG__SMC, CG_STATIC_SCREEN_PARAMETER, STATIC_SCREEN_THRESHOLD_UNIT,
700− data->static_screen_threshold_unit);
701− /* Set static screen threshold*/
702− PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device,
703− CGS_IND_REG__SMC, CG_STATIC_SCREEN_PARAMETER, STATIC_SCREEN_THRESHOLD,
704− data->static_screen_threshold);
705−
706− return 0;
707−}
708−
709−/**
710− * Setup display gap for glitch free memory clock switching.
711− *
712− * @param hwmgr the address of the powerplay hardware manager.
713− * @return always 0
714− */
715−int iceland_enable_display_gap(struct pp_hwmgr *hwmgr)
716−{
717− uint32_t display_gap = cgs_read_ind_register(hwmgr->device,
718− CGS_IND_REG__SMC, ixCG_DISPLAY_GAP_CNTL);
719−
720− display_gap = PHM_SET_FIELD(display_gap,
721− CG_DISPLAY_GAP_CNTL, DISP_GAP, DISPLAY_GAP_IGNORE);
722−
723− display_gap = PHM_SET_FIELD(display_gap,
724− CG_DISPLAY_GAP_CNTL, DISP_GAP_MCHG, DISPLAY_GAP_VBLANK);
725−
726− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
727− ixCG_DISPLAY_GAP_CNTL, display_gap);
728−
729− return 0;
730−}
731−
732−/**
733− * Programs activity state transition voting clients
734− *
735− * @param hwmgr the address of the powerplay hardware manager.
736− * @return always 0
737− */
738−int iceland_program_voting_clients(struct pp_hwmgr *hwmgr)
739−{
740− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
741−
742− /* Clear reset for voting clients before enabling DPM */
743− PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
744− SCLK_PWRMGT_CNTL, RESET_SCLK_CNT, 0);
745− PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
746− SCLK_PWRMGT_CNTL, RESET_BUSY_CNT, 0);
747−
748− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
749− ixCG_FREQ_TRAN_VOTING_0, data->voting_rights_clients0);
750− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
751− ixCG_FREQ_TRAN_VOTING_1, data->voting_rights_clients1);
752− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
753− ixCG_FREQ_TRAN_VOTING_2, data->voting_rights_clients2);
754− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
755− ixCG_FREQ_TRAN_VOTING_3, data->voting_rights_clients3);
756− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
757− ixCG_FREQ_TRAN_VOTING_4, data->voting_rights_clients4);
758− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
759− ixCG_FREQ_TRAN_VOTING_5, data->voting_rights_clients5);
760− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
761− ixCG_FREQ_TRAN_VOTING_6, data->voting_rights_clients6);
762− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
763− ixCG_FREQ_TRAN_VOTING_7, data->voting_rights_clients7);
764−
765− return 0;
766−}
767−
768−static int iceland_upload_firmware(struct pp_hwmgr *hwmgr)
769−{
770− int ret = 0;
771−
772− if (!iceland_is_smc_ram_running(hwmgr->smumgr))
773− ret = iceland_smu_upload_firmware_image(hwmgr->smumgr);
774−
775− return ret;
776−}
777−
778−/**
779− * Get the location of various tables inside the FW image.
780− *
781− * @param hwmgr the address of the powerplay hardware manager.
782− * @return always 0
783− */
784−static int iceland_process_firmware_header(struct pp_hwmgr *hwmgr)
785−{
786− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
787−
788− uint32_t tmp;
789− int result;
790− bool error = 0;
791−
792− result = iceland_read_smc_sram_dword(hwmgr->smumgr,
793− SMU71_FIRMWARE_HEADER_LOCATION +
794− offsetof(SMU71_Firmware_Header, DpmTable),
795− &tmp, data->sram_end);
796−
797− if (0 == result) {
798− data->dpm_table_start = tmp;
799− }
800−
801− error |= (0 != result);
802−
803− result = iceland_read_smc_sram_dword(hwmgr->smumgr,
804− SMU71_FIRMWARE_HEADER_LOCATION +
805− offsetof(SMU71_Firmware_Header, SoftRegisters),
806− &tmp, data->sram_end);
807−
808− if (0 == result) {
809− data->soft_regs_start = tmp;
810− }
811−
812− error |= (0 != result);
813−
814−
815− result = iceland_read_smc_sram_dword(hwmgr->smumgr,
816− SMU71_FIRMWARE_HEADER_LOCATION +
817− offsetof(SMU71_Firmware_Header, mcRegisterTable),
818− &tmp, data->sram_end);
819−
820− if (0 == result) {
821− data->mc_reg_table_start = tmp;
822− }
823−
824− result = iceland_read_smc_sram_dword(hwmgr->smumgr,
825− SMU71_FIRMWARE_HEADER_LOCATION +
826− offsetof(SMU71_Firmware_Header, FanTable),
827− &tmp, data->sram_end);
828−
829− if (0 == result) {
830− data->fan_table_start = tmp;
831− }
832−
833− error |= (0 != result);
834−
835− result = iceland_read_smc_sram_dword(hwmgr->smumgr,
836− SMU71_FIRMWARE_HEADER_LOCATION +
837− offsetof(SMU71_Firmware_Header, mcArbDramTimingTable),
838− &tmp, data->sram_end);
839−
840− if (0 == result) {
841− data->arb_table_start = tmp;
842− }
843−
844− error |= (0 != result);
845−
846−
847− result = iceland_read_smc_sram_dword(hwmgr->smumgr,
848− SMU71_FIRMWARE_HEADER_LOCATION +
849− offsetof(SMU71_Firmware_Header, Version),
850− &tmp, data->sram_end);
851−
852− if (0 == result) {
853− hwmgr->microcode_version_info.SMC = tmp;
854− }
855−
856− error |= (0 != result);
857−
858− result = iceland_read_smc_sram_dword(hwmgr->smumgr,
859− SMU71_FIRMWARE_HEADER_LOCATION +
860− offsetof(SMU71_Firmware_Header, UlvSettings),
861− &tmp, data->sram_end);
862−
863− if (0 == result) {
864− data->ulv_settings_start = tmp;
865− }
866−
867− error |= (0 != result);
868−
869− return error ? 1 : 0;
870−}
871−
872−/*
873−* Copy one arb setting to another and then switch the active set.
874−* arbFreqSrc and arbFreqDest is one of the MC_CG_ARB_FREQ_Fx constants.
875−*/
876−int iceland_copy_and_switch_arb_sets(struct pp_hwmgr *hwmgr,
877− uint32_t arbFreqSrc, uint32_t arbFreqDest)
878−{
879− uint32_t mc_arb_dram_timing;
880− uint32_t mc_arb_dram_timing2;
881− uint32_t burst_time;
882− uint32_t mc_cg_config;
883−
884− switch (arbFreqSrc) {
885− case MC_CG_ARB_FREQ_F0:
886− mc_arb_dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING);
887− mc_arb_dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2);
888− burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0);
889− break;
890−
891− case MC_CG_ARB_FREQ_F1:
892− mc_arb_dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING_1);
893− mc_arb_dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2_1);
894− burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE1);
895− break;
896−
897− default:
898− return -1;
899− }
900−
901− switch (arbFreqDest) {
902− case MC_CG_ARB_FREQ_F0:
903− cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING, mc_arb_dram_timing);
904− cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2, mc_arb_dram_timing2);
905− PHM_WRITE_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0, burst_time);
906− break;
907−
908− case MC_CG_ARB_FREQ_F1:
909− cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING_1, mc_arb_dram_timing);
910− cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2_1, mc_arb_dram_timing2);
911− PHM_WRITE_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE1, burst_time);
912− break;
913−
914− default:
915− return -1;
916− }
917−
918− mc_cg_config = cgs_read_register(hwmgr->device, mmMC_CG_CONFIG);
919− mc_cg_config |= 0x0000000F;
920− cgs_write_register(hwmgr->device, mmMC_CG_CONFIG, mc_cg_config);
921− PHM_WRITE_FIELD(hwmgr->device, MC_ARB_CG, CG_ARB_REQ, arbFreqDest);
922−
923− return 0;
924−}
925−
926−/**
927− * Initial switch from ARB F0->F1
928− *
929− * @param hwmgr the address of the powerplay hardware manager.
930− * @return always 0
931− * This function is to be called from the SetPowerState table.
932− */
933−int iceland_initial_switch_from_arb_f0_to_f1(struct pp_hwmgr *hwmgr)
934−{
935− return iceland_copy_and_switch_arb_sets(hwmgr, MC_CG_ARB_FREQ_F0, MC_CG_ARB_FREQ_F1);
936−}
937−
938−/* ---------------------------------------- ULV related functions ----------------------------------------------------*/
939−
940−
941−static int iceland_reset_single_dpm_table(
942− struct pp_hwmgr *hwmgr,
943− struct iceland_single_dpm_table *dpm_table,
944− uint32_t count)
945−{
946− uint32_t i;
947− if (!(count <= MAX_REGULAR_DPM_NUMBER))
948− printk(KERN_ERR "[ powerplay ] Fatal error, can not set up single DPM \
949− table entries to exceed max number! \n");
950−
951− dpm_table->count = count;
952− for (i = 0; i < MAX_REGULAR_DPM_NUMBER; i++) {
953− dpm_table->dpm_levels[i].enabled = 0;
954− }
955−
956− return 0;
957−}
958−
959−static void iceland_setup_pcie_table_entry(
960− struct iceland_single_dpm_table *dpm_table,
961− uint32_t index, uint32_t pcie_gen,
962− uint32_t pcie_lanes)
963−{
964− dpm_table->dpm_levels[index].value = pcie_gen;
965− dpm_table->dpm_levels[index].param1 = pcie_lanes;
966− dpm_table->dpm_levels[index].enabled = 1;
967−}
968−
969−/*
970− * Set up the PCIe DPM table as follows:
971− *
972− * A = Performance State, Max, Gen Speed
973− * C = Performance State, Min, Gen Speed
974− * 1 = Performance State, Max, Lane #
975− * 3 = Performance State, Min, Lane #
976− *
977− * B = Power Saving State, Max, Gen Speed
978− * D = Power Saving State, Min, Gen Speed
979− * 2 = Power Saving State, Max, Lane #
980− * 4 = Power Saving State, Min, Lane #
981− *
982− *
983− * DPM Index Gen Speed Lane #
984− * 5 A 1
985− * 4 B 2
986− * 3 C 1
987− * 2 D 2
988− * 1 C 3
989− * 0 D 4
990− *
991− */
992−static int iceland_setup_default_pcie_tables(struct pp_hwmgr *hwmgr)
993−{
994− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
995−
996− PP_ASSERT_WITH_CODE((data->use_pcie_performance_levels ||
997− data->use_pcie_power_saving_levels),
998− "No pcie performance levels!", return -EINVAL);
999−
1000− if (data->use_pcie_performance_levels && !data->use_pcie_power_saving_levels) {
1001− data->pcie_gen_power_saving = data->pcie_gen_performance;
1002− data->pcie_lane_power_saving = data->pcie_lane_performance;
1003− } else if (!data->use_pcie_performance_levels && data->use_pcie_power_saving_levels) {
1004− data->pcie_gen_performance = data->pcie_gen_power_saving;
1005− data->pcie_lane_performance = data->pcie_lane_power_saving;
1006− }
1007−
1008− iceland_reset_single_dpm_table(hwmgr, &data->dpm_table.pcie_speed_table, SMU71_MAX_LEVELS_LINK);
1009−
1010− /* Hardcode Pcie Table */
1011− iceland_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 0,
1012− get_pcie_gen_support(data->pcie_gen_cap, PP_Min_PCIEGen),
1013− get_pcie_lane_support(data->pcie_lane_cap, PP_Max_PCIELane));
1014− iceland_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 1,
1015− get_pcie_gen_support(data->pcie_gen_cap, PP_Min_PCIEGen),
1016− get_pcie_lane_support(data->pcie_lane_cap, PP_Max_PCIELane));
1017− iceland_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 2,
1018− get_pcie_gen_support(data->pcie_gen_cap, PP_Max_PCIEGen),
1019− get_pcie_lane_support(data->pcie_lane_cap, PP_Max_PCIELane));
1020− iceland_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 3,
1021− get_pcie_gen_support(data->pcie_gen_cap, PP_Max_PCIEGen),
1022− get_pcie_lane_support(data->pcie_lane_cap, PP_Max_PCIELane));
1023− iceland_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 4,
1024− get_pcie_gen_support(data->pcie_gen_cap, PP_Max_PCIEGen),
1025− get_pcie_lane_support(data->pcie_lane_cap, PP_Max_PCIELane));
1026− iceland_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 5,
1027− get_pcie_gen_support(data->pcie_gen_cap, PP_Max_PCIEGen),
1028− get_pcie_lane_support(data->pcie_lane_cap, PP_Max_PCIELane));
1029− data->dpm_table.pcie_speed_table.count = 6;
1030−
1031− return 0;
1032−
1033−}
1034−
1035−
1036−/*
1037− * This function is to initalize all DPM state tables for SMU7 based on the dependency table.
1038− * Dynamic state patching function will then trim these state tables to the allowed range based
1039− * on the power policy or external client requests, such as UVD request, etc.
1040− */
1041−static int iceland_setup_default_dpm_tables(struct pp_hwmgr *hwmgr)
1042−{
1043− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
1044− uint32_t i;
1045−
1046− struct phm_clock_voltage_dependency_table *allowed_vdd_sclk_table =
1047− hwmgr->dyn_state.vddc_dependency_on_sclk;
1048− struct phm_clock_voltage_dependency_table *allowed_vdd_mclk_table =
1049− hwmgr->dyn_state.vddc_dependency_on_mclk;
1050− struct phm_cac_leakage_table *std_voltage_table =
1051− hwmgr->dyn_state.cac_leakage_table;
1052−
1053− PP_ASSERT_WITH_CODE(allowed_vdd_sclk_table != NULL,
1054− "SCLK dependency table is missing. This table is mandatory", return -1);
1055− PP_ASSERT_WITH_CODE(allowed_vdd_sclk_table->count >= 1,
1056− "SCLK dependency table has to have is missing. This table is mandatory", return -1);
1057−
1058− PP_ASSERT_WITH_CODE(allowed_vdd_mclk_table != NULL,
1059− "MCLK dependency table is missing. This table is mandatory", return -1);
1060− PP_ASSERT_WITH_CODE(allowed_vdd_mclk_table->count >= 1,
1061− "VMCLK dependency table has to have is missing. This table is mandatory", return -1);
1062−
1063− /* clear the state table to reset everything to default */
1064− memset(&(data->dpm_table), 0x00, sizeof(data->dpm_table));
1065− iceland_reset_single_dpm_table(hwmgr, &data->dpm_table.sclk_table, SMU71_MAX_LEVELS_GRAPHICS);
1066− iceland_reset_single_dpm_table(hwmgr, &data->dpm_table.mclk_table, SMU71_MAX_LEVELS_MEMORY);
1067− iceland_reset_single_dpm_table(hwmgr, &data->dpm_table.vddc_table, SMU71_MAX_LEVELS_VDDC);
1068− iceland_reset_single_dpm_table(hwmgr, &data->dpm_table.vdd_ci_table, SMU71_MAX_LEVELS_VDDCI);
1069− iceland_reset_single_dpm_table(hwmgr, &data->dpm_table.mvdd_table, SMU71_MAX_LEVELS_MVDD);
1070−
1071− PP_ASSERT_WITH_CODE(allowed_vdd_sclk_table != NULL,
1072− "SCLK dependency table is missing. This table is mandatory", return -1);
1073− /* Initialize Sclk DPM table based on allow Sclk values*/
1074− data->dpm_table.sclk_table.count = 0;
1075−
1076− for (i = 0; i < allowed_vdd_sclk_table->count; i++) {
1077− if (i == 0 || data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count-1].value !=
1078− allowed_vdd_sclk_table->entries[i].clk) {
1079− data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].value =
1080− allowed_vdd_sclk_table->entries[i].clk;
1081− data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].enabled = 1; /*(i==0) ? 1 : 0; to do */
1082− data->dpm_table.sclk_table.count++;
1083− }
1084− }
1085−
1086− PP_ASSERT_WITH_CODE(allowed_vdd_mclk_table != NULL,
1087− "MCLK dependency table is missing. This table is mandatory", return -1);
1088− /* Initialize Mclk DPM table based on allow Mclk values */
1089− data->dpm_table.mclk_table.count = 0;
1090− for (i = 0; i < allowed_vdd_mclk_table->count; i++) {
1091− if (i == 0 || data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count-1].value !=
1092− allowed_vdd_mclk_table->entries[i].clk) {
1093− data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].value =
1094− allowed_vdd_mclk_table->entries[i].clk;
1095− data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].enabled = 1; /*(i==0) ? 1 : 0; */
1096− data->dpm_table.mclk_table.count++;
1097− }
1098− }
1099−
1100− /* Initialize Vddc DPM table based on allow Vddc values. And populate corresponding std values. */
1101− for (i = 0; i < allowed_vdd_sclk_table->count; i++) {
1102− data->dpm_table.vddc_table.dpm_levels[i].value = allowed_vdd_mclk_table->entries[i].v;
1103− data->dpm_table.vddc_table.dpm_levels[i].param1 = std_voltage_table->entries[i].Leakage;
1104− /* param1 is for corresponding std voltage */
1105− data->dpm_table.vddc_table.dpm_levels[i].enabled = 1;
1106− }
1107−
1108− data->dpm_table.vddc_table.count = allowed_vdd_sclk_table->count;
1109− allowed_vdd_mclk_table = hwmgr->dyn_state.vddci_dependency_on_mclk;
1110−
1111− if (NULL != allowed_vdd_mclk_table) {
1112− /* Initialize Vddci DPM table based on allow Mclk values */
1113− for (i = 0; i < allowed_vdd_mclk_table->count; i++) {
1114− data->dpm_table.vdd_ci_table.dpm_levels[i].value = allowed_vdd_mclk_table->entries[i].v;
1115− data->dpm_table.vdd_ci_table.dpm_levels[i].enabled = 1;
1116− }
1117− data->dpm_table.vdd_ci_table.count = allowed_vdd_mclk_table->count;
1118− }
1119−
1120− allowed_vdd_mclk_table = hwmgr->dyn_state.mvdd_dependency_on_mclk;
1121−
1122− if (NULL != allowed_vdd_mclk_table) {
1123− /*
1124− * Initialize MVDD DPM table based on allow Mclk
1125− * values
1126− */
1127− for (i = 0; i < allowed_vdd_mclk_table->count; i++) {
1128− data->dpm_table.mvdd_table.dpm_levels[i].value = allowed_vdd_mclk_table->entries[i].v;
1129− data->dpm_table.mvdd_table.dpm_levels[i].enabled = 1;
1130− }
1131− data->dpm_table.mvdd_table.count = allowed_vdd_mclk_table->count;
1132− }
1133−
1134− /* setup PCIE gen speed levels*/
1135− iceland_setup_default_pcie_tables(hwmgr);
1136−
1137− /* save a copy of the default DPM table*/
1138− memcpy(&(data->golden_dpm_table), &(data->dpm_table), sizeof(struct iceland_dpm_table));
1139−
1140− return 0;
1141−}
1142−
1143−/**
1144− * @brief PhwIceland_GetVoltageOrder
1145− * Returns index of requested voltage record in lookup(table)
1146− * @param hwmgr - pointer to hardware manager
1147− * @param lookutab - lookup list to search in
1148− * @param voltage - voltage to look for
1149− * @return 0 on success
1150− */
1151−uint8_t iceland_get_voltage_index(phm_ppt_v1_voltage_lookup_table *look_up_table,
1152− uint16_t voltage)
1153−{
1154− uint8_t count = (uint8_t) (look_up_table->count);
1155− uint8_t i;
1156−
1157− PP_ASSERT_WITH_CODE((NULL != look_up_table), "Lookup Table empty.", return 0;);
1158− PP_ASSERT_WITH_CODE((0 != count), "Lookup Table empty.", return 0;);
1159−
1160− for (i = 0; i < count; i++) {
1161− /* find first voltage equal or bigger than requested */
1162− if (look_up_table->entries[i].us_vdd >= voltage)
1163− return i;
1164− }
1165−
1166− /* voltage is bigger than max voltage in the table */
1167− return i-1;
1168−}
1169−
1170−
1171−static int iceland_get_std_voltage_value_sidd(struct pp_hwmgr *hwmgr,
1172− pp_atomctrl_voltage_table_entry *tab, uint16_t *hi,
1173− uint16_t *lo)
1174−{
1175− uint16_t v_index;
1176− bool vol_found = false;
1177− *hi = tab->value * VOLTAGE_SCALE;
1178− *lo = tab->value * VOLTAGE_SCALE;
1179−
1180− /* SCLK/VDDC Dependency Table has to exist. */
1181− PP_ASSERT_WITH_CODE(NULL != hwmgr->dyn_state.vddc_dependency_on_sclk,
1182− "The SCLK/VDDC Dependency Table does not exist.\n",
1183− return -EINVAL);
1184−
1185− if (NULL == hwmgr->dyn_state.cac_leakage_table) {
1186− pr_warning("CAC Leakage Table does not exist, using vddc.\n");
1187− return 0;
1188− }
1189−
1190− /*
1191− * Since voltage in the sclk/vddc dependency table is not
1192− * necessarily in ascending order because of ELB voltage
1193− * patching, loop through entire list to find exact voltage.
1194− */
1195− for (v_index = 0; (uint32_t)v_index < hwmgr->dyn_state.vddc_dependency_on_sclk->count; v_index++) {
1196− if (tab->value == hwmgr->dyn_state.vddc_dependency_on_sclk->entries[v_index].v) {
1197− vol_found = true;
1198− if ((uint32_t)v_index < hwmgr->dyn_state.cac_leakage_table->count) {
1199− *lo = hwmgr->dyn_state.cac_leakage_table->entries[v_index].Vddc * VOLTAGE_SCALE;
1200− *hi = (uint16_t)(hwmgr->dyn_state.cac_leakage_table->entries[v_index].Leakage * VOLTAGE_SCALE);
1201− } else {
1202− pr_warning("Index from SCLK/VDDC Dependency Table exceeds the CAC Leakage Table index, using maximum index from CAC table.\n");
1203− *lo = hwmgr->dyn_state.cac_leakage_table->entries[hwmgr->dyn_state.cac_leakage_table->count - 1].Vddc * VOLTAGE_SCALE;
1204− *hi = (uint16_t)(hwmgr->dyn_state.cac_leakage_table->entries[hwmgr->dyn_state.cac_leakage_table->count - 1].Leakage * VOLTAGE_SCALE);
1205− }
1206− break;
1207− }
1208− }
1209−
1210− /*
1211− * If voltage is not found in the first pass, loop again to
1212− * find the best match, equal or higher value.
1213− */
1214− if (!vol_found) {
1215− for (v_index = 0; (uint32_t)v_index < hwmgr->dyn_state.vddc_dependency_on_sclk->count; v_index++) {
1216− if (tab->value <= hwmgr->dyn_state.vddc_dependency_on_sclk->entries[v_index].v) {
1217− vol_found = true;
1218− if ((uint32_t)v_index < hwmgr->dyn_state.cac_leakage_table->count) {
1219− *lo = hwmgr->dyn_state.cac_leakage_table->entries[v_index].Vddc * VOLTAGE_SCALE;
1220− *hi = (uint16_t)(hwmgr->dyn_state.cac_leakage_table->entries[v_index].Leakage) * VOLTAGE_SCALE;
1221− } else {
1222− pr_warning("Index from SCLK/VDDC Dependency Table exceeds the CAC Leakage Table index in second look up, using maximum index from CAC table.");
1223− *lo = hwmgr->dyn_state.cac_leakage_table->entries[hwmgr->dyn_state.cac_leakage_table->count - 1].Vddc * VOLTAGE_SCALE;
1224− *hi = (uint16_t)(hwmgr->dyn_state.cac_leakage_table->entries[hwmgr->dyn_state.cac_leakage_table->count - 1].Leakage * VOLTAGE_SCALE);
1225− }
1226− break;
1227− }
1228− }
1229−
1230− if (!vol_found)
1231− pr_warning("Unable to get std_vddc from SCLK/VDDC Dependency Table, using vddc.\n");
1232− }
1233−
1234− return 0;
1235−}
1236−
1237−static int iceland_populate_smc_voltage_table(struct pp_hwmgr *hwmgr,
1238− pp_atomctrl_voltage_table_entry *tab,
1239− SMU71_Discrete_VoltageLevel *smc_voltage_tab) {
1240− int result;
1241−
1242−
1243− result = iceland_get_std_voltage_value_sidd(hwmgr, tab,
1244− &smc_voltage_tab->StdVoltageHiSidd,
1245− &smc_voltage_tab->StdVoltageLoSidd);
1246− if (0 != result) {
1247− smc_voltage_tab->StdVoltageHiSidd = tab->value * VOLTAGE_SCALE;
1248− smc_voltage_tab->StdVoltageLoSidd = tab->value * VOLTAGE_SCALE;
1249− }
1250−
1251− smc_voltage_tab->Voltage = PP_HOST_TO_SMC_US(tab->value * VOLTAGE_SCALE);
1252− CONVERT_FROM_HOST_TO_SMC_US(smc_voltage_tab->StdVoltageHiSidd);
1253− CONVERT_FROM_HOST_TO_SMC_US(smc_voltage_tab->StdVoltageHiSidd);
1254−
1255− return 0;
1256−}
1257−
1258−/**
1259− * Vddc table preparation for SMC.
1260− *
1261− * @param hwmgr the address of the hardware manager
1262− * @param table the SMC DPM table structure to be populated
1263− * @return always 0
1264− */
1265−static int iceland_populate_smc_vddc_table(struct pp_hwmgr *hwmgr,
1266− SMU71_Discrete_DpmTable *table)
1267−{
1268− unsigned int count;
1269− int result;
1270−
1271− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
1272−
1273− table->VddcLevelCount = data->vddc_voltage_table.count;
1274− for (count = 0; count < table->VddcLevelCount; count++) {
1275− result = iceland_populate_smc_voltage_table(hwmgr,
1276− &data->vddc_voltage_table.entries[count],
1277− &table->VddcLevel[count]);
1278− PP_ASSERT_WITH_CODE(0 == result, "do not populate SMC VDDC voltage table", return -EINVAL);
1279−
1280− /* GPIO voltage control */
1281− if (ICELAND_VOLTAGE_CONTROL_BY_GPIO == data->voltage_control)
1282− table->VddcLevel[count].Smio |= data->vddc_voltage_table.entries[count].smio_low;
1283− else if (ICELAND_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control)
1284− table->VddcLevel[count].Smio = 0;
1285− }
1286−
1287− CONVERT_FROM_HOST_TO_SMC_UL(table->VddcLevelCount);
1288−
1289− return 0;
1290−}
1291−
1292−/**
1293− * Vddci table preparation for SMC.
1294− *
1295− * @param *hwmgr The address of the hardware manager.
1296− * @param *table The SMC DPM table structure to be populated.
1297− * @return 0
1298− */
1299−static int iceland_populate_smc_vdd_ci_table(struct pp_hwmgr *hwmgr,
1300− SMU71_Discrete_DpmTable *table)
1301−{
1302− int result;
1303− uint32_t count;
1304− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
1305−
1306− table->VddciLevelCount = data->vddci_voltage_table.count;
1307− for (count = 0; count < table->VddciLevelCount; count++) {
1308− result = iceland_populate_smc_voltage_table(hwmgr,
1309− &data->vddci_voltage_table.entries[count],
1310− &table->VddciLevel[count]);
1311− PP_ASSERT_WITH_CODE(0 == result, "do not populate SMC VDDCI voltage table", return -EINVAL);
1312−
1313− /* GPIO voltage control */
1314− if (ICELAND_VOLTAGE_CONTROL_BY_GPIO == data->vdd_ci_control)
1315− table->VddciLevel[count].Smio |= data->vddci_voltage_table.entries[count].smio_low;
1316− else
1317− table->VddciLevel[count].Smio = 0;
1318− }
1319−
1320− CONVERT_FROM_HOST_TO_SMC_UL(table->VddcLevelCount);
1321−
1322− return 0;
1323−}
1324−
1325−/**
1326− * Mvdd table preparation for SMC.
1327− *
1328− * @param *hwmgr The address of the hardware manager.
1329− * @param *table The SMC DPM table structure to be populated.
1330− * @return 0
1331− */
1332−static int iceland_populate_smc_mvdd_table(struct pp_hwmgr *hwmgr,
1333− SMU71_Discrete_DpmTable *table)
1334−{
1335− int result;
1336− uint32_t count;
1337− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
1338−
1339− table->MvddLevelCount = data->mvdd_voltage_table.count;
1340− for (count = 0; count < table->MvddLevelCount; count++) {
1341− result = iceland_populate_smc_voltage_table(hwmgr,
1342− &data->mvdd_voltage_table.entries[count],
1343− &table->MvddLevel[count]);
1344− PP_ASSERT_WITH_CODE(0 == result, "do not populate SMC VDDCI voltage table", return -EINVAL);
1345−
1346− /* GPIO voltage control */
1347− if (ICELAND_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control)
1348− table->MvddLevel[count].Smio |= data->mvdd_voltage_table.entries[count].smio_low;
1349− else
1350− table->MvddLevel[count].Smio = 0;
1351− }
1352−
1353− CONVERT_FROM_HOST_TO_SMC_UL(table->MvddLevelCount);
1354−
1355− return 0;
1356−}
1357−
1358−int iceland_populate_bapm_vddc_vid_sidd(struct pp_hwmgr *hwmgr)
1359−{
1360− int i;
1361− struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
1362− uint8_t * hi_vid = data->power_tune_table.BapmVddCVidHiSidd;
1363− uint8_t * lo_vid = data->power_tune_table.BapmVddCVidLoSidd;
1364−
1365− PP_ASSERT_WITH_CODE(NULL != hwmgr->dyn_state.cac_leakage_table,
1366− "The CAC Leakage table does not exist!", return -EINVAL);
1367− PP_ASSERT_WITH_CODE(hwmgr->dyn_state.cac_leakage_table->count <= 8,
1368− "There should never be more than 8 entries for BapmVddcVid!!!", return -EINVAL);
1369− PP_ASSERT_WITH_CODE(hwmgr->dyn_state.cac_leakage_table->count == hwmgr->dyn_state.vddc_dependency_on_sclk->count,
1370− "CACLeakageTable->count and VddcDependencyOnSCLk->count not equal", return -EINVAL);
1371−
1372− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_EVV)) {
1373− for (i = 0; (uint32_t) i < hwmgr->dyn_state.cac_leakage_table->count; i++) {
1374− lo_vid[i] = convert_to_vid(hwmgr->dyn_state.cac_leakage_table->entries[i].Vddc1);
1375− hi_vid[i] = convert_to_vid(hwmgr->dyn_state.cac_leakage_table->entries[i].Vddc2);
1376− }
1377− } else {
1378− PP_ASSERT_WITH_CODE(false, "Iceland should always support EVV", return -EINVAL);
1379− }
1380−
1381− return 0;
1382−}
1383−
1384−int iceland_populate_vddc_vid(struct pp_hwmgr *hwmgr)
1385−{
1386− int i;
1387− struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
1388− uint8_t *vid = data->power_tune_table.VddCVid;
1389−
1390− PP_ASSERT_WITH_CODE(data->vddc_voltage_table.count <= 8,
1391− "There should never be more than 8 entries for VddcVid!!!",
1392− return -EINVAL);
1393−
1394− for (i = 0; i < (int)data->vddc_voltage_table.count; i++) {
1395− vid[i] = convert_to_vid(data->vddc_voltage_table.entries[i].value);
1396− }
1397−
1398− return 0;
1399−}
1400−
1401−/**
1402− * Preparation of voltage tables for SMC.
1403− *
1404− * @param hwmgr the address of the hardware manager
1405− * @param table the SMC DPM table structure to be populated
1406− * @return always 0
1407− */
1408−
1409−int iceland_populate_smc_voltage_tables(struct pp_hwmgr *hwmgr,
1410− SMU71_Discrete_DpmTable *table)
1411−{
1412− int result;
1413−
1414− result = iceland_populate_smc_vddc_table(hwmgr, table);
1415− PP_ASSERT_WITH_CODE(0 == result,
1416− "can not populate VDDC voltage table to SMC", return -1);
1417−
1418− result = iceland_populate_smc_vdd_ci_table(hwmgr, table);
1419− PP_ASSERT_WITH_CODE(0 == result,
1420− "can not populate VDDCI voltage table to SMC", return -1);
1421−
1422− result = iceland_populate_smc_mvdd_table(hwmgr, table);
1423− PP_ASSERT_WITH_CODE(0 == result,
1424− "can not populate MVDD voltage table to SMC", return -1);
1425−
1426− return 0;
1427−}
1428−
1429−
1430−/**
1431− * Re-generate the DPM level mask value
1432− * @param hwmgr the address of the hardware manager
1433− */
1434−static uint32_t iceland_get_dpm_level_enable_mask_value(
1435− struct iceland_single_dpm_table * dpm_table)
1436−{
1437− uint32_t i;
1438− uint32_t mask_value = 0;
1439−
1440− for (i = dpm_table->count; i > 0; i--) {
1441− mask_value = mask_value << 1;
1442−
1443− if (dpm_table->dpm_levels[i-1].enabled)
1444− mask_value |= 0x1;
1445− else
1446− mask_value &= 0xFFFFFFFE;
1447− }
1448− return mask_value;
1449−}
1450−
1451−int iceland_populate_memory_timing_parameters(
1452− struct pp_hwmgr *hwmgr,
1453− uint32_t engine_clock,
1454− uint32_t memory_clock,
1455− struct SMU71_Discrete_MCArbDramTimingTableEntry *arb_regs
1456− )
1457−{
1458− uint32_t dramTiming;
1459− uint32_t dramTiming2;
1460− uint32_t burstTime;
1461− int result;
1462−
1463− result = atomctrl_set_engine_dram_timings_rv770(hwmgr,
1464− engine_clock, memory_clock);
1465−
1466− PP_ASSERT_WITH_CODE(result == 0,
1467− "Error calling VBIOS to set DRAM_TIMING.", return result);
1468−
1469− dramTiming = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING);
1470− dramTiming2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2);
1471− burstTime = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0);
1472−
1473− arb_regs->McArbDramTiming = PP_HOST_TO_SMC_UL(dramTiming);
1474− arb_regs->McArbDramTiming2 = PP_HOST_TO_SMC_UL(dramTiming2);
1475− arb_regs->McArbBurstTime = (uint8_t)burstTime;
1476−
1477− return 0;
1478−}
1479−
1480−/**
1481− * Setup parameters for the MC ARB.
1482− *
1483− * @param hwmgr the address of the powerplay hardware manager.
1484− * @return always 0
1485− * This function is to be called from the SetPowerState table.
1486− */
1487−int iceland_program_memory_timing_parameters(struct pp_hwmgr *hwmgr)
1488−{
1489− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
1490− int result = 0;
1491− SMU71_Discrete_MCArbDramTimingTable arb_regs;
1492− uint32_t i, j;
1493−
1494− memset(&arb_regs, 0x00, sizeof(SMU71_Discrete_MCArbDramTimingTable));
1495−
1496− for (i = 0; i < data->dpm_table.sclk_table.count; i++) {
1497− for (j = 0; j < data->dpm_table.mclk_table.count; j++) {
1498− result = iceland_populate_memory_timing_parameters
1499− (hwmgr, data->dpm_table.sclk_table.dpm_levels[i].value,
1500− data->dpm_table.mclk_table.dpm_levels[j].value,
1501− &arb_regs.entries[i][j]);
1502−
1503− if (0 != result) {
1504− break;
1505− }
1506− }
1507− }
1508−
1509− if (0 == result) {
1510− result = iceland_copy_bytes_to_smc(
1511− hwmgr->smumgr,
1512− data->arb_table_start,
1513− (uint8_t *)&arb_regs,
1514− sizeof(SMU71_Discrete_MCArbDramTimingTable),
1515− data->sram_end
1516− );
1517− }
1518−
1519− return result;
1520−}
1521−
1522−static int iceland_populate_smc_link_level(struct pp_hwmgr *hwmgr, SMU71_Discrete_DpmTable *table)
1523−{
1524− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
1525− struct iceland_dpm_table *dpm_table = &data->dpm_table;
1526− uint32_t i;
1527−
1528− /* Index (dpm_table->pcie_speed_table.count) is reserved for PCIE boot level. */
1529− for (i = 0; i <= dpm_table->pcie_speed_table.count; i++) {
1530− table->LinkLevel[i].PcieGenSpeed =
1531− (uint8_t)dpm_table->pcie_speed_table.dpm_levels[i].value;
1532− table->LinkLevel[i].PcieLaneCount =
1533− (uint8_t)encode_pcie_lane_width(dpm_table->pcie_speed_table.dpm_levels[i].param1);
1534− table->LinkLevel[i].EnabledForActivity =
1535− 1;
1536− table->LinkLevel[i].SPC =
1537− (uint8_t)(data->pcie_spc_cap & 0xff);
1538− table->LinkLevel[i].DownThreshold =
1539− PP_HOST_TO_SMC_UL(5);
1540− table->LinkLevel[i].UpThreshold =
1541− PP_HOST_TO_SMC_UL(30);
1542− }
1543−
1544− data->smc_state_table.LinkLevelCount =
1545− (uint8_t)dpm_table->pcie_speed_table.count;
1546− data->dpm_level_enable_mask.pcie_dpm_enable_mask =
1547− iceland_get_dpm_level_enable_mask_value(&dpm_table->pcie_speed_table);
1548−
1549− return 0;
1550−}
1551−
1552−static int iceland_populate_smc_uvd_level(struct pp_hwmgr *hwmgr,
1553− SMU71_Discrete_DpmTable *table)
1554−{
1555− return 0;
1556−}
1557−
1558−uint8_t iceland_get_voltage_id(pp_atomctrl_voltage_table *voltage_table,
1559− uint32_t voltage)
1560−{
1561− uint8_t count = (uint8_t) (voltage_table->count);
1562− uint8_t i = 0;
1563−
1564− PP_ASSERT_WITH_CODE((NULL != voltage_table),
1565− "Voltage Table empty.", return 0;);
1566− PP_ASSERT_WITH_CODE((0 != count),
1567− "Voltage Table empty.", return 0;);
1568−
1569− for (i = 0; i < count; i++) {
1570− /* find first voltage bigger than requested */
1571− if (voltage_table->entries[i].value >= voltage)
1572− return i;
1573− }
1574−
1575− /* voltage is bigger than max voltage in the table */
1576− return i - 1;
1577−}
1578−
1579−static int iceland_populate_smc_vce_level(struct pp_hwmgr *hwmgr,
1580− SMU71_Discrete_DpmTable *table)
1581−{
1582− return 0;
1583−}
1584−
1585−static int iceland_populate_smc_acp_level(struct pp_hwmgr *hwmgr,
1586− SMU71_Discrete_DpmTable *table)
1587−{
1588− return 0;
1589−}
1590−
1591−static int iceland_populate_smc_samu_level(struct pp_hwmgr *hwmgr,
1592− SMU71_Discrete_DpmTable *table)
1593−{
1594− return 0;
1595−}
1596−
1597−
1598−static int iceland_populate_smc_svi2_config(struct pp_hwmgr *hwmgr,
1599− SMU71_Discrete_DpmTable *tab)
1600−{
1601− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
1602−
1603− if(ICELAND_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control)
1604− tab->SVI2Enable |= VDDC_ON_SVI2;
1605−
1606− if(ICELAND_VOLTAGE_CONTROL_BY_SVID2 == data->vdd_ci_control)
1607− tab->SVI2Enable |= VDDCI_ON_SVI2;
1608− else
1609− tab->MergedVddci = 1;
1610−
1611− if(ICELAND_VOLTAGE_CONTROL_BY_SVID2 == data->mvdd_control)
1612− tab->SVI2Enable |= MVDD_ON_SVI2;
1613−
1614− PP_ASSERT_WITH_CODE( tab->SVI2Enable != (VDDC_ON_SVI2 | VDDCI_ON_SVI2 | MVDD_ON_SVI2) &&
1615− (tab->SVI2Enable & VDDC_ON_SVI2), "SVI2 domain configuration is incorrect!", return -EINVAL);
1616−
1617− return 0;
1618−}
1619−
1620−static int iceland_get_dependecy_volt_by_clk(struct pp_hwmgr *hwmgr,
1621− struct phm_clock_voltage_dependency_table *allowed_clock_voltage_table,
1622− uint32_t clock, uint32_t *vol)
1623−{
1624− uint32_t i = 0;
1625−
1626− /* clock - voltage dependency table is empty table */
1627− if (allowed_clock_voltage_table->count == 0)
1628− return -EINVAL;
1629−
1630− for (i = 0; i < allowed_clock_voltage_table->count; i++) {
1631− /* find first sclk bigger than request */
1632− if (allowed_clock_voltage_table->entries[i].clk >= clock) {
1633− *vol = allowed_clock_voltage_table->entries[i].v;
1634− return 0;
1635− }
1636− }
1637−
1638− /* sclk is bigger than max sclk in the dependence table */
1639− *vol = allowed_clock_voltage_table->entries[i - 1].v;
1640−
1641− return 0;
1642−}
1643−
1644−static uint8_t iceland_get_mclk_frequency_ratio(uint32_t memory_clock,
1645− bool strobe_mode)
1646−{
1647− uint8_t mc_para_index;
1648−
1649− if (strobe_mode) {
1650− if (memory_clock < 12500) {
1651− mc_para_index = 0x00;
1652− } else if (memory_clock > 47500) {
1653− mc_para_index = 0x0f;
1654− } else {
1655− mc_para_index = (uint8_t)((memory_clock - 10000) / 2500);
1656− }
1657− } else {
1658− if (memory_clock < 65000) {
1659− mc_para_index = 0x00;
1660− } else if (memory_clock > 135000) {
1661− mc_para_index = 0x0f;
1662− } else {
1663− mc_para_index = (uint8_t)((memory_clock - 60000) / 5000);
1664− }
1665− }
1666−
1667− return mc_para_index;
1668−}
1669−
1670−static uint8_t iceland_get_ddr3_mclk_frequency_ratio(uint32_t memory_clock)
1671−{
1672− uint8_t mc_para_index;
1673−
1674− if (memory_clock < 10000) {
1675− mc_para_index = 0;
1676− } else if (memory_clock >= 80000) {
1677− mc_para_index = 0x0f;
1678− } else {
1679− mc_para_index = (uint8_t)((memory_clock - 10000) / 5000 + 1);
1680− }
1681−
1682− return mc_para_index;
1683−}
1684−
1685−static int iceland_populate_phase_value_based_on_sclk(struct pp_hwmgr *hwmgr, const struct phm_phase_shedding_limits_table *pl,
1686− uint32_t sclk, uint32_t *p_shed)
1687−{
1688− unsigned int i;
1689−
1690− /* use the minimum phase shedding */
1691− *p_shed = 1;
1692−
1693− /*
1694− * PPGen ensures the phase shedding limits table is sorted
1695− * from lowest voltage/sclk/mclk to highest voltage/sclk/mclk.
1696− * VBIOS ensures the phase shedding masks table is sorted from
1697− * least phases enabled (phase shedding on) to most phases
1698− * enabled (phase shedding off).
1699− */
1700− for (i = 0; i < pl->count; i++) {
1701− if (sclk < pl->entries[i].Sclk) {
1702− /* Enable phase shedding */
1703− *p_shed = i;
1704− break;
1705− }
1706− }
1707−
1708− return 0;
1709−}
1710−
1711−static int iceland_populate_phase_value_based_on_mclk(struct pp_hwmgr *hwmgr, const struct phm_phase_shedding_limits_table *pl,
1712− uint32_t memory_clock, uint32_t *p_shed)
1713−{
1714− unsigned int i;
1715−
1716− /* use the minimum phase shedding */
1717− *p_shed = 1;
1718−
1719− /*
1720− * PPGen ensures the phase shedding limits table is sorted
1721− * from lowest voltage/sclk/mclk to highest voltage/sclk/mclk.
1722− * VBIOS ensures the phase shedding masks table is sorted from
1723− * least phases enabled (phase shedding on) to most phases
1724− * enabled (phase shedding off).
1725− */
1726− for (i = 0; i < pl->count; i++) {
1727− if (memory_clock < pl->entries[i].Mclk) {
1728− /* Enable phase shedding */
1729− *p_shed = i;
1730− break;
1731− }
1732− }
1733−
1734− return 0;
1735−}
1736−
1737−/**
1738− * Populates the SMC MCLK structure using the provided memory clock
1739− *
1740− * @param hwmgr the address of the hardware manager
1741− * @param memory_clock the memory clock to use to populate the structure
1742− * @param sclk the SMC SCLK structure to be populated
1743− */
1744−static int iceland_calculate_mclk_params(
1745− struct pp_hwmgr *hwmgr,
1746− uint32_t memory_clock,
1747− SMU71_Discrete_MemoryLevel *mclk,
1748− bool strobe_mode,
1749− bool dllStateOn
1750− )
1751−{
1752− const iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
1753− uint32_t dll_cntl = data->clock_registers.vDLL_CNTL;
1754− uint32_t mclk_pwrmgt_cntl = data->clock_registers.vMCLK_PWRMGT_CNTL;
1755− uint32_t mpll_ad_func_cntl = data->clock_registers.vMPLL_AD_FUNC_CNTL;
1756− uint32_t mpll_dq_func_cntl = data->clock_registers.vMPLL_DQ_FUNC_CNTL;
1757− uint32_t mpll_func_cntl = data->clock_registers.vMPLL_FUNC_CNTL;
1758− uint32_t mpll_func_cntl_1 = data->clock_registers.vMPLL_FUNC_CNTL_1;
1759− uint32_t mpll_func_cntl_2 = data->clock_registers.vMPLL_FUNC_CNTL_2;
1760− uint32_t mpll_ss1 = data->clock_registers.vMPLL_SS1;
1761− uint32_t mpll_ss2 = data->clock_registers.vMPLL_SS2;
1762−
1763− pp_atomctrl_memory_clock_param mpll_param;
1764− int result;
1765−
1766− result = atomctrl_get_memory_pll_dividers_si(hwmgr,
1767− memory_clock, &mpll_param, strobe_mode);
1768− PP_ASSERT_WITH_CODE(0 == result,
1769− "Error retrieving Memory Clock Parameters from VBIOS.", return result);
1770−
1771− /* MPLL_FUNC_CNTL setup*/
1772− mpll_func_cntl = PHM_SET_FIELD(mpll_func_cntl, MPLL_FUNC_CNTL, BWCTRL, mpll_param.bw_ctrl);
1773−
1774− /* MPLL_FUNC_CNTL_1 setup*/
1775− mpll_func_cntl_1 = PHM_SET_FIELD(mpll_func_cntl_1,
1776− MPLL_FUNC_CNTL_1, CLKF, mpll_param.mpll_fb_divider.cl_kf);
1777− mpll_func_cntl_1 = PHM_SET_FIELD(mpll_func_cntl_1,
1778− MPLL_FUNC_CNTL_1, CLKFRAC, mpll_param.mpll_fb_divider.clk_frac);
1779− mpll_func_cntl_1 = PHM_SET_FIELD(mpll_func_cntl_1,
1780− MPLL_FUNC_CNTL_1, VCO_MODE, mpll_param.vco_mode);
1781−
1782− /* MPLL_AD_FUNC_CNTL setup*/
1783− mpll_ad_func_cntl = PHM_SET_FIELD(mpll_ad_func_cntl,
1784− MPLL_AD_FUNC_CNTL, YCLK_POST_DIV, mpll_param.mpll_post_divider);
1785−
1786− if (data->is_memory_GDDR5) {
1787− /* MPLL_DQ_FUNC_CNTL setup*/
1788− mpll_dq_func_cntl = PHM_SET_FIELD(mpll_dq_func_cntl,
1789− MPLL_DQ_FUNC_CNTL, YCLK_SEL, mpll_param.yclk_sel);
1790− mpll_dq_func_cntl = PHM_SET_FIELD(mpll_dq_func_cntl,
1791− MPLL_DQ_FUNC_CNTL, YCLK_POST_DIV, mpll_param.mpll_post_divider);
1792− }
1793−
1794− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1795− PHM_PlatformCaps_MemorySpreadSpectrumSupport)) {
1796− /*
1797− ************************************
1798− Fref = Reference Frequency
1799− NF = Feedback divider ratio
1800− NR = Reference divider ratio
1801− Fnom = Nominal VCO output frequency = Fref * NF / NR
1802− Fs = Spreading Rate
1803− D = Percentage down-spread / 2
1804− Fint = Reference input frequency to PFD = Fref / NR
1805− NS = Spreading rate divider ratio = int(Fint / (2 * Fs))
1806− CLKS = NS - 1 = ISS_STEP_NUM[11:0]
1807− NV = D * Fs / Fnom * 4 * ((Fnom/Fref * NR) ^ 2)
1808− CLKV = 65536 * NV = ISS_STEP_SIZE[25:0]
1809− *************************************
1810− */
1811− pp_atomctrl_internal_ss_info ss_info;
1812− uint32_t freq_nom;
1813− uint32_t tmp;
1814− uint32_t reference_clock = atomctrl_get_mpll_reference_clock(hwmgr);
1815−
1816− /* for GDDR5 for all modes and DDR3 */
1817− if (1 == mpll_param.qdr)
1818− freq_nom = memory_clock * 4 * (1 << mpll_param.mpll_post_divider);
1819− else
1820− freq_nom = memory_clock * 2 * (1 << mpll_param.mpll_post_divider);
1821−
1822− /* tmp = (freq_nom / reference_clock * reference_divider) ^ 2 Note: S.I. reference_divider = 1*/
1823− tmp = (freq_nom / reference_clock);
1824− tmp = tmp * tmp;
1825−
1826− if (0 == atomctrl_get_memory_clock_spread_spectrum(hwmgr, freq_nom, &ss_info)) {
1827− /* ss_info.speed_spectrum_percentage -- in unit of 0.01% */
1828− /* ss.Info.speed_spectrum_rate -- in unit of khz */
1829− /* CLKS = reference_clock / (2 * speed_spectrum_rate * reference_divider) * 10 */
1830− /* = reference_clock * 5 / speed_spectrum_rate */
1831− uint32_t clks = reference_clock * 5 / ss_info.speed_spectrum_rate;
1832−
1833− /* CLKV = 65536 * speed_spectrum_percentage / 2 * spreadSpecrumRate / freq_nom * 4 / 100000 * ((freq_nom / reference_clock) ^ 2) */
1834− /* = 131 * speed_spectrum_percentage * speed_spectrum_rate / 100 * ((freq_nom / reference_clock) ^ 2) / freq_nom */
1835− uint32_t clkv =
1836− (uint32_t)((((131 * ss_info.speed_spectrum_percentage *
1837− ss_info.speed_spectrum_rate) / 100) * tmp) / freq_nom);
1838−
1839− mpll_ss1 = PHM_SET_FIELD(mpll_ss1, MPLL_SS1, CLKV, clkv);
1840− mpll_ss2 = PHM_SET_FIELD(mpll_ss2, MPLL_SS2, CLKS, clks);
1841− }
1842− }
1843−
1844− /* MCLK_PWRMGT_CNTL setup */
1845− mclk_pwrmgt_cntl = PHM_SET_FIELD(mclk_pwrmgt_cntl,
1846− MCLK_PWRMGT_CNTL, DLL_SPEED, mpll_param.dll_speed);
1847− mclk_pwrmgt_cntl = PHM_SET_FIELD(mclk_pwrmgt_cntl,
1848− MCLK_PWRMGT_CNTL, MRDCK0_PDNB, dllStateOn);
1849− mclk_pwrmgt_cntl = PHM_SET_FIELD(mclk_pwrmgt_cntl,
1850− MCLK_PWRMGT_CNTL, MRDCK1_PDNB, dllStateOn);
1851−
1852−
1853− /* Save the result data to outpupt memory level structure */
1854− mclk->MclkFrequency = memory_clock;
1855− mclk->MpllFuncCntl = mpll_func_cntl;
1856− mclk->MpllFuncCntl_1 = mpll_func_cntl_1;
1857− mclk->MpllFuncCntl_2 = mpll_func_cntl_2;
1858− mclk->MpllAdFuncCntl = mpll_ad_func_cntl;
1859− mclk->MpllDqFuncCntl = mpll_dq_func_cntl;
1860− mclk->MclkPwrmgtCntl = mclk_pwrmgt_cntl;
1861− mclk->DllCntl = dll_cntl;
1862− mclk->MpllSs1 = mpll_ss1;
1863− mclk->MpllSs2 = mpll_ss2;
1864−
1865− return 0;
1866−}
1867−
1868−static int iceland_populate_single_memory_level(
1869− struct pp_hwmgr *hwmgr,
1870− uint32_t memory_clock,
1871− SMU71_Discrete_MemoryLevel *memory_level
1872− )
1873−{
1874− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
1875− int result = 0;
1876− bool dllStateOn;
1877− struct cgs_display_info info = {0};
1878−
1879−
1880− if (NULL != hwmgr->dyn_state.vddc_dependency_on_mclk) {
1881− result = iceland_get_dependecy_volt_by_clk(hwmgr,
1882− hwmgr->dyn_state.vddc_dependency_on_mclk, memory_clock, &memory_level->MinVddc);
1883− PP_ASSERT_WITH_CODE((0 == result),
1884− "can not find MinVddc voltage value from memory VDDC voltage dependency table", return result);
1885− }
1886−
1887− if (data->vdd_ci_control == ICELAND_VOLTAGE_CONTROL_NONE) {
1888− memory_level->MinVddci = memory_level->MinVddc;
1889− } else if (NULL != hwmgr->dyn_state.vddci_dependency_on_mclk) {
1890− result = iceland_get_dependecy_volt_by_clk(hwmgr,
1891− hwmgr->dyn_state.vddci_dependency_on_mclk,
1892− memory_clock,
1893− &memory_level->MinVddci);
1894− PP_ASSERT_WITH_CODE((0 == result),
1895− "can not find MinVddci voltage value from memory VDDCI voltage dependency table", return result);
1896− }
1897−
1898− if (NULL != hwmgr->dyn_state.mvdd_dependency_on_mclk) {
1899− result = iceland_get_dependecy_volt_by_clk(hwmgr,
1900− hwmgr->dyn_state.mvdd_dependency_on_mclk, memory_clock, &memory_level->MinMvdd);
1901− PP_ASSERT_WITH_CODE((0 == result),
1902− "can not find MinMVDD voltage value from memory MVDD voltage dependency table", return result);
1903− }
1904−
1905− memory_level->MinVddcPhases = 1;
1906−
1907− if (data->vddc_phase_shed_control) {
1908− iceland_populate_phase_value_based_on_mclk(hwmgr, hwmgr->dyn_state.vddc_phase_shed_limits_table,
1909− memory_clock, &memory_level->MinVddcPhases);
1910− }
1911−
1912− memory_level->EnabledForThrottle = 1;
1913− memory_level->EnabledForActivity = 1;
1914− memory_level->UpHyst = 0;
1915− memory_level->DownHyst = 100;
1916− memory_level->VoltageDownHyst = 0;
1917−
1918− /* Indicates maximum activity level for this performance level.*/
1919− memory_level->ActivityLevel = (uint16_t)data->mclk_activity_target;
1920− memory_level->StutterEnable = 0;
1921− memory_level->StrobeEnable = 0;
1922− memory_level->EdcReadEnable = 0;
1923− memory_level->EdcWriteEnable = 0;
1924− memory_level->RttEnable = 0;
1925−
1926− /* default set to low watermark. Highest level will be set to high later.*/
1927− memory_level->DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW;
1928−
1929− cgs_get_active_displays_info(hwmgr->device, &info);
1930− data->display_timing.num_existing_displays = info.display_count;
1931−
1932− //if ((data->mclk_stutter_mode_threshold != 0) &&
1933− // (memory_clock <= data->mclk_stutter_mode_threshold) &&
1934− // (data->is_uvd_enabled == 0)
1935− // && (PHM_READ_FIELD(hwmgr->device, DPG_PIPE_STUTTER_CONTROL, STUTTER_ENABLE) & 0x1)
1936− // && (data->display_timing.num_existing_displays <= 2)
1937− // && (data->display_timing.num_existing_displays != 0))
1938− // memory_level->StutterEnable = 1;
1939−
1940− /* decide strobe mode*/
1941− memory_level->StrobeEnable = (data->mclk_strobe_mode_threshold != 0) &&
1942− (memory_clock <= data->mclk_strobe_mode_threshold);
1943−
1944− /* decide EDC mode and memory clock ratio*/
1945− if (data->is_memory_GDDR5) {
1946− memory_level->StrobeRatio = iceland_get_mclk_frequency_ratio(memory_clock,
1947− memory_level->StrobeEnable);
1948−
1949− if ((data->mclk_edc_enable_threshold != 0) &&
1950− (memory_clock > data->mclk_edc_enable_threshold)) {
1951− memory_level->EdcReadEnable = 1;
1952− }
1953−
1954− if ((data->mclk_edc_wr_enable_threshold != 0) &&
1955− (memory_clock > data->mclk_edc_wr_enable_threshold)) {
1956− memory_level->EdcWriteEnable = 1;
1957− }
1958−
1959− if (memory_level->StrobeEnable) {
1960− if (iceland_get_mclk_frequency_ratio(memory_clock, 1) >=
1961− ((cgs_read_register(hwmgr->device, mmMC_SEQ_MISC7) >> 16) & 0xf)) {
1962− dllStateOn = ((cgs_read_register(hwmgr->device, mmMC_SEQ_MISC5) >> 1) & 0x1) ? 1 : 0;
1963− } else {
1964− dllStateOn = ((cgs_read_register(hwmgr->device, mmMC_SEQ_MISC6) >> 1) & 0x1) ? 1 : 0;
1965− }
1966−
1967− } else {
1968− dllStateOn = data->dll_defaule_on;
1969− }
1970− } else {
1971− memory_level->StrobeRatio =
1972− iceland_get_ddr3_mclk_frequency_ratio(memory_clock);
1973− dllStateOn = ((cgs_read_register(hwmgr->device, mmMC_SEQ_MISC5) >> 1) & 0x1) ? 1 : 0;
1974− }
1975−
1976− result = iceland_calculate_mclk_params(hwmgr,
1977− memory_clock, memory_level, memory_level->StrobeEnable, dllStateOn);
1978−
1979− if (0 == result) {
1980− memory_level->MinVddc = PP_HOST_TO_SMC_UL(memory_level->MinVddc * VOLTAGE_SCALE);
1981− CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MinVddcPhases);
1982− memory_level->MinVddci = PP_HOST_TO_SMC_UL(memory_level->MinVddci * VOLTAGE_SCALE);
1983− memory_level->MinMvdd = PP_HOST_TO_SMC_UL(memory_level->MinMvdd * VOLTAGE_SCALE);
1984− /* MCLK frequency in units of 10KHz*/
1985− CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MclkFrequency);
1986− /* Indicates maximum activity level for this performance level.*/
1987− CONVERT_FROM_HOST_TO_SMC_US(memory_level->ActivityLevel);
1988− CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MpllFuncCntl);
1989− CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MpllFuncCntl_1);
1990− CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MpllFuncCntl_2);
1991− CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MpllAdFuncCntl);
1992− CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MpllDqFuncCntl);
1993− CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MclkPwrmgtCntl);
1994− CONVERT_FROM_HOST_TO_SMC_UL(memory_level->DllCntl);
1995− CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MpllSs1);
1996− CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MpllSs2);
1997− }
1998−
1999− return result;
2000−}
2001−
2002−/**
2003− * Populates the SMC MVDD structure using the provided memory clock.
2004− *
2005− * @param hwmgr the address of the hardware manager
2006− * @param mclk the MCLK value to be used in the decision if MVDD should be high or low.
2007− * @param voltage the SMC VOLTAGE structure to be populated
2008− */
2009−int iceland_populate_mvdd_value(struct pp_hwmgr *hwmgr, uint32_t mclk, SMU71_Discrete_VoltageLevel *voltage)
2010−{
2011− const iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
2012− uint32_t i = 0;
2013−
2014− if (ICELAND_VOLTAGE_CONTROL_NONE != data->mvdd_control) {
2015− /* find mvdd value which clock is more than request */
2016− for (i = 0; i < hwmgr->dyn_state.mvdd_dependency_on_mclk->count; i++) {
2017− if (mclk <= hwmgr->dyn_state.mvdd_dependency_on_mclk->entries[i].clk) {
2018− /* Always round to higher voltage. */
2019− voltage->Voltage = data->mvdd_voltage_table.entries[i].value;
2020− break;
2021− }
2022− }
2023−
2024− PP_ASSERT_WITH_CODE(i < hwmgr->dyn_state.mvdd_dependency_on_mclk->count,
2025− "MVDD Voltage is outside the supported range.", return -1);
2026−
2027− } else {
2028− return -1;
2029− }
2030−
2031− return 0;
2032−}
2033−
2034−
2035−static int iceland_populate_smc_acpi_level(struct pp_hwmgr *hwmgr,
2036− SMU71_Discrete_DpmTable *table)
2037−{
2038− int result = 0;
2039− const iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
2040− pp_atomctrl_clock_dividers_vi dividers;
2041− SMU71_Discrete_VoltageLevel voltage_level;
2042− uint32_t spll_func_cntl = data->clock_registers.vCG_SPLL_FUNC_CNTL;
2043− uint32_t spll_func_cntl_2 = data->clock_registers.vCG_SPLL_FUNC_CNTL_2;
2044− uint32_t dll_cntl = data->clock_registers.vDLL_CNTL;
2045− uint32_t mclk_pwrmgt_cntl = data->clock_registers.vMCLK_PWRMGT_CNTL;
2046−
2047− /* The ACPI state should not do DPM on DC (or ever).*/
2048− table->ACPILevel.Flags &= ~PPSMC_SWSTATE_FLAG_DC;
2049−
2050− if (data->acpi_vddc)
2051− table->ACPILevel.MinVddc = PP_HOST_TO_SMC_UL(data->acpi_vddc * VOLTAGE_SCALE);
2052− else
2053− table->ACPILevel.MinVddc = PP_HOST_TO_SMC_UL(data->min_vddc_in_pp_table * VOLTAGE_SCALE);
2054−
2055− table->ACPILevel.MinVddcPhases = (data->vddc_phase_shed_control) ? 0 : 1;
2056−
2057− /* assign zero for now*/
2058− table->ACPILevel.SclkFrequency = atomctrl_get_reference_clock(hwmgr);
2059−
2060− /* get the engine clock dividers for this clock value*/
2061− result = atomctrl_get_engine_pll_dividers_vi(hwmgr,
2062− table->ACPILevel.SclkFrequency, &dividers);
2063−
2064− PP_ASSERT_WITH_CODE(result == 0,
2065− "Error retrieving Engine Clock dividers from VBIOS.", return result);
2066−
2067− /* divider ID for required SCLK*/
2068− table->ACPILevel.SclkDid = (uint8_t)dividers.pll_post_divider;
2069− table->ACPILevel.DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW;
2070− table->ACPILevel.DeepSleepDivId = 0;
2071−
2072− spll_func_cntl = PHM_SET_FIELD(spll_func_cntl,
2073− CG_SPLL_FUNC_CNTL, SPLL_PWRON, 0);
2074− spll_func_cntl = PHM_SET_FIELD(spll_func_cntl,
2075− CG_SPLL_FUNC_CNTL, SPLL_RESET, 1);
2076− spll_func_cntl_2 = PHM_SET_FIELD(spll_func_cntl_2,
2077− CG_SPLL_FUNC_CNTL_2, SCLK_MUX_SEL, 4);
2078−
2079− table->ACPILevel.CgSpllFuncCntl = spll_func_cntl;
2080− table->ACPILevel.CgSpllFuncCntl2 = spll_func_cntl_2;
2081− table->ACPILevel.CgSpllFuncCntl3 = data->clock_registers.vCG_SPLL_FUNC_CNTL_3;
2082− table->ACPILevel.CgSpllFuncCntl4 = data->clock_registers.vCG_SPLL_FUNC_CNTL_4;
2083− table->ACPILevel.SpllSpreadSpectrum = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM;
2084− table->ACPILevel.SpllSpreadSpectrum2 = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM_2;
2085− table->ACPILevel.CcPwrDynRm = 0;
2086− table->ACPILevel.CcPwrDynRm1 = 0;
2087−
2088−
2089− /* For various features to be enabled/disabled while this level is active.*/
2090− CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.Flags);
2091− /* SCLK frequency in units of 10KHz*/
2092− CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.SclkFrequency);
2093− CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CgSpllFuncCntl);
2094− CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CgSpllFuncCntl2);
2095− CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CgSpllFuncCntl3);
2096− CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CgSpllFuncCntl4);
2097− CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.SpllSpreadSpectrum);
2098− CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.SpllSpreadSpectrum2);
2099− CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CcPwrDynRm);
2100− CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CcPwrDynRm1);
2101−
2102− table->MemoryACPILevel.MinVddc = table->ACPILevel.MinVddc;
2103− table->MemoryACPILevel.MinVddcPhases = table->ACPILevel.MinVddcPhases;
2104−
2105− /* CONVERT_FROM_HOST_TO_SMC_UL(table->MemoryACPILevel.MinVoltage);*/
2106−
2107− if (0 == iceland_populate_mvdd_value(hwmgr, 0, &voltage_level))
2108− table->MemoryACPILevel.MinMvdd =
2109− PP_HOST_TO_SMC_UL(voltage_level.Voltage * VOLTAGE_SCALE);
2110− else
2111− table->MemoryACPILevel.MinMvdd = 0;
2112−
2113− /* Force reset on DLL*/
2114− mclk_pwrmgt_cntl = PHM_SET_FIELD(mclk_pwrmgt_cntl,
2115− MCLK_PWRMGT_CNTL, MRDCK0_RESET, 0x1);
2116− mclk_pwrmgt_cntl = PHM_SET_FIELD(mclk_pwrmgt_cntl,
2117− MCLK_PWRMGT_CNTL, MRDCK1_RESET, 0x1);
2118−
2119− /* Disable DLL in ACPIState*/
2120− mclk_pwrmgt_cntl = PHM_SET_FIELD(mclk_pwrmgt_cntl,
2121− MCLK_PWRMGT_CNTL, MRDCK0_PDNB, 0);
2122− mclk_pwrmgt_cntl = PHM_SET_FIELD(mclk_pwrmgt_cntl,
2123− MCLK_PWRMGT_CNTL, MRDCK1_PDNB, 0);
2124−
2125− /* Enable DLL bypass signal*/
2126− dll_cntl = PHM_SET_FIELD(dll_cntl,
2127− DLL_CNTL, MRDCK0_BYPASS, 0);
2128− dll_cntl = PHM_SET_FIELD(dll_cntl,
2129− DLL_CNTL, MRDCK1_BYPASS, 0);
2130−
2131− table->MemoryACPILevel.DllCntl =
2132− PP_HOST_TO_SMC_UL(dll_cntl);
2133− table->MemoryACPILevel.MclkPwrmgtCntl =
2134− PP_HOST_TO_SMC_UL(mclk_pwrmgt_cntl);
2135− table->MemoryACPILevel.MpllAdFuncCntl =
2136− PP_HOST_TO_SMC_UL(data->clock_registers.vMPLL_AD_FUNC_CNTL);
2137− table->MemoryACPILevel.MpllDqFuncCntl =
2138− PP_HOST_TO_SMC_UL(data->clock_registers.vMPLL_DQ_FUNC_CNTL);
2139− table->MemoryACPILevel.MpllFuncCntl =
2140− PP_HOST_TO_SMC_UL(data->clock_registers.vMPLL_FUNC_CNTL);
2141− table->MemoryACPILevel.MpllFuncCntl_1 =
2142− PP_HOST_TO_SMC_UL(data->clock_registers.vMPLL_FUNC_CNTL_1);
2143− table->MemoryACPILevel.MpllFuncCntl_2 =
2144− PP_HOST_TO_SMC_UL(data->clock_registers.vMPLL_FUNC_CNTL_2);
2145− table->MemoryACPILevel.MpllSs1 =
2146− PP_HOST_TO_SMC_UL(data->clock_registers.vMPLL_SS1);
2147− table->MemoryACPILevel.MpllSs2 =
2148− PP_HOST_TO_SMC_UL(data->clock_registers.vMPLL_SS2);
2149−
2150− table->MemoryACPILevel.EnabledForThrottle = 0;
2151− table->MemoryACPILevel.EnabledForActivity = 0;
2152− table->MemoryACPILevel.UpHyst = 0;
2153− table->MemoryACPILevel.DownHyst = 100;
2154− table->MemoryACPILevel.VoltageDownHyst = 0;
2155− /* Indicates maximum activity level for this performance level.*/
2156− table->MemoryACPILevel.ActivityLevel = PP_HOST_TO_SMC_US((uint16_t)data->mclk_activity_target);
2157−
2158− table->MemoryACPILevel.StutterEnable = 0;
2159− table->MemoryACPILevel.StrobeEnable = 0;
2160− table->MemoryACPILevel.EdcReadEnable = 0;
2161− table->MemoryACPILevel.EdcWriteEnable = 0;
2162− table->MemoryACPILevel.RttEnable = 0;
2163−
2164− return result;
2165−}
2166−
2167−static int iceland_find_boot_level(struct iceland_single_dpm_table *table, uint32_t value, uint32_t *boot_level)
2168−{
2169− int result = 0;
2170− uint32_t i;
2171−
2172− for (i = 0; i < table->count; i++) {
2173− if (value == table->dpm_levels[i].value) {
2174− *boot_level = i;
2175− result = 0;
2176− }
2177− }
2178− return result;
2179−}
2180−
2181−/**
2182− * Calculates the SCLK dividers using the provided engine clock
2183− *
2184− * @param hwmgr the address of the hardware manager
2185− * @param engine_clock the engine clock to use to populate the structure
2186− * @param sclk the SMC SCLK structure to be populated
2187− */
2188−int iceland_calculate_sclk_params(struct pp_hwmgr *hwmgr,
2189− uint32_t engine_clock, SMU71_Discrete_GraphicsLevel *sclk)
2190−{
2191− const iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
2192− pp_atomctrl_clock_dividers_vi dividers;
2193− uint32_t spll_func_cntl = data->clock_registers.vCG_SPLL_FUNC_CNTL;
2194− uint32_t spll_func_cntl_3 = data->clock_registers.vCG_SPLL_FUNC_CNTL_3;
2195− uint32_t spll_func_cntl_4 = data->clock_registers.vCG_SPLL_FUNC_CNTL_4;
2196− uint32_t cg_spll_spread_spectrum = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM;
2197− uint32_t cg_spll_spread_spectrum_2 = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM_2;
2198− uint32_t reference_clock;
2199− uint32_t reference_divider;
2200− uint32_t fbdiv;
2201− int result;
2202−
2203− /* get the engine clock dividers for this clock value*/
2204− result = atomctrl_get_engine_pll_dividers_vi(hwmgr, engine_clock, &dividers);
2205−
2206− PP_ASSERT_WITH_CODE(result == 0,
2207− "Error retrieving Engine Clock dividers from VBIOS.", return result);
2208−
2209− /* To get FBDIV we need to multiply this by 16384 and divide it by Fref.*/
2210− reference_clock = atomctrl_get_reference_clock(hwmgr);
2211−
2212− reference_divider = 1 + dividers.uc_pll_ref_div;
2213−
2214− /* low 14 bits is fraction and high 12 bits is divider*/
2215− fbdiv = dividers.ul_fb_div.ul_fb_divider & 0x3FFFFFF;
2216−
2217− /* SPLL_FUNC_CNTL setup*/
2218− spll_func_cntl = PHM_SET_FIELD(spll_func_cntl,
2219− CG_SPLL_FUNC_CNTL, SPLL_REF_DIV, dividers.uc_pll_ref_div);
2220− spll_func_cntl = PHM_SET_FIELD(spll_func_cntl,
2221− CG_SPLL_FUNC_CNTL, SPLL_PDIV_A, dividers.uc_pll_post_div);
2222−
2223− /* SPLL_FUNC_CNTL_3 setup*/
2224− spll_func_cntl_3 = PHM_SET_FIELD(spll_func_cntl_3,
2225− CG_SPLL_FUNC_CNTL_3, SPLL_FB_DIV, fbdiv);
2226−
2227− /* set to use fractional accumulation*/
2228− spll_func_cntl_3 = PHM_SET_FIELD(spll_func_cntl_3,
2229− CG_SPLL_FUNC_CNTL_3, SPLL_DITHEN, 1);
2230−
2231− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2232− PHM_PlatformCaps_EngineSpreadSpectrumSupport)) {
2233− pp_atomctrl_internal_ss_info ss_info;
2234−
2235− uint32_t vcoFreq = engine_clock * dividers.uc_pll_post_div;
2236− if (0 == atomctrl_get_engine_clock_spread_spectrum(hwmgr, vcoFreq, &ss_info)) {
2237− /*
2238− * ss_info.speed_spectrum_percentage -- in unit of 0.01%
2239− * ss_info.speed_spectrum_rate -- in unit of khz
2240− */
2241− /* clks = reference_clock * 10 / (REFDIV + 1) / speed_spectrum_rate / 2 */
2242− uint32_t clkS = reference_clock * 5 / (reference_divider * ss_info.speed_spectrum_rate);
2243−
2244− /* clkv = 2 * D * fbdiv / NS */
2245− uint32_t clkV = 4 * ss_info.speed_spectrum_percentage * fbdiv / (clkS * 10000);
2246−
2247− cg_spll_spread_spectrum =
2248− PHM_SET_FIELD(cg_spll_spread_spectrum, CG_SPLL_SPREAD_SPECTRUM, CLKS, clkS);
2249− cg_spll_spread_spectrum =
2250− PHM_SET_FIELD(cg_spll_spread_spectrum, CG_SPLL_SPREAD_SPECTRUM, SSEN, 1);
2251− cg_spll_spread_spectrum_2 =
2252− PHM_SET_FIELD(cg_spll_spread_spectrum_2, CG_SPLL_SPREAD_SPECTRUM_2, CLKV, clkV);
2253− }
2254− }
2255−
2256− sclk->SclkFrequency = engine_clock;
2257− sclk->CgSpllFuncCntl3 = spll_func_cntl_3;
2258− sclk->CgSpllFuncCntl4 = spll_func_cntl_4;
2259− sclk->SpllSpreadSpectrum = cg_spll_spread_spectrum;
2260− sclk->SpllSpreadSpectrum2 = cg_spll_spread_spectrum_2;
2261− sclk->SclkDid = (uint8_t)dividers.pll_post_divider;
2262−
2263− return 0;
2264−}
2265−
2266−static uint8_t iceland_get_sleep_divider_id_from_clock(struct pp_hwmgr *hwmgr,
2267− uint32_t engine_clock, uint32_t min_engine_clock_in_sr)
2268−{
2269− uint32_t i, temp;
2270− uint32_t min = (min_engine_clock_in_sr > ICELAND_MINIMUM_ENGINE_CLOCK) ?
2271− min_engine_clock_in_sr : ICELAND_MINIMUM_ENGINE_CLOCK;
2272−
2273− PP_ASSERT_WITH_CODE((engine_clock >= min),
2274− "Engine clock can't satisfy stutter requirement!", return 0);
2275−
2276− for (i = ICELAND_MAX_DEEPSLEEP_DIVIDER_ID;; i--) {
2277− temp = engine_clock / (1 << i);
2278−
2279− if(temp >= min || i == 0)
2280− break;
2281− }
2282− return (uint8_t)i;
2283−}
2284−
2285−/**
2286− * Populates single SMC SCLK structure using the provided engine clock
2287− *
2288− * @param hwmgr the address of the hardware manager
2289− * @param engine_clock the engine clock to use to populate the structure
2290− * @param sclk the SMC SCLK structure to be populated
2291− */
2292−static int iceland_populate_single_graphic_level(struct pp_hwmgr *hwmgr,
2293− uint32_t engine_clock, uint16_t sclk_activity_level_threshold,
2294− SMU71_Discrete_GraphicsLevel *graphic_level)
2295−{
2296− int result;
2297− uint32_t threshold;
2298− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
2299−
2300− result = iceland_calculate_sclk_params(hwmgr, engine_clock, graphic_level);
2301−
2302−
2303− /* populate graphics levels*/
2304− result = iceland_get_dependecy_volt_by_clk(hwmgr,
2305− hwmgr->dyn_state.vddc_dependency_on_sclk, engine_clock, &graphic_level->MinVddc);
2306− PP_ASSERT_WITH_CODE((0 == result),
2307− "can not find VDDC voltage value for VDDC engine clock dependency table", return result);
2308−
2309− /* SCLK frequency in units of 10KHz*/
2310− graphic_level->SclkFrequency = engine_clock;
2311−
2312− /*
2313− * Minimum VDDC phases required to support this level, it
2314− * should get from dependence table.
2315− */
2316− graphic_level->MinVddcPhases = 1;
2317−
2318− if (data->vddc_phase_shed_control) {
2319− iceland_populate_phase_value_based_on_sclk(hwmgr,
2320− hwmgr->dyn_state.vddc_phase_shed_limits_table,
2321− engine_clock,
2322− &graphic_level->MinVddcPhases);
2323− }
2324−
2325− /* Indicates maximum activity level for this performance level. 50% for now*/
2326− graphic_level->ActivityLevel = sclk_activity_level_threshold;
2327−
2328− graphic_level->CcPwrDynRm = 0;
2329− graphic_level->CcPwrDynRm1 = 0;
2330− /* this level can be used if activity is high enough.*/
2331− graphic_level->EnabledForActivity = 1;
2332− /* this level can be used for throttling.*/
2333− graphic_level->EnabledForThrottle = 1;
2334− graphic_level->UpHyst = 0;
2335− graphic_level->DownHyst = 100;
2336− graphic_level->VoltageDownHyst = 0;
2337− graphic_level->PowerThrottle = 0;
2338−
2339− threshold = engine_clock * data->fast_watermark_threshold / 100;
2340−
2341− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2342− PHM_PlatformCaps_SclkDeepSleep)) {
2343− graphic_level->DeepSleepDivId =
2344− iceland_get_sleep_divider_id_from_clock(hwmgr, engine_clock,
2345− data->display_timing.min_clock_insr);
2346− }
2347−
2348− /* Default to slow, highest DPM level will be set to PPSMC_DISPLAY_WATERMARK_LOW later.*/
2349− graphic_level->DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW;
2350−
2351− if (0 == result) {
2352− graphic_level->MinVddc = PP_HOST_TO_SMC_UL(graphic_level->MinVddc * VOLTAGE_SCALE);
2353− /* CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->MinVoltage);*/
2354− CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->MinVddcPhases);
2355− CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->SclkFrequency);
2356− CONVERT_FROM_HOST_TO_SMC_US(graphic_level->ActivityLevel);
2357− CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->CgSpllFuncCntl3);
2358− CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->CgSpllFuncCntl4);
2359− CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->SpllSpreadSpectrum);
2360− CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->SpllSpreadSpectrum2);
2361− CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->CcPwrDynRm);
2362− CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->CcPwrDynRm1);
2363− }
2364−
2365− return result;
2366−}
2367−
2368−/**
2369− * Populates all SMC SCLK levels' structure based on the trimmed allowed dpm engine clock states
2370− *
2371− * @param hwmgr the address of the hardware manager
2372− */
2373−static int iceland_populate_all_graphic_levels(struct pp_hwmgr *hwmgr)
2374−{
2375− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
2376− struct iceland_dpm_table *dpm_table = &data->dpm_table;
2377− int result = 0;
2378− uint32_t level_array_adress = data->dpm_table_start +
2379− offsetof(SMU71_Discrete_DpmTable, GraphicsLevel);
2380−
2381− uint32_t level_array_size = sizeof(SMU71_Discrete_GraphicsLevel) * SMU71_MAX_LEVELS_GRAPHICS;
2382− SMU71_Discrete_GraphicsLevel *levels = data->smc_state_table.GraphicsLevel;
2383− uint32_t i;
2384− uint8_t highest_pcie_level_enabled = 0, lowest_pcie_level_enabled = 0, mid_pcie_level_enabled = 0, count = 0;
2385− memset(levels, 0x00, level_array_size);
2386−
2387− for (i = 0; i < dpm_table->sclk_table.count; i++) {
2388− result = iceland_populate_single_graphic_level(hwmgr,
2389− dpm_table->sclk_table.dpm_levels[i].value,
2390− (uint16_t)data->activity_target[i],
2391− &(data->smc_state_table.GraphicsLevel[i]));
2392− if (0 != result)
2393− return result;
2394−
2395− /* Making sure only DPM level 0-1 have Deep Sleep Div ID populated. */
2396− if (i > 1)
2397− data->smc_state_table.GraphicsLevel[i].DeepSleepDivId = 0;
2398− }
2399−
2400− /* set highest level watermark to high */
2401− if (dpm_table->sclk_table.count > 1)
2402− data->smc_state_table.GraphicsLevel[dpm_table->sclk_table.count-1].DisplayWatermark =
2403− PPSMC_DISPLAY_WATERMARK_HIGH;
2404−
2405− data->smc_state_table.GraphicsDpmLevelCount =
2406− (uint8_t)dpm_table->sclk_table.count;
2407− data->dpm_level_enable_mask.sclk_dpm_enable_mask =
2408− iceland_get_dpm_level_enable_mask_value(&dpm_table->sclk_table);
2409−
2410− while ((data->dpm_level_enable_mask.pcie_dpm_enable_mask &
2411− (1 << (highest_pcie_level_enabled + 1))) != 0) {
2412− highest_pcie_level_enabled++;
2413− }
2414−
2415− while ((data->dpm_level_enable_mask.pcie_dpm_enable_mask &
2416− (1 << lowest_pcie_level_enabled)) == 0) {
2417− lowest_pcie_level_enabled++;
2418− }
2419−
2420− while ((count < highest_pcie_level_enabled) &&
2421− ((data->dpm_level_enable_mask.pcie_dpm_enable_mask &
2422− (1 << (lowest_pcie_level_enabled + 1 + count))) == 0)) {
2423− count++;
2424− }
2425−
2426− mid_pcie_level_enabled = (lowest_pcie_level_enabled+1+count) < highest_pcie_level_enabled ?
2427− (lowest_pcie_level_enabled + 1 + count) : highest_pcie_level_enabled;
2428−
2429− /* set pcieDpmLevel to highest_pcie_level_enabled*/
2430− for (i = 2; i < dpm_table->sclk_table.count; i++) {
2431− data->smc_state_table.GraphicsLevel[i].pcieDpmLevel = highest_pcie_level_enabled;
2432− }
2433−
2434− /* set pcieDpmLevel to lowest_pcie_level_enabled*/
2435− data->smc_state_table.GraphicsLevel[0].pcieDpmLevel = lowest_pcie_level_enabled;
2436−
2437− /* set pcieDpmLevel to mid_pcie_level_enabled*/
2438− data->smc_state_table.GraphicsLevel[1].pcieDpmLevel = mid_pcie_level_enabled;
2439−
2440− /* level count will send to smc once at init smc table and never change*/
2441− result = iceland_copy_bytes_to_smc(hwmgr->smumgr, level_array_adress, (uint8_t *)levels, (uint32_t)level_array_size, data->sram_end);
2442−
2443− if (0 != result)
2444− return result;
2445−
2446− return 0;
2447−}
2448−
2449−/**
2450− * Populates all SMC MCLK levels' structure based on the trimmed allowed dpm memory clock states
2451− *
2452− * @param hwmgr the address of the hardware manager
2453− */
2454−
2455−static int iceland_populate_all_memory_levels(struct pp_hwmgr *hwmgr)
2456−{
2457− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
2458− struct iceland_dpm_table *dpm_table = &data->dpm_table;
2459− int result;
2460− /* populate MCLK dpm table to SMU7 */
2461− uint32_t level_array_adress = data->dpm_table_start + offsetof(SMU71_Discrete_DpmTable, MemoryLevel);
2462− uint32_t level_array_size = sizeof(SMU71_Discrete_MemoryLevel) * SMU71_MAX_LEVELS_MEMORY;
2463− SMU71_Discrete_MemoryLevel *levels = data->smc_state_table.MemoryLevel;
2464− uint32_t i;
2465−
2466− memset(levels, 0x00, level_array_size);
2467−
2468− for (i = 0; i < dpm_table->mclk_table.count; i++) {
2469− PP_ASSERT_WITH_CODE((0 != dpm_table->mclk_table.dpm_levels[i].value),
2470− "can not populate memory level as memory clock is zero", return -1);
2471− result = iceland_populate_single_memory_level(hwmgr, dpm_table->mclk_table.dpm_levels[i].value,
2472− &(data->smc_state_table.MemoryLevel[i]));
2473− if (0 != result) {
2474− return result;
2475− }
2476− }
2477−
2478− /* Only enable level 0 for now.*/
2479− data->smc_state_table.MemoryLevel[0].EnabledForActivity = 1;
2480−
2481− /*
2482− * in order to prevent MC activity from stutter mode to push DPM up.
2483− * the UVD change complements this by putting the MCLK in a higher state
2484− * by default such that we are not effected by up threshold or and MCLK DPM latency.
2485− */
2486− data->smc_state_table.MemoryLevel[0].ActivityLevel = 0x1F;
2487− CONVERT_FROM_HOST_TO_SMC_US(data->smc_state_table.MemoryLevel[0].ActivityLevel);
2488−
2489− data->smc_state_table.MemoryDpmLevelCount = (uint8_t)dpm_table->mclk_table.count;
2490− data->dpm_level_enable_mask.mclk_dpm_enable_mask = iceland_get_dpm_level_enable_mask_value(&dpm_table->mclk_table);
2491− /* set highest level watermark to high*/
2492− data->smc_state_table.MemoryLevel[dpm_table->mclk_table.count-1].DisplayWatermark = PPSMC_DISPLAY_WATERMARK_HIGH;
2493−
2494− /* level count will send to smc once at init smc table and never change*/
2495− result = iceland_copy_bytes_to_smc(hwmgr->smumgr,
2496− level_array_adress, (uint8_t *)levels, (uint32_t)level_array_size, data->sram_end);
2497−
2498− if (0 != result) {
2499− return result;
2500− }
2501−
2502− return 0;
2503−}
2504−
2505−struct ICELAND_DLL_SPEED_SETTING
2506−{
2507− uint16_t Min; /* Minimum Data Rate*/
2508− uint16_t Max; /* Maximum Data Rate*/
2509− uint32_t dll_speed; /* The desired DLL_SPEED setting*/
2510−};
2511−
2512−static int iceland_populate_ulv_level(struct pp_hwmgr *hwmgr, SMU71_Discrete_Ulv *pstate)
2513−{
2514− int result = 0;
2515− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
2516− uint32_t voltage_response_time, ulv_voltage;
2517−
2518− pstate->CcPwrDynRm = 0;
2519− pstate->CcPwrDynRm1 = 0;
2520−
2521− //backbiasResponseTime is use for ULV state voltage value.
2522− result = pp_tables_get_response_times(hwmgr, &voltage_response_time, &ulv_voltage);
2523− PP_ASSERT_WITH_CODE((0 == result), "can not get ULV voltage value", return result;);
2524−
2525− if(!ulv_voltage) {
2526− data->ulv.ulv_supported = false;
2527− return 0;
2528− }
2529−
2530− if (ICELAND_VOLTAGE_CONTROL_BY_SVID2 != data->voltage_control) {
2531− /* use minimum voltage if ulv voltage in pptable is bigger than minimum voltage */
2532− if (ulv_voltage > hwmgr->dyn_state.vddc_dependency_on_sclk->entries[0].v) {
2533− pstate->VddcOffset = 0;
2534− }
2535− else {
2536− /* used in SMIO Mode. not implemented for now. this is backup only for CI. */
2537− pstate->VddcOffset = (uint16_t)(hwmgr->dyn_state.vddc_dependency_on_sclk->entries[0].v - ulv_voltage);
2538− }
2539− } else {
2540− /* use minimum voltage if ulv voltage in pptable is bigger than minimum voltage */
2541− if(ulv_voltage > hwmgr->dyn_state.vddc_dependency_on_sclk->entries[0].v) {
2542− pstate->VddcOffsetVid = 0;
2543− } else {
2544− /* used in SVI2 Mode */
2545− pstate->VddcOffsetVid = (uint8_t)((hwmgr->dyn_state.vddc_dependency_on_sclk->entries[0].v - ulv_voltage) * VOLTAGE_VID_OFFSET_SCALE2 / VOLTAGE_VID_OFFSET_SCALE1);
2546− }
2547− }
2548−
2549− /* used in SVI2 Mode to shed phase */
2550− pstate->VddcPhase = (data->vddc_phase_shed_control) ? 0 : 1;
2551−
2552− if (0 == result) {
2553− CONVERT_FROM_HOST_TO_SMC_UL(pstate->CcPwrDynRm);
2554− CONVERT_FROM_HOST_TO_SMC_UL(pstate->CcPwrDynRm1);
2555− CONVERT_FROM_HOST_TO_SMC_US(pstate->VddcOffset);
2556− }
2557−
2558− return result;
2559−}
2560−
2561−static int iceland_populate_ulv_state(struct pp_hwmgr *hwmgr, SMU71_Discrete_Ulv *ulv)
2562−{
2563− return iceland_populate_ulv_level(hwmgr, ulv);
2564−}
2565−
2566−static int iceland_populate_smc_initial_state(struct pp_hwmgr *hwmgr)
2567−{
2568− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
2569− uint8_t count, level;
2570−
2571− count = (uint8_t)(hwmgr->dyn_state.vddc_dependency_on_sclk->count);
2572−
2573− for (level = 0; level < count; level++) {
2574− if (hwmgr->dyn_state.vddc_dependency_on_sclk->entries[level].clk
2575− >= data->vbios_boot_state.sclk_bootup_value) {
2576− data->smc_state_table.GraphicsBootLevel = level;
2577− break;
2578− }
2579− }
2580−
2581− count = (uint8_t)(hwmgr->dyn_state.vddc_dependency_on_mclk->count);
2582−
2583− for (level = 0; level < count; level++) {
2584− if (hwmgr->dyn_state.vddc_dependency_on_mclk->entries[level].clk
2585− >= data->vbios_boot_state.mclk_bootup_value) {
2586− data->smc_state_table.MemoryBootLevel = level;
2587− break;
2588− }
2589− }
2590−
2591− return 0;
2592−}
2593−
2594−/**
2595− * Initializes the SMC table and uploads it
2596− *
2597− * @param hwmgr the address of the powerplay hardware manager.
2598− * @param pInput the pointer to input data (PowerState)
2599− * @return always 0
2600− */
2601−static int iceland_init_smc_table(struct pp_hwmgr *hwmgr)
2602−{
2603− int result;
2604− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
2605− SMU71_Discrete_DpmTable *table = &(data->smc_state_table);
2606− const struct phw_iceland_ulv_parm *ulv = &(data->ulv);
2607−
2608− result = iceland_setup_default_dpm_tables(hwmgr);
2609− PP_ASSERT_WITH_CODE(0 == result,
2610− "Failed to setup default DPM tables!", return result;);
2611− memset(&(data->smc_state_table), 0x00, sizeof(data->smc_state_table));
2612−
2613− if (ICELAND_VOLTAGE_CONTROL_NONE != data->voltage_control) {
2614− iceland_populate_smc_voltage_tables(hwmgr, table);
2615− }
2616−
2617− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2618− PHM_PlatformCaps_AutomaticDCTransition)) {
2619− table->SystemFlags |= PPSMC_SYSTEMFLAG_GPIO_DC;
2620− }
2621−
2622− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2623− PHM_PlatformCaps_StepVddc)) {
2624− table->SystemFlags |= PPSMC_SYSTEMFLAG_STEPVDDC;
2625− }
2626−
2627− if (data->is_memory_GDDR5) {
2628− table->SystemFlags |= PPSMC_SYSTEMFLAG_GDDR5;
2629− }
2630−
2631− if (ulv->ulv_supported) {
2632− result = iceland_populate_ulv_state(hwmgr, &data->ulv_setting);
2633− PP_ASSERT_WITH_CODE(0 == result,
2634− "Failed to initialize ULV state!", return result;);
2635−
2636− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
2637− ixCG_ULV_PARAMETER, ulv->ch_ulv_parameter);
2638− }
2639−
2640− result = iceland_populate_smc_link_level(hwmgr, table);
2641− PP_ASSERT_WITH_CODE(0 == result,
2642− "Failed to initialize Link Level!", return result;);
2643−
2644− result = iceland_populate_all_graphic_levels(hwmgr);
2645− PP_ASSERT_WITH_CODE(0 == result,
2646− "Failed to initialize Graphics Level!", return result;);
2647−
2648− result = iceland_populate_all_memory_levels(hwmgr);
2649− PP_ASSERT_WITH_CODE(0 == result,
2650− "Failed to initialize Memory Level!", return result;);
2651−
2652− result = iceland_populate_smc_acpi_level(hwmgr, table);
2653− PP_ASSERT_WITH_CODE(0 == result,
2654− "Failed to initialize ACPI Level!", return result;);
2655−
2656− result = iceland_populate_smc_vce_level(hwmgr, table);
2657− PP_ASSERT_WITH_CODE(0 == result,
2658− "Failed to initialize VCE Level!", return result;);
2659−
2660− result = iceland_populate_smc_acp_level(hwmgr, table);
2661− PP_ASSERT_WITH_CODE(0 == result,
2662− "Failed to initialize ACP Level!", return result;);
2663−
2664− result = iceland_populate_smc_samu_level(hwmgr, table);
2665− PP_ASSERT_WITH_CODE(0 == result,
2666− "Failed to initialize SAMU Level!", return result;);
2667−
2668− /*
2669− * Since only the initial state is completely set up at this
2670− * point (the other states are just copies of the boot state)
2671− * we only need to populate the ARB settings for the initial
2672− * state.
2673− */
2674− result = iceland_program_memory_timing_parameters(hwmgr);
2675− PP_ASSERT_WITH_CODE(0 == result,
2676− "Failed to Write ARB settings for the initial state.", return result;);
2677−
2678− result = iceland_populate_smc_uvd_level(hwmgr, table);
2679− PP_ASSERT_WITH_CODE(0 == result,
2680− "Failed to initialize UVD Level!", return result;);
2681−
2682− table->GraphicsBootLevel = 0;
2683− table->MemoryBootLevel = 0;
2684−
2685− /* find boot level from dpm table */
2686− result = iceland_find_boot_level(&(data->dpm_table.sclk_table),
2687− data->vbios_boot_state.sclk_bootup_value,
2688− (uint32_t *)&(data->smc_state_table.GraphicsBootLevel));
2689−
2690− if (result)
2691− pr_warning("VBIOS did not find boot engine clock value in dependency table.\n");
2692−
2693− result = iceland_find_boot_level(&(data->dpm_table.mclk_table),
2694− data->vbios_boot_state.mclk_bootup_value,
2695− (uint32_t *)&(data->smc_state_table.MemoryBootLevel));
2696−
2697− if (result)
2698− pr_warning("VBIOS did not find boot memory clock value in dependency table.\n");
2699−
2700− table->BootVddc = data->vbios_boot_state.vddc_bootup_value;
2701− if (ICELAND_VOLTAGE_CONTROL_NONE == data->vdd_ci_control) {
2702− table->BootVddci = table->BootVddc;
2703− }
2704− else {
2705− table->BootVddci = data->vbios_boot_state.vddci_bootup_value;
2706− }
2707− table->BootMVdd = data->vbios_boot_state.mvdd_bootup_value;
2708−
2709− result = iceland_populate_smc_initial_state(hwmgr);
2710− PP_ASSERT_WITH_CODE(0 == result, "Failed to initialize Boot State!", return result);
2711−
2712− result = iceland_populate_bapm_parameters_in_dpm_table(hwmgr);
2713− PP_ASSERT_WITH_CODE(0 == result, "Failed to populate BAPM Parameters!", return result);
2714−
2715− table->GraphicsVoltageChangeEnable = 1;
2716− table->GraphicsThermThrottleEnable = 1;
2717− table->GraphicsInterval = 1;
2718− table->VoltageInterval = 1;
2719− table->ThermalInterval = 1;
2720− table->TemperatureLimitHigh =
2721− (data->thermal_temp_setting.temperature_high *
2722− ICELAND_Q88_FORMAT_CONVERSION_UNIT) / PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
2723− table->TemperatureLimitLow =
2724− (data->thermal_temp_setting.temperature_low *
2725− ICELAND_Q88_FORMAT_CONVERSION_UNIT) / PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
2726− table->MemoryVoltageChangeEnable = 1;
2727− table->MemoryInterval = 1;
2728− table->VoltageResponseTime = 0;
2729− table->PhaseResponseTime = 0;
2730− table->MemoryThermThrottleEnable = 1;
2731− table->PCIeBootLinkLevel = 0;
2732− table->PCIeGenInterval = 1;
2733−
2734− result = iceland_populate_smc_svi2_config(hwmgr, table);
2735− PP_ASSERT_WITH_CODE(0 == result,
2736− "Failed to populate SVI2 setting!", return result);
2737−
2738− table->ThermGpio = 17;
2739− table->SclkStepSize = 0x4000;
2740−
2741− CONVERT_FROM_HOST_TO_SMC_UL(table->SystemFlags);
2742− CONVERT_FROM_HOST_TO_SMC_UL(table->SmioMaskVddcVid);
2743− CONVERT_FROM_HOST_TO_SMC_UL(table->SmioMaskVddcPhase);
2744− CONVERT_FROM_HOST_TO_SMC_UL(table->SmioMaskVddciVid);
2745− CONVERT_FROM_HOST_TO_SMC_UL(table->SmioMaskMvddVid);
2746− CONVERT_FROM_HOST_TO_SMC_UL(table->SclkStepSize);
2747− CONVERT_FROM_HOST_TO_SMC_US(table->TemperatureLimitHigh);
2748− CONVERT_FROM_HOST_TO_SMC_US(table->TemperatureLimitLow);
2749− CONVERT_FROM_HOST_TO_SMC_US(table->VoltageResponseTime);
2750− CONVERT_FROM_HOST_TO_SMC_US(table->PhaseResponseTime);
2751−
2752− table->BootVddc = PP_HOST_TO_SMC_US(table->BootVddc * VOLTAGE_SCALE);
2753− table->BootVddci = PP_HOST_TO_SMC_US(table->BootVddci * VOLTAGE_SCALE);
2754− table->BootMVdd = PP_HOST_TO_SMC_US(table->BootMVdd * VOLTAGE_SCALE);
2755−
2756− /* Upload all dpm data to SMC memory.(dpm level, dpm level count etc) */
2757− result = iceland_copy_bytes_to_smc(hwmgr->smumgr, data->dpm_table_start +
2758− offsetof(SMU71_Discrete_DpmTable, SystemFlags),
2759− (uint8_t *)&(table->SystemFlags),
2760− sizeof(SMU71_Discrete_DpmTable) - 3 * sizeof(SMU71_PIDController),
2761− data->sram_end);
2762−
2763− PP_ASSERT_WITH_CODE(0 == result,
2764− "Failed to upload dpm data to SMC memory!", return result);
2765−
2766− /* Upload all ulv setting to SMC memory.(dpm level, dpm level count etc) */
2767− result = iceland_copy_bytes_to_smc(hwmgr->smumgr,
2768− data->ulv_settings_start,
2769− (uint8_t *)&(data->ulv_setting),
2770− sizeof(SMU71_Discrete_Ulv),
2771− data->sram_end);
2772−
2773−#if 0
2774− /* Notify SMC to follow new GPIO scheme */
2775− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2776− PHM_PlatformCaps_AutomaticDCTransition)) {
2777− if (0 == iceland_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_UseNewGPIOScheme))
2778− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2779− PHM_PlatformCaps_SMCtoPPLIBAcdcGpioScheme);
2780− }
2781−#endif
2782−
2783− return result;
2784−}
2785−
2786−int iceland_populate_mc_reg_address(struct pp_hwmgr *hwmgr, SMU71_Discrete_MCRegisters *mc_reg_table)
2787−{
2788− const struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
2789−
2790− uint32_t i, j;
2791−
2792− for (i = 0, j = 0; j < data->iceland_mc_reg_table.last; j++) {
2793− if (data->iceland_mc_reg_table.validflag & 1<<j) {
2794− PP_ASSERT_WITH_CODE(i < SMU71_DISCRETE_MC_REGISTER_ARRAY_SIZE,
2795− "Index of mc_reg_table->address[] array out of boundary", return -1);
2796− mc_reg_table->address[i].s0 =
2797− PP_HOST_TO_SMC_US(data->iceland_mc_reg_table.mc_reg_address[j].s0);
2798− mc_reg_table->address[i].s1 =
2799− PP_HOST_TO_SMC_US(data->iceland_mc_reg_table.mc_reg_address[j].s1);
2800− i++;
2801− }
2802− }
2803−
2804− mc_reg_table->last = (uint8_t)i;
2805−
2806− return 0;
2807−}
2808−
2809−/* convert register values from driver to SMC format */
2810−void iceland_convert_mc_registers(
2811− const phw_iceland_mc_reg_entry * pEntry,
2812− SMU71_Discrete_MCRegisterSet *pData,
2813− uint32_t numEntries, uint32_t validflag)
2814−{
2815− uint32_t i, j;
2816−
2817− for (i = 0, j = 0; j < numEntries; j++) {
2818− if (validflag & 1<<j) {
2819− pData->value[i] = PP_HOST_TO_SMC_UL(pEntry->mc_data[j]);
2820− i++;
2821− }
2822− }
2823−}
2824−
2825−/* find the entry in the memory range table, then populate the value to SMC's iceland_mc_reg_table */
2826−int iceland_convert_mc_reg_table_entry_to_smc(
2827− struct pp_hwmgr *hwmgr,
2828− const uint32_t memory_clock,
2829− SMU71_Discrete_MCRegisterSet *mc_reg_table_data
2830− )
2831−{
2832− const iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
2833− uint32_t i = 0;
2834−
2835− for (i = 0; i < data->iceland_mc_reg_table.num_entries; i++) {
2836− if (memory_clock <=
2837− data->iceland_mc_reg_table.mc_reg_table_entry[i].mclk_max) {
2838− break;
2839− }
2840− }
2841−
2842− if ((i == data->iceland_mc_reg_table.num_entries) && (i > 0))
2843− --i;
2844−
2845− iceland_convert_mc_registers(&data->iceland_mc_reg_table.mc_reg_table_entry[i],
2846− mc_reg_table_data, data->iceland_mc_reg_table.last, data->iceland_mc_reg_table.validflag);
2847−
2848− return 0;
2849−}
2850−
2851−int iceland_convert_mc_reg_table_to_smc(struct pp_hwmgr *hwmgr,
2852− SMU71_Discrete_MCRegisters *mc_reg_table)
2853−{
2854− int result = 0;
2855− iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
2856− int res;
2857− uint32_t i;
2858−
2859− for (i = 0; i < data->dpm_table.mclk_table.count; i++) {
2860− res = iceland_convert_mc_reg_table_entry_to_smc(
2861− hwmgr,
2862− data->dpm_table.mclk_table.dpm_levels[i].value,
2863− &mc_reg_table->data[i]
2864− );
2865−
2866− if (0 != res)
2867− result = res;
2868− }
2869−
2870− return result;
2871−}
2872−
2873−int iceland_populate_initial_mc_reg_table(struct pp_hwmgr *hwmgr)
2874−{
2875− int result;
2876− struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
2877−
2878− memset(&data->mc_reg_table, 0x00, sizeof(SMU71_Discrete_MCRegisters));
2879− result = iceland_populate_mc_reg_address(hwmgr, &(data->mc_reg_table));
2880− PP_ASSERT_WITH_CODE(0 == result,
2881− "Failed to initialize MCRegTable for the MC register addresses!", return result;);
2882−
2883− result = iceland_convert_mc_reg_table_to_smc(hwmgr, &data->mc_reg_table);
2884− PP_ASSERT_WITH_CODE(0 == result,
2885− "Failed to initialize MCRegTable for driver state!", return result;);
2886−
2887− return iceland_copy_bytes_to_smc(hwmgr->smumgr, data->mc_reg_table_start,
2888− (uint8_t *)&data->mc_reg_table, sizeof(SMU71_Discrete_MCRegisters), data->sram_end);
2889−}
2890−
2891−int iceland_notify_smc_display_change(struct pp_hwmgr *hwmgr, bool has_display)
2892−{
2893− PPSMC_Msg msg = has_display? (PPSMC_Msg)PPSMC_HasDisplay : (PPSMC_Msg)PPSMC_NoDisplay;
2894−
2895− return (smum_send_msg_to_smc(hwmgr->smumgr, msg) == 0) ? 0 : -1;
2896−}
2897−
2898−int iceland_enable_sclk_control(struct pp_hwmgr *hwmgr)
2899−{
2900− PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL, SCLK_PWRMGT_OFF, 0);
2901−
2902− return 0;
2903−}
2904−
2905−int iceland_enable_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
2906−{
2907− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
2908−
2909− /* enable SCLK dpm */
2910− if (0 == data->sclk_dpm_key_disabled) {
2911− PP_ASSERT_WITH_CODE(
2912− (0 == smum_send_msg_to_smc(hwmgr->smumgr,
2913− PPSMC_MSG_DPM_Enable)),
2914− "Failed to enable SCLK DPM during DPM Start Function!",
2915− return -1);
2916− }
2917−
2918− /* enable MCLK dpm */
2919− if (0 == data->mclk_dpm_key_disabled) {
2920− PP_ASSERT_WITH_CODE(
2921− (0 == smum_send_msg_to_smc(hwmgr->smumgr,
2922− PPSMC_MSG_MCLKDPM_Enable)),
2923− "Failed to enable MCLK DPM during DPM Start Function!",
2924− return -1);
2925−
2926− PHM_WRITE_FIELD(hwmgr->device, MC_SEQ_CNTL_3, CAC_EN, 0x1);
2927−
2928− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
2929− ixLCAC_MC0_CNTL, 0x05);/* CH0,1 read */
2930− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
2931− ixLCAC_MC1_CNTL, 0x05);/* CH2,3 read */
2932− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
2933− ixLCAC_CPL_CNTL, 0x100005);/*Read */
2934−
2935− udelay(10);
2936−
2937− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
2938− ixLCAC_MC0_CNTL, 0x400005);/* CH0,1 write */
2939− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
2940− ixLCAC_MC1_CNTL, 0x400005);/* CH2,3 write */
2941− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
2942− ixLCAC_CPL_CNTL, 0x500005);/* write */
2943−
2944− }
2945−
2946− return 0;
2947−}
2948−
2949−int iceland_start_dpm(struct pp_hwmgr *hwmgr)
2950−{
2951− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
2952−
2953− /* enable general power management */
2954− PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT, GLOBAL_PWRMGT_EN, 1);
2955− /* enable sclk deep sleep */
2956− PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL, DYNAMIC_PM_EN, 1);
2957−
2958− /* prepare for PCIE DPM */
2959− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SOFT_REGISTERS_TABLE_12, VoltageChangeTimeout, 0x1000);
2960−
2961− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__PCIE, SWRST_COMMAND_1, RESETLC, 0x0);
2962−
2963− PP_ASSERT_WITH_CODE(
2964− (0 == smum_send_msg_to_smc(hwmgr->smumgr,
2965− PPSMC_MSG_Voltage_Cntl_Enable)),
2966− "Failed to enable voltage DPM during DPM Start Function!",
2967− return -1);
2968−
2969− if (0 != iceland_enable_sclk_mclk_dpm(hwmgr)) {
2970− PP_ASSERT_WITH_CODE(0, "Failed to enable Sclk DPM and Mclk DPM!", return -1);
2971− }
2972−
2973− /* enable PCIE dpm */
2974− if (0 == data->pcie_dpm_key_disabled) {
2975− PP_ASSERT_WITH_CODE(
2976− (0 == smum_send_msg_to_smc(hwmgr->smumgr,
2977− PPSMC_MSG_PCIeDPM_Enable)),
2978− "Failed to enable pcie DPM during DPM Start Function!",
2979− return -1
2980− );
2981− }
2982−
2983− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2984− PHM_PlatformCaps_Falcon_QuickTransition)) {
2985− smum_send_msg_to_smc(hwmgr->smumgr,
2986− PPSMC_MSG_EnableACDCGPIOInterrupt);
2987− }
2988−
2989− return 0;
2990−}
2991−
2992−static void iceland_set_dpm_event_sources(struct pp_hwmgr *hwmgr,
2993− uint32_t sources)
2994−{
2995− bool protection;
2996− enum DPM_EVENT_SRC src;
2997−
2998− switch (sources) {
2999− default:
3000− printk(KERN_ERR "Unknown throttling event sources.");
3001− /* fall through */
3002− case 0:
3003− protection = false;
3004− /* src is unused */
3005− break;
3006− case (1 << PHM_AutoThrottleSource_Thermal):
3007− protection = true;
3008− src = DPM_EVENT_SRC_DIGITAL;
3009− break;
3010− case (1 << PHM_AutoThrottleSource_External):
3011− protection = true;
3012− src = DPM_EVENT_SRC_EXTERNAL;
3013− break;
3014− case (1 << PHM_AutoThrottleSource_External) |
3015− (1 << PHM_AutoThrottleSource_Thermal):
3016− protection = true;
3017− src = DPM_EVENT_SRC_DIGITAL_OR_EXTERNAL;
3018− break;
3019− }
3020− /* Order matters - don't enable thermal protection for the wrong source. */
3021− if (protection) {
3022− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_THERMAL_CTRL,
3023− DPM_EVENT_SRC, src);
3024− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
3025− THERMAL_PROTECTION_DIS,
3026− !phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3027− PHM_PlatformCaps_ThermalController));
3028− } else
3029− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
3030− THERMAL_PROTECTION_DIS, 1);
3031−}
3032−
3033−static int iceland_enable_auto_throttle_source(struct pp_hwmgr *hwmgr,
3034− PHM_AutoThrottleSource source)
3035−{
3036− struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
3037−
3038− if (!(data->active_auto_throttle_sources & (1 << source))) {
3039− data->active_auto_throttle_sources |= 1 << source;
3040− iceland_set_dpm_event_sources(hwmgr, data->active_auto_throttle_sources);
3041− }
3042− return 0;
3043−}
3044−
3045−static int iceland_enable_thermal_auto_throttle(struct pp_hwmgr *hwmgr)
3046−{
3047− return iceland_enable_auto_throttle_source(hwmgr, PHM_AutoThrottleSource_Thermal);
3048−}
3049−
3050−static int iceland_tf_start_smc(struct pp_hwmgr *hwmgr)
3051−{
3052− int ret = 0;
3053−
3054− if (!iceland_is_smc_ram_running(hwmgr->smumgr))
3055− ret = iceland_smu_start_smc(hwmgr->smumgr);
3056−
3057− return ret;
3058−}
3059−
3060−/**
3061−* Programs the Deep Sleep registers
3062−*
3063−* @param pHwMgr the address of the powerplay hardware manager.
3064−* @param pInput the pointer to input data (PhwEvergreen_DisplayConfiguration)
3065−* @param pOutput the pointer to output data (unused)
3066−* @param pStorage the pointer to temporary storage (unused)
3067−* @param Result the last failure code (unused)
3068−* @return always 0
3069−*/
3070−static int iceland_enable_deep_sleep_master_switch(struct pp_hwmgr *hwmgr)
3071−{
3072− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3073− PHM_PlatformCaps_SclkDeepSleep)) {
3074− if (smum_send_msg_to_smc(hwmgr->smumgr,
3075− PPSMC_MSG_MASTER_DeepSleep_ON) != 0)
3076− PP_ASSERT_WITH_CODE(false,
3077− "Attempt to enable Master Deep Sleep switch failed!",
3078− return -EINVAL);
3079− } else {
3080− if (smum_send_msg_to_smc(hwmgr->smumgr,
3081− PPSMC_MSG_MASTER_DeepSleep_OFF) != 0)
3082− PP_ASSERT_WITH_CODE(false,
3083− "Attempt to disable Master Deep Sleep switch failed!",
3084− return -EINVAL);
3085− }
3086−
3087− return 0;
3088−}
3089−
3090−static int iceland_enable_dpm_tasks(struct pp_hwmgr *hwmgr)
3091−{
3092− int tmp_result, result = 0;
3093−
3094− if (cf_iceland_voltage_control(hwmgr)) {
3095− tmp_result = iceland_enable_voltage_control(hwmgr);
3096− PP_ASSERT_WITH_CODE((0 == tmp_result),
3097− "Failed to enable voltage control!", return tmp_result);
3098−
3099− tmp_result = iceland_construct_voltage_tables(hwmgr);
3100− PP_ASSERT_WITH_CODE((0 == tmp_result),
3101− "Failed to contruct voltage tables!", return tmp_result);
3102− }
3103−
3104− tmp_result = iceland_initialize_mc_reg_table(hwmgr);
3105− PP_ASSERT_WITH_CODE((0 == tmp_result),
3106− "Failed to initialize MC reg table!", return tmp_result);
3107−
3108− tmp_result = iceland_program_static_screen_threshold_parameters(hwmgr);
3109− PP_ASSERT_WITH_CODE((0 == tmp_result),
3110− "Failed to program static screen threshold parameters!", return tmp_result);
3111−
3112− tmp_result = iceland_enable_display_gap(hwmgr);
3113− PP_ASSERT_WITH_CODE((0 == tmp_result),
3114− "Failed to enable display gap!", return tmp_result);
3115−
3116− tmp_result = iceland_program_voting_clients(hwmgr);
3117− PP_ASSERT_WITH_CODE((0 == tmp_result),
3118− "Failed to program voting clients!", return tmp_result);
3119−
3120− tmp_result = iceland_upload_firmware(hwmgr);
3121− PP_ASSERT_WITH_CODE((0 == tmp_result),
3122− "Failed to upload firmware header!", return tmp_result);
3123−
3124− tmp_result = iceland_process_firmware_header(hwmgr);
3125− PP_ASSERT_WITH_CODE((0 == tmp_result),
3126− "Failed to process firmware header!", return tmp_result);
3127−
3128− tmp_result = iceland_initial_switch_from_arb_f0_to_f1(hwmgr);
3129− PP_ASSERT_WITH_CODE((0 == tmp_result),
3130− "Failed to initialize switch from ArbF0 to F1!", return tmp_result);
3131−
3132− tmp_result = iceland_init_smc_table(hwmgr);
3133− PP_ASSERT_WITH_CODE((0 == tmp_result),
3134− "Failed to initialize SMC table!", return tmp_result);
3135−
3136− tmp_result = iceland_populate_initial_mc_reg_table(hwmgr);
3137− PP_ASSERT_WITH_CODE((0 == tmp_result),
3138− "Failed to populate initialize MC Reg table!", return tmp_result);
3139−
3140− tmp_result = iceland_populate_pm_fuses(hwmgr);
3141− PP_ASSERT_WITH_CODE((0 == tmp_result),
3142− "Failed to populate PM fuses!", return tmp_result);
3143−
3144− /* start SMC */
3145− tmp_result = iceland_tf_start_smc(hwmgr);
3146− PP_ASSERT_WITH_CODE((0 == tmp_result),
3147− "Failed to start SMC!", return tmp_result);
3148−
3149− /* enable SCLK control */
3150− tmp_result = iceland_enable_sclk_control(hwmgr);
3151− PP_ASSERT_WITH_CODE((0 == tmp_result),
3152− "Failed to enable SCLK control!", return tmp_result);
3153−
3154− tmp_result = iceland_enable_deep_sleep_master_switch(hwmgr);
3155− PP_ASSERT_WITH_CODE((tmp_result == 0),
3156− "Failed to enable deep sleep!", return tmp_result);
3157−
3158− /* enable DPM */
3159− tmp_result = iceland_start_dpm(hwmgr);
3160− PP_ASSERT_WITH_CODE((0 == tmp_result),
3161− "Failed to start DPM!", return tmp_result);
3162−
3163− tmp_result = iceland_enable_smc_cac(hwmgr);
3164− PP_ASSERT_WITH_CODE((0 == tmp_result),
3165− "Failed to enable SMC CAC!", return tmp_result);
3166−
3167− tmp_result = iceland_enable_power_containment(hwmgr);
3168− PP_ASSERT_WITH_CODE((0 == tmp_result),
3169− "Failed to enable power containment!", return tmp_result);
3170−
3171− tmp_result = iceland_power_control_set_level(hwmgr);
3172− PP_ASSERT_WITH_CODE((0 == tmp_result),
3173− "Failed to power control set level!", result = tmp_result);
3174−
3175− tmp_result = iceland_enable_thermal_auto_throttle(hwmgr);
3176− PP_ASSERT_WITH_CODE((0 == tmp_result),
3177− "Failed to enable thermal auto throttle!", result = tmp_result);
3178−
3179− return result;
3180−}
3181−
3182−static int iceland_hwmgr_backend_fini(struct pp_hwmgr *hwmgr)
3183−{
3184− return phm_hwmgr_backend_fini(hwmgr);
3185−}
3186−
3187−static void iceland_initialize_dpm_defaults(struct pp_hwmgr *hwmgr)
3188−{
3189− iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
3190− struct phw_iceland_ulv_parm *ulv;
3191−
3192− ulv = &data->ulv;
3193− ulv->ch_ulv_parameter = PPICELAND_CGULVPARAMETER_DFLT;
3194− data->voting_rights_clients0 = PPICELAND_VOTINGRIGHTSCLIENTS_DFLT0;
3195− data->voting_rights_clients1 = PPICELAND_VOTINGRIGHTSCLIENTS_DFLT1;
3196− data->voting_rights_clients2 = PPICELAND_VOTINGRIGHTSCLIENTS_DFLT2;
3197− data->voting_rights_clients3 = PPICELAND_VOTINGRIGHTSCLIENTS_DFLT3;
3198− data->voting_rights_clients4 = PPICELAND_VOTINGRIGHTSCLIENTS_DFLT4;
3199− data->voting_rights_clients5 = PPICELAND_VOTINGRIGHTSCLIENTS_DFLT5;
3200− data->voting_rights_clients6 = PPICELAND_VOTINGRIGHTSCLIENTS_DFLT6;
3201− data->voting_rights_clients7 = PPICELAND_VOTINGRIGHTSCLIENTS_DFLT7;
3202−
3203− data->static_screen_threshold_unit = PPICELAND_STATICSCREENTHRESHOLDUNIT_DFLT;
3204− data->static_screen_threshold = PPICELAND_STATICSCREENTHRESHOLD_DFLT;
3205−
3206− phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
3207− PHM_PlatformCaps_ABM);
3208− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3209− PHM_PlatformCaps_NonABMSupportInPPLib);
3210−
3211− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3212− PHM_PlatformCaps_DynamicACTiming);
3213−
3214− phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
3215− PHM_PlatformCaps_DisableMemoryTransition);
3216−
3217− iceland_initialize_power_tune_defaults(hwmgr);
3218−
3219− data->mclk_strobe_mode_threshold = 40000;
3220− data->mclk_stutter_mode_threshold = 30000;
3221− data->mclk_edc_enable_threshold = 40000;
3222− data->mclk_edc_wr_enable_threshold = 40000;
3223−
3224− phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
3225− PHM_PlatformCaps_DisableMCLS);
3226−
3227− data->pcie_gen_performance.max = PP_PCIEGen1;
3228− data->pcie_gen_performance.min = PP_PCIEGen3;
3229− data->pcie_gen_power_saving.max = PP_PCIEGen1;
3230− data->pcie_gen_power_saving.min = PP_PCIEGen3;
3231−
3232− data->pcie_lane_performance.max = 0;
3233− data->pcie_lane_performance.min = 16;
3234− data->pcie_lane_power_saving.max = 0;
3235− data->pcie_lane_power_saving.min = 16;
3236−
3237− phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
3238− PHM_PlatformCaps_SclkThrottleLowNotification);
3239−}
3240−
3241−static int iceland_get_evv_voltage(struct pp_hwmgr *hwmgr)
3242−{
3243− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
3244− uint16_t virtual_voltage_id;
3245− uint16_t vddc = 0;
3246− uint16_t i;
3247−
3248− /* the count indicates actual number of entries */
3249− data->vddc_leakage.count = 0;
3250− data->vddci_leakage.count = 0;
3251−
3252− if (!phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_EVV)) {
3253− pr_err("Iceland should always support EVV\n");
3254− return -EINVAL;
3255− }
3256−
3257− /* retrieve voltage for leakage ID (0xff01 + i) */
3258− for (i = 0; i < ICELAND_MAX_LEAKAGE_COUNT; i++) {
3259− virtual_voltage_id = ATOM_VIRTUAL_VOLTAGE_ID0 + i;
3260−
3261− PP_ASSERT_WITH_CODE((0 == atomctrl_get_voltage_evv(hwmgr, virtual_voltage_id, &vddc)),
3262− "Error retrieving EVV voltage value!\n", continue);
3263−
3264− if (vddc >= 2000)
3265− pr_warning("Invalid VDDC value!\n");
3266−
3267− if (vddc != 0 && vddc != virtual_voltage_id) {
3268− data->vddc_leakage.actual_voltage[data->vddc_leakage.count] = vddc;
3269− data->vddc_leakage.leakage_id[data->vddc_leakage.count] = virtual_voltage_id;
3270− data->vddc_leakage.count++;
3271− }
3272− }
3273−
3274− return 0;
3275−}
3276−
3277−static void iceland_patch_with_vddc_leakage(struct pp_hwmgr *hwmgr,
3278− uint32_t *vddc)
3279−{
3280− iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
3281− uint32_t leakage_index;
3282− struct phw_iceland_leakage_voltage *leakage_table = &data->vddc_leakage;
3283−
3284− /* search for leakage voltage ID 0xff01 ~ 0xff08 */
3285− for (leakage_index = 0; leakage_index < leakage_table->count; leakage_index++) {
3286− /*
3287− * If this voltage matches a leakage voltage ID, patch
3288− * with actual leakage voltage.
3289− */
3290− if (leakage_table->leakage_id[leakage_index] == *vddc) {
3291− /*
3292− * Need to make sure vddc is less than 2v or
3293− * else, it could burn the ASIC.
3294− */
3295− if (leakage_table->actual_voltage[leakage_index] >= 2000)
3296− pr_warning("Invalid VDDC value!\n");
3297− *vddc = leakage_table->actual_voltage[leakage_index];
3298− /* we found leakage voltage */
3299− break;
3300− }
3301− }
3302−
3303− if (*vddc >= ATOM_VIRTUAL_VOLTAGE_ID0)
3304− pr_warning("Voltage value looks like a Leakage ID but it's not patched\n");
3305−}
3306−
3307−static void iceland_patch_with_vddci_leakage(struct pp_hwmgr *hwmgr,
3308− uint32_t *vddci)
3309−{
3310− iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
3311− uint32_t leakage_index;
3312− struct phw_iceland_leakage_voltage *leakage_table = &data->vddci_leakage;
3313−
3314− /* search for leakage voltage ID 0xff01 ~ 0xff08 */
3315− for (leakage_index = 0; leakage_index < leakage_table->count; leakage_index++) {
3316− /*
3317− * If this voltage matches a leakage voltage ID, patch
3318− * with actual leakage voltage.
3319− */
3320− if (leakage_table->leakage_id[leakage_index] == *vddci) {
3321− *vddci = leakage_table->actual_voltage[leakage_index];
3322− /* we found leakage voltage */
3323− break;
3324− }
3325− }
3326−
3327− if (*vddci >= ATOM_VIRTUAL_VOLTAGE_ID0)
3328− pr_warning("Voltage value looks like a Leakage ID but it's not patched\n");
3329−}
3330−
3331−static int iceland_patch_vddc(struct pp_hwmgr *hwmgr,
3332− struct phm_clock_voltage_dependency_table *tab)
3333−{
3334− uint16_t i;
3335−
3336− if (tab)
3337− for (i = 0; i < tab->count; i++)
3338− iceland_patch_with_vddc_leakage(hwmgr, &tab->entries[i].v);
3339−
3340− return 0;
3341−}
3342−
3343−static int iceland_patch_vddci(struct pp_hwmgr *hwmgr,
3344− struct phm_clock_voltage_dependency_table *tab)
3345−{
3346− uint16_t i;
3347−
3348− if (tab)
3349− for (i = 0; i < tab->count; i++)
3350− iceland_patch_with_vddci_leakage(hwmgr, &tab->entries[i].v);
3351−
3352− return 0;
3353−}
3354−
3355−static int iceland_patch_vce_vddc(struct pp_hwmgr *hwmgr,
3356− struct phm_vce_clock_voltage_dependency_table *tab)
3357−{
3358− uint16_t i;
3359−
3360− if (tab)
3361− for (i = 0; i < tab->count; i++)
3362− iceland_patch_with_vddc_leakage(hwmgr, &tab->entries[i].v);
3363−
3364− return 0;
3365−}
3366−
3367−
3368−static int iceland_patch_uvd_vddc(struct pp_hwmgr *hwmgr,
3369− struct phm_uvd_clock_voltage_dependency_table *tab)
3370−{
3371− uint16_t i;
3372−
3373− if (tab)
3374− for (i = 0; i < tab->count; i++)
3375− iceland_patch_with_vddc_leakage(hwmgr, &tab->entries[i].v);
3376−
3377− return 0;
3378−}
3379−
3380−static int iceland_patch_vddc_shed_limit(struct pp_hwmgr *hwmgr,
3381− struct phm_phase_shedding_limits_table *tab)
3382−{
3383− uint16_t i;
3384−
3385− if (tab)
3386− for (i = 0; i < tab->count; i++)
3387− iceland_patch_with_vddc_leakage(hwmgr, &tab->entries[i].Voltage);
3388−
3389− return 0;
3390−}
3391−
3392−static int iceland_patch_samu_vddc(struct pp_hwmgr *hwmgr,
3393− struct phm_samu_clock_voltage_dependency_table *tab)
3394−{
3395− uint16_t i;
3396−
3397− if (tab)
3398− for (i = 0; i < tab->count; i++)
3399− iceland_patch_with_vddc_leakage(hwmgr, &tab->entries[i].v);
3400−
3401− return 0;
3402−}
3403−
3404−static int iceland_patch_acp_vddc(struct pp_hwmgr *hwmgr,
3405− struct phm_acp_clock_voltage_dependency_table *tab)
3406−{
3407− uint16_t i;
3408−
3409− if (tab)
3410− for (i = 0; i < tab->count; i++)
3411− iceland_patch_with_vddc_leakage(hwmgr, &tab->entries[i].v);
3412−
3413− return 0;
3414−}
3415−
3416−static int iceland_patch_limits_vddc(struct pp_hwmgr *hwmgr,
3417− struct phm_clock_and_voltage_limits *tab)
3418−{
3419− if (tab) {
3420− iceland_patch_with_vddc_leakage(hwmgr, (uint32_t *)&tab->vddc);
3421− iceland_patch_with_vddci_leakage(hwmgr, (uint32_t *)&tab->vddci);
3422− }
3423−
3424− return 0;
3425−}
3426−
3427−static int iceland_patch_cac_vddc(struct pp_hwmgr *hwmgr, struct phm_cac_leakage_table *tab)
3428−{
3429− uint32_t i;
3430− uint32_t vddc;
3431−
3432− if (tab) {
3433− for (i = 0; i < tab->count; i++) {
3434− vddc = (uint32_t)(tab->entries[i].Vddc);
3435− iceland_patch_with_vddc_leakage(hwmgr, &vddc);
3436− tab->entries[i].Vddc = (uint16_t)vddc;
3437− }
3438− }
3439−
3440− return 0;
3441−}
3442−
3443−static int iceland_patch_dependency_tables_with_leakage(struct pp_hwmgr *hwmgr)
3444−{
3445− int tmp;
3446−
3447− tmp = iceland_patch_vddc(hwmgr, hwmgr->dyn_state.vddc_dependency_on_sclk);
3448− if(tmp)
3449− return -EINVAL;
3450−
3451− tmp = iceland_patch_vddc(hwmgr, hwmgr->dyn_state.vddc_dependency_on_mclk);
3452− if(tmp)
3453− return -EINVAL;
3454−
3455− tmp = iceland_patch_vddc(hwmgr, hwmgr->dyn_state.vddc_dep_on_dal_pwrl);
3456− if(tmp)
3457− return -EINVAL;
3458−
3459− tmp = iceland_patch_vddci(hwmgr, hwmgr->dyn_state.vddci_dependency_on_mclk);
3460− if(tmp)
3461− return -EINVAL;
3462−
3463− tmp = iceland_patch_vce_vddc(hwmgr, hwmgr->dyn_state.vce_clock_voltage_dependency_table);
3464− if(tmp)
3465− return -EINVAL;
3466−
3467− tmp = iceland_patch_uvd_vddc(hwmgr, hwmgr->dyn_state.uvd_clock_voltage_dependency_table);
3468− if(tmp)
3469− return -EINVAL;
3470−
3471− tmp = iceland_patch_samu_vddc(hwmgr, hwmgr->dyn_state.samu_clock_voltage_dependency_table);
3472− if(tmp)
3473− return -EINVAL;
3474−
3475− tmp = iceland_patch_acp_vddc(hwmgr, hwmgr->dyn_state.acp_clock_voltage_dependency_table);
3476− if(tmp)
3477− return -EINVAL;
3478−
3479− tmp = iceland_patch_vddc_shed_limit(hwmgr, hwmgr->dyn_state.vddc_phase_shed_limits_table);
3480− if(tmp)
3481− return -EINVAL;
3482−
3483− tmp = iceland_patch_limits_vddc(hwmgr, &hwmgr->dyn_state.max_clock_voltage_on_ac);
3484− if(tmp)
3485− return -EINVAL;
3486−
3487− tmp = iceland_patch_limits_vddc(hwmgr, &hwmgr->dyn_state.max_clock_voltage_on_dc);
3488− if(tmp)
3489− return -EINVAL;
3490−
3491− tmp = iceland_patch_cac_vddc(hwmgr, hwmgr->dyn_state.cac_leakage_table);
3492− if(tmp)
3493− return -EINVAL;
3494−
3495− return 0;
3496−}
3497−
3498−static int iceland_set_private_var_based_on_pptale(struct pp_hwmgr *hwmgr)
3499−{
3500− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
3501−
3502− struct phm_clock_voltage_dependency_table *allowed_sclk_vddc_table = hwmgr->dyn_state.vddc_dependency_on_sclk;
3503− struct phm_clock_voltage_dependency_table *allowed_mclk_vddc_table = hwmgr->dyn_state.vddc_dependency_on_mclk;
3504− struct phm_clock_voltage_dependency_table *allowed_mclk_vddci_table = hwmgr->dyn_state.vddci_dependency_on_mclk;
3505−
3506− PP_ASSERT_WITH_CODE(allowed_sclk_vddc_table != NULL,
3507− "VDDC dependency on SCLK table is missing. This table is mandatory\n", return -EINVAL);
3508− PP_ASSERT_WITH_CODE(allowed_sclk_vddc_table->count >= 1,
3509− "VDDC dependency on SCLK table has to have is missing. This table is mandatory\n", return -EINVAL);
3510−
3511− PP_ASSERT_WITH_CODE(allowed_mclk_vddc_table != NULL,
3512− "VDDC dependency on MCLK table is missing. This table is mandatory\n", return -EINVAL);
3513− PP_ASSERT_WITH_CODE(allowed_mclk_vddc_table->count >= 1,
3514− "VDD dependency on MCLK table has to have is missing. This table is mandatory\n", return -EINVAL);
3515−
3516− data->min_vddc_in_pp_table = (uint16_t)allowed_sclk_vddc_table->entries[0].v;
3517− data->max_vddc_in_pp_table = (uint16_t)allowed_sclk_vddc_table->entries[allowed_sclk_vddc_table->count - 1].v;
3518−
3519− hwmgr->dyn_state.max_clock_voltage_on_ac.sclk =
3520− allowed_sclk_vddc_table->entries[allowed_sclk_vddc_table->count - 1].clk;
3521− hwmgr->dyn_state.max_clock_voltage_on_ac.mclk =
3522− allowed_mclk_vddc_table->entries[allowed_mclk_vddc_table->count - 1].clk;
3523− hwmgr->dyn_state.max_clock_voltage_on_ac.vddc =
3524− allowed_sclk_vddc_table->entries[allowed_sclk_vddc_table->count - 1].v;
3525−
3526− if (allowed_mclk_vddci_table != NULL && allowed_mclk_vddci_table->count >= 1) {
3527− data->min_vddci_in_pp_table = (uint16_t)allowed_mclk_vddci_table->entries[0].v;
3528− data->max_vddci_in_pp_table = (uint16_t)allowed_mclk_vddci_table->entries[allowed_mclk_vddci_table->count - 1].v;
3529− }
3530−
3531− if (hwmgr->dyn_state.vddci_dependency_on_mclk != NULL && hwmgr->dyn_state.vddci_dependency_on_mclk->count > 1)
3532− hwmgr->dyn_state.max_clock_voltage_on_ac.vddci = hwmgr->dyn_state.vddci_dependency_on_mclk->entries[hwmgr->dyn_state.vddci_dependency_on_mclk->count - 1].v;
3533−
3534− return 0;
3535−}
3536−
3537−static int iceland_initializa_dynamic_state_adjustment_rule_settings(struct pp_hwmgr *hwmgr)
3538−{
3539− uint32_t table_size;
3540− struct phm_clock_voltage_dependency_table *table_clk_vlt;
3541−
3542− hwmgr->dyn_state.mclk_sclk_ratio = 4;
3543− hwmgr->dyn_state.sclk_mclk_delta = 15000; /* 150 MHz */
3544− hwmgr->dyn_state.vddc_vddci_delta = 200; /* 200mV */
3545−
3546− /* initialize vddc_dep_on_dal_pwrl table */
3547− table_size = sizeof(uint32_t) + 4 * sizeof(struct phm_clock_voltage_dependency_record);
3548− table_clk_vlt = (struct phm_clock_voltage_dependency_table *)kzalloc(table_size, GFP_KERNEL);
3549−
3550− if (NULL == table_clk_vlt) {
3551− pr_err("[ powerplay ] Can not allocate space for vddc_dep_on_dal_pwrl! \n");
3552− return -ENOMEM;
3553− } else {
3554− table_clk_vlt->count = 4;
3555− table_clk_vlt->entries[0].clk = PP_DAL_POWERLEVEL_ULTRALOW;
3556− table_clk_vlt->entries[0].v = 0;
3557− table_clk_vlt->entries[1].clk = PP_DAL_POWERLEVEL_LOW;
3558− table_clk_vlt->entries[1].v = 720;
3559− table_clk_vlt->entries[2].clk = PP_DAL_POWERLEVEL_NOMINAL;
3560− table_clk_vlt->entries[2].v = 810;
3561− table_clk_vlt->entries[3].clk = PP_DAL_POWERLEVEL_PERFORMANCE;
3562− table_clk_vlt->entries[3].v = 900;
3563− hwmgr->dyn_state.vddc_dep_on_dal_pwrl = table_clk_vlt;
3564− }
3565−
3566− return 0;
3567−}
3568−
3569−/**
3570− * Initializes the Volcanic Islands Hardware Manager
3571− *
3572− * @param hwmgr the address of the powerplay hardware manager.
3573− * @return 1 if success; otherwise appropriate error code.
3574− */
3575−static int iceland_hwmgr_backend_init(struct pp_hwmgr *hwmgr)
3576−{
3577− int result = 0;
3578− SMU71_Discrete_DpmTable *table = NULL;
3579− iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
3580− pp_atomctrl_gpio_pin_assignment gpio_pin_assignment;
3581− bool stay_in_boot;
3582− struct phw_iceland_ulv_parm *ulv;
3583− struct cgs_system_info sys_info = {0};
3584−
3585− PP_ASSERT_WITH_CODE((NULL != hwmgr),
3586− "Invalid Parameter!", return -EINVAL;);
3587−
3588− data->dll_defaule_on = 0;
3589− data->sram_end = SMC_RAM_END;
3590−
3591− data->activity_target[0] = PPICELAND_TARGETACTIVITY_DFLT;
3592− data->activity_target[1] = PPICELAND_TARGETACTIVITY_DFLT;
3593− data->activity_target[2] = PPICELAND_TARGETACTIVITY_DFLT;
3594− data->activity_target[3] = PPICELAND_TARGETACTIVITY_DFLT;
3595− data->activity_target[4] = PPICELAND_TARGETACTIVITY_DFLT;
3596− data->activity_target[5] = PPICELAND_TARGETACTIVITY_DFLT;
3597− data->activity_target[6] = PPICELAND_TARGETACTIVITY_DFLT;
3598− data->activity_target[7] = PPICELAND_TARGETACTIVITY_DFLT;
3599−
3600− data->mclk_activity_target = PPICELAND_MCLK_TARGETACTIVITY_DFLT;
3601−
3602− data->sclk_dpm_key_disabled = 0;
3603− data->mclk_dpm_key_disabled = 0;
3604− data->pcie_dpm_key_disabled = 0;
3605− data->pcc_monitor_enabled = 0;
3606−
3607− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3608− PHM_PlatformCaps_UnTabledHardwareInterface);
3609−
3610− data->gpio_debug = 0;
3611− data->engine_clock_data = 0;
3612− data->memory_clock_data = 0;
3613−
3614− phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
3615− PHM_PlatformCaps_SclkDeepSleepAboveLow);
3616−
3617− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3618− PHM_PlatformCaps_DynamicPatchPowerState);
3619−
3620− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3621− PHM_PlatformCaps_TablelessHardwareInterface);
3622−
3623− /* Initializes DPM default values. */
3624− iceland_initialize_dpm_defaults(hwmgr);
3625−
3626− /* Enable Platform EVV support. */
3627− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3628− PHM_PlatformCaps_EVV);
3629−
3630− /* Get leakage voltage based on leakage ID. */
3631− result = iceland_get_evv_voltage(hwmgr);
3632− if (result)
3633− goto failed;
3634−
3635− /**
3636− * Patch our voltage dependency table with actual leakage
3637− * voltage. We need to perform leakage translation before it's
3638− * used by other functions such as
3639− * iceland_set_hwmgr_variables_based_on_pptable.
3640− */
3641− result = iceland_patch_dependency_tables_with_leakage(hwmgr);
3642− if (result)
3643− goto failed;
3644−
3645− /* Parse pptable data read from VBIOS. */
3646− result = iceland_set_private_var_based_on_pptale(hwmgr);
3647− if (result)
3648− goto failed;
3649−
3650− /* ULV support */
3651− ulv = &(data->ulv);
3652− ulv->ulv_supported = 1;
3653−
3654− /* Initalize Dynamic State Adjustment Rule Settings*/
3655− result = iceland_initializa_dynamic_state_adjustment_rule_settings(hwmgr);
3656− if (result) {
3657− pr_err("[ powerplay ] iceland_initializa_dynamic_state_adjustment_rule_settings failed!\n");
3658− goto failed;
3659− }
3660−
3661− data->voltage_control = ICELAND_VOLTAGE_CONTROL_NONE;
3662− data->vdd_ci_control = ICELAND_VOLTAGE_CONTROL_NONE;
3663− data->mvdd_control = ICELAND_VOLTAGE_CONTROL_NONE;
3664−
3665− /*
3666− * Hardcode thermal temperature settings for now, these will
3667− * be overwritten if a custom policy exists.
3668− */
3669− data->thermal_temp_setting.temperature_low = 99500;
3670− data->thermal_temp_setting.temperature_high = 100000;
3671− data->thermal_temp_setting.temperature_shutdown = 104000;
3672− data->uvd_enabled = false;
3673−
3674− table = &data->smc_state_table;
3675−
3676− if (atomctrl_get_pp_assign_pin(hwmgr, VDDC_VRHOT_GPIO_PINID,
3677− &gpio_pin_assignment)) {
3678− table->VRHotGpio = gpio_pin_assignment.uc_gpio_pin_bit_shift;
3679− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3680− PHM_PlatformCaps_RegulatorHot);
3681− } else {
3682− table->VRHotGpio = ICELAND_UNUSED_GPIO_PIN;
3683− phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
3684− PHM_PlatformCaps_RegulatorHot);
3685− }
3686−
3687− if (atomctrl_get_pp_assign_pin(hwmgr, PP_AC_DC_SWITCH_GPIO_PINID,
3688− &gpio_pin_assignment)) {
3689− table->AcDcGpio = gpio_pin_assignment.uc_gpio_pin_bit_shift;
3690− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3691− PHM_PlatformCaps_AutomaticDCTransition);
3692− } else {
3693− table->AcDcGpio = ICELAND_UNUSED_GPIO_PIN;
3694− phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
3695− PHM_PlatformCaps_AutomaticDCTransition);
3696− }
3697−
3698− /*
3699− * If ucGPIO_ID=VDDC_PCC_GPIO_PINID in GPIO_LUTable, Peak.
3700− * Current Control feature is enabled and we should program
3701− * PCC HW register
3702− */
3703− if (atomctrl_get_pp_assign_pin(hwmgr, VDDC_PCC_GPIO_PINID,
3704− &gpio_pin_assignment)) {
3705− uint32_t temp_reg = cgs_read_ind_register(hwmgr->device,
3706− CGS_IND_REG__SMC,
3707− ixCNB_PWRMGT_CNTL);
3708−
3709− switch (gpio_pin_assignment.uc_gpio_pin_bit_shift) {
3710− case 0:
3711− temp_reg = PHM_SET_FIELD(temp_reg,
3712− CNB_PWRMGT_CNTL, GNB_SLOW_MODE, 0x1);
3713− break;
3714− case 1:
3715− temp_reg = PHM_SET_FIELD(temp_reg,
3716− CNB_PWRMGT_CNTL, GNB_SLOW_MODE, 0x2);
3717− break;
3718− case 2:
3719− temp_reg = PHM_SET_FIELD(temp_reg,
3720− CNB_PWRMGT_CNTL, GNB_SLOW, 0x1);
3721− break;
3722− case 3:
3723− temp_reg = PHM_SET_FIELD(temp_reg,
3724− CNB_PWRMGT_CNTL, FORCE_NB_PS1, 0x1);
3725− break;
3726− case 4:
3727− temp_reg = PHM_SET_FIELD(temp_reg,
3728− CNB_PWRMGT_CNTL, DPM_ENABLED, 0x1);
3729− break;
3730− default:
3731− pr_warning("[ powerplay ] Failed to setup PCC HW register! Wrong GPIO assigned for VDDC_PCC_GPIO_PINID!\n");
3732− break;
3733− }
3734− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3735− ixCNB_PWRMGT_CNTL, temp_reg);
3736− }
3737−
3738− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3739− PHM_PlatformCaps_EnableSMU7ThermalManagement);
3740− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3741− PHM_PlatformCaps_SMU7);
3742−
3743− if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
3744− VOLTAGE_TYPE_VDDC,
3745− VOLTAGE_OBJ_GPIO_LUT))
3746− data->voltage_control = ICELAND_VOLTAGE_CONTROL_BY_GPIO;
3747− else if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
3748− VOLTAGE_TYPE_VDDC,
3749− VOLTAGE_OBJ_SVID2))
3750− data->voltage_control = ICELAND_VOLTAGE_CONTROL_BY_SVID2;
3751−
3752− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3753− PHM_PlatformCaps_ControlVDDCI)) {
3754− if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
3755− VOLTAGE_TYPE_VDDCI,
3756− VOLTAGE_OBJ_GPIO_LUT))
3757− data->vdd_ci_control = ICELAND_VOLTAGE_CONTROL_BY_GPIO;
3758− else if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
3759− VOLTAGE_TYPE_VDDCI,
3760− VOLTAGE_OBJ_SVID2))
3761− data->vdd_ci_control = ICELAND_VOLTAGE_CONTROL_BY_SVID2;
3762− }
3763−
3764− if (data->vdd_ci_control == ICELAND_VOLTAGE_CONTROL_NONE)
3765− phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
3766− PHM_PlatformCaps_ControlVDDCI);
3767−
3768− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3769− PHM_PlatformCaps_EnableMVDDControl)) {
3770− if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
3771− VOLTAGE_TYPE_MVDDC,
3772− VOLTAGE_OBJ_GPIO_LUT))
3773− data->mvdd_control = ICELAND_VOLTAGE_CONTROL_BY_GPIO;
3774− else if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
3775− VOLTAGE_TYPE_MVDDC,
3776− VOLTAGE_OBJ_SVID2))
3777− data->mvdd_control = ICELAND_VOLTAGE_CONTROL_BY_SVID2;
3778− }
3779−
3780− if (data->mvdd_control == ICELAND_VOLTAGE_CONTROL_NONE)
3781− phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
3782− PHM_PlatformCaps_EnableMVDDControl);
3783−
3784− data->vddc_phase_shed_control = false;
3785−
3786− stay_in_boot = phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3787− PHM_PlatformCaps_StayInBootState);
3788−
3789− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3790− PHM_PlatformCaps_DynamicPowerManagement);
3791−
3792− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3793− PHM_PlatformCaps_ActivityReporting);
3794−
3795− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3796− PHM_PlatformCaps_GFXClockGatingSupport);
3797−
3798− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3799− PHM_PlatformCaps_MemorySpreadSpectrumSupport);
3800− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3801− PHM_PlatformCaps_EngineSpreadSpectrumSupport);
3802−
3803− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3804− PHM_PlatformCaps_DynamicPCIEGen2Support);
3805− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3806− PHM_PlatformCaps_SMC);
3807−
3808− phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
3809− PHM_PlatformCaps_DisablePowerGating);
3810− phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
3811− PHM_PlatformCaps_BACO);
3812−
3813− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3814− PHM_PlatformCaps_ThermalAutoThrottling);
3815− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3816− PHM_PlatformCaps_DisableLSClockGating);
3817− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3818− PHM_PlatformCaps_SamuDPM);
3819− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3820− PHM_PlatformCaps_AcpDPM);
3821− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3822− PHM_PlatformCaps_OD6inACSupport);
3823− phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
3824− PHM_PlatformCaps_EnablePlatformPowerManagement);
3825−
3826− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3827− PHM_PlatformCaps_PauseMMSessions);
3828−
3829− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3830− PHM_PlatformCaps_OD6PlusinACSupport);
3831− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3832− PHM_PlatformCaps_PauseMMSessions);
3833− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3834− PHM_PlatformCaps_GFXClockGatingManagedInCAIL);
3835− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3836− PHM_PlatformCaps_IcelandULPSSWWorkAround);
3837−
3838−
3839− /* iceland doesn't support UVD and VCE */
3840− phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
3841− PHM_PlatformCaps_UVDPowerGating);
3842− phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
3843− PHM_PlatformCaps_VCEPowerGating);
3844−
3845− sys_info.size = sizeof(struct cgs_system_info);
3846− sys_info.info_id = CGS_SYSTEM_INFO_PG_FLAGS;
3847− result = cgs_query_system_info(hwmgr->device, &sys_info);
3848− if (!result) {
3849− if (sys_info.value & AMD_PG_SUPPORT_UVD)
3850− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3851− PHM_PlatformCaps_UVDPowerGating);
3852− if (sys_info.value & AMD_PG_SUPPORT_VCE)
3853− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3854− PHM_PlatformCaps_VCEPowerGating);
3855−
3856− data->is_tlu_enabled = false;
3857− hwmgr->platform_descriptor.hardwareActivityPerformanceLevels =
3858− ICELAND_MAX_HARDWARE_POWERLEVELS;
3859− hwmgr->platform_descriptor.hardwarePerformanceLevels = 2;
3860− hwmgr->platform_descriptor.minimumClocksReductionPercentage = 50;
3861−
3862− sys_info.size = sizeof(struct cgs_system_info);
3863− sys_info.info_id = CGS_SYSTEM_INFO_PCIE_GEN_INFO;
3864− result = cgs_query_system_info(hwmgr->device, &sys_info);
3865− if (result)
3866− data->pcie_gen_cap = AMDGPU_DEFAULT_PCIE_GEN_MASK;
3867− else
3868− data->pcie_gen_cap = (uint32_t)sys_info.value;
3869− if (data->pcie_gen_cap & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)
3870− data->pcie_spc_cap = 20;
3871− sys_info.size = sizeof(struct cgs_system_info);
3872− sys_info.info_id = CGS_SYSTEM_INFO_PCIE_MLW;
3873− result = cgs_query_system_info(hwmgr->device, &sys_info);
3874− if (result)
3875− data->pcie_lane_cap = AMDGPU_DEFAULT_PCIE_MLW_MASK;
3876− else
3877− data->pcie_lane_cap = (uint32_t)sys_info.value;
3878− } else {
3879− /* Ignore return value in here, we are cleaning up a mess. */
3880− iceland_hwmgr_backend_fini(hwmgr);
3881− }
3882−
3883− return 0;
3884−failed:
3885− return result;
3886−}
3887−
3888−static int iceland_get_num_of_entries(struct pp_hwmgr *hwmgr)
3889−{
3890− int result;
3891− unsigned long ret = 0;
3892−
3893− result = pp_tables_get_num_of_entries(hwmgr, &ret);
3894−
3895− return result ? 0 : ret;
3896−}
3897−
3898−static const unsigned long PhwIceland_Magic = (unsigned long)(PHM_VIslands_Magic);
3899−
3900−struct iceland_power_state *cast_phw_iceland_power_state(
3901− struct pp_hw_power_state *hw_ps)
3902−{
3903− if (hw_ps == NULL)
3904− return NULL;
3905−
3906− PP_ASSERT_WITH_CODE((PhwIceland_Magic == hw_ps->magic),
3907− "Invalid Powerstate Type!",
3908− return NULL);
3909−
3910− return (struct iceland_power_state *)hw_ps;
3911−}
3912−
3913−static int iceland_apply_state_adjust_rules(struct pp_hwmgr *hwmgr,
3914− struct pp_power_state *prequest_ps,
3915− const struct pp_power_state *pcurrent_ps)
3916−{
3917− struct iceland_power_state *iceland_ps =
3918− cast_phw_iceland_power_state(&prequest_ps->hardware);
3919−
3920− uint32_t sclk;
3921− uint32_t mclk;
3922− struct PP_Clocks minimum_clocks = {0};
3923− bool disable_mclk_switching;
3924− bool disable_mclk_switching_for_frame_lock;
3925− struct cgs_display_info info = {0};
3926− const struct phm_clock_and_voltage_limits *max_limits;
3927− uint32_t i;
3928− iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
3929−
3930− int32_t count;
3931− int32_t stable_pstate_sclk = 0, stable_pstate_mclk = 0;
3932−
3933− data->battery_state = (PP_StateUILabel_Battery == prequest_ps->classification.ui_label);
3934−
3935− PP_ASSERT_WITH_CODE(iceland_ps->performance_level_count == 2,
3936− "VI should always have 2 performance levels",
3937− );
3938−
3939− max_limits = (PP_PowerSource_AC == hwmgr->power_source) ?
3940− &(hwmgr->dyn_state.max_clock_voltage_on_ac) :
3941− &(hwmgr->dyn_state.max_clock_voltage_on_dc);
3942−
3943− if (PP_PowerSource_DC == hwmgr->power_source) {
3944− for (i = 0; i < iceland_ps->performance_level_count; i++) {
3945− if (iceland_ps->performance_levels[i].memory_clock > max_limits->mclk)
3946− iceland_ps->performance_levels[i].memory_clock = max_limits->mclk;
3947− if (iceland_ps->performance_levels[i].engine_clock > max_limits->sclk)
3948− iceland_ps->performance_levels[i].engine_clock = max_limits->sclk;
3949− }
3950− }
3951−
3952− iceland_ps->vce_clocks.EVCLK = hwmgr->vce_arbiter.evclk;
3953− iceland_ps->vce_clocks.ECCLK = hwmgr->vce_arbiter.ecclk;
3954−
3955− cgs_get_active_displays_info(hwmgr->device, &info);
3956−
3957− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_StablePState)) {
3958−
3959− max_limits = &(hwmgr->dyn_state.max_clock_voltage_on_ac);
3960− stable_pstate_sclk = (max_limits->sclk * 75) / 100;
3961−
3962− for (count = hwmgr->dyn_state.vddc_dependency_on_sclk->count-1; count >= 0; count--) {
3963− if (stable_pstate_sclk >= hwmgr->dyn_state.vddc_dependency_on_sclk->entries[count].clk) {
3964− stable_pstate_sclk = hwmgr->dyn_state.vddc_dependency_on_sclk->entries[count].clk;
3965− break;
3966− }
3967− }
3968−
3969− if (count < 0)
3970− stable_pstate_sclk = hwmgr->dyn_state.vddc_dependency_on_sclk->entries[0].clk;
3971−
3972− stable_pstate_mclk = max_limits->mclk;
3973−
3974− minimum_clocks.engineClock = stable_pstate_sclk;
3975− minimum_clocks.memoryClock = stable_pstate_mclk;
3976− }
3977−
3978− if (minimum_clocks.engineClock < hwmgr->gfx_arbiter.sclk)
3979− minimum_clocks.engineClock = hwmgr->gfx_arbiter.sclk;
3980−
3981− if (minimum_clocks.memoryClock < hwmgr->gfx_arbiter.mclk)
3982− minimum_clocks.memoryClock = hwmgr->gfx_arbiter.mclk;
3983−
3984− iceland_ps->sclk_threshold = hwmgr->gfx_arbiter.sclk_threshold;
3985−
3986− if (0 != hwmgr->gfx_arbiter.sclk_over_drive) {
3987− PP_ASSERT_WITH_CODE((hwmgr->gfx_arbiter.sclk_over_drive <= hwmgr->platform_descriptor.overdriveLimit.engineClock),
3988− "Overdrive sclk exceeds limit",
3989− hwmgr->gfx_arbiter.sclk_over_drive = hwmgr->platform_descriptor.overdriveLimit.engineClock);
3990−
3991− if (hwmgr->gfx_arbiter.sclk_over_drive >= hwmgr->gfx_arbiter.sclk)
3992− iceland_ps->performance_levels[1].engine_clock = hwmgr->gfx_arbiter.sclk_over_drive;
3993− }
3994−
3995− if (0 != hwmgr->gfx_arbiter.mclk_over_drive) {
3996− PP_ASSERT_WITH_CODE((hwmgr->gfx_arbiter.mclk_over_drive <= hwmgr->platform_descriptor.overdriveLimit.memoryClock),
3997− "Overdrive mclk exceeds limit",
3998− hwmgr->gfx_arbiter.mclk_over_drive = hwmgr->platform_descriptor.overdriveLimit.memoryClock);
3999−
4000− if (hwmgr->gfx_arbiter.mclk_over_drive >= hwmgr->gfx_arbiter.mclk)
4001− iceland_ps->performance_levels[1].memory_clock = hwmgr->gfx_arbiter.mclk_over_drive;
4002− }
4003−
4004− disable_mclk_switching_for_frame_lock = phm_cap_enabled(
4005− hwmgr->platform_descriptor.platformCaps,
4006− PHM_PlatformCaps_DisableMclkSwitchingForFrameLock);
4007−
4008− disable_mclk_switching = (1 < info.display_count) ||
4009− disable_mclk_switching_for_frame_lock;
4010−
4011− sclk = iceland_ps->performance_levels[0].engine_clock;
4012− mclk = iceland_ps->performance_levels[0].memory_clock;
4013−
4014− if (disable_mclk_switching)
4015− mclk = iceland_ps->performance_levels[iceland_ps->performance_level_count - 1].memory_clock;
4016−
4017− if (sclk < minimum_clocks.engineClock)
4018− sclk = (minimum_clocks.engineClock > max_limits->sclk) ? max_limits->sclk : minimum_clocks.engineClock;
4019−
4020− if (mclk < minimum_clocks.memoryClock)
4021− mclk = (minimum_clocks.memoryClock > max_limits->mclk) ? max_limits->mclk : minimum_clocks.memoryClock;
4022−
4023− iceland_ps->performance_levels[0].engine_clock = sclk;
4024− iceland_ps->performance_levels[0].memory_clock = mclk;
4025−
4026− iceland_ps->performance_levels[1].engine_clock =
4027− (iceland_ps->performance_levels[1].engine_clock >= iceland_ps->performance_levels[0].engine_clock) ?
4028− iceland_ps->performance_levels[1].engine_clock :
4029− iceland_ps->performance_levels[0].engine_clock;
4030−
4031− if (disable_mclk_switching) {
4032− if (mclk < iceland_ps->performance_levels[1].memory_clock)
4033− mclk = iceland_ps->performance_levels[1].memory_clock;
4034−
4035− iceland_ps->performance_levels[0].memory_clock = mclk;
4036− iceland_ps->performance_levels[1].memory_clock = mclk;
4037− } else {
4038− if (iceland_ps->performance_levels[1].memory_clock < iceland_ps->performance_levels[0].memory_clock)
4039− iceland_ps->performance_levels[1].memory_clock = iceland_ps->performance_levels[0].memory_clock;
4040− }
4041−
4042− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_StablePState)) {
4043− for (i=0; i < iceland_ps->performance_level_count; i++) {
4044− iceland_ps->performance_levels[i].engine_clock = stable_pstate_sclk;
4045− iceland_ps->performance_levels[i].memory_clock = stable_pstate_mclk;
4046− iceland_ps->performance_levels[i].pcie_gen = data->pcie_gen_performance.max;
4047− iceland_ps->performance_levels[i].pcie_lane = data->pcie_gen_performance.max;
4048− }
4049− }
4050−
4051− return 0;
4052−}
4053−
4054−static bool iceland_is_dpm_running(struct pp_hwmgr *hwmgr)
4055−{
4056− /*
4057− * We return the status of Voltage Control instead of checking SCLK/MCLK DPM
4058− * because we may have test scenarios that need us intentionly disable SCLK/MCLK DPM,
4059− * whereas voltage control is a fundemental change that will not be disabled
4060− */
4061− return (0 == PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
4062− FEATURE_STATUS, VOLTAGE_CONTROLLER_ON) ? 1 : 0);
4063−}
4064−
4065−/**
4066− * force DPM power State
4067− *
4068− * @param hwmgr: the address of the powerplay hardware manager.
4069− * @param n : DPM level
4070− * @return The response that came from the SMC.
4071− */
4072−int iceland_dpm_force_state(struct pp_hwmgr *hwmgr, uint32_t n)
4073−{
4074− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
4075−
4076− /* Checking if DPM is running. If we discover hang because of this, we should skip this message. */
4077− PP_ASSERT_WITH_CODE(0 == iceland_is_dpm_running(hwmgr),
4078− "Trying to force SCLK when DPM is disabled", return -1;);
4079− if (0 == data->sclk_dpm_key_disabled)
4080− return (0 == smum_send_msg_to_smc_with_parameter(
4081− hwmgr->smumgr,
4082− PPSMC_MSG_DPM_ForceState,
4083− n) ? 0 : 1);
4084−
4085− return 0;
4086−}
4087−
4088−/**
4089− * force DPM power State
4090− *
4091− * @param hwmgr: the address of the powerplay hardware manager.
4092− * @param n : DPM level
4093− * @return The response that came from the SMC.
4094− */
4095−int iceland_dpm_force_state_mclk(struct pp_hwmgr *hwmgr, uint32_t n)
4096−{
4097− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
4098−
4099− /* Checking if DPM is running. If we discover hang because of this, we should skip this message. */
4100− PP_ASSERT_WITH_CODE(0 == iceland_is_dpm_running(hwmgr),
4101− "Trying to Force MCLK when DPM is disabled", return -1;);
4102− if (0 == data->mclk_dpm_key_disabled)
4103− return (0 == smum_send_msg_to_smc_with_parameter(
4104− hwmgr->smumgr,
4105− PPSMC_MSG_MCLKDPM_ForceState,
4106− n) ? 0 : 1);
4107−
4108− return 0;
4109−}
4110−
4111−/**
4112− * force DPM power State
4113− *
4114− * @param hwmgr: the address of the powerplay hardware manager.
4115− * @param n : DPM level
4116− * @return The response that came from the SMC.
4117− */
4118−int iceland_dpm_force_state_pcie(struct pp_hwmgr *hwmgr, uint32_t n)
4119−{
4120− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
4121−
4122− /* Checking if DPM is running. If we discover hang because of this, we should skip this message.*/
4123− PP_ASSERT_WITH_CODE(0 == iceland_is_dpm_running(hwmgr),
4124− "Trying to Force PCIE level when DPM is disabled", return -1;);
4125− if (0 == data->pcie_dpm_key_disabled)
4126− return (0 == smum_send_msg_to_smc_with_parameter(
4127− hwmgr->smumgr,
4128− PPSMC_MSG_PCIeDPM_ForceLevel,
4129− n) ? 0 : 1);
4130−
4131− return 0;
4132−}
4133−
4134−static int iceland_force_dpm_highest(struct pp_hwmgr *hwmgr)
4135−{
4136− uint32_t level, tmp;
4137− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
4138−
4139− if (0 == data->sclk_dpm_key_disabled) {
4140− /* SCLK */
4141− if (data->dpm_level_enable_mask.sclk_dpm_enable_mask != 0) {
4142− level = 0;
4143− tmp = data->dpm_level_enable_mask.sclk_dpm_enable_mask;
4144− while (tmp >>= 1)
4145− level++ ;
4146−
4147− if (0 != level) {
4148− PP_ASSERT_WITH_CODE((0 == iceland_dpm_force_state(hwmgr, level)),
4149− "force highest sclk dpm state failed!", return -1);
4150− PHM_WAIT_INDIRECT_FIELD(hwmgr->device,
4151− SMC_IND, TARGET_AND_CURRENT_PROFILE_INDEX, CURR_SCLK_INDEX, level);
4152− }
4153− }
4154− }
4155−
4156− if (0 == data->mclk_dpm_key_disabled) {
4157− /* MCLK */
4158− if (data->dpm_level_enable_mask.mclk_dpm_enable_mask != 0) {
4159− level = 0;
4160− tmp = data->dpm_level_enable_mask.mclk_dpm_enable_mask;
4161− while (tmp >>= 1)
4162− level++ ;
4163−
4164− if (0 != level) {
4165− PP_ASSERT_WITH_CODE((0 == iceland_dpm_force_state_mclk(hwmgr, level)),
4166− "force highest mclk dpm state failed!", return -1);
4167− PHM_WAIT_INDIRECT_FIELD(hwmgr->device, SMC_IND,
4168− TARGET_AND_CURRENT_PROFILE_INDEX, CURR_MCLK_INDEX, level);
4169− }
4170− }
4171− }
4172−
4173− if (0 == data->pcie_dpm_key_disabled) {
4174− /* PCIE */
4175− if (data->dpm_level_enable_mask.pcie_dpm_enable_mask != 0) {
4176− level = 0;
4177− tmp = data->dpm_level_enable_mask.pcie_dpm_enable_mask;
4178− while (tmp >>= 1)
4179− level++ ;
4180−
4181− if (0 != level) {
4182− PP_ASSERT_WITH_CODE((0 == iceland_dpm_force_state_pcie(hwmgr, level)),
4183− "force highest pcie dpm state failed!", return -1);
4184− }
4185− }
4186− }
4187−
4188− return 0;
4189−}
4190−
4191−static uint32_t iceland_get_lowest_enable_level(struct pp_hwmgr *hwmgr,
4192− uint32_t level_mask)
4193−{
4194− uint32_t level = 0;
4195−
4196− while (0 == (level_mask & (1 << level)))
4197− level++;
4198−
4199− return level;
4200−}
4201−
4202−static int iceland_force_dpm_lowest(struct pp_hwmgr *hwmgr)
4203−{
4204− uint32_t level;
4205− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
4206−
4207− /* for now force only sclk */
4208− if (0 != data->dpm_level_enable_mask.sclk_dpm_enable_mask) {
4209− level = iceland_get_lowest_enable_level(hwmgr,
4210− data->dpm_level_enable_mask.sclk_dpm_enable_mask);
4211−
4212− PP_ASSERT_WITH_CODE((0 == iceland_dpm_force_state(hwmgr, level)),
4213− "force sclk dpm state failed!", return -1);
4214−
4215− PHM_WAIT_INDIRECT_FIELD(hwmgr->device, SMC_IND,
4216− TARGET_AND_CURRENT_PROFILE_INDEX,
4217− CURR_SCLK_INDEX,
4218− level);
4219− }
4220−
4221− return 0;
4222−}
4223−
4224−int iceland_unforce_dpm_levels(struct pp_hwmgr *hwmgr)
4225−{
4226− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
4227−
4228− PP_ASSERT_WITH_CODE (0 == iceland_is_dpm_running(hwmgr),
4229− "Trying to Unforce DPM when DPM is disabled. Returning without sending SMC message.",
4230− return -1);
4231−
4232− if (0 == data->sclk_dpm_key_disabled) {
4233− PP_ASSERT_WITH_CODE((0 == smum_send_msg_to_smc(
4234− hwmgr->smumgr,
4235− PPSMC_MSG_NoForcedLevel)),
4236− "unforce sclk dpm state failed!",
4237− return -1);
4238− }
4239−
4240− if (0 == data->mclk_dpm_key_disabled) {
4241− PP_ASSERT_WITH_CODE((0 == smum_send_msg_to_smc(
4242− hwmgr->smumgr,
4243− PPSMC_MSG_MCLKDPM_NoForcedLevel)),
4244− "unforce mclk dpm state failed!",
4245− return -1);
4246− }
4247−
4248− if (0 == data->pcie_dpm_key_disabled) {
4249− PP_ASSERT_WITH_CODE((0 == smum_send_msg_to_smc(
4250− hwmgr->smumgr,
4251− PPSMC_MSG_PCIeDPM_UnForceLevel)),
4252− "unforce pcie level failed!",
4253− return -1);
4254− }
4255−
4256− return 0;
4257−}
4258−
4259−static int iceland_force_dpm_level(struct pp_hwmgr *hwmgr,
4260− enum amd_dpm_forced_level level)
4261−{
4262− int ret = 0;
4263−
4264− switch (level) {
4265− case AMD_DPM_FORCED_LEVEL_HIGH:
4266− ret = iceland_force_dpm_highest(hwmgr);
4267− if (ret)
4268− return ret;
4269− break;
4270− case AMD_DPM_FORCED_LEVEL_LOW:
4271− ret = iceland_force_dpm_lowest(hwmgr);
4272− if (ret)
4273− return ret;
4274− break;
4275− case AMD_DPM_FORCED_LEVEL_AUTO:
4276− ret = iceland_unforce_dpm_levels(hwmgr);
4277− if (ret)
4278− return ret;
4279− break;
4280− default:
4281− break;
4282− }
4283−
4284− hwmgr->dpm_level = level;
4285− return ret;
4286−}
4287−
4288−const struct iceland_power_state *cast_const_phw_iceland_power_state(
4289− const struct pp_hw_power_state *hw_ps)
4290−{
4291− if (hw_ps == NULL)
4292− return NULL;
4293−
4294− PP_ASSERT_WITH_CODE((PhwIceland_Magic == hw_ps->magic),
4295− "Invalid Powerstate Type!",
4296− return NULL);
4297−
4298− return (const struct iceland_power_state *)hw_ps;
4299−}
4300−
4301−static int iceland_find_dpm_states_clocks_in_dpm_table(struct pp_hwmgr *hwmgr, const void *input)
4302−{
4303− const struct phm_set_power_state_input *states = (const struct phm_set_power_state_input *)input;
4304− const struct iceland_power_state *iceland_ps = cast_const_phw_iceland_power_state(states->pnew_state);
4305− struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
4306− struct iceland_single_dpm_table *psclk_table = &(data->dpm_table.sclk_table);
4307− uint32_t sclk = iceland_ps->performance_levels[iceland_ps->performance_level_count-1].engine_clock;
4308− struct iceland_single_dpm_table *pmclk_table = &(data->dpm_table.mclk_table);
4309− uint32_t mclk = iceland_ps->performance_levels[iceland_ps->performance_level_count-1].memory_clock;
4310− struct PP_Clocks min_clocks = {0};
4311− uint32_t i;
4312− struct cgs_display_info info = {0};
4313−
4314− data->need_update_smu7_dpm_table = 0;
4315−
4316− for (i = 0; i < psclk_table->count; i++) {
4317− if (sclk == psclk_table->dpm_levels[i].value)
4318− break;
4319− }
4320−
4321− if (i >= psclk_table->count)
4322− data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_SCLK;
4323− else {
4324− /*
4325− * TODO: Check SCLK in DAL's minimum clocks in case DeepSleep
4326− * divider update is required.
4327− */
4328− if(data->display_timing.min_clock_insr != min_clocks.engineClockInSR)
4329− data->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_SCLK;
4330− }
4331−
4332− for (i = 0; i < pmclk_table->count; i++) {
4333− if (mclk == pmclk_table->dpm_levels[i].value)
4334− break;
4335− }
4336−
4337− if (i >= pmclk_table->count)
4338− data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_MCLK;
4339−
4340− cgs_get_active_displays_info(hwmgr->device, &info);
4341−
4342− if (data->display_timing.num_existing_displays != info.display_count)
4343− data->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_MCLK;
4344−
4345− return 0;
4346−}
4347−
4348−static uint16_t iceland_get_maximum_link_speed(struct pp_hwmgr *hwmgr, const struct iceland_power_state *hw_ps)
4349−{
4350− uint32_t i;
4351− uint32_t pcie_speed, max_speed = 0;
4352−
4353− for (i = 0; i < hw_ps->performance_level_count; i++) {
4354− pcie_speed = hw_ps->performance_levels[i].pcie_gen;
4355− if (max_speed < pcie_speed)
4356− max_speed = pcie_speed;
4357− }
4358−
4359− return max_speed;
4360−}
4361−
4362−static uint16_t iceland_get_current_pcie_speed(struct pp_hwmgr *hwmgr)
4363−{
4364− uint32_t speed_cntl = 0;
4365−
4366− speed_cntl = cgs_read_ind_register(hwmgr->device,
4367− CGS_IND_REG__PCIE,
4368− ixPCIE_LC_SPEED_CNTL);
4369− return((uint16_t)PHM_GET_FIELD(speed_cntl,
4370− PCIE_LC_SPEED_CNTL, LC_CURRENT_DATA_RATE));
4371−}
4372−
4373−
4374−static int iceland_request_link_speed_change_before_state_change(struct pp_hwmgr *hwmgr, const void *input)
4375−{
4376− const struct phm_set_power_state_input *states = (const struct phm_set_power_state_input *)input;
4377− struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
4378− const struct iceland_power_state *iceland_nps = cast_const_phw_iceland_power_state(states->pnew_state);
4379− const struct iceland_power_state *iceland_cps = cast_const_phw_iceland_power_state(states->pcurrent_state);
4380−
4381− uint16_t target_link_speed = iceland_get_maximum_link_speed(hwmgr, iceland_nps);
4382− uint16_t current_link_speed;
4383−
4384− if (data->force_pcie_gen == PP_PCIEGenInvalid)
4385− current_link_speed = iceland_get_maximum_link_speed(hwmgr, iceland_cps);
4386− else
4387− current_link_speed = data->force_pcie_gen;
4388−
4389− data->force_pcie_gen = PP_PCIEGenInvalid;
4390− data->pspp_notify_required = false;
4391− if (target_link_speed > current_link_speed) {
4392− switch(target_link_speed) {
4393− case PP_PCIEGen3:
4394− if (0 == acpi_pcie_perf_request(hwmgr->device, PCIE_PERF_REQ_GEN3, false))
4395− break;
4396− data->force_pcie_gen = PP_PCIEGen2;
4397− if (current_link_speed == PP_PCIEGen2)
4398− break;
4399− case PP_PCIEGen2:
4400− if (0 == acpi_pcie_perf_request(hwmgr->device, PCIE_PERF_REQ_GEN2, false))
4401− break;
4402− default:
4403− data->force_pcie_gen = iceland_get_current_pcie_speed(hwmgr);
4404− break;
4405− }
4406− } else {
4407− if (target_link_speed < current_link_speed)
4408− data->pspp_notify_required = true;
4409− }
4410−
4411− return 0;
4412−}
4413−
4414−static int iceland_freeze_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
4415−{
4416− struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
4417−
4418− if (0 == data->need_update_smu7_dpm_table)
4419− return 0;
4420−
4421− if ((0 == data->sclk_dpm_key_disabled) &&
4422− (data->need_update_smu7_dpm_table &
4423− (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK))) {
4424− PP_ASSERT_WITH_CODE(
4425− 0 == iceland_is_dpm_running(hwmgr),
4426− "Trying to freeze SCLK DPM when DPM is disabled",
4427− );
4428− PP_ASSERT_WITH_CODE(
4429− 0 == smum_send_msg_to_smc(hwmgr->smumgr,
4430− PPSMC_MSG_SCLKDPM_FreezeLevel),
4431− "Failed to freeze SCLK DPM during FreezeSclkMclkDPM Function!",
4432− return -1);
4433− }
4434−
4435− if ((0 == data->mclk_dpm_key_disabled) &&
4436− (data->need_update_smu7_dpm_table &
4437− DPMTABLE_OD_UPDATE_MCLK)) {
4438− PP_ASSERT_WITH_CODE(0 == iceland_is_dpm_running(hwmgr),
4439− "Trying to freeze MCLK DPM when DPM is disabled",
4440− );
4441− PP_ASSERT_WITH_CODE(
4442− 0 == smum_send_msg_to_smc(hwmgr->smumgr,
4443− PPSMC_MSG_MCLKDPM_FreezeLevel),
4444− "Failed to freeze MCLK DPM during FreezeSclkMclkDPM Function!",
4445− return -1);
4446− }
4447−
4448− return 0;
4449−}
4450−
4451−static int iceland_populate_and_upload_sclk_mclk_dpm_levels(struct pp_hwmgr *hwmgr, const void *input)
4452−{
4453− int result = 0;
4454−
4455− const struct phm_set_power_state_input *states = (const struct phm_set_power_state_input *)input;
4456− const struct iceland_power_state *iceland_ps = cast_const_phw_iceland_power_state(states->pnew_state);
4457− struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
4458− uint32_t sclk = iceland_ps->performance_levels[iceland_ps->performance_level_count-1].engine_clock;
4459− uint32_t mclk = iceland_ps->performance_levels[iceland_ps->performance_level_count-1].memory_clock;
4460− struct iceland_dpm_table *pdpm_table = &data->dpm_table;
4461−
4462− struct iceland_dpm_table *pgolden_dpm_table = &data->golden_dpm_table;
4463− uint32_t dpm_count, clock_percent;
4464− uint32_t i;
4465−
4466− if (0 == data->need_update_smu7_dpm_table)
4467− return 0;
4468−
4469− if (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_SCLK) {
4470− pdpm_table->sclk_table.dpm_levels[pdpm_table->sclk_table.count-1].value = sclk;
4471−
4472− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinACSupport) ||
4473− phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinDCSupport)) {
4474− /*
4475− * Need to do calculation based on the golden DPM table
4476− * as the Heatmap GPU Clock axis is also based on the default values
4477− */
4478− PP_ASSERT_WITH_CODE(
4479− (pgolden_dpm_table->sclk_table.dpm_levels[pgolden_dpm_table->sclk_table.count-1].value != 0),
4480− "Divide by 0!",
4481− return -1);
4482− dpm_count = pdpm_table->sclk_table.count < 2 ? 0 : pdpm_table->sclk_table.count-2;
4483− for (i = dpm_count; i > 1; i--) {
4484− if (sclk > pgolden_dpm_table->sclk_table.dpm_levels[pgolden_dpm_table->sclk_table.count-1].value) {
4485− clock_percent = ((sclk - pgolden_dpm_table->sclk_table.dpm_levels[pgolden_dpm_table->sclk_table.count-1].value)*100) /
4486− pgolden_dpm_table->sclk_table.dpm_levels[pgolden_dpm_table->sclk_table.count-1].value;
4487−
4488− pdpm_table->sclk_table.dpm_levels[i].value =
4489− pgolden_dpm_table->sclk_table.dpm_levels[i].value +
4490− (pgolden_dpm_table->sclk_table.dpm_levels[i].value * clock_percent)/100;
4491−
4492− } else if (pgolden_dpm_table->sclk_table.dpm_levels[pdpm_table->sclk_table.count-1].value > sclk) {
4493− clock_percent = ((pgolden_dpm_table->sclk_table.dpm_levels[pgolden_dpm_table->sclk_table.count-1].value - sclk)*100) /
4494− pgolden_dpm_table->sclk_table.dpm_levels[pgolden_dpm_table->sclk_table.count-1].value;
4495−
4496− pdpm_table->sclk_table.dpm_levels[i].value =
4497− pgolden_dpm_table->sclk_table.dpm_levels[i].value -
4498− (pgolden_dpm_table->sclk_table.dpm_levels[i].value * clock_percent)/100;
4499− } else
4500− pdpm_table->sclk_table.dpm_levels[i].value =
4501− pgolden_dpm_table->sclk_table.dpm_levels[i].value;
4502− }
4503− }
4504− }
4505−
4506− if (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK) {
4507− pdpm_table->mclk_table.dpm_levels[pdpm_table->mclk_table.count-1].value = mclk;
4508−
4509− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinACSupport) ||
4510− phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinDCSupport)) {
4511−
4512− PP_ASSERT_WITH_CODE(
4513− (pgolden_dpm_table->mclk_table.dpm_levels[pgolden_dpm_table->mclk_table.count-1].value != 0),
4514− "Divide by 0!",
4515− return -1);
4516− dpm_count = pdpm_table->mclk_table.count < 2? 0 : pdpm_table->mclk_table.count-2;
4517− for (i = dpm_count; i > 1; i--) {
4518− if (mclk > pgolden_dpm_table->mclk_table.dpm_levels[pgolden_dpm_table->mclk_table.count-1].value) {
4519− clock_percent = ((mclk - pgolden_dpm_table->mclk_table.dpm_levels[pgolden_dpm_table->mclk_table.count-1].value)*100) /
4520− pgolden_dpm_table->mclk_table.dpm_levels[pgolden_dpm_table->mclk_table.count-1].value;
4521−
4522− pdpm_table->mclk_table.dpm_levels[i].value =
4523− pgolden_dpm_table->mclk_table.dpm_levels[i].value +
4524− (pgolden_dpm_table->mclk_table.dpm_levels[i].value * clock_percent)/100;
4525−
4526− } else if (pgolden_dpm_table->mclk_table.dpm_levels[pdpm_table->mclk_table.count-1].value > mclk) {
4527− clock_percent = ((pgolden_dpm_table->mclk_table.dpm_levels[pgolden_dpm_table->mclk_table.count-1].value - mclk)*100) /
4528− pgolden_dpm_table->mclk_table.dpm_levels[pgolden_dpm_table->mclk_table.count-1].value;
4529−
4530− pdpm_table->mclk_table.dpm_levels[i].value =
4531− pgolden_dpm_table->mclk_table.dpm_levels[i].value -
4532− (pgolden_dpm_table->mclk_table.dpm_levels[i].value * clock_percent)/100;
4533− } else
4534− pdpm_table->mclk_table.dpm_levels[i].value = pgolden_dpm_table->mclk_table.dpm_levels[i].value;
4535− }
4536− }
4537− }
4538−
4539−
4540− if (data->need_update_smu7_dpm_table & (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK)) {
4541− result = iceland_populate_all_graphic_levels(hwmgr);
4542− PP_ASSERT_WITH_CODE((0 == result),
4543− "Failed to populate SCLK during PopulateNewDPMClocksStates Function!",
4544− return result);
4545− }
4546−
4547− if (data->need_update_smu7_dpm_table & (DPMTABLE_OD_UPDATE_MCLK + DPMTABLE_UPDATE_MCLK)) {
4548− /*populate MCLK dpm table to SMU7 */
4549− result = iceland_populate_all_memory_levels(hwmgr);
4550− PP_ASSERT_WITH_CODE((0 == result),
4551− "Failed to populate MCLK during PopulateNewDPMClocksStates Function!",
4552− return result);
4553− }
4554−
4555− return result;
4556−}
4557−
4558−static int iceland_trim_single_dpm_states(struct pp_hwmgr *hwmgr,
4559− struct iceland_single_dpm_table *pdpm_table,
4560− uint32_t low_limit, uint32_t high_limit)
4561−{
4562− uint32_t i;
4563−
4564− for (i = 0; i < pdpm_table->count; i++) {
4565− if ((pdpm_table->dpm_levels[i].value < low_limit) ||
4566− (pdpm_table->dpm_levels[i].value > high_limit))
4567− pdpm_table->dpm_levels[i].enabled = false;
4568− else
4569− pdpm_table->dpm_levels[i].enabled = true;
4570− }
4571− return 0;
4572−}
4573−
4574−static int iceland_trim_dpm_states(struct pp_hwmgr *hwmgr, const struct iceland_power_state *hw_state)
4575−{
4576− int result = 0;
4577− struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
4578− uint32_t high_limit_count;
4579−
4580− PP_ASSERT_WITH_CODE((hw_state->performance_level_count >= 1),
4581− "power state did not have any performance level",
4582− return -1);
4583−
4584− high_limit_count = (1 == hw_state->performance_level_count) ? 0: 1;
4585−
4586− iceland_trim_single_dpm_states(hwmgr, &(data->dpm_table.sclk_table),
4587− hw_state->performance_levels[0].engine_clock,
4588− hw_state->performance_levels[high_limit_count].engine_clock);
4589−
4590− iceland_trim_single_dpm_states(hwmgr, &(data->dpm_table.mclk_table),
4591− hw_state->performance_levels[0].memory_clock,
4592− hw_state->performance_levels[high_limit_count].memory_clock);
4593−
4594− return result;
4595−}
4596−
4597−static int iceland_generate_dpm_level_enable_mask(struct pp_hwmgr *hwmgr, const void *input)
4598−{
4599− int result;
4600− const struct phm_set_power_state_input *states = (const struct phm_set_power_state_input *)input;
4601− struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
4602− const struct iceland_power_state *iceland_ps = cast_const_phw_iceland_power_state(states->pnew_state);
4603−
4604− result = iceland_trim_dpm_states(hwmgr, iceland_ps);
4605− if (0 != result)
4606− return result;
4607−
4608− data->dpm_level_enable_mask.sclk_dpm_enable_mask = iceland_get_dpm_level_enable_mask_value(&data->dpm_table.sclk_table);
4609− data->dpm_level_enable_mask.mclk_dpm_enable_mask = iceland_get_dpm_level_enable_mask_value(&data->dpm_table.mclk_table);
4610− data->last_mclk_dpm_enable_mask = data->dpm_level_enable_mask.mclk_dpm_enable_mask;
4611− if (data->uvd_enabled && (data->dpm_level_enable_mask.mclk_dpm_enable_mask & 1))
4612− data->dpm_level_enable_mask.mclk_dpm_enable_mask &= 0xFFFFFFFE;
4613−
4614− data->dpm_level_enable_mask.pcie_dpm_enable_mask = iceland_get_dpm_level_enable_mask_value(&data->dpm_table.pcie_speed_table);
4615−
4616− return 0;
4617−}
4618−
4619−static int iceland_update_vce_dpm(struct pp_hwmgr *hwmgr, const void *input)
4620−{
4621− return 0;
4622−}
4623−
4624−static int iceland_update_sclk_threshold(struct pp_hwmgr *hwmgr)
4625−{
4626− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
4627−
4628− int result = 0;
4629− uint32_t low_sclk_interrupt_threshold = 0;
4630−
4631− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4632− PHM_PlatformCaps_SclkThrottleLowNotification)
4633− && (hwmgr->gfx_arbiter.sclk_threshold != data->low_sclk_interrupt_threshold)) {
4634− data->low_sclk_interrupt_threshold = hwmgr->gfx_arbiter.sclk_threshold;
4635− low_sclk_interrupt_threshold = data->low_sclk_interrupt_threshold;
4636−
4637− CONVERT_FROM_HOST_TO_SMC_UL(low_sclk_interrupt_threshold);
4638−
4639− result = iceland_copy_bytes_to_smc(
4640− hwmgr->smumgr,
4641− data->dpm_table_start + offsetof(SMU71_Discrete_DpmTable,
4642− LowSclkInterruptThreshold),
4643− (uint8_t *)&low_sclk_interrupt_threshold,
4644− sizeof(uint32_t),
4645− data->sram_end
4646− );
4647− }
4648−
4649− return result;
4650−}
4651−
4652−static int iceland_update_and_upload_mc_reg_table(struct pp_hwmgr *hwmgr)
4653−{
4654− struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
4655−
4656− uint32_t address;
4657− int32_t result;
4658−
4659− if (0 == (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK))
4660− return 0;
4661−
4662−
4663− memset(&data->mc_reg_table, 0, sizeof(SMU71_Discrete_MCRegisters));
4664−
4665− result = iceland_convert_mc_reg_table_to_smc(hwmgr, &(data->mc_reg_table));
4666−
4667− if(result != 0)
4668− return result;
4669−
4670−
4671− address = data->mc_reg_table_start + (uint32_t)offsetof(SMU71_Discrete_MCRegisters, data[0]);
4672−
4673− return iceland_copy_bytes_to_smc(hwmgr->smumgr, address,
4674− (uint8_t *)&data->mc_reg_table.data[0],
4675− sizeof(SMU71_Discrete_MCRegisterSet) * data->dpm_table.mclk_table.count,
4676− data->sram_end);
4677−}
4678−
4679−static int iceland_program_memory_timing_parameters_conditionally(struct pp_hwmgr *hwmgr)
4680−{
4681− struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
4682−
4683− if (data->need_update_smu7_dpm_table &
4684− (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_OD_UPDATE_MCLK))
4685− return iceland_program_memory_timing_parameters(hwmgr);
4686−
4687− return 0;
4688−}
4689−
4690−static int iceland_unfreeze_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
4691−{
4692− struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
4693−
4694− if (0 == data->need_update_smu7_dpm_table)
4695− return 0;
4696−
4697− if ((0 == data->sclk_dpm_key_disabled) &&
4698− (data->need_update_smu7_dpm_table &
4699− (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK))) {
4700−
4701− PP_ASSERT_WITH_CODE(0 == iceland_is_dpm_running(hwmgr),
4702− "Trying to Unfreeze SCLK DPM when DPM is disabled",
4703− );
4704− PP_ASSERT_WITH_CODE(
4705− 0 == smum_send_msg_to_smc(hwmgr->smumgr,
4706− PPSMC_MSG_SCLKDPM_UnfreezeLevel),
4707− "Failed to unfreeze SCLK DPM during UnFreezeSclkMclkDPM Function!",
4708− return -1);
4709− }
4710−
4711− if ((0 == data->mclk_dpm_key_disabled) &&
4712− (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK)) {
4713−
4714− PP_ASSERT_WITH_CODE(
4715− 0 == iceland_is_dpm_running(hwmgr),
4716− "Trying to Unfreeze MCLK DPM when DPM is disabled",
4717− );
4718− PP_ASSERT_WITH_CODE(
4719− 0 == smum_send_msg_to_smc(hwmgr->smumgr,
4720− PPSMC_MSG_MCLKDPM_UnfreezeLevel),
4721− "Failed to unfreeze MCLK DPM during UnFreezeSclkMclkDPM Function!",
4722− return -1);
4723− }
4724−
4725− data->need_update_smu7_dpm_table = 0;
4726−
4727− return 0;
4728−}
4729−
4730−static int iceland_notify_link_speed_change_after_state_change(struct pp_hwmgr *hwmgr, const void *input)
4731−{
4732− const struct phm_set_power_state_input *states = (const struct phm_set_power_state_input *)input;
4733− struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
4734− const struct iceland_power_state *iceland_ps = cast_const_phw_iceland_power_state(states->pnew_state);
4735− uint16_t target_link_speed = iceland_get_maximum_link_speed(hwmgr, iceland_ps);
4736− uint8_t request;
4737−
4738− if (data->pspp_notify_required ||
4739− data->pcie_performance_request) {
4740− if (target_link_speed == PP_PCIEGen3)
4741− request = PCIE_PERF_REQ_GEN3;
4742− else if (target_link_speed == PP_PCIEGen2)
4743− request = PCIE_PERF_REQ_GEN2;
4744− else
4745− request = PCIE_PERF_REQ_GEN1;
4746−
4747− if(request == PCIE_PERF_REQ_GEN1 && iceland_get_current_pcie_speed(hwmgr) > 0) {
4748− data->pcie_performance_request = false;
4749− return 0;
4750− }
4751−
4752− if (0 != acpi_pcie_perf_request(hwmgr->device, request, false)) {
4753− if (PP_PCIEGen2 == target_link_speed)
4754− printk("PSPP request to switch to Gen2 from Gen3 Failed!");
4755− else
4756− printk("PSPP request to switch to Gen1 from Gen2 Failed!");
4757− }
4758− }
4759−
4760− data->pcie_performance_request = false;
4761− return 0;
4762−}
4763−
4764−int iceland_upload_dpm_level_enable_mask(struct pp_hwmgr *hwmgr)
4765−{
4766− PPSMC_Result result;
4767− iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend);
4768−
4769− if (0 == data->sclk_dpm_key_disabled) {
4770− /* Checking if DPM is running. If we discover hang because of this, we should skip this message.*/
4771− if (0 != iceland_is_dpm_running(hwmgr))
4772− printk(KERN_ERR "[ powerplay ] Trying to set Enable Sclk Mask when DPM is disabled \n");
4773−
4774− if (0 != data->dpm_level_enable_mask.sclk_dpm_enable_mask) {
4775− result = smum_send_msg_to_smc_with_parameter(
4776− hwmgr->smumgr,
4777− (PPSMC_Msg)PPSMC_MSG_SCLKDPM_SetEnabledMask,
4778− data->dpm_level_enable_mask.sclk_dpm_enable_mask);
4779− PP_ASSERT_WITH_CODE((0 == result),
4780− "Set Sclk Dpm enable Mask failed", return -1);
4781− }
4782− }
4783−
4784− if (0 == data->mclk_dpm_key_disabled) {
4785− /* Checking if DPM is running. If we discover hang because of this, we should skip this message.*/
4786− if (0 != iceland_is_dpm_running(hwmgr))
4787− printk(KERN_ERR "[ powerplay ] Trying to set Enable Mclk Mask when DPM is disabled \n");
4788−
4789− if (0 != data->dpm_level_enable_mask.mclk_dpm_enable_mask) {
4790− result = smum_send_msg_to_smc_with_parameter(
4791− hwmgr->smumgr,
4792− (PPSMC_Msg)PPSMC_MSG_MCLKDPM_SetEnabledMask,
4793− data->dpm_level_enable_mask.mclk_dpm_enable_mask);
4794− PP_ASSERT_WITH_CODE((0 == result),
4795− "Set Mclk Dpm enable Mask failed", return -1);
4796− }
4797− }
4798−
4799− return 0;
4800−}
4801−
4802−static int iceland_set_power_state_tasks(struct pp_hwmgr *hwmgr, const void *input)
4803−{
4804− int tmp_result, result = 0;
4805−
4806− tmp_result = iceland_find_dpm_states_clocks_in_dpm_table(hwmgr, input);
4807− PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to find DPM states clocks in DPM table!", result = tmp_result);
4808−
4809− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_PCIEPerformanceRequest)) {
4810− tmp_result = iceland_request_link_speed_change_before_state_change(hwmgr, input);
4811− PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to request link speed change before state change!", result = tmp_result);
4812− }
4813−
4814− tmp_result = iceland_freeze_sclk_mclk_dpm(hwmgr);
4815− PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to freeze SCLK MCLK DPM!", result = tmp_result);
4816−
4817− tmp_result = iceland_populate_and_upload_sclk_mclk_dpm_levels(hwmgr, input);
4818− PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to populate and upload SCLK MCLK DPM levels!", result = tmp_result);
4819−
4820− tmp_result = iceland_generate_dpm_level_enable_mask(hwmgr, input);
4821− PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to generate DPM level enabled mask!", result = tmp_result);
4822−
4823− tmp_result = iceland_update_vce_dpm(hwmgr, input);
4824− PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to update VCE DPM!", result = tmp_result);
4825−
4826− tmp_result = iceland_update_sclk_threshold(hwmgr);
4827− PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to update SCLK threshold!", result = tmp_result);
4828−
4829− tmp_result = iceland_update_and_upload_mc_reg_table(hwmgr);
4830− PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to upload MC reg table!", result = tmp_result);
4831−
4832− tmp_result = iceland_program_memory_timing_parameters_conditionally(hwmgr);
4833− PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to program memory timing parameters!", result = tmp_result);
4834−
4835− tmp_result = iceland_unfreeze_sclk_mclk_dpm(hwmgr);
4836− PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to unfreeze SCLK MCLK DPM!", result = tmp_result);
4837−
4838− tmp_result = iceland_upload_dpm_level_enable_mask(hwmgr);
4839− PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to upload DPM level enabled mask!", result = tmp_result);
4840−
4841− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_PCIEPerformanceRequest)) {
4842− tmp_result = iceland_notify_link_speed_change_after_state_change(hwmgr, input);
4843− PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to notify link speed change after state change!", result = tmp_result);
4844− }
4845−
4846− return result;
4847−}
4848−
4849−static int iceland_get_power_state_size(struct pp_hwmgr *hwmgr)
4850−{
4851− return sizeof(struct iceland_power_state);
4852−}
4853−
4854−static int iceland_dpm_get_mclk(struct pp_hwmgr *hwmgr, bool low)
4855−{
4856− struct pp_power_state *ps;
4857− struct iceland_power_state *iceland_ps;
4858−
4859− if (hwmgr == NULL)
4860− return -EINVAL;
4861−
4862− ps = hwmgr->request_ps;
4863−
4864− if (ps == NULL)
4865− return -EINVAL;
4866−
4867− iceland_ps = cast_phw_iceland_power_state(&ps->hardware);
4868−
4869− if (low)
4870− return iceland_ps->performance_levels[0].memory_clock;
4871− else
4872− return iceland_ps->performance_levels[iceland_ps->performance_level_count-1].memory_clock;
4873−}
4874−
4875−static int iceland_dpm_get_sclk(struct pp_hwmgr *hwmgr, bool low)
4876−{
4877− struct pp_power_state *ps;
4878− struct iceland_power_state *iceland_ps;
4879−
4880− if (hwmgr == NULL)
4881− return -EINVAL;
4882−
4883− ps = hwmgr->request_ps;
4884−
4885− if (ps == NULL)
4886− return -EINVAL;
4887−
4888− iceland_ps = cast_phw_iceland_power_state(&ps->hardware);
4889−
4890− if (low)
4891− return iceland_ps->performance_levels[0].engine_clock;
4892− else
4893− return iceland_ps->performance_levels[iceland_ps->performance_level_count-1].engine_clock;
4894−}
4895−
4896−static int iceland_get_current_pcie_lane_number(
4897− struct pp_hwmgr *hwmgr)
4898−{
4899− uint32_t link_width;
4900−
4901− link_width = PHM_READ_INDIRECT_FIELD(hwmgr->device,
4902− CGS_IND_REG__PCIE,
4903− PCIE_LC_LINK_WIDTH_CNTL,
4904− LC_LINK_WIDTH_RD);
4905−
4906− PP_ASSERT_WITH_CODE((7 >= link_width),
4907− "Invalid PCIe lane width!", return 0);
4908−
4909− return decode_pcie_lane_width(link_width);
4910−}
4911−
4912−static int iceland_dpm_patch_boot_state(struct pp_hwmgr *hwmgr,
4913− struct pp_hw_power_state *hw_ps)
4914−{
4915− struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
4916− struct iceland_power_state *ps = (struct iceland_power_state *)hw_ps;
4917− ATOM_FIRMWARE_INFO_V2_2 *fw_info;
4918− uint16_t size;
4919− uint8_t frev, crev;
4920− int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
4921−
4922− /* First retrieve the Boot clocks and VDDC from the firmware info table.
4923− * We assume here that fw_info is unchanged if this call fails.
4924− */
4925− fw_info = (ATOM_FIRMWARE_INFO_V2_2 *)cgs_atom_get_data_table(
4926− hwmgr->device, index,
4927− &size, &frev, &crev);
4928− if (!fw_info)
4929− /* During a test, there is no firmware info table. */
4930− return 0;
4931−
4932− /* Patch the state. */
4933− data->vbios_boot_state.sclk_bootup_value = le32_to_cpu(fw_info->ulDefaultEngineClock);
4934− data->vbios_boot_state.mclk_bootup_value = le32_to_cpu(fw_info->ulDefaultMemoryClock);
4935− data->vbios_boot_state.mvdd_bootup_value = le16_to_cpu(fw_info->usBootUpMVDDCVoltage);
4936− data->vbios_boot_state.vddc_bootup_value = le16_to_cpu(fw_info->usBootUpVDDCVoltage);
4937− data->vbios_boot_state.vddci_bootup_value = le16_to_cpu(fw_info->usBootUpVDDCIVoltage);
4938− data->vbios_boot_state.pcie_gen_bootup_value = iceland_get_current_pcie_speed(hwmgr);
4939− data->vbios_boot_state.pcie_lane_bootup_value =
4940− (uint16_t)iceland_get_current_pcie_lane_number(hwmgr);
4941−
4942− /* set boot power state */
4943− ps->performance_levels[0].memory_clock = data->vbios_boot_state.mclk_bootup_value;
4944− ps->performance_levels[0].engine_clock = data->vbios_boot_state.sclk_bootup_value;
4945− ps->performance_levels[0].pcie_gen = data->vbios_boot_state.pcie_gen_bootup_value;
4946− ps->performance_levels[0].pcie_lane = data->vbios_boot_state.pcie_lane_bootup_value;
4947−
4948− return 0;
4949−}
4950−
4951−static int iceland_get_pp_table_entry_callback_func(struct pp_hwmgr *hwmgr,
4952− struct pp_hw_power_state *power_state,
4953− unsigned int index, const void *clock_info)
4954−{
4955− struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
4956− struct iceland_power_state *iceland_power_state = cast_phw_iceland_power_state(power_state);
4957− const ATOM_PPLIB_CI_CLOCK_INFO *visland_clk_info = clock_info;
4958− struct iceland_performance_level *performance_level;
4959− uint32_t engine_clock, memory_clock;
4960− uint16_t pcie_gen_from_bios;
4961−
4962− engine_clock = visland_clk_info->ucEngineClockHigh << 16 | visland_clk_info->usEngineClockLow;
4963− memory_clock = visland_clk_info->ucMemoryClockHigh << 16 | visland_clk_info->usMemoryClockLow;
4964−
4965− if (!(data->mc_micro_code_feature & DISABLE_MC_LOADMICROCODE) && memory_clock > data->highest_mclk)
4966− data->highest_mclk = memory_clock;
4967−
4968− performance_level = &(iceland_power_state->performance_levels
4969− [iceland_power_state->performance_level_count++]);
4970−
4971− PP_ASSERT_WITH_CODE(
4972− (iceland_power_state->performance_level_count < SMU71_MAX_LEVELS_GRAPHICS),
4973− "Performance levels exceeds SMC limit!",
4974− return -1);
4975−
4976− PP_ASSERT_WITH_CODE(
4977− (iceland_power_state->performance_level_count <=
4978− hwmgr->platform_descriptor.hardwareActivityPerformanceLevels),
4979− "Performance levels exceeds Driver limit!",
4980− return -1);
4981−
4982− /* Performance levels are arranged from low to high. */
4983− performance_level->memory_clock = memory_clock;
4984− performance_level->engine_clock = engine_clock;
4985−
4986− pcie_gen_from_bios = visland_clk_info->ucPCIEGen;
4987−
4988− performance_level->pcie_gen = get_pcie_gen_support(data->pcie_gen_cap, pcie_gen_from_bios);
4989− performance_level->pcie_lane = get_pcie_lane_support(data->pcie_lane_cap, visland_clk_info->usPCIELane);
4990−
4991− return 0;
4992−}
4993−
4994−static int iceland_get_pp_table_entry(struct pp_hwmgr *hwmgr,
4995− unsigned long entry_index, struct pp_power_state *state)
4996−{
4997− int result;
4998− struct iceland_power_state *ps;
4999− struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);

685 more lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.h+0−424
@@ -1,424 +0,0 @@
1−/*
2− * Copyright 2016 Advanced Micro Devices, Inc.
3− *
4− * Permission is hereby granted, free of charge, to any person obtaining a
5− * copy of this software and associated documentation files (the "Software"),
6− * to deal in the Software without restriction, including without limitation
7− * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8− * and/or sell copies of the Software, and to permit persons to whom the
9− * Software is furnished to do so, subject to the following conditions:
10− *
11− * The above copyright notice and this permission notice shall be included in
12− * all copies or substantial portions of the Software.
13− *
14− * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15− * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16− * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17− * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18− * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19− * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20− * OTHER DEALINGS IN THE SOFTWARE.
21− *
22− * Author: Huang Rui <ray.huang@amd.com>
23− *
24− */
25−#ifndef ICELAND_HWMGR_H
26−#define ICELAND_HWMGR_H
27−
28−#include "hwmgr.h"
29−#include "ppatomctrl.h"
30−#include "ppinterrupt.h"
31−#include "ppsmc.h"
32−#include "iceland_powertune.h"
33−#include "pp_endian.h"
34−#include "smu71_discrete.h"
35−
36−#define ICELAND_MAX_HARDWARE_POWERLEVELS 2
37−#define ICELAND_DYNCLK_NUMBER_OF_TREND_COEFFICIENTS 15
38−
39−struct iceland_performance_level {
40− uint32_t memory_clock;
41− uint32_t engine_clock;
42− uint16_t pcie_gen;
43− uint16_t pcie_lane;
44−};
45−
46−struct _phw_iceland_bacos {
47− uint32_t best_match;
48− uint32_t baco_flags;
49− struct iceland_performance_level performance_level;
50−};
51−typedef struct _phw_iceland_bacos phw_iceland_bacos;
52−
53−struct _phw_iceland_uvd_clocks {
54− uint32_t VCLK;
55− uint32_t DCLK;
56−};
57−
58−typedef struct _phw_iceland_uvd_clocks phw_iceland_uvd_clocks;
59−
60−struct _phw_iceland_vce_clocks {
61− uint32_t EVCLK;
62− uint32_t ECCLK;
63−};
64−
65−typedef struct _phw_iceland_vce_clocks phw_iceland_vce_clocks;
66−
67−struct iceland_power_state {
68− uint32_t magic;
69− phw_iceland_uvd_clocks uvd_clocks;
70− phw_iceland_vce_clocks vce_clocks;
71− uint32_t sam_clk;
72− uint32_t acp_clk;
73− uint16_t performance_level_count;
74− bool dc_compatible;
75− uint32_t sclk_threshold;
76− struct iceland_performance_level performance_levels[ICELAND_MAX_HARDWARE_POWERLEVELS];
77−};
78−
79−struct _phw_iceland_dpm_level {
80− bool enabled;
81− uint32_t value;
82− uint32_t param1;
83−};
84−typedef struct _phw_iceland_dpm_level phw_iceland_dpm_level;
85−
86−#define ICELAND_MAX_DEEPSLEEP_DIVIDER_ID 5
87−#define MAX_REGULAR_DPM_NUMBER 8
88−#define ICELAND_MINIMUM_ENGINE_CLOCK 5000
89−
90−struct iceland_single_dpm_table {
91− uint32_t count;
92− phw_iceland_dpm_level dpm_levels[MAX_REGULAR_DPM_NUMBER];
93−};
94−
95−struct iceland_dpm_table {
96− struct iceland_single_dpm_table sclk_table;
97− struct iceland_single_dpm_table mclk_table;
98− struct iceland_single_dpm_table pcie_speed_table;
99− struct iceland_single_dpm_table vddc_table;
100− struct iceland_single_dpm_table vdd_gfx_table;
101− struct iceland_single_dpm_table vdd_ci_table;
102− struct iceland_single_dpm_table mvdd_table;
103−};
104−typedef struct _phw_iceland_dpm_table phw_iceland_dpm_table;
105−
106−
107−struct _phw_iceland_clock_regisiters {
108− uint32_t vCG_SPLL_FUNC_CNTL;
109− uint32_t vCG_SPLL_FUNC_CNTL_2;
110− uint32_t vCG_SPLL_FUNC_CNTL_3;
111− uint32_t vCG_SPLL_FUNC_CNTL_4;
112− uint32_t vCG_SPLL_SPREAD_SPECTRUM;
113− uint32_t vCG_SPLL_SPREAD_SPECTRUM_2;
114− uint32_t vDLL_CNTL;
115− uint32_t vMCLK_PWRMGT_CNTL;
116− uint32_t vMPLL_AD_FUNC_CNTL;
117− uint32_t vMPLL_DQ_FUNC_CNTL;
118− uint32_t vMPLL_FUNC_CNTL;
119− uint32_t vMPLL_FUNC_CNTL_1;
120− uint32_t vMPLL_FUNC_CNTL_2;
121− uint32_t vMPLL_SS1;
122− uint32_t vMPLL_SS2;
123−};
124−typedef struct _phw_iceland_clock_regisiters phw_iceland_clock_registers;
125−
126−struct _phw_iceland_voltage_smio_registers {
127− uint32_t vs0_vid_lower_smio_cntl;
128−};
129−typedef struct _phw_iceland_voltage_smio_registers phw_iceland_voltage_smio_registers;
130−
131−
132−struct _phw_iceland_mc_reg_entry {
133− uint32_t mclk_max;
134− uint32_t mc_data[SMU71_DISCRETE_MC_REGISTER_ARRAY_SIZE];
135−};
136−typedef struct _phw_iceland_mc_reg_entry phw_iceland_mc_reg_entry;
137−
138−struct _phw_iceland_mc_reg_table {
139− uint8_t last; /* number of registers*/
140− uint8_t num_entries; /* number of entries in mc_reg_table_entry used*/
141− uint16_t validflag; /* indicate the corresponding register is valid or not. 1: valid, 0: invalid. bit0->address[0], bit1->address[1], etc.*/
142− phw_iceland_mc_reg_entry mc_reg_table_entry[MAX_AC_TIMING_ENTRIES];
143− SMU71_Discrete_MCRegisterAddress mc_reg_address[SMU71_DISCRETE_MC_REGISTER_ARRAY_SIZE];
144−};
145−typedef struct _phw_iceland_mc_reg_table phw_iceland_mc_reg_table;
146−
147−#define DISABLE_MC_LOADMICROCODE 1
148−#define DISABLE_MC_CFGPROGRAMMING 2
149−
150−
151−/*Ultra Low Voltage parameter structure */
152−struct phw_iceland_ulv_parm{
153− bool ulv_supported;
154− uint32_t ch_ulv_parameter;
155− uint32_t ulv_volt_change_delay;
156− struct iceland_performance_level ulv_power_level;
157−};
158−
159−#define ICELAND_MAX_LEAKAGE_COUNT 8
160−
161−struct phw_iceland_leakage_voltage {
162− uint16_t count;
163− uint16_t leakage_id[ICELAND_MAX_LEAKAGE_COUNT];
164− uint16_t actual_voltage[ICELAND_MAX_LEAKAGE_COUNT];
165−};
166−
167−struct _phw_iceland_display_timing {
168− uint32_t min_clock_insr;
169− uint32_t num_existing_displays;
170−};
171−typedef struct _phw_iceland_display_timing phw_iceland_display_timing;
172−
173−
174−struct phw_iceland_thermal_temperature_setting
175−{
176− long temperature_low;
177− long temperature_high;
178− long temperature_shutdown;
179−};
180−
181−struct _phw_iceland_dpmlevel_enable_mask {
182− uint32_t uvd_dpm_enable_mask;
183− uint32_t vce_dpm_enable_mask;
184− uint32_t acp_dpm_enable_mask;
185− uint32_t samu_dpm_enable_mask;
186− uint32_t sclk_dpm_enable_mask;
187− uint32_t mclk_dpm_enable_mask;
188− uint32_t pcie_dpm_enable_mask;
189−};
190−typedef struct _phw_iceland_dpmlevel_enable_mask phw_iceland_dpmlevel_enable_mask;
191−
192−struct _phw_iceland_pcie_perf_range {
193− uint16_t max;
194− uint16_t min;
195−};
196−typedef struct _phw_iceland_pcie_perf_range phw_iceland_pcie_perf_range;
197−
198−struct _phw_iceland_vbios_boot_state {
199− uint16_t mvdd_bootup_value;
200− uint16_t vddc_bootup_value;
201− uint16_t vddci_bootup_value;
202− uint16_t vddgfx_bootup_value;
203− uint32_t sclk_bootup_value;
204− uint32_t mclk_bootup_value;
205− uint16_t pcie_gen_bootup_value;
206− uint16_t pcie_lane_bootup_value;
207−};
208−typedef struct _phw_iceland_vbios_boot_state phw_iceland_vbios_boot_state;
209−
210−#define DPMTABLE_OD_UPDATE_SCLK 0x00000001
211−#define DPMTABLE_OD_UPDATE_MCLK 0x00000002
212−#define DPMTABLE_UPDATE_SCLK 0x00000004
213−#define DPMTABLE_UPDATE_MCLK 0x00000008
214−
215−/* We need to review which fields are needed. */
216−/* This is mostly a copy of the RV7xx/Evergreen structure which is close, but not identical to the N.Islands one. */
217−struct iceland_hwmgr {
218− struct iceland_dpm_table dpm_table;
219− struct iceland_dpm_table golden_dpm_table;
220−
221− uint32_t voting_rights_clients0;
222− uint32_t voting_rights_clients1;
223− uint32_t voting_rights_clients2;
224− uint32_t voting_rights_clients3;
225− uint32_t voting_rights_clients4;
226− uint32_t voting_rights_clients5;
227− uint32_t voting_rights_clients6;
228− uint32_t voting_rights_clients7;
229− uint32_t static_screen_threshold_unit;
230− uint32_t static_screen_threshold;
231− uint32_t voltage_control;
232− uint32_t vdd_gfx_control;
233−
234− uint32_t vddc_vddci_delta;
235− uint32_t vddc_vddgfx_delta;
236−
237− struct pp_interrupt_registration_info internal_high_thermal_interrupt_info;
238− struct pp_interrupt_registration_info internal_low_thermal_interrupt_info;
239− struct pp_interrupt_registration_info smc_to_host_interrupt_info;
240− uint32_t active_auto_throttle_sources;
241−
242− struct pp_interrupt_registration_info external_throttle_interrupt;
243− irq_handler_func_t external_throttle_callback;
244− void *external_throttle_context;
245−
246− struct pp_interrupt_registration_info ctf_interrupt_info;
247− irq_handler_func_t ctf_callback;
248− void *ctf_context;
249−
250− phw_iceland_clock_registers clock_registers;
251− phw_iceland_voltage_smio_registers voltage_smio_registers;
252−
253− bool is_memory_GDDR5;
254− uint16_t acpi_vddc;
255− bool pspp_notify_required; /* Flag to indicate if PSPP notification to SBIOS is required */
256− uint16_t force_pcie_gen; /* The forced PCI-E speed if not 0xffff */
257− uint16_t acpi_pcie_gen; /* The PCI-E speed at ACPI time */
258− uint32_t pcie_gen_cap; /* The PCI-E speed capabilities bitmap from CAIL */
259− uint32_t pcie_lane_cap; /* The PCI-E lane capabilities bitmap from CAIL */
260− uint32_t pcie_spc_cap; /* Symbol Per Clock Capabilities from registry */
261− struct phw_iceland_leakage_voltage vddc_leakage; /* The Leakage VDDC supported (based on leakage ID).*/
262− struct phw_iceland_leakage_voltage vddcgfx_leakage; /* The Leakage VDDC supported (based on leakage ID). */
263− struct phw_iceland_leakage_voltage vddci_leakage; /* The Leakage VDDCI supported (based on leakage ID). */
264−
265− uint32_t mvdd_control;
266− uint32_t vddc_mask_low;
267− uint32_t mvdd_mask_low;
268− uint16_t max_vddc_in_pp_table; /* the maximum VDDC value in the powerplay table*/
269− uint16_t min_vddc_in_pp_table;
270− uint16_t max_vddci_in_pp_table; /* the maximum VDDCI value in the powerplay table */
271− uint16_t min_vddci_in_pp_table;
272− uint32_t mclk_strobe_mode_threshold;
273− uint32_t mclk_stutter_mode_threshold;
274− uint32_t mclk_edc_enable_threshold;
275− uint32_t mclk_edc_wr_enable_threshold;
276− bool is_uvd_enabled;
277− bool is_xdma_enabled;
278− phw_iceland_vbios_boot_state vbios_boot_state;
279−
280− bool battery_state;
281− bool is_tlu_enabled;
282− bool pcie_performance_request;
283−
284− /* -------------- SMC SRAM Address of firmware header tables ----------------*/
285− uint32_t sram_end; /* The first address after the SMC SRAM. */
286− uint32_t dpm_table_start; /* The start of the dpm table in the SMC SRAM. */
287− uint32_t soft_regs_start; /* The start of the soft registers in the SMC SRAM. */
288− uint32_t mc_reg_table_start; /* The start of the mc register table in the SMC SRAM. */
289− uint32_t fan_table_start; /* The start of the fan table in the SMC SRAM. */
290− uint32_t arb_table_start; /* The start of the ARB setting table in the SMC SRAM. */
291− uint32_t ulv_settings_start;
292− SMU71_Discrete_DpmTable smc_state_table; /* The carbon copy of the SMC state table. */
293− SMU71_Discrete_MCRegisters mc_reg_table;
294− SMU71_Discrete_Ulv ulv_setting; /* The carbon copy of ULV setting. */
295−
296− /* -------------- Stuff originally coming from Evergreen --------------------*/
297− phw_iceland_mc_reg_table iceland_mc_reg_table;
298− uint32_t vdd_ci_control;
299− pp_atomctrl_voltage_table vddc_voltage_table;
300− pp_atomctrl_voltage_table vddci_voltage_table;
301− pp_atomctrl_voltage_table vddgfx_voltage_table;
302− pp_atomctrl_voltage_table mvdd_voltage_table;
303−
304− uint32_t mgcg_cgtt_local2;
305− uint32_t mgcg_cgtt_local3;
306− uint32_t gpio_debug;
307− uint32_t mc_micro_code_feature;
308− uint32_t highest_mclk;
309− uint16_t acpi_vdd_ci;
310− uint8_t mvdd_high_index;
311− uint8_t mvdd_low_index;
312− bool dll_defaule_on;
313− bool performance_request_registered;
314−
315− /* ----------------- Low Power Features ---------------------*/
316− phw_iceland_bacos bacos;
317− struct phw_iceland_ulv_parm ulv;
318−
319− /* ----------------- CAC Stuff ---------------------*/
320− uint32_t cac_table_start;
321− bool cac_configuration_required; /* TRUE if PP_CACConfigurationRequired == 1 */
322− bool driver_calculate_cac_leakage; /* TRUE if PP_DriverCalculateCACLeakage == 1 */
323− bool cac_enabled;
324−
325− /* ----------------- DPM2 Parameters ---------------------*/
326− uint32_t power_containment_features;
327− bool enable_bapm_feature;
328− bool enable_dte_feature;
329− bool enable_tdc_limit_feature;
330− bool enable_pkg_pwr_tracking_feature;
331− bool disable_uvd_power_tune_feature;
332− struct iceland_pt_defaults *power_tune_defaults;
333− SMU71_Discrete_PmFuses power_tune_table;
334− uint32_t ul_dte_tj_offset; /* Fudge factor in DPM table to correct HW DTE errors */
335− uint32_t fast_watermark_threshold; /* use fast watermark if clock is equal or above this. In percentage of the target high sclk. */
336−
337− /* ----------------- Phase Shedding ---------------------*/
338− bool vddc_phase_shed_control;
339−
340− /* --------------------- DI/DT --------------------------*/
341− phw_iceland_display_timing display_timing;
342−
343− /* --------- ReadRegistry data for memory and engine clock margins ---- */
344− uint32_t engine_clock_data;
345− uint32_t memory_clock_data;
346−
347− /* -------- Thermal Temperature Setting --------------*/
348− struct phw_iceland_thermal_temperature_setting thermal_temp_setting;
349− phw_iceland_dpmlevel_enable_mask dpm_level_enable_mask;
350−
351− uint32_t need_update_smu7_dpm_table;
352− uint32_t sclk_dpm_key_disabled;
353− uint32_t mclk_dpm_key_disabled;
354− uint32_t pcie_dpm_key_disabled;
355− /* used to store the previous dal min sclock */
356− uint32_t min_engine_clocks;
357− phw_iceland_pcie_perf_range pcie_gen_performance;
358− phw_iceland_pcie_perf_range pcie_lane_performance;
359− phw_iceland_pcie_perf_range pcie_gen_power_saving;
360− phw_iceland_pcie_perf_range pcie_lane_power_saving;
361− bool use_pcie_performance_levels;
362− bool use_pcie_power_saving_levels;
363− /* percentage value from 0-100, default 50 */
364− uint32_t activity_target[SMU71_MAX_LEVELS_GRAPHICS];
365− uint32_t mclk_activity_target;
366− uint32_t low_sclk_interrupt_threshold;
367− uint32_t last_mclk_dpm_enable_mask;
368− bool uvd_enabled;
369− uint32_t pcc_monitor_enabled;
370−
371− /* --------- Power Gating States ------------*/
372− bool uvd_power_gated; /* 1: gated, 0:not gated */
373− bool vce_power_gated; /* 1: gated, 0:not gated */
374− bool samu_power_gated; /* 1: gated, 0:not gated */
375− bool acp_power_gated; /* 1: gated, 0:not gated */
376− bool pg_acp_init;
377−
378− /* soft pptable for re-uploading into smu */
379− void *soft_pp_table;
380−};
381−
382−typedef struct iceland_hwmgr iceland_hwmgr;
383−
384−int iceland_hwmgr_init(struct pp_hwmgr *hwmgr);
385−int iceland_update_uvd_dpm(struct pp_hwmgr *hwmgr, bool bgate);
386−uint32_t iceland_get_xclk(struct pp_hwmgr *hwmgr);
387−int iceland_populate_bapm_vddc_vid_sidd(struct pp_hwmgr *hwmgr);
388−int iceland_populate_vddc_vid(struct pp_hwmgr *hwmgr);
389−
390−#define ICELAND_DPM2_NEAR_TDP_DEC 10
391−#define ICELAND_DPM2_ABOVE_SAFE_INC 5
392−#define ICELAND_DPM2_BELOW_SAFE_INC 20
393−
394−/*
395− * Log2 of the LTA window size (l2numWin_TDP). Eg. If LTA windows size
396− * is 128, then this value should be Log2(128) = 7.
397− */
398−#define ICELAND_DPM2_LTA_WINDOW_SIZE 7
399−
400−#define ICELAND_DPM2_LTS_TRUNCATE 0
401−
402−#define ICELAND_DPM2_TDP_SAFE_LIMIT_PERCENT 80 // Maximum 100
403−
404−#define ICELAND_DPM2_MAXPS_PERCENT_H 90 // Maximum 0xFF
405−#define ICELAND_DPM2_MAXPS_PERCENT_M 90 // Maximum 0xFF
406−
407−#define ICELAND_DPM2_PWREFFICIENCYRATIO_MARGIN 50
408−
409−#define ICELAND_DPM2_SQ_RAMP_MAX_POWER 0x3FFF
410−#define ICELAND_DPM2_SQ_RAMP_MIN_POWER 0x12
411−#define ICELAND_DPM2_SQ_RAMP_MAX_POWER_DELTA 0x15
412−#define ICELAND_DPM2_SQ_RAMP_SHORT_TERM_INTERVAL_SIZE 0x1E
413−#define ICELAND_DPM2_SQ_RAMP_LONG_TERM_INTERVAL_RATIO 0xF
414−
415−#define ICELAND_VOLTAGE_CONTROL_NONE 0x0
416−#define ICELAND_VOLTAGE_CONTROL_BY_GPIO 0x1
417−#define ICELAND_VOLTAGE_CONTROL_BY_SVID2 0x2
418−
419−/* convert to Q8.8 format for firmware */
420−#define ICELAND_Q88_FORMAT_CONVERSION_UNIT 256
421−
422−#define ICELAND_UNUSED_GPIO_PIN 0x7F
423−
424−#endif
drivers/gpu/drm/amd/powerplay/hwmgr/iceland_powertune.c+0−490
@@ -1,490 +0,0 @@
1−/*
2− * Copyright 2016 Advanced Micro Devices, Inc.
3− *
4− * Permission is hereby granted, free of charge, to any person obtaining a
5− * copy of this software and associated documentation files (the "Software"),
6− * to deal in the Software without restriction, including without limitation
7− * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8− * and/or sell copies of the Software, and to permit persons to whom the
9− * Software is furnished to do so, subject to the following conditions:
10− *
11− * The above copyright notice and this permission notice shall be included in
12− * all copies or substantial portions of the Software.
13− *
14− * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15− * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16− * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17− * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18− * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19− * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20− * OTHER DEALINGS IN THE SOFTWARE.
21− *
22− * Author: Huang Rui <ray.huang@amd.com>
23− *
24− */
25−
26−#include "amdgpu.h"
27−#include "hwmgr.h"
28−#include "smumgr.h"
29−#include "iceland_hwmgr.h"
30−#include "iceland_powertune.h"
31−#include "iceland_smumgr.h"
32−#include "smu71_discrete.h"
33−#include "smu71.h"
34−#include "pp_debug.h"
35−#include "cgs_common.h"
36−#include "pp_endian.h"
37−
38−#include "bif/bif_5_0_d.h"
39−#include "bif/bif_5_0_sh_mask.h"
40−
41−#define VOLTAGE_SCALE 4
42−#define POWERTUNE_DEFAULT_SET_MAX 1
43−
44−#define DEVICE_ID_VI_ICELAND_M_6900 0x6900
45−#define DEVICE_ID_VI_ICELAND_M_6901 0x6901
46−#define DEVICE_ID_VI_ICELAND_M_6902 0x6902
47−#define DEVICE_ID_VI_ICELAND_M_6903 0x6903
48−
49−
50−struct iceland_pt_defaults defaults_iceland =
51−{
52− /*
53− * sviLoadLIneEn, SviLoadLineVddC, TDC_VDDC_ThrottleReleaseLimitPerc,
54− * TDC_MAWt, TdcWaterfallCtl, DTEAmbientTempBase, DisplayCac, BAPM_TEMP_GRADIENT
55− */
56− 1, 0xF, 0xFD, 0x19, 5, 45, 0, 0xB0000,
57− { 0x79, 0x253, 0x25D, 0xAE, 0x72, 0x80, 0x83, 0x86, 0x6F, 0xC8, 0xC9, 0xC9, 0x2F, 0x4D, 0x61 },
58− { 0x17C, 0x172, 0x180, 0x1BC, 0x1B3, 0x1BD, 0x206, 0x200, 0x203, 0x25D, 0x25A, 0x255, 0x2C3, 0x2C5, 0x2B4 }
59−};
60−
61−/* 35W - XT, XTL */
62−struct iceland_pt_defaults defaults_icelandxt =
63−{
64− /*
65− * sviLoadLIneEn, SviLoadLineVddC,
66− * TDC_VDDC_ThrottleReleaseLimitPerc, TDC_MAWt,
67− * TdcWaterfallCtl, DTEAmbientTempBase, DisplayCac,
68− * BAPM_TEMP_GRADIENT
69− */
70− 1, 0xF, 0xFD, 0x19, 5, 45, 0, 0x0,
71− { 0xA7, 0x0, 0x0, 0xB5, 0x0, 0x0, 0x9F, 0x0, 0x0, 0xD6, 0x0, 0x0, 0xD7, 0x0, 0x0},
72− { 0x1EA, 0x0, 0x0, 0x224, 0x0, 0x0, 0x25E, 0x0, 0x0, 0x28E, 0x0, 0x0, 0x2AB, 0x0, 0x0}
73−};
74−
75−/* 25W - PRO, LE */
76−struct iceland_pt_defaults defaults_icelandpro =
77−{
78− /*
79− * sviLoadLIneEn, SviLoadLineVddC,
80− * TDC_VDDC_ThrottleReleaseLimitPerc, TDC_MAWt,
81− * TdcWaterfallCtl, DTEAmbientTempBase, DisplayCac,
82− * BAPM_TEMP_GRADIENT
83− */
84− 1, 0xF, 0xFD, 0x19, 5, 45, 0, 0x0,
85− { 0xB7, 0x0, 0x0, 0xC3, 0x0, 0x0, 0xB5, 0x0, 0x0, 0xEA, 0x0, 0x0, 0xE6, 0x0, 0x0},
86− { 0x1EA, 0x0, 0x0, 0x224, 0x0, 0x0, 0x25E, 0x0, 0x0, 0x28E, 0x0, 0x0, 0x2AB, 0x0, 0x0}
87−};
88−
89−void iceland_initialize_power_tune_defaults(struct pp_hwmgr *hwmgr)
90−{
91− struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
92− uint32_t tmp = 0;
93− struct cgs_system_info sys_info = {0};
94− uint32_t pdev_id;
95−
96− sys_info.size = sizeof(struct cgs_system_info);
97− sys_info.info_id = CGS_SYSTEM_INFO_PCIE_DEV;
98− cgs_query_system_info(hwmgr->device, &sys_info);
99− pdev_id = (uint32_t)sys_info.value;
100−
101− switch (pdev_id) {
102− case DEVICE_ID_VI_ICELAND_M_6900:
103− case DEVICE_ID_VI_ICELAND_M_6903:
104− data->power_tune_defaults = &defaults_icelandxt;
105− break;
106−
107− case DEVICE_ID_VI_ICELAND_M_6901:
108− case DEVICE_ID_VI_ICELAND_M_6902:
109− data->power_tune_defaults = &defaults_icelandpro;
110− break;
111− default:
112− /* TODO: need to assign valid defaults */
113− data->power_tune_defaults = &defaults_iceland;
114− pr_warning("Unknown V.I. Device ID.\n");
115− break;
116− }
117−
118− /* Assume disabled */
119− phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
120− PHM_PlatformCaps_PowerContainment);
121− phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
122− PHM_PlatformCaps_CAC);
123− phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
124− PHM_PlatformCaps_SQRamping);
125− phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
126− PHM_PlatformCaps_DBRamping);
127− phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
128− PHM_PlatformCaps_TDRamping);
129− phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
130− PHM_PlatformCaps_TCPRamping);
131−
132− data->ul_dte_tj_offset = tmp;
133−
134− if (!tmp) {
135− phm_cap_set(hwmgr->platform_descriptor.platformCaps,
136− PHM_PlatformCaps_CAC);
137−
138− data->fast_watermark_threshold = 100;
139−
140− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
141− PHM_PlatformCaps_PowerContainment)) {
142− tmp = 1;
143− data->enable_dte_feature = tmp ? false : true;
144− data->enable_tdc_limit_feature = tmp ? true : false;
145− data->enable_pkg_pwr_tracking_feature = tmp ? true : false;
146− }
147− }
148−}
149−
150−int iceland_populate_bapm_parameters_in_dpm_table(struct pp_hwmgr *hwmgr)
151−{
152− struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
153− struct iceland_pt_defaults *defaults = data->power_tune_defaults;
154− SMU71_Discrete_DpmTable *dpm_table = &(data->smc_state_table);
155− struct phm_cac_tdp_table *cac_dtp_table = hwmgr->dyn_state.cac_dtp_table;
156− struct phm_ppm_table *ppm = hwmgr->dyn_state.ppm_parameter_table;
157− uint16_t *def1, *def2;
158− int i, j, k;
159−
160− /*
161− * TDP number of fraction bits are changed from 8 to 7 for Iceland
162− * as requested by SMC team
163− */
164− dpm_table->DefaultTdp = PP_HOST_TO_SMC_US((uint16_t)(cac_dtp_table->usTDP * 256));
165− dpm_table->TargetTdp = PP_HOST_TO_SMC_US((uint16_t)(cac_dtp_table->usConfigurableTDP * 256));
166−
167− dpm_table->DTETjOffset = (uint8_t)data->ul_dte_tj_offset;
168−
169− dpm_table->GpuTjMax = (uint8_t)(data->thermal_temp_setting.temperature_high / PP_TEMPERATURE_UNITS_PER_CENTIGRADES);
170− dpm_table->GpuTjHyst = 8;
171−
172− dpm_table->DTEAmbientTempBase = defaults->dte_ambient_temp_base;
173−
174− /* The following are for new Iceland Multi-input fan/thermal control */
175− if(NULL != ppm) {
176− dpm_table->PPM_PkgPwrLimit = (uint16_t)ppm->dgpu_tdp * 256 / 1000;
177− dpm_table->PPM_TemperatureLimit = (uint16_t)ppm->tj_max * 256;
178− } else {
179− dpm_table->PPM_PkgPwrLimit = 0;
180− dpm_table->PPM_TemperatureLimit = 0;
181− }
182−
183− CONVERT_FROM_HOST_TO_SMC_US(dpm_table->PPM_PkgPwrLimit);
184− CONVERT_FROM_HOST_TO_SMC_US(dpm_table->PPM_TemperatureLimit);
185−
186− dpm_table->BAPM_TEMP_GRADIENT = PP_HOST_TO_SMC_UL(defaults->bamp_temp_gradient);
187− def1 = defaults->bapmti_r;
188− def2 = defaults->bapmti_rc;
189−
190− for (i = 0; i < SMU71_DTE_ITERATIONS; i++) {
191− for (j = 0; j < SMU71_DTE_SOURCES; j++) {
192− for (k = 0; k < SMU71_DTE_SINKS; k++) {
193− dpm_table->BAPMTI_R[i][j][k] = PP_HOST_TO_SMC_US(*def1);
194− dpm_table->BAPMTI_RC[i][j][k] = PP_HOST_TO_SMC_US(*def2);
195− def1++;
196− def2++;
197− }
198− }
199− }
200−
201− return 0;
202−}
203−
204−static int iceland_populate_svi_load_line(struct pp_hwmgr *hwmgr)
205−{
206− struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
207− const struct iceland_pt_defaults *defaults = data->power_tune_defaults;
208−
209− data->power_tune_table.SviLoadLineEn = defaults->svi_load_line_en;
210− data->power_tune_table.SviLoadLineVddC = defaults->svi_load_line_vddc;
211− data->power_tune_table.SviLoadLineTrimVddC = 3;
212− data->power_tune_table.SviLoadLineOffsetVddC = 0;
213−
214− return 0;
215−}
216−
217−static int iceland_populate_tdc_limit(struct pp_hwmgr *hwmgr)
218−{
219− uint16_t tdc_limit;
220− struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
221− const struct iceland_pt_defaults *defaults = data->power_tune_defaults;
222−
223− /* TDC number of fraction bits are changed from 8 to 7
224− * for Iceland as requested by SMC team
225− */
226− tdc_limit = (uint16_t)(hwmgr->dyn_state.cac_dtp_table->usTDC * 256);
227− data->power_tune_table.TDC_VDDC_PkgLimit =
228− CONVERT_FROM_HOST_TO_SMC_US(tdc_limit);
229− data->power_tune_table.TDC_VDDC_ThrottleReleaseLimitPerc =
230− defaults->tdc_vddc_throttle_release_limit_perc;
231− data->power_tune_table.TDC_MAWt = defaults->tdc_mawt;
232−
233− return 0;
234−}
235−
236−static int iceland_populate_dw8(struct pp_hwmgr *hwmgr, uint32_t fuse_table_offset)
237−{
238− struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
239− const struct iceland_pt_defaults *defaults = data->power_tune_defaults;
240− uint32_t temp;
241−
242− if (iceland_read_smc_sram_dword(hwmgr->smumgr,
243− fuse_table_offset +
244− offsetof(SMU71_Discrete_PmFuses, TdcWaterfallCtl),
245− (uint32_t *)&temp, data->sram_end))
246− PP_ASSERT_WITH_CODE(false,
247− "Attempt to read PmFuses.DW6 (SviLoadLineEn) from SMC Failed!",
248− return -EINVAL);
249− else
250− data->power_tune_table.TdcWaterfallCtl = defaults->tdc_waterfall_ctl;
251−
252− return 0;
253−}
254−
255−static int iceland_populate_temperature_scaler(struct pp_hwmgr *hwmgr)
256−{
257− return 0;
258−}
259−
260−static int iceland_populate_gnb_lpml(struct pp_hwmgr *hwmgr)
261−{
262− int i;
263− struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
264−
265− /* Currently not used. Set all to zero. */
266− for (i = 0; i < 8; i++)
267− data->power_tune_table.GnbLPML[i] = 0;
268−
269− return 0;
270−}
271−
272−static int iceland_min_max_vgnb_lpml_id_from_bapm_vddc(struct pp_hwmgr *hwmgr)
273−{
274− return 0;
275−}
276−
277−static int iceland_populate_bapm_vddc_base_leakage_sidd(struct pp_hwmgr *hwmgr)
278−{
279− struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
280− uint16_t HiSidd = data->power_tune_table.BapmVddCBaseLeakageHiSidd;
281− uint16_t LoSidd = data->power_tune_table.BapmVddCBaseLeakageLoSidd;
282− struct phm_cac_tdp_table *cac_table = hwmgr->dyn_state.cac_dtp_table;
283−
284− HiSidd = (uint16_t)(cac_table->usHighCACLeakage / 100 * 256);
285− LoSidd = (uint16_t)(cac_table->usLowCACLeakage / 100 * 256);
286−
287− data->power_tune_table.BapmVddCBaseLeakageHiSidd =
288− CONVERT_FROM_HOST_TO_SMC_US(HiSidd);
289− data->power_tune_table.BapmVddCBaseLeakageLoSidd =
290− CONVERT_FROM_HOST_TO_SMC_US(LoSidd);
291−
292− return 0;
293−}
294−
295−int iceland_populate_pm_fuses(struct pp_hwmgr *hwmgr)
296−{
297− struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
298− uint32_t pm_fuse_table_offset;
299−
300− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
301− PHM_PlatformCaps_PowerContainment)) {
302− if (iceland_read_smc_sram_dword(hwmgr->smumgr,
303− SMU71_FIRMWARE_HEADER_LOCATION +
304− offsetof(SMU71_Firmware_Header, PmFuseTable),
305− &pm_fuse_table_offset, data->sram_end))
306− PP_ASSERT_WITH_CODE(false,
307− "Attempt to get pm_fuse_table_offset Failed!",
308− return -EINVAL);
309−
310− /* DW0 - DW3 */
311− if (iceland_populate_bapm_vddc_vid_sidd(hwmgr))
312− PP_ASSERT_WITH_CODE(false,
313− "Attempt to populate bapm vddc vid Failed!",
314− return -EINVAL);
315−
316− /* DW4 - DW5 */
317− if (iceland_populate_vddc_vid(hwmgr))
318− PP_ASSERT_WITH_CODE(false,
319− "Attempt to populate vddc vid Failed!",
320− return -EINVAL);
321−
322− /* DW6 */
323− if (iceland_populate_svi_load_line(hwmgr))
324− PP_ASSERT_WITH_CODE(false,
325− "Attempt to populate SviLoadLine Failed!",
326− return -EINVAL);
327− /* DW7 */
328− if (iceland_populate_tdc_limit(hwmgr))
329− PP_ASSERT_WITH_CODE(false,
330− "Attempt to populate TDCLimit Failed!", return -EINVAL);
331− /* DW8 */
332− if (iceland_populate_dw8(hwmgr, pm_fuse_table_offset))
333− PP_ASSERT_WITH_CODE(false,
334− "Attempt to populate TdcWaterfallCtl, "
335− "LPMLTemperature Min and Max Failed!",
336− return -EINVAL);
337−
338− /* DW9-DW12 */
339− if (0 != iceland_populate_temperature_scaler(hwmgr))
340− PP_ASSERT_WITH_CODE(false,
341− "Attempt to populate LPMLTemperatureScaler Failed!",
342− return -EINVAL);
343−
344− /* DW13-DW16 */
345− if (iceland_populate_gnb_lpml(hwmgr))
346− PP_ASSERT_WITH_CODE(false,
347− "Attempt to populate GnbLPML Failed!",
348− return -EINVAL);
349−
350− /* DW17 */
351− if (iceland_min_max_vgnb_lpml_id_from_bapm_vddc(hwmgr))
352− PP_ASSERT_WITH_CODE(false,
353− "Attempt to populate GnbLPML Min and Max Vid Failed!",
354− return -EINVAL);
355−
356− /* DW18 */
357− if (iceland_populate_bapm_vddc_base_leakage_sidd(hwmgr))
358− PP_ASSERT_WITH_CODE(false,
359− "Attempt to populate BapmVddCBaseLeakage Hi and Lo Sidd Failed!",
360− return -EINVAL);
361−
362− if (iceland_copy_bytes_to_smc(hwmgr->smumgr, pm_fuse_table_offset,
363− (uint8_t *)&data->power_tune_table,
364− sizeof(struct SMU71_Discrete_PmFuses), data->sram_end))
365− PP_ASSERT_WITH_CODE(false,
366− "Attempt to download PmFuseTable Failed!",
367− return -EINVAL);
368− }
369− return 0;
370−}
371−
372−int iceland_enable_smc_cac(struct pp_hwmgr *hwmgr)
373−{
374− struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
375− int result = 0;
376−
377− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
378− PHM_PlatformCaps_CAC)) {
379− int smc_result;
380− smc_result = smum_send_msg_to_smc(hwmgr->smumgr,
381− (uint16_t)(PPSMC_MSG_EnableCac));
382− PP_ASSERT_WITH_CODE((0 == smc_result),
383− "Failed to enable CAC in SMC.", result = -1);
384−
385− data->cac_enabled = (0 == smc_result) ? true : false;
386− }
387− return result;
388−}
389−
390−static int iceland_set_power_limit(struct pp_hwmgr *hwmgr, uint32_t n)
391−{
392− struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
393−
394− if(data->power_containment_features &
395− POWERCONTAINMENT_FEATURE_PkgPwrLimit)
396− return smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
397− PPSMC_MSG_PkgPwrSetLimit, n);
398− return 0;
399−}
400−
401−static int iceland_set_overdriver_target_tdp(struct pp_hwmgr *pHwMgr, uint32_t target_tdp)
402−{
403− return smum_send_msg_to_smc_with_parameter(pHwMgr->smumgr,
404− PPSMC_MSG_OverDriveSetTargetTdp, target_tdp);
405−}
406−
407−int iceland_enable_power_containment(struct pp_hwmgr *hwmgr)
408−{
409− struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
410− SMU71_Discrete_DpmTable *dpm_table = &data->smc_state_table;
411− int smc_result;
412− int result = 0;
413− uint32_t is_asic_kicker;
414−
415− data->power_containment_features = 0;
416− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
417− PHM_PlatformCaps_PowerContainment)) {
418− is_asic_kicker = cgs_read_register(hwmgr->device, mmCC_BIF_BX_STRAP2);
419− is_asic_kicker = (is_asic_kicker >> 12) & 0x01;
420−
421− if (data->enable_bapm_feature &&
422− (!is_asic_kicker ||
423− phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
424− PHM_PlatformCaps_DisableUsingActualTemperatureForPowerCalc))) {
425− smc_result = smum_send_msg_to_smc(hwmgr->smumgr,
426− (uint16_t)(PPSMC_MSG_EnableDTE));
427− PP_ASSERT_WITH_CODE((0 == smc_result),
428− "Failed to enable BAPM in SMC.", result = -1;);
429− if (0 == smc_result)
430− data->power_containment_features |= POWERCONTAINMENT_FEATURE_BAPM;
431− }
432−
433− if (is_asic_kicker && !phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
434− PHM_PlatformCaps_DisableUsingActualTemperatureForPowerCalc))
435− dpm_table->DTEMode = 2;
436−
437− if (data->enable_tdc_limit_feature) {
438− smc_result = smum_send_msg_to_smc(hwmgr->smumgr,
439− (uint16_t)(PPSMC_MSG_TDCLimitEnable));
440− PP_ASSERT_WITH_CODE((0 == smc_result),
441− "Failed to enable TDCLimit in SMC.", result = -1;);
442− if (0 == smc_result)
443− data->power_containment_features |=
444− POWERCONTAINMENT_FEATURE_TDCLimit;
445− }
446−
447− if (data->enable_pkg_pwr_tracking_feature) {
448− smc_result = smum_send_msg_to_smc(hwmgr->smumgr,
449− (uint16_t)(PPSMC_MSG_PkgPwrLimitEnable));
450− PP_ASSERT_WITH_CODE((0 == smc_result),
451− "Failed to enable PkgPwrTracking in SMC.", result = -1;);
452− if (0 == smc_result) {
453− struct phm_cac_tdp_table *cac_table =
454− hwmgr->dyn_state.cac_dtp_table;
455− uint32_t default_limit =
456− (uint32_t)(cac_table->usMaximumPowerDeliveryLimit * 256);
457−
458− data->power_containment_features |=
459− POWERCONTAINMENT_FEATURE_PkgPwrLimit;
460−
461− if (iceland_set_power_limit(hwmgr, default_limit))
462− printk(KERN_ERR "Failed to set Default Power Limit in SMC!");
463− }
464− }
465− }
466− return result;
467−}
468−
469−int iceland_power_control_set_level(struct pp_hwmgr *hwmgr)
470−{
471− struct phm_cac_tdp_table *cac_table = hwmgr->dyn_state.cac_dtp_table;
472− int adjust_percent, target_tdp;
473− int result = 0;
474−
475− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
476− PHM_PlatformCaps_PowerContainment)) {
477− /* adjustment percentage has already been validated */
478− adjust_percent = hwmgr->platform_descriptor.TDPAdjustmentPolarity ?
479− hwmgr->platform_descriptor.TDPAdjustment :
480− (-1 * hwmgr->platform_descriptor.TDPAdjustment);
481− /*
482− * SMC requested that target_tdp to be 7 bit fraction in DPM table
483− * but message to be 8 bit fraction for messages
484− */
485− target_tdp = ((100 + adjust_percent) * (int)(cac_table->usTDP * 256)) / 100;
486− result = iceland_set_overdriver_target_tdp(hwmgr, (uint32_t)target_tdp);
487− }
488−
489− return result;
490−}
drivers/gpu/drm/amd/powerplay/hwmgr/iceland_powertune.h+0−74
@@ -1,74 +0,0 @@
1−/*
2− * Copyright 2016 Advanced Micro Devices, Inc.
3− *
4− * Permission is hereby granted, free of charge, to any person obtaining a
5− * copy of this software and associated documentation files (the "Software"),
6− * to deal in the Software without restriction, including without limitation
7− * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8− * and/or sell copies of the Software, and to permit persons to whom the
9− * Software is furnished to do so, subject to the following conditions:
10− *
11− * The above copyright notice and this permission notice shall be included in
12− * all copies or substantial portions of the Software.
13− *
14− * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15− * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16− * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17− * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18− * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19− * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20− * OTHER DEALINGS IN THE SOFTWARE.
21− *
22− * Author: Huang Rui <ray.huang@amd.com>
23− *
24− */
25−#ifndef ICELAND_POWERTUNE_H
26−#define ICELAND_POWERTUNE_H
27−
28−#include "smu71.h"
29−
30−enum iceland_pt_config_reg_type {
31− ICELAND_CONFIGREG_MMR = 0,
32− ICELAND_CONFIGREG_SMC_IND,
33− ICELAND_CONFIGREG_DIDT_IND,
34− ICELAND_CONFIGREG_CACHE,
35− ICELAND_CONFIGREG_MAX
36−};
37−
38−/* PowerContainment Features */
39−#define POWERCONTAINMENT_FEATURE_DTE 0x00000001
40−#define POWERCONTAINMENT_FEATURE_TDCLimit 0x00000002
41−#define POWERCONTAINMENT_FEATURE_PkgPwrLimit 0x00000004
42−#define POWERCONTAINMENT_FEATURE_BAPM 0x00000001
43−
44−struct iceland_pt_config_reg {
45− uint32_t offset;
46− uint32_t mask;
47− uint32_t shift;
48− uint32_t value;
49− enum iceland_pt_config_reg_type type;
50−};
51−
52−struct iceland_pt_defaults
53−{
54− uint8_t svi_load_line_en;
55− uint8_t svi_load_line_vddc;
56− uint8_t tdc_vddc_throttle_release_limit_perc;
57− uint8_t tdc_mawt;
58− uint8_t tdc_waterfall_ctl;
59− uint8_t dte_ambient_temp_base;
60− uint32_t display_cac;
61− uint32_t bamp_temp_gradient;
62− uint16_t bapmti_r[SMU71_DTE_ITERATIONS * SMU71_DTE_SOURCES * SMU71_DTE_SINKS];
63− uint16_t bapmti_rc[SMU71_DTE_ITERATIONS * SMU71_DTE_SOURCES * SMU71_DTE_SINKS];
64−};
65−
66−void iceland_initialize_power_tune_defaults(struct pp_hwmgr *hwmgr);
67−int iceland_populate_bapm_parameters_in_dpm_table(struct pp_hwmgr *hwmgr);
68−int iceland_populate_pm_fuses(struct pp_hwmgr *hwmgr);
69−int iceland_enable_smc_cac(struct pp_hwmgr *hwmgr);
70−int iceland_enable_power_containment(struct pp_hwmgr *hwmgr);
71−int iceland_power_control_set_level(struct pp_hwmgr *hwmgr);
72−
73−#endif /* ICELAND_POWERTUNE_H */
74−
drivers/gpu/drm/amd/powerplay/hwmgr/iceland_thermal.c+0−595
@@ -1,595 +0,0 @@
1−/*
2− * Copyright 2016 Advanced Micro Devices, Inc.
3− *
4− * Permission is hereby granted, free of charge, to any person obtaining a
5− * copy of this software and associated documentation files (the "Software"),
6− * to deal in the Software without restriction, including without limitation
7− * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8− * and/or sell copies of the Software, and to permit persons to whom the
9− * Software is furnished to do so, subject to the following conditions:
10− *
11− * The above copyright notice and this permission notice shall be included in
12− * all copies or substantial portions of the Software.
13− *
14− * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15− * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16− * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17− * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18− * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19− * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20− * OTHER DEALINGS IN THE SOFTWARE.
21− *
22− * Author: Huang Rui <ray.huang@amd.com>
23− *
24− */
25−#include <asm/div64.h>
26−#include "iceland_thermal.h"
27−#include "iceland_hwmgr.h"
28−#include "iceland_smumgr.h"
29−#include "atombios.h"
30−#include "ppsmc.h"
31−
32−#include "gmc/gmc_8_1_d.h"
33−#include "gmc/gmc_8_1_sh_mask.h"
34−
35−#include "bif/bif_5_0_d.h"
36−#include "bif/bif_5_0_sh_mask.h"
37−
38−#include "smu/smu_7_1_1_d.h"
39−#include "smu/smu_7_1_1_sh_mask.h"
40−
41−
42−/**
43−* Get Fan Speed Control Parameters.
44−* @param hwmgr the address of the powerplay hardware manager.
45−* @param pSpeed is the address of the structure where the result is to be placed.
46−* @exception Always succeeds except if we cannot zero out the output structure.
47−*/
48−int iceland_fan_ctrl_get_fan_speed_info(struct pp_hwmgr *hwmgr,
49− struct phm_fan_speed_info *fan_speed_info)
50−{
51−
52− if (hwmgr->thermal_controller.fanInfo.bNoFan)
53− return 0;
54−
55− fan_speed_info->supports_percent_read = true;
56− fan_speed_info->supports_percent_write = true;
57− fan_speed_info->min_percent = 0;
58− fan_speed_info->max_percent = 100;
59−
60− if (0 != hwmgr->thermal_controller.fanInfo.ucTachometerPulsesPerRevolution) {
61− fan_speed_info->supports_rpm_read = true;
62− fan_speed_info->supports_rpm_write = true;
63− fan_speed_info->min_rpm = hwmgr->thermal_controller.fanInfo.ulMinRPM;
64− fan_speed_info->max_rpm = hwmgr->thermal_controller.fanInfo.ulMaxRPM;
65− } else {
66− fan_speed_info->min_rpm = 0;
67− fan_speed_info->max_rpm = 0;
68− }
69−
70− return 0;
71−}
72−
73−/**
74−* Get Fan Speed in percent.
75−* @param hwmgr the address of the powerplay hardware manager.
76−* @param pSpeed is the address of the structure where the result is to be placed.
77−* @exception Fails is the 100% setting appears to be 0.
78−*/
79−int iceland_fan_ctrl_get_fan_speed_percent(struct pp_hwmgr *hwmgr, uint32_t *speed)
80−{
81− uint32_t duty100;
82− uint32_t duty;
83− uint64_t tmp64;
84−
85− if (hwmgr->thermal_controller.fanInfo.bNoFan)
86− return 0;
87−
88− duty100 = PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_FDO_CTRL1, FMAX_DUTY100);
89− duty = PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_THERMAL_STATUS, FDO_PWM_DUTY);
90−
91− if (0 == duty100)
92− return -EINVAL;
93−
94−
95− tmp64 = (uint64_t)duty * 100;
96− do_div(tmp64, duty100);
97− *speed = (uint32_t)tmp64;
98−
99− if (*speed > 100)
100− *speed = 100;
101−
102− return 0;
103−}
104−
105−/**
106−* Get Fan Speed in RPM.
107−* @param hwmgr the address of the powerplay hardware manager.
108−* @param speed is the address of the structure where the result is to be placed.
109−* @exception Returns not supported if no fan is found or if pulses per revolution are not set
110−*/
111−int iceland_fan_ctrl_get_fan_speed_rpm(struct pp_hwmgr *hwmgr, uint32_t *speed)
112−{
113− return 0;
114−}
115−
116−/**
117−* Set Fan Speed Control to static mode, so that the user can decide what speed to use.
118−* @param hwmgr the address of the powerplay hardware manager.
119−* mode the fan control mode, 0 default, 1 by percent, 5, by RPM
120−* @exception Should always succeed.
121−*/
122−int iceland_fan_ctrl_set_static_mode(struct pp_hwmgr *hwmgr, uint32_t mode)
123−{
124−
125− if (hwmgr->fan_ctrl_is_in_default_mode) {
126− hwmgr->fan_ctrl_default_mode = PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_FDO_CTRL2, FDO_PWM_MODE);
127− hwmgr->tmin = PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_FDO_CTRL2, TMIN);
128− hwmgr->fan_ctrl_is_in_default_mode = false;
129− }
130−
131− PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_FDO_CTRL2, TMIN, 0);
132− PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_FDO_CTRL2, FDO_PWM_MODE, mode);
133−
134− return 0;
135−}
136−
137−/**
138−* Reset Fan Speed Control to default mode.
139−* @param hwmgr the address of the powerplay hardware manager.
140−* @exception Should always succeed.
141−*/
142−static int iceland_fan_ctrl_set_default_mode(struct pp_hwmgr *hwmgr)
143−{
144− if (!hwmgr->fan_ctrl_is_in_default_mode) {
145− PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_FDO_CTRL2, FDO_PWM_MODE, hwmgr->fan_ctrl_default_mode);
146− PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_FDO_CTRL2, TMIN, hwmgr->tmin);
147− hwmgr->fan_ctrl_is_in_default_mode = true;
148− }
149−
150− return 0;
151−}
152−
153−int iceland_fan_ctrl_start_smc_fan_control(struct pp_hwmgr *hwmgr)
154−{
155− return (smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_StartFanControl) == 0) ? 0 : -EINVAL;
156−}
157−
158−
159−int iceland_fan_ctrl_stop_smc_fan_control(struct pp_hwmgr *hwmgr)
160−{
161− return (smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_StopFanControl) == 0) ? 0 : -EINVAL;
162−}
163−
164−/**
165−* Set Fan Speed in percent.
166−* @param hwmgr the address of the powerplay hardware manager.
167−* @param speed is the percentage value (0% - 100%) to be set.
168−* @exception Fails is the 100% setting appears to be 0.
169−*/
170−int iceland_fan_ctrl_set_fan_speed_percent(struct pp_hwmgr *hwmgr, uint32_t speed)
171−{
172− uint32_t duty100;
173− uint32_t duty;
174− uint64_t tmp64;
175−
176− if (hwmgr->thermal_controller.fanInfo.bNoFan)
177− return -EINVAL;
178−
179− if (speed > 100) {
180− pr_warning("Cannot set more than 100%% duty cycle. Set it to 100.\n");
181− speed = 100;
182− }
183−
184− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_MicrocodeFanControl))
185− iceland_fan_ctrl_stop_smc_fan_control(hwmgr);
186−
187− duty100 = PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_FDO_CTRL1, FMAX_DUTY100);
188−
189− if (0 == duty100)
190− return -EINVAL;
191−
192− tmp64 = (uint64_t)speed * duty100;
193− do_div(tmp64, 100);
194− duty = (uint32_t)tmp64;
195−
196− PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_FDO_CTRL0, FDO_STATIC_DUTY, duty);
197−
198− return iceland_fan_ctrl_set_static_mode(hwmgr, FDO_PWM_MODE_STATIC);
199−}
200−
201−/**
202−* Reset Fan Speed to default.
203−* @param hwmgr the address of the powerplay hardware manager.
204−* @exception Always succeeds.
205−*/
206−int iceland_fan_ctrl_reset_fan_speed_to_default(struct pp_hwmgr *hwmgr)
207−{
208− int result;
209−
210− if (hwmgr->thermal_controller.fanInfo.bNoFan)
211− return 0;
212−
213− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_MicrocodeFanControl)) {
214− result = iceland_fan_ctrl_set_static_mode(hwmgr, FDO_PWM_MODE_STATIC);
215− if (0 == result)
216− result = iceland_fan_ctrl_start_smc_fan_control(hwmgr);
217− } else
218− result = iceland_fan_ctrl_set_default_mode(hwmgr);
219−
220− return result;
221−}
222−
223−/**
224−* Set Fan Speed in RPM.
225−* @param hwmgr the address of the powerplay hardware manager.
226−* @param speed is the percentage value (min - max) to be set.
227−* @exception Fails is the speed not lie between min and max.
228−*/
229−int iceland_fan_ctrl_set_fan_speed_rpm(struct pp_hwmgr *hwmgr, uint32_t speed)
230−{
231− return 0;
232−}
233−
234−/**
235−* Reads the remote temperature from the SIslands thermal controller.
236−*
237−* @param hwmgr The address of the hardware manager.
238−*/
239−int iceland_thermal_get_temperature(struct pp_hwmgr *hwmgr)
240−{
241− int temp;
242−
243− temp = PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_MULT_THERMAL_STATUS, CTF_TEMP);
244−
245− /*
246− * Bit 9 means the reading is lower than the lowest usable
247− * value.
248− */
249− if (0 != (0x200 & temp))
250− temp = ICELAND_THERMAL_MAXIMUM_TEMP_READING;
251− else
252− temp = (temp & 0x1ff);
253−
254− temp = temp * PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
255−
256− return temp;
257−}
258−
259−/**
260−* Set the requested temperature range for high and low alert signals
261−*
262−* @param hwmgr The address of the hardware manager.
263−* @param range Temperature range to be programmed for high and low alert signals
264−* @exception PP_Result_BadInput if the input data is not valid.
265−*/
266−static int iceland_thermal_set_temperature_range(struct pp_hwmgr *hwmgr, uint32_t low_temp, uint32_t high_temp)
267−{
268− uint32_t low = ICELAND_THERMAL_MINIMUM_ALERT_TEMP * PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
269− uint32_t high = ICELAND_THERMAL_MAXIMUM_ALERT_TEMP * PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
270−
271− if (low < low_temp)
272− low = low_temp;
273− if (high > high_temp)
274− high = high_temp;
275−
276− if (low > high)
277− return -EINVAL;
278−
279− PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_THERMAL_INT, DIG_THERM_INTH, (high / PP_TEMPERATURE_UNITS_PER_CENTIGRADES));
280− PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_THERMAL_INT, DIG_THERM_INTL, (low / PP_TEMPERATURE_UNITS_PER_CENTIGRADES));
281− PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_THERMAL_CTRL, DIG_THERM_DPM, (high / PP_TEMPERATURE_UNITS_PER_CENTIGRADES));
282−
283− return 0;
284−}
285−
286−/**
287−* Programs thermal controller one-time setting registers
288−*
289−* @param hwmgr The address of the hardware manager.
290−*/
291−static int iceland_thermal_initialize(struct pp_hwmgr *hwmgr)
292−{
293− if (0 != hwmgr->thermal_controller.fanInfo.ucTachometerPulsesPerRevolution)
294− PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
295− CG_TACH_CTRL, EDGE_PER_REV,
296− hwmgr->thermal_controller.fanInfo.ucTachometerPulsesPerRevolution - 1);
297−
298− PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_FDO_CTRL2, TACH_PWM_RESP_RATE, 0x28);
299−
300− return 0;
301−}
302−
303−/**
304−* Enable thermal alerts on the RV770 thermal controller.
305−*
306−* @param hwmgr The address of the hardware manager.
307−*/
308−static int iceland_thermal_enable_alert(struct pp_hwmgr *hwmgr)
309−{
310− uint32_t alert;
311−
312− alert = PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_THERMAL_INT, THERM_INT_MASK);
313− alert &= ~(ICELAND_THERMAL_HIGH_ALERT_MASK | ICELAND_THERMAL_LOW_ALERT_MASK);
314− PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_THERMAL_INT, THERM_INT_MASK, alert);
315−
316− /* send message to SMU to enable internal thermal interrupts */
317− return (smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_Thermal_Cntl_Enable) == 0) ? 0 : -1;
318−}
319−
320−/**
321−* Disable thermal alerts on the RV770 thermal controller.
322−* @param hwmgr The address of the hardware manager.
323−*/
324−static int iceland_thermal_disable_alert(struct pp_hwmgr *hwmgr)
325−{
326− uint32_t alert;
327−
328− alert = PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_THERMAL_INT, THERM_INT_MASK);
329− alert |= (ICELAND_THERMAL_HIGH_ALERT_MASK | ICELAND_THERMAL_LOW_ALERT_MASK);
330− PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_THERMAL_INT, THERM_INT_MASK, alert);
331−
332− /* send message to SMU to disable internal thermal interrupts */
333− return (smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_Thermal_Cntl_Disable) == 0) ? 0 : -1;
334−}
335−
336−/**
337−* Uninitialize the thermal controller.
338−* Currently just disables alerts.
339−* @param hwmgr The address of the hardware manager.
340−*/
341−int iceland_thermal_stop_thermal_controller(struct pp_hwmgr *hwmgr)
342−{
343− int result = iceland_thermal_disable_alert(hwmgr);
344−
345− if (result)
346− pr_warning("Failed to disable thermal alerts!\n");
347−
348− if (hwmgr->thermal_controller.fanInfo.bNoFan)
349− iceland_fan_ctrl_set_default_mode(hwmgr);
350−
351− return result;
352−}
353−
354−/**
355−* Set up the fan table to control the fan using the SMC.
356−* @param hwmgr the address of the powerplay hardware manager.
357−* @param pInput the pointer to input data
358−* @param pOutput the pointer to output data
359−* @param pStorage the pointer to temporary storage
360−* @param Result the last failure code
361−* @return result from set temperature range routine
362−*/
363−int tf_iceland_thermal_setup_fan_table(struct pp_hwmgr *hwmgr, void *input, void *output, void *storage, int result)
364−{
365− struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend);
366− SMU71_Discrete_FanTable fan_table = { FDO_MODE_HARDWARE };
367− uint32_t duty100;
368− uint32_t t_diff1, t_diff2, pwm_diff1, pwm_diff2;
369− uint16_t fdo_min, slope1, slope2;
370− uint32_t reference_clock;
371− int res;
372− uint64_t tmp64;
373−
374− if (!phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_MicrocodeFanControl))
375− return 0;
376−
377− if (0 == data->fan_table_start) {
378− phm_cap_unset(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_MicrocodeFanControl);
379− return 0;
380− }
381−
382− duty100 = PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_FDO_CTRL1, FMAX_DUTY100);
383−
384− if (0 == duty100) {
385− phm_cap_unset(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_MicrocodeFanControl);
386− return 0;
387− }
388−
389− tmp64 = hwmgr->thermal_controller.advanceFanControlParameters.usPWMMin * duty100;
390− do_div(tmp64, 10000);
391− fdo_min = (uint16_t)tmp64;
392−
393− t_diff1 = hwmgr->thermal_controller.advanceFanControlParameters.usTMed - hwmgr->thermal_controller.advanceFanControlParameters.usTMin;
394− t_diff2 = hwmgr->thermal_controller.advanceFanControlParameters.usTHigh - hwmgr->thermal_controller.advanceFanControlParameters.usTMed;
395−
396− pwm_diff1 = hwmgr->thermal_controller.advanceFanControlParameters.usPWMMed - hwmgr->thermal_controller.advanceFanControlParameters.usPWMMin;
397− pwm_diff2 = hwmgr->thermal_controller.advanceFanControlParameters.usPWMHigh - hwmgr->thermal_controller.advanceFanControlParameters.usPWMMed;
398−
399− slope1 = (uint16_t)((50 + ((16 * duty100 * pwm_diff1) / t_diff1)) / 100);
400− slope2 = (uint16_t)((50 + ((16 * duty100 * pwm_diff2) / t_diff2)) / 100);
401−
402− fan_table.TempMin = cpu_to_be16((50 + hwmgr->thermal_controller.advanceFanControlParameters.usTMin) / 100);
403− fan_table.TempMed = cpu_to_be16((50 + hwmgr->thermal_controller.advanceFanControlParameters.usTMed) / 100);
404− fan_table.TempMax = cpu_to_be16((50 + hwmgr->thermal_controller.advanceFanControlParameters.usTMax) / 100);
405−
406− fan_table.Slope1 = cpu_to_be16(slope1);
407− fan_table.Slope2 = cpu_to_be16(slope2);
408−
409− fan_table.FdoMin = cpu_to_be16(fdo_min);
410−
411− fan_table.HystDown = cpu_to_be16(hwmgr->thermal_controller.advanceFanControlParameters.ucTHyst);
412−
413− fan_table.HystUp = cpu_to_be16(1);
414−
415− fan_table.HystSlope = cpu_to_be16(1);
416−
417− fan_table.TempRespLim = cpu_to_be16(5);
418−
419− reference_clock = iceland_get_xclk(hwmgr);
420−
421− fan_table.RefreshPeriod = cpu_to_be32((hwmgr->thermal_controller.advanceFanControlParameters.ulCycleDelay * reference_clock) / 1600);
422−
423− fan_table.FdoMax = cpu_to_be16((uint16_t)duty100);
424−
425− fan_table.TempSrc = (uint8_t)PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_MULT_THERMAL_CTRL, TEMP_SEL);
426−
427− //fan_table.FanControl_GL_Flag = 1;
428−
429− res = iceland_copy_bytes_to_smc(hwmgr->smumgr, data->fan_table_start, (uint8_t *)&fan_table, (uint32_t)sizeof(fan_table), data->sram_end);
430−/* TO DO FOR SOME DEVICE ID 0X692b, send this msg return invalid command.
431− if (res == 0 && hwmgr->thermal_controller.advanceFanControlParameters.ucMinimumPWMLimit != 0)
432− res = (0 == smum_send_msg_to_smc_with_parameter(hwmgr->smumgr, PPSMC_MSG_SetFanMinPwm, \
433− hwmgr->thermal_controller.advanceFanControlParameters.ucMinimumPWMLimit) ? 0 : -1);
434−
435− if (res == 0 && hwmgr->thermal_controller.advanceFanControlParameters.ulMinFanSCLKAcousticLimit != 0)
436− res = (0 == smum_send_msg_to_smc_with_parameter(hwmgr->smumgr, PPSMC_MSG_SetFanSclkTarget, \
437− hwmgr->thermal_controller.advanceFanControlParameters.ulMinFanSCLKAcousticLimit) ? 0 : -1);
438−
439− if (0 != res)
440− phm_cap_unset(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_MicrocodeFanControl);
441−*/
442− return 0;
443−}
444−
445−/**
446−* Start the fan control on the SMC.
447−* @param hwmgr the address of the powerplay hardware manager.
448−* @param pInput the pointer to input data
449−* @param pOutput the pointer to output data
450−* @param pStorage the pointer to temporary storage
451−* @param Result the last failure code
452−* @return result from set temperature range routine
453−*/
454−int tf_iceland_thermal_start_smc_fan_control(struct pp_hwmgr *hwmgr, void *input, void *output, void *storage, int result)
455−{
456−/* If the fantable setup has failed we could have disabled PHM_PlatformCaps_MicrocodeFanControl even after this function was included in the table.
457− * Make sure that we still think controlling the fan is OK.
458−*/
459− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_MicrocodeFanControl)) {
460− iceland_fan_ctrl_start_smc_fan_control(hwmgr);
461− iceland_fan_ctrl_set_static_mode(hwmgr, FDO_PWM_MODE_STATIC);
462− }
463−
464− return 0;
465−}
466−
467−/**
468−* Set temperature range for high and low alerts
469−* @param hwmgr the address of the powerplay hardware manager.
470−* @param pInput the pointer to input data
471−* @param pOutput the pointer to output data
472−* @param pStorage the pointer to temporary storage
473−* @param Result the last failure code
474−* @return result from set temperature range routine
475−*/
476−static int tf_iceland_thermal_set_temperature_range(struct pp_hwmgr *hwmgr,
477− void *input, void *output, void *storage, int result)
478−{
479− struct PP_TemperatureRange *range = (struct PP_TemperatureRange *)input;
480−
481− if (range == NULL)
482− return -EINVAL;
483−
484− return iceland_thermal_set_temperature_range(hwmgr, range->min, range->max);
485−}
486−
487−/**
488−* Programs one-time setting registers
489−* @param hwmgr the address of the powerplay hardware manager.
490−* @param pInput the pointer to input data
491−* @param pOutput the pointer to output data
492−* @param pStorage the pointer to temporary storage
493−* @param Result the last failure code
494−* @return result from initialize thermal controller routine
495−*/
496−static int tf_iceland_thermal_initialize(struct pp_hwmgr *hwmgr, void *input,
497− void *output, void *storage, int result)
498−{
499− return iceland_thermal_initialize(hwmgr);
500−}
501−
502−/**
503−* Enable high and low alerts
504−* @param hwmgr the address of the powerplay hardware manager.
505−* @param pInput the pointer to input data
506−* @param pOutput the pointer to output data
507−* @param pStorage the pointer to temporary storage
508−* @param Result the last failure code
509−* @return result from enable alert routine
510−*/
511−static int tf_iceland_thermal_enable_alert(struct pp_hwmgr *hwmgr,
512− void *input, void *output, void *storage, int result)
513−{
514− return iceland_thermal_enable_alert(hwmgr);
515−}
516−
517−/**
518−* Disable high and low alerts
519−* @param hwmgr the address of the powerplay hardware manager.
520−* @param pInput the pointer to input data
521−* @param pOutput the pointer to output data
522−* @param pStorage the pointer to temporary storage
523−* @param Result the last failure code
524−* @return result from disable alert routine
525−*/
526−static int tf_iceland_thermal_disable_alert(struct pp_hwmgr *hwmgr, void *input, void *output, void *storage, int result)
527−{
528− return iceland_thermal_disable_alert(hwmgr);
529−}
530−
531−static const struct phm_master_table_item iceland_thermal_start_thermal_controller_master_list[] = {
532− { NULL, tf_iceland_thermal_initialize },
533− { NULL, tf_iceland_thermal_set_temperature_range },
534− { NULL, tf_iceland_thermal_enable_alert },
535− /*
536− * We should restrict performance levels to low before we halt
537− * the SMC. On the other hand we are still in boot state when
538− * we do this so it would be pointless. If this assumption
539− * changes we have to revisit this table.
540− */
541− { NULL, tf_iceland_thermal_setup_fan_table},
542− { NULL, tf_iceland_thermal_start_smc_fan_control},
543− { NULL, NULL }
544−};
545−
546−static const struct phm_master_table_header iceland_thermal_start_thermal_controller_master = {
547− 0,
548− PHM_MasterTableFlag_None,
549− iceland_thermal_start_thermal_controller_master_list
550−};
551−
552−static const struct phm_master_table_item iceland_thermal_set_temperature_range_master_list[] = {
553− { NULL, tf_iceland_thermal_disable_alert},
554− { NULL, tf_iceland_thermal_set_temperature_range},
555− { NULL, tf_iceland_thermal_enable_alert},
556− { NULL, NULL }
557−};
558−
559−static const struct phm_master_table_header iceland_thermal_set_temperature_range_master = {
560− 0,
561− PHM_MasterTableFlag_None,
562− iceland_thermal_set_temperature_range_master_list
563−};
564−
565−int iceland_thermal_ctrl_uninitialize_thermal_controller(struct pp_hwmgr *hwmgr)
566−{
567− if (!hwmgr->thermal_controller.fanInfo.bNoFan)
568− iceland_fan_ctrl_set_default_mode(hwmgr);
569− return 0;
570−}
571−
572−/**
573−* Initializes the thermal controller related functions in the Hardware Manager structure.
574−* @param hwmgr The address of the hardware manager.
575−* @exception Any error code from the low-level communication.
576−*/
577−int pp_iceland_thermal_initialize(struct pp_hwmgr *hwmgr)
578−{
579− int result;
580−
581− result = phm_construct_table(hwmgr, &iceland_thermal_set_temperature_range_master, &(hwmgr->set_temperature_range));
582−
583− if (0 == result) {
584− result = phm_construct_table(hwmgr,
585− &iceland_thermal_start_thermal_controller_master,
586− &(hwmgr->start_thermal_controller));
587− if (0 != result)
588− phm_destroy_table(hwmgr, &(hwmgr->set_temperature_range));
589− }
590−
591− if (0 == result)
592− hwmgr->fan_ctrl_is_in_default_mode = true;
593− return result;
594−}
595−
drivers/gpu/drm/amd/powerplay/hwmgr/iceland_thermal.h+0−58
@@ -1,58 +0,0 @@
1−/*
2− * Copyright 2016 Advanced Micro Devices, Inc.
3− *
4− * Permission is hereby granted, free of charge, to any person obtaining a
5− * copy of this software and associated documentation files (the "Software"),
6− * to deal in the Software without restriction, including without limitation
7− * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8− * and/or sell copies of the Software, and to permit persons to whom the
9− * Software is furnished to do so, subject to the following conditions:
10− *
11− * The above copyright notice and this permission notice shall be included in
12− * all copies or substantial portions of the Software.
13− *
14− * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15− * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16− * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17− * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18− * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19− * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20− * OTHER DEALINGS IN THE SOFTWARE.
21− *
22− * Author: Huang Rui <ray.huang@amd.com>
23− *
24− */
25−
26−#ifndef ICELAND_THERMAL_H
27−#define ICELAND_THERMAL_H
28−
29−#include "hwmgr.h"
30−
31−#define ICELAND_THERMAL_HIGH_ALERT_MASK 0x1
32−#define ICELAND_THERMAL_LOW_ALERT_MASK 0x2
33−
34−#define ICELAND_THERMAL_MINIMUM_TEMP_READING -256
35−#define ICELAND_THERMAL_MAXIMUM_TEMP_READING 255
36−
37−#define ICELAND_THERMAL_MINIMUM_ALERT_TEMP 0
38−#define ICELAND_THERMAL_MAXIMUM_ALERT_TEMP 255
39−
40−#define FDO_PWM_MODE_STATIC 1
41−#define FDO_PWM_MODE_STATIC_RPM 5
42−
43−
44−extern int iceland_thermal_get_temperature(struct pp_hwmgr *hwmgr);
45−extern int iceland_thermal_stop_thermal_controller(struct pp_hwmgr *hwmgr);
46−extern int iceland_fan_ctrl_get_fan_speed_info(struct pp_hwmgr *hwmgr, struct phm_fan_speed_info *fan_speed_info);
47−extern int iceland_fan_ctrl_get_fan_speed_percent(struct pp_hwmgr *hwmgr, uint32_t *speed);
48−extern int iceland_fan_ctrl_set_static_mode(struct pp_hwmgr *hwmgr, uint32_t mode);
49−extern int iceland_fan_ctrl_set_fan_speed_percent(struct pp_hwmgr *hwmgr, uint32_t speed);
50−extern int iceland_fan_ctrl_reset_fan_speed_to_default(struct pp_hwmgr *hwmgr);
51−extern int pp_iceland_thermal_initialize(struct pp_hwmgr *hwmgr);
52−extern int iceland_thermal_ctrl_uninitialize_thermal_controller(struct pp_hwmgr *hwmgr);
53−extern int iceland_fan_ctrl_set_fan_speed_rpm(struct pp_hwmgr *hwmgr, uint32_t speed);
54−extern int iceland_fan_ctrl_get_fan_speed_rpm(struct pp_hwmgr *hwmgr, uint32_t *speed);
55−extern int iceland_fan_ctrl_stop_smc_fan_control(struct pp_hwmgr *hwmgr);
56−
57−#endif
58−
drivers/gpu/drm/amd/powerplay/hwmgr/polaris10_dyn_defaults.h+0−62
@@ -1,62 +0,0 @@
1−/*
2− * Copyright 2015 Advanced Micro Devices, Inc.
3− *
4− * Permission is hereby granted, free of charge, to any person obtaining a
5− * copy of this software and associated documentation files (the "Software"),
6− * to deal in the Software without restriction, including without limitation
7− * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8− * and/or sell copies of the Software, and to permit persons to whom the
9− * Software is furnished to do so, subject to the following conditions:
10− *
11− * The above copyright notice and this permission notice shall be included in
12− * all copies or substantial portions of the Software.
13− *
14− * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15− * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16− * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17− * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18− * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19− * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20− * OTHER DEALINGS IN THE SOFTWARE.
21− *
22− */
23−
24−#ifndef POLARIS10_DYN_DEFAULTS_H
25−#define POLARIS10_DYN_DEFAULTS_H
26−
27−
28−enum Polaris10dpm_TrendDetection {
29− Polaris10Adpm_TrendDetection_AUTO,
30− Polaris10Adpm_TrendDetection_UP,
31− Polaris10Adpm_TrendDetection_DOWN
32−};
33−typedef enum Polaris10dpm_TrendDetection Polaris10dpm_TrendDetection;
34−
35−/* We need to fill in the default values */
36−
37−
38−#define PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT0 0x3FFFC102
39−#define PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT1 0x000400
40−#define PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT2 0xC00080
41−#define PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT3 0xC00200
42−#define PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT4 0xC01680
43−#define PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT5 0xC00033
44−#define PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT6 0xC00033
45−#define PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT7 0x3FFFC000
46−
47−
48−#define PPPOLARIS10_THERMALPROTECTCOUNTER_DFLT 0x200
49−#define PPPOLARIS10_STATICSCREENTHRESHOLDUNIT_DFLT 0
50−#define PPPOLARIS10_STATICSCREENTHRESHOLD_DFLT 0x00C8
51−#define PPPOLARIS10_GFXIDLECLOCKSTOPTHRESHOLD_DFLT 0x200
52−#define PPPOLARIS10_REFERENCEDIVIDER_DFLT 4
53−
54−#define PPPOLARIS10_ULVVOLTAGECHANGEDELAY_DFLT 1687
55−
56−#define PPPOLARIS10_CGULVPARAMETER_DFLT 0x00040035
57−#define PPPOLARIS10_CGULVCONTROL_DFLT 0x00007450
58−#define PPPOLARIS10_TARGETACTIVITY_DFLT 50
59−#define PPPOLARIS10_MCLK_TARGETACTIVITY_DFLT 10
60−
61−#endif
62−
drivers/gpu/drm/amd/powerplay/hwmgr/polaris10_hwmgr.c+0−5289
@@ -1,5289 +0,0 @@
1−/*
2− * Copyright 2015 Advanced Micro Devices, Inc.
3− *
4− * Permission is hereby granted, free of charge, to any person obtaining a
5− * copy of this software and associated documentation files (the "Software"),
6− * to deal in the Software without restriction, including without limitation
7− * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8− * and/or sell copies of the Software, and to permit persons to whom the
9− * Software is furnished to do so, subject to the following conditions:
10− *
11− * The above copyright notice and this permission notice shall be included in
12− * all copies or substantial portions of the Software.
13− *
14− * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15− * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16− * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17− * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18− * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19− * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20− * OTHER DEALINGS IN THE SOFTWARE.
21− *
22− */
23−#include <linux/module.h>
24−#include <linux/slab.h>
25−#include <asm/div64.h>
26−#include "linux/delay.h"
27−#include "pp_acpi.h"
28−#include "hwmgr.h"
29−#include "polaris10_hwmgr.h"
30−#include "polaris10_powertune.h"
31−#include "polaris10_dyn_defaults.h"
32−#include "polaris10_smumgr.h"
33−#include "pp_debug.h"
34−#include "ppatomctrl.h"
35−#include "atombios.h"
36−#include "pptable_v1_0.h"
37−#include "pppcielanes.h"
38−#include "amd_pcie_helpers.h"
39−#include "hardwaremanager.h"
40−#include "process_pptables_v1_0.h"
41−#include "cgs_common.h"
42−#include "smu74.h"
43−#include "smu_ucode_xfer_vi.h"
44−#include "smu74_discrete.h"
45−#include "smu/smu_7_1_3_d.h"
46−#include "smu/smu_7_1_3_sh_mask.h"
47−#include "gmc/gmc_8_1_d.h"
48−#include "gmc/gmc_8_1_sh_mask.h"
49−#include "oss/oss_3_0_d.h"
50−#include "gca/gfx_8_0_d.h"
51−#include "bif/bif_5_0_d.h"
52−#include "bif/bif_5_0_sh_mask.h"
53−#include "gmc/gmc_8_1_d.h"
54−#include "gmc/gmc_8_1_sh_mask.h"
55−#include "bif/bif_5_0_d.h"
56−#include "bif/bif_5_0_sh_mask.h"
57−#include "dce/dce_10_0_d.h"
58−#include "dce/dce_10_0_sh_mask.h"
59−
60−#include "polaris10_thermal.h"
61−#include "polaris10_clockpowergating.h"
62−
63−#define MC_CG_ARB_FREQ_F0 0x0a
64−#define MC_CG_ARB_FREQ_F1 0x0b
65−#define MC_CG_ARB_FREQ_F2 0x0c
66−#define MC_CG_ARB_FREQ_F3 0x0d
67−
68−#define MC_CG_SEQ_DRAMCONF_S0 0x05
69−#define MC_CG_SEQ_DRAMCONF_S1 0x06
70−#define MC_CG_SEQ_YCLK_SUSPEND 0x04
71−#define MC_CG_SEQ_YCLK_RESUME 0x0a
72−
73−
74−#define SMC_RAM_END 0x40000
75−
76−#define SMC_CG_IND_START 0xc0030000
77−#define SMC_CG_IND_END 0xc0040000
78−
79−#define VOLTAGE_SCALE 4
80−#define VOLTAGE_VID_OFFSET_SCALE1 625
81−#define VOLTAGE_VID_OFFSET_SCALE2 100
82−
83−#define VDDC_VDDCI_DELTA 200
84−
85−#define MEM_FREQ_LOW_LATENCY 25000
86−#define MEM_FREQ_HIGH_LATENCY 80000
87−
88−#define MEM_LATENCY_HIGH 45
89−#define MEM_LATENCY_LOW 35
90−#define MEM_LATENCY_ERR 0xFFFF
91−
92−#define MC_SEQ_MISC0_GDDR5_SHIFT 28
93−#define MC_SEQ_MISC0_GDDR5_MASK 0xf0000000
94−#define MC_SEQ_MISC0_GDDR5_VALUE 5
95−
96−
97−#define PCIE_BUS_CLK 10000
98−#define TCLK (PCIE_BUS_CLK / 10)
99−
100−/** Values for the CG_THERMAL_CTRL::DPM_EVENT_SRC field. */
101−enum DPM_EVENT_SRC {
102− DPM_EVENT_SRC_ANALOG = 0,
103− DPM_EVENT_SRC_EXTERNAL = 1,
104− DPM_EVENT_SRC_DIGITAL = 2,
105− DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
106− DPM_EVENT_SRC_DIGITAL_OR_EXTERNAL = 4
107−};
108−
109−static const unsigned long PhwPolaris10_Magic = (unsigned long)(PHM_VIslands_Magic);
110−
111−static struct polaris10_power_state *cast_phw_polaris10_power_state(
112− struct pp_hw_power_state *hw_ps)
113−{
114− PP_ASSERT_WITH_CODE((PhwPolaris10_Magic == hw_ps->magic),
115− "Invalid Powerstate Type!",
116− return NULL);
117−
118− return (struct polaris10_power_state *)hw_ps;
119−}
120−
121−static const struct polaris10_power_state *
122−cast_const_phw_polaris10_power_state(
123− const struct pp_hw_power_state *hw_ps)
124−{
125− PP_ASSERT_WITH_CODE((PhwPolaris10_Magic == hw_ps->magic),
126− "Invalid Powerstate Type!",
127− return NULL);
128−
129− return (const struct polaris10_power_state *)hw_ps;
130−}
131−
132−static bool polaris10_is_dpm_running(struct pp_hwmgr *hwmgr)
133−{
134− return (1 == PHM_READ_INDIRECT_FIELD(hwmgr->device,
135− CGS_IND_REG__SMC, FEATURE_STATUS, VOLTAGE_CONTROLLER_ON))
136− ? true : false;
137−}
138−
139−/**
140− * Find the MC microcode version and store it in the HwMgr struct
141− *
142− * @param hwmgr the address of the powerplay hardware manager.
143− * @return always 0
144− */
145−static int phm_get_mc_microcode_version(struct pp_hwmgr *hwmgr)
146−{
147− cgs_write_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_INDEX, 0x9F);
148−
149− hwmgr->microcode_version_info.MC = cgs_read_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_DATA);
150−
151− return 0;
152−}
153−
154−static uint16_t phm_get_current_pcie_speed(struct pp_hwmgr *hwmgr)
155−{
156− uint32_t speedCntl = 0;
157−
158− /* mmPCIE_PORT_INDEX rename as mmPCIE_INDEX */
159− speedCntl = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__PCIE,
160− ixPCIE_LC_SPEED_CNTL);
161− return((uint16_t)PHM_GET_FIELD(speedCntl,
162− PCIE_LC_SPEED_CNTL, LC_CURRENT_DATA_RATE));
163−}
164−
165−static int phm_get_current_pcie_lane_number(struct pp_hwmgr *hwmgr)
166−{
167− uint32_t link_width;
168−
169− /* mmPCIE_PORT_INDEX rename as mmPCIE_INDEX */
170− link_width = PHM_READ_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__PCIE,
171− PCIE_LC_LINK_WIDTH_CNTL, LC_LINK_WIDTH_RD);
172−
173− PP_ASSERT_WITH_CODE((7 >= link_width),
174− "Invalid PCIe lane width!", return 0);
175−
176− return decode_pcie_lane_width(link_width);
177−}
178−
179−/**
180−* Enable voltage control
181−*
182−* @param pHwMgr the address of the powerplay hardware manager.
183−* @return always PP_Result_OK
184−*/
185−static int polaris10_enable_smc_voltage_controller(struct pp_hwmgr *hwmgr)
186−{
187− PP_ASSERT_WITH_CODE(
188− (hwmgr->smumgr->smumgr_funcs->send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_Voltage_Cntl_Enable) == 0),
189− "Failed to enable voltage DPM during DPM Start Function!",
190− return 1;
191− );
192−
193− return 0;
194−}
195−
196−/**
197−* Checks if we want to support voltage control
198−*
199−* @param hwmgr the address of the powerplay hardware manager.
200−*/
201−static bool polaris10_voltage_control(const struct pp_hwmgr *hwmgr)
202−{
203− const struct polaris10_hwmgr *data =
204− (const struct polaris10_hwmgr *)(hwmgr->backend);
205−
206− return (POLARIS10_VOLTAGE_CONTROL_NONE != data->voltage_control);
207−}
208−
209−/**
210−* Enable voltage control
211−*
212−* @param hwmgr the address of the powerplay hardware manager.
213−* @return always 0
214−*/
215−static int polaris10_enable_voltage_control(struct pp_hwmgr *hwmgr)
216−{
217− /* enable voltage control */
218− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
219− GENERAL_PWRMGT, VOLT_PWRMGT_EN, 1);
220−
221− return 0;
222−}
223−
224−/**
225−* Create Voltage Tables.
226−*
227−* @param hwmgr the address of the powerplay hardware manager.
228−* @return always 0
229−*/
230−static int polaris10_construct_voltage_tables(struct pp_hwmgr *hwmgr)
231−{
232− struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
233− struct phm_ppt_v1_information *table_info =
234− (struct phm_ppt_v1_information *)hwmgr->pptable;
235− int result;
236−
237− if (POLARIS10_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) {
238− result = atomctrl_get_voltage_table_v3(hwmgr,
239− VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_GPIO_LUT,
240− &(data->mvdd_voltage_table));
241− PP_ASSERT_WITH_CODE((0 == result),
242− "Failed to retrieve MVDD table.",
243− return result);
244− } else if (POLARIS10_VOLTAGE_CONTROL_BY_SVID2 == data->mvdd_control) {
245− result = phm_get_svi2_mvdd_voltage_table(&(data->mvdd_voltage_table),
246− table_info->vdd_dep_on_mclk);
247− PP_ASSERT_WITH_CODE((0 == result),
248− "Failed to retrieve SVI2 MVDD table from dependancy table.",
249− return result;);
250− }
251−
252− if (POLARIS10_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control) {
253− result = atomctrl_get_voltage_table_v3(hwmgr,
254− VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT,
255− &(data->vddci_voltage_table));
256− PP_ASSERT_WITH_CODE((0 == result),
257− "Failed to retrieve VDDCI table.",
258− return result);
259− } else if (POLARIS10_VOLTAGE_CONTROL_BY_SVID2 == data->vddci_control) {
260− result = phm_get_svi2_vddci_voltage_table(&(data->vddci_voltage_table),
261− table_info->vdd_dep_on_mclk);
262− PP_ASSERT_WITH_CODE((0 == result),
263− "Failed to retrieve SVI2 VDDCI table from dependancy table.",
264− return result);
265− }
266−
267− if (POLARIS10_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) {
268− result = phm_get_svi2_vdd_voltage_table(&(data->vddc_voltage_table),
269− table_info->vddc_lookup_table);
270− PP_ASSERT_WITH_CODE((0 == result),
271− "Failed to retrieve SVI2 VDDC table from lookup table.",
272− return result);
273− }
274−
275− PP_ASSERT_WITH_CODE(
276− (data->vddc_voltage_table.count <= (SMU74_MAX_LEVELS_VDDC)),
277− "Too many voltage values for VDDC. Trimming to fit state table.",
278− phm_trim_voltage_table_to_fit_state_table(SMU74_MAX_LEVELS_VDDC,
279− &(data->vddc_voltage_table)));
280−
281− PP_ASSERT_WITH_CODE(
282− (data->vddci_voltage_table.count <= (SMU74_MAX_LEVELS_VDDCI)),
283− "Too many voltage values for VDDCI. Trimming to fit state table.",
284− phm_trim_voltage_table_to_fit_state_table(SMU74_MAX_LEVELS_VDDCI,
285− &(data->vddci_voltage_table)));
286−
287− PP_ASSERT_WITH_CODE(
288− (data->mvdd_voltage_table.count <= (SMU74_MAX_LEVELS_MVDD)),
289− "Too many voltage values for MVDD. Trimming to fit state table.",
290− phm_trim_voltage_table_to_fit_state_table(SMU74_MAX_LEVELS_MVDD,
291− &(data->mvdd_voltage_table)));
292−
293− return 0;
294−}
295−
296−/**
297−* Programs static screed detection parameters
298−*
299−* @param hwmgr the address of the powerplay hardware manager.
300−* @return always 0
301−*/
302−static int polaris10_program_static_screen_threshold_parameters(
303− struct pp_hwmgr *hwmgr)
304−{
305− struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
306−
307− /* Set static screen threshold unit */
308− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
309− CG_STATIC_SCREEN_PARAMETER, STATIC_SCREEN_THRESHOLD_UNIT,
310− data->static_screen_threshold_unit);
311− /* Set static screen threshold */
312− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
313− CG_STATIC_SCREEN_PARAMETER, STATIC_SCREEN_THRESHOLD,
314− data->static_screen_threshold);
315−
316− return 0;
317−}
318−
319−/**
320−* Setup display gap for glitch free memory clock switching.
321−*
322−* @param hwmgr the address of the powerplay hardware manager.
323−* @return always 0
324−*/
325−static int polaris10_enable_display_gap(struct pp_hwmgr *hwmgr)
326−{
327− uint32_t display_gap =
328− cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
329− ixCG_DISPLAY_GAP_CNTL);
330−
331− display_gap = PHM_SET_FIELD(display_gap, CG_DISPLAY_GAP_CNTL,
332− DISP_GAP, DISPLAY_GAP_IGNORE);
333−
334− display_gap = PHM_SET_FIELD(display_gap, CG_DISPLAY_GAP_CNTL,
335− DISP_GAP_MCHG, DISPLAY_GAP_VBLANK);
336−
337− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
338− ixCG_DISPLAY_GAP_CNTL, display_gap);
339−
340− return 0;
341−}
342−
343−/**
344−* Programs activity state transition voting clients
345−*
346−* @param hwmgr the address of the powerplay hardware manager.
347−* @return always 0
348−*/
349−static int polaris10_program_voting_clients(struct pp_hwmgr *hwmgr)
350−{
351− struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
352−
353− /* Clear reset for voting clients before enabling DPM */
354− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
355− SCLK_PWRMGT_CNTL, RESET_SCLK_CNT, 0);
356− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
357− SCLK_PWRMGT_CNTL, RESET_BUSY_CNT, 0);
358−
359− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
360− ixCG_FREQ_TRAN_VOTING_0, data->voting_rights_clients0);
361− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
362− ixCG_FREQ_TRAN_VOTING_1, data->voting_rights_clients1);
363− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
364− ixCG_FREQ_TRAN_VOTING_2, data->voting_rights_clients2);
365− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
366− ixCG_FREQ_TRAN_VOTING_3, data->voting_rights_clients3);
367− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
368− ixCG_FREQ_TRAN_VOTING_4, data->voting_rights_clients4);
369− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
370− ixCG_FREQ_TRAN_VOTING_5, data->voting_rights_clients5);
371− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
372− ixCG_FREQ_TRAN_VOTING_6, data->voting_rights_clients6);
373− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
374− ixCG_FREQ_TRAN_VOTING_7, data->voting_rights_clients7);
375−
376− return 0;
377−}
378−
379−static int polaris10_clear_voting_clients(struct pp_hwmgr *hwmgr)
380−{
381− /* Reset voting clients before disabling DPM */
382− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
383− SCLK_PWRMGT_CNTL, RESET_SCLK_CNT, 1);
384− PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
385− SCLK_PWRMGT_CNTL, RESET_BUSY_CNT, 1);
386−
387− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
388− ixCG_FREQ_TRAN_VOTING_0, 0);
389− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
390− ixCG_FREQ_TRAN_VOTING_1, 0);
391− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
392− ixCG_FREQ_TRAN_VOTING_2, 0);
393− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
394− ixCG_FREQ_TRAN_VOTING_3, 0);
395− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
396− ixCG_FREQ_TRAN_VOTING_4, 0);
397− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
398− ixCG_FREQ_TRAN_VOTING_5, 0);
399− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
400− ixCG_FREQ_TRAN_VOTING_6, 0);
401− cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
402− ixCG_FREQ_TRAN_VOTING_7, 0);
403−
404− return 0;
405−}
406−
407−/**
408−* Get the location of various tables inside the FW image.
409−*
410−* @param hwmgr the address of the powerplay hardware manager.
411−* @return always 0
412−*/
413−static int polaris10_process_firmware_header(struct pp_hwmgr *hwmgr)
414−{
415− struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
416− struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smumgr->backend);
417− uint32_t tmp;
418− int result;
419− bool error = false;
420−
421− result = polaris10_read_smc_sram_dword(hwmgr->smumgr,
422− SMU7_FIRMWARE_HEADER_LOCATION +
423− offsetof(SMU74_Firmware_Header, DpmTable),
424− &tmp, data->sram_end);
425−
426− if (0 == result)
427− data->dpm_table_start = tmp;
428−
429− error |= (0 != result);
430−
431− result = polaris10_read_smc_sram_dword(hwmgr->smumgr,
432− SMU7_FIRMWARE_HEADER_LOCATION +
433− offsetof(SMU74_Firmware_Header, SoftRegisters),
434− &tmp, data->sram_end);
435−
436− if (!result) {
437− data->soft_regs_start = tmp;
438− smu_data->soft_regs_start = tmp;
439− }
440−
441− error |= (0 != result);
442−
443− result = polaris10_read_smc_sram_dword(hwmgr->smumgr,
444− SMU7_FIRMWARE_HEADER_LOCATION +
445− offsetof(SMU74_Firmware_Header, mcRegisterTable),
446− &tmp, data->sram_end);
447−
448− if (!result)
449− data->mc_reg_table_start = tmp;
450−
451− result = polaris10_read_smc_sram_dword(hwmgr->smumgr,
452− SMU7_FIRMWARE_HEADER_LOCATION +
453− offsetof(SMU74_Firmware_Header, FanTable),
454− &tmp, data->sram_end);
455−
456− if (!result)
457− data->fan_table_start = tmp;
458−
459− error |= (0 != result);
460−
461− result = polaris10_read_smc_sram_dword(hwmgr->smumgr,
462− SMU7_FIRMWARE_HEADER_LOCATION +
463− offsetof(SMU74_Firmware_Header, mcArbDramTimingTable),
464− &tmp, data->sram_end);
465−
466− if (!result)
467− data->arb_table_start = tmp;
468−
469− error |= (0 != result);
470−
471− result = polaris10_read_smc_sram_dword(hwmgr->smumgr,
472− SMU7_FIRMWARE_HEADER_LOCATION +
473− offsetof(SMU74_Firmware_Header, Version),
474− &tmp, data->sram_end);
475−
476− if (!result)
477− hwmgr->microcode_version_info.SMC = tmp;
478−
479− error |= (0 != result);
480−
481− return error ? -1 : 0;
482−}
483−
484−/* Copy one arb setting to another and then switch the active set.
485− * arb_src and arb_dest is one of the MC_CG_ARB_FREQ_Fx constants.
486− */
487−static int polaris10_copy_and_switch_arb_sets(struct pp_hwmgr *hwmgr,
488− uint32_t arb_src, uint32_t arb_dest)
489−{
490− uint32_t mc_arb_dram_timing;
491− uint32_t mc_arb_dram_timing2;
492− uint32_t burst_time;
493− uint32_t mc_cg_config;
494−
495− switch (arb_src) {
496− case MC_CG_ARB_FREQ_F0:
497− mc_arb_dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING);
498− mc_arb_dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2);
499− burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0);
500− break;
501− case MC_CG_ARB_FREQ_F1:
502− mc_arb_dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING_1);
503− mc_arb_dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2_1);
504− burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE1);
505− break;
506− default:
507− return -EINVAL;
508− }
509−
510− switch (arb_dest) {
511− case MC_CG_ARB_FREQ_F0:
512− cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING, mc_arb_dram_timing);
513− cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2, mc_arb_dram_timing2);
514− PHM_WRITE_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0, burst_time);
515− break;
516− case MC_CG_ARB_FREQ_F1:
517− cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING_1, mc_arb_dram_timing);
518− cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2_1, mc_arb_dram_timing2);
519− PHM_WRITE_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE1, burst_time);
520− break;
521− default:
522− return -EINVAL;
523− }
524−
525− mc_cg_config = cgs_read_register(hwmgr->device, mmMC_CG_CONFIG);
526− mc_cg_config |= 0x0000000F;
527− cgs_write_register(hwmgr->device, mmMC_CG_CONFIG, mc_cg_config);
528− PHM_WRITE_FIELD(hwmgr->device, MC_ARB_CG, CG_ARB_REQ, arb_dest);
529−
530− return 0;
531−}
532−
533−static int polaris10_reset_to_default(struct pp_hwmgr *hwmgr)
534−{
535− return smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_ResetToDefaults);
536−}
537−
538−/**
539−* Initial switch from ARB F0->F1
540−*
541−* @param hwmgr the address of the powerplay hardware manager.
542−* @return always 0
543−* This function is to be called from the SetPowerState table.
544−*/
545−static int polaris10_initial_switch_from_arbf0_to_f1(struct pp_hwmgr *hwmgr)
546−{
547− return polaris10_copy_and_switch_arb_sets(hwmgr,
548− MC_CG_ARB_FREQ_F0, MC_CG_ARB_FREQ_F1);
549−}
550−
551−static int polaris10_force_switch_to_arbf0(struct pp_hwmgr *hwmgr)
552−{
553− uint32_t tmp;
554−
555− tmp = (cgs_read_ind_register(hwmgr->device,
556− CGS_IND_REG__SMC, ixSMC_SCRATCH9) &
557− 0x0000ff00) >> 8;
558−
559− if (tmp == MC_CG_ARB_FREQ_F0)
560− return 0;
561−
562− return polaris10_copy_and_switch_arb_sets(hwmgr,
563− tmp, MC_CG_ARB_FREQ_F0);
564−}
565−
566−static int polaris10_setup_default_pcie_table(struct pp_hwmgr *hwmgr)
567−{
568− struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
569− struct phm_ppt_v1_information *table_info =
570− (struct phm_ppt_v1_information *)(hwmgr->pptable);
571− struct phm_ppt_v1_pcie_table *pcie_table = table_info->pcie_table;
572− uint32_t i, max_entry;
573−
574− PP_ASSERT_WITH_CODE((data->use_pcie_performance_levels ||
575− data->use_pcie_power_saving_levels), "No pcie performance levels!",
576− return -EINVAL);
577−
578− if (data->use_pcie_performance_levels &&
579− !data->use_pcie_power_saving_levels) {
580− data->pcie_gen_power_saving = data->pcie_gen_performance;
581− data->pcie_lane_power_saving = data->pcie_lane_performance;
582− } else if (!data->use_pcie_performance_levels &&
583− data->use_pcie_power_saving_levels) {
584− data->pcie_gen_performance = data->pcie_gen_power_saving;
585− data->pcie_lane_performance = data->pcie_lane_power_saving;
586− }
587−
588− phm_reset_single_dpm_table(&data->dpm_table.pcie_speed_table,
589− SMU74_MAX_LEVELS_LINK,
590− MAX_REGULAR_DPM_NUMBER);
591−
592− if (pcie_table != NULL) {
593− /* max_entry is used to make sure we reserve one PCIE level
594− * for boot level (fix for A+A PSPP issue).
595− * If PCIE table from PPTable have ULV entry + 8 entries,
596− * then ignore the last entry.*/
597− max_entry = (SMU74_MAX_LEVELS_LINK < pcie_table->count) ?
598− SMU74_MAX_LEVELS_LINK : pcie_table->count;
599− for (i = 1; i < max_entry; i++) {
600− phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, i - 1,
601− get_pcie_gen_support(data->pcie_gen_cap,
602− pcie_table->entries[i].gen_speed),
603− get_pcie_lane_support(data->pcie_lane_cap,
604− pcie_table->entries[i].lane_width));
605− }
606− data->dpm_table.pcie_speed_table.count = max_entry - 1;
607−
608− /* Setup BIF_SCLK levels */
609− for (i = 0; i < max_entry; i++)
610− data->bif_sclk_table[i] = pcie_table->entries[i].pcie_sclk;
611− } else {
612− /* Hardcode Pcie Table */
613− phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 0,
614− get_pcie_gen_support(data->pcie_gen_cap,
615− PP_Min_PCIEGen),
616− get_pcie_lane_support(data->pcie_lane_cap,
617− PP_Max_PCIELane));
618− phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 1,
619− get_pcie_gen_support(data->pcie_gen_cap,
620− PP_Min_PCIEGen),
621− get_pcie_lane_support(data->pcie_lane_cap,
622− PP_Max_PCIELane));
623− phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 2,
624− get_pcie_gen_support(data->pcie_gen_cap,
625− PP_Max_PCIEGen),
626− get_pcie_lane_support(data->pcie_lane_cap,
627− PP_Max_PCIELane));
628− phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 3,
629− get_pcie_gen_support(data->pcie_gen_cap,
630− PP_Max_PCIEGen),
631− get_pcie_lane_support(data->pcie_lane_cap,
632− PP_Max_PCIELane));
633− phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 4,
634− get_pcie_gen_support(data->pcie_gen_cap,
635− PP_Max_PCIEGen),
636− get_pcie_lane_support(data->pcie_lane_cap,
637− PP_Max_PCIELane));
638− phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 5,
639− get_pcie_gen_support(data->pcie_gen_cap,
640− PP_Max_PCIEGen),
641− get_pcie_lane_support(data->pcie_lane_cap,
642− PP_Max_PCIELane));
643−
644− data->dpm_table.pcie_speed_table.count = 6;
645− }
646− /* Populate last level for boot PCIE level, but do not increment count. */
647− phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table,
648− data->dpm_table.pcie_speed_table.count,
649− get_pcie_gen_support(data->pcie_gen_cap,
650− PP_Min_PCIEGen),
651− get_pcie_lane_support(data->pcie_lane_cap,
652− PP_Max_PCIELane));
653−
654− return 0;
655−}
656−
657−/*
658− * This function is to initalize all DPM state tables
659− * for SMU7 based on the dependency table.
660− * Dynamic state patching function will then trim these
661− * state tables to the allowed range based
662− * on the power policy or external client requests,
663− * such as UVD request, etc.
664− */
665−static int polaris10_setup_default_dpm_tables(struct pp_hwmgr *hwmgr)
666−{
667− struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
668− struct phm_ppt_v1_information *table_info =
669− (struct phm_ppt_v1_information *)(hwmgr->pptable);
670− uint32_t i;
671−
672− struct phm_ppt_v1_clock_voltage_dependency_table *dep_sclk_table =
673− table_info->vdd_dep_on_sclk;
674− struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table =
675− table_info->vdd_dep_on_mclk;
676−
677− PP_ASSERT_WITH_CODE(dep_sclk_table != NULL,
678− "SCLK dependency table is missing. This table is mandatory",
679− return -EINVAL);
680− PP_ASSERT_WITH_CODE(dep_sclk_table->count >= 1,
681− "SCLK dependency table has to have is missing."
682− "This table is mandatory",
683− return -EINVAL);
684−
685− PP_ASSERT_WITH_CODE(dep_mclk_table != NULL,
686− "MCLK dependency table is missing. This table is mandatory",
687− return -EINVAL);
688− PP_ASSERT_WITH_CODE(dep_mclk_table->count >= 1,
689− "MCLK dependency table has to have is missing."
690− "This table is mandatory",
691− return -EINVAL);
692−
693− /* clear the state table to reset everything to default */
694− phm_reset_single_dpm_table(
695− &data->dpm_table.sclk_table, SMU74_MAX_LEVELS_GRAPHICS, MAX_REGULAR_DPM_NUMBER);
696− phm_reset_single_dpm_table(
697− &data->dpm_table.mclk_table, SMU74_MAX_LEVELS_MEMORY, MAX_REGULAR_DPM_NUMBER);
698−
699−
700− /* Initialize Sclk DPM table based on allow Sclk values */
701− data->dpm_table.sclk_table.count = 0;
702− for (i = 0; i < dep_sclk_table->count; i++) {
703− if (i == 0 || data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count - 1].value !=
704− dep_sclk_table->entries[i].clk) {
705−
706− data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].value =
707− dep_sclk_table->entries[i].clk;
708−
709− data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].enabled =
710− (i == 0) ? true : false;
711− data->dpm_table.sclk_table.count++;
712− }
713− }
714−
715− /* Initialize Mclk DPM table based on allow Mclk values */
716− data->dpm_table.mclk_table.count = 0;
717− for (i = 0; i < dep_mclk_table->count; i++) {
718− if (i == 0 || data->dpm_table.mclk_table.dpm_levels
719− [data->dpm_table.mclk_table.count - 1].value !=
720− dep_mclk_table->entries[i].clk) {
721− data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].value =
722− dep_mclk_table->entries[i].clk;
723− data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].enabled =
724− (i == 0) ? true : false;
725− data->dpm_table.mclk_table.count++;
726− }
727− }
728−
729− /* setup PCIE gen speed levels */
730− polaris10_setup_default_pcie_table(hwmgr);
731−
732− /* save a copy of the default DPM table */
733− memcpy(&(data->golden_dpm_table), &(data->dpm_table),
734− sizeof(struct polaris10_dpm_table));
735−
736− return 0;
737−}
738−
739−/**
740− * Mvdd table preparation for SMC.
741− *
742− * @param *hwmgr The address of the hardware manager.
743− * @param *table The SMC DPM table structure to be populated.
744− * @return 0
745− */
746−static int polaris10_populate_smc_mvdd_table(struct pp_hwmgr *hwmgr,
747− SMU74_Discrete_DpmTable *table)
748−{
749− struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
750− uint32_t count, level;
751−
752− if (POLARIS10_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) {
753− count = data->mvdd_voltage_table.count;
754− if (count > SMU_MAX_SMIO_LEVELS)
755− count = SMU_MAX_SMIO_LEVELS;
756− for (level = 0; level < count; level++) {
757− table->SmioTable2.Pattern[level].Voltage =
758− PP_HOST_TO_SMC_US(data->mvdd_voltage_table.entries[count].value * VOLTAGE_SCALE);
759− /* Index into DpmTable.Smio. Drive bits from Smio entry to get this voltage level.*/
760− table->SmioTable2.Pattern[level].Smio =
761− (uint8_t) level;
762− table->Smio[level] |=
763− data->mvdd_voltage_table.entries[level].smio_low;
764− }
765− table->SmioMask2 = data->mvdd_voltage_table.mask_low;
766−
767− table->MvddLevelCount = (uint32_t) PP_HOST_TO_SMC_UL(count);
768− }
769−
770− return 0;
771−}
772−
773−static int polaris10_populate_smc_vddci_table(struct pp_hwmgr *hwmgr,
774− struct SMU74_Discrete_DpmTable *table)
775−{
776− uint32_t count, level;
777− struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
778−
779− count = data->vddci_voltage_table.count;
780−
781− if (POLARIS10_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control) {
782− if (count > SMU_MAX_SMIO_LEVELS)
783− count = SMU_MAX_SMIO_LEVELS;
784− for (level = 0; level < count; ++level) {
785− table->SmioTable1.Pattern[level].Voltage =
786− PP_HOST_TO_SMC_US(data->vddci_voltage_table.entries[level].value * VOLTAGE_SCALE);
787− table->SmioTable1.Pattern[level].Smio = (uint8_t) level;
788−
789− table->Smio[level] |= data->vddci_voltage_table.entries[level].smio_low;
790− }
791− }
792−
793− table->SmioMask1 = data->vddci_voltage_table.mask_low;
794−
795− return 0;
796−}
797−
798−/**
799−* Preparation of vddc and vddgfx CAC tables for SMC.
800−*
801−* @param hwmgr the address of the hardware manager
802−* @param table the SMC DPM table structure to be populated
803−* @return always 0
804−*/
805−static int polaris10_populate_cac_table(struct pp_hwmgr *hwmgr,
806− struct SMU74_Discrete_DpmTable *table)
807−{
808− uint32_t count;
809− uint8_t index;
810− struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
811− struct phm_ppt_v1_information *table_info =
812− (struct phm_ppt_v1_information *)(hwmgr->pptable);
813− struct phm_ppt_v1_voltage_lookup_table *lookup_table =
814− table_info->vddc_lookup_table;
815− /* tables is already swapped, so in order to use the value from it,
816− * we need to swap it back.
817− * We are populating vddc CAC data to BapmVddc table
818− * in split and merged mode
819− */
820− for (count = 0; count < lookup_table->count; count++) {
821− index = phm_get_voltage_index(lookup_table,
822− data->vddc_voltage_table.entries[count].value);
823− table->BapmVddcVidLoSidd[count] = convert_to_vid(lookup_table->entries[index].us_cac_low);
824− table->BapmVddcVidHiSidd[count] = convert_to_vid(lookup_table->entries[index].us_cac_mid);
825− table->BapmVddcVidHiSidd2[count] = convert_to_vid(lookup_table->entries[index].us_cac_high);
826− }
827−
828− return 0;
829−}
830−
831−/**
832−* Preparation of voltage tables for SMC.
833−*
834−* @param hwmgr the address of the hardware manager
835−* @param table the SMC DPM table structure to be populated
836−* @return always 0
837−*/
838−
839−static int polaris10_populate_smc_voltage_tables(struct pp_hwmgr *hwmgr,
840− struct SMU74_Discrete_DpmTable *table)
841−{
842− polaris10_populate_smc_vddci_table(hwmgr, table);
843− polaris10_populate_smc_mvdd_table(hwmgr, table);
844− polaris10_populate_cac_table(hwmgr, table);
845−
846− return 0;
847−}
848−
849−static int polaris10_populate_ulv_level(struct pp_hwmgr *hwmgr,
850− struct SMU74_Discrete_Ulv *state)
851−{
852− struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
853− struct phm_ppt_v1_information *table_info =
854− (struct phm_ppt_v1_information *)(hwmgr->pptable);
855−
856− state->CcPwrDynRm = 0;
857− state->CcPwrDynRm1 = 0;
858−
859− state->VddcOffset = (uint16_t) table_info->us_ulv_voltage_offset;
860− state->VddcOffsetVid = (uint8_t)(table_info->us_ulv_voltage_offset *
861− VOLTAGE_VID_OFFSET_SCALE2 / VOLTAGE_VID_OFFSET_SCALE1);
862−
863− state->VddcPhase = (data->vddc_phase_shed_control) ? 0 : 1;
864−
865− CONVERT_FROM_HOST_TO_SMC_UL(state->CcPwrDynRm);
866− CONVERT_FROM_HOST_TO_SMC_UL(state->CcPwrDynRm1);
867− CONVERT_FROM_HOST_TO_SMC_US(state->VddcOffset);
868−
869− return 0;
870−}
871−
872−static int polaris10_populate_ulv_state(struct pp_hwmgr *hwmgr,
873− struct SMU74_Discrete_DpmTable *table)
874−{
875− return polaris10_populate_ulv_level(hwmgr, &table->Ulv);
876−}
877−
878−static int polaris10_populate_smc_link_level(struct pp_hwmgr *hwmgr,
879− struct SMU74_Discrete_DpmTable *table)
880−{
881− struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
882− struct polaris10_dpm_table *dpm_table = &data->dpm_table;
883− int i;
884−
885− /* Index (dpm_table->pcie_speed_table.count)
886− * is reserved for PCIE boot level. */
887− for (i = 0; i <= dpm_table->pcie_speed_table.count; i++) {
888− table->LinkLevel[i].PcieGenSpeed =
889− (uint8_t)dpm_table->pcie_speed_table.dpm_levels[i].value;
890− table->LinkLevel[i].PcieLaneCount = (uint8_t)encode_pcie_lane_width(
891− dpm_table->pcie_speed_table.dpm_levels[i].param1);
892− table->LinkLevel[i].EnabledForActivity = 1;
893− table->LinkLevel[i].SPC = (uint8_t)(data->pcie_spc_cap & 0xff);
894− table->LinkLevel[i].DownThreshold = PP_HOST_TO_SMC_UL(5);
895− table->LinkLevel[i].UpThreshold = PP_HOST_TO_SMC_UL(30);
896− }
897−
898− data->smc_state_table.LinkLevelCount =
899− (uint8_t)dpm_table->pcie_speed_table.count;
900− data->dpm_level_enable_mask.pcie_dpm_enable_mask =
901− phm_get_dpm_level_enable_mask_value(&dpm_table->pcie_speed_table);
902−
903− return 0;
904−}
905−
906−static uint32_t polaris10_get_xclk(struct pp_hwmgr *hwmgr)
907−{
908− uint32_t reference_clock, tmp;
909− struct cgs_display_info info = {0};
910− struct cgs_mode_info mode_info;
911−
912− info.mode_info = &mode_info;
913−
914− tmp = PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_CLKPIN_CNTL_2, MUX_TCLK_TO_XCLK);
915−
916− if (tmp)
917− return TCLK;
918−
919− cgs_get_active_displays_info(hwmgr->device, &info);
920− reference_clock = mode_info.ref_clock;
921−
922− tmp = PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_CLKPIN_CNTL, XTALIN_DIVIDE);
923−
924− if (0 != tmp)
925− return reference_clock / 4;
926−
927− return reference_clock;
928−}
929−
930−/**
931−* Calculates the SCLK dividers using the provided engine clock
932−*
933−* @param hwmgr the address of the hardware manager
934−* @param clock the engine clock to use to populate the structure
935−* @param sclk the SMC SCLK structure to be populated
936−*/
937−static int polaris10_calculate_sclk_params(struct pp_hwmgr *hwmgr,
938− uint32_t clock, SMU_SclkSetting *sclk_setting)
939−{
940− const struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
941− const SMU74_Discrete_DpmTable *table = &(data->smc_state_table);
942− struct pp_atomctrl_clock_dividers_ai dividers;
943−
944− uint32_t ref_clock;
945− uint32_t pcc_target_percent, pcc_target_freq, ss_target_percent, ss_target_freq;
946− uint8_t i;
947− int result;
948− uint64_t temp;
949−
950− sclk_setting->SclkFrequency = clock;
951− /* get the engine clock dividers for this clock value */
952− result = atomctrl_get_engine_pll_dividers_ai(hwmgr, clock, &dividers);
953− if (result == 0) {
954− sclk_setting->Fcw_int = dividers.usSclk_fcw_int;
955− sclk_setting->Fcw_frac = dividers.usSclk_fcw_frac;
956− sclk_setting->Pcc_fcw_int = dividers.usPcc_fcw_int;
957− sclk_setting->PllRange = dividers.ucSclkPllRange;
958− sclk_setting->Sclk_slew_rate = 0x400;
959− sclk_setting->Pcc_up_slew_rate = dividers.usPcc_fcw_slew_frac;
960− sclk_setting->Pcc_down_slew_rate = 0xffff;
961− sclk_setting->SSc_En = dividers.ucSscEnable;
962− sclk_setting->Fcw1_int = dividers.usSsc_fcw1_int;
963− sclk_setting->Fcw1_frac = dividers.usSsc_fcw1_frac;
964− sclk_setting->Sclk_ss_slew_rate = dividers.usSsc_fcw_slew_frac;
965− return result;
966− }
967−
968− ref_clock = polaris10_get_xclk(hwmgr);
969−
970− for (i = 0; i < NUM_SCLK_RANGE; i++) {
971− if (clock > data->range_table[i].trans_lower_frequency
972− && clock <= data->range_table[i].trans_upper_frequency) {
973− sclk_setting->PllRange = i;
974− break;
975− }
976− }
977−
978− sclk_setting->Fcw_int = (uint16_t)((clock << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv) / ref_clock);
979− temp = clock << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv;
980− temp <<= 0x10;
981− do_div(temp, ref_clock);
982− sclk_setting->Fcw_frac = temp & 0xffff;
983−
984− pcc_target_percent = 10; /* Hardcode 10% for now. */
985− pcc_target_freq = clock - (clock * pcc_target_percent / 100);
986− sclk_setting->Pcc_fcw_int = (uint16_t)((pcc_target_freq << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv) / ref_clock);
987−
988− ss_target_percent = 2; /* Hardcode 2% for now. */
989− sclk_setting->SSc_En = 0;
990− if (ss_target_percent) {
991− sclk_setting->SSc_En = 1;
992− ss_target_freq = clock - (clock * ss_target_percent / 100);
993− sclk_setting->Fcw1_int = (uint16_t)((ss_target_freq << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv) / ref_clock);
994− temp = ss_target_freq << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv;
995− temp <<= 0x10;
996− do_div(temp, ref_clock);
997− sclk_setting->Fcw1_frac = temp & 0xffff;
998− }
999−
1000− return 0;
1001−}
1002−
1003−static int polaris10_get_dependency_volt_by_clk(struct pp_hwmgr *hwmgr,
1004− struct phm_ppt_v1_clock_voltage_dependency_table *dep_table,
1005− uint32_t clock, SMU_VoltageLevel *voltage, uint32_t *mvdd)
1006−{
1007− uint32_t i;
1008− uint16_t vddci;
1009− struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1010−
1011− *voltage = *mvdd = 0;
1012−
1013− /* clock - voltage dependency table is empty table */
1014− if (dep_table->count == 0)
1015− return -EINVAL;
1016−
1017− for (i = 0; i < dep_table->count; i++) {
1018− /* find first sclk bigger than request */
1019− if (dep_table->entries[i].clk >= clock) {
1020− *voltage |= (dep_table->entries[i].vddc *
1021− VOLTAGE_SCALE) << VDDC_SHIFT;
1022− if (POLARIS10_VOLTAGE_CONTROL_NONE == data->vddci_control)
1023− *voltage |= (data->vbios_boot_state.vddci_bootup_value *
1024− VOLTAGE_SCALE) << VDDCI_SHIFT;
1025− else if (dep_table->entries[i].vddci)
1026− *voltage |= (dep_table->entries[i].vddci *
1027− VOLTAGE_SCALE) << VDDCI_SHIFT;
1028− else {
1029− vddci = phm_find_closest_vddci(&(data->vddci_voltage_table),
1030− (dep_table->entries[i].vddc -
1031− (uint16_t)data->vddc_vddci_delta));
1032− *voltage |= (vddci * VOLTAGE_SCALE) << VDDCI_SHIFT;
1033− }
1034−
1035− if (POLARIS10_VOLTAGE_CONTROL_NONE == data->mvdd_control)
1036− *mvdd = data->vbios_boot_state.mvdd_bootup_value *
1037− VOLTAGE_SCALE;
1038− else if (dep_table->entries[i].mvdd)
1039− *mvdd = (uint32_t) dep_table->entries[i].mvdd *
1040− VOLTAGE_SCALE;
1041−
1042− *voltage |= 1 << PHASES_SHIFT;
1043− return 0;
1044− }
1045− }
1046−
1047− /* sclk is bigger than max sclk in the dependence table */
1048− *voltage |= (dep_table->entries[i - 1].vddc * VOLTAGE_SCALE) << VDDC_SHIFT;
1049−
1050− if (POLARIS10_VOLTAGE_CONTROL_NONE == data->vddci_control)
1051− *voltage |= (data->vbios_boot_state.vddci_bootup_value *
1052− VOLTAGE_SCALE) << VDDCI_SHIFT;
1053− else if (dep_table->entries[i-1].vddci) {
1054− vddci = phm_find_closest_vddci(&(data->vddci_voltage_table),
1055− (dep_table->entries[i].vddc -
1056− (uint16_t)data->vddc_vddci_delta));
1057− *voltage |= (vddci * VOLTAGE_SCALE) << VDDCI_SHIFT;
1058− }
1059−
1060− if (POLARIS10_VOLTAGE_CONTROL_NONE == data->mvdd_control)
1061− *mvdd = data->vbios_boot_state.mvdd_bootup_value * VOLTAGE_SCALE;
1062− else if (dep_table->entries[i].mvdd)
1063− *mvdd = (uint32_t) dep_table->entries[i - 1].mvdd * VOLTAGE_SCALE;
1064−
1065− return 0;
1066−}
1067−
1068−static const sclkFcwRange_t Range_Table[NUM_SCLK_RANGE] =
1069−{ {VCO_2_4, POSTDIV_DIV_BY_16, 75, 160, 112},
1070− {VCO_3_6, POSTDIV_DIV_BY_16, 112, 224, 160},
1071− {VCO_2_4, POSTDIV_DIV_BY_8, 75, 160, 112},
1072− {VCO_3_6, POSTDIV_DIV_BY_8, 112, 224, 160},
1073− {VCO_2_4, POSTDIV_DIV_BY_4, 75, 160, 112},
1074− {VCO_3_6, POSTDIV_DIV_BY_4, 112, 216, 160},
1075− {VCO_2_4, POSTDIV_DIV_BY_2, 75, 160, 108},
1076− {VCO_3_6, POSTDIV_DIV_BY_2, 112, 216, 160} };
1077−
1078−static void polaris10_get_sclk_range_table(struct pp_hwmgr *hwmgr)
1079−{
1080− uint32_t i, ref_clk;
1081− struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1082− SMU74_Discrete_DpmTable *table = &(data->smc_state_table);
1083− struct pp_atom_ctrl_sclk_range_table range_table_from_vbios = { { {0} } };
1084−
1085− ref_clk = polaris10_get_xclk(hwmgr);
1086−
1087− if (0 == atomctrl_get_smc_sclk_range_table(hwmgr, &range_table_from_vbios)) {
1088− for (i = 0; i < NUM_SCLK_RANGE; i++) {
1089− table->SclkFcwRangeTable[i].vco_setting = range_table_from_vbios.entry[i].ucVco_setting;
1090− table->SclkFcwRangeTable[i].postdiv = range_table_from_vbios.entry[i].ucPostdiv;
1091− table->SclkFcwRangeTable[i].fcw_pcc = range_table_from_vbios.entry[i].usFcw_pcc;
1092−
1093− table->SclkFcwRangeTable[i].fcw_trans_upper = range_table_from_vbios.entry[i].usFcw_trans_upper;
1094− table->SclkFcwRangeTable[i].fcw_trans_lower = range_table_from_vbios.entry[i].usRcw_trans_lower;
1095−
1096− CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_pcc);
1097− CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_trans_upper);
1098− CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_trans_lower);
1099− }
1100− return;
1101− }
1102−
1103− for (i = 0; i < NUM_SCLK_RANGE; i++) {
1104−
1105− data->range_table[i].trans_lower_frequency = (ref_clk * Range_Table[i].fcw_trans_lower) >> Range_Table[i].postdiv;
1106− data->range_table[i].trans_upper_frequency = (ref_clk * Range_Table[i].fcw_trans_upper) >> Range_Table[i].postdiv;
1107−
1108− table->SclkFcwRangeTable[i].vco_setting = Range_Table[i].vco_setting;
1109− table->SclkFcwRangeTable[i].postdiv = Range_Table[i].postdiv;
1110− table->SclkFcwRangeTable[i].fcw_pcc = Range_Table[i].fcw_pcc;
1111−
1112− table->SclkFcwRangeTable[i].fcw_trans_upper = Range_Table[i].fcw_trans_upper;
1113− table->SclkFcwRangeTable[i].fcw_trans_lower = Range_Table[i].fcw_trans_lower;
1114−
1115− CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_pcc);
1116− CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_trans_upper);
1117− CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_trans_lower);
1118− }
1119−}
1120−
1121−/**
1122−* Populates single SMC SCLK structure using the provided engine clock
1123−*
1124−* @param hwmgr the address of the hardware manager
1125−* @param clock the engine clock to use to populate the structure
1126−* @param sclk the SMC SCLK structure to be populated
1127−*/
1128−
1129−static int polaris10_populate_single_graphic_level(struct pp_hwmgr *hwmgr,
1130− uint32_t clock, uint16_t sclk_al_threshold,
1131− struct SMU74_Discrete_GraphicsLevel *level)
1132−{
1133− int result, i, temp;
1134− /* PP_Clocks minClocks; */
1135− uint32_t mvdd;
1136− struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1137− struct phm_ppt_v1_information *table_info =
1138− (struct phm_ppt_v1_information *)(hwmgr->pptable);
1139− SMU_SclkSetting curr_sclk_setting = { 0 };
1140−
1141− result = polaris10_calculate_sclk_params(hwmgr, clock, &curr_sclk_setting);
1142−
1143− /* populate graphics levels */
1144− result = polaris10_get_dependency_volt_by_clk(hwmgr,
1145− table_info->vdd_dep_on_sclk, clock,
1146− &level->MinVoltage, &mvdd);
1147−
1148− PP_ASSERT_WITH_CODE((0 == result),
1149− "can not find VDDC voltage value for "
1150− "VDDC engine clock dependency table",
1151− return result);
1152− level->ActivityLevel = sclk_al_threshold;
1153−
1154− level->CcPwrDynRm = 0;
1155− level->CcPwrDynRm1 = 0;
1156− level->EnabledForActivity = 0;
1157− level->EnabledForThrottle = 1;
1158− level->UpHyst = 10;
1159− level->DownHyst = 0;
1160− level->VoltageDownHyst = 0;
1161− level->PowerThrottle = 0;
1162−
1163− /*
1164− * TODO: get minimum clocks from dal configaration
1165− * PECI_GetMinClockSettings(hwmgr->pPECI, &minClocks);
1166− */
1167− /* data->DisplayTiming.minClockInSR = minClocks.engineClockInSR; */
1168−
1169− /* get level->DeepSleepDivId
1170− if (phm_cap_enabled(hwmgr->platformDescriptor.platformCaps, PHM_PlatformCaps_SclkDeepSleep))
1171− level->DeepSleepDivId = PhwFiji_GetSleepDividerIdFromClock(hwmgr, clock, minClocks.engineClockInSR);
1172− */
1173− PP_ASSERT_WITH_CODE((clock >= POLARIS10_MINIMUM_ENGINE_CLOCK), "Engine clock can't satisfy stutter requirement!", return 0);
1174− for (i = POLARIS10_MAX_DEEPSLEEP_DIVIDER_ID; ; i--) {
1175− temp = clock >> i;
1176−
1177− if (temp >= POLARIS10_MINIMUM_ENGINE_CLOCK || i == 0)
1178− break;
1179− }
1180−
1181− level->DeepSleepDivId = i;
1182−
1183− /* Default to slow, highest DPM level will be
1184− * set to PPSMC_DISPLAY_WATERMARK_LOW later.
1185− */
1186− if (data->update_up_hyst)
1187− level->UpHyst = (uint8_t)data->up_hyst;
1188− if (data->update_down_hyst)
1189− level->DownHyst = (uint8_t)data->down_hyst;
1190−
1191− level->SclkSetting = curr_sclk_setting;
1192−
1193− CONVERT_FROM_HOST_TO_SMC_UL(level->MinVoltage);
1194− CONVERT_FROM_HOST_TO_SMC_UL(level->CcPwrDynRm);
1195− CONVERT_FROM_HOST_TO_SMC_UL(level->CcPwrDynRm1);
1196− CONVERT_FROM_HOST_TO_SMC_US(level->ActivityLevel);
1197− CONVERT_FROM_HOST_TO_SMC_UL(level->SclkSetting.SclkFrequency);
1198− CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Fcw_int);
1199− CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Fcw_frac);
1200− CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Pcc_fcw_int);
1201− CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Sclk_slew_rate);
1202− CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Pcc_up_slew_rate);
1203− CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Pcc_down_slew_rate);
1204− CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Fcw1_int);
1205− CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Fcw1_frac);
1206− CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Sclk_ss_slew_rate);
1207− return 0;
1208−}
1209−
1210−/**
1211−* Populates all SMC SCLK levels' structure based on the trimmed allowed dpm engine clock states
1212−*
1213−* @param hwmgr the address of the hardware manager
1214−*/
1215−static int polaris10_populate_all_graphic_levels(struct pp_hwmgr *hwmgr)
1216−{
1217− struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1218− struct polaris10_dpm_table *dpm_table = &data->dpm_table;
1219− struct phm_ppt_v1_information *table_info =
1220− (struct phm_ppt_v1_information *)(hwmgr->pptable);
1221− struct phm_ppt_v1_pcie_table *pcie_table = table_info->pcie_table;
1222− uint8_t pcie_entry_cnt = (uint8_t) data->dpm_table.pcie_speed_table.count;
1223− int result = 0;
1224− uint32_t array = data->dpm_table_start +
1225− offsetof(SMU74_Discrete_DpmTable, GraphicsLevel);
1226− uint32_t array_size = sizeof(struct SMU74_Discrete_GraphicsLevel) *
1227− SMU74_MAX_LEVELS_GRAPHICS;
1228− struct SMU74_Discrete_GraphicsLevel *levels =
1229− data->smc_state_table.GraphicsLevel;
1230− uint32_t i, max_entry;
1231− uint8_t hightest_pcie_level_enabled = 0,
1232− lowest_pcie_level_enabled = 0,
1233− mid_pcie_level_enabled = 0,
1234− count = 0;
1235−
1236− polaris10_get_sclk_range_table(hwmgr);
1237−
1238− for (i = 0; i < dpm_table->sclk_table.count; i++) {
1239−
1240− result = polaris10_populate_single_graphic_level(hwmgr,
1241− dpm_table->sclk_table.dpm_levels[i].value,
1242− (uint16_t)data->activity_target[i],
1243− &(data->smc_state_table.GraphicsLevel[i]));
1244− if (result)
1245− return result;
1246−
1247− /* Making sure only DPM level 0-1 have Deep Sleep Div ID populated. */
1248− if (i > 1)
1249− levels[i].DeepSleepDivId = 0;
1250− }
1251− if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1252− PHM_PlatformCaps_SPLLShutdownSupport))
1253− data->smc_state_table.GraphicsLevel[0].SclkSetting.SSc_En = 0;
1254−
1255− data->smc_state_table.GraphicsLevel[0].EnabledForActivity = 1;
1256− data->smc_state_table.GraphicsDpmLevelCount =
1257− (uint8_t)dpm_table->sclk_table.count;
1258− data->dpm_level_enable_mask.sclk_dpm_enable_mask =
1259− phm_get_dpm_level_enable_mask_value(&dpm_table->sclk_table);
1260−
1261−
1262− if (pcie_table != NULL) {
1263− PP_ASSERT_WITH_CODE((1 <= pcie_entry_cnt),
1264− "There must be 1 or more PCIE levels defined in PPTable.",
1265− return -EINVAL);
1266− max_entry = pcie_entry_cnt - 1;
1267− for (i = 0; i < dpm_table->sclk_table.count; i++)
1268− levels[i].pcieDpmLevel =
1269− (uint8_t) ((i < max_entry) ? i : max_entry);
1270− } else {
1271− while (data->dpm_level_enable_mask.pcie_dpm_enable_mask &&
1272− ((data->dpm_level_enable_mask.pcie_dpm_enable_mask &
1273− (1 << (hightest_pcie_level_enabled + 1))) != 0))
1274− hightest_pcie_level_enabled++;
1275−
1276− while (data->dpm_level_enable_mask.pcie_dpm_enable_mask &&
1277− ((data->dpm_level_enable_mask.pcie_dpm_enable_mask &
1278− (1 << lowest_pcie_level_enabled)) == 0))
1279− lowest_pcie_level_enabled++;
1280−
1281− while ((count < hightest_pcie_level_enabled) &&
1282− ((data->dpm_level_enable_mask.pcie_dpm_enable_mask &
1283− (1 << (lowest_pcie_level_enabled + 1 + count))) == 0))
1284− count++;
1285−
1286− mid_pcie_level_enabled = (lowest_pcie_level_enabled + 1 + count) <
1287− hightest_pcie_level_enabled ?
1288− (lowest_pcie_level_enabled + 1 + count) :
1289− hightest_pcie_level_enabled;
1290−
1291− /* set pcieDpmLevel to hightest_pcie_level_enabled */
1292− for (i = 2; i < dpm_table->sclk_table.count; i++)
1293− levels[i].pcieDpmLevel = hightest_pcie_level_enabled;
1294−
1295− /* set pcieDpmLevel to lowest_pcie_level_enabled */
1296− levels[0].pcieDpmLevel = lowest_pcie_level_enabled;
1297−
1298− /* set pcieDpmLevel to mid_pcie_level_enabled */
1299− levels[1].pcieDpmLevel = mid_pcie_level_enabled;
1300− }
1301− /* level count will send to smc once at init smc table and never change */
1302− result = polaris10_copy_bytes_to_smc(hwmgr->smumgr, array, (uint8_t *)levels,
1303− (uint32_t)array_size, data->sram_end);
1304−
1305− return result;
1306−}
1307−
1308−static int polaris10_populate_single_memory_level(struct pp_hwmgr *hwmgr,
1309− uint32_t clock, struct SMU74_Discrete_MemoryLevel *mem_level)
1310−{
1311− struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1312− struct phm_ppt_v1_information *table_info =
1313− (struct phm_ppt_v1_information *)(hwmgr->pptable);
1314− int result = 0;
1315− struct cgs_display_info info = {0, 0, NULL};
1316−
1317− cgs_get_active_displays_info(hwmgr->device, &info);
1318−
1319− if (table_info->vdd_dep_on_mclk) {
1320− result = polaris10_get_dependency_volt_by_clk(hwmgr,
1321− table_info->vdd_dep_on_mclk, clock,
1322− &mem_level->MinVoltage, &mem_level->MinMvdd);
1323− PP_ASSERT_WITH_CODE((0 == result),
1324− "can not find MinVddc voltage value from memory "
1325− "VDDC voltage dependency table", return result);
1326− }
1327−
1328− mem_level->MclkFrequency = clock;
1329− mem_level->EnabledForThrottle = 1;
1330− mem_level->EnabledForActivity = 0;
1331− mem_level->UpHyst = 0;
1332− mem_level->DownHyst = 100;
1333− mem_level->VoltageDownHyst = 0;
1334− mem_level->ActivityLevel = (uint16_t)data->mclk_activity_target;
1335− mem_level->StutterEnable = false;
1336− mem_level->DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW;
1337−

3952 more lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/hwmgr/polaris10_thermal.c+0−716

This diff is large: its 717 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/hwmgr/polaris10_thermal.h+0−62

This diff is large: its 63 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/hwmgr/smu7_clockpowergating.crenamed from drivers/gpu/drm/amd/powerplay/hwmgr/polaris10_clockpowergating.c+102−58

This diff is large: its 424 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/hwmgr/smu7_clockpowergating.hrenamed from drivers/gpu/drm/amd/powerplay/hwmgr/fiji_clockpowergating.h+15−10

This diff is large: its 37 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/hwmgr/smu7_dyn_defaults.h+55−0

This diff is large: its 56 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c+4359−0

This diff is large: its 4360 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.hrenamed from drivers/gpu/drm/amd/powerplay/hwmgr/polaris10_hwmgr.h+120−121

This diff is large: its 409 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/hwmgr/smu7_powertune.crenamed from drivers/gpu/drm/amd/powerplay/hwmgr/polaris10_powertune.c+363−622

This diff is large: its 1188 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/hwmgr/smu7_powertune.hrenamed from drivers/gpu/drm/amd/powerplay/hwmgr/polaris10_powertune.h+12−31

This diff is large: its 61 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/hwmgr/smu7_thermal.crenamed from drivers/gpu/drm/amd/powerplay/hwmgr/fiji_thermal.c+74−184

This diff is large: its 545 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/hwmgr/smu7_thermal.h+58−0

This diff is large: its 59 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/hwmgr/tonga_clockpowergating.c+0−350

This diff is large: its 351 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/hwmgr/tonga_dyn_defaults.h+0−107

This diff is large: its 108 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/hwmgr/tonga_hwmgr.c+0−6370

This diff is large: its 6371 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/hwmgr/tonga_hwmgr.h+0−402

This diff is large: its 403 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/hwmgr/tonga_powertune.c+0−495

This diff is large: its 496 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/hwmgr/tonga_thermal.c+0−590

This diff is large: its 591 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/hwmgr/tonga_thermal.h+0−61

This diff is large: its 62 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/inc/amd_powerplay.h+17−2

This diff is large: its 52 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/inc/hwmgr.h+2−2

This diff is large: its 25 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/inc/polaris10_pwrvirus.h+1−2

This diff is large: its 10 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/inc/smu7_common.hrenamed from drivers/gpu/drm/amd/amdgpu/iceland_smum.h+30−13

This diff is large: its 52 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/inc/smu7_ppsmc.h+412−0

This diff is large: its 413 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/inc/smumgr.h+70−0

This diff is large: its 98 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/smumgr/Makefile+3−2

This diff is large: its 12 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/smumgr/fiji_smc.c+2374−0

This diff is large: its 2375 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/smumgr/fiji_smc.hrenamed from drivers/gpu/drm/amd/amdgpu/fiji_smum.h+25−16

This diff is large: its 55 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/smumgr/fiji_smumgr.c+45−567

This diff is large: its 756 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/smumgr/fiji_smumgr.h+13−19

This diff is large: its 51 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/smumgr/iceland_smc.c+2576−0

This diff is large: its 2577 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/smumgr/iceland_smc.hrenamed from drivers/gpu/drm/amd/powerplay/hwmgr/tonga_clockpowergating.h+15−11

This diff is large: its 33 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/smumgr/iceland_smumgr.c+75−538

This diff is large: its 702 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/smumgr/iceland_smumgr.h+35−28

This diff is large: its 75 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smc.c+2287−0

This diff is large: its 2288 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smc.hrenamed from drivers/gpu/drm/amd/amdgpu/tonga_smum.h+16−16

This diff is large: its 46 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smumgr.c+58−645

This diff is large: its 840 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smumgr.h+14−27

This diff is large: its 67 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c+589−0

This diff is large: its 590 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.h+87−0

This diff is large: its 88 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/smumgr/smumgr.c+100−1

This diff is large: its 125 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/smumgr/tonga_smc.c+3207−0

This diff is large: its 3208 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/smumgr/tonga_smc.hrenamed from drivers/gpu/drm/amd/powerplay/hwmgr/tonga_powertune.h+18−38

This diff is large: its 73 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/smumgr/tonga_smumgr.c+34−638

This diff is large: its 736 lines aren’t shown here.

drivers/gpu/drm/amd/powerplay/smumgr/tonga_smumgr.h+26−20

This diff is large: its 57 lines aren’t shown here.

drivers/gpu/drm/radeon/radeon_acpi.c+17−0

This diff is large: its 38 lines aren’t shown here.

drivers/gpu/drm/radeon/radeon_atpx_handler.c+5−0

This diff is large: its 19 lines aren’t shown here.

drivers/gpu/drm/radeon/radeon_device.c+5−6

This diff is large: its 32 lines aren’t shown here.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t