From patchwork Tue Aug 27 07:40:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 13779037 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E06D21386C6 for ; Tue, 27 Aug 2024 07:40:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724744437; cv=none; b=F7RPS3w4U7ltI/+9A6wtkHBBlIBXxIQX7nkspwaJN/W2CHsXRJ3vxMSNndZhYE9Q0OqI4nh7wzYJ8VqAeasGkddgS2AYUjnfmITfwCa1ImCqlXbDn7WZ4ZcPZmhVtbFd5Buyml8glPUz88EcdZUhkLs1eZlJWXmE67vUd7MgnRE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724744437; c=relaxed/simple; bh=9oQYutyaMOqF0Dhr+m43f5SOj9YtHMZEAOH2lpITvso=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=foxeVy48vnZDbfkTvyU+hFgigN/bQ9vqw0LtK+JOaTpsF5UYaZTJAYzrriOgJ3SFGGLgfQjF9025znkTPY+LbHFR+VAIl4voVH4u1QKe1DHELTYscFh592LpRII8b8V1hL7axXn8AdBb8SENnEkHDv8IkiqShx/f+yyF9K5P1t8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=cNfsDj7+; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="cNfsDj7+" Received: from ideasonboard.com (mob-5-90-141-165.net.vodafone.it [5.90.141.165]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B2381AB5; Tue, 27 Aug 2024 09:39:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1724744361; bh=9oQYutyaMOqF0Dhr+m43f5SOj9YtHMZEAOH2lpITvso=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cNfsDj7+iEkMZpZP18ekbwucykwCwT/g7JznSpCOyz29QG7k0wMKVQfrUxofwE9bH 5+9YywPIZHtGv1VluZrInaY63HMdxzcRAAjIBOcDeph0wAkxqgieeZ6Cf0e3Y3An1G X7dbYPRrk2Ri/tF+UJ3PLUhdbvEaxDDlkmgr0xek= From: Jacopo Mondi To: Naushir Patuck , Nick Hollinghurst , David Plowman , Dave Stevenson , Laurent Pinchart Cc: Jacopo Mondi , linux-media@vger.kernel.org Subject: [PATCH v3 1/4] media: pisp_be: Drop reference to non-existing function Date: Tue, 27 Aug 2024 09:40:15 +0200 Message-ID: <20240827074018.534354-2-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240827074018.534354-1-jacopo.mondi@ideasonboard.com> References: <20240827074018.534354-1-jacopo.mondi@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 A comment in the pisp_be driver references to the pispbe_schedule_internal() which doesn't exist. Drop it. Signed-off-by: Jacopo Mondi --- drivers/media/platform/raspberrypi/pisp_be/pisp_be.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c b/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c index 65ff2382cffe..8ba1b9f43ba1 100644 --- a/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c +++ b/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c @@ -368,10 +368,7 @@ static void pispbe_xlate_addrs(struct pispbe_dev *pispbe, ret = pispbe_get_planes_addr(addrs, buf[MAIN_INPUT_NODE], &pispbe->node[MAIN_INPUT_NODE]); if (ret <= 0) { - /* - * This shouldn't happen; pispbe_schedule_internal should insist - * on an input. - */ + /* Shouldn't happen, we have validated an input is available. */ dev_warn(pispbe->dev, "ISP-BE missing input\n"); hw_en->bayer_enables = 0; hw_en->rgb_enables = 0; From patchwork Tue Aug 27 07:40:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 13779038 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC62815884D for ; Tue, 27 Aug 2024 07:40:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724744439; cv=none; b=Edto+OPc62Ao0enRYPEK16nJl5TAHpPSicm9kCihkkGWz7vixbHJcaDzwagB2NVKgbFjx9LGY09YEgUx9dxp5oEP1PU5mfN0hR5x+xB1obVS7M1E7UWIpK7ZtYitkikaIjvzfkcD5K0/hsMATDaC1FzjyZrx94qQ2aJrXMLeKZE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724744439; c=relaxed/simple; bh=Wdxv9SQ6HPlRDOYbzWq3gMXeob61suNvNjG4TSNiDsE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q1/d6RB3llh8A4JVBbCqNHcT+1EGb44sXtIeXcqeGKBt+YpSyuA0jjXtGmvEPd1l2nPMin1dD/Oew7b2i8Up2tft3F1SLC9dJi5HoQpe73uDd6oijkDLhemr3QtUzcjRkBs7Vjsl88YO5SS8ohz5c6xtowCIwJYXRE+rWZO5U+Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=JTlE1gRu; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="JTlE1gRu" Received: from ideasonboard.com (mob-5-90-141-165.net.vodafone.it [5.90.141.165]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9E549B0B; Tue, 27 Aug 2024 09:39:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1724744362; bh=Wdxv9SQ6HPlRDOYbzWq3gMXeob61suNvNjG4TSNiDsE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JTlE1gRujUSUalu+CJyF3BOcvcScoRDVv3mm4raM86+WZ5MdtwjB26lqk92Gyfsi3 xEpJ/cEF5jBLJ1ejCDhEworf+5rhTHo4VS2tolJkzdlLQp6wqKZlCsKuuN4whITel7 nARWpQgoy/B6MXAmCqcwUpInEHtoefkEk6jsKmPE= From: Jacopo Mondi To: Naushir Patuck , Nick Hollinghurst , David Plowman , Dave Stevenson , Laurent Pinchart Cc: Jacopo Mondi , linux-media@vger.kernel.org Subject: [PATCH v3 2/4] media: pisp_be: Remove config validation from schedule() Date: Tue, 27 Aug 2024 09:40:16 +0200 Message-ID: <20240827074018.534354-3-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240827074018.534354-1-jacopo.mondi@ideasonboard.com> References: <20240827074018.534354-1-jacopo.mondi@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The config parameters buffer is already validated in pisp_be_validate_config() at .buf_prepare() time. However some of the same validations are also performed at pispbe_schedule() time. In particular the function checks that: 1) config.num_tiles is valid 2) At least one of the BAYER or RGB input is enabled The input validation is already performed in pisp_be_validate_config() and there is no need to repeat that at pispbe_schedule() time. The num_tiles validation can be moved to pisp_be_validate_config() as well. As num_tiles is a u32 it can'be be < 0, so change the sanity check accordingly. Signed-off-by: Jacopo Mondi --- .../platform/raspberrypi/pisp_be/pisp_be.c | 25 ++++++------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c b/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c index 8ba1b9f43ba1..73a5c88e25d0 100644 --- a/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c +++ b/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c @@ -588,24 +588,6 @@ static void pispbe_schedule(struct pispbe_dev *pispbe, bool clear_hw_busy) pispbe->hw_busy = true; spin_unlock_irqrestore(&pispbe->hw_lock, flags); - if (job.config->num_tiles <= 0 || - job.config->num_tiles > PISP_BACK_END_NUM_TILES || - !((job.hw_enables.bayer_enables | job.hw_enables.rgb_enables) & - PISP_BE_BAYER_ENABLE_INPUT)) { - /* - * Bad job. We can't let it proceed as it could lock up - * the hardware, or worse! - * - * For now, just force num_tiles to 0, which causes the - * H/W to do something bizarre but survivable. It - * increments (started,done) counters by more than 1, - * but we seem to survive... - */ - dev_dbg(pispbe->dev, "Bad job: invalid number of tiles: %u\n", - job.config->num_tiles); - job.config->num_tiles = 0; - } - pispbe_queue_job(pispbe, &job); return; @@ -703,6 +685,13 @@ static int pisp_be_validate_config(struct pispbe_dev *pispbe, return -EIO; } + if (config->num_tiles == 0 || + config->num_tiles > PISP_BACK_END_NUM_TILES) { + dev_dbg(dev, "%s: Invalid number of tiles: %d\n", __func__, + config->num_tiles); + return -EIO; + } + /* Ensure output config strides and buffer sizes match the V4L2 formats. */ fmt = &pispbe->node[TDN_OUTPUT_NODE].format; if (bayer_enables & PISP_BE_BAYER_ENABLE_TDN_OUTPUT) { From patchwork Tue Aug 27 07:40:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 13779039 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE7B81386C6 for ; Tue, 27 Aug 2024 07:40:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724744440; cv=none; b=WD463itVVpYqBvNpncuJ1NnycQjMRST15gbtPm/kOmYejftIHLSfZwa0933sCp2lEiawDbxBMEQdQlPGcqD4AMJPV7oNtxGTQnmFyLnbCnawTh78o58h3onVHJb1gj/7Rj0Pjo/kQs+RFwkWkfSG1NXlf4pJL5gCF5o85zXT+LA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724744440; c=relaxed/simple; bh=rNfj1r2BmYuLAhonK75fj6llVhCusCLkj0fbb4C4avA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J4p9QiTol2qQD03M7lupwcnFlcFkfO6Q8T9HcRxaQxmQIKcb4yFlq6mKyCh2dOomoxipTVmBM2wrmKKx+tsoevOB3+VQB826FPrBU9L8gorq4JZjfjSUtLlWQDo5JVrBNFzbEIr/bcDjSmhJe8sFOdLQcuLAAMO+2GghDgUer0E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=UcKolpGU; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="UcKolpGU" Received: from ideasonboard.com (mob-5-90-141-165.net.vodafone.it [5.90.141.165]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7E410EA5; Tue, 27 Aug 2024 09:39:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1724744363; bh=rNfj1r2BmYuLAhonK75fj6llVhCusCLkj0fbb4C4avA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UcKolpGUhkfUzfKFGXyqdHc7lkJXTFKQ+YRCpbVWTOSGAN6OVD0VTyhQ6HjBak+32 ZJLKRu8HsCfWmkC4Od5/1TnSkoBOyR0OvcrMUOZGJkyxLCrJ0RWpu6HWY46vurVJNv 6/0Y4OMjG4n+VhqS6/0O+ad7eiR9+Od9CkRiNrwc= From: Jacopo Mondi To: Naushir Patuck , Nick Hollinghurst , David Plowman , Dave Stevenson , Laurent Pinchart Cc: Jacopo Mondi , linux-media@vger.kernel.org Subject: [PATCH v3 3/4] media: pisp-be: Split jobs creation and scheduling Date: Tue, 27 Aug 2024 09:40:17 +0200 Message-ID: <20240827074018.534354-4-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240827074018.534354-1-jacopo.mondi@ideasonboard.com> References: <20240827074018.534354-1-jacopo.mondi@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently the 'pispbe_schedule()' function does two things: 1) Tries to assemble a job by inspecting all the video node queues to make sure all the required buffers are available 2) Submit the job to the hardware The pispbe_schedule() function is called at: - video device start_streaming() time - video device qbuf() time - irq handler As assembling a job requires inspecting all queues, it is a rather time consuming operation which is better not run in IRQ context. To avoid the executing the time consuming job creation in interrupt context split the job creation and job scheduling in two distinct operations. When a well-formed job is created, append it to the newly introduced 'pispbe->job_queue' where it will be dequeued from by the scheduling routine. At start_streaming() and qbuf() time immediately try to schedule a job if one has been created as the irq handler routing is only called when a job has completed, and we can't solely rely on it for scheduling new jobs. Signed-off-by: Jacopo Mondi --- .../platform/raspberrypi/pisp_be/pisp_be.c | 137 +++++++++++------- 1 file changed, 83 insertions(+), 54 deletions(-) diff --git a/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c b/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c index 73a5c88e25d0..f42541bb4827 100644 --- a/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c +++ b/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c @@ -190,6 +190,8 @@ struct pispbe_hw_enables { /* Records a job configuration and memory addresses. */ struct pispbe_job_descriptor { + struct list_head queue; + struct pispbe_buffer *buffers[PISPBE_NUM_NODES]; dma_addr_t hw_dma_addrs[N_HW_ADDRESSES]; struct pisp_be_tiles_config *config; struct pispbe_hw_enables hw_enables; @@ -215,8 +217,10 @@ struct pispbe_dev { unsigned int sequence; u32 streaming_map; struct pispbe_job queued_job, running_job; - spinlock_t hw_lock; /* protects "hw_busy" flag and streaming_map */ + /* protects "hw_busy" flag, streaming_map and job_queue*/ + spinlock_t hw_lock; bool hw_busy; /* non-zero if a job is queued or is being started */ + struct list_head job_queue; int irq; u32 hw_version; u8 done, started; @@ -440,41 +444,50 @@ static void pispbe_xlate_addrs(struct pispbe_dev *pispbe, * For Output0, Output1, Tdn and Stitch, a buffer only needs to be * available if the blocks are enabled in the config. * - * Needs to be called with hw_lock held. + * If all the buffers required to form a job are available, append the + * job descriptor to the job queue to be later queued to the HW. * * Returns 0 if a job has been successfully prepared, < 0 otherwise. */ -static int pispbe_prepare_job(struct pispbe_dev *pispbe, - struct pispbe_job_descriptor *job) +static int pispbe_prepare_job(struct pispbe_dev *pispbe) { struct pispbe_buffer *buf[PISPBE_NUM_NODES] = {}; + struct pispbe_job_descriptor *job; + unsigned int streaming_map; unsigned int config_index; struct pispbe_node *node; - unsigned long flags; - lockdep_assert_held(&pispbe->hw_lock); + scoped_guard(spinlock_irqsave, &pispbe->hw_lock) { + static const u32 mask = BIT(CONFIG_NODE) | BIT(MAIN_INPUT_NODE); - memset(job, 0, sizeof(struct pispbe_job_descriptor)); + if ((pispbe->streaming_map & mask) != mask) + return -ENODEV; - if (((BIT(CONFIG_NODE) | BIT(MAIN_INPUT_NODE)) & - pispbe->streaming_map) != - (BIT(CONFIG_NODE) | BIT(MAIN_INPUT_NODE))) - return -ENODEV; + /* + * Take a copy of streaming_map: nodes activated after this + * point are ignored when preparing this job. + */ + streaming_map = pispbe->streaming_map; + } + + job = kzalloc(sizeof(*job), GFP_KERNEL); + if (!job) + return -ENOMEM; node = &pispbe->node[CONFIG_NODE]; - spin_lock_irqsave(&node->ready_lock, flags); - buf[CONFIG_NODE] = list_first_entry_or_null(&node->ready_queue, - struct pispbe_buffer, - ready_list); - if (buf[CONFIG_NODE]) { + + scoped_guard(spinlock_irqsave, &node->ready_lock) { + buf[CONFIG_NODE] = list_first_entry_or_null(&node->ready_queue, + struct pispbe_buffer, + ready_list); + if (!buf[CONFIG_NODE]) { + kfree(job); + return -ENODEV; + } + list_del(&buf[CONFIG_NODE]->ready_list); - pispbe->queued_job.buf[CONFIG_NODE] = buf[CONFIG_NODE]; + job->buffers[CONFIG_NODE] = buf[CONFIG_NODE]; } - spin_unlock_irqrestore(&node->ready_lock, flags); - - /* Exit early if no config buffer has been queued. */ - if (!buf[CONFIG_NODE]) - return -ENODEV; config_index = buf[CONFIG_NODE]->vb.vb2_buf.index; job->config = &pispbe->config[config_index]; @@ -495,7 +508,7 @@ static int pispbe_prepare_job(struct pispbe_dev *pispbe, continue; buf[i] = NULL; - if (!(pispbe->streaming_map & BIT(i))) + if (!(streaming_map & BIT(i))) continue; if ((!(rgb_en & PISP_BE_RGB_ENABLE_OUTPUT0) && @@ -522,25 +535,27 @@ static int pispbe_prepare_job(struct pispbe_dev *pispbe, node = &pispbe->node[i]; /* Pull a buffer from each V4L2 queue to form the queued job */ - spin_lock_irqsave(&node->ready_lock, flags); + spin_lock(&node->ready_lock); buf[i] = list_first_entry_or_null(&node->ready_queue, struct pispbe_buffer, ready_list); if (buf[i]) { list_del(&buf[i]->ready_list); - pispbe->queued_job.buf[i] = buf[i]; + job->buffers[i] = buf[i]; } - spin_unlock_irqrestore(&node->ready_lock, flags); + spin_unlock(&node->ready_lock); if (!buf[i] && !ignore_buffers) goto err_return_buffers; } - pispbe->queued_job.valid = true; - /* Convert buffers to DMA addresses for the hardware */ pispbe_xlate_addrs(pispbe, job, buf); + spin_lock(&pispbe->hw_lock); + list_add_tail(&job->queue, &pispbe->job_queue); + spin_unlock(&pispbe->hw_lock); + return 0; err_return_buffers: @@ -551,33 +566,41 @@ static int pispbe_prepare_job(struct pispbe_dev *pispbe, continue; /* Return the buffer to the ready_list queue */ - spin_lock_irqsave(&n->ready_lock, flags); + spin_lock(&n->ready_lock); list_add(&buf[i]->ready_list, &n->ready_queue); - spin_unlock_irqrestore(&n->ready_lock, flags); + spin_unlock(&n->ready_lock); } - memset(&pispbe->queued_job, 0, sizeof(pispbe->queued_job)); + kfree(job); return -ENODEV; } static void pispbe_schedule(struct pispbe_dev *pispbe, bool clear_hw_busy) { - struct pispbe_job_descriptor job; - unsigned long flags; - int ret; + struct pispbe_job_descriptor *job; - spin_lock_irqsave(&pispbe->hw_lock, flags); + scoped_guard(spinlock_irqsave, &pispbe->hw_lock) { + if (clear_hw_busy) + pispbe->hw_busy = false; - if (clear_hw_busy) - pispbe->hw_busy = false; + if (pispbe->hw_busy) + return; - if (pispbe->hw_busy) - goto unlock_and_return; + job = list_first_entry_or_null(&pispbe->job_queue, + struct pispbe_job_descriptor, + queue); + if (!job) + return; - ret = pispbe_prepare_job(pispbe, &job); - if (ret) - goto unlock_and_return; + list_del(&job->queue); + + for (unsigned int i = 0; i < PISPBE_NUM_NODES; i++) + pispbe->queued_job.buf[i] = job->buffers[i]; + pispbe->queued_job.valid = true; + + pispbe->hw_busy = true; + } /* * We can kick the job off without the hw_lock, as this can @@ -585,16 +608,8 @@ static void pispbe_schedule(struct pispbe_dev *pispbe, bool clear_hw_busy) * only when the following job has been queued and an interrupt * is rised. */ - pispbe->hw_busy = true; - spin_unlock_irqrestore(&pispbe->hw_lock, flags); - - pispbe_queue_job(pispbe, &job); - - return; - -unlock_and_return: - /* No job has been queued, just release the lock and return. */ - spin_unlock_irqrestore(&pispbe->hw_lock, flags); + pispbe_queue_job(pispbe, job); + kfree(job); } static void pispbe_isr_jobdone(struct pispbe_dev *pispbe, @@ -857,7 +872,8 @@ static void pispbe_node_buffer_queue(struct vb2_buffer *buf) * Every time we add a buffer, check if there's now some work for the hw * to do. */ - pispbe_schedule(pispbe, false); + if (!pispbe_prepare_job(pispbe)) + pispbe_schedule(pispbe, false); } static int pispbe_node_start_streaming(struct vb2_queue *q, unsigned int count) @@ -883,7 +899,8 @@ static int pispbe_node_start_streaming(struct vb2_queue *q, unsigned int count) node->pispbe->streaming_map); /* Maybe we're ready to run. */ - pispbe_schedule(pispbe, false); + if (!pispbe_prepare_job(pispbe)) + pispbe_schedule(pispbe, false); return 0; @@ -935,6 +952,16 @@ static void pispbe_node_stop_streaming(struct vb2_queue *q) spin_lock_irqsave(&pispbe->hw_lock, flags); pispbe->streaming_map &= ~BIT(node->id); + + /* Release all jobs once all nodes have stopped streaming. */ + if (pispbe->streaming_map == 0) { + struct pispbe_job_descriptor *job, *temp; + + list_for_each_entry_safe(job, temp, &pispbe->job_queue, queue) { + list_del(&job->queue); + kfree(job); + } + } spin_unlock_irqrestore(&pispbe->hw_lock, flags); pm_runtime_mark_last_busy(pispbe->dev); @@ -1677,6 +1704,8 @@ static int pispbe_probe(struct platform_device *pdev) if (!pispbe) return -ENOMEM; + INIT_LIST_HEAD(&pispbe->job_queue); + dev_set_drvdata(&pdev->dev, pispbe); pispbe->dev = &pdev->dev; platform_set_drvdata(pdev, pispbe); From patchwork Tue Aug 27 07:40:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 13779040 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 024B817BEB4 for ; Tue, 27 Aug 2024 07:40:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724744442; cv=none; b=XWXB09o3BI7WrGCrVUC8dgom6+Ri9ft0hHXBCLp3Zr9plVcs6LPyOyEXCeArTc/0CoGUgsTdKb7nbeVstx7FiDx7hNjwObwRf1tsQYW9x/9PIpofOPZjhgDewwj0SUucITXfx+5AzpelJhPGAtIRVYdzWmojOKsykD6eh6UfbQk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724744442; c=relaxed/simple; bh=C1GMOlCCmHK5jSLrEL5ZhvA7WyLSyThxLUvjpRamQGw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VJo8bNXk8dNlpbpbv0q+ZrLZbG8IqyQ3RqZhJ0wwYXg3JoVUUv0UPsIL2dwwFuy/z/HnEyF5QpRm8pZ8IyiMGLpVO5OvNTZGYNPvMxSv2TofqcVUTfzex7esDv4KLLv4eEKELpNH0ffcpZHY4vzpJ/3wFMxn6fljhdtKffkzweM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=NGfAYLY4; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="NGfAYLY4" Received: from ideasonboard.com (mob-5-90-141-165.net.vodafone.it [5.90.141.165]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6122B108D; Tue, 27 Aug 2024 09:39:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1724744364; bh=C1GMOlCCmHK5jSLrEL5ZhvA7WyLSyThxLUvjpRamQGw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NGfAYLY4t/QSXq8N801vnYL5CPj+Th1FRiiFc5CEOjwOyBIzFRNRIe0Qnm8XJDzIB uaQ1BLgzkhlY9GuHHq5c/8gGjb/HCfGhcOydam/hBV0Zt1QtU0hIBnwOgfQzmQ8o8/ 4Ki3aKZ0S9EGI2a5u5W/hSreEZdwweqqSWFWEn0U= From: Jacopo Mondi To: Naushir Patuck , Nick Hollinghurst , David Plowman , Dave Stevenson , Laurent Pinchart Cc: Jacopo Mondi , linux-media@vger.kernel.org Subject: [PATCH v3 4/4] media: pisp_be: Fix pm_runtime underrun in probe Date: Tue, 27 Aug 2024 09:40:18 +0200 Message-ID: <20240827074018.534354-5-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240827074018.534354-1-jacopo.mondi@ideasonboard.com> References: <20240827074018.534354-1-jacopo.mondi@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The pisp_be driver uses and depends on runtime_pm. During the probe() routine, the driver needs to power up the interface in order to identify and initialize the hardware and it later suspends it at the end of probe(). The driver erroneously resumes the interface by calling the pispbe_runtime_resume() function directly, without going through the pm_runtime helpers, but later suspends it by calling pm_runtime_put_autosuspend(). This causes a PM usage count imbalance at probe time, notified by the runtime_pm framework with the below message in the system log: pispbe 1000880000.pisp_be: Runtime PM usage count underflow! Fix this by resuming the interface using the pm runtime helpers instead of calling the resume function directly. Fixes: 12187bd5d4f8 ("media: raspberrypi: Add support for PiSP BE") Signed-off-by: Jacopo Mondi --- v2->v3: - Mark pispbe_runtime_resume() as __maybe_unused as reported by the kernel test robot - Add fixes tag --- drivers/media/platform/raspberrypi/pisp_be/pisp_be.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.45.2 diff --git a/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c b/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c index f42541bb4827..7b62585d7510 100644 --- a/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c +++ b/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c @@ -1638,7 +1638,7 @@ static int pispbe_runtime_suspend(struct device *dev) return 0; } -static int pispbe_runtime_resume(struct device *dev) +static int __maybe_unused pispbe_runtime_resume(struct device *dev) { struct pispbe_dev *pispbe = dev_get_drvdata(dev); int ret; @@ -1741,7 +1741,7 @@ static int pispbe_probe(struct platform_device *pdev) pm_runtime_use_autosuspend(pispbe->dev); pm_runtime_enable(pispbe->dev); - ret = pispbe_runtime_resume(pispbe->dev); + ret = pm_runtime_resume_and_get(pispbe->dev); if (ret) goto pm_runtime_disable_err;