target-i386: Move apic_state field from CPUX86State to X86CPU

This motion is preparing for refactoring vCPU APIC subsequently.

Signed-off-by: Chen Fan <chen.fan.fnst@cn.fujitsu.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
This commit is contained in:
Chen Fan 2013-12-23 17:04:02 +08:00 committed by Andreas Färber
parent eb2535f411
commit 02e5148334
10 changed files with 48 additions and 57 deletions

View File

@ -320,7 +320,7 @@ int cpu_exec(CPUArchState *env)
#if !defined(CONFIG_USER_ONLY) #if !defined(CONFIG_USER_ONLY)
if (interrupt_request & CPU_INTERRUPT_POLL) { if (interrupt_request & CPU_INTERRUPT_POLL) {
cpu->interrupt_request &= ~CPU_INTERRUPT_POLL; cpu->interrupt_request &= ~CPU_INTERRUPT_POLL;
apic_poll_irq(env->apic_state); apic_poll_irq(x86_env_get_cpu(env)->apic_state);
} }
#endif #endif
if (interrupt_request & CPU_INTERRUPT_INIT) { if (interrupt_request & CPU_INTERRUPT_INIT) {

5
cpus.c
View File

@ -1458,12 +1458,11 @@ void qmp_inject_nmi(Error **errp)
CPU_FOREACH(cs) { CPU_FOREACH(cs) {
X86CPU *cpu = X86_CPU(cs); X86CPU *cpu = X86_CPU(cs);
CPUX86State *env = &cpu->env;
if (!env->apic_state) { if (!cpu->apic_state) {
cpu_interrupt(cs, CPU_INTERRUPT_NMI); cpu_interrupt(cs, CPU_INTERRUPT_NMI);
} else { } else {
apic_deliver_nmi(env->apic_state); apic_deliver_nmi(cpu->apic_state);
} }
} }
#elif defined(TARGET_S390X) #elif defined(TARGET_S390X)

View File

@ -366,7 +366,7 @@ static int vapic_enable(VAPICROMState *s, X86CPU *cpu)
(((hwaddr)cpu_number) << VAPIC_CPU_SHIFT); (((hwaddr)cpu_number) << VAPIC_CPU_SHIFT);
cpu_physical_memory_rw(vapic_paddr + offsetof(VAPICState, enabled), cpu_physical_memory_rw(vapic_paddr + offsetof(VAPICState, enabled),
(void *)&enabled, sizeof(enabled), 1); (void *)&enabled, sizeof(enabled), 1);
apic_enable_vapic(cpu->env.apic_state, vapic_paddr); apic_enable_vapic(cpu->apic_state, vapic_paddr);
s->state = VAPIC_ACTIVE; s->state = VAPIC_ACTIVE;
@ -496,12 +496,10 @@ static void vapic_enable_tpr_reporting(bool enable)
}; };
CPUState *cs; CPUState *cs;
X86CPU *cpu; X86CPU *cpu;
CPUX86State *env;
CPU_FOREACH(cs) { CPU_FOREACH(cs) {
cpu = X86_CPU(cs); cpu = X86_CPU(cs);
env = &cpu->env; info.apic = cpu->apic_state;
info.apic = env->apic_state;
run_on_cpu(cs, vapic_do_enable_tpr_reporting, &info); run_on_cpu(cs, vapic_do_enable_tpr_reporting, &info);
} }
} }
@ -700,7 +698,7 @@ static void vapic_write(void *opaque, hwaddr addr, uint64_t data,
default: default:
case 4: case 4:
if (!kvm_irqchip_in_kernel()) { if (!kvm_irqchip_in_kernel()) {
apic_poll_irq(env->apic_state); apic_poll_irq(cpu->apic_state);
} }
break; break;
} }

View File

