userspace address to bus address

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
I'm currently writing my first kernel module, but i got stuck with address
translations. I want my pcie device to access a buffer which was allocated
in userspace (page aligned, currently smaller than one page to ignore
scattering). I tried to translate the userspace address to a bus address
in my ioctrl handler like this:

void __user *data = arg;
down_read(&current->mm->mmap_sem);
get_user_pages(current, current->mm, (unsigned long)data, len/*1*/, 1, 0,
&pages, NULL);
up_read(&current->mm->mmap_sem);
void* kvaddr = kmap(pages[0]);
unsigned long baddr = virt_to_bus(kaddr);
kunmap(pages[0]);
page_cache_release(pages[0]);
//...

data is page-aligned and was locked in userspace with mlock.
There is some address in baddr, but the device does not write to the
correct location and sometimes causes kernel freezes. Can someone tell me,
what is wrong with this code?TheI device works with a address, that was
received in different way (closed source driver).
I use 32 bit Ubuntu with an 2.6.32 kernel.


_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux