From patchwork Thu Nov 9 21:03:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 163595 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b129:0:b0:403:3b70:6f57 with SMTP id q9csp707162vqs; Thu, 9 Nov 2023 13:07:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IF0Vi9a2GrSGjQfX5Gls3B2Lq5Kx0YSWkbwI6ENXxO0PR0ztj5jV7v3h5YeVEywQLnicc9f X-Received: by 2002:a05:6830:13c4:b0:6bd:d1fc:2f2f with SMTP id e4-20020a05683013c400b006bdd1fc2f2fmr7096758otq.21.1699564020184; Thu, 09 Nov 2023 13:07:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699564020; cv=none; d=google.com; s=arc-20160816; b=DXq1Dn0kFPtU5q/M/porq8iK7qfLbnxfM6eeQnA9dVcCDGP61s/gRHrmnvGUShrt4Z LFCiEBnnYof9xIwZi1F5CAA3n24ggxDBBcBrBKWRSrfiI58miNAXjjmLBKwbAzuOHDmd ZXB7BrbFCX+0A1Yo7igcCWcw3p/+hapHy+bDl0KGl1FWxDMRpgMnyVuq1pL0y8exH1+S C4OgfBmlqaLBB135NNbBE6/Y7Ko8ivOAJkI+N2NvO0+nQx1j6/jl8Xf39zPtZpVW9V4R 3IwTiDPDKLAUC+GjjJYmgtsdkwLs26mOMUayUlSuYYUFZSwSz7OsVGf/bWPuv5CQOvlT yq0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YRElO3WGjXFc7N3zQF6ct4VWSaoDdCUB923nVkOWsVo=; fh=CGD8sPkE9LFVktNEez1cSTZ9bW97xSrzpPiSAFxWsOU=; b=zZX2Q9T26QFY+GA0kjR8ChMcsQfwTXYPNHCBpOLksLlmmy4/oOvHJ+BZftz1IyT5DH h7mMmy2cJwwXfXYhxrsqY5/XxQplMLCnDI4Fe1Ey5MyxWvIe9RXVOEypp4V01ymLYqbY k5lBxGPGaMeDIlCrUUepklhjPCqX+3T5/DWehOxmywVLNconOJ/Zbx9Nj52wMseOSTMH ml4ULLmEyEFCk8+vszYknXcSXqV6FWaMI6xsRwn/nOsYDXRsqWVL6vJXmEyIAEO4PL5e HMXnar0Hf+gZlHexve5dTEGSpmoTwpsg5W1tS3OZMf9t+b9J+nTgw0wc2l8kG0gvcFdy Y5Fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=CvgblSuq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id z20-20020a9d62d4000000b006bca76aa21esi6275081otk.103.2023.11.09.13.06.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 13:07:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=CvgblSuq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id D86BC832CE7E; Thu, 9 Nov 2023 13:06:45 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345287AbjKIVEr (ORCPT + 30 others); Thu, 9 Nov 2023 16:04:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345357AbjKIVEP (ORCPT ); Thu, 9 Nov 2023 16:04:15 -0500 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5952349E3; Thu, 9 Nov 2023 13:03:54 -0800 (PST) Received: from umang.jain (unknown [103.251.226.64]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 84CCF124F; Thu, 9 Nov 2023 22:03:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1699563810; bh=/NhVBkmAZJpXUdV/Jyjhk0OJS8toVJ5blJzkBkbr6Kk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CvgblSuqljkOD0d8324ELh4rRIfsAlfbn5V3NRpTHVKi0qJPcdshB50g24NTFQiPY xelivhSZbzi2bS4oFz6nfAFhT1loHvmixQ44aawVULJhQ/3P/xX27u1c7T0fiJMqxB fmXZa02gCxm3svoAMFWEOg1QuXCiIjrfZeIWTdO0= From: Umang Jain To: linux-media@vger.kernel.org, kernel-list@raspberrypi.com, linux-kernel@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-staging@lists.linux.dev Cc: Dave Stevenson , Kieran Bingham , Laurent Pinchart , "Ricardo B . Marliere" , Dan Carpenter , Stefan Wahren , Naushir Patuck , Umang Jain Subject: [PATCH v2 13/15] staging: vc04_services: bcm2835_isp: Allow multiple users Date: Thu, 9 Nov 2023 16:03:05 -0500 Message-ID: <20231109210309.638594-14-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231109210309.638594-1-umang.jain@ideasonboard.com> References: <20231109210309.638594-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 09 Nov 2023 13:06:45 -0800 (PST) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782122042064360169 X-GMAIL-MSGID: 1782122042064360169 From: Naushir Patuck Add a second (identical) set of device nodes to allow concurrent use of the bcm2835-isp hardware by another user. This change effectively creates a second state structure (struct bcm2835_isp_dev) to maintain independent state for the second user. Node and media entity names are appened with the instance index appropriately. Further users can be added by changing the BCM2835_ISP_NUM_INSTANCES define. Signed-off-by: Naushir Patuck Signed-off-by: Umang Jain --- .../bcm2835-isp/bcm2835-v4l2-isp.c | 73 +++++++++++++++---- 1 file changed, 59 insertions(+), 14 deletions(-) diff --git a/drivers/staging/vc04_services/bcm2835-isp/bcm2835-v4l2-isp.c b/drivers/staging/vc04_services/bcm2835-isp/bcm2835-v4l2-isp.c index b6ac1ee8f9f3..316d35d5f19d 100644 --- a/drivers/staging/vc04_services/bcm2835-isp/bcm2835-v4l2-isp.c +++ b/drivers/staging/vc04_services/bcm2835-isp/bcm2835-v4l2-isp.c @@ -28,13 +28,19 @@ MODULE_IMPORT_NS(DMA_BUF); +/* + * We want to instantiate 2 independent instances allowing 2 simultaneous users + * of the ISP hardware. + */ +#define BCM2835_ISP_NUM_INSTANCES 2 + static unsigned int debug; module_param(debug, uint, 0644); MODULE_PARM_DESC(debug, "activates debug info"); -static unsigned int video_nr = 13; -module_param(video_nr, uint, 0644); -MODULE_PARM_DESC(video_nr, "base video device number"); +static unsigned int video_nr[BCM2835_ISP_NUM_INSTANCES] = { 13, 20 }; +module_param_array(video_nr, uint, NULL, 0644); +MODULE_PARM_DESC(video_nr, "base video device numbers"); #define BCM2835_ISP_NAME "bcm2835-isp" #define BCM2835_ISP_ENTITY_NAME_LEN 32 @@ -1287,6 +1293,7 @@ static int bcm2835_isp_get_supported_fmts(struct bcm2835_isp_node *node) * or output nodes. */ static int register_node(struct bcm2835_isp_dev *dev, + unsigned int instance, struct bcm2835_isp_node *node, int index) { @@ -1448,7 +1455,7 @@ static int register_node(struct bcm2835_isp_dev *dev, snprintf(vfd->name, sizeof(node->vfd.name), "%s-%s%d", BCM2835_ISP_NAME, node->name, node->id); - ret = video_register_device(vfd, VFL_TYPE_VIDEO, video_nr + index); + ret = video_register_device(vfd, VFL_TYPE_VIDEO, video_nr[instance]); if (ret) { v4l2_err(&dev->v4l2_dev, "Failed to register video %s[%d] device node\n", @@ -1669,9 +1676,8 @@ static int media_controller_register(struct bcm2835_isp_dev *dev) return ret; } -static void bcm2835_isp_remove(struct vchiq_device *device) +static void bcm2835_isp_remove_instance(struct bcm2835_isp_dev *dev) { - struct bcm2835_isp_dev *dev = vchiq_get_drvdata(device); unsigned int i; media_controller_unregister(dev); @@ -1688,7 +1694,9 @@ static void bcm2835_isp_remove(struct vchiq_device *device) vchiq_mmal_finalise(dev->mmal_instance); } -static int bcm2835_isp_probe(struct vchiq_device *device) +static int bcm2835_isp_probe_instance(struct vchiq_device *device, + struct bcm2835_isp_dev **dev_int, + unsigned int instance) { struct bcm2835_isp_dev *dev; unsigned int i; @@ -1698,6 +1706,7 @@ static int bcm2835_isp_probe(struct vchiq_device *device) if (!dev) return -ENOMEM; + *dev_int = dev; dev->dev = &device->dev; ret = v4l2_device_register(&device->dev, &dev->v4l2_dev); @@ -1715,7 +1724,7 @@ static int bcm2835_isp_probe(struct vchiq_device *device) if (ret) { v4l2_err(&dev->v4l2_dev, "%s: failed to create ril.isp component\n", __func__); - goto error; + return ret; } if (dev->component->inputs < BCM2835_ISP_NUM_OUTPUTS || @@ -1727,7 +1736,7 @@ static int bcm2835_isp_probe(struct vchiq_device *device) BCM2835_ISP_NUM_OUTPUTS, dev->component->outputs, BCM2835_ISP_NUM_CAPTURES + BCM2835_ISP_NUM_METADATA); - goto error; + return -EINVAL; } atomic_set(&dev->num_streaming, 0); @@ -1735,17 +1744,53 @@ static int bcm2835_isp_probe(struct vchiq_device *device) for (i = 0; i < BCM2835_ISP_NUM_NODES; i++) { struct bcm2835_isp_node *node = &dev->node[i]; - ret = register_node(dev, node, i); + ret = register_node(dev, instance, node, i); if (ret) - goto error; + return ret; } ret = media_controller_register(dev); if (ret) - goto error; + return ret; + + return 0; +} + +static void bcm2835_isp_remove(struct vchiq_device *device) +{ + struct bcm2835_isp_dev **bcm2835_isp_instances; + unsigned int i; + + bcm2835_isp_instances = vchiq_get_drvdata(device); + for (i = 0; i < BCM2835_ISP_NUM_INSTANCES; i++) { + if (bcm2835_isp_instances[i]) + bcm2835_isp_remove_instance(bcm2835_isp_instances[i]); + } +} + +static int bcm2835_isp_probe(struct vchiq_device *device) +{ + struct bcm2835_isp_dev **bcm2835_isp_instances; + unsigned int i; + int ret; + + bcm2835_isp_instances = devm_kzalloc(&device->dev, + sizeof(bcm2835_isp_instances) * + BCM2835_ISP_NUM_INSTANCES, + GFP_KERNEL); + if (!bcm2835_isp_instances) + return -ENOMEM; + + vchiq_set_drvdata(device, bcm2835_isp_instances); + + for (i = 0; i < BCM2835_ISP_NUM_INSTANCES; i++) { + ret = bcm2835_isp_probe_instance(device, + &bcm2835_isp_instances[i], i); + if (ret) + goto error; + } - vchiq_set_drvdata(device, dev); - v4l2_info(&dev->v4l2_dev, "Loaded V4L2 %s\n", BCM2835_ISP_NAME); + dev_info(&device->dev, "Loaded V4L2 %s\n", BCM2835_ISP_NAME); return 0; error: