OSDN Git Service

Merge android-4.4.143 (7bbfac1) into msm-4.4
[sagit-ice-cold/kernel_xiaomi_msm8998.git] / drivers / gpu / drm / msm / msm_snapshot.c
1 /* Copyright (c) 2016 The Linux Foundation. All rights reserved.
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 and
5  * only version 2 as published by the Free Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  */
12
13 #include "msm_gpu.h"
14 #include "msm_gem.h"
15 #include "msm_snapshot_api.h"
16
17 void msm_snapshot_destroy(struct msm_gpu *gpu, struct msm_snapshot *snapshot)
18 {
19         struct drm_device *dev = gpu->dev;
20         struct msm_drm_private *priv = dev->dev_private;
21         struct platform_device *pdev = priv->gpu_pdev;
22
23         if (!snapshot)
24                 return;
25
26         dma_free_coherent(&pdev->dev, SZ_1M, snapshot->ptr,
27                 snapshot->physaddr);
28
29         kfree(snapshot);
30 }
31
32 struct msm_snapshot *msm_snapshot_new(struct msm_gpu *gpu)
33 {
34         struct drm_device *dev = gpu->dev;
35         struct msm_drm_private *priv = dev->dev_private;
36         struct platform_device *pdev = priv->gpu_pdev;
37         struct msm_snapshot *snapshot;
38
39         snapshot = kzalloc(sizeof(*snapshot), GFP_KERNEL);
40         if (!snapshot)
41                 return ERR_PTR(-ENOMEM);
42
43         snapshot->ptr = dma_alloc_coherent(&pdev->dev, SZ_1M,
44                 &snapshot->physaddr, GFP_KERNEL);
45
46         if (!snapshot->ptr) {
47                 kfree(snapshot);
48                 return ERR_PTR(-ENOMEM);
49         }
50
51         seq_buf_init(&snapshot->buf, snapshot->ptr, SZ_1M);
52
53         return snapshot;
54 }
55
56 int msm_gpu_snapshot(struct msm_gpu *gpu, struct msm_snapshot *snapshot)
57 {
58         int ret;
59         struct msm_snapshot_header header;
60         uint64_t val;
61
62         if (!snapshot)
63                 return -ENOMEM;
64
65         /*
66          * For now, blow away the snapshot and take a new one  - the most
67          * interesting hang is the last one we saw
68          */
69         seq_buf_init(&snapshot->buf, snapshot->ptr, SZ_1M);
70
71         header.magic = SNAPSHOT_MAGIC;
72         gpu->funcs->get_param(gpu, MSM_PARAM_GPU_ID, &val);
73         header.gpuid = lower_32_bits(val);
74
75         gpu->funcs->get_param(gpu, MSM_PARAM_CHIP_ID, &val);
76         header.chipid = lower_32_bits(val);
77
78         seq_buf_putmem(&snapshot->buf, &header, sizeof(header));
79
80         ret = gpu->funcs->snapshot(gpu, snapshot);
81
82         if (!ret) {
83                 struct msm_snapshot_section_header end;
84
85                 end.magic = SNAPSHOT_SECTION_MAGIC;
86                 end.id = SNAPSHOT_SECTION_END;
87                 end.size = sizeof(end);
88
89                 seq_buf_putmem(&snapshot->buf, &end, sizeof(end));
90
91                 dev_info(gpu->dev->dev, "GPU snapshot created [0x%pa (%d bytes)]\n",
92                         &snapshot->physaddr, seq_buf_used(&snapshot->buf));
93         }
94
95         return ret;
96 }
97
98 int msm_snapshot_write(struct msm_gpu *gpu, struct seq_file *m)
99 {
100         if (gpu && gpu->snapshot)
101                 seq_write(m, gpu->snapshot->ptr,
102                         seq_buf_used(&gpu->snapshot->buf));
103
104         return 0;
105 }