1 // SPDX-License-Identifier: MIT
2 /*
3 * Copyright © 2022 Intel Corporation
4 */
5
6 #include "xe_guc_log.h"
7
8 #include <drm/drm_managed.h>
9 #include <linux/vmalloc.h>
10
11 #include "xe_bo.h"
12 #include "xe_devcoredump.h"
13 #include "xe_gt.h"
14 #include "xe_gt_printk.h"
15 #include "xe_map.h"
16 #include "xe_module.h"
17
18 static struct xe_gt *
log_to_gt(struct xe_guc_log * log)19 log_to_gt(struct xe_guc_log *log)
20 {
21 return container_of(log, struct xe_gt, uc.guc.log);
22 }
23
24 static struct xe_device *
log_to_xe(struct xe_guc_log * log)25 log_to_xe(struct xe_guc_log *log)
26 {
27 return gt_to_xe(log_to_gt(log));
28 }
29
guc_log_size(void)30 static size_t guc_log_size(void)
31 {
32 /*
33 * GuC Log buffer Layout
34 *
35 * +===============================+ 00B
36 * | Crash dump state header |
37 * +-------------------------------+ 32B
38 * | Debug state header |
39 * +-------------------------------+ 64B
40 * | Capture state header |
41 * +-------------------------------+ 96B
42 * | |
43 * +===============================+ PAGE_SIZE (4KB)
44 * | Crash Dump logs |
45 * +===============================+ + CRASH_SIZE
46 * | Debug logs |
47 * +===============================+ + DEBUG_SIZE
48 * | Capture logs |
49 * +===============================+ + CAPTURE_SIZE
50 */
51 return PAGE_SIZE + CRASH_BUFFER_SIZE + DEBUG_BUFFER_SIZE +
52 CAPTURE_BUFFER_SIZE;
53 }
54
55 /**
56 * xe_guc_log_print - dump a copy of the GuC log to some useful location
57 * @log: GuC log structure
58 * @p: the printer object to output to
59 */
xe_guc_log_print(struct xe_guc_log * log,struct drm_printer * p)60 void xe_guc_log_print(struct xe_guc_log *log, struct drm_printer *p)
61 {
62 struct xe_device *xe = log_to_xe(log);
63 size_t size;
64 void *copy;
65
66 if (!log->bo) {
67 drm_puts(p, "GuC log buffer not allocated");
68 return;
69 }
70
71 size = log->bo->size;
72
73 copy = vmalloc(size);
74 if (!copy) {
75 drm_printf(p, "Failed to allocate %zu", size);
76 return;
77 }
78
79 xe_map_memcpy_from(xe, copy, &log->bo->vmap, 0, size);
80
81 xe_print_blob_ascii85(p, "Log data", '\n', copy, 0, size);
82
83 vfree(copy);
84 }
85
xe_guc_log_init(struct xe_guc_log * log)86 int xe_guc_log_init(struct xe_guc_log *log)
87 {
88 struct xe_device *xe = log_to_xe(log);
89 struct xe_tile *tile = gt_to_tile(log_to_gt(log));
90 struct xe_bo *bo;
91
92 bo = xe_managed_bo_create_pin_map(xe, tile, guc_log_size(),
93 XE_BO_FLAG_SYSTEM |
94 XE_BO_FLAG_GGTT |
95 XE_BO_FLAG_GGTT_INVALIDATE);
96 if (IS_ERR(bo))
97 return PTR_ERR(bo);
98
99 xe_map_memset(xe, &bo->vmap, 0, 0, guc_log_size());
100 log->bo = bo;
101 log->level = xe_modparam.guc_log_level;
102
103 return 0;
104 }
105