Skip to contentSkip to conversation

qmp: query-device-slots command

RFC Superseded Eduardo Habkost 3 participants 5 messages Dec 14, 2016 – Dec 15, 2016

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

RFC v2 1/1 qmp: query-device-slots command

This adds a new command to QMP: query-device-slots. It will allow management software to query possible slots where devices can be plugged.

This implementation of the command will return:

* Multiple PCI slots per bus, in the case of PCI buses;
* One slot per bus for the other buses (that don't implement slot enumeration yet);
* One slot for each entry from query-hotpluggable-cpus.

Git tree
--------

This patch needs the previous query-machines series I am working on. The full tree can be found on the git tree at:

git://github.com/ehabkost/qemu-hacks.git work/query-machines-bus-info

Example output
--------------

The following output was returned by QEMU when running it as:

 $ qemu-system-x86_64 -machine q35 \
   -readconfig docs/q35-chipset.cfg \
   -smp 4,maxcpus=8,sockets=2,cores=2,threads=2
  {
    "return": [
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "i2c"
            },
            "type": "non-slot",
            "accepted-device-types": [
                "i2c-slave"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ide.4"
            },
            "type": "non-slot",
            "accepted-device-types": [
                "ide-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ide.5"
            },
            "type": "non-slot",
            "accepted-device-types": [
                "ide-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ide.0"
            },
            "type": "non-slot",
            "accepted-device-types": [
                "ide-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ide.1"
            },
            "type": "non-slot",
            "accepted-device-types": [
                "ide-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ide.2"
            },
            "type": "non-slot",
            "accepted-device-types": [
                "ide-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ide.3"
            },
            "type": "non-slot",
            "accepted-device-types": [
                "ide-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "main-system-bus"
            },
            "type": "non-slot",
            "accepted-device-types": [
                "sys-bus-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "isa.0"
            },
            "type": "non-slot",
            "accepted-device-types": [
                "isa-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 0
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 1
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 2
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 3
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 4
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 5
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 6
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 7
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 8
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 9
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 10
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 11
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 12
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 13
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 14
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 15
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 16
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 17
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 18
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 19
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 20
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 21
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 22
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 23
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 24
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 25
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 26
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 27
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 28
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 29
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 30
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 31
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": true,
            "hotpluggable": true,
            "props": {
                "bus": "ich9-pcie-port-1",
                "device-number": 0
            },
            "type": "pci",
            "accepted-device-types": [
                "pci-express-device"
            ]
        },
        {
            "available": true,
            "hotpluggable": true,
            "props": {
                "bus": "ich9-pcie-port-2",
                "device-number": 0
            },
            "type": "pci",
            "accepted-device-types": [
                "pci-express-device"
            ]
        },
        {
            "available": true,
            "hotpluggable": true,
            "props": {
                "bus": "ich9-pcie-port-3",
                "device-number": 0
            },
            "type": "pci",
            "accepted-device-types": [
                "pci-express-device"
            ]
        },
        {
            "available": true,
            "hotpluggable": true,
            "props": {
                "bus": "ich9-pcie-port-4",
                "device-number": 0
            },
            "type": "pci",
            "accepted-device-types": [
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 0
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 1
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 2
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 3
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 4
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 5
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 6
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 7
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 8
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 9
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 10
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 11
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 12
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 13
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 14
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 15
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 16
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 17
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 18
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 19
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 20
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 21
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 22
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 23
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 24
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 25
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 26
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 27
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 28
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 29
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 30
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 31
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },
        {
            "available": true,
            "hotpluggable": true,
            "props": {
                "bus": "ich9-ehci-1.0"
            },
            "type": "non-slot",
            "accepted-device-types": [
                "usb-device"
            ]
        },
        {
            "available": true,
            "hotpluggable": true,
            "props": {
                "bus": "ich9-ehci-2.0"
            },
            "type": "non-slot",
            "accepted-device-types": [
                "usb-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-hda-audio.0"
            },
            "type": "non-slot",
            "accepted-device-types": [
                "hda-codec"
            ]
        },
        {
            "available": true,
            "hotpluggable": true,
            "props": {
                "socket-id": 1,
                "core-id": 1,
                "thread-id": 1
            },
            "type": "cpu",
            "accepted-device-types": [
                "qemu64-x86_64-cpu"
            ]
        },
        {
            "available": true,
            "hotpluggable": true,
            "props": {
                "socket-id": 1,
                "core-id": 1,
                "thread-id": 0
            },
            "type": "cpu",
            "accepted-device-types": [
                "qemu64-x86_64-cpu"
            ]
        },
        {
            "available": true,
            "hotpluggable": true,
            "props": {
                "socket-id": 1,
                "core-id": 0,
                "thread-id": 1
            },
            "type": "cpu",
            "accepted-device-types": [
                "qemu64-x86_64-cpu"
            ]
        },
        {
            "available": true,
            "hotpluggable": true,
            "props": {
                "socket-id": 1,
                "core-id": 0,
                "thread-id": 0
            },
            "type": "cpu",
            "accepted-device-types": [
                "qemu64-x86_64-cpu"
            ]
        },
        {
            "available": false,
            "hotpluggable": true,
            "props": {
                "socket-id": 0,
                "core-id": 1,
                "thread-id": 1
            },
            "type": "cpu",
            "accepted-device-types": [
                "qemu64-x86_64-cpu"
            ]
        },
        {
            "available": false,
            "hotpluggable": true,
            "props": {
                "socket-id": 0,
                "core-id": 1,
                "thread-id": 0
            },
            "type": "cpu",
            "accepted-device-types": [
                "qemu64-x86_64-cpu"
            ]
        },
        {
            "available": false,
            "hotpluggable": true,
            "props": {
                "socket-id": 0,
                "core-id": 0,
                "thread-id": 1
            },
            "type": "cpu",
            "accepted-device-types": [
                "qemu64-x86_64-cpu"
            ]
        },
        {
            "available": false,
            "hotpluggable": true,
            "props": {
                "socket-id": 0,
                "core-id": 0,
                "thread-id": 0
            },
            "type": "cpu",
            "accepted-device-types": [
                "qemu64-x86_64-cpu"
            ]
        }
    ]
  }
Cc Marcel Apfelbaum <[email protected]>
Cc Markus Armbruster <[email protected]>
Cc Igor Mammedov <[email protected]>
Cc Laine Stump <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>

---
Changes v1 -> v2:
* Don't show sysbus unless has_dynamic_sysbus is set for the machine type
* Removed max-devices and devices properties
* Introduced "non-slot" slot type, to explicitly indicate we are returning info on a bus that doesn't implement slot enumeration yet.
* Return bus name instead of full QOM path on "bus" field
* PCI: Replaced "addr" property (string parsed by property setter) with "device-number" uint32 property
* PCI: return only one slot for PCIe ports

---
 qapi-schema.json       | 131 +++++++++++++++++++++++++++++++++++++++
 include/hw/qdev-core.h |   6 ++
 hw/core/bus.c          |  35 +++++++++++
 hw/pci/pci.c           | 165 +++++++++++++++++++++++++++++++++++++++++--------
 qdev-monitor.c         |  88 ++++++++++++++++++++++++--
 5 files changed, 392 insertions(+), 33 deletions(-)
qapi-schema.json +131 -0
index d48ff3f..50e09f5 100644
@@ -3166,6 +3166,137 @@
 { 'command': 'closefd', 'data': {'fdname': 'str'} }
 
 ##
+# @DeviceSlotType:
+#
+# Type of device slot
+#
+# @non-slot: Slot type representing a bus that doesn't return any
+#            specific slot information yet.
+# @pci: PCI device slot
+# @cpu: CPU device slot
+#
+#TODO: try to find a better name for non-slot. "generic-bus", maybe?
+##
+{ 'enum': 'DeviceSlotType',
+  'data': ['non-slot', 'pci', 'cpu'] }
+
+##
+# @DeviceSlotInfo:
+#
+# Information on a slot where devices can be plugged.
+#
+# @type: type of device slot.
+#
+# @accepted-device-types: List of device types accepted by the slot.
+#                         Any device plugged to the slot should implement
+#                         one of the accepted device types.
+#
+# @available: If false, the slot is not available for plugging any device.
+#             This value can change at runtime if condition changes
+#             (e.g. if the slot becomes full, or if the machine
+#             was already initialized and the slot doesn't support
+#             hotplug).
+#
+# @hotpluggable: If true, the slot accepts hotplugged devices.
+#
+# @props: The arguments that should be given to @device_add if plugging
+#         a device to this slot.
+#
+# For specific rules about what can be plugged on each type of slot,
+# see the type-specific structs (@NonSlotInfo, @PCISlotInfo,
+# @CPUSlotInfo).
+##
+{ 'union': 'DeviceSlotInfo',
+  'base': { 'type': 'DeviceSlotType',
+            'accepted-device-types': [ 'str' ],
+            'available': 'bool', 'hotpluggable': 'bool' },
+  'discriminator': 'type',
+  'data': { 'non-slot': 'NonSlotInfo',
+            'pci': 'PCISlotInfo',
+            'cpu': 'CPUSlotInfo' } }
+
+##
+# @NonSlotProperties:
+#
+# Arguments to @device_add when plugging a device to a bus that
+# doesn't return specific slot info yet.
+#
+# @bus: "bus" argument to @device_add.
+#
+# Slots returned as type=non-slot might require extra arguments to
+# be set to specify the device address, but they are not covered by
+# NonSlotInfoProperties.
+##
+{ 'struct': 'NonSlotProperties',
+  'data': { 'bus': 'str' } }
+
+
+##
+# @NonSlotInfo:
+#
+# Generic entry representing a bus that doesn't support slot enumeration
+# yet. Slots of this type should be replaced by more specific slot types
+# in future QEMU versions.
+#
+# Slots of this type may or may not support multiple devices.
+#
+# @props: The arguments that should be given to @device_add if plugging
+#         a device to this slot. The list of properties might be incomplete
+#         in case the bus requires additional parameters to be provided.
+##
+{ 'struct': 'NonSlotInfo',
+  'data': { 'props': 'NonSlotProperties' } }
+
+##
+# @PCIDeviceSlotProperties:
+#
+# Arguments to @device_add when plugging a device to a PCI slot.
+#
+# @bus: "bus" argument to @device_add.
+# @slot: "device-number" argument to @device_add. PCI device
+#        number (sometimes called "slot").
+#
+##
+{ 'struct': 'PCIDeviceSlotProperties',
+  'data': { 'bus': 'str', 'device-number': 'int' } }
+
+##
+# @PCISlotInfo:
+#
+# Information on a PCI device slot.
+#
+# @props: The arguments that should be given to @device_add if plugging
+#         a device to this slot.
+#
+# PCI device slots become unavailable after a device is plugged to
+# function 0.
+##
+{ 'struct': 'PCISlotInfo',
+  'data': { 'props': 'PCIDeviceSlotProperties' } }
+
+##
+# @CPUSlotInfo:
+#
+# Information on a CPU device slot.
+#
+# @props: The arguments that should be given to @device_add if plugging
+#         a device to this slot.
+#
+# CPU slots become unavailable after one device is plugged to them.
+##
+{ 'struct': 'CPUSlotInfo',
+  'data': { 'props': 'CpuInstanceProperties' } }
+
+##
+# @query-device-slots:
+#
+# Return the list of possible slots for plugging devices using
+# @device_add.
+##
+{ 'command': 'query-device-slots',
+  'returns': [ 'DeviceSlotInfo' ] }
+
+##
 # @MachineBusInfo
 #
 # Information about a bus present on a machine.
include/hw/qdev-core.h +6 -0
index a7f9ac4..2cb043a 100644
@@ -214,6 +214,10 @@ struct BusClass {
      * but on some cases bus instances may override it.
      */
     const char *device_type;
+
+    /*TODO: write doc */
+    DeviceSlotInfoList *(*enumerate_slots)(BusState *bus, Error **errp);
+
 };
 
 typedef struct BusChild {
@@ -412,4 +416,6 @@ static inline bool qbus_is_hotpluggable(BusState *bus)
 void device_listener_register(DeviceListener *listener);
 void device_listener_unregister(DeviceListener *listener);
 
+bool qbus_is_full(BusState *bus);
+
 #endif
hw/core/bus.c +35 -0
index d2bf717..451fa46 100644
@@ -21,6 +21,7 @@
 #include "qemu-common.h"
 #include "hw/qdev.h"
 #include "qapi/error.h"
+#include "qapi/clone-visitor.h"
 #include "qapi-visit.h"
 
 static void qbus_set_hotplug_handler_internal(BusState *bus, Object *handler,
@@ -225,12 +226,46 @@ static void bus_get_device_type(Object *obj, Visitor *v,
     visit_type_strList(v, NULL, &bus->accepted_device_types, errp);
 }
 
+bool qbus_is_full(BusState *bus)
+{
+    BusClass *bus_class = BUS_GET_CLASS(bus);
+    return bus_class->max_dev && bus->max_index >= bus_class->max_dev;
+}
+
+/* Generic slot enumeration function that will return a generic-slot slot type.
+ */
+static DeviceSlotInfoList *bus_generic_enumerate_slots(BusState *bus, Error **errp)
+{
+    Error *local_err = NULL;
+    DeviceSlotInfoList *r = g_new0(DeviceSlotInfoList, 1);
+
+    r->value = g_new0(DeviceSlotInfo, 1);
+    r->value->type = DEVICE_SLOT_TYPE_NON_SLOT;
+    r->value->accepted_device_types = QAPI_CLONE(strList, bus->accepted_device_types);
+    r->value->u.non_slot.props = g_new0(NonSlotProperties, 1);
+    r->value->u.non_slot.props->bus = g_strdup(bus->name);
+
+    r->value->hotpluggable = qbus_is_hotpluggable(bus);
+
+    /* Conditions that make a bus unavailable:
+     * - Bus already full
+     * - Hotplug when the bus is not hotpluggable
+     */
+    r->value->available =
+        !(qbus_is_full(bus) ||
+          (qdev_hotplug && !qbus_is_hotpluggable(bus)));
+
+    error_propagate(errp, local_err);
+    return r;
+}
+
 static void bus_class_init(ObjectClass *class, void *data)
 {
     BusClass *bc = BUS_CLASS(class);
 
     class->unparent = bus_unparent;
     bc->get_fw_dev_path = default_bus_get_fw_dev_path;
+    bc->enumerate_slots = bus_generic_enumerate_slots;
 
     object_class_property_add(class, "accepted-device-types", "strList",
                               bus_get_device_type, NULL, NULL, NULL,
hw/pci/pci.c +138 -27

207 lines not on this page · raw message

qdev-monitor.c +82 -6

106 lines not on this page · raw message

Signature · 1 line
2.7.4
#1 lore raw
Quoted 10 lines · On Wed, 14 Dec 2016 17:39:08 -0200 Eduardo Habkost <[email protected]> wrote:

This adds a new command to QMP: query-device-slots. It will allow management software to query possible slots where devices can be plugged.

This implementation of the command will return:

* Multiple PCI slots per bus, in the case of PCI buses;
* One slot per bus for the other buses (that don't implement slot enumeration yet);
* One slot for each entry from query-hotpluggable-cpus.

Perhaps command should handle slots enumeration for DIMM/NV-DIMM devices as well which are also bus-less as cpus but don't have dedicated command for possible slots enumeration.

[...]

Quoted 6 lines
qapi-schema.json +6 -0
+##
+# @DeviceSlotInfo:
+#
+# Information on a slot where devices can be plugged.
+#
+# @type: type of device slot.

qapi-schema.json line 3198

Quoted 10 lines
qapi-schema.json +10 -0
+#
+# @accepted-device-types: List of device types accepted by the slot.
+#                         Any device plugged to the slot should implement
+#                         one of the accepted device types.
+#
+# @available: If false, the slot is not available for plugging any device.
+#             This value can change at runtime if condition changes
+#             (e.g. if the slot becomes full, or if the machine
+#             was already initialized and the slot doesn't support
+#             hotplug).

or slot has been freed as result of unplug action

qapi-schema.json line 3203

Quoted 4 lines
qapi-schema.json +4 -0
+# @hotpluggable: If true, the slot accepts hotplugged devices.
+#
+# @props: The arguments that should be given to @device_add if plugging
+#         a device to this slot.

Could it be a list of arbitrary properties?
What do we gain making it a union of fixed types which are in the end just property lists?

[...]

Quoted 23 lines
qdev-monitor.c +23 -0
+{
+    SlotListState s = { };
+    MachineState *ms = MACHINE(qdev_get_machine());
+    MachineClass *mc = MACHINE_GET_CLASS(ms);
+
+    s.machine = ms;
+    s.next = &s.result;
+
+    /* We build the device slot list from two sources:
+     * 1) Calling the BusClass::enumerate_slots() method on all buses;
+     * 2) The return value of MachineClass::query_hotpluggable_cpus()
+     */
+
+
+    object_child_foreach_recursive(qdev_get_machine(), walk_bus, &s);
+    if (s.err) {
+        goto out;
+    }
+
+    if (mc->query_hotpluggable_cpus) {
+        HotpluggableCPUList *hcl = mc->query_hotpluggable_cpus(ms);
+        HotpluggableCPUList *i;
+

qdev-monitor.c DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) · line 694

Quoted 10 lines
qdev-monitor.c +10 -0
+        for (i = hcl; i; i = i->next) {
+            DeviceSlotInfoList *r = g_new0(DeviceSlotInfoList, 1);
+            HotpluggableCPU *hc = i->value;
+            r->value = g_new0(DeviceSlotInfo, 1);
+            r->value->type = DEVICE_SLOT_TYPE_CPU;
+            r->value->accepted_device_types = g_new0(strList, 1);
+            r->value->accepted_device_types->value = g_strdup(hc->type);
+            r->value->available = !hc->has_qom_path;
+            /*TODO: should it be always true? */
+            r->value->hotpluggable = true;

it shouldn't be true for BSP, and for the rest of x86 cpus it's true provided machine versions supports cpu hotplug.

But it might be another story for SPAPR or s390,
CCing maintainers.

Quoted 18 lines
qdev-monitor.c +15 -0
+
+            r->value->u.cpu.props = QAPI_CLONE(CpuInstanceProperties,
+                                               hc->props);
+            *s.next = r;
+            s.next = & r->next;
+        }
+
+        qapi_free_HotpluggableCPUList(hcl);
+    }
+
+out:
+    error_propagate(errp, s.err);
+    return s.result;
+}
+
 
 #define qdev_printf(fmt, ...) monitor_printf(mon, "%*s" fmt, indent, "", ## __VA_ARGS__)
 static void qbus_print(Monitor *mon, BusState *bus, int indent);
#3 lore raw
In reply to Eduardo Habkost
Quoted 28 lines · Eduardo Habkost

This adds a new command to QMP: query-device-slots. It will allow management software to query possible slots where devices can be plugged.

This implementation of the command will return:

* Multiple PCI slots per bus, in the case of PCI buses;
* One slot per bus for the other buses (that don't implement slot enumeration yet);
* One slot for each entry from query-hotpluggable-cpus.

Git tree
--------

This patch needs the previous query-machines series I am working on. The full tree can be found on the git tree at:

git://github.com/ehabkost/qemu-hacks.git work/query-machines-bus-info

Example output
--------------

The following output was returned by QEMU when running it as:

 $ qemu-system-x86_64 -machine q35 \
   -readconfig docs/q35-chipset.cfg \
   -smp 4,maxcpus=8,sockets=2,cores=2,threads=2
Quoted 7 lines
  {
    "return": [
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "i2c"

Missing: bus "i2c-bus" device address, property name "address", value 0..255.

Quoted 2 lines
            },
            "type": "non-slot",

I guess "non-slot" means "props" is incomplete, but the rest should be okay.

Quoted 9 lines
            "accepted-device-types": [
                "i2c-slave"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ide.4"

Bus "IDE" device address property "unit", value 0 (because this is SATA, for PATA it would be 0..1).

Quoted 6 lines
            },
            "type": "non-slot",
            "accepted-device-types": [
                "ide-device"
            ]
        },

[...]

Quoted 11 lines
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "main-system-bus"
            },
            "type": "non-slot",
            "accepted-device-types": [
                "sys-bus-device"
            ]
        },

Can't give guidance on this one, I'm afraid.

Quoted 11 lines
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "isa.0"
            },
            "type": "non-slot",
            "accepted-device-types": [
                "isa-device"
            ]
        },

Bus "ISA" is iffy, too.

Quoted 6 lines
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 0

Really? "device_add e1000e,help" shows now property "device-number". Oh, I see, you're adding it in this patch, along with "function".

Quoted 20 lines
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 1
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },

[...]

Quoted 5 lines
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
Quoted 8 lines
                "device-number": 31
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },

