drm/amd/pm: Add helper functions to fetch pptable
Subsystems (3)
PATCH 1/5 drm/amd/pm: Add helper functions to fetch pptable
PPTables could be embedded in firmware binaries with v2.0 or v2.1 format. Add a common helper to get pptable from firmware binaries.
--- drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c | 140 +++++++++++++++++++++++++ drivers/gpu/drm/amd/pm/swsmu/smu_cmn.h | 3 + 2 files changed, 143 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +140 -0
@@ -1551,3 +1551,143 @@ int smu_cmn_dpm_pcie_width_idx(int width)return ret; } + +static int smu_cmn_get_pptable_v2_0 (struct smu_context *smu,void **table,uint32_t *size) +{ +const struct smc_firmware_header_v2_0 *v2; +struct amdgpu_device *adev = smu->adev; +size_t fw_size = adev->pm.fw->size; +uint32_t ppt_offset_bytes; +uint32_t ppt_size_bytes; + +if (fw_size <sizeof (*v2)) { +dev_err (adev->dev, +"SMC firmware too small for v2.0 header: %zu < %zu\n" , + fw_size,sizeof (*v2)); +return -EINVAL ; + } + + v2 = (const struct smc_firmware_header_v2_0 *)adev->pm.fw->data; + + ppt_offset_bytes =le32_to_cpu (v2->ppt_offset_bytes); + ppt_size_bytes =le32_to_cpu (v2->ppt_size_bytes); + +if (ppt_offset_bytes > fw_size || + ppt_size_bytes > fw_size - ppt_offset_bytes) { +dev_err (adev->dev, +"pptable v2.0 exceeds firmware binary: offset %u + size %u > %zu\n" , + ppt_offset_bytes, ppt_size_bytes, fw_size); +return -EINVAL ; + } + + *size = ppt_size_bytes; + *table = (uint8_t *)v2 + ppt_offset_bytes; + +return 0 ; +} + +static int smu_cmn_get_pptable_v2_1 (struct smu_context *smu,void **table, +uint32_t *size,uint32_t pptable_id) +{ +const struct smc_firmware_header_v2_1 *v2_1; +struct amdgpu_device *adev = smu->adev; +struct smc_soft_pptable_entry *entries; +size_t fw_size = adev->pm.fw->size; +uint32_t pptable_entry_offset; +uint32_t ppt_offset_bytes; +uint32_t ppt_size_bytes; +uint32_t pptable_count; +int i; + +if (fw_size <sizeof (*v2_1)) { +dev_err (adev->dev, +"SMC firmware too small for v2.1 header: %zu < %zu\n" , + fw_size,sizeof (*v2_1)); +return -EINVAL ; + } + + v2_1 = (const struct smc_firmware_header_v2_1 *)adev->pm.fw->data; + + pptable_entry_offset =le32_to_cpu (v2_1->pptable_entry_offset); + pptable_count =le32_to_cpu (v2_1->pptable_count); + +if (pptable_entry_offset > fw_size || + pptable_count > (fw_size - pptable_entry_offset) /sizeof (*entries)) { +dev_err (adev->dev, +"pptable v2.1 entry array exceeds firmware binary: offset %u, count %u\n" , + pptable_entry_offset, pptable_count); +return -EINVAL ; + } + + entries = (struct smc_soft_pptable_entry *) + ((uint8_t *)v2_1 + pptable_entry_offset); + +for (i =0 ; i < pptable_count; i++) { +if (le32_to_cpu (entries[i].id) != pptable_id) +continue ; + + ppt_offset_bytes =le32_to_cpu (entries[i].ppt_offset_bytes); + ppt_size_bytes =le32_to_cpu (entries[i].ppt_size_bytes); + +if (ppt_offset_bytes > fw_size || + ppt_size_bytes > fw_size - ppt_offset_bytes) { +dev_err (adev->dev, +"pptable entry %d exceeds firmware binary: offset %u + size %u > %zu\n" , + i, ppt_offset_bytes, ppt_size_bytes, fw_size); +return -EINVAL ; + } + + *table = (uint8_t *)v2_1 + ppt_offset_bytes; + *size = ppt_size_bytes; +return 0 ; + } + +return -EINVAL ; +} + +/** +* smu_cmn_get_pptable_from_firmware - locate the soft pptable embedded in the +* SMC firmware binary. +* @smu: SMU context +* @table: on success, set to the start of the pptable within the firmware +* blob +* @size: on success, set to the pptable size in bytes +* @pptable_id: the entry ID to search for (used only for v2.1 binaries) +* +* Reads the firmware header version and dispatches to the appropriate v2.x +* parser. Only major version 2 is supported; minor version selects between +* the single-entry (v2.0) and multi-entry directory (v2.1) layouts. +* +* Return: 0 on success, -EINVAL for an unsupported version or if the +* requested pptable cannot be found or exceeds the binary bounds. +*/ +int smu_cmn_get_pptable_from_firmware (struct smu_context *smu,void **table, +uint32_t *size,uint32_t pptable_id) +{ +const struct smc_firmware_header_v1_0 *hdr; +struct amdgpu_device *adev = smu->adev; +uint16_t version_major, version_minor; + + hdr = (const struct smc_firmware_header_v1_0 *)adev->pm.fw->data; +if (!hdr) +return -EINVAL ; + +dev_info (adev->dev,"use driver provided pptable %d\n" , pptable_id); + + version_major =le16_to_cpu (hdr->header.header_version_major); + version_minor =le16_to_cpu (hdr->header.header_version_minor); +if (version_major !=2 ) { +dev_err (adev->dev,"Unsupported smu firmware version %d.%d\n" , + version_major, version_minor); +return -EINVAL ; + } + +switch (version_minor) { +case 0 : +return smu_cmn_get_pptable_v2_0 (smu, table, size); +case 1 : +return smu_cmn_get_pptable_v2_1 (smu, table, size, pptable_id); +default : +return -EINVAL ; + } +}
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.h +3 -0
@@ -249,6 +249,9 @@ int smu_cmn_dpm_pcie_gen_idx(int gen);int smu_cmn_dpm_pcie_width_idx (int width);int smu_cmn_check_fw_version (struct smu_context *smu); +int smu_cmn_get_pptable_from_firmware (struct smu_context *smu,void **table, +uint32_t *size,uint32_t pptable_id); +/*SMU gpu metrics */ /* Attribute ID mapping */
Signature · 1 line
2.49.0
PATCH 2/5 drm/amd/pm: Use helper to get pptable in SMUv11
Use common helper function to get pptable from firmware binary in SMUv11.
--- .../gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c | 79 +++---------------- 1 file changed, 10 insertions(+), 69 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c +10 -69
@@ -192,81 +192,22 @@ int smu_v11_0_check_fw_status(struct smu_context *smu)return -EIO ; } -static int smu_v11_0_set_pptable_v2_0 (struct smu_context *smu,void **table,uint32_t *size) -{ -struct amdgpu_device *adev = smu->adev; -uint32_t ppt_offset_bytes; -const struct smc_firmware_header_v2_0 *v2; - - v2 = (const struct smc_firmware_header_v2_0 *) adev->pm.fw->data; - - ppt_offset_bytes =le32_to_cpu (v2->ppt_offset_bytes); - *size =le32_to_cpu (v2->ppt_size_bytes); - *table = (uint8_t *)v2 + ppt_offset_bytes; - -return 0 ; -} - -static int smu_v11_0_set_pptable_v2_1 (struct smu_context *smu,void **table, -uint32_t *size,uint32_t pptable_id) -{ -struct amdgpu_device *adev = smu->adev; -const struct smc_firmware_header_v2_1 *v2_1; -struct smc_soft_pptable_entry *entries; -uint32_t pptable_count =0 ; -int i =0 ; - - v2_1 = (const struct smc_firmware_header_v2_1 *) adev->pm.fw->data; - entries = (struct smc_soft_pptable_entry *) - ((uint8_t *)v2_1 +le32_to_cpu (v2_1->pptable_entry_offset)); - pptable_count =le32_to_cpu (v2_1->pptable_count); -for (i =0 ; i < pptable_count; i++) { -if (le32_to_cpu (entries[i].id) == pptable_id) { - *table = ((uint8_t *)v2_1 +le32_to_cpu (entries[i].ppt_offset_bytes)); - *size =le32_to_cpu (entries[i].ppt_size_bytes); -break ; - } - } - -if (i == pptable_count) -return -EINVAL ; - -return 0 ; -} -int smu_v11_0_setup_pptable (struct smu_context *smu) {struct amdgpu_device *adev = smu->adev; -const struct smc_firmware_header_v1_0 *hdr; -int ret, index; -uint32_t size =0 ;uint16_t atom_table_size;uint8_t frev, crev; +uint32_t size =0 ; +int ret, index;void *table; -uint16_t version_major, version_minor; - -if (!amdgpu_sriov_vf (adev)) { - hdr = (const struct smc_firmware_header_v1_0 *) adev->pm.fw->data; - version_major =le16_to_cpu (hdr->header.header_version_major); - version_minor =le16_to_cpu (hdr->header.header_version_minor); -if (version_major ==2 && smu->smu_table.boot_values.pp_table_id >0 ) { -dev_info (adev->dev,"use driver provided pptable %d\n" , smu->smu_table.boot_values.pp_table_id); -switch (version_minor) { -case 0 : - ret =smu_v11_0_set_pptable_v2_0 (smu, &table, &size); -break ; -case 1 : - ret =smu_v11_0_set_pptable_v2_1 (smu, &table, &size, - smu->smu_table.boot_values.pp_table_id); -break ; -default : - ret = -EINVAL ; -break ; - } -if (ret) -return ret; - goto out; - } + +if (!amdgpu_sriov_vf (adev) && + smu->smu_table.boot_values.pp_table_id >0 ) { + ret =smu_cmn_get_pptable_from_firmware (smu, &table, &size, + smu->smu_table.boot_values.pp_table_id); +if (ret) +return ret; + goto out; }dev_info (adev->dev,"use vbios provided pptable\n" );
Signature · 1 line
2.49.0
PATCH 3/5 drm/amd/pm: Use helper to get pptable in SMUv13
In reply to Lijo LazarUse common helper function to get pptable from firmware binary in SMUv13.
--- drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h | 4 - .../gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c | 85 +------------------ 2 files changed, 2 insertions(+), 87 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h +0 -4
@@ -255,10 +255,6 @@ void smu_v13_0_init_msg_ctl(struct smu_context *smu,int smu_v13_0_mode1_reset (struct smu_context *smu); -int smu_v13_0_get_pptable_from_firmware (struct smu_context *smu, -void **table, -uint32_t *size, -uint32_t pptable_id); int smu_v13_0_update_pcie_parameters(struct smu_context *smu, uint8_t pcie_gen_cap,
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c +2 -83
109 lines not on this page · raw message
Signature · 1 line
2.49.0
PATCH 4/5 drm/amd/pm: Use helper to get pptable in SMUv14
In reply to Lijo LazarUse common helper function to get pptable from firmware binary in SMUv14.
--- drivers/gpu/drm/amd/pm/swsmu/inc/smu_v14_0.h | 4 - .../gpu/drm/amd/pm/swsmu/smu14/smu_v14_0.c | 85 +------------------ 2 files changed, 2 insertions(+), 87 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/inc/smu_v14_0.h +0 -4
@@ -203,10 +203,6 @@ int smu_v14_0_set_gfx_power_up_by_imu(struct smu_context *smu);int smu_v14_0_set_default_dpm_tables (struct smu_context *smu); -int smu_v14_0_get_pptable_from_firmware (struct smu_context *smu, -void **table, -uint32_t *size, -uint32_t pptable_id); int smu_v14_0_od_edit_dpm_table(struct smu_context *smu, enum PP_OD_DPM_TABLE_COMMAND type,
drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0.c +2 -83
109 lines not on this page · raw message
Signature · 1 line
2.49.0
PATCH 5/5 drm/amd/pm: Use helper to get pptable in SMUv15
In reply to Lijo LazarUse common helper function to get pptable from firmware binary in SMUv15.
--- drivers/gpu/drm/amd/pm/swsmu/inc/smu_v15_0.h | 4 - .../gpu/drm/amd/pm/swsmu/smu15/smu_v15_0.c | 85 +------------------ 2 files changed, 2 insertions(+), 87 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/inc/smu_v15_0.h +0 -4
@@ -211,10 +211,6 @@ int smu_v15_0_deep_sleep_control(struct smu_context *smu,int smu_v15_0_set_gfx_power_up_by_imu (struct smu_context *smu); -int smu_v15_0_get_pptable_from_firmware (struct smu_context *smu, -void **table, -uint32_t *size, -uint32_t pptable_id); int smu_v15_0_od_edit_dpm_table(struct smu_context *smu, enum PP_OD_DPM_TABLE_COMMAND type,
drivers/gpu/drm/amd/pm/swsmu/smu15/smu_v15_0.c +2 -83
109 lines not on this page · raw message
Signature · 1 line
2.49.0
AMD General
Series is
Regards,
Hawking
-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, May 29, 2026 5:41 PM
To: [email protected]
Cc: Zhang, Hawking <[email protected]>; Deucher, Alexander <[email protected]>; Kamal, Asad <[email protected]>; Wang, Yang(Kevin) <[email protected]>
Subject: [PATCH 1/5] drm/amd/pm: Add helper functions to fetch pptable
PPTables could be embedded in firmware binaries with v2.0 or v2.1 format. Add a common helper to get pptable from firmware binaries.
--- drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c | 140 +++++++++++++++++++++++++ drivers/gpu/drm/amd/pm/swsmu/smu_cmn.h | 3 + 2 files changed, 143 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +140 -0
@@ -1551,3 +1551,143 @@ int smu_cmn_dpm_pcie_width_idx(int width)return ret; } + +static int smu_cmn_get_pptable_v2_0 (struct smu_context *smu,void +**table,uint32_t *size) { +const struct smc_firmware_header_v2_0 *v2; +struct amdgpu_device *adev = smu->adev; +size_t fw_size = adev->pm.fw->size; +uint32_t ppt_offset_bytes; +uint32_t ppt_size_bytes; + +if (fw_size <sizeof (*v2)) { +dev_err (adev->dev, +"SMC firmware too small for v2.0 header: %zu < %zu\n" , + fw_size,sizeof (*v2)); +return -EINVAL ; + } + + v2 = (const struct smc_firmware_header_v2_0 *)adev->pm.fw->data; + + ppt_offset_bytes =le32_to_cpu (v2->ppt_offset_bytes); + ppt_size_bytes =le32_to_cpu (v2->ppt_size_bytes); + +if (ppt_offset_bytes > fw_size || + ppt_size_bytes > fw_size - ppt_offset_bytes) { +dev_err (adev->dev, +"pptable v2.0 exceeds firmware binary: offset %u + size %u > %zu\n" , + ppt_offset_bytes, ppt_size_bytes, fw_size); +return -EINVAL ; + } + + *size = ppt_size_bytes; + *table = (uint8_t *)v2 + ppt_offset_bytes; + +return 0 ; +} + +static int smu_cmn_get_pptable_v2_1 (struct smu_context *smu,void **table, +uint32_t *size,uint32_t pptable_id) { +const struct smc_firmware_header_v2_1 *v2_1; +struct amdgpu_device *adev = smu->adev; +struct smc_soft_pptable_entry *entries; +size_t fw_size = adev->pm.fw->size; +uint32_t pptable_entry_offset; +uint32_t ppt_offset_bytes; +uint32_t ppt_size_bytes; +uint32_t pptable_count; +int i; + +if (fw_size <sizeof (*v2_1)) { +dev_err (adev->dev, +"SMC firmware too small for v2.1 header: %zu < %zu\n" , + fw_size,sizeof (*v2_1)); +return -EINVAL ; + } + + v2_1 = (const struct smc_firmware_header_v2_1 *)adev->pm.fw->data; + + pptable_entry_offset =le32_to_cpu (v2_1->pptable_entry_offset); + pptable_count =le32_to_cpu (v2_1->pptable_count); + +if (pptable_entry_offset > fw_size || + pptable_count > (fw_size - pptable_entry_offset) /sizeof (*entries)) { +dev_err (adev->dev, +"pptable v2.1 entry array exceeds firmware binary: offset %u, count %u\n" , + pptable_entry_offset, pptable_count); +return -EINVAL ; + } + + entries = (struct smc_soft_pptable_entry *) + ((uint8_t *)v2_1 + pptable_entry_offset); + +for (i =0 ; i < pptable_count; i++) { +if (le32_to_cpu (entries[i].id) != pptable_id) +continue ; + + ppt_offset_bytes =le32_to_cpu (entries[i].ppt_offset_bytes); + ppt_size_bytes =le32_to_cpu (entries[i].ppt_size_bytes); + +if (ppt_offset_bytes > fw_size || + ppt_size_bytes > fw_size - ppt_offset_bytes) { +dev_err (adev->dev, +"pptable entry %d exceeds firmware binary: offset %u + size %u > %zu\n" , + i, ppt_offset_bytes, ppt_size_bytes, fw_size); +return -EINVAL ; + } + + *table = (uint8_t *)v2_1 + ppt_offset_bytes; + *size = ppt_size_bytes; +return 0 ; + } + +return -EINVAL ; +} + +/** +* smu_cmn_get_pptable_from_firmware - locate the soft pptable embedded in the +* SMC firmware binary. +* @smu: SMU context +* @table: on success, set to the start of the pptable within the firmware +* blob +* @size: on success, set to the pptable size in bytes +* @pptable_id: the entry ID to search for (used only for v2.1 +binaries) +* +* Reads the firmware header version and dispatches to the appropriate +v2.x +* parser. Only major version 2 is supported; minor version selects +between +* the single-entry (v2.0) and multi-entry directory (v2.1) layouts. +* +* Return: 0 on success, -EINVAL for an unsupported version or if the +* requested pptable cannot be found or exceeds the binary bounds. +*/ +int smu_cmn_get_pptable_from_firmware (struct smu_context *smu,void **table, +uint32_t *size,uint32_t pptable_id) { +const struct smc_firmware_header_v1_0 *hdr; +struct amdgpu_device *adev = smu->adev; +uint16_t version_major, version_minor; + + hdr = (const struct smc_firmware_header_v1_0 *)adev->pm.fw->data; +if (!hdr) +return -EINVAL ; + +dev_info (adev->dev,"use driver provided pptable %d\n" , pptable_id); + + version_major =le16_to_cpu (hdr->header.header_version_major); + version_minor =le16_to_cpu (hdr->header.header_version_minor); +if (version_major !=2 ) { +dev_err (adev->dev,"Unsupported smu firmware version %d.%d\n" , + version_major, version_minor); +return -EINVAL ; + } + +switch (version_minor) { +case 0 : +return smu_cmn_get_pptable_v2_0 (smu, table, size); +case 1 : +return smu_cmn_get_pptable_v2_1 (smu, table, size, pptable_id); +default : +return -EINVAL ; + }
+}
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.h +3 -1
@@ -249,6 +249,9 @@ int smu_cmn_dpm_pcie_gen_idx(int gen); int smu_cmn_dpm_pcie_width_idx(int width); int smu_cmn_check_fw_version(struct smu_context *smu); +int smu_cmn_get_pptable_from_firmware (struct smu_context *smu,void **table, +uint32_t *size,uint32_t pptable_id); +/*SMU gpu metrics */ /* Attribute ID mapping */ --
2.49.0