blob: 698db540972c3a09ec3f3147bd87eea156681f4a [file] [log] [blame]
Lucas Stachf6ffbd42018-05-08 16:20:54 +02001// SPDX-License-Identifier: GPL-2.0
The etnaviv authorsa8c21a52015-12-03 18:21:29 +01002/*
Lucas Stachf6ffbd42018-05-08 16:20:54 +02003 * Copyright (C) 2015-2018 Etnaviv Project
The etnaviv authorsa8c21a52015-12-03 18:21:29 +01004 */
5
6#include <linux/devcoredump.h>
Lucas Stach2e737e52019-07-04 12:43:37 +02007#include <linux/moduleparam.h>
8
Lucas Stachea1f5722017-01-16 16:09:51 +01009#include "etnaviv_cmdbuf.h"
The etnaviv authorsa8c21a52015-12-03 18:21:29 +010010#include "etnaviv_dump.h"
11#include "etnaviv_gem.h"
12#include "etnaviv_gpu.h"
13#include "etnaviv_mmu.h"
Lucas Stach6d7a20c2017-12-06 10:53:27 +010014#include "etnaviv_sched.h"
The etnaviv authorsa8c21a52015-12-03 18:21:29 +010015#include "state.xml.h"
16#include "state_hi.xml.h"
17
Lucas Stach6d7a20c2017-12-06 10:53:27 +010018static bool etnaviv_dump_core = true;
19module_param_named(dump_core, etnaviv_dump_core, bool, 0600);
20
The etnaviv authorsa8c21a52015-12-03 18:21:29 +010021struct core_dump_iterator {
22 void *start;
23 struct etnaviv_dump_object_header *hdr;
24 void *data;
25};
26
27static const unsigned short etnaviv_dump_registers[] = {
28 VIVS_HI_AXI_STATUS,
29 VIVS_HI_CLOCK_CONTROL,
30 VIVS_HI_IDLE_STATE,
31 VIVS_HI_AXI_CONFIG,
32 VIVS_HI_INTR_ENBL,
33 VIVS_HI_CHIP_IDENTITY,
34 VIVS_HI_CHIP_FEATURE,
35 VIVS_HI_CHIP_MODEL,
36 VIVS_HI_CHIP_REV,
37 VIVS_HI_CHIP_DATE,
38 VIVS_HI_CHIP_TIME,
39 VIVS_HI_CHIP_MINOR_FEATURE_0,
40 VIVS_HI_CACHE_CONTROL,
41 VIVS_HI_AXI_CONTROL,
42 VIVS_PM_POWER_CONTROLS,
43 VIVS_PM_MODULE_CONTROLS,
44 VIVS_PM_MODULE_STATUS,
45 VIVS_PM_PULSE_EATER,
46 VIVS_MC_MMU_FE_PAGE_TABLE,
47 VIVS_MC_MMU_TX_PAGE_TABLE,
48 VIVS_MC_MMU_PE_PAGE_TABLE,
49 VIVS_MC_MMU_PEZ_PAGE_TABLE,
50 VIVS_MC_MMU_RA_PAGE_TABLE,
51 VIVS_MC_DEBUG_MEMORY,
52 VIVS_MC_MEMORY_BASE_ADDR_RA,
53 VIVS_MC_MEMORY_BASE_ADDR_FE,
54 VIVS_MC_MEMORY_BASE_ADDR_TX,
55 VIVS_MC_MEMORY_BASE_ADDR_PEZ,
56 VIVS_MC_MEMORY_BASE_ADDR_PE,
57 VIVS_MC_MEMORY_TIMING_CONTROL,
58 VIVS_MC_BUS_CONFIG,
59 VIVS_FE_DMA_STATUS,
60 VIVS_FE_DMA_DEBUG_STATE,
61 VIVS_FE_DMA_ADDRESS,
62 VIVS_FE_DMA_LOW,
63 VIVS_FE_DMA_HIGH,
64 VIVS_FE_AUTO_FLUSH,
65};
66
67static void etnaviv_core_dump_header(struct core_dump_iterator *iter,
68 u32 type, void *data_end)
69{
70 struct etnaviv_dump_object_header *hdr = iter->hdr;
71
72 hdr->magic = cpu_to_le32(ETDUMP_MAGIC);
73 hdr->type = cpu_to_le32(type);
74 hdr->file_offset = cpu_to_le32(iter->data - iter->start);
75 hdr->file_size = cpu_to_le32(data_end - iter->data);
76
77 iter->hdr++;
78 iter->data += hdr->file_size;
79}
80
81static void etnaviv_core_dump_registers(struct core_dump_iterator *iter,
82 struct etnaviv_gpu *gpu)
83{
84 struct etnaviv_dump_registers *reg = iter->data;
85 unsigned int i;
86
87 for (i = 0; i < ARRAY_SIZE(etnaviv_dump_registers); i++, reg++) {
88 reg->reg = etnaviv_dump_registers[i];
89 reg->value = gpu_read(gpu, etnaviv_dump_registers[i]);
90 }
91
92 etnaviv_core_dump_header(iter, ETDUMP_BUF_REG, reg);
93}
94
95static void etnaviv_core_dump_mmu(struct core_dump_iterator *iter,
Lucas Stach27b67272019-07-05 19:17:24 +020096 struct etnaviv_iommu_context *mmu, size_t mmu_size)
The etnaviv authorsa8c21a52015-12-03 18:21:29 +010097{
Lucas Stach3001eeb2019-08-09 13:59:25 +020098 etnaviv_iommu_dump(mmu, iter->data);
The etnaviv authorsa8c21a52015-12-03 18:21:29 +010099
100 etnaviv_core_dump_header(iter, ETDUMP_BUF_MMU, iter->data + mmu_size);
101}
102
103static void etnaviv_core_dump_mem(struct core_dump_iterator *iter, u32 type,
104 void *ptr, size_t size, u64 iova)
105{
106 memcpy(iter->data, ptr, size);
107
108 iter->hdr->iova = cpu_to_le64(iova);
109
110 etnaviv_core_dump_header(iter, type, iter->data + size);
111}
112
Lucas Stach9a1fdae2019-08-09 13:58:02 +0200113void etnaviv_core_dump(struct etnaviv_gem_submit *submit)
The etnaviv authorsa8c21a52015-12-03 18:21:29 +0100114{
Lucas Stach9a1fdae2019-08-09 13:58:02 +0200115 struct etnaviv_gpu *gpu = submit->gpu;
The etnaviv authorsa8c21a52015-12-03 18:21:29 +0100116 struct core_dump_iterator iter;
The etnaviv authorsa8c21a52015-12-03 18:21:29 +0100117 struct etnaviv_gem_object *obj;
The etnaviv authorsa8c21a52015-12-03 18:21:29 +0100118 unsigned int n_obj, n_bomap_pages;
119 size_t file_size, mmu_size;
120 __le64 *bomap, *bomap_start;
Lucas Stach9a1fdae2019-08-09 13:58:02 +0200121 int i;
The etnaviv authorsa8c21a52015-12-03 18:21:29 +0100122
Lucas Stach6d7a20c2017-12-06 10:53:27 +0100123 /* Only catch the first event, or when manually re-armed */
124 if (!etnaviv_dump_core)
125 return;
126 etnaviv_dump_core = false;
127
Lucas Stach27b67272019-07-05 19:17:24 +0200128 mutex_lock(&gpu->mmu_context->lock);
Lucas Stach13965002019-05-21 14:53:40 +0200129
Lucas Stach27b67272019-07-05 19:17:24 +0200130 mmu_size = etnaviv_iommu_dump_size(gpu->mmu_context);
The etnaviv authorsa8c21a52015-12-03 18:21:29 +0100131
Lucas Stach9a1fdae2019-08-09 13:58:02 +0200132 /* We always dump registers, mmu, ring, hanging cmdbuf and end marker */
133 n_obj = 5;
The etnaviv authorsa8c21a52015-12-03 18:21:29 +0100134 n_bomap_pages = 0;
135 file_size = ARRAY_SIZE(etnaviv_dump_registers) *
136 sizeof(struct etnaviv_dump_registers) +
Lucas Stach9a1fdae2019-08-09 13:58:02 +0200137 mmu_size + gpu->buffer.size + submit->cmdbuf.size;
The etnaviv authorsa8c21a52015-12-03 18:21:29 +0100138
139 /* Add in the active buffer objects */
Lucas Stach9a1fdae2019-08-09 13:58:02 +0200140 for (i = 0; i < submit->nr_bos; i++) {
141 obj = submit->bos[i].obj;
The etnaviv authorsa8c21a52015-12-03 18:21:29 +0100142 file_size += obj->base.size;
143 n_bomap_pages += obj->base.size >> PAGE_SHIFT;
144 n_obj++;
145 }
146
147 /* If we have any buffer objects, add a bomap object */
148 if (n_bomap_pages) {
149 file_size += n_bomap_pages * sizeof(__le64);
150 n_obj++;
151 }
152
153 /* Add the size of the headers */
154 file_size += sizeof(*iter.hdr) * n_obj;
155
156 /* Allocate the file in vmalloc memory, it's likely to be big */
Michal Hocko19809c22017-05-08 15:57:44 -0700157 iter.start = __vmalloc(file_size, GFP_KERNEL | __GFP_NOWARN | __GFP_NORETRY,
158 PAGE_KERNEL);
The etnaviv authorsa8c21a52015-12-03 18:21:29 +0100159 if (!iter.start) {
Lucas Stach27b67272019-07-05 19:17:24 +0200160 mutex_unlock(&gpu->mmu_context->lock);
The etnaviv authorsa8c21a52015-12-03 18:21:29 +0100161 dev_warn(gpu->dev, "failed to allocate devcoredump file\n");
162 return;
163 }
164
165 /* Point the data member after the headers */
166 iter.hdr = iter.start;
167 iter.data = &iter.hdr[n_obj];
168
169 memset(iter.hdr, 0, iter.data - iter.start);
170
171 etnaviv_core_dump_registers(&iter, gpu);
Lucas Stach27b67272019-07-05 19:17:24 +0200172 etnaviv_core_dump_mmu(&iter, gpu->mmu_context, mmu_size);
Lucas Stach2f9225d2017-11-24 16:56:37 +0100173 etnaviv_core_dump_mem(&iter, ETDUMP_BUF_RING, gpu->buffer.vaddr,
174 gpu->buffer.size,
Lucas Stachdb82a042019-07-05 19:17:21 +0200175 etnaviv_cmdbuf_get_va(&gpu->buffer,
Lucas Stach17e46602019-07-05 19:17:27 +0200176 &gpu->mmu_context->cmdbuf_mapping));
The etnaviv authorsa8c21a52015-12-03 18:21:29 +0100177
Lucas Stach9a1fdae2019-08-09 13:58:02 +0200178 etnaviv_core_dump_mem(&iter, ETDUMP_BUF_CMD,
179 submit->cmdbuf.vaddr, submit->cmdbuf.size,
Lucas Stachdb82a042019-07-05 19:17:21 +0200180 etnaviv_cmdbuf_get_va(&submit->cmdbuf,
Lucas Stach17e46602019-07-05 19:17:27 +0200181 &gpu->mmu_context->cmdbuf_mapping));
The etnaviv authorsa8c21a52015-12-03 18:21:29 +0100182
183 /* Reserve space for the bomap */
184 if (n_bomap_pages) {
185 bomap_start = bomap = iter.data;
186 memset(bomap, 0, sizeof(*bomap) * n_bomap_pages);
187 etnaviv_core_dump_header(&iter, ETDUMP_BUF_BOMAP,
188 bomap + n_bomap_pages);
189 } else {
190 /* Silence warning */
191 bomap_start = bomap = NULL;
192 }
193
Lucas Stach9a1fdae2019-08-09 13:58:02 +0200194 for (i = 0; i < submit->nr_bos; i++) {
195 struct etnaviv_vram_mapping *vram;
The etnaviv authorsa8c21a52015-12-03 18:21:29 +0100196 struct page **pages;
197 void *vaddr;
198
Lucas Stach9a1fdae2019-08-09 13:58:02 +0200199 obj = submit->bos[i].obj;
200 vram = submit->bos[i].mapping;
The etnaviv authorsa8c21a52015-12-03 18:21:29 +0100201
Lucas Stach339073e2016-01-22 12:03:03 +0100202 mutex_lock(&obj->lock);
The etnaviv authorsa8c21a52015-12-03 18:21:29 +0100203 pages = etnaviv_gem_get_pages(obj);
Lucas Stach339073e2016-01-22 12:03:03 +0100204 mutex_unlock(&obj->lock);
Dan Carpenterf8261c32019-01-14 13:49:46 +0300205 if (!IS_ERR(pages)) {
The etnaviv authorsa8c21a52015-12-03 18:21:29 +0100206 int j;
207
208 iter.hdr->data[0] = bomap - bomap_start;
209
210 for (j = 0; j < obj->base.size >> PAGE_SHIFT; j++)
211 *bomap++ = cpu_to_le64(page_to_phys(*pages++));
212 }
213
214 iter.hdr->iova = cpu_to_le64(vram->iova);
215
Lucas Stachce3088f2016-01-26 18:10:32 +0100216 vaddr = etnaviv_gem_vmap(&obj->base);
Lucas Stach9f07bb02016-01-25 15:37:28 +0100217 if (vaddr)
The etnaviv authorsa8c21a52015-12-03 18:21:29 +0100218 memcpy(iter.data, vaddr, obj->base.size);
219
220 etnaviv_core_dump_header(&iter, ETDUMP_BUF_BO, iter.data +
221 obj->base.size);
222 }
223
Lucas Stach27b67272019-07-05 19:17:24 +0200224 mutex_unlock(&gpu->mmu_context->lock);
Lucas Stach13965002019-05-21 14:53:40 +0200225
The etnaviv authorsa8c21a52015-12-03 18:21:29 +0100226 etnaviv_core_dump_header(&iter, ETDUMP_BUF_END, iter.data);
227
228 dev_coredumpv(gpu->dev, iter.start, iter.data - iter.start, GFP_KERNEL);
229}