setpci设定PCIe寄存器

news/2024/12/22 10:55:02/

PCIe寄存器信息读取、分析、配置

  • 1.获取bdf (bus:device.function)地址
  • 2.根据bdf地址抓取pci信息
  • 3.结合PCIe Spec对读到的信息进行分析
  • 使用setpci修改

1.获取bdf (bus:device.function)地址

在Linux系统下使用命令:
ls -l /sys/block | grep nvme 可以得到nvme硬盘的bdf地址:其中 0000:00:02.1为root port
0000:01:00.0为 endpoint,我们下面使用setpci时会需要涉及到

lrwxrwxrwx. 1 root root 0 Nov  4 15:25 nvme0n1 -> ../devices/pci0000:00/0000:00:02.1/0000:01:00.0/nvme/nvme0/nvme0n1

2.根据bdf地址抓取pci信息

使用lspci -vvvxxx -s $bdf 可以抓取pci寄存器的讯息
我的电脑下抓到的信息如下:
硬盘的bdf:

[root@localhost ~]# lspci -vvvxxx -s 01:00.0
01:00.0 Non-Volatile memory controller: Samsung Electronics Co Ltd NVMe SSD Controller SM981/PM981/PM983 (prog-if 02 [NVM Express])Subsystem: Samsung Electronics Co Ltd Device a801Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx+Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-Latency: 0, Cache Line Size: 64 bytesInterrupt: pin A routed to IRQ 48NUMA node: 0Region 0: Memory at c0800000 (64-bit, non-prefetchable) [size=16K]Capabilities: [40] Power Management version 3Flags: PMEClk- DSI- D1- D2- AuxCurrent=0mA PME(D0-,D1-,D2-,D3hot-,D3cold-)Status: D0 NoSoftRst+ PME-Enable- DSel=0 DScale=0 PME-Capabilities: [50] MSI: Enable- Count=1/32 Maskable- 64bit+Address: 0000000000000000  Data: 0000Capabilities: [70] Express (v2) Endpoint, MSI 00DevCap: MaxPayload 256 bytes, PhantFunc 0, Latency L0s unlimited, L1 unlimitedExtTag- AttnBtn- AttnInd- PwrInd- RBE+ FLReset+ SlotPowerLimit 0.000WDevCtl: Report errors: Correctable+ Non-Fatal+ Fatal+ Unsupported+RlxdOrd+ ExtTag- PhantFunc- AuxPwr- NoSnoop+ FLReset-MaxPayload 256 bytes, MaxReadReq 512 bytesDevSta: CorrErr- UncorrErr- FatalErr- UnsuppReq- AuxPwr- TransPend-LnkCap: Port #0, Speed 8GT/s, Width x4, ASPM L1, Exit Latency L0s unlimited, L1 <64usClockPM+ Surprise- LLActRep- BwNot- ASPMOptComp+LnkCtl: ASPM L1 Enabled; RCB 64 bytes Disabled- CommClk+ExtSynch- ClockPM+ AutWidDis- BWInt- AutBWInt-LnkSta: Speed 8GT/s, Width x4, TrErr- Train- SlotClk+ DLActive- BWMgmt- ABWMgmt-DevCap2: Completion Timeout: Range ABCD, TimeoutDis+, LTR+, OBFF Not SupportedDevCtl2: Completion Timeout: 50us to 50ms, TimeoutDis-, LTR+, OBFF DisabledLnkCtl2: Target Link Speed: 8GT/s, EnterCompliance- SpeedDis-Transmit Margin: Normal Operating Range, EnterModifiedCompliance- ComplianceSOS-Compliance De-emphasis: -6dBLnkSta2: Current De-emphasis Level: -3.5dB, EqualizationComplete+, EqualizationPhase1+EqualizationPhase2+, EqualizationPhase3+, LinkEqualizationRequest-Capabilities: [b0] MSI-X: Enable+ Count=33 Masked-Vector table: BAR=0 offset=00003000PBA: BAR=0 offset=00002000Capabilities: [100 v2] Advanced Error ReportingUESta:  DLP- SDES- TLP- FCP- CmpltTO- CmpltAbrt- UnxCmplt- RxOF- MalfTLP- ECRC- UnsupReq- ACSViol-UEMsk:  DLP- SDES- TLP- FCP- CmpltTO- CmpltAbrt- UnxCmplt- RxOF- MalfTLP- ECRC- UnsupReq- ACSViol-UESvrt: DLP+ SDES+ TLP- FCP+ CmpltTO- CmpltAbrt- UnxCmplt- RxOF+ MalfTLP+ ECRC- UnsupReq- ACSViol-CESta:  RxErr- BadTLP- BadDLLP- Rollover- Timeout- NonFatalErr-CEMsk:  RxErr- BadTLP- BadDLLP- Rollover- Timeout- NonFatalErr+AERCap: First Error Pointer: 00, GenCap+ CGenEn- ChkCap+ ChkEn-Capabilities: [148 v1] Device Serial Number 00-00-00-00-00-00-00-00Capabilities: [158 v1] Power Budgeting <?>Capabilities: [168 v1] #19Capabilities: [188 v1] Latency Tolerance ReportingMax snoop latency: 1048576nsMax no snoop latency: 1048576nsCapabilities: [190 v1] L1 PM SubstatesL1SubCap: PCI-PM_L1.2+ PCI-PM_L1.1+ ASPM_L1.2+ ASPM_L1.1+ L1_PM_Substates+PortCommonModeRestoreTime=10us PortTPowerOnTime=10usKernel driver in use: nvmeKernel modules: nvme
00: 4d 14 08 a8 06 04 10 00 00 02 08 01 10 00 00 00
10: 04 00 80 c0 00 00 00 00 00 00 00 00 00 00 00 00
20: 00 00 00 00 00 00 00 00 00 00 00 00 4d 14 01 a8
30: 00 00 00 00 40 00 00 00 00 00 00 00 04 01 00 00
40: 01 50 03 00 08 00 00 00 00 00 00 00 00 00 00 00
50: 05 70 8a 00 00 00 00 00 00 00 00 00 00 00 00 00
60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
70: 10 b0 02 00 c1 8f 00 10 3f 28 00 00 43 78 47 00
80: 42 01 43 10 00 00 00 00 00 00 00 00 00 00 00 00
90: 00 00 00 00 1f 08 00 00 00 04 00 00 0e 00 00 00
a0: 03 00 1f 00 00 00 00 00 00 00 00 00 00 00 00 00
b0: 11 00 20 80 00 30 00 00 00 20 00 00 00 00 00 00
c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
d0: 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

