summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvi Kivity <avi@redhat.com>2010-06-21 18:18:18 +0300
committerAvi Kivity <avi@redhat.com>2010-06-21 18:18:18 +0300
commit303d1f34a55d36c60f1042a868638b19ae3d89f0 (patch)
treec5d43328e97031fe4a09a0631856d47eafac6c4a
parent6de75b40ade8b7eac6539c5d62cf14114268f667 (diff)
parent4a942ceac7e38c259116960e45ba9619611d1df9 (diff)
Merge commit '4a942ceac7e38c259116960e45ba9619611d1df9' into upstream-merge
* commit '4a942ceac7e38c259116960e45ba9619611d1df9': apic: avoid passing CPUState from CPU code apic: avoid passing CPUState from devices Signed-off-by: Avi Kivity <avi@redhat.com>
-rw-r--r--hw/apic.c71
-rw-r--r--hw/apic.h18
-rw-r--r--hw/pc.c10
-rw-r--r--qemu-kvm-x86.c8
-rw-r--r--target-i386/cpu.h14
-rw-r--r--target-i386/helper.c4
-rw-r--r--target-i386/kvm.c14
-rw-r--r--target-i386/op_helper.c8
8 files changed, 72 insertions, 75 deletions
diff --git a/hw/apic.c b/hw/apic.c
index b90baaaaf..77d9d1d2d 100644
--- a/hw/apic.c
+++ b/hw/apic.c
@@ -94,7 +94,7 @@
#define MSI_ADDR_BASE 0xfee00000
#define MSI_ADDR_SIZE 0x100000
-typedef struct APICState {
+struct APICState {
CPUState *cpu_env;
uint32_t apicbase;
uint8_t id;
@@ -118,7 +118,7 @@ typedef struct APICState {
QEMUTimer *timer;
int sipi_vector;
int wait_for_sipi;
-} APICState;
+};
static int apic_io_memory;
static APICState *local_apics[MAX_APICS + 1];
@@ -167,9 +167,8 @@ static inline int get_bit(uint32_t *tab, int index)
return !!(tab[i] & mask);
}
-static void apic_local_deliver(CPUState *env, int vector)
+static void apic_local_deliver(APICState *s, int vector)
{
- APICState *s = env->apic_state;
uint32_t lvt = s->lvt[vector];
int trigger_mode;
@@ -180,15 +179,15 @@ static void apic_local_deliver(CPUState *env, int vector)
switch ((lvt >> 8) & 7) {
case APIC_DM_SMI:
- cpu_interrupt(env, CPU_INTERRUPT_SMI);
+ cpu_interrupt(s->cpu_env, CPU_INTERRUPT_SMI);
break;
case APIC_DM_NMI:
- cpu_interrupt(env, CPU_INTERRUPT_NMI);
+ cpu_interrupt(s->cpu_env, CPU_INTERRUPT_NMI);
break;
case APIC_DM_EXTINT:
- cpu_interrupt(env, CPU_INTERRUPT_HARD);
+ cpu_interrupt(s->cpu_env, CPU_INTERRUPT_HARD);
break;
case APIC_DM_FIXED:
@@ -200,12 +199,11 @@ static void apic_local_deliver(CPUState *env, int vector)
}
}
-void apic_deliver_pic_intr(CPUState *env, int level)
+void apic_deliver_pic_intr(APICState *s, int level)
{
- if (level)
- apic_local_deliver(env, APIC_LVT_LINT0);
- else {
- APICState *s = env->apic_state;
+ if (level) {
+ apic_local_deliver(s, APIC_LVT_LINT0);
+ } else {
uint32_t lvt = s->lvt[APIC_LVT_LINT0];
switch ((lvt >> 8) & 7) {
@@ -215,7 +213,7 @@ void apic_deliver_pic_intr(CPUState *env, int level)
reset_bit(s->irr, lvt & 0xff);
/* fall through */
case APIC_DM_EXTINT:
- cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);
+ cpu_reset_interrupt(s->cpu_env, CPU_INTERRUPT_HARD);
break;
}
}
@@ -312,10 +310,8 @@ void apic_deliver_irq(uint8_t dest, uint8_t dest_mode,
trigger_mode);
}
-void cpu_set_apic_base(CPUState *env, uint64_t val)
+void cpu_set_apic_base(APICState *s, uint64_t val)
{
- APICState *s = env->apic_state;
-
DPRINTF("cpu_set_apic_base: %016" PRIx64 "\n", val);
if (!s)
return;
@@ -327,32 +323,28 @@ void cpu_set_apic_base(CPUState *env, uint64_t val)
/* if disabled, cannot be enabled again */
if (!(val & MSR_IA32_APICBASE_ENABLE)) {
s->apicbase &= ~MSR_IA32_APICBASE_ENABLE;
- env->cpuid_features &= ~CPUID_APIC;
+ s->cpu_env->cpuid_features &= ~CPUID_APIC;
s->spurious_vec &= ~APIC_SV_ENABLE;
}
}
-uint64_t cpu_get_apic_base(CPUState *env)
+uint64_t cpu_get_apic_base(APICState *s)
{
- APICState *s = env->apic_state;
-
DPRINTF("cpu_get_apic_base: %016" PRIx64 "\n",
s ? (uint64_t)s->apicbase: 0);
return s ? s->apicbase : 0;
}
-void cpu_set_apic_tpr(CPUX86State *env, uint8_t val)
+void cpu_set_apic_tpr(APICState *s, uint8_t val)
{
- APICState *s = env->apic_state;
if (!s)
return;
s->tpr = (val & 0x0f) << 4;
apic_update_irq(s);
}
-uint8_t cpu_get_apic_tpr(CPUX86State *env)
+uint8_t cpu_get_apic_tpr(APICState *s)
{
- APICState *s = env->apic_state;
return s ? s->tpr >> 4 : 0;
}
@@ -500,9 +492,8 @@ static void apic_get_delivery_bitmask(uint32_t *deliver_bitmask,
}
-void apic_init_reset(CPUState *env)
+void apic_init_reset(APICState *s)
{
- APICState *s = env->apic_state;
int i;
if (!s)
@@ -526,7 +517,7 @@ void apic_init_reset(CPUState *env)
s->next_time = 0;
s->wait_for_sipi = 1;
- env->halted = !(s->apicbase & MSR_IA32_APICBASE_BSP);
+ s->cpu_env->halted = !(s->apicbase & MSR_IA32_APICBASE_BSP);
}
static void apic_startup(APICState *s, int vector_num)
@@ -535,19 +526,19 @@ static void apic_startup(APICState *s, int vector_num)
cpu_interrupt(s->cpu_env, CPU_INTERRUPT_SIPI);
}
-void apic_sipi(CPUState *env)
+void apic_sipi(APICState *s)
{
- APICState *s = env->apic_state;
-
- cpu_reset_interrupt(env, CPU_INTERRUPT_SIPI);
+ cpu_reset_interrupt(s->cpu_env, CPU_INTERRUPT_SIPI);
if (!s->wait_for_sipi)
return;
- env->eip = 0;
- cpu_x86_load_seg_cache(env, R_CS, s->sipi_vector << 8, s->sipi_vector << 12,
- env->segs[R_CS].limit, env->segs[R_CS].flags);
- env->halted = 0;
+ s->cpu_env->eip = 0;
+ cpu_x86_load_seg_cache(s->cpu_env, R_CS, s->sipi_vector << 8,
+ s->sipi_vector << 12,
+ s->cpu_env->segs[R_CS].limit,
+ s->cpu_env->segs[R_CS].flags);
+ s->cpu_env->halted = 0;
s->wait_for_sipi = 0;
}
@@ -599,9 +590,8 @@ static void apic_deliver(APICState *s, uint8_t dest, uint8_t dest_mode,
trigger_mode);
}
-int apic_get_interrupt(CPUState *env)
+int apic_get_interrupt(APICState *s)
{
- APICState *s = env->apic_state;
int intno;
/* if the APIC is installed or enabled, we let the 8259 handle the
@@ -623,9 +613,8 @@ int apic_get_interrupt(CPUState *env)
return intno;
}
-int apic_accept_pic_intr(CPUState *env)
+int apic_accept_pic_intr(APICState *s)
{
- APICState *s = env->apic_state;
uint32_t lvt0;
if (!s)
@@ -687,7 +676,7 @@ static void apic_timer(void *opaque)
{
APICState *s = opaque;
- apic_local_deliver(s->cpu_env, APIC_LVT_TIMER);
+ apic_local_deliver(s, APIC_LVT_TIMER);
apic_timer_update(s, s->next_time);
}
@@ -1064,7 +1053,7 @@ static void apic_reset(void *opaque)
(bsp ? MSR_IA32_APICBASE_BSP : 0) | MSR_IA32_APICBASE_ENABLE;
cpu_reset(s->cpu_env);
- apic_init_reset(s->cpu_env);
+ apic_init_reset(s);
if (bsp) {
/*
diff --git a/hw/apic.h b/hw/apic.h
index 5e039af4f..668a7cd02 100644
--- a/hw/apic.h
+++ b/hw/apic.h
@@ -1,18 +1,30 @@
#ifndef APIC_H
#define APIC_H
+/* apic.c */
+typedef struct APICState APICState;
void apic_deliver_irq(uint8_t dest, uint8_t dest_mode,
uint8_t delivery_mode,
uint8_t vector_num, uint8_t polarity,
uint8_t trigger_mode);
int apic_init(CPUState *env);
-int apic_accept_pic_intr(CPUState *env);
-void apic_deliver_pic_intr(CPUState *env, int level);
-int apic_get_interrupt(CPUState *env);
+int apic_accept_pic_intr(APICState *s);
+void apic_deliver_pic_intr(APICState *s, int level);
+int apic_get_interrupt(APICState *s);
void apic_reset_irq_delivered(void);
int apic_get_irq_delivered(void);
void apic_set_irq_delivered(void);
int cpu_is_bsp(CPUState *env);
+void cpu_set_apic_base(APICState *s, uint64_t val);
+uint64_t cpu_get_apic_base(APICState *s);
+void cpu_set_apic_tpr(APICState *s, uint8_t val);
+#ifndef NO_CPU_IO_DEFS
+uint8_t cpu_get_apic_tpr(APICState *s);
+#endif
+
+void apic_init_reset(APICState *s);
+void apic_sipi(APICState *s);
+
#endif
diff --git a/hw/pc.c b/hw/pc.c
index 2010e8c2d..3b3cfd49c 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -149,7 +149,7 @@ int cpu_get_pic_interrupt(CPUState *env)
{
int intno;
- intno = apic_get_interrupt(env);
+ intno = apic_get_interrupt(env->apic_state);
if (intno >= 0) {
/* set irq request if a PIC irq is still pending */
/* XXX: improve that */
@@ -157,8 +157,9 @@ int cpu_get_pic_interrupt(CPUState *env)
return intno;
}
/* read the irq from the PIC */
- if (!apic_accept_pic_intr(env))
+ if (!apic_accept_pic_intr(env->apic_state)) {
return -1;
+ }
intno = pic_read_irq(isa_pic);
return intno;
@@ -171,8 +172,9 @@ static void pic_irq_request(void *opaque, int irq, int level)
DPRINTF("pic_irqs: %s irq %d\n", level? "raise" : "lower", irq);
if (env->apic_state) {
while (env) {
- if (apic_accept_pic_intr(env))
- apic_deliver_pic_intr(env, level);
+ if (apic_accept_pic_intr(env->apic_state)) {
+ apic_deliver_pic_intr(env->apic_state, level);
+ }
env = env->next_cpu;
}
} else {
diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c
index 1232049e6..403337a57 100644
--- a/qemu-kvm-x86.c
+++ b/qemu-kvm-x86.c
@@ -906,8 +906,8 @@ void kvm_arch_load_regs(CPUState *env, int level)
sregs.cr3 = env->cr[3];
sregs.cr4 = env->cr[4];
- sregs.cr8 = cpu_get_apic_tpr(env);
- sregs.apic_base = cpu_get_apic_base(env);
+ sregs.cr8 = cpu_get_apic_tpr(env->apic_state);
+ sregs.apic_base = cpu_get_apic_base(env->apic_state);
sregs.efer = env->efer;
@@ -1090,7 +1090,7 @@ void kvm_arch_save_regs(CPUState *env)
env->cr[3] = sregs.cr3;
env->cr[4] = sregs.cr4;
- cpu_set_apic_base(env, sregs.apic_base);
+ cpu_set_apic_base(env->apic_state, sregs.apic_base);
env->efer = sregs.efer;
//cpu_set_apic_tpr(env, sregs.cr8);
@@ -1230,7 +1230,7 @@ int kvm_arch_halt(CPUState *env)
int kvm_arch_pre_run(CPUState *env, struct kvm_run *run)
{
if (!kvm_irqchip_in_kernel())
- kvm_set_cr8(env, cpu_get_apic_tpr(env));
+ kvm_set_cr8(env, cpu_get_apic_tpr(env->apic_state));
return 0;
}
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index c32f854f2..49e59ccfc 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -882,14 +882,6 @@ void cpu_x86_update_cr0(CPUX86State *env, uint32_t new_cr0);
void cpu_x86_update_cr3(CPUX86State *env, target_ulong new_cr3);
void cpu_x86_update_cr4(CPUX86State *env, uint32_t new_cr4);
-/* hw/apic.c */
-void cpu_set_apic_base(CPUX86State *env, uint64_t val);
-uint64_t cpu_get_apic_base(CPUX86State *env);
-void cpu_set_apic_tpr(CPUX86State *env, uint8_t val);
-#ifndef NO_CPU_IO_DEFS
-uint8_t cpu_get_apic_tpr(CPUX86State *env);
-#endif
-
/* hw/pc.c */
void cpu_smm_update(CPUX86State *env);
uint64_t cpu_get_tsc(CPUX86State *env);
@@ -952,6 +944,10 @@ static inline void cpu_clone_regs(CPUState *env, target_ulong newsp)
#include "svm.h"
+#if !defined(CONFIG_USER_ONLY)
+#include "hw/apic.h"
+#endif
+
static inline void cpu_pc_from_tb(CPUState *env, TranslationBlock *tb)
{
env->eip = tb->pc - tb->cs_base;
@@ -966,8 +962,6 @@ static inline void cpu_get_tb_cpu_state(CPUState *env, target_ulong *pc,
(env->eflags & (IOPL_MASK | TF_MASK | RF_MASK | VM_MASK));
}
-void apic_init_reset(CPUState *env);
-void apic_sipi(CPUState *env);
void do_cpu_init(CPUState *env);
void do_cpu_sipi(CPUState *env);
#endif /* CPU_I386_H */
diff --git a/target-i386/helper.c b/target-i386/helper.c
index ae7fbf1fe..9072a3495 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -1157,12 +1157,12 @@ void do_cpu_init(CPUState *env)
int sipi = env->interrupt_request & CPU_INTERRUPT_SIPI;
cpu_reset(env);
env->interrupt_request = sipi;
- apic_init_reset(env);
+ apic_init_reset(env->apic_state);
}
void do_cpu_sipi(CPUState *env)
{
- apic_sipi(env);
+ apic_sipi(env->apic_state);
}
#else
void do_cpu_init(CPUState *env)
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 57327f586..791fedaba 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -558,8 +558,8 @@ static int kvm_put_sregs(CPUState *env)
sregs.cr3 = env->cr[3];
sregs.cr4 = env->cr[4];
- sregs.cr8 = cpu_get_apic_tpr(env);
- sregs.apic_base = cpu_get_apic_base(env);
+ sregs.cr8 = cpu_get_apic_tpr(env->apic_state);
+ sregs.apic_base = cpu_get_apic_base(env->apic_state);
sregs.efer = env->efer;
@@ -674,10 +674,10 @@ static int kvm_get_sregs(CPUState *env)
env->cr[3] = sregs.cr3;
env->cr[4] = sregs.cr4;
- cpu_set_apic_base(env, sregs.apic_base);
+ cpu_set_apic_base(env->apic_state, sregs.apic_base);
env->efer = sregs.efer;
- //cpu_set_apic_tpr(env, sregs.cr8);
+ //cpu_set_apic_tpr(env->apic_state, sregs.cr8);
#define HFLAG_COPY_MASK ~( \
HF_CPL_MASK | HF_PE_MASK | HF_MP_MASK | HF_EM_MASK | \
@@ -1083,7 +1083,7 @@ int kvm_arch_pre_run(CPUState *env, struct kvm_run *run)
run->request_interrupt_window = 0;
DPRINTF("setting tpr\n");
- run->cr8 = cpu_get_apic_tpr(env);
+ run->cr8 = cpu_get_apic_tpr(env->apic_state);
return 0;
}
@@ -1096,8 +1096,8 @@ int kvm_arch_post_run(CPUState *env, struct kvm_run *run)
else
env->eflags &= ~IF_MASK;
- cpu_set_apic_tpr(env, run->cr8);
- cpu_set_apic_base(env, run->apic_base);
+ cpu_set_apic_tpr(env->apic_state, run->cr8);
+ cpu_set_apic_base(env->apic_state, run->apic_base);
return 0;
}
diff --git a/target-i386/op_helper.c b/target-i386/op_helper.c
index dcbdfe7e0..c1256f4ab 100644
--- a/target-i386/op_helper.c
+++ b/target-i386/op_helper.c
@@ -2888,7 +2888,7 @@ target_ulong helper_read_crN(int reg)
break;
case 8:
if (!(env->hflags2 & HF2_VINTR_MASK)) {
- val = cpu_get_apic_tpr(env);
+ val = cpu_get_apic_tpr(env->apic_state);
} else {
val = env->v_tpr;
}
@@ -2912,7 +2912,7 @@ void helper_write_crN(int reg, target_ulong t0)
break;
case 8:
if (!(env->hflags2 & HF2_VINTR_MASK)) {
- cpu_set_apic_tpr(env, t0);
+ cpu_set_apic_tpr(env->apic_state, t0);
}
env->v_tpr = t0 & 0x0f;
break;
@@ -3020,7 +3020,7 @@ void helper_wrmsr(void)
env->sysenter_eip = val;
break;
case MSR_IA32_APICBASE:
- cpu_set_apic_base(env, val);
+ cpu_set_apic_base(env->apic_state, val);
break;
case MSR_EFER:
{
@@ -3153,7 +3153,7 @@ void helper_rdmsr(void)
val = env->sysenter_eip;
break;
case MSR_IA32_APICBASE:
- val = cpu_get_apic_base(env);
+ val = cpu_get_apic_base(env->apic_state);
break;
case MSR_EFER:
val = env->efer;