| 1 |
// SPDX-License-Identifier: GPL-2.0-only |
| 2 |
// |
| 3 |
// Copyright(c) 2021-2022 Intel Corporation |
| 4 |
// |
| 5 |
// Authors: Cezary Rojewski <[email protected]> |
| 6 |
// Amadeusz Slawinski <[email protected]> |
| 7 |
// |
| 8 |
|
| 9 |
#include <linux/devcoredump.h> |
| 10 |
#include <linux/slab.h> |
| 11 |
#include <sound/hdaudio_ext.h> |
| 12 |
#include "avs.h" |
| 13 |
#include "debug.h" |
| 14 |
#include "messages.h" |
| 15 |
#include "path.h" |
| 16 |
#include "registers.h" |
| 17 |
#include "topology.h" |
| 18 |
|
| 19 |
static irqreturn_t avs_apl_dsp_interrupt(struct avs_dev *adev) |
| 20 |
{ |
| 21 |
u32 adspis = snd_hdac_adsp_readl(adev, AVS_ADSP_REG_ADSPIS); |
| 22 |
irqreturn_t ret = IRQ_NONE; |
| 23 |
|
| 24 |
if (adspis == UINT_MAX) |
| 25 |
return ret; |
| 26 |
|
| 27 |
if (adspis & AVS_ADSP_ADSPIS_IPC) { |
| 28 |
avs_skl_ipc_interrupt(adev); |
| 29 |
ret = IRQ_HANDLED; |
| 30 |
} |
| 31 |
|
| 32 |
return ret; |
| 33 |
} |
| 34 |
|
| 35 |
#ifdef CONFIG_DEBUG_FS |
| 36 |
int avs_apl_enable_logs(struct avs_dev *adev, enum avs_log_enable enable, u32 aging_period, |
| 37 |
u32 fifo_full_period, unsigned long resource_mask, u32 *priorities) |
| 38 |
{ |
| 39 |
struct avs_apl_log_state_info *info; |
| 40 |
u32 size, num_cores = adev->hw_cfg.dsp_cores; |
| 41 |
int ret, i; |
| 42 |
|
| 43 |
if (fls_long(resource_mask) > num_cores) |
| 44 |
return -EINVAL; |
| 45 |
size = struct_size(info, logs_core, num_cores); |
| 46 |
info = kzalloc(size, GFP_KERNEL); |
| 47 |
if (!info) |
| 48 |
return -ENOMEM; |
| 49 |
|
| 50 |
info->aging_timer_period = aging_period; |
| 51 |
info->fifo_full_timer_period = fifo_full_period; |
| 52 |
info->core_mask = resource_mask; |
| 53 |
if (enable) |
| 54 |
for_each_set_bit(i, &resource_mask, num_cores) { |
| 55 |
info->logs_core[i].enable = enable; |
| 56 |
info->logs_core[i].min_priority = *priorities++; |
| 57 |
} |
| 58 |
else |
| 59 |
for_each_set_bit(i, &resource_mask, num_cores) |
| 60 |
info->logs_core[i].enable = enable; |
| 61 |
|
| 62 |
ret = avs_ipc_set_enable_logs(adev, (u8 *)info, size); |
| 63 |
kfree(info); |
| 64 |
if (ret) |
| 65 |
return AVS_IPC_RET(ret); |
| 66 |
|
| 67 |
return 0; |
| 68 |
} |
| 69 |
#endif |
| 70 |
|
| 71 |
int avs_apl_log_buffer_status(struct avs_dev *adev, union avs_notify_msg *msg) |
| 72 |
{ |
| 73 |
struct avs_apl_log_buffer_layout layout; |
| 74 |
void __iomem *addr, *buf; |
| 75 |
|
| 76 |
addr = avs_log_buffer_addr(adev, msg->log.core); |
| 77 |
if (!addr) |
| 78 |
return -ENXIO; |
| 79 |
|
| 80 |
memcpy_fromio(&layout, addr, sizeof(layout)); |
| 81 |
|
| 82 |
if (!avs_logging_fw(adev)) |
| 83 |
/* consume the logs regardless of consumer presence */ |
| 84 |
goto update_read_ptr; |
| 85 |
|
| 86 |
buf = avs_apl_log_payload_addr(addr); |
| 87 |
|
| 88 |
if (layout.read_ptr > layout.write_ptr) { |
| 89 |
avs_dump_fw_log(adev, buf + layout.read_ptr, |
| 90 |
avs_apl_log_payload_size(adev) - layout.read_ptr); |
| 91 |
layout.read_ptr = 0; |
| 92 |
} |
| 93 |
avs_dump_fw_log_wakeup(adev, buf + layout.read_ptr, layout.write_ptr - layout.read_ptr); |
| 94 |
|
| 95 |
update_read_ptr: |
| 96 |
writel(layout.write_ptr, addr); |
| 97 |
return 0; |
| 98 |
} |
| 99 |
|
| 100 |
static int avs_apl_wait_log_entry(struct avs_dev *adev, u32 core, |
| 101 |
struct avs_apl_log_buffer_layout *layout) |
| 102 |
{ |
| 103 |
unsigned long timeout; |
| 104 |
void __iomem *addr; |
| 105 |
|
| 106 |
addr = avs_log_buffer_addr(adev, core); |
| 107 |
if (!addr) |
| 108 |
return -ENXIO; |
| 109 |
|
| 110 |
timeout = jiffies + msecs_to_jiffies(10); |
| 111 |
|
| 112 |
do { |
| 113 |
memcpy_fromio(layout, addr, sizeof(*layout)); |
| 114 |
if (layout->read_ptr != layout->write_ptr) |
| 115 |
return 0; |
| 116 |
usleep_range(500, 1000); |
| 117 |
} while (!time_after(jiffies, timeout)); |
| 118 |
|
| 119 |
return -ETIMEDOUT; |
| 120 |
} |
| 121 |
|
| 122 |
/* reads log header and tests its type */ |
| 123 |
#define avs_apl_is_entry_stackdump(addr) ((readl(addr) >> 30) & 0x1) |
| 124 |
|
| 125 |
int avs_apl_coredump(struct avs_dev *adev, union avs_notify_msg *msg) |
| 126 |
{ |
| 127 |
struct avs_apl_log_buffer_layout layout; |
| 128 |
void __iomem *addr, *buf; |
| 129 |
size_t dump_size; |
| 130 |
u32 offset = 0; |
| 131 |
u8 *dump, *pos; |
| 132 |
|
| 133 |
dump_size = AVS_FW_REGS_SIZE + msg->ext.coredump.stack_dump_size; |
| 134 |
dump = vzalloc(dump_size); |
| 135 |
if (!dump) |
| 136 |
return -ENOMEM; |
| 137 |
|
| 138 |
memcpy_fromio(dump, avs_sram_addr(adev, AVS_FW_REGS_WINDOW), AVS_FW_REGS_SIZE); |
| 139 |
|
| 140 |
if (!msg->ext.coredump.stack_dump_size) |
| 141 |
goto exit; |
| 142 |
|
| 143 |
/* Dump the registers even if an external error prevents gathering the stack. */ |
| 144 |
addr = avs_log_buffer_addr(adev, msg->ext.coredump.core_id); |
| 145 |
if (!addr) |
| 146 |
goto exit; |
| 147 |
|
| 148 |
buf = avs_apl_log_payload_addr(addr); |
| 149 |
memcpy_fromio(&layout, addr, sizeof(layout)); |
| 150 |
if (!avs_apl_is_entry_stackdump(buf + layout.read_ptr)) { |
| 151 |
union avs_notify_msg lbs_msg = AVS_NOTIFICATION(LOG_BUFFER_STATUS); |
| 152 |
|
| 153 |
/* |
| 154 |
* DSP awaits the remaining logs to be |
| 155 |
* gathered before dumping stack |
| 156 |
*/ |
| 157 |
lbs_msg.log.core = msg->ext.coredump.core_id; |
| 158 |
avs_log_buffer_status_locked(adev, &lbs_msg); |
| 159 |
} |
| 160 |
|
| 161 |
pos = dump + AVS_FW_REGS_SIZE; |
| 162 |
/* gather the stack */ |
| 163 |
do { |
| 164 |
u32 count; |
| 165 |
|
| 166 |
if (avs_apl_wait_log_entry(adev, msg->ext.coredump.core_id, &layout)) |
| 167 |
break; |
| 168 |
|
| 169 |
if (layout.read_ptr > layout.write_ptr) { |
| 170 |
count = avs_apl_log_payload_size(adev) - layout.read_ptr; |
| 171 |
memcpy_fromio(pos + offset, buf + layout.read_ptr, count); |
| 172 |
layout.read_ptr = 0; |
| 173 |
offset += count; |
| 174 |
} |
| 175 |
count = layout.write_ptr - layout.read_ptr; |
| 176 |
memcpy_fromio(pos + offset, buf + layout.read_ptr, count); |
| 177 |
offset += count; |
| 178 |
|
| 179 |
/* update read pointer */ |
| 180 |
writel(layout.write_ptr, addr); |
| 181 |
} while (offset < msg->ext.coredump.stack_dump_size); |
| 182 |
|
| 183 |
exit: |
| 184 |
dev_coredumpv(adev->dev, dump, dump_size, GFP_KERNEL); |
| 185 |
|
| 186 |
return 0; |
| 187 |
} |
| 188 |
|
| 189 |
static bool avs_apl_lp_streaming(struct avs_dev *adev) |
| 190 |
{ |
| 191 |
struct avs_path *path; |
| 192 |
|
| 193 |
spin_lock(&adev->path_list_lock); |
| 194 |
/* Any gateway without buffer allocated in LP area disqualifies D0IX. */ |
| 195 |
list_for_each_entry(path, &adev->path_list, node) { |
| 196 |
struct avs_path_pipeline *ppl; |
| 197 |
|
| 198 |
list_for_each_entry(ppl, &path->ppl_list, node) { |
| 199 |
struct avs_path_module *mod; |
| 200 |
|
| 201 |
list_for_each_entry(mod, &ppl->mod_list, node) { |
| 202 |
struct avs_tplg_modcfg_ext *cfg; |
| 203 |
|
| 204 |
cfg = mod->template->cfg_ext; |
| 205 |
|
| 206 |
/* only copiers have gateway attributes */ |
| 207 |
if (!guid_equal(&cfg->type, &AVS_COPIER_MOD_UUID)) |
| 208 |
continue; |
| 209 |
/* non-gateway copiers do not prevent PG */ |
| 210 |
if (cfg->copier.dma_type == INVALID_OBJECT_ID) |
| 211 |
continue; |
| 212 |
|
| 213 |
if (!mod->gtw_attrs.lp_buffer_alloc) { |
| 214 |
spin_unlock(&adev->path_list_lock); |
| 215 |
return false; |
| 216 |
} |
| 217 |
} |
| 218 |
} |
| 219 |
} |
| 220 |
spin_unlock(&adev->path_list_lock); |
| 221 |
|
| 222 |
return true; |
| 223 |
} |
| 224 |
|
| 225 |
bool avs_apl_d0ix_toggle(struct avs_dev *adev, struct avs_ipc_msg *tx, bool wake) |
| 226 |
{ |
| 227 |
/* wake in all cases */ |
| 228 |
if (wake) |
| 229 |
return true; |
| 230 |
|
| 231 |
/* |
| 232 |
* If no pipelines are running, allow for d0ix schedule. |
| 233 |
* If all gateways have lp=1, allow for d0ix schedule. |
| 234 |
* If any gateway with lp=0 is allocated, abort scheduling d0ix. |
| 235 |
* |
| 236 |
* Note: for cAVS 1.5+ and 1.8, D0IX is LP-firmware transition, |
| 237 |
* not the power-gating mechanism known from cAVS 2.0. |
| 238 |
*/ |
| 239 |
return avs_apl_lp_streaming(adev); |
| 240 |
} |
| 241 |
|
| 242 |
int avs_apl_set_d0ix(struct avs_dev *adev, bool enable) |
| 243 |
{ |
| 244 |
bool streaming = false; |
| 245 |
int ret; |
| 246 |
|
| 247 |
if (enable) |
| 248 |
/* Either idle or all gateways with lp=1. */ |
| 249 |
streaming = !list_empty(&adev->path_list); |
| 250 |
|
| 251 |
ret = avs_ipc_set_d0ix(adev, enable, streaming); |
| 252 |
return AVS_IPC_RET(ret); |
| 253 |
} |
| 254 |
|
| 255 |
const struct avs_dsp_ops avs_apl_dsp_ops = { |
| 256 |
.power = avs_dsp_core_power, |
| 257 |
.reset = avs_dsp_core_reset, |
| 258 |
.stall = avs_dsp_core_stall, |
| 259 |
.dsp_interrupt = avs_apl_dsp_interrupt, |
| 260 |
.int_control = avs_dsp_interrupt_control, |
| 261 |
.load_basefw = avs_hda_load_basefw, |
| 262 |
.load_lib = avs_hda_load_library, |
| 263 |
.transfer_mods = avs_hda_transfer_modules, |
| 264 |
.log_buffer_offset = avs_skl_log_buffer_offset, |
| 265 |
.log_buffer_status = avs_apl_log_buffer_status, |
| 266 |
.coredump = avs_apl_coredump, |
| 267 |
.d0ix_toggle = avs_apl_d0ix_toggle, |
| 268 |
.set_d0ix = avs_apl_set_d0ix, |
| 269 |
AVS_SET_ENABLE_LOGS_OP(apl) |
| 270 |
}; |