2013-03-17 17:06:52 -04:00
#
2013-10-27 21:59:46 +01:00
# Copyright 2009, 2013 Red Hat, Inc.
2013-03-17 17:06:52 -04:00
#
2018-04-04 14:35:41 +01:00
# This work is licensed under the GNU GPLv2 or later.
2018-03-20 15:00:02 -04:00
# See the COPYING file in the top-level directory.
2013-03-17 17:06:52 -04:00
2018-03-20 12:18:35 -04:00
from . device import Device
2018-03-20 12:27:37 -04:00
from . . xmlbuilder import XMLProperty
2013-03-17 17:06:52 -04:00
2013-04-13 14:34:52 -04:00
2018-03-20 12:18:35 -04:00
class DeviceVideo ( Device ) :
2018-03-21 10:53:34 -04:00
XML_NAME = " video "
2013-03-17 17:06:52 -04:00
2024-03-25 14:49:23 +01:00
_XML_PROP_ORDER = [ " _model " , " vram " , " heads " , " vgamem " ]
2013-09-19 13:27:30 -04:00
vram = XMLProperty ( " ./model/@vram " , is_int = True )
2017-03-05 14:51:25 -05:00
vram64 = XMLProperty ( " ./model/@vram64 " , is_int = True )
2013-09-19 13:27:30 -04:00
ram = XMLProperty ( " ./model/@ram " , is_int = True )
heads = XMLProperty ( " ./model/@heads " , is_int = True )
2014-12-01 15:56:29 +01:00
vgamem = XMLProperty ( " ./model/@vgamem " , is_int = True )
2016-03-04 12:31:52 +01:00
accel3d = XMLProperty ( " ./model/acceleration/@accel3d " , is_yesno = True )
2023-07-11 08:26:51 +08:00
blob = XMLProperty ( " ./model/@blob " , is_onoff = True )
2024-09-18 10:36:26 -04:00
primary = XMLProperty ( " ./model/@primary " , is_yesno = True )
2018-09-01 17:01:46 -04:00
2024-03-25 14:49:23 +01:00
def _set_model ( self , val ) :
self . _model = val
if self . _model != " qxl " :
self . ram = None
self . vgamem = None
self . vram64 = None
def _get_model ( self ) :
return self . _model
_model = XMLProperty ( " ./model/@type " )
model = property ( _get_model , _set_model )
2018-09-01 17:01:46 -04:00
##################
# Default config #
##################
@staticmethod
def default_model ( guest ) :
2019-10-03 15:41:44 -04:00
if not guest . os . is_hvm ( ) :
return None
2018-09-01 17:01:46 -04:00
if guest . os . is_pseries ( ) :
return " vga "
2023-12-13 04:43:51 -05:00
if guest . os . is_loongarch64 ( ) :
return " virtio "
2022-02-03 13:08:06 -05:00
if guest . os . is_arm_machvirt ( ) :
# For all cases here the hv and guest are new enough for virtio
2018-09-01 17:01:46 -04:00
return " virtio "
2022-02-03 13:08:06 -05:00
if guest . os . is_riscv_virt ( ) :
# For all cases here the hv and guest are new enough for virtio
2018-12-13 16:39:43 -05:00
return " virtio "
2022-02-03 13:08:06 -05:00
if guest . os . is_s390x ( ) and guest . conn . is_qemu ( ) :
# s390x doesn't support any of the PCI video devices
return " virtio "
if guest . has_spice ( ) and guest . has_gl ( ) :
# virtio is implied in this case
return " virtio "
2022-02-03 13:11:20 -05:00
if ( guest . lookup_domcaps ( ) . supports_video_virtio ( ) and
guest . osinfo . supports_virtiogpu ( ) ) :
# When the guest supports it, this is the top preference
return " virtio "
2022-02-03 13:08:06 -05:00
if ( guest . os . is_x86 ( ) and
2022-02-03 13:11:20 -05:00
guest . has_spice ( ) and
guest . lookup_domcaps ( ) . supports_video_qxl ( ) ) :
2022-02-03 13:08:06 -05:00
# qxl is only beneficial over regular vga when paired with spice.
# The device still may not be available though
2018-09-01 17:01:46 -04:00
return " qxl "
2019-10-03 10:50:34 +02:00
if ( guest . is_uefi ( ) and
guest . lookup_domcaps ( ) . supports_video_bochs ( ) ) :
return " bochs "
2019-10-03 15:41:44 -04:00
return " vga "
2018-09-01 17:01:46 -04:00
def set_defaults ( self , guest ) :
if not self . model :
self . model = self . default_model ( guest )
if self . model == ' virtio ' and guest . has_gl ( ) :
self . accel3d = True