Design question: do we need to describe the bus with 32 separate objects, or would a single object do? The objects only differ in the value of props.device-number...

For a hypothetical bus with uint32_t device addresses, separate objects would be impossible. So we probably need to describe slot sets, anyway.

Quoted 60 lines
        {
            "available": true,
            "hotpluggable": true,
            "props": {
                "bus": "ich9-pcie-port-1",
                "device-number": 0
            },
            "type": "pci",
            "accepted-device-types": [
                "pci-express-device"
            ]
        },
        {
            "available": true,
            "hotpluggable": true,
            "props": {
                "bus": "ich9-pcie-port-2",
                "device-number": 0
            },
            "type": "pci",
            "accepted-device-types": [
                "pci-express-device"
            ]
        },
        {
            "available": true,
            "hotpluggable": true,
            "props": {
                "bus": "ich9-pcie-port-3",
                "device-number": 0
            },
            "type": "pci",
            "accepted-device-types": [
                "pci-express-device"
            ]
        },
        {
            "available": true,
            "hotpluggable": true,
            "props": {
                "bus": "ich9-pcie-port-4",
                "device-number": 0
            },
            "type": "pci",
            "accepted-device-types": [
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 0
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },

[...]

Quoted 4 lines
        {
            "available": false,
            "hotpluggable": false,
            "props": {
Quoted 8 lines
                "bus": "ich9-pci-bridge",
                "device-number": 31
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },

Likewise.

Quoted 11 lines
        {
            "available": true,
            "hotpluggable": true,
            "props": {
                "bus": "ich9-ehci-1.0"
            },
            "type": "non-slot",
            "accepted-device-types": [
                "usb-device"
            ]
        },

Okay, more bad news: bus "usb-bus" device address property is "port", value is a sequence of port numbers separated by '.'. The reason is "convenience"

A real USB host controller has a fixed number of ports, numbered 1..N. This one has six.

A real USB hub device plugs into a port and in turn provides a fixed number of ports, numbered 1..N. The USB hub device we model provides eight.

An obvious way to model this would be to have the host controller provide a bus with a fixed number of slots, and the usb-hub provide a separate bus with eight. This is how we do PCI bridges. But it's not how we do USB hubs.

Host software can treat the tree formed by USB host controller, hubs and other devices as a single bus, and that's how we model it.

A "port" value that is a single number addresses that port on the host controller.

A value containing '.' addresses something behind a hub. The leftmost number addresses a host controller port. A hub must be plugged in there. Recurse for the rest of the port string.

If you device_add an USB device without specifying a port, it picks an unused one. When it has to pick the last port, it tries to add a usb-hub device there, which provides eight ports, then picks a port for your device. If adding the usb-hub succeeds, it'll get the new hub's port 1. Else, it gets the last port. There's a hard-coded limit of five on the depth of the hub chain. So, if you keep adding USB devices to the bus provided by ich9-ehci, the first five go into ports "1", ..., "5", the sixth goes into "6.1" (with usb-hub in port "6"), and so forth, until the 41st goes into "6.8.8.8.8.8". Adding hubs manually permits more devices.

If you do specify "port", then that port must already exist.

I think the sanest way to represent the existing ports is enumerating them, like this:

          {
              "available": true,
              "hotpluggable": true,
              "props": {
                  "bus": "ich9-ehci-1.0", "port": "1"
              },
              "type": "usb",
              "accepted-device-types": [
                  "usb-device"
              ]
          },
          [...]
          {
              "available": true,
              "hotpluggable": true,
              "props": {
                  "bus": "ich9-ehci-1.0", "port": "6"
              },
              "type": "usb",
              "accepted-device-types": [
                  "usb-device"
              ]
          },

Plugging usb-hub into a port with port: "P" then flips that port's "available" to false, and adds eight new ports with "port": "P.1", ... "P.8".

So, plugging a device can not only add buses provided by the device, but also, and less obviously, add slots to the bus it plugs into! Likewise for unplug.

Perhaps we should emit events when slots come and go.

Quoted 8 lines
        {
            "available": true,
            "hotpluggable": true,
            "props": {
                "bus": "ich9-ehci-2.0"
            },
            "type": "non-slot",
            "accepted-device-types": [
Quoted 8 lines
                "usb-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-hda-audio.0"

Bus "HDA" device address property is "cad", value 0..14.

Quoted 11 lines
            },
            "type": "non-slot",
            "accepted-device-types": [
                "hda-codec"
            ]
        },
        {
            "available": true,
            "hotpluggable": true,
            "props": {
                "socket-id": 1,
Quoted 8 lines
                "core-id": 1,
                "thread-id": 1
            },
            "type": "cpu",
            "accepted-device-types": [
                "qemu64-x86_64-cpu"
            ]
        },

You know CPUs better than me.

[More of them...]

Quoted 2 lines
    ]

}

