ASoC: SOF: topology: fix: handle DAI widget connections properly with multiple CPU DAI's#1863
Conversation
plbossart
left a comment
There was a problem hiding this comment.
not fully clear on what this fixes?
sound/soc/sof/topology.c
Outdated
| for_each_rtd_cpu_dai(rtd, i, cpu_dai) | ||
| cpu_dai->capture_widget = w; | ||
| for_each_rtd_cpu_dai(rtd, i, cpu_dai) { | ||
| /* find the first empty capture_widget */ |
There was a problem hiding this comment.
probably want to explain that the order does not matter.
There was a problem hiding this comment.
@bardliao the change looks good to me I'd modify the commit message to say something like this:
ASoC: SOF: topology: handle DAI widget connections properly with multiple CPU DAI's
" Currently, when connecting a DAI widget to the BE CPU DAI, we overwrite the previous connections. This worked because we only ever had 1 CPU DAI for each rtd until now. But with multiple CPU DAI's, a new connection between a BE CPU DAI and the DAI widget should be established without affecting the previous connections. So, modify the loop to set the playback/capture widget for the first BE CPU DAI that does have a connection established previously."
Thanks @ranj063 That's much clear than mine. |
sound/soc/sof/topology.c
Outdated
| * We expect that DAI widget will define in | ||
| * right order by topology, however, it is also | ||
| * fine if it doesn't since all DAI widgets | ||
| * will be enabled/disabled at the same time |
There was a problem hiding this comment.
@bardliao better to just say "the order of DAI widgets defined in topology doesnt matter as all the CPU DAI's will be enabled/disabled simultaneously". same thing below
sound/soc/sof/topology.c
Outdated
| if (!cpu_dai->capture_widget) | ||
| break; | ||
| } | ||
| if (cpu_dai->capture_widget) { |
There was a problem hiding this comment.
This isn't safe. If you didn't find a free slot i.e. if you didn't break out of the above loop and it ran until its termination, it means the stop condition of the loop was triggered, which can mean, that cpu_dai == NULL. In general it isn't safe to dereference the iterator after a "list_for_each()" style loop has possibly terminated normally. This isn't a list-traversing loop, but it still doesn't look safe.
sound/soc/sof/topology.c
Outdated
| if (!cpu_dai->playback_widget) | ||
| break; | ||
| } | ||
| if (cpu_dai->playback_widget) { |
There was a problem hiding this comment.
ditto, you need a better detection of loop terminating normally.
kv2019i
left a comment
There was a problem hiding this comment.
Some improvements needed still, see inline
kv2019i
left a comment
There was a problem hiding this comment.
Seems better now, waiting for consensus on the couple of inline discussions.
plbossart
left a comment
There was a problem hiding this comment.
note to maintainers: need to remove the fixes tag and squash this with initial version before upstream
| * Please create DAI widget in the right order | ||
| * to ensure BE will connect to the right DAI | ||
| * widget. | ||
| */ |
There was a problem hiding this comment.
Sorry, I might be the only one who doesn't understand this, but the correct order should be between what and what? I understand that certain two sequences should be defined in a matching order, right? Are both of them in topology files? Are they created automatically by macros from the same code or are these two sequences actually coded by humans? Or is this one sequence in topology and one in a machine driver? If both are created automatically from the same source, then maybe it's ok to rely on this. If not, maybe we need a way to match?
There was a problem hiding this comment.
Sorry, I might be the only one who doesn't understand this, but the correct order should be between what and what? I understand that certain two sequences should be defined in a matching order, right? Are both of them in topology files? Are they created automatically by macros from the same code or are these two sequences actually coded by humans? Or is this one sequence in topology and one in a machine driver? If both are created automatically from the same source, then maybe it's ok to rely on this. If not, maybe we need a way to match?
@lyakh The correct order is we set it in the same order between the CPU dais defined in a dai link and the DAI widget defined in topology. e,g,
SND_SOC_DAILINK_DEFsdw1_codec,
DAILINK_COMP_ARRAY(
COMP_CODEC("sdw:1:25d:1308:0", "rt1308-aif1"),
COMP_CODEC("sdw:2:25d:1308:0", "rt1308-aif1")));
in machine driver.
and
DAI_ADD(sof/pipe-dai-playback.m4,
3, ALH, 0x102, SDW1-Playback,
PIPELINE_SOURCE_3, 2, s24le,
1000, 0, 0, SCHEDULE_TIME_DOMAIN_TIMER)
DAI_ADD(sof/pipe-dai-playback.m4,
4, ALH, 0x202, SDW2-Playback,
PIPELINE_SOURCE_4, 2, s24le,
1000, 0, 0, SCHEDULE_TIME_DOMAIN_TIMER)
in topology m4 file.
Where we want to connect ALH0x102 to sdw:1:25d:1308:0 rt1308-aif1 and ALH0x202 to sdw:2:25d:1308:0 rt1308-aif1. So the pipe id (3 and 4) should be in the same order as COMP_CODEC("sdw:1:25d:1308:0", "rt1308-aif1") and COMP_CODEC("sdw:2:25d:1308:0", "rt1308-aif1"). Unfortunately, they are one in machine driver and the other in topology and both of them are created by human.
There was a problem hiding this comment.
Sorry, I might be the only one who doesn't understand this, but the correct order should be between what and what? I understand that certain two sequences should be defined in a matching order, right? Are both of them in topology files? Are they created automatically by macros from the same code or are these two sequences actually coded by humans? Or is this one sequence in topology and one in a machine driver? If both are created automatically from the same source, then maybe it's ok to rely on this. If not, maybe we need a way to match?
@lyakh [snip] Unfortunately, they are one in machine driver and the other in topology and both of them are created by human.
@bardliao ok, thanks for the explanation. So, as you said, both files are man-made so mistakes would be possible. It would be good to be able to verify matching here, but I don't know how difficult it would be to add nor whether this is actually a usual situation and we have more of them around, in which case this might be considered acceptable.
There was a problem hiding this comment.
@lyakh we have debug message here to show the match info, so it is easy to find mismatch. And the algorithm in machine driver is fixed, we only need to design topology based on the machine driver. Now we can only seek some indirect info from the cpu dai name and widget name to match them, but this still depends on how we set name in topology and machine driver.
There was a problem hiding this comment.
A possible solution is to use a new token to identify the index. But it might need ipc structure change. So I would prefer leave it as it is.
There was a problem hiding this comment.
Yeah, it's similar to what just recently happened to apl-pcm512x: we replaced the kernel driver with a new one, that changed the order of the HDMIs, then we had to adjust the topology. Now they don't mix - you need either both new or both old, but new + old or old + new doesn't work...
RanderWang
left a comment
There was a problem hiding this comment.
I understand : we need to design topology according to the behavior of machine driver to match them correctly
|
Seems ready for merging @lyakh are you ok with the explanation to the ordering question? You still have this marked as changes-requested... |
|
CI seems completely in the weeds @wenqingfu |
@kv2019i the ordering issue seems to be not new, it isn't added by this patch. IMHO it would be good to remove that ordering dependency and replace it with a reliable matching, but that would be a separate piece of work. So probably that issue shouldn't be a blocker for this patch. |
@lyakh do you mind using the 'approve' button then? Requesting changes means we have to use admin superpowers to merge, which should be an exception. |
|
@plbossart @kv2019i unfortunately there's a conflict and force pushing new changes will dismiss all approvals. Im wondering is resolving conflicts using the web editor will retain the approvals |
I don't think doing a force-push will dismiss approvals? Anyways, it's better if bard does it. I've had nothing but issues with the web editor, let's not go there unless it's a true emergency. Mark merged the initial version, I missed this one, so we'll have to do it right and add the correct Fixes: tag from his tree. |
OK better for @bardliao to do it but it will certainly dismiss all approvals. |
… multiple CPU DAI's Currently, when connecting a DAI widget to the BE CPU DAI, we overwrite the previous connections. This worked because we only ever had 1 CPU DAI for each rtd until now. But with multiple CPU DAI's, a new connection between a BE CPU DAI and the DAI widget should be established without affecting the previous connections. So, modify the loop to set the playback/capture widget for the first BE CPU DAI that does not have a connection established previously. Fixes: 4a7e26a ("ASoC: SOF: topology: connect dai widget to all cpu-dais") Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
0558853
Done. Tested on CML. |
Currently, when connecting a DAI widget to the BE CPU DAI, we overwrite
the previous connections. This worked because we only ever had 1 CPU DAI
for each rtd until now. But with multiple CPU DAI's, a new connection
between a BE CPU DAI and the DAI widget should be established without
affecting the previous connections. So, modify the loop to set the
playback/capture widget for the first BE CPU DAI that does have a
connection established previously.
Fixes: 4a7e26a ("ASoC: SOF: topology: connect dai widget to all
cpu-dais")
Signed-off-by: Bard Liao yung-chuan.liao@linux.intel.com