From 2e466df762326045c7d40f179bff6e54d2e0d015 Mon Sep 17 00:00:00 2001
From: Xianglai Li <lixianglai@loongson.cn>
Date: Wed, 28 Feb 2024 02:07:26 -0500
Subject: [PATCH 2/4] Add loongarch support in guest class

Add adaptations for loongarch with the following features in guest class:
virtio Support
input deveice support
default graphic Support
usb redir support

Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
---
 virtinst/guest.py | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/virtinst/guest.py b/virtinst/guest.py
index e663602..86f6e14 100644
--- a/virtinst/guest.py
+++ b/virtinst/guest.py
@@ -352,7 +352,8 @@ class Guest(XMLBuilder):
         if (self.os.is_arm_machvirt() or
             self.os.is_riscv_virt() or
             self.os.is_s390x() or
-            self.os.is_pseries()):
+            self.os.is_pseries() or
+            self.os.is_loongarch64()):
             return True
 
         if not os_support:
@@ -541,7 +542,7 @@ class Guest(XMLBuilder):
             # and doesn't break QEMU internal snapshots
             prefer_efi = self.osinfo.requires_firmware_efi(self.os.arch)
         else:
-            prefer_efi = self.os.is_arm_machvirt() or self.conn.is_bhyve()
+            prefer_efi = self.os.is_arm_machvirt() or self.conn.is_bhyve() or self.os.is_loongarch64()
 
         log.debug("Prefer EFI => %s", prefer_efi)
         return prefer_efi
@@ -902,7 +903,8 @@ class Guest(XMLBuilder):
             usb_tablet = True
         if (self.os.is_arm_machvirt() or
             self.os.is_riscv_virt() or
-            self.os.is_pseries()):
+            self.os.is_pseries() or
+            self.os.is_loongarch64()):
             usb_tablet = True
             usb_keyboard = True
 
@@ -984,7 +986,11 @@ class Guest(XMLBuilder):
             # For pseries, we always assume OS supports usb3
             if qemu_usb3:
                 usb3 = True
-
+        elif self.os.is_loongarch64():
+            # For machvirt, we always assume OS supports usb3
+            if (qemu_usb3 and
+                self.conn.support.conn_machvirt_pci_default()):
+                usb3 = True
 
         if usb2:
             for dev in DeviceController.get_usb2_controllers(self.conn):
@@ -1016,7 +1022,7 @@ class Guest(XMLBuilder):
         if self.os.is_container() and not self.conn.is_vz():
             return
         if (not self.os.is_x86() and
-            not self.os.is_pseries()):
+            not self.os.is_pseries() and not self.os.is_loongarch64()):
             return
         self.add_device(DeviceGraphics(self.conn))
 
@@ -1155,6 +1161,8 @@ class Guest(XMLBuilder):
         self.add_device(dev)
 
     def _add_spice_usbredir(self):
+        if (self.os.is_loongarch64()):
+            return
         if self.skip_default_usbredir:
             return
         if self.devices.redirdev:
-- 
2.27.0