There's still more...

Bus "SCSI" device address property is "scsi-id", value 0..N, where N depends on the SCSI HBA.

Bus "virtio-serial-bus" device address property is "nr", value 0..N, where N is configurable, currenrly up to 511.

ccid-bus device address property is "slot", value 0..N, where N depends on the device providing the bus (I think).

Buses not yet covered by docs/qdev-device-use.txt: "floppy-bus", "apple-desktop-bus", "IndustryPack", "aux-bus", "spapr-vio-bus", "virtual-css-bus", "s390-sclp-events-bus", "s390-pcibus", "sd-bus", "SSI", "virtio-bus", "xen-sysbus". Grep for ".parent = TYPE_BUS".

To find all buses in a certain build, use:

    { "execute": "qom-list-types", "arguments": { "implements": "bus" } }

[No code review, yet]

#2 lore raw
In reply to Igor Mammedov
Quoted 9 lines · Igor Mammedov
Quoted 6 lines · On Wed, 14 Dec 2016 17:39:08 -0200 Eduardo Habkost <[email protected]> wrote:

This adds a new command to QMP: query-device-slots. It will allow management software to query possible slots where devices can be plugged.

This implementation of the command will return:

Quoted 7 lines
Quoted 4 lines

* Multiple PCI slots per bus, in the case of PCI buses;
* One slot per bus for the other buses (that don't implement slot enumeration yet);
* One slot for each entry from query-hotpluggable-cpus.

Perhaps command should handle slots enumeration for DIMM/NV-DIMM devices as well which are also bus-less as cpus but don't have dedicated command for possible slots enumeration.

Good idea. I will take a look.

Quoted 11 lines

[...]

Quoted 9 lines
qapi-schema.json +9 -0
+##
+# @DeviceSlotInfo:
+#
+# Information on a slot where devices can be plugged.
+#
+# @type: type of device slot.
+#
+# @accepted-device-types: List of device types accepted by the slot.
+#                         Any device plugged to the slot should implement
Quoted 8 lines

qapi-schema.json line 3198

Quoted 7 lines
qapi-schema.json +7 -0
+#                         one of the accepted device types.
+#
+# @available: If false, the slot is not available for plugging any device.
+#             This value can change at runtime if condition changes
+#             (e.g. if the slot becomes full, or if the machine
+#             was already initialized and the slot doesn't support
+#             hotplug).

or slot has been freed as result of unplug action

True. I will update it.

Quoted 8 lines

qapi-schema.json line 3203

Quoted 6 lines
qapi-schema.json +4 -0
+# @hotpluggable: If true, the slot accepts hotplugged devices.
+#
+# @props: The arguments that should be given to @device_add if plugging
+#         a device to this slot.

Could it be a list of arbitrary properties?
What do we gain making it a union of fixed types which are in the end just property lists?

For the same reason HotpluggableCPU.props is CpuInstanceProperties instead of an arbitrary list. It forces us to explicitly document how the returned data behaves, while still allowing clients to simply use the field like an opaque dictionary (if they want to).

Quoted 38 lines

[...]

Quoted 23 lines
qdev-monitor.c +23 -0
+{
+    SlotListState s = { };
+    MachineState *ms = MACHINE(qdev_get_machine());
+    MachineClass *mc = MACHINE_GET_CLASS(ms);
+
+    s.machine = ms;
+    s.next = &s.result;
+
+    /* We build the device slot list from two sources:
+     * 1) Calling the BusClass::enumerate_slots() method on all buses;
+     * 2) The return value of MachineClass::query_hotpluggable_cpus()
+     */
+
+
+    object_child_foreach_recursive(qdev_get_machine(), walk_bus, &s);
+    if (s.err) {
+        goto out;
+    }
+
+    if (mc->query_hotpluggable_cpus) {
+        HotpluggableCPUList *hcl = mc->query_hotpluggable_cpus(ms);
+        HotpluggableCPUList *i;
+

qdev-monitor.c DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) · line 694

Quoted 10 lines
qdev-monitor.c +10 -0
+        for (i = hcl; i; i = i->next) {
+            DeviceSlotInfoList *r = g_new0(DeviceSlotInfoList, 1);
+            HotpluggableCPU *hc = i->value;
+            r->value = g_new0(DeviceSlotInfo, 1);
+            r->value->type = DEVICE_SLOT_TYPE_CPU;
+            r->value->accepted_device_types = g_new0(strList, 1);
+            r->value->accepted_device_types->value = g_strdup(hc->type);
+            r->value->available = !hc->has_qom_path;
+            /*TODO: should it be always true? */
+            r->value->hotpluggable = true;

it shouldn't be true for BSP, and for the rest of x86 cpus it's true provided machine versions supports cpu hotplug.

Quoted 2 lines

But it might be another story for SPAPR or s390,
CCing maintainers.

Thanks!

Quoted 20 lines
Quoted 19 lines
qdev-monitor.c +15 -0
+
+            r->value->u.cpu.props = QAPI_CLONE(CpuInstanceProperties,
+                                               hc->props);
+            *s.next = r;
+            s.next = & r->next;
+        }
+
+        qapi_free_HotpluggableCPUList(hcl);
+    }
+
+out:
+    error_propagate(errp, s.err);
+    return s.result;
+}
+
 
 #define qdev_printf(fmt, ...) monitor_printf(mon, "%*s" fmt, indent, "", ## __VA_ARGS__)
 static void qbus_print(Monitor *mon, BusState *bus, int indent);
