drm/amd/pm: Create board/ as a kobject
Subsystems (3)
PATCH 1/3 drm/amd/pm: Create board/ as a kobject
Give board/ its own kobject and populate it with the board attribute group. Sysfs paths under board/ stay the same.
Signed-off-by Asad Kamal <[email protected]>
--- drivers/gpu/drm/amd/pm/amdgpu_pm.c | 120 +++++++++++++++++++++--- drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h | 3 + 2 files changed, 108 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_pm.c +105 -15
@@ -2410,11 +2410,15 @@ static struct attribute *board_attrs[] = {NULL }; +struct amdgpu_sysfs_kobj { +struct kobject kobj; +struct amdgpu_device *adev; +}; +static umode_t amdgpu_board_attr_visible (struct kobject *kobj,struct attribute *attr,int n) { -struct device *dev =kobj_to_dev (kobj); -struct drm_device *ddev =dev_get_drvdata (dev); -struct amdgpu_device *adev =drm_to_adev (ddev); + struct amdgpu_sysfs_kobj *board = container_of(kobj, struct amdgpu_sysfs_kobj, kobj); +struct amdgpu_device *adev = board->adev;if (attr == &dev_attr_baseboard_temp.attr) {if (!amdgpu_dpm_is_temp_metrics_supported (adev,SMU_TEMP_METRIC_BASEBOARD ))
@@ -2430,7 +2434,6 @@ static umode_t amdgpu_board_attr_visible(struct kobject *kobj, struct attribute }const struct attribute_group amdgpu_board_attr_group = { - .name ="board" , .attrs = board_attrs, .is_visible = amdgpu_board_attr_visible, };
@@ -4750,6 +4753,71 @@ static int amdgpu_od_set_init(struct amdgpu_device *adev)return ret; } +static ssize_t amdgpu_sysfs_attr_show (struct kobject *kobj,struct attribute *attr, +char *buf) +{ + struct amdgpu_sysfs_kobj *sk = container_of(kobj, struct amdgpu_sysfs_kobj, kobj); + struct device_attribute *dattr = container_of(attr, struct device_attribute, attr); + +if (!dattr->show) +return -EIO ; + +return dattr->show (sk->adev->dev, dattr, buf); +} + +static ssize_t amdgpu_sysfs_attr_store (struct kobject *kobj,struct attribute *attr, +const char *buf,size_t count) +{ + struct amdgpu_sysfs_kobj *sk = container_of(kobj, struct amdgpu_sysfs_kobj, kobj); + struct device_attribute *dattr = container_of(attr, struct device_attribute, attr); + +if (!dattr->store) +return -EIO ; + +return dattr->store (sk->adev->dev, dattr, buf, count); +} + +static void amdgpu_sysfs_kobj_release (struct kobject *kobj) +{ +kfree (container_of(kobj ,struct amdgpu_sysfs_kobj ,kobj )); +} + +static const struct sysfs_ops amdgpu_sysfs_ops = { + .show = amdgpu_sysfs_attr_show, + .store = amdgpu_sysfs_attr_store, +}; + +static const struct kobj_type amdgpu_sysfs_ktype = { + .sysfs_ops = &amdgpu_sysfs_ops, + .release = amdgpu_sysfs_kobj_release, +}; + +static struct kobject *amdgpu_board_kobj_create (struct amdgpu_device *adev) +{ +struct amdgpu_sysfs_kobj *board; +int ret; + + board =kzalloc_obj (*board); +if (!board) +return ERR_PTR (-ENOMEM ); + + board->adev = adev; + ret =kobject_init_and_add (&board->kobj, &amdgpu_sysfs_ktype, + &adev->dev->kobj,"board" ); +if (ret) + goto err_put; + + ret =sysfs_create_group (&board->kobj, &amdgpu_board_attr_group); +if (ret) + goto err_put; + +return &board->kobj; + +err_put: +kobject_put (&board->kobj); +return ERR_PTR (ret); +} +static void amdgpu_pm_npm_sysfs_init (struct amdgpu_device *adev) { static const struct {
@@ -4763,7 +4831,7 @@ static void amdgpu_pm_npm_sysfs_init(struct amdgpu_device *adev) { &dev_attr_npm_status, AMDGPU_NPM_CAP_NPM_STATUS }, };u64 cap =amdgpu_dpm_get_npm_cap (adev); -int i; +int i, ret;if (!cap)return ;
@@ -4776,8 +4844,12 @@ static void amdgpu_pm_npm_sysfs_init(struct amdgpu_device *adev)continue ; attr->attr.mode = ((bits &BIT (1 )) && attr->store) ?0644 :0444 ; -sysfs_add_file_to_group (&adev->dev->kobj, &attr->attr, - amdgpu_board_attr_group.name); + ret =sysfs_create_file (adev->pm.board_kobj, &attr->attr); +if (ret) { +dev_err (adev->dev,"failed to create sysfs file %s\n" , + attr->attr.name); +return ; + } } }
@@ -4848,18 +4920,27 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev) }if (amdgpu_dpm_is_temp_metrics_supported (adev,SMU_TEMP_METRIC_GPUBOARD )) { - ret =devm_device_add_group (adev->dev, - &amdgpu_board_attr_group); -if (ret) +struct kobject *board =amdgpu_board_kobj_create (adev); + +if (IS_ERR (board)) { + ret =PTR_ERR (board); goto err_out1; + } + adev->pm.board_kobj = board; +amdgpu_pm_npm_sysfs_init (adev);if (amdgpu_pm_get_sensor_generic (adev,AMDGPU_PP_SENSOR_UBB_POWER_LIMIT , (void *)&tmp) != -EOPNOTSUPP ) { -sysfs_add_file_to_group (&adev->dev->kobj, - &dev_attr_baseboard_power_limit.attr, - amdgpu_board_attr_group.name); -sysfs_add_file_to_group (&adev->dev->kobj, &dev_attr_baseboard_power.attr, - amdgpu_board_attr_group.name); + ret =sysfs_create_file (adev->pm.board_kobj, + &dev_attr_baseboard_power_limit.attr); +if (ret) +dev_err (adev->dev,"failed to create sysfs file %s\n" , + dev_attr_baseboard_power_limit.attr.name); + ret =sysfs_create_file (adev->pm.board_kobj, + &dev_attr_baseboard_power.attr); +if (ret) +dev_err (adev->dev,"failed to create sysfs file %s\n" , + dev_attr_baseboard_power.attr.name); } }
@@ -4868,6 +4949,10 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)return 0 ; err_out1: +if (adev->pm.board_kobj) { +kobject_put (adev->pm.board_kobj); + adev->pm.board_kobj =NULL ; + }amdgpu_device_attr_remove_groups (adev, &adev->pm.pm_attr_list); err_out0:if (adev->pm.int_hwmon_dev)
@@ -4878,6 +4963,11 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)void amdgpu_pm_sysfs_fini (struct amdgpu_device *adev) { +if (adev->pm.board_kobj) { +kobject_put (adev->pm.board_kobj); + adev->pm.board_kobj =NULL ; + } +amdgpu_od_set_fini (adev);if (adev->pm.int_hwmon_dev)
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +3 -0
@@ -23,6 +23,8 @@#ifndef __AMDGPU_DPM_H__#define __AMDGPU_DPM_H__ +struct kobject ; +/* Argument for PPSMC_MSG_GpuChangeState */ enum gfx_change_state { sGpuChangeState_D0Entry = 1,
@@ -387,6 +389,7 @@ struct amdgpu_pm {struct list_head od_kobj_list;uint32_t od_feature_mask; +struct kobject *board_kobj; }; int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors sensor,
Signature · 1 line
2.46.0
PATCH 2/3 drm/amd/pm: Place NPM sysfs files under board/npm
Create board/npm/ when AMDGPU_NPM_FLAGS_DIR is set and put the NPM files there. Devices that do not set the bit keep those files in board/.
Signed-off-by Asad Kamal <[email protected]>
--- .../gpu/drm/amd/include/kgd_pp_interface.h | 2 + drivers/gpu/drm/amd/pm/amdgpu_pm.c | 71 +++++++++++++++---- drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h | 1 + 3 files changed, 59 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/include/kgd_pp_interface.h +2 -0
@@ -190,6 +190,8 @@ enum amdgpu_npm_cap_field {#define AMDGPU_NPM_CAP_R (field) BIT_ULL((field) * 2)#define AMDGPU_NPM_CAP_W (field) BIT_ULL((field) * 2 + 1) +#define AMDGPU_NPM_FLAGS_DIR BIT_ULL(63) +enum amd_pp_task {AMD_PP_TASK_DISPLAY_CONFIG_CHANGE ,AMD_PP_TASK_ENABLE_USER_STATE ,
drivers/gpu/drm/amd/pm/amdgpu_pm.c +56 -15
122 lines not on this page · raw message
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +1 -0
@@ -390,6 +390,7 @@ struct amdgpu_pm {struct list_head od_kobj_list;uint32_t od_feature_mask;struct kobject *board_kobj; +struct kobject *npm_kobj; }; int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors sensor,
Signature · 1 line
2.46.0
PATCH 3/3 drm/amd/pm: Advertise NPM sysfs dir for smu_v15_0_8
In reply to Asad KamalSet AMDGPU_NPM_FLAGS_DIR so smu_v15_0_8 NPM files are created under board/npm/.
Signed-off-by Asad Kamal <[email protected]>
--- drivers/gpu/drm/amd/pm/swsmu/smu15/smu_v15_0_8_ppt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/smu15/smu_v15_0_8_ppt.c +2 -1
@@ -665,7 +665,8 @@ static u64 smu_v15_0_8_get_npm_cap(struct smu_context *smu)AMDGPU_NPM_CAP_R (AMDGPU_NPM_CAP_NODE_POWER ) |AMDGPU_NPM_CAP_R (AMDGPU_NPM_CAP_GLOBAL_PPT_RESID ) |AMDGPU_NPM_CAP_R (AMDGPU_NPM_CAP_MAX_NODE_POWER_LIMIT ) | -AMDGPU_NPM_CAP_R (AMDGPU_NPM_CAP_NPM_STATUS ); +AMDGPU_NPM_CAP_R (AMDGPU_NPM_CAP_NPM_STATUS ) | +AMDGPU_NPM_FLAGS_DIR ; } static int smu_v15_0_8_get_npm_data(struct smu_context *smu,
Signature · 1 line
2.46.0