aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c')
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c566
1 files changed, 392 insertions, 174 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
index 01a996c6b802..361975cf45a9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
@@ -116,7 +116,7 @@ static ssize_t amdgpu_set_dpm_state(struct device *dev,
116 } 116 }
117 117
118 if (adev->powerplay.pp_funcs->dispatch_tasks) { 118 if (adev->powerplay.pp_funcs->dispatch_tasks) {
119 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_ENABLE_USER_STATE, &state, NULL); 119 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_ENABLE_USER_STATE, &state);
120 } else { 120 } else {
121 mutex_lock(&adev->pm.mutex); 121 mutex_lock(&adev->pm.mutex);
122 adev->pm.dpm.user_state = state; 122 adev->pm.dpm.user_state = state;
@@ -316,7 +316,7 @@ static ssize_t amdgpu_set_pp_force_state(struct device *dev,
316 if (state != POWER_STATE_TYPE_INTERNAL_BOOT && 316 if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
317 state != POWER_STATE_TYPE_DEFAULT) { 317 state != POWER_STATE_TYPE_DEFAULT) {
318 amdgpu_dpm_dispatch_task(adev, 318 amdgpu_dpm_dispatch_task(adev,
319 AMD_PP_TASK_ENABLE_USER_STATE, &state, NULL); 319 AMD_PP_TASK_ENABLE_USER_STATE, &state);
320 adev->pp_force_state_enabled = true; 320 adev->pp_force_state_enabled = true;
321 } 321 }
322 } 322 }
@@ -360,6 +360,90 @@ static ssize_t amdgpu_set_pp_table(struct device *dev,
360 return count; 360 return count;
361} 361}
362 362
363static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev,
364 struct device_attribute *attr,
365 const char *buf,
366 size_t count)
367{
368 struct drm_device *ddev = dev_get_drvdata(dev);
369 struct amdgpu_device *adev = ddev->dev_private;
370 int ret;
371 uint32_t parameter_size = 0;
372 long parameter[64];
373 char buf_cpy[128];
374 char *tmp_str;
375 char *sub_str;
376 const char delimiter[3] = {' ', '\n', '\0'};
377 uint32_t type;
378
379 if (count > 127)
380 return -EINVAL;
381
382 if (*buf == 's')
383 type = PP_OD_EDIT_SCLK_VDDC_TABLE;
384 else if (*buf == 'm')
385 type = PP_OD_EDIT_MCLK_VDDC_TABLE;
386 else if(*buf == 'r')
387 type = PP_OD_RESTORE_DEFAULT_TABLE;
388 else if (*buf == 'c')
389 type = PP_OD_COMMIT_DPM_TABLE;
390 else
391 return -EINVAL;
392
393 memcpy(buf_cpy, buf, count+1);
394
395 tmp_str = buf_cpy;
396
397 while (isspace(*++tmp_str));
398
399 while (tmp_str[0]) {
400 sub_str = strsep(&tmp_str, delimiter);
401 ret = kstrtol(sub_str, 0, &parameter[parameter_size]);
402 if (ret)
403 return -EINVAL;
404 parameter_size++;
405
406 while (isspace(*tmp_str))
407 tmp_str++;
408 }
409
410 if (adev->powerplay.pp_funcs->odn_edit_dpm_table)
411 ret = amdgpu_dpm_odn_edit_dpm_table(adev, type,
412 parameter, parameter_size);
413
414 if (ret)
415 return -EINVAL;
416
417 if (type == PP_OD_COMMIT_DPM_TABLE) {
418 if (adev->powerplay.pp_funcs->dispatch_tasks) {
419 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_READJUST_POWER_STATE, NULL);
420 return count;
421 } else {
422 return -EINVAL;
423 }
424 }
425
426 return count;
427}
428
429static ssize_t amdgpu_get_pp_od_clk_voltage(struct device *dev,
430 struct device_attribute *attr,
431 char *buf)
432{
433 struct drm_device *ddev = dev_get_drvdata(dev);
434 struct amdgpu_device *adev = ddev->dev_private;
435 uint32_t size = 0;
436
437 if (adev->powerplay.pp_funcs->print_clock_levels) {
438 size = amdgpu_dpm_print_clock_levels(adev, OD_SCLK, buf);
439 size += amdgpu_dpm_print_clock_levels(adev, OD_MCLK, buf+size);
440 return size;
441 } else {
442 return snprintf(buf, PAGE_SIZE, "\n");
443 }
444
445}
446
363static ssize_t amdgpu_get_pp_dpm_sclk(struct device *dev, 447static ssize_t amdgpu_get_pp_dpm_sclk(struct device *dev,
364 struct device_attribute *attr, 448 struct device_attribute *attr,
365 char *buf) 449 char *buf)
@@ -530,7 +614,7 @@ static ssize_t amdgpu_set_pp_sclk_od(struct device *dev,
530 amdgpu_dpm_set_sclk_od(adev, (uint32_t)value); 614 amdgpu_dpm_set_sclk_od(adev, (uint32_t)value);
531 615
532 if (adev->powerplay.pp_funcs->dispatch_tasks) { 616 if (adev->powerplay.pp_funcs->dispatch_tasks) {
533 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_READJUST_POWER_STATE, NULL, NULL); 617 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_READJUST_POWER_STATE, NULL);
534 } else { 618 } else {
535 adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps; 619 adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
536 amdgpu_pm_compute_clocks(adev); 620 amdgpu_pm_compute_clocks(adev);
@@ -574,7 +658,7 @@ static ssize_t amdgpu_set_pp_mclk_od(struct device *dev,
574 amdgpu_dpm_set_mclk_od(adev, (uint32_t)value); 658 amdgpu_dpm_set_mclk_od(adev, (uint32_t)value);
575 659
576 if (adev->powerplay.pp_funcs->dispatch_tasks) { 660 if (adev->powerplay.pp_funcs->dispatch_tasks) {
577 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_READJUST_POWER_STATE, NULL, NULL); 661 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_READJUST_POWER_STATE, NULL);
578 } else { 662 } else {
579 adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps; 663 adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
580 amdgpu_pm_compute_clocks(adev); 664 amdgpu_pm_compute_clocks(adev);
@@ -584,159 +668,70 @@ fail:
584 return count; 668 return count;
585} 669}
586 670
587static ssize_t amdgpu_get_pp_power_profile(struct device *dev, 671static ssize_t amdgpu_get_pp_power_profile_mode(struct device *dev,
588 char *buf, struct amd_pp_profile *query) 672 struct device_attribute *attr,
673 char *buf)
589{ 674{
590 struct drm_device *ddev = dev_get_drvdata(dev); 675 struct drm_device *ddev = dev_get_drvdata(dev);
591 struct amdgpu_device *adev = ddev->dev_private; 676 struct amdgpu_device *adev = ddev->dev_private;
592 int ret = 0xff;
593 677
594 if (adev->powerplay.pp_funcs->get_power_profile_state) 678 if (adev->powerplay.pp_funcs->get_power_profile_mode)
595 ret = amdgpu_dpm_get_power_profile_state( 679 return amdgpu_dpm_get_power_profile_mode(adev, buf);
596 adev, query);
597 680
598 if (ret) 681 return snprintf(buf, PAGE_SIZE, "\n");
599 return ret;
600
601 return snprintf(buf, PAGE_SIZE,
602 "%d %d %d %d %d\n",
603 query->min_sclk / 100,
604 query->min_mclk / 100,
605 query->activity_threshold,
606 query->up_hyst,
607 query->down_hyst);
608} 682}
609 683
610static ssize_t amdgpu_get_pp_gfx_power_profile(struct device *dev,
611 struct device_attribute *attr,
612 char *buf)
613{
614 struct amd_pp_profile query = {0};
615
616 query.type = AMD_PP_GFX_PROFILE;
617
618 return amdgpu_get_pp_power_profile(dev, buf, &query);
619}
620 684
621static ssize_t amdgpu_get_pp_compute_power_profile(struct device *dev, 685static ssize_t amdgpu_set_pp_power_profile_mode(struct device *dev,
622 struct device_attribute *attr, 686 struct device_attribute *attr,
623 char *buf)
624{
625 struct amd_pp_profile query = {0};
626
627 query.type = AMD_PP_COMPUTE_PROFILE;
628
629 return amdgpu_get_pp_power_profile(dev, buf, &query);
630}
631
632static ssize_t amdgpu_set_pp_power_profile(struct device *dev,
633 const char *buf, 687 const char *buf,
634 size_t count, 688 size_t count)
635 struct amd_pp_profile *request)
636{ 689{
690 int ret = 0xff;
637 struct drm_device *ddev = dev_get_drvdata(dev); 691 struct drm_device *ddev = dev_get_drvdata(dev);
638 struct amdgpu_device *adev = ddev->dev_private; 692 struct amdgpu_device *adev = ddev->dev_private;
639 uint32_t loop = 0; 693 uint32_t parameter_size = 0;
640 char *sub_str, buf_cpy[128], *tmp_str; 694 long parameter[64];
695 char *sub_str, buf_cpy[128];
696 char *tmp_str;
697 uint32_t i = 0;
698 char tmp[2];
699 long int profile_mode = 0;
641 const char delimiter[3] = {' ', '\n', '\0'}; 700 const char delimiter[3] = {' ', '\n', '\0'};
642 long int value;
643 int ret = 0xff;
644
645 if (strncmp("reset", buf, strlen("reset")) == 0) {
646 if (adev->powerplay.pp_funcs->reset_power_profile_state)
647 ret = amdgpu_dpm_reset_power_profile_state(
648 adev, request);
649 if (ret) {
650 count = -EINVAL;
651 goto fail;
652 }
653 return count;
654 }
655
656 if (strncmp("set", buf, strlen("set")) == 0) {
657 if (adev->powerplay.pp_funcs->set_power_profile_state)
658 ret = amdgpu_dpm_set_power_profile_state(
659 adev, request);
660
661 if (ret) {
662 count = -EINVAL;
663 goto fail;
664 }
665 return count;
666 }
667 701
668 if (count + 1 >= 128) { 702 tmp[0] = *(buf);
669 count = -EINVAL; 703 tmp[1] = '\0';
704 ret = kstrtol(tmp, 0, &profile_mode);
705 if (ret)
670 goto fail; 706 goto fail;
671 }
672
673 memcpy(buf_cpy, buf, count + 1);
674 tmp_str = buf_cpy;
675
676 while (tmp_str[0]) {
677 sub_str = strsep(&tmp_str, delimiter);
678 ret = kstrtol(sub_str, 0, &value);
679 if (ret) {
680 count = -EINVAL;
681 goto fail;
682 }
683 707
684 switch (loop) { 708 if (profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
685 case 0: 709 if (count < 2 || count > 127)
686 /* input unit MHz convert to dpm table unit 10KHz*/ 710 return -EINVAL;
687 request->min_sclk = (uint32_t)value * 100; 711 while (isspace(*++buf))
688 break; 712 i++;
689 case 1: 713 memcpy(buf_cpy, buf, count-i);
690 /* input unit MHz convert to dpm table unit 10KHz*/ 714 tmp_str = buf_cpy;
691 request->min_mclk = (uint32_t)value * 100; 715 while (tmp_str[0]) {
692 break; 716 sub_str = strsep(&tmp_str, delimiter);
693 case 2: 717 ret = kstrtol(sub_str, 0, &parameter[parameter_size]);
694 request->activity_threshold = (uint16_t)value; 718 if (ret) {
695 break; 719 count = -EINVAL;
696 case 3: 720 goto fail;
697 request->up_hyst = (uint8_t)value; 721 }
698 break; 722 parameter_size++;
699 case 4: 723 while (isspace(*tmp_str))
700 request->down_hyst = (uint8_t)value; 724 tmp_str++;
701 break;
702 default:
703 break;
704 } 725 }
705
706 loop++;
707 } 726 }
708 if (adev->powerplay.pp_funcs->set_power_profile_state) 727 parameter[parameter_size] = profile_mode;
709 ret = amdgpu_dpm_set_power_profile_state(adev, request); 728 if (adev->powerplay.pp_funcs->set_power_profile_mode)
710 729 ret = amdgpu_dpm_set_power_profile_mode(adev, parameter, parameter_size);
711 if (ret)
712 count = -EINVAL;
713 730
731 if (!ret)
732 return count;
714fail: 733fail:
715 return count; 734 return -EINVAL;
716}
717
718static ssize_t amdgpu_set_pp_gfx_power_profile(struct device *dev,
719 struct device_attribute *attr,
720 const char *buf,
721 size_t count)
722{
723 struct amd_pp_profile request = {0};
724
725 request.type = AMD_PP_GFX_PROFILE;
726
727 return amdgpu_set_pp_power_profile(dev, buf, count, &request);
728}
729
730static ssize_t amdgpu_set_pp_compute_power_profile(struct device *dev,
731 struct device_attribute *attr,
732 const char *buf,
733 size_t count)
734{
735 struct amd_pp_profile request = {0};
736
737 request.type = AMD_PP_COMPUTE_PROFILE;
738
739 return amdgpu_set_pp_power_profile(dev, buf, count, &request);
740} 735}
741 736
742static DEVICE_ATTR(power_dpm_state, S_IRUGO | S_IWUSR, amdgpu_get_dpm_state, amdgpu_set_dpm_state); 737static DEVICE_ATTR(power_dpm_state, S_IRUGO | S_IWUSR, amdgpu_get_dpm_state, amdgpu_set_dpm_state);
@@ -766,12 +761,12 @@ static DEVICE_ATTR(pp_sclk_od, S_IRUGO | S_IWUSR,
766static DEVICE_ATTR(pp_mclk_od, S_IRUGO | S_IWUSR, 761static DEVICE_ATTR(pp_mclk_od, S_IRUGO | S_IWUSR,
767 amdgpu_get_pp_mclk_od, 762 amdgpu_get_pp_mclk_od,
768 amdgpu_set_pp_mclk_od); 763 amdgpu_set_pp_mclk_od);
769static DEVICE_ATTR(pp_gfx_power_profile, S_IRUGO | S_IWUSR, 764static DEVICE_ATTR(pp_power_profile_mode, S_IRUGO | S_IWUSR,
770 amdgpu_get_pp_gfx_power_profile, 765 amdgpu_get_pp_power_profile_mode,
771 amdgpu_set_pp_gfx_power_profile); 766 amdgpu_set_pp_power_profile_mode);
772static DEVICE_ATTR(pp_compute_power_profile, S_IRUGO | S_IWUSR, 767static DEVICE_ATTR(pp_od_clk_voltage, S_IRUGO | S_IWUSR,
773 amdgpu_get_pp_compute_power_profile, 768 amdgpu_get_pp_od_clk_voltage,
774 amdgpu_set_pp_compute_power_profile); 769 amdgpu_set_pp_od_clk_voltage);
775 770
776static ssize_t amdgpu_hwmon_show_temp(struct device *dev, 771static ssize_t amdgpu_hwmon_show_temp(struct device *dev,
777 struct device_attribute *attr, 772 struct device_attribute *attr,
@@ -779,17 +774,23 @@ static ssize_t amdgpu_hwmon_show_temp(struct device *dev,
779{ 774{
780 struct amdgpu_device *adev = dev_get_drvdata(dev); 775 struct amdgpu_device *adev = dev_get_drvdata(dev);
781 struct drm_device *ddev = adev->ddev; 776 struct drm_device *ddev = adev->ddev;
782 int temp; 777 int r, temp, size = sizeof(temp);
783 778
784 /* Can't get temperature when the card is off */ 779 /* Can't get temperature when the card is off */
785 if ((adev->flags & AMD_IS_PX) && 780 if ((adev->flags & AMD_IS_PX) &&
786 (ddev->switch_power_state != DRM_SWITCH_POWER_ON)) 781 (ddev->switch_power_state != DRM_SWITCH_POWER_ON))
787 return -EINVAL; 782 return -EINVAL;
788 783
789 if (!adev->powerplay.pp_funcs->get_temperature) 784 /* sanity check PP is enabled */
790 temp = 0; 785 if (!(adev->powerplay.pp_funcs &&
791 else 786 adev->powerplay.pp_funcs->read_sensor))
792 temp = amdgpu_dpm_get_temperature(adev); 787 return -EINVAL;
788
789 /* get the temperature */
790 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_TEMP,
791 (void *)&temp, &size);
792 if (r)
793 return r;
793 794
794 return snprintf(buf, PAGE_SIZE, "%d\n", temp); 795 return snprintf(buf, PAGE_SIZE, "%d\n", temp);
795} 796}
@@ -834,6 +835,11 @@ static ssize_t amdgpu_hwmon_set_pwm1_enable(struct device *dev,
834 int err; 835 int err;
835 int value; 836 int value;
836 837
838 /* Can't adjust fan when the card is off */
839 if ((adev->flags & AMD_IS_PX) &&
840 (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))
841 return -EINVAL;
842
837 if (!adev->powerplay.pp_funcs->set_fan_control_mode) 843 if (!adev->powerplay.pp_funcs->set_fan_control_mode)
838 return -EINVAL; 844 return -EINVAL;
839 845
@@ -868,6 +874,11 @@ static ssize_t amdgpu_hwmon_set_pwm1(struct device *dev,
868 int err; 874 int err;
869 u32 value; 875 u32 value;
870 876
877 /* Can't adjust fan when the card is off */
878 if ((adev->flags & AMD_IS_PX) &&
879 (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))
880 return -EINVAL;
881
871 err = kstrtou32(buf, 10, &value); 882 err = kstrtou32(buf, 10, &value);
872 if (err) 883 if (err)
873 return err; 884 return err;
@@ -891,6 +902,11 @@ static ssize_t amdgpu_hwmon_get_pwm1(struct device *dev,
891 int err; 902 int err;
892 u32 speed = 0; 903 u32 speed = 0;
893 904
905 /* Can't adjust fan when the card is off */
906 if ((adev->flags & AMD_IS_PX) &&
907 (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))
908 return -EINVAL;
909
894 if (adev->powerplay.pp_funcs->get_fan_speed_percent) { 910 if (adev->powerplay.pp_funcs->get_fan_speed_percent) {
895 err = amdgpu_dpm_get_fan_speed_percent(adev, &speed); 911 err = amdgpu_dpm_get_fan_speed_percent(adev, &speed);
896 if (err) 912 if (err)
@@ -910,6 +926,11 @@ static ssize_t amdgpu_hwmon_get_fan1_input(struct device *dev,
910 int err; 926 int err;
911 u32 speed = 0; 927 u32 speed = 0;
912 928
929 /* Can't adjust fan when the card is off */
930 if ((adev->flags & AMD_IS_PX) &&
931 (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))
932 return -EINVAL;
933
913 if (adev->powerplay.pp_funcs->get_fan_speed_rpm) { 934 if (adev->powerplay.pp_funcs->get_fan_speed_rpm) {
914 err = amdgpu_dpm_get_fan_speed_rpm(adev, &speed); 935 err = amdgpu_dpm_get_fan_speed_rpm(adev, &speed);
915 if (err) 936 if (err)
@@ -919,6 +940,175 @@ static ssize_t amdgpu_hwmon_get_fan1_input(struct device *dev,
919 return sprintf(buf, "%i\n", speed); 940 return sprintf(buf, "%i\n", speed);
920} 941}
921 942
943static ssize_t amdgpu_hwmon_show_vddgfx(struct device *dev,
944 struct device_attribute *attr,
945 char *buf)
946{
947 struct amdgpu_device *adev = dev_get_drvdata(dev);
948 struct drm_device *ddev = adev->ddev;
949 u32 vddgfx;
950 int r, size = sizeof(vddgfx);
951
952 /* Can't get voltage when the card is off */
953 if ((adev->flags & AMD_IS_PX) &&
954 (ddev->switch_power_state != DRM_SWITCH_POWER_ON))
955 return -EINVAL;
956
957 /* sanity check PP is enabled */
958 if (!(adev->powerplay.pp_funcs &&
959 adev->powerplay.pp_funcs->read_sensor))
960 return -EINVAL;
961
962 /* get the voltage */
963 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDGFX,
964 (void *)&vddgfx, &size);
965 if (r)
966 return r;
967
968 return snprintf(buf, PAGE_SIZE, "%d\n", vddgfx);
969}
970
971static ssize_t amdgpu_hwmon_show_vddgfx_label(struct device *dev,
972 struct device_attribute *attr,
973 char *buf)
974{
975 return snprintf(buf, PAGE_SIZE, "vddgfx\n");
976}
977
978static ssize_t amdgpu_hwmon_show_vddnb(struct device *dev,
979 struct device_attribute *attr,
980 char *buf)
981{
982 struct amdgpu_device *adev = dev_get_drvdata(dev);
983 struct drm_device *ddev = adev->ddev;
984 u32 vddnb;
985 int r, size = sizeof(vddnb);
986
987 /* only APUs have vddnb */
988 if (adev->flags & AMD_IS_APU)
989 return -EINVAL;
990
991 /* Can't get voltage when the card is off */
992 if ((adev->flags & AMD_IS_PX) &&
993 (ddev->switch_power_state != DRM_SWITCH_POWER_ON))
994 return -EINVAL;
995
996 /* sanity check PP is enabled */
997 if (!(adev->powerplay.pp_funcs &&
998 adev->powerplay.pp_funcs->read_sensor))
999 return -EINVAL;
1000
1001 /* get the voltage */
1002 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDNB,
1003 (void *)&vddnb, &size);
1004 if (r)
1005 return r;
1006
1007 return snprintf(buf, PAGE_SIZE, "%d\n", vddnb);
1008}
1009
1010static ssize_t amdgpu_hwmon_show_vddnb_label(struct device *dev,
1011 struct device_attribute *attr,
1012 char *buf)
1013{
1014 return snprintf(buf, PAGE_SIZE, "vddnb\n");
1015}
1016
1017static ssize_t amdgpu_hwmon_show_power_avg(struct device *dev,
1018 struct device_attribute *attr,
1019 char *buf)
1020{
1021 struct amdgpu_device *adev = dev_get_drvdata(dev);
1022 struct drm_device *ddev = adev->ddev;
1023 struct pp_gpu_power query = {0};
1024 int r, size = sizeof(query);
1025 unsigned uw;
1026
1027 /* Can't get power when the card is off */
1028 if ((adev->flags & AMD_IS_PX) &&
1029 (ddev->switch_power_state != DRM_SWITCH_POWER_ON))
1030 return -EINVAL;
1031
1032 /* sanity check PP is enabled */
1033 if (!(adev->powerplay.pp_funcs &&
1034 adev->powerplay.pp_funcs->read_sensor))
1035 return -EINVAL;
1036
1037 /* get the voltage */
1038 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_POWER,
1039 (void *)&query, &size);
1040 if (r)
1041 return r;
1042
1043 /* convert to microwatts */
1044 uw = (query.average_gpu_power >> 8) * 1000000;
1045
1046 return snprintf(buf, PAGE_SIZE, "%u\n", uw);
1047}
1048
1049static ssize_t amdgpu_hwmon_show_power_cap_min(struct device *dev,
1050 struct device_attribute *attr,
1051 char *buf)
1052{
1053 return sprintf(buf, "%i\n", 0);
1054}
1055
1056static ssize_t amdgpu_hwmon_show_power_cap_max(struct device *dev,
1057 struct device_attribute *attr,
1058 char *buf)
1059{
1060 struct amdgpu_device *adev = dev_get_drvdata(dev);
1061 uint32_t limit = 0;
1062
1063 if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->get_power_limit) {
1064 adev->powerplay.pp_funcs->get_power_limit(adev->powerplay.pp_handle, &limit, true);
1065 return snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
1066 } else {
1067 return snprintf(buf, PAGE_SIZE, "\n");
1068 }
1069}
1070
1071static ssize_t amdgpu_hwmon_show_power_cap(struct device *dev,
1072 struct device_attribute *attr,
1073 char *buf)
1074{
1075 struct amdgpu_device *adev = dev_get_drvdata(dev);
1076 uint32_t limit = 0;
1077
1078 if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->get_power_limit) {
1079 adev->powerplay.pp_funcs->get_power_limit(adev->powerplay.pp_handle, &limit, false);
1080 return snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
1081 } else {
1082 return snprintf(buf, PAGE_SIZE, "\n");
1083 }
1084}
1085
1086
1087static ssize_t amdgpu_hwmon_set_power_cap(struct device *dev,
1088 struct device_attribute *attr,
1089 const char *buf,
1090 size_t count)
1091{
1092 struct amdgpu_device *adev = dev_get_drvdata(dev);
1093 int err;
1094 u32 value;
1095
1096 err = kstrtou32(buf, 10, &value);
1097 if (err)
1098 return err;
1099
1100 value = value / 1000000; /* convert to Watt */
1101 if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->set_power_limit) {
1102 err = adev->powerplay.pp_funcs->set_power_limit(adev->powerplay.pp_handle, value);
1103 if (err)
1104 return err;
1105 } else {
1106 return -EINVAL;
1107 }
1108
1109 return count;
1110}
1111
922static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, amdgpu_hwmon_show_temp, NULL, 0); 1112static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, amdgpu_hwmon_show_temp, NULL, 0);
923static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 0); 1113static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 0);
924static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 1); 1114static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 1);
@@ -927,6 +1117,14 @@ static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1_
927static SENSOR_DEVICE_ATTR(pwm1_min, S_IRUGO, amdgpu_hwmon_get_pwm1_min, NULL, 0); 1117static SENSOR_DEVICE_ATTR(pwm1_min, S_IRUGO, amdgpu_hwmon_get_pwm1_min, NULL, 0);
928static SENSOR_DEVICE_ATTR(pwm1_max, S_IRUGO, amdgpu_hwmon_get_pwm1_max, NULL, 0); 1118static SENSOR_DEVICE_ATTR(pwm1_max, S_IRUGO, amdgpu_hwmon_get_pwm1_max, NULL, 0);
929static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, amdgpu_hwmon_get_fan1_input, NULL, 0); 1119static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, amdgpu_hwmon_get_fan1_input, NULL, 0);
1120static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, amdgpu_hwmon_show_vddgfx, NULL, 0);
1121static SENSOR_DEVICE_ATTR(in0_label, S_IRUGO, amdgpu_hwmon_show_vddgfx_label, NULL, 0);
1122static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, amdgpu_hwmon_show_vddnb, NULL, 0);
1123static SENSOR_DEVICE_ATTR(in1_label, S_IRUGO, amdgpu_hwmon_show_vddnb_label, NULL, 0);
1124static SENSOR_DEVICE_ATTR(power1_average, S_IRUGO, amdgpu_hwmon_show_power_avg, NULL, 0);
1125static SENSOR_DEVICE_ATTR(power1_cap_max, S_IRUGO, amdgpu_hwmon_show_power_cap_max, NULL, 0);
1126static SENSOR_DEVICE_ATTR(power1_cap_min, S_IRUGO, amdgpu_hwmon_show_power_cap_min, NULL, 0);
1127static SENSOR_DEVICE_ATTR(power1_cap, S_IRUGO | S_IWUSR, amdgpu_hwmon_show_power_cap, amdgpu_hwmon_set_power_cap, 0);
930 1128
931static struct attribute *hwmon_attributes[] = { 1129static struct attribute *hwmon_attributes[] = {
932 &sensor_dev_attr_temp1_input.dev_attr.attr, 1130 &sensor_dev_attr_temp1_input.dev_attr.attr,
@@ -937,6 +1135,14 @@ static struct attribute *hwmon_attributes[] = {
937 &sensor_dev_attr_pwm1_min.dev_attr.attr, 1135 &sensor_dev_attr_pwm1_min.dev_attr.attr,
938 &sensor_dev_attr_pwm1_max.dev_attr.attr, 1136 &sensor_dev_attr_pwm1_max.dev_attr.attr,
939 &sensor_dev_attr_fan1_input.dev_attr.attr, 1137 &sensor_dev_attr_fan1_input.dev_attr.attr,
1138 &sensor_dev_attr_in0_input.dev_attr.attr,
1139 &sensor_dev_attr_in0_label.dev_attr.attr,
1140 &sensor_dev_attr_in1_input.dev_attr.attr,
1141 &sensor_dev_attr_in1_label.dev_attr.attr,
1142 &sensor_dev_attr_power1_average.dev_attr.attr,
1143 &sensor_dev_attr_power1_cap_max.dev_attr.attr,
1144 &sensor_dev_attr_power1_cap_min.dev_attr.attr,
1145 &sensor_dev_attr_power1_cap.dev_attr.attr,
940 NULL 1146 NULL
941}; 1147};
942 1148
@@ -947,9 +1153,19 @@ static umode_t hwmon_attributes_visible(struct kobject *kobj,
947 struct amdgpu_device *adev = dev_get_drvdata(dev); 1153 struct amdgpu_device *adev = dev_get_drvdata(dev);
948 umode_t effective_mode = attr->mode; 1154 umode_t effective_mode = attr->mode;
949 1155
950 /* no skipping for powerplay */ 1156 /* handle non-powerplay limitations */
951 if (adev->powerplay.cgs_device) 1157 if (!adev->powerplay.pp_handle) {
952 return effective_mode; 1158 /* Skip fan attributes if fan is not present */
1159 if (adev->pm.no_fan &&
1160 (attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
1161 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
1162 attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
1163 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
1164 return 0;
1165 /* requires powerplay */
1166 if (attr == &sensor_dev_attr_fan1_input.dev_attr.attr)
1167 return 0;
1168 }
953 1169
954 /* Skip limit attributes if DPM is not enabled */ 1170 /* Skip limit attributes if DPM is not enabled */
955 if (!adev->pm.dpm_enabled && 1171 if (!adev->pm.dpm_enabled &&
@@ -961,14 +1177,6 @@ static umode_t hwmon_attributes_visible(struct kobject *kobj,
961 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr)) 1177 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
962 return 0; 1178 return 0;
963 1179
964 /* Skip fan attributes if fan is not present */
965 if (adev->pm.no_fan &&
966 (attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
967 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
968 attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
969 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
970 return 0;
971
972 /* mask fan attributes if we have no bindings for this asic to expose */ 1180 /* mask fan attributes if we have no bindings for this asic to expose */
973 if ((!adev->powerplay.pp_funcs->get_fan_speed_percent && 1181 if ((!adev->powerplay.pp_funcs->get_fan_speed_percent &&
974 attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't query fan */ 1182 attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't query fan */
@@ -982,6 +1190,12 @@ static umode_t hwmon_attributes_visible(struct kobject *kobj,
982 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't manage state */ 1190 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't manage state */
983 effective_mode &= ~S_IWUSR; 1191 effective_mode &= ~S_IWUSR;
984 1192
1193 if ((adev->flags & AMD_IS_APU) &&
1194 (attr == &sensor_dev_attr_power1_cap_max.dev_attr.attr ||
1195 attr == &sensor_dev_attr_power1_cap_min.dev_attr.attr||
1196 attr == &sensor_dev_attr_power1_cap.dev_attr.attr))
1197 return 0;
1198
985 /* hide max/min values if we can't both query and manage the fan */ 1199 /* hide max/min values if we can't both query and manage the fan */
986 if ((!adev->powerplay.pp_funcs->set_fan_speed_percent && 1200 if ((!adev->powerplay.pp_funcs->set_fan_speed_percent &&
987 !adev->powerplay.pp_funcs->get_fan_speed_percent) && 1201 !adev->powerplay.pp_funcs->get_fan_speed_percent) &&
@@ -989,8 +1203,10 @@ static umode_t hwmon_attributes_visible(struct kobject *kobj,
989 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr)) 1203 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
990 return 0; 1204 return 0;
991 1205
992 /* requires powerplay */ 1206 /* only APUs have vddnb */
993 if (attr == &sensor_dev_attr_fan1_input.dev_attr.attr) 1207 if (!(adev->flags & AMD_IS_APU) &&
1208 (attr == &sensor_dev_attr_in1_input.dev_attr.attr ||
1209 attr == &sensor_dev_attr_in1_label.dev_attr.attr))
994 return 0; 1210 return 0;
995 1211
996 return effective_mode; 1212 return effective_mode;
@@ -1013,13 +1229,15 @@ void amdgpu_dpm_thermal_work_handler(struct work_struct *work)
1013 pm.dpm.thermal.work); 1229 pm.dpm.thermal.work);
1014 /* switch to the thermal state */ 1230 /* switch to the thermal state */
1015 enum amd_pm_state_type dpm_state = POWER_STATE_TYPE_INTERNAL_THERMAL; 1231 enum amd_pm_state_type dpm_state = POWER_STATE_TYPE_INTERNAL_THERMAL;
1232 int temp, size = sizeof(temp);
1016 1233
1017 if (!adev->pm.dpm_enabled) 1234 if (!adev->pm.dpm_enabled)
1018 return; 1235 return;
1019 1236
1020 if (adev->powerplay.pp_funcs->get_temperature) { 1237 if (adev->powerplay.pp_funcs &&
1021 int temp = amdgpu_dpm_get_temperature(adev); 1238 adev->powerplay.pp_funcs->read_sensor &&
1022 1239 !amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_TEMP,
1240 (void *)&temp, &size)) {
1023 if (temp < adev->pm.dpm.thermal.min_temp) 1241 if (temp < adev->pm.dpm.thermal.min_temp)
1024 /* switch back the user state */ 1242 /* switch back the user state */
1025 dpm_state = adev->pm.dpm.user_state; 1243 dpm_state = adev->pm.dpm.user_state;
@@ -1319,9 +1537,6 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
1319 if (adev->pm.dpm_enabled == 0) 1537 if (adev->pm.dpm_enabled == 0)
1320 return 0; 1538 return 0;
1321 1539
1322 if (adev->powerplay.pp_funcs->get_temperature == NULL)
1323 return 0;
1324
1325 adev->pm.int_hwmon_dev = hwmon_device_register_with_groups(adev->dev, 1540 adev->pm.int_hwmon_dev = hwmon_device_register_with_groups(adev->dev,
1326 DRIVER_NAME, adev, 1541 DRIVER_NAME, adev,
1327 hwmon_groups); 1542 hwmon_groups);
@@ -1391,20 +1606,19 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
1391 return ret; 1606 return ret;
1392 } 1607 }
1393 ret = device_create_file(adev->dev, 1608 ret = device_create_file(adev->dev,
1394 &dev_attr_pp_gfx_power_profile); 1609 &dev_attr_pp_power_profile_mode);
1395 if (ret) { 1610 if (ret) {
1396 DRM_ERROR("failed to create device file " 1611 DRM_ERROR("failed to create device file "
1397 "pp_gfx_power_profile\n"); 1612 "pp_power_profile_mode\n");
1398 return ret; 1613 return ret;
1399 } 1614 }
1400 ret = device_create_file(adev->dev, 1615 ret = device_create_file(adev->dev,
1401 &dev_attr_pp_compute_power_profile); 1616 &dev_attr_pp_od_clk_voltage);
1402 if (ret) { 1617 if (ret) {
1403 DRM_ERROR("failed to create device file " 1618 DRM_ERROR("failed to create device file "
1404 "pp_compute_power_profile\n"); 1619 "pp_od_clk_voltage\n");
1405 return ret; 1620 return ret;
1406 } 1621 }
1407
1408 ret = amdgpu_debugfs_pm_init(adev); 1622 ret = amdgpu_debugfs_pm_init(adev);
1409 if (ret) { 1623 if (ret) {
1410 DRM_ERROR("Failed to register debugfs file for dpm!\n"); 1624 DRM_ERROR("Failed to register debugfs file for dpm!\n");
@@ -1437,9 +1651,9 @@ void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)
1437 device_remove_file(adev->dev, &dev_attr_pp_sclk_od); 1651 device_remove_file(adev->dev, &dev_attr_pp_sclk_od);
1438 device_remove_file(adev->dev, &dev_attr_pp_mclk_od); 1652 device_remove_file(adev->dev, &dev_attr_pp_mclk_od);
1439 device_remove_file(adev->dev, 1653 device_remove_file(adev->dev,
1440 &dev_attr_pp_gfx_power_profile); 1654 &dev_attr_pp_power_profile_mode);
1441 device_remove_file(adev->dev, 1655 device_remove_file(adev->dev,
1442 &dev_attr_pp_compute_power_profile); 1656 &dev_attr_pp_od_clk_voltage);
1443} 1657}
1444 1658
1445void amdgpu_pm_compute_clocks(struct amdgpu_device *adev) 1659void amdgpu_pm_compute_clocks(struct amdgpu_device *adev)
@@ -1462,7 +1676,7 @@ void amdgpu_pm_compute_clocks(struct amdgpu_device *adev)
1462 } 1676 }
1463 1677
1464 if (adev->powerplay.pp_funcs->dispatch_tasks) { 1678 if (adev->powerplay.pp_funcs->dispatch_tasks) {
1465 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_DISPLAY_CONFIG_CHANGE, NULL, NULL); 1679 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_DISPLAY_CONFIG_CHANGE, NULL);
1466 } else { 1680 } else {
1467 mutex_lock(&adev->pm.mutex); 1681 mutex_lock(&adev->pm.mutex);
1468 adev->pm.dpm.new_active_crtcs = 0; 1682 adev->pm.dpm.new_active_crtcs = 0;
@@ -1512,6 +1726,10 @@ static int amdgpu_debugfs_pm_info_pp(struct seq_file *m, struct amdgpu_device *a
1512 seq_printf(m, "\t%u MHz (MCLK)\n", value/100); 1726 seq_printf(m, "\t%u MHz (MCLK)\n", value/100);
1513 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_SCLK, (void *)&value, &size)) 1727 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_SCLK, (void *)&value, &size))
1514 seq_printf(m, "\t%u MHz (SCLK)\n", value/100); 1728 seq_printf(m, "\t%u MHz (SCLK)\n", value/100);
1729 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_STABLE_PSTATE_SCLK, (void *)&value, &size))
1730 seq_printf(m, "\t%u MHz (PSTATE_SCLK)\n", value/100);
1731 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_STABLE_PSTATE_MCLK, (void *)&value, &size))
1732 seq_printf(m, "\t%u MHz (PSTATE_MCLK)\n", value/100);
1515 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDGFX, (void *)&value, &size)) 1733 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDGFX, (void *)&value, &size))
1516 seq_printf(m, "\t%u mV (VDDGFX)\n", value); 1734 seq_printf(m, "\t%u mV (VDDGFX)\n", value);
1517 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDNB, (void *)&value, &size)) 1735 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDNB, (void *)&value, &size))