Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

media: subdev: Split v4l2_subdev_get_frame_desc_passthrough() into locked and unlocked

The recently added v4l2_subdev_get_frame_desc_passthrough() can be used
directly as an implementation for .get_frame_desc subdev op. However, in
some cases the drivers may want to add some customizations, while the
bulk of the work is still identical to what
v4l2_subdev_get_frame_desc_passthrough() does. Current locking scheme
makes this impossible to do properly.

Split v4l2_subdev_get_frame_desc_passthrough() into two functions:

__v4l2_subdev_get_frame_desc_passthrough(), which takes a locked subdev
state as a parameter, instead of locking and getting the active state
internally. Other than that, it does the same as
v4l2_subdev_get_frame_desc_passthrough() used to do.

v4l2_subdev_get_frame_desc_passthrough(), which locks the active state
and calls __v4l2_subdev_get_frame_desc_passthrough().

In other words, v4l2_subdev_get_frame_desc_passthrough() works as
before, but drivers can now alternatively add custom .get_frame_desc
code and call v4l2_subdev_get_frame_desc_passthrough().

An example use case is with DS90UB953 serializer: in normal use the
serializer passes through everything, but when test-pattern-generator
(TPG) is used, an internal TPG source is used. After this commit, the
UB953 get_frame_desc() can lock the state, look at the routing table to
see if we're in normal or TPG mode, then either call
__v4l2_subdev_get_frame_desc_passthrough() if in normal mode, or
construct a TPG frame desc if in TPG mode.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen+renesas@ideasonboard.com>
[Sakari Ailus: Rebase on an earlier remote source pad error code fix.]
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>

authored by

Tomi Valkeinen and committed by
Hans Verkuil
64d712aa f40306e0

