Memory mapping in X86
Sathishkumar Duraisamy
bewithsathish at gmail.com
Sat Nov 19 02:04:03 EST 2011
Hi Santhosh,
I got this thing in dmesg:
[10256.068664] driver_test:7114 map pfn RAM range req uncached-minus
for 2f866000-2f867000, got write-back.
I am writing some random numbers in mmapped memory. But I am not able
to get it from the user space.
Note:
( I have allocated memory via adc_dev.adcMemoryArea = (adcdata_t *)
__get_free_pages(GFP_KERNEL, 1); )
On Sat, Nov 19, 2011 at 12:16 PM, santhosh kumars
<karuna.linux at gmail.com> wrote:
> hi,
> what is the exact error you are getting.
> thanks,
> santosh.
>
> On Mon, Nov 14, 2011 at 10:26 AM, Sathishkumar Duraisamy
> <bewithsathish at gmail.com> wrote:
>> Hi,
>>
>> I trying to implement mmap method (And by the way I writing driver to
>> model adc). I had implemented as shown below. I am not getting the
>> result as I expected. But got some error: map pfn RAM range req
>> uncached-minus for 36a0e000-36a0f000, got write-back.
>>
>> In user space, I call mmap as follows: map_ptr = (signed short *)
>> mmap(0,ADC_USER_MEM_SIZE,PROT_READ, MAP_SHARED,fd,0);
>>
>> Am I doing anything wrong here?
>>
>>
>> static int simdrv_mmap(struct file *filp,struct vm_area_struct *vma)
>> {
>> unsigned long off = vma->vm_pgoff << PAGE_SHIFT;
>> unsigned long physical = (__pa((void *)adc_dev.adcMemoryArea) >>
>> PAGE_SHIFT) + off; // adcMemory I got via
>> __get_free_pages(GFP_KERNEL, 1);
>> unsigned long vsize = vma->vm_end - vma->vm_start;
>> unsigned long psize = __pa((void *) adc_dev.adcMemoryArea) - off;
>>
>> // Module spanning too high
>> if (vsize > psize)
>> {
>> printk(KERN_ALERT "Module spanning too high");
>> return -EINVAL;
>> }
>>
>> vma->vm_flags |= VM_IO;
>> vma->vm_flags |= VM_RESERVED;
>> vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
>>
>> if (remap_pfn_range(vma,vma->vm_start, physical,vsize,vma->vm_page_prot))
>> {
>> return -EAGAIN;
>> }
>> printk(KERN_ALERT "Sucessfully memory mapped");
>> return 0;
>> }
>>
--
Regards,
Sathishkumar D
http://flowersopenlab.weebly.com/
More information about the Kernelnewbies
mailing list