1 /* Copyright (c) 2016 The Linux Foundation. All rights reserved.
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.
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.
15 #include "msm_snapshot_api.h"
17 void msm_snapshot_destroy(struct msm_gpu *gpu, struct msm_snapshot *snapshot)
19 struct drm_device *dev = gpu->dev;
20 struct msm_drm_private *priv = dev->dev_private;
21 struct platform_device *pdev = priv->gpu_pdev;
26 dma_free_coherent(&pdev->dev, SZ_1M, snapshot->ptr,
32 struct msm_snapshot *msm_snapshot_new(struct msm_gpu *gpu)
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;
39 snapshot = kzalloc(sizeof(*snapshot), GFP_KERNEL);
41 return ERR_PTR(-ENOMEM);
43 snapshot->ptr = dma_alloc_coherent(&pdev->dev, SZ_1M,
44 &snapshot->physaddr, GFP_KERNEL);
48 return ERR_PTR(-ENOMEM);
51 seq_buf_init(&snapshot->buf, snapshot->ptr, SZ_1M);
56 int msm_gpu_snapshot(struct msm_gpu *gpu, struct msm_snapshot *snapshot)
59 struct msm_snapshot_header header;
66 * For now, blow away the snapshot and take a new one - the most
67 * interesting hang is the last one we saw
69 seq_buf_init(&snapshot->buf, snapshot->ptr, SZ_1M);
71 header.magic = SNAPSHOT_MAGIC;
72 gpu->funcs->get_param(gpu, MSM_PARAM_GPU_ID, &val);
73 header.gpuid = lower_32_bits(val);
75 gpu->funcs->get_param(gpu, MSM_PARAM_CHIP_ID, &val);
76 header.chipid = lower_32_bits(val);
78 seq_buf_putmem(&snapshot->buf, &header, sizeof(header));
80 ret = gpu->funcs->snapshot(gpu, snapshot);
83 struct msm_snapshot_section_header end;
85 end.magic = SNAPSHOT_SECTION_MAGIC;
86 end.id = SNAPSHOT_SECTION_END;
87 end.size = sizeof(end);
89 seq_buf_putmem(&snapshot->buf, &end, sizeof(end));
91 dev_info(gpu->dev->dev, "GPU snapshot created [0x%pa (%d bytes)]\n",
92 &snapshot->physaddr, seq_buf_used(&snapshot->buf));
98 int msm_snapshot_write(struct msm_gpu *gpu, struct seq_file *m)
100 if (gpu && gpu->snapshot)
101 seq_write(m, gpu->snapshot->ptr,
102 seq_buf_used(&gpu->snapshot->buf));