Signature · 1 line
Eduardo
#4 lore raw
In reply to Markus Armbruster
Quoted 38 lines · Markus Armbruster
Quoted 28 lines · Eduardo Habkost

This adds a new command to QMP: query-device-slots. It will allow management software to query possible slots where devices can be plugged.

This implementation of the command will return:

* Multiple PCI slots per bus, in the case of PCI buses;
* One slot per bus for the other buses (that don't implement slot enumeration yet);
* One slot for each entry from query-hotpluggable-cpus.

Git tree
--------

This patch needs the previous query-machines series I am working on. The full tree can be found on the git tree at:

git://github.com/ehabkost/qemu-hacks.git work/query-machines-bus-info

Example output
--------------

The following output was returned by QEMU when running it as:

 $ qemu-system-x86_64 -machine q35 \
   -readconfig docs/q35-chipset.cfg \
   -smp 4,maxcpus=8,sockets=2,cores=2,threads=2
Quoted 7 lines
  {
    "return": [
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "i2c"
Quoted 8 lines

Missing: bus "i2c-bus" device address, property name "address", value 0..255.

Quoted 2 lines
            },
            "type": "non-slot",

I guess "non-slot" means "props" is incomplete, but the rest should be okay.

Yes, non-slot is explicitly documented as incomplete.

Quoted 33 lines
Quoted 10 lines
            "accepted-device-types": [
                "i2c-slave"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ide.4"

Bus "IDE" device address property "unit", value 0 (because this is SATA, for PATA it would be 0..1).

Quoted 6 lines
            },
            "type": "non-slot",
            "accepted-device-types": [
                "ide-device"
            ]
        },

[...]

Quoted 11 lines
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "main-system-bus"
            },
            "type": "non-slot",
            "accepted-device-types": [
                "sys-bus-device"
            ]
        },
