Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
1
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
6eebd39
Documentation
LICENSES
arch
block
certs
crypto
drivers
fs
include
init
ipc
kernel
lib
mm
net
samples
scripts
security
sound
ac97
aoa
arm
atmel
core
drivers
firewire
hda
i2c
isa
mips
oss
parisc
pci
pcmcia
ppc
sh
soc
adi
amd
atmel
au1x
bcm
cirrus
codecs
dwc
fsl
generic
hisilicon
img
intel
jz4740
kirkwood
mediatek
meson
mxs
nuc900
pxa
qcom
rockchip
samsung
sh
sirf
sof
intel
Kconfig
Makefile
apl.c
bdw.c
byt.c
cnl.c
hda-bus.c
hda-codec.c
hda-ctrl.c
hda-dai.c
hda-dsp.c
hda-ipc.c
hda-loader.c
hda-pcm.c
hda-stream.c
hda-trace.c
hda.c
hda.h
intel-ipc.c
shim.h
xtensa
Kconfig
Makefile
control.c
core.c
debug.c
ipc.c
loader.c
nocodec.c
ops.c
ops.h
pcm.c
pm.c
sof-acpi-dev.c
sof-pci-dev.c
sof-priv.h
topology.c
trace.c
utils.c
spear
sprd
sti
stm
sunxi
tegra
ti
txx9
uniphier
ux500
xilinx
xtensa
zte
Kconfig
Makefile
soc-ac97.c
soc-acpi.c
soc-component.c
soc-compress.c
soc-core.c
soc-dai.c
soc-dapm.c
soc-devres.c
soc-generic-dmaengine-pcm.c
soc-io.c
soc-jack.c
soc-ops.c
soc-pcm.c
soc-topology.c
soc-utils.c
sparc
spi
synth
usb
x86
xen
Kconfig
Makefile
ac97_bus.c
last.c
sound_core.c
tools
usr
virt
.clang-format
.cocciconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
Breadcrumbs
linux
/
sound
/
soc
/
sof
/
intel
/
hda-ipc.c
Copy path
Blame
Blame
Latest commit
History
History
323 lines (269 loc) · 8.49 KB
Breadcrumbs
linux
/
sound
/
soc
/
sof
/
intel
/
hda-ipc.c
Top
File metadata and controls
Code
Blame
323 lines (269 loc) · 8.49 KB
Raw
// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) // // This file is provided under a dual BSD/GPLv2 license. When using or // redistributing this file, you may do so under either license. // // Copyright(c) 2018 Intel Corporation. All rights reserved. // // Authors: Liam Girdwood <liam.r.girdwood@linux.intel.com> // Ranjani Sridharan <ranjani.sridharan@linux.intel.com> // Rander Wang <rander.wang@intel.com> // Keyon Jie <yang.jie@linux.intel.com> // /* * Hardware interface for generic Intel audio DSP HDA IP */ #include "../ops.h" #include "hda.h" static void hda_dsp_ipc_host_done(struct snd_sof_dev *sdev) { /* * tell DSP cmd is done - clear busy * interrupt and send reply msg to dsp */ snd_sof_dsp_update_bits_forced(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCT, HDA_DSP_REG_HIPCT_BUSY, HDA_DSP_REG_HIPCT_BUSY); /* unmask BUSY interrupt */ snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCCTL, HDA_DSP_REG_HIPCCTL_BUSY, HDA_DSP_REG_HIPCCTL_BUSY); } static void hda_dsp_ipc_dsp_done(struct snd_sof_dev *sdev) { /* * set DONE bit - tell DSP we have received the reply msg * from DSP, and processed it, don't send more reply to host */ snd_sof_dsp_update_bits_forced(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCIE, HDA_DSP_REG_HIPCIE_DONE, HDA_DSP_REG_HIPCIE_DONE); /* unmask Done interrupt */ snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCCTL, HDA_DSP_REG_HIPCCTL_DONE, HDA_DSP_REG_HIPCCTL_DONE); } int hda_dsp_ipc_send_msg(struct snd_sof_dev *sdev, struct snd_sof_ipc_msg *msg) { /* send IPC message to DSP */ sof_mailbox_write(sdev, sdev->host_box.offset, msg->msg_data, msg->msg_size); snd_sof_dsp_write(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCI, HDA_DSP_REG_HIPCI_BUSY); return 0; } void hda_dsp_ipc_get_reply(struct snd_sof_dev *sdev) { struct snd_sof_ipc_msg *msg = sdev->msg; struct sof_ipc_reply reply; struct sof_ipc_cmd_hdr *hdr; int ret = 0; /* * Sometimes, there is unexpected reply ipc arriving. The reply * ipc belongs to none of the ipcs sent from driver. * In this case, the driver must ignore the ipc. */ if (!msg) { dev_warn(sdev->dev, "unexpected ipc interrupt raised!\n"); return; } hdr = msg->msg_data; if (hdr->cmd == (SOF_IPC_GLB_PM_MSG | SOF_IPC_PM_CTX_SAVE)) { /* * memory windows are powered off before sending IPC reply, * so we can't read the mailbox for CTX_SAVE reply. */ reply.error = 0; reply.hdr.cmd = SOF_IPC_GLB_REPLY; reply.hdr.size = sizeof(reply); memcpy(msg->reply_data, &reply, sizeof(reply)); goto out; } /* get IPC reply from DSP in the mailbox */ sof_mailbox_read(sdev, sdev->host_box.offset, &reply, sizeof(reply)); if (reply.error < 0) { memcpy(msg->reply_data, &reply, sizeof(reply)); ret = reply.error; } else { /* reply correct size ? */ if (reply.hdr.size != msg->reply_size) { dev_err(sdev->dev, "error: reply expected %zu got %u bytes\n", msg->reply_size, reply.hdr.size); ret = -EINVAL; } /* read the message */ if (msg->reply_size > 0) sof_mailbox_read(sdev, sdev->host_box.offset, msg->reply_data, msg->reply_size); } out: msg->reply_error = ret; } static bool hda_dsp_ipc_is_sof(uint32_t msg) { return (msg & (HDA_DSP_IPC_PURGE_FW | 0xf << 9)) != msg || (msg & HDA_DSP_IPC_PURGE_FW) != HDA_DSP_IPC_PURGE_FW; } /* IPC handler thread */ irqreturn_t hda_dsp_ipc_irq_thread(int irq, void *context) { struct snd_sof_dev *sdev = context; u32 hipci; u32 hipcie; u32 hipct; u32 hipcte; u32 msg; u32 msg_ext; bool ipc_irq = false; /* read IPC status */ hipcie = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCIE); hipct = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCT); hipci = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCI); hipcte = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCTE); /* is this a reply message from the DSP */ if (hipcie & HDA_DSP_REG_HIPCIE_DONE) { msg = hipci & HDA_DSP_REG_HIPCI_MSG_MASK; msg_ext = hipcie & HDA_DSP_REG_HIPCIE_MSG_MASK; dev_vdbg(sdev->dev, "ipc: firmware response, msg:0x%x, msg_ext:0x%x\n", msg, msg_ext); /* mask Done interrupt */ snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCCTL, HDA_DSP_REG_HIPCCTL_DONE, 0); /* * Make sure the interrupt thread cannot be preempted between * waking up the sender and re-enabling the interrupt. Also * protect against a theoretical race with sof_ipc_tx_message(): * if the DSP is fast enough to receive an IPC message, reply to * it, and the host interrupt processing calls this function on * a different core from the one, where the sending is taking * place, the message might not yet be marked as expecting a * reply. */ spin_lock_irq(&sdev->ipc_lock); /* handle immediate reply from DSP core - ignore ROM messages */ if (hda_dsp_ipc_is_sof(msg)) { hda_dsp_ipc_get_reply(sdev); snd_sof_ipc_reply(sdev, msg); } /* wake up sleeper if we are loading code */ if (sdev->code_loading) { sdev->code_loading = 0; wake_up(&sdev->waitq); } /* set the done bit */ hda_dsp_ipc_dsp_done(sdev); spin_unlock_irq(&sdev->ipc_lock); ipc_irq = true; } /* is this a new message from DSP */ if (hipct & HDA_DSP_REG_HIPCT_BUSY) { msg = hipct & HDA_DSP_REG_HIPCT_MSG_MASK; msg_ext = hipcte & HDA_DSP_REG_HIPCTE_MSG_MASK; dev_vdbg(sdev->dev, "ipc: firmware initiated, msg:0x%x, msg_ext:0x%x\n", msg, msg_ext); /* mask BUSY interrupt */ snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCCTL, HDA_DSP_REG_HIPCCTL_BUSY, 0); /* handle messages from DSP */ if ((hipct & SOF_IPC_PANIC_MAGIC_MASK) == SOF_IPC_PANIC_MAGIC) { /* this is a PANIC message !! */ snd_sof_dsp_panic(sdev, HDA_DSP_PANIC_OFFSET(msg_ext)); } else { /* normal message - process normally */ snd_sof_ipc_msgs_rx(sdev); } hda_dsp_ipc_host_done(sdev); ipc_irq = true; } if (!ipc_irq) { /* * This interrupt is not shared so no need to return IRQ_NONE. */ dev_dbg_ratelimited(sdev->dev, "nothing to do in IPC IRQ thread\n"); } /* re-enable IPC interrupt */ snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, HDA_DSP_REG_ADSPIC, HDA_DSP_ADSPIC_IPC, HDA_DSP_ADSPIC_IPC); return IRQ_HANDLED; } /* is this IRQ for ADSP ? - we only care about IPC here */ irqreturn_t hda_dsp_ipc_irq_handler(int irq, void *context) { struct snd_sof_dev *sdev = context; int ret = IRQ_NONE; u32 irq_status; spin_lock(&sdev->hw_lock); /* store status */ irq_status = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_ADSPIS); dev_vdbg(sdev->dev, "irq handler: irq_status:0x%x\n", irq_status); /* invalid message ? */ if (irq_status == 0xffffffff) goto out; /* IPC message ? */ if (irq_status & HDA_DSP_ADSPIS_IPC) { /* disable IPC interrupt */ snd_sof_dsp_update_bits_unlocked(sdev, HDA_DSP_BAR, HDA_DSP_REG_ADSPIC, HDA_DSP_ADSPIC_IPC, 0); ret = IRQ_WAKE_THREAD; } out: spin_unlock(&sdev->hw_lock); return ret; } int hda_dsp_ipc_get_mailbox_offset(struct snd_sof_dev *sdev) { return HDA_DSP_MBOX_UPLINK_OFFSET; } int hda_dsp_ipc_get_window_offset(struct snd_sof_dev *sdev, u32 id) { return SRAM_WINDOW_OFFSET(id); } void hda_ipc_msg_data(struct snd_sof_dev *sdev, struct snd_pcm_substream *substream, void *p, size_t sz) { if (!substream || !sdev->stream_box.size) { sof_mailbox_read(sdev, sdev->dsp_box.offset, p, sz); } else { struct hdac_stream *hstream = substream->runtime->private_data; struct sof_intel_hda_stream *hda_stream; hda_stream = container_of(hstream, struct sof_intel_hda_stream, hda_stream.hstream); /* The stream might already be closed */ if (hstream) sof_mailbox_read(sdev, hda_stream->stream.posn_offset, p, sz); } } int hda_ipc_pcm_params(struct snd_sof_dev *sdev, struct snd_pcm_substream *substream, const struct sof_ipc_pcm_params_reply *reply) { struct hdac_stream *hstream = substream->runtime->private_data; struct sof_intel_hda_stream *hda_stream; /* validate offset */ size_t posn_offset = reply->posn_offset; hda_stream = container_of(hstream, struct sof_intel_hda_stream, hda_stream.hstream); /* check for unaligned offset or overflow */ if (posn_offset > sdev->stream_box.size || posn_offset % sizeof(struct sof_ipc_stream_posn) != 0) return -EINVAL; hda_stream->stream.posn_offset = sdev->stream_box.offset + posn_offset; dev_dbg(sdev->dev, "pcm: stream dir %d, posn mailbox offset is %zu", substream->stream, hda_stream->stream.posn_offset); return 0; }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
You can’t perform that action at this time.