Skip to content

Commit 7576e2f

Browse files
crojewsk-intelbroonie
authored andcommitted
ASoC: Intel: avs: Abstract IPC handling
Servicing IPCs on CNL platforms and onward differs from the existing one. To make room for these, enrich platform descriptor with fields representing crucial IPC registers and utilize them throughout the code. While cleaning up device descriptors, reduce the number of code lines by assigning 'min_fw_version' within a single line. Reviewed-by: Amadeusz Sławiński <amadeuszx.slawinski@linux.intel.com> Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com> Link: https://msgid.link/r/20240220115035.770402-5-cezary.rojewski@intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent a8f858d commit 7576e2f

File tree

5 files changed

+72
-41
lines changed

5 files changed

+72
-41
lines changed

sound/soc/intel/avs/avs.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,23 @@ extern const struct avs_dsp_ops avs_apl_dsp_ops;
7373
#define avs_platattr_test(adev, attr) \
7474
((adev)->spec->attributes & AVS_PLATATTR_##attr)
7575

76+
struct avs_sram_spec {
77+
const u32 base_offset;
78+
const u32 window_size;
79+
const u32 rom_status_offset;
80+
};
81+
82+
struct avs_hipc_spec {
83+
const u32 req_offset;
84+
const u32 req_ext_offset;
85+
const u32 req_busy_mask;
86+
const u32 ack_offset;
87+
const u32 ack_done_mask;
88+
const u32 rsp_offset;
89+
const u32 rsp_busy_mask;
90+
const u32 ctl_offset;
91+
};
92+
7693
/* Platform specific descriptor */
7794
struct avs_spec {
7895
const char *name;
@@ -82,9 +99,8 @@ struct avs_spec {
8299

83100
const u32 core_init_mask; /* used during DSP boot */
84101
const u64 attributes; /* bitmask of AVS_PLATATTR_* */
85-
const u32 sram_base_offset;
86-
const u32 sram_window_size;
87-
const u32 rom_status;
102+
const struct avs_sram_spec *sram;
103+
const struct avs_hipc_spec *hipc;
88104
};
89105

90106
struct avs_fw_entry {

sound/soc/intel/avs/core.c

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -730,36 +730,47 @@ static const struct dev_pm_ops avs_dev_pm = {
730730
SET_RUNTIME_PM_OPS(avs_runtime_suspend, avs_runtime_resume, NULL)
731731
};
732732

733+
static const struct avs_sram_spec skl_sram_spec = {
734+
.base_offset = SKL_ADSP_SRAM_BASE_OFFSET,
735+
.window_size = SKL_ADSP_SRAM_WINDOW_SIZE,
736+
.rom_status_offset = SKL_ADSP_SRAM_BASE_OFFSET,
737+
};
738+
739+
static const struct avs_sram_spec apl_sram_spec = {
740+
.base_offset = APL_ADSP_SRAM_BASE_OFFSET,
741+
.window_size = APL_ADSP_SRAM_WINDOW_SIZE,
742+
.rom_status_offset = APL_ADSP_SRAM_BASE_OFFSET,
743+
};
744+
745+
static const struct avs_hipc_spec skl_hipc_spec = {
746+
.req_offset = SKL_ADSP_REG_HIPCI,
747+
.req_ext_offset = SKL_ADSP_REG_HIPCIE,
748+
.req_busy_mask = SKL_ADSP_HIPCI_BUSY,
749+
.ack_offset = SKL_ADSP_REG_HIPCIE,
750+
.ack_done_mask = SKL_ADSP_HIPCIE_DONE,
751+
.rsp_offset = SKL_ADSP_REG_HIPCT,
752+
.rsp_busy_mask = SKL_ADSP_HIPCT_BUSY,
753+
.ctl_offset = SKL_ADSP_REG_HIPCCTL,
754+
};
755+
733756
static const struct avs_spec skl_desc = {
734757
.name = "skl",
735-
.min_fw_version = {
736-
.major = 9,
737-
.minor = 21,
738-
.hotfix = 0,
739-
.build = 4732,
740-
},
758+
.min_fw_version = { 9, 21, 0, 4732 },
741759
.dsp_ops = &avs_skl_dsp_ops,
742760
.core_init_mask = 1,
743761
.attributes = AVS_PLATATTR_CLDMA,
744-
.sram_base_offset = SKL_ADSP_SRAM_BASE_OFFSET,
745-
.sram_window_size = SKL_ADSP_SRAM_WINDOW_SIZE,
746-
.rom_status = SKL_ADSP_SRAM_BASE_OFFSET,
762+
.sram = &skl_sram_spec,
763+
.hipc = &skl_hipc_spec,
747764
};
748765

749766
static const struct avs_spec apl_desc = {
750767
.name = "apl",
751-
.min_fw_version = {
752-
.major = 9,
753-
.minor = 22,
754-
.hotfix = 1,
755-
.build = 4323,
756-
},
768+
.min_fw_version = { 9, 22, 1, 4323 },
757769
.dsp_ops = &avs_apl_dsp_ops,
758770
.core_init_mask = 3,
759771
.attributes = AVS_PLATATTR_IMR,
760-
.sram_base_offset = APL_ADSP_SRAM_BASE_OFFSET,
761-
.sram_window_size = APL_ADSP_SRAM_WINDOW_SIZE,
762-
.rom_status = APL_ADSP_SRAM_BASE_OFFSET,
772+
.sram = &apl_sram_spec,
773+
.hipc = &skl_hipc_spec,
763774
};
764775

765776
static const struct pci_device_id avs_ids[] = {

sound/soc/intel/avs/ipc.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -305,42 +305,43 @@ irqreturn_t avs_dsp_irq_handler(int irq, void *dev_id)
305305
{
306306
struct avs_dev *adev = dev_id;
307307
struct avs_ipc *ipc = adev->ipc;
308+
const struct avs_spec *const spec = adev->spec;
308309
u32 adspis, hipc_rsp, hipc_ack;
309310
irqreturn_t ret = IRQ_NONE;
310311

311312
adspis = snd_hdac_adsp_readl(adev, AVS_ADSP_REG_ADSPIS);
312313
if (adspis == UINT_MAX || !(adspis & AVS_ADSP_ADSPIS_IPC))
313314
return ret;
314315

315-
hipc_ack = snd_hdac_adsp_readl(adev, SKL_ADSP_REG_HIPCIE);
316-
hipc_rsp = snd_hdac_adsp_readl(adev, SKL_ADSP_REG_HIPCT);
316+
hipc_ack = snd_hdac_adsp_readl(adev, spec->hipc->ack_offset);
317+
hipc_rsp = snd_hdac_adsp_readl(adev, spec->hipc->rsp_offset);
317318

318319
/* DSP acked host's request */
319-
if (hipc_ack & SKL_ADSP_HIPCIE_DONE) {
320+
if (hipc_ack & spec->hipc->ack_done_mask) {
320321
/*
321322
* As an extra precaution, mask done interrupt. Code executed
322323
* due to complete() found below does not assume any masking.
323324
*/
324-
snd_hdac_adsp_updatel(adev, SKL_ADSP_REG_HIPCCTL,
325+
snd_hdac_adsp_updatel(adev, spec->hipc->ctl_offset,
325326
AVS_ADSP_HIPCCTL_DONE, 0);
326327

327328
complete(&ipc->done_completion);
328329

329330
/* tell DSP it has our attention */
330-
snd_hdac_adsp_updatel(adev, SKL_ADSP_REG_HIPCIE,
331-
SKL_ADSP_HIPCIE_DONE,
332-
SKL_ADSP_HIPCIE_DONE);
331+
snd_hdac_adsp_updatel(adev, spec->hipc->ack_offset,
332+
spec->hipc->ack_done_mask,
333+
spec->hipc->ack_done_mask);
333334
/* unmask done interrupt */
334-
snd_hdac_adsp_updatel(adev, SKL_ADSP_REG_HIPCCTL,
335+
snd_hdac_adsp_updatel(adev, spec->hipc->ctl_offset,
335336
AVS_ADSP_HIPCCTL_DONE,
336337
AVS_ADSP_HIPCCTL_DONE);
337338
ret = IRQ_HANDLED;
338339
}
339340

340341
/* DSP sent new response to process */
341-
if (hipc_rsp & SKL_ADSP_HIPCT_BUSY) {
342+
if (hipc_rsp & spec->hipc->rsp_busy_mask) {
342343
/* mask busy interrupt */
343-
snd_hdac_adsp_updatel(adev, SKL_ADSP_REG_HIPCCTL,
344+
snd_hdac_adsp_updatel(adev, spec->hipc->ctl_offset,
344345
AVS_ADSP_HIPCCTL_BUSY, 0);
345346

346347
ret = IRQ_WAKE_THREAD;
@@ -379,10 +380,11 @@ irqreturn_t avs_dsp_irq_thread(int irq, void *dev_id)
379380
static bool avs_ipc_is_busy(struct avs_ipc *ipc)
380381
{
381382
struct avs_dev *adev = to_avs_dev(ipc->dev);
383+
const struct avs_spec *const spec = adev->spec;
382384
u32 hipc_rsp;
383385

384-
hipc_rsp = snd_hdac_adsp_readl(adev, SKL_ADSP_REG_HIPCT);
385-
return hipc_rsp & SKL_ADSP_HIPCT_BUSY;
386+
hipc_rsp = snd_hdac_adsp_readl(adev, spec->hipc->rsp_offset);
387+
return hipc_rsp & spec->hipc->rsp_busy_mask;
386388
}
387389

388390
static int avs_ipc_wait_busy_completion(struct avs_ipc *ipc, int timeout)
@@ -440,18 +442,19 @@ static void avs_ipc_msg_init(struct avs_ipc *ipc, struct avs_ipc_msg *reply)
440442

441443
static void avs_dsp_send_tx(struct avs_dev *adev, struct avs_ipc_msg *tx, bool read_fwregs)
442444
{
445+
const struct avs_spec *const spec = adev->spec;
443446
u64 reg = ULONG_MAX;
444447

445-
tx->header |= SKL_ADSP_HIPCI_BUSY;
448+
tx->header |= spec->hipc->req_busy_mask;
446449
if (read_fwregs)
447450
reg = readq(avs_sram_addr(adev, AVS_FW_REGS_WINDOW));
448451

449452
trace_avs_request(tx, reg);
450453

451454
if (tx->size)
452455
memcpy_toio(avs_downlink_addr(adev), tx->data, tx->size);
453-
snd_hdac_adsp_writel(adev, SKL_ADSP_REG_HIPCIE, tx->header >> 32);
454-
snd_hdac_adsp_writel(adev, SKL_ADSP_REG_HIPCI, tx->header & UINT_MAX);
456+
snd_hdac_adsp_writel(adev, spec->hipc->req_ext_offset, tx->header >> 32);
457+
snd_hdac_adsp_writel(adev, spec->hipc->req_offset, tx->header & UINT_MAX);
455458
}
456459

457460
static int avs_dsp_do_send_msg(struct avs_dev *adev, struct avs_ipc_msg *request,
@@ -606,6 +609,7 @@ int avs_dsp_send_rom_msg(struct avs_dev *adev, struct avs_ipc_msg *request, cons
606609

607610
void avs_dsp_interrupt_control(struct avs_dev *adev, bool enable)
608611
{
612+
const struct avs_spec *const spec = adev->spec;
609613
u32 value, mask;
610614

611615
/*
@@ -617,7 +621,7 @@ void avs_dsp_interrupt_control(struct avs_dev *adev, bool enable)
617621

618622
mask = AVS_ADSP_HIPCCTL_DONE | AVS_ADSP_HIPCCTL_BUSY;
619623
value = enable ? mask : 0;
620-
snd_hdac_adsp_updatel(adev, SKL_ADSP_REG_HIPCCTL, mask, value);
624+
snd_hdac_adsp_updatel(adev, spec->hipc->ctl_offset, mask, value);
621625
}
622626

623627
int avs_ipc_init(struct avs_ipc *ipc, struct device *dev)

sound/soc/intel/avs/loader.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ avs_hda_init_rom(struct avs_dev *adev, unsigned int dma_id, bool purge)
306306
}
307307

308308
/* await ROM init */
309-
ret = snd_hdac_adsp_readq_poll(adev, spec->rom_status, reg,
309+
ret = snd_hdac_adsp_readq_poll(adev, spec->sram->rom_status_offset, reg,
310310
(reg & 0xF) == AVS_ROM_INIT_DONE ||
311311
(reg & 0xF) == APL_ROM_FW_ENTERED,
312312
AVS_ROM_INIT_POLLING_US, APL_ROM_INIT_TIMEOUT_US);

sound/soc/intel/avs/registers.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
#define APL_ADSP_SRAM_WINDOW_SIZE 0x20000
5858

5959
/* Constants used when accessing SRAM, space shared with firmware */
60-
#define AVS_FW_REG_BASE(adev) ((adev)->spec->sram_base_offset)
60+
#define AVS_FW_REG_BASE(adev) ((adev)->spec->sram->base_offset)
6161
#define AVS_FW_REG_STATUS(adev) (AVS_FW_REG_BASE(adev) + 0x0)
6262
#define AVS_FW_REG_ERROR_CODE(adev) (AVS_FW_REG_BASE(adev) + 0x4)
6363

@@ -72,8 +72,8 @@
7272

7373
/* registry I/O helpers */
7474
#define avs_sram_offset(adev, window_idx) \
75-
((adev)->spec->sram_base_offset + \
76-
(adev)->spec->sram_window_size * (window_idx))
75+
((adev)->spec->sram->base_offset + \
76+
(adev)->spec->sram->window_size * (window_idx))
7777

7878
#define avs_sram_addr(adev, window_idx) \
7979
((adev)->dsp_ba + avs_sram_offset(adev, window_idx))

0 commit comments

Comments
 (0)