Commit 4624bb2f authored by Peter Ujfalusi's avatar Peter Ujfalusi Committed by Mark Brown

ASoC: SOF: core: Do not use 'bar' as parameter for block_read/write

The use of bar in the core poses limits on the portability of the code
to other, non iomapped platforms.
To make the API more generic, remove the use of 'bar' as parameter
for the block copy API.
Signed-off-by: default avatarPeter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: default avatarDaniel Baluta <daniel.baluta@gmail.com>
Reviewed-by: default avatarRanjani Sridharan <ranjani.sridharan@linux.intel.com>
Reviewed-by: default avatarGuennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Link: https://lore.kernel.org/r/20210915122116.18317-8-peter.ujfalusi@linux.intel.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 4ff134e2
...@@ -709,15 +709,19 @@ int snd_sof_ipc_set_get_comp_data(struct snd_sof_control *scontrol, ...@@ -709,15 +709,19 @@ int snd_sof_ipc_set_get_comp_data(struct snd_sof_control *scontrol,
send_bytes = sizeof(struct sof_ipc_ctrl_value_chan) * send_bytes = sizeof(struct sof_ipc_ctrl_value_chan) *
cdata->num_elems; cdata->num_elems;
if (send) if (send)
snd_sof_dsp_block_write(sdev, sdev->mmio_bar, err = snd_sof_dsp_block_write(sdev, SOF_FW_BLK_TYPE_IRAM,
scontrol->readback_offset, scontrol->readback_offset,
cdata->chanv, send_bytes); cdata->chanv, send_bytes);
else else
snd_sof_dsp_block_read(sdev, sdev->mmio_bar, err = snd_sof_dsp_block_read(sdev, SOF_FW_BLK_TYPE_IRAM,
scontrol->readback_offset, scontrol->readback_offset,
cdata->chanv, send_bytes); cdata->chanv, send_bytes);
return 0;
if (err)
dev_err_once(sdev->dev, "error: %s TYPE_IRAM failed\n",
send ? "write to" : "read from");
return err;
} }
cdata->rhdr.hdr.cmd = SOF_IPC_GLB_COMP_MSG | ipc_cmd; cdata->rhdr.hdr.cmd = SOF_IPC_GLB_COMP_MSG | ipc_cmd;
......
...@@ -86,7 +86,7 @@ static int get_cc_info(struct snd_sof_dev *sdev, ...@@ -86,7 +86,7 @@ static int get_cc_info(struct snd_sof_dev *sdev,
} }
/* parse the extended FW boot data structures from FW boot message */ /* parse the extended FW boot data structures from FW boot message */
static int snd_sof_fw_parse_ext_data(struct snd_sof_dev *sdev, u32 bar, u32 offset) static int snd_sof_fw_parse_ext_data(struct snd_sof_dev *sdev, u32 offset)
{ {
struct sof_ipc_ext_data_hdr *ext_hdr; struct sof_ipc_ext_data_hdr *ext_hdr;
void *ext_data; void *ext_data;
...@@ -97,15 +97,16 @@ static int snd_sof_fw_parse_ext_data(struct snd_sof_dev *sdev, u32 bar, u32 offs ...@@ -97,15 +97,16 @@ static int snd_sof_fw_parse_ext_data(struct snd_sof_dev *sdev, u32 bar, u32 offs
return -ENOMEM; return -ENOMEM;
/* get first header */ /* get first header */
snd_sof_dsp_block_read(sdev, bar, offset, ext_data, snd_sof_dsp_block_read(sdev, SOF_FW_BLK_TYPE_SRAM, offset, ext_data,
sizeof(*ext_hdr)); sizeof(*ext_hdr));
ext_hdr = ext_data; ext_hdr = ext_data;
while (ext_hdr->hdr.cmd == SOF_IPC_FW_READY) { while (ext_hdr->hdr.cmd == SOF_IPC_FW_READY) {
/* read in ext structure */ /* read in ext structure */
snd_sof_dsp_block_read(sdev, bar, offset + sizeof(*ext_hdr), snd_sof_dsp_block_read(sdev, SOF_FW_BLK_TYPE_SRAM,
(void *)((u8 *)ext_data + sizeof(*ext_hdr)), offset + sizeof(*ext_hdr),
ext_hdr->hdr.size - sizeof(*ext_hdr)); (void *)((u8 *)ext_data + sizeof(*ext_hdr)),
ext_hdr->hdr.size - sizeof(*ext_hdr));
dev_dbg(sdev->dev, "found ext header type %d size 0x%x\n", dev_dbg(sdev->dev, "found ext header type %d size 0x%x\n",
ext_hdr->type, ext_hdr->hdr.size); ext_hdr->type, ext_hdr->hdr.size);
...@@ -138,7 +139,7 @@ static int snd_sof_fw_parse_ext_data(struct snd_sof_dev *sdev, u32 bar, u32 offs ...@@ -138,7 +139,7 @@ static int snd_sof_fw_parse_ext_data(struct snd_sof_dev *sdev, u32 bar, u32 offs
/* move to next header */ /* move to next header */
offset += ext_hdr->hdr.size; offset += ext_hdr->hdr.size;
snd_sof_dsp_block_read(sdev, bar, offset, ext_data, snd_sof_dsp_block_read(sdev, SOF_FW_BLK_TYPE_SRAM, offset, ext_data,
sizeof(*ext_hdr)); sizeof(*ext_hdr));
ext_hdr = ext_data; ext_hdr = ext_data;
} }
...@@ -361,6 +362,7 @@ static int snd_sof_fw_ext_man_parse(struct snd_sof_dev *sdev, ...@@ -361,6 +362,7 @@ static int snd_sof_fw_ext_man_parse(struct snd_sof_dev *sdev,
*/ */
static void sof_get_windows(struct snd_sof_dev *sdev) static void sof_get_windows(struct snd_sof_dev *sdev)
{ {
int bar = snd_sof_dsp_get_bar_index(sdev, SOF_FW_BLK_TYPE_SRAM);
struct sof_ipc_window_elem *elem; struct sof_ipc_window_elem *elem;
u32 outbox_offset = 0; u32 outbox_offset = 0;
u32 stream_offset = 0; u32 stream_offset = 0;
...@@ -371,7 +373,6 @@ static void sof_get_windows(struct snd_sof_dev *sdev) ...@@ -371,7 +373,6 @@ static void sof_get_windows(struct snd_sof_dev *sdev)
u32 debug_size = 0; u32 debug_size = 0;
u32 debug_offset = 0; u32 debug_offset = 0;
int window_offset; int window_offset;
int bar;
int i; int i;
if (!sdev->info_window) { if (!sdev->info_window) {
...@@ -379,12 +380,6 @@ static void sof_get_windows(struct snd_sof_dev *sdev) ...@@ -379,12 +380,6 @@ static void sof_get_windows(struct snd_sof_dev *sdev)
return; return;
} }
bar = snd_sof_dsp_get_bar_index(sdev, SOF_FW_BLK_TYPE_SRAM);
if (bar < 0) {
dev_err(sdev->dev, "error: have no bar mapping\n");
return;
}
for (i = 0; i < sdev->info_window->num_windows; i++) { for (i = 0; i < sdev->info_window->num_windows; i++) {
elem = &sdev->info_window->window[i]; elem = &sdev->info_window->window[i];
...@@ -496,7 +491,6 @@ int sof_fw_ready(struct snd_sof_dev *sdev, u32 msg_id) ...@@ -496,7 +491,6 @@ int sof_fw_ready(struct snd_sof_dev *sdev, u32 msg_id)
{ {
struct sof_ipc_fw_ready *fw_ready = &sdev->fw_ready; struct sof_ipc_fw_ready *fw_ready = &sdev->fw_ready;
int offset; int offset;
int bar;
int ret; int ret;
/* mailbox must be on 4k boundary */ /* mailbox must be on 4k boundary */
...@@ -506,12 +500,6 @@ int sof_fw_ready(struct snd_sof_dev *sdev, u32 msg_id) ...@@ -506,12 +500,6 @@ int sof_fw_ready(struct snd_sof_dev *sdev, u32 msg_id)
return offset; return offset;
} }
bar = snd_sof_dsp_get_bar_index(sdev, SOF_FW_BLK_TYPE_SRAM);
if (bar < 0) {
dev_err(sdev->dev, "error: have no bar mapping\n");
return -EINVAL;
}
dev_dbg(sdev->dev, "ipc: DSP is ready 0x%8.8x offset 0x%x\n", dev_dbg(sdev->dev, "ipc: DSP is ready 0x%8.8x offset 0x%x\n",
msg_id, offset); msg_id, offset);
...@@ -519,8 +507,17 @@ int sof_fw_ready(struct snd_sof_dev *sdev, u32 msg_id) ...@@ -519,8 +507,17 @@ int sof_fw_ready(struct snd_sof_dev *sdev, u32 msg_id)
if (!sdev->first_boot) if (!sdev->first_boot)
return 0; return 0;
/* copy data from the DSP FW ready offset */ /*
snd_sof_dsp_block_read(sdev, bar, offset, fw_ready, sizeof(*fw_ready)); * copy data from the DSP FW ready offset
* Subsequent error handling is not needed for BLK_TYPE_SRAM
*/
ret = snd_sof_dsp_block_read(sdev, SOF_FW_BLK_TYPE_SRAM, offset, fw_ready,
sizeof(*fw_ready));
if (ret) {
dev_err(sdev->dev,
"error: unable to read fw_ready, read from TYPE_SRAM failed\n");
return ret;
}
/* make sure ABI version is compatible */ /* make sure ABI version is compatible */
ret = snd_sof_ipc_valid(sdev); ret = snd_sof_ipc_valid(sdev);
...@@ -528,8 +525,7 @@ int sof_fw_ready(struct snd_sof_dev *sdev, u32 msg_id) ...@@ -528,8 +525,7 @@ int sof_fw_ready(struct snd_sof_dev *sdev, u32 msg_id)
return ret; return ret;
/* now check for extended data */ /* now check for extended data */
snd_sof_fw_parse_ext_data(sdev, bar, offset + snd_sof_fw_parse_ext_data(sdev, offset + sizeof(struct sof_ipc_fw_ready));
sizeof(struct sof_ipc_fw_ready));
sof_get_windows(sdev); sof_get_windows(sdev);
...@@ -542,7 +538,7 @@ int snd_sof_parse_module_memcpy(struct snd_sof_dev *sdev, ...@@ -542,7 +538,7 @@ int snd_sof_parse_module_memcpy(struct snd_sof_dev *sdev,
struct snd_sof_mod_hdr *module) struct snd_sof_mod_hdr *module)
{ {
struct snd_sof_blk_hdr *block; struct snd_sof_blk_hdr *block;
int count, bar; int count, ret;
u32 offset; u32 offset;
size_t remaining; size_t remaining;
...@@ -579,13 +575,6 @@ int snd_sof_parse_module_memcpy(struct snd_sof_dev *sdev, ...@@ -579,13 +575,6 @@ int snd_sof_parse_module_memcpy(struct snd_sof_dev *sdev,
case SOF_FW_BLK_TYPE_DRAM: case SOF_FW_BLK_TYPE_DRAM:
case SOF_FW_BLK_TYPE_SRAM: case SOF_FW_BLK_TYPE_SRAM:
offset = block->offset; offset = block->offset;
bar = snd_sof_dsp_get_bar_index(sdev, block->type);
if (bar < 0) {
dev_err(sdev->dev,
"error: no BAR mapping for block type 0x%x\n",
block->type);
return bar;
}
break; break;
default: default:
dev_err(sdev->dev, "error: bad type 0x%x for block 0x%x\n", dev_err(sdev->dev, "error: bad type 0x%x for block 0x%x\n",
...@@ -603,8 +592,13 @@ int snd_sof_parse_module_memcpy(struct snd_sof_dev *sdev, ...@@ -603,8 +592,13 @@ int snd_sof_parse_module_memcpy(struct snd_sof_dev *sdev,
block->size); block->size);
return -EINVAL; return -EINVAL;
} }
snd_sof_dsp_block_write(sdev, bar, offset, ret = snd_sof_dsp_block_write(sdev, block->type, offset,
block + 1, block->size); block + 1, block->size);
if (ret < 0) {
dev_err(sdev->dev, "error: write to block type 0x%x failed\n",
block->type);
return ret;
}
if (remaining < block->size) { if (remaining < block->size) {
dev_err(sdev->dev, "error: not enough data remaining\n"); dev_err(sdev->dev, "error: not enough data remaining\n");
......
...@@ -297,16 +297,18 @@ static inline u64 snd_sof_dsp_read64(struct snd_sof_dev *sdev, u32 bar, ...@@ -297,16 +297,18 @@ static inline u64 snd_sof_dsp_read64(struct snd_sof_dev *sdev, u32 bar,
} }
/* block IO */ /* block IO */
static inline void snd_sof_dsp_block_read(struct snd_sof_dev *sdev, u32 bar, static inline int snd_sof_dsp_block_read(struct snd_sof_dev *sdev,
u32 offset, void *dest, size_t bytes) enum snd_sof_fw_blk_type blk_type,
u32 offset, void *dest, size_t bytes)
{ {
sof_ops(sdev)->block_read(sdev, bar, offset, dest, bytes); return sof_ops(sdev)->block_read(sdev, blk_type, offset, dest, bytes);
} }
static inline void snd_sof_dsp_block_write(struct snd_sof_dev *sdev, u32 bar, static inline int snd_sof_dsp_block_write(struct snd_sof_dev *sdev,
u32 offset, void *src, size_t bytes) enum snd_sof_fw_blk_type blk_type,
u32 offset, void *src, size_t bytes)
{ {
sof_ops(sdev)->block_write(sdev, bar, offset, src, bytes); return sof_ops(sdev)->block_write(sdev, blk_type, offset, src, bytes);
} }
/* ipc */ /* ipc */
......
...@@ -127,12 +127,12 @@ struct snd_sof_dsp_ops { ...@@ -127,12 +127,12 @@ struct snd_sof_dsp_ops {
void __iomem *addr); /* optional */ void __iomem *addr); /* optional */
/* memcpy IO */ /* memcpy IO */
void (*block_read)(struct snd_sof_dev *sof_dev, u32 bar, int (*block_read)(struct snd_sof_dev *sof_dev,
u32 offset, void *dest, enum snd_sof_fw_blk_type type, u32 offset,
size_t size); /* mandatory */ void *dest, size_t size); /* mandatory */
void (*block_write)(struct snd_sof_dev *sof_dev, u32 bar, int (*block_write)(struct snd_sof_dev *sof_dev,
u32 offset, void *src, enum snd_sof_fw_blk_type type, u32 offset,
size_t size); /* mandatory */ void *src, size_t size); /* mandatory */
/* doorbell */ /* doorbell */
irqreturn_t (*irq_handler)(int irq, void *context); /* optional */ irqreturn_t (*irq_handler)(int irq, void *context); /* optional */
...@@ -568,10 +568,10 @@ void sof_mailbox_write(struct snd_sof_dev *sdev, u32 offset, ...@@ -568,10 +568,10 @@ void sof_mailbox_write(struct snd_sof_dev *sdev, u32 offset,
void *message, size_t bytes); void *message, size_t bytes);
void sof_mailbox_read(struct snd_sof_dev *sdev, u32 offset, void sof_mailbox_read(struct snd_sof_dev *sdev, u32 offset,
void *message, size_t bytes); void *message, size_t bytes);
void sof_block_write(struct snd_sof_dev *sdev, u32 bar, u32 offset, void *src, int sof_block_write(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,
size_t size); u32 offset, void *src, size_t size);
void sof_block_read(struct snd_sof_dev *sdev, u32 bar, u32 offset, void *dest, int sof_block_read(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,
size_t size); u32 offset, void *dest, size_t size);
int sof_fw_ready(struct snd_sof_dev *sdev, u32 msg_id); int sof_fw_ready(struct snd_sof_dev *sdev, u32 msg_id);
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <sound/soc.h> #include <sound/soc.h>
#include <sound/sof.h> #include <sound/sof.h>
#include "sof-priv.h" #include "sof-priv.h"
#include "ops.h"
/* /*
* Register IO * Register IO
...@@ -72,15 +73,21 @@ EXPORT_SYMBOL(sof_mailbox_read); ...@@ -72,15 +73,21 @@ EXPORT_SYMBOL(sof_mailbox_read);
* Memory copy. * Memory copy.
*/ */
void sof_block_write(struct snd_sof_dev *sdev, u32 bar, u32 offset, void *src, int sof_block_write(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,
size_t size) u32 offset, void *src, size_t size)
{ {
void __iomem *dest = sdev->bar[bar] + offset; int bar = snd_sof_dsp_get_bar_index(sdev, blk_type);
const u8 *src_byte = src; const u8 *src_byte = src;
void __iomem *dest;
u32 affected_mask; u32 affected_mask;
u32 tmp; u32 tmp;
int m, n; int m, n;
if (bar < 0)
return bar;
dest = sdev->bar[bar] + offset;
m = size / 4; m = size / 4;
n = size % 4; n = size % 4;
...@@ -100,15 +107,22 @@ void sof_block_write(struct snd_sof_dev *sdev, u32 bar, u32 offset, void *src, ...@@ -100,15 +107,22 @@ void sof_block_write(struct snd_sof_dev *sdev, u32 bar, u32 offset, void *src,
tmp |= *(u32 *)(src_byte + m * 4) & affected_mask; tmp |= *(u32 *)(src_byte + m * 4) & affected_mask;
iowrite32(tmp, dest + m * 4); iowrite32(tmp, dest + m * 4);
} }
return 0;
} }
EXPORT_SYMBOL(sof_block_write); EXPORT_SYMBOL(sof_block_write);
void sof_block_read(struct snd_sof_dev *sdev, u32 bar, u32 offset, void *dest, int sof_block_read(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,
size_t size) u32 offset, void *dest, size_t size)
{ {
void __iomem *src = sdev->bar[bar] + offset; int bar = snd_sof_dsp_get_bar_index(sdev, blk_type);
if (bar < 0)
return bar;
memcpy_fromio(dest, sdev->bar[bar] + offset, size);
memcpy_fromio(dest, src, size); return 0;
} }
EXPORT_SYMBOL(sof_block_read); EXPORT_SYMBOL(sof_block_read);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment