]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
ALSA: support module on-demand loading for seq and timer
authorKay Sievers <kay.sievers@vrfy.org>
Tue, 23 Nov 2010 16:43:19 +0000 (17:43 +0100)
committerTakashi Iwai <tiwai@suse.de>
Wed, 24 Nov 2010 04:53:25 +0000 (05:53 +0100)
If CONFIG_SND_DYNAMIC_MINORS is used, assign /dev/snd/seq and
/dev/snd/timer the usual static minors, and export specific
module aliases to generate udev module on-demand loading
instructions:

  $ cat /lib/modules/2.6.33.4-smp/modules.devname
  # Device nodes to trigger on-demand module loading.
  microcode cpu/microcode c10:184
  fuse fuse c10:229
  ppp_generic ppp c108:0
  tun net/tun c10:200
  uinput uinput c10:223
  dm_mod mapper/control c10:236
  snd_timer snd/timer c116:33
  snd_seq snd/seq c116:1

The last two lines instruct udev to create device nodes, even
when the modules are not loaded at that time.

As soon as userspace accesses any of these nodes, the in-kernel
module-loader will load the module, and the device can be used.

The header file minor calculation needed to be simplified to
make __stringify() (supports only two indirections) in
the MODULE_ALIAS macro work.

This is part of systemd's effort to get rid of unconditional
module load instructions and needless init scripts.

Cc: Lennart Poettering <lennart@poettering.net>
Signed-off-by: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
include/sound/minors.h
sound/core/seq/seq.c
sound/core/sound.c
sound/core/timer.c

index a81798ab73edc1bcdeb8e39ff9068febd2647b51..8f764204a8567ddb7924ae78a7a083063ea191d2 100644 (file)
@@ -31,8 +31,8 @@
 /* these minors can still be used for autoloading devices (/dev/aload*) */
 #define SNDRV_MINOR_CONTROL            0       /* 0 */
 #define SNDRV_MINOR_GLOBAL             1       /* 1 */
-#define SNDRV_MINOR_SEQUENCER          (SNDRV_MINOR_GLOBAL + 0 * 32)
-#define SNDRV_MINOR_TIMER              (SNDRV_MINOR_GLOBAL + 1 * 32)
+#define SNDRV_MINOR_SEQUENCER          1       /* SNDRV_MINOR_GLOBAL + 0 * 32 */
+#define SNDRV_MINOR_TIMER              33      /* SNDRV_MINOR_GLOBAL + 1 * 32 */
 
 #ifndef CONFIG_SND_DYNAMIC_MINORS
                                                /* 2 - 3 (reserved) */
index bf09a5ad186536c385e4ef85e9333b8dd38e236a..119fddb6fc99cfd5b6561bcbcc6486e1313d45ea 100644 (file)
@@ -32,6 +32,7 @@
 #include "seq_timer.h"
 #include "seq_system.h"
 #include "seq_info.h"
+#include <sound/minors.h>
 #include <sound/seq_device.h>
 
 #if defined(CONFIG_SND_SEQ_DUMMY_MODULE)
@@ -73,6 +74,9 @@ MODULE_PARM_DESC(seq_default_timer_subdevice, "The default timer subdevice numbe
 module_param(seq_default_timer_resolution, int, 0644);
 MODULE_PARM_DESC(seq_default_timer_resolution, "The default timer resolution in Hz.");
 
+MODULE_ALIAS_CHARDEV(CONFIG_SND_MAJOR, SNDRV_MINOR_SEQUENCER);
+MODULE_ALIAS("devname:snd/seq");
+
 /*
  *  INIT PART
  */
index 62a093efb453cc5d9657e4a3ce822ce42ca07748..345caea2d7497547eb95cf9d8320f2748a312fc6 100644 (file)
@@ -189,14 +189,22 @@ static const struct file_operations snd_fops =
 };
 
 #ifdef CONFIG_SND_DYNAMIC_MINORS
-static int snd_find_free_minor(void)
+static int snd_find_free_minor(int type)
 {
        int minor;
 
+       /* static minors for module auto loading */
+       if (type == SNDRV_DEVICE_TYPE_SEQUENCER)
+               return SNDRV_MINOR_SEQUENCER;
+       if (type == SNDRV_DEVICE_TYPE_TIMER)
+               return SNDRV_MINOR_TIMER;
+
        for (minor = 0; minor < ARRAY_SIZE(snd_minors); ++minor) {
-               /* skip minors still used statically for autoloading devices */
-               if (SNDRV_MINOR_DEVICE(minor) == SNDRV_MINOR_CONTROL ||
-                   minor == SNDRV_MINOR_SEQUENCER)
+               /* skip static minors still used for module auto loading */
+               if (SNDRV_MINOR_DEVICE(minor) == SNDRV_MINOR_CONTROL)
+                       continue;
+               if (minor == SNDRV_MINOR_SEQUENCER ||
+                   minor == SNDRV_MINOR_TIMER)
                        continue;
                if (!snd_minors[minor])
                        return minor;
@@ -270,7 +278,7 @@ int snd_register_device_for_dev(int type, struct snd_card *card, int dev,
        preg->private_data = private_data;
        mutex_lock(&sound_mutex);
 #ifdef CONFIG_SND_DYNAMIC_MINORS
-       minor = snd_find_free_minor();
+       minor = snd_find_free_minor(type);
 #else
        minor = snd_kernel_minor(type, card, dev);
        if (minor >= 0 && snd_minors[minor])
index b3aaa600dcc211fe9c9ee0fbc0b14482ca68e99f..ed016329e911e9ab77d95b3abb7e2a44693363df 100644 (file)
@@ -52,6 +52,9 @@ MODULE_PARM_DESC(timer_limit, "Maximum global timers in system.");
 module_param(timer_tstamp_monotonic, int, 0444);
 MODULE_PARM_DESC(timer_tstamp_monotonic, "Use posix monotonic clock source for timestamps (default).");
 
+MODULE_ALIAS_CHARDEV(CONFIG_SND_MAJOR, SNDRV_MINOR_TIMER);
+MODULE_ALIAS("devname:snd/timer");
+
 struct snd_timer_user {
        struct snd_timer_instance *timeri;
        int tread;              /* enhanced read with timestamps and events */