Add a generic vga device type for that specified by '-device'
PATCH 1/2 Add a generic vga device type for that specified by '-device'
Some machine (like ppc) initialization code determines if it has vga configured according to vga_interface_type. In the original code, vga_interface_type is evaluated to VGA_NONE even if a vga is added by '-device VGA'. It causes the machine not aware of the graphics device configured. This patch adds a new vga device type to indicate that it has a vga device, but the machine code doesn't need to care about its initialization.
--- include/sysemu/sysemu.h | 2 +- vl.c | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-)
include/sysemu/sysemu.h +1 -1
@@ -103,7 +103,7 @@ typedef enum DisplayTypeextern int autostart;typedef enum { -VGA_NONE ,VGA_STD ,VGA_CIRRUS ,VGA_VMWARE ,VGA_XENFB ,VGA_QXL , +VGA_NONE ,VGA_STD ,VGA_CIRRUS ,VGA_VMWARE ,VGA_XENFB ,VGA_QXL ,VGA_DEVICE }VGAInterfaceType ;extern int vga_interface_type;
vl.c +7 -1
@@ -226,6 +226,7 @@ static int default_floppy = 1;static int default_cdrom =1 ;static int default_sdcard =1 ;static int default_vga =1 ; +static int has_defaults =1 ; static struct { const char *driver;
@@ -2066,7 +2067,11 @@ static void select_vgahw (const char *p)fprintf (stderr,"Error: QXL VGA not available\n" );exit (0 ); } - }else if (!strstart (p,"none" , &opts)) { + }else if (strstart (p,"none" , &opts)) { +if (!has_defaults && !default_vga) { + vga_interface_type =VGA_DEVICE ; + } + }else { invalid_vga:fprintf (stderr,"Unknown vga type: %s\n" , p);exit (1 );
@@ -3672,6 +3677,7 @@ int main(int argc, char **argv, char **envp) default_cdrom =0 ; default_sdcard =0 ; default_vga =0 ; + has_defaults =0 ;break ;case QEMU_OPTION_xen_domid:if (!(xen_available ())) {
Signature · 1 line
1.8.4.2
PATCH 2/2 Fix return value of vga initlization on ppc
Before spapr_vga_init will returned false if the vga is specified by the command '-device VGA' because vga_interface_type was evaluated to VGA_NONE. With the change in previous patch of this series, spapr_vga_init should return true if it's told that the vga will be initialized in flow of the generic devices initialization.
This patch also makes two cleanups:
1. skip initialization for VGA_NONE
2. remove the useless 'break'
--- hw/ppc/spapr.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
hw/ppc/spapr.c +3 -1
@@ -765,13 +765,15 @@ static int spapr_vga_init(PCIBus *pci_bus) {switch (vga_interface_type) {case VGA_NONE : +return false; +case VGA_DEVICE : +return true;case VGA_STD :return pci_vga_init (pci_bus) !=NULL ;default :fprintf (stderr,"This vga model is not supported," "currently it only supports -vga std\n" );exit (0 ); -break ; } }
Signature · 1 line
1.8.4.2
Il 28/02/2014 13:45, Mark Wu ha scritto:
Quoted 7 lines
Some machine (like ppc) initialization code determines if it has vga configured according to
vga_interface_type. In the original code,vga_interface_typeis evaluated toVGA_NONEeven if a vga is added by '-device VGA'. It causes the machine not aware of the graphics device configured. This patch adds a new vga device type to indicate that it has a vga device, but the machine code doesn't need to care about its initialization.
Can you use memory_region_present and look (for example) for a device that owns I/O port 0x3d4?
Paolo
Quoted 53 lines
Signed-off-by Mark Wu <[email protected]>--- include/sysemu/sysemu.h | 2 +- vl.c | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-)include/sysemu/sysemu.h +1
-1@@ -103,7 +103,7 @@ typedef enum DisplayTypeextern int autostart;typedef enum { -VGA_NONE ,VGA_STD ,VGA_CIRRUS ,VGA_VMWARE ,VGA_XENFB ,VGA_QXL , +VGA_NONE ,VGA_STD ,VGA_CIRRUS ,VGA_VMWARE ,VGA_XENFB ,VGA_QXL ,VGA_DEVICE }VGAInterfaceType ;extern int vga_interface_type;vl.c +7
-1@@ -226,6 +226,7 @@ static int default_floppy = 1;static int default_cdrom =1 ;static int default_sdcard =1 ;static int default_vga =1 ; +static int has_defaults =1 ; static struct { const char *driver;@@ -2066,7 +2067,11 @@ static void select_vgahw (const char *p)fprintf (stderr,"Error: QXL VGA not available\n" );exit (0 ); } - }else if (!strstart (p,"none" , &opts)) { + }else if (strstart (p,"none" , &opts)) { +if (!has_defaults && !default_vga) { + vga_interface_type =VGA_DEVICE ; + } + }else { invalid_vga:fprintf (stderr,"Unknown vga type: %s\n" , p);exit (1 );@@ -3672,6 +3677,7 @@ int main(int argc, char **argv, char **envp) default_cdrom =0 ; default_sdcard =0 ; default_vga =0 ; + has_defaults =0 ;break ;case QEMU_OPTION_xen_domid:if (!(xen_available ())) {
Quoted 10 lines · Paolo Bonzini
Il 28/02/2014 13:45, Mark Wu ha scritto:
Quoted 7 lines
Some machine (like ppc) initialization code determines if it has vga configured according to
vga_interface_type. In the original code,vga_interface_typeis evaluated toVGA_NONEeven if a vga is added by '-device VGA'. It causes the machine not aware of the graphics device configured. This patch adds a new vga device type to indicate that it has a vga device, but the machine code doesn't need to care about its initialization.Can you use
memory_region_presentand look (for example) for a device that owns I/O port0x3d4?
Thanks for your reply! I need confirm I am understanding your comments correctly. I think you're suggesting to traverse the pci devices and check if it owns the I/O port 0x3d4 to detect if the vga device
is initialized. But it seems not be able to resolve the bug. Because the machine initialization code runs before the generic device initialization, the I/O port 0x3d4 will not be registered at the time machine initializes. So it can't change the return value of pci_vga_init. The return value is checked in ppc code, which causes the bug.
Please correct me if my understanding on your comments is wrong. Thanks!
Quoted 59 lines
Paolo
Quoted 54 lines
Signed-off-by Mark Wu <[email protected]>--- include/sysemu/sysemu.h | 2 +- vl.c | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-)include/sysemu/sysemu.h +1
-1@@ -103,7 +103,7 @@ typedef enum DisplayTypeextern int autostart; typedef enum { - VGA_NONE, VGA_STD, VGA_CIRRUS, VGA_VMWARE, VGA_XENFB, VGA_QXL, + VGA_NONE, VGA_STD, VGA_CIRRUS, VGA_VMWARE, VGA_XENFB, VGA_QXL,
VGA_DEVICE
} VGAInterfaceType;extern int
vga_interface_type;vl.c +7
-1@@ -226,6 +226,7 @@ static int default_floppy = 1;static int default_cdrom =1 ;static int default_sdcard =1 ;static int default_vga =1 ; +static int has_defaults =1 ; static struct { const char *driver;@@ -2066,7 +2067,11 @@ static void select_vgahw (const char *p)fprintf (stderr,"Error: QXL VGA not available\n" );exit (0 ); } - }else if (!strstart (p,"none" , &opts)) { + }else if (strstart (p,"none" , &opts)) { +if (!has_defaults && !default_vga) { + vga_interface_type =VGA_DEVICE ; + } + }else { invalid_vga:fprintf (stderr,"Unknown vga type: %s\n" , p);exit (1 );@@ -3672,6 +3677,7 @@ int main(int argc, char **argv, char **envp) default_cdrom =0 ; default_sdcard =0 ; default_vga =0 ; + has_defaults =0 ;break ;case QEMU_OPTION_xen_domid:if (!(xen_available ())) {
Il 06/03/2014 14:37, Mark Wu ha scritto:
Quoted 9 lines
Thanks for your reply! I need confirm I am understanding your comments correctly. I think you're suggesting to traverse the pci devices and check if it owns the I/O port
0x3d4to detect if the vga device
is initialized. But it seems not be able to resolve the bug. Because
the machine initialization code runs before the generic device initialization, the I/O port0x3d4will not be registered at the time machine initializes. So it can't change the return value ofpci_vga_init. The return value is checked in ppc code, which causes the bug.
Right. What about looking for any PCI device with VGA class?
Paolo
Am 06.03.2014 15:33, schrieb Paolo Bonzini:
Quoted 11 lines
Il 06/03/2014 14:37, Mark Wu ha scritto:
Quoted 9 lines
Thanks for your reply! I need confirm I am understanding your comments correctly. I think you're suggesting to traverse the pci devices and check if it owns the I/O port
0x3d4to detect if the vga device
is initialized. But it seems not be able to resolve the bug. Because
the machine initialization code runs before the generic device initialization, the I/O port0x3d4will not be registered at the time machine initializes. So it can't change the return value ofpci_vga_init. The return value is checked in ppc code, which causes the bug.
Quoted 1 line
Right. What about looking for any PCI device with VGA class?
Since VGA doesn't need to be PCI (e.g., ISA, SysBus) maybe it would be a good idea to add a QOM interface to those devices?
Regards,
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Il 06/03/2014 15:39, Andreas Färber ha scritto:
Quoted 12 lines
Am 06.03.2014 15:33, schrieb Paolo Bonzini:
Quoted 11 lines
Il 06/03/2014 14:37, Mark Wu ha scritto:
Quoted 9 lines
Thanks for your reply! I need confirm I am understanding your comments correctly. I think you're suggesting to traverse the pci devices and check if it owns the I/O port
0x3d4to detect if the vga device
is initialized. But it seems not be able to resolve the bug. Because
the machine initialization code runs before the generic device initialization, the I/O port0x3d4will not be registered at the time machine initializes. So it can't change the return value ofpci_vga_init. The return value is checked in ppc code, which causes the bug.
Quoted 4 lines
Quoted 1 line
Right. What about looking for any PCI device with VGA class?
Since VGA doesn't need to be PCI (e.g., ISA, SysBus) maybe it would be a good idea to add a QOM interface to those devices?
Actually, I now understand the problem better. All of this happens before the VGA device is even created, so it cannot be done with QOM. It's basically a command-line parsing problem.
There are four cases:
1) "-vga none" on the command line
2) "-device VGA" on the command line
3) "-nodefaults" on the command line
4) "-nodefaults -device VGA" on the command line
sPAPR wants to enable graphics in the second and fourth case. However, this is not exactly what the patch does, as I read it, because it actually enables graphics in the third and fourth cases, and not in the second case. Both the third and the fourth case have !has_defaults, and with has_defaults == 0 you always have default_vga == 0.
The last three cases have "default_vga == 0" in vl.c. The problem is that -nodefaults sets default_vga to 0 too early. Perhaps something like this would work:
vl.c +22 -20
@@ -213,6 +213,7 @@ ---> add a new variableenum xen_mode xen_mode =XEN_EMULATE ;static int tcg_tb_size; +static int no_defaults =0 ;static int default_serial =1 ;static int default_parallel =1 ;static int default_virtcon =1 ;
@@ -2041,7 +2042,7 @@ ---> select_vgahw is never called with VGA_DEVICE {const char *opts; - vga_interface_type =VGA_NONE ; +assert (vga_interface_type ==VGA_NONE );if (strstart (p,"std" , &opts)) {if (vga_available ()) { vga_interface_type =VGA_STD ;
@@ -2825,7 +2826,7 @@ ---> need to detect -vgaconst char *loadvm =NULL ;QEMUMachine *machine;const char *cpu_model; -const char *vga_model ="none" ; +const char *vga_model =NULL ;const char *qtest_chrdev =NULL ;const char *qtest_log =NULL ;const char *pid_file =NULL ;
@@ -3682,16 +3683,7 @@ ---> just set a flag hererunstate_set (RUN_STATE_INMIGRATE );break ;case QEMU_OPTION_nodefaults: - default_serial =0 ; - default_parallel =0 ; - default_virtcon =0 ; - default_sclp =0 ; - default_monitor =0 ; - default_net =0 ; - default_floppy =0 ; - default_cdrom =0 ; - default_sdcard =0 ; - default_vga =0 ; + no_defaults =1 ;break ;case QEMU_OPTION_xen_domid:if (!(xen_available ())) {
@@ -3918,27 +3910,35 @@ ---> detect "-device VGA" here, also disable defaults for -nodefaultsqemu_opts_foreach (qemu_find_opts ("device" ), default_driver_check,NULL ,0 );qemu_opts_foreach (qemu_find_opts ("global" ), default_driver_check,NULL ,0 ); -if (machine->no_serial) { +if (!vga_model && !default_vga) { + vga_interface_type =VGA_DEVICE ; + } +if (no_defaults || machine->no_serial) { default_serial =0 ; } -if (machine->no_parallel) { +if (no_defaults || machine->no_parallel) { default_parallel =0 ; } -if (!machine->use_virtcon) { +if (no_defaults || !machine->use_virtcon) { default_virtcon =0 ; } -if (!machine->use_sclp) { +if (no_defaults || !machine->use_sclp) { default_sclp =0 ; } -if (machine->no_floppy) { +if (no_defaults || machine->no_floppy) { default_floppy =0 ; } -if (machine->no_cdrom) { +if (no_defaults || machine->no_cdrom) { default_cdrom =0 ; } -if (machine->no_sdcard) { +if (no_defaults || machine->no_sdcard) { default_sdcard =0 ; } +if (no_defaults) { + default_monitor =0 ; + default_net =0 ; + default_vga =0 ; + }if (is_daemonized ()) {/* According to documentation and historically, -nographic redirects
@@ -4243,7 +4243,9 @@ ---> only call select_vgahw for "-vga" (or the default VGA, see the if ending here) vga_model ="std" ; } } -select_vgahw (vga_model); +if (vga_model) { +select_vgahw (vga_model); + }if (watchdog) { i =select_watchdog (watchdog);
Quoted 27 lines · Paolo Bonzini
Il 06/03/2014 15:39, Andreas Färber ha scritto:
Quoted 11 lines
Am 06.03.2014 15:33, schrieb Paolo Bonzini:
Quoted 10 lines
Il 06/03/2014 14:37, Mark Wu ha scritto:
Quoted 9 lines
Thanks for your reply! I need confirm I am understanding your comments correctly. I think you're suggesting to traverse the pci devices and check if it owns the I/O port
0x3d4to detect if the vga device
is initialized. But it seems not be able to resolve the bug. Because
the machine initialization code runs before the generic device initialization, the I/O port0x3d4will not be registered at the time machine initializes. So it can't change the return value ofpci_vga_init. The return value is checked in ppc code, which causes the bug.Quoted 3 lines
Quoted 1 line
Right. What about looking for any PCI device with VGA class?
Since VGA doesn't need to be PCI (e.g., ISA, SysBus) maybe it would be a good idea to add a QOM interface to those devices?
Actually, I now understand the problem better. All of this happens before the VGA device is even created, so it cannot be done with QOM. It's basically a command-line parsing problem.
There are four cases:
1) "-vga none" on the command line
2) "-device VGA" on the command line
3) "-nodefaults" on the command line
Quoted 7 lines
4) "-nodefaults -device VGA" on the command line
sPAPR wants to enable graphics in the second and fourth case. However, this is not exactly what the patch does, as I read it, because it actually enables graphics in the third and fourth cases, and not in the second case. Both the third and the fourth case have !has_defaults, and with
has_defaults== 0 you always havedefault_vga== 0.
Yes, you're correct. I didn't think it clearly. I will update the patch as what you suggested. Thanks a lot for the great help!
Quoted 108 lines
The last three cases have "
default_vga== 0" invl.c. The problem is that -nodefaults setsdefault_vgato 0 too early. Perhaps something like this would work:vl.c +22
-20@@ -213,6 +213,7 @@ ---> add a new variableenum xen_mode xen_mode =XEN_EMULATE ;static int tcg_tb_size; +static int no_defaults =0 ;static int default_serial =1 ;static int default_parallel =1 ;static int default_virtcon =1 ;@@ -2041,7 +2042,7 @@ ---> select_vgahw is never called with VGA_DEVICE {const char *opts; - vga_interface_type =VGA_NONE ; +assert (vga_interface_type ==VGA_NONE );if (strstart (p,"std" , &opts)) {if (vga_available ()) { vga_interface_type =VGA_STD ;@@ -2825,7 +2826,7 @@ ---> need to detect -vgaconst char *loadvm =NULL ;QEMUMachine *machine;const char *cpu_model; -const char *vga_model ="none" ; +const char *vga_model =NULL ;const char *qtest_chrdev =NULL ;const char *qtest_log =NULL ;const char *pid_file =NULL ;@@ -3682,16 +3683,7 @@ ---> just set a flag hererunstate_set (RUN_STATE_INMIGRATE );break ;case QEMU_OPTION_nodefaults: - default_serial =0 ; - default_parallel =0 ; - default_virtcon =0 ; - default_sclp =0 ; - default_monitor =0 ; - default_net =0 ; - default_floppy =0 ; - default_cdrom =0 ; - default_sdcard =0 ; - default_vga =0 ; + no_defaults =1 ;break ;case QEMU_OPTION_xen_domid:if (!(xen_available ())) {@@ -3918,27 +3910,35 @@ ---> detect "-device VGA" here, also disable defaults for -nodefaultsqemu_opts_foreach (qemu_find_opts ("device" ), default_driver_check,NULL ,0 );qemu_opts_foreach (qemu_find_opts ("global" ), default_driver_check,NULL ,0 ); -if (machine->no_serial) { +if (!vga_model && !default_vga) { + vga_interface_type =VGA_DEVICE ; + } +if (no_defaults || machine->no_serial) { default_serial =0 ; } -if (machine->no_parallel) { +if (no_defaults || machine->no_parallel) { default_parallel =0 ; } -if (!machine->use_virtcon) { +if (no_defaults || !machine->use_virtcon) { default_virtcon =0 ; } -if (!machine->use_sclp) { +if (no_defaults || !machine->use_sclp) { default_sclp =0 ; } -if (machine->no_floppy) { +if (no_defaults || machine->no_floppy) { default_floppy =0 ; } -if (machine->no_cdrom) { +if (no_defaults || machine->no_cdrom) { default_cdrom =0 ; } -if (machine->no_sdcard) { +if (no_defaults || machine->no_sdcard) { default_sdcard =0 ; } +if (no_defaults) { + default_monitor =0 ; + default_net =0 ; + default_vga =0 ; + }if (is_daemonized ()) {/* According to documentation and historically, -nographic redirects @@ -4243,7 +4243,9 @@ ---> only call select_vgahw for "-vga" (or the default VGA, see the if ending here) vga_model ="std" ; } } -select_vgahw (vga_model); +if (vga_model) { +select_vgahw (vga_model); + }if (watchdog) { i =select_watchdog (watchdog);