Results 1 to 3 of 3
Hello,
i'm a Linux-newbie. I just starte working with it two days ago.
I'm struggling with the same problem since then.
The problem i have is related to PCI-Device-Access. My ...
- 07-23-2009 #1Just Joined!
- Join Date
- Jul 2009
- Posts
- 2
PCI-Access
Hello,
i'm a Linux-newbie. I just starte working with it two days ago.
I'm struggling with the same problem since then.
The problem i have is related to PCI-Device-Access. My aim is to have
direct access to a pci-device, in order to read/write out data.
I wrote the following test-code, just for testing out the reading function.
If i compile this piece of code i get the following output.Code:#define __KERNEL__ #include <linux/pci.h> int main() { //Finds the first pci-device with the passed Vendor-ID and Device-ID pci_dev* pPciDevice = pci_find_dev(0xBE12, 0x3042, NULL); //... read out data... }
I installed the linux-kernel-headers and the linux-source of my kernel version and i'm pretty sure they are all included.Code:In file included from /usr/include/linux/kernel.h:18, from PCIAccessLinux.c:7: /usr/include/linux/ratelimit.h: In function ‘ratelimit’: /usr/include/linux/ratelimit.h:23: error: ‘CONFIG_HZ’ undeclared (first use in this function) /usr/include/linux/ratelimit.h:23: error: (Each undeclared identifier is reported only once /usr/include/linux/ratelimit.h:23: error: for each function it appears in.) In file included from /usr/include/linux/prefetch.h:14, from /usr/include/linux/list.h:6, from /usr/include/linux/pci.h:48, from PCIAccessLinux.c:8: /usr/include/asm/processor.h: At top level: /usr/include/asm/processor.h:112: error: ‘CONFIG_X86_L1_CACHE_SHIFT’ undeclared here (not in a function) /usr/include/asm/processor.h:112: error: requested alignment is not a constant /usr/include/asm/processor.h: In function ‘load_cr3’: /usr/include/asm/processor.h:184: error: ‘CONFIG_PAGE_OFFSETUL’ undeclared (first use in this function) /usr/include/asm/processor.h: At top level: /usr/include/asm/processor.h:233: error: requested alignment is not a constant /usr/include/asm/processor.h:270: error: requested alignment is not a constant In file included from /usr/include/linux/gfp.h:4, from /usr/include/linux/kmod.h:22, from /usr/include/linux/module.h:13, from /usr/include/linux/device.h:22, from /usr/include/linux/pci.h:53, from PCIAccessLinux.c:8: /usr/include/linux/mmzone.h:18:26: error: linux/bounds.h: No such file or directory In file included from /usr/include/linux/gfp.h:4, from /usr/include/linux/kmod.h:22, from /usr/include/linux/module.h:13, from /usr/include/linux/device.h:22, from /usr/include/linux/pci.h:53, from PCIAccessLinux.c:8: /usr/include/linux/mmzone.h:218: error: ‘MAX_NR_ZONES’ undeclared here (not in a function) In file included from /usr/include/linux/elf.h:7, from /usr/include/linux/module.h:14, from /usr/include/linux/device.h:22, from /usr/include/linux/pci.h:53, from PCIAccessLinux.c:8: /usr/include/asm/elf.h: In function ‘elf_common_init’: /usr/include/asm/elf.h:166: error: ‘struct pt_regs’ has no member named ‘r8’ /usr/include/asm/elf.h:166: error: ‘struct pt_regs’ has no member named ‘r9’ /usr/include/asm/elf.h:166: error: ‘struct pt_regs’ has no member named ‘r10’ /usr/include/asm/elf.h:166: error: ‘struct pt_regs’ has no member named ‘r11’ /usr/include/asm/elf.h:167: error: ‘struct pt_regs’ has no member named ‘r12’ /usr/include/asm/elf.h:167: error: ‘struct pt_regs’ has no member named ‘r13’ /usr/include/asm/elf.h:167: error: ‘struct pt_regs’ has no member named ‘r14’ /usr/include/asm/elf.h:167: error: ‘struct pt_regs’ has no member named ‘r15’ In file included from /usr/include/linux/module.h:21, from /usr/include/linux/device.h:22, from /usr/include/linux/pci.h:53, from PCIAccessLinux.c:8: /usr/include/asm/module.h:70:2: error: #error unknown processor family In file included from /usr/include/asm/pgtable.h:364, from /usr/include/linux/mm.h:39, from /usr/include/asm/pci.h:4, from /usr/include/linux/pci.h:983, from PCIAccessLinux.c:8: /usr/include/asm/pgtable_64.h: In function ‘native_pmd_clear’: /usr/include/asm/pgtable_64.h:114: error: incompatible type for argument 2 of ‘native_set_pmd’ /usr/include/asm/pgtable_64.h: In function ‘native_pud_clear’: /usr/include/asm/pgtable_64.h:124: error: incompatible type for argument 2 of ‘native_set_pud’ /usr/include/asm/pgtable_64.h: At top level: /usr/include/asm/pgtable_64.h:159: error: redefinition of ‘pgd_bad’ /usr/include/asm-generic/pgtable-nopud.h:26: error: previous definition of ‘pgd_bad’ was here /usr/include/asm/pgtable_64.h:164: error: redefinition of ‘pud_bad’ /usr/include/asm-generic/pgtable-nopmd.h:30: error: previous definition of ‘pud_bad’ was here In file included from /usr/include/asm/pci.h:4, from /usr/include/linux/pci.h:983, from PCIAccessLinux.c:8: /usr/include/linux/mm.h: In function ‘virt_to_head_page’: /usr/include/linux/mm.h:302: error: ‘CONFIG_PAGE_OFFSETUL’ undeclared (first use in this function) In file included from /usr/include/asm/pci.h:4, from /usr/include/linux/pci.h:983, from PCIAccessLinux.c:8: /usr/include/linux/mm.h: In function ‘lowmem_page_address’: /usr/include/linux/mm.h:591: error: ‘CONFIG_PAGE_OFFSETUL’ undeclared (first use in this function) PCIAccessLinux.c: In function ‘main’: PCIAccessLinux.c:12: error: ‘pci_dev’ undeclared (first use in this function) PCIAccessLinux.c:12: error: ‘dev’ undeclared (first use in this function)
Please help me to compile this code. I googled around half the world, but i could not resolve my problem.
Some reported they had a similar problem and resolved it using makefile... :/
PS:
i use the command
to compile with Gcc 4.3.Code:gcc -Wall -o PCIAccessLinux PCIAccessLinux.c
I have kernel 2.6.27.7-pae.
- 07-24-2009 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
You cannot run an application in user space that is using kernel space code. You need to create a kernel module and access it with the appropriate system calls, such as an ioctl(), read(), write(), etc. Since you are a Linux newbie, you really need to adsorb a bunch of kernel documentation to learn how to do this. Look at these sites for documentation:
The Linux Kernel Archives
The Linux Documentation ProjectSometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 07-25-2009 #3Just Joined!
- Join Date
- Jul 2009
- Posts
- 2
Thank you very much for this pieces of information. I was just going crazy...
I was able to fix the compiler errors above including autoconf.h and copying the files generated by executing make prepare in the top level directory of the linux source code to the include directory of gcc (/usr/include/). I had to include a path called "/usr/include/asm/mach-default/", too. But then I still got a linker error, cause i didn't link the kernel modules. I guess it's because my app is not compiled as a kernel module.
Finally I found a library that permits to access PCI in user space. It's called LIBPCI. It's working fine. But i'm not sure if it is possible to access every memory area of the device.
Are there similar free libraries fitting my requirements?
Thanx


Reply With Quote