QEMU-Devel Archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Jiaxun Yang" <jiaxun.yang@flygoat.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PULL 22/26] hw/mips/loongson3_virt: Emulate suspend function
Date: Wed,  8 May 2024 19:45:06 +0200	[thread overview]
Message-ID: <20240508174510.60470-23-philmd@linaro.org> (raw)
In-Reply-To: <20240508174510.60470-1-philmd@linaro.org>

From: Jiaxun Yang <jiaxun.yang@flygoat.com>

Suspend function is emulated as what hardware actually do.
Doorbell register fields are updates to include suspend value,
suspend vector is encoded in firmware blob and fw_cfg is updated
to include S3 bits as what x86 did.

Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Message-ID: <20240508-loongson3v-suspend-v1-1-186725524a39@flygoat.com>
[PMD: Use g_memdup2(), constify suspend array]
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/mips/loongson3_bootp.c |  1 +
 hw/mips/loongson3_virt.c  | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/hw/mips/loongson3_bootp.c b/hw/mips/loongson3_bootp.c
index f99af22932..03a10b63c1 100644
--- a/hw/mips/loongson3_bootp.c
+++ b/hw/mips/loongson3_bootp.c
@@ -148,4 +148,5 @@ void init_reset_system(struct efi_reset_system_t *reset)
     reset->Shutdown = cpu_to_le64(0xffffffffbfc000a8);
     reset->ResetCold = cpu_to_le64(0xffffffffbfc00080);
     reset->ResetWarm = cpu_to_le64(0xffffffffbfc00080);
+    reset->DoSuspend = cpu_to_le64(0xffffffffbfc000d0);
 }
diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c
index b10a611a98..440268a074 100644
--- a/hw/mips/loongson3_virt.c
+++ b/hw/mips/loongson3_virt.c
@@ -127,6 +127,9 @@ static void loongson3_pm_write(void *opaque, hwaddr addr,
     case 0x00:
         qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
         return;
+    case 0x01:
+        qemu_system_suspend_request();
+        return;
     case 0xff:
         qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
         return;
@@ -250,6 +253,17 @@ static void init_boot_rom(void)
         0x240D00FF,   /* li      t1, 0xff                                     */
         0xA18D0000,   /* sb      t1, (t0)                                     */
         0x1000FFFF,   /* 1:  b   1b                                           */
+        0x00000000,   /* nop                                                  */
+                      /* Suspend                                              */
+        0x3C0C9000,   /* dli     t0, 0x9000000010080010                       */
+        0x358C0000,
+        0x000C6438,
+        0x358C1008,
+        0x000C6438,
+        0x358C0010,
+        0x240D0001,   /* li      t1, 0x01                                     */
+        0xA18D0000,   /* sb      t1, (t0)                                     */
+        0x03e00008,   /* jr      ra                                           */
         0x00000000    /* nop                                                  */
     };
 
@@ -265,6 +279,7 @@ static void fw_cfg_boot_set(void *opaque, const char *boot_device,
 
 static void fw_conf_init(unsigned long ram_size)
 {
+    static const uint8_t suspend[6] = {128, 0, 0, 129, 128, 128};
     FWCfgState *fw_cfg;
     hwaddr cfg_addr = virt_memmap[VIRT_FW_CFG].base;
 
@@ -274,6 +289,10 @@ static void fw_conf_init(unsigned long ram_size)
     fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
     fw_cfg_add_i32(fw_cfg, FW_CFG_MACHINE_VERSION, 1);
     fw_cfg_add_i64(fw_cfg, FW_CFG_CPU_FREQ, get_cpu_freq_hz());
+
+    fw_cfg_add_file(fw_cfg, "etc/system-states",
+                    g_memdup2(suspend, sizeof(suspend)), sizeof(suspend));
+
     qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
 }
 
@@ -553,6 +572,7 @@ static void mips_loongson3_virt_init(MachineState *machine)
                            machine->ram, 0, virt_memmap[VIRT_LOWMEM].size);
     memory_region_init_io(iomem, NULL, &loongson3_pm_ops,
                            NULL, "loongson3_pm", virt_memmap[VIRT_PM].size);
+    qemu_register_wakeup_support();
 
     memory_region_add_subregion(address_space_mem,
                       virt_memmap[VIRT_LOWMEM].base, ram);
