drm/amdgpu: support per device powerplay enablement (v2)
authorJammy Zhou <Jammy.Zhou@amd.com>
Tue, 10 Nov 2015 23:31:08 +0000 (18:31 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 21 Dec 2015 21:42:27 +0000 (16:42 -0500)
The amdgu_powerplay variable is global for multiple GPU instances.

v2: fold in Flora's module option change, protect adev reference in
macros

Signed-off-by: Jammy Zhou <Jammy.Zhou@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu.h
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
drivers/gpu/drm/amd/amdgpu/amdgpu_powerplay.c
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c

index 8b1ff13d50ccf22a2831a7aa85fa856c104e197c..637eff393bc7b6dc8afd11a128c92b29f6c9e26a 100644 (file)
@@ -2040,6 +2040,7 @@ struct amdgpu_device {
 
        /* powerplay */
        struct amd_powerplay            powerplay;
+       bool                            pp_enabled;
 
        /* dpm */
        struct amdgpu_pm                pm;
@@ -2268,68 +2269,68 @@ amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
 #define amdgpu_dpm_enable_bapm(adev, e) (adev)->pm.funcs->enable_bapm((adev), (e))
 
 #define amdgpu_dpm_get_temperature(adev) \
-               amdgpu_powerplay ? \
-               (adev)->powerplay.pp_funcs->get_temperature((adev)->powerplay.pp_handle) : \
-               (adev)->pm.funcs->get_temperature((adev))
+       (adev)->pp_enabled ?                                            \
+             (adev)->powerplay.pp_funcs->get_temperature((adev)->powerplay.pp_handle) : \
+             (adev)->pm.funcs->get_temperature((adev))
 
 #define amdgpu_dpm_set_fan_control_mode(adev, m) \
-               amdgpu_powerplay ? \
-               (adev)->powerplay.pp_funcs->set_fan_control_mode((adev)->powerplay.pp_handle, (m)) : \
-               (adev)->pm.funcs->set_fan_control_mode((adev), (m))
+       (adev)->pp_enabled ?                                            \
+             (adev)->powerplay.pp_funcs->set_fan_control_mode((adev)->powerplay.pp_handle, (m)) : \
+             (adev)->pm.funcs->set_fan_control_mode((adev), (m))
 
 #define amdgpu_dpm_get_fan_control_mode(adev) \
-               amdgpu_powerplay ? \
-               (adev)->powerplay.pp_funcs->get_fan_control_mode((adev)->powerplay.pp_handle) : \
-               (adev)->pm.funcs->get_fan_control_mode((adev))
+       (adev)->pp_enabled ?                                            \
+             (adev)->powerplay.pp_funcs->get_fan_control_mode((adev)->powerplay.pp_handle) : \
+             (adev)->pm.funcs->get_fan_control_mode((adev))
 
 #define amdgpu_dpm_set_fan_speed_percent(adev, s) \
-               amdgpu_powerplay ? \
-               (adev)->powerplay.pp_funcs->set_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
-               (adev)->pm.funcs->set_fan_speed_percent((adev), (s))
+       (adev)->pp_enabled ?                                            \
+             (adev)->powerplay.pp_funcs->set_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
+             (adev)->pm.funcs->set_fan_speed_percent((adev), (s))
 
 #define amdgpu_dpm_get_fan_speed_percent(adev, s) \
-               amdgpu_powerplay ? \
-               (adev)->powerplay.pp_funcs->get_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
-               (adev)->pm.funcs->get_fan_speed_percent((adev), (s))
+       (adev)->pp_enabled ?                                            \
+             (adev)->powerplay.pp_funcs->get_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
+             (adev)->pm.funcs->get_fan_speed_percent((adev), (s))
 
 #define amdgpu_dpm_get_sclk(adev, l) \
-               amdgpu_powerplay ? \
-               (adev)->powerplay.pp_funcs->get_sclk((adev)->powerplay.pp_handle, (l)) : \
+       (adev)->pp_enabled ?                                            \
+             (adev)->powerplay.pp_funcs->get_sclk((adev)->powerplay.pp_handle, (l)) : \
                (adev)->pm.funcs->get_sclk((adev), (l))
 
 #define amdgpu_dpm_get_mclk(adev, l)  \
-               amdgpu_powerplay ? \
-               (adev)->powerplay.pp_funcs->get_mclk((adev)->powerplay.pp_handle, (l)) : \
-               (adev)->pm.funcs->get_mclk((adev), (l))
+       (adev)->pp_enabled ?                                            \
+             (adev)->powerplay.pp_funcs->get_mclk((adev)->powerplay.pp_handle, (l)) : \
+             (adev)->pm.funcs->get_mclk((adev), (l))
 
 
 #define amdgpu_dpm_force_performance_level(adev, l) \
-               amdgpu_powerplay ? \
-               (adev)->powerplay.pp_funcs->force_performance_level((adev)->powerplay.pp_handle, (l)) : \
-               (adev)->pm.funcs->force_performance_level((adev), (l))
+       (adev)->pp_enabled ?                                            \
+             (adev)->powerplay.pp_funcs->force_performance_level((adev)->powerplay.pp_handle, (l)) : \
+             (adev)->pm.funcs->force_performance_level((adev), (l))
 
 #define amdgpu_dpm_powergate_uvd(adev, g) \
-               amdgpu_powerplay ? \
-               (adev)->powerplay.pp_funcs->powergate_uvd((adev)->powerplay.pp_handle, (g)) : \
-               (adev)->pm.funcs->powergate_uvd((adev), (g))
+       (adev)->pp_enabled ?                                            \
+             (adev)->powerplay.pp_funcs->powergate_uvd((adev)->powerplay.pp_handle, (g)) : \
+             (adev)->pm.funcs->powergate_uvd((adev), (g))
 
 #define amdgpu_dpm_powergate_vce(adev, g) \
-               amdgpu_powerplay ? \
-               (adev)->powerplay.pp_funcs->powergate_vce((adev)->powerplay.pp_handle, (g)) : \
-               (adev)->pm.funcs->powergate_vce((adev), (g))
+       (adev)->pp_enabled ?                                            \
+             (adev)->powerplay.pp_funcs->powergate_vce((adev)->powerplay.pp_handle, (g)) : \
+             (adev)->pm.funcs->powergate_vce((adev), (g))
 
 #define amdgpu_dpm_debugfs_print_current_performance_level(adev, m) \
-               amdgpu_powerplay ? \
-               (adev)->powerplay.pp_funcs->print_current_performance_level((adev)->powerplay.pp_handle, (m)) : \
-               (adev)->pm.funcs->debugfs_print_current_performance_level((adev), (m))
+       (adev)->pp_enabled ?                                            \
+             (adev)->powerplay.pp_funcs->print_current_performance_level((adev)->powerplay.pp_handle, (m)) : \
+             (adev)->pm.funcs->debugfs_print_current_performance_level((adev), (m))
 
 #define amdgpu_dpm_get_current_power_state(adev) \
-               (adev)->powerplay.pp_funcs->get_current_power_state((adev)->powerplay.pp_handle)
+       (adev)->powerplay.pp_funcs->get_current_power_state((adev)->powerplay.pp_handle)
 
 #define amdgpu_dpm_get_performance_level(adev) \
-               (adev)->powerplay.pp_funcs->get_performance_level((adev)->powerplay.pp_handle)
+       (adev)->powerplay.pp_funcs->get_performance_level((adev)->powerplay.pp_handle)
 
-#define amdgpu_dpm_dispatch_task(adev, event_id, input, output) \
+#define amdgpu_dpm_dispatch_task(adev, event_id, input, output)                \
        (adev)->powerplay.pp_funcs->dispatch_tasks((adev)->powerplay.pp_handle, (event_id), (input), (output))
 
 #define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a))
index a15ca4c7cf60cea4ff43f9a94035f9e6fb600a09..b5dbbb57349190ce4b28409547781c515283994f 100644 (file)
@@ -82,7 +82,7 @@ int amdgpu_enable_scheduler = 1;
 int amdgpu_sched_jobs = 32;
 int amdgpu_sched_hw_submission = 2;
 int amdgpu_enable_semaphores = 0;
-int amdgpu_powerplay = 0;
+int amdgpu_powerplay = -1;
 
 MODULE_PARM_DESC(vramlimit, "Restrict VRAM for testing, in megabytes");
 module_param_named(vramlimit, amdgpu_vram_limit, int, 0600);
@@ -166,7 +166,7 @@ MODULE_PARM_DESC(enable_semaphores, "Enable semaphores (1 = enable, 0 = disable
 module_param_named(enable_semaphores, amdgpu_enable_semaphores, int, 0644);
 
 #ifdef CONFIG_DRM_AMD_POWERPLAY
-MODULE_PARM_DESC(powerplay, "Powerplay component (1 = enable, 0 = disable (default))");
+MODULE_PARM_DESC(powerplay, "Powerplay component (1 = enable, 0 = disable, -1 = auto (default))");
 module_param_named(powerplay, amdgpu_powerplay, int, 0444);
 #endif
 
index 40ae30530a01ee3421498811c76a1f63418c189f..3b78982abaf120be305b1b10ce4ed59f4d65a31c 100644 (file)
@@ -36,7 +36,7 @@ static int amdgpu_debugfs_pm_init(struct amdgpu_device *adev);
 
 void amdgpu_pm_acpi_event_handler(struct amdgpu_device *adev)
 {
-       if (amdgpu_powerplay)
+       if (adev->pp_enabled)
                /* TODO */
                return;
 
@@ -60,7 +60,7 @@ static ssize_t amdgpu_get_dpm_state(struct device *dev,
        struct amdgpu_device *adev = ddev->dev_private;
        enum amd_pm_state_type pm;
 
-       if (amdgpu_powerplay) {
+       if (adev->pp_enabled) {
                pm = amdgpu_dpm_get_current_power_state(adev);
        } else
                pm = adev->pm.dpm.user_state;
@@ -90,7 +90,7 @@ static ssize_t amdgpu_set_dpm_state(struct device *dev,
                goto fail;
        }
 
-       if (amdgpu_powerplay) {
+       if (adev->pp_enabled) {
                amdgpu_dpm_dispatch_task(adev, AMD_PP_EVENT_ENABLE_USER_STATE, &state, NULL);
        } else {
                mutex_lock(&adev->pm.mutex);
@@ -113,7 +113,7 @@ static ssize_t amdgpu_get_dpm_forced_performance_level(struct device *dev,
        struct drm_device *ddev = dev_get_drvdata(dev);
        struct amdgpu_device *adev = ddev->dev_private;
 
-       if (amdgpu_powerplay) {
+       if (adev->pp_enabled) {
                enum amd_dpm_forced_level level;
 
                level = amdgpu_dpm_get_performance_level(adev);
@@ -151,7 +151,7 @@ static ssize_t amdgpu_set_dpm_forced_performance_level(struct device *dev,
                goto fail;
        }
 
-       if (amdgpu_powerplay)
+       if (adev->pp_enabled)
                amdgpu_dpm_force_performance_level(adev, level);
        else {
                mutex_lock(&adev->pm.mutex);
@@ -184,7 +184,7 @@ static ssize_t amdgpu_hwmon_show_temp(struct device *dev,
        struct amdgpu_device *adev = dev_get_drvdata(dev);
        int temp;
 
-       if (!amdgpu_powerplay && !adev->pm.funcs->get_temperature)
+       if (!adev->pp_enabled && !adev->pm.funcs->get_temperature)
                temp = 0;
        else
                temp = amdgpu_dpm_get_temperature(adev);
@@ -215,7 +215,7 @@ static ssize_t amdgpu_hwmon_get_pwm1_enable(struct device *dev,
        struct amdgpu_device *adev = dev_get_drvdata(dev);
        u32 pwm_mode = 0;
 
-       if (!amdgpu_powerplay && !adev->pm.funcs->get_fan_control_mode)
+       if (!adev->pp_enabled && !adev->pm.funcs->get_fan_control_mode)
                return -EINVAL;
 
        pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
@@ -233,7 +233,7 @@ static ssize_t amdgpu_hwmon_set_pwm1_enable(struct device *dev,
        int err;
        int value;
 
-       if (!amdgpu_powerplay && !adev->pm.funcs->set_fan_control_mode)
+       if (!adev->pp_enabled && !adev->pm.funcs->set_fan_control_mode)
                return -EINVAL;
 
        err = kstrtoint(buf, 10, &value);
@@ -340,7 +340,7 @@ static umode_t hwmon_attributes_visible(struct kobject *kobj,
             attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
                return 0;
 
-       if (amdgpu_powerplay)
+       if (adev->pp_enabled)
                return effective_mode;
 
        /* Skip fan attributes if fan is not present */
@@ -674,7 +674,7 @@ done:
 
 void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable)
 {
-       if (amdgpu_powerplay)
+       if (adev->pp_enabled)
                amdgpu_dpm_powergate_uvd(adev, !enable);
        else {
                if (adev->pm.funcs->powergate_uvd) {
@@ -701,7 +701,7 @@ void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable)
 
 void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)
 {
-       if (amdgpu_powerplay)
+       if (adev->pp_enabled)
                amdgpu_dpm_powergate_vce(adev, !enable);
        else {
                if (adev->pm.funcs->powergate_vce) {
@@ -729,7 +729,7 @@ void amdgpu_pm_print_power_states(struct amdgpu_device *adev)
 {
        int i;
 
-       if (amdgpu_powerplay)
+       if (adev->pp_enabled)
                /* TO DO */
                return;
 
@@ -745,7 +745,7 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
        if (adev->pm.sysfs_initialized)
                return 0;
 
-       if (!amdgpu_powerplay) {
+       if (!adev->pp_enabled) {
                if (adev->pm.funcs->get_temperature == NULL)
                        return 0;
        }
@@ -798,7 +798,7 @@ void amdgpu_pm_compute_clocks(struct amdgpu_device *adev)
        if (!adev->pm.dpm_enabled)
                return;
 
-       if (amdgpu_powerplay) {
+       if (adev->pp_enabled) {
                int i = 0;
 
                amdgpu_display_bandwidth_update(adev);
@@ -852,7 +852,7 @@ static int amdgpu_debugfs_pm_info(struct seq_file *m, void *data)
                seq_printf(m, "dpm not enabled\n");
                return 0;
        }
-       if (amdgpu_powerplay) {
+       if (adev->pp_enabled) {
                amdgpu_dpm_debugfs_print_current_performance_level(adev, m);
        } else {
                mutex_lock(&adev->pm.mutex);
index 1ff6fd54df61c0ef7630a57313ee85ee4d8fb523..6b46fbfd6be48eba35fccccc0b63b44803722994 100644 (file)
@@ -40,7 +40,7 @@ static int amdgpu_powerplay_init(struct amdgpu_device *adev)
 
        amd_pp = &(adev->powerplay);
 
-       if (amdgpu_powerplay) {
+       if (adev->pp_enabled) {
 #ifdef CONFIG_DRM_AMD_POWERPLAY
                struct amd_pp_init *pp_init;
 
@@ -100,11 +100,14 @@ static int amdgpu_pp_early_init(void *handle)
        switch (adev->asic_type) {
                case CHIP_TONGA:
                case CHIP_FIJI:
-                       amdgpu_powerplay = 1;
+                       adev->pp_enabled = (amdgpu_powerplay == 0) ? false : true;
                        break;
                default:
+                       adev->pp_enabled = (amdgpu_powerplay > 0) ? true : false;
                        break;
        }
+#else
+       adev->pp_enabled = false;
 #endif
 
        ret = amdgpu_powerplay_init(adev);
@@ -127,7 +130,7 @@ static int amdgpu_pp_sw_init(void *handle)
                                        adev->powerplay.pp_handle);
 
 #ifdef CONFIG_DRM_AMD_POWERPLAY
-       if (amdgpu_powerplay) {
+       if (adev->pp_enabled) {
                adev->pm.dpm_enabled = true;
                amdgpu_pm_sysfs_init(adev);
        }
@@ -148,7 +151,7 @@ static int amdgpu_pp_sw_fini(void *handle)
                return ret;
 
 #ifdef CONFIG_DRM_AMD_POWERPLAY
-       if (amdgpu_powerplay) {
+       if (adev->pp_enabled) {
                amdgpu_pm_sysfs_fini(adev);
                amd_powerplay_fini(adev->powerplay.pp_handle);
        }
@@ -162,7 +165,7 @@ static int amdgpu_pp_hw_init(void *handle)
        int ret = 0;
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
-       if (amdgpu_powerplay && adev->firmware.smu_load)
+       if (adev->pp_enabled && adev->firmware.smu_load)
                amdgpu_ucode_init_bo(adev);
 
        if (adev->powerplay.ip_funcs->hw_init)
@@ -181,7 +184,7 @@ static int amdgpu_pp_hw_fini(void *handle)
                ret = adev->powerplay.ip_funcs->hw_fini(
                                        adev->powerplay.pp_handle);
 
-       if (amdgpu_powerplay && adev->firmware.smu_load)
+       if (adev->pp_enabled && adev->firmware.smu_load)
                amdgpu_ucode_fini_bo(adev);
 
        return ret;
index d90aae08445e07c3cf108a86607730f2439b7878..6c063a4a2c388f10f583d9500d123f52389fb871 100644 (file)
@@ -2902,7 +2902,7 @@ static int gfx_v8_0_rlc_resume(struct amdgpu_device *adev)
 
        gfx_v8_0_rlc_reset(adev);
 
-       if (!amdgpu_powerplay) {
+       if (!adev->pp_enabled) {
                if (!adev->firmware.smu_load) {
                        /* legacy rlc firmware loading */
                        r = gfx_v8_0_rlc_load_microcode(adev);
@@ -3804,7 +3804,7 @@ static int gfx_v8_0_cp_resume(struct amdgpu_device *adev)
        if (!(adev->flags & AMD_IS_APU))
                gfx_v8_0_enable_gui_idle_interrupt(adev, false);
 
-       if (!amdgpu_powerplay) {
+       if (!adev->pp_enabled) {
                if (!adev->firmware.smu_load) {
                        /* legacy firmware loading */
                        r = gfx_v8_0_cp_gfx_load_microcode(adev);
index 8091c1c37c4ef39a19301a8acfb7ad5d02d119aa..c741c091bc9e44d680b09fe4cb28eb207bb5f0b6 100644 (file)
@@ -727,7 +727,7 @@ static int sdma_v3_0_start(struct amdgpu_device *adev)
 {
        int r, i;
 
-       if (!amdgpu_powerplay) {
+       if (!adev->pp_enabled) {
                if (!adev->firmware.smu_load) {
                        r = sdma_v3_0_load_microcode(adev);
                        if (r)