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 <linux/types.h> 10 11 #include <uapi/drm/drm_ras.h> 12 13 /** 14 * struct drm_ras_node - A DRM RAS Node 15 */ 16 struct drm_ras_node { 17 /** @id: Unique identifier for the node. Dynamically assigned. */ 18 u32 id; 19 /** 20 * @device_name: Human-readable name of the device. Given by the driver. 21 */ 22 const char *device_name; 23 /** @node_name: Human-readable name of the node. Given by the driver. */ 24 const char *node_name; 25 /** @type: Type of the node (enum drm_ras_node_type). */ 26 enum drm_ras_node_type type; 27 28 /* Error-Counter Related Callback and Variables */ 29 30 /** @error_counter_range: Range of valid Error IDs for this node. */ 31 struct { 32 /** @first: First valid Error ID. */ 33 u32 first; 34 /** @last: Last valid Error ID. Mandatory entry. */ 35 u32 last; 36 } error_counter_range; 37 38 /** 39 * @query_error_counter: 40 * 41 * This callback is used by drm-ras to query a specific error counter. 42 * Used for input check and to iterate all error counters in a node. 43 * 44 * Driver should expect query_error_counter() to be called with 45 * error_id from `error_counter_range.first` to 46 * `error_counter_range.last`. 47 * 48 * The @query_error_counter is a mandatory callback for 49 * error_counter_node. 50 * 51 * Returns: 0 on success, 52 * -ENOENT when error_id is not supported as an indication that 53 * drm_ras should silently skip this entry. Used for 54 * supporting non-contiguous error ranges. 55 * Driver is responsible for maintaining the list of 56 * supported error IDs in the range of first to last. 57 * Other negative values on errors that should terminate the 58 * netlink query. 59 */ 60 int (*query_error_counter)(struct drm_ras_node *node, u32 error_id, 61 const char **name, u32 *val); 62 63 /** 64 * @clear_error_counter: 65 * 66 * This callback is used by drm_ras to clear a specific error counter. 67 * Driver should implement this callback to support clearing error counters 68 * of a node. 69 * 70 * Returns: 0 on success, negative error code on failure. 71 */ 72 int (*clear_error_counter)(struct drm_ras_node *node, u32 error_id); 73 74 /** 75 * @query_error_threshold: 76 * 77 * This callback is used by drm-ras to query error threshold of a 78 * specific counter. 79 * 80 * Driver should expect query_error_threshold() to be called with 81 * error_id from `error_counter_range.first` to 82 * `error_counter_range.last`. 83 * 84 * Returns: 0 on success, negative error code on failure. 85 */ 86 int (*query_error_threshold)(struct drm_ras_node *node, u32 error_id, const char **name, 87 u32 *threshold); 88 89 /** 90 * @set_error_threshold: 91 * 92 * This callback is used by drm-ras to set error threshold of a specific 93 * counter. 94 * 95 * Driver should expect set_error_threshold() to be called with error_id 96 * from `error_counter_range.first` to `error_counter_range.last`. 97 * Driver is responsible for error threshold bounds checking. 98 * 99 * Returns: 0 on success, negative error code on failure. 100 */ 101 int (*set_error_threshold)(struct drm_ras_node *node, u32 error_id, u32 threshold); 102 103 /** @priv: Driver private data */ 104 void *priv; 105 }; 106 107 struct drm_device; 108 109 #if IS_ENABLED(CONFIG_DRM_RAS) 110 int drm_ras_node_register(struct drm_ras_node *node); 111 void drm_ras_node_unregister(struct drm_ras_node *node); 112 int drm_ras_nl_error_event(struct drm_ras_node *node, u32 error_id, const char *error_name, 113 u32 value); 114 #else 115 static inline int drm_ras_node_register(struct drm_ras_node *node) { return 0; } 116 static inline void drm_ras_node_unregister(struct drm_ras_node *node) { } 117 static inline int drm_ras_nl_error_event(struct drm_ras_node *node, u32 error_id, 118 const char *error_name, u32 value) 119 { return 0; } 120 #endif 121 122 #endif 123