* how to mmap in videobuf-dma-sg.c
@ 2009-05-21 4:46 Figo.zhang
2009-05-21 10:35 ` Mauro Carvalho Chehab
0 siblings, 1 reply; 7+ messages in thread
From: Figo.zhang @ 2009-05-21 4:46 UTC (permalink / raw)
To: linux-media; +Cc: linux-media
hi,all,
I am puzzle that how to mmap ( V4L2_MEMORY_MMAP) in videobuf-dma-sg.c?
In this file, it alloc the momery using vmalloc_32() , and put this
momery into sglist table,and then use dma_map_sg() to create sg dma at
__videobuf_iolock() function. but in __videobuf_mmap_mapper(), i canot
understand how it do the mmap?
why it not use the remap_vmalloc_range() to do the mmap?
Thanks ,
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: how to mmap in videobuf-dma-sg.c
2009-05-21 4:46 how to mmap in videobuf-dma-sg.c Figo.zhang
@ 2009-05-21 10:35 ` Mauro Carvalho Chehab
2009-05-21 10:48 ` Figo.zhang
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Mauro Carvalho Chehab @ 2009-05-21 10:35 UTC (permalink / raw)
To: Figo.zhang; +Cc: linux-media
Em Thu, 21 May 2009 12:46:04 +0800
"Figo.zhang" <figo1802@gmail.com> escreveu:
> hi,all,
> I am puzzle that how to mmap ( V4L2_MEMORY_MMAP) in videobuf-dma-sg.c?
>
> In this file, it alloc the momery using vmalloc_32() , and put this
> momery into sglist table,and then use dma_map_sg() to create sg dma at
> __videobuf_iolock() function. but in __videobuf_mmap_mapper(), i canot
> understand how it do the mmap?
> why it not use the remap_vmalloc_range() to do the mmap?
The answer is simple: remap_vmalloc_range() is newer than videobuf code. This
part of the code was written back to kernel 2.4, and nobody cared to update it
to use those newer functions, and simplify its code.
If you want, feel free to propose some cleanups on it
Cheers,
Mauro
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: how to mmap in videobuf-dma-sg.c
2009-05-21 10:35 ` Mauro Carvalho Chehab
@ 2009-05-21 10:48 ` Figo.zhang
2009-06-10 15:06 ` Figo.zhang
2010-07-24 13:43 ` Figo.zhang
[not found] ` <AANLkTimExb4hh8K5lRCRiM0IMIgsOpCw69bFvqLlQCDc@mail.gmail.com>
2 siblings, 1 reply; 7+ messages in thread
From: Figo.zhang @ 2009-05-21 10:48 UTC (permalink / raw)
To: Mauro Carvalho Chehab; +Cc: linux-media
On Thu, 2009-05-21 at 07:35 -0300, Mauro Carvalho Chehab wrote:
> Em Thu, 21 May 2009 12:46:04 +0800
> "Figo.zhang" <figo1802@gmail.com> escreveu:
>
> > hi,all,
> > I am puzzle that how to mmap ( V4L2_MEMORY_MMAP) in videobuf-dma-sg.c?
> >
> > In this file, it alloc the momery using vmalloc_32() , and put this
> > momery into sglist table,and then use dma_map_sg() to create sg dma at
> > __videobuf_iolock() function. but in __videobuf_mmap_mapper(), i canot
> > understand how it do the mmap?
> > why it not use the remap_vmalloc_range() to do the mmap?
>
> The answer is simple: remap_vmalloc_range() is newer than videobuf code. This
> part of the code was written back to kernel 2.4, and nobody cared to update it
> to use those newer functions, and simplify its code.
>
> If you want, feel free to propose some cleanups on it
>
>
>
> Cheers,
> Mauro
hi mauro,
Thank you!
But i canot found the similar function code of remap_vmalloc_range() in
the videobuf-dma-contig.c file. So i want to know the how is work in
__videobuf_mmap_mapper() function?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: how to mmap in videobuf-dma-sg.c
2009-05-21 10:48 ` Figo.zhang
@ 2009-06-10 15:06 ` Figo.zhang
0 siblings, 0 replies; 7+ messages in thread
From: Figo.zhang @ 2009-06-10 15:06 UTC (permalink / raw)
To: Mauro Carvalho Chehab; +Cc: linux-media, Mauro Carvalho Chehab
On Thu, 2009-05-21 at 18:48 +0800, Figo.zhang wrote:
> On Thu, 2009-05-21 at 07:35 -0300, Mauro Carvalho Chehab wrote:
> > Em Thu, 21 May 2009 12:46:04 +0800
> > "Figo.zhang" <figo1802@gmail.com> escreveu:
> >
> > > hi,all,
> > > I am puzzle that how to mmap ( V4L2_MEMORY_MMAP) in videobuf-dma-sg.c?
> > >
> > > In this file, it alloc the momery using vmalloc_32() , and put this
> > > momery into sglist table,and then use dma_map_sg() to create sg dma at
> > > __videobuf_iolock() function. but in __videobuf_mmap_mapper(), i canot
> > > understand how it do the mmap?
> > > why it not use the remap_vmalloc_range() to do the mmap?
> >
> > The answer is simple: remap_vmalloc_range() is newer than videobuf code. This
> > part of the code was written back to kernel 2.4, and nobody cared to update it
> > to use those newer functions, and simplify its code.
> >
> > If you want, feel free to propose some cleanups on it
> >
> >
> >
> > Cheers,
> > Mauro
>
> hi mauro,
> Thank you!
> But i canot found the similar function code of remap_vmalloc_range() in
> the videobuf-dma-contig.c file. So i want to know the how is work in
> __videobuf_mmap_mapper() function?
>
>
hi mauro:
Thank you. But i still have a puzzle question about mmap() in
videobuf-dma-sg.c. I canot find how to remap the dma buffer
(which alloc by vmalloc_32()) to the vma area in
__videobuf_mmap_mapper()?
there is my test driver code about dma-sg,it work well. i use
remap_pfn_range() to remap the dma buffer to vma area in mmap method.
so would you like to give me some detail about it?
Best Regards,
Figo.zhang
static int mydev_alloc_dma_sg(struct mydev_device *dev, struct mydev_buf
*buf)
{
int nr_pages;
int i;
struct page *pg;
unsigned char * virt;
nr_pages = mydev_buffer_pages(buf->size);
buf->nr_pages = nr_pages;
dprintk("%s:: buf->nr_pages =%d\n", __func__, buf->nr_pages);
buf->sglist = kcalloc(buf->nr_pages, sizeof(struct scatterlist),
GFP_KERNEL);
if (NULL == buf->sglist)
return NULL;
sg_init_table(buf->sglist, buf->nr_pages);
buf->vmalloc = vmalloc_32(buf->nr_pages << PAGE_SHIFT);
memset(buf->vmalloc,0,buf->nr_pages << PAGE_SHIFT);
virt = buf->vmalloc;
for(i = 0; i< buf->nr_pages; i++,virt += PAGE_SIZE){
pg = vmalloc_to_page(virt);
if (NULL == pg)
goto nopage;
BUG_ON(PageHighMem(pg));
sg_set_page(&buf->sglist[i], pg, PAGE_SIZE, 0);
}
buf->sglen = dma_map_sg(&dev->pci->dev, buf->sglist,
buf->nr_pages, DMA_FROM_DEVICE);
return 0;
nopage:
dprintk("sgl: oops - no page\n");
kfree(buf->sglist);
return 0;
}
in mmap();
static int do_mmap_sg(struct mydev_device *dev, struct vm_area_struct *
vma)
{
struct videobuf_mapping *map;
unsigned long pos,page;
unsigned long start = vma->vm_start;
unsigned long size = vma->vm_end - vma->vm_start;
unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
unsigned int first, last, end;
int retval = -EINVAL;
int i;
/* look for first buffer to map */
for (first = 0; first < VIDEO_MAX_FRAME; first++) {
if (dev->ktbuf[first].boff == (vma->vm_pgoff << PAGE_SHIFT))
break;
}
if (VIDEO_MAX_FRAME == first) {
dprintk("mmap app bug: offset invalid [offset=0x%lx]\n",
(vma->vm_pgoff << PAGE_SHIFT));
goto done;
}
/* create mapping + update buffer list */
retval = -ENOMEM;
map = kmalloc(sizeof(struct videobuf_mapping),GFP_KERNEL);
if (NULL == map)
goto done;
pos = (unsigned long)dev->ktbuf[first].vmalloc;
while (size > 0) {
page = vmalloc_to_pfn((void *)pos);
if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) {
return -EAGAIN;
}
start += PAGE_SIZE;
pos += PAGE_SIZE;
if (size > PAGE_SIZE)
size -= PAGE_SIZE;
else
size = 0;
}
map->count = 1;
map->start = vma->vm_start;
map->end = vma->vm_end;
vma->vm_ops = &mydev_vm_ops;
vma->vm_flags |=/* VM_DONTEXPAND |*/ VM_RESERVED;
vma->vm_flags &= ~VM_IO; /* using shared anonymous pages */
vma->vm_private_data = map;
mydev_vm_open(vma);
retval = 0;
done:
return retval;
}
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: how to mmap in videobuf-dma-sg.c
2009-05-21 10:35 ` Mauro Carvalho Chehab
2009-05-21 10:48 ` Figo.zhang
@ 2010-07-24 13:43 ` Figo.zhang
[not found] ` <AANLkTimExb4hh8K5lRCRiM0IMIgsOpCw69bFvqLlQCDc@mail.gmail.com>
2 siblings, 0 replies; 7+ messages in thread
From: Figo.zhang @ 2010-07-24 13:43 UTC (permalink / raw)
To: Mauro Carvalho Chehab; +Cc: linux-media
On Thu, 2009-05-21 at 07:35 -0300, Mauro Carvalho Chehab wrote:
> Em Thu, 21 May 2009 12:46:04 +0800
> "Figo.zhang" <figo1802@gmail.com> escreveu:
>
> > hi,all,
> > I am puzzle that how to mmap ( V4L2_MEMORY_MMAP) in videobuf-dma-sg.c?
> >
> > In this file, it alloc the momery using vmalloc_32() , and put this
> > momery into sglist table,and then use dma_map_sg() to create sg dma at
> > __videobuf_iolock() function. but in __videobuf_mmap_mapper(), i canot
> > understand how it do the mmap?
> > why it not use the remap_vmalloc_range() to do the mmap?
>
> The answer is simple: remap_vmalloc_range() is newer than videobuf code. This
> part of the code was written back to kernel 2.4, and nobody cared to update it
> to use those newer functions, and simplify its code.
>
> If you want, feel free to propose some cleanups on it
thanks, in __videobuf_mmap_mapper(), it define a videobuf_vm_ops->fault,
it
will alloc a new page for mmaping when it encounter page fault
(do_page_fault),
so how the mmap() can mmap the vmalloc memory which had allocted before
using __videobuf_iolock()/vmalloc_
32() ?
Thanks,
Figo.zhang
>
>
>
> Cheers,
> Mauro
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: how to mmap in videobuf-dma-sg.c
[not found] ` <AANLkTimExb4hh8K5lRCRiM0IMIgsOpCw69bFvqLlQCDc@mail.gmail.com>
@ 2010-07-25 17:46 ` Mauro Carvalho Chehab
2010-07-26 8:16 ` Laurent Pinchart
0 siblings, 1 reply; 7+ messages in thread
From: Mauro Carvalho Chehab @ 2010-07-25 17:46 UTC (permalink / raw)
To: figo zhang; +Cc: hverkuil, linux-media, Mauro Carvalho Chehab
Em 22-07-2010 23:31, figo zhang escreveu:
>
> Em Thu, 21 May 2009 12:46:04 +0800
> "Figo.zhang" <figo1802@gmail.com <mailto:figo1802@gmail.com>> escreveu:
>
> > hi,all,
> > I am puzzle that how to mmap ( V4L2_MEMORY_MMAP) in videobuf-dma-sg.c?
> >
> > In this file, it alloc the momery using vmalloc_32() , and put this
> > momery into sglist table,and then use dma_map_sg() to create sg dma at
> > __videobuf_iolock() function. but in __videobuf_mmap_mapper(), i canot
> > understand how it do the mmap?
> > why it not use the remap_vmalloc_range() to do the mmap?
>
> The answer is simple: remap_vmalloc_range() is newer than videobuf code. This
> part of the code was written back to kernel 2.4, and nobody cared to update it
> to use those newer functions, and simplify its code.
>
>
> thanks, in __videobuf_mmap_mapper(), it define a videobuf_vm_ops->fault, it will alloc a new page for mmaping when it encounter page fault (do_page_fault),
> so how the mmap() can mmap the vmalloc memory which had allocted before using __videobuf_iolock()/vmalloc_32() ?
Sorry for not answering earlier.
The current videobuf implementation has some problems. Laurent and Pawel are working
on a new implementation that will likely solve such issues. Not sure if they already
submitted the patches, since I just return back from vacations, and I'm still trying
to handle all the backlogs on my inboxes. I haven't look at LMML posts yet.
Cheers,
Mauro.
>
> Thanks,
> Figo.zhang
>
>
>
> If you want, feel free to propose some cleanups on it
>
>
>
> Cheers,
> Mauro
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: how to mmap in videobuf-dma-sg.c
2010-07-25 17:46 ` Mauro Carvalho Chehab
@ 2010-07-26 8:16 ` Laurent Pinchart
0 siblings, 0 replies; 7+ messages in thread
From: Laurent Pinchart @ 2010-07-26 8:16 UTC (permalink / raw)
To: Mauro Carvalho Chehab
Cc: figo zhang, hverkuil, linux-media, Mauro Carvalho Chehab
Hi Mauro,
On Sunday 25 July 2010 19:46:49 Mauro Carvalho Chehab wrote:
[snip]
> The current videobuf implementation has some problems. Laurent and Pawel
> are working on a new implementation that will likely solve such issues.
> Not sure if they already submitted the patches, since I just return back
> from vacations, and I'm still trying to handle all the backlogs on my
> inboxes. I haven't look at LMML posts yet.
No patches submitted yet. It will probably still be weeks before we can submit
something.
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2010-07-26 8:16 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-21 4:46 how to mmap in videobuf-dma-sg.c Figo.zhang
2009-05-21 10:35 ` Mauro Carvalho Chehab
2009-05-21 10:48 ` Figo.zhang
2009-06-10 15:06 ` Figo.zhang
2010-07-24 13:43 ` Figo.zhang
[not found] ` <AANLkTimExb4hh8K5lRCRiM0IMIgsOpCw69bFvqLlQCDc@mail.gmail.com>
2010-07-25 17:46 ` Mauro Carvalho Chehab
2010-07-26 8:16 ` Laurent Pinchart
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox