copy_to_user hangs system on buffers >= 4K bytes
Hello, I'm having trouble with returning data from my char driver's read method. During "probe" driver intialization I request a DMA buffer for my pci-express device like this:
Code:
my_device.dma_cpu_addr = pci_alloc_consistent(dev, DMA_MEM_SIZE, &my_device.dma_phy_handle);
in my read method I basically do this (watered down code)
Code:
byte [] buffer[nbytes];
memcpy_fromio( &buffer, my_device.dma_cpu_addr + my_device.offset, nbytes);
copy_to_user(buf, &buffer, nbytes);
*ppos += nbytes;
return nbytes;
This works well as long as nbytes is less than 4K. At 4K the system absolutely freezes. At first I assumed this maybe had to do with PAGE_SIZE limits, so I decided to loop the 'memcpy' and 'copy_to_user' calls multiple times in incrments less than 4K (I started with 1K). This also would result in system hangs. Perhaps is there something with my intermediate "buffer" array? Could I just directly copy from I/O memory to user space without using an intermediate buffer? Thank for taking the time to read this.