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_overlay_snapshot *overlay;
23 struct intel_dmc_snapshot *dmc;
24 struct intel_display_irq_snapshot *irq;
25 };
26
intel_display_snapshot_capture(struct intel_display * display)27 struct intel_display_snapshot *intel_display_snapshot_capture(struct intel_display *display)
28 {
29 struct intel_display_snapshot *snapshot;
30
31 snapshot = kzalloc(sizeof(*snapshot), GFP_ATOMIC);
32 if (!snapshot)
33 return NULL;
34
35 snapshot->display = display;
36
37 memcpy(&snapshot->info, DISPLAY_INFO(display), sizeof(snapshot->info));
38 memcpy(&snapshot->runtime_info, DISPLAY_RUNTIME_INFO(display),
39 sizeof(snapshot->runtime_info));
40
41 intel_display_params_copy(&snapshot->params);
42
43 snapshot->irq = intel_display_irq_snapshot_capture(display);
44 snapshot->overlay = intel_overlay_snapshot_capture(display);
45 snapshot->dmc = intel_dmc_snapshot_capture(display);
46
47 return snapshot;
48 }
49
intel_display_snapshot_print(const struct intel_display_snapshot * snapshot,struct drm_printer * p)50 void intel_display_snapshot_print(const struct intel_display_snapshot *snapshot,
51 struct drm_printer *p)
52 {
53 struct intel_display *display;
54
55 if (!snapshot)
56 return;
57
58 display = snapshot->display;
59
60 intel_display_device_info_print(&snapshot->info, &snapshot->runtime_info, p);
61 intel_display_params_dump(&snapshot->params, display->drm->driver->name, p);
62
63 intel_display_irq_snapshot_print(snapshot->irq, p);
64 intel_overlay_snapshot_print(snapshot->overlay, p);
65 intel_dmc_snapshot_print(snapshot->dmc, p);
66 }
67
intel_display_snapshot_free(struct intel_display_snapshot * snapshot)68 void intel_display_snapshot_free(struct intel_display_snapshot *snapshot)
69 {
70 if (!snapshot)
71 return;
72
73 intel_display_params_free(&snapshot->params);
74
75 kfree(snapshot->irq);
76 kfree(snapshot->overlay);
77 kfree(snapshot->dmc);
78 kfree(snapshot);
79 }
80