summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsad Kamal <asad.kamal@amd.com>2026-06-23 00:00:00 +0000
committerAlex Deucher <alexander.deucher@amd.com>2026-07-01 11:25:48 -0400
commitc42871ba4833855fb3ac1cdc586b3c5345d09e5d (patch)
tree9a7859b9eb2f2abb1ab039d0a2f100b79c2e9cd0
parent5d3cc8e388464f485d0944b87b8f9426e637d082 (diff)
downloadlinux-stable-c42871ba4833855fb3ac1cdc586b3c5345d09e5d.tar.gz
linux-stable-c42871ba4833855fb3ac1cdc586b3c5345d09e5d.zip
drm/amdgpu/pm: add pp_entries_max() helper
Add a static inline that returns the maximum safe record count for a PowerPlay sub-table, bounded by the lesser of soft_pp_table_size and adev->bios_size. Uses adev->bios directly to avoid a dependency on struct atom_context. Subsequent patches use it to clamp ucNumEntries. Signed-off-by: Asad Kamal <asad.kamal@amd.com> Reviewed-by: Lijo Lazar <lijo.lazar@amd.com> Reviewed-by: Hawking Zhang <Hawking.Zhang@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
-rw-r--r--drivers/gpu/drm/amd/pm/powerplay/inc/hwmgr.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/drivers/gpu/drm/amd/pm/powerplay/inc/hwmgr.h b/drivers/gpu/drm/amd/pm/powerplay/inc/hwmgr.h
index ca71efaa1656..7ebc1344023f 100644
--- a/drivers/gpu/drm/amd/pm/powerplay/inc/hwmgr.h
+++ b/drivers/gpu/drm/amd/pm/powerplay/inc/hwmgr.h
@@ -829,4 +829,21 @@ int smu8_init_function_pointers(struct pp_hwmgr *hwmgr);
int vega12_hwmgr_init(struct pp_hwmgr *hwmgr);
int vega20_hwmgr_init(struct pp_hwmgr *hwmgr);
+static inline uint32_t pp_entries_max(const struct pp_hwmgr *hwmgr,
+ const void *sub_table,
+ size_t hdr_size, size_t rec_size)
+{
+ struct amdgpu_device *adev = (struct amdgpu_device *)hwmgr->adev;
+ const char *bios_end = (const char *)adev->bios + adev->bios_size;
+ const char *pp_end = (const char *)hwmgr->soft_pp_table
+ + hwmgr->soft_pp_table_size;
+ const char *entries = (const char *)sub_table + hdr_size;
+
+ if (pp_end > bios_end)
+ return 0;
+ if (!rec_size || entries >= pp_end)
+ return 0;
+ return (uint32_t)((pp_end - entries) / rec_size);
+}
+
#endif /* _HWMGR_H_ */