From patchwork Sun Feb 7 18:40:41 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 77628 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o17IdrO1006594 for ; Sun, 7 Feb 2010 18:39:53 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932729Ab0BGSjv (ORCPT ); Sun, 7 Feb 2010 13:39:51 -0500 Received: from smtp.nokia.com ([192.100.105.134]:64089 "EHLO mgw-mx09.nokia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932788Ab0BGSju (ORCPT ); Sun, 7 Feb 2010 13:39:50 -0500 Received: from esebh105.NOE.Nokia.com (esebh105.ntc.nokia.com [172.21.138.211]) by mgw-mx09.nokia.com (Switch-3.3.3/Switch-3.3.3) with ESMTP id o17IdiGB031060; Sun, 7 Feb 2010 12:39:46 -0600 Received: from esebh102.NOE.Nokia.com ([172.21.138.183]) by esebh105.NOE.Nokia.com with Microsoft SMTPSVC(6.0.3790.3959); Sun, 7 Feb 2010 20:39:44 +0200 Received: from mgw-sa02.ext.nokia.com ([147.243.1.48]) by esebh102.NOE.Nokia.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.3959); Sun, 7 Feb 2010 20:39:44 +0200 Received: from maxwell.research.nokia.com (maxwell.research.nokia.com [172.21.50.162]) by mgw-sa02.ext.nokia.com (Switch-3.3.3/Switch-3.3.3) with ESMTP id o17IdgeY031648 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 7 Feb 2010 20:39:42 +0200 Received: from lanttu (unknown [192.168.239.74]) by maxwell.research.nokia.com (Postfix) with ESMTPS id 6407370088; Sun, 7 Feb 2010 20:39:42 +0200 (EET) Received: from sakke by lanttu with local (Exim 4.69) (envelope-from ) id 1NeC3s-00085p-3Z; Sun, 07 Feb 2010 20:40:48 +0200 From: Sakari Ailus To: linux-media@vger.kernel.org Cc: hverkuil@xs4all.nl, laurent.pinchart@ideasonboard.com, iivanov@mm-sol.com, gururaj.nagendra@intel.com, david.cohen@nokia.com, Sakari Ailus Subject: [PATCH v2 1/7] V4L: File handles Date: Sun, 7 Feb 2010 20:40:41 +0200 Message-Id: <1265568047-31073-1-git-send-email-sakari.ailus@maxwell.research.nokia.com> X-Mailer: git-send-email 1.5.6.5 In-Reply-To: <4B6F0922.9070206@maxwell.research.nokia.com> References: <4B6F0922.9070206@maxwell.research.nokia.com> X-OriginalArrivalTime: 07 Feb 2010 18:39:44.0347 (UTC) FILETIME=[EAB48AB0:01CAA824] X-Nokia-AV: Clean Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Sun, 07 Feb 2010 18:39:53 +0000 (UTC) diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile index 6e75647..b888ad1 100644 --- a/drivers/media/video/Makefile +++ b/drivers/media/video/Makefile @@ -10,7 +10,8 @@ stkwebcam-objs := stk-webcam.o stk-sensor.o omap2cam-objs := omap24xxcam.o omap24xxcam-dma.o -videodev-objs := v4l2-dev.o v4l2-ioctl.o v4l2-device.o v4l2-subdev.o +videodev-objs := v4l2-dev.o v4l2-ioctl.o v4l2-device.o v4l2-subdev.o \ + v4l2-fh.o # V4L2 core modules diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c index 13a899d..d8c14a5 100644 --- a/drivers/media/video/v4l2-dev.c +++ b/drivers/media/video/v4l2-dev.c @@ -423,6 +423,8 @@ static int __video_register_device(struct video_device *vdev, int type, int nr, if (!vdev->release) return -EINVAL; + v4l2_fh_init(vdev); + /* Part 1: check device type */ switch (type) { case VFL_TYPE_GRABBER: diff --git a/drivers/media/video/v4l2-fh.c b/drivers/media/video/v4l2-fh.c new file mode 100644 index 0000000..c1e8baf --- /dev/null +++ b/drivers/media/video/v4l2-fh.c @@ -0,0 +1,58 @@ +/* + * drivers/media/video/v4l2-fh.c + * + * V4L2 file handles. + * + * Copyright (C) 2009 Nokia Corporation. + * + * Contact: Sakari Ailus + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include +#include + +void v4l2_fh_add(struct video_device *vdev, struct v4l2_fh *fh) +{ + unsigned long flags; + + fh->vdev = vdev; + + spin_lock_irqsave(&vdev->fhs.lock, flags); + list_add(&fh->list, &vdev->fhs.list); + spin_unlock_irqrestore(&vdev->fhs.lock, flags); +} +EXPORT_SYMBOL_GPL(v4l2_fh_add); + +void v4l2_fh_del(struct v4l2_fh *fh) +{ + unsigned long flags; + + BUG_ON(fh->vdev == NULL); + + spin_lock_irqsave(&fh->vdev->fhs.lock, flags); + list_del(&fh->list); + spin_unlock_irqrestore(&fh->vdev->fhs.lock, flags); + + fh->vdev = NULL; +} +EXPORT_SYMBOL_GPL(v4l2_fh_del); + +void v4l2_fh_init(struct video_device *vdev) +{ + spin_lock_init(&vdev->fhs.lock); + INIT_LIST_HEAD(&vdev->fhs.list); +} diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h index 26d4e79..65d9dc8 100644 --- a/include/media/v4l2-dev.h +++ b/include/media/v4l2-dev.h @@ -18,6 +18,8 @@ #include +#include + #define VIDEO_MAJOR 81 #define VFL_TYPE_GRABBER 0 @@ -82,6 +84,9 @@ struct video_device /* attribute to differentiate multiple indices on one physical device */ int index; + /* V4L2 file handles */ + struct v4l2_fhs fhs; + int debug; /* Activates debug level*/ /* Video standard vars */ diff --git a/include/media/v4l2-fh.h b/include/media/v4l2-fh.h new file mode 100644 index 0000000..e70200a --- /dev/null +++ b/include/media/v4l2-fh.h @@ -0,0 +1,52 @@ +/* + * include/media/v4l2-fh.h + * + * V4L2 file handle. + * + * Copyright (C) 2009 Nokia Corporation. + * + * Contact: Sakari Ailus + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef V4L2_FH_H +#define V4L2_FH_H + +#include +#include + +#include + +struct video_device; + +struct v4l2_fh { + struct list_head list; + struct video_device *vdev; +}; + +/* File handle related data for video_device. */ +struct v4l2_fhs { + /* Lock for file handle list */ + spinlock_t lock; + /* File handle list */ + struct list_head list; +}; + +void v4l2_fh_add(struct video_device *vdev, struct v4l2_fh *fh); +void v4l2_fh_del(struct v4l2_fh *fh); +void v4l2_fh_init(struct video_device *vdev); + +#endif /* V4L2_EVENT_H */