1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
4  */
5 
6 #ifndef MSM_DISP_SNAPSHOT_H_
7 #define MSM_DISP_SNAPSHOT_H_
8 
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>
23 #include <linux/pm.h>
24 #include <linux/pm_runtime.h>
25 #include <linux/kthread.h>
26 #include <linux/devcoredump.h>
27 #include <stdarg.h>
28 #include "msm_kms.h"
29 
30 #define MSM_DISP_SNAPSHOT_MAX_BLKS		10
31 
32 /* debug option to print the registers in logs */
33 #define MSM_DISP_SNAPSHOT_DUMP_IN_CONSOLE 0
34 
35 /* print debug ranges in groups of 4 u32s */
36 #define REG_DUMP_ALIGN		16
37 
38 /**
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
44  */
45 struct msm_disp_state {
46 	struct device *dev;
47 	struct drm_device *drm_dev;
48 
49 	struct list_head blocks;
50 
51 	struct drm_atomic_state *atomic_state;
52 
53 	ktime_t timestamp;
54 };
55 
56 /**
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
63  */
64 struct msm_disp_state_block {
65 	char name[SZ_128];
66 	struct list_head node;
67 	unsigned int size;
68 	u32 *state;
69 	void __iomem *base_addr;
70 };
71 
72 /**
73  * msm_disp_snapshot_init - initialize display snapshot
74  * @drm_dev:	drm device handle
75  *
76  * Returns:		0 or -ERROR
77  */
78 int msm_disp_snapshot_init(struct drm_device *drm_dev);
79 
80 /**
81  * msm_disp_snapshot_destroy - destroy the display snapshot
82  * @drm_dev:    drm device handle
83  *
84  * Returns:	none
85  */
86 void msm_disp_snapshot_destroy(struct drm_device *drm_dev);
87 
88 /**
89  * msm_disp_snapshot_state - trigger to dump the display snapshot
90  * @drm_dev:	handle to drm device
91 
92  * Returns:	none
93  */
94 void msm_disp_snapshot_state(struct drm_device *drm_dev);
95 
96 /**
97  * msm_disp_state_print - print out the current dpu state
98  * @disp_state:	    handle to drm device
99  * @p:	    handle to drm printer
100  *
101  * Returns:	none
102  */
103 void msm_disp_state_print(struct msm_disp_state *disp_state, struct drm_printer *p);
104 
105 /**
106  * msm_disp_snapshot_capture_state - utility to capture atomic state and hw registers
107  * @disp_state:	    handle to msm_disp_state struct
108 
109  * Returns:	none
110  */
111 void msm_disp_snapshot_capture_state(struct msm_disp_state *disp_state);
112 
113 /**
114  * msm_disp_state_free - free the memory after the coredump has been read
115  * @data:	    handle to struct msm_disp_state
116 
117  * Returns: none
118  */
119 void msm_disp_state_free(void *data);
120 
121 /**
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
128  *
129  * Returns: none
130  */
131 __printf(4, 5)
132 void msm_disp_snapshot_add_block(struct msm_disp_state *disp_state, u32 len,
133 		void __iomem *base_addr, const char *fmt, ...);
134 
135 #endif /* MSM_DISP_SNAPSHOT_H_ */
136