Bug Summary

File:dev/pci/drm/i915/gt/uc/intel_guc_log.c
Warning:line 42, column 27
Value stored to 'i915' during its initialization is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.4 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name intel_guc_log.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -ffp-contract=on -fno-rounding-math -mconstructor-aliases -ffreestanding -mcmodel=kernel -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -target-feature -sse2 -target-feature -sse -target-feature -3dnow -target-feature -mmx -target-feature +save-args -target-feature +retpoline-external-thunk -disable-red-zone -no-implicit-float -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/sys/arch/amd64/compile/GENERIC.MP/obj -nostdsysteminc -nobuiltininc -resource-dir /usr/local/llvm16/lib/clang/16 -I /usr/src/sys -I /usr/src/sys/arch/amd64/compile/GENERIC.MP/obj -I /usr/src/sys/arch -I /usr/src/sys/dev/pci/drm/include -I /usr/src/sys/dev/pci/drm/include/uapi -I /usr/src/sys/dev/pci/drm/amd/include/asic_reg -I /usr/src/sys/dev/pci/drm/amd/include -I /usr/src/sys/dev/pci/drm/amd/amdgpu -I /usr/src/sys/dev/pci/drm/amd/display -I /usr/src/sys/dev/pci/drm/amd/display/include -I /usr/src/sys/dev/pci/drm/amd/display/dc -I /usr/src/sys/dev/pci/drm/amd/display/amdgpu_dm -I /usr/src/sys/dev/pci/drm/amd/pm/inc -I /usr/src/sys/dev/pci/drm/amd/pm/legacy-dpm -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu/inc -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu/smu11 -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu/smu12 -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu/smu13 -I /usr/src/sys/dev/pci/drm/amd/pm/powerplay/inc -I /usr/src/sys/dev/pci/drm/amd/pm/powerplay/hwmgr -I /usr/src/sys/dev/pci/drm/amd/pm/powerplay/smumgr -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu/inc -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu/inc/pmfw_if -I /usr/src/sys/dev/pci/drm/amd/display/dc/inc -I /usr/src/sys/dev/pci/drm/amd/display/dc/inc/hw -I /usr/src/sys/dev/pci/drm/amd/display/dc/clk_mgr -I /usr/src/sys/dev/pci/drm/amd/display/modules/inc -I /usr/src/sys/dev/pci/drm/amd/display/modules/hdcp -I /usr/src/sys/dev/pci/drm/amd/display/dmub/inc -I /usr/src/sys/dev/pci/drm/i915 -D DDB -D DIAGNOSTIC -D KTRACE -D ACCOUNTING -D KMEMSTATS -D PTRACE -D POOL_DEBUG -D CRYPTO -D SYSVMSG -D SYSVSEM -D SYSVSHM -D UVM_SWAP_ENCRYPT -D FFS -D FFS2 -D FFS_SOFTUPDATES -D UFS_DIRHASH -D QUOTA -D EXT2FS -D MFS -D NFSCLIENT -D NFSSERVER -D CD9660 -D UDF -D MSDOSFS -D FIFO -D FUSE -D SOCKET_SPLICE -D TCP_ECN -D TCP_SIGNATURE -D INET6 -D IPSEC -D PPP_BSDCOMP -D PPP_DEFLATE -D PIPEX -D MROUTING -D MPLS -D BOOT_CONFIG -D USER_PCICONF -D APERTURE -D MTRR -D NTFS -D SUSPEND -D HIBERNATE -D PCIVERBOSE -D USBVERBOSE -D WSDISPLAY_COMPAT_USL -D WSDISPLAY_COMPAT_RAWKBD -D WSDISPLAY_DEFAULTSCREENS=6 -D X86EMU -D ONEWIREVERBOSE -D MULTIPROCESSOR -D MAXUSERS=80 -D _KERNEL -O2 -Wno-pointer-sign -Wno-address-of-packed-member -Wno-constant-conversion -Wno-unused-but-set-variable -Wno-gnu-folding-constant -fdebug-compilation-dir=/usr/src/sys/arch/amd64/compile/GENERIC.MP/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fcf-protection=branch -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -o /home/ben/Projects/scan/2024-01-11-110808-61670-1 -x c /usr/src/sys/dev/pci/drm/i915/gt/uc/intel_guc_log.c
1// SPDX-License-Identifier: MIT
2/*
3 * Copyright © 2014-2019 Intel Corporation
4 */
5
6#include <linux/debugfs.h>
7#include <linux/string_helpers.h>
8
9#include "gt/intel_gt.h"
10#include "i915_drv.h"
11#include "i915_irq.h"
12#include "i915_memcpy.h"
13#include "intel_guc_capture.h"
14#include "intel_guc_log.h"
15
16#if defined(CONFIG_DRM_I915_DEBUG_GUC)
17#define GUC_LOG_DEFAULT_CRASH_BUFFER_SIZE(8 << 10) SZ_2M(2 << 20)
18#define GUC_LOG_DEFAULT_DEBUG_BUFFER_SIZE(64 << 10) SZ_16M(16 << 20)
19#define GUC_LOG_DEFAULT_CAPTURE_BUFFER_SIZE(1 << 20) SZ_1M(1 << 20)
20#elif defined(CONFIG_DRM_I915_DEBUG_GEM)
21#define GUC_LOG_DEFAULT_CRASH_BUFFER_SIZE(8 << 10) SZ_1M(1 << 20)
22#define GUC_LOG_DEFAULT_DEBUG_BUFFER_SIZE(64 << 10) SZ_2M(2 << 20)
23#define GUC_LOG_DEFAULT_CAPTURE_BUFFER_SIZE(1 << 20) SZ_1M(1 << 20)
24#else
25#define GUC_LOG_DEFAULT_CRASH_BUFFER_SIZE(8 << 10) SZ_8K(8 << 10)
26#define GUC_LOG_DEFAULT_DEBUG_BUFFER_SIZE(64 << 10) SZ_64K(64 << 10)
27#define GUC_LOG_DEFAULT_CAPTURE_BUFFER_SIZE(1 << 20) SZ_1M(1 << 20)
28#endif
29
30static void guc_log_copy_debuglogs_for_relay(struct intel_guc_log *log);
31
32struct guc_log_section {
33 u32 max;
34 u32 flag;
35 u32 default_val;
36 const char *name;
37};
38
39static void _guc_log_init_sizes(struct intel_guc_log *log)
40{
41 struct intel_guc *guc = log_to_guc(log);
42 struct drm_i915_privateinteldrm_softc *i915 = guc_to_gt(guc)->i915;
Value stored to 'i915' during its initialization is never read
43 static const struct guc_log_section sections[GUC_LOG_SECTIONS_LIMIT] = {
44 {
45 GUC_LOG_CRASH_MASK(0x3 << 4) >> GUC_LOG_CRASH_SHIFT4,
46 GUC_LOG_LOG_ALLOC_UNITS(1UL << (3)),
47 GUC_LOG_DEFAULT_CRASH_BUFFER_SIZE(8 << 10),
48 "crash dump"
49 },
50 {
51 GUC_LOG_DEBUG_MASK(0xF << 6) >> GUC_LOG_DEBUG_SHIFT6,
52 GUC_LOG_LOG_ALLOC_UNITS(1UL << (3)),
53 GUC_LOG_DEFAULT_DEBUG_BUFFER_SIZE(64 << 10),
54 "debug",
55 },
56 {
57 GUC_LOG_CAPTURE_MASK(0x3 << 10) >> GUC_LOG_CAPTURE_SHIFT10,
58 GUC_LOG_CAPTURE_ALLOC_UNITS(1UL << (2)),
59 GUC_LOG_DEFAULT_CAPTURE_BUFFER_SIZE(1 << 20),
60 "capture",
61 }
62 };
63 int i;
64
65 for (i = 0; i < GUC_LOG_SECTIONS_LIMIT; i++)
66 log->sizes[i].bytes = sections[i].default_val;
67
68 /* If debug size > 1MB then bump default crash size to keep the same units */
69 if (log->sizes[GUC_LOG_SECTIONS_DEBUG].bytes >= SZ_1M(1 << 20) &&
70 GUC_LOG_DEFAULT_CRASH_BUFFER_SIZE(8 << 10) < SZ_1M(1 << 20))
71 log->sizes[GUC_LOG_SECTIONS_CRASH].bytes = SZ_1M(1 << 20);
72
73 /* Prepare the GuC API structure fields: */
74 for (i = 0; i < GUC_LOG_SECTIONS_LIMIT; i++) {
75 /* Convert to correct units */
76 if ((log->sizes[i].bytes % SZ_1M(1 << 20)) == 0) {
77 log->sizes[i].units = SZ_1M(1 << 20);
78 log->sizes[i].flag = sections[i].flag;
79 } else {
80 log->sizes[i].units = SZ_4K(4 << 10);
81 log->sizes[i].flag = 0;
82 }
83
84 if (!IS_ALIGNED(log->sizes[i].bytes, log->sizes[i].units)(((log->sizes[i].bytes) & ((log->sizes[i].units) - 1
)) == 0)
)
85 drm_err(&i915->drm, "Mis-aligned GuC log %s size: 0x%X vs 0x%X!",printf("drm:pid%d:%s *ERROR* " "[drm] " "*ERROR* " "Mis-aligned GuC log %s size: 0x%X vs 0x%X!"
, ({struct cpu_info *__ci; asm volatile("movq %%gs:%P1,%0" : "=r"
(__ci) :"n" (__builtin_offsetof(struct cpu_info, ci_self)));
__ci;})->ci_curproc->p_p->ps_pid, __func__ , sections
[i].name, log->sizes[i].bytes, log->sizes[i].units)
86 sections[i].name, log->sizes[i].bytes, log->sizes[i].units)printf("drm:pid%d:%s *ERROR* " "[drm] " "*ERROR* " "Mis-aligned GuC log %s size: 0x%X vs 0x%X!"
, ({struct cpu_info *__ci; asm volatile("movq %%gs:%P1,%0" : "=r"
(__ci) :"n" (__builtin_offsetof(struct cpu_info, ci_self)));
__ci;})->ci_curproc->p_p->ps_pid, __func__ , sections
[i].name, log->sizes[i].bytes, log->sizes[i].units)
;
87 log->sizes[i].count = log->sizes[i].bytes / log->sizes[i].units;
88
89 if (!log->sizes[i].count) {
90 drm_err(&i915->drm, "Zero GuC log %s size!", sections[i].name)printf("drm:pid%d:%s *ERROR* " "[drm] " "*ERROR* " "Zero GuC log %s size!"
, ({struct cpu_info *__ci; asm volatile("movq %%gs:%P1,%0" : "=r"
(__ci) :"n" (__builtin_offsetof(struct cpu_info, ci_self)));
__ci;})->ci_curproc->p_p->ps_pid, __func__ , sections
[i].name)
;
91 } else {
92 /* Size is +1 unit */
93 log->sizes[i].count--;
94 }
95
96 /* Clip to field size */
97 if (log->sizes[i].count > sections[i].max) {
98 drm_err(&i915->drm, "GuC log %s size too large: %d vs %d!",printf("drm:pid%d:%s *ERROR* " "[drm] " "*ERROR* " "GuC log %s size too large: %d vs %d!"
, ({struct cpu_info *__ci; asm volatile("movq %%gs:%P1,%0" : "=r"
(__ci) :"n" (__builtin_offsetof(struct cpu_info, ci_self)));
__ci;})->ci_curproc->p_p->ps_pid, __func__ , sections
[i].name, log->sizes[i].count + 1, sections[i].max + 1)
99 sections[i].name, log->sizes[i].count + 1, sections[i].max + 1)printf("drm:pid%d:%s *ERROR* " "[drm] " "*ERROR* " "GuC log %s size too large: %d vs %d!"
, ({struct cpu_info *__ci; asm volatile("movq %%gs:%P1,%0" : "=r"
(__ci) :"n" (__builtin_offsetof(struct cpu_info, ci_self)));
__ci;})->ci_curproc->p_p->ps_pid, __func__ , sections
[i].name, log->sizes[i].count + 1, sections[i].max + 1)
;
100 log->sizes[i].count = sections[i].max;
101 }
102 }
103
104 if (log->sizes[GUC_LOG_SECTIONS_CRASH].units != log->sizes[GUC_LOG_SECTIONS_DEBUG].units) {
105 drm_err(&i915->drm, "Unit mis-match for GuC log crash and debug sections: %d vs %d!",printf("drm:pid%d:%s *ERROR* " "[drm] " "*ERROR* " "Unit mis-match for GuC log crash and debug sections: %d vs %d!"
, ({struct cpu_info *__ci; asm volatile("movq %%gs:%P1,%0" : "=r"
(__ci) :"n" (__builtin_offsetof(struct cpu_info, ci_self)));
__ci;})->ci_curproc->p_p->ps_pid, __func__ , log->
sizes[GUC_LOG_SECTIONS_CRASH].units, log->sizes[GUC_LOG_SECTIONS_DEBUG
].units)
106 log->sizes[GUC_LOG_SECTIONS_CRASH].units,printf("drm:pid%d:%s *ERROR* " "[drm] " "*ERROR* " "Unit mis-match for GuC log crash and debug sections: %d vs %d!"
, ({struct cpu_info *__ci; asm volatile("movq %%gs:%P1,%0" : "=r"
(__ci) :"n" (__builtin_offsetof(struct cpu_info, ci_self)));
__ci;})->ci_curproc->p_p->ps_pid, __func__ , log->
sizes[GUC_LOG_SECTIONS_CRASH].units, log->sizes[GUC_LOG_SECTIONS_DEBUG
].units)
107 log->sizes[GUC_LOG_SECTIONS_DEBUG].units)printf("drm:pid%d:%s *ERROR* " "[drm] " "*ERROR* " "Unit mis-match for GuC log crash and debug sections: %d vs %d!"
, ({struct cpu_info *__ci; asm volatile("movq %%gs:%P1,%0" : "=r"
(__ci) :"n" (__builtin_offsetof(struct cpu_info, ci_self)));
__ci;})->ci_curproc->p_p->ps_pid, __func__ , log->
sizes[GUC_LOG_SECTIONS_CRASH].units, log->sizes[GUC_LOG_SECTIONS_DEBUG
].units)
;
108 log->sizes[GUC_LOG_SECTIONS_CRASH].units = log->sizes[GUC_LOG_SECTIONS_DEBUG].units;
109 log->sizes[GUC_LOG_SECTIONS_CRASH].count = 0;
110 }
111
112 log->sizes_initialised = true1;
113}
114
115static void guc_log_init_sizes(struct intel_guc_log *log)
116{
117 if (log->sizes_initialised)
118 return;
119
120 _guc_log_init_sizes(log);
121}
122
123static u32 intel_guc_log_section_size_crash(struct intel_guc_log *log)
124{
125 guc_log_init_sizes(log);
126
127 return log->sizes[GUC_LOG_SECTIONS_CRASH].bytes;
128}
129
130static u32 intel_guc_log_section_size_debug(struct intel_guc_log *log)
131{
132 guc_log_init_sizes(log);
133
134 return log->sizes[GUC_LOG_SECTIONS_DEBUG].bytes;
135}
136
137u32 intel_guc_log_section_size_capture(struct intel_guc_log *log)
138{
139 guc_log_init_sizes(log);
140
141 return log->sizes[GUC_LOG_SECTIONS_CAPTURE].bytes;
142}
143
144static u32 intel_guc_log_size(struct intel_guc_log *log)
145{
146 /*
147 * GuC Log buffer Layout:
148 *
149 * NB: Ordering must follow "enum guc_log_buffer_type".
150 *
151 * +===============================+ 00B
152 * | Debug state header |
153 * +-------------------------------+ 32B
154 * | Crash dump state header |
155 * +-------------------------------+ 64B
156 * | Capture state header |
157 * +-------------------------------+ 96B
158 * | |
159 * +===============================+ PAGE_SIZE (4KB)
160 * | Debug logs |
161 * +===============================+ + DEBUG_SIZE
162 * | Crash Dump logs |
163 * +===============================+ + CRASH_SIZE
164 * | Capture logs |
165 * +===============================+ + CAPTURE_SIZE
166 */
167 return PAGE_SIZE(1 << 12) +
168 intel_guc_log_section_size_crash(log) +
169 intel_guc_log_section_size_debug(log) +
170 intel_guc_log_section_size_capture(log);
171}
172
173/**
174 * DOC: GuC firmware log
175 *
176 * Firmware log is enabled by setting i915.guc_log_level to the positive level.
177 * Log data is printed out via reading debugfs i915_guc_log_dump. Reading from
178 * i915_guc_load_status will print out firmware loading status and scratch
179 * registers value.
180 */
181
182static int guc_action_flush_log_complete(struct intel_guc *guc)
183{
184 u32 action[] = {
185 INTEL_GUC_ACTION_LOG_BUFFER_FILE_FLUSH_COMPLETE,
186 GUC_DEBUG_LOG_BUFFER
187 };
188
189 return intel_guc_send_nb(guc, action, ARRAY_SIZE(action)(sizeof((action)) / sizeof((action)[0])), 0);
190}
191
192static int guc_action_flush_log(struct intel_guc *guc)
193{
194 u32 action[] = {
195 INTEL_GUC_ACTION_FORCE_LOG_BUFFER_FLUSH,
196 0
197 };
198
199 return intel_guc_send(guc, action, ARRAY_SIZE(action)(sizeof((action)) / sizeof((action)[0])));
200}
201
202static int guc_action_control_log(struct intel_guc *guc, bool_Bool enable,
203 bool_Bool default_logging, u32 verbosity)
204{
205 u32 action[] = {
206 INTEL_GUC_ACTION_UK_LOG_ENABLE_LOGGING,
207 (enable ? GUC_LOG_CONTROL_LOGGING_ENABLED(1 << 0) : 0) |
208 (verbosity << GUC_LOG_CONTROL_VERBOSITY_SHIFT4) |
209 (default_logging ? GUC_LOG_CONTROL_DEFAULT_LOGGING(1 << 8) : 0)
210 };
211
212 GEM_BUG_ON(verbosity > GUC_LOG_VERBOSITY_MAX)((void)0);
213
214 return intel_guc_send(guc, action, ARRAY_SIZE(action)(sizeof((action)) / sizeof((action)[0])));
215}
216
217#ifdef __linux__
218
219/*
220 * Sub buffer switch callback. Called whenever relay has to switch to a new
221 * sub buffer, relay stays on the same sub buffer if 0 is returned.
222 */
223static int subbuf_start_callback(struct rchan_buf *buf,
224 void *subbuf,
225 void *prev_subbuf,
226 size_t prev_padding)
227{
228 /*
229 * Use no-overwrite mode by default, where relay will stop accepting
230 * new data if there are no empty sub buffers left.
231 * There is no strict synchronization enforced by relay between Consumer
232 * and Producer. In overwrite mode, there is a possibility of getting
233 * inconsistent/garbled data, the producer could be writing on to the
234 * same sub buffer from which Consumer is reading. This can't be avoided
235 * unless Consumer is fast enough and can always run in tandem with
236 * Producer.
237 */
238 if (relay_buf_full(buf))
239 return 0;
240
241 return 1;
242}
243
244/*
245 * file_create() callback. Creates relay file in debugfs.
246 */
247static struct dentry *create_buf_file_callback(const char *filename,
248 struct dentry *parent,
249 umode_t mode,
250 struct rchan_buf *buf,
251 int *is_global)
252{
253 struct dentry *buf_file;
254
255 /*
256 * This to enable the use of a single buffer for the relay channel and
257 * correspondingly have a single file exposed to User, through which
258 * it can collect the logs in order without any post-processing.
259 * Need to set 'is_global' even if parent is NULL for early logging.
260 */
261 *is_global = 1;
262
263 if (!parent)
264 return NULL((void *)0);
265
266 buf_file = debugfs_create_file(filename, mode,ERR_PTR(-78)
267 parent, buf, &relay_file_operations)ERR_PTR(-78);
268 if (IS_ERR(buf_file))
269 return NULL((void *)0);
270
271 return buf_file;
272}
273
274/*
275 * file_remove() default callback. Removes relay file in debugfs.
276 */
277static int remove_buf_file_callback(struct dentry *dentry)
278{
279 debugfs_remove(dentry);
280 return 0;
281}
282
283/* relay channel callbacks */
284static const struct rchan_callbacks relay_callbacks = {
285 .subbuf_start = subbuf_start_callback,
286 .create_buf_file = create_buf_file_callback,
287 .remove_buf_file = remove_buf_file_callback,
288};
289
290#endif /* __linux__ */
291
292static void guc_move_to_next_buf(struct intel_guc_log *log)
293{
294 STUB()do { printf("%s: stub\n", __func__); } while(0);
295#ifdef notyet
296 /*
297 * Make sure the updates made in the sub buffer are visible when
298 * Consumer sees the following update to offset inside the sub buffer.
299 */
300 smp_wmb()do { __asm volatile("" ::: "memory"); } while (0);
301
302 /* All data has been written, so now move the offset of sub buffer. */
303 relay_reserve(log->relay.channel, log->vma->obj->base.size -
304 intel_guc_log_section_size_capture(log));
305
306 /* Switch to the next sub buffer */
307 relay_flush(log->relay.channel);
308#endif
309}
310
311static void *guc_get_write_buffer(struct intel_guc_log *log)
312{
313 STUB()do { printf("%s: stub\n", __func__); } while(0);
314 return NULL((void *)0);
315#ifdef notyet
316 /*
317 * Just get the base address of a new sub buffer and copy data into it
318 * ourselves. NULL will be returned in no-overwrite mode, if all sub
319 * buffers are full. Could have used the relay_write() to indirectly
320 * copy the data, but that would have been bit convoluted, as we need to
321 * write to only certain locations inside a sub buffer which cannot be
322 * done without using relay_reserve() along with relay_write(). So its
323 * better to use relay_reserve() alone.
324 */
325 return relay_reserve(log->relay.channel, 0);
326#endif
327}
328
329bool_Bool intel_guc_check_log_buf_overflow(struct intel_guc_log *log,
330 enum guc_log_buffer_type type,
331 unsigned int full_cnt)
332{
333 unsigned int prev_full_cnt = log->stats[type].sampled_overflow;
334 bool_Bool overflow = false0;
335
336 if (full_cnt != prev_full_cnt) {
337 overflow = true1;
338
339 log->stats[type].overflow = full_cnt;
340 log->stats[type].sampled_overflow += full_cnt - prev_full_cnt;
341
342 if (full_cnt < prev_full_cnt) {
343 /* buffer_full_cnt is a 4 bit counter */
344 log->stats[type].sampled_overflow += 16;
345 }
346
347 dev_notice_ratelimited(guc_to_gt(log_to_guc(log))->i915->drm.dev,printf("drm:pid%d:%s *NOTICE* " "GuC log buffer overflow\n", (
{struct cpu_info *__ci; asm volatile("movq %%gs:%P1,%0" : "=r"
(__ci) :"n" (__builtin_offsetof(struct cpu_info, ci_self)));
__ci;})->ci_curproc->p_p->ps_pid, __func__)
348 "GuC log buffer overflow\n")printf("drm:pid%d:%s *NOTICE* " "GuC log buffer overflow\n", (
{struct cpu_info *__ci; asm volatile("movq %%gs:%P1,%0" : "=r"
(__ci) :"n" (__builtin_offsetof(struct cpu_info, ci_self)));
__ci;})->ci_curproc->p_p->ps_pid, __func__)
;
349 }
350
351 return overflow;
352}
353
354unsigned int intel_guc_get_log_buffer_size(struct intel_guc_log *log,
355 enum guc_log_buffer_type type)
356{
357 switch (type) {
358 case GUC_DEBUG_LOG_BUFFER:
359 return intel_guc_log_section_size_debug(log);
360 case GUC_CRASH_DUMP_LOG_BUFFER:
361 return intel_guc_log_section_size_crash(log);
362 case GUC_CAPTURE_LOG_BUFFER:
363 return intel_guc_log_section_size_capture(log);
364 default:
365 MISSING_CASE(type)({ int __ret = !!(1); if (__ret) printf("Missing case (%s == %ld)\n"
, "type", (long)(type)); __builtin_expect(!!(__ret), 0); })
;
366 }
367
368 return 0;
369}
370
371size_t intel_guc_get_log_buffer_offset(struct intel_guc_log *log,
372 enum guc_log_buffer_type type)
373{
374 enum guc_log_buffer_type i;
375 size_t offset = PAGE_SIZE(1 << 12);/* for the log_buffer_states */
376
377 for (i = GUC_DEBUG_LOG_BUFFER; i < GUC_MAX_LOG_BUFFER; ++i) {
378 if (i == type)
379 break;
380 offset += intel_guc_get_log_buffer_size(log, i);
381 }
382
383 return offset;
384}
385
386static void _guc_log_copy_debuglogs_for_relay(struct intel_guc_log *log)
387{
388 unsigned int buffer_size, read_offset, write_offset, bytes_to_copy, full_cnt;
389 struct guc_log_buffer_state *log_buf_state, *log_buf_snapshot_state;
390 struct guc_log_buffer_state log_buf_state_local;
391 enum guc_log_buffer_type type;
392 void *src_data, *dst_data;
393 bool_Bool new_overflow;
394
395 mutex_lock(&log->relay.lock)rw_enter_write(&log->relay.lock);
396
397 if (WARN_ON(!intel_guc_log_relay_created(log))({ int __ret = !!(!intel_guc_log_relay_created(log)); if (__ret
) printf("WARNING %s failed at %s:%d\n", "!intel_guc_log_relay_created(log)"
, "/usr/src/sys/dev/pci/drm/i915/gt/uc/intel_guc_log.c", 397)
; __builtin_expect(!!(__ret), 0); })
)
398 goto out_unlock;
399
400 /* Get the pointer to shared GuC log buffer */
401 src_data = log->buf_addr;
402 log_buf_state = src_data;
403
404 /* Get the pointer to local buffer to store the logs */
405 log_buf_snapshot_state = dst_data = guc_get_write_buffer(log);
406
407 if (unlikely(!log_buf_snapshot_state)__builtin_expect(!!(!log_buf_snapshot_state), 0)) {
408 /*
409 * Used rate limited to avoid deluge of messages, logs might be
410 * getting consumed by User at a slow rate.
411 */
412 DRM_ERROR_RATELIMITED("no sub-buffer to copy general logs\n")({ static struct ratelimit_state _rs; if (__ratelimit(&_rs
)) drm_dev_printk(((void *)0), "\0013", "*ERROR* " "no sub-buffer to copy general logs\n"
); })
;
413 log->relay.full_count++;
414
415 goto out_unlock;
416 }
417
418 /* Actual logs are present from the 2nd page */
419 src_data += PAGE_SIZE(1 << 12);
420 dst_data += PAGE_SIZE(1 << 12);
421
422 /* For relay logging, we exclude error state capture */
423 for (type = GUC_DEBUG_LOG_BUFFER; type <= GUC_CRASH_DUMP_LOG_BUFFER; type++) {
424 /*
425 * Make a copy of the state structure, inside GuC log buffer
426 * (which is uncached mapped), on the stack to avoid reading
427 * from it multiple times.
428 */
429 memcpy(&log_buf_state_local, log_buf_state,__builtin_memcpy((&log_buf_state_local), (log_buf_state),
(sizeof(struct guc_log_buffer_state)))
430 sizeof(struct guc_log_buffer_state))__builtin_memcpy((&log_buf_state_local), (log_buf_state),
(sizeof(struct guc_log_buffer_state)))
;
431 buffer_size = intel_guc_get_log_buffer_size(log, type);
432 read_offset = log_buf_state_local.read_ptr;
433 write_offset = log_buf_state_local.sampled_write_ptr;
434 full_cnt = log_buf_state_local.buffer_full_cnt;
435
436 /* Bookkeeping stuff */
437 log->stats[type].flush += log_buf_state_local.flush_to_file;
438 new_overflow = intel_guc_check_log_buf_overflow(log, type, full_cnt);
439
440 /* Update the state of shared log buffer */
441 log_buf_state->read_ptr = write_offset;
442 log_buf_state->flush_to_file = 0;
443 log_buf_state++;
444
445 /* First copy the state structure in snapshot buffer */
446 memcpy(log_buf_snapshot_state, &log_buf_state_local,__builtin_memcpy((log_buf_snapshot_state), (&log_buf_state_local
), (sizeof(struct guc_log_buffer_state)))
447 sizeof(struct guc_log_buffer_state))__builtin_memcpy((log_buf_snapshot_state), (&log_buf_state_local
), (sizeof(struct guc_log_buffer_state)))
;
448
449 /*
450 * The write pointer could have been updated by GuC firmware,
451 * after sending the flush interrupt to Host, for consistency
452 * set write pointer value to same value of sampled_write_ptr
453 * in the snapshot buffer.
454 */
455 log_buf_snapshot_state->write_ptr = write_offset;
456 log_buf_snapshot_state++;
457
458 /* Now copy the actual logs. */
459 if (unlikely(new_overflow)__builtin_expect(!!(new_overflow), 0)) {
460 /* copy the whole buffer in case of overflow */
461 read_offset = 0;
462 write_offset = buffer_size;
463 } else if (unlikely((read_offset > buffer_size) ||__builtin_expect(!!((read_offset > buffer_size) || (write_offset
> buffer_size)), 0)
464 (write_offset > buffer_size))__builtin_expect(!!((read_offset > buffer_size) || (write_offset
> buffer_size)), 0)
) {
465 DRM_ERROR("invalid log buffer state\n")__drm_err("invalid log buffer state\n");
466 /* copy whole buffer as offsets are unreliable */
467 read_offset = 0;
468 write_offset = buffer_size;
469 }
470
471 /* Just copy the newly written data */
472 if (read_offset > write_offset) {
473 i915_memcpy_from_wc(dst_data, src_data, write_offset);
474 bytes_to_copy = buffer_size - read_offset;
475 } else {
476 bytes_to_copy = write_offset - read_offset;
477 }
478 i915_memcpy_from_wc(dst_data + read_offset,
479 src_data + read_offset, bytes_to_copy);
480
481 src_data += buffer_size;
482 dst_data += buffer_size;
483 }
484
485 guc_move_to_next_buf(log);
486
487out_unlock:
488 mutex_unlock(&log->relay.lock)rw_exit_write(&log->relay.lock);
489}
490
491static void copy_debug_logs_work(struct work_struct *work)
492{
493 struct intel_guc_log *log =
494 container_of(work, struct intel_guc_log, relay.flush_work)({ const __typeof( ((struct intel_guc_log *)0)->relay.flush_work
) *__mptr = (work); (struct intel_guc_log *)( (char *)__mptr
- __builtin_offsetof(struct intel_guc_log, relay.flush_work)
);})
;
495
496 guc_log_copy_debuglogs_for_relay(log);
497}
498
499static int guc_log_relay_map(struct intel_guc_log *log)
500{
501 lockdep_assert_held(&log->relay.lock)do { (void)(&log->relay.lock); } while(0);
502
503 if (!log->vma || !log->buf_addr)
504 return -ENODEV19;
505
506 /*
507 * WC vmalloc mapping of log buffer pages was done at
508 * GuC Log Init time, but lets keep a ref for book-keeping
509 */
510 i915_gem_object_get(log->vma->obj);
511 log->relay.buf_in_use = true1;
512
513 return 0;
514}
515
516static void guc_log_relay_unmap(struct intel_guc_log *log)
517{
518 lockdep_assert_held(&log->relay.lock)do { (void)(&log->relay.lock); } while(0);
519
520 i915_gem_object_put(log->vma->obj);
521 log->relay.buf_in_use = false0;
522}
523
524void intel_guc_log_init_early(struct intel_guc_log *log)
525{
526 rw_init(&log->relay.lock, "rllk")_rw_init_flags(&log->relay.lock, "rllk", 0, ((void *)0
))
;
527 INIT_WORK(&log->relay.flush_work, copy_debug_logs_work);
528 log->relay.started = false0;
529}
530
531static int guc_log_relay_create(struct intel_guc_log *log)
532{
533 STUB()do { printf("%s: stub\n", __func__); } while(0);
534 return -ENOSYS78;
535#ifdef notyet
536 struct intel_guc *guc = log_to_guc(log);
537 struct drm_i915_privateinteldrm_softc *dev_priv = guc_to_gt(guc)->i915;
538 struct rchan *guc_log_relay_chan;
539 size_t n_subbufs, subbuf_size;
540 int ret;
541
542 lockdep_assert_held(&log->relay.lock)do { (void)(&log->relay.lock); } while(0);
543 GEM_BUG_ON(!log->vma)((void)0);
544
545 /*
546 * Keep the size of sub buffers same as shared log buffer
547 * but GuC log-events excludes the error-state-capture logs
548 */
549 subbuf_size = log->vma->size - intel_guc_log_section_size_capture(log);
550
551 /*
552 * Store up to 8 snapshots, which is large enough to buffer sufficient
553 * boot time logs and provides enough leeway to User, in terms of
554 * latency, for consuming the logs from relay. Also doesn't take
555 * up too much memory.
556 */
557 n_subbufs = 8;
558
559 guc_log_relay_chan = relay_open("guc_log",
560 dev_priv->drm.primary->debugfs_root,
561 subbuf_size, n_subbufs,
562 &relay_callbacks, dev_priv);
563 if (!guc_log_relay_chan) {
564 DRM_ERROR("Couldn't create relay chan for GuC logging\n")__drm_err("Couldn't create relay chan for GuC logging\n");
565
566 ret = -ENOMEM12;
567 return ret;
568 }
569
570 GEM_BUG_ON(guc_log_relay_chan->subbuf_size < subbuf_size)((void)0);
571 log->relay.channel = guc_log_relay_chan;
572
573 return 0;
574#endif
575}
576
577static void guc_log_relay_destroy(struct intel_guc_log *log)
578{
579 STUB()do { printf("%s: stub\n", __func__); } while(0);
580#ifdef notyet
581 lockdep_assert_held(&log->relay.lock)do { (void)(&log->relay.lock); } while(0);
582
583 relay_close(log->relay.channel);
584 log->relay.channel = NULL((void *)0);
585#endif
586}
587
588static void guc_log_copy_debuglogs_for_relay(struct intel_guc_log *log)
589{
590 struct intel_guc *guc = log_to_guc(log);
591 struct drm_i915_privateinteldrm_softc *dev_priv = guc_to_gt(guc)->i915;
592 intel_wakeref_t wakeref;
593
594 _guc_log_copy_debuglogs_for_relay(log);
595
596 /*
597 * Generally device is expected to be active only at this
598 * time, so get/put should be really quick.
599 */
600 with_intel_runtime_pm(&dev_priv->runtime_pm, wakeref)for ((wakeref) = intel_runtime_pm_get(&dev_priv->runtime_pm
); (wakeref); intel_runtime_pm_put((&dev_priv->runtime_pm
), (wakeref)), (wakeref) = 0)
601 guc_action_flush_log_complete(guc);
602}
603
604static u32 __get_default_log_level(struct intel_guc_log *log)
605{
606 struct intel_guc *guc = log_to_guc(log);
607 struct drm_i915_privateinteldrm_softc *i915 = guc_to_gt(guc)->i915;
608
609 /* A negative value means "use platform/config default" */
610 if (i915->params.guc_log_level < 0) {
611 return (IS_ENABLED(CONFIG_DRM_I915_DEBUG)0 ||
612 IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM)0) ?
613 GUC_LOG_LEVEL_MAX((3) + 2) : GUC_LOG_LEVEL_NON_VERBOSE1;
614 }
615
616 if (i915->params.guc_log_level > GUC_LOG_LEVEL_MAX((3) + 2)) {
617 DRM_WARN("Incompatible option detected: %s=%d, %s!\n",printk("\0014" "[" "drm" "] " "Incompatible option detected: %s=%d, %s!\n"
, "guc_log_level", i915->params.guc_log_level, "verbosity too high"
)
618 "guc_log_level", i915->params.guc_log_level,printk("\0014" "[" "drm" "] " "Incompatible option detected: %s=%d, %s!\n"
, "guc_log_level", i915->params.guc_log_level, "verbosity too high"
)
619 "verbosity too high")printk("\0014" "[" "drm" "] " "Incompatible option detected: %s=%d, %s!\n"
, "guc_log_level", i915->params.guc_log_level, "verbosity too high"
)
;
620 return (IS_ENABLED(CONFIG_DRM_I915_DEBUG)0 ||
621 IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM)0) ?
622 GUC_LOG_LEVEL_MAX((3) + 2) : GUC_LOG_LEVEL_DISABLED0;
623 }
624
625 GEM_BUG_ON(i915->params.guc_log_level < GUC_LOG_LEVEL_DISABLED)((void)0);
626 GEM_BUG_ON(i915->params.guc_log_level > GUC_LOG_LEVEL_MAX)((void)0);
627 return i915->params.guc_log_level;
628}
629
630int intel_guc_log_create(struct intel_guc_log *log)
631{
632 struct intel_guc *guc = log_to_guc(log);
633 struct i915_vma *vma;
634 void *vaddr;
635 u32 guc_log_size;
636 int ret;
637
638 GEM_BUG_ON(log->vma)((void)0);
639
640 guc_log_size = intel_guc_log_size(log);
641
642 vma = intel_guc_allocate_vma(guc, guc_log_size);
643 if (IS_ERR(vma)) {
644 ret = PTR_ERR(vma);
645 goto err;
646 }
647
648 log->vma = vma;
649 /*
650 * Create a WC (Uncached for read) vmalloc mapping up front immediate access to
651 * data from memory during critical events such as error capture
652 */
653 vaddr = i915_gem_object_pin_map_unlocked(log->vma->obj, I915_MAP_WC);
654 if (IS_ERR(vaddr)) {
655 ret = PTR_ERR(vaddr);
656 i915_vma_unpin_and_release(&log->vma, 0);
657 goto err;
658 }
659 log->buf_addr = vaddr;
660
661 log->level = __get_default_log_level(log);
662 DRM_DEBUG_DRIVER("guc_log_level=%d (%s, verbose:%s, verbosity:%d)\n",___drm_dbg(((void *)0), DRM_UT_DRIVER, "guc_log_level=%d (%s, verbose:%s, verbosity:%d)\n"
, log->level, str_enabled_disabled(log->level), str_yes_no
(((log->level) > 1)), ({ typeof(log->level) _x = (log
->level); ((_x) > 1) ? _x - 2 : 0; }))
663 log->level, str_enabled_disabled(log->level),___drm_dbg(((void *)0), DRM_UT_DRIVER, "guc_log_level=%d (%s, verbose:%s, verbosity:%d)\n"
, log->level, str_enabled_disabled(log->level), str_yes_no
(((log->level) > 1)), ({ typeof(log->level) _x = (log
->level); ((_x) > 1) ? _x - 2 : 0; }))
664 str_yes_no(GUC_LOG_LEVEL_IS_VERBOSE(log->level)),___drm_dbg(((void *)0), DRM_UT_DRIVER, "guc_log_level=%d (%s, verbose:%s, verbosity:%d)\n"
, log->level, str_enabled_disabled(log->level), str_yes_no
(((log->level) > 1)), ({ typeof(log->level) _x = (log
->level); ((_x) > 1) ? _x - 2 : 0; }))
665 GUC_LOG_LEVEL_TO_VERBOSITY(log->level))___drm_dbg(((void *)0), DRM_UT_DRIVER, "guc_log_level=%d (%s, verbose:%s, verbosity:%d)\n"
, log->level, str_enabled_disabled(log->level), str_yes_no
(((log->level) > 1)), ({ typeof(log->level) _x = (log
->level); ((_x) > 1) ? _x - 2 : 0; }))
;
666
667 return 0;
668
669err:
670 DRM_ERROR("Failed to allocate or map GuC log buffer. %d\n", ret)__drm_err("Failed to allocate or map GuC log buffer. %d\n", ret
)
;
671 return ret;
672}
673
674void intel_guc_log_destroy(struct intel_guc_log *log)
675{
676 log->buf_addr = NULL((void *)0);
677 i915_vma_unpin_and_release(&log->vma, I915_VMA_RELEASE_MAP(1UL << (0)));
678}
679
680int intel_guc_log_set_level(struct intel_guc_log *log, u32 level)
681{
682 struct intel_guc *guc = log_to_guc(log);
683 struct drm_i915_privateinteldrm_softc *dev_priv = guc_to_gt(guc)->i915;
684 intel_wakeref_t wakeref;
685 int ret = 0;
686
687 BUILD_BUG_ON(GUC_LOG_VERBOSITY_MIN != 0)extern char _ctassert[(!(0 != 0)) ? 1 : -1 ] __attribute__((__unused__
))
;
688 GEM_BUG_ON(!log->vma)((void)0);
689
690 /*
691 * GuC is recognizing log levels starting from 0 to max, we're using 0
692 * as indication that logging should be disabled.
693 */
694 if (level < GUC_LOG_LEVEL_DISABLED0 || level > GUC_LOG_LEVEL_MAX((3) + 2))
695 return -EINVAL22;
696
697 mutex_lock(&dev_priv->drm.struct_mutex)rw_enter_write(&dev_priv->drm.struct_mutex);
698
699 if (log->level == level)
700 goto out_unlock;
701
702 with_intel_runtime_pm(&dev_priv->runtime_pm, wakeref)for ((wakeref) = intel_runtime_pm_get(&dev_priv->runtime_pm
); (wakeref); intel_runtime_pm_put((&dev_priv->runtime_pm
), (wakeref)), (wakeref) = 0)
703 ret = guc_action_control_log(guc,
704 GUC_LOG_LEVEL_IS_VERBOSE(level)((level) > 1),
705 GUC_LOG_LEVEL_IS_ENABLED(level)((level) > 0),
706 GUC_LOG_LEVEL_TO_VERBOSITY(level)({ typeof(level) _x = (level); ((_x) > 1) ? _x - 2 : 0; }));
707 if (ret) {
708 DRM_DEBUG_DRIVER("guc_log_control action failed %d\n", ret)___drm_dbg(((void *)0), DRM_UT_DRIVER, "guc_log_control action failed %d\n"
, ret)
;
709 goto out_unlock;
710 }
711
712 log->level = level;
713
714out_unlock:
715 mutex_unlock(&dev_priv->drm.struct_mutex)rw_exit_write(&dev_priv->drm.struct_mutex);
716
717 return ret;
718}
719
720bool_Bool intel_guc_log_relay_created(const struct intel_guc_log *log)
721{
722 return log->buf_addr;
723}
724
725int intel_guc_log_relay_open(struct intel_guc_log *log)
726{
727 int ret;
728
729 if (!log->vma)
730 return -ENODEV19;
731
732 mutex_lock(&log->relay.lock)rw_enter_write(&log->relay.lock);
733
734 if (intel_guc_log_relay_created(log)) {
735 ret = -EEXIST17;
736 goto out_unlock;
737 }
738
739 /*
740 * We require SSE 4.1 for fast reads from the GuC log buffer and
741 * it should be present on the chipsets supporting GuC based
742 * submissions.
743 */
744 if (!i915_has_memcpy_from_wc()i915_memcpy_from_wc(((void *)0), ((void *)0), 0)) {
745 ret = -ENXIO6;
746 goto out_unlock;
747 }
748
749 ret = guc_log_relay_create(log);
750 if (ret)
751 goto out_unlock;
752
753 ret = guc_log_relay_map(log);
754 if (ret)
755 goto out_relay;
756
757 mutex_unlock(&log->relay.lock)rw_exit_write(&log->relay.lock);
758
759 return 0;
760
761out_relay:
762 guc_log_relay_destroy(log);
763out_unlock:
764 mutex_unlock(&log->relay.lock)rw_exit_write(&log->relay.lock);
765
766 return ret;
767}
768
769int intel_guc_log_relay_start(struct intel_guc_log *log)
770{
771 if (log->relay.started)
772 return -EEXIST17;
773
774 /*
775 * When GuC is logging without us relaying to userspace, we're ignoring
776 * the flush notification. This means that we need to unconditionally
777 * flush on relay enabling, since GuC only notifies us once.
778 */
779 queue_work(system_highpri_wq, &log->relay.flush_work);
780
781 log->relay.started = true1;
782
783 return 0;
784}
785
786void intel_guc_log_relay_flush(struct intel_guc_log *log)
787{
788 struct intel_guc *guc = log_to_guc(log);
789 intel_wakeref_t wakeref;
790
791 if (!log->relay.started)
792 return;
793
794 /*
795 * Before initiating the forceful flush, wait for any pending/ongoing
796 * flush to complete otherwise forceful flush may not actually happen.
797 */
798 flush_work(&log->relay.flush_work);
799
800 with_intel_runtime_pm(guc_to_gt(guc)->uncore->rpm, wakeref)for ((wakeref) = intel_runtime_pm_get(guc_to_gt(guc)->uncore
->rpm); (wakeref); intel_runtime_pm_put((guc_to_gt(guc)->
uncore->rpm), (wakeref)), (wakeref) = 0)
801 guc_action_flush_log(guc);
802
803 /* GuC would have updated log buffer by now, so copy it */
804 guc_log_copy_debuglogs_for_relay(log);
805}
806
807/*
808 * Stops the relay log. Called from intel_guc_log_relay_close(), so no
809 * possibility of race with start/flush since relay_write cannot race
810 * relay_close.
811 */
812static void guc_log_relay_stop(struct intel_guc_log *log)
813{
814 struct intel_guc *guc = log_to_guc(log);
815 struct drm_i915_privateinteldrm_softc *i915 = guc_to_gt(guc)->i915;
816
817 if (!log->relay.started)
818 return;
819
820 intel_synchronize_irq(i915);
821
822 flush_work(&log->relay.flush_work);
823
824 log->relay.started = false0;
825}
826
827void intel_guc_log_relay_close(struct intel_guc_log *log)
828{
829 guc_log_relay_stop(log);
830
831 mutex_lock(&log->relay.lock)rw_enter_write(&log->relay.lock);
832 GEM_BUG_ON(!intel_guc_log_relay_created(log))((void)0);
833 guc_log_relay_unmap(log);
834 guc_log_relay_destroy(log);
835 mutex_unlock(&log->relay.lock)rw_exit_write(&log->relay.lock);
836}
837
838void intel_guc_log_handle_flush_event(struct intel_guc_log *log)
839{
840 if (log->relay.started)
841 queue_work(system_highpri_wq, &log->relay.flush_work);
842}
843
844static const char *
845stringify_guc_log_type(enum guc_log_buffer_type type)
846{
847 switch (type) {
848 case GUC_DEBUG_LOG_BUFFER:
849 return "DEBUG";
850 case GUC_CRASH_DUMP_LOG_BUFFER:
851 return "CRASH";
852 case GUC_CAPTURE_LOG_BUFFER:
853 return "CAPTURE";
854 default:
855 MISSING_CASE(type)({ int __ret = !!(1); if (__ret) printf("Missing case (%s == %ld)\n"
, "type", (long)(type)); __builtin_expect(!!(__ret), 0); })
;
856 }
857
858 return "";
859}
860
861/**
862 * intel_guc_log_info - dump information about GuC log relay
863 * @log: the GuC log
864 * @p: the &drm_printer
865 *
866 * Pretty printer for GuC log info
867 */
868void intel_guc_log_info(struct intel_guc_log *log, struct drm_printer *p)
869{
870 enum guc_log_buffer_type type;
871
872 if (!intel_guc_log_relay_created(log)) {
873 drm_puts(p, "GuC log relay not created\n");
874 return;
875 }
876
877 drm_puts(p, "GuC logging stats:\n");
878
879 drm_printf(p, "\tRelay full count: %u\n", log->relay.full_count);
880
881 for (type = GUC_DEBUG_LOG_BUFFER; type < GUC_MAX_LOG_BUFFER; type++) {
882 drm_printf(p, "\t%s:\tflush count %10u, overflow count %10u\n",
883 stringify_guc_log_type(type),
884 log->stats[type].flush,
885 log->stats[type].sampled_overflow);
886 }
887}
888
889/**
890 * intel_guc_log_dump - dump the contents of the GuC log
891 * @log: the GuC log
892 * @p: the &drm_printer
893 * @dump_load_err: dump the log saved on GuC load error
894 *
895 * Pretty printer for the GuC log
896 */
897int intel_guc_log_dump(struct intel_guc_log *log, struct drm_printer *p,
898 bool_Bool dump_load_err)
899{
900 struct intel_guc *guc = log_to_guc(log);
901 struct intel_uc *uc = container_of(guc, struct intel_uc, guc)({ const __typeof( ((struct intel_uc *)0)->guc ) *__mptr =
(guc); (struct intel_uc *)( (char *)__mptr - __builtin_offsetof
(struct intel_uc, guc) );})
;
902 struct drm_i915_gem_object *obj = NULL((void *)0);
903 void *map;
904 u32 *page;
905 int i, j;
906
907 if (!intel_guc_is_supported(guc))
908 return -ENODEV19;
909
910 if (dump_load_err)
911 obj = uc->load_err_log;
912 else if (guc->log.vma)
913 obj = guc->log.vma->obj;
914
915 if (!obj)
916 return 0;
917
918 page = (u32 *)__get_free_page(GFP_KERNEL(0x0001 | 0x0004));
919 if (!page)
920 return -ENOMEM12;
921
922 intel_guc_dump_time_info(guc, p);
923
924 map = i915_gem_object_pin_map_unlocked(obj, I915_MAP_WC);
925 if (IS_ERR(map)) {
926 DRM_DEBUG("Failed to pin object\n")___drm_dbg(((void *)0), DRM_UT_CORE, "Failed to pin object\n"
)
;
927 drm_puts(p, "(log data unaccessible)\n");
928 free_page((unsigned long)page);
929 return PTR_ERR(map);
930 }
931
932 for (i = 0; i < obj->base.size; i += PAGE_SIZE(1 << 12)) {
933 if (!i915_memcpy_from_wc(page, map + i, PAGE_SIZE(1 << 12)))
934 memcpy(page, map + i, PAGE_SIZE)__builtin_memcpy((page), (map + i), ((1 << 12)));
935
936 for (j = 0; j < PAGE_SIZE(1 << 12) / sizeof(u32); j += 4)
937 drm_printf(p, "0x%08x 0x%08x 0x%08x 0x%08x\n",
938 *(page + j + 0), *(page + j + 1),
939 *(page + j + 2), *(page + j + 3));
940 }
941
942 drm_puts(p, "\n");
943
944 i915_gem_object_unpin_map(obj);
945 free_page((unsigned long)page);
946
947 return 0;
948}