Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/driver/amdxdna/aie2_pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,7 @@ static int aie2_query_sensors(struct amdxdna_client *client,
{
struct amdxdna_drm_query_sensor *sensor;
struct amdxdna_dev *xdna = client->xdna;
int power_estimate;
int ret = 0;
int min;

Expand All @@ -896,8 +897,9 @@ static int aie2_query_sensors(struct amdxdna_client *client,
if (!sensor)
return -ENOMEM;

power_estimate = aie2_smu_get_power_estimate();
sensor->type = AMDXDNA_SENSOR_TYPE_POWER;
sensor->input = __UINT32_MAX__; /* TODO: query the device and get the power data */
sensor->input = power_estimate >= 0 ? power_estimate : __UINT32_MAX__;
sensor->unitm = -3; /* in milliwatts */
snprintf(sensor->label, sizeof(sensor->label), "Total Power");
snprintf(sensor->units, sizeof(sensor->units), "mW");
Expand Down
8 changes: 6 additions & 2 deletions src/driver/amdxdna/aie2_pci.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <linux/workqueue.h>
#include <linux/completion.h>
#include <drm/gpu_scheduler.h>
#include <linux/version.h>
#include <linux/amd-pmf-io.h>

#include "drm_local/amdxdna_accel.h"
#include "aie2_msg_priv.h"
Expand Down Expand Up @@ -432,11 +434,13 @@ int aie2_smu_start(struct amdxdna_dev_hdl *ndev);
void aie2_smu_stop(struct amdxdna_dev_hdl *ndev);
int npu1_set_dpm(struct amdxdna_dev_hdl *ndev, u32 dpm_level);
int npu4_set_dpm(struct amdxdna_dev_hdl *ndev, u32 dpm_level);
int aie2_smu_get_mpnpu_clock_freq(struct amdxdna_dev_hdl *ndev);
int aie2_smu_get_hclock_freq(struct amdxdna_dev_hdl *ndev);
int aie2_smu_set_power_on(struct amdxdna_dev_hdl *ndev);
int aie2_smu_set_power_off(struct amdxdna_dev_hdl *ndev);
int aie2_smu_get_power_state(struct amdxdna_dev_hdl *ndev);
int aie2_smu_get_power_estimate(void);
#if KERNEL_VERSION(6, 18, 0) < LINUX_VERSION_CODE
int aie2_smu_get_npu_metrics(struct amd_pmf_npu_metrics *data);
#endif

/* aie2_pm.c */
int aie2_pm_init(struct amdxdna_dev_hdl *ndev);
Expand Down
20 changes: 16 additions & 4 deletions src/driver/amdxdna/aie2_smu.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,26 @@ int npu4_set_dpm(struct amdxdna_dev_hdl *ndev, u32 dpm_level)
return 0;
}

int aie2_smu_get_mpnpu_clock_freq(struct amdxdna_dev_hdl *ndev)
#if KERNEL_VERSION(6, 18, 0) < LINUX_VERSION_CODE
int aie2_smu_get_npu_metrics(struct amd_pmf_npu_metrics *data)
{
return ndev->npuclk_freq;
return amd_pmf_get_npu_data(data);
}
#endif

int aie2_smu_get_hclock_freq(struct amdxdna_dev_hdl *ndev)
int aie2_smu_get_power_estimate(void)
{
return ndev->hclk_freq;
#if KERNEL_VERSION(6, 18, 0) < LINUX_VERSION_CODE
struct amd_pmf_npu_metrics npu_metrics;
int ret;

ret = aie2_smu_get_npu_metrics(&npu_metrics);
if (ret)
return ret;

return npu_metrics.npu_power;
#endif
return -EOPNOTSUPP;
}

int aie2_smu_set_power_on(struct amdxdna_dev_hdl *ndev)
Expand Down