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/debugfs.h>
20 #include <linux/uaccess.h>
21 #include <linux/dma-buf.h>
22 #include <linux/slab.h>
23 #include <linux/list_sort.h>
25 #include <linux/pm_runtime.h>
26 #include <linux/kthread.h>
27 #include <linux/devcoredump.h>
31 #define MSM_DISP_SNAPSHOT_MAX_BLKS 10
33 /* debug option to print the registers in logs */
34 #define MSM_DISP_SNAPSHOT_DUMP_IN_CONSOLE 0
36 /* print debug ranges in groups of 4 u32s */
37 #define REG_DUMP_ALIGN 16
40 * struct msm_disp_state - structure to store current dpu state
41 * @dev: device pointer
42 * @drm_dev: drm device pointer
43 * @atomic_state: atomic state duplicated at the time of the error
44 * @timestamp: timestamp at which the coredump was captured
46 struct msm_disp_state {
48 struct drm_device *drm_dev;
50 struct list_head blocks;
52 struct drm_atomic_state *atomic_state;
58 * struct msm_disp_state_block - structure to store each hardware block state
59 * @name: name of the block
60 * @drm_dev: handle to the linked list head
61 * @size: size of the register space of this hardware block
62 * @state: array holding the register dump of this hardware block
63 * @base_addr: starting address of this hardware block's register space
65 struct msm_disp_state_block {
67 struct list_head node;
70 void __iomem *base_addr;
74 * msm_disp_snapshot_init - initialize display snapshot
75 * @drm_dev: drm device handle
77 * Returns: 0 or -ERROR
79 int msm_disp_snapshot_init(struct drm_device *drm_dev);
82 * msm_disp_snapshot_destroy - destroy the display snapshot
83 * @drm_dev: drm device handle
87 void msm_disp_snapshot_destroy(struct drm_device *drm_dev);
90 * msm_disp_snapshot_state - trigger to dump the display snapshot
91 * @drm_dev: handle to drm device
95 void msm_disp_snapshot_state(struct drm_device *drm_dev);
98 * msm_disp_state_print - print out the current dpu state
99 * @disp_state: handle to drm device
100 * @p: handle to drm printer
104 void msm_disp_state_print(struct msm_disp_state *disp_state, struct drm_printer *p);
107 * msm_disp_snapshot_capture_state - utility to capture atomic state and hw registers
108 * @disp_state: handle to msm_disp_state struct
112 void msm_disp_snapshot_capture_state(struct msm_disp_state *disp_state);
115 * msm_disp_state_free - free the memory after the coredump has been read
116 * @data: handle to struct msm_disp_state
120 void msm_disp_state_free(void *data);
123 * msm_disp_snapshot_add_block - add a hardware block with its register dump
124 * @disp_state: handle to struct msm_disp_state
125 * @name: name of the hardware block
126 * @len: size of the register space of the hardware block
127 * @base_addr: starting address of the register space of the hardware block
128 * @fmt: format in which the block names need to be printed
133 void msm_disp_snapshot_add_block(struct msm_disp_state *disp_state, u32 len,
134 void __iomem *base_addr, const char *fmt, ...);
136 #endif /* MSM_DISP_SNAPSHOT_H_ */