All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: Vinod Koul <vinod.koul@intel.com>
Cc: tiwai@suse.de, alsa-devel@alsa-project.org, broonie@linaro.org,
	Clemens Ladisch <clemens@ladisch.de>,
	omair.m.abdullah@intel.com
Subject: Re: [PATCH 1/4] ALSA: control: return payload length for TLV operation
Date: Wed, 31 Aug 2016 07:04:12 +0900	[thread overview]
Message-ID: <38f437e4-56e7-dc7a-6892-c1d812fd56d3@sakamocchi.jp> (raw)
In-Reply-To: <20160830145136.GE9355@localhost>

On Aug 30 2016 23:51, Vinod Koul wrote:
> On Tue, Aug 30, 2016 at 04:09:33PM +0900, Takashi Sakamoto wrote:
>> On Aug 30 2016 16:05, Clemens Ladisch wrote:
>>> Takashi Sakamoto wrote:
>>>> [...] APIs return operated length, while TLV feature
>>>> can't. This is inconvenient to applications.
>>>>
>>>> This commit enables control core to return operated length of TLV feature.
>>>> This changes the prototype of 'snd_kcontrol_tlv_rw_t' to get a pointer to
>>>> size variable so that each implementation of the prototype can modify the
>>>> variable with operated length.
>>>
>>> I'll use this function as an example:
>>>
>>>> --- a/sound/usb/mixer.c
>>>> +++ b/sound/usb/mixer.c
>>>> @@ -535,17 +535,20 @@ int snd_usb_set_cur_mix_value(struct usb_mixer_elem_info *cval, int channel,
>>>>  * TLV callback for mixer volume controls
>>>>  */
>>>> int snd_usb_mixer_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
>>>> -			 unsigned int size, unsigned int __user *_tlv)
>>>> +			 unsigned int *size, unsigned int __user *_tlv)
>>>> {
>>>> 	struct usb_mixer_elem_info *cval = kcontrol->private_data;
>>>> 	DECLARE_TLV_DB_MINMAX(scale, 0, 0);
>>>>
>>>> -	if (size < sizeof(scale))
>>>> +	if (*size < sizeof(scale))
>>>> 		return -ENOMEM;
>>>> 	scale[2] = cval->dBmin;
>>>> 	scale[3] = cval->dBmax;
>>>> 	if (copy_to_user(_tlv, scale, sizeof(scale)))
>>>> 		return -EFAULT;
>>>> +
>>>> +	*size = sizeof(scale);
>>>> +
>>>> 	return 0;
>>>> }
>>>
>>> The size is already returned in scale[1] (it's initialized by
>>> DECLARE_TLV_DB_MINMAX()).  That's exactly what the "L" in "TLV" means.
>>>
>>> All other TLV callbacks also take care to set this field correctly.
>>>
>>> If there were any TLV callback that did not set _tlv[1] to the actual
>>> size, it would be buggy, and just needed to be fixed to do so.
>>
>> As I described, TLV feature of ALSA control interface is not only
>> used to transfer threshold level information, but also arbitrary
>> data for I/O by developers in ALSA SoC part. The '_tlv[1]' protocol
>> is not necessarily kept by them.
> 
> can you explain what you mean by 'to transfer threshold level information'
> 
> And on this discussion, IIUC, we should fill tlv[1] with size being returned
> right? For the asoc part, I think we should fix snd_soc_bytes_tlv_callback()
> to update this.

The layout of TLV packet is:
struct snd_ctl_tlv {
    unsigned int numid;   # numerical ID of a control element
    unsigned int length;  # length of payload
    unsigned int tlv[0];  # payload
};
http://git.kernel.org/cgit/linux/kernel/git/tiwai/sound.git/tree/include/uapi/sound/asound.h?h=sound-4.8-rc4#n945

In our implementaion, TLV packet payload (struct snd_ctl_tlv.tlv) is
used to transfer data. For pure threshold level information, we expects
applications and drivers to fill the payload with this protocol:
struct snd_ctl_tlv.tlv[0]:  one of SNDRV_CTL_TLVT_XXX
struct snd_ctl_tlv.tlv[1]:  length of data
struct snd_ctl_tlv.tlv[2..]: data

(You can see SNDRV_CTL_TLVT_XXX in this header.
http://git.kernel.org/cgit/linux/kernel/git/tiwai/sound.git/tree/include/uapi/sound/tlv.h?h=sound-4.8-rc4
)

