~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/soc/sof/iomem-utils.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
  2 //
  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.
  5 //
  6 // Copyright(c) 2018-2022 Intel Corporation
  7 //
  8 // Author: Keyon Jie <yang.jie@linux.intel.com>
  9 //
 10 
 11 #include <linux/io-64-nonatomic-lo-hi.h>
 12 #include <linux/platform_device.h>
 13 #include <asm/unaligned.h>
 14 #include <sound/soc.h>
 15 #include <sound/sof.h>
 16 #include "sof-priv.h"
 17 #include "ops.h"
 18 
 19 /*
 20  * Register IO
 21  *
 22  * The sof_io_xyz() wrappers are typically referenced in snd_sof_dsp_ops
 23  * structures and cannot be inlined.
 24  */
 25 
 26 void sof_io_write(struct snd_sof_dev *sdev, void __iomem *addr, u32 value)
 27 {
 28         writel(value, addr);
 29 }
 30 EXPORT_SYMBOL(sof_io_write);
 31 
 32 u32 sof_io_read(struct snd_sof_dev *sdev, void __iomem *addr)
 33 {
 34         return readl(addr);
 35 }
 36 EXPORT_SYMBOL(sof_io_read);
 37 
 38 void sof_io_write64(struct snd_sof_dev *sdev, void __iomem *addr, u64 value)
 39 {
 40         writeq(value, addr);
 41 }
 42 EXPORT_SYMBOL(sof_io_write64);
 43 
 44 u64 sof_io_read64(struct snd_sof_dev *sdev, void __iomem *addr)
 45 {
 46         return readq(addr);
 47 }
 48 EXPORT_SYMBOL(sof_io_read64);
 49 
 50 /*
 51  * IPC Mailbox IO
 52  */
 53 
 54 void sof_mailbox_write(struct snd_sof_dev *sdev, u32 offset,
 55                        void *message, size_t bytes)
 56 {
 57         void __iomem *dest = sdev->bar[sdev->mailbox_bar] + offset;
 58 
 59         memcpy_toio(dest, message, bytes);
 60 }
 61 EXPORT_SYMBOL(sof_mailbox_write);
 62 
 63 void sof_mailbox_read(struct snd_sof_dev *sdev, u32 offset,
 64                       void *message, size_t bytes)
 65 {
 66         void __iomem *src = sdev->bar[sdev->mailbox_bar] + offset;
 67 
 68         memcpy_fromio(message, src, bytes);
 69 }
 70 EXPORT_SYMBOL(sof_mailbox_read);
 71 
 72 /*
 73  * Memory copy.
 74  */
 75 
 76 int sof_block_write(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,
 77                     u32 offset, void *src, size_t size)
 78 {
 79         int bar = snd_sof_dsp_get_bar_index(sdev, blk_type);
 80         const u8 *src_byte = src;
 81         void __iomem *dest;
 82         u32 affected_mask;
 83         u32 tmp;
 84         int m, n;
 85 
 86         if (bar < 0)
 87                 return bar;
 88 
 89         dest = sdev->bar[bar] + offset;
 90 
 91         m = size / 4;
 92         n = size % 4;
 93 
 94         /* __iowrite32_copy use 32bit size values so divide by 4 */
 95         __iowrite32_copy(dest, src, m);
 96 
 97         if (n) {
 98                 affected_mask = (1 << (8 * n)) - 1;
 99 
100                 /* first read the 32bit data of dest, then change affected
101                  * bytes, and write back to dest. For unaffected bytes, it
102                  * should not be changed
103                  */
104                 tmp = ioread32(dest + m * 4);
105                 tmp &= ~affected_mask;
106 
107                 tmp |= *(u32 *)(src_byte + m * 4) & affected_mask;
108                 iowrite32(tmp, dest + m * 4);
109         }
110 
111         return 0;
112 }
113 EXPORT_SYMBOL(sof_block_write);
114 
115 int sof_block_read(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,
116                    u32 offset, void *dest, size_t size)
117 {
118         int bar = snd_sof_dsp_get_bar_index(sdev, blk_type);
119 
120         if (bar < 0)
121                 return bar;
122 
123         memcpy_fromio(dest, sdev->bar[bar] + offset, size);
124 
125         return 0;
126 }
127 EXPORT_SYMBOL(sof_block_read);
128 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php