Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / accel / ivpu / ivpu_coredump.c
blob16ad0c30818ccf9d33f303b9d036e3c7592efe5e
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (C) 2020-2024 Intel Corporation
4 */
6 #include <linux/devcoredump.h>
7 #include <linux/firmware.h>
9 #include "ivpu_coredump.h"
10 #include "ivpu_fw.h"
11 #include "ivpu_gem.h"
12 #include "vpu_boot_api.h"
14 #define CRASH_DUMP_HEADER "Intel NPU crash dump"
15 #define CRASH_DUMP_HEADERS_SIZE SZ_4K
17 void ivpu_dev_coredump(struct ivpu_device *vdev)
19 struct drm_print_iterator pi = {};
20 struct drm_printer p;
21 size_t coredump_size;
22 char *coredump;
24 coredump_size = CRASH_DUMP_HEADERS_SIZE + FW_VERSION_HEADER_SIZE +
25 ivpu_bo_size(vdev->fw->mem_log_crit) + ivpu_bo_size(vdev->fw->mem_log_verb);
26 coredump = vmalloc(coredump_size);
27 if (!coredump)
28 return;
30 pi.data = coredump;
31 pi.remain = coredump_size;
32 p = drm_coredump_printer(&pi);
34 drm_printf(&p, "%s\n", CRASH_DUMP_HEADER);
35 drm_printf(&p, "FW version: %s\n", vdev->fw->version);
36 ivpu_fw_log_print(vdev, false, &p);
38 dev_coredumpv(vdev->drm.dev, coredump, pi.offset, GFP_KERNEL);