root port端的信息:

[root@localhost ~]# lspci -vvvxxx -s 00:02.1
00:02.1 PCI bridge: Advanced Micro Devices, Inc. [AMD] Renoir PCIe GPP Bridge (prog-if 00 [Normal decode])Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx+Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-Latency: 0, Cache Line Size: 64 bytesInterrupt: pin ? routed to IRQ 26Bus: primary=00, secondary=01, subordinate=01, sec-latency=0I/O behind bridge: 0000f000-00000fffMemory behind bridge: c0800000-c08fffffPrefetchable memory behind bridge: 00000000fff00000-00000000000fffffSecondary status: 66MHz- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- <SERR- <PERR-BridgeCtl: Parity- SERR- NoISA- VGA- MAbort- >Reset- FastB2B-PriDiscTmr- SecDiscTmr- DiscTmrStat- DiscTmrSERREn-Capabilities: [50] Power Management version 3Flags: PMEClk- DSI- D1- D2- AuxCurrent=0mA PME(D0+,D1-,D2-,D3hot+,D3cold+)Status: D0 NoSoftRst- PME-Enable- DSel=0 DScale=0 PME-Capabilities: [58] Express (v2) Root Port (Slot+), MSI 00DevCap: MaxPayload 512 bytes, PhantFunc 0ExtTag+ RBE+DevCtl: Report errors: Correctable- Non-Fatal- Fatal- Unsupported-RlxdOrd+ ExtTag+ PhantFunc- AuxPwr- NoSnoop+MaxPayload 256 bytes, MaxReadReq 512 bytesDevSta: CorrErr- UncorrErr- FatalErr- UnsuppReq- AuxPwr- TransPend-LnkCap: Port #1, Speed 8GT/s, Width x4, ASPM L1, Exit Latency L0s unlimited, L1 <64usClockPM- Surprise- LLActRep+ BwNot+ ASPMOptComp+LnkCtl: ASPM L1 Enabled; RCB 64 bytes Disabled- CommClk+ExtSynch- ClockPM- AutWidDis- BWInt- AutBWInt-LnkSta: Speed 8GT/s, Width x4, TrErr- Train- SlotClk+ DLActive+ BWMgmt+ ABWMgmt-SltCap: AttnBtn- PwrCtrl- MRL- AttnInd- PwrInd- HotPlug- Surprise-Slot #0, PowerLimit 0.000W; Interlock- NoCompl+SltCtl: Enable: AttnBtn- PwrFlt- MRL- PresDet- CmdCplt- HPIrq- LinkChg-Control: AttnInd Unknown, PwrInd Unknown, Power- Interlock-SltSta: Status: AttnBtn- PowerFlt- MRL- CmdCplt- PresDet+ Interlock-Changed: MRL- PresDet- LinkState+RootCtl: ErrCorrectable- ErrNon-Fatal- ErrFatal- PMEIntEna+ CRSVisible+RootCap: CRSVisible+RootSta: PME ReqID 0000, PMEStatus- PMEPending-DevCap2: Completion Timeout: Range ABCD, TimeoutDis+, LTR+, OBFF Not Supported ARIFwd+DevCtl2: Completion Timeout: 65ms to 210ms, TimeoutDis-, LTR+, OBFF Disabled ARIFwd-LnkCtl2: Target Link Speed: 8GT/s, EnterCompliance- SpeedDis-Transmit Margin: Normal Operating Range, EnterModifiedCompliance- ComplianceSOS-Compliance De-emphasis: -6dBLnkSta2: Current De-emphasis Level: -3.5dB, EqualizationComplete+, EqualizationPhase1+EqualizationPhase2+, EqualizationPhase3+, LinkEqualizationRequest-Capabilities: [a0] MSI: Enable+ Count=1/1 Maskable- 64bit+Address: 00000000fee00000  Data: 0000Capabilities: [c0] Subsystem: Advanced Micro Devices, Inc. [AMD] Device 1453Capabilities: [c8] HyperTransport: MSI Mapping Enable+ Fixed+Capabilities: [100 v1] Vendor Specific Information: ID=0001 Rev=1 Len=010 <?>Capabilities: [270 v1] #19Capabilities: [2a0 v1] Access Control ServicesACSCap: SrcValid+ TransBlk+ ReqRedir+ CmpltRedir+ UpstreamFwd+ EgressCtrl- DirectTrans+ACSCtl: SrcValid+ TransBlk- ReqRedir+ CmpltRedir+ UpstreamFwd+ EgressCtrl- DirectTrans-Capabilities: [370 v1] L1 PM SubstatesL1SubCap: PCI-PM_L1.2+ PCI-PM_L1.1+ ASPM_L1.2+ ASPM_L1.1+ L1_PM_Substates+PortCommonModeRestoreTime=10us PortTPowerOnTime=150usCapabilities: [380 v1] Downstream Port ContainmentDpcCap: INT Msg #0, RPExt+ PoisonedTLP+ SwTrigger+ RP PIO Log 6, DL_ActiveErr+DpcCtl: Trigger:0 Cmpl- INT- ErrCor- PoisonedTLP- SwTrigger- DL_ActiveErr-DpcSta: Trigger- Reason:00 INT- RPBusy- TriggerExt:00 RP PIO ErrPtr:1fSource: 0000Capabilities: [400 v1] #25Capabilities: [410 v1] #26Capabilities: [440 v1] #27Kernel driver in use: pcieport
00: 22 10 34 16 07 04 10 00 00 00 04 06 10 00 81 00
10: 00 00 00 00 00 00 00 00 00 01 01 00 f1 01 00 00
20: 80 c0 80 c0 f1 ff 01 00 00 00 00 00 00 00 00 00
30: 00 00 00 00 50 00 00 00 00 00 00 00 ff 00 00 00
40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
50: 01 58 03 c8 00 00 00 00 10 a0 42 01 22 80 00 00
60: 30 29 00 00 43 78 73 01 42 00 43 70 00 00 04 00
70: 00 00 40 01 18 00 01 00 00 00 00 00 bf 19 70 00
80: 06 04 00 00 0e 00 00 00 03 00 1f 00 00 00 00 00
90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
a0: 05 c0 81 00 00 00 e0 fe 00 00 00 00 00 00 00 00
b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
c0: 0d c8 00 00 22 10 53 14 08 00 03 a8 00 00 00 00
d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