-- 
2.41.0



  parent reply	other threads:[~2024-05-08 17:47 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-08 17:44 [PULL 00/26] Misc HW patches for 2024-05-08 Philippe Mathieu-Daudé
2024-05-08 17:44 ` [PULL 01/26] block/qcow2-bitmap: Replace g_memdup() by g_memdup2() Philippe Mathieu-Daudé
2024-05-08 17:44 ` [PULL 02/26] target/ppc: " Philippe Mathieu-Daudé
2024-05-08 17:44 ` [PULL 03/26] hw/hppa/machine: " Philippe Mathieu-Daudé
2024-05-08 17:44 ` [PULL 04/26] hw/ppc/spapr_pci: " Philippe Mathieu-Daudé
2024-05-08 17:44 ` [PULL 05/26] hw/remote/vfio-user: Fix config space access byte order Philippe Mathieu-Daudé
2024-05-10  8:18   ` Michael Tokarev
2024-05-10  9:54     ` Philippe Mathieu-Daudé
2024-05-08 17:44 ` [PULL 06/26] system/physmem: Replace qemu_mutex_lock() calls with QEMU_LOCK_GUARD Philippe Mathieu-Daudé
2024-05-08 17:44 ` [PULL 07/26] system/physmem: Propagate AddressSpace to MapClient helpers Philippe Mathieu-Daudé
2024-05-08 17:44 ` [PULL 08/26] system/physmem: Per-AddressSpace bounce buffering Philippe Mathieu-Daudé
2024-05-08 17:44 ` [PULL 09/26] hw/i386/pc: Allow to compile without CONFIG_FDC_ISA Philippe Mathieu-Daudé
2024-05-08 17:44 ` [PULL 10/26] hw/i386/Kconfig: Allow to compile Q35 without FDC_ISA Philippe Mathieu-Daudé
2024-05-08 17:44 ` [PULL 11/26] hw/i386: Add the possibility to use i440fx and isapc without FDC Philippe Mathieu-Daudé
2024-05-08 17:44 ` [PULL 12/26] hw/i386/x86: Eliminate two if statements in x86_bios_rom_init() Philippe Mathieu-Daudé
2024-05-08 17:44 ` [PULL 13/26] hw/i386: Have x86_bios_rom_init() take X86MachineState rather than MachineState Philippe Mathieu-Daudé
2024-05-08 17:44 ` [PULL 14/26] hw/i386/x86: Don't leak "isa-bios" memory regions Philippe Mathieu-Daudé
2024-05-08 17:44 ` [PULL 15/26] hw/usb/dev-network: Remove unused struct 'rndis_config_parameter' Philippe Mathieu-Daudé
2024-05-08 17:45 ` [PULL 16/26] hw/gpio: Handle clock migration in STM32L4x5 gpios Philippe Mathieu-Daudé
2024-05-08 17:45 ` [PULL 17/26] hw/ppc: Deprecate 'ref405ep' machine and 405 CPUs Philippe Mathieu-Daudé
2024-05-08 17:45 ` [PULL 18/26] hw/loongarch: move memory map to boot.c Philippe Mathieu-Daudé
2024-05-08 17:45 ` [PULL 19/26] hw/loongarch/virt: Fix memory leak Philippe Mathieu-Daudé
2024-05-08 17:45 ` [PULL 20/26] hw/loongarch: Rename LOONGARCH_MACHINE with LOONGARCH_VIRT_MACHINE Philippe Mathieu-Daudé
2024-05-08 17:45 ` [PULL 21/26] hw/loongarch: Rename LoongArchMachineState with LoongArchVirtMachineState Philippe Mathieu-Daudé
2024-05-08 17:45 ` Philippe Mathieu-Daudé [this message]
2024-05-08 17:45 ` [PULL 23/26] hw/intc/loongarch_ipi: Remove pointless MAX_CPU check Philippe Mathieu-Daudé
2024-05-08 17:45 ` [PULL 24/26] hw/intc/loongarch_ipi: Rename as loongson_ipi Philippe Mathieu-Daudé
2024-05-08 17:45 ` [PULL 25/26] hw/intc/loongson_ipi: Implement IOCSR address space for MIPS Philippe Mathieu-Daudé
2024-05-08 17:45 ` [PULL 26/26] misc: Use QEMU header path relative to include/ directory Philippe Mathieu-Daudé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240508174510.60470-23-philmd@linaro.org \
    --to=philmd@linaro.org \
    --cc=jiaxun.yang@flygoat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).