README
1INTRODUCTION
2============
3Sometimes, it is useful to check what the driver is doing with
4the PCI registers.
5
6As it took me some time to get the right info from the Intenet,
7and to write a few patches to enable debug, and to write them
8to a file, I'm documenting here the procedure I used, as it
9may be useful for the others.
10
11One of the ways to see what a driver is doing with PCI registers
12is to write several debug printk's. Another way is to enable PCI
13device access at a VM machine, and catch the PCI emulation logs.
14
15To use the second case, one of the ways is to modify the qemu-kvm
16package. In my case, I wrote some patches for
17qemu-kvm-0.12.1.2-2.113.el6.x86_64 (shipped with RHEL6), but they
18probably apply on other versions of qemu.
19
20Be careful: in order to get the PCI writes, the patches I'm using
21intercepts all calls to PCI write/read to the mapped devices. This
22is slow, and may cause machine hangs. If you're willing to use it,
23you'll likely need to do on a separate machine, used just for
24tests. On my test machine, they work fine for digital TV, but hangs
25the machine with analog TV (probably because digital streams use
26compressed traffic).
27
28PATCHES FOR QEMU-KVM
29====================
30
31There are a few patches that are needed to allow getting a kvm log
32from the PCI traffic.
33
34The patches should be applied on this order:
35
36kvm-allow-assigned-different-than-4K.patch
37kvm-dev-assign-debug.patch
38write_log_to_file.patch
39
401) kvm-allow-assigned-different-than-4K.patch
41
42This patch came from qemu-kvm git tree. It will likely be available
43on some stable version soon. It is needed for some devices.
44
452) kvm-dev-assign-debug.patch
46This patch were written by me. It basically enables some debug
47logs. It is licensed with GPLv2;
48
493) write_log_to_file.patch
50
51This patch were written by me. It changes the debug logic to write
52logs on a file, instead of stderr. The file is: /var/log/qemu_hw_pci.log.
53You'll need to create it previously, change its ownership to match
54qemu user, and fix selinux permissions (if you're using selinux).
55In the case of RHEL6, I'm using:
56
57-rw-r--r--. qemu qemu system_u:system_r:svirt_t:s0 qemu_hw_pci.log
58
59IRQ CONFLICTS
60=============
61
62You need to be sure that IRQ's are not shared between the device you
63want to sniff and any other device, otherwise, kvm won't allow you
64to see the physical device. This is (currently) a kvm restriction.
65
66You may check it by looking at /proc/interrupts.
67
68In my case, ehci_hcd and uhci_hcd shares interrrupts with devices I
69plug on my PCI slots. So, I wrote a script to disconnect all USB buses
70from my test machine. The script is:
71
72 disconnect_usb.sh
73
74MAPPING THE PHYSICAL DEVICE ON QEMU
75===================================
76
77You'll need to use an option for KVM to map the PCI device at the
78machine. In my case, I'm using those lines:
79
80-device pci-assign,host=37:09.0,id=hostdev0,configfd=22,bus=pci.0,addr=0x6
81-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5
82
83The actual line depends on the PCI device that you're using. The above
84example assumes a device at PCI address 37:09.0.
85
86You may also use virt-manager to configure physical access to your PCI
87device.
88
89I hope this may be useful for you.
90Mauro Carvalho Chehab <mchehab@kernel.org>
91