Hi,
I'm just writing some code that wants to implement a stupid mmap on a 
device.
What  I did is the following:
1 - allocating a buffer with kmalloc:
        kmalloc_ptr = kmalloc(LEN + 2 * PAGE_SIZE, GFP_KERNEL);
2 - make sure that it's page aligned:
        kmalloc_area = (kmalloc_ptr + PAGE_SIZE -1) & PAGE_MASK;
  ( _area and _ptr point to the same address, though )
3 - fill it with some dumb numbers and print them to check:
        for( i = 0; i < LEN; i++) {
                ((unsigned char*)kmalloc_area)[i] = (unsigned char)i;
        }
        for( i = 0; i < 20; i++) {
                printk(" %d ",( (unsigned char*)kmalloc_area)[i]);
        }
4 - in properly registered mmap, driver side, i wrote simply:
      ret = remap_pfn_range(vma, vma->vm_start,
             virt_to_phys(kmalloc_area) >> PAGE_SHIFT,
             vma->vm_end-vma->vm_start, vma->vm_page_prot);

Ok, what's wrong with that? From a userspace test program, I got only 
zeroes:
   fd = open("/dev/mmaptest",O_RDWR);
   mmapped_ptr = mmap(NULL,SIZE,PROT_READ | PROT_WRITE, MAP_FILE | 
MAP_SHARED ,fd,0);
   for( i=0; i < SIZE; i++){
       printf(" i=%d, mmap[%d]=%d\n",i,i,mmapped_ptr[i]);
   }
and that's the output:
 i=0, mmap[0]=0
 i=1, mmap[1]=0
 i=2, mmap[2]=0
...

Side notes:
- my machine has no swap, so there's no need to lock pages to prevent them 
from being swapped.
- this code works fine on a i386 architecture (unexpectedly)

I'm clearly missing something trivial, and probably need more coffe... ;)
Ideas? 
Thanks in advance.
-- 
Andrea Gasparini 
---- ImaVis S.r.l. ----
web: www.imavis.com


_______________________________________________
Davinci-linux-open-source mailing list
[email protected]
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source

Reply via email to