 |
|
| Linux Forum Index » Linux Development - System » Accessing a DMA Buffer... |
|
Page 1 of 1 |
|
| Author |
Message |
| Thomas Reinemann... |
Posted: Wed Sep 30, 2009 2:28 am |
|
|
|
Guest
|
Hi,
I'm developing a PCIe Device, therefore I need some test programs and a
driver. I have to transfer data from the Device to Memory of my host
processor by DMA. This shall be happen via DMA.
Testing shall be done under Linux (Centos 4.7 kernel 2.6.9). Actually I have
a driver and a program but recieve a segmentation fault. Someone helped to
setup the driver, but he hasn't time for it.
What I'm doing in the driver
static void* pvFPGA_PCI_ReadBuffer = NULL;
pvFPGA_PCI_ReadBuffer = (void*)__get_free_pages(GFP_KERNEL | GFP_DMA,
get_order(ulFPGA_PCI_Read_SIZE));
physical = virt_to_bus((void *)pvFPGA_PCI_ReadBuffer);
if( io_remap_page_range
(vma,
vma->vm_start,
physical,
vma->vm_end - vma->vm_start,
vma->vm_page_prot)) return -EAGAIN;
vma->vm_ops = &abaxmem_remap_vm_ops;
abaxmem_vma_open(vma);
Just now the buffer is be mapped to the dev (/dev/abaxrd).
Can I read the device in a "cat" manner?
In my program I do:
fh_read = fopen ("/dev/abaxrd", "r+");
pci_read_mem = (unsigned long*) mmap (
NULL,
0x1000, /* wieviele Bytes ? */
PROT_READ | PROT_WRITE, /* lesen und schreiben */
MAP_SHARED, /* keine Kopie */
fileno(fh_read), /* Handle zum /dev */
(__off_t)offset); /* Basisadresse */
The segmentation fault happens, if I try to read from the buffer
printf ("Counter(in pci_read_mem[0..3]): %ld %ld %ld %ld\n",
pci_read_mem[0],pci_read_mem[1],pci_read_mem[2],pci_read_mem[3]);
I check, whether the mappings and all other things are successfully, they
are.
What is wrong.
If you need the whole source, please ask me.
Thank you
Tom |
|
|
| Back to top |
|
|
|
| Bill Waddington... |
Posted: Wed Sep 30, 2009 9:14 am |
|
|
|
Guest
|
On Wed, 30 Sep 2009 10:28:12 +0200, Thomas Reinemann
<tom.foren at (no spam) abaxor.de> wrote:
Quote: Hi,
I'm developing a PCIe Device, therefore I need some test programs and a
driver. I have to transfer data from the Device to Memory of my host
processor by DMA. This shall be happen via DMA.
Testing shall be done under Linux (Centos 4.7 kernel 2.6.9). Actually I have
a driver and a program but recieve a segmentation fault. Someone helped to
setup the driver, but he hasn't time for it.
What I'm doing in the driver
static void* pvFPGA_PCI_ReadBuffer = NULL;
pvFPGA_PCI_ReadBuffer = (void*)__get_free_pages(GFP_KERNEL | GFP_DMA,
get_order(ulFPGA_PCI_Read_SIZE));
physical = virt_to_bus((void *)pvFPGA_PCI_ReadBuffer);
if( io_remap_page_range
(vma,
vma->vm_start,
physical,
vma->vm_end - vma->vm_start,
vma->vm_page_prot)) return -EAGAIN;
vma->vm_ops = &abaxmem_remap_vm_ops;
abaxmem_vma_open(vma);
Just now the buffer is be mapped to the dev (/dev/abaxrd).
Can I read the device in a "cat" manner?
In my program I do:
fh_read = fopen ("/dev/abaxrd", "r+");
pci_read_mem = (unsigned long*) mmap (
NULL,
0x1000, /* wieviele Bytes ? */
PROT_READ | PROT_WRITE, /* lesen und schreiben */
MAP_SHARED, /* keine Kopie */
fileno(fh_read), /* Handle zum /dev */
(__off_t)offset); /* Basisadresse */
The segmentation fault happens, if I try to read from the buffer
printf ("Counter(in pci_read_mem[0..3]): %ld %ld %ld %ld\n",
pci_read_mem[0],pci_read_mem[1],pci_read_mem[2],pci_read_mem[3]);
I check, whether the mappings and all other things are successfully, they
are.
What is wrong.
If you need the whole source, please ask me.
Do you want to do DMA or memory-mapped I/O? You seem to be doing a
little of both. That probably won't work. Or I misunderstand...
A link to the code might help.
Bill
--
William D Waddington
william.waddington at (no spam) beezmo.com
"Even bugs...are unexpected signposts on
the long road of creativity..." - Ken Burtch |
|
|
| Back to top |
|
|
|
| Thomas Reinemann... |
Posted: Thu Oct 01, 2009 1:08 am |
|
|
|
Guest
|
Bill Waddington wrote:
Quote: On Wed, 30 Sep 2009 10:28:12 +0200, Thomas Reinemann
tom.foren at (no spam) abaxor.de> wrote:
Hi,
I'm developing a PCIe Device, therefore I need some test programs and a
driver. I have to transfer data from the Device to Memory of my host
processor by DMA. This shall be happen via DMA.
Testing shall be done under Linux (Centos 4.7 kernel 2.6.9). Actually I
have a driver and a program but recieve a segmentation fault. Someone
helped to setup the driver, but he hasn't time for it.
What I'm doing in the driver
static void* pvFPGA_PCI_ReadBuffer = NULL;
pvFPGA_PCI_ReadBuffer = (void*)__get_free_pages(GFP_KERNEL | GFP_DMA,
get_order(ulFPGA_PCI_Read_SIZE));
physical = virt_to_bus((void *)pvFPGA_PCI_ReadBuffer);
if( io_remap_page_range
(vma,
vma->vm_start,
physical,
vma->vm_end - vma->vm_start,
vma->vm_page_prot)) return -EAGAIN;
vma->vm_ops = &abaxmem_remap_vm_ops;
abaxmem_vma_open(vma);
Just now the buffer is be mapped to the dev (/dev/abaxrd).
Can I read the device in a "cat" manner?
In my program I do:
fh_read = fopen ("/dev/abaxrd", "r+");
pci_read_mem = (unsigned long*) mmap (
NULL,
0x1000, /* wieviele Bytes ? */
PROT_READ | PROT_WRITE, /* lesen und schreiben */
MAP_SHARED, /* keine Kopie */
fileno(fh_read), /* Handle zum /dev */
(__off_t)offset); /* Basisadresse */
The segmentation fault happens, if I try to read from the buffer
printf ("Counter(in pci_read_mem[0..3]): %ld %ld %ld %ld\n",
pci_read_mem[0],pci_read_mem[1],pci_read_mem[2],pci_read_mem[3]);
I check, whether the mappings and all other things are successfully, they
are.
What is wrong.
If you need the whole source, please ask me.
Do you want to do DMA or memory-mapped I/O? You seem to be doing a
little of both. That probably won't work. Or I misunderstand...
You may right. What is the difference?. I'm an FPGA Designer, not a driver
programmer. The PCIDevice makes memory write requests. Therefore I would
say DMA is needed.
Quote:
A link to the code might help.
http://www.abaxor.de/download/abaxmem.tar.gz
Thank you, Tom |
|
|
| Back to top |
|
|
|
| Bill Waddington... |
Posted: Thu Oct 01, 2009 7:23 am |
|
|
|
Guest
|
On Thu, 01 Oct 2009 09:08:48 +0200, Thomas Reinemann
<tom.foren at (no spam) abaxor.de> wrote:
Quote: Bill Waddington wrote:
On Wed, 30 Sep 2009 10:28:12 +0200, Thomas Reinemann
tom.foren at (no spam) abaxor.de> wrote:
Hi,
I'm developing a PCIe Device, therefore I need some test programs and a
driver. I have to transfer data from the Device to Memory of my host
processor by DMA. This shall be happen via DMA.
[snippage]
Quote:
If you need the whole source, please ask me.
Do you want to do DMA or memory-mapped I/O? You seem to be doing a
little of both. That probably won't work. Or I misunderstand...
You may right. What is the difference?. I'm an FPGA Designer, not a driver
programmer. The PCIDevice makes memory write requests. Therefore I would
say DMA is needed.
A link to the code might help.
http://www.abaxor.de/download/abaxmem.tar.gz
I'll try for a more detailed answer later. And have a look at your
code. In the meantime, are you using "Linux Device Drivers 3rd
Edition" as a reference? If not, you should be. There are lots of
examples in the kernel source tree too.
Here's a link to my drivers. What you need is in there, but there is
so much other stuff going on, it will be hard to dig out the DMA
parts.
http://www.tahomatech.com/DeviceDrivers.htm
I'm an old FPGA and board designer forced to wing it as a driver
writer. You would be well advised to look elsewhere for coding
examples :)
Others, please feel free to chime in w/simpler examples.
I'll post back later and try to pick out the steps to set up DMA.
Ultimately, do you want the DMA data to land in kernel memory, or
a user buffer?
Bill
--
William D Waddington
william.waddington at (no spam) beezmo.com
"Even bugs...are unexpected signposts on
the long road of creativity..." - Ken Burtch |
|
|
| Back to top |
|
|
|
| Thomas Reinemann... |
Posted: Thu Oct 01, 2009 8:42 am |
|
|
|
Guest
|
Bill Waddington wrote:
Quote: On Thu, 01 Oct 2009 09:08:48 +0200, Thomas Reinemann
tom.foren at (no spam) abaxor.de> wrote:
Bill Waddington wrote:
On Wed, 30 Sep 2009 10:28:12 +0200, Thomas Reinemann
tom.foren at (no spam) abaxor.de> wrote:
Hi,
I'm developing a PCIe Device, therefore I need some test programs and a
driver. I have to transfer data from the Device to Memory of my host
processor by DMA. This shall be happen via DMA.
[snippage]
If you need the whole source, please ask me.
Do you want to do DMA or memory-mapped I/O? You seem to be doing a
little of both. That probably won't work. Or I misunderstand...
You may right. What is the difference?. I'm an FPGA Designer, not a driver
programmer. The PCIDevice makes memory write requests. Therefore I would
say DMA is needed.
A link to the code might help.
http://www.abaxor.de/download/abaxmem.tar.gz
I'll try for a more detailed answer later. And have a look at your
code. In the meantime, are you using "Linux Device Drivers 3rd
Edition" as a reference? If not, you should be.
Do you mean lwn.net/Kernel/LDD3/, yes I read it the Chapter 15. But the guy,
who setup the driver for me followed a different approach.
Quote: I'm an old FPGA and board designer forced to wing it as a driver
writer.
I started with the first Xilinx devices in the early 1990s.
Quote: There are lots of
examples in the kernel source tree too.
Yes, but I'm looking for a test utility. The driver will be only used
therfore. It don't be very advanced.
Quote: Ultimately, do you want the DMA data to land in kernel memory, or
a user buffer?
It seems I've problems to access the kernel memory, mapped to a device. A
user buffer would be better, I think.
Tom |
|
|
| Back to top |
|
|
|
|
|
All times are GMT - 5 Hours
The time now is Tue Dec 01, 2009 12:44 pm
|
|