From patchwork Fri Sep 11 10:09:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 7159171 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2FA109F39B for ; Fri, 11 Sep 2015 10:11:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3898020828 for ; Fri, 11 Sep 2015 10:11:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2936E2082D for ; Fri, 11 Sep 2015 10:11:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752355AbbIKKLW (ORCPT ); Fri, 11 Sep 2015 06:11:22 -0400 Received: from mga03.intel.com ([134.134.136.65]:28146 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751584AbbIKKLR (ORCPT ); Fri, 11 Sep 2015 06:11:17 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP; 11 Sep 2015 03:11:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,511,1437462000"; d="scan'208";a="559700302" Received: from paasikivi.fi.intel.com ([10.237.72.42]) by FMSMGA003.fm.intel.com with ESMTP; 11 Sep 2015 03:11:01 -0700 Received: from nauris.fi.intel.com (nauris.localdomain [192.168.240.2]) by paasikivi.fi.intel.com (Postfix) with ESMTP id 8087720EA1; Fri, 11 Sep 2015 13:11:00 +0300 (EEST) Received: by nauris.fi.intel.com (Postfix, from userid 1000) id 5160F20187; Fri, 11 Sep 2015 13:09:23 +0300 (EEST) From: Sakari Ailus To: linux-media@vger.kernel.org Cc: laurent.pinchart@ideasonboard.com, javier@osg.samsung.com, mchehab@osg.samsung.com, hverkuil@xs4all.nl Subject: [RFC 2/9] media: Introduce low_id for media entities Date: Fri, 11 Sep 2015 13:09:05 +0300 Message-Id: <1441966152-28444-3-git-send-email-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.1.0.231.g7484e3b In-Reply-To: <1441966152-28444-1-git-send-email-sakari.ailus@linux.intel.com> References: <1441966152-28444-1-git-send-email-sakari.ailus@linux.intel.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A low ID is a unique number specific to a media entity. The number is guaranteed to be under MEDIA_ENTITY_MAX_LOW_ID. Signed-off-by: Sakari Ailus --- drivers/media/media-device.c | 14 ++++++++++++++ include/media/media-device.h | 2 ++ include/media/media-entity.h | 3 +++ 3 files changed, 19 insertions(+) diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c index 1312e93..dfc5e4a 100644 --- a/drivers/media/media-device.c +++ b/drivers/media/media-device.c @@ -20,6 +20,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include #include #include #include @@ -543,6 +544,8 @@ int __must_check __media_device_register(struct media_device *mdev, if (WARN_ON(mdev->dev == NULL || mdev->model[0] == 0)) return -EINVAL; + bitmap_zero(mdev->entity_low_id, MEDIA_ENTITY_MAX_LOW_ID); + INIT_LIST_HEAD(&mdev->entities); INIT_LIST_HEAD(&mdev->interfaces); INIT_LIST_HEAD(&mdev->pads); @@ -628,6 +631,15 @@ int __must_check media_device_register_entity(struct media_device *mdev, INIT_LIST_HEAD(&entity->links); spin_lock(&mdev->lock); + entity->low_id = find_first_zero_bit(mdev->entity_low_id, + MEDIA_ENTITY_MAX_LOW_ID); + if (entity->low_id == MEDIA_ENTITY_MAX_LOW_ID) { + spin_unlock(&mdev->lock); + return -ENOSPC; + } + + __set_bit(entity->low_id, mdev->entity_low_id); + /* Initialize media_gobj embedded at the entity */ media_gobj_init(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj); @@ -660,6 +672,8 @@ void media_device_unregister_entity(struct media_entity *entity) spin_lock(&mdev->lock); + __clear_bit(entity->low_id, mdev->entity_low_id); + /* Remove interface links with this entity on it */ list_for_each_entry_safe(link, tmp, &mdev->links, graph_obj.list) { if (media_type(link->gobj1) == MEDIA_GRAPH_ENTITY diff --git a/include/media/media-device.h b/include/media/media-device.h index 1b12774..732163f 100644 --- a/include/media/media-device.h +++ b/include/media/media-device.h @@ -47,6 +47,7 @@ struct device; * @pad_id: Unique ID used on the last pad registered * @link_id: Unique ID used on the last link registered * @intf_devnode_id: Unique ID used on the last interface devnode registered + * @entity_low_id: Allocated low entity IDs * @entities: List of registered entities * @interfaces: List of registered interfaces * @pads: List of registered pads @@ -82,6 +83,7 @@ struct media_device { u32 pad_id; u32 link_id; u32 intf_devnode_id; + DECLARE_BITMAP(entity_low_id, MEDIA_ENTITY_MAX_LOW_ID); struct list_head entities; struct list_head interfaces; diff --git a/include/media/media-entity.h b/include/media/media-entity.h index bb6383b..2c56027 100644 --- a/include/media/media-entity.h +++ b/include/media/media-entity.h @@ -159,6 +159,8 @@ struct media_entity_operations { * @num_pads: Number of sink and source pads. * @num_links: Number of existing links, both enabled and disabled. * @num_backlinks: Number of backlinks + * @low_id: An unique low entity specific number. The numbers are + * re-used if entities are unregistered or registered again. * @pads: Pads array with the size defined by @num_pads. * @links: Linked list for the data links. * @ops: Entity operations. @@ -187,6 +189,7 @@ struct media_entity { u16 num_pads; u16 num_links; u16 num_backlinks; + u8 low_id; struct media_pad *pads; struct list_head links;