2013-03-18 01:06:52 +04:00
#
2014-02-12 13:39:32 +04:00
# Copyright 2010, 2013, 2014 Red Hat, Inc.
2013-03-18 01:06:52 +04:00
#
2018-04-04 16:35:41 +03:00
# This work is licensed under the GNU GPLv2 or later.
2018-03-20 22:00:02 +03:00
# See the COPYING file in the top-level directory.
2013-03-18 01:06:52 +04:00
2018-03-20 19:18:35 +03:00
from . device import Device
2018-03-20 19:27:37 +03:00
from . . xmlbuilder import XMLProperty
2013-03-18 01:06:52 +04:00
2013-04-13 22:34:52 +04:00
2018-03-20 19:18:35 +03:00
class DeviceController ( Device ) :
2018-03-21 17:53:34 +03:00
XML_NAME = " controller "
2013-03-18 01:06:52 +04:00
2013-07-16 05:52:18 +04:00
TYPE_IDE = " ide "
TYPE_FDC = " fdc "
TYPE_SCSI = " scsi "
TYPE_SATA = " sata "
TYPE_VIRTIOSERIAL = " virtio-serial "
TYPE_USB = " usb "
TYPE_PCI = " pci "
TYPE_CCID = " ccid "
2018-09-06 23:05:12 +03:00
@staticmethod
def get_recommended_types ( _guest ) :
return [ DeviceController . TYPE_SCSI ,
DeviceController . TYPE_USB ,
DeviceController . TYPE_VIRTIOSERIAL ,
DeviceController . TYPE_CCID ]
2013-03-18 01:06:52 +04:00
@staticmethod
def pretty_type ( ctype ) :
pretty_mappings = {
2018-03-20 19:18:35 +03:00
DeviceController . TYPE_IDE : " IDE " ,
DeviceController . TYPE_FDC : _ ( " Floppy " ) ,
DeviceController . TYPE_SCSI : " SCSI " ,
DeviceController . TYPE_SATA : " SATA " ,
DeviceController . TYPE_VIRTIOSERIAL : " VirtIO Serial " ,
DeviceController . TYPE_USB : " USB " ,
DeviceController . TYPE_PCI : " PCI " ,
DeviceController . TYPE_CCID : " CCID " ,
2013-04-13 22:34:52 +04:00
}
2013-03-18 01:06:52 +04:00
if ctype not in pretty_mappings :
return ctype
return pretty_mappings [ ctype ]
2013-07-18 01:58:24 +04:00
@staticmethod
def get_usb2_controllers ( conn ) :
ret = [ ]
2018-03-20 19:18:35 +03:00
ctrl = DeviceController ( conn )
2013-07-18 01:58:24 +04:00
ctrl . type = " usb "
ctrl . model = " ich9-ehci1 "
ret . append ( ctrl )
2018-03-20 19:18:35 +03:00
ctrl = DeviceController ( conn )
2013-07-18 01:58:24 +04:00
ctrl . type = " usb "
ctrl . model = " ich9-uhci1 "
ctrl . master_startport = 0
ret . append ( ctrl )
2018-03-20 19:18:35 +03:00
ctrl = DeviceController ( conn )
2013-07-18 01:58:24 +04:00
ctrl . type = " usb "
ctrl . model = " ich9-uhci2 "
ctrl . master_startport = 2
ret . append ( ctrl )
2018-03-20 19:18:35 +03:00
ctrl = DeviceController ( conn )
2013-07-18 01:58:24 +04:00
ctrl . type = " usb "
ctrl . model = " ich9-uhci3 "
ctrl . master_startport = 4
ret . append ( ctrl )
return ret
2017-06-28 22:35:07 +03:00
@staticmethod
2017-07-11 02:40:19 +03:00
def get_usb3_controller ( conn , guest ) :
2018-10-04 01:53:16 +03:00
ignore = guest
2018-03-20 19:18:35 +03:00
ctrl = DeviceController ( conn )
2017-06-28 22:35:07 +03:00
ctrl . type = " usb "
ctrl . model = " nec-xhci "
2018-10-04 01:53:16 +03:00
if conn . check_support ( conn . SUPPORT_CONN_QEMU_XHCI ) :
2017-07-11 02:40:19 +03:00
ctrl . model = " qemu-xhci "
2017-06-28 22:35:07 +03:00
if conn . check_support ( conn . SUPPORT_CONN_USB3_PORTS ) :
2018-10-04 18:55:57 +03:00
# 15 is the max ports qemu supports, might as well
# Add as many as possible
ctrl . ports = 15
2017-06-28 22:35:07 +03:00
return ctrl
2013-07-18 01:58:24 +04:00
2019-03-12 11:56:57 +03:00
_XML_PROP_ORDER = [ " type " , " index " , " model " , " master_startport " , " driver_queues " ]
2013-03-18 01:06:52 +04:00
2013-09-19 21:27:30 +04:00
type = XMLProperty ( " ./@type " )
model = XMLProperty ( " ./@model " )
vectors = XMLProperty ( " ./@vectors " , is_int = True )
ports = XMLProperty ( " ./@ports " , is_int = True )
master_startport = XMLProperty ( " ./master/@startport " , is_int = True )
2019-03-12 11:56:57 +03:00
driver_queues = XMLProperty ( " ./driver/@queues " , is_int = True )
2013-03-18 01:06:52 +04:00
2018-09-02 05:01:14 +03:00
index = XMLProperty ( " ./@index " , is_int = True )
2013-07-24 16:46:55 +04:00
2015-04-05 03:01:03 +03:00
def pretty_desc ( self ) :
ret = self . pretty_type ( self . type )
if self . type == " scsi " :
if self . model == " virtio-scsi " :
ret = " Virtio " + ret
elif self . address . type == " spapr-vio " :
ret = " sPAPR " + ret
2017-06-27 22:28:12 +03:00
if self . type == " pci " and self . model == " pcie-root " :
ret = " PCIe "
2015-04-05 03:01:03 +03:00
return ret
2018-09-02 05:01:14 +03:00
##################
# Default config #
##################
def set_defaults ( self , _guest ) :
if self . index is None :
self . index = 0