linux pcie RC 框架

2023-05-16

1. linux pcie rc framework

 

Following is a brief explanation of layers shown in the diagram:

  • There are different drivers for the connected PCIe devices like pci_endpoint_test, tg-3, r8169, xhci-pci, ahci, etc. It could be vendor-specific like most of the ethernet cards (tg3, r8169) or class-specific like xhci-pci and ahci. Each of these drivers will also interact with it’s own domain-specific stack. For example, tg3 will interface with network stack, and xhci-pci will interface with USB stack.

  • The PCI core layer scans the PCIe bus to identify and detect any PCIe devices. It also binds the driver from the layer above, for the PCIe device, based on vendorid, deviceid and class.

  • The PCI BIOS layer handles resource management. For example, allocation of memory resources for BARs.

  • The bottom-most layer consists of the PCIe platform drivers like pcie-cadence, pcie-designware, etc. pci-j721e and pci-dra7xx are TI’s wrappers over these drivers. They configure platform-specific controllers and perform actual register writes. 

另一种架构图:

  • arch pcie driver:放一些和架构强相关的pcie的函数实现,对应arch/arm64/kernel/pci.c

  • acpi pcie driver: apci扫描时所涉及到的pcie代码,包括host bridge的解析初始化,pcie bus的创建,ecam的映射等, 对应drivers/acpi/pci*.c

  • pcie core driver: pcie的子系统代码,包括pcie的枚举流程,资源分配流程,中断流程等,主要对应drivers/pci/*.c

  • pcie port bus driver: 是pcie port的四个service代码的整合, 四个service主要指的是pcie dpc/pme/hotplug/aer,对应的是drivers/pci/pcie/*

  • pcie ep driver:是叶子节点的设备驱动,比如显卡,网卡,nvme等。

2. pci device driver

基于pci core实现pci ep deivce driver

rtl8168 pcie网卡设备驱动向上与网络协议栈对接

pci_endpoint_test会虚拟成一个设备,在应用层直接通过ioctl来控制

3. pci core

kernel\linux\linux-4.19.125\drivers\pci\pci.c

3.1 register driver

pci_register_driver

module_pci_driver -> pci_register_driver

3.2 Device Initialization Steps(do this in pci device driver probe)

1) Enable the device

pci_enable_device() Before touching any device registers, the driver needs to enable the PCI device by calling pci_enable_device()

pci_set_master() will enable DMA by setting the bus master bit in the PCI_COMMAND register.

pcim_enable_device()  Managed pci_enable_device()

2) Request MMIO/IOP resources

The device driver needs to call pci_request_region() to verify no other device is already using the same address resource.

Generic flavors of pci_request_region() are request_mem_region() (for MMIO ranges) and request_region() (for IO Port ranges).

3) Set the DMA mask size (for both coherent and streaming DMA)

Drivers for all PCI-X and PCIe compliant devices must call pci_set_dma_mask() as they are 64-bit DMA devices.

4) Allocate and initialize shared control data 

pci_allocate_coherent()

5) Access device configuration space (if needed)

6) Register IRQ handler (request_irq())

request_irq()

pci_alloc_irq_vectors()

MSI capability can be enabled by calling pci_alloc_irq_vectors() with the

PCI_IRQ_MSI and/or PCI_IRQ_MSIX flags before calling request_irq().

7) Initialize non-PCI (i.e. LAN/SCSI/etc parts of the chip)

8) Enable DMA/processing engines

3.3 How to access PCI config space

pci_(read|write)_config_(byte|word|dword)

pci_bus_(read|write)_config_(byte|word|dword)

pci_find_capability()

3.4 Other interesting functions

pci_set_power_state()        Set PCI Power Management state (0=D0 ... 3=D3)

pci_find_capability()        Find specified capability in device's capability list.

pci_resource_start()        Returns bus start address for a given PCI region

pci_resource_end()        Returns bus end address for a given PCI region

pci_resource_len()        Returns the byte length of a PCI region

pci_set_drvdata()        Set private driver data pointer for a pci_dev

pci_get_drvdata()        Return private driver data pointer for a pci_dev

pci_set_mwi()            Enable Memory-Write-Invalidate transactions.

pci_clear_mwi()            Disable Memory-Write-Invalidate transactions.

pcim_set_mwi            a device-managed pci_set_mwi()

3.5 访问配置空间

pci_bus_read_config_byte

pci_bus_read_config_word

pci_bus_read_config_dword

pci_bus_write_config_byte

pci_bus_write_config_word

pci_bus_write_config_dword

3.6 other

pci_ioremap_bar(): 设备驱动程序调用pci_ioremap_bar()将写入EP BAR的总线地址(保存在resource数组中)映射到系统内存的虚拟地址,之后软件就可以通过虚拟地址访问PCI设备的存储空间

pci_remap_iospace

devm_pci_remap_cfgspace

pcim_iomap_regions

4. pci bios

linux-4.19.125/arch/arm64/kernel/pci.c

linux-4.19.125/arch/arm64/kernel/bios32.c

pcibios只有使能了CONFIG_ACPI,才会被使用。

5. pci host controller driver

5.1 dw_pcie_host_init使用到的PCI API

dw_plat_pcie_probe -> dw_plat_add_pcie_port -> dw_pcie_host_init:

  • devm_pci_alloc_host_bridge

  • devm_of_pci_get_host_bridge_resources

  • devm_request_pci_bus_resources

  • devm_pci_remap_cfgspace -> pci_remap_cfgspace

  • pci_scan_root_bus_bridge

  • pci_bus_size_bridges

  • pci_bus_assign_resources

  • pci_bus_add_devices

以上这些函数均在linux-4.19.125/drivers/pci/*中实现

也可以直接调用pci_host_probe带代替调用pci_scan_root_bus_bridge & pci_bus_size_bridges & pci_bus_assign_resources & pci_bus_add_devices这些函数

pci_host_probe -> pci_scan_root_bus_bridge & pci_bus_size_bridges & pci_bus_assign_resources & pci_bus_add_devices

如linux-4.19.125\drivers\pci\controller\pcie-cadence-host.c

cdns_pcie_host_probe -> devm_pci_alloc_host_bridge & devm_pci_remap_cfg_resource &  cdns_pcie_host_init & pci_host_probe

5.2 init RC

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

linux pcie RC 框架 的相关文章

随机推荐

  • 优化USB UVC ISO传输速度

    1 issue USB3 0单路uvc iso传输速率只有92MB s 1080p yuv 23 4fps 我们需要优化UVC传输速率 提高YUV帧率 2 analysis 2 1 ISO速度 ISO速度由mult burst max pa
  • UVC V4L2的实现

    linux 4 19 125 drivers media usb uvc uvc v4l2 c 1 uvc ops const struct v4l2 file operations uvc fops owner THIS MODULE o
  • USB3.0 PIPE接口

    1 introduction PHY Interface for the PCI Express and USB 3 0 Architectures USB SuperSpeed PHY Layer The USB SuperSpeed P
  • USB2.0 UTMI接口

    1 UTM Functional Block Diagram 2 UTMI Signal Descriptions 2 1 nbsp System Interface Signals 2 2 Data Interface Signals n
  • USB2.0 ULPI接口介绍

    UTMI Low Pin Interface ULPI nbsp a generic low pin interface LPI between a Link and a PHY 1 general ULPI defines a PHY t
  • 《IT项目管理》(郭宁编著) 课后习题答案

    目录 第一章 it项目管理概述 第二章 组织环境与项目管理过程 第三章 it项目整体管理 第四章 it项目范围管理 第五章 it项目时间管理 第六章 it项目成本管理 第七章 it项目质量管理 第八章 项目人力资源管理 第九章 项目沟通管理
  • FPGA USB device原型验证流程及调试手段

    device mode enable usb ACM usb serial gadget function and connect it to PC host 1 register access check if register acce
  • FPGA USB host原型验证流程及调试手段

    host mode plug in a device for test super speed device usb3 0 usb storage high speed device usb2 0 usb storage full spee
  • USB2.0 UTMI+接口

    1 UTMI The UTMI standard contains progressive levels of technology support because the complexity requirements for devic
  • cadence usb linux配置

    1 kernel config 2 dts
  • USB3.0 host xHCI驱动

    xHCI驱动在usb host中 主要初始化xHCI xHCI作为usb nbsp host部分的驱动 1 nbsp xhci driver与device的匹配 usb host xhci plat c static struct plat
  • windows PCIe 工具: TeleScan

    TeleScan PE for Windows 用户可以通过TeleScan PE来扫描系统中的PCI PCIe设备 xff0c 并提供了读写其配置空间中的寄存器的功能 download Teledyne LeCroy PCI Expres
  • intel 82574 1000M pcie 网卡 kernel driver

    0 kernel config Device Drivers gt Network device support gt Ethernet driver support gt Intel devices lt gt Intel R PRO 1
  • Windows NFS server:Winnfsd

    1 Winnfsd GitHub winnfsd winnfsd Usage WinNFSd exe id lt uid gt lt gid gt log on off pathFile lt file gt addr lt ip gt e
  • windows dhcp server

    1 tool Open DHCP Server Open Source Freeware Windows Linux MultiSubnet MultiDomain DHCP Server supports every Industry S
  • uboot环境变量保存到EMMC

    1 cmd 命令行可以用setenv printenv saveenv uboot u boot 2020 04 cmd nvedit c setenv gt do env set gt do env set gt hsearch r en
  • 安装VScode配置c/c++环境出现问题提示#include errors detected. Please update your includePath......解决办法

    文章目录 1 vscode下载安装以及c c 43 43 插件安装 2 MinGW安装3 配置环境变量4 配置几个json文件 1 vscode下载安装以及c c 43 43 插件安装 VScode下载地址 2 MinGW安装 官网下载地址
  • linux支持ipv6

    1 kernel config Networking support gt Networking options gt lt gt The IPv6 protocol gt 2 test 2 1 proc net if inet6 查看 p
  • 以太网 网线分类

    1 双绞线分类 一类线 xff1a 主要用于传输语音 xff08 一类标准主要用于八十年代初之前的电话线缆 xff09 xff0c 不同于数据传输 二类线 xff1a 传输频率为1MHZ xff0c 用于语音传输和最高传输速率4Mbps的数
  • linux pcie RC 框架

    1 linux pcie rc framework Following is a brief explanation of layers shown in the diagram There are different drivers fo