From patchwork Sat Jan 6 16:02:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 185654 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:37c1:b0:101:2151:f287 with SMTP id y1csp176051dyq; Sat, 6 Jan 2024 08:06:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IF83YcWaeW3UgT12K3vK4OQTS7K0Q4nHyaYUr/U0So6ZQ2Ggvln9Ica9hDiHl5BHJYpPf2J X-Received: by 2002:a05:6e02:2165:b0:35f:ee15:688d with SMTP id s5-20020a056e02216500b0035fee15688dmr2064001ilv.104.1704557216975; Sat, 06 Jan 2024 08:06:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704557216; cv=none; d=google.com; s=arc-20160816; b=HX4NGCKoAgRT3OOxtTdJ4hw64Pu1ktYnU7uqQ99HWgnZFiiYAcxDuFvlY8gO1VG4SL cnBm9c7CCUJW5cu1hZHfQBJ5Ts6nueu8MN3fELLYSOR8nWCwJACFjkFH8dtFHNgIUyqB SHAuJ28g6olr8mvtsqWdDJE8d7m6AGVZMUGKn5qgyFRuO4DkpXt3zvHQIPfW/udusNag JjEABW3SF8rpS0J7J7BrGAR4WJ1i6iOcJfs6t8uu9ZF9SQe2X6lwQaMiN8K6CIdygASP PE1Y3IqgwAWGUQQl39uc1+FbwqkNqiPKdR4JRMpCA520FodbFHe3OCL62Kgl0qiuGX7c geJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=5UJ/dTPBuI4q27INQwzffO+Na++1xDF94SW3cWcmLoU=; fh=umSzPHAeNmSBhpDl7Ba4ElbET6cYzKRFPeRC9WGHErc=; b=t8i+4DpQttIM3q4Y23zk42uODIHytZakqrkxGVsCr4XI0Fy44alAZpLRaXnCoFgkcU qHVVvetbIZVxsZpPdf+9NrPBrhWo2u8cVAWzSkNcrgxys7iQtKFA4RAtkKs8vFGTptjV mhUIPzptegFWXLLMrtEBKmmjx7ixUGzLG2p7T+1ddUcXLxUyJY4OM98maleIGid8xB8l ER4IL+iu0THioRKer304hj1kMFJytAbhSsdrsEtHcewwfMi2Fz3bOrlP1NVAjF7W/azG z1847iRV/Nq/fLWgPp1SkFaw/DU/d2HnLESqcVzKd1SvhpUe7PFQCZpW4QXnrAOgO2gX RCtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b="AguXs/TP"; spf=pass (google.com: domain of linux-kernel+bounces-18647-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18647-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id q25-20020a656859000000b005cdf7e9debasi3113821pgt.522.2024.01.06.08.06.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jan 2024 08:06:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-18647-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b="AguXs/TP"; spf=pass (google.com: domain of linux-kernel+bounces-18647-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18647-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id AC12A281B39 for ; Sat, 6 Jan 2024 16:06:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7D1972941B; Sat, 6 Jan 2024 16:03:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="AguXs/TP" X-Original-To: linux-kernel@vger.kernel.org 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 3E29028DB0; Sat, 6 Jan 2024 16:03:43 +0000 (UTC) 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 Received: from pyrite.hamster-moth.ts.net (unknown [IPv6:2001:268:c203:a8ee:6c57:4243:1eb3:6cb]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 40A6F12E4; Sat, 6 Jan 2024 17:02:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1704556959; bh=GZ3mG3aZZi9UhDy5rVEhWkfre+iLzRpRP+lojR1SgpI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AguXs/TPUZJ138/RYNu8wuiY04Vq9bO7OJNqdMC+p+IRSoBfKyJcZYXF0cNgAPpPI q5qHaL0hDD1TgKDRCihjvE9g2+kWo/3Q5y/crRpmkUQL04onoOaPF8lSndGKR8KJe+ 2hvNWNPJ3d6ftqXuBksxOD7PNmg/I5p0sPR+C7Rg= From: Paul Elder To: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, devicetree@vger.kernel.org Cc: kieran.bingham@ideasonboard.com, tomi.valkeinen@ideasonboard.com, umang.jain@ideasonboard.com, aford173@gmail.com, Paul Elder , Laurent Pinchart , Alexander Stein , Dafna Hirschfeld , Mauro Carvalho Chehab , Heiko Stuebner , linux-arm-kernel@lists.infradead.org (moderated list:ARM/Rockchip SoC support), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v5 08/10] media: rkisp1: Shift DMA buffer addresses on i.MX8MP Date: Sun, 7 Jan 2024 01:02:19 +0900 Message-Id: <20240106160221.4183409-9-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240106160221.4183409-1-paul.elder@ideasonboard.com> References: <20240106160221.4183409-1-paul.elder@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787357788381012737 X-GMAIL-MSGID: 1787357788381012737 On the ISP that is integrated in the i.MX8MP, DMA addresses have been extended to 34 bits, with the 32 MSBs stored in the DMA address registers and the 2 LSBs set to 0. Shift the buffer addresses right by 2 on that platform. While at it, fix an issue where if the system allocated CMA memory happens to be located higher than 32-bits, the driver will fail to allocate CMA memory and falls back to kmalloc(), which will fail for larger allocations (over MAX_ORDER, which often mean 4MB). Fix this by setting the dma mask to 34 bits when allowed, and fixing the use dma_addr_t when storing dma addresses instead of u32. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart Signed-off-by: Tomi Valkeinen Tested-by: Alexander Stein Tested-by: Adam Ford Reviewed-by: Tomi Valkeinen Reviewed-by: Tomi Valkeinen --- Changes since v4: - Squash in fix from Tomi: - https://gitlab.com/ideasonboard/nxp/linux/-/commit/d6477fe673b1c0d05d12ae21d8db9a03b07e7fea Changes since v2: - Document the RKISP1_FEATURE_DMA_34BIT bit - Use the rkisp1_has_feature() macro --- .../platform/rockchip/rkisp1/rkisp1-capture.c | 20 ++++++++++--------- .../platform/rockchip/rkisp1/rkisp1-common.h | 4 +++- .../platform/rockchip/rkisp1/rkisp1-dev.c | 11 +++++++++- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c index ca95f62822fa..1ee7639c42b7 100644 --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c @@ -648,11 +648,13 @@ static void rkisp1_dummy_buf_destroy(struct rkisp1_capture *cap) static void rkisp1_set_next_buf(struct rkisp1_capture *cap) { + u8 shift = rkisp1_has_feature(cap->rkisp1, DMA_34BIT) ? 2 : 0; + cap->buf.curr = cap->buf.next; cap->buf.next = NULL; if (!list_empty(&cap->buf.queue)) { - u32 *buff_addr; + dma_addr_t *buff_addr; cap->buf.next = list_first_entry(&cap->buf.queue, struct rkisp1_buffer, queue); list_del(&cap->buf.next->queue); @@ -660,7 +662,7 @@ static void rkisp1_set_next_buf(struct rkisp1_capture *cap) buff_addr = cap->buf.next->buff_addr; rkisp1_write(cap->rkisp1, cap->config->mi.y_base_ad_init, - buff_addr[RKISP1_PLANE_Y]); + buff_addr[RKISP1_PLANE_Y] >> shift); /* * In order to support grey format we capture * YUV422 planar format from the camera and @@ -669,17 +671,17 @@ static void rkisp1_set_next_buf(struct rkisp1_capture *cap) if (cap->pix.cfg->fourcc == V4L2_PIX_FMT_GREY) { rkisp1_write(cap->rkisp1, cap->config->mi.cb_base_ad_init, - cap->buf.dummy.dma_addr); + cap->buf.dummy.dma_addr >> shift); rkisp1_write(cap->rkisp1, cap->config->mi.cr_base_ad_init, - cap->buf.dummy.dma_addr); + cap->buf.dummy.dma_addr >> shift); } else { rkisp1_write(cap->rkisp1, cap->config->mi.cb_base_ad_init, - buff_addr[RKISP1_PLANE_CB]); + buff_addr[RKISP1_PLANE_CB] >> shift); rkisp1_write(cap->rkisp1, cap->config->mi.cr_base_ad_init, - buff_addr[RKISP1_PLANE_CR]); + buff_addr[RKISP1_PLANE_CR] >> shift); } } else { /* @@ -687,11 +689,11 @@ static void rkisp1_set_next_buf(struct rkisp1_capture *cap) * throw data if there is no available buffer. */ rkisp1_write(cap->rkisp1, cap->config->mi.y_base_ad_init, - cap->buf.dummy.dma_addr); + cap->buf.dummy.dma_addr >> shift); rkisp1_write(cap->rkisp1, cap->config->mi.cb_base_ad_init, - cap->buf.dummy.dma_addr); + cap->buf.dummy.dma_addr >> shift); rkisp1_write(cap->rkisp1, cap->config->mi.cr_base_ad_init, - cap->buf.dummy.dma_addr); + cap->buf.dummy.dma_addr >> shift); } /* Set plane offsets */ diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h b/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h index 69940014d597..26573f6ae575 100644 --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h @@ -114,6 +114,7 @@ enum rkisp1_isp_pad { * @RKISP1_FEATURE_MAIN_STRIDE: The ISP supports configurable stride on the main path * @RKISP1_FEATURE_SELF_PATH: The ISP has a self path * @RKISP1_FEATURE_DUAL_CROP: The ISP has the dual crop block at the resizer input + * @RKISP1_FEATURE_DMA_34BIT: The ISP uses 34-bit DMA addresses * * The ISP features are stored in a bitmask in &rkisp1_info.features and allow * the driver to implement support for features present in some ISP versions @@ -124,6 +125,7 @@ enum rkisp1_feature { RKISP1_FEATURE_MAIN_STRIDE = BIT(1), RKISP1_FEATURE_SELF_PATH = BIT(2), RKISP1_FEATURE_DUAL_CROP = BIT(3), + RKISP1_FEATURE_DMA_34BIT = BIT(4), }; #define rkisp1_has_feature(rkisp1, feature) \ @@ -239,7 +241,7 @@ struct rkisp1_vdev_node { struct rkisp1_buffer { struct vb2_v4l2_buffer vb; struct list_head queue; - u32 buff_addr[VIDEO_MAX_PLANES]; + dma_addr_t buff_addr[VIDEO_MAX_PLANES]; }; /* diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c index 01f811b9f9a5..fd99355d5fe0 100644 --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c @@ -549,7 +549,8 @@ static const struct rkisp1_info imx8mp_isp_info = { .isrs = imx8mp_isp_isrs, .isr_size = ARRAY_SIZE(imx8mp_isp_isrs), .isp_ver = IMX8MP_V10, - .features = RKISP1_FEATURE_MAIN_STRIDE, + .features = RKISP1_FEATURE_MAIN_STRIDE + | RKISP1_FEATURE_DMA_34BIT, }; static const struct of_device_id rkisp1_of_match[] = { @@ -575,6 +576,7 @@ static int rkisp1_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct rkisp1_device *rkisp1; struct v4l2_device *v4l2_dev; + unsigned long long dma_mask; unsigned int i; int ret, irq; u32 cif_id; @@ -589,6 +591,13 @@ static int rkisp1_probe(struct platform_device *pdev) dev_set_drvdata(dev, rkisp1); rkisp1->dev = dev; + dma_mask = rkisp1_has_feature(rkisp1, DMA_34BIT) ? DMA_BIT_MASK(34) : + DMA_BIT_MASK(32); + + ret = dma_set_mask_and_coherent(dev, dma_mask); + if (ret) + return ret; + mutex_init(&rkisp1->stream_lock); rkisp1->base_addr = devm_platform_ioremap_resource(pdev, 0);