| 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 |  | 
|---|
| 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(to: &snapshot->info, DISPLAY_INFO(display), len: sizeof(snapshot->info)); | 
|---|
| 38 | memcpy(to: &snapshot->runtime_info, DISPLAY_RUNTIME_INFO(display), | 
|---|
| 39 | len: sizeof(snapshot->runtime_info)); | 
|---|
| 40 |  | 
|---|
| 41 | intel_display_params_copy(dest: &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 |  | 
|---|
| 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(info: &snapshot->info, runtime: &snapshot->runtime_info, p); | 
|---|
| 61 | intel_display_params_dump(params: &snapshot->params, driver_name: display->drm->driver->name, p); | 
|---|
| 62 |  | 
|---|
| 63 | intel_display_irq_snapshot_print(snapshot: snapshot->irq, p); | 
|---|
| 64 | intel_overlay_snapshot_print(error: snapshot->overlay, p); | 
|---|
| 65 | intel_dmc_snapshot_print(snapshot: snapshot->dmc, p); | 
|---|
| 66 | } | 
|---|
| 67 |  | 
|---|
| 68 | void intel_display_snapshot_free(struct intel_display_snapshot *snapshot) | 
|---|
| 69 | { | 
|---|
| 70 | if (!snapshot) | 
|---|
| 71 | return; | 
|---|
| 72 |  | 
|---|
| 73 | intel_display_params_free(params: &snapshot->params); | 
|---|
| 74 |  | 
|---|
| 75 | kfree(objp: snapshot->irq); | 
|---|
| 76 | kfree(objp: snapshot->overlay); | 
|---|
| 77 | kfree(objp: snapshot->dmc); | 
|---|
| 78 | kfree(objp: snapshot); | 
|---|
| 79 | } | 
|---|
| 80 |  | 
|---|