1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
3 // This file is provided under a dual BSD/GPLv2 license. When using or
4 // redistributing this file, you may do so under either license.
6 // Copyright(c) 2018 Intel Corporation. All rights reserved.
8 // Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
11 #include <linux/pci.h>
15 bool snd_sof_pci_update_bits_unlocked(struct snd_sof_dev *sdev, u32 offset,
18 struct pci_dev *pci = to_pci_dev(sdev->dev);
19 unsigned int old, new;
22 pci_read_config_dword(pci, offset, &ret);
24 dev_dbg(sdev->dev, "Debug PCIR: %8.8x at %8.8x\n", old & mask, offset);
26 new = (old & ~mask) | (value & mask);
31 pci_write_config_dword(pci, offset, new);
32 dev_dbg(sdev->dev, "Debug PCIW: %8.8x at %8.8x\n", value,
38 bool snd_sof_pci_update_bits(struct snd_sof_dev *sdev, u32 offset,
44 spin_lock_irqsave(&sdev->hw_lock, flags);
45 change = snd_sof_pci_update_bits_unlocked(sdev, offset, mask, value);
46 spin_unlock_irqrestore(&sdev->hw_lock, flags);
49 EXPORT_SYMBOL(snd_sof_pci_update_bits);
51 bool snd_sof_dsp_update_bits_unlocked(struct snd_sof_dev *sdev, u32 bar,
52 u32 offset, u32 mask, u32 value)
54 unsigned int old, new;
57 ret = snd_sof_dsp_read(sdev, bar, offset);
60 new = (old & ~mask) | (value & mask);
65 snd_sof_dsp_write(sdev, bar, offset, new);
69 EXPORT_SYMBOL(snd_sof_dsp_update_bits_unlocked);
71 bool snd_sof_dsp_update_bits64_unlocked(struct snd_sof_dev *sdev, u32 bar,
72 u32 offset, u64 mask, u64 value)
76 old = snd_sof_dsp_read64(sdev, bar, offset);
78 new = (old & ~mask) | (value & mask);
83 snd_sof_dsp_write64(sdev, bar, offset, new);
87 EXPORT_SYMBOL(snd_sof_dsp_update_bits64_unlocked);
89 /* This is for registers bits with attribute RWC */
90 bool snd_sof_dsp_update_bits(struct snd_sof_dev *sdev, u32 bar, u32 offset,
96 spin_lock_irqsave(&sdev->hw_lock, flags);
97 change = snd_sof_dsp_update_bits_unlocked(sdev, bar, offset, mask,
99 spin_unlock_irqrestore(&sdev->hw_lock, flags);
102 EXPORT_SYMBOL(snd_sof_dsp_update_bits);
104 bool snd_sof_dsp_update_bits64(struct snd_sof_dev *sdev, u32 bar, u32 offset,
110 spin_lock_irqsave(&sdev->hw_lock, flags);
111 change = snd_sof_dsp_update_bits64_unlocked(sdev, bar, offset, mask,
113 spin_unlock_irqrestore(&sdev->hw_lock, flags);
116 EXPORT_SYMBOL(snd_sof_dsp_update_bits64);
119 void snd_sof_dsp_update_bits_forced_unlocked(struct snd_sof_dev *sdev, u32 bar,
120 u32 offset, u32 mask, u32 value)
122 unsigned int old, new;
125 ret = snd_sof_dsp_read(sdev, bar, offset);
128 new = (old & ~mask) | (value & mask);
130 snd_sof_dsp_write(sdev, bar, offset, new);
133 /* This is for registers bits with attribute RWC */
134 void snd_sof_dsp_update_bits_forced(struct snd_sof_dev *sdev, u32 bar,
135 u32 offset, u32 mask, u32 value)
139 spin_lock_irqsave(&sdev->hw_lock, flags);
140 snd_sof_dsp_update_bits_forced_unlocked(sdev, bar, offset, mask, value);
141 spin_unlock_irqrestore(&sdev->hw_lock, flags);
143 EXPORT_SYMBOL(snd_sof_dsp_update_bits_forced);
146 * snd_sof_dsp_panic - handle a received DSP panic message
147 * @sdev: Pointer to the device's sdev
148 * @offset: offset of panic information
149 * @non_recoverable: the panic is fatal, no recovery will be done by the caller
151 void snd_sof_dsp_panic(struct snd_sof_dev *sdev, u32 offset, bool non_recoverable)
154 * if DSP is not ready and the dsp_oops_offset is not yet set, use the
155 * offset from the panic message.
157 if (!sdev->dsp_oops_offset)
158 sdev->dsp_oops_offset = offset;
161 * Print warning if the offset from the panic message differs from
164 if (sdev->dsp_oops_offset != offset)
166 "%s: dsp_oops_offset %zu differs from panic offset %u\n",
167 __func__, sdev->dsp_oops_offset, offset);
170 * Set the fw_state to crashed only in case of non recoverable DSP panic
172 * Use different message within the snd_sof_dsp_dbg_dump() depending on
173 * the non_recoverable flag.
175 sdev->dbg_dump_printed = false;
176 if (non_recoverable) {
177 snd_sof_dsp_dbg_dump(sdev, "DSP panic!",
178 SOF_DBG_DUMP_REGS | SOF_DBG_DUMP_MBOX);
179 sof_set_fw_state(sdev, SOF_FW_CRASHED);
180 sof_fw_trace_fw_crashed(sdev);
182 snd_sof_dsp_dbg_dump(sdev,
183 "DSP panic (recovery will be attempted)",
184 SOF_DBG_DUMP_REGS | SOF_DBG_DUMP_MBOX);
187 EXPORT_SYMBOL(snd_sof_dsp_panic);