xref: /aosp_15_r20/external/igt-gpu-tools/lib/igt_debugfs.h (revision d83cc019efdc2edc6c4b16e9034a3ceb8d35d77c)
1 /*
2  * Copyright © 2013 Intel Corporation
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 (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  *
23  */
24 
25 #ifndef __IGT_DEBUGFS_H__
26 #define __IGT_DEBUGFS_H__
27 
28 #include <stdbool.h>
29 #include <stdint.h>
30 #include <stdio.h>
31 
32 enum pipe
33 #ifdef __cplusplus
34 : int
35 #endif
36 ;
37 
38 const char *igt_debugfs_mount(void);
39 char *igt_debugfs_path(int device, char *path, int pathlen);
40 
41 int igt_debugfs_dir(int device);
42 int igt_debugfs_connector_dir(int device, char *conn_name, int mode);
43 
44 int igt_debugfs_open(int fd, const char *filename, int mode);
45 void __igt_debugfs_read(int fd, const char *filename, char *buf, int size);
46 int igt_debugfs_simple_read(int dir, const char *filename, char *buf, int size);
47 bool igt_debugfs_search(int fd, const char *filename, const char *substring);
48 
49 /**
50  * igt_debugfs_read:
51  * @filename: name of the debugfs file
52  * @buf: buffer where the contents will be stored, allocated by the caller.
53  *
54  * This is just a convenience wrapper for __igt_debugfs_read. See its
55  * documentation.
56  */
57 #define igt_debugfs_read(fd, filename, buf) \
58 		__igt_debugfs_read(fd, (filename), (buf), sizeof(buf))
59 
60 /*
61  * Pipe CRC
62  */
63 
64 /**
65  * igt_pipe_crc_t:
66  *
67  * Pipe CRC support structure. Needs to be allocated and set up with
68  * igt_pipe_crc_new() for a specific pipe and pipe CRC source value.
69  */
70 typedef struct _igt_pipe_crc igt_pipe_crc_t;
71 
72 #define DRM_MAX_CRC_NR 10
73 /**
74  * igt_crc_t:
75  * @frame: frame number of the capture CRC
76  * @n_words: internal field, don't access
77  * @crc: internal field, don't access
78  *
79  * Pipe CRC value. All other members than @frame are private and should not be
80  * inspected by testcases.
81  */
82 typedef struct {
83 	uint32_t frame;
84 	bool has_valid_frame;
85 	int n_words;
86 	uint32_t crc[DRM_MAX_CRC_NR];
87 } igt_crc_t;
88 
89 #define INTEL_PIPE_CRC_SOURCE_AUTO "auto"
90 #define AMDGPU_PIPE_CRC_SOURCE_DPRX "dprx"
91 
92 void igt_assert_crc_equal(const igt_crc_t *a, const igt_crc_t *b);
93 bool igt_check_crc_equal(const igt_crc_t *a, const igt_crc_t *b);
94 char *igt_crc_to_string_extended(igt_crc_t *crc, char delimiter, int crc_size);
95 char *igt_crc_to_string(igt_crc_t *crc);
96 
97 void igt_require_pipe_crc(int fd);
98 igt_pipe_crc_t *
99 igt_pipe_crc_new(int fd, enum pipe pipe, const char *source);
100 igt_pipe_crc_t *
101 igt_pipe_crc_new_nonblock(int fd, enum pipe pipe, const char *source);
102 void igt_pipe_crc_free(igt_pipe_crc_t *pipe_crc);
103 void igt_pipe_crc_start(igt_pipe_crc_t *pipe_crc);
104 void igt_pipe_crc_stop(igt_pipe_crc_t *pipe_crc);
105 __attribute__((warn_unused_result))
106 int igt_pipe_crc_get_crcs(igt_pipe_crc_t *pipe_crc, int n_crcs,
107 			  igt_crc_t **out_crcs);
108 void igt_pipe_crc_drain(igt_pipe_crc_t *pipe_crc);
109 void igt_pipe_crc_get_single(igt_pipe_crc_t *pipe_crc, igt_crc_t *out_crc);
110 void igt_pipe_crc_get_current(int drm_fd, igt_pipe_crc_t *pipe_crc, igt_crc_t *crc);
111 
112 void igt_pipe_crc_collect_crc(igt_pipe_crc_t *pipe_crc, igt_crc_t *out_crc);
113 
114 void igt_hpd_storm_set_threshold(int fd, unsigned int threshold);
115 void igt_hpd_storm_reset(int fd);
116 bool igt_hpd_storm_detected(int fd);
117 void igt_require_hpd_storm_ctl(int fd);
118 
119 /*
120  * Drop caches
121  */
122 
123 /**
124  * DROP_UNBOUND:
125  *
126  * Drop all currently unbound gem buffer objects from the cache.
127  */
128 #define DROP_UNBOUND 0x1
129 /**
130  * DROP_BOUND:
131  *
132  * Drop all inactive objects which are bound into some gpu address space.
133  */
134 #define DROP_BOUND 0x2
135 /**
136  * DROP_RETIRE:
137  *
138  * Wait for all outstanding gpu commands to complete, but do not take any
139  * further actions.
140  */
141 #define DROP_RETIRE 0x4
142 /**
143  * DROP_ACTIVE:
144  *
145  * Also drop active objects once retired.
146  */
147 #define DROP_ACTIVE 0x8
148 /**
149  * DROP_FREED:
150  *
151  * Also drop freed objects.
152  */
153 #define DROP_FREED 0x10
154 /**
155  * DROP_SHRINK_ALL:
156  *
157  * Force all unpinned buffers to be evicted from their GTT and returned to the
158  * system.
159  */
160 #define DROP_SHRINK_ALL 0x20
161 /**
162  * DROP_IDLE:
163  *
164  * Flush the driver's idle_worker, releasing internal caches and wakerefs.
165  */
166 #define DROP_IDLE 0x40
167 /**
168  * DROP_RESET_ACTIVE:
169  *
170  * Cancel all outstanding requests by forcing a gpu reset
171  */
172 #define DROP_RESET_ACTIVE 0x80
173 /**
174  * DROP_RESET_SEQNO:
175  *
176  * Reset the global request seqno counter back to 0
177  */
178 #define DROP_RESET_SEQNO 0x100
179 /**
180  * DROP_ALL:
181  *
182  * All of the above DROP_ flags combined.
183  */
184 #define DROP_ALL (DROP_UNBOUND | \
185 		  DROP_BOUND | \
186 		  DROP_SHRINK_ALL | \
187 		  DROP_RETIRE | \
188 		  DROP_ACTIVE | \
189 		  DROP_FREED | \
190 		  DROP_IDLE)
191 
192 void igt_reset_fifo_underrun_reporting(int drm_fd);
193 
194 bool igt_drop_caches_has(int fd, uint64_t val);
195 void igt_drop_caches_set(int fd, uint64_t val);
196 
197 /*
198  * Prefault control
199  */
200 
201 void igt_disable_prefault(void);
202 void igt_enable_prefault(void);
203 
204 /*
205  * Put the driver into a stable (quiescent) state and get the current number of
206  * gem buffer objects
207  */
208 int igt_get_stable_obj_count(int driver);
209 void __igt_debugfs_dump(int device, const char *filename, int level);
210 #define igt_debugfs_dump(d, f) __igt_debugfs_dump(d, f, IGT_LOG_DEBUG)
211 
212 #endif /* __IGT_DEBUGFS_H__ */
213