1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Copyright (C) 2020-2024 Intel Corporation 4 */ 5 6 #include <linux/devcoredump.h> 7 #include <linux/firmware.h> 8 9 #include "ivpu_coredump.h" 10 #include "ivpu_fw.h" 11 #include "ivpu_gem.h" 12 #include "vpu_boot_api.h" 13 14 #define CRASH_DUMP_HEADER "Intel NPU crash dump" 15 #define CRASH_DUMP_HEADERS_SIZE SZ_4K 16 17 void ivpu_dev_coredump(struct ivpu_device *vdev) 18 { 19 struct drm_print_iterator pi = {}; 20 struct drm_printer p; 21 size_t coredump_size; 22 char *coredump; 23 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; 29 30 pi.data = coredump; 31 pi.remain = coredump_size; 32 p = drm_coredump_printer(&pi); 33 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); 37 38 dev_coredumpv(vdev->drm.dev, coredump, pi.offset, GFP_KERNEL); 39 } 40