PCIe driver simple framework-V1

Source: Internet
Author: User

Platform: x86 saiyang e3400

Kernel version: Linux 3.2.1 #11 SMP sun Nov 2 13:27:52 CST 2014 i686 i686 i386 GNU/Linux

Function: enumerate the following PCIe devices, where 8111 is the PCIE-PCI bridge, the uplink port is the PCIe port, and the downlink port is the PCI port.

. 0 0604: 10b5: 8111 (Rev 21)
0:04. 0 0680: 10b5: 86e1 (Rev aa)


The source code is as follows:

[email protected]:/study/driver/kobox/src/pcie_frame# cat pcie_drv.c #include <linux/kernel.h>#include <linux/module.h>#include <linux/pci.h>#include <linux/init.h>static struct pci_device_id pci_drv_ids[] = {{PCI_DEVICE(0x10b5, 0x8111), },{PCI_DEVICE(0x10b5, 0x86e1), },{0, }};MODULE_DEVICE_TABLE(pci, pci_drv_ids);static int pci_drv_probe(struct pci_dev *dev, const struct pci_device_id *d){int i;unsigned uiVal;printk("Enter [%s][%d]\n", __FUNCTION__, __LINE__);printk("\n*********************************************\n");for(i=0; i<0x40; i+=4){pci_read_config_dword(dev, i, &uiVal);printk("[addr:%03x] [hex:%08x]\n", i, uiVal);}printk("\n*********************************************\n");printk("Leave [%s][%d]\n", __FUNCTION__, __LINE__);return 0;}static void pci_drv_remove(struct pci_dev *dev){return;}static struct pci_driver pci_drv_ops = {.name = "pci_drv",.id_table = pci_drv_ids,.probe = pci_drv_probe,.remove = pci_drv_remove,};static int __init pci_drv_init(void){return pci_register_driver(&pci_drv_ops);}static void __exit pci_drv_exit(void){pci_unregister_driver(&pci_drv_ops);}module_init(pci_drv_init);module_exit(pci_drv_exit);MODULE_LICENSE("GPL");

Execution result:

[ 7539.354646] *********************************************[ 7539.354653] [addr:000] [hex:811110b5][ 7539.354659] [addr:004] [hex:00100007][ 7539.354664] [addr:008] [hex:06040021][ 7539.354669] [addr:00c] [hex:00010001][ 7539.354675] [addr:010] [hex:fddf000c][ 7539.354680] [addr:014] [hex:00000000][ 7539.354685] [addr:018] [hex:20020201][ 7539.354690] [addr:01c] [hex:2200c0c0][ 7539.354696] [addr:020] [hex:fde0fde0][ 7539.354701] [addr:024] [hex:0000fff0][ 7539.354706] [addr:028] [hex:00000000][ 7539.354711] [addr:02c] [hex:00000000][ 7539.354716] [addr:030] [hex:00000000][ 7539.354721] [addr:034] [hex:00000040][ 7539.354726] [addr:038] [hex:00000000][ 7539.354731] [addr:03c] [hex:0000010c][ 7539.354734] [ 7539.354735] *********************************************[ 7539.354738] Leave [pci_drv_probe][31][ 7539.354765] Enter [pci_drv_probe][20][ 7539.354767] [ 7539.354768] *********************************************[ 7539.354774] [addr:000] [hex:86e110b5][ 7539.354780] [addr:004] [hex:02b00007][ 7539.354785] [addr:008] [hex:068000aa][ 7539.354790] [addr:00c] [hex:00002001][ 7539.354796] [addr:010] [hex:fdeff000][ 7539.354801] [addr:014] [hex:0000ce01][ 7539.354806] [addr:018] [hex:fdec0000][ 7539.354812] [addr:01c] [hex:fdea0000][ 7539.354817] [addr:020] [hex:00000000][ 7539.354822] [addr:024] [hex:00000000][ 7539.354827] [addr:028] [hex:00000000][ 7539.354833] [addr:02c] [hex:831110b5][ 7539.354838] [addr:030] [hex:00000000][ 7539.354843] [addr:034] [hex:00000040][ 7539.354849] [addr:038] [hex:00000000][ 7539.354854] [addr:03c] [hex:0000010c][ 7539.354856] [ 7539.354857] *********************************************[ 7539.354861] Leave [pci_drv_probe][31]


For information about the bridge to lspci-VX, you can view the following information:

01:00.0 PCI bridge: PLX Technology, Inc. PEX 8111 PCI Express-to-PCI Bridge (rev 21) (prog-if 00 [Normal decode])Flags: bus master, fast devsel, latency 0Memory at fddf0000 (64-bit, prefetchable) [size=64K]Bus: primary=01, secondary=02, subordinate=02, sec-latency=32I/O behind bridge: 0000c000-0000cfffMemory behind bridge: fde00000-fdefffffCapabilities: [40] Power Management version 2Capabilities: [50] MSI: Enable- Count=1/1 Maskable- 64bit+Capabilities: [60] Express PCI/PCI-X Bridge, MSI 00Capabilities: [100] Power Budgeting <?>Kernel driver in use: pci_drv00: b5 10 11 81 07 00 10 00 21 00 04 06 01 00 01 0010: 0c 00 df fd 00 00 00 00 01 02 02 20 c0 c0 00 2220: e0 fd e0 fd f0 ff 00 00 00 00 00 00 00 00 00 0030: 00 00 00 00 40 00 00 00 00 00 00 00 0c 01 00 0002:04.0 Bridge: PLX Technology, Inc. Device 86e1 (rev aa)Subsystem: PLX Technology, Inc. Device 8311Flags: bus master, 66MHz, medium devsel, latency 32, IRQ 12Memory at fdeff000 (32-bit, non-prefetchable) [size=512]I/O ports at ce00 [size=256]Memory at fdec0000 (32-bit, non-prefetchable) [size=128K]Memory at fdea0000 (32-bit, non-prefetchable) [size=128K]Capabilities: [40] Power Management version 2Capabilities: [48] CompactPCI hot-swap <?>Capabilities: [4c] Vital Product DataKernel driver in use: pci_drv00: b5 10 e1 86 07 00 b0 02 aa 00 80 06 01 20 00 0010: 00 f0 ef fd 01 ce 00 00 00 00 ec fd 00 00 ea fd20: 00 00 00 00 00 00 00 00 00 00 00 00 b5 10 11 8330: 00 00 00 00 40 00 00 00 00 00 00 00 0c 01 00 00

As you can see, the config configuration is read from the driver, and the configuration in the config area is the same as that in lspci-VX.


PCIe driver simple framework-V1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.