AMD General

Series is

Reviewed-by: Hawking Zhang <[email protected]>

Regards,
Hawking
-----Original Message-----
From: Kamal, Asad <[email protected]>
Sent: Wednesday, June 24, 2026 2:44 PM
To: [email protected]
Cc: Lazar, Lijo <[email protected]>; Zhang, Hawking <[email protected]>; 
Ma, Le <[email protected]>; Zhang, Morris <[email protected]>; Deucher, Alexander 
<[email protected]>; Wang, Yang(Kevin) <[email protected]>; Kamal, 
Asad <[email protected]>
Subject: [PATCH 1/5] 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 <[email protected]>
Reviewed-by: Lijo Lazar <[email protected]>
---
 drivers/gpu/drm/amd/pm/powerplay/inc/hwmgr.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

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

Reply via email to