diff options
-rw-r--r-- | Makefile | 16 | ||||
-rw-r--r-- | alsa-pcm.c | 70 | ||||
-rw-r--r-- | configfs.c | 116 | ||||
-rw-r--r-- | core.c | 197 | ||||
-rw-r--r-- | core.h | 33 | ||||
-rw-r--r-- | docs/2.Building.md | 2 | ||||
-rw-r--r-- | docs/3.Usage.md | 40 | ||||
-rw-r--r-- | dummy/Makefile | 4 | ||||
-rw-r--r-- | dummy/dummy.c | 22 | ||||
-rw-r--r-- | loopback/Makefile | 4 | ||||
-rw-r--r-- | loopback/loopback.c | 32 | ||||
-rwxr-xr-x | scripts/load.sh | 6 | ||||
-rwxr-xr-x | scripts/make-agl.sh | 6 | ||||
-rwxr-xr-x | scripts/test_configfs.sh | 26 | ||||
-rwxr-xr-x | scripts/unload.sh | 10 | ||||
-rw-r--r-- | sound/avirt.h | 54 |
16 files changed, 325 insertions, 313 deletions
@@ -1,8 +1,8 @@ # SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_AVIRT) += avirt_core.o -avirt_core-y := core.o -avirt_core-y += alsa-pcm.o -avirt_core-y += configfs.o +obj-$(CONFIG_AVIRT) += snd-avirt-core.o +snd-avirt-core-y := core.o +snd-avirt-core-y += alsa-pcm.o +snd-avirt-core-y += configfs.o ifeq ($(CONFIG_AVIRT_BUILDLOCAL),) CCFLAGS_AVIRT := "drivers/staging/" @@ -13,8 +13,8 @@ endif ccflags-y += -I${CCFLAGS_AVIRT} $(info $(KERNELRELEASE)) -obj-$(CONFIG_AVIRT_DUMMYAP) += dummy/ -obj-$(CONFIG_AVIRT_LOOPBACKAP) += loopback/ +obj-$(CONFIG_AVIRT_AP_DUMMY) += dummy/ +obj-$(CONFIG_AVIRT_AP_LOOPBACK) += loopback/ ### # For out-of-tree building @@ -29,8 +29,8 @@ endif all: CONFIG_AVIRT=m CONFIG_AVIRT_BUILDLOCAL=y \ - CONFIG_AVIRT_DUMMYAP=m \ - CONFIG_AVIRT_LOOPBACKAP=m \ + CONFIG_AVIRT_AP_DUMMY=m \ + CONFIG_AVIRT_AP_LOOPBACK=m \ make -C $(KERNEL_SRC) M=$(PWD) clean: @@ -3,7 +3,7 @@ * AVIRT - ALSA Virtual Soundcard * * Copyright (c) 2010-2018 Fiberdyne Systems Pty Ltd - * + * * alsa-pcm.c - AVIRT PCM interface */ @@ -15,24 +15,24 @@ #define D_PRINTK(fmt, args...) DDEBUG(D_LOGNAME, fmt, ##args) #define D_ERRORK(fmt, args...) DERROR(D_LOGNAME, fmt, ##args) -#define DO_AUDIOPATH_CB(ap, callback, substream, ...) \ - (((ap)->pcm_ops->callback) ? \ - (ap)->pcm_ops->callback((substream), ##__VA_ARGS__) : \ +#define DO_AUDIOPATH_CB(ap, callback, substream, ...) \ + (((ap)->pcm_ops->callback) ? \ + (ap)->pcm_ops->callback((substream), ##__VA_ARGS__) : \ 0) /** - * avirt_pcm_period_elapsed - PCM buffer complete callback + * snd_avirt_pcm_period_elapsed - PCM buffer complete callback * @substreamid: pointer to ALSA PCM substream * - * This should be called from a child Audio Path once it has finished processing - * the pcm buffer + * This should be called from a child Audio Path once it has finished + * processing the pcm buffer */ -void avirt_pcm_period_elapsed(struct snd_pcm_substream *substream) +void snd_avirt_pcm_period_elapsed(struct snd_pcm_substream *substream) { // Notify ALSA middle layer of the elapsed period boundary snd_pcm_period_elapsed(substream); } -EXPORT_SYMBOL_GPL(avirt_pcm_period_elapsed); +EXPORT_SYMBOL_GPL(snd_avirt_pcm_period_elapsed); /******************************************************************************* * ALSA PCM Callbacks @@ -41,20 +41,20 @@ EXPORT_SYMBOL_GPL(avirt_pcm_period_elapsed); * pcm_open - Implements 'open' callback for PCM middle layer * @substream: pointer to ALSA PCM substream * - * This is called when an ALSA PCM substream is opened. The substream device is - * configured here. + * This is called when an ALSA PCM substream is opened. The substream device + * is configured here. * * Returns 0 on success or error code otherwise. */ static int pcm_open(struct snd_pcm_substream *substream) { - struct avirt_audiopath *audiopath; - struct avirt_stream *stream; + struct snd_avirt_audiopath *audiopath; + struct snd_avirt_stream *stream; struct snd_pcm_hardware *hw; unsigned int chans = 0; - stream = __avirt_stream_find_by_device(substream->pcm->device); - audiopath = avirt_audiopath_get(stream->map); + stream = snd_avirt_stream_find_by_device(substream->pcm->device); + audiopath = snd_avirt_audiopath_get(stream->map); CHK_NULL_V(audiopath, "Cannot find Audio Path uid: '%s'!", stream->map); substream->private_data = audiopath; @@ -62,7 +62,7 @@ static int pcm_open(struct snd_pcm_substream *substream) hw = &substream->runtime->hw; memcpy(hw, audiopath->hw, sizeof(struct snd_pcm_hardware)); - stream = __avirt_stream_find_by_device(substream->pcm->device); + stream = snd_avirt_stream_find_by_device(substream->pcm->device); if (IS_ERR_VALUE(stream) || !stream) return PTR_ERR(stream); @@ -87,7 +87,7 @@ static int pcm_close(struct snd_pcm_substream *substream) { // Do additional Audio Path 'close' callback return DO_AUDIOPATH_CB( - ((struct avirt_audiopath *)substream->private_data), close, + ((struct snd_avirt_audiopath *)substream->private_data), close, substream); } @@ -106,10 +106,10 @@ static int pcm_hw_params(struct snd_pcm_substream *substream, { int retval; size_t bufsz; - struct avirt_audiopath *audiopath; - struct avirt_stream *stream; + struct snd_avirt_audiopath *audiopath; + struct snd_avirt_stream *stream; - stream = __avirt_stream_find_by_device(substream->pcm->device); + stream = snd_avirt_stream_find_by_device(substream->pcm->device); if (IS_ERR_VALUE(stream) || !stream) return PTR_ERR(stream); @@ -120,7 +120,7 @@ static int pcm_hw_params(struct snd_pcm_substream *substream, return -EINVAL; } - audiopath = ((struct avirt_audiopath *)substream->private_data); + audiopath = ((struct snd_avirt_audiopath *)substream->private_data); bufsz = params_buffer_bytes(hw_params) * audiopath->hw->periods_max; retval = snd_pcm_lib_alloc_vmalloc_buffer(substream, bufsz); @@ -145,8 +145,8 @@ static int pcm_hw_free(struct snd_pcm_substream *substream) // Do additional Audio Path 'hw_free' callback err = DO_AUDIOPATH_CB( - ((struct avirt_audiopath *)substream->private_data), hw_free, - substream); + ((struct snd_avirt_audiopath *)substream->private_data), + hw_free, substream); return snd_pcm_lib_free_vmalloc_buffer(substream); } @@ -165,8 +165,8 @@ static int pcm_prepare(struct snd_pcm_substream *substream) { // Do additional Audio Path 'prepare' callback return DO_AUDIOPATH_CB( - ((struct avirt_audiopath *)substream->private_data), prepare, - substream); + ((struct snd_avirt_audiopath *)substream->private_data), + prepare, substream); } /** @@ -194,8 +194,8 @@ static int pcm_trigger(struct snd_pcm_substream *substream, int cmd) // Do additional Audio Path 'trigger' callback return DO_AUDIOPATH_CB( - ((struct avirt_audiopath *)substream->private_data), trigger, - substream, cmd); + ((struct snd_avirt_audiopath *)substream->private_data), + trigger, substream, cmd); } /** @@ -212,8 +212,8 @@ static snd_pcm_uframes_t pcm_pointer(struct snd_pcm_substream *substream) { // Do additional Audio Path 'pointer' callback return DO_AUDIOPATH_CB( - ((struct avirt_audiopath *)substream->private_data), pointer, - substream); + ((struct snd_avirt_audiopath *)substream->private_data), + pointer, substream); } /** @@ -235,7 +235,7 @@ static int pcm_get_time_info( struct snd_pcm_audio_tstamp_report *audio_tstamp_report) { return DO_AUDIOPATH_CB( - ((struct avirt_audiopath *)substream->private_data), + ((struct snd_avirt_audiopath *)substream->private_data), get_time_info, substream, system_ts, audio_ts, audio_tstamp_config, audio_tstamp_report); } @@ -265,8 +265,8 @@ static int pcm_copy_user(struct snd_pcm_substream *substream, int channel, // Do additional Audio Path 'copy_user' callback return DO_AUDIOPATH_CB( - ((struct avirt_audiopath *)substream->private_data), copy_user, - substream, channel, pos, src, count); + ((struct snd_avirt_audiopath *)substream->private_data), + copy_user, substream, channel, pos, src, count); } /** @@ -286,7 +286,7 @@ static int pcm_copy_kernel(struct snd_pcm_substream *substream, int channel, unsigned long pos, void *buf, unsigned long count) { return DO_AUDIOPATH_CB( - ((struct avirt_audiopath *)substream->private_data), + ((struct snd_avirt_audiopath *)substream->private_data), copy_kernel, substream, channel, pos, buf, count); } @@ -302,7 +302,7 @@ static int pcm_copy_kernel(struct snd_pcm_substream *substream, int channel, static int pcm_ack(struct snd_pcm_substream *substream) { return DO_AUDIOPATH_CB( - ((struct avirt_audiopath *)substream->private_data), ack, + ((struct snd_avirt_audiopath *)substream->private_data), ack, substream); } @@ -310,7 +310,7 @@ static int pcm_silence(struct snd_pcm_substream *substream, int channel, snd_pcm_uframes_t pos, snd_pcm_uframes_t count) { return DO_AUDIOPATH_CB( - ((struct avirt_audiopath *)substream->private_data), + ((struct snd_avirt_audiopath *)substream->private_data), fill_silence, substream, channel, pos, count); } @@ -1,9 +1,9 @@ // SPDX-License-Identifier: GPL-2.0 -/* +/* * AVIRT - ALSA Virtual Soundcard * * Copyright (c) 2010-2018 Fiberdyne Systems Pty Ltd - * + * * configfs.c - AVIRT configfs support */ @@ -17,54 +17,61 @@ #define D_PRINTK(fmt, args...) DDEBUG(D_LOGNAME, fmt, ##args) #define D_ERRORK(fmt, args...) DERROR(D_LOGNAME, fmt, ##args) -static ssize_t cfg_avirt_stream_direction_show(struct config_item *item, - char *page) +static ssize_t cfg_snd_avirt_stream_direction_show(struct config_item *item, + char *page) { ssize_t count; - struct avirt_stream *stream = avirt_stream_from_config_item(item); + struct snd_avirt_stream *stream = + snd_avirt_stream_from_config_item(item); count = sprintf(page, "%d\n", stream->direction); return count; } -CONFIGFS_ATTR_RO(cfg_avirt_stream_, direction); +CONFIGFS_ATTR_RO(cfg_snd_avirt_stream_, direction); -static ssize_t cfg_avirt_stream_map_show(struct config_item *item, char *page) +static ssize_t cfg_snd_avirt_stream_map_show(struct config_item *item, + char *page) { - struct avirt_stream *stream = avirt_stream_from_config_item(item); + struct snd_avirt_stream *stream = + snd_avirt_stream_from_config_item(item); return sprintf(page, "%s\n", stream->map); } -static ssize_t cfg_avirt_stream_map_store(struct config_item *item, - const char *page, size_t count) +static ssize_t cfg_snd_avirt_stream_map_store(struct config_item *item, + const char *page, size_t count) { char *split; - struct avirt_stream *stream = avirt_stream_from_config_item(item); + struct snd_avirt_stream *stream = + snd_avirt_stream_from_config_item(item); split = strsep((char **)&page, "\n"); memcpy(stream->map, (char *)split, count); return count; } -CONFIGFS_ATTR(cfg_avirt_stream_, map); +CONFIGFS_ATTR(cfg_snd_avirt_stream_, map); -static ssize_t cfg_avirt_stream_channels_show(struct config_item *item, - char *page) +static ssize_t cfg_snd_avirt_stream_channels_show(struct config_item *item, + char *page) { ssize_t count; - struct avirt_stream *stream = avirt_stream_from_config_item(item); + struct snd_avirt_stream *stream = + snd_avirt_stream_from_config_item(item); count = sprintf(page, "%d\n", stream->channels); return count; } -static ssize_t cfg_avirt_stream_channels_store(struct config_item *item, - const char *page, size_t count) +static ssize_t cfg_snd_avirt_stream_channels_store(struct config_item *item, + const char *page, + size_t count) { int err; - struct avirt_stream *stream = avirt_stream_from_config_item(item); + struct snd_avirt_stream *stream = + snd_avirt_stream_from_config_item(item); unsigned long tmp; char *p = (char *)page; @@ -79,37 +86,37 @@ static ssize_t cfg_avirt_stream_channels_store(struct config_item *item, return count; } -CONFIGFS_ATTR(cfg_avirt_stream_, channels); +CONFIGFS_ATTR(cfg_snd_avirt_stream_, channels); -static struct configfs_attribute *cfg_avirt_stream_attrs[] = { - &cfg_avirt_stream_attr_channels, - &cfg_avirt_stream_attr_map, - &cfg_avirt_stream_attr_direction, +static struct configfs_attribute *cfg_snd_avirt_stream_attrs[] = { + &cfg_snd_avirt_stream_attr_channels, + &cfg_snd_avirt_stream_attr_map, + &cfg_snd_avirt_stream_attr_direction, NULL, }; -static void cfg_avirt_stream_release(struct config_item *item) +static void cfg_snd_avirt_stream_release(struct config_item *item) { D_INFOK("item->name:%s", item->ci_namebuf); - kfree(avirt_stream_from_config_item(item)); + kfree(snd_avirt_stream_from_config_item(item)); } -static struct configfs_item_operations cfg_avirt_stream_ops = { - .release = cfg_avirt_stream_release, +static struct configfs_item_operations cfg_snd_avirt_stream_ops = { + .release = cfg_snd_avirt_stream_release, }; -static struct config_item_type cfg_avirt_stream_type = { - .ct_item_ops = &cfg_avirt_stream_ops, - .ct_attrs = cfg_avirt_stream_attrs, +static struct config_item_type cfg_snd_avirt_stream_type = { + .ct_item_ops = &cfg_snd_avirt_stream_ops, + .ct_attrs = cfg_snd_avirt_stream_attrs, .ct_owner = THIS_MODULE, }; static struct config_item * - cfg_avirt_stream_make_item(struct config_group *group, const char *name) +cfg_snd_avirt_stream_make_item(struct config_group *group, const char *name) { char *split; int direction; - struct avirt_stream *stream; + struct snd_avirt_stream *stream; // Get prefix (playback_ or capture_) split = strsep((char **)&name, "_"); @@ -130,24 +137,25 @@ static struct config_item * // Get stream name, and create PCM for stream split = strsep((char **)&name, "\n"); - stream = __avirt_stream_create(split, direction); + stream = snd_avirt_stream_create(split, direction); if (IS_ERR(stream)) return ERR_PTR(PTR_ERR(stream)); - config_item_init_type_name(&stream->item, name, &cfg_avirt_stream_type); + config_item_init_type_name(&stream->item, name, + &cfg_snd_avirt_stream_type); return &stream->item; } -static ssize_t cfg_avirt_stream_group_sealed_show(struct config_item *item, - char *page) +static ssize_t cfg_snd_avirt_stream_group_sealed_show(struct config_item *item, + char *page) { - return snprintf(page, PAGE_SIZE, "%d\n", __avirt_streams_sealed()); + return snprintf(page, PAGE_SIZE, "%d\n", snd_avirt_streams_sealed()); } -static ssize_t cfg_avirt_stream_group_sealed_store(struct config_item *item, - const char *page, - size_t count) +static ssize_t cfg_snd_avirt_stream_group_sealed_store(struct config_item *item, + const char *page, + size_t count) { unsigned long tmp; char *p = (char *)page; @@ -159,24 +167,24 @@ static ssize_t cfg_avirt_stream_group_sealed_store(struct config_item *item, return -ERANGE; } - __avirt_streams_seal(); + snd_avirt_streams_seal(); return count; } -CONFIGFS_ATTR(cfg_avirt_stream_group_, sealed); +CONFIGFS_ATTR(cfg_snd_avirt_stream_group_, sealed); -static struct configfs_attribute *cfg_avirt_stream_group_attrs[] = { - &cfg_avirt_stream_group_attr_sealed, +static struct configfs_attribute *cfg_snd_avirt_stream_group_attrs[] = { + &cfg_snd_avirt_stream_group_attr_sealed, NULL, }; -static struct configfs_group_operations cfg_avirt_stream_group_ops = { - .make_item = cfg_avirt_stream_make_item +static struct configfs_group_operations cfg_snd_avirt_stream_group_ops = { + .make_item = cfg_snd_avirt_stream_make_item }; static struct config_item_type cfg_stream_group_type = { - .ct_group_ops = &cfg_avirt_stream_group_ops, - .ct_attrs = cfg_avirt_stream_group_attrs, + .ct_group_ops = &cfg_snd_avirt_stream_group_ops, + .ct_attrs = cfg_snd_avirt_stream_group_attrs, .ct_owner = THIS_MODULE }; @@ -185,17 +193,15 @@ static struct config_item_type cfg_avirt_group_type = { }; static struct configfs_subsystem cfg_subsys = { - .su_group = - { - .cg_item = - { - .ci_namebuf = "avirt", + .su_group = { + .cg_item = { + .ci_namebuf = "snd-avirt", .ci_type = &cfg_avirt_group_type, }, }, }; -int __init __avirt_configfs_init(struct avirt_core *core) +int __init snd_avirt_configfs_init(struct snd_avirt_core *core) { int err; @@ -222,7 +228,7 @@ exit_configfs: return err; } -void __exit __avirt_configfs_exit(struct avirt_core *core) +void __exit snd_avirt_configfs_exit(struct snd_avirt_core *core) { configfs_unregister_default_group(core->stream_group); configfs_unregister_subsystem(&cfg_subsys); @@ -3,7 +3,7 @@ * AVIRT - ALSA Virtual Soundcard * * Copyright (c) 2010-2018 Fiberdyne Systems Pty Ltd - * + * * core.c - AVIRT core internals */ @@ -27,44 +27,43 @@ MODULE_LICENSE("GPL v2"); #define SND_AVIRTUAL_DRIVER "snd_avirt" -extern struct snd_pcm_ops pcm_ops; - -static struct avirt_core core = { +static struct snd_avirt_core core = { .stream_count = 0, .streams_sealed = false, }; -struct avirt_coreinfo coreinfo = { - .version = {0, 0, 1}, +struct snd_avirt_coreinfo coreinfo = { + .version = { 0, 0, 1 }, }; static LIST_HEAD(audiopath_list); -struct avirt_audiopath_obj { +struct snd_avirt_audiopath_obj { struct kobject kobj; struct list_head list; - struct avirt_audiopath *path; + struct snd_avirt_audiopath *path; }; -static struct kset *avirt_audiopath_kset; +static struct kset *snd_avirt_audiopath_kset; static struct kobject *kobj; -#define to_audiopath_obj(d) container_of(d, struct avirt_audiopath_obj, kobj) -#define to_audiopath_attr(a) \ - container_of(a, struct avirt_audiopath_attribute, attr) +#define to_audiopath_obj(d) \ + container_of(d, struct snd_avirt_audiopath_obj, kobj) +#define to_audiopath_attr(a) \ + container_of(a, struct snd_avirt_audiopath_attribute, attr) /** - * struct avirt_audiopath_attribute - access the attributes of Audio Path + * struct snd_avirt_audiopath_attribute - access the attributes of Audio Path * @attr: attributes of an Audio Path * @show: pointer to the show function * @store: pointer to the store function */ -struct avirt_audiopath_attribute { +struct snd_avirt_audiopath_attribute { struct attribute attr; - ssize_t (*show)(struct avirt_audiopath_obj *d, - struct avirt_audiopath_attribute *attr, char *buf); - ssize_t (*store)(struct avirt_audiopath_obj *d, - struct avirt_audiopath_attribute *attr, + ssize_t (*show)(struct snd_avirt_audiopath_obj *d, + struct snd_avirt_audiopath_attribute *attr, char *buf); + ssize_t (*store)(struct snd_avirt_audiopath_obj *d, + struct snd_avirt_audiopath_attribute *attr, const char *buf, size_t count); }; @@ -77,8 +76,8 @@ struct avirt_audiopath_attribute { static ssize_t audiopath_attr_show(struct kobject *kobj, struct attribute *attr, char *buf) { - struct avirt_audiopath_attribute *audiopath_attr; - struct avirt_audiopath_obj *audiopath_obj; + struct snd_avirt_audiopath_attribute *audiopath_attr; + struct snd_avirt_audiopath_obj *audiopath_obj; audiopath_attr = to_audiopath_attr(attr); audiopath_obj = to_audiopath_obj(kobj); @@ -100,8 +99,8 @@ static ssize_t audiopath_attr_store(struct kobject *kobj, struct attribute *attr, const char *buf, size_t len) { - struct avirt_audiopath_attribute *audiopath_attr; - struct avirt_audiopath_obj *audiopath_obj; + struct snd_avirt_audiopath_attribute *audiopath_attr; + struct snd_avirt_audiopath_obj *audiopath_obj; audiopath_attr = to_audiopath_attr(attr); audiopath_obj = to_audiopath_obj(kobj); @@ -111,84 +110,88 @@ static ssize_t audiopath_attr_store(struct kobject *kobj, return audiopath_attr->store(audiopath_obj, audiopath_attr, buf, len); } -static const struct sysfs_ops avirt_audiopath_sysfs_ops = { +static const struct sysfs_ops snd_avirt_audiopath_sysfs_ops = { .show = audiopath_attr_show, .store = audiopath_attr_store, }; /** - * avirt_audiopath_release - Audio Path release function + * snd_avirt_audiopath_release - Audio Path release function * @kobj: pointer to Audio Paths's kobject */ -static void avirt_audiopath_release(struct kobject *kobj) +static void snd_avirt_audiopath_release(struct kobject *kobj) { - struct avirt_audiopath_obj *audiopath_obj = to_audiopath_obj(kobj); + struct snd_avirt_audiopath_obj *audiopath_obj = to_audiopath_obj(kobj); kfree(audiopath_obj); } -static ssize_t audiopath_name_show(struct avirt_audiopath_obj *audiopath_obj, - struct avirt_audiopath_attribute *attr, - char *buf) +static ssize_t + audiopath_name_show(struct snd_avirt_audiopath_obj *audiopath_obj, + struct snd_avirt_audiopath_attribute *attr, + char *buf) { return sprintf(buf, "%s\n", audiopath_obj->path->name); } -static ssize_t audiopath_version_show(struct avirt_audiopath_obj *audiopath_obj, - struct avirt_audiopath_attribute *attr, - char *buf) +static ssize_t + audiopath_version_show(struct snd_avirt_audiopath_obj *audiopath_obj, + struct snd_avirt_audiopath_attribute *attr, + char *buf) { - struct avirt_audiopath *audiopath = audiopath_obj->path; + struct snd_avirt_audiopath *audiopath = audiopath_obj->path; return sprintf(buf, "%d.%d.%d\n", audiopath->version[0], audiopath->version[1], audiopath->version[2]); } -static struct avirt_audiopath_attribute avirt_audiopath_attrs[] = { +static struct snd_avirt_audiopath_attribute snd_avirt_audiopath_attrs[] = { __ATTR_RO(audiopath_name), __ATTR_RO(audiopath_version), }; -static struct attribute *avirt_audiopath_def_attrs[] = { - &avirt_audiopath_attrs[0].attr, - &avirt_audiopath_attrs[1].attr, +static struct attribute *snd_avirt_audiopath_def_attrs[] = { + &snd_avirt_audiopath_attrs[0].attr, + &snd_avirt_audiopath_attrs[1].attr, NULL, }; -static struct kobj_type avirt_audiopath_ktype = { - .sysfs_ops = &avirt_audiopath_sysfs_ops, - .release = avirt_audiopath_release, - .default_attrs = avirt_audiopath_def_attrs, +static struct kobj_type snd_avirt_audiopath_ktype = { + .sysfs_ops = &snd_avirt_audiopath_sysfs_ops, + .release = snd_avirt_audiopath_release, + .default_attrs = snd_avirt_audiopath_def_attrs, }; /** - * create_avirt_audiopath_obj - creates an Audio Path object + * create_snd_avirt_audiopath_obj - creates an Audio Path object * @uid: Unique ID of the Audio Path * * This creates an Audio Path object and assigns the kset and registers * it with sysfs. * @return: Pointer to the Audio Path object or NULL if it failed. */ -static struct avirt_audiopath_obj *create_avirt_audiopath_obj(const char *uid) +static struct snd_avirt_audiopath_obj * + create_snd_avirt_audiopath_obj(const char *uid) { - struct avirt_audiopath_obj *avirt_audiopath; + struct snd_avirt_audiopath_obj *snd_avirt_audiopath; int retval; - avirt_audiopath = kzalloc(sizeof(*avirt_audiopath), GFP_KERNEL); - if (!avirt_audiopath) + snd_avirt_audiopath = kzalloc(sizeof(*snd_avirt_audiopath), GFP_KERNEL); + if (!snd_avirt_audiopath) return NULL; - avirt_audiopath->kobj.kset = avirt_audiopath_kset; - retval = kobject_init_and_add(&avirt_audiopath->kobj, - &avirt_audiopath_ktype, kobj, "%s", uid); + snd_avirt_audiopath->kobj.kset = snd_avirt_audiopath_kset; + retval = kobject_init_and_add(&snd_avirt_audiopath->kobj, + &snd_avirt_audiopath_ktype, kobj, "%s", + uid); if (retval) { - kobject_put(&avirt_audiopath->kobj); + kobject_put(&snd_avirt_audiopath->kobj); return NULL; } - kobject_uevent(&avirt_audiopath->kobj, KOBJ_ADD); - return avirt_audiopath; + kobject_uevent(&snd_avirt_audiopath->kobj, KOBJ_ADD); + return snd_avirt_audiopath; } -static struct snd_pcm *pcm_create(struct avirt_stream *stream) +static struct snd_pcm *pcm_create(struct snd_avirt_stream *stream) { bool playback = false, capture = false; struct snd_pcm *pcm; @@ -224,25 +227,24 @@ static struct snd_pcm *pcm_create(struct avirt_stream *stream) } /** - * destroy_avirt_audiopath_obj - destroys an Audio Path object + * destroy_snd_avirt_audiopath_obj - destroys an Audio Path object * @name: the Audio Path object */ -static void destroy_avirt_audiopath_obj(struct avirt_audiopath_obj *p) +static void destroy_snd_avirt_audiopath_obj(struct snd_avirt_audiopath_obj *p) { kobject_put(&p->kobj); } /** - * avirt_audiopath_get - retrieves the Audio Path by its UID + * snd_avirt_audiopath_get - retrieves the Audio Path by its UID * @uid: Unique ID for the Audio Path * @return: Corresponding Audio Path */ -struct avirt_audiopath *avirt_audiopath_get(const char *uid) +struct snd_avirt_audiopath *snd_avirt_audiopath_get(const char *uid) { - struct avirt_audiopath_obj *ap_obj; + struct snd_avirt_audiopath_obj *ap_obj; - list_for_each_entry(ap_obj, &audiopath_list, list) - { + list_for_each_entry(ap_obj, &audiopath_list, list) { // pr_info("get_ap %s\n", ap_obj->path->uid); if (!strcmp(ap_obj->path->uid, uid)) return ap_obj->path; @@ -252,22 +254,22 @@ struct avirt_audiopath *avirt_audiopath_get(const char *uid) } /** - * avirt_audiopath_register - register Audio Path with ALSA virtual driver + * snd_avirt_audiopath_register - register Audio Path with AVIRT * @audiopath: Audio Path to be registered * @core: ALSA virtual driver core info * @return: 0 on success or error code otherwise */ -int avirt_audiopath_register(struct avirt_audiopath *audiopath, - struct avirt_coreinfo **info) +int snd_avirt_audiopath_register(struct snd_avirt_audiopath *audiopath, + struct snd_avirt_coreinfo **info) { - struct avirt_audiopath_obj *audiopath_obj; + struct snd_avirt_audiopath_obj *audiopath_obj; if (!audiopath) { D_ERRORK("Audio Path is NULL!"); return -EINVAL; } - audiopath_obj = create_avirt_audiopath_obj(audiopath->uid); + audiopath_obj = create_snd_avirt_audiopath_obj(audiopath->uid); if (!audiopath_obj) { D_INFOK("Failed to alloc driver object"); return -ENOMEM; @@ -288,16 +290,16 @@ int avirt_audiopath_register(struct avirt_audiopath *audiopath, return 0; } -EXPORT_SYMBOL_GPL(avirt_audiopath_register); +EXPORT_SYMBOL_GPL(snd_avirt_audiopath_register); /** - * avirt_audiopath_deregister - deregister Audio Path with ALSA virtual driver + * snd_avirt_audiopath_deregister - deregister Audio Path with AVIRT * @audiopath: Audio Path to be deregistered * @return: 0 on success or error code otherwise */ -int avirt_audiopath_deregister(struct avirt_audiopath *audiopath) +int snd_avirt_audiopath_deregister(struct snd_avirt_audiopath *audiopath) { - struct avirt_audiopath_obj *audiopath_obj; + struct snd_avirt_audiopath_obj *audiopath_obj; // Check if audio path is registered if (!audiopath) { @@ -312,32 +314,31 @@ int avirt_audiopath_deregister(struct avirt_audiopath *audiopath) } list_del(&audiopath_obj->list); - destroy_avirt_audiopath_obj(audiopath_obj); + destroy_snd_avirt_audiopath_obj(audiopath_obj); D_INFOK("Deregistered Audio Path %s", audiopath->uid); return 0; } -EXPORT_SYMBOL_GPL(avirt_audiopath_deregister); +EXPORT_SYMBOL_GPL(snd_avirt_audiopath_deregister); /** - * avirt_stream_count - get the stream count for the given direction + * snd_avirt_stream_count - get the stream count for the given direction * @direction: The direction to get the stream count for * @return: The stream count */ -int avirt_stream_count(unsigned int direction) +int snd_avirt_stream_count(unsigned int direction) { struct list_head *entry; struct config_item *item; - struct avirt_stream *stream; + struct snd_avirt_stream *stream; unsigned int count = 0; if (direction > 1) return -ERANGE; - list_for_each(entry, &core.stream_group->cg_children) - { + list_for_each(entry, &core.stream_group->cg_children) { item = container_of(entry, struct config_item, ci_entry); - stream = avirt_stream_from_config_item(item); + stream = snd_avirt_stream_from_config_item(item); if (!stream) return -EFAULT; if (stream->direction == direction) @@ -346,18 +347,19 @@ int avirt_stream_count(unsigned int direction) return count; } -EXPORT_SYMBOL_GPL(avirt_stream_count); +EXPORT_SYMBOL_GPL(snd_avirt_stream_count); /** - * __avirt_stream_create - Create audio stream, including it's ALSA PCM device + * snd_avirt_stream_create - Create audio stream, including it's ALSA PCM device * @name: The name designated to the audio stream * @direction: The PCM direction (SNDRV_PCM_STREAM_PLAYBACK or * SNDRV_PCM_STREAM_CAPTURE) * @return: The newly created audio stream if successful, or an error pointer */ -struct avirt_stream *__avirt_stream_create(const char *name, int direction) +struct snd_avirt_stream *snd_avirt_stream_create(const char *name, + int direction) { - struct avirt_stream *stream; + struct snd_avirt_stream *stream; stream = kzalloc(sizeof(*stream), GFP_KERNEL); if (!stream) @@ -374,11 +376,11 @@ struct avirt_stream *__avirt_stream_create(const char *name, int direction) return stream; } -int __avirt_streams_seal(void) +int snd_avirt_streams_seal(void) { int err = 0; - struct avirt_audiopath_obj *ap_obj; - struct avirt_stream *stream; + struct snd_avirt_audiopath_obj *ap_obj; + struct snd_avirt_stream *stream; struct config_item *item; struct list_head *entry; @@ -387,9 +389,9 @@ int __avirt_streams_seal(void) return -1; } - list_for_each (entry, &core.stream_group->cg_children) { + list_for_each(entry, &core.stream_group->cg_children) { item = container_of(entry, struct config_item, ci_entry); - stream = avirt_stream_from_config_item(item); + stream = snd_avirt_stream_from_config_item(item); if (!stream) return -EFAULT; stream->pcm = pcm_create(stream); @@ -397,7 +399,7 @@ int __avirt_streams_seal(void) return (PTR_ERR(stream->pcm)); } - list_for_each_entry (ap_obj, &audiopath_list, list) { + list_for_each_entry(ap_obj, &audiopath_list, list) { D_INFOK("configure() AP uid: %s", ap_obj->path->uid); ap_obj->path->configure(core.card, core.stream_group, core.stream_count); @@ -414,14 +416,14 @@ int __avirt_streams_seal(void) return err; } -bool __avirt_streams_sealed(void) +bool snd_avirt_streams_sealed(void) { return core.streams_sealed; } -struct avirt_stream *__avirt_stream_find_by_device(unsigned int device) +struct snd_avirt_stream *snd_avirt_stream_find_by_device(unsigned int device) { - struct avirt_stream *stream; + struct snd_avirt_stream *stream; struct config_item *item; struct list_head *entry; @@ -430,10 +432,9 @@ struct avirt_stream *__avirt_stream_find_by_device(unsigned int device) return ERR_PTR(-EINVAL); } - list_for_each(entry, &core.stream_group->cg_children) - { + list_for_each(entry, &core.stream_group->cg_children) { item = container_of(entry, struct config_item, ci_entry); - stream = avirt_stream_from_config_item(item); + stream = snd_avirt_stream_from_config_item(item); if (!stream) return ERR_PTR(-EFAULT); if (stream->device == device) @@ -478,14 +479,14 @@ static int __init core_init(void) strncpy(core.card->longname, "A virtual sound card driver for ALSA", 80); - avirt_audiopath_kset = + snd_avirt_audiopath_kset = kset_create_and_add("audiopaths", NULL, &core.dev->kobj); - if (!avirt_audiopath_kset) { + if (!snd_avirt_audiopath_kset) { err = -ENOMEM; goto exit_snd_card; } - err = __avirt_configfs_init(&core); + err = snd_avirt_configfs_init(&core); if (err < 0) goto exit_snd_card; @@ -506,9 +507,9 @@ exit_class: */ static void __exit core_exit(void) { - __avirt_configfs_exit(&core); + snd_avirt_configfs_exit(&core); - kset_unregister(avirt_audiopath_kset); + kset_unregister(snd_avirt_audiopath_kset); snd_card_free(core.card); device_destroy(core.avirt_class, 0); class_destroy(core.avirt_class); @@ -14,7 +14,9 @@ #include "utils.h" -struct avirt_core { +extern struct snd_pcm_ops pcm_ops; + +struct snd_avirt_core { struct snd_card *card; struct device *dev; struct class *avirt_class; @@ -24,44 +26,45 @@ struct avirt_core { }; /** - * __avirt_configfs_init - Initialise the configfs system - * @core: The avirt_core pointer + * snd_avirt_configfs_init - Initialise the configfs system + * @core: The snd_avirt_core pointer * @return: 0 on success, negative ERRNO on failure */ -int __init __avirt_configfs_init(struct avirt_core *core); +int __init snd_avirt_configfs_init(struct snd_avirt_core *core); /** - * __avirt_configfs_exit - Clean up and exit the configfs system - * @core: The avirt_core pointer + * snd_avirt_configfs_exit - Clean up and exit the configfs system + * @core: The snd_avirt_core pointer */ -void __exit __avirt_configfs_exit(struct avirt_core *core); +void __exit snd_avirt_configfs_exit(struct snd_avirt_core *core); /** - * __avirt_streams_seal - Register the sound card to user space + * snd_avirt_streams_seal - Register the sound card to user space * @return: 0 on success, negative ERRNO on failure */ -int __avirt_streams_seal(void); +int snd_avirt_streams_seal(void); /** - * __avirt_streams_sealed - Check whether the streams have been sealed or not + * snd_avirt_streams_sealed - Check if the streams have been sealed or not * @return: true if sealed, false otherwise */ -bool __avirt_streams_sealed(void); +bool snd_avirt_streams_sealed(void); /** - * __avirt_stream_find_by_device - Get audio stream from device number + * snd_avirt_stream_find_by_device - Get audio stream from device number * @device: The PCM device number corresponding to the desired stream * @return: The audio stream if found, or an error pointer otherwise */ -struct avirt_stream *__avirt_stream_find_by_device(unsigned int device); +struct snd_avirt_stream *snd_avirt_stream_find_by_device(unsigned int device); /** - * __avirt_stream_create - Create audio stream, including it's ALSA PCM device + * snd_avirt_stream_create - Create audio stream, including it's ALSA PCM device * @name: The name designated to the audio stream * @direction: The PCM direction (SNDRV_PCM_STREAM_PLAYBACK or * SNDRV_PCM_STREAM_CAPTURE) * @return: The newly created audio stream if successful, or an error pointer */ -struct avirt_stream *__avirt_stream_create(const char *name, int direction); +struct snd_avirt_stream *snd_avirt_stream_create(const char *name, + int direction); #endif /* __SOUND_AVIRT_CORE_H */ diff --git a/docs/2.Building.md b/docs/2.Building.md index 3e42746..5fd9d23 100644 --- a/docs/2.Building.md +++ b/docs/2.Building.md @@ -28,7 +28,7 @@ $ make or ```sh -$ CONFIG_AVIRT=m CONFIG_AVIRT_BUILDLOCAL=y CONFIG_AVIRT_DUMMYAP=m make -C /lib/modules/$(uname -r)/build/ M=$(pwd) +$ CONFIG_AVIRT=m CONFIG_AVIRT_BUILDLOCAL=y CONFIG_AVIRT_AP_DUMMY=m CONFIG_AVIRT_AP_LOOPBACK=m make -C /lib/modules/$(uname -r)/build/ M=$(pwd) ``` The latter is executed internally with the make file. diff --git a/docs/3.Usage.md b/docs/3.Usage.md index d65d50d..f535a07 100644 --- a/docs/3.Usage.md +++ b/docs/3.Usage.md @@ -18,9 +18,9 @@ As root, load the required `avirt_core.ko` and subsequent audio path. As an example, the Dummy Audiopath is being loaded here. ```sh -insmod avirt_core.ko -insmod dummy/avirt_dummyap.ko -insmod loopback/avirt_loopbackap.ko +insmod snd-avirt-core.ko +insmod dummy/snd-avirt-ap-dummy.ko +insmod loopback/snd-avirt-ap-loopback.ko ``` ### Note: @@ -47,16 +47,16 @@ For example, in AGL: ```sh mkdir -p /lib/modules/$(uname -r)/extra -cp avirt_core.ko avirt_dummyap.ko avirt_loopbackap.ko /lib/modules/$(uname -r)/extra +cp snd-avirt-core.ko snd-avirt-ap-dummy.ko snd-avirt-ap-loopback.ko /lib/modules/$(uname -r)/extra depmod ``` Once the modules are in place, we can load the modules using: ```sh -modprobe avirt_core -modprobe avirt_dummyap -modprobe avirt_loopbackap +modprobe snd-avirt-core +modprobe snd-avirt-ap-dummy +modprobe snd-avirt-ap-loopback ``` <a name="configure-avirt" /> @@ -93,24 +93,24 @@ Finally, we can configure AVIRT, for example: ```sh # Set up each of the cards channels -mkdir /config/avirt/streams/playback_media -echo "2">/config/avirt/streams/playback_media/channels -echo "ap_dummy">/config/avirt/streams/playback_media/map +mkdir /config/snd-avirt/streams/playback_media +echo "2">/config/snd-avirt/streams/playback_media/channels +echo "ap_dummy">/config/snd-avirt/streams/playback_media/map -mkdir /config/avirt/streams/playback_navigation -echo "1">/config/avirt/streams/playback_navigation/channels -echo "ap_dummy">/config/avirt/streams/playback_navigation/map +mkdir /config/snd-avirt/streams/playback_navigation +echo "1">/config/snd-avirt/streams/playback_navigation/channels +echo "ap_dummy">/config/snd-avirt/streams/playback_navigation/map -mkdir /config/avirt/streams/playback_emergency -echo "1">/config/avirt/streams/playback_emergency/channels -echo "ap_dummy">/config/avirt/streams/playback_emergency/map +mkdir /config/snd-avirt/streams/playback_emergency +echo "1">/config/snd-avirt/streams/playback_emergency/channels +echo "ap_dummy">/config/snd-avirt/streams/playback_emergency/map -mkdir /config/avirt/streams/capture_voice -echo "1">/config/avirt/streams/capture_voice/channels -echo "ap_dummy">/config/avirt/streams/capture_voice/map +mkdir /config/snd-avirt/streams/capture_voice +echo "1">/config/snd-avirt/streams/capture_voice/channels +echo "ap_dummy">/config/snd-avirt/streams/capture_voice/map # Finally, seal the card, and initiate configuration -echo "1">/config/avirt/streams/sealed +echo "1">/config/snd-avirt/streams/sealed ``` Alternatively, the test script at `scripts/test_configfs.sh` can be used. diff --git a/dummy/Makefile b/dummy/Makefile index 78579d7..11ceceb 100644 --- a/dummy/Makefile +++ b/dummy/Makefile @@ -1,6 +1,6 @@ -obj-$(CONFIG_AVIRT_DUMMYAP) += avirt_dummyap.o +obj-$(CONFIG_AVIRT_AP_DUMMY) += snd-avirt-ap-dummy.o $(info $(src)) -avirt_dummyap-objs := dummy.o +snd-avirt-ap-dummy-objs := dummy.o ccflags-y += -Idrivers/staging/ ccflags-y += -I$(src)/../ diff --git a/dummy/dummy.c b/dummy/dummy.c index 100972a..5f19564 100644 --- a/dummy/dummy.c +++ b/dummy/dummy.c @@ -34,7 +34,7 @@ MODULE_LICENSE("GPL v2"); #define get_dummy_ops(substream) \ (*(const struct dummy_timer_ops **)(substream)->runtime->private_data) -static struct avirt_coreinfo *coreinfo; +static struct snd_avirt_coreinfo *coreinfo; /******************************************************************************* * System Timer Interface @@ -140,7 +140,7 @@ static void dummy_systimer_callback(struct timer_list *t) dpcm->elapsed = 0; spin_unlock_irqrestore(&dpcm->lock, flags); if (elapsed) - avirt_pcm_period_elapsed(dpcm->substream); + snd_avirt_pcm_period_elapsed(dpcm->substream); } static snd_pcm_uframes_t @@ -241,18 +241,18 @@ static struct snd_pcm_ops dummyap_pcm_ops = { /******************************************************************************* * Dummy Audio Path AVIRT registration ******************************************************************************/ -int dummy_configure(struct snd_card *card, - struct config_group *avirt_stream_group, - unsigned int stream_count) +static int dummy_configure(struct snd_card *card, + struct config_group *snd_avirt_stream_group, + unsigned int stream_count) { // Do something with streams struct list_head *entry; - list_for_each (entry, &avirt_stream_group->cg_children) { + list_for_each (entry, &snd_avirt_stream_group->cg_children) { struct config_item *item = container_of(entry, struct config_item, ci_entry); - struct avirt_stream *stream = - avirt_stream_from_config_item(item); + struct snd_avirt_stream *stream = + snd_avirt_stream_from_config_item(item); AP_INFOK("stream name:%s device:%d channels:%d", stream->name, stream->device, stream->channels); } @@ -272,7 +272,7 @@ static struct snd_pcm_hardware dummyap_hw = { .periods_max = DUMMY_PERIODS_MAX, }; -static struct avirt_audiopath dummyap_module = { +static struct snd_avirt_audiopath dummyap_module = { .uid = "ap_dummy", .name = "Dummy Audio Path", .version = { 0, 0, 1 }, @@ -287,7 +287,7 @@ static int __init dummy_init(void) pr_info("init()\n"); - err = avirt_audiopath_register(&dummyap_module, &coreinfo); + err = snd_avirt_audiopath_register(&dummyap_module, &coreinfo); if ((err < 0) || (!coreinfo)) { pr_err("%s: coreinfo is NULL!\n", __func__); return err; @@ -300,7 +300,7 @@ static void __exit dummy_exit(void) { pr_info("exit()\n"); - avirt_audiopath_deregister(&dummyap_module); + snd_avirt_audiopath_deregister(&dummyap_module); } module_init(dummy_init); diff --git a/loopback/Makefile b/loopback/Makefile index 9d3c606..0546168 100644 --- a/loopback/Makefile +++ b/loopback/Makefile @@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_AVIRT_LOOPBACKAP) += avirt_loopbackap.o +obj-$(CONFIG_AVIRT_AP_LOOPBACK) += snd-avirt-ap-loopback.o $(info $(src)) -avirt_loopbackap-objs := loopback.o +snd-avirt-ap-loopback-objs := loopback.o ccflags-y += -Idrivers/staging/ ccflags-y += -I$(src)/../ diff --git a/loopback/loopback.c b/loopback/loopback.c index ba9225e..b4a82e5 100644 --- a/loopback/loopback.c +++ b/loopback/loopback.c @@ -46,7 +46,7 @@ MODULE_LICENSE("GPL"); #define NO_PITCH 100000 -static struct avirt_coreinfo *coreinfo; +static struct snd_avirt_coreinfo *coreinfo; static struct loopback *loopback; struct loopback_pcm; @@ -509,7 +509,7 @@ static void loopback_timer_function(struct timer_list *t) dpcm->period_update_pending = 0; spin_unlock_irqrestore(&dpcm->cable->lock, flags); /* need to unlock before calling below */ - avirt_pcm_period_elapsed(dpcm->substream); + snd_avirt_pcm_period_elapsed(dpcm->substream); return; } } @@ -529,7 +529,7 @@ static snd_pcm_uframes_t loopback_pointer(struct snd_pcm_substream *substream) return bytes_to_frames(runtime, pos); } -static const struct snd_pcm_hardware loopback_pcm_hardware = { +static const struct snd_pcm_hardware loopbackap_pcm_hardware = { .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME), @@ -661,7 +661,7 @@ static int loopback_open(struct snd_pcm_substream *substream) goto unlock; } spin_lock_init(&cable->lock); - cable->hw = loopback_pcm_hardware; + cable->hw = loopbackap_pcm_hardware; loopback->cables[substream->pcm->device] = cable; } dpcm->cable = cable; @@ -689,7 +689,7 @@ static int loopback_open(struct snd_pcm_substream *substream) runtime->private_data = dpcm; runtime->private_free = loopback_runtime_free; if (get_notify(dpcm)) - runtime->hw = loopback_pcm_hardware; + runtime->hw = loopbackap_pcm_hardware; else runtime->hw = cable->hw; @@ -936,7 +936,7 @@ static int loopback_mixer_new(struct loopback *loopback, int notify) int dev, dev_count, idx, err; strcpy(card->mixername, "Loopback Mixer"); - dev_count = avirt_stream_count(SNDRV_PCM_STREAM_PLAYBACK); + dev_count = snd_avirt_stream_count(SNDRV_PCM_STREAM_PLAYBACK); for (dev = 0; dev < dev_count; dev++) { pcm = loopback->pcm[dev]; setup = &loopback->setup[dev]; @@ -1043,9 +1043,9 @@ static int loopback_proc_new(struct loopback *loopback, int cidx) return 0; } -int loopbackap_configure(struct snd_card *card, - struct config_group *avirt_stream_group, - unsigned int stream_count) +static int loopbackap_configure(struct snd_card *card, + struct config_group *snd_avirt_stream_group, + unsigned int stream_count) { int err; struct list_head *entry; @@ -1056,11 +1056,11 @@ int loopbackap_configure(struct snd_card *card, loopback->card = card; mutex_init(&loopback->cable_lock); - list_for_each (entry, &avirt_stream_group->cg_children) { + list_for_each (entry, &snd_avirt_stream_group->cg_children) { struct config_item *item = container_of(entry, struct config_item, ci_entry); - struct avirt_stream *stream = - avirt_stream_from_config_item(item); + struct snd_avirt_stream *stream = + snd_avirt_stream_from_config_item(item); loopback->pcm[stream->device] = stream->pcm; AP_INFOK("stream name:%s device:%d channels:%d", stream->name, @@ -1080,11 +1080,11 @@ int loopbackap_configure(struct snd_card *card, /******************************************************************************* * Loopback Audio Path AVIRT registration ******************************************************************************/ -static struct avirt_audiopath loopbackap_module = { +static struct snd_avirt_audiopath loopbackap_module = { .uid = AP_UID, .name = "Loopback Audio Path", .version = { 0, 0, 1 }, - .hw = &loopback_pcm_hardware, + .hw = &loopbackap_pcm_hardware, .pcm_ops = &loopbackap_pcm_ops, .configure = loopbackap_configure, }; @@ -1093,7 +1093,7 @@ static int __init alsa_card_loopback_init(void) { int err = 0; - err = avirt_audiopath_register(&loopbackap_module, &coreinfo); + err = snd_avirt_audiopath_register(&loopbackap_module, &coreinfo); if ((err < 0) || (!coreinfo)) { AP_ERRORK("coreinfo is NULL!"); return err; @@ -1104,7 +1104,7 @@ static int __init alsa_card_loopback_init(void) static void __exit alsa_card_loopback_exit(void) { - avirt_audiopath_deregister(&loopbackap_module); + snd_avirt_audiopath_deregister(&loopbackap_module); } module_init(alsa_card_loopback_init); diff --git a/scripts/load.sh b/scripts/load.sh index 82f613a..103a63b 100755 --- a/scripts/load.sh +++ b/scripts/load.sh @@ -1,11 +1,11 @@ #!/bin/sh # Load the core -insmod avirt_core.ko +insmod snd-avirt-core.ko # Load the additional Audio Paths -insmod dummy/avirt_dummyap.ko -insmod loopback/avirt_loopbackap.ko +insmod dummy/snd-avirt-ap-dummy.ko +insmod loopback/snd-avirt-ap-loopback.ko # Run the test script ./scripts/test_configfs.sh diff --git a/scripts/make-agl.sh b/scripts/make-agl.sh index 4421af8..6c94fbb 100755 --- a/scripts/make-agl.sh +++ b/scripts/make-agl.sh @@ -7,6 +7,8 @@ long_sdkpath=$(xds-cli sdks get $sdk_id | grep Path) sdkpath=${long_sdkpath:4} # Build -/opt/AGL/bin/xds-cli exec --config xds-project.conf -- \ - LDFLAGS= CONFIG_AVIRT=m CONFIG_AVIRT_BUILDLOCAL=y CONFIG_AVIRT_DUMMYAP=m \ +/opt/AGL/bin/xds-cli exec --config xds-project.conf -- \ + LDFLAGS= CONFIG_AVIRT=m CONFIG_AVIRT_BUILDLOCAL=y \ + CONFIG_AVIRT_AP_DUMMY=m \ + CONFIG_AVIRT_AP_LOOPBACK=m \ make -C $sdkpath/sysroots/aarch64-agl-linux/usr/src/kernel M=$(pwd) $@ diff --git a/scripts/test_configfs.sh b/scripts/test_configfs.sh index baa5e58..b6a56f6 100755 --- a/scripts/test_configfs.sh +++ b/scripts/test_configfs.sh @@ -2,20 +2,20 @@ mkdir -p /config && mount -t configfs none /config -mkdir /config/avirt/streams/playback_media -echo "2">/config/avirt/streams/playback_media/channels -echo "ap_loopback">/config/avirt/streams/playback_media/map +mkdir /config/snd-avirt/streams/playback_media +echo "2">/config/snd-avirt/streams/playback_media/channels +echo "ap_loopback">/config/snd-avirt/streams/playback_media/map -mkdir /config/avirt/streams/playback_navigation -echo "1">/config/avirt/streams/playback_navigation/channels -echo "ap_loopback">/config/avirt/streams/playback_navigation/map +mkdir /config/snd-avirt/streams/playback_navigation +echo "1">/config/snd-avirt/streams/playback_navigation/channels +echo "ap_loopback">/config/snd-avirt/streams/playback_navigation/map -mkdir /config/avirt/streams/playback_emergency -echo "1">/config/avirt/streams/playback_emergency/channels -echo "ap_loopback">/config/avirt/streams/playback_emergency/map +mkdir /config/snd-avirt/streams/playback_emergency +echo "1">/config/snd-avirt/streams/playback_emergency/channels +echo "ap_loopback">/config/snd-avirt/streams/playback_emergency/map -mkdir /config/avirt/streams/capture_voice -echo "1">/config/avirt/streams/capture_voice/channels -echo "ap_loopback">/config/avirt/streams/capture_voice/map +mkdir /config/snd-avirt/streams/capture_voice +echo "1">/config/snd-avirt/streams/capture_voice/channels +echo "ap_loopback">/config/snd-avirt/streams/capture_voice/map -echo "1">/config/avirt/streams/sealed +echo "1">/config/snd-avirt/streams/sealed diff --git a/scripts/unload.sh b/scripts/unload.sh index 2c158d5..a18e1f5 100755 --- a/scripts/unload.sh +++ b/scripts/unload.sh @@ -1,13 +1,13 @@ #!/bin/sh -rmdir /config/avirt/streams/playback_* -rmdir /config/avirt/streams/capture_* +rmdir /config/snd-avirt/streams/playback_* +rmdir /config/snd-avirt/streams/capture_* rm_module() { lsmod |grep "^$1\>" && rmmod $1 || true } -rm_module avirt_loopbackap -rm_module avirt_dummyap -rm_module avirt_core +rm_module snd_avirt_ap_loopback +rm_module snd_avirt_ap_dummy +rm_module snd_avirt_core echo "Drivers Removed!" diff --git a/sound/avirt.h b/sound/avirt.h index 5df84fe..1a5c546 100644 --- a/sound/avirt.h +++ b/sound/avirt.h @@ -17,34 +17,34 @@ #define MAX_STREAMS 16 #define MAX_NAME_LEN 80 -#define DINFO(logname, fmt, args...) \ +#define DINFO(logname, fmt, args...) \ snd_printk(KERN_INFO "AVIRT: %s: " fmt "\n", logname, ##args) -#define DERROR(logname, fmt, args...) \ +#define DERROR(logname, fmt, args...) \ snd_printk(KERN_ERR "AVIRT: %s: " fmt "\n", logname, ##args) -#define DDEBUG(logname, fmt, args...) \ +#define DDEBUG(logname, fmt, args...) \ snd_printk(KERN_DEBUG "AVIRT: %s: " fmt "\n", logname, ##args) /** * AVIRT Audio Path configure function type - * Each Audio Path registers this at avirt_audiopath_register time. + * Each Audio Path registers this at snd_avirt_audiopath_register time. * It is then called by the core once AVIRT has been configured */ -typedef int (*avirt_audiopath_configure)(struct snd_card *card, - struct config_group *stream_group, - unsigned int stream_count); +typedef int (*snd_avirt_audiopath_configure)(struct snd_card *card, + struct config_group *stream_group, + unsigned int stream_count); /** * AVIRT Audio Path info */ -struct avirt_audiopath { +struct snd_avirt_audiopath { const char *uid; /* Unique identifier */ const char *name; /* Pretty name */ unsigned int version[3]; /* Version - Major.Minor.Ext */ const struct snd_pcm_hardware *hw; /* ALSA PCM HW conf */ const struct snd_pcm_ops *pcm_ops; /* ALSA PCM op table */ - avirt_audiopath_configure configure; /* Configure callback function */ + snd_avirt_audiopath_configure configure; /* Config callback function */ void *context; }; @@ -52,7 +52,7 @@ struct avirt_audiopath { /* * Audio stream configuration */ -struct avirt_stream { +struct snd_avirt_stream { char name[MAX_NAME_LEN]; /* Stream name */ char map[MAX_NAME_LEN]; /* Stream Audio Path mapping */ unsigned int channels; /* Stream channel count */ @@ -65,58 +65,58 @@ struct avirt_stream { /** * AVIRT core info */ -struct avirt_coreinfo { +struct snd_avirt_coreinfo { unsigned int version[3]; }; /** - * avirt_audiopath_register - register Audio Path with ALSA virtual driver + * snd_avirt_audiopath_register - register Audio Path with AVIRT * @audiopath: Audio Path to be registered * @core: ALSA virtual driver core info * @return: 0 on success or error code otherwise */ -int avirt_audiopath_register(struct avirt_audiopath *audiopath, - struct avirt_coreinfo **coreinfo); +int snd_avirt_audiopath_register(struct snd_avirt_audiopath *audiopath, + struct snd_avirt_coreinfo **coreinfo); /** - * avirt_audiopath_deregister - deregister Audio Path with ALSA virtual driver + * snd_avirt_audiopath_deregister - deregister Audio Path with AVIRT * @audiopath: Audio Path to be deregistered * @return: 0 on success or error code otherwise */ -int avirt_audiopath_deregister(struct avirt_audiopath *audiopath); +int snd_avirt_audiopath_deregister(struct snd_avirt_audiopath *audiopath); /** - * avirt_audiopath_get - retrieves the Audio Path by it's UID + * snd_avirt_audiopath_get - retrieves the Audio Path by it's UID * @uid: Unique ID for the Audio Path * @return: Corresponding Audio Path */ -struct avirt_audiopath *avirt_audiopath_get(const char *uid); +struct snd_avirt_audiopath *snd_avirt_audiopath_get(const char *uid); /** - * avirt_stream_count - get the stream count for the given direction + * snd_avirt_stream_count - get the stream count for the given direction * @direction: The direction to get the stream count for * @return: The stream count */ -int avirt_stream_count(unsigned int direction); +int snd_avirt_stream_count(unsigned int direction); /** - * avirt_stream_from_config_item - Convert a config_item to an avirt_stream + * snd_avirt_stream_from_config_item - Convert config_item to a snd_avirt_stream * @item: The config_item to convert from - * @return: The item's avirt_stream if successful, NULL otherwise + * @return: The item's snd_avirt_stream if successful, NULL otherwise */ -static inline struct avirt_stream * -avirt_stream_from_config_item(struct config_item *item) +static inline struct snd_avirt_stream * + snd_avirt_stream_from_config_item(struct config_item *item) { - return item ? container_of(item, struct avirt_stream, item) : NULL; + return item ? container_of(item, struct snd_avirt_stream, item) : NULL; } /** - * avirt_pcm_period_elapsed - PCM buffer complete callback + * snd_avirt_pcm_period_elapsed - PCM buffer complete callback * @substream: pointer to ALSA PCM substream * * This should be called from a child Audio Path once it has finished processing * the PCM buffer */ -void avirt_pcm_period_elapsed(struct snd_pcm_substream *substream); +void snd_avirt_pcm_period_elapsed(struct snd_pcm_substream *substream); #endif // __SOUND_AVIRT_H |