Quoted 1 line

Can't give guidance on this one, I'm afraid.

So, the good news here seems to be: very few machines-type accept sysbus devices on -device. This means we can investigate why exactly we set has_dynamic_sysbus=true on some machine-types (maybe this will be obvious from the git log, maybe it won't, but I'm feeling optimistic today), manually whitelist the (hopefully) few device types that can be created dynamically, create specific slots for them, and hide sysbus completely from clients.

Quoted 22 lines
Quoted 12 lines
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "isa.0"
            },
            "type": "non-slot",
            "accepted-device-types": [
                "isa-device"
            ]
        },

Bus "ISA" is iffy, too.

Quoted 6 lines
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 0
Quoted 2 lines

Really? "device_add e1000e,help" shows now property "device-number". Oh, I see, you're adding it in this patch, along with "function".

Yes. But I am still not sure about how to model/describe "function". Should we say that (device-number=0, function=0) and (device-number=0, function=1) are part of the same "slot", or two different slots?

If we implement something to easily represent slot sets, it will be easier to represent each PCI function as a separate slot.

Quoted 36 lines
Quoted 21 lines
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
                "device-number": 1
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },

[...]

Quoted 5 lines
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "pcie.0",
Quoted 8 lines
                "device-number": 31
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device",
                "pci-express-device"
            ]
        },
