From patchwork Fri Aug 14 16:30:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 11714769 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 904BA1744 for ; Fri, 14 Aug 2020 16:30:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 74CCA208B3 for ; Fri, 14 Aug 2020 16:30:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728147AbgHNQaV (ORCPT ); Fri, 14 Aug 2020 12:30:21 -0400 Received: from mga12.intel.com ([192.55.52.136]:2838 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728079AbgHNQaV (ORCPT ); Fri, 14 Aug 2020 12:30:21 -0400 IronPort-SDR: Ov5Ve5+PVdgL7ZEe0161diwcNHHuWyXYtH2wh/Hmwx94615F8br2zqCAicrIV2DLhBq0SQuZEH mihuLFnVY+/g== X-IronPort-AV: E=McAfee;i="6000,8403,9713"; a="133964974" X-IronPort-AV: E=Sophos;i="5.76,312,1592895600"; d="scan'208";a="133964974" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Aug 2020 09:30:20 -0700 IronPort-SDR: qDStCq5sQ9k+J7f8i9tXCawKkML4+Q4p0fyqGB3+2s1tOGw3/qjxTM0dPaOEd1tbmpVlVoGNkd D1Qk+uu3WGsQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,312,1592895600"; d="scan'208";a="440159479" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga004.jf.intel.com with ESMTP; 14 Aug 2020 09:30:18 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id EEA5B190; Fri, 14 Aug 2020 19:30:17 +0300 (EEST) From: Andy Shevchenko To: Yong Zhi , Sakari Ailus , Bingbu Cao , Tian Shu Qiu , linux-media@vger.kernel.org, Mauro Carvalho Chehab Cc: Andy Shevchenko Subject: [PATCH v1 1/7] media: ipu3-cio2: Simplify cleanup code Date: Fri, 14 Aug 2020 19:30:11 +0300 Message-Id: <20200814163017.35001-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The code looks more nicer if we use: while (i--) instead: for (i = i - 1; i >= 0; i--) Signed-off-by: Andy Shevchenko --- drivers/media/pci/intel/ipu3/ipu3-cio2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.c b/drivers/media/pci/intel/ipu3/ipu3-cio2.c index 92f5eadf2c99..c7c3692a6e72 100644 --- a/drivers/media/pci/intel/ipu3/ipu3-cio2.c +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.c @@ -887,7 +887,7 @@ static int cio2_vb2_buf_init(struct vb2_buffer *vb) b->lop[i][j] = cio2->dummy_page_bus_addr >> PAGE_SHIFT; return 0; fail: - for (i--; i >= 0; i--) + while (i--) dma_free_coherent(dev, CIO2_PAGE_SIZE, b->lop[i], b->lop_bus_addr[i]); return -ENOMEM; From patchwork Fri Aug 14 16:30:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 11714773 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 96E2916B1 for ; Fri, 14 Aug 2020 16:30:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8788C21744 for ; Fri, 14 Aug 2020 16:30:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728320AbgHNQaX (ORCPT ); Fri, 14 Aug 2020 12:30:23 -0400 Received: from mga18.intel.com ([134.134.136.126]:29792 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728099AbgHNQaV (ORCPT ); Fri, 14 Aug 2020 12:30:21 -0400 IronPort-SDR: 1+q73f4BRec9NcpDDTViyUDP3a3XTKS3V9bcXQGA28w0njih/Kw/Ac40u7b7UD1+NS6GVNFy2R zUAZFb3V7OXg== X-IronPort-AV: E=McAfee;i="6000,8403,9713"; a="142064534" X-IronPort-AV: E=Sophos;i="5.76,312,1592895600"; d="scan'208";a="142064534" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Aug 2020 09:30:21 -0700 IronPort-SDR: 98qXiqtJdLVob08IzdfRw+yTlTzQUpKbAEK7rL4UCmcvMzq4x/iRC/gdeYFDRYV4RT9Ol4l4Ro 1F04kBwAqNIQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,312,1592895600"; d="scan'208";a="399505047" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 14 Aug 2020 09:30:19 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 0290915D; Fri, 14 Aug 2020 19:30:17 +0300 (EEST) From: Andy Shevchenko To: Yong Zhi , Sakari Ailus , Bingbu Cao , Tian Shu Qiu , linux-media@vger.kernel.org, Mauro Carvalho Chehab Cc: Andy Shevchenko Subject: [PATCH v1 2/7] media: ipu3-cio2: Introduce CIO2_MAX_ENTRIES constant Date: Fri, 14 Aug 2020 19:30:12 +0300 Message-Id: <20200814163017.35001-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200814163017.35001-1-andriy.shevchenko@linux.intel.com> References: <20200814163017.35001-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org This constant is used in several places in the code, define it for better maintenance. Signed-off-by: Andy Shevchenko --- drivers/media/pci/intel/ipu3/ipu3-cio2.c | 13 +++++-------- drivers/media/pci/intel/ipu3/ipu3-cio2.h | 3 +++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.c b/drivers/media/pci/intel/ipu3/ipu3-cio2.c index c7c3692a6e72..79641c79df25 100644 --- a/drivers/media/pci/intel/ipu3/ipu3-cio2.c +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.c @@ -127,7 +127,7 @@ static int cio2_fbpt_init_dummy(struct cio2_device *cio2) * List of Pointers(LOP) contains 1024x32b pointers to 4KB page each * Initialize each entry to dummy_page bus base address. */ - for (i = 0; i < CIO2_PAGE_SIZE / sizeof(*cio2->dummy_lop); i++) + for (i = 0; i < CIO2_MAX_ENTRIES; i++) cio2->dummy_lop[i] = cio2->dummy_page_bus_addr >> PAGE_SHIFT; return 0; @@ -160,8 +160,7 @@ static void cio2_fbpt_entry_init_dummy(struct cio2_device *cio2, unsigned int i; entry[0].first_entry.first_page_offset = 0; - entry[1].second_entry.num_of_pages = - CIO2_PAGE_SIZE / sizeof(u32) * CIO2_MAX_LOPS; + entry[1].second_entry.num_of_pages = CIO2_MAX_ENTRIES * CIO2_MAX_LOPS; entry[1].second_entry.last_page_available_bytes = CIO2_PAGE_SIZE - 1; for (i = 0; i < CIO2_MAX_LOPS; i++) @@ -201,7 +200,7 @@ static void cio2_fbpt_entry_init_buf(struct cio2_device *cio2, i = 0; while (remaining > 0) { entry->lop_page_addr = b->lop_bus_addr[i] >> PAGE_SHIFT; - remaining -= CIO2_PAGE_SIZE / sizeof(u32) * CIO2_PAGE_SIZE; + remaining -= CIO2_MAX_ENTRIES * CIO2_PAGE_SIZE; entry++; i++; } @@ -841,10 +840,8 @@ static int cio2_vb2_buf_init(struct vb2_buffer *vb) struct device *dev = &cio2->pci_dev->dev; struct cio2_buffer *b = container_of(vb, struct cio2_buffer, vbb.vb2_buf); - static const unsigned int entries_per_page = - CIO2_PAGE_SIZE / sizeof(u32); unsigned int pages = DIV_ROUND_UP(vb->planes[0].length, CIO2_PAGE_SIZE); - unsigned int lops = DIV_ROUND_UP(pages + 1, entries_per_page); + unsigned int lops = DIV_ROUND_UP(pages + 1, CIO2_MAX_ENTRIES); struct sg_table *sg; struct sg_dma_page_iter sg_iter; int i, j; @@ -878,7 +875,7 @@ static int cio2_vb2_buf_init(struct vb2_buffer *vb) break; b->lop[i][j] = sg_page_iter_dma_address(&sg_iter) >> PAGE_SHIFT; j++; - if (j == entries_per_page) { + if (j == CIO2_MAX_ENTRIES) { i++; j = 0; } diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.h b/drivers/media/pci/intel/ipu3/ipu3-cio2.h index 7caab9b8c2b9..6ee5919d913b 100644 --- a/drivers/media/pci/intel/ipu3/ipu3-cio2.h +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.h @@ -4,6 +4,8 @@ #ifndef __IPU3_CIO2_H #define __IPU3_CIO2_H +#include + #define CIO2_NAME "ipu3-cio2" #define CIO2_DEVICE_NAME "Intel IPU3 CIO2" #define CIO2_ENTITY_NAME "ipu3-csi2" @@ -17,6 +19,7 @@ /* 32MB = 8xFBPT_entry */ #define CIO2_MAX_LOPS 8 #define CIO2_MAX_BUFFERS (PAGE_SIZE / 16 / CIO2_MAX_LOPS) +#define CIO2_MAX_ENTRIES (PAGE_SIZE / sizeof(u32)) #define CIO2_PAD_SINK 0 #define CIO2_PAD_SOURCE 1 From patchwork Fri Aug 14 16:30:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 11714775 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 518CC16B1 for ; Fri, 14 Aug 2020 16:30:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4250121744 for ; Fri, 14 Aug 2020 16:30:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728357AbgHNQaX (ORCPT ); Fri, 14 Aug 2020 12:30:23 -0400 Received: from mga07.intel.com ([134.134.136.100]:51896 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728129AbgHNQaW (ORCPT ); Fri, 14 Aug 2020 12:30:22 -0400 IronPort-SDR: DEdUW7s4bTzztoLzIyOy/1QtgE9CnAllhVdJ7gZ/OSvFi9L8ui5ofRIV48bTOaEfLp//FkJ5jJ OZ7p52TxrfJw== X-IronPort-AV: E=McAfee;i="6000,8403,9713"; a="218773598" X-IronPort-AV: E=Sophos;i="5.76,312,1592895600"; d="scan'208";a="218773598" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Aug 2020 09:30:20 -0700 IronPort-SDR: phxODpmJ3uvWQU7SsnnggSLX/hKLy1tepTCV1SAmWNu0P3KJSMMNk83FfBHAncO/vZmDfb1e8d uLA63SYTipeg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,312,1592895600"; d="scan'208";a="369941447" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga001.jf.intel.com with ESMTP; 14 Aug 2020 09:30:18 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 15F9136B; Fri, 14 Aug 2020 19:30:18 +0300 (EEST) From: Andy Shevchenko To: Yong Zhi , Sakari Ailus , Bingbu Cao , Tian Shu Qiu , linux-media@vger.kernel.org, Mauro Carvalho Chehab Cc: Andy Shevchenko Subject: [PATCH v1 3/7] media: ipu2-cio2: Replace custom definition with PAGE_SIZE Date: Fri, 14 Aug 2020 19:30:13 +0300 Message-Id: <20200814163017.35001-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200814163017.35001-1-andriy.shevchenko@linux.intel.com> References: <20200814163017.35001-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org It's quite unlikely the other page size will be supported, but in any case there is still an inconsistency between custom page size definition and generic macros used in the driver. Switch over to generic PAGE_SIZE for sake of the consistency. Signed-off-by: Andy Shevchenko --- drivers/media/pci/intel/ipu3/ipu3-cio2.c | 29 +++++++++++------------- drivers/media/pci/intel/ipu3/ipu3-cio2.h | 1 - 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.c b/drivers/media/pci/intel/ipu3/ipu3-cio2.c index 79641c79df25..2b3a865fa2da 100644 --- a/drivers/media/pci/intel/ipu3/ipu3-cio2.c +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.c @@ -96,12 +96,12 @@ static inline u32 cio2_bytesperline(const unsigned int width) static void cio2_fbpt_exit_dummy(struct cio2_device *cio2) { if (cio2->dummy_lop) { - dma_free_coherent(&cio2->pci_dev->dev, CIO2_PAGE_SIZE, + dma_free_coherent(&cio2->pci_dev->dev, PAGE_SIZE, cio2->dummy_lop, cio2->dummy_lop_bus_addr); cio2->dummy_lop = NULL; } if (cio2->dummy_page) { - dma_free_coherent(&cio2->pci_dev->dev, CIO2_PAGE_SIZE, + dma_free_coherent(&cio2->pci_dev->dev, PAGE_SIZE, cio2->dummy_page, cio2->dummy_page_bus_addr); cio2->dummy_page = NULL; } @@ -111,12 +111,10 @@ static int cio2_fbpt_init_dummy(struct cio2_device *cio2) { unsigned int i; - cio2->dummy_page = dma_alloc_coherent(&cio2->pci_dev->dev, - CIO2_PAGE_SIZE, + cio2->dummy_page = dma_alloc_coherent(&cio2->pci_dev->dev, PAGE_SIZE, &cio2->dummy_page_bus_addr, GFP_KERNEL); - cio2->dummy_lop = dma_alloc_coherent(&cio2->pci_dev->dev, - CIO2_PAGE_SIZE, + cio2->dummy_lop = dma_alloc_coherent(&cio2->pci_dev->dev, PAGE_SIZE, &cio2->dummy_lop_bus_addr, GFP_KERNEL); if (!cio2->dummy_page || !cio2->dummy_lop) { @@ -161,7 +159,7 @@ static void cio2_fbpt_entry_init_dummy(struct cio2_device *cio2, entry[0].first_entry.first_page_offset = 0; entry[1].second_entry.num_of_pages = CIO2_MAX_ENTRIES * CIO2_MAX_LOPS; - entry[1].second_entry.last_page_available_bytes = CIO2_PAGE_SIZE - 1; + entry[1].second_entry.last_page_available_bytes = PAGE_SIZE - 1; for (i = 0; i < CIO2_MAX_LOPS; i++) entry[i].lop_page_addr = cio2->dummy_lop_bus_addr >> PAGE_SHIFT; @@ -182,25 +180,25 @@ static void cio2_fbpt_entry_init_buf(struct cio2_device *cio2, entry[0].first_entry.first_page_offset = b->offset; remaining = length + entry[0].first_entry.first_page_offset; entry[1].second_entry.num_of_pages = - DIV_ROUND_UP(remaining, CIO2_PAGE_SIZE); + DIV_ROUND_UP(remaining, PAGE_SIZE); /* * last_page_available_bytes has the offset of the last byte in the * last page which is still accessible by DMA. DMA cannot access * beyond this point. Valid range for this is from 0 to 4095. * 0 indicates 1st byte in the page is DMA accessible. - * 4095 (CIO2_PAGE_SIZE - 1) means every single byte in the last page + * 4095 (PAGE_SIZE - 1) means every single byte in the last page * is available for DMA transfer. */ entry[1].second_entry.last_page_available_bytes = (remaining & ~PAGE_MASK) ? (remaining & ~PAGE_MASK) - 1 : - CIO2_PAGE_SIZE - 1; + PAGE_SIZE - 1; /* Fill FBPT */ remaining = length; i = 0; while (remaining > 0) { entry->lop_page_addr = b->lop_bus_addr[i] >> PAGE_SHIFT; - remaining -= CIO2_MAX_ENTRIES * CIO2_PAGE_SIZE; + remaining -= CIO2_MAX_ENTRIES * PAGE_SIZE; entry++; i++; } @@ -840,7 +838,7 @@ static int cio2_vb2_buf_init(struct vb2_buffer *vb) struct device *dev = &cio2->pci_dev->dev; struct cio2_buffer *b = container_of(vb, struct cio2_buffer, vbb.vb2_buf); - unsigned int pages = DIV_ROUND_UP(vb->planes[0].length, CIO2_PAGE_SIZE); + unsigned int pages = DIV_ROUND_UP(vb->planes[0].length, PAGE_SIZE); unsigned int lops = DIV_ROUND_UP(pages + 1, CIO2_MAX_ENTRIES); struct sg_table *sg; struct sg_dma_page_iter sg_iter; @@ -855,7 +853,7 @@ static int cio2_vb2_buf_init(struct vb2_buffer *vb) memset(b->lop, 0, sizeof(b->lop)); /* Allocate LOP table */ for (i = 0; i < lops; i++) { - b->lop[i] = dma_alloc_coherent(dev, CIO2_PAGE_SIZE, + b->lop[i] = dma_alloc_coherent(dev, PAGE_SIZE, &b->lop_bus_addr[i], GFP_KERNEL); if (!b->lop[i]) goto fail; @@ -885,8 +883,7 @@ static int cio2_vb2_buf_init(struct vb2_buffer *vb) return 0; fail: while (i--) - dma_free_coherent(dev, CIO2_PAGE_SIZE, - b->lop[i], b->lop_bus_addr[i]); + dma_free_coherent(dev, PAGE_SIZE, b->lop[i], b->lop_bus_addr[i]); return -ENOMEM; } @@ -976,7 +973,7 @@ static void cio2_vb2_buf_cleanup(struct vb2_buffer *vb) /* Free LOP table */ for (i = 0; i < CIO2_MAX_LOPS; i++) { if (b->lop[i]) - dma_free_coherent(&cio2->pci_dev->dev, CIO2_PAGE_SIZE, + dma_free_coherent(&cio2->pci_dev->dev, PAGE_SIZE, b->lop[i], b->lop_bus_addr[i]); } } diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.h b/drivers/media/pci/intel/ipu3/ipu3-cio2.h index 6ee5919d913b..48da6f7eb218 100644 --- a/drivers/media/pci/intel/ipu3/ipu3-cio2.h +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.h @@ -392,7 +392,6 @@ struct cio2_device { sizeof(struct cio2_fbpt_entry)) #define CIO2_FBPT_SUBENTRY_UNIT 4 -#define CIO2_PAGE_SIZE 4096 /* cio2 fbpt first_entry ctrl status */ #define CIO2_FBPT_CTRL_VALID BIT(0) From patchwork Fri Aug 14 16:30:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 11714771 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A4249739 for ; Fri, 14 Aug 2020 16:30:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 96118208B3 for ; Fri, 14 Aug 2020 16:30:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728154AbgHNQaV (ORCPT ); Fri, 14 Aug 2020 12:30:21 -0400 Received: from mga12.intel.com ([192.55.52.136]:2838 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728099AbgHNQaV (ORCPT ); Fri, 14 Aug 2020 12:30:21 -0400 IronPort-SDR: wAXAkx2Mgpd/mPBbOGfHxmfsXUgHOS0gh4ZWO6z6+bIPl+X9KambgxhgTm2hglcieCxNQJo1JD pUVwSg3w8Wsw== X-IronPort-AV: E=McAfee;i="6000,8403,9713"; a="133964975" X-IronPort-AV: E=Sophos;i="5.76,312,1592895600"; d="scan'208";a="133964975" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Aug 2020 09:30:20 -0700 IronPort-SDR: LRq+qjYBpAe5xluv5arX/PvjogF6aRbQcWL0ctefGmJKgq5omjQYXdiFof0OFPP1jW23nW08qd cQkeYzj/l+0A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,313,1592895600"; d="scan'208";a="325768085" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga008.jf.intel.com with ESMTP; 14 Aug 2020 09:30:18 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 1B979348; Fri, 14 Aug 2020 19:30:18 +0300 (EEST) From: Andy Shevchenko To: Yong Zhi , Sakari Ailus , Bingbu Cao , Tian Shu Qiu , linux-media@vger.kernel.org, Mauro Carvalho Chehab Cc: Andy Shevchenko Subject: [PATCH v1 4/7] media: ipu3-cio2: Use macros from pfn.h Date: Fri, 14 Aug 2020 19:30:14 +0300 Message-Id: <20200814163017.35001-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200814163017.35001-1-andriy.shevchenko@linux.intel.com> References: <20200814163017.35001-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org There are few nice macros in pfn.h, some of which we may use here. Signed-off-by: Andy Shevchenko --- drivers/media/pci/intel/ipu3/ipu3-cio2.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.c b/drivers/media/pci/intel/ipu3/ipu3-cio2.c index 2b3a865fa2da..eee7f841050d 100644 --- a/drivers/media/pci/intel/ipu3/ipu3-cio2.c +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -126,7 +127,7 @@ static int cio2_fbpt_init_dummy(struct cio2_device *cio2) * Initialize each entry to dummy_page bus base address. */ for (i = 0; i < CIO2_MAX_ENTRIES; i++) - cio2->dummy_lop[i] = cio2->dummy_page_bus_addr >> PAGE_SHIFT; + cio2->dummy_lop[i] = PFN_DOWN(cio2->dummy_page_bus_addr); return 0; } @@ -162,7 +163,7 @@ static void cio2_fbpt_entry_init_dummy(struct cio2_device *cio2, entry[1].second_entry.last_page_available_bytes = PAGE_SIZE - 1; for (i = 0; i < CIO2_MAX_LOPS; i++) - entry[i].lop_page_addr = cio2->dummy_lop_bus_addr >> PAGE_SHIFT; + entry[i].lop_page_addr = PFN_DOWN(cio2->dummy_lop_bus_addr); cio2_fbpt_entry_enable(cio2, entry); } @@ -179,8 +180,7 @@ static void cio2_fbpt_entry_init_buf(struct cio2_device *cio2, entry[0].first_entry.first_page_offset = b->offset; remaining = length + entry[0].first_entry.first_page_offset; - entry[1].second_entry.num_of_pages = - DIV_ROUND_UP(remaining, PAGE_SIZE); + entry[1].second_entry.num_of_pages = PFN_UP(remaining); /* * last_page_available_bytes has the offset of the last byte in the * last page which is still accessible by DMA. DMA cannot access @@ -197,7 +197,7 @@ static void cio2_fbpt_entry_init_buf(struct cio2_device *cio2, remaining = length; i = 0; while (remaining > 0) { - entry->lop_page_addr = b->lop_bus_addr[i] >> PAGE_SHIFT; + entry->lop_page_addr = PFN_DOWN(b->lop_bus_addr[i]); remaining -= CIO2_MAX_ENTRIES * PAGE_SIZE; entry++; i++; @@ -206,7 +206,7 @@ static void cio2_fbpt_entry_init_buf(struct cio2_device *cio2, /* * The first not meaningful FBPT entry should point to a valid LOP */ - entry->lop_page_addr = cio2->dummy_lop_bus_addr >> PAGE_SHIFT; + entry->lop_page_addr = PFN_DOWN(cio2->dummy_lop_bus_addr); cio2_fbpt_entry_enable(cio2, entry); } @@ -472,8 +472,7 @@ static int cio2_hw_init(struct cio2_device *cio2, struct cio2_queue *q) } /* Enable DMA */ - writel(q->fbpt_bus_addr >> PAGE_SHIFT, - base + CIO2_REG_CDMABA(CIO2_DMA_CHAN)); + writel(PFN_DOWN(q->fbpt_bus_addr), base + CIO2_REG_CDMABA(CIO2_DMA_CHAN)); writel(num_buffers1 << CIO2_CDMAC0_FBPT_LEN_SHIFT | FBPT_WIDTH << CIO2_CDMAC0_FBPT_WIDTH_SHIFT | @@ -838,7 +837,7 @@ static int cio2_vb2_buf_init(struct vb2_buffer *vb) struct device *dev = &cio2->pci_dev->dev; struct cio2_buffer *b = container_of(vb, struct cio2_buffer, vbb.vb2_buf); - unsigned int pages = DIV_ROUND_UP(vb->planes[0].length, PAGE_SIZE); + unsigned int pages = PFN_UP(vb->planes[0].length); unsigned int lops = DIV_ROUND_UP(pages + 1, CIO2_MAX_ENTRIES); struct sg_table *sg; struct sg_dma_page_iter sg_iter; @@ -871,7 +870,7 @@ static int cio2_vb2_buf_init(struct vb2_buffer *vb) for_each_sg_dma_page (sg->sgl, &sg_iter, sg->nents, 0) { if (!pages--) break; - b->lop[i][j] = sg_page_iter_dma_address(&sg_iter) >> PAGE_SHIFT; + b->lop[i][j] = PFN_DOWN(sg_page_iter_dma_address(&sg_iter)); j++; if (j == CIO2_MAX_ENTRIES) { i++; @@ -879,7 +878,7 @@ static int cio2_vb2_buf_init(struct vb2_buffer *vb) } } - b->lop[i][j] = cio2->dummy_page_bus_addr >> PAGE_SHIFT; + b->lop[i][j] = PFN_DOWN(cio2->dummy_page_bus_addr); return 0; fail: while (i--) From patchwork Fri Aug 14 16:30:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 11714767 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BCB5D16B1 for ; Fri, 14 Aug 2020 16:30:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ACBA6207DA for ; Fri, 14 Aug 2020 16:30:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728140AbgHNQaV (ORCPT ); Fri, 14 Aug 2020 12:30:21 -0400 Received: from mga12.intel.com ([192.55.52.136]:2838 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726320AbgHNQaU (ORCPT ); Fri, 14 Aug 2020 12:30:20 -0400 IronPort-SDR: oQCBArlvamHJxWCsyw9GVHt/l9FKt9PXETx1gHG30E8YOP+l7iBcBt8acXz0i72JcOz9HjEIt5 Q7Tfj5uIgpsA== X-IronPort-AV: E=McAfee;i="6000,8403,9713"; a="133964972" X-IronPort-AV: E=Sophos;i="5.76,312,1592895600"; d="scan'208";a="133964972" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Aug 2020 09:30:20 -0700 IronPort-SDR: 0GaUVX7pav7BGI0OjRu7tHB84a+ytiZySCjM/yWJxNLkR26HMeGFV7QzP/h7b3tCZ7or97gFLZ FMQj/20Tw14A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,312,1592895600"; d="scan'208";a="327931578" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga002.fm.intel.com with ESMTP; 14 Aug 2020 09:30:19 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 2EE223D7; Fri, 14 Aug 2020 19:30:18 +0300 (EEST) From: Andy Shevchenko To: Yong Zhi , Sakari Ailus , Bingbu Cao , Tian Shu Qiu , linux-media@vger.kernel.org, Mauro Carvalho Chehab Cc: Andy Shevchenko Subject: [PATCH v1 5/7] media: ipu3-cio2: Replace infinite loop by one with clear exit condition Date: Fri, 14 Aug 2020 19:30:15 +0300 Message-Id: <20200814163017.35001-5-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200814163017.35001-1-andriy.shevchenko@linux.intel.com> References: <20200814163017.35001-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Refactor cio2_buffer_done() to get rid of infinite loop by replacing it by one with clear exit condition. This change also allows to check for an error ahead. Signed-off-by: Andy Shevchenko --- drivers/media/pci/intel/ipu3/ipu3-cio2.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.c b/drivers/media/pci/intel/ipu3/ipu3-cio2.c index eee7f841050d..f4175dc1501a 100644 --- a/drivers/media/pci/intel/ipu3/ipu3-cio2.c +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.c @@ -541,7 +541,7 @@ static void cio2_buffer_done(struct cio2_device *cio2, unsigned int dma_chan) { struct device *dev = &cio2->pci_dev->dev; struct cio2_queue *q = cio2->cur_queue; - int buffers_found = 0; + struct cio2_fbpt_entry *const entry; u64 ns = ktime_get_ns(); if (dma_chan >= CIO2_QUEUES) { @@ -549,15 +549,18 @@ static void cio2_buffer_done(struct cio2_device *cio2, unsigned int dma_chan) return; } + entry = &q->fbpt[q->bufs_first * CIO2_MAX_LOPS]; + if (entry->first_entry.ctrl & CIO2_FBPT_CTRL_VALID) { + dev_warn(&cio2->pci_dev->dev, + "no ready buffers found on DMA channel %u\n", + dma_chan); + return; + } + /* Find out which buffer(s) are ready */ do { - struct cio2_fbpt_entry *const entry = - &q->fbpt[q->bufs_first * CIO2_MAX_LOPS]; struct cio2_buffer *b; - if (entry->first_entry.ctrl & CIO2_FBPT_CTRL_VALID) - break; - b = q->bufs[q->bufs_first]; if (b) { unsigned int bytes = entry[1].second_entry.num_of_bytes; @@ -579,13 +582,8 @@ static void cio2_buffer_done(struct cio2_device *cio2, unsigned int dma_chan) atomic_inc(&q->frame_sequence); cio2_fbpt_entry_init_dummy(cio2, entry); q->bufs_first = (q->bufs_first + 1) % CIO2_MAX_BUFFERS; - buffers_found++; - } while (1); - - if (buffers_found == 0) - dev_warn(&cio2->pci_dev->dev, - "no ready buffers found on DMA channel %u\n", - dma_chan); + entry = &q->fbpt[q->bufs_first * CIO2_MAX_LOPS]; + } while (!(entry->first_entry.ctrl & CIO2_FBPT_CTRL_VALID)); } static void cio2_queue_event_sof(struct cio2_device *cio2, struct cio2_queue *q) From patchwork Fri Aug 14 16:30:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 11714779 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A9F491744 for ; Fri, 14 Aug 2020 16:30:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 91F9120885 for ; Fri, 14 Aug 2020 16:30:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728363AbgHNQaZ (ORCPT ); Fri, 14 Aug 2020 12:30:25 -0400 Received: from mga18.intel.com ([134.134.136.126]:29792 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728129AbgHNQaX (ORCPT ); Fri, 14 Aug 2020 12:30:23 -0400 IronPort-SDR: b3ubtzdyAmHfLqHXMIDASFWKQLtZ3KqorKtg7/Wsq6FKRQD5lDn/NwHI0ZtqmHPjeBfX9CwYqd sfSQj0VmTyqQ== X-IronPort-AV: E=McAfee;i="6000,8403,9713"; a="142064537" X-IronPort-AV: E=Sophos;i="5.76,312,1592895600"; d="scan'208";a="142064537" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Aug 2020 09:30:23 -0700 IronPort-SDR: U0sBx6InpTBH3hjdaLu+/nuJbIFRW6pmLl1xxdupv0e99UMkBMqTngypihfGGkGAorokyuwsbc 7X8361Qo8NNA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,312,1592895600"; d="scan'208";a="278449489" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga008.fm.intel.com with ESMTP; 14 Aug 2020 09:30:21 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 341513A3; Fri, 14 Aug 2020 19:30:18 +0300 (EEST) From: Andy Shevchenko To: Yong Zhi , Sakari Ailus , Bingbu Cao , Tian Shu Qiu , linux-media@vger.kernel.org, Mauro Carvalho Chehab Cc: Andy Shevchenko Subject: [PATCH v1 6/7] media: ipu3-cio2: Use readl_poll_timeout() helper Date: Fri, 14 Aug 2020 19:30:16 +0300 Message-Id: <20200814163017.35001-6-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200814163017.35001-1-andriy.shevchenko@linux.intel.com> References: <20200814163017.35001-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org We may use special helper macro to poll IO till condition or timeout occurs. Signed-off-by: Andy Shevchenko --- drivers/media/pci/intel/ipu3/ipu3-cio2.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.c b/drivers/media/pci/intel/ipu3/ipu3-cio2.c index f4175dc1501a..5f8ff91dbf09 100644 --- a/drivers/media/pci/intel/ipu3/ipu3-cio2.c +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.c @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -509,7 +510,10 @@ static int cio2_hw_init(struct cio2_device *cio2, struct cio2_queue *q) static void cio2_hw_exit(struct cio2_device *cio2, struct cio2_queue *q) { void __iomem *base = cio2->base; - unsigned int i, maxloops = 1000; + void __iomem *dma = base + CIO2_REG_CDMAC0(CIO2_DMA_CHAN); + unsigned int i; + u32 value; + int ret; /* Disable CSI receiver and MIPI backend devices */ writel(0, q->csi_rx_base + CIO2_REG_IRQCTRL_MASK); @@ -518,14 +522,9 @@ static void cio2_hw_exit(struct cio2_device *cio2, struct cio2_queue *q) writel(0, q->csi_rx_base + CIO2_REG_MIPIBE_ENABLE); /* Halt DMA */ - writel(0, base + CIO2_REG_CDMAC0(CIO2_DMA_CHAN)); - do { - if (readl(base + CIO2_REG_CDMAC0(CIO2_DMA_CHAN)) & - CIO2_CDMAC0_DMA_HALTED) - break; - usleep_range(1000, 2000); - } while (--maxloops); - if (!maxloops) + writel(0, dma); + ret = readl_poll_timeout(dma, value, value & CIO2_CDMAC0_DMA_HALTED, 4000, 2000000); + if (ret) dev_err(&cio2->pci_dev->dev, "DMA %i can not be halted\n", CIO2_DMA_CHAN); From patchwork Fri Aug 14 16:30:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 11714777 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4C454739 for ; Fri, 14 Aug 2020 16:30:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3297F20791 for ; Fri, 14 Aug 2020 16:30:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728362AbgHNQaY (ORCPT ); Fri, 14 Aug 2020 12:30:24 -0400 Received: from mga18.intel.com ([134.134.136.126]:29793 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728360AbgHNQaY (ORCPT ); Fri, 14 Aug 2020 12:30:24 -0400 IronPort-SDR: /pCnGfNV/29j2qB37iwoJep8al54AoQI9xVtONzwQPwE/0l7fzlVheQs2u7/QpC7nJ5+CyVguN qD9Km7Wzr3mQ== X-IronPort-AV: E=McAfee;i="6000,8403,9713"; a="142064539" X-IronPort-AV: E=Sophos;i="5.76,312,1592895600"; d="scan'208";a="142064539" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Aug 2020 09:30:23 -0700 IronPort-SDR: v9i+1e9iU9+a6wNkj4Ee5BIf18zUYZAZF4xMHBBl/HYYgjZkZX8i3ymlAU6Pwa7i+0JKoYEWkl EnUnedGy3NXA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,312,1592895600"; d="scan'208";a="278449490" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga008.fm.intel.com with ESMTP; 14 Aug 2020 09:30:21 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 409F0456; Fri, 14 Aug 2020 19:30:18 +0300 (EEST) From: Andy Shevchenko To: Yong Zhi , Sakari Ailus , Bingbu Cao , Tian Shu Qiu , linux-media@vger.kernel.org, Mauro Carvalho Chehab Cc: Andy Shevchenko Subject: [PATCH v1 7/7] media: ipu3-cio2: Update Copyright year and fix indentation issues Date: Fri, 14 Aug 2020 19:30:17 +0300 Message-Id: <20200814163017.35001-7-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200814163017.35001-1-andriy.shevchenko@linux.intel.com> References: <20200814163017.35001-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Update Copyright year to cover the previous changes and at the same time address indentation issues. Signed-off-by: Andy Shevchenko --- drivers/media/pci/intel/ipu3/ipu3-cio2.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.c b/drivers/media/pci/intel/ipu3/ipu3-cio2.c index 5f8ff91dbf09..8925bab8ba06 100644 --- a/drivers/media/pci/intel/ipu3/ipu3-cio2.c +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 /* - * Copyright (C) 2017 Intel Corporation + * Copyright (C) 2017,2020 Intel Corporation * * Based partially on Intel IPU4 driver written by * Sakari Ailus @@ -9,7 +9,6 @@ * Jouni Ukkonen * Antti Laakso * et al. - * */ #include @@ -864,7 +863,7 @@ static int cio2_vb2_buf_init(struct vb2_buffer *vb) b->offset = sg->sgl->offset; i = j = 0; - for_each_sg_dma_page (sg->sgl, &sg_iter, sg->nents, 0) { + for_each_sg_dma_page(sg->sgl, &sg_iter, sg->nents, 0) { if (!pages--) break; b->lop[i][j] = PFN_DOWN(sg_page_iter_dma_address(&sg_iter));