target/openrisc: Support non-busy idle state using PMR SPR

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.

Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Stafford Horne <shorne@gmail.com>
This commit is contained in:
Stafford Horne 2017-04-24 06:07:42 +09:00
parent 48a1b62baa
commit f4d1414a93
6 changed files with 29 additions and 1 deletions

View File

@ -61,6 +61,7 @@ void cpu_openrisc_timer_update(OpenRISCCPU *cpu)
} }
next = now + (uint64_t)wait * TIMER_PERIOD; next = now + (uint64_t)wait * TIMER_PERIOD;
timer_mod(cpu->env.timer, next); timer_mod(cpu->env.timer, next);
qemu_cpu_kick(CPU(cpu));
} }
void cpu_openrisc_count_start(OpenRISCCPU *cpu) void cpu_openrisc_count_start(OpenRISCCPU *cpu)

View File

@ -51,7 +51,8 @@ static void openrisc_cpu_reset(CPUState *s)
cpu->env.lock_addr = -1; cpu->env.lock_addr = -1;
s->exception_index = -1; s->exception_index = -1;
cpu->env.upr = UPR_UP | UPR_DMP | UPR_IMP | UPR_PICP | UPR_TTP; cpu->env.upr = UPR_UP | UPR_DMP | UPR_IMP | UPR_PICP | UPR_TTP |
UPR_PMP;
cpu->env.dmmucfgr = (DMMUCFGR_NTW & (0 << 2)) | (DMMUCFGR_NTS & (6 << 2)); cpu->env.dmmucfgr = (DMMUCFGR_NTW & (0 << 2)) | (DMMUCFGR_NTS & (6 << 2));
cpu->env.immucfgr = (IMMUCFGR_NTW & (0 << 2)) | (IMMUCFGR_NTS & (6 << 2)); cpu->env.immucfgr = (IMMUCFGR_NTW & (0 << 2)) | (IMMUCFGR_NTS & (6 << 2));

View File

@ -140,6 +140,15 @@ enum {
IMMUCFGR_HTR = (1 << 11), IMMUCFGR_HTR = (1 << 11),
}; };
/* Power management register */
enum {
PMR_SDF = (15 << 0),
PMR_DME = (1 << 4),
PMR_SME = (1 << 5),
PMR_DCGE = (1 << 6),
PMR_SUME = (1 << 7),
};
/* Float point control status register */ /* Float point control status register */
enum { enum {
FPCSR_FPEE = 1, FPCSR_FPEE = 1,
@ -284,6 +293,7 @@ typedef struct CPUOpenRISCState {
uint32_t immucfgr; /* IMMU configure register */ uint32_t immucfgr; /* IMMU configure register */
uint32_t esr; /* Exception supervisor register */ uint32_t esr; /* Exception supervisor register */
uint32_t evbar; /* Exception vector base address register */ uint32_t evbar; /* Exception vector base address register */
uint32_t pmr; /* Power Management Register */
uint32_t fpcsr; /* Float register */ uint32_t fpcsr; /* Float register */
float_status fp_status; float_status fp_status;

View File

@ -60,6 +60,8 @@ void openrisc_cpu_do_interrupt(CPUState *cs)
env->sr |= SR_SM; env->sr |= SR_SM;
env->sr &= ~SR_IEE; env->sr &= ~SR_IEE;
env->sr &= ~SR_TEE; env->sr &= ~SR_TEE;
env->pmr &= ~PMR_DME;
env->pmr &= ~PMR_SME;
env->tlb->cpu_openrisc_map_address_data = &cpu_openrisc_get_phys_nommu; env->tlb->cpu_openrisc_map_address_data = &cpu_openrisc_get_phys_nommu;
env->tlb->cpu_openrisc_map_address_code = &cpu_openrisc_get_phys_nommu; env->tlb->cpu_openrisc_map_address_code = &cpu_openrisc_get_phys_nommu;
env->lock_addr = -1; env->lock_addr = -1;

View File

@ -138,6 +138,7 @@ static const VMStateDescription vmstate_env = {
VMSTATE_UINT32(dmmucfgr, CPUOpenRISCState), VMSTATE_UINT32(dmmucfgr, CPUOpenRISCState),
VMSTATE_UINT32(immucfgr, CPUOpenRISCState), VMSTATE_UINT32(immucfgr, CPUOpenRISCState),
VMSTATE_UINT32(evbar, CPUOpenRISCState), VMSTATE_UINT32(evbar, CPUOpenRISCState),
VMSTATE_UINT32(pmr, CPUOpenRISCState),
VMSTATE_UINT32(esr, CPUOpenRISCState), VMSTATE_UINT32(esr, CPUOpenRISCState),
VMSTATE_UINT32(fpcsr, CPUOpenRISCState), VMSTATE_UINT32(fpcsr, CPUOpenRISCState),
VMSTATE_UINT64(mac, CPUOpenRISCState), VMSTATE_UINT64(mac, CPUOpenRISCState),

View File

@ -22,6 +22,7 @@
#include "cpu.h" #include "cpu.h"
#include "exec/exec-all.h" #include "exec/exec-all.h"
#include "exec/helper-proto.h" #include "exec/helper-proto.h"
#include "exception.h"
#define TO_SPR(group, number) (((group) << 11) + (number)) #define TO_SPR(group, number) (((group) << 11) + (number))
@ -141,6 +142,15 @@ void HELPER(mtspr)(CPUOpenRISCState *env,
case TO_SPR(5, 2): /* MACHI */ case TO_SPR(5, 2): /* MACHI */
env->mac = deposit64(env->mac, 32, 32, rb); env->mac = deposit64(env->mac, 32, 32, rb);
break; break;
case TO_SPR(8, 0): /* PMR */
env->pmr = rb;
if (env->pmr & PMR_DME || env->pmr & PMR_SME) {
cpu_restore_state(cs, GETPC());
env->pc += 4;
cs->halted = 1;
raise_exception(cpu, EXCP_HALTED);
}
break;
case TO_SPR(9, 0): /* PICMR */ case TO_SPR(9, 0): /* PICMR */
env->picmr |= rb; env->picmr |= rb;
break; break;
@ -287,6 +297,9 @@ target_ulong HELPER(mfspr)(CPUOpenRISCState *env,
return env->mac >> 32; return env->mac >> 32;
break; break;
case TO_SPR(8, 0): /* PMR */
return env->pmr;
case TO_SPR(9, 0): /* PICMR */ case TO_SPR(9, 0): /* PICMR */
return env->picmr; return env->picmr;