|
| 1 | +/* |
| 2 | + * Copyright (c) 2023 Intel Corporation. |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#include <errno.h> |
| 8 | +#include <zephyr/sys/util.h> |
| 9 | + |
| 10 | +#include <zephyr/debug/coredump.h> |
| 11 | +#include "coredump_internal.h" |
| 12 | + |
| 13 | +#include <zephyr/logging/log.h> |
| 14 | +#include <zephyr/logging/log_ctrl.h> |
| 15 | +#include <adsp_memory.h> |
| 16 | +#include <adsp_debug_window.h> |
| 17 | +LOG_MODULE_REGISTER(coredump_error, CONFIG_KERNEL_LOG_LEVEL); |
| 18 | + |
| 19 | +static int error; |
| 20 | + |
| 21 | +static void coredump_mem_window_backend_start(void) |
| 22 | +{ |
| 23 | + /* Reset error */ |
| 24 | + error = 0; |
| 25 | + ADSP_DW->descs[1].type = ADSP_DW_SLOT_TELEMETRY; |
| 26 | + |
| 27 | + while (LOG_PROCESS()) { |
| 28 | + ; |
| 29 | + } |
| 30 | + |
| 31 | + LOG_PANIC(); |
| 32 | + LOG_ERR(COREDUMP_PREFIX_STR COREDUMP_BEGIN_STR); |
| 33 | +} |
| 34 | + |
| 35 | +static void coredump_mem_window_backend_end(void) |
| 36 | +{ |
| 37 | + if (error != 0) { |
| 38 | + LOG_ERR(COREDUMP_PREFIX_STR COREDUMP_ERROR_STR); |
| 39 | + } |
| 40 | + |
| 41 | + LOG_ERR(COREDUMP_PREFIX_STR COREDUMP_END_STR); |
| 42 | +} |
| 43 | + |
| 44 | +static void coredump_mem_window_backend_buffer_output(uint8_t *buf, size_t buflen) |
| 45 | +{ |
| 46 | + uint32_t *mem_window_separator = (uint32_t *)(ADSP_DW->slots[1]); |
| 47 | + uint8_t *mem_window_sink = (uint8_t *)(ADSP_DW->slots[1]) + 4; |
| 48 | + uint8_t *coredump_data = buf; |
| 49 | + size_t data_left; |
| 50 | + /* Default place for telemetry dump is in memory window. Each data is easily find using |
| 51 | + * separator. For telemetry that separator is 0x0DEC0DEB. |
| 52 | + */ |
| 53 | + *mem_window_separator = 0x0DEC0DEB; |
| 54 | + |
| 55 | + if (buf) { |
| 56 | + for (data_left = buflen; data_left > 0; data_left--) { |
| 57 | + *mem_window_sink = *coredump_data; |
| 58 | + mem_window_sink++; |
| 59 | + coredump_data++; |
| 60 | + } |
| 61 | + } else { |
| 62 | + error = -EINVAL; |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +static int coredump_mem_window_backend_query(enum coredump_query_id query_id, |
| 67 | + void *arg) |
| 68 | +{ |
| 69 | + int ret; |
| 70 | + |
| 71 | + switch (query_id) { |
| 72 | + case COREDUMP_QUERY_GET_ERROR: |
| 73 | + ret = error; |
| 74 | + break; |
| 75 | + default: |
| 76 | + ret = -ENOTSUP; |
| 77 | + break; |
| 78 | + } |
| 79 | + |
| 80 | + return ret; |
| 81 | +} |
| 82 | + |
| 83 | +static int coredump_mem_window_backend_cmd(enum coredump_cmd_id cmd_id, |
| 84 | + void *arg) |
| 85 | +{ |
| 86 | + int ret; |
| 87 | + |
| 88 | + switch (cmd_id) { |
| 89 | + case COREDUMP_CMD_CLEAR_ERROR: |
| 90 | + ret = 0; |
| 91 | + error = 0; |
| 92 | + break; |
| 93 | + default: |
| 94 | + ret = -ENOTSUP; |
| 95 | + break; |
| 96 | + } |
| 97 | + |
| 98 | + return ret; |
| 99 | +} |
| 100 | + |
| 101 | +struct coredump_backend_api coredump_backend_intel_adsp_mem_window = { |
| 102 | + .start = coredump_mem_window_backend_start, |
| 103 | + .end = coredump_mem_window_backend_end, |
| 104 | + .buffer_output = coredump_mem_window_backend_buffer_output, |
| 105 | + .query = coredump_mem_window_backend_query, |
| 106 | + .cmd = coredump_mem_window_backend_cmd, |
| 107 | +}; |
0 commit comments