@ -171,14 +171,15 @@ void cpu_smm_update(CPUX86State *env)
/* IRQ handling */ /* IRQ handling */
int cpu_get_pic_interrupt(CPUX86State *env) int cpu_get_pic_interrupt(CPUX86State *env)
{ {
X86CPU *cpu = x86_env_get_cpu(env);
int intno; int intno;
intno = apic_get_interrupt(env->apic_state); intno = apic_get_interrupt(cpu->apic_state);
if (intno >= 0) { if (intno >= 0) {
return intno; return intno;
} }
/* read the irq from the PIC */ /* read the irq from the PIC */
if (!apic_accept_pic_intr(env->apic_state)) { if (!apic_accept_pic_intr(cpu->apic_state)) {
return -1; return -1;
} }
@ -190,15 +191,13 @@ static void pic_irq_request(void *opaque, int irq, int level)
{ {
CPUState *cs = first_cpu; CPUState *cs = first_cpu;
X86CPU *cpu = X86_CPU(cs); X86CPU *cpu = X86_CPU(cs);
CPUX86State *env = &cpu->env;
DPRINTF("pic_irqs: %s irq %d\n", level? "raise" : "lower", irq); DPRINTF("pic_irqs: %s irq %d\n", level? "raise" : "lower", irq);
if (env->apic_state) { if (cpu->apic_state) {
CPU_FOREACH(cs) { CPU_FOREACH(cs) {
cpu = X86_CPU(cs); cpu = X86_CPU(cs);
env = &cpu->env; if (apic_accept_pic_intr(cpu->apic_state)) {
if (apic_accept_pic_intr(env->apic_state)) { apic_deliver_pic_intr(cpu->apic_state, level);
apic_deliver_pic_intr(env->apic_state, level);
} }
} }
} else { } else {
@ -908,7 +907,7 @@ DeviceState *cpu_get_current_apic(void)
{ {
if (current_cpu) { if (current_cpu) {
X86CPU *cpu = X86_CPU(current_cpu); X86CPU *cpu = X86_CPU(current_cpu);
return cpu->env.apic_state; return cpu->apic_state;
} else { } else {
return NULL; return NULL;
} }
@ -1002,7 +1001,7 @@ void pc_cpus_init(const char *cpu_model, DeviceState *icc_bridge)
} }
/* map APIC MMIO area if CPU has APIC */ /* map APIC MMIO area if CPU has APIC */
if (cpu && cpu->env.apic_state) { if (cpu && cpu->apic_state) {
/* XXX: what if the base changes? */ /* XXX: what if the base changes? */
sysbus_mmio_map_overlap(SYS_BUS_DEVICE(icc_bridge), 0, sysbus_mmio_map_overlap(SYS_BUS_DEVICE(icc_bridge), 0,
APIC_DEFAULT_ADDRESS, 0x1000); APIC_DEFAULT_ADDRESS, 0x1000);

View File

@ -82,6 +82,10 @@ typedef struct X86CPU {
* capabilities) directly to the guest. * capabilities) directly to the guest.
*/ */
bool enable_pmu; bool enable_pmu;
/* in order to simplify APIC support, we leave this pointer to the
user */
struct DeviceState *apic_state;
} X86CPU; } X86CPU;
static inline X86CPU *x86_env_get_cpu(CPUX86State *env) static inline X86CPU *x86_env_get_cpu(CPUX86State *env)

View File

@ -2449,7 +2449,7 @@ static void x86_cpu_reset(CPUState *s)
#if !defined(CONFIG_USER_ONLY) #if !defined(CONFIG_USER_ONLY)
/* We hard-wire the BSP to the first CPU. */ /* We hard-wire the BSP to the first CPU. */
if (s->cpu_index == 0) { if (s->cpu_index == 0) {
apic_designate_bsp(env->apic_state); apic_designate_bsp(cpu->apic_state);
} }
s->halted = !cpu_is_bsp(cpu); s->halted = !cpu_is_bsp(cpu);
@ -2459,7 +2459,7 @@ static void x86_cpu_reset(CPUState *s)
#ifndef CONFIG_USER_ONLY #ifndef CONFIG_USER_ONLY
bool cpu_is_bsp(X86CPU *cpu) bool cpu_is_bsp(X86CPU *cpu)
{ {
return cpu_get_apic_base(cpu->env.apic_state) & MSR_IA32_APICBASE_BSP; return cpu_get_apic_base(cpu->apic_state) & MSR_IA32_APICBASE_BSP;
} }
/* TODO: remove me, when reset over QOM tree is implemented */ /* TODO: remove me, when reset over QOM tree is implemented */
@ -2500,31 +2500,29 @@ static void x86_cpu_apic_create(X86CPU *cpu, Error **errp)
apic_type = "xen-apic"; apic_type = "xen-apic";
} }
env->apic_state = qdev_try_create(qdev_get_parent_bus(dev), apic_type); cpu->apic_state = qdev_try_create(qdev_get_parent_bus(dev), apic_type);
if (env->apic_state == NULL) { if (cpu->apic_state == NULL) {
error_setg(errp, "APIC device '%s' could not be created", apic_type); error_setg(errp, "APIC device '%s' could not be created", apic_type);
return; return;
} }
object_property_add_child(OBJECT(cpu), "apic", object_property_add_child(OBJECT(cpu), "apic",
OBJECT(env->apic_state), NULL); OBJECT(cpu->apic_state), NULL);
qdev_prop_set_uint8(env->apic_state, "id", env->cpuid_apic_id); qdev_prop_set_uint8(cpu->apic_state, "id", env->cpuid_apic_id);
/* TODO: convert to link<> */ /* TODO: convert to link<> */
apic = APIC_COMMON(env->apic_state); apic = APIC_COMMON(cpu->apic_state);
apic->cpu = cpu; apic->cpu = cpu;
} }
static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp) static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)
{ {
CPUX86State *env = &cpu->env; if (cpu->apic_state == NULL) {
if (env->apic_state == NULL) {
return; return;
} }
if (qdev_init(env->apic_state)) { if (qdev_init(cpu->apic_state)) {
error_setg(errp, "APIC device '%s' could not be initialized", error_setg(errp, "APIC device '%s' could not be initialized",
object_get_typename(OBJECT(env->apic_state))); object_get_typename(OBJECT(cpu->apic_state)));
return; return;
} }
} }

