At very beginning, I want to take destroy-and-recreate method to implement VGA live switch. After reading code and doing some experiments, I find both of two ways can hide the VGA device. And then we can assign VGA device to another HVM during its creating process.
1. Invoke pci_hide_device function, which set pci_dev->bus->devices[0x10] to NULL
2. dpci_infos.php_devs[0x10].valid =1
And the qemu-hw gets the knowledge of passthrough pci devices from the PCIBus and dpci_infos structures. These two structures reserve the context of each pt pci devce, such as its irqs、write function、read function、mmio maps、pio maps… So I have a simple idea that we can assign which domain to use VGA screen by saving/restoring VGA device infos of these two structures. My experiment result as below:
[root@localhost ~]# xm list
Name ID Mem VCPUs State Time(s)
Domain-0 0 1786 4 r----- 67.2
PHY_HVMDomain 1 2048 4 -b---- 219.1
[root@localhost ~]# xm pci-list 1
VSlt VFn domain bus slot func
0x02 0x0 0x0000 0x00 0x02 0x0
0x05 0x0 0x0000 0x00 0x1a 0x0
0x06 0x0 0x0000 0x00 0x1a 0x1
0x07 0x0 0x0000 0x00 0x1a 0x2
0x08 0x0 0x0000 0x00 0x1a 0x7
[root@localhost ~]# xm pause 1
[root@localhost ~]# xm pci-detach 1 00:00:02.0
[root@localhost ~]# xm pci-list 1
VSlt VFn domain bus slot func
0x05 0x0 0x0000 0x00 0x1a 0x0
0x06 0x0 0x0000 0x00 0x1a 0x1
0x07 0x0 0x0000 0x00 0x1a 0x2
0x08 0x0 0x0000 0x00 0x1a 0x7
[root@localhost ~]# xm list
Name ID Mem VCPUs State Time(s)
Domain-0 0 1786 4 r----- 68.9
PHY_HVMDomain 1 2048 4 --p--- 223.3
[root@localhost ~]# xm pci-attach 1 00:00:02.0
[root@localhost ~]# xm unpause 1
[root@localhost ~]# xm list
Name ID Mem VCPUs State Time(s)
Domain-0 0 1786 4 r----- 69.6
PHY_HVMDomain 1 2048 4 -b---- 224.3
[root@localhost ~]# xm pci-list 1
VSlt VFn domain bus slot func
0x02 0x0 0x0000 0x00 0x02 0x0
0x05 0x0 0x0000 0x00 0x1a 0x0
0x06 0x0 0x0000 0x00 0x1a 0x1
0x07 0x0 0x0000 0x00 0x1a 0x2
0x08 0x0 0x0000 0x00 0x1a 0x7
[root@localhost ~]# xm list
Name ID Mem VCPUs State Time(s)
Domain-0 0 1786 4 r----- 70.3
PHY_HVMDomain 1 2048 4 -b---- 225.6
[root@localhost ~]#
When unpausing PHY_HVMDomain, it seems working well. But the screen is black and cannot receive any signals. I am sure that this strategy missed something important, especially on video BIOS. Could you give me some ideas?