diff --git a/sound/soc/sof/intel/apl.c b/sound/soc/sof/intel/apl.c index 7e28fba1768239..0f10e2a100cc4d 100644 --- a/sound/soc/sof/intel/apl.c +++ b/sound/soc/sof/intel/apl.c @@ -45,22 +45,22 @@ struct snd_sof_dsp_ops sof_apl_ops = { .remove = hda_dsp_remove, /* Register IO */ - .write = hda_dsp_write, - .read = hda_dsp_read, - .write64 = hda_dsp_write64, - .read64 = hda_dsp_read64, + .write = sof_io_write, + .read = sof_io_read, + .write64 = sof_io_write64, + .read64 = sof_io_read64, /* Block IO */ - .block_read = hda_dsp_block_read, - .block_write = hda_dsp_block_write, + .block_read = sof_block_read, + .block_write = sof_block_write, /* doorbell */ .irq_handler = hda_dsp_ipc_irq_handler, .irq_thread = hda_dsp_ipc_irq_thread, /* mailbox */ - .mailbox_read = hda_dsp_mailbox_read, - .mailbox_write = hda_dsp_mailbox_write, + .mailbox_read = sof_mailbox_read, + .mailbox_write = sof_mailbox_write, /* ipc */ .send_msg = hda_dsp_ipc_send_msg, diff --git a/sound/soc/sof/intel/bdw.c b/sound/soc/sof/intel/bdw.c index edf46dce0a773f..8cbe5af59d07e2 100644 --- a/sound/soc/sof/intel/bdw.c +++ b/sound/soc/sof/intel/bdw.c @@ -74,82 +74,6 @@ static const struct snd_sof_debugfs_map bdw_debugfs[] = { static int bdw_cmd_done(struct snd_sof_dev *sdev, int dir); -/* - * Memory copy. - */ - -/* write has to deal with copying non 32 bit sized data */ -static void bdw_block_write(struct snd_sof_dev *sdev, u32 offset, void *src, - size_t size) -{ - void __iomem *dest = sdev->bar[sdev->mmio_bar] + offset; - u32 tmp = 0; - int i, m, n; - const u8 *src_byte = src; - - m = size / 4; - n = size % 4; - - /* __iowrite32_copy use 32bit size values so divide by 4 */ - __iowrite32_copy(dest, src, m); - - if (n) { - for (i = 0; i < n; i++) - tmp |= (u32)*(src_byte + m * 4 + i) << (i * 8); - __iowrite32_copy(dest + m * 4, &tmp, 1); - } -} - -static void bdw_block_read(struct snd_sof_dev *sdev, u32 offset, void *dest, - size_t size) -{ - void __iomem *src = sdev->bar[sdev->mmio_bar] + offset; - - memcpy_fromio(dest, src, size); -} - -static void bdw_mailbox_write(struct snd_sof_dev *sdev, u32 offset, - void *message, size_t bytes) -{ - void __iomem *dest = sdev->bar[sdev->mailbox_bar] + offset; - - memcpy_toio(dest, message, bytes); -} - -static void bdw_mailbox_read(struct snd_sof_dev *sdev, u32 offset, - void *message, size_t bytes) -{ - void __iomem *src = sdev->bar[sdev->mailbox_bar] + offset; - - memcpy_fromio(message, src, bytes); -} - -/* - * Register IO - */ - -static void bdw_write(struct snd_sof_dev *sdev, void __iomem *addr, - u32 value) -{ - writel(value, addr); -} - -static u32 bdw_read(struct snd_sof_dev *sdev, void __iomem *addr) -{ - return readl(addr); -} - -static void bdw_write64(struct snd_sof_dev *sdev, void __iomem *addr, - u64 value) -{ - writeq(value, addr); -} - -static u64 bdw_read64(struct snd_sof_dev *sdev, void __iomem *addr) -{ - return readq(addr); -} - /* * DSP Control. */ @@ -299,14 +223,14 @@ static void bdw_get_registers(struct snd_sof_dev *sdev, u32 *stack, size_t stack_words) { /* first read regsisters */ - bdw_mailbox_read(sdev, sdev->dsp_oops_offset, xoops, sizeof(*xoops)); + sof_mailbox_read(sdev, sdev->dsp_oops_offset, xoops, sizeof(*xoops)); /* then get panic info */ - bdw_mailbox_read(sdev, sdev->dsp_oops_offset + sizeof(*xoops), + sof_mailbox_read(sdev, sdev->dsp_oops_offset + sizeof(*xoops), panic_info, sizeof(*panic_info)); /* then get the stack */ - bdw_mailbox_read(sdev, sdev->dsp_oops_offset + sizeof(*xoops) + + sof_mailbox_read(sdev, sdev->dsp_oops_offset + sizeof(*xoops) + sizeof(*panic_info), stack, stack_words * sizeof(u32)); } @@ -368,7 +292,7 @@ static irqreturn_t bdw_irq_thread(int irq, void *context) /* reply message from DSP */ if (ipcx & SHIM_IPCX_DONE) { /* Handle Immediate reply from DSP Core */ - bdw_mailbox_read(sdev, sdev->host_box.offset, &hdr, + sof_mailbox_read(sdev, sdev->host_box.offset, &hdr, sizeof(hdr)); /* @@ -511,7 +435,7 @@ static int bdw_fw_ready(struct snd_sof_dev *sdev, u32 msg_id) msg_id, offset); /* copy data from the DSP FW ready offset */ - bdw_block_read(sdev, offset, fw_ready, sizeof(*fw_ready)); + sof_block_read(sdev, offset, fw_ready, sizeof(*fw_ready)); snd_sof_dsp_mailbox_init(sdev, fw_ready->dspbox_offset, fw_ready->dspbox_size, @@ -553,7 +477,7 @@ static int bdw_is_ready(struct snd_sof_dev *sdev) static int bdw_send_msg(struct snd_sof_dev *sdev, struct snd_sof_ipc_msg *msg) { /* send the message */ - bdw_mailbox_write(sdev, sdev->host_box.offset, msg->msg_data, + sof_mailbox_write(sdev, sdev->host_box.offset, msg->msg_data, msg->msg_size); snd_sof_dsp_write(sdev, BDW_DSP_BAR, SHIM_IPCX, SHIM_IPCX_BUSY); @@ -567,7 +491,7 @@ static int bdw_get_reply(struct snd_sof_dev *sdev, struct snd_sof_ipc_msg *msg) u32 size; /* get reply */ - bdw_mailbox_read(sdev, sdev->host_box.offset, &reply, sizeof(reply)); + sof_mailbox_read(sdev, sdev->host_box.offset, &reply, sizeof(reply)); if (reply.error < 0) { size = sizeof(reply); ret = reply.error; @@ -585,7 +509,7 @@ static int bdw_get_reply(struct snd_sof_dev *sdev, struct snd_sof_ipc_msg *msg) /* read the message */ if (msg->msg_data && size > 0) - bdw_mailbox_read(sdev, sdev->host_box.offset, msg->reply_data, + sof_mailbox_read(sdev, sdev->host_box.offset, msg->reply_data, size); return ret; @@ -751,18 +675,18 @@ struct snd_sof_dsp_ops sof_bdw_ops = { .reset = bdw_reset, /* Register IO */ - .read = bdw_read, - .write = bdw_write, - .read64 = bdw_read64, - .write64 = bdw_write64, + .write = sof_io_write, + .read = sof_io_read, + .write64 = sof_io_write64, + .read64 = sof_io_read64, /* Block IO */ - .block_read = bdw_block_read, - .block_write = bdw_block_write, + .block_read = sof_block_read, + .block_write = sof_block_write, /* mailbox */ - .mailbox_read = bdw_mailbox_read, - .mailbox_write = bdw_mailbox_write, + .mailbox_read = sof_mailbox_read, + .mailbox_write = sof_mailbox_write, /* ipc */ .send_msg = bdw_send_msg, diff --git a/sound/soc/sof/intel/byt.c b/sound/soc/sof/intel/byt.c index 6766c971d2488c..99571bd1560c86 100644 --- a/sound/soc/sof/intel/byt.c +++ b/sound/soc/sof/intel/byt.c @@ -99,65 +99,6 @@ static const struct snd_sof_debugfs_map cht_debugfs[] = { static int byt_cmd_done(struct snd_sof_dev *sdev, int dir); -/* - * Register IO - */ - -static void byt_write(struct snd_sof_dev *sdev, void __iomem *addr, - u32 value) -{ - writel(value, addr); -} - -static u32 byt_read(struct snd_sof_dev *sdev, void __iomem *addr) -{ - return readl(addr); -} - -static void byt_write64(struct snd_sof_dev *sdev, void __iomem *addr, - u64 value) -{ - writeq(value, addr); -} - -static u64 byt_read64(struct snd_sof_dev *sdev, void __iomem *addr) -{ - return readq(addr); -} - -/* - * Memory copy. - */ - -static void byt_block_write(struct snd_sof_dev *sdev, u32 offset, void *src, - size_t size) -{ - void __iomem *dest = sdev->bar[sdev->mmio_bar] + offset; - u32 tmp = 0; - int i, m, n; - const u8 *src_byte = src; - - m = size / 4; - n = size % 4; - - /* __iowrite32_copy use 32bit size values so divide by 4 */ - __iowrite32_copy(dest, src, m); - - if (n) { - for (i = 0; i < n; i++) - tmp |= (u32)*(src_byte + m * 4 + i) << (i * 8); - __iowrite32_copy(dest + m * 4, &tmp, 1); - } -} - -static void byt_block_read(struct snd_sof_dev *sdev, u32 offset, void *dest, - size_t size) -{ - void __iomem *src = sdev->bar[sdev->mmio_bar] + offset; - - memcpy_fromio(dest, src, size); -} - /* * IPC Firmware ready. */ @@ -271,7 +212,7 @@ static int byt_fw_ready(struct snd_sof_dev *sdev, u32 msg_id) msg_id, offset); /* copy data from the DSP FW ready offset */ - byt_block_read(sdev, offset, fw_ready, sizeof(*fw_ready)); + sof_block_read(sdev, offset, fw_ready, sizeof(*fw_ready)); snd_sof_dsp_mailbox_init(sdev, fw_ready->dspbox_offset, fw_ready->dspbox_size, @@ -295,26 +236,6 @@ static int byt_fw_ready(struct snd_sof_dev *sdev, u32 msg_id) return 0; } -/* - * IPC Mailbox IO - */ - -static void byt_mailbox_write(struct snd_sof_dev *sdev, u32 offset, - void *message, size_t bytes) -{ - void __iomem *dest = sdev->bar[sdev->mailbox_bar] + offset; - - memcpy_toio(dest, message, bytes); -} - -static void byt_mailbox_read(struct snd_sof_dev *sdev, u32 offset, - void *message, size_t bytes) -{ - void __iomem *src = sdev->bar[sdev->mailbox_bar] + offset; - - memcpy_fromio(message, src, bytes); -} - /* * Debug */ @@ -325,14 +246,14 @@ static void byt_get_registers(struct snd_sof_dev *sdev, u32 *stack, size_t stack_words) { /* first read regsisters */ - byt_mailbox_read(sdev, sdev->dsp_oops_offset, xoops, sizeof(*xoops)); + sof_mailbox_read(sdev, sdev->dsp_oops_offset, xoops, sizeof(*xoops)); /* then get panic info */ - byt_mailbox_read(sdev, sdev->dsp_oops_offset + sizeof(*xoops), + sof_mailbox_read(sdev, sdev->dsp_oops_offset + sizeof(*xoops), panic_info, sizeof(*panic_info)); /* then get the stack */ - byt_mailbox_read(sdev, sdev->dsp_oops_offset + sizeof(*xoops) + + sof_mailbox_read(sdev, sdev->dsp_oops_offset + sizeof(*xoops) + sizeof(*panic_info), stack, stack_words * sizeof(u32)); } @@ -437,7 +358,7 @@ static int byt_send_msg(struct snd_sof_dev *sdev, struct snd_sof_ipc_msg *msg) u64 cmd = msg->header; /* send the message */ - byt_mailbox_write(sdev, sdev->host_box.offset, msg->msg_data, + sof_mailbox_write(sdev, sdev->host_box.offset, msg->msg_data, msg->msg_size); snd_sof_dsp_write64(sdev, BYT_DSP_BAR, SHIM_IPCX, cmd | SHIM_BYT_IPCX_BUSY); @@ -452,7 +373,7 @@ static int byt_get_reply(struct snd_sof_dev *sdev, struct snd_sof_ipc_msg *msg) u32 size; /* get reply */ - byt_mailbox_read(sdev, sdev->host_box.offset, &reply, sizeof(reply)); + sof_mailbox_read(sdev, sdev->host_box.offset, &reply, sizeof(reply)); if (reply.error < 0) { size = sizeof(reply); ret = reply.error; @@ -470,7 +391,7 @@ static int byt_get_reply(struct snd_sof_dev *sdev, struct snd_sof_ipc_msg *msg) /* read the message */ if (msg->msg_data && size > 0) - byt_mailbox_read(sdev, sdev->host_box.offset, msg->reply_data, + sof_mailbox_read(sdev, sdev->host_box.offset, msg->reply_data, size); return ret; @@ -799,22 +720,22 @@ struct snd_sof_dsp_ops sof_byt_ops = { .reset = byt_reset, /* Register IO */ - .write = byt_write, - .read = byt_read, - .write64 = byt_write64, - .read64 = byt_read64, + .write = sof_io_write, + .read = sof_io_read, + .write64 = sof_io_write64, + .read64 = sof_io_read64, /* Block IO */ - .block_read = byt_block_read, - .block_write = byt_block_write, + .block_read = sof_block_read, + .block_write = sof_block_write, /* doorbell */ .irq_handler = byt_irq_handler, .irq_thread = byt_irq_thread, /* mailbox */ - .mailbox_read = byt_mailbox_read, - .mailbox_write = byt_mailbox_write, + .mailbox_read = sof_mailbox_read, + .mailbox_write = sof_mailbox_write, /* ipc */ .send_msg = byt_send_msg, @@ -850,22 +771,22 @@ struct snd_sof_dsp_ops sof_cht_ops = { .reset = byt_reset, /* Register IO */ - .write = byt_write, - .read = byt_read, - .write64 = byt_write64, - .read64 = byt_read64, + .write = sof_io_write, + .read = sof_io_read, + .write64 = sof_io_write64, + .read64 = sof_io_read64, /* Block IO */ - .block_read = byt_block_read, - .block_write = byt_block_write, + .block_read = sof_block_read, + .block_write = sof_block_write, /* doorbell */ .irq_handler = byt_irq_handler, .irq_thread = byt_irq_thread, /* mailbox */ - .mailbox_read = byt_mailbox_read, - .mailbox_write = byt_mailbox_write, + .mailbox_read = sof_mailbox_read, + .mailbox_write = sof_mailbox_write, /* ipc */ .send_msg = byt_send_msg, diff --git a/sound/soc/sof/intel/cnl.c b/sound/soc/sof/intel/cnl.c index b561d287368592..76ab0be961b008 100644 --- a/sound/soc/sof/intel/cnl.c +++ b/sound/soc/sof/intel/cnl.c @@ -180,8 +180,8 @@ static int cnl_ipc_send_msg(struct snd_sof_dev *sdev, u32 cmd = msg->header; /* send the message */ - hda_dsp_mailbox_write(sdev, sdev->host_box.offset, msg->msg_data, - msg->msg_size); + sof_mailbox_write(sdev, sdev->host_box.offset, msg->msg_data, + msg->msg_size); snd_sof_dsp_write(sdev, HDA_DSP_BAR, CNL_DSP_REG_HIPCIDR, cmd | CNL_DSP_REG_HIPCIDR_BUSY); @@ -195,22 +195,22 @@ struct snd_sof_dsp_ops sof_cnl_ops = { .remove = hda_dsp_remove, /* Register IO */ - .write = hda_dsp_write, - .read = hda_dsp_read, - .write64 = hda_dsp_write64, - .read64 = hda_dsp_read64, + .write = sof_io_write, + .read = sof_io_read, + .write64 = sof_io_write64, + .read64 = sof_io_read64, /* Block IO */ - .block_read = hda_dsp_block_read, - .block_write = hda_dsp_block_write, + .block_read = sof_block_read, + .block_write = sof_block_write, /* doorbell */ .irq_handler = hda_dsp_ipc_irq_handler, .irq_thread = cnl_ipc_irq_thread, /* mailbox */ - .mailbox_read = hda_dsp_mailbox_read, - .mailbox_write = hda_dsp_mailbox_write, + .mailbox_read = sof_mailbox_read, + .mailbox_write = sof_mailbox_write, /* ipc */ .send_msg = cnl_ipc_send_msg, diff --git a/sound/soc/sof/intel/hda-ipc.c b/sound/soc/sof/intel/hda-ipc.c index efaf293c2c77dc..c307a8a67e839c 100644 --- a/sound/soc/sof/intel/hda-ipc.c +++ b/sound/soc/sof/intel/hda-ipc.c @@ -88,8 +88,8 @@ int hda_dsp_ipc_send_msg(struct snd_sof_dev *sdev, struct snd_sof_ipc_msg *msg) u32 cmd = msg->header; /* send IPC message to DSP */ - hda_dsp_mailbox_write(sdev, sdev->host_box.offset, msg->msg_data, - msg->msg_size); + 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, cmd | HDA_DSP_REG_HIPCI_BUSY); @@ -104,8 +104,7 @@ int hda_dsp_ipc_get_reply(struct snd_sof_dev *sdev, u32 size; /* get IPC reply from DSP in the mailbox */ - hda_dsp_mailbox_read(sdev, sdev->host_box.offset, &reply, - sizeof(reply)); + sof_mailbox_read(sdev, sdev->host_box.offset, &reply, sizeof(reply)); if (reply.error < 0) { size = sizeof(reply); ret = reply.error; @@ -123,8 +122,8 @@ int hda_dsp_ipc_get_reply(struct snd_sof_dev *sdev, /* read the message */ if (msg->msg_data && size > 0) - hda_dsp_mailbox_read(sdev, sdev->host_box.offset, - msg->reply_data, size); + sof_mailbox_read(sdev, sdev->host_box.offset, + msg->reply_data, size); return ret; } @@ -381,7 +380,7 @@ int hda_dsp_ipc_fw_ready(struct snd_sof_dev *sdev, u32 msg_id) msg_id, offset); /* copy data from the DSP FW ready offset */ - hda_dsp_block_read(sdev, offset, fw_ready, sizeof(*fw_ready)); + sof_block_read(sdev, offset, fw_ready, sizeof(*fw_ready)); dev_info(sdev->dev, " Firmware info: version %d.%d-%s build %d on %s:%s\n", v->major, v->minor, v->tag, v->build, v->date, v->time); diff --git a/sound/soc/sof/intel/hda-stream.c b/sound/soc/sof/intel/hda-stream.c index bfcc0cd63a6693..0c9c2d794061d3 100644 --- a/sound/soc/sof/intel/hda-stream.c +++ b/sound/soc/sof/intel/hda-stream.c @@ -155,7 +155,7 @@ int hda_dsp_stream_spib_config(struct snd_sof_dev *sdev, enable << hstream->index); /* set the SPIB value */ - hda_dsp_write(sdev, stream->spib_addr, size); + sof_io_write(sdev, stream->spib_addr, size); return 0; } diff --git a/sound/soc/sof/intel/hda.c b/sound/soc/sof/intel/hda.c index 31d6108d3bff9f..3356d5d25f64a9 100644 --- a/sound/soc/sof/intel/hda.c +++ b/sound/soc/sof/intel/hda.c @@ -42,72 +42,6 @@ /* platform specific devices */ #include "shim.h" -/* - * Register IO - */ - -void hda_dsp_write(struct snd_sof_dev *sdev, void __iomem *addr, u32 value) -{ - writel(value, addr); -} - -u32 hda_dsp_read(struct snd_sof_dev *sdev, void __iomem *addr) -{ - return readl(addr); -} - -void hda_dsp_write64(struct snd_sof_dev *sdev, void __iomem *addr, u64 value) -{ - writeq(value, addr); -} - -u64 hda_dsp_read64(struct snd_sof_dev *sdev, void __iomem *addr) -{ - return readq(addr); -} - -/* - * Memory copy. - */ - -void hda_dsp_block_write(struct snd_sof_dev *sdev, u32 offset, void *src, - size_t size) -{ - void __iomem *dest = sdev->bar[sdev->mmio_bar] + offset; - u32 tmp = 0; - int i, m, n; - const u8 *src_byte = src; - u8 *dst_byte; - - m = size / 4; - n = size % 4; - - /* __iowrite32_copy use 32bit size values so divide by 4 */ - __iowrite32_copy(dest, src, m); - - if (n) { - /* first read the 32bit data of dest, then change affected - * bytes, and write back to dest. For unaffected bytes, it - * should not be changed - */ - __ioread32_copy(&tmp, dest + m * 4, 1); - - dst_byte = (u8 *)&tmp; - for (i = 0; i < n; i++) - dst_byte[i] = src_byte[m * 4 + i]; - - __iowrite32_copy(dest + m * 4, &tmp, 1); - } -} - -void hda_dsp_block_read(struct snd_sof_dev *sdev, u32 offset, void *dest, - size_t size) -{ - void __iomem *src = sdev->bar[sdev->mmio_bar] + offset; - - memcpy_fromio(dest, src, size); -} - /* * Debug */ @@ -185,16 +119,16 @@ static void hda_dsp_get_registers(struct snd_sof_dev *sdev, u32 *stack, size_t stack_words) { /* first read registers */ - hda_dsp_block_read(sdev, sdev->dsp_oops_offset, xoops, sizeof(*xoops)); + sof_block_read(sdev, sdev->dsp_oops_offset, xoops, sizeof(*xoops)); /* then get panic info */ - hda_dsp_block_read(sdev, sdev->dsp_oops_offset + sizeof(*xoops), - panic_info, sizeof(*panic_info)); + sof_block_read(sdev, sdev->dsp_oops_offset + sizeof(*xoops), + panic_info, sizeof(*panic_info)); /* then get the stack */ - hda_dsp_block_read(sdev, sdev->dsp_oops_offset + sizeof(*xoops) + - sizeof(*panic_info), stack, - stack_words * sizeof(u32)); + sof_block_read(sdev, sdev->dsp_oops_offset + sizeof(*xoops) + + sizeof(*panic_info), stack, + stack_words * sizeof(u32)); } void hda_dsp_dump_skl(struct snd_sof_dev *sdev, u32 flags) @@ -254,26 +188,6 @@ void hda_dsp_dump(struct snd_sof_dev *sdev, u32 flags) } } -/* - * IPC Mailbox IO - */ - -void hda_dsp_mailbox_write(struct snd_sof_dev *sdev, u32 offset, - void *message, size_t bytes) -{ - void __iomem *dest = sdev->bar[sdev->mailbox_bar] + offset; - - memcpy_toio(dest, message, bytes); -} - -void hda_dsp_mailbox_read(struct snd_sof_dev *sdev, u32 offset, - void *message, size_t bytes) -{ - void __iomem *src = sdev->bar[sdev->mailbox_bar] + offset; - - memcpy_fromio(message, src, bytes); -} - /* * Supported devices. */ diff --git a/sound/soc/sof/intel/hda.h b/sound/soc/sof/intel/hda.h index d0ce487d2678f2..8a31e60068af51 100644 --- a/sound/soc/sof/intel/hda.h +++ b/sound/soc/sof/intel/hda.h @@ -413,22 +413,6 @@ int hda_dsp_runtime_resume(struct snd_sof_dev *sdev); void hda_dsp_dump_skl(struct snd_sof_dev *sdev, u32 flags); void hda_dsp_dump(struct snd_sof_dev *sdev, u32 flags); -/* - * DSP IO - */ -void hda_dsp_write(struct snd_sof_dev *sdev, void __iomem *addr, u32 value); -u32 hda_dsp_read(struct snd_sof_dev *sdev, void __iomem *addr); -void hda_dsp_write64(struct snd_sof_dev *sdev, void __iomem *addr, u64 value); -u64 hda_dsp_read64(struct snd_sof_dev *sdev, void __iomem *addr); -void hda_dsp_block_write(struct snd_sof_dev *sdev, u32 offset, void *src, - size_t size); -void hda_dsp_block_read(struct snd_sof_dev *sdev, u32 offset, void *dest, - size_t size); -void hda_dsp_mailbox_write(struct snd_sof_dev *sdev, u32 offset, - void *message, size_t bytes); -void hda_dsp_mailbox_read(struct snd_sof_dev *sdev, u32 offset, - void *message, size_t bytes); - /* * DSP PCM Operations. */ diff --git a/sound/soc/sof/intel/hsw.c b/sound/soc/sof/intel/hsw.c index 675a75baff2eb9..0a329bc5a30f70 100644 --- a/sound/soc/sof/intel/hsw.c +++ b/sound/soc/sof/intel/hsw.c @@ -74,82 +74,6 @@ static const struct snd_sof_debugfs_map hsw_debugfs[] = { static int hsw_cmd_done(struct snd_sof_dev *sdev, int dir); -/* - * Memory copy. - */ - -/* write has to deal with copying non 32 bit sized data */ -static void hsw_block_write(struct snd_sof_dev *sdev, u32 offset, void *src, - size_t size) -{ - void __iomem *dest = sdev->bar[sdev->mmio_bar] + offset; - u32 tmp = 0; - int i, m, n; - const u8 *src_byte = src; - - m = size / 4; - n = size % 4; - - /* __iowrite32_copy use 32bit size values so divide by 4 */ - __iowrite32_copy(dest, src, m); - - if (n) { - for (i = 0; i < n; i++) - tmp |= (u32)*(src_byte + m * 4 + i) << (i * 8); - __iowrite32_copy(dest + m * 4, &tmp, 1); - } -} - -static void hsw_block_read(struct snd_sof_dev *sdev, u32 offset, void *dest, - size_t size) -{ - void __iomem *src = sdev->bar[sdev->mmio_bar] + offset; - - memcpy_fromio(dest, src, size); -} - -static void hsw_mailbox_write(struct snd_sof_dev *sdev, u32 offset, - void *message, size_t bytes) -{ - void __iomem *dest = sdev->bar[sdev->mailbox_bar] + offset; - - memcpy_toio(dest, message, bytes); -} - -static void hsw_mailbox_read(struct snd_sof_dev *sdev, u32 offset, - void *message, size_t bytes) -{ - void __iomem *src = sdev->bar[sdev->mailbox_bar] + offset; - - memcpy_fromio(message, src, bytes); -} - -/* - * Register IO - */ - -static void hsw_write(struct snd_sof_dev *sdev, void __iomem *addr, - u32 value) -{ - writel(value, addr); -} - -static u32 hsw_read(struct snd_sof_dev *sdev, void __iomem *addr) -{ - return readl(addr); -} - -static void hsw_write64(struct snd_sof_dev *sdev, void __iomem *addr, - u64 value) -{ - writeq(value, addr); -} - -static u64 hsw_read64(struct snd_sof_dev *sdev, void __iomem *addr) -{ - return readq(addr); -} - /* * DSP Control. */ @@ -297,14 +221,14 @@ static void hsw_get_registers(struct snd_sof_dev *sdev, u32 *stack, size_t stack_words) { /* first read regsisters */ - hsw_mailbox_read(sdev, sdev->dsp_oops_offset, xoops, sizeof(*xoops)); + sof_mailbox_read(sdev, sdev->dsp_oops_offset, xoops, sizeof(*xoops)); /* then get panic info */ - hsw_mailbox_read(sdev, sdev->dsp_oops_offset + sizeof(*xoops), + sof_mailbox_read(sdev, sdev->dsp_oops_offset + sizeof(*xoops), panic_info, sizeof(*panic_info)); /* then get the stack */ - hsw_mailbox_read(sdev, sdev->dsp_oops_offset + sizeof(*xoops) + + sof_mailbox_read(sdev, sdev->dsp_oops_offset + sizeof(*xoops) + sizeof(*panic_info), stack, stack_words * sizeof(u32)); } @@ -369,7 +293,7 @@ static irqreturn_t hsw_irq_thread(int irq, void *context) /* reply message from DSP */ if (ipcx & SHIM_IPCX_DONE) { /* Handle Immediate reply from DSP Core */ - hsw_mailbox_read(sdev, sdev->host_box.offset, &hdr, + sof_mailbox_read(sdev, sdev->host_box.offset, &hdr, sizeof(hdr)); /* @@ -512,7 +436,7 @@ static int hsw_fw_ready(struct snd_sof_dev *sdev, u32 msg_id) msg_id, offset); /* copy data from the DSP FW ready offset */ - hsw_block_read(sdev, offset, fw_ready, sizeof(*fw_ready)); + sof_block_read(sdev, offset, fw_ready, sizeof(*fw_ready)); snd_sof_dsp_mailbox_init(sdev, fw_ready->dspbox_offset, fw_ready->dspbox_size, @@ -554,7 +478,7 @@ static int hsw_is_ready(struct snd_sof_dev *sdev) static int hsw_send_msg(struct snd_sof_dev *sdev, struct snd_sof_ipc_msg *msg) { /* send the message */ - hsw_mailbox_write(sdev, sdev->host_box.offset, msg->msg_data, + sof_mailbox_write(sdev, sdev->host_box.offset, msg->msg_data, msg->msg_size); snd_sof_dsp_write(sdev, HSW_DSP_BAR, SHIM_IPCX, SHIM_IPCX_BUSY); @@ -568,7 +492,7 @@ static int hsw_get_reply(struct snd_sof_dev *sdev, struct snd_sof_ipc_msg *msg) u32 size; /* get reply */ - hsw_mailbox_read(sdev, sdev->host_box.offset, &reply, sizeof(reply)); + sof_mailbox_read(sdev, sdev->host_box.offset, &reply, sizeof(reply)); if (reply.error < 0) { size = sizeof(reply); ret = reply.error; @@ -586,7 +510,7 @@ static int hsw_get_reply(struct snd_sof_dev *sdev, struct snd_sof_ipc_msg *msg) /* read the message */ if (msg->msg_data && size > 0) - hsw_mailbox_read(sdev, sdev->host_box.offset, msg->reply_data, + sof_mailbox_read(sdev, sdev->host_box.offset, msg->reply_data, size); return ret; } @@ -751,18 +675,18 @@ struct snd_sof_dsp_ops sof_hsw_ops = { .reset = hsw_reset, /* Register IO */ - .read = hsw_read, - .write = hsw_write, - .read64 = hsw_read64, - .write64 = hsw_write64, + .write = sof_io_write, + .read = sof_io_read, + .write64 = sof_io_write64, + .read64 = sof_io_read64, /* Block IO */ - .block_read = hsw_block_read, - .block_write = hsw_block_write, + .block_read = sof_block_read, + .block_write = sof_block_write, /* mailbox */ - .mailbox_read = hsw_mailbox_read, - .mailbox_write = hsw_mailbox_write, + .mailbox_read = sof_mailbox_read, + .mailbox_write = sof_mailbox_write, /* ipc */ .send_msg = hsw_send_msg, diff --git a/sound/soc/sof/intel/skl.c b/sound/soc/sof/intel/skl.c index 9531d531478ad9..83a61d58d3c1b6 100644 --- a/sound/soc/sof/intel/skl.c +++ b/sound/soc/sof/intel/skl.c @@ -45,22 +45,22 @@ struct snd_sof_dsp_ops sof_skl_ops = { .remove = hda_dsp_remove, /* Register IO */ - .write = hda_dsp_write, - .read = hda_dsp_read, - .write64 = hda_dsp_write64, - .read64 = hda_dsp_read64, + .write = sof_io_write, + .read = sof_io_read, + .write64 = sof_io_write64, + .read64 = sof_io_read64, /* Block IO */ - .block_read = hda_dsp_block_read, - .block_write = hda_dsp_block_write, + .block_read = sof_block_read, + .block_write = sof_block_write, /* doorbell */ .irq_handler = hda_dsp_ipc_irq_handler, .irq_thread = hda_dsp_ipc_irq_thread, /* mailbox */ - .mailbox_read = hda_dsp_mailbox_read, - .mailbox_write = hda_dsp_mailbox_write, + .mailbox_read = sof_mailbox_read, + .mailbox_write = sof_mailbox_write, /* ipc */ .send_msg = hda_dsp_ipc_send_msg, diff --git a/sound/soc/sof/sof-priv.h b/sound/soc/sof/sof-priv.h index 61069d77c5151a..5c311e437c58c2 100644 --- a/sound/soc/sof/sof-priv.h +++ b/sound/soc/sof/sof-priv.h @@ -570,4 +570,17 @@ extern const struct sof_arch_ops sof_xtensa_arch_ops; * Utilities */ int sof_create_platform_device(struct sof_platform_priv *priv); +void sof_io_write(struct snd_sof_dev *sdev, void __iomem *addr, u32 value); +void sof_io_write64(struct snd_sof_dev *sdev, void __iomem *addr, u64 value); +u32 sof_io_read(struct snd_sof_dev *sdev, void __iomem *addr); +u64 sof_io_read64(struct snd_sof_dev *sdev, void __iomem *addr); +void sof_mailbox_write(struct snd_sof_dev *sdev, u32 offset, + void *message, size_t bytes); +void sof_mailbox_read(struct snd_sof_dev *sdev, u32 offset, + void *message, size_t bytes); +void sof_block_write(struct snd_sof_dev *sdev, u32 offset, void *src, + size_t size); +void sof_block_read(struct snd_sof_dev *sdev, u32 offset, void *dest, + size_t size); + #endif diff --git a/sound/soc/sof/utils.c b/sound/soc/sof/utils.c index 23597064b8e33b..de2b4fa8a66329 100644 --- a/sound/soc/sof/utils.c +++ b/sound/soc/sof/utils.c @@ -9,6 +9,7 @@ // #include +#include #include #include #include @@ -66,3 +67,108 @@ int sof_create_platform_device(struct sof_platform_priv *priv) return 0; } EXPORT_SYMBOL(sof_create_platform_device); + +/* + * Register IO + */ + +void sof_io_write(struct snd_sof_dev *sdev, void __iomem *addr, u32 value) +{ + writel(value, addr); +} +EXPORT_SYMBOL(sof_io_write); + +u32 sof_io_read(struct snd_sof_dev *sdev, void __iomem *addr) +{ + return readl(addr); +} +EXPORT_SYMBOL(sof_io_read); + +void sof_io_write64(struct snd_sof_dev *sdev, void __iomem *addr, u64 value) +{ +#ifdef CONFIG_64BIT + writeq(value, addr); +#else + memcpy_toio(addr, &value, sizeof(value)); +#endif +} +EXPORT_SYMBOL(sof_io_write64); + +u64 sof_io_read64(struct snd_sof_dev *sdev, void __iomem *addr) +{ +#ifdef CONFIG_64BIT + return readq(addr); +#else + u64 val; + + memcpy_fromio(&val, addr, sizeof(val)); + return val; +#endif +} +EXPORT_SYMBOL(sof_io_read64); + +/* + * IPC Mailbox IO + */ + +void sof_mailbox_write(struct snd_sof_dev *sdev, u32 offset, + void *message, size_t bytes) +{ + void __iomem *dest = sdev->bar[sdev->mailbox_bar] + offset; + + memcpy_toio(dest, message, bytes); +} +EXPORT_SYMBOL(sof_mailbox_write); + +void sof_mailbox_read(struct snd_sof_dev *sdev, u32 offset, + void *message, size_t bytes) +{ + void __iomem *src = sdev->bar[sdev->mailbox_bar] + offset; + + memcpy_fromio(message, src, bytes); +} +EXPORT_SYMBOL(sof_mailbox_read); + +/* + * Memory copy. + */ + +void sof_block_write(struct snd_sof_dev *sdev, u32 offset, void *src, + size_t size) +{ + void __iomem *dest = sdev->bar[sdev->mmio_bar] + offset; + const u8 *src_byte = src; + u32 affected_mask; + u32 tmp = 0; + int m, n; + + m = size / 4; + n = size % 4; + + /* __iowrite32_copy use 32bit size values so divide by 4 */ + __iowrite32_copy(dest, src, m); + + if (n) { + affected_mask = (1 << (8 * n)) - 1; + + /* first read the 32bit data of dest, then change affected + * bytes, and write back to dest. For unaffected bytes, it + * should not be changed + */ + __ioread32_copy(&tmp, dest + m * 4, 1); + tmp &= ~affected_mask; + + tmp |= *(u32 *)(src_byte + m * 4) & affected_mask; + __iowrite32_copy(dest + m * 4, &tmp, 1); + } +} +EXPORT_SYMBOL(sof_block_write); + +void sof_block_read(struct snd_sof_dev *sdev, u32 offset, void *dest, + size_t size) +{ + void __iomem *src = sdev->bar[sdev->mmio_bar] + offset; + + memcpy_fromio(dest, src, size); +} +EXPORT_SYMBOL(sof_block_read);