LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   HOW to do BUFFER COPY in LINUX KERNEL (https://www.linuxquestions.org/questions/programming-9/how-to-do-buffer-copy-in-linux-kernel-4175434860/)

dgashu 10-31-2012 03:22 AM

HOW to do BUFFER COPY in LINUX KERNEL
 
Hi all ,

I am working for an DMA driver on LINUX 2.6.32.

I having having the DMA data from the device in BUFFER A[using dma_alloc_coherent] such that

char *dmasrcptr =dma_alloc_coherent(NULL,GLOBAL_BUFFER_SIZE,&dmadest,0);


Now from user space i am getting an structure which has the buffer on which need to do copy this buffer.


typedef struct {
unsigned int value;
unsigned char charbuf[GLOBAL_BUFFER_SIZE];
}driver_struct;


At present i am doing an copy to user_buffer[in structure] using an for loop.

like :-
a. I am assigning an local char pointer.
b. This pointer i am initializing to BUFFER of user structure.
c. Then using FOR loop i am acessing data from DMA buffer and storing it in user buffer [in structure] using for loop.

Can any one please let me know if there is any better method or an optimized function call.{ like MEMCPY }



Thanks
Ashish Mishra

linosaurusroot 11-01-2012 07:28 AM

This might go down better at http://kernelnewbies.org/

There are definitely functions for copying between kernel and user space. The fastest tip may be to look at an existing driver.

Tinkster 11-01-2012 02:22 PM

Moved: This thread is more suitable in <PROGRAMMING> and has been moved accordingly to help your thread/question get the exposure it deserves.

dgashu 11-02-2012 11:29 AM

Hi all ,

#include <linux/string.h>
memmove did the work for me !!!!


All times are GMT -5. The time now is 09:55 PM.