Changes in 4.9.204 net/mlx4_en: fix mlx4 ethtool -N insertion net: rtnetlink: prevent underflows in do_setvfinfo() sfc: Only cancel the PPS workqueue if it exists net/mlx5e: Fix set vf link state error flow net/sched: act_pedit: fix WARN() in the traffic path gpio: max77620: Fixup debounce delays tools: gpio: Correctly add make dependencies for gpio_utils Revert "fs: ocfs2: fix possible null-pointer dereferences in ocfs2_xa_prepare_entry()" mm/ksm.c: don't WARN if page is still mapped in remove_stable_node() platform/x86: asus-nb-wmi: Support ALS on the Zenbook UX430UQ platform/x86: asus-wmi: Only Tell EC the OS will handle display hotkeys from asus_nb_wmi mwifiex: Fix NL80211_TX_POWER_LIMITED ALSA: isight: fix leak of reference to firewire unit in error path of .probe callback printk: fix integer overflow in setup_log_buf() gfs2: Fix marking bitmaps non-full synclink_gt(): fix compat_ioctl() powerpc: Fix signedness bug in update_flash_db() powerpc/eeh: Fix use of EEH_PE_KEEP on wrong field brcmsmac: AP mode: update beacon when TIM changes ath10k: allocate small size dma memory in ath10k_pci_diag_write_mem spi: sh-msiof: fix deferred probing mmc: mediatek: fix cannot receive new request when msdc_cmd_is_ready fail btrfs: handle error of get_old_root gsmi: Fix bug in append_to_eventlog sysfs handler misc: mic: fix a DMA pool free failure m68k: fix command-line parsing when passed from u-boot amiflop: clean up on errors during setup scsi: ips: fix missing break in switch KVM/x86: Fix invvpid and invept register operand size in 64-bit mode scsi: isci: Use proper enumerated type in atapi_d2h_reg_frame_handler scsi: isci: Change sci_controller_start_task's return type to sci_status scsi: iscsi_tcp: Explicitly cast param in iscsi_sw_tcp_host_get_param clk: mmp2: fix the clock id for sdh2_clk and sdh3_clk ASoC: tegra_sgtl5000: fix device_node refcounting scsi: dc395x: fix dma API usage in srb_done scsi: dc395x: fix DMA API usage in sg_update_list net: fix warning in af_unix net: ena: Fix Kconfig dependency on X86 xfs: fix use-after-free race in xfs_buf_rele kprobes, x86/ptrace.h: Make regs_get_kernel_stack_nth() not fault on bad stack ALSA: i2c/cs8427: Fix int to char conversion macintosh/windfarm_smu_sat: Fix debug output USB: misc: appledisplay: fix backlight update_status return code usbip: tools: fix atoi() on non-null terminated string SUNRPC: Fix a compile warning for cmpxchg64() sunrpc: safely reallow resvport min/max inversion atm: zatm: Fix empty body Clang warnings s390/perf: Return error when debug_register fails spi: omap2-mcspi: Set FIFO DMA trigger level to word length sparc: Fix parport build warnings. ceph: fix dentry leak in ceph_readdir_prepopulate rtc: s35390a: Change buf's type to u8 in s35390a_init f2fs: fix to spread clear_cold_data() mISDN: Fix type of switch control variable in ctrl_teimanager qlcnic: fix a return in qlcnic_dcb_get_capability() net: ethernet: ti: cpsw: unsync mcast entries while switch promisc mode mfd: arizona: Correct calling of runtime_put_sync mfd: mc13xxx-core: Fix PMIC shutdown when reading ADC values mfd: max8997: Enale irq-wakeup unconditionally selftests/ftrace: Fix to test kprobe $comm arg only if available thermal: rcar_thermal: Prevent hardware access during system suspend powerpc/process: Fix flush_all_to_thread for SPE sparc64: Rework xchg() definition to avoid warnings. fs/ocfs2/dlm/dlmdebug.c: fix a sleep-in-atomic-context bug in dlm_print_one_mle() mm/page-writeback.c: fix range_cyclic writeback vs writepages deadlock macsec: update operstate when lower device changes macsec: let the administrator set UP state even if lowerdev is down um: Make line/tty semantics use true write IRQ linux/bitmap.h: handle constant zero-size bitmaps correctly linux/bitmap.h: fix type of nbits in bitmap_shift_right() hfsplus: fix BUG on bnode parent update hfs: fix BUG on bnode parent update hfsplus: prevent btree data loss on ENOSPC hfs: prevent btree data loss on ENOSPC hfsplus: fix return value of hfsplus_get_block() hfs: fix return value of hfs_get_block() hfsplus: update timestamps on truncate() hfs: update timestamp on truncate() fs/hfs/extent.c: fix array out of bounds read of array extent mm/memory_hotplug: make add_memory() take the device_hotplug_lock igb: shorten maximum PHC timecounter update interval ntb_netdev: fix sleep time mismatch ntb: intel: fix return value for ndev_vec_mask() arm64: makefile fix build of .i file in external module case ocfs2: don't put and assigning null to bh allocated outside ocfs2: fix clusters leak in ocfs2_defrag_extent() net: do not abort bulk send on BQL status sched/fair: Don't increase sd->balance_interval on newidle balance audit: print empty EXECVE args wlcore: Fix the return value in case of error in 'wlcore_vendor_cmd_smart_config_start()' rtl8xxxu: Fix missing break in switch brcmsmac: never log "tid x is not agg'able" by default wireless: airo: potential buffer overflow in sprintf() rtlwifi: rtl8192de: Fix misleading REG_MCUFWDL information scsi: mpt3sas: Fix Sync cache command failure during driver unload scsi: mpt3sas: Fix driver modifying persistent data in Manufacturing page11 scsi: megaraid_sas: Fix msleep granularity scsi: lpfc: fcoe: Fix link down issue after 1000+ link bounces dlm: fix invalid free dlm: don't leak kernel pointer to userspace ACPICA: Use %d for signed int print formatting instead of %u net: bcmgenet: return correct value 'ret' from bcmgenet_power_down sock: Reset dst when changing sk_mark via setsockopt pinctrl: qcom: spmi-gpio: fix gpio-hog related boot issues pinctrl: lpc18xx: Use define directive for PIN_CONFIG_GPIO_PIN_INT pinctrl: zynq: Use define directive for PIN_CONFIG_IO_STANDARD PCI: keystone: Use quirk to limit MRRS for K2G spi: omap2-mcspi: Fix DMA and FIFO event trigger size mismatch mm/memory_hotplug: Do not unlock when fails to take the device_hotplug_lock Bluetooth: Fix invalid-free in bcsp_close() KVM: MMU: Do not treat ZONE_DEVICE pages as being reserved ath9k_hw: fix uninitialized variable data dm: use blk_set_queue_dying() in __dm_destroy() arm64: fix for bad_mode() handler to always result in panic cpufreq: Skip cpufreq resume if it's not suspended ocfs2: remove ocfs2_is_o2cb_active() ARM: 8904/1: skip nomap memblocks while finding the lowmem/highmem boundary ARC: perf: Accommodate big-endian CPU x86/insn: Fix awk regexp warnings x86/speculation: Fix incorrect MDS/TAA mitigation status x86/speculation: Fix redundant MDS mitigation message nfc: port100: handle command failure cleanly l2tp: don't use l2tp_tunnel_find() in l2tp_ip and l2tp_ip6 media: vivid: Set vid_cap_streaming and vid_out_streaming to true media: vivid: Fix wrong locking that causes race conditions on streaming stop media: usbvision: Fix races among open, close, and disconnect cpufreq: Add NULL checks to show() and store() methods of cpufreq media: uvcvideo: Fix error path in control parsing failure media: b2c2-flexcop-usb: add sanity checking media: cxusb: detect cxusb_ctrl_msg error in query media: imon: invalid dereference in imon_touch_event virtio_console: reset on out of memory virtio_console: don't tie bufs to a vq virtio_console: allocate inbufs in add_port() only if it is needed virtio_ring: fix return code on DMA mapping fails virtio_console: fix uninitialized variable use virtio_console: drop custom control queue cleanup virtio_console: move removal code usbip: tools: fix fd leakage in the function of read_attr_usbip_status usb-serial: cp201x: support Mark-10 digital force gauge USB: chaoskey: fix error case of a timeout appledisplay: fix error handling in the scheduled work USB: serial: mos7840: add USB ID to support Moxa UPort 2210 USB: serial: mos7720: fix remote wakeup USB: serial: mos7840: fix remote wakeup USB: serial: option: add support for DW5821e with eSIM support USB: serial: option: add support for Foxconn T77W968 LTE modules staging: comedi: usbduxfast: usbduxfast_ai_cmdtest rounding error powerpc/64s: support nospectre_v2 cmdline option powerpc/book3s64: Fix link stack flush on context switch KVM: PPC: Book3S HV: Flush link stack on guest exit to host kernel Linux 4.9.204 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
311 lines
9.1 KiB
C
311 lines
9.1 KiB
C
/*
|
|
* vivid-kthread-out.h - video/vbi output thread support functions.
|
|
*
|
|
* Copyright 2014 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
|
|
*
|
|
* This program is free software; you may redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; version 2 of the License.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
* SOFTWARE.
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/errno.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/init.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/font.h>
|
|
#include <linux/mutex.h>
|
|
#include <linux/videodev2.h>
|
|
#include <linux/kthread.h>
|
|
#include <linux/freezer.h>
|
|
#include <linux/random.h>
|
|
#include <linux/v4l2-dv-timings.h>
|
|
#include <asm/div64.h>
|
|
#include <media/videobuf2-vmalloc.h>
|
|
#include <media/v4l2-dv-timings.h>
|
|
#include <media/v4l2-ioctl.h>
|
|
#include <media/v4l2-fh.h>
|
|
#include <media/v4l2-event.h>
|
|
|
|
#include "vivid-core.h"
|
|
#include "vivid-vid-common.h"
|
|
#include "vivid-vid-cap.h"
|
|
#include "vivid-vid-out.h"
|
|
#include "vivid-radio-common.h"
|
|
#include "vivid-radio-rx.h"
|
|
#include "vivid-radio-tx.h"
|
|
#include "vivid-sdr-cap.h"
|
|
#include "vivid-vbi-cap.h"
|
|
#include "vivid-vbi-out.h"
|
|
#include "vivid-osd.h"
|
|
#include "vivid-ctrls.h"
|
|
#include "vivid-kthread-out.h"
|
|
|
|
static void vivid_thread_vid_out_tick(struct vivid_dev *dev)
|
|
{
|
|
struct vivid_buffer *vid_out_buf = NULL;
|
|
struct vivid_buffer *vbi_out_buf = NULL;
|
|
|
|
dprintk(dev, 1, "Video Output Thread Tick\n");
|
|
|
|
/* Drop a certain percentage of buffers. */
|
|
if (dev->perc_dropped_buffers &&
|
|
prandom_u32_max(100) < dev->perc_dropped_buffers)
|
|
return;
|
|
|
|
spin_lock(&dev->slock);
|
|
/*
|
|
* Only dequeue buffer if there is at least one more pending.
|
|
* This makes video loopback possible.
|
|
*/
|
|
if (!list_empty(&dev->vid_out_active) &&
|
|
!list_is_singular(&dev->vid_out_active)) {
|
|
vid_out_buf = list_entry(dev->vid_out_active.next,
|
|
struct vivid_buffer, list);
|
|
list_del(&vid_out_buf->list);
|
|
}
|
|
if (!list_empty(&dev->vbi_out_active) &&
|
|
(dev->field_out != V4L2_FIELD_ALTERNATE ||
|
|
(dev->vbi_out_seq_count & 1))) {
|
|
vbi_out_buf = list_entry(dev->vbi_out_active.next,
|
|
struct vivid_buffer, list);
|
|
list_del(&vbi_out_buf->list);
|
|
}
|
|
spin_unlock(&dev->slock);
|
|
|
|
if (!vid_out_buf && !vbi_out_buf)
|
|
return;
|
|
|
|
if (vid_out_buf) {
|
|
vid_out_buf->vb.sequence = dev->vid_out_seq_count;
|
|
if (dev->field_out == V4L2_FIELD_ALTERNATE) {
|
|
/*
|
|
* The sequence counter counts frames, not fields.
|
|
* So divide by two.
|
|
*/
|
|
vid_out_buf->vb.sequence /= 2;
|
|
}
|
|
vid_out_buf->vb.vb2_buf.timestamp =
|
|
ktime_get_ns() + dev->time_wrap_offset;
|
|
vb2_buffer_done(&vid_out_buf->vb.vb2_buf, dev->dqbuf_error ?
|
|
VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
|
|
dprintk(dev, 2, "vid_out buffer %d done\n",
|
|
vid_out_buf->vb.vb2_buf.index);
|
|
}
|
|
|
|
if (vbi_out_buf) {
|
|
if (dev->stream_sliced_vbi_out)
|
|
vivid_sliced_vbi_out_process(dev, vbi_out_buf);
|
|
|
|
vbi_out_buf->vb.sequence = dev->vbi_out_seq_count;
|
|
vbi_out_buf->vb.vb2_buf.timestamp =
|
|
ktime_get_ns() + dev->time_wrap_offset;
|
|
vb2_buffer_done(&vbi_out_buf->vb.vb2_buf, dev->dqbuf_error ?
|
|
VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
|
|
dprintk(dev, 2, "vbi_out buffer %d done\n",
|
|
vbi_out_buf->vb.vb2_buf.index);
|
|
}
|
|
dev->dqbuf_error = false;
|
|
}
|
|
|
|
static int vivid_thread_vid_out(void *data)
|
|
{
|
|
struct vivid_dev *dev = data;
|
|
u64 numerators_since_start;
|
|
u64 buffers_since_start;
|
|
u64 next_jiffies_since_start;
|
|
unsigned long jiffies_since_start;
|
|
unsigned long cur_jiffies;
|
|
unsigned wait_jiffies;
|
|
unsigned numerator;
|
|
unsigned denominator;
|
|
|
|
dprintk(dev, 1, "Video Output Thread Start\n");
|
|
|
|
set_freezable();
|
|
|
|
/* Resets frame counters */
|
|
dev->out_seq_offset = 0;
|
|
if (dev->seq_wrap)
|
|
dev->out_seq_count = 0xffffff80U;
|
|
dev->jiffies_vid_out = jiffies;
|
|
dev->vid_out_seq_start = dev->vbi_out_seq_start = 0;
|
|
dev->out_seq_resync = false;
|
|
|
|
for (;;) {
|
|
try_to_freeze();
|
|
if (kthread_should_stop())
|
|
break;
|
|
|
|
if (!mutex_trylock(&dev->mutex)) {
|
|
schedule_timeout_uninterruptible(1);
|
|
continue;
|
|
}
|
|
|
|
cur_jiffies = jiffies;
|
|
if (dev->out_seq_resync) {
|
|
dev->jiffies_vid_out = cur_jiffies;
|
|
dev->out_seq_offset = dev->out_seq_count + 1;
|
|
dev->out_seq_count = 0;
|
|
dev->out_seq_resync = false;
|
|
}
|
|
numerator = dev->timeperframe_vid_out.numerator;
|
|
denominator = dev->timeperframe_vid_out.denominator;
|
|
|
|
if (dev->field_out == V4L2_FIELD_ALTERNATE)
|
|
denominator *= 2;
|
|
|
|
/* Calculate the number of jiffies since we started streaming */
|
|
jiffies_since_start = cur_jiffies - dev->jiffies_vid_out;
|
|
/* Get the number of buffers streamed since the start */
|
|
buffers_since_start = (u64)jiffies_since_start * denominator +
|
|
(HZ * numerator) / 2;
|
|
do_div(buffers_since_start, HZ * numerator);
|
|
|
|
/*
|
|
* After more than 0xf0000000 (rounded down to a multiple of
|
|
* 'jiffies-per-day' to ease jiffies_to_msecs calculation)
|
|
* jiffies have passed since we started streaming reset the
|
|
* counters and keep track of the sequence offset.
|
|
*/
|
|
if (jiffies_since_start > JIFFIES_RESYNC) {
|
|
dev->jiffies_vid_out = cur_jiffies;
|
|
dev->out_seq_offset = buffers_since_start;
|
|
buffers_since_start = 0;
|
|
}
|
|
dev->out_seq_count = buffers_since_start + dev->out_seq_offset;
|
|
dev->vid_out_seq_count = dev->out_seq_count - dev->vid_out_seq_start;
|
|
dev->vbi_out_seq_count = dev->out_seq_count - dev->vbi_out_seq_start;
|
|
|
|
vivid_thread_vid_out_tick(dev);
|
|
mutex_unlock(&dev->mutex);
|
|
|
|
/*
|
|
* Calculate the number of 'numerators' streamed since we started,
|
|
* not including the current buffer.
|
|
*/
|
|
numerators_since_start = buffers_since_start * numerator;
|
|
|
|
/* And the number of jiffies since we started */
|
|
jiffies_since_start = jiffies - dev->jiffies_vid_out;
|
|
|
|
/* Increase by the 'numerator' of one buffer */
|
|
numerators_since_start += numerator;
|
|
/*
|
|
* Calculate when that next buffer is supposed to start
|
|
* in jiffies since we started streaming.
|
|
*/
|
|
next_jiffies_since_start = numerators_since_start * HZ +
|
|
denominator / 2;
|
|
do_div(next_jiffies_since_start, denominator);
|
|
/* If it is in the past, then just schedule asap */
|
|
if (next_jiffies_since_start < jiffies_since_start)
|
|
next_jiffies_since_start = jiffies_since_start;
|
|
|
|
wait_jiffies = next_jiffies_since_start - jiffies_since_start;
|
|
schedule_timeout_interruptible(wait_jiffies ? wait_jiffies : 1);
|
|
}
|
|
dprintk(dev, 1, "Video Output Thread End\n");
|
|
return 0;
|
|
}
|
|
|
|
static void vivid_grab_controls(struct vivid_dev *dev, bool grab)
|
|
{
|
|
v4l2_ctrl_grab(dev->ctrl_has_crop_out, grab);
|
|
v4l2_ctrl_grab(dev->ctrl_has_compose_out, grab);
|
|
v4l2_ctrl_grab(dev->ctrl_has_scaler_out, grab);
|
|
v4l2_ctrl_grab(dev->ctrl_tx_mode, grab);
|
|
v4l2_ctrl_grab(dev->ctrl_tx_rgb_range, grab);
|
|
}
|
|
|
|
int vivid_start_generating_vid_out(struct vivid_dev *dev, bool *pstreaming)
|
|
{
|
|
dprintk(dev, 1, "%s\n", __func__);
|
|
|
|
if (dev->kthread_vid_out) {
|
|
u32 seq_count = dev->out_seq_count + dev->seq_wrap * 128;
|
|
|
|
if (pstreaming == &dev->vid_out_streaming)
|
|
dev->vid_out_seq_start = seq_count;
|
|
else
|
|
dev->vbi_out_seq_start = seq_count;
|
|
*pstreaming = true;
|
|
return 0;
|
|
}
|
|
|
|
/* Resets frame counters */
|
|
dev->jiffies_vid_out = jiffies;
|
|
dev->vid_out_seq_start = dev->seq_wrap * 128;
|
|
dev->vbi_out_seq_start = dev->seq_wrap * 128;
|
|
|
|
dev->kthread_vid_out = kthread_run(vivid_thread_vid_out, dev,
|
|
"%s-vid-out", dev->v4l2_dev.name);
|
|
|
|
if (IS_ERR(dev->kthread_vid_out)) {
|
|
int err = PTR_ERR(dev->kthread_vid_out);
|
|
|
|
dev->kthread_vid_out = NULL;
|
|
v4l2_err(&dev->v4l2_dev, "kernel_thread() failed\n");
|
|
return err;
|
|
}
|
|
*pstreaming = true;
|
|
vivid_grab_controls(dev, true);
|
|
|
|
dprintk(dev, 1, "returning from %s\n", __func__);
|
|
return 0;
|
|
}
|
|
|
|
void vivid_stop_generating_vid_out(struct vivid_dev *dev, bool *pstreaming)
|
|
{
|
|
dprintk(dev, 1, "%s\n", __func__);
|
|
|
|
if (dev->kthread_vid_out == NULL)
|
|
return;
|
|
|
|
*pstreaming = false;
|
|
if (pstreaming == &dev->vid_out_streaming) {
|
|
/* Release all active buffers */
|
|
while (!list_empty(&dev->vid_out_active)) {
|
|
struct vivid_buffer *buf;
|
|
|
|
buf = list_entry(dev->vid_out_active.next,
|
|
struct vivid_buffer, list);
|
|
list_del(&buf->list);
|
|
vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
|
|
dprintk(dev, 2, "vid_out buffer %d done\n",
|
|
buf->vb.vb2_buf.index);
|
|
}
|
|
}
|
|
|
|
if (pstreaming == &dev->vbi_out_streaming) {
|
|
while (!list_empty(&dev->vbi_out_active)) {
|
|
struct vivid_buffer *buf;
|
|
|
|
buf = list_entry(dev->vbi_out_active.next,
|
|
struct vivid_buffer, list);
|
|
list_del(&buf->list);
|
|
vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
|
|
dprintk(dev, 2, "vbi_out buffer %d done\n",
|
|
buf->vb.vb2_buf.index);
|
|
}
|
|
}
|
|
|
|
if (dev->vid_out_streaming || dev->vbi_out_streaming)
|
|
return;
|
|
|
|
/* shutdown control thread */
|
|
vivid_grab_controls(dev, false);
|
|
kthread_stop(dev->kthread_vid_out);
|
|
dev->kthread_vid_out = NULL;
|
|
}
|