使用 setpci 配置 PCI 设备

下面快速记录一下使用 setpci命令配置 PCI设备的步骤。
首先,简单看一下 setpci的使用方法:

$ setpci --help
Usage: setpci [<options>] (<device>+ <reg>[=<values>]*)*

General options:
-f		Don't complain if there's nothing to do
-v		Be verbose
-D		List changes, don't commit them
-r		Use raw access without bus scan if possible
--dumpregs	Dump all known register names and exit

PCI access options:
-A <method>	Use the specified PCI access method (see '-A help' for a list)
-O <par>=<val>	Set PCI access parameter (see '-O help' for a list)
-G		Enable PCI access debugging
-H <mode>	Use direct hardware access (<mode> = 1 or 2)

Setting commands:
<device>:	-s [[[<domain>]:][<bus>]:][<slot>][.[<func>]]
			-d [<vendor>]:[<device>]
<reg>:		<base>[+<offset>][.(B|W|L)][@<number>]
<base>:		<address>
			<named-register>
			[E]CAP_<capability-name>
			[E]CAP<capability-number>
<values>:	<value>[,<value>...]
<value>:	<hex>
			<hex>:<mask>

稍微有点复杂,但其实用法很简单。

需要明确的一点是,PCI设备的配置空间共由 64个字节组成,其地址范围为 0x00 ~ 0x3F,这 64个字节是所有 PCI设备必须支持的。
此外,PCIe设备还扩展了 0x40 ~ 0xFF这段配置空间,在这段空间主要存放一些与 MSI或者 MSI-X中断机制和电源管理相关的 Capability结构。其中所有能够提交中断请求的 PCIe设备,必须支持 MSI或者 MSI-X Capability

例如,可以使用 lspci查看 82599网卡的 0x00 ~ 0xFF配置空间中的内容:

$ lspci -s 0b:00.0 -xxx
0b:00.0 Ethernet controller: Intel Corporation 82599ES 10-Gigabit SFI/SFP+ Network Connection (rev 01)
00: 86 80 fb 10 43 01 10 00 01 00 00 02 10 00 80 00
10: 0c 00 d8 ff 9f 03 00 00 21 20 00 00 00 00 00 00
20: 0c 40 e0 ff 9f 03 00 00 00 00 00 00 86 80 03 00
30: 00 00 00 00 40 00 00 00 00 00 00 00 0b 01 00 00
40: 01 50 23 48 00 20 00 2b 00 00 00 00 00 00 00 00
50: 05 70 80 01 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: 11 a0 3f 00 04 00 00 00 04 20 00 00 00 00 00 00
80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
a0: 10 00 02 00 c2 8c 00 10 36 58 09 00 82 c4 01 02
b0: 40 00 82 10 00 00 00 00 00 00 00 00 00 00 00 00
c0: 00 00 00 00 1f 00 00 00 00 00 00 00 00 00 00 00
d0: 02 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

我们在使用 setpci修改 PCI设备的配置空间内容时,
1)需要指定设备信息,也就是设备号,与 lspci类似,使用 -s xx:xx.x
2)还需要指定待修改的寄存器的地址,范围是 0x00 ~ 0xFF,并且通过 ‘w’, ‘b’后缀指定数据宽度,其中,'w'表示 2字节,'b'表示 1字节
3)还需要为寄存器指定修改后的值,例如:A0.b=0x01

例如:
查看 0a:00.0设备配置空间 A0地址处 2字节的内容

$ setpci -s 0a:00.0 A0.w

修改 0a:00.0设备配置空间 A0地址处 1字节的内容

$ setpci -s 0a:00.0 A0.b=0x01 

例如,我们要打开 XL710网卡的 PCIe IDO功能,
1)首先通过 XL710手册找到 IDO功能所在的配置寄存器,为 Device Control 2寄存器,它的地址是 0XC8
2)通过 setpci查看 device control2的原值

$ setpci -s 0a:00.0 c8.w
0000

3)在原值的基础上使能 IDO功能,并写入新值

$ setpci -s 0a:00.0 c8.w=0x0300

4)确认已经写入成功

$ setpci -s 0a:00.0 c8.w
0300
  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值