Commit 9bf19fbf authored by Sakari Ailus's avatar Sakari Ailus Committed by Mauro Carvalho Chehab
Browse files

media: v4l: async: Rework internal lists



This patch re-arranges internal V4L2 async lists for preparation of
supporting multiple connections per sub-device as well as cleaning up used
lists.

The list of unbound V4L2 sub-devices shall be maintained for the purpose of
listing those sub-devices only, not for their bindin status. Also, the V4L2
async connections now have, instead of two list entries, a single list
entry in the notifier's list, be that either waiting or done lists, while
the notifier's asc_list is removed.

The one-to-one relation between a sub-device and a connection is still
maintained in this patch.

Signed-off-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Tested-by: Philipp Zabel <p.zabel@pengutronix.de> # imx6qp
Tested-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> # rcar + adv746x
Tested-by: Aishwarya Kothari <aishwarya.kothari@toradex.com> # Apalis i.MX6Q with TC358743
Tested-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> # Renesas RZ/G2L SMARC
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
parent 393cfcc0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1421,7 +1421,7 @@ static int cio2_notifier_complete(struct v4l2_async_notifier *notifier)
	struct cio2_queue *q;
	int ret;

	list_for_each_entry(asd, &cio2->notifier.asc_list, asc_entry) {
	list_for_each_entry(asd, &cio2->notifier.done_list, asc_entry) {
		s_asd = to_sensor_asd(asd);
		q = &cio2->queue[s_asd->csi2.port];

+1 −1
Original line number Diff line number Diff line
@@ -395,7 +395,7 @@ static int rvin_group_notifier_init(struct rvin_dev *vin, unsigned int port,
		}
	}

	if (list_empty(&vin->group->notifier.asc_list))
	if (list_empty(&vin->group->notifier.waiting_list))
		return 0;

	vin->group->notifier.ops = &rvin_group_notify_ops;
+1 −1
Original line number Diff line number Diff line
@@ -190,7 +190,7 @@ static int rzg2l_cru_mc_parse_of_graph(struct rzg2l_cru_dev *cru)

	cru->notifier.ops = &rzg2l_cru_async_ops;

	if (list_empty(&cru->notifier.asc_list))
	if (list_empty(&cru->notifier.waiting_list))
		return 0;

	ret = v4l2_async_nf_register(&cru->v4l2_dev, &cru->notifier);
+4 −4
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ xvip_graph_find_entity(struct xvip_composite_device *xdev,
	struct xvip_graph_entity *entity;
	struct v4l2_async_connection *asd;

	list_for_each_entry(asd, &xdev->notifier.asc_list, asc_entry) {
	list_for_each_entry(asd, &xdev->notifier.done_list, asc_entry) {
		entity = to_xvip_entity(asd);
		if (entity->asd.match.fwnode == fwnode)
			return entity;
@@ -291,7 +291,7 @@ static int xvip_graph_notify_complete(struct v4l2_async_notifier *notifier)
	dev_dbg(xdev->dev, "notify complete, all subdevs registered\n");

	/* Create links for every entity. */
	list_for_each_entry(asd, &xdev->notifier.asc_list, asc_entry) {
	list_for_each_entry(asd, &xdev->notifier.done_list, asc_entry) {
		entity = to_xvip_entity(asd);
		ret = xvip_graph_build_one(xdev, entity);
		if (ret < 0)
@@ -393,7 +393,7 @@ static int xvip_graph_parse(struct xvip_composite_device *xdev)
	if (ret < 0)
		return 0;

	list_for_each_entry(asd, &xdev->notifier.asc_list, asc_entry) {
	list_for_each_entry(asd, &xdev->notifier.waiting_list, asc_entry) {
		entity = to_xvip_entity(asd);
		ret = xvip_graph_parse_one(xdev, entity->asd.match.fwnode);
		if (ret < 0) {
@@ -501,7 +501,7 @@ static int xvip_graph_init(struct xvip_composite_device *xdev)
		goto done;
	}

	if (list_empty(&xdev->notifier.asc_list)) {
	if (list_empty(&xdev->notifier.waiting_list)) {
		dev_err(xdev->dev, "no subdev found in graph\n");
		ret = -ENOENT;
		goto done;
+54 −48
Original line number Diff line number Diff line
@@ -160,7 +160,7 @@ v4l2_async_find_match(struct v4l2_async_notifier *notifier,
		      struct v4l2_async_match_desc *match);
	struct v4l2_async_connection *asc;

	list_for_each_entry(asc, &notifier->waiting_list, waiting_entry) {
	list_for_each_entry(asc, &notifier->waiting_list, asc_entry) {
		/* bus_type has been verified valid before */
		switch (asc->match.type) {
		case V4L2_ASYNC_MATCH_TYPE_I2C:
@@ -232,14 +232,14 @@ v4l2_async_nf_find_v4l2_dev(struct v4l2_async_notifier *notifier)
static bool
v4l2_async_nf_can_complete(struct v4l2_async_notifier *notifier)
{
	struct v4l2_subdev *sd;
	struct v4l2_async_connection *asc;

	if (!list_empty(&notifier->waiting_list))
		return false;

	list_for_each_entry(sd, &notifier->done_list, async_list) {
	list_for_each_entry(asc, &notifier->done_list, asc_entry) {
		struct v4l2_async_notifier *subdev_notifier =
			v4l2_async_find_subdev_notifier(sd);
			v4l2_async_find_subdev_notifier(asc->sd);

		if (subdev_notifier &&
		    !v4l2_async_nf_can_complete(subdev_notifier))
@@ -333,12 +333,13 @@ static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier,
	if (ret)
		goto err_call_unbind;

	list_del(&asc->waiting_entry);
	sd->asd = asc;
	sd->notifier = notifier;

	/* Move from the global subdevice list to notifier's done */
	list_move(&sd->async_list, &notifier->done_list);
	asc->sd = sd;

	/* Move from the waiting list to notifier's done */
	list_move(&asc->asc_entry, &notifier->done_list);

	dev_dbg(notifier_dev(notifier), "v4l2-async: %s bound (ret %d)\n",
		dev_name(sd->dev), ret);
@@ -422,25 +423,23 @@ static void v4l2_async_cleanup(struct v4l2_subdev *sd)

/* Unbind all sub-devices in the notifier tree. */
static void
v4l2_async_nf_unbind_all_subdevs(struct v4l2_async_notifier *notifier,
				 bool readd)
v4l2_async_nf_unbind_all_subdevs(struct v4l2_async_notifier *notifier)
{
	struct v4l2_subdev *sd, *tmp;
	struct v4l2_async_connection *asc, *asc_tmp;

	list_for_each_entry_safe(sd, tmp, &notifier->done_list, async_list) {
	list_for_each_entry_safe(asc, asc_tmp, &notifier->done_list,
				 asc_entry) {
		struct v4l2_async_notifier *subdev_notifier =
			v4l2_async_find_subdev_notifier(sd);
			v4l2_async_find_subdev_notifier(asc->sd);

		if (subdev_notifier)
			v4l2_async_nf_unbind_all_subdevs(subdev_notifier, true);

		v4l2_async_nf_call_unbind(notifier, sd, sd->asd);
		if (readd)
			list_add_tail(&sd->asd->waiting_entry,
				      &notifier->waiting_list);
		v4l2_async_cleanup(sd);
			v4l2_async_nf_unbind_all_subdevs(subdev_notifier);

		list_move(&sd->async_list, &subdev_list);
		v4l2_async_nf_call_unbind(notifier, asc->sd, asc);
		v4l2_async_cleanup(asc->sd);
		list_move_tail(&asc->asc_entry, &notifier->waiting_list);
		list_move(&asc->sd->async_list, &subdev_list);
		asc->sd = NULL;
	}

	notifier->parent = NULL;
@@ -452,17 +451,16 @@ v4l2_async_nf_has_async_match_entry(struct v4l2_async_notifier *notifier,
				    struct v4l2_async_match_desc *match)
{
	struct v4l2_async_connection *asc;
	struct v4l2_subdev *sd;

	list_for_each_entry(asc, &notifier->waiting_list, waiting_entry)
	list_for_each_entry(asc, &notifier->waiting_list, asc_entry)
		if (v4l2_async_match_equal(&asc->match, match))
			return true;

	list_for_each_entry(sd, &notifier->done_list, async_list) {
		if (WARN_ON(!sd->asd))
	list_for_each_entry(asc, &notifier->done_list, asc_entry) {
		if (WARN_ON(!asc->sd->asd))
			continue;

		if (v4l2_async_match_equal(&sd->asd->match, match))
		if (v4l2_async_match_equal(&asc->match, match))
			return true;
	}

@@ -477,17 +475,25 @@ static bool
v4l2_async_nf_has_async_match(struct v4l2_async_notifier *notifier,
			      struct v4l2_async_match_desc *match)
{
	struct v4l2_async_connection *asc;
	struct list_head *heads[] = {
		&notifier->waiting_list,
		&notifier->done_list,
	};
	unsigned int i;

	lockdep_assert_held(&list_lock);

	/* Check that an asd is not being added more than once. */
	list_for_each_entry(asc, &notifier->asc_list, asc_entry) {
	for (i = 0; i < ARRAY_SIZE(heads); i++) {
		struct v4l2_async_connection *asc;

		list_for_each_entry(asc, heads[i], asc_entry) {
			if (&asc->match == match)
				continue;
			if (v4l2_async_match_equal(&asc->match, match))
				return true;
		}
	}

	/* Check that an asc does not exist in other notifiers. */
	list_for_each_entry(notifier, &notifier_list, notifier_entry)
@@ -521,7 +527,8 @@ static int v4l2_async_nf_match_valid(struct v4l2_async_notifier *notifier,

void v4l2_async_nf_init(struct v4l2_async_notifier *notifier)
{
	INIT_LIST_HEAD(&notifier->asc_list);
	INIT_LIST_HEAD(&notifier->waiting_list);
	INIT_LIST_HEAD(&notifier->done_list);
}
EXPORT_SYMBOL(v4l2_async_nf_init);

@@ -530,17 +537,12 @@ static int __v4l2_async_nf_register(struct v4l2_async_notifier *notifier)
	struct v4l2_async_connection *asc;
	int ret;

	INIT_LIST_HEAD(&notifier->waiting_list);
	INIT_LIST_HEAD(&notifier->done_list);

	mutex_lock(&list_lock);

	list_for_each_entry(asc, &notifier->asc_list, asc_entry) {
	list_for_each_entry(asc, &notifier->waiting_list, asc_entry) {
		ret = v4l2_async_nf_match_valid(notifier, &asc->match);
		if (ret)
			goto err_unlock;

		list_add_tail(&asc->waiting_entry, &notifier->waiting_list);
	}

	ret = v4l2_async_nf_try_all_subdevs(notifier);
@@ -562,7 +564,7 @@ static int __v4l2_async_nf_register(struct v4l2_async_notifier *notifier)
	/*
	 * On failure, unbind all sub-devices registered through this notifier.
	 */
	v4l2_async_nf_unbind_all_subdevs(notifier, false);
	v4l2_async_nf_unbind_all_subdevs(notifier);

err_unlock:
	mutex_unlock(&list_lock);
@@ -612,7 +614,7 @@ __v4l2_async_nf_unregister(struct v4l2_async_notifier *notifier)
	if (!notifier || (!notifier->v4l2_dev && !notifier->sd))
		return;

	v4l2_async_nf_unbind_all_subdevs(notifier, false);
	v4l2_async_nf_unbind_all_subdevs(notifier);

	notifier->sd = NULL;
	notifier->v4l2_dev = NULL;
@@ -634,10 +636,12 @@ static void __v4l2_async_nf_cleanup(struct v4l2_async_notifier *notifier)
{
	struct v4l2_async_connection *asc, *tmp;

	if (!notifier || !notifier->asc_list.next)
	if (!notifier || !notifier->waiting_list.next)
		return;

	list_for_each_entry_safe(asc, tmp, &notifier->asc_list, asc_entry) {
	WARN_ON(!list_empty(&notifier->done_list));

	list_for_each_entry_safe(asc, tmp, &notifier->waiting_list, asc_entry) {
		switch (asc->match.type) {
		case V4L2_ASYNC_MATCH_TYPE_FWNODE:
			fwnode_handle_put(asc->match.fwnode);
@@ -667,7 +671,7 @@ static int __v4l2_async_nf_add_connection(struct v4l2_async_notifier *notifier,
{
	mutex_lock(&list_lock);

	list_add_tail(&asc->asc_entry, &notifier->asc_list);
	list_add_tail(&asc->asc_entry, &notifier->waiting_list);

	mutex_unlock(&list_lock);

@@ -810,10 +814,12 @@ int v4l2_async_register_subdev(struct v4l2_subdev *sd)
	 */
	subdev_notifier = v4l2_async_find_subdev_notifier(sd);
	if (subdev_notifier)
		v4l2_async_nf_unbind_all_subdevs(subdev_notifier, false);
		v4l2_async_nf_unbind_all_subdevs(subdev_notifier);

	if (sd->asd)
	if (sd->asd) {
		v4l2_async_nf_call_unbind(notifier, sd, sd->asd);
		sd->asd->sd = NULL;
	}
	v4l2_async_cleanup(sd);

	mutex_unlock(&list_lock);
@@ -839,9 +845,9 @@ void v4l2_async_unregister_subdev(struct v4l2_subdev *sd)
	if (sd->asd) {
		struct v4l2_async_notifier *notifier = sd->notifier;

		list_add(&sd->asd->waiting_entry, &notifier->waiting_list);

		list_move(&sd->asd->asc_entry, &notifier->waiting_list);
		v4l2_async_nf_call_unbind(notifier, sd, sd->asd);
		sd->asd->sd = NULL;
	}

	v4l2_async_cleanup(sd);
@@ -895,7 +901,7 @@ static int pending_subdevs_show(struct seq_file *s, void *data)

	list_for_each_entry(notif, &notifier_list, notifier_entry) {
		seq_printf(s, "%s:\n", v4l2_async_nf_name(notif));
		list_for_each_entry(asc, &notif->waiting_list, waiting_entry)
		list_for_each_entry(asc, &notif->waiting_list, asc_entry)
			print_waiting_match(s, &asc->match);
	}

Loading