|
20 | 20 | #include "msm_mmu.h" |
21 | 21 | #include "msm_fence.h" |
22 | 22 |
|
| 23 | +#include <generated/utsrelease.h> |
23 | 24 | #include <linux/string_helpers.h> |
24 | 25 | #include <linux/pm_opp.h> |
25 | 26 | #include <linux/devfreq.h> |
26 | | - |
| 27 | +#include <linux/devcoredump.h> |
27 | 28 |
|
28 | 29 | /* |
29 | 30 | * Power Management: |
@@ -273,6 +274,81 @@ int msm_gpu_hw_init(struct msm_gpu *gpu) |
273 | 274 | return ret; |
274 | 275 | } |
275 | 276 |
|
| 277 | +#ifdef CONFIG_DEV_COREDUMP |
| 278 | +static ssize_t msm_gpu_devcoredump_read(char *buffer, loff_t offset, |
| 279 | + size_t count, void *data, size_t datalen) |
| 280 | +{ |
| 281 | + struct msm_gpu *gpu = data; |
| 282 | + struct drm_print_iterator iter; |
| 283 | + struct drm_printer p; |
| 284 | + struct msm_gpu_state *state; |
| 285 | + |
| 286 | + state = msm_gpu_crashstate_get(gpu); |
| 287 | + if (!state) |
| 288 | + return 0; |
| 289 | + |
| 290 | + iter.data = buffer; |
| 291 | + iter.offset = 0; |
| 292 | + iter.start = offset; |
| 293 | + iter.remain = count; |
| 294 | + |
| 295 | + p = drm_coredump_printer(&iter); |
| 296 | + |
| 297 | + drm_printf(&p, "---\n"); |
| 298 | + drm_printf(&p, "kernel: " UTS_RELEASE "\n"); |
| 299 | + drm_printf(&p, "module: " KBUILD_MODNAME "\n"); |
| 300 | + drm_printf(&p, "time: %ld.%ld\n", |
| 301 | + state->time.tv_sec, state->time.tv_usec); |
| 302 | + if (state->comm) |
| 303 | + drm_printf(&p, "comm: %s\n", state->comm); |
| 304 | + if (state->cmd) |
| 305 | + drm_printf(&p, "cmdline: %s\n", state->cmd); |
| 306 | + |
| 307 | + gpu->funcs->show(gpu, state, &p); |
| 308 | + |
| 309 | + msm_gpu_crashstate_put(gpu); |
| 310 | + |
| 311 | + return count - iter.remain; |
| 312 | +} |
| 313 | + |
| 314 | +static void msm_gpu_devcoredump_free(void *data) |
| 315 | +{ |
| 316 | + struct msm_gpu *gpu = data; |
| 317 | + |
| 318 | + msm_gpu_crashstate_put(gpu); |
| 319 | +} |
| 320 | + |
| 321 | +static void msm_gpu_crashstate_capture(struct msm_gpu *gpu, char *comm, |
| 322 | + char *cmd) |
| 323 | +{ |
| 324 | + struct msm_gpu_state *state; |
| 325 | + |
| 326 | + /* Only save one crash state at a time */ |
| 327 | + if (gpu->crashstate) |
| 328 | + return; |
| 329 | + |
| 330 | + state = gpu->funcs->gpu_state_get(gpu); |
| 331 | + if (IS_ERR_OR_NULL(state)) |
| 332 | + return; |
| 333 | + |
| 334 | + /* Fill in the additional crash state information */ |
| 335 | + state->comm = kstrdup(comm, GFP_KERNEL); |
| 336 | + state->cmd = kstrdup(cmd, GFP_KERNEL); |
| 337 | + |
| 338 | + /* Set the active crash state to be dumped on failure */ |
| 339 | + gpu->crashstate = state; |
| 340 | + |
| 341 | + /* FIXME: Release the crashstate if this errors out? */ |
| 342 | + dev_coredumpm(gpu->dev->dev, THIS_MODULE, gpu, 0, GFP_KERNEL, |
| 343 | + msm_gpu_devcoredump_read, msm_gpu_devcoredump_free); |
| 344 | +} |
| 345 | +#else |
| 346 | +static void msm_gpu_crashstate_capture(struct msm_gpu *gpu, char *comm, |
| 347 | + char *cmd) |
| 348 | +{ |
| 349 | +} |
| 350 | +#endif |
| 351 | + |
276 | 352 | /* |
277 | 353 | * Hangcheck detection for locked gpu: |
278 | 354 | */ |
@@ -356,6 +432,11 @@ static void recover_worker(struct work_struct *work) |
356 | 432 | msm_rd_dump_submit(priv->hangrd, submit, NULL); |
357 | 433 | } |
358 | 434 |
|
| 435 | + /* Record the crash state */ |
| 436 | + pm_runtime_get_sync(&gpu->pdev->dev); |
| 437 | + msm_gpu_crashstate_capture(gpu, comm, cmd); |
| 438 | + pm_runtime_put_sync(&gpu->pdev->dev); |
| 439 | + |
359 | 440 | kfree(cmd); |
360 | 441 | kfree(comm); |
361 | 442 |
|
|
0 commit comments