+61 -25
+28 -20
drivers/media/v4l2-core/v4l2-subdev.c
··· 2545 2545 } 2546 2546 EXPORT_SYMBOL_GPL(v4l2_subdev_s_stream_helper); 2547 2547 2548 - int v4l2_subdev_get_frame_desc_passthrough(struct v4l2_subdev *sd, 2549 - unsigned int pad, 2550 - struct v4l2_mbus_frame_desc *fd) 2548 + int __v4l2_subdev_get_frame_desc_passthrough(struct v4l2_subdev *sd, 2549 + struct v4l2_subdev_state *state, 2550 + unsigned int pad, 2551 + struct v4l2_mbus_frame_desc *fd) 2551 2552 { 2552 2553 struct media_pad *local_sink_pad; 2553 2554 struct v4l2_subdev_route *route; 2554 - struct v4l2_subdev_state *state; 2555 2555 struct device *dev = sd->dev; 2556 2556 int ret = 0; 2557 2557 2558 + lockdep_assert_held(state->lock); 2559 + 2558 2560 if (WARN_ON(!(sd->entity.pads[pad].flags & MEDIA_PAD_FL_SOURCE))) 2559 2561 return -EINVAL; 2560 - 2561 - state = v4l2_subdev_lock_and_get_active_state(sd); 2562 2562 2563 2563 /* Iterate over sink pads */ 2564 2564 media_entity_for_each_pad(&sd->entity, local_sink_pad) { ··· 2586 2586 if (IS_ERR(remote_source_pad)) { 2587 2587 dev_dbg(dev, "Failed to find remote pad for sink pad %u\n", 2588 2588 local_sink_pad->index); 2589 - ret = PTR_ERR(remote_source_pad); 2590 - goto out_unlock; 2589 + return PTR_ERR(remote_source_pad); 2591 2590 } 2592 2591 2593 2592 remote_sd = media_entity_to_v4l2_subdev(remote_source_pad->entity); 2594 - if (!remote_sd) { 2595 - ret = -EINVAL; 2596 - goto out_unlock; 2597 - } 2593 + if (!remote_sd) 2594 + return -EINVAL; 2598 2595 2599 2596 ret = v4l2_subdev_call(remote_sd, pad, 2600 2597 get_frame_desc, ··· 2601 2604 dev_err(dev, 2602 2605 "Failed to get frame desc from remote subdev %s\n", 2603 2606 remote_sd->name); 2604 - goto out_unlock; 2607 + return ret; 2605 2608 } 2606 2609 2607 2610 have_source_fd = true; ··· 2612 2615 dev_err(dev, 2613 2616 "Frame desc type mismatch: %u != %u\n", 2614 2617 fd->type, source_fd.type); 2615 - ret = -EPIPE; 2616 - goto out_unlock; 2618 + return -EPIPE; 2617 2619 } 2618 2620 } 2619 2621 ··· 2627 2631 dev_dbg(dev, 2628 2632 "Failed to find stream %u from source frame desc\n", 2629 2633 route->sink_stream); 2630 - ret = -EPIPE; 2631 - goto out_unlock; 2634 + return -EPIPE; 2632 2635 } 2633 2636 2634 2637 if (fd->num_entries >= V4L2_FRAME_DESC_ENTRY_MAX) { 2635 2638 dev_dbg(dev, "Frame desc entry limit reached\n"); 2636 - ret = -ENOSPC; 2637 - goto out_unlock; 2639 + return -ENOSPC; 2638 2640 } 2639 2641 2640 2642 fd->entry[fd->num_entries] = *source_entry; ··· 2643 2649 } 2644 2650 } 2645 2651 2646 - out_unlock: 2652 + return 0; 2653 + } 2654 + EXPORT_SYMBOL_GPL(__v4l2_subdev_get_frame_desc_passthrough); 2655 + 2656 + int v4l2_subdev_get_frame_desc_passthrough(struct v4l2_subdev *sd, 2657 + unsigned int pad, 2658 + struct v4l2_mbus_frame_desc *fd) 2659 + { 2660 + struct v4l2_subdev_state *state; 2661 + int ret; 2662 + 2663 + state = v4l2_subdev_lock_and_get_active_state(sd); 2664 + 2665 + ret = __v4l2_subdev_get_frame_desc_passthrough(sd, state, pad, fd); 2666 + 2647 2667 v4l2_subdev_unlock_state(state); 2648 2668 2649 2669 return ret;
+33 -5
include/media/v4l2-subdev.h
··· 1723 1723 int v4l2_subdev_s_stream_helper(struct v4l2_subdev *sd, int enable); 1724 1724 1725 1725 /** 1726 - * v4l2_subdev_get_frame_desc_passthrough() - Helper to implement the subdev 1727 - * get_frame_desc operation in simple passthrough cases 1726 + * __v4l2_subdev_get_frame_desc_passthrough - Helper to implement the 1727 + * subdev get_frame_desc operation in simple passthrough cases 1728 1728 * @sd: The subdevice 1729 + * @state: The locked subdevice active state 1729 1730 * @pad: The source pad index 1730 1731 * @fd: The mbus frame desc 1731 1732 * 1732 - * This helper implements get_frame_desc operation for subdevices that pass 1733 - * streams through without modification. It can be assigned directly as the 1734 - * .get_frame_desc callback in &v4l2_subdev_pad_ops. 1733 + * This helper implements the get_frame_desc operation for subdevices that pass 1734 + * streams through without modification. 1735 1735 * 1736 1736 * The helper iterates over the subdevice's sink pads, calls get_frame_desc on 1737 1737 * the remote subdevice connected to each sink pad, and collects the frame desc ··· 1743 1743 * The frame desc type is taken from the first upstream source. If multiple 1744 1744 * sink pads are involved and the upstream sources report different frame desc 1745 1745 * types, -EPIPE is returned. 1746 + * 1747 + * The caller must hold the subdevice's active state lock. This variant is 1748 + * intended for drivers that need to perform additional work around the 1749 + * passthrough frame descriptor collection. Drivers that do not need any 1750 + * customization should use v4l2_subdev_get_frame_desc_passthrough() instead. 1751 + * 1752 + * Return: 0 on success, or a negative error code otherwise. 1753 + */ 1754 + int __v4l2_subdev_get_frame_desc_passthrough(struct v4l2_subdev *sd, 1755 + struct v4l2_subdev_state *state, 1756 + unsigned int pad, 1757 + struct v4l2_mbus_frame_desc *fd); 1758 + 1759 + /** 1760 + * v4l2_subdev_get_frame_desc_passthrough() - Helper to implement the subdev 1761 + * get_frame_desc operation in simple passthrough cases 1762 + * @sd: The subdevice 1763 + * @pad: The source pad index 1764 + * @fd: The mbus frame desc 1765 + * 1766 + * This function locks the subdevice's active state, calls 1767 + * __v4l2_subdev_get_frame_desc_passthrough(), and unlocks the state. 1768 + * 1769 + * This function can be assigned directly as the .get_frame_desc callback in 1770 + * &v4l2_subdev_pad_ops for subdevices that pass streams through without 1771 + * modification. Drivers that need to perform additional work should use 1772 + * __v4l2_subdev_get_frame_desc_passthrough() in their custom 1773 + * .get_frame_desc implementation instead. 1746 1774 * 1747 1775 * Return: 0 on success, or a negative error code otherwise. 1748 1776 */