alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Clemens Ladisch <clemens@ladisch.de>
To: Takashi Iwai <tiwai@suse.de>,
	Mark Brown <broonie@opensource.wolfsonmicro.com>,
	alsa-devel@alsa-project.org
Subject: [RFC PATCH 05/11] ALSA: implement MEDIA_IOC_ENUM_LINKS (2)
Date: Tue, 28 Aug 2012 00:31:53 +0200	[thread overview]
Message-ID: <503BF559.7090204@ladisch.de> (raw)
In-Reply-To: <503BF48E.1090100@ladisch.de>

Allow drivers to create links between entities.

Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
---
 include/sound/core.h  |    3 ++
 include/sound/media.h |   11 ++++++
 sound/core/media.c    |   86 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 100 insertions(+), 0 deletions(-)

diff --git a/include/sound/core.h b/include/sound/core.h
index 072b642..f6577ec 100644
--- a/include/sound/core.h
+++ b/include/sound/core.h
@@ -43,6 +43,7 @@ struct module;
 struct device;
 struct device_attribute;
 struct snd_media_card_ops;
+struct snd_media_link;

 /* device allocation stuff */

@@ -152,6 +153,8 @@ struct snd_card {
 	const struct snd_media_card_ops *media_ops;
 	struct mutex media_mutex;
 	struct list_head media_entities;
+	unsigned int media_links_count;
+	struct snd_media_link *media_links;
 #endif
 };

diff --git a/include/sound/media.h b/include/sound/media.h
index 65dd068..ebb7c7d 100644
--- a/include/sound/media.h
+++ b/include/sound/media.h
@@ -44,6 +44,11 @@ int snd_media_entity_create(struct snd_card *card,
 			    unsigned int id,
 			    unsigned int sinks, unsigned int sources,
 			    void *private_data);
+int snd_media_link_create(struct snd_card *card,
+			  unsigned int source_entity,
+			  unsigned int source_pad,
+			  unsigned int sink_entity,
+			  unsigned int sink_pad);

 int snd_media_create(struct snd_card *card);
 void __init snd_media_init(void);
@@ -59,6 +64,12 @@ static inline int snd_media_entity_create(struct snd_card *card,
 					  unsigned int sinks, unsigned int sources,
 					  void *private_data)
 { return 0; }
+static inline int snd_media_link_create(struct snd_card *card,
+					unsigned int source_entity,
+					unsigned int source_pad,
+					unsigned int sink_entity,
+					unsigned int sink_pad)
+{ return 0; }


 static inline int snd_media_create(struct snd_card *card)
diff --git a/sound/core/media.c b/sound/core/media.c
index 96b09a3..aa90848 100644
--- a/sound/core/media.c
+++ b/sound/core/media.c
@@ -36,6 +36,13 @@ struct snd_media_entity {
 	unsigned int sinks, sources;
 };

+struct snd_media_link {
+	unsigned int source_entity;
+	unsigned int sink_entity;
+	unsigned short source_pad;
+	unsigned short sink_pad;
+};
+
 static struct snd_media_entity *search_entity(struct snd_card *card,
 					      unsigned int id)
 {
@@ -82,6 +89,47 @@ int snd_media_entity_create(struct snd_card *card,
 }
 EXPORT_SYMBOL(snd_media_entity_create);

+int snd_media_link_create(struct snd_card *card,
+			  unsigned int source_entity,
+			  unsigned int source_pad,
+			  unsigned int sink_entity,
+			  unsigned int sink_pad)
+{
+	struct snd_media_link link;
+	struct snd_media_link *links;
+	size_t new_size = 0;
+
+	link.source_entity = source_entity;
+	link.sink_entity = sink_entity;
+	link.source_pad = source_pad;
+	link.sink_pad = sink_pad;
+
+	mutex_lock(&card->media_mutex);
+
+	if (card->media_links) {
+		size_t allocated = ksize(card->media_links);
+		if (allocated < (card->media_links_count + 1) * sizeof(link))
+			new_size = allocated * 2;
+	} else {
+		new_size = 4 * sizeof(link);
+	}
+	if (new_size > 0) {
+		links = krealloc(card->media_links, new_size, GFP_KERNEL);
+		if (!links) {
+			mutex_unlock(&card->media_mutex);
+			return -ENOMEM;
+		}
+		card->media_links = links;
+	}
+
+	card->media_links[card->media_links_count++] = link;
+
+	mutex_unlock(&card->media_mutex);
+
+	return 0;
+}
+EXPORT_SYMBOL(snd_media_link_create);
+
 static int snd_media_dev_free(struct snd_device *device)
 {
 	struct snd_card *card = device->device_data;
@@ -94,6 +142,8 @@ static int snd_media_dev_free(struct snd_device *device)
 		kfree(e);
 	}

+	kfree(card->media_links);
+
 	return 0;
 }

