xref: /linux/drivers/gpu/drm/i915/display/intel_display_snapshot.c (revision 53597deca0e38c30e6cd4ba2114fa42d2bcd85bb)
1 // SPDX-License-Identifier: MIT
2 /* Copyright © 2024 Intel Corporation */
3 
4 #include <linux/slab.h>
5 
6 #include <drm/drm_drv.h>
7 
8 #include "intel_display_core.h"
9 #include "intel_display_device.h"
10 #include "intel_display_irq.h"
11 #include "intel_display_params.h"
12 #include "intel_display_snapshot.h"
13 #include "intel_dmc.h"
14 #include "intel_overlay.h"
15 
16 struct intel_display_snapshot {
17 	struct intel_display *display;
18 
19 	struct intel_display_device_info info;
20 	struct intel_display_runtime_info runtime_info;
21 	struct intel_display_params params;
22 	struct intel_dmc_snapshot *dmc;
23 	struct intel_display_irq_snapshot *irq;
24 };
25 
26 struct intel_display_snapshot *intel_display_snapshot_capture(struct intel_display *display)
27 {
28 	struct intel_display_snapshot *snapshot;
29 
30 	snapshot = kzalloc_obj(*snapshot, GFP_ATOMIC);
31 	if (!snapshot)
32 		return NULL;
33 
34 	snapshot->display = display;
35 
36 	memcpy(&snapshot->info, DISPLAY_INFO(display), sizeof(snapshot->info));
37 	memcpy(&snapshot->runtime_info, DISPLAY_RUNTIME_INFO(display),
38 	       sizeof(snapshot->runtime_info));
39 
40 	intel_display_params_copy(&snapshot->params);
41 
42 	snapshot->irq = intel_display_irq_snapshot_capture(display);
43 	snapshot->dmc = intel_dmc_snapshot_capture(display);
44 
45 	return snapshot;
46 }
47 
48 void intel_display_snapshot_print(const struct intel_display_snapshot *snapshot,
49 				  struct drm_printer *p)
50 {
51 	struct intel_display *display;
52 
53 	if (!snapshot)
54 		return;
55 
56 	display = snapshot->display;
57 
58 	intel_display_device_info_print(&snapshot->info, &snapshot->runtime_info, p);
59 	intel_display_params_dump(&snapshot->params, display->drm->driver->name, p);
60 
61 	intel_display_irq_snapshot_print(snapshot->irq, p);
62 	intel_dmc_snapshot_print(snapshot->dmc, p);
63 }
64 
65 void intel_display_snapshot_free(struct intel_display_snapshot *snapshot)
66 {
67 	if (!snapshot)
68 		return;
69 
70 	intel_display_params_free(&snapshot->params);
71 
72 	kfree(snapshot->irq);
73 	kfree(snapshot->dmc);
74 	kfree(snapshot);
75 }
76