virttest.qemu_vm: Use aobject instead of type for PCI bus

The pci bus assignement should be strictly defined. We should be able
to assign each device to the specific PCI bus. Currently only
'pci.0' bus is created by devices.machine_by_params() function.

Additionally correct the 'pci' type to the qemu matching ones (PCI, PCIE)

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
virttest.qemu_devices: Simplify qdev.insert (remove force)

The force insertion code is unused and unreadable. Let people
handle negative testing on their own and focus on the important
parts as device creation for now.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
virttest.qemu_devices: Allow bus to create additional devices on insert

This patch adds the possibility for bus to specify list of devices,
which needs to be plugged prior to the device. This enables us to
create internal autotest buses, which simulates complex behaviors
and it's going to be used for PCI switch definition.

Additionally this patch brings the possibility to specify list of devices
to be inserted instead just a simple device. Still when the insertion
fails the qdev remains unchanged.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
virttest.qemu_devices: Change match_bus policy

The match_bus in atest (soft) mode allowed atype to be mismatched.
This is not enough and the problem with other matching bus could
occur. Change this policy to match only 'type' thus other matching
buses might be found and strict_mode enforced during insert.

Additionally add support for multiple acceptable values (list, tuple).

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
virttest.qemu_devices: Support length definition for QPCIBus

This patch modifies the QSparseBus to use self.first_port to modify
the first usable port (there are many buses starting on port 1). This
function is used in QPCIBus to let user specify the first acceptable
port.

Also with this patch users are allowed to specify the PCI bus length.
(PCI bridge accepts only addresses 1-19)

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
virttest.qemu_devices: Always set properties of QPCIBus

PCI bridge must always set the device's PCI address. Instead of custom
behavior only for the bridges this patch forces strict_mode (set all
properties) for all QPCIBus buses.

This might bring some problems in the beginning, but it should help
us to test what we really want. So in the long-term this should
simplify testing and analyzing of failures.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
virttest.qemu_devices: Support for PCI RC/bridge/switch

This patch adds the support for various PCI root controllers, bridges and
switches.

PCI root controllers and bridges (and custom switches) work as normal
QPCIBus (with limited address ranges).

It's possible to say you want an automated x3130 switch. This switch
creates x3130-upstream port and for each inserted device
xio3130-downstream port. This is done automatically at any stage (during
hotplug). If you need different behavior (multiple devices on a single
switch port) you have to create the switch using your own x3130-upstream
and xio3130-downstream ports.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
virttest.qemu_vm: Add support for PCI RC/bridge/switch

This patch adds the support to define PCI root controllers, bridges and
switches via autotest params. The syntax is:

# controller names/objects
pci_controllers = "root.1 pci_bridge1"

# default pci_bus (all devices will be plugged here)
pci_bus = 'pci_bridge1'
# parent bus of root.1
pci_bus_root.1 = 'pci.0'
# parent bus of pci_bridge1
pci_bus_pci_bridge1 = 'root.1'
# type of root.1 controller (root controller ioh3420)
type_root.1 = 'ioh3420'
# type of pci_bridge1 (PCI2PCI bridge)
type_pci_bridge1 = 'pci-bridge'
virttest.qemu_devices: Docstring/PEP8/pylint fixes

Some pylint PEP8 fixups and additional docstrings.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
virttest.qemu_devices: Support for default parameter in device.get_param

similarily to dictionary support the default return in case the key is
not found.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
virttest.qemu_devices: Support bus.reserve(addr) to reserve the addr

We might reserve particular address. This address will not be used for
devices, which won't ask for the exact address.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
virttest.qemu_devices: Define first_port for each addr item

first_port of each addr item might be different. Implement it as
list of integers instead of just integer.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
virttest.qemu_devices: Support for DevContainer.get_by_properties()

This function returns the devices filtered by the dictionary of
properties (and values)

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
virttest.qemu_devices: Support for multifunction PCI devices

PCI bus supports multifunction devices compound of upt o 8 devices
on the same PCI addr. This patch adds the support for subaddress
into the qdev representation.

Function is not incremented by default so new devices are still set
to the new PCI slot. But when you define addr with '.' function is set
and used in the representation.

In order to be closer to qtree representation this patch also changes
the addr string to '%02x.%x'.

Last but not least PCI bus changed from QDenseBus to QSparseBus as
lots of the addresses are unused and this way the representation is more
readable.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
virttest.qemu_devices: QPCISwitchBus improvements

Addopt the QPCISwitchBus to create the structure on-the-fly in the same
maner as the user would create the bus. The difference is that this way
we'll be able to follow the qtree structure without any hooks.

From now each new port means new PCI bus inserted into the representation.
Users are allowed to add additional ports whenever they want.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
virttest.qemu_devices: Support PCI addre reservation

This patch brings the possibility to specify addresses, which should
be reserved for furthure use by specifying "reserved_slots = ...".
Those addresses won't be assigned by default and will be accepted only
when the device would ask for this specific address.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
virttest.qemu_devices: Use multifunction devs to create ehci usbc

ehci usb controller is compound by 4 devices. Previously only the 0st
one was added into the representation. Now when QPCIBus supports
multifunction add all of them.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
virttest.qemu_devices: Set all of the machine PCI devices

Add all of the PCI devices which are added by the -M into PCI
representation.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
virttest.qemu_qtree: Fix the corrupted id:

Some devices in qtree had corrupted IDs. This occured because the line
is now striped before use.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
qemu.tests.pci_devices: Add test of pci devices

This test boots VM with a define set of PCI devices and compares
the qtree and internal representation.

In the future this test should also check the operation system view
of the devices (lspci or the windows equivalent)

The testing setup is done via graphical representation of the setup.
Note that the number of spaces is irelevant. The location is defined
by the number of '->' characters. You can verify the setup in the test.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>