mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-09 02:24:58 -06:00
target-i386: use memory API to implement SMRAM
Remove cpu_smm_register and cpu_smm_update. Instead, each CPU address space gets an extra region which is an alias of /machine/smram. This extra region is enabled or disabled as the CPU enters/exits SMM. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
fe6567d5fd
commit
f809c60512
14 changed files with 68 additions and 93 deletions
|
@ -23,6 +23,7 @@
|
|||
#include "qom/cpu.h"
|
||||
#include "cpu.h"
|
||||
#include "qapi/error.h"
|
||||
#include "qemu/notify.h"
|
||||
|
||||
#ifdef TARGET_X86_64
|
||||
#define TYPE_X86_CPU "x86_64-cpu"
|
||||
|
@ -111,7 +112,8 @@ typedef struct X86CPU {
|
|||
/* in order to simplify APIC support, we leave this pointer to the
|
||||
user */
|
||||
struct DeviceState *apic_state;
|
||||
struct MemoryRegion *cpu_as_root;
|
||||
struct MemoryRegion *cpu_as_root, *cpu_as_mem, *smram;
|
||||
Notifier machine_done;
|
||||
} X86CPU;
|
||||
|
||||
static inline X86CPU *x86_env_get_cpu(CPUX86State *env)
|
||||
|
|
|
@ -2751,6 +2751,21 @@ static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)
|
|||
object_property_set_bool(OBJECT(cpu->apic_state), true, "realized",
|
||||
errp);
|
||||
}
|
||||
|
||||
static void x86_cpu_machine_done(Notifier *n, void *unused)
|
||||
{
|
||||
X86CPU *cpu = container_of(n, X86CPU, machine_done);
|
||||
MemoryRegion *smram =
|
||||
(MemoryRegion *) object_resolve_path("/machine/smram", NULL);
|
||||
|
||||
if (smram) {
|
||||
cpu->smram = g_new(MemoryRegion, 1);
|
||||
memory_region_init_alias(cpu->smram, OBJECT(cpu), "smram",
|
||||
smram, 0, 1ull << 32);
|
||||
memory_region_set_enabled(cpu->smram, false);
|
||||
memory_region_add_subregion_overlap(cpu->cpu_as_root, 0, cpu->smram, 1);
|
||||
}
|
||||
}
|
||||
#else
|
||||
static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)
|
||||
{
|
||||
|
@ -2815,12 +2830,26 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
|
|||
|
||||
#ifndef CONFIG_USER_ONLY
|
||||
if (tcg_enabled()) {
|
||||
cpu->cpu_as_mem = g_new(MemoryRegion, 1);
|
||||
cpu->cpu_as_root = g_new(MemoryRegion, 1);
|
||||
cs->as = g_new(AddressSpace, 1);
|
||||
memory_region_init_alias(cpu->cpu_as_root, OBJECT(cpu), "memory",
|
||||
get_system_memory(), 0, ~0ull);
|
||||
|
||||
/* Outer container... */
|
||||
memory_region_init(cpu->cpu_as_root, OBJECT(cpu), "memory", ~0ull);
|
||||
memory_region_set_enabled(cpu->cpu_as_root, true);
|
||||
|
||||
/* ... with two regions inside: normal system memory with low
|
||||
* priority, and...
|
||||
*/
|
||||
memory_region_init_alias(cpu->cpu_as_mem, OBJECT(cpu), "memory",
|
||||
get_system_memory(), 0, ~0ull);
|
||||
memory_region_add_subregion_overlap(cpu->cpu_as_root, 0, cpu->cpu_as_mem, 0);
|
||||
memory_region_set_enabled(cpu->cpu_as_mem, true);
|
||||
address_space_init(cs->as, cpu->cpu_as_root, "CPU");
|
||||
|
||||
/* ... SMRAM with higher priority, linked from /machine/smram. */
|
||||
cpu->machine_done.notify = x86_cpu_machine_done;
|
||||
qemu_add_machine_init_done_notifier(&cpu->machine_done);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1157,7 +1157,6 @@ void cpu_x86_update_cr3(CPUX86State *env, target_ulong new_cr3);
|
|||
void cpu_x86_update_cr4(CPUX86State *env, uint32_t new_cr4);
|
||||
|
||||
/* hw/pc.c */
|
||||
void cpu_smm_update(CPUX86State *env);
|
||||
uint64_t cpu_get_tsc(CPUX86State *env);
|
||||
|
||||
#define TARGET_PAGE_BITS 12
|
||||
|
@ -1323,7 +1322,9 @@ void cpu_vmexit(CPUX86State *nenv, uint32_t exit_code, uint64_t exit_info_1);
|
|||
/* seg_helper.c */
|
||||
void do_interrupt_x86_hardirq(CPUX86State *env, int intno, int is_hw);
|
||||
|
||||
/* smm_helper.c */
|
||||
void do_smm_enter(X86CPU *cpu);
|
||||
void cpu_smm_update(X86CPU *cpu);
|
||||
|
||||
void cpu_report_tpr_access(CPUX86State *env, TPRAccess access);
|
||||
|
||||
|
|
|
@ -372,6 +372,9 @@ static int cpu_post_load(void *opaque, int version_id)
|
|||
}
|
||||
tlb_flush(cs, 1);
|
||||
|
||||
if (tcg_enabled()) {
|
||||
cpu_smm_update(cpu);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,16 @@ void helper_rsm(CPUX86State *env)
|
|||
#define SMM_REVISION_ID 0x00020000
|
||||
#endif
|
||||
|
||||
void cpu_smm_update(X86CPU *cpu)
|
||||
{
|
||||
CPUX86State *env = &cpu->env;
|
||||
bool smm_enabled = (env->hflags & HF_SMM_MASK);
|
||||
|
||||
if (cpu->smram) {
|
||||
memory_region_set_enabled(cpu->smram, smm_enabled);
|
||||
}
|
||||
}
|
||||
|
||||
void do_smm_enter(X86CPU *cpu)
|
||||
{
|
||||
CPUX86State *env = &cpu->env;
|
||||
|
@ -57,7 +67,7 @@ void do_smm_enter(X86CPU *cpu)
|
|||
} else {
|
||||
env->hflags2 |= HF2_NMI_MASK;
|
||||
}
|
||||
cpu_smm_update(env);
|
||||
cpu_smm_update(cpu);
|
||||
|
||||
sm_state = env->smbase + 0x8000;
|
||||
|
||||
|
@ -317,7 +327,7 @@ void helper_rsm(CPUX86State *env)
|
|||
}
|
||||
env->hflags2 &= ~HF2_SMM_INSIDE_NMI_MASK;
|
||||
env->hflags &= ~HF_SMM_MASK;
|
||||
cpu_smm_update(env);
|
||||
cpu_smm_update(cpu);
|
||||
|
||||
qemu_log_mask(CPU_LOG_INT, "SMM: after RSM\n");
|
||||
log_cpu_state_mask(CPU_LOG_INT, CPU(cpu), CPU_DUMP_CCOP);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue