首页 > 代码库 > pcie驱动 简单框架 -v1
pcie驱动 简单框架 -v1
平台: x86 赛扬 E3400
内核版本:Linux linux 3.2.1 #11 SMP Sun Nov 2 13:27:52 CST 2014 i686 i686 i386 GNU/Linux
功能:枚举如下pcie设备,其中8111为PCIE-PCI桥,上行口为PCIE PORT,下行口为PCI PORT
01:00.0 0604: 10b5:8111 (rev 21)
02:04.0 0680: 10b5:86e1 (rev aa)
源码如下:
root@linux:/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");
执行结果:
[ 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]
关于这个桥到信息,lspci -vx可以查看到:
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 0 Memory at fddf0000 (64-bit, prefetchable) [size=64K] Bus: primary=01, secondary=02, subordinate=02, sec-latency=32 I/O behind bridge: 0000c000-0000cfff Memory behind bridge: fde00000-fdefffff Capabilities: [40] Power Management version 2 Capabilities: [50] MSI: Enable- Count=1/1 Maskable- 64bit+ Capabilities: [60] Express PCI/PCI-X Bridge, MSI 00 Capabilities: [100] Power Budgeting <?> Kernel driver in use: pci_drv 00: b5 10 11 81 07 00 10 00 21 00 04 06 01 00 01 00 10: 0c 00 df fd 00 00 00 00 01 02 02 20 c0 c0 00 22 20: e0 fd e0 fd f0 ff 00 00 00 00 00 00 00 00 00 00 30: 00 00 00 00 40 00 00 00 00 00 00 00 0c 01 00 00 02:04.0 Bridge: PLX Technology, Inc. Device 86e1 (rev aa) Subsystem: PLX Technology, Inc. Device 8311 Flags: bus master, 66MHz, medium devsel, latency 32, IRQ 12 Memory 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 2 Capabilities: [48] CompactPCI hot-swap <?> Capabilities: [4c] Vital Product Data Kernel driver in use: pci_drv 00: b5 10 e1 86 07 00 b0 02 aa 00 80 06 01 20 00 00 10: 00 f0 ef fd 01 ce 00 00 00 00 ec fd 00 00 ea fd 20: 00 00 00 00 00 00 00 00 00 00 00 00 b5 10 11 83 30: 00 00 00 00 40 00 00 00 00 00 00 00 0c 01 00 00
可以看到,从驱动中读取到到config配置,和lspci -vx查看到下config区域的配置是相同的
pcie驱动 简单框架 -v1
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。