2013-03-17 17:06:52 -04:00
#
2014-02-12 10:39:32 +01:00
# Copyright 2010, 2013, 2014 Red Hat, Inc.
2013-03-17 17:06:52 -04:00
# Cole Robinson <crobinso@redhat.com>
#
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 DeviceController ( Device ) :
2018-03-21 10:53:34 -04:00
XML_NAME = " controller "
2013-03-17 17:06:52 -04:00
2013-07-15 21: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 "
TYPES = [ TYPE_IDE , TYPE_FDC ,
TYPE_SCSI , TYPE_SATA ,
TYPE_VIRTIOSERIAL , TYPE_USB ,
TYPE_PCI , TYPE_CCID ]
2013-03-17 17:06:52 -04:00
@staticmethod
def pretty_type ( ctype ) :
pretty_mappings = {
2018-03-20 12:18:35 -04: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 14:34:52 -04:00
}
2013-03-17 17:06:52 -04:00
if ctype not in pretty_mappings :
return ctype
return pretty_mappings [ ctype ]
2013-07-17 17:58:24 -04:00
@staticmethod
def get_usb2_controllers ( conn ) :
ret = [ ]
2018-03-20 12:18:35 -04:00
ctrl = DeviceController ( conn )
2013-07-17 17:58:24 -04:00
ctrl . type = " usb "
ctrl . model = " ich9-ehci1 "
ret . append ( ctrl )
2018-03-20 12:18:35 -04:00
ctrl = DeviceController ( conn )
2013-07-17 17:58:24 -04:00
ctrl . type = " usb "
ctrl . model = " ich9-uhci1 "
ctrl . master_startport = 0
ret . append ( ctrl )
2018-03-20 12:18:35 -04:00
ctrl = DeviceController ( conn )
2013-07-17 17:58:24 -04:00
ctrl . type = " usb "
ctrl . model = " ich9-uhci2 "
ctrl . master_startport = 2
ret . append ( ctrl )
2018-03-20 12:18:35 -04:00
ctrl = DeviceController ( conn )
2013-07-17 17:58:24 -04:00
ctrl . type = " usb "
ctrl . model = " ich9-uhci3 "
ctrl . master_startport = 4
ret . append ( ctrl )
return ret
2017-06-28 15:35:07 -04:00
@staticmethod
2017-07-10 19:40:19 -04:00
def get_usb3_controller ( conn , guest ) :
2018-03-20 12:18:35 -04:00
ctrl = DeviceController ( conn )
2017-06-28 15:35:07 -04:00
ctrl . type = " usb "
ctrl . model = " nec-xhci "
2017-07-10 19:40:19 -04:00
if ( ( guest . os . is_arm_machvirt ( ) or guest . os . is_pseries ( ) ) and
conn . check_support ( conn . SUPPORT_CONN_QEMU_XHCI ) ) :
ctrl . model = " qemu-xhci "
2017-06-28 15:35:07 -04:00
if conn . check_support ( conn . SUPPORT_CONN_USB3_PORTS ) :
ctrl . ports = 8
return ctrl
2013-07-17 17:58:24 -04:00
_XML_PROP_ORDER = [ " type " , " index " , " model " , " master_startport " ]
2013-03-17 17:06:52 -04:00
2013-09-19 13: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 )
2013-03-17 17:06:52 -04:00
2013-09-19 13:27:30 -04:00
index = XMLProperty ( " ./@index " , is_int = True , default_cb = lambda s : 0 )
2013-07-24 08:46:55 -04:00
2015-04-04 20:01:03 -04: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 15:28:12 -04:00
if self . type == " pci " and self . model == " pcie-root " :
ret = " PCIe "
2015-04-04 20:01:03 -04:00
return ret