diff mbox

spapr: Add support for -vga option

Message ID 1323854540.7671.16.camel@pasglop
State New
Headers show

Commit Message

Benjamin Herrenschmidt Dec. 14, 2011, 9:22 a.m. UTC
The -vga option is a handy "high level" option for instanciating things
automatically. This adds support for it to the spapr (aka pseries)
machine.

Also instanciate the USB keyboard and mouse when that option is used
(you can still use -device to create individual devices without all
the defaults)

The default remains no VGA and no USB, and of course you can use -device
to manually instanciate individual devices.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
 Makefile.target |    2 +-
 hw/spapr.c      |   47 ++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 47 insertions(+), 2 deletions(-)

Comments

Paolo Bonzini Dec. 14, 2011, 3:30 p.m. UTC | #1
On 12/14/2011 10:22 AM, Benjamin Herrenschmidt wrote:
> of course you can use -device
> to manually instanciate individual devices.

That's true, however...

> @@ -563,7 +568,9 @@ static void spapr_finalize_fdt(sPAPREnvironment *spapr,
>           }
>       }
>
> -    spapr_populate_chosen_stdout(fdt, spapr->vio_bus);
> +    if (!spapr_has_graphics) {
> +	spapr_populate_chosen_stdout(fdt, spapr->vio_bus);
> +    }
>
>       _FDT((fdt_pack(fdt)));
>

... the stdout-path would still point to the serial console.  Can that 
be fixed somehow?

Paolo
Benjamin Herrenschmidt Dec. 14, 2011, 8:04 p.m. UTC | #2
On Wed, 2011-12-14 at 16:30 +0100, Paolo Bonzini wrote:
> On 12/14/2011 10:22 AM, Benjamin Herrenschmidt wrote:
> > of course you can use -device
> > to manually instanciate individual devices.
> 
> That's true, however...
> 
> > @@ -563,7 +568,9 @@ static void spapr_finalize_fdt(sPAPREnvironment *spapr,
> >           }
> >       }
> >
> > -    spapr_populate_chosen_stdout(fdt, spapr->vio_bus);
> > +    if (!spapr_has_graphics) {
> > +	spapr_populate_chosen_stdout(fdt, spapr->vio_bus);
> > +    }
> >
> >       _FDT((fdt_pack(fdt)));
> >
> 
> ... the stdout-path would still point to the serial console.  Can that 
> be fixed somehow?

That's hard. We don't want to change it unless there is both a video
card and a keyboard and even then...

Ideally we'd want a way to specifiy what the stdout path is to qemu but
I don't see any clean way to do so.

Another option would be to remove setting of stdout path from qemu
completely and instead set it entirely in SLOF.

The problem with that is that we also have this thing where SLOF (and
the kenrel low level debug when enabled) output to hvterm 0, which we
"magically" route to the same hvterm that we chose for stdout-path in
qemu so things remain consistent.

I suppose a way to solve that would be to not set stdout path but
instead a different property (qemu,default-hvterm) which SLOF can use as
part of its algorithm to select a default console.

This wouldn't be ideal for non-SLOF boots (-kernel) but then I've been
thinking about getting rid of that feature anyway (always use SLOF, just
pass it the kernel image someway) since we want SLOF to setup the PCI
BARs (and now to initialize the video card) etc...

In any case, I'd like to do those changes as a separate patch on top of
this one which doesn't introduce a regression from what is there today.
At which point I can synchronize the SLOF and qemu updates.

(Note the patch I posted applies on top of David's internal -next
branch, it may not apply on top of what's out there today, David will
sort things out for me I expect :-)

