Message ID | 20241206220001.164049-6-lizhi.hou@amd.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | AMD NPU driver improvements | expand |
On 12/6/2024 15:59, Lizhi Hou wrote: > Enhance GET_INFO ioctl to support retrieving firmware version. > > Signed-off-by: Lizhi Hou <lizhi.hou@amd.com> Reviewed-by: Mario Limonciello <mario.limonciello@amd.com> > --- > drivers/accel/amdxdna/aie2_pci.c | 20 ++++++++++++++++++++ > include/uapi/drm/amdxdna_accel.h | 16 +++++++++++++++- > 2 files changed, 35 insertions(+), 1 deletion(-) > > diff --git a/drivers/accel/amdxdna/aie2_pci.c b/drivers/accel/amdxdna/aie2_pci.c > index 1c8170325837..83abd16ade11 100644 > --- a/drivers/accel/amdxdna/aie2_pci.c > +++ b/drivers/accel/amdxdna/aie2_pci.c > @@ -640,6 +640,23 @@ static int aie2_get_aie_version(struct amdxdna_client *client, > return 0; > } > > +static int aie2_get_firmware_version(struct amdxdna_client *client, > + struct amdxdna_drm_get_info *args) > +{ > + struct amdxdna_drm_query_firmware_version version; > + struct amdxdna_dev *xdna = client->xdna; > + > + version.major = xdna->fw_ver.major; > + version.minor = xdna->fw_ver.minor; > + version.patch = xdna->fw_ver.sub; > + version.build = xdna->fw_ver.build; > + > + if (copy_to_user(u64_to_user_ptr(args->buffer), &version, sizeof(version))) > + return -EFAULT; > + > + return 0; > +} > + > static int aie2_get_clock_metadata(struct amdxdna_client *client, > struct amdxdna_drm_get_info *args) > { > @@ -752,6 +769,9 @@ static int aie2_get_info(struct amdxdna_client *client, struct amdxdna_drm_get_i > case DRM_AMDXDNA_QUERY_HW_CONTEXTS: > ret = aie2_get_hwctx_status(client, args); > break; > + case DRM_AMDXDNA_QUERY_FIRMWARE_VERSION: > + ret = aie2_get_firmware_version(client, args); > + break; > default: > XDNA_ERR(xdna, "Not supported request parameter %u", args->param); > ret = -EOPNOTSUPP; > diff --git a/include/uapi/drm/amdxdna_accel.h b/include/uapi/drm/amdxdna_accel.h > index af12af8bd699..4f15e53a548d 100644 > --- a/include/uapi/drm/amdxdna_accel.h > +++ b/include/uapi/drm/amdxdna_accel.h > @@ -375,6 +375,20 @@ struct amdxdna_drm_query_hwctx { > __u64 errors; > }; > > +/** > + * struct amdxdna_drm_query_firmware_version - Query the firmware version > + * @major: The major version number > + * @minor: The minor version number > + * @patch: The patch level version number > + * @build: The build ID > + */ > +struct amdxdna_drm_query_firmware_version { > + __u32 major; /* out */ > + __u32 minor; /* out */ > + __u32 patch; /* out */ > + __u32 build; /* out */ > +}; > + > enum amdxdna_drm_get_param { > DRM_AMDXDNA_QUERY_AIE_STATUS, > DRM_AMDXDNA_QUERY_AIE_METADATA, > @@ -382,7 +396,7 @@ enum amdxdna_drm_get_param { > DRM_AMDXDNA_QUERY_CLOCK_METADATA, > DRM_AMDXDNA_QUERY_SENSORS, > DRM_AMDXDNA_QUERY_HW_CONTEXTS, > - DRM_AMDXDNA_NUM_GET_PARAM, > + DRM_AMDXDNA_QUERY_FIRMWARE_VERSION = 8, > }; > > /**
On 12/6/2024 2:59 PM, Lizhi Hou wrote: > Enhance GET_INFO ioctl to support retrieving firmware version. > > Signed-off-by: Lizhi Hou <lizhi.hou@amd.com> Reviewed-by: Jeffrey Hugo <quic_jhugo@quicinc.com> Warning below through. > enum amdxdna_drm_get_param { > DRM_AMDXDNA_QUERY_AIE_STATUS, > DRM_AMDXDNA_QUERY_AIE_METADATA, > @@ -382,7 +396,7 @@ enum amdxdna_drm_get_param { > DRM_AMDXDNA_QUERY_CLOCK_METADATA, > DRM_AMDXDNA_QUERY_SENSORS, > DRM_AMDXDNA_QUERY_HW_CONTEXTS, > - DRM_AMDXDNA_NUM_GET_PARAM, > + DRM_AMDXDNA_QUERY_FIRMWARE_VERSION = 8, This would normally be considered breaking the uAPI, but since this driver is not yet in a released kernel, this is allowed. Keep this in mind for the future (can add things, but not remove them).
diff --git a/drivers/accel/amdxdna/aie2_pci.c b/drivers/accel/amdxdna/aie2_pci.c index 1c8170325837..83abd16ade11 100644 --- a/drivers/accel/amdxdna/aie2_pci.c +++ b/drivers/accel/amdxdna/aie2_pci.c @@ -640,6 +640,23 @@ static int aie2_get_aie_version(struct amdxdna_client *client, return 0; } +static int aie2_get_firmware_version(struct amdxdna_client *client, + struct amdxdna_drm_get_info *args) +{ + struct amdxdna_drm_query_firmware_version version; + struct amdxdna_dev *xdna = client->xdna; + + version.major = xdna->fw_ver.major; + version.minor = xdna->fw_ver.minor; + version.patch = xdna->fw_ver.sub; + version.build = xdna->fw_ver.build; + + if (copy_to_user(u64_to_user_ptr(args->buffer), &version, sizeof(version))) + return -EFAULT; + + return 0; +} + static int aie2_get_clock_metadata(struct amdxdna_client *client, struct amdxdna_drm_get_info *args) { @@ -752,6 +769,9 @@ static int aie2_get_info(struct amdxdna_client *client, struct amdxdna_drm_get_i case DRM_AMDXDNA_QUERY_HW_CONTEXTS: ret = aie2_get_hwctx_status(client, args); break; + case DRM_AMDXDNA_QUERY_FIRMWARE_VERSION: + ret = aie2_get_firmware_version(client, args); + break; default: XDNA_ERR(xdna, "Not supported request parameter %u", args->param); ret = -EOPNOTSUPP; diff --git a/include/uapi/drm/amdxdna_accel.h b/include/uapi/drm/amdxdna_accel.h index af12af8bd699..4f15e53a548d 100644 --- a/include/uapi/drm/amdxdna_accel.h +++ b/include/uapi/drm/amdxdna_accel.h @@ -375,6 +375,20 @@ struct amdxdna_drm_query_hwctx { __u64 errors; }; +/** + * struct amdxdna_drm_query_firmware_version - Query the firmware version + * @major: The major version number + * @minor: The minor version number + * @patch: The patch level version number + * @build: The build ID + */ +struct amdxdna_drm_query_firmware_version { + __u32 major; /* out */ + __u32 minor; /* out */ + __u32 patch; /* out */ + __u32 build; /* out */ +}; + enum amdxdna_drm_get_param { DRM_AMDXDNA_QUERY_AIE_STATUS, DRM_AMDXDNA_QUERY_AIE_METADATA, @@ -382,7 +396,7 @@ enum amdxdna_drm_get_param { DRM_AMDXDNA_QUERY_CLOCK_METADATA, DRM_AMDXDNA_QUERY_SENSORS, DRM_AMDXDNA_QUERY_HW_CONTEXTS, - DRM_AMDXDNA_NUM_GET_PARAM, + DRM_AMDXDNA_QUERY_FIRMWARE_VERSION = 8, }; /**
Enhance GET_INFO ioctl to support retrieving firmware version. Signed-off-by: Lizhi Hou <lizhi.hou@amd.com> --- drivers/accel/amdxdna/aie2_pci.c | 20 ++++++++++++++++++++ include/uapi/drm/amdxdna_accel.h | 16 +++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-)