From nobody Wed May 8 19:49:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1493413877457413.469631203263; Fri, 28 Apr 2017 14:11:17 -0700 (PDT) Received: from localhost ([::1]:38909 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d4DAa-0002kw-4J for importer@patchew.org; Fri, 28 Apr 2017 17:11:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36525) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d4D9q-0002Kq-Jj for qemu-devel@nongnu.org; Fri, 28 Apr 2017 17:10:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d4D9n-0007d6-E1 for qemu-devel@nongnu.org; Fri, 28 Apr 2017 17:10:30 -0400 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]:34846) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d4D9n-0007cm-5b for qemu-devel@nongnu.org; Fri, 28 Apr 2017 17:10:27 -0400 Received: by mail-pf0-x241.google.com with SMTP id o68so3871pfj.2 for ; Fri, 28 Apr 2017 14:10:27 -0700 (PDT) Received: from localhost (z17.58-98-173.ppp.wakwak.ne.jp. [58.98.173.17]) by smtp.gmail.com with ESMTPSA id z22sm13283707pfg.117.2017.04.28.14.10.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 28 Apr 2017 14:10:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=XFOM5HNSizLGHX7yMoZY0xsUkNWXnvxHIA/Ev04MYi0=; b=Kc6OHTrbxpQvQv4XyuYo9tH0MQO7Am0/hicgNxrCq5ZHac8kzJyBdY64G0RCuPDo1/ bVQ7O2VESVNf4JrjPDSOGvoi/h6rFnlExxkLGfSsU3jdlp/DykT5bLvzyqDNujod72Sw /8nQp2Oe1FP9tnt5X8iYp+fzIIxoZL6+emLHRoethQ8hu6pBwhs4b5xWdsbjv9/xlJX5 2UgXdWTK0ZQkSsZvjcf73m2/vScbvVrp7uqfKPPr6EhpWb1okXfPTqiaRg4E40Y9E2fF ZUwMSg4XB/t4mBX5J6r9yIE8KIAnm+IhfKiYUVD3VVJSsE8/1k95NReTIwgr0BjHTgKu z2NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=XFOM5HNSizLGHX7yMoZY0xsUkNWXnvxHIA/Ev04MYi0=; b=WkQTdm0y6/zcL1R9ohCtURT7Nj4H9hK31JE9gvvlu6TptUsdKOhgM8TImL9DQkv7sr 4YeIe+10Gfwg6eGaQ3kL9L2X8Qouokn+UjL3whahxz+bvlSYjLb0y3QHWuKsxZAquW1H vH/bCr7LQTgwtXRmxqUOJonjK5a6ZIPkiAAzrxZSwk1DA4OESuUAEsv9HGbbasQb2fU/ smXIXzTbdshYbECcGw0INql1Dedk5l1x7r0ux8PkHQw5Y302JwhqlqOCkY7ChQcyMesa YIMB95IqEP7c91mFMnzV6LdfK8o3Ysub+lMGOjJx7vEUUk1yWwRSkPJfENzBwxid4MxP Iivg== X-Gm-Message-State: AN3rC/7AwXPK5rTTk9zzu7Qy/3v5hBXo6/AnJeQVhKcdRMqkypcvvZyi vlm/2x0uKRPbjQ== X-Received: by 10.84.224.70 with SMTP id a6mr17819905plt.25.1493413826226; Fri, 28 Apr 2017 14:10:26 -0700 (PDT) From: Stafford Horne To: QEMU Development Date: Sat, 29 Apr 2017 06:10:18 +0900 Message-Id: <20170428211018.2927-1-shorne@gmail.com> X-Mailer: git-send-email 2.9.3 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::241 Subject: [Qemu-devel] [PATCH] target/openrisc: Support non-busy idle state using PMR SPR X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stafford Horne , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The OpenRISC architecture has the Power Management Register (PMR) special purpose register to manage cpu power states. The interesting modes are: * Doze Mode (DME) - Stop cpu except timer & pic - wake on interrupt * Sleep Mode (SME) - Stop cpu and all units - wake on interrupt * Suspend Model (SUME) - Stop cpu and all units - wake on reset The linux kernel will set DME when idle. This patch implements the PMR SPR and halts the qemu cpu when there is a change to DME or SME. This means that openrisc qemu in no longer peggs a host cpu at 100%. In order for this to work we need to kick the CPU when timers are expired. Update the cpu timer to kick the cpu upon each timer event. Signed-off-by: Stafford Horne Reviewed-by: Richard Henderson --- Changes since last RFC - none hw/openrisc/cputimer.c | 1 + target/openrisc/cpu.c | 3 ++- target/openrisc/cpu.h | 10 ++++++++++ target/openrisc/interrupt.c | 2 ++ target/openrisc/machine.c | 1 + target/openrisc/sys_helper.c | 13 +++++++++++++ 6 files changed, 29 insertions(+), 1 deletion(-) diff --git a/hw/openrisc/cputimer.c b/hw/openrisc/cputimer.c index a98c799..febc469 100644 --- a/hw/openrisc/cputimer.c +++ b/hw/openrisc/cputimer.c @@ -61,6 +61,7 @@ void cpu_openrisc_timer_update(OpenRISCCPU *cpu) } next =3D now + (uint64_t)wait * TIMER_PERIOD; timer_mod(cpu->env.timer, next); + qemu_cpu_kick(CPU(cpu)); } =20 void cpu_openrisc_count_start(OpenRISCCPU *cpu) diff --git a/target/openrisc/cpu.c b/target/openrisc/cpu.c index c9b3f22..1d6330c 100644 --- a/target/openrisc/cpu.c +++ b/target/openrisc/cpu.c @@ -51,7 +51,8 @@ static void openrisc_cpu_reset(CPUState *s) cpu->env.lock_addr =3D -1; s->exception_index =3D -1; =20 - cpu->env.upr =3D UPR_UP | UPR_DMP | UPR_IMP | UPR_PICP | UPR_TTP; + cpu->env.upr =3D UPR_UP | UPR_DMP | UPR_IMP | UPR_PICP | UPR_TTP | + UPR_PMP; cpu->env.dmmucfgr =3D (DMMUCFGR_NTW & (0 << 2)) | (DMMUCFGR_NTS & (6 <= < 2)); cpu->env.immucfgr =3D (IMMUCFGR_NTW & (0 << 2)) | (IMMUCFGR_NTS & (6 <= < 2)); =20 diff --git a/target/openrisc/cpu.h b/target/openrisc/cpu.h index 938ccc3..2721432 100644 --- a/target/openrisc/cpu.h +++ b/target/openrisc/cpu.h @@ -140,6 +140,15 @@ enum { IMMUCFGR_HTR =3D (1 << 11), }; =20 +/* Power management register */ +enum { + PMR_SDF =3D (15 << 0), + PMR_DME =3D (1 << 4), + PMR_SME =3D (1 << 5), + PMR_DCGE =3D (1 << 6), + PMR_SUME =3D (1 << 7), +}; + /* Float point control status register */ enum { FPCSR_FPEE =3D 1, @@ -284,6 +293,7 @@ typedef struct CPUOpenRISCState { uint32_t immucfgr; /* IMMU configure register */ uint32_t esr; /* Exception supervisor register */ uint32_t evbar; /* Exception vector base address register */ + uint32_t pmr; /* Power Management Register */ uint32_t fpcsr; /* Float register */ float_status fp_status; =20 diff --git a/target/openrisc/interrupt.c b/target/openrisc/interrupt.c index 2c91fab..3959671 100644 --- a/target/openrisc/interrupt.c +++ b/target/openrisc/interrupt.c @@ -60,6 +60,8 @@ void openrisc_cpu_do_interrupt(CPUState *cs) env->sr |=3D SR_SM; env->sr &=3D ~SR_IEE; env->sr &=3D ~SR_TEE; + env->pmr &=3D ~PMR_DME; + env->pmr &=3D ~PMR_SME; env->tlb->cpu_openrisc_map_address_data =3D &cpu_openrisc_get_phys_nom= mu; env->tlb->cpu_openrisc_map_address_code =3D &cpu_openrisc_get_phys_nom= mu; env->lock_addr =3D -1; diff --git a/target/openrisc/machine.c b/target/openrisc/machine.c index a82be62..a20cce7 100644 --- a/target/openrisc/machine.c +++ b/target/openrisc/machine.c @@ -138,6 +138,7 @@ static const VMStateDescription vmstate_env =3D { VMSTATE_UINT32(dmmucfgr, CPUOpenRISCState), VMSTATE_UINT32(immucfgr, CPUOpenRISCState), VMSTATE_UINT32(evbar, CPUOpenRISCState), + VMSTATE_UINT32(pmr, CPUOpenRISCState), VMSTATE_UINT32(esr, CPUOpenRISCState), VMSTATE_UINT32(fpcsr, CPUOpenRISCState), VMSTATE_UINT64(mac, CPUOpenRISCState), diff --git a/target/openrisc/sys_helper.c b/target/openrisc/sys_helper.c index fa3d6a4..44acf0d 100644 --- a/target/openrisc/sys_helper.c +++ b/target/openrisc/sys_helper.c @@ -22,6 +22,7 @@ #include "cpu.h" #include "exec/exec-all.h" #include "exec/helper-proto.h" +#include "exception.h" =20 #define TO_SPR(group, number) (((group) << 11) + (number)) =20 @@ -141,6 +142,15 @@ void HELPER(mtspr)(CPUOpenRISCState *env, case TO_SPR(5, 2): /* MACHI */ env->mac =3D deposit64(env->mac, 32, 32, rb); break; + case TO_SPR(8, 0): /* PMR */ + env->pmr =3D rb; + if (env->pmr & PMR_DME || env->pmr & PMR_SME) { + cpu_restore_state(cs, GETPC()); + env->pc +=3D 4; + cs->halted =3D 1; + raise_exception(cpu, EXCP_HLT); + } + break; case TO_SPR(9, 0): /* PICMR */ env->picmr |=3D rb; break; @@ -287,6 +297,9 @@ target_ulong HELPER(mfspr)(CPUOpenRISCState *env, return env->mac >> 32; break; =20 + case TO_SPR(8, 0): /* PMR */ + return env->pmr; + case TO_SPR(9, 0): /* PICMR */ return env->picmr; =20 --=20 2.9.3