From patchwork Wed Jan 15 17:25:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 13940684 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 527A41A76C7; Wed, 15 Jan 2025 17:25:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736961935; cv=none; b=kuBSB1bENmeKhpahAlll7BwlSgNUsROnpdIOrTylTYUuKPHOhioVkyfKV82odVJSotW8owfjrkUdx5OiPLRnG6fFT3e1v0sGgnTKG9Pv9BUjqoutMwyc/1PWhuHWhKAJ0yL1HFc+QZjlj4kUuNN82dk92VuIi+OqlmD/B+nutr8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736961935; c=relaxed/simple; bh=mlYRc6C2JKLmWHattYXyz8UKfy+cpS8lvLrsjq/bJT0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VgQMDbxcxH5lAQo47NGkFRaOCcY5gGIN8lYttwikU/dYkeZV+oDNkYmqC0p0CJJ9gU+gS7GwvMLsQ0jNRW1v6SwUPA6aNukvDOzWKlRY5N3V550CxqlAqcbFH19gCli/AGGxJvrF0fny4gdTtaZqQyfmisauvQiWTSe5Lln89o8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lluBnIVU; arc=none smtp.client-ip=209.85.167.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lluBnIVU" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-53e384e3481so27183e87.2; Wed, 15 Jan 2025 09:25:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736961931; x=1737566731; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=9HYJB0bgtbTOpoerPY9z51D+wj9so15vlFQsgiuWCBU=; b=lluBnIVURjsrlETMFBLK2BKcPDWWPFWkWrSkJqBtGmCAqUMLoFAUV54sW6PHzHb4m0 es1xJhWhclmEKpJXZhJFcF52cFHWkMnKF8DZRLwEBxsntRJUshj3qomLoh8kmivpCFht 4A2+xals5hsdTxqzgKSNKQGinKVGrGBouHdYQn3SoGIt+1DanrIVsrNnkCKDDR/tZD+C nQINkeM747OB1vrA8w7L3P8z2YwD3VNniiL9hkWNSfg/tA2hTpHfpJOkogjS43SmA4BI lncqoI7Cd4sAQoiYV9uS2Nv9oABX6WJvQZbP0m076OHAQq7IepKO80RWat1FuY8WUXPj NYTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736961931; x=1737566731; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9HYJB0bgtbTOpoerPY9z51D+wj9so15vlFQsgiuWCBU=; b=PxvjYq5qEFvlpBPt5Kxm9SWY8sv+tW5Yophd7cLWKXu4kOSapWBoI8bZRQ7Npvttjs +w0mhM5vhuy+9KHKQgebkTsDdg4GomR/3cAqc0/7onDAnUPi6hTZLYTxSe0qW1aS/wM8 2Ms6FnExFxB2nY/mQVkyVJ3/B9gSvDrBvjaoDr1G5JE0esx21uA/+QJBXD82htRgKWsP KzbBy8wqkApVn1bYlhCVuClBAyif5osqHVGbScNWxs8TyeyJ3ZNydydLUZlDGZ6Iluq+ 7DeapaCf37BKVq961jZEA/bZCNbjo334Tg87/HuShiM3lL2gk4w7SSyoCUYLFj54jQPI ucfA== X-Forwarded-Encrypted: i=1; AJvYcCW/zQxXHugBtlTL6Z5XH0NGoUQZJcN0jWwTDtbeHYfvXAe+sXx7Nwswx/0ZyOrgxWAC9DXojovy5mPEsrQ=@vger.kernel.org, AJvYcCWFcajDiAnVqv3BR8mzSL5jreOwD9BpGH31VzLzaHiBIbf32iAMUilB2hCvw8saw/LFx8/FPFLA@vger.kernel.org X-Gm-Message-State: AOJu0Yz411F+ZrHKs/8jHMN99eaDPrEakHvNZFkVXt9n65aL4n9xTqXk iAAjK3uwyBd1OiDAdZNJXbdgOmAIjumcRb0D+FDqW3xgaKBNHiKC X-Gm-Gg: ASbGncvkJgrkszlsemvWfd7428wRGjuyidjSYOwnNAcH9EYfj0tSk9vNkiNLM36n4gm A1mCvd5BgGAno00yHjFGd4GdWKQNAEapUQ+6LS3/+rZIxO04ApJ0lTNYCQp6tmIdHg5c/dqCJSp O2Kn1Fn2/RFcqNTEfzUrJAImyc3+DFZUevET9c+o6RwPkwsYxfbJpV+o6JsstCmu5o9G+iL7tjy qYXQGBczNBc+VNtJ7Qk6+OniSjh+KcbTqWszOiYv1VcW6/IKEqR3CDirRGqNp+HHQe4HQ49v3ta d8lRBcmQySymkU230Z73OwmRUSZ+MF0GfUQKXcgPQoEdcEvQpPSE X-Google-Smtp-Source: AGHT+IFhReerzg0C0GMOuDmee4BEEqa7ojvFKpwemJ7g9blemjVU9cqitdDPgbWYVTUhloDx1iqr8Q== X-Received: by 2002:a05:6512:1188:b0:540:1a0c:9bac with SMTP id 2adb3069b0e04-542845d61d7mr10635824e87.34.1736961931138; Wed, 15 Jan 2025 09:25:31 -0800 (PST) Received: from razdolb.local (static.248.157.217.95.clients.your-server.de. [95.217.157.248]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5428bea6778sm2105360e87.131.2025.01.15.09.25.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2025 09:25:30 -0800 (PST) From: Mikhail Rudenko Date: Wed, 15 Jan 2025 20:25:05 +0300 Subject: [PATCH v2 1/2] media: videobuf2: Fix dmabuf cache sync/flush in dma-contig Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250115-b4-rkisp-noncoherent-v2-1-0853e1a24012@gmail.com> References: <20250115-b4-rkisp-noncoherent-v2-0-0853e1a24012@gmail.com> In-Reply-To: <20250115-b4-rkisp-noncoherent-v2-0-0853e1a24012@gmail.com> To: Dafna Hirschfeld , Laurent Pinchart , Mauro Carvalho Chehab , Heiko Stuebner , Tomasz Figa , Marek Szyprowski , Hans Verkuil , Sergey Senozhatsky Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mauro Carvalho Chehab , Mikhail Rudenko , stable@vger.kernel.org X-Mailer: b4 0.14.2 When support for V4L2_FLAG_MEMORY_NON_CONSISTENT was removed in commit 129134e5415d ("media: media/v4l2: remove V4L2_FLAG_MEMORY_NON_CONSISTENT flag"), vb2_dc_dmabuf_ops_{begin,end}_cpu_access() functions were made no-ops. Later, when support for V4L2_MEMORY_FLAG_NON_COHERENT was introduced in commit c0acf9cfeee0 ("media: videobuf2: handle V4L2_MEMORY_FLAG_NON_COHERENT flag"), the above functions remained no-ops, making cache maintenance for non-coherent dmabufs allocated by dma-contig impossible. Fix this by reintroducing dma_sync_sg_for_{cpu,device} calls to vb2_dc_dmabuf_ops_{begin,end}_cpu_access() functions for non-coherent buffers. Fixes: c0acf9cfeee0 ("media: videobuf2: handle V4L2_MEMORY_FLAG_NON_COHERENT flag") Cc: stable@vger.kernel.org Signed-off-by: Mikhail Rudenko --- drivers/media/common/videobuf2/videobuf2-dma-contig.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/media/common/videobuf2/videobuf2-dma-contig.c b/drivers/media/common/videobuf2/videobuf2-dma-contig.c index bb0b7fa67b539aa73ad5ccf3c3bc318e26f8a4cb..889d6c11e15ab5cd4b4c317e865f1fef92df4b66 100644 --- a/drivers/media/common/videobuf2/videobuf2-dma-contig.c +++ b/drivers/media/common/videobuf2/videobuf2-dma-contig.c @@ -427,6 +427,13 @@ static int vb2_dc_dmabuf_ops_begin_cpu_access(struct dma_buf *dbuf, enum dma_data_direction direction) { + struct vb2_dc_buf *buf = dbuf->priv; + struct sg_table *sgt = buf->dma_sgt; + + if (!buf->non_coherent_mem || buf->vb->skip_cache_sync_on_finish) + return 0; + + dma_sync_sg_for_cpu(buf->dev, sgt->sgl, sgt->nents, buf->dma_dir); return 0; } @@ -434,6 +441,13 @@ static int vb2_dc_dmabuf_ops_end_cpu_access(struct dma_buf *dbuf, enum dma_data_direction direction) { + struct vb2_dc_buf *buf = dbuf->priv; + struct sg_table *sgt = buf->dma_sgt; + + if (!buf->non_coherent_mem || buf->vb->skip_cache_sync_on_prepare) + return 0; + + dma_sync_sg_for_device(buf->dev, sgt->sgl, sgt->nents, buf->dma_dir); return 0; } From patchwork Wed Jan 15 17:25:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 13940685 Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8AF2E1D47D9; Wed, 15 Jan 2025 17:25:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736961937; cv=none; b=nmuZ79L5lszbQItmWqeN3/s7mJRC9Wf3qqvYEPqQHR7mGEzAESVY/mh+4CzRpPQIg4uyGbLiazf82T1STn+QnlKhVqO4f8WYcm1/iC7whDTPPmpjkb1EnDPSEXGzIOKnQe1iixPEqqd8uIQfGuTs76hPlD9VU1Hr5brsKEEU4TY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736961937; c=relaxed/simple; bh=yqiH8zQa4ElqkkjmIJW5m3RfF/o4uD61OfV0gG8rgTM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MDpZC4fjSIT3Ib7aqR5CneNTnT2u/+eWeBDPi27tbX9HxYKJQ8yAirkewx62XpFV9WcLetxdY901U+OKGyIYlHTyLWk2ZK1Zb5A4PWxyV08aVQyckOhR/7tu29VxmLlX4s0+RsC77HazU49vKC+Lo9RGEdL9YTL/5za/i91uDs4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RibZaNXg; arc=none smtp.client-ip=209.85.167.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RibZaNXg" Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-53f22fd6832so30252e87.1; Wed, 15 Jan 2025 09:25:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736961934; x=1737566734; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=UOk1tpd1Scx8u9ygptTnBU+QUAeBmZsMjmcHaDde8t4=; b=RibZaNXg+arYzlQ4HPARuv5XPoMWk6G7HunxXKLMcqEDfq7KlOy6h3tsGcjlscMWhu wrQy/A5YaxgObGBlHUp4NimM3Zw65d89W0rliPuCciqpcNSAqOXyq3xy9IwKGy7L4vk9 iEybdufG4dcn3H8ghhDuZczzw5p8TEb8hemKmK8tje/uE9He3h59ZfDB/SBNPGGpYhaP J/AHDEa6H0hmHk+5bfv6mH8VbiWB9Drt1rY9lEe7uRJj41EEOae4OyzM8BlibjjGx61N +XsOBUdolw+V321/U4F86n0aiVdi8R8MVu2i8xuJjIMfFQ57JY34ijSSEncvjMrpXGe+ nw6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736961934; x=1737566734; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UOk1tpd1Scx8u9ygptTnBU+QUAeBmZsMjmcHaDde8t4=; b=QwSvbEBGcwIJDv8/lHuekAY7h9RKEAgw1Nl+dc0ewYvH/0bQIUqSLdE8Om4UuNCcMh kGQIouoTAkj+U6LkA+hqID9wFJ2loU6CPICI8NzIgTo6e2kCvmM943nzSM9vXWhuJiBx ZIjWs8iBnDQhO/a6ql2uVNEAQk3vrGF5y+dqJ4DVJrsywbKvHoHu+L0W9bazP8r5MWtX hjoIpJU+1QSwFMhpyqj1ViXOgCY+5ArJKmvjjaQWFl9nzDFHH9XvD5z5Gcu7Xrvd9XMs NLzNgPPI4vUtOEF1Uvr5Le9N+cG/0fSR9Yt1iiCOgu8Tm78LlI0cPQDIe3hk0eukEtFf rhPg== X-Forwarded-Encrypted: i=1; AJvYcCXmiDQ0dT8f6A2xBivDLhNQOmU3jj5ph0dsz1DHobACY3sB8ioBYvn0tzwhV82I0hON2xpTQwJr5jZmUuY=@vger.kernel.org X-Gm-Message-State: AOJu0YzcImbK6/dG1zBpVt0n7BCJdGNkOqLchEXRKzbKoboVJi5xhi4z NrAjIuwaiuCJsvkQWTXGqDedxNOIJVBcavAnlsf/Y7zImDCp0uRv X-Gm-Gg: ASbGncsB4FsrM3GlYkB/QBRpKIqMNmoK17QlGUCB3HXNfI8Zi1Q8+xPGCXu330JTYTF 9tfZZ7uejb4wjLCKZmRqsAcBQi6+TQpsNzd5e3VpstNAq7r/x4z+vXklW91ysMrN6vGa2LM54z3 07hGS0vk7I1n0R3Zt273DMp1uw4P3Q+9+zTKQ1aGTHYcGSzlBbZMCOAM1c5TcXKGPAtG9FkNjLJ n6Ok/2eDL5csp1K2ef5f5RJ3vRmVuLQGBfNvtj5L4hqbT6UAXkiVpeDUSLhSnzsqbwWGRj6/L7b ULq8407YU+Zgt7cMvwNVkR87Lw21k7/Gu8/EAiN8JH1XbkD599rh X-Google-Smtp-Source: AGHT+IFFOoCcSAzA0wB433xlaBd40KuCCYr+BuGWAMVyMEtJFz3DrRjgISJriqbitaXGlv5UNa4Zlw== X-Received: by 2002:a05:6512:138d:b0:540:23dd:2139 with SMTP id 2adb3069b0e04-542845d322dmr7884243e87.29.1736961933312; Wed, 15 Jan 2025 09:25:33 -0800 (PST) Received: from razdolb.local (static.248.157.217.95.clients.your-server.de. [95.217.157.248]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5428bea6778sm2105360e87.131.2025.01.15.09.25.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2025 09:25:32 -0800 (PST) From: Mikhail Rudenko Date: Wed, 15 Jan 2025 20:25:06 +0300 Subject: [PATCH v2 2/2] media: rkisp1: Allow non-coherent video capture buffers Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250115-b4-rkisp-noncoherent-v2-2-0853e1a24012@gmail.com> References: <20250115-b4-rkisp-noncoherent-v2-0-0853e1a24012@gmail.com> In-Reply-To: <20250115-b4-rkisp-noncoherent-v2-0-0853e1a24012@gmail.com> To: Dafna Hirschfeld , Laurent Pinchart , Mauro Carvalho Chehab , Heiko Stuebner , Tomasz Figa , Marek Szyprowski , Hans Verkuil , Sergey Senozhatsky Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mauro Carvalho Chehab , Mikhail Rudenko X-Mailer: b4 0.14.2 Currently, the rkisp1 driver always uses coherent DMA allocations for video capture buffers. However, on some platforms, using non-coherent buffers can improve performance, especially when CPU processing of MMAP'ed video buffers is required. For example, on the Rockchip RK3399 running at maximum CPU frequency, the time to memcpy a frame from a 1280x720 XRGB32 MMAP'ed buffer to a malloc'ed userspace buffer decreases from 7.7 ms to 1.1 ms when using non-coherent DMA allocation. When doing cache management with DMA_BUF_IOCTL_SYNC, DMA_BUF_SYNC_START and DMA_BUF_SYNC_END operations take around 270 us each. This change allows userspace to request the allocation of non-coherent buffers. Note that the behavior for existing users will remain unchanged unless they explicitly set the V4L2_MEMORY_FLAG_NON_COHERENT flag when allocating buffers. Signed-off-by: Mikhail Rudenko --- drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c index 6dcefd144d5abe358323e37ac6133c6134ac636e..c94f7d1d73a92646457a27da20726ec6f92e7717 100644 --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c @@ -1563,6 +1563,7 @@ static int rkisp1_register_capture(struct rkisp1_capture *cap) q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; q->lock = &node->vlock; q->dev = cap->rkisp1->dev; + q->allow_cache_hints = 1; ret = vb2_queue_init(q); if (ret) { dev_err(cap->rkisp1->dev,