View File

@ -895,10 +895,6 @@ typedef struct CPUX86State {
int tsc_khz; int tsc_khz;
void *kvm_xsave_buf; void *kvm_xsave_buf;
/* in order to simplify APIC support, we leave this pointer to the
user */
struct DeviceState *apic_state;
uint64_t mcg_cap; uint64_t mcg_cap;
uint64_t mcg_ctl; uint64_t mcg_ctl;
uint64_t mce_banks[MCE_BANKS_DEF*4]; uint64_t mce_banks[MCE_BANKS_DEF*4];

View File

@ -1241,14 +1241,16 @@ void cpu_x86_inject_mce(Monitor *mon, X86CPU *cpu, int bank,
void cpu_report_tpr_access(CPUX86State *env, TPRAccess access) void cpu_report_tpr_access(CPUX86State *env, TPRAccess access)
{ {
X86CPU *cpu = x86_env_get_cpu(env);
if (kvm_enabled()) { if (kvm_enabled()) {
env->tpr_access_type = access; env->tpr_access_type = access;
cpu_interrupt(CPU(x86_env_get_cpu(env)), CPU_INTERRUPT_TPR); cpu_interrupt(CPU(cpu), CPU_INTERRUPT_TPR);
} else { } else {
cpu_restore_state(env, env->mem_io_pc); cpu_restore_state(env, env->mem_io_pc);
apic_handle_tpr_access_report(env->apic_state, env->eip, access); apic_handle_tpr_access_report(cpu->apic_state, env->eip, access);
} }
} }
#endif /* !CONFIG_USER_ONLY */ #endif /* !CONFIG_USER_ONLY */
@ -1295,14 +1297,12 @@ void do_cpu_init(X86CPU *cpu)
cpu_reset(cs); cpu_reset(cs);
cs->interrupt_request = sipi; cs->interrupt_request = sipi;
env->pat = pat; env->pat = pat;
apic_init_reset(env->apic_state); apic_init_reset(cpu->apic_state);
} }
void do_cpu_sipi(X86CPU *cpu) void do_cpu_sipi(X86CPU *cpu)
{ {
CPUX86State *env = &cpu->env; apic_sipi(cpu->apic_state);
apic_sipi(env->apic_state);
} }
#else #else
void do_cpu_init(X86CPU *cpu) void do_cpu_init(X86CPU *cpu)

