xref: /netbsd-src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_mmhub.c (revision 41ec02673d281bbb3d38e6c78504ce6e30c228c1)
1 /*	$NetBSD: amdgpu_mmhub.c,v 1.2 2021/12/18 23:44:58 riastradh Exp $	*/
2 
3 /*
4  * Copyright 2019 Advanced Micro Devices, Inc.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22  * OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */
25 
26 #include <sys/cdefs.h>
27 __KERNEL_RCSID(0, "$NetBSD: amdgpu_mmhub.c,v 1.2 2021/12/18 23:44:58 riastradh Exp $");
28 
29 #include "amdgpu.h"
30 #include "amdgpu_ras.h"
31 
amdgpu_mmhub_ras_late_init(struct amdgpu_device * adev)32 int amdgpu_mmhub_ras_late_init(struct amdgpu_device *adev)
33 {
34 	int r;
35 	struct ras_ih_if ih_info = {
36 		.cb = NULL,
37 	};
38 	struct ras_fs_if fs_info = {
39 		.sysfs_name = "mmhub_err_count",
40 		.debugfs_name = "mmhub_err_inject",
41 	};
42 
43 	if (!adev->mmhub.ras_if) {
44 		adev->mmhub.ras_if = kmalloc(sizeof(struct ras_common_if), GFP_KERNEL);
45 		if (!adev->mmhub.ras_if)
46 			return -ENOMEM;
47 		adev->mmhub.ras_if->block = AMDGPU_RAS_BLOCK__MMHUB;
48 		adev->mmhub.ras_if->type = AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE;
49 		adev->mmhub.ras_if->sub_block_index = 0;
50 		strcpy(adev->mmhub.ras_if->name, "mmhub");
51 	}
52 	ih_info.head = fs_info.head = *adev->mmhub.ras_if;
53 	r = amdgpu_ras_late_init(adev, adev->mmhub.ras_if,
54 				 &fs_info, &ih_info);
55 	if (r || !amdgpu_ras_is_supported(adev, adev->mmhub.ras_if->block)) {
56 		kfree(adev->mmhub.ras_if);
57 		adev->mmhub.ras_if = NULL;
58 	}
59 
60 	return r;
61 }
62 
amdgpu_mmhub_ras_fini(struct amdgpu_device * adev)63 void amdgpu_mmhub_ras_fini(struct amdgpu_device *adev)
64 {
65 	if (amdgpu_ras_is_supported(adev, AMDGPU_RAS_BLOCK__MMHUB) &&
66 			adev->mmhub.ras_if) {
67 		struct ras_common_if *ras_if = adev->mmhub.ras_if;
68 		struct ras_ih_if ih_info = {
69 			.cb = NULL,
70 		};
71 
72 		amdgpu_ras_late_fini(adev, ras_if, &ih_info);
73 		kfree(ras_if);
74 	}
75 }
76