1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
6 #ifndef MSM_DISP_SNAPSHOT_H_
7 #define MSM_DISP_SNAPSHOT_H_
9 #include <drm/drm_atomic_helper.h>
10 #include <drm/drm_device.h>
11 #include "../../../drm_crtc_internal.h"
12 #include <drm/drm_print.h>
13 #include <drm/drm_atomic.h>
14 #include <linux/debugfs.h>
15 #include <linux/list.h>
16 #include <linux/delay.h>
17 #include <linux/spinlock.h>
18 #include <linux/ktime.h>
19 #include <linux/uaccess.h>
20 #include <linux/dma-buf.h>
21 #include <linux/slab.h>
22 #include <linux/list_sort.h>
24 #include <linux/pm_runtime.h>
25 #include <linux/kthread.h>
26 #include <linux/devcoredump.h>
30 #define MSM_DISP_SNAPSHOT_MAX_BLKS 10
32 /* debug option to print the registers in logs */
33 #define MSM_DISP_SNAPSHOT_DUMP_IN_CONSOLE 0
35 /* print debug ranges in groups of 4 u32s */
36 #define REG_DUMP_ALIGN 16
39 * struct msm_disp_state - structure to store current dpu state
40 * @dev: device pointer
41 * @drm_dev: drm device pointer
42 * @atomic_state: atomic state duplicated at the time of the error
43 * @timestamp: timestamp at which the coredump was captured
45 struct msm_disp_state {
47 struct drm_device *drm_dev;
49 struct list_head blocks;
51 struct drm_atomic_state *atomic_state;
57 * struct msm_disp_state_block - structure to store each hardware block state
58 * @name: name of the block
59 * @drm_dev: handle to the linked list head
60 * @size: size of the register space of this hardware block
61 * @state: array holding the register dump of this hardware block
62 * @base_addr: starting address of this hardware block's register space
64 struct msm_disp_state_block {
66 struct list_head node;
69 void __iomem *base_addr;
73 * msm_disp_snapshot_init - initialize display snapshot
74 * @drm_dev: drm device handle
76 * Returns: 0 or -ERROR
78 int msm_disp_snapshot_init(struct drm_device *drm_dev);
81 * msm_disp_snapshot_destroy - destroy the display snapshot
82 * @drm_dev: drm device handle
86 void msm_disp_snapshot_destroy(struct drm_device *drm_dev);
89 * msm_disp_snapshot_state - trigger to dump the display snapshot
90 * @drm_dev: handle to drm device
94 void msm_disp_snapshot_state(struct drm_device *drm_dev);
97 * msm_disp_state_print - print out the current dpu state
98 * @disp_state: handle to drm device
99 * @p: handle to drm printer
103 void msm_disp_state_print(struct msm_disp_state *disp_state, struct drm_printer *p);
106 * msm_disp_snapshot_capture_state - utility to capture atomic state and hw registers
107 * @disp_state: handle to msm_disp_state struct
111 void msm_disp_snapshot_capture_state(struct msm_disp_state *disp_state);
114 * msm_disp_state_free - free the memory after the coredump has been read
115 * @data: handle to struct msm_disp_state
119 void msm_disp_state_free(void *data);
122 * msm_disp_snapshot_add_block - add a hardware block with its register dump
123 * @disp_state: handle to struct msm_disp_state
124 * @name: name of the hardware block
125 * @len: size of the register space of the hardware block
126 * @base_addr: starting address of the register space of the hardware block
127 * @fmt: format in which the block names need to be printed
132 void msm_disp_snapshot_add_block(struct msm_disp_state *disp_state, u32 len,
133 void __iomem *base_addr, const char *fmt, ...);
135 #endif /* MSM_DISP_SNAPSHOT_H_ */