Quoted 6 lines

Design question: do we need to describe the bus with 32 separate objects, or would a single object do? The objects only differ in the value of props.device-number...

For a hypothetical bus with uint32_t device addresses, separate objects would be impossible. So we probably need to describe slot sets, anyway.

My question is: do we need to describe slots sets in the first version, or can we do it as an extension later?

Quoted 115 lines
Quoted 61 lines
        {
            "available": true,
            "hotpluggable": true,
            "props": {
                "bus": "ich9-pcie-port-1",
                "device-number": 0
            },
            "type": "pci",
            "accepted-device-types": [
                "pci-express-device"
            ]
        },
        {
            "available": true,
            "hotpluggable": true,
            "props": {
                "bus": "ich9-pcie-port-2",
                "device-number": 0
            },
            "type": "pci",
            "accepted-device-types": [
                "pci-express-device"
            ]
        },
        {
            "available": true,
            "hotpluggable": true,
            "props": {
                "bus": "ich9-pcie-port-3",
                "device-number": 0
            },
            "type": "pci",
            "accepted-device-types": [
                "pci-express-device"
            ]
        },
        {
            "available": true,
            "hotpluggable": true,
            "props": {
                "bus": "ich9-pcie-port-4",
                "device-number": 0
            },
            "type": "pci",
            "accepted-device-types": [
                "pci-express-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-pci-bridge",
                "device-number": 0
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },

[...]

Quoted 4 lines
        {
            "available": false,
            "hotpluggable": false,
            "props": {
Quoted 8 lines
                "bus": "ich9-pci-bridge",
                "device-number": 31
            },
            "type": "pci",
            "accepted-device-types": [
                "legacy-pci-device"
            ]
        },

Likewise.

Quoted 11 lines
        {
            "available": true,
            "hotpluggable": true,
            "props": {
                "bus": "ich9-ehci-1.0"
            },
            "type": "non-slot",
            "accepted-device-types": [
                "usb-device"
            ]
        },

Okay, more bad news: bus "usb-bus" device address property is "port", value is a sequence of port numbers separated by '.'. The reason is "convenience"

A real USB host controller has a fixed number of ports, numbered 1..N. This one has six.

A real USB hub device plugs into a port and in turn provides a fixed number of ports, numbered 1..N. The USB hub device we model provides eight.

An obvious way to model this would be to have the host controller provide a bus with a fixed number of slots, and the usb-hub provide a separate bus with eight. This is how we do PCI bridges. But it's not how we do USB hubs.

Host software can treat the tree formed by USB host controller, hubs and other devices as a single bus, and that's how we model it.

A "port" value that is a single number addresses that port on the host controller.

A value containing '.' addresses something behind a hub. The leftmost number addresses a host controller port. A hub must be plugged in there. Recurse for the rest of the port string.

Quoted 10 lines

If you device_add an USB device without specifying a port, it picks an unused one. When it has to pick the last port, it tries to add a usb-hub device there, which provides eight ports, then picks a port for your device. If adding the usb-hub succeeds, it'll get the new hub's port 1. Else, it gets the last port. There's a hard-coded limit of five on the depth of the hub chain. So, if you keep adding USB devices to the bus provided by ich9-ehci, the first five go into ports "1", ..., "5", the sixth goes into "6.1" (with usb-hub in port "6"), and so forth, until the 41st goes into "6.8.8.8.8.8". Adding hubs manually permits more devices.

I assume we won't need to represent the automagic port creation rules in the query. Only the next case:

Quoted 3 lines

If you do specify "port", then that port must already exist.

So, hubs are _not_ created automatically at ports "A", "A.B" and "A.B.C" if I explicitly try to plug something to port "A.B.C.D"? That's good news, because then we can simply represent only the available ports.

Quoted 27 lines

I think the sanest way to represent the existing ports is enumerating them, like this:

          {
              "available": true,
              "hotpluggable": true,
              "props": {
                  "bus": "ich9-ehci-1.0", "port": "1"
              },
              "type": "usb",
              "accepted-device-types": [
                  "usb-device"
              ]
          },
          [...]
          {
              "available": true,
              "hotpluggable": true,
              "props": {
                  "bus": "ich9-ehci-1.0", "port": "6"
              },
              "type": "usb",
              "accepted-device-types": [
                  "usb-device"
              ]
          },
Quoted 7 lines

Plugging usb-hub into a port with port: "P" then flips that port's "available" to false, and adds eight new ports with "port": "P.1", ... "P.8".

So, plugging a device can not only add buses provided by the device, but also, and less obviously, add slots to the bus it plugs into! Likewise for unplug.

Interesting.

Quoted 2 lines

Perhaps we should emit events when slots come and go.

Perhaps. Should we leave this for later?

FWIW, the problem I am trying to solve right now is querying for machine-type capabilities before creating the VM. The runtime querying command in this patch is just the first step. Then I plan to also return DeviceSlotInfo for machine-types just like the "query-machines"/"available-buses" series I sent.

Quoted 40 lines
Quoted 17 lines
        {
            "available": true,
            "hotpluggable": true,
            "props": {
                "bus": "ich9-ehci-2.0"
            },
            "type": "non-slot",
            "accepted-device-types": [
                "usb-device"
            ]
        },
        {
            "available": false,
            "hotpluggable": false,
            "props": {
                "bus": "ich9-hda-audio.0"

Bus "HDA" device address property is "cad", value 0..14.

Quoted 11 lines
            },
            "type": "non-slot",
            "accepted-device-types": [
                "hda-codec"
            ]
        },
        {
            "available": true,
            "hotpluggable": true,
            "props": {
                "socket-id": 1,
Quoted 8 lines
                "core-id": 1,
                "thread-id": 1
            },
            "type": "cpu",
            "accepted-device-types": [
                "qemu64-x86_64-cpu"
            ]
        },
Quoted 1 line

You know CPUs better than me.

Fortunately CPU slots are already modelled, I am just translating the query-hotpluggable-cpus data.

Quoted 5 lines

[More of them...]

Quoted 2 lines
    ]

}

Quoted 7 lines

There's still more...

Bus "SCSI" device address property is "scsi-id", value 0..N, where N depends on the SCSI HBA.

Bus "virtio-serial-bus" device address property is "nr", value 0..N, where N is configurable, currenrly up to 511.

Sounds like this is large enough to justify representing slot-sets since the first version of this interface.

Quoted 8 lines

ccid-bus device address property is "slot", value 0..N, where N depends on the device providing the bus (I think).

Buses not yet covered by docs/qdev-device-use.txt: "floppy-bus", "apple-desktop-bus", "IndustryPack", "aux-bus", "spapr-vio-bus", "virtual-css-bus", "s390-sclp-events-bus", "s390-pcibus", "sd-bus", "SSI", "virtio-bus", "xen-sysbus". Grep for ".parent = TYPE_BUS".

This will be fun...

Thanks a lot for the information and ideas about the cases above.

Quoted 6 lines

To find all buses in a certain build, use:

    { "execute": "qom-list-types", "arguments": { "implements": "bus" } }

[No code review, yet]

Signature · 1 line
Eduardo