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>
This commit is contained in:
Asad Kamal 2026-06-23 00:00:00 +00:00 committed by Alex Deucher
parent 5d3cc8e388
commit c42871ba48

View File

@ -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_ */