3.结合PCIe Spec对读到的信息进行分析

比如我需要抓取盘端的MaxPayload值,lspci下可以看到如下讯息:

 Capabilities: [70] Express (v2) Endpoint, MSI 00DevCap: MaxPayload 256 bytes, PhantFunc 0, Latency L0s unlimited, L1 unlimitedExtTag- AttnBtn- AttnInd- PwrInd- RBE+ FLReset+ SlotPowerLimit 0.000W

使用setpci也可以抓到:

[root@localhost ~]# setpci -s 01:00.0 70+04.w
8fc1

可以看到, -s 01:00.0 是盘的bdf,那么后面的 70+04.w是什么意思呢?
70对应 lspci读到的 Capabilities的起始位, +04 代表偏移量,这里的偏移量取自PCIe Spec的规定
w 代表两个字节
在这里插入图片描述
在这里插入图片描述
如上,我们抓到的值为 8fc1,16进制,转换为2进制为 1000 1111 1100 0001 ,参考上图:Max_Payload_Size Supported 对应 0-2 bit,因此这里得到的值为 1000 1111 1100 0001,此处001再参照PCIe Spec,得到值为256在这里插入图片描述
这个就是如何去参考lspci信息和Spec去抓取我们想要的信息。注意上图中 register Description 栏下的 RO 代表 read only,即此处的值是不可被修改的,后续我们再将如何对可以修改的项目进行修改