Cheers,
Ben.
Anthony Liguori Dec. 14, 2011, 9:48 p.m. UTC | #3
On 12/14/2011 03:22 AM, Benjamin Herrenschmidt wrote:
> The -vga option is a handy "high level" option for instanciating things
> automatically. This adds support for it to the spapr (aka pseries)
> machine.
>
> Also instanciate the USB keyboard and mouse when that option is used
> (you can still use -device to create individual devices without all
> the defaults)
>
> The default remains no VGA and no USB, and of course you can use -device
> to manually instanciate individual devices.
>
> Signed-off-by: Benjamin Herrenschmidt<benh@kernel.crashing.org>
> ---
>   Makefile.target |    2 +-
>   hw/spapr.c      |   47 ++++++++++++++++++++++++++++++++++++++++++++++-
>   2 files changed, 47 insertions(+), 2 deletions(-)
>
> diff --git a/Makefile.target b/Makefile.target
> index 03e3c55..c78fc25 100644
> --- a/Makefile.target
> +++ b/Makefile.target
> @@ -243,7 +243,7 @@ obj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o
>
>   # shared objects
>   obj-ppc-y = ppc.o ppc_booke.o
> -obj-ppc-y += vga.o
> +obj-ppc-y += vga.o cirrus_vga.o
>   # PREP target
>   obj-ppc-y += mc146818rtc.o
>   obj-ppc-y += ppc_prep.o
> diff --git a/hw/spapr.c b/hw/spapr.c
> index c5353fb..3b9e576 100644
> --- a/hw/spapr.c
> +++ b/hw/spapr.c
> @@ -49,6 +49,7 @@
>   #include "pci.h"
>   #include "usb.h"
>   #include "usb-ohci.h"
> +#include "pc.h"
>
>   #include "exec-memory.h"
>
> @@ -76,6 +77,7 @@
>   #define PHANDLE_XICP            0x00001111
>
>   sPAPREnvironment *spapr;
> +static int spapr_has_graphics;
>
>   qemu_irq spapr_allocate_irq(uint32_t hint, uint32_t *irq_num)
>   {
> @@ -318,6 +320,9 @@ static void *spapr_create_fdt_skel(const char *cpu_model,
>       _FDT((fdt_property(fdt, "linux,initrd-end",
>                          &end_prop, sizeof(end_prop))));
>       _FDT((fdt_property_string(fdt, "qemu,boot-device", boot_device)));
> +    _FDT((fdt_property_cell(fdt, "qemu,graphic-width", graphic_width)));
> +    _FDT((fdt_property_cell(fdt, "qemu,graphic-height", graphic_height)));
> +    _FDT((fdt_property_cell(fdt, "qemu,graphic-depth", graphic_depth)));
>
>       _FDT((fdt_end_node(fdt)));
>
> @@ -563,7 +568,9 @@ static void spapr_finalize_fdt(sPAPREnvironment *spapr,
>           }
>       }
>
> -    spapr_populate_chosen_stdout(fdt, spapr->vio_bus);
> +    if (!spapr_has_graphics) {
> +	spapr_populate_chosen_stdout(fdt, spapr->vio_bus);
> +    }
>
>       _FDT((fdt_pack(fdt)));
>
> @@ -603,6 +610,26 @@ static void spapr_reset(void *opaque)
>
>   }
>
> +static int spapr_vga_init(PCIBus *pci_bus)
> +{
> +    /* Default is nothing */
> +    if (cirrus_vga_enabled) {
> +        pci_cirrus_vga_init(pci_bus);
> +    } else if (vmsvga_enabled) {
> +	fprintf(stderr, "Warning: vmware_vga not available,"
> +		" using standard VGA instead\n");
> +	pci_vga_init(pci_bus);
> +#ifdef CONFIG_SPICE
> +    } else if (qxl_enabled) {
> +        pci_create_simple(pci_bus, -1, "qxl-vga");
> +#endif
> +    } else if (std_vga_enabled) {
> +        pci_vga_init(pci_bus);
> +    } else
> +       return 0;
> +    return 1;
> +}
> +
>   /* pSeries LPAR / sPAPR hardware init */
>   static void ppc_spapr_init(ram_addr_t ram_size,
>                              const char *boot_device,
> @@ -746,9 +773,27 @@ static void ppc_spapr_init(ram_addr_t ram_size,
>           spapr_vscsi_create(spapr->vio_bus, 0x2000 + i);
>       }
>
> +    /* Graphics */
> +    if (spapr_vga_init(QLIST_FIRST(&spapr->phbs)->host_state.bus)) {
> +	spapr_has_graphics = 1;
> +	usb_enabled = 1;
> +    }
> +
> +    /* Default depth is 15 which is bad, SLOF only supports 8 so it should
> +     * be the default (while we should still allow to specify 16 or 32)
> +     * so I'm cheating and converting 15 to 8 here. Ideally we should have
> +     * a way to set the defaults per machine.
> +     */
> +    if (graphic_depth == 15)
> +        graphic_depth = 8;
> +
>       /* USB */
>       if (usb_enabled) {
>           usb_ohci_init_pci(QLIST_FIRST(&spapr->phbs)->host_state.bus, -1);
> +	if (spapr_has_graphics) {
> +	    usbdevice_create("keyboard");
> +	    usbdevice_create("mouse");

It is better to use usb_create() and pass it the usb bus directly as this will 
make it easier to express this as composition down the road.

Regards,

Anthony Liguori

> +	}
>       }
>
>       if (kernel_filename) {
>
>
>
Benjamin Herrenschmidt Dec. 15, 2011, midnight UTC | #4
On Wed, 2011-12-14 at 15:48 -0600, Anthony Liguori wrote:
> >       /* USB */
> >       if (usb_enabled) {
> >
> usb_ohci_init_pci(QLIST_FIRST(&spapr->phbs)->host_state.bus, -1);
> > +     if (spapr_has_graphics) {
> > +         usbdevice_create("keyboard");
> > +         usbdevice_create("mouse");
> 
> It is better to use usb_create() and pass it the usb bus directly as
> this will make it easier to express this as composition down the road.

How do I do that ? usb_ohci_init_pci() doesn't appear to return
the USB bus....

Cheers,
Ben.
Anthony Liguori Dec. 15, 2011, 12:10 a.m. UTC | #5
On 12/14/2011 06:00 PM, Benjamin Herrenschmidt wrote:
> On Wed, 2011-12-14 at 15:48 -0600, Anthony Liguori wrote:
>>>        /* USB */
>>>        if (usb_enabled) {
>>>
>> usb_ohci_init_pci(QLIST_FIRST(&spapr->phbs)->host_state.bus, -1);
>>> +     if (spapr_has_graphics) {
>>> +         usbdevice_create("keyboard");
>>> +         usbdevice_create("mouse");
>>
>> It is better to use usb_create() and pass it the usb bus directly as
>> this will make it easier to express this as composition down the road.
>
> How do I do that ? usb_ohci_init_pci() doesn't appear to return
> the USB bus....

Let's make it...  I'll send a patch.

Regards,

Anthony Liguori

>
> Cheers,
> Ben.
>
>
>
Benjamin Herrenschmidt Dec. 23, 2011, 5:36 a.m. UTC | #6
On Wed, 2011-12-14 at 20:22 +1100, Benjamin Herrenschmidt wrote:
> The -vga option is a handy "high level" option for instanciating things
> automatically. This adds support for it to the spapr (aka pseries)
> machine.
> 
> Also instanciate the USB keyboard and mouse when that option is used
> (you can still use -device to create individual devices without all
> the defaults)
> 
> The default remains no VGA and no USB, and of course you can use -device
> to manually instanciate individual devices.
> 
> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> ---

BTW. Don't apply this just yet. New version coming soon.

Cheers,
Ben.

>  Makefile.target |    2 +-
>  hw/spapr.c      |   47 ++++++++++++++++++++++++++++++++++++++++++++++-
>  2 files changed, 47 insertions(+), 2 deletions(-)
> 
> diff --git a/Makefile.target b/Makefile.target
> index 03e3c55..c78fc25 100644
> --- a/Makefile.target
> +++ b/Makefile.target
> @@ -243,7 +243,7 @@ obj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o
>  
>  # shared objects
>  obj-ppc-y = ppc.o ppc_booke.o
> -obj-ppc-y += vga.o
> +obj-ppc-y += vga.o cirrus_vga.o
>  # PREP target
>  obj-ppc-y += mc146818rtc.o
>  obj-ppc-y += ppc_prep.o
> diff --git a/hw/spapr.c b/hw/spapr.c
> index c5353fb..3b9e576 100644
> --- a/hw/spapr.c
> +++ b/hw/spapr.c
> @@ -49,6 +49,7 @@
>  #include "pci.h"
>  #include "usb.h"
>  #include "usb-ohci.h"
> +#include "pc.h"
>  
>  #include "exec-memory.h"
>  
> @@ -76,6 +77,7 @@
>  #define PHANDLE_XICP            0x00001111
>  
>  sPAPREnvironment *spapr;
> +static int spapr_has_graphics;
>  
>  qemu_irq spapr_allocate_irq(uint32_t hint, uint32_t *irq_num)
>  {
> @@ -318,6 +320,9 @@ static void *spapr_create_fdt_skel(const char *cpu_model,
>      _FDT((fdt_property(fdt, "linux,initrd-end",
>                         &end_prop, sizeof(end_prop))));
>      _FDT((fdt_property_string(fdt, "qemu,boot-device", boot_device)));
> +    _FDT((fdt_property_cell(fdt, "qemu,graphic-width", graphic_width)));
> +    _FDT((fdt_property_cell(fdt, "qemu,graphic-height", graphic_height)));
> +    _FDT((fdt_property_cell(fdt, "qemu,graphic-depth", graphic_depth)));
>  
>      _FDT((fdt_end_node(fdt)));
>  
> @@ -563,7 +568,9 @@ static void spapr_finalize_fdt(sPAPREnvironment *spapr,
>          }
>      }
>  
> -    spapr_populate_chosen_stdout(fdt, spapr->vio_bus);
> +    if (!spapr_has_graphics) {
> +	spapr_populate_chosen_stdout(fdt, spapr->vio_bus);
> +    }
>  
>      _FDT((fdt_pack(fdt)));
>  
> @@ -603,6 +610,26 @@ static void spapr_reset(void *opaque)
>  
>  }
>  
> +static int spapr_vga_init(PCIBus *pci_bus)
> +{
> +    /* Default is nothing */
> +    if (cirrus_vga_enabled) {
> +        pci_cirrus_vga_init(pci_bus);
> +    } else if (vmsvga_enabled) {
> +	fprintf(stderr, "Warning: vmware_vga not available,"
> +		" using standard VGA instead\n");
> +	pci_vga_init(pci_bus);
> +#ifdef CONFIG_SPICE
> +    } else if (qxl_enabled) {
> +        pci_create_simple(pci_bus, -1, "qxl-vga");
> +#endif
> +    } else if (std_vga_enabled) {
> +        pci_vga_init(pci_bus);
> +    } else
> +       return 0;
> +    return 1;
> +}
> +
>  /* pSeries LPAR / sPAPR hardware init */
>  static void ppc_spapr_init(ram_addr_t ram_size,
>                             const char *boot_device,
> @@ -746,9 +773,27 @@ static void ppc_spapr_init(ram_addr_t ram_size,
>          spapr_vscsi_create(spapr->vio_bus, 0x2000 + i);
>      }
>  
> +    /* Graphics */
> +    if (spapr_vga_init(QLIST_FIRST(&spapr->phbs)->host_state.bus)) {
> +	spapr_has_graphics = 1;
> +	usb_enabled = 1;
> +    }
> +
> +    /* Default depth is 15 which is bad, SLOF only supports 8 so it should
> +     * be the default (while we should still allow to specify 16 or 32)
> +     * so I'm cheating and converting 15 to 8 here. Ideally we should have
> +     * a way to set the defaults per machine.
> +     */
> +    if (graphic_depth == 15)
> +        graphic_depth = 8;
> +
>      /* USB */
>      if (usb_enabled) {
>          usb_ohci_init_pci(QLIST_FIRST(&spapr->phbs)->host_state.bus, -1);
> +	if (spapr_has_graphics) {
> +	    usbdevice_create("keyboard");
> +	    usbdevice_create("mouse");
> +	}
>      }
>  
>      if (kernel_filename) {
>
diff mbox

Patch

diff --git a/Makefile.target b/Makefile.target
index 03e3c55..c78fc25 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -243,7 +243,7 @@  obj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o
 
 # shared objects
 obj-ppc-y = ppc.o ppc_booke.o
-obj-ppc-y += vga.o
+obj-ppc-y += vga.o cirrus_vga.o
 # PREP target
 obj-ppc-y += mc146818rtc.o
 obj-ppc-y += ppc_prep.o
diff --git a/hw/spapr.c b/hw/spapr.c
index c5353fb..3b9e576 100644
--- a/hw/spapr.c
+++ b/hw/spapr.c
@@ -49,6 +49,7 @@ 
 #include "pci.h"
 #include "usb.h"
 #include "usb-ohci.h"
+#include "pc.h"
 
 #include "exec-memory.h"
 
@@ -76,6 +77,7 @@ 
 #define PHANDLE_XICP            0x00001111
 
 sPAPREnvironment *spapr;
+static int spapr_has_graphics;
 
 qemu_irq spapr_allocate_irq(uint32_t hint, uint32_t *irq_num)
 {
@@ -318,6 +320,9 @@  static void *spapr_create_fdt_skel(const char *cpu_model,
     _FDT((fdt_property(fdt, "linux,initrd-end",
                        &end_prop, sizeof(end_prop))));
     _FDT((fdt_property_string(fdt, "qemu,boot-device", boot_device)));
+    _FDT((fdt_property_cell(fdt, "qemu,graphic-width", graphic_width)));
+    _FDT((fdt_property_cell(fdt, "qemu,graphic-height", graphic_height)));
+    _FDT((fdt_property_cell(fdt, "qemu,graphic-depth", graphic_depth)));
 
     _FDT((fdt_end_node(fdt)));
 
@@ -563,7 +568,9 @@  static void spapr_finalize_fdt(sPAPREnvironment *spapr,
         }
     }
 
-    spapr_populate_chosen_stdout(fdt, spapr->vio_bus);
+    if (!spapr_has_graphics) {
+	spapr_populate_chosen_stdout(fdt, spapr->vio_bus);
+    }
 
     _FDT((fdt_pack(fdt)));
 
@@ -603,6 +610,26 @@  static void spapr_reset(void *opaque)
 
 }
 
+static int spapr_vga_init(PCIBus *pci_bus)
+{
+    /* Default is nothing */
+    if (cirrus_vga_enabled) {
+        pci_cirrus_vga_init(pci_bus);
+    } else if (vmsvga_enabled) {
+	fprintf(stderr, "Warning: vmware_vga not available,"
+		" using standard VGA instead\n");
+	pci_vga_init(pci_bus);
+#ifdef CONFIG_SPICE
+    } else if (qxl_enabled) {
+        pci_create_simple(pci_bus, -1, "qxl-vga");
+#endif
+    } else if (std_vga_enabled) {
+        pci_vga_init(pci_bus);
+    } else
+       return 0;
+    return 1;
+}
+
 /* pSeries LPAR / sPAPR hardware init */
 static void ppc_spapr_init(ram_addr_t ram_size,
                            const char *boot_device,
@@ -746,9 +773,27 @@  static void ppc_spapr_init(ram_addr_t ram_size,
         spapr_vscsi_create(spapr->vio_bus, 0x2000 + i);
     }
 
+    /* Graphics */
+    if (spapr_vga_init(QLIST_FIRST(&spapr->phbs)->host_state.bus)) {
+	spapr_has_graphics = 1;
+	usb_enabled = 1;
+    }
+
+    /* Default depth is 15 which is bad, SLOF only supports 8 so it should
+     * be the default (while we should still allow to specify 16 or 32)
+     * so I'm cheating and converting 15 to 8 here. Ideally we should have
+     * a way to set the defaults per machine.
+     */
+    if (graphic_depth == 15)
+        graphic_depth = 8;
+
     /* USB */
     if (usb_enabled) {
         usb_ohci_init_pci(QLIST_FIRST(&spapr->phbs)->host_state.bus, -1);
+	if (spapr_has_graphics) {
+	    usbdevice_create("keyboard");
+	    usbdevice_create("mouse");
+	}
     }
 
     if (kernel_filename) {