2013-03-18 05:06:52 +08:00
|
|
|
#
|
2014-02-12 17:39:32 +08:00
|
|
|
# Copyright 2010, 2013, 2014 Red Hat, Inc.
|
2013-03-18 05:06:52 +08:00
|
|
|
# Cole Robinson <crobinso@redhat.com>
|
|
|
|
#
|
2018-04-04 21:35:41 +08:00
|
|
|
# This work is licensed under the GNU GPLv2 or later.
|
2018-03-21 03:00:02 +08:00
|
|
|
# See the COPYING file in the top-level directory.
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2018-03-21 00:18:35 +08:00
|
|
|
from .device import Device
|
2018-03-21 00:27:37 +08:00
|
|
|
from ..xmlbuilder import XMLProperty
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2013-04-14 02:34:52 +08:00
|
|
|
|
2018-03-21 00:18:35 +08:00
|
|
|
class DeviceController(Device):
|
2018-03-21 22:53:34 +08:00
|
|
|
XML_NAME = "controller"
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2013-07-16 09:52:18 +08: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-07 04:05:12 +08:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_recommended_types(_guest):
|
|
|
|
return [DeviceController.TYPE_SCSI,
|
|
|
|
DeviceController.TYPE_USB,
|
|
|
|
DeviceController.TYPE_VIRTIOSERIAL,
|
|
|
|
DeviceController.TYPE_CCID]
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def pretty_type(ctype):
|
|
|
|
pretty_mappings = {
|
2018-03-21 00:18:35 +08: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-14 02:34:52 +08:00
|
|
|
}
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
if ctype not in pretty_mappings:
|
|
|
|
return ctype
|
|
|
|
return pretty_mappings[ctype]
|
|
|
|
|
2013-07-18 05:58:24 +08:00
|
|
|
@staticmethod
|
|
|
|
def get_usb2_controllers(conn):
|
|
|
|
ret = []
|
2018-03-21 00:18:35 +08:00
|
|
|
ctrl = DeviceController(conn)
|
2013-07-18 05:58:24 +08:00
|
|
|
ctrl.type = "usb"
|
|
|
|
ctrl.model = "ich9-ehci1"
|
|
|
|
ret.append(ctrl)
|
|
|
|
|
2018-03-21 00:18:35 +08:00
|
|
|
ctrl = DeviceController(conn)
|
2013-07-18 05:58:24 +08:00
|
|
|
ctrl.type = "usb"
|
|
|
|
ctrl.model = "ich9-uhci1"
|
|
|
|
ctrl.master_startport = 0
|
|
|
|
ret.append(ctrl)
|
|
|
|
|
2018-03-21 00:18:35 +08:00
|
|
|
ctrl = DeviceController(conn)
|
2013-07-18 05:58:24 +08:00
|
|
|
ctrl.type = "usb"
|
|
|
|
ctrl.model = "ich9-uhci2"
|
|
|
|
ctrl.master_startport = 2
|
|
|
|
ret.append(ctrl)
|
|
|
|
|
2018-03-21 00:18:35 +08:00
|
|
|
ctrl = DeviceController(conn)
|
2013-07-18 05:58:24 +08:00
|
|
|
ctrl.type = "usb"
|
|
|
|
ctrl.model = "ich9-uhci3"
|
|
|
|
ctrl.master_startport = 4
|
|
|
|
ret.append(ctrl)
|
|
|
|
return ret
|
|
|
|
|
2017-06-29 03:35:07 +08:00
|
|
|
@staticmethod
|
2017-07-11 07:40:19 +08:00
|
|
|
def get_usb3_controller(conn, guest):
|
2018-03-21 00:18:35 +08:00
|
|
|
ctrl = DeviceController(conn)
|
2017-06-29 03:35:07 +08:00
|
|
|
ctrl.type = "usb"
|
|
|
|
ctrl.model = "nec-xhci"
|
2017-07-11 07:40:19 +08: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-29 03:35:07 +08:00
|
|
|
if conn.check_support(conn.SUPPORT_CONN_USB3_PORTS):
|
|
|
|
ctrl.ports = 8
|
|
|
|
return ctrl
|
|
|
|
|
2013-07-18 05:58:24 +08:00
|
|
|
|
|
|
|
_XML_PROP_ORDER = ["type", "index", "model", "master_startport"]
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2013-09-20 01:27:30 +08: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-18 05:06:52 +08:00
|
|
|
|
2018-09-02 10:01:14 +08:00
|
|
|
index = XMLProperty("./@index", is_int=True)
|
2013-07-24 20:46:55 +08:00
|
|
|
|
2015-04-05 08:01:03 +08: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-28 03:28:12 +08:00
|
|
|
if self.type == "pci" and self.model == "pcie-root":
|
|
|
|
ret = "PCIe"
|
2015-04-05 08:01:03 +08:00
|
|
|
return ret
|
2018-09-02 10:01:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
##################
|
|
|
|
# Default config #
|
|
|
|
##################
|
|
|
|
|
|
|
|
def set_defaults(self, _guest):
|
|
|
|
if self.index is None:
|
|
|
|
self.index = 0
|