Skip to content

Commit 2b3a7f0

Browse files
Shyam Sundar S Kjwrdegoede
authored andcommitted
platform/x86/amd/pmf: Change return type of amd_pmf_set_dram_addr()
In the current code, the metrics table information was required only for auto-mode or CnQF at a given time. Hence keeping the return type of amd_pmf_set_dram_addr() as static made sense. But with the addition of Smart PC builder feature, the metrics table information has to be shared by the Smart PC also and this feature resides outside of core.c. To make amd_pmf_set_dram_addr() visible outside of core.c make it as a non-static function and move the allocation of memory for metrics table from amd_pmf_init_metrics_table() to amd_pmf_set_dram_addr() as amd_pmf_set_dram_addr() is the common function to set the DRAM address. Add a suspend handler that can free up the allocated memory for getting the metrics table information. Reviewed-by: Mario Limonciello <[email protected]> Signed-off-by: Shyam Sundar S K <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Hans de Goede <[email protected]>
1 parent ae82cef commit 2b3a7f0

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

drivers/platform/x86/amd/pmf/core.c

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -251,29 +251,37 @@ static const struct pci_device_id pmf_pci_ids[] = {
251251
{ }
252252
};
253253

254-
static void amd_pmf_set_dram_addr(struct amd_pmf_dev *dev)
254+
int amd_pmf_set_dram_addr(struct amd_pmf_dev *dev, bool alloc_buffer)
255255
{
256256
u64 phys_addr;
257257
u32 hi, low;
258258

259+
/* Get Metrics Table Address */
260+
if (alloc_buffer) {
261+
dev->buf = kzalloc(sizeof(dev->m_table), GFP_KERNEL);
262+
if (!dev->buf)
263+
return -ENOMEM;
264+
}
265+
259266
phys_addr = virt_to_phys(dev->buf);
260267
hi = phys_addr >> 32;
261268
low = phys_addr & GENMASK(31, 0);
262269

263270
amd_pmf_send_cmd(dev, SET_DRAM_ADDR_HIGH, 0, hi, NULL);
264271
amd_pmf_send_cmd(dev, SET_DRAM_ADDR_LOW, 0, low, NULL);
272+
273+
return 0;
265274
}
266275

267276
int amd_pmf_init_metrics_table(struct amd_pmf_dev *dev)
268277
{
269-
/* Get Metrics Table Address */
270-
dev->buf = kzalloc(sizeof(dev->m_table), GFP_KERNEL);
271-
if (!dev->buf)
272-
return -ENOMEM;
278+
int ret;
273279

274280
INIT_DELAYED_WORK(&dev->work_buffer, amd_pmf_get_metrics);
275281

276-
amd_pmf_set_dram_addr(dev);
282+
ret = amd_pmf_set_dram_addr(dev, true);
283+
if (ret)
284+
return ret;
277285

278286
/*
279287
* Start collecting the metrics data after a small delay
@@ -284,17 +292,30 @@ int amd_pmf_init_metrics_table(struct amd_pmf_dev *dev)
284292
return 0;
285293
}
286294

295+
static int amd_pmf_suspend_handler(struct device *dev)
296+
{
297+
struct amd_pmf_dev *pdev = dev_get_drvdata(dev);
298+
299+
kfree(pdev->buf);
300+
301+
return 0;
302+
}
303+
287304
static int amd_pmf_resume_handler(struct device *dev)
288305
{
289306
struct amd_pmf_dev *pdev = dev_get_drvdata(dev);
307+
int ret;
290308

291-
if (pdev->buf)
292-
amd_pmf_set_dram_addr(pdev);
309+
if (pdev->buf) {
310+
ret = amd_pmf_set_dram_addr(pdev, false);
311+
if (ret)
312+
return ret;
313+
}
293314

294315
return 0;
295316
}
296317

297-
static DEFINE_SIMPLE_DEV_PM_OPS(amd_pmf_pm, NULL, amd_pmf_resume_handler);
318+
static DEFINE_SIMPLE_DEV_PM_OPS(amd_pmf_pm, amd_pmf_suspend_handler, amd_pmf_resume_handler);
298319

299320
static void amd_pmf_init_features(struct amd_pmf_dev *dev)
300321
{

drivers/platform/x86/amd/pmf/pmf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ int amd_pmf_init_metrics_table(struct amd_pmf_dev *dev);
421421
int amd_pmf_get_power_source(void);
422422
int apmf_install_handler(struct amd_pmf_dev *pmf_dev);
423423
int apmf_os_power_slider_update(struct amd_pmf_dev *dev, u8 flag);
424+
int amd_pmf_set_dram_addr(struct amd_pmf_dev *dev, bool alloc_buffer);
424425

425426
/* SPS Layer */
426427
int amd_pmf_get_pprof_modes(struct amd_pmf_dev *pmf);

0 commit comments

Comments
 (0)