From patchwork Wed May 8 17:45:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 795494 Delivered-To: patch@linaro.org Received: by 2002:a5d:525c:0:b0:34e:ceec:bfcd with SMTP id k28csp903407wrc; Wed, 8 May 2024 10:47:32 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVvTtjLmz/qlmhGZ24GyAlHp1I4DBWMgrjFQHyFe2GJd8aN6vWr5CD/hckXJcsxfBdLPYsEQ+5Wi8qfhR8GzhoX X-Google-Smtp-Source: AGHT+IHDiVsbiDVINzhUnaQwrBgKPG1PP6SJaARrWL4Ha1Duj/ROJlAxvoN2qcDGvv8i7f0Yyf31 X-Received: by 2002:a05:620a:1a28:b0:790:f2f5:cbc6 with SMTP id af79cd13be357-792b26f4611mr386229985a.36.1715190452016; Wed, 08 May 2024 10:47:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715190452; cv=none; d=google.com; s=arc-20160816; b=YqkE9vjlxLlVh3FqGpi59w4gRO9x3ArbNFQd5mOqkTDNsS0LiKgKPA19Ev/lO4PDzz 5gnJIe485AyKLSKRVR44bjJCdxraGqQSA2DDPrPEervZa9JsnHX3lUyP4a0jk63bh0ra oKKtdMPi9BfNegYjDgmXxSDLf82BG7uQkp0PHWMCQgL0zibhjJTPspW+NcZLDpQh4P5Y nnkbKHYJN8+iVSBOoxsU2Pl6c0dWrm1KRgDzm9SdfpfHFkFyZqCyy5JPXEW3SvAtgNLO V03W+TTL4mQ7Ces6dhJCJkm1ZeH1SMn0koQHkCPgocvixKgGBa1NnOxm37bwilTEGdVZ zV/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=RtqJ/HpVTKlat1filTS1A2oaNsIBTtDSWzDDsWKSNIM=; fh=jiKM5Jsg5IywfmBhne3oNkoWpsaS5OqwqtJOUwmjFpk=; b=U0BzTmZ4LqZqhNfWTKSgMHADSvw0TtSvmvt+f+onaBeknOUXlT/2crF5McQZDFfj4Z bejCWAOaYDphyb1IU3fxCvUSnv47vxlroPVZUxrqwhENMiYzo+30V4L+EbprT7p+991Z TeRFZc+YZDNH5t5iMibQMAbP4ZXthqWwaypJXxCuQEQ81bJ5nJKjrBdT8MXnh5pGkoD8 X1Q5OzDCS1xku9QMvcMz+EduF0KcjXcsbYrkU+bDWcjvqXHhhTpXoJJ+RPcSljUPdJ8F P3b+dTSFikA+R3PhX2XlMpTEXia1N+XN1/Nca4eTYrnUurPE/L2C73UIz8f/u3+DgCB2 teTg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cqA4pbQu; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id wj22-20020a05620a575600b00792a5749868si4884131qkn.128.2024.05.08.10.47.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 08 May 2024 10:47:31 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cqA4pbQu; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4lO4-00040J-AQ; Wed, 08 May 2024 13:47:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4lNt-0003aV-FV for qemu-devel@nongnu.org; Wed, 08 May 2024 13:47:19 -0400 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s4lNq-0000ho-L5 for qemu-devel@nongnu.org; Wed, 08 May 2024 13:47:16 -0400 Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-a59cdd185b9so207222466b.1 for ; Wed, 08 May 2024 10:47:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715190432; x=1715795232; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RtqJ/HpVTKlat1filTS1A2oaNsIBTtDSWzDDsWKSNIM=; b=cqA4pbQuySvqH9/N0uaqeHCLIPf1X9tjNJrsxqIkAMmltNG2JXC32oh0f3HSxYUUv7 GCAfTmQ0Dmv6lOW0sYtMl1an2ozJqI7Pxe8AUWXSl5yvtJxYL3keQX5WYoFteZYALZY5 0+Ldhu+IHXxQ8X6o/4NcWumgUbJghcor3sUg+o2hJU4OPEFDdc1elZZkAsYwlZIdsWnu FrW9qjz3irkiNCaHx2EXM7hsseJu1VS1sn1L5r+TyAcYblsJ7QMOt1A1uGdzUOC3UoFK oATCIolrArlJ1FqAz4LAycrxquAFZgahTkbM/4xSbwf4j06gog5H4I8Rs5MBl5JPowhN r7gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715190432; x=1715795232; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RtqJ/HpVTKlat1filTS1A2oaNsIBTtDSWzDDsWKSNIM=; b=L9qMUq8Yv6jmawywzIvKCCoqTvFC/+SdxUweq2Ps5KkjoVXXEsBJ3Mj7rEqsat86m2 sGlCkHwtHnh6m06UkQHWlCYOSgtHjAg/nMJpRx44ZwaUC7HVPIbB3MC/AfLkbfNqt3xX gayb/NpnSrjhETNFAFPrMU7PDevdKTLZGKWTrqmgH3/SRKHoypKxSSDPWWybcOAZXM7N j/AyC54V2O+3Dky7/N+zV5q6a5iXBgEI4FTcg2KZQEl1/BtaHiq46SUTB64uu1GbMAYE miVodEA1IbjHW9vsqXdg0yUA+XjsTQ0NDejEJg+HXJ2uRlP2809WLW5KY+jAvHOZRRyp dUTQ== X-Gm-Message-State: AOJu0YwvTlb/l+6/p5dHzMwA4pC4o42Q4sMZDiMUHJaNfXomkwjEzH9U wDZ2tk7zhWSq7BJcN8KvZbKIJA8u5OX/vt76ngtKiuLs94Ot8Xg3Cl3sL28Hej0620+b/jFLcRE q X-Received: by 2002:a17:906:2bd3:b0:a59:a1b1:2978 with SMTP id a640c23a62f3a-a5a116ece99mr27068166b.20.1715190432235; Wed, 08 May 2024 10:47:12 -0700 (PDT) Received: from m1x-phil.lan (sar95-h02-176-184-10-250.dsl.sta.abo.bbox.fr. [176.184.10.250]) by smtp.gmail.com with ESMTPSA id g23-20020a1709067c5700b00a5a0b34110dsm560178ejp.1.2024.05.08.10.47.11 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 08 May 2024 10:47:11 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Jiaxun Yang , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [PULL 22/26] hw/mips/loongson3_virt: Emulate suspend function Date: Wed, 8 May 2024 19:45:06 +0200 Message-ID: <20240508174510.60470-23-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240508174510.60470-1-philmd@linaro.org> References: <20240508174510.60470-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62f; envelope-from=philmd@linaro.org; helo=mail-ej1-x62f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Jiaxun Yang 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 Message-ID: <20240508-loongson3v-suspend-v1-1-186725524a39@flygoat.com> [PMD: Use g_memdup2(), constify suspend array] Signed-off-by: Philippe Mathieu-Daudé --- 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);