From: Hans Verkuil <hverkuil-cisco@xs4all.nl>
To: linux-media@vger.kernel.org
Cc: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Subject: [PATCHv2 09/19] media: common: saa7146: use for_each_sg_dma_page
Date: Thu, 23 Mar 2023 16:53:33 +0100 [thread overview]
Message-ID: <20230323155343.2399473-10-hverkuil-cisco@xs4all.nl> (raw)
In-Reply-To: <20230323155343.2399473-1-hverkuil-cisco@xs4all.nl>
When building the pgtables, use for_each_sg_dma_page.
Also clean up the code a bit.
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
drivers/media/common/saa7146/saa7146_core.c | 29 ++------
drivers/media/common/saa7146/saa7146_video.c | 76 +++++++-------------
2 files changed, 32 insertions(+), 73 deletions(-)
diff --git a/drivers/media/common/saa7146/saa7146_core.c b/drivers/media/common/saa7146/saa7146_core.c
index f15caf54771b..bcb957883044 100644
--- a/drivers/media/common/saa7146/saa7146_core.c
+++ b/drivers/media/common/saa7146/saa7146_core.c
@@ -235,11 +235,12 @@ int saa7146_pgtable_alloc(struct pci_dev *pci, struct saa7146_pgtable *pt)
}
int saa7146_pgtable_build_single(struct pci_dev *pci, struct saa7146_pgtable *pt,
- struct scatterlist *list, int sglen )
+ struct scatterlist *list, int sglen)
{
+ struct sg_dma_page_iter dma_iter;
__le32 *ptr, fill;
int nr_pages = 0;
- int i,p;
+ int i;
if (WARN_ON(!sglen) ||
WARN_ON(list->offset > PAGE_SIZE))
@@ -250,32 +251,16 @@ int saa7146_pgtable_build_single(struct pci_dev *pci, struct saa7146_pgtable *pt
pt->offset = list->offset;
ptr = pt->cpu;
- for (i = 0; i < sglen; i++, list++) {
-/*
- pr_debug("i:%d, adr:0x%08x, len:%d, offset:%d\n",
- i, sg_dma_address(list), sg_dma_len(list),
- list->offset);
-*/
- for (p = 0; p * 4096 < sg_dma_len(list); p++, ptr++) {
- *ptr = cpu_to_le32(sg_dma_address(list) + p * 4096);
- nr_pages++;
- }
+ for_each_sg_dma_page(list, &dma_iter, sglen, 0) {
+ *ptr++ = cpu_to_le32(sg_page_iter_dma_address(&dma_iter));
+ nr_pages++;
}
/* safety; fill the page table up with the last valid page */
fill = *(ptr-1);
- for(i=nr_pages;i<1024;i++) {
+ for (i = nr_pages; i < 1024; i++)
*ptr++ = fill;
- }
-
-/*
- ptr = pt->cpu;
- pr_debug("offset: %d\n", pt->offset);
- for(i=0;i<5;i++) {
- pr_debug("ptr1 %d: 0x%08x\n", i, ptr[i]);
- }
-*/
return 0;
}
diff --git a/drivers/media/common/saa7146/saa7146_video.c b/drivers/media/common/saa7146/saa7146_video.c
index bc4e8d12873b..6af30fece176 100644
--- a/drivers/media/common/saa7146/saa7146_video.c
+++ b/drivers/media/common/saa7146/saa7146_video.c
@@ -107,31 +107,32 @@ static int saa7146_pgtable_build(struct saa7146_dev *dev, struct saa7146_buf *bu
struct saa7146_pgtable *pt1 = &buf->pt[0];
struct saa7146_pgtable *pt2 = &buf->pt[1];
struct saa7146_pgtable *pt3 = &buf->pt[2];
+ struct sg_dma_page_iter dma_iter;
__le32 *ptr1, *ptr2, *ptr3;
__le32 fill;
int size = pix->width * pix->height;
- int i,p,m1,m2,m3,o1,o2;
+ int i, m1, m2, m3, o1, o2;
switch( sfmt->depth ) {
case 12: {
/* create some offsets inside the page table */
- m1 = ((size+PAGE_SIZE)/PAGE_SIZE)-1;
- m2 = ((size+(size/4)+PAGE_SIZE)/PAGE_SIZE)-1;
- m3 = ((size+(size/2)+PAGE_SIZE)/PAGE_SIZE)-1;
- o1 = size%PAGE_SIZE;
- o2 = (size+(size/4))%PAGE_SIZE;
+ m1 = ((size + PAGE_SIZE) / PAGE_SIZE) - 1;
+ m2 = ((size + (size / 4) + PAGE_SIZE) / PAGE_SIZE) - 1;
+ m3 = ((size + (size / 2) + PAGE_SIZE) / PAGE_SIZE) - 1;
+ o1 = size % PAGE_SIZE;
+ o2 = (size + (size / 4)) % PAGE_SIZE;
DEB_CAP("size:%d, m1:%d, m2:%d, m3:%d, o1:%d, o2:%d\n",
size, m1, m2, m3, o1, o2);
break;
}
case 16: {
/* create some offsets inside the page table */
- m1 = ((size+PAGE_SIZE)/PAGE_SIZE)-1;
- m2 = ((size+(size/2)+PAGE_SIZE)/PAGE_SIZE)-1;
- m3 = ((2*size+PAGE_SIZE)/PAGE_SIZE)-1;
- o1 = size%PAGE_SIZE;
- o2 = (size+(size/2))%PAGE_SIZE;
+ m1 = ((size + PAGE_SIZE) / PAGE_SIZE) - 1;
+ m2 = ((size + (size / 2) + PAGE_SIZE) / PAGE_SIZE) - 1;
+ m3 = ((2 * size + PAGE_SIZE) / PAGE_SIZE) - 1;
+ o1 = size % PAGE_SIZE;
+ o2 = (size + (size / 2)) % PAGE_SIZE;
DEB_CAP("size:%d, m1:%d, m2:%d, m3:%d, o1:%d, o2:%d\n",
size, m1, m2, m3, o1, o2);
break;
@@ -145,64 +146,37 @@ static int saa7146_pgtable_build(struct saa7146_dev *dev, struct saa7146_buf *bu
ptr2 = pt2->cpu;
ptr3 = pt3->cpu;
- /* walk all pages, copy all page addresses to ptr1 */
- for (i = 0; i < length; i++, list++) {
- for (p = 0; p * 4096 < sg_dma_len(list); p++, ptr1++)
- *ptr1 = cpu_to_le32(sg_dma_address(list) - list->offset);
- }
-/*
- ptr1 = pt1->cpu;
- for(j=0;j<40;j++) {
- printk("ptr1 %d: 0x%08x\n",j,ptr1[j]);
- }
-*/
+ for_each_sg_dma_page(list, &dma_iter, length, 0)
+ *ptr1++ = cpu_to_le32(sg_page_iter_dma_address(&dma_iter) - list->offset);
/* if we have a user buffer, the first page may not be
aligned to a page boundary. */
pt1->offset = dma->sglist->offset;
- pt2->offset = pt1->offset+o1;
- pt3->offset = pt1->offset+o2;
+ pt2->offset = pt1->offset + o1;
+ pt3->offset = pt1->offset + o2;
/* create video-dma2 page table */
ptr1 = pt1->cpu;
- for(i = m1; i <= m2 ; i++, ptr2++) {
+ for (i = m1; i <= m2; i++, ptr2++)
*ptr2 = ptr1[i];
- }
- fill = *(ptr2-1);
- for(;i<1024;i++,ptr2++) {
+ fill = *(ptr2 - 1);
+ for (; i < 1024; i++, ptr2++)
*ptr2 = fill;
- }
/* create video-dma3 page table */
ptr1 = pt1->cpu;
- for(i = m2; i <= m3; i++,ptr3++) {
+ for (i = m2; i <= m3; i++, ptr3++)
*ptr3 = ptr1[i];
- }
- fill = *(ptr3-1);
- for(;i<1024;i++,ptr3++) {
+ fill = *(ptr3 - 1);
+ for (; i < 1024; i++, ptr3++)
*ptr3 = fill;
- }
/* finally: finish up video-dma1 page table */
- ptr1 = pt1->cpu+m1;
+ ptr1 = pt1->cpu + m1;
fill = pt1->cpu[m1];
- for(i=m1;i<1024;i++,ptr1++) {
+ for (i = m1; i < 1024; i++, ptr1++)
*ptr1 = fill;
- }
-/*
- ptr1 = pt1->cpu;
- ptr2 = pt2->cpu;
- ptr3 = pt3->cpu;
- for(j=0;j<40;j++) {
- printk("ptr1 %d: 0x%08x\n",j,ptr1[j]);
- }
- for(j=0;j<40;j++) {
- printk("ptr2 %d: 0x%08x\n",j,ptr2[j]);
- }
- for(j=0;j<40;j++) {
- printk("ptr3 %d: 0x%08x\n",j,ptr3[j]);
- }
-*/
} else {
struct saa7146_pgtable *pt = &buf->pt[0];
+
return saa7146_pgtable_build_single(pci, pt, list, length);
}
--
2.39.2
next prev parent reply other threads:[~2023-03-23 15:54 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-23 15:53 [PATCHv2 00/19] saa7146: convert to vb2 Hans Verkuil
2023-03-23 15:53 ` [PATCHv2 01/19] media: common: saa7146: disable clipping Hans Verkuil
2023-03-23 15:53 ` [PATCHv2 02/19] common/saa7146: fix VFL direction for vbi output Hans Verkuil
2023-03-23 15:53 ` [PATCHv2 03/19] media: pci: saa7146: hexium_orion: initialize input 0 Hans Verkuil
2023-03-23 15:53 ` [PATCHv2 04/19] media: saa7146: drop 'dev' and 'resources' from struct saa7146_fh Hans Verkuil
2023-03-23 15:53 ` [PATCHv2 05/19] media: common: saa7146: drop 'fmt' from struct saa7146_buf Hans Verkuil
2023-03-23 15:53 ` [PATCHv2 06/19] media: common: saa7146: replace BUG_ON by WARN_ON Hans Verkuil
2023-03-23 15:53 ` [PATCHv2 07/19] staging: media: av7110: " Hans Verkuil
2023-03-23 15:53 ` [PATCHv2 08/19] media: common: saa7146: fix broken V4L2_PIX_FMT_YUV422P support Hans Verkuil
2023-03-23 15:53 ` Hans Verkuil [this message]
2023-03-23 15:53 ` [PATCHv2 10/19] media: saa7146: convert to vb2 Hans Verkuil
2023-03-23 15:53 ` [PATCHv2 11/19] media: common: saa7146: fix compliance problems with field handling Hans Verkuil
2023-03-23 15:53 ` [PATCHv2 12/19] media: common: saa7146: check minimum video format size Hans Verkuil
2023-03-23 15:53 ` [PATCHv2 13/19] media: common: saa7146: fall back to V4L2_PIX_FMT_BGR24 Hans Verkuil
2023-03-23 15:53 ` [PATCHv2 14/19] media: common: saa7146: allow S_STD(G_STD) Hans Verkuil
2023-03-23 15:53 ` [PATCHv2 15/19] media: mxb: update the tvnorms when changing input Hans Verkuil
2023-03-23 15:53 ` [PATCHv2 16/19] media: common: saa7146: add support for missing .vidioc_try_fmt_vbi_cap Hans Verkuil
2023-03-23 15:53 ` [PATCHv2 17/19] media: mxb: allow tuner/input/audio ioctls for vbi Hans Verkuil
2023-03-23 15:53 ` [PATCHv2 18/19] media: pci: saa7146: advertise only those TV standard that are supported Hans Verkuil
2023-03-23 15:53 ` [PATCHv2 19/19] staging: media: av7110: fix VBI output support Hans Verkuil
2023-03-23 17:23 ` [PATCHv2 00/19] saa7146: convert to vb2 Hans Verkuil
2023-03-24 10:18 ` Hans Verkuil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230323155343.2399473-10-hverkuil-cisco@xs4all.nl \
--to=hverkuil-cisco@xs4all.nl \
--cc=linux-media@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).