使用setpci修改

在这里插入图片描述

如上图,我们准备对此项进行修改,对照Spec,知道偏移量为 14h
参考lspci信息,起始位为100

        Capabilities: [100 v2] Advanced Error ReportingUESta:  DLP- SDES- TLP- FCP- CmpltTO- CmpltAbrt- UnxCmplt- RxOF- MalfTLP- ECRC- UnsupReq- ACSViol-UEMsk:  DLP- SDES- TLP- FCP- CmpltTO- CmpltAbrt- UnxCmplt- RxOF- MalfTLP- ECRC- UnsupReq- ACSViol-UESvrt: DLP+ SDES+ TLP- FCP+ CmpltTO- CmpltAbrt- UnxCmplt- RxOF+ MalfTLP+ ECRC- UnsupReq- ACSViol-CESta:  RxErr- BadTLP- BadDLLP- Rollover- Timeout- NonFatalErr-CEMsk:  RxErr- BadTLP- BadDLLP- Rollover- Timeout- NonFatalErr+AERCap: First Error Pointer: 00, GenCap+ CGenEn- ChkCap+ ChkEn-

下命令抓取现在的值:

[root@localhost ~]# setpci -s 01:00.0 100+14.w
e000

转为2进制 1110 0000 0000 0000, spec定义第6位,默认为0
我们将第6位置为1,得到 1110 0000 0100 0000,16进制为e040
于是命令如下:
直接再后面加=e040赋值即可修改,修改完成后,再次读回来,返回生效

