18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright 2019 Advanced Micro Devices, Inc. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 58c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 68c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation 78c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 88c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 98c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included in 128c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software. 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 158c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 168c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 178c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 188c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 198c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 208c2ecf20Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE. 218c2ecf20Sopenharmony_ci * 228c2ecf20Sopenharmony_ci */ 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci#include "amdgpu.h" 258c2ecf20Sopenharmony_ci#include "amdgpu_ras.h" 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ciint amdgpu_mmhub_ras_late_init(struct amdgpu_device *adev) 288c2ecf20Sopenharmony_ci{ 298c2ecf20Sopenharmony_ci int r; 308c2ecf20Sopenharmony_ci struct ras_ih_if ih_info = { 318c2ecf20Sopenharmony_ci .cb = NULL, 328c2ecf20Sopenharmony_ci }; 338c2ecf20Sopenharmony_ci struct ras_fs_if fs_info = { 348c2ecf20Sopenharmony_ci .sysfs_name = "mmhub_err_count", 358c2ecf20Sopenharmony_ci }; 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci if (!adev->mmhub.ras_if) { 388c2ecf20Sopenharmony_ci adev->mmhub.ras_if = kmalloc(sizeof(struct ras_common_if), GFP_KERNEL); 398c2ecf20Sopenharmony_ci if (!adev->mmhub.ras_if) 408c2ecf20Sopenharmony_ci return -ENOMEM; 418c2ecf20Sopenharmony_ci adev->mmhub.ras_if->block = AMDGPU_RAS_BLOCK__MMHUB; 428c2ecf20Sopenharmony_ci adev->mmhub.ras_if->type = AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE; 438c2ecf20Sopenharmony_ci adev->mmhub.ras_if->sub_block_index = 0; 448c2ecf20Sopenharmony_ci strcpy(adev->mmhub.ras_if->name, "mmhub"); 458c2ecf20Sopenharmony_ci } 468c2ecf20Sopenharmony_ci ih_info.head = fs_info.head = *adev->mmhub.ras_if; 478c2ecf20Sopenharmony_ci r = amdgpu_ras_late_init(adev, adev->mmhub.ras_if, 488c2ecf20Sopenharmony_ci &fs_info, &ih_info); 498c2ecf20Sopenharmony_ci if (r || !amdgpu_ras_is_supported(adev, adev->mmhub.ras_if->block)) { 508c2ecf20Sopenharmony_ci kfree(adev->mmhub.ras_if); 518c2ecf20Sopenharmony_ci adev->mmhub.ras_if = NULL; 528c2ecf20Sopenharmony_ci } 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci return r; 558c2ecf20Sopenharmony_ci} 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_civoid amdgpu_mmhub_ras_fini(struct amdgpu_device *adev) 588c2ecf20Sopenharmony_ci{ 598c2ecf20Sopenharmony_ci if (amdgpu_ras_is_supported(adev, AMDGPU_RAS_BLOCK__MMHUB) && 608c2ecf20Sopenharmony_ci adev->mmhub.ras_if) { 618c2ecf20Sopenharmony_ci struct ras_common_if *ras_if = adev->mmhub.ras_if; 628c2ecf20Sopenharmony_ci struct ras_ih_if ih_info = { 638c2ecf20Sopenharmony_ci .cb = NULL, 648c2ecf20Sopenharmony_ci }; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci amdgpu_ras_late_fini(adev, ras_if, &ih_info); 678c2ecf20Sopenharmony_ci kfree(ras_if); 688c2ecf20Sopenharmony_ci } 698c2ecf20Sopenharmony_ci} 70