0db2ec12c5
This commit introduces a new PCI library and associated tools for inspecting and modifying PCI configuration space via Linux sysfs. The following changes were made: - Implemented `pci.c` and `pci.h` for PCI device management, including enumeration, attribute reading, and configuration space access. - Added `setpci` command-line utility for reading and writing PCI configuration registers, with support for filtering devices by vendor, device, and slot. - Created manual pages for `setpci` to document its usage and options. - Developed test scripts for both `lspci` and `setpci` to ensure functionality and correctness of the new features. These additions enhance the ability to interact with PCI devices, providing a robust framework for device management and configuration.
34 lines
1.1 KiB
Bash
34 lines
1.1 KiB
Bash
#!/bin/sh
|
|
_test_name="setpci"
|
|
. "$(dirname "$0")/harness.sh"
|
|
|
|
setup_tmpdir
|
|
SETPCI="$VX setpci"
|
|
|
|
echo "Running setpci tests..."
|
|
|
|
dev_path="/sys/bus/pci/devices/$(ls /sys/bus/pci/devices | head -n 1)"
|
|
slot="$(basename "$dev_path")"
|
|
short_slot="$(printf '%s' "$slot" | sed 's/^0000://')"
|
|
vendor="$(sed 's/^0x//' "$dev_path/vendor")"
|
|
device="$(sed 's/^0x//' "$dev_path/device")"
|
|
command_reg="$(od -An -tx2 -N2 -j4 "$dev_path/config" | tr -d ' \n')"
|
|
|
|
$SETPCI --dumpregs > dumpregs.out
|
|
check_grep "VENDOR_ID" dumpregs.out "dumpregs: lists standard names"
|
|
|
|
out="$($SETPCI -s "$short_slot" VENDOR_ID)"
|
|
check_eq "$out" "$vendor" "read: VENDOR_ID matches sysfs"
|
|
|
|
out="$($SETPCI -s "$short_slot" DEVICE_ID)"
|
|
check_eq "$out" "$device" "read: DEVICE_ID matches sysfs"
|
|
|
|
out="$($SETPCI -s "$short_slot" 04.w)"
|
|
check_eq "$out" "$command_reg" "read: numeric register syntax works"
|
|
|
|
check_exit "dry-run: masked write succeeds" 0 $SETPCI -D -s "$short_slot" COMMAND="$command_reg:ffff"
|
|
after="$($SETPCI -s "$short_slot" COMMAND)"
|
|
check_eq "$after" "$command_reg" "dry-run: command register unchanged"
|
|
|
|
summary
|