[root@localhost ~]# setpci -s 01:00.0 100+14.w=e040
[root@localhost ~]# setpci -s 01:00.0 100+14.w
e040
[root@localhost ~]#

我们再lspci -vvvxxx -s bdf看一下现在显示是怎么样的

CEMsk:  RxErr- BadTLP+ BadDLLP- Rollover- Timeout- NonFatalErr+

可以看到原来 CEMsk是 BadTLP-,我们将其置一后,现在是BadTLP+,修改生效

此方法同样适用于修改LinkSpeed及LinkDisable等项,用法和参照方法是一样的


http://www.ppmy.cn/news/1204821.html

相关文章

C# set的一些使用方法

在C#应用中&#xff0c;使用set监控值的改变触发事件是一种非常常见的编程模式。 比如下面一些应用。 1、属性更改通知&#xff1a;当某个属性的值发生变化时&#xff0c;可以使用set监控属性的改变&#xff0c;并触发一个事件来通知其他部分代码。这在MVVM&#xff08;Model…

工作应该选择稳定的、工资低的?还是有挑战的工资高的?

工作应该选择稳定的、工资低的&#xff1f;还是有挑战的工资高的&#xff1f; 这个问题曾经深深的困扰着我&#xff0c;在我毕业面临择业的时候以及刚毕业的一段时间&#xff0c;我一直被这个问题困扰。 2019年秋招时候&#xff0c;我室友只面试了几家公司&#xff0c;就拿到…

【mapboxgl源码解析】深度测试问题

mapbox所有图层深度测试 globeAtmosphere&#xff08;不写深度&#xff09; new DepthMode(gl.LEQUAL, DepthMode.ReadOnly, [0, 1]); circle&#xff08;不写深度&#xff09; painter.depthModeForSublayer(0, DepthMode.ReadOnly); line&#xff08;不写深度&#xff09; p…

程序员可以做哪些副业?我整理的千字副业指南。

都说不想做副业的程序员不是好程序员&#xff0c;尤其是在经济形势不好的现在&#xff0c;有一份靠谱和稳定的副业更是成为了程序员的不二之选。程序员的副业是细水长流型的&#xff0c;虽然收入未必能超过主业&#xff0c;但胜在每月稳定入账&#xff0c;可以作为小金库和备用…

Python教程之Python中文件路径

文章目录 前言一、Python中文件路径1.绝对路径和相对路径2.目录中的斜杠们3.正则表达式中的斜杠们 二、什么是文件路径&#xff0c;Python中如何书写文件路径&#xff1f;1.Windows上的反斜杠以及OS X和Linux上的正斜杠关于Python技术储备一、Python所有方向的学习路线二、Pyth…

昇腾CANN 7.0 黑科技:大模型推理部署技术解密

CANN作为最接近昇腾AI系列硬件产品的一层&#xff0c;通过软硬件联合设计&#xff0c;打造出适合昇腾AI处理器的软件架构&#xff0c;充分使能和释放昇腾硬件的澎湃算力。针对大模型推理场景&#xff0c;CANN最新发布的CANN 7.0版本有机整合各内部组件&#xff0c;支持大模型的…

AD教程 (十)Value值的核对

AD教程 &#xff08;十&#xff09;Value值的核对 填写器件位号 直接根据原理图的原始编号进行更改 通过位号编辑器快速更改 点击工具&#xff0c;选择标注&#xff0c;选择原理图标注&#xff0c;进入位号编辑器 可以在位号编辑器中 设置处理顺序&#xff0c;从上往下还是从…

[ACTF2020 新生赛]BackupFile 1

题目环境&#xff1a; 好好好&#xff0c;让找源文件是吧&#xff1f;咱们二话不说直接扫它后台 使用dirsearch工具扫描网站后台&#xff08;博主有这个工具的压缩包&#xff0c;可以私聊我领取&#xff09;python dirsearch.py -u http://0d418151-ebaf-4f26-86b2-5363ed16530…