Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

drm/amdgpu: Add reset control to amdgpu_device

v1: Add generic amdgpu_reset_control to handle different types of resets. It
may be added at device, hive or ip level. Each reset control has a list
of handlers associated with it to handle different types of reset. Reset
control is responsible for choosing the right handler given a particular
reset context.

Handler objects may implement a set of functions on how to handle a
particular type of reset.

prepare_env = Prepare environment/software context (not used currently).
prepare_hwcontext = Prepare hardware context for the reset.
perform_reset = Perform the type of reset.
restore_hwcontext = Restore the hw context after reset.
restore_env = Restore the environment after reset (not used currently).

Reset context carries the context of reset, as of now this is based on
the parameters used for current set of resets.

v2: Fix coding style

Signed-off-by: Lijo Lazar <lijo.lazar@amd.com>
Reviewed-by: Feifei Xu <Feifei.Xu@amd.com>
Reviewed-by: Hawking Zhang <Hawking.Zhang@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Lijo Lazar and committed by
Alex Deucher
e071dce3 c941e9fe

+175
+5
drivers/gpu/drm/amd/amdgpu/Makefile
··· 179 179 smuio_v11_0_6.o \ 180 180 smuio_v13_0.o 181 181 182 + # add reset block 183 + amdgpu-y += \ 184 + amdgpu_reset.o 185 + 182 186 # add amdkfd interfaces 183 187 amdgpu-y += amdgpu_amdkfd.o 188 + 184 189 185 190 ifneq ($(CONFIG_HSA_AMD),) 186 191 AMDKFD_PATH := ../amdkfd
+3
drivers/gpu/drm/amd/amdgpu/amdgpu.h
··· 270 270 struct amdgpu_atif; 271 271 struct kfd_vm_fault_info; 272 272 struct amdgpu_hive_info; 273 + struct amdgpu_reset_control; 273 274 274 275 enum amdgpu_cp_irq { 275 276 AMDGPU_CP_IRQ_GFX_ME0_PIPE0_EOP = 0, ··· 589 588 }; 590 589 591 590 enum amd_reset_method { 591 + AMD_RESET_METHOD_NONE = -1, 592 592 AMD_RESET_METHOD_LEGACY = 0, 593 593 AMD_RESET_METHOD_MODE0, 594 594 AMD_RESET_METHOD_MODE1, ··· 1075 1073 1076 1074 bool in_pci_err_recovery; 1077 1075 struct pci_saved_state *pci_state; 1076 + struct amdgpu_reset_control *reset_cntl; 1078 1077 }; 1079 1078 1080 1079 static inline struct amdgpu_device *drm_to_adev(struct drm_device *ddev)
+82
drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c
··· 1 + /* 2 + * Copyright 2021 Advanced Micro Devices, Inc. 3 + * 4 + * Permission is hereby granted, free of charge, to any person obtaining a 5 + * copy of this software and associated documentation files (the "Software"), 6 + * to deal in the Software without restriction, including without limitation 7 + * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 + * and/or sell copies of the Software, and to permit persons to whom the 9 + * Software is furnished to do so, subject to the following conditions: 10 + * 11 + * The above copyright notice and this permission notice shall be included in 12 + * all copies or substantial portions of the Software. 13 + * 14 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 + * OTHER DEALINGS IN THE SOFTWARE. 21 + * 22 + */ 23 + 24 + #include "amdgpu_reset.h" 25 + #include "aldebaran.h" 26 + 27 + int amdgpu_reset_add_handler(struct amdgpu_reset_control *reset_ctl, 28 + struct amdgpu_reset_handler *handler) 29 + { 30 + /* TODO: Check if handler exists? */ 31 + list_add_tail(&handler->handler_list, &reset_ctl->reset_handlers); 32 + return 0; 33 + } 34 + 35 + int amdgpu_reset_init(struct amdgpu_device *adev) 36 + { 37 + int ret = 0; 38 + 39 + return ret; 40 + } 41 + 42 + int amdgpu_reset_fini(struct amdgpu_device *adev) 43 + { 44 + int ret = 0; 45 + 46 + return ret; 47 + } 48 + 49 + int amdgpu_reset_prepare_hwcontext(struct amdgpu_device *adev, 50 + struct amdgpu_reset_context *reset_context) 51 + { 52 + struct amdgpu_reset_handler *reset_handler = NULL; 53 + 54 + if (adev->reset_cntl && adev->reset_cntl->get_reset_handler) 55 + reset_handler = adev->reset_cntl->get_reset_handler( 56 + adev->reset_cntl, reset_context); 57 + if (!reset_handler) 58 + return -ENOSYS; 59 + 60 + return reset_handler->prepare_hwcontext(adev->reset_cntl, 61 + reset_context); 62 + } 63 + 64 + int amdgpu_reset_perform_reset(struct amdgpu_device *adev, 65 + struct amdgpu_reset_context *reset_context) 66 + { 67 + int ret; 68 + struct amdgpu_reset_handler *reset_handler = NULL; 69 + 70 + if (adev->reset_cntl) 71 + reset_handler = adev->reset_cntl->get_reset_handler( 72 + adev->reset_cntl, reset_context); 73 + if (!reset_handler) 74 + return -ENOSYS; 75 + 76 + ret = reset_handler->perform_reset(adev->reset_cntl, reset_context); 77 + if (ret) 78 + return ret; 79 + 80 + return reset_handler->restore_hwcontext(adev->reset_cntl, 81 + reset_context); 82 + }
+85
drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h
··· 1 + /* 2 + * Copyright 2021 Advanced Micro Devices, Inc. 3 + * 4 + * Permission is hereby granted, free of charge, to any person obtaining a 5 + * copy of this software and associated documentation files (the "Software"), 6 + * to deal in the Software without restriction, including without limitation 7 + * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 + * and/or sell copies of the Software, and to permit persons to whom the 9 + * Software is furnished to do so, subject to the following conditions: 10 + * 11 + * The above copyright notice and this permission notice shall be included in 12 + * all copies or substantial portions of the Software. 13 + * 14 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 + * OTHER DEALINGS IN THE SOFTWARE. 21 + * 22 + */ 23 + 24 + #ifndef __AMDUGPU_RESET_H__ 25 + #define __AMDGPU_RESET_H__ 26 + 27 + #include "amdgpu.h" 28 + 29 + enum AMDGPU_RESET_FLAGS { 30 + 31 + AMDGPU_NEED_FULL_RESET = 0, 32 + AMDGPU_SKIP_HW_RESET = 1, 33 + }; 34 + 35 + struct amdgpu_reset_context { 36 + enum amd_reset_method method; 37 + struct amdgpu_device *reset_req_dev; 38 + struct amdgpu_job *job; 39 + struct amdgpu_hive_info *hive; 40 + unsigned long flags; 41 + }; 42 + 43 + struct amdgpu_reset_handler { 44 + enum amd_reset_method reset_method; 45 + struct list_head handler_list; 46 + int (*prepare_env)(struct amdgpu_reset_control *reset_ctl, 47 + struct amdgpu_reset_context *context); 48 + int (*prepare_hwcontext)(struct amdgpu_reset_control *reset_ctl, 49 + struct amdgpu_reset_context *context); 50 + int (*perform_reset)(struct amdgpu_reset_control *reset_ctl, 51 + struct amdgpu_reset_context *context); 52 + int (*restore_hwcontext)(struct amdgpu_reset_control *reset_ctl, 53 + struct amdgpu_reset_context *context); 54 + int (*restore_env)(struct amdgpu_reset_control *reset_ctl, 55 + struct amdgpu_reset_context *context); 56 + 57 + int (*do_reset)(struct amdgpu_device *adev); 58 + }; 59 + 60 + struct amdgpu_reset_control { 61 + void *handle; 62 + struct work_struct reset_work; 63 + struct mutex reset_lock; 64 + struct list_head reset_handlers; 65 + atomic_t in_reset; 66 + enum amd_reset_method active_reset; 67 + struct amdgpu_reset_handler *(*get_reset_handler)( 68 + struct amdgpu_reset_control *reset_ctl, 69 + struct amdgpu_reset_context *context); 70 + void (*async_reset)(struct work_struct *work); 71 + }; 72 + 73 + int amdgpu_reset_init(struct amdgpu_device *adev); 74 + int amdgpu_reset_fini(struct amdgpu_device *adev); 75 + 76 + int amdgpu_reset_prepare_hwcontext(struct amdgpu_device *adev, 77 + struct amdgpu_reset_context *reset_context); 78 + 79 + int amdgpu_reset_perform_reset(struct amdgpu_device *adev, 80 + struct amdgpu_reset_context *reset_context); 81 + 82 + int amdgpu_reset_add_handler(struct amdgpu_reset_control *reset_ctl, 83 + struct amdgpu_reset_handler *handler); 84 + 85 + #endif