drm/amd/pm: export a function amdgpu_smu_ras_send_msg to allow send msg directly
PATCH 1/3 drm/amd/pm: export a function amdgpu_smu_ras_send_msg to allow send msg directly
provide a interface that allows ras client send msg to smu/pmfw directly.
--- drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 11 +++++++++++ drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h | 11 +++++++++++ .../drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c | 19 +++++++++++++++++++ 3 files changed, 41 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +11 -0
@@ -609,6 +609,17 @@ bool is_support_cclk_dpm(struct amdgpu_device *adev)return true; } +int amdgpu_smu_ras_send_msg (struct amdgpu_device *adev,enum smu_message_type msg, +uint32_t param,uint32_t *read_arg) +{ +struct smu_context *smu = adev->powerplay.pp_handle; +int ret = -EOPNOTSUPP ; + +if (smu->ppt_funcs && smu->ppt_funcs->ras_send_msg) + ret = smu->ppt_funcs->ras_send_msg (smu, msg, param, read_arg); + +return ret; +}static int smu_sys_get_pp_table (void *handle,char **table)
drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h +11 -0
@@ -1521,6 +1521,15 @@ struct pptable_funcs {*/ ssize_t (*get_xcp_metrics)(struct smu_context *smu,int xcp_id,void *table); +/** +* @ras_send_msg: Send a message with a parameter from Ras +* &msg: Type of message. +* ¶m: Message parameter. +* &read_arg: SMU response (optional). +*/ +int (*ras_send_msg)(struct smu_context *smu, +enum smu_message_type msg,uint32_t param,uint32_t *read_arg); + }; typedef enum {
@@ -1786,6 +1795,8 @@ int smu_set_pm_policy(struct smu_context *smu, enum pp_pm_policy p_type,ssize_t smu_get_pm_policy_info (struct smu_context *smu,enum pp_pm_policy p_type,char *sysbuf); +int amdgpu_smu_ras_send_msg (struct amdgpu_device *adev,enum smu_message_type msg, +uint32_t param,uint32_t *readarg);#endif void smu_feature_cap_set (struct smu_context *smu,enum smu_feature_cap_id fea_id);
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c +19 -0
@@ -3227,6 +3227,24 @@ static int smu_v13_0_6_reset_vcn(struct smu_context *smu, uint32_t inst_mask)return ret; } +static int smu_v13_0_6_ras_send_msg (struct smu_context *smu,enum smu_message_type msg,uint32_t param,uint32_t *read_arg) +{ +int ret; + +switch (msg) { +case SMU_MSG_QueryValidMcaCount: +case SMU_MSG_QueryValidMcaCeCount: +case SMU_MSG_McaBankDumpDW: +case SMU_MSG_McaBankCeDumpDW: +case SMU_MSG_ClearMcaOnRead: + ret =smu_cmn_send_smc_msg_with_param (smu, msg, param, read_arg); +break ; +default : + ret = -EPERM ; + } + +return ret; +}static int smu_v13_0_6_post_init (struct smu_context *smu) {
@@ -3922,6 +3940,7 @@ static const struct pptable_funcs smu_v13_0_6_ppt_funcs = { .reset_sdma = smu_v13_0_6_reset_sdma, .dpm_reset_vcn = smu_v13_0_6_reset_vcn, .post_init = smu_v13_0_6_post_init, + .ras_send_msg = smu_v13_0_6_ras_send_msg, };void smu_v13_0_6_set_ppt_funcs (struct smu_context *smu)
Signature · 1 line
2.34.1
PATCH 2/3 drm/amdgpu: Add ras module files into amdgpu
Add ras module files into amdgpu.
--- drivers/gpu/drm/amd/amdgpu/Makefile | 8 +++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/Makefile +7 -1
@@ -37,7 +37,8 @@ ccflags-y := -I$(FULL_AMD_PATH)/include/asic_reg \ -I$(FULL_AMD_DISPLAY_PATH)/modules/inc \ -I$(FULL_AMD_DISPLAY_PATH)/dc \ -I$(FULL_AMD_DISPLAY_PATH)/amdgpu_dm \ - -I$(FULL_AMD_PATH)/amdkfd + -I$(FULL_AMD_PATH)/amdkfd \ + -I$(FULL_AMD_PATH)/ras/ras_mgr # Locally disable W=1 warnings enabled in drm subsystem Makefile subdir-ccflags-y += -Wno-override-init
@@ -324,4 +325,9 @@ amdgpu-y += \ isp_v4_1_1.o endif +AMD_GPU_RAS_PATH := ../ras +AMD_GPU_RAS_FULL_PATH := $(FULL_AMD_PATH)/ras +include $(AMD_GPU_RAS_FULL_PATH)/Makefile +amdgpu-y += $(AMD_GPU_RAS_FILES) + obj-$(CONFIG_DRM_AMDGPU)+= amdgpu.o
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +1 -0
@@ -504,6 +504,7 @@ struct ras_critical_region { };struct amdgpu_ras { +void *ras_mgr;/* ras infrastructure */ /* for ras itself. */ uint32_t features;
Signature · 1 line
2.34.1
PATCH 3/3 drm/amdgpu: Add amdgpu drm ras ioctl for ras module
In reply to YiPeng ChaiAdd amdgpu drm ras ioctl for ras module.
V2:
Updated ras ioctl structure and description.
V3:
Rename the ras command.
V4:
Remove some variables.
V5:
Add null pointer check.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 + .../gpu/drm/amd/ras/ras_mgr/amdgpu_ras_cmd.c | 44 +++++++++++++++++++ include/uapi/drm/amdgpu_drm.h | 32 ++++++++++++++ 4 files changed, 80 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3 -0
@@ -718,6 +718,9 @@ int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *fiint amdgpu_cs_wait_fences_ioctl (struct drm_device *dev,void *data,struct drm_file *filp); +int amdgpu_ras_mgr_ioctl (struct drm_device *dev,void *data, +struct drm_file *filp); +/* VRAM scratch page for HDP bug, default vram page */ struct amdgpu_mem_scratch {struct amdgpu_bo *robj;
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
@@ -3057,6 +3057,7 @@ const struct drm_ioctl_desc amdgpu_ioctls_kms[] = {DRM_IOCTL_DEF_DRV (AMDGPU_USERQ_SIGNAL , amdgpu_userq_signal_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_USERQ_WAIT , amdgpu_userq_wait_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_GEM_LIST_HANDLES , amdgpu_gem_list_handles_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ), + DRM_IOCTL_DEF_DRV(AMDGPU_RAS, amdgpu_ras_mgr_ioctl, DRM_AUTH|DRM_RENDER_ALLOW), }; static const struct drm_driver amdgpu_kms_driver = {
drivers/gpu/drm/amd/ras/ras_mgr/amdgpu_ras_cmd.c +44 -0
47 lines not on this page · raw message
include/uapi/drm/amdgpu_drm.h +32 -0
@@ -59,6 +59,9 @@ extern "C" {#define DRM_AMDGPU_USERQ_WAIT 0x18#define DRM_AMDGPU_GEM_LIST_HANDLES 0x19 +/* amdgpu ras ioctls */ +#define DRM_AMDGPU_RAS 0x5d +#define DRM_IOCTL_AMDGPU_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)#define DRM_IOCTL_AMDGPU_GEM_MMAP DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)#define DRM_IOCTL_AMDGPU_CTX DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_CTX, union drm_amdgpu_ctx)
@@ -79,6 +82,7 @@ extern "C" {#define DRM_IOCTL_AMDGPU_USERQ_SIGNAL DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_SIGNAL, struct drm_amdgpu_userq_signal)#define DRM_IOCTL_AMDGPU_USERQ_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_WAIT, struct drm_amdgpu_userq_wait)#define DRM_IOCTL_AMDGPU_GEM_LIST_HANDLES DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_LIST_HANDLES, struct drm_amdgpu_gem_list_handles) +#define DRM_IOCTL_AMDGPU_RAS DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_RAS, struct drm_amdgpu_ras)/** * DOC: memory domains
@@ -1686,6 +1690,34 @@ struct drm_color_ctm_3x4 {__u64 matrix[12 ]; }; +/* +* Amdgpu ras command id +*/ + +/* Get amdgpu ras capabilities */ +#define AMDGPU_RAS_CMD_GET_CAPS 0x01 + +/* Input structure for amdgpu ras ioctl */ +struct drm_amdgpu_ras { +/* Amdgpu ras version */ +__u32 version; +/* AMDGPU_RAS_CMD_* */ +__u32 cmd_id; +/* Pointer to input parameter buffer */ +__u64 input_buf_ptr; +/* Pointer to output buffer */ +__u64 output_buf_ptr; +/* Output buffer size */ +__u32 output_buf_size; +__u32 pad; +}; + +struct drm_amdgpu_ras_caps { +/* OAM ID */ +__u32 oam_id; +__u32 pad; +}; +#if defined(__cplusplus) }#endif
Signature · 1 line
2.34.1
Re: [PATCH 3/3] drm/amdgpu: Add amdgpu drm ras ioctl for ras module
Quoted 2 lines · YiPeng Chai
Add amdgpu drm ras ioctl for ras module.
Please describe the IOCTL and how it is used and what functionality it provides. Additionally please provide a link to the proposed open source userspace tools that will use it. We can't merge the kernel code until we have the userspace side available. Additional comments below.
Quoted 41 lines
V2:
Updated ras ioctl structure and description.V3:
Rename the ras command.V4:
Remove some variables.V5:
Add null pointer check.Signed-off-by YiPeng Chai <[email protected]>Reviewed-by Tao Zhou <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 + .../gpu/drm/amd/ras/ras_mgr/amdgpu_ras_cmd.c | 44 +++++++++++++++++++ include/uapi/drm/amdgpu_drm.h | 32 ++++++++++++++ 4 files changed, 80 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu.h +3
-0@@ -718,6 +718,9 @@ int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *fiint amdgpu_cs_wait_fences_ioctl (struct drm_device *dev,void *data,struct drm_file *filp); +int amdgpu_ras_mgr_ioctl (struct drm_device *dev,void *data, +struct drm_file *filp); +/* VRAM scratch page for HDP bug, default vram page */ struct amdgpu_mem_scratch {struct amdgpu_bo *robj;drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c const struct drm_ioctl_desc amdgpu_ioctls_kms[] = { · line 3060
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1
-0@@ -3057,6 +3057,7 @@ const struct drm_ioctl_desc amdgpu_ioctls_kms[] = {DRM_IOCTL_DEF_DRV (AMDGPU_USERQ_SIGNAL , amdgpu_userq_signal_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_USERQ_WAIT , amdgpu_userq_wait_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_GEM_LIST_HANDLES , amdgpu_gem_list_handles_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ), + DRM_IOCTL_DEF_DRV(AMDGPU_RAS, amdgpu_ras_mgr_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
Is this interface for administrators only? If so, you should either remove DRM_RENDER_ALLOW, or check CAP_ADMIN in the IOCTL.
Alex
Quoted 115 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-0};static const struct drm_driver amdgpu_kms_driver = {drivers/gpu/drm/amd/ras/ras_mgr/amdgpu_ras_cmd.c +44
-0@@ -361,3 +361,47 @@ int amdgpu_ras_cmd_ioctl_handler(struct ras_core_context *ras_core,return RAS_CMD__SUCCESS ; } + +static int amdgpu_ras_get_caps (struct amdgpu_device *adev, +struct drm_amdgpu_ras *cmd) +{ +void __user *output_ptr =u64_to_user_ptr (cmd->output_buf_ptr); +struct drm_amdgpu_ras_caps caps; + +memset (&caps,0 ,sizeof (caps)); + +if (adev->smuio.funcs && adev->smuio.funcs->get_socket_id) + caps.oam_id = adev->smuio.funcs->get_socket_id (adev); + +if (output_ptr && (cmd->output_buf_size >=sizeof (caps)) && + !copy_to_user (output_ptr, &caps,sizeof (caps))) +return 0 ; + +return -EINVAL ; +} + +int amdgpu_ras_mgr_ioctl (struct drm_device *dev,void *data, +struct drm_file *filp) +{ +struct amdgpu_device *adev =drm_to_adev (dev); +struct amdgpu_ras_mgr *ras_mgr =amdgpu_ras_mgr_get_context (adev); +struct drm_amdgpu_ras *args = data; +int res =RAS_CMD__ERROR_INVALID_CMD ; + +if (!ras_mgr || !ras_mgr->ras_core || !args) +return -EPERM ; + +if (!ras_core_is_enabled (ras_mgr->ras_core)) +return RAS_CMD__ERROR_ACCESS_DENIED ; + +switch (args->cmd_id) { +case AMDGPU_RAS_CMD_GET_CAPS : + res =amdgpu_ras_get_caps (adev, args); +break ; +default : + res =RAS_CMD__ERROR_UKNOWN_CMD ; +break ; + } + +return res; +}include/uapi/drm/amdgpu_drm.h +32
-1@@ -59,6 +59,9 @@ extern "C" {#define DRM_AMDGPU_USERQ_WAIT 0x18#define DRM_AMDGPU_GEM_LIST_HANDLES 0x19 +/* amdgpu ras ioctls */ +#define DRM_AMDGPU_RAS 0x5d +#define DRM_IOCTL_AMDGPU_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)#define DRM_IOCTL_AMDGPU_GEM_MMAP DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)#define DRM_IOCTL_AMDGPU_CTX DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_CTX, union drm_amdgpu_ctx)@@ -79,6 +82,7 @@ extern "C" {#define DRM_IOCTL_AMDGPU_USERQ_SIGNAL DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_SIGNAL, struct drm_amdgpu_userq_signal)#define DRM_IOCTL_AMDGPU_USERQ_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_WAIT, struct drm_amdgpu_userq_wait)#define DRM_IOCTL_AMDGPU_GEM_LIST_HANDLES DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_LIST_HANDLES, struct drm_amdgpu_gem_list_handles) +#define DRM_IOCTL_AMDGPU_RAS DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_RAS, struct drm_amdgpu_ras)/** * DOC: memory domains @@ -1686,6 +1690,34 @@ struct drm_color_ctm_3x4 {__u64 matrix[12 ]; }; +/* +* Amdgpu ras command id +*/ + +/* Get amdgpu ras capabilities */ +#define AMDGPU_RAS_CMD_GET_CAPS 0x01 + +/* Input structure for amdgpu ras ioctl */ +struct drm_amdgpu_ras { +/* Amdgpu ras version */ +__u32 version; +/* AMDGPU_RAS_CMD_* */ +__u32 cmd_id; +/* Pointer to input parameter buffer */ +__u64 input_buf_ptr; +/* Pointer to output buffer */ +__u64 output_buf_ptr; +/* Output buffer size */ +__u32 output_buf_size; +__u32 pad; +}; + +struct drm_amdgpu_ras_caps { +/* OAM ID */ +__u32 oam_id; +__u32 pad; +}; +#if defined(__cplusplus) }#endif --2.34.1