Skip to content

Commit 2561ff5

Browse files
ujfalusikv2019i
authored andcommitted
ASoC: SOF: Split up utils.c into sof-utils and iomem-utils
The utils.c contains wrappers and implementation for accessing iomem mapped regions and a single unrelated function to create a compressed page table from snd_dma_buffer for firmware use. The latter is used by the PCM and the dma trace code and it needs to be moved to a generic source/header for the client conversion to be possible. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
1 parent 9b704f0 commit 2561ff5

7 files changed

Lines changed: 103 additions & 65 deletions

File tree

sound/soc/sof/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
22

33
snd-sof-objs := core.o ops.o loader.o ipc.o pcm.o pm.o debug.o topology.o\
4-
control.o trace.o utils.o sof-audio.o stream-ipc.o ipc4.o
4+
control.o trace.o iomem-utils.o sof-audio.o stream-ipc.o ipc4.o
55

66
snd-sof-$(CONFIG_SND_SOC_SOF_DEBUG_PROBES) += sof-probes.o
77
snd-sof-$(CONFIG_SND_SOC_SOF_COMPRESS) += compress.o
@@ -12,9 +12,12 @@ snd-sof-of-objs := sof-of-dev.o
1212

1313
snd-sof-nocodec-objs := nocodec.o
1414

15+
snd-sof-utils-objs := sof-utils.o
16+
1517
obj-$(CONFIG_SND_SOC_SOF) += snd-sof.o
1618
obj-$(CONFIG_SND_SOC_SOF_NOCODEC) += snd-sof-nocodec.o
1719

20+
obj-$(CONFIG_SND_SOC_SOF) += snd-sof-utils.o
1821

1922
obj-$(CONFIG_SND_SOC_SOF_ACPI_DEV) += snd-sof-acpi.o
2023
obj-$(CONFIG_SND_SOC_SOF_OF_DEV) += snd-sof-of.o
Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// This file is provided under a dual BSD/GPLv2 license. When using or
44
// redistributing this file, you may do so under either license.
55
//
6-
// Copyright(c) 2018 Intel Corporation. All rights reserved.
6+
// Copyright(c) 2018-2021 Intel Corporation. All rights reserved.
77
//
88
// Author: Keyon Jie <yang.jie@linux.intel.com>
99
//
@@ -125,62 +125,3 @@ int sof_block_read(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,
125125
return 0;
126126
}
127127
EXPORT_SYMBOL(sof_block_read);
128-
129-
/*
130-
* Generic buffer page table creation.
131-
* Take the each physical page address and drop the least significant unused
132-
* bits from each (based on PAGE_SIZE). Then pack valid page address bits
133-
* into compressed page table.
134-
*/
135-
136-
int snd_sof_create_page_table(struct device *dev,
137-
struct snd_dma_buffer *dmab,
138-
unsigned char *page_table, size_t size)
139-
{
140-
int i, pages;
141-
142-
pages = snd_sgbuf_aligned_pages(size);
143-
144-
dev_dbg(dev, "generating page table for %p size 0x%zx pages %d\n",
145-
dmab->area, size, pages);
146-
147-
for (i = 0; i < pages; i++) {
148-
/*
149-
* The number of valid address bits for each page is 20.
150-
* idx determines the byte position within page_table
151-
* where the current page's address is stored
152-
* in the compressed page_table.
153-
* This can be calculated by multiplying the page number by 2.5.
154-
*/
155-
u32 idx = (5 * i) >> 1;
156-
u32 pfn = snd_sgbuf_get_addr(dmab, i * PAGE_SIZE) >> PAGE_SHIFT;
157-
u8 *pg_table;
158-
159-
dev_vdbg(dev, "pfn i %i idx %d pfn %x\n", i, idx, pfn);
160-
161-
pg_table = (u8 *)(page_table + idx);
162-
163-
/*
164-
* pagetable compression:
165-
* byte 0 byte 1 byte 2 byte 3 byte 4 byte 5
166-
* ___________pfn 0__________ __________pfn 1___________ _pfn 2...
167-
* .... .... .... .... .... .... .... .... .... .... ....
168-
* It is created by:
169-
* 1. set current location to 0, PFN index i to 0
170-
* 2. put pfn[i] at current location in Little Endian byte order
171-
* 3. calculate an intermediate value as
172-
* x = (pfn[i+1] << 4) | (pfn[i] & 0xf)
173-
* 4. put x at offset (current location + 2) in LE byte order
174-
* 5. increment current location by 5 bytes, increment i by 2
175-
* 6. continue to (2)
176-
*/
177-
if (i & 1)
178-
put_unaligned_le32((pg_table[0] & 0xf) | pfn << 4,
179-
pg_table);
180-
else
181-
put_unaligned_le32(pfn, pg_table);
182-
}
183-
184-
return pages;
185-
}
186-
EXPORT_SYMBOL(snd_sof_create_page_table);