On the other hand, ALSA SoC part performs:
struct snd_ctl_tlv.tlv[0..]: arbitrary data

If your 'tlv[1]' means the 'struct snd_ctl_tlv.tlv[1]', no sense.

The issue I address is current implementation cannot correctly handle
this case:
 - applications request a buffer with a certain size
 - drivers processes the request with smaller size
 - application cannot get the size

When implementing I/O operation, in my understanding, this situation
often occurs, depending on driver implementation. Fortunately, current
implementation of WM-ADSP is free from this concern, but it's better for
us not to expect this luck always.


Regards

Takashi Sakamoto

  reply	other threads:[~2016-08-30 22:04 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-29 23:44 [RFC][PATCH 0/4] ALSA: control: return payload length of TLV operation Takashi Sakamoto
2016-08-29 23:44 ` [PATCH 1/4] ALSA: control: return payload length for " Takashi Sakamoto
2016-08-30  5:29   ` Takashi Iwai
2016-08-30  6:19     ` Takashi Sakamoto
2016-08-30  6:59       ` Takashi Iwai
2016-08-30  7:13         ` Takashi Sakamoto
2016-08-30  7:39           ` Takashi Iwai
2016-08-30  7:05   ` Clemens Ladisch
2016-08-30  7:09     ` Takashi Sakamoto
2016-08-30  8:04       ` Clemens Ladisch
2016-08-30 12:22         ` Takashi Sakamoto
2016-08-30 14:51       ` Vinod Koul
2016-08-30 22:04         ` Takashi Sakamoto [this message]
2016-08-31  4:20           ` Vinod Koul
2016-08-31  4:30             ` Takashi Sakamoto
2016-08-31  9:05               ` Charles Keepax
2016-08-31  9:40                 ` Takashi Iwai
2016-08-31 11:54                   ` Clemens Ladisch
2016-08-31 12:08                     ` Takashi Iwai
2016-08-31 15:26                       ` Takashi Sakamoto
2016-08-31 15:40                         ` Takashi Iwai
2016-09-02 11:30                           ` Takashi Sakamoto
2016-09-02 13:09                             ` Takashi Iwai
2016-09-02 14:50                               ` Takashi Sakamoto
2016-09-02 15:19                                 ` Takashi Iwai
2016-09-02 16:26                                   ` Takashi Iwai
2016-09-03 11:38                             ` Charles Keepax
2016-09-04 11:07                               ` Takashi Sakamoto
2016-09-04 20:45                                 ` Takashi Iwai
2016-09-06  3:30                                   ` Takashi Sakamoto
2016-09-12 12:37                                     ` Charles Keepax
2016-09-12 15:25                                       ` Vinod Koul
2016-09-12 15:28                                         ` Takashi Iwai
2016-09-12 16:03                                           ` Charles Keepax
2016-09-12 16:28                                             ` Takashi Iwai
2016-09-13  8:39                                               ` Charles Keepax
2016-08-31 12:19                     ` Charles Keepax
2016-08-31 13:24                       ` Clemens Ladisch
2016-08-31 14:18                         ` Charles Keepax
2016-08-31 16:05                           ` Vinod Koul
2016-09-02 11:18                     ` Takashi Sakamoto
2016-09-02 16:05                       ` Takashi Iwai
2016-09-03  3:53                         ` Takashi Sakamoto
2016-09-03 11:32                       ` Charles Keepax
2016-08-29 23:44 ` [PATCH 2/4] ALSA: control: delegate checking the length of data payload to each drivers Takashi Sakamoto
2016-08-30 15:46   ` Vinod Koul
2016-08-29 23:44 ` [PATCH 3/4] ALSA: control: add kerneldoc for snd_kcontrol_tlv_rw_t Takashi Sakamoto
2016-08-29 23:44 ` [PATCH 4/4] ALSA: control: bump up protocol version to 2.0.8 Takashi Sakamoto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=38f437e4-56e7-dc7a-6892-c1d812fd56d3@sakamocchi.jp \
    --to=o-takashi@sakamocchi.jp \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@linaro.org \
    --cc=clemens@ladisch.de \
    --cc=omair.m.abdullah@intel.com \
    --cc=tiwai@suse.de \
    --cc=vinod.koul@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.