* [PATCH 2/9] ALSA: pcm: Remove unused SNDRV_PCM_IOCTL1_{FALSE, TRUE} defines
2014-12-29 18:41 [PATCH 1/9] ALSA: pcm_params: Remove unused add/sub functions Lars-Peter Clausen
@ 2014-12-29 18:41 ` Lars-Peter Clausen
2014-12-29 18:41 ` [PATCH 3/9] ALSA: pcm: Fix kerneldoc for params_*() functions Lars-Peter Clausen
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Lars-Peter Clausen @ 2014-12-29 18:41 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai; +Cc: alsa-devel, Lars-Peter Clausen
Both SNDRV_PCM_IOCTL1_FALSE and SNDRV_PCM_IOCTL1_TRUE are unused and have in
fact never been used (at least as far as the git history goes).
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
include/sound/pcm.h | 3 ---
1 file changed, 3 deletions(-)
diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index 1e7f74a..dbf2f7f 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -94,9 +94,6 @@ struct snd_pcm_ops {
#define SNDRV_PCM_DEVICES 8
#endif
-#define SNDRV_PCM_IOCTL1_FALSE ((void *)0)
-#define SNDRV_PCM_IOCTL1_TRUE ((void *)1)
-
#define SNDRV_PCM_IOCTL1_RESET 0
#define SNDRV_PCM_IOCTL1_INFO 1
#define SNDRV_PCM_IOCTL1_CHANNEL_INFO 2
--
1.8.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 3/9] ALSA: pcm: Fix kerneldoc for params_*() functions
2014-12-29 18:41 [PATCH 1/9] ALSA: pcm_params: Remove unused add/sub functions Lars-Peter Clausen
2014-12-29 18:41 ` [PATCH 2/9] ALSA: pcm: Remove unused SNDRV_PCM_IOCTL1_{FALSE, TRUE} defines Lars-Peter Clausen
@ 2014-12-29 18:41 ` Lars-Peter Clausen
2014-12-29 18:41 ` [PATCH 4/9] ALSA: pcm: Convert params_* mask helpers to static inline functions Lars-Peter Clausen
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Lars-Peter Clausen @ 2014-12-29 18:41 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai; +Cc: alsa-devel, Lars-Peter Clausen
Fix a copy and paste error in the kernel doc description for the params_*()
functions.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
include/sound/pcm.h | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index dbf2f7f..3652c94 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -854,7 +854,7 @@ static inline unsigned int params_channels(const struct snd_pcm_hw_params *p)
}
/**
- * params_channels - Get the sample rate from the hw params
+ * params_rate - Get the sample rate from the hw params
* @p: hw params
*/
static inline unsigned int params_rate(const struct snd_pcm_hw_params *p)
@@ -863,7 +863,7 @@ static inline unsigned int params_rate(const struct snd_pcm_hw_params *p)
}
/**
- * params_channels - Get the period size (in frames) from the hw params
+ * params_period_size - Get the period size (in frames) from the hw params
* @p: hw params
*/
static inline unsigned int params_period_size(const struct snd_pcm_hw_params *p)
@@ -872,7 +872,7 @@ static inline unsigned int params_period_size(const struct snd_pcm_hw_params *p)
}
/**
- * params_channels - Get the number of periods from the hw params
+ * params_periods - Get the number of periods from the hw params
* @p: hw params
*/
static inline unsigned int params_periods(const struct snd_pcm_hw_params *p)
@@ -881,7 +881,7 @@ static inline unsigned int params_periods(const struct snd_pcm_hw_params *p)
}
/**
- * params_channels - Get the buffer size (in frames) from the hw params
+ * params_buffer_size - Get the buffer size (in frames) from the hw params
* @p: hw params
*/
static inline unsigned int params_buffer_size(const struct snd_pcm_hw_params *p)
@@ -890,7 +890,7 @@ static inline unsigned int params_buffer_size(const struct snd_pcm_hw_params *p)
}
/**
- * params_channels - Get the buffer size (in bytes) from the hw params
+ * params_buffer_bytes - Get the buffer size (in bytes) from the hw params
* @p: hw params
*/
static inline unsigned int params_buffer_bytes(const struct snd_pcm_hw_params *p)
--
1.8.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 4/9] ALSA: pcm: Convert params_* mask helpers to static inline functions
2014-12-29 18:41 [PATCH 1/9] ALSA: pcm_params: Remove unused add/sub functions Lars-Peter Clausen
2014-12-29 18:41 ` [PATCH 2/9] ALSA: pcm: Remove unused SNDRV_PCM_IOCTL1_{FALSE, TRUE} defines Lars-Peter Clausen
2014-12-29 18:41 ` [PATCH 3/9] ALSA: pcm: Fix kerneldoc for params_*() functions Lars-Peter Clausen
@ 2014-12-29 18:41 ` Lars-Peter Clausen
2014-12-29 18:41 ` [PATCH 5/9] ALSA: pcm: Add kernel doc for params_*() functions Lars-Peter Clausen
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Lars-Peter Clausen @ 2014-12-29 18:41 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai; +Cc: alsa-devel, Lars-Peter Clausen
Use static inline functions instead of macros for the remaining params_*()
helpers that have not been converted yet. This is slightly cleaner and
offers better type safety.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
include/sound/pcm_params.h | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/include/sound/pcm_params.h b/include/sound/pcm_params.h
index 15760f5..bf51f22 100644
--- a/include/sound/pcm_params.h
+++ b/include/sound/pcm_params.h
@@ -325,12 +325,24 @@ static inline int snd_interval_eq(const struct snd_interval *i1, const struct sn
i1->max == i2->max && i1->openmax == i2->openmax;
}
-#define params_access(p) ((__force snd_pcm_access_t)\
- snd_mask_min(hw_param_mask_c((p), SNDRV_PCM_HW_PARAM_ACCESS)))
-#define params_format(p) ((__force snd_pcm_format_t)\
- snd_mask_min(hw_param_mask_c((p), SNDRV_PCM_HW_PARAM_FORMAT)))
-#define params_subformat(p) \
- snd_mask_min(hw_param_mask_c((p), SNDRV_PCM_HW_PARAM_SUBFORMAT))
+static inline snd_pcm_access_t params_access(const struct snd_pcm_hw_params *p)
+{
+ return (__force snd_pcm_access_t)snd_mask_min(hw_param_mask_c(p,
+ SNDRV_PCM_HW_PARAM_ACCESS));
+}
+
+static inline snd_pcm_format_t params_format(const struct snd_pcm_hw_params *p)
+{
+ return (__force snd_pcm_format_t)snd_mask_min(hw_param_mask_c(p,
+ SNDRV_PCM_HW_PARAM_FORMAT));
+}
+
+static inline snd_pcm_subformat_t
+params_subformat(const struct snd_pcm_hw_params *p)
+{
+ return (__force snd_pcm_subformat_t)snd_mask_min(hw_param_mask_c(p,
+ SNDRV_PCM_HW_PARAM_SUBFORMAT));
+}
static inline unsigned int
params_period_bytes(const struct snd_pcm_hw_params *p)
--
1.8.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 5/9] ALSA: pcm: Add kernel doc for params_*() functions
2014-12-29 18:41 [PATCH 1/9] ALSA: pcm_params: Remove unused add/sub functions Lars-Peter Clausen
` (2 preceding siblings ...)
2014-12-29 18:41 ` [PATCH 4/9] ALSA: pcm: Convert params_* mask helpers to static inline functions Lars-Peter Clausen
@ 2014-12-29 18:41 ` Lars-Peter Clausen
2014-12-29 18:41 ` [PATCH 6/9] ALSA: pcm: Simplify params_period_bytes() Lars-Peter Clausen
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Lars-Peter Clausen @ 2014-12-29 18:41 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai; +Cc: alsa-devel, Lars-Peter Clausen
Add kernel doc for the remaining undocumented params_*() functions.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
include/sound/pcm_params.h | 37 +++++++++++++++++++++++++++++++++----
1 file changed, 33 insertions(+), 4 deletions(-)
diff --git a/include/sound/pcm_params.h b/include/sound/pcm_params.h
index bf51f22..2e2169e 100644
--- a/include/sound/pcm_params.h
+++ b/include/sound/pcm_params.h
@@ -325,18 +325,30 @@ static inline int snd_interval_eq(const struct snd_interval *i1, const struct sn
i1->max == i2->max && i1->openmax == i2->openmax;
}
+/**
+ * params_access - get the access type from the hw params
+ * @p: hw params
+ */
static inline snd_pcm_access_t params_access(const struct snd_pcm_hw_params *p)
{
return (__force snd_pcm_access_t)snd_mask_min(hw_param_mask_c(p,
SNDRV_PCM_HW_PARAM_ACCESS));
}
+/**
+ * params_format - get the sample format from the hw params
+ * @p: hw params
+ */
static inline snd_pcm_format_t params_format(const struct snd_pcm_hw_params *p)
{
return (__force snd_pcm_format_t)snd_mask_min(hw_param_mask_c(p,
SNDRV_PCM_HW_PARAM_FORMAT));
}
+/**
+ * params_subformat - get the sample subformat from the hw params
+ * @p: hw params
+ */
static inline snd_pcm_subformat_t
params_subformat(const struct snd_pcm_hw_params *p)
{
@@ -344,6 +356,10 @@ params_subformat(const struct snd_pcm_hw_params *p)
SNDRV_PCM_HW_PARAM_SUBFORMAT));
}
+/**
+ * params_period_bytes - get the period size (in bytes) from the hw params
+ * @p: hw params
+ */
static inline unsigned int
params_period_bytes(const struct snd_pcm_hw_params *p)
{
@@ -352,14 +368,27 @@ params_period_bytes(const struct snd_pcm_hw_params *p)
params_channels(p)) / 8;
}
-static inline int
-params_width(const struct snd_pcm_hw_params *p)
+/**
+ * params_width - get the number of bits of the sample format from the hw params
+ * @p: hw params
+ *
+ * This function returns the number of bits per sample that the selected sample
+ * format of the hw params has.
+ */
+static inline int params_width(const struct snd_pcm_hw_params *p)
{
return snd_pcm_format_width(params_format(p));
}
-static inline int
-params_physical_width(const struct snd_pcm_hw_params *p)
+/*
+ * params_physical_width - get the storage size of the sample format from the hw params
+ * @p: hw params
+ *
+ * This functions returns the number of bits per sample that the selected sample
+ * format of the hw params takes up in memory. This will be equal or larger than
+ * params_width().
+ */
+static inline int params_physical_width(const struct snd_pcm_hw_params *p)
{
return snd_pcm_format_physical_width(params_format(p));
}
--
1.8.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 6/9] ALSA: pcm: Simplify params_period_bytes()
2014-12-29 18:41 [PATCH 1/9] ALSA: pcm_params: Remove unused add/sub functions Lars-Peter Clausen
` (3 preceding siblings ...)
2014-12-29 18:41 ` [PATCH 5/9] ALSA: pcm: Add kernel doc for params_*() functions Lars-Peter Clausen
@ 2014-12-29 18:41 ` Lars-Peter Clausen
2014-12-29 18:41 ` [PATCH 7/9] ALSA: pcm: Use __ffs() instead of ffs() in snd_mask_min() Lars-Peter Clausen
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Lars-Peter Clausen @ 2014-12-29 18:41 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai; +Cc: alsa-devel, Lars-Peter Clausen
The hw_params struct has a parameter that contains the period size in bytes.
This can be used instead of deriving the value from other parameters. This
is similar to e.g. params_buffer_bytes()
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
include/sound/pcm_params.h | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/include/sound/pcm_params.h b/include/sound/pcm_params.h
index 2e2169e..042049b 100644
--- a/include/sound/pcm_params.h
+++ b/include/sound/pcm_params.h
@@ -363,9 +363,7 @@ params_subformat(const struct snd_pcm_hw_params *p)
static inline unsigned int
params_period_bytes(const struct snd_pcm_hw_params *p)
{
- return (params_period_size(p) *
- snd_pcm_format_physical_width(params_format(p)) *
- params_channels(p)) / 8;
+ return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_PERIOD_BYTES)->min;
}
/**
--
1.8.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 7/9] ALSA: pcm: Use __ffs() instead of ffs() in snd_mask_min()
2014-12-29 18:41 [PATCH 1/9] ALSA: pcm_params: Remove unused add/sub functions Lars-Peter Clausen
` (4 preceding siblings ...)
2014-12-29 18:41 ` [PATCH 6/9] ALSA: pcm: Simplify params_period_bytes() Lars-Peter Clausen
@ 2014-12-29 18:41 ` Lars-Peter Clausen
2014-12-29 18:41 ` [PATCH 8/9] ALSA: snd_pcm_oss_period_size: Use round{up, down}_pow_of_two() Lars-Peter Clausen
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Lars-Peter Clausen @ 2014-12-29 18:41 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai; +Cc: alsa-devel, Lars-Peter Clausen
The difference between __ffs and ffs is that ffs will return a one based
index whereas __ffs will return a zero based index. Furthermore ffs will
check if the passed value is zero and return zero in that case, whereas
__ffs behavior is undefined if the passed parameter is 0.
Since we already check if the mask is 0 before calling ffs and also subtract
1 from the result __ffs is the better choice.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
include/sound/pcm_params.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/sound/pcm_params.h b/include/sound/pcm_params.h
index 042049b..c99e20b 100644
--- a/include/sound/pcm_params.h
+++ b/include/sound/pcm_params.h
@@ -92,7 +92,7 @@ static inline unsigned int snd_mask_min(const struct snd_mask *mask)
int i;
for (i = 0; i < SNDRV_MASK_SIZE; i++) {
if (mask->bits[i])
- return ffs(mask->bits[i]) - 1 + (i << 5);
+ return __ffs(mask->bits[i]) + (i << 5);
}
return 0;
}
--
1.8.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 8/9] ALSA: snd_pcm_oss_period_size: Use round{up, down}_pow_of_two()
2014-12-29 18:41 [PATCH 1/9] ALSA: pcm_params: Remove unused add/sub functions Lars-Peter Clausen
` (5 preceding siblings ...)
2014-12-29 18:41 ` [PATCH 7/9] ALSA: pcm: Use __ffs() instead of ffs() in snd_mask_min() Lars-Peter Clausen
@ 2014-12-29 18:41 ` Lars-Peter Clausen
2014-12-29 18:41 ` [PATCH 9/9] ALSA: pcm: Replace custom ld2 function with __fls Lars-Peter Clausen
2014-12-30 15:49 ` [PATCH 1/9] ALSA: pcm_params: Remove unused add/sub functions Takashi Iwai
8 siblings, 0 replies; 10+ messages in thread
From: Lars-Peter Clausen @ 2014-12-29 18:41 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai; +Cc: alsa-devel, Lars-Peter Clausen
Instead of opencoding them use the standard roundup_pow_of_two() and
rounddown_pow_of_two() helper functions. This gets rids one of the few users
of the custom ld2() function and also makes it a bit more obvious what the
code does.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
sound/core/oss/pcm_oss.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
index ada69d7..80423a4c 100644
--- a/sound/core/oss/pcm_oss.c
+++ b/sound/core/oss/pcm_oss.c
@@ -719,7 +719,7 @@ static int snd_pcm_oss_period_size(struct snd_pcm_substream *substream,
oss_buffer_size = snd_pcm_plug_client_size(substream,
snd_pcm_hw_param_value_max(slave_params, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, NULL)) * oss_frame_size;
- oss_buffer_size = 1 << ld2(oss_buffer_size);
+ oss_buffer_size = rounddown_pow_of_two(oss_buffer_size);
if (atomic_read(&substream->mmap_count)) {
if (oss_buffer_size > runtime->oss.mmap_bytes)
oss_buffer_size = runtime->oss.mmap_bytes;
@@ -755,14 +755,14 @@ static int snd_pcm_oss_period_size(struct snd_pcm_substream *substream,
min_period_size = snd_pcm_plug_client_size(substream,
snd_pcm_hw_param_value_min(slave_params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, NULL));
min_period_size *= oss_frame_size;
- min_period_size = 1 << (ld2(min_period_size - 1) + 1);
+ min_period_size = roundup_pow_of_two(min_period_size);
if (oss_period_size < min_period_size)
oss_period_size = min_period_size;
max_period_size = snd_pcm_plug_client_size(substream,
snd_pcm_hw_param_value_max(slave_params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, NULL));
max_period_size *= oss_frame_size;
- max_period_size = 1 << ld2(max_period_size);
+ max_period_size = rounddown_pow_of_two(max_period_size);
if (oss_period_size > max_period_size)
oss_period_size = max_period_size;
--
1.8.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 9/9] ALSA: pcm: Replace custom ld2 function with __fls
2014-12-29 18:41 [PATCH 1/9] ALSA: pcm_params: Remove unused add/sub functions Lars-Peter Clausen
` (6 preceding siblings ...)
2014-12-29 18:41 ` [PATCH 8/9] ALSA: snd_pcm_oss_period_size: Use round{up, down}_pow_of_two() Lars-Peter Clausen
@ 2014-12-29 18:41 ` Lars-Peter Clausen
2014-12-30 15:49 ` [PATCH 1/9] ALSA: pcm_params: Remove unused add/sub functions Takashi Iwai
8 siblings, 0 replies; 10+ messages in thread
From: Lars-Peter Clausen @ 2014-12-29 18:41 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai; +Cc: alsa-devel, Lars-Peter Clausen
__fls has the same semantics as ld2, so there is no need to re-implement it.
Furthermore a lot of architectures have custom implementations of __fls that
are able to use special hardware instructions to compute the result. This
makes the code slightly shorter and faster.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
include/sound/pcm_params.h | 27 +--------------------------
1 file changed, 1 insertion(+), 26 deletions(-)
diff --git a/include/sound/pcm_params.h b/include/sound/pcm_params.h
index c99e20b..3c45f39 100644
--- a/include/sound/pcm_params.h
+++ b/include/sound/pcm_params.h
@@ -38,31 +38,6 @@ int snd_pcm_hw_param_value(const struct snd_pcm_hw_params *params,
#define MASK_OFS(i) ((i) >> 5)
#define MASK_BIT(i) (1U << ((i) & 31))
-static inline unsigned int ld2(u_int32_t v)
-{
- unsigned r = 0;
-
- if (v >= 0x10000) {
- v >>= 16;
- r += 16;
- }
- if (v >= 0x100) {
- v >>= 8;
- r += 8;
- }
- if (v >= 0x10) {
- v >>= 4;
- r += 4;
- }
- if (v >= 4) {
- v >>= 2;
- r += 2;
- }
- if (v >= 2)
- r++;
- return r;
-}
-
static inline size_t snd_mask_sizeof(void)
{
return sizeof(struct snd_mask);
@@ -102,7 +77,7 @@ static inline unsigned int snd_mask_max(const struct snd_mask *mask)
int i;
for (i = SNDRV_MASK_SIZE - 1; i >= 0; i--) {
if (mask->bits[i])
- return ld2(mask->bits[i]) + (i << 5);
+ return __fls(mask->bits[i]) + (i << 5);
}
return 0;
}
--
1.8.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH 1/9] ALSA: pcm_params: Remove unused add/sub functions
2014-12-29 18:41 [PATCH 1/9] ALSA: pcm_params: Remove unused add/sub functions Lars-Peter Clausen
` (7 preceding siblings ...)
2014-12-29 18:41 ` [PATCH 9/9] ALSA: pcm: Replace custom ld2 function with __fls Lars-Peter Clausen
@ 2014-12-30 15:49 ` Takashi Iwai
8 siblings, 0 replies; 10+ messages in thread
From: Takashi Iwai @ 2014-12-30 15:49 UTC (permalink / raw)
To: Lars-Peter Clausen; +Cc: alsa-devel
At Mon, 29 Dec 2014 19:41:38 +0100,
Lars-Peter Clausen wrote:
>
> Those two functions are not used anywhere and also their name is a bit to
> generic to be in a global header, so remove them.
>
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Thanks, applied all 9 patches. But the patch 3 was applied to
for-linus branch for 3.19-rc, as it's an obvious fix. The rest are
targeted for 3.20.
Takashi
> ---
> include/sound/pcm_params.h | 14 --------------
> 1 file changed, 14 deletions(-)
>
> diff --git a/include/sound/pcm_params.h b/include/sound/pcm_params.h
> index 6b1c78f..15760f5 100644
> --- a/include/sound/pcm_params.h
> +++ b/include/sound/pcm_params.h
> @@ -325,20 +325,6 @@ static inline int snd_interval_eq(const struct snd_interval *i1, const struct sn
> i1->max == i2->max && i1->openmax == i2->openmax;
> }
>
> -static inline unsigned int add(unsigned int a, unsigned int b)
> -{
> - if (a >= UINT_MAX - b)
> - return UINT_MAX;
> - return a + b;
> -}
> -
> -static inline unsigned int sub(unsigned int a, unsigned int b)
> -{
> - if (a > b)
> - return a - b;
> - return 0;
> -}
> -
> #define params_access(p) ((__force snd_pcm_access_t)\
> snd_mask_min(hw_param_mask_c((p), SNDRV_PCM_HW_PARAM_ACCESS)))
> #define params_format(p) ((__force snd_pcm_format_t)\
> --
> 1.8.0
>
^ permalink raw reply [flat|nested] 10+ messages in thread