xref: /linux/include/drm/drm_ras.h (revision 056e065a6b6e01ab54bb9770c0d5a15350e571e2)
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright © 2026 Intel Corporation
4  */
5 
6 #ifndef __DRM_RAS_H__
7 #define __DRM_RAS_H__
8 
9 #include <uapi/drm/drm_ras.h>
10 
11 /**
12  * struct drm_ras_node - A DRM RAS Node
13  */
14 struct drm_ras_node {
15 	/** @id: Unique identifier for the node. Dynamically assigned. */
16 	u32 id;
17 	/**
18 	 * @device_name: Human-readable name of the device. Given by the driver.
19 	 */
20 	const char *device_name;
21 	/** @node_name: Human-readable name of the node. Given by the driver. */
22 	const char *node_name;
23 	/** @type: Type of the node (enum drm_ras_node_type). */
24 	enum drm_ras_node_type type;
25 
26 	/* Error-Counter Related Callback and Variables */
27 
28 	/** @error_counter_range: Range of valid Error IDs for this node. */
29 	struct {
30 		/** @first: First valid Error ID. */
31 		u32 first;
32 		/** @last: Last valid Error ID. Mandatory entry. */
33 		u32 last;
34 	} error_counter_range;
35 
36 	/**
37 	 * @query_error_counter:
38 	 *
39 	 * This callback is used by drm-ras to query a specific error counter.
40 	 * Used for input check and to iterate all error counters in a node.
41 	 *
42 	 * Driver should expect query_error_counter() to be called with
43 	 * error_id from `error_counter_range.first` to
44 	 * `error_counter_range.last`.
45 	 *
46 	 * The @query_error_counter is a mandatory callback for
47 	 * error_counter_node.
48 	 *
49 	 * Returns: 0 on success,
50 	 *          -ENOENT when error_id is not supported as an indication that
51 	 *                  drm_ras should silently skip this entry. Used for
52 	 *                  supporting non-contiguous error ranges.
53 	 *                  Driver is responsible for maintaining the list of
54 	 *                  supported error IDs in the range of first to last.
55 	 *          Other negative values on errors that should terminate the
56 	 *          netlink query.
57 	 */
58 	int (*query_error_counter)(struct drm_ras_node *node, u32 error_id,
59 				   const char **name, u32 *val);
60 
61 	/**
62 	 * @clear_error_counter:
63 	 *
64 	 * This callback is used by drm_ras to clear a specific error counter.
65 	 * Driver should implement this callback to support clearing error counters
66 	 * of a node.
67 	 *
68 	 * Returns: 0 on success, negative error code on failure.
69 	 */
70 	int (*clear_error_counter)(struct drm_ras_node *node, u32 error_id);
71 
72 	/** @priv: Driver private data */
73 	void *priv;
74 };
75 
76 struct drm_device;
77 
78 #if IS_ENABLED(CONFIG_DRM_RAS)
79 int drm_ras_node_register(struct drm_ras_node *node);
80 void drm_ras_node_unregister(struct drm_ras_node *node);
81 #else
82 static inline int drm_ras_node_register(struct drm_ras_node *node) { return 0; }
83 static inline void drm_ras_node_unregister(struct drm_ras_node *node) { }
84 #endif
85 
86 #endif
87