Skip to content

Commit 304cd07

Browse files
tiwaiperexg
authored andcommitted
[ALSA] Introduce slots option to snd module
Introduced the global 'slots' option to snd module. This option provides an alternative way to handle the order of multiple sound card instances. It's an easier approach to avoid conflict with hotplug devices, and can be used together with the existing 'order' option of each card driver. Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
1 parent e97a516 commit 304cd07

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

‎Documentation/sound/alsa/ALSA-Configuration.txt‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
5757
- Default: 1
5858
- For auto-loading more than one card, specify this
5959
option together with snd-card-X aliases.
60-
60+
slots - Reserve the slot index for the given driver.
61+
This option takes multiple strings.
62+
See "Module Autoloading Support" section for details.
6163

6264
Module snd-pcm-oss
6365
------------------
@@ -2140,6 +2142,23 @@ alias sound-slot-1 snd-ens1371
21402142
In this example, the interwave card is always loaded as the first card
21412143
(index 0) and ens1371 as the second (index 1).
21422144

2145+
Alternative (and new) way to fixate the slot assignment is to use
2146+
"slots" option of snd module. In the case above, specify like the
2147+
following:
2148+
2149+
options snd slots=snd-interwave,snd-ens1371
2150+
2151+
Then, the first slot (#0) is reserved for snd-interwave driver, and
2152+
the second (#1) for snd-ens1371. You can omit index option in each
2153+
driver if slots option is used (although you can still have them at
2154+
the same time as long as they don't conflict).
2155+
2156+
The slots option is especially useful for avoiding the possible
2157+
hot-plugging and the resultant slot conflict. For example, in the
2158+
case above again, the first two slots are already reserved. If any
2159+
other driver (e.g. snd-usb-audio) is loaded before snd-interwave or
2160+
snd-ens1371, it will be assigned to the third or later slot.
2161+
21432162

21442163
ALSA PCM devices to OSS devices mapping
21452164
=======================================

‎sound/core/init.c‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,40 @@ EXPORT_SYMBOL(snd_cards);
4343

4444
static DEFINE_MUTEX(snd_card_mutex);
4545

46+
static char *slots[SNDRV_CARDS];
47+
module_param_array(slots, charp, NULL, 0444);
48+
MODULE_PARM_DESC(slots, "Module names assigned to the slots.");
49+
50+
/* return non-zero if the given index is already reserved for another
51+
* module via slots option
52+
*/
53+
static int module_slot_mismatch(struct module *module, int idx)
54+
{
55+
#ifdef MODULE
56+
char *s1, *s2;
57+
if (!module || !module->name || !slots[idx])
58+
return 0;
59+
s1 = slots[idx];
60+
s2 = module->name;
61+
/* compare module name strings
62+
* hyphens are handled as equivalent with underscore
63+
*/
64+
for (;;) {
65+
char c1 = *s1++;
66+
char c2 = *s2++;
67+
if (c1 == '-')
68+
c1 = '_';
69+
if (c2 == '-')
70+
c2 = '_';
71+
if (c1 != c2)
72+
return 1;
73+
if (!c1)
74+
break;
75+
}
76+
#endif
77+
return 0;
78+
}
79+
4680
#if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
4781
int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int free_flag);
4882
EXPORT_SYMBOL(snd_mixer_oss_notify_callback);
@@ -115,6 +149,8 @@ struct snd_card *snd_card_new(int idx, const char *xid,
115149
for (idx2 = 0; idx2 < SNDRV_CARDS; idx2++)
116150
/* idx == -1 == 0xffff means: take any free slot */
117151
if (~snd_cards_lock & idx & 1<<idx2) {
152+
if (module_slot_mismatch(module, idx2))
153+
continue;
118154
idx = idx2;
119155
if (idx >= snd_ecards_limit)
120156
snd_ecards_limit = idx + 1;

0 commit comments

Comments
 (0)