map kernel buffer into user space

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

 



Hi,

I have allocated a PCI buffer which is accessible by another device.
This is done by the following code (ioctl).

----

TSStreamPci currentstream;
unsigned size;
                
DBG("FUNCTIONCALL: %s at %d (PPC2DSP_MAP_PCI)\n", __FUNCTION__, __LINE__);
        
copy_from_user(&currentstream, (TSStreamPci *) arg, sizeof(TSStreamPci));

/* Make certain that we have a valid source */
legacyptr->xfersize = size =
max(currentstream.__from_kernel_size,currentstream.__to_kernel_size);
                
/* before mapping, make certain that the stream was not already mapped */
if(legacyptr->bus_addr){}
else if(!(legacyptr->kern_addr = 

pci_alloc_consistent(legacyptr->dev,size,&(legacyptr->bus_addr)))){
  currentstream.pciaddress=0x0;
  copy_to_user((TSStreamPci*)arg,&currentstream,sizeof(TSStreamPci));
  return -ENXIO;
}
currentstream.pciaddress = legacyptr->bus_addr;
                                
copy_to_user((TSStreamPci*)arg,&currentstream,sizeof(TSStreamPci));
break;

-----

By passing along the bus address to the other device, it can read the
memory and initiate DMA transfers. The xfer size is PAGE_SIZE.

Currently, the data is generated in userspace and copied into this
buffer. Since we are pumping quite some data to the other device, I
would like to map this buffer into userspace with
  remap_page_range

I would assume that I pass the bus address or the kernel address in
some way and obtain some address 0xXXXX that can be used in userspace.

However, when I try to read the documentation and reverse engineer the
little examples I found (could be that I am just looking in the wrong
places), I cannot make out such a thing.

I am currently trying something along the lines of

if (remap_page_range(vma, vma->vm_start, legacyptr->kern_addr, PAGE_SIZE,
  vma->vm_page_prot)) {
  printk(KERN_ERR DRV_NAME ": remap_page_range failed in %s\n", __FILE__);
  return -EAGAIN;
}

But I am not quite certain what address I can use now, nor the real
use of the vma structures...

-- 
ash nazg durbatulûk, ash nazg gimbatul,
ash nazg thrakatulûk agh burzum-ishi krimpatul

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/




[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