sound/soc/sof/pcm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_PROBES)
2020
#include "sof-probes.h"
2121
#endif
22+
#include "sof-utils.h"
2223

2324
/* Create DMA buffer page table for DSP */
2425
static int create_page_table(struct snd_soc_component *component,

sound/soc/sof/sof-priv.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,10 +514,6 @@ void snd_sof_complete(struct device *dev);
514514

515515
void snd_sof_new_platform_drv(struct snd_sof_dev *sdev);
516516

517-
int snd_sof_create_page_table(struct device *dev,
518-
struct snd_dma_buffer *dmab,
519-
unsigned char *page_table, size_t size);
520-
521517
/*
522518
* Firmware loading.
523519
*/

sound/soc/sof/sof-utils.c

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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-2021 Intel Corporation. All rights reserved.
7+
//
8+
// Author: Keyon Jie <yang.jie@linux.intel.com>
9+
//
10+
11+
#include <asm/unaligned.h>
12+
#include <linux/io-64-nonatomic-lo-hi.h>
13+
#include <linux/device.h>
14+
#include <sound/memalloc.h>
15+
#include <linux/module.h>
16+
#include "sof-utils.h"
17+
18+
/*
19+
* Generic buffer page table creation.
20+
* Take the each physical page address and drop the least significant unused
21+
* bits from each (based on PAGE_SIZE). Then pack valid page address bits
22+
* into compressed page table.
23+
*/
24+
25+
int snd_sof_create_page_table(struct device *dev,
26+
struct snd_dma_buffer *dmab,
27+
unsigned char *page_table, size_t size)
28+
{
29+
int i, pages;
30+
31+
pages = snd_sgbuf_aligned_pages(size);
32+
33+
dev_dbg(dev, "generating page table for %p size 0x%zx pages %d\n",
34+
dmab->area, size, pages);
35+
36+
for (i = 0; i < pages; i++) {
37+
/*
38+
* The number of valid address bits for each page is 20.
39+
* idx determines the byte position within page_table
40+
* where the current page's address is stored
41+
* in the compressed page_table.
42+
* This can be calculated by multiplying the page number by 2.5.
43+
*/
44+
u32 idx = (5 * i) >> 1;
45+
u32 pfn = snd_sgbuf_get_addr(dmab, i * PAGE_SIZE) >> PAGE_SHIFT;
46+
u8 *pg_table;
47+
48+
dev_vdbg(dev, "pfn i %i idx %d pfn %x\n", i, idx, pfn);
49+
50+
pg_table = (u8 *)(page_table + idx);
51+
52+
/*
53+
* pagetable compression:
54+
* byte 0 byte 1 byte 2 byte 3 byte 4 byte 5
55+
* ___________pfn 0__________ __________pfn 1___________ _pfn 2...
56+
* .... .... .... .... .... .... .... .... .... .... ....
57+
* It is created by:
58+
* 1. set current location to 0, PFN index i to 0
59+
* 2. put pfn[i] at current location in Little Endian byte order
60+
* 3. calculate an intermediate value as
61+
* x = (pfn[i+1] << 4) | (pfn[i] & 0xf)
62+
* 4. put x at offset (current location + 2) in LE byte order
63+
* 5. increment current location by 5 bytes, increment i by 2
64+
* 6. continue to (2)
65+
*/
66+
if (i & 1)
67+
put_unaligned_le32((pg_table[0] & 0xf) | pfn << 4,
68+
pg_table);
69+
else
70+
put_unaligned_le32(pfn, pg_table);
71+
}
72+
73+
return pages;
74+
}
75+
EXPORT_SYMBOL(snd_sof_create_page_table);
76+
77+
MODULE_LICENSE("Dual BSD/GPL");

sound/soc/sof/sof-utils.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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) 2021 Intel Corporation. All rights reserved.
7+
*/
8+
9+
#ifndef __SOC_SOF_UTILS_H
10+
#define __SOC_SOF_UTILS_H
11+
12+
struct snd_dma_buffer;
13+
struct device;
14+
15+
int snd_sof_create_page_table(struct device *dev,
16+
struct snd_dma_buffer *dmab,
17+
unsigned char *page_table, size_t size);
18+
19+
#endif

sound/soc/sof/trace.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/sched/signal.h>
1313
#include "sof-priv.h"
1414
#include "ops.h"
15+
#include "sof-utils.h"
1516

1617
#define TRACE_FILTER_ELEMENTS_PER_ENTRY 4
1718
#define TRACE_FILTER_MAX_CONFIG_STRING_LENGTH 1024

0 commit comments

Comments
 (0)