@@ -136,6 +186,7 @@ static int snd_media_enum_entities(struct snd_card *card,
 {
 	struct media_entity_desc desc;
 	struct snd_media_entity *entity;
+	unsigned int i;
 	int err;

 	if (copy_from_user(&desc, descp, sizeof(desc)))
@@ -152,7 +203,13 @@ static int snd_media_enum_entities(struct snd_card *card,
 	desc.flags = 0;
 	desc.group_id = 0;
 	desc.pads = entity->sinks + entity->sources;
+
 	desc.links = 0;
+	mutex_lock(&card->media_mutex);
+	for (i = 0; i < card->media_links_count; i++)
+		if (card->media_links[i].source_entity == desc.id)
+			desc.links++;
+	mutex_unlock(&card->media_mutex);

 	err = entity->get_desc(card, entity->private_data, &desc);
 	if (err < 0)
@@ -200,6 +257,35 @@ static int snd_media_enum_links(struct snd_card *card,
 		}
 	}

+	if (links.links) {
+		struct media_link_desc desc;
+		struct snd_media_link *link;
+		unsigned int i;
+
+		memset(&desc, 0, sizeof(desc));
+		desc.source.entity = links.entity;
+		desc.source.flags = MEDIA_PAD_FL_SOURCE;
+		desc.sink.flags = MEDIA_PAD_FL_SINK;
+		desc.flags = MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE;
+
+		mutex_lock(&card->media_mutex);
+		for (i = 0; i < card->media_links_count; i++) {
+			link = &card->media_links[i];
+			if (link->source_entity != links.entity)
+				continue;
+
+			desc.source.index = link->source_pad;
+			desc.sink.entity = link->sink_entity;
+			desc.sink.index = link->sink_pad;
+			if (copy_to_user(links.links, &desc, sizeof(desc))) {
+				mutex_unlock(&card->media_mutex);
+				return -EFAULT;
+			}
+			links.links++;
+		}
+		mutex_unlock(&card->media_mutex);
+	}
+
 	return 0;
 }

  parent reply	other threads:[~2012-08-27 22:32 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-27 22:28 [RFC PATCH 1/11] expose sound device topology information Clemens Ladisch
2012-08-27 22:29 ` [RFC PATCH 01/11] ALSA: implement MEDIA_IOC_DEVICE_INFO Clemens Ladisch
2012-09-07  2:13   ` Mark Brown
2012-09-07  7:14     ` Clemens Ladisch
2012-09-07 10:40       ` Takashi Iwai
2012-08-27 22:30 ` [RFC PATCH 02/11] ALSA: implement MEDIA_IOC_ENUM_ENTITIES Clemens Ladisch
2012-08-27 22:30 ` [RFC PATCH 03/11] ALSA: pcm: add ALSA PCM device entities Clemens Ladisch
2012-08-27 22:31 ` [RFC PATCH 04/11] ALSA: implement MEDIA_IOC_ENUM_LINKS (1) Clemens Ladisch
2012-08-27 22:31 ` Clemens Ladisch [this message]
2012-08-27 22:32 ` [RFC PATCH 06/11] ALSA: implement MEDIA_IOC_SETUP_LINK Clemens Ladisch
2012-08-27 22:33 ` [RFC PATCH 07/11] [media] media: add entity types for ALSA Clemens Ladisch
2012-08-27 22:33 ` [RFC PATCH 08/11] ALSA: usb-audio: implement card get_info callback Clemens Ladisch
2012-08-27 22:34 ` [RFC PATCH 09/11] ALSA: usb-audio: create PCM device entities Clemens Ladisch
2012-08-27 22:35 ` [RFC PATCH 10/11] ALSA: usb-audio: add terminal/unit entities and links Clemens Ladisch
2012-08-27 22:36 ` [RFC PATCH 11/11] ALSA: hda-intel: implement card get_info callback Clemens Ladisch
2012-09-04 15:56 ` [RFC PATCH 1/11] expose sound device topology information Takashi Iwai
2012-09-04 18:02   ` Clemens Ladisch

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=503BF559.7090204@ladisch.de \
    --to=clemens@ladisch.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=tiwai@suse.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).