public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Paulius Zaleckas <paulius.zaleckas@teltonika.lt>
To: video4linux-list@redhat.com
Cc: video4linux-list@redhat.com, linux-sh@vger.kernel.org
Subject: Re: [PATCH 03/04] videobuf: Add physically contiguous queue code V2
Date: Tue, 08 Jul 2008 17:33:07 +0300	[thread overview]
Message-ID: <48737AA3.3080902@teltonika.lt> (raw)
In-Reply-To: <20080705025405.27137.16206.sendpatchset@rx1.opensource.se>

Magnus Damm wrote:
> This is V2 of the physically contiguous videobuf queues patch.
> Useful for hardware such as the SuperH Mobile CEU which doesn't
> support scatter gatter bus mastering.

spelling gatther :)

> +static int __videobuf_mmap_mapper(struct videobuf_queue *q,
> +				  struct vm_area_struct *vma)
> +{
> +	struct videobuf_dma_contig_memory *mem;
> +	struct videobuf_mapping *map;
> +	unsigned int first;
> +	int retval;
> +	unsigned long size, offset = vma->vm_pgoff << PAGE_SHIFT;
> +
> +	dev_dbg(q->dev, "%s\n", __func__);
> +	if (!(vma->vm_flags & VM_WRITE) || !(vma->vm_flags & VM_SHARED))
> +		return -EINVAL;
> +
> +	/* look for first buffer to map */
> +	for (first = 0; first < VIDEO_MAX_FRAME; first++) {
> +		if (!q->bufs[first])
> +			continue;
> +
> +		if (V4L2_MEMORY_MMAP != q->bufs[first]->memory)
> +			continue;
> +		if (q->bufs[first]->boff == offset)
> +			break;
> +	}
> +	if (VIDEO_MAX_FRAME == first) {
> +		dev_dbg(q->dev, "invalid user space offset [offset=0x%lx]\n",
> +			offset);
> +		return -EINVAL;
> +	}
> +
> +	/* create mapping + update buffer list */
> +	map = kzalloc(sizeof(struct videobuf_mapping), GFP_KERNEL);
> +	if (!map)
> +		return -ENOMEM;
> +
> +	q->bufs[first]->map = map;
> +	map->start = vma->vm_start;
> +	map->end = vma->vm_end;
> +	map->q = q;
> +
> +	q->bufs[first]->baddr = vma->vm_start;
> +
> +	mem = q->bufs[first]->priv;
> +	BUG_ON(!mem);
> +	MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
> +
> +	mem->size = PAGE_ALIGN(q->bufs[first]->bsize);
> +	mem->vaddr = dma_alloc_coherent(q->dev, mem->size,
> +					&mem->dma_handle, GFP_KERNEL);
> +	if (!mem->vaddr) {
> +		dev_err(q->dev, "dma_alloc_coherent size %ld failed\n",
> +			mem->size);
> +		goto error;
> +	}
> +	dev_dbg(q->dev, "dma_alloc_coherent data is at addr %p (size %ld)\n",
> +		mem->vaddr, mem->size);
> +
> +	/* Try to remap memory */
> +
> +	size = vma->vm_end - vma->vm_start;
> +	size = (size < mem->size) ? size : mem->size;
> +
> +	vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
> +	retval = remap_pfn_range(vma, vma->vm_start,
> +				 __pa(mem->vaddr) >> PAGE_SHIFT,

__pa(mem->vaddr) doesn't work on ARM architecture... It is a long story
about handling memory allocations and mapping for ARM (there is
dma_mmap_coherent to deal with this), but there is a workaround:

mem->dma_handle >> PAGE_SHIFT,

It is safe to do it this way and also saves some CPU instructions :)

> +				 size, vma->vm_page_prot);
> +	if (retval) {
> +		dev_err(q->dev, "mmap: remap failed with error %d. ", retval);
> +		dma_free_coherent(q->dev, mem->size,
> +				  mem->vaddr, mem->dma_handle);
> +		goto error;
> +	}
> +
> +	vma->vm_ops          = &videobuf_vm_ops;
> +	vma->vm_flags       |= VM_DONTEXPAND;
> +	vma->vm_private_data = map;
> +
> +	dev_dbg(q->dev, "mmap %p: q=%p %08lx-%08lx (%lx) pgoff %08lx buf %d\n",
> +		map, q, vma->vm_start, vma->vm_end,
> +		(long int) q->bufs[first]->bsize,
> +		vma->vm_pgoff, first);
> +
> +	videobuf_vm_open(vma);
> +
> +	return 0;
> +
> +error:
> +	kfree(map);
> +	return -ENOMEM;
> +}

--
video4linux-list mailing list
Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list

  reply	other threads:[~2008-07-08 14:35 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-05  2:53 [PATCH 00/04] soc_camera: SuperH Mobile CEU support V2 Magnus Damm
2008-07-05  2:53 ` [PATCH 01/04] soc_camera: Move spinlocks Magnus Damm
2008-07-05  4:19   ` Guennadi Liakhovetski
2008-07-05  4:24     ` Magnus Damm
2008-07-05  2:53 ` [PATCH 02/04] soc_camera: Add 16-bit bus width support Magnus Damm
2008-07-05  2:54 ` [PATCH 03/04] videobuf: Add physically contiguous queue code V2 Magnus Damm
2008-07-08 14:33   ` Paulius Zaleckas [this message]
2008-07-08 14:42     ` Laurent Pinchart
2008-07-09  8:33       ` Magnus Damm
2008-07-11 21:33     ` Guennadi Liakhovetski
2008-07-14  3:51       ` Magnus Damm
2008-07-14  9:25         ` Paulius Zaleckas
     [not found]         ` <20080715034850.GA3722@linux-sh.org>
2008-07-15  8:28           ` Magnus Damm
2008-07-11 13:38   ` Karicheri, Muralidharan
2008-07-05  2:54 ` [PATCH 04/04] sh_mobile_ceu_camera: Add SuperH Mobile CEU driver V2 Magnus Damm

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=48737AA3.3080902@teltonika.lt \
    --to=paulius.zaleckas@teltonika.lt \
    --cc=linux-sh@vger.kernel.org \
    --cc=video4linux-list@redhat.com \
    /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