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 "
2019-03-20 23:24:41 +03:00
TYPE_XENBUS = " xenbus "
2018-09-06 23:05:12 +03:00
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 "
2019-06-07 23:06:52 +03:00
if conn . support . conn_qemu_xhci ( ) :
2017-07-11 02:40:19 +03:00
ctrl . model = " qemu-xhci "
2019-06-07 23:06:52 +03:00
if 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-05-12 15:54:36 +03:00
_XML_PROP_ORDER = [ " type " , " index " , " model " , " master_startport " ,
" driver_queues " , " maxGrantFrames " ]
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 )
2019-03-20 23:24:41 +03:00
maxGrantFrames = XMLProperty ( " ./@maxGrantFrames " , is_int = True )
2018-09-02 05:01:14 +03:00
index = XMLProperty ( " ./@index " , is_int = True )
2013-07-24 16:46:55 +04:00
2019-08-28 20:17:32 +03:00
driver_iothread = XMLProperty ( " ./driver/@iothread " , is_int = True )
driver_queues = XMLProperty ( " ./driver/@queues " , is_int = True )
master_startport = XMLProperty ( " ./master/@startport " , is_int = True )
2020-01-27 16:02:19 +03:00
2020-11-21 00:59:54 +03:00
target_chassisNr = XMLProperty ( " ./target/@chassisNr " , is_int = True )
target_chassis = XMLProperty ( " ./target/@chassis " , is_int = True )
target_port = XMLProperty ( " ./target/@port " , is_int = True )
target_hotplug = XMLProperty ( " ./target/@hotplug " , is_onoff = True )
target_busNr = XMLProperty ( " ./target/@busNr " , is_int = True )
target_index = XMLProperty ( " ./target/@index " , is_int = True )
target_node = XMLProperty ( " ./target/node " , is_int = True )
2020-01-27 16:02:19 +03:00
def _get_attached_disk_devices ( self , guest ) :
ret = [ ]
for disk in guest . devices . disk :
if ( self . type == disk . bus and
self . index == disk . address . controller ) :
ret . append ( disk )
return ret
def _get_attached_virtioserial_devices ( self , guest ) :
ret = [ ]
for dev in guest . devices . channel :
if ( self . type == dev . address . type and
self . index == dev . address . controller ) :
ret . append ( dev )
for dev in guest . devices . console :
# virtio console is implied to be on virtio-serial index=0
if self . index == 0 and dev . target_type == " virtio " :
ret . append ( dev )
return ret
def get_attached_devices ( self , guest ) :
"""
Return all the Device objects from the passed Guest that are attached
to this controller
"""
ret = [ ]
if self . type == " virtio-serial " :
ret = self . _get_attached_virtioserial_devices ( guest )
elif self . type in [ " scsi " , " sata " , " ide " , " fdc " ] :
ret = self . _get_attached_disk_devices ( guest )
return ret