View File

@ -1069,8 +1069,8 @@ static int kvm_put_sregs(X86CPU *cpu)
sregs.cr3 = env->cr[3]; sregs.cr3 = env->cr[3];
sregs.cr4 = env->cr[4]; sregs.cr4 = env->cr[4];
sregs.cr8 = cpu_get_apic_tpr(env->apic_state); sregs.cr8 = cpu_get_apic_tpr(cpu->apic_state);
sregs.apic_base = cpu_get_apic_base(env->apic_state); sregs.apic_base = cpu_get_apic_base(cpu->apic_state);
sregs.efer = env->efer; sregs.efer = env->efer;
@ -1619,8 +1619,7 @@ static int kvm_get_mp_state(X86CPU *cpu)
static int kvm_get_apic(X86CPU *cpu) static int kvm_get_apic(X86CPU *cpu)
{ {
CPUX86State *env = &cpu->env; DeviceState *apic = cpu->apic_state;
DeviceState *apic = env->apic_state;
struct kvm_lapic_state kapic; struct kvm_lapic_state kapic;
int ret; int ret;
@ -1637,8 +1636,7 @@ static int kvm_get_apic(X86CPU *cpu)
static int kvm_put_apic(X86CPU *cpu) static int kvm_put_apic(X86CPU *cpu)
{ {
CPUX86State *env = &cpu->env; DeviceState *apic = cpu->apic_state;
DeviceState *apic = env->apic_state;
struct kvm_lapic_state kapic; struct kvm_lapic_state kapic;
if (apic && kvm_irqchip_in_kernel()) { if (apic && kvm_irqchip_in_kernel()) {
@ -1962,7 +1960,7 @@ void kvm_arch_pre_run(CPUState *cpu, struct kvm_run *run)
} }
DPRINTF("setting tpr\n"); DPRINTF("setting tpr\n");
run->cr8 = cpu_get_apic_tpr(env->apic_state); run->cr8 = cpu_get_apic_tpr(x86_cpu->apic_state);
} }
} }
@ -1976,8 +1974,8 @@ void kvm_arch_post_run(CPUState *cpu, struct kvm_run *run)
} else { } else {
env->eflags &= ~IF_MASK; env->eflags &= ~IF_MASK;
} }
cpu_set_apic_tpr(env->apic_state, run->cr8); cpu_set_apic_tpr(x86_cpu->apic_state, run->cr8);
cpu_set_apic_base(env->apic_state, run->apic_base); cpu_set_apic_base(x86_cpu->apic_state, run->apic_base);
} }
int kvm_arch_process_async_events(CPUState *cs) int kvm_arch_process_async_events(CPUState *cs)
@ -2014,7 +2012,7 @@ int kvm_arch_process_async_events(CPUState *cs)
if (cs->interrupt_request & CPU_INTERRUPT_POLL) { if (cs->interrupt_request & CPU_INTERRUPT_POLL) {
cs->interrupt_request &= ~CPU_INTERRUPT_POLL; cs->interrupt_request &= ~CPU_INTERRUPT_POLL;
apic_poll_irq(env->apic_state); apic_poll_irq(cpu->apic_state);
} }
if (((cs->interrupt_request & CPU_INTERRUPT_HARD) && if (((cs->interrupt_request & CPU_INTERRUPT_HARD) &&
(env->eflags & IF_MASK)) || (env->eflags & IF_MASK)) ||
@ -2032,7 +2030,7 @@ int kvm_arch_process_async_events(CPUState *cs)
if (cs->interrupt_request & CPU_INTERRUPT_TPR) { if (cs->interrupt_request & CPU_INTERRUPT_TPR) {
cs->interrupt_request &= ~CPU_INTERRUPT_TPR; cs->interrupt_request &= ~CPU_INTERRUPT_TPR;
kvm_cpu_synchronize_state(cs); kvm_cpu_synchronize_state(cs);
apic_handle_tpr_access_report(env->apic_state, env->eip, apic_handle_tpr_access_report(cpu->apic_state, env->eip,
env->tpr_access_type); env->tpr_access_type);
} }
@ -2056,11 +2054,10 @@ static int kvm_handle_halt(X86CPU *cpu)
static int kvm_handle_tpr_access(X86CPU *cpu) static int kvm_handle_tpr_access(X86CPU *cpu)
{ {
CPUX86State *env = &cpu->env;
CPUState *cs = CPU(cpu); CPUState *cs = CPU(cpu);
struct kvm_run *run = cs->kvm_run; struct kvm_run *run = cs->kvm_run;
apic_handle_tpr_access_report(env->apic_state, run->tpr_access.rip, apic_handle_tpr_access_report(cpu->apic_state, run->tpr_access.rip,
run->tpr_access.is_write ? TPR_ACCESS_WRITE run->tpr_access.is_write ? TPR_ACCESS_WRITE
: TPR_ACCESS_READ); : TPR_ACCESS_READ);
return 1; return 1;

View File

@ -155,7 +155,7 @@ target_ulong helper_read_crN(CPUX86State *env, int reg)
break; break;
case 8: case 8:
if (!(env->hflags2 & HF2_VINTR_MASK)) { if (!(env->hflags2 & HF2_VINTR_MASK)) {
val = cpu_get_apic_tpr(env->apic_state); val = cpu_get_apic_tpr(x86_env_get_cpu(env)->apic_state);
} else { } else {
val = env->v_tpr; val = env->v_tpr;
} }
@ -179,7 +179,7 @@ void helper_write_crN(CPUX86State *env, int reg, target_ulong t0)
break; break;
case 8: case 8:
if (!(env->hflags2 & HF2_VINTR_MASK)) { if (!(env->hflags2 & HF2_VINTR_MASK)) {
cpu_set_apic_tpr(env->apic_state, t0); cpu_set_apic_tpr(x86_env_get_cpu(env)->apic_state, t0);
} }
env->v_tpr = t0 & 0x0f; env->v_tpr = t0 & 0x0f;
break; break;
@ -286,7 +286,7 @@ void helper_wrmsr(CPUX86State *env)
env->sysenter_eip = val; env->sysenter_eip = val;
break; break;
case MSR_IA32_APICBASE: case MSR_IA32_APICBASE:
cpu_set_apic_base(env->apic_state, val); cpu_set_apic_base(x86_env_get_cpu(env)->apic_state, val);
break; break;
case MSR_EFER: case MSR_EFER:
{ {
@ -437,7 +437,7 @@ void helper_rdmsr(CPUX86State *env)
val = env->sysenter_eip; val = env->sysenter_eip;
break; break;
case MSR_IA32_APICBASE: case MSR_IA32_APICBASE:
val = cpu_get_apic_base(env->apic_state); val = cpu_get_apic_base(x86_env_get_cpu(env)->apic_state);
break; break;
case MSR_EFER: case MSR_EFER:
val = env->efer; val = env->efer;