diff mbox

pc: apic: introduce APIC macro

Message ID 1473900213-8765-1-git-send-email-wanpeng.li@hotmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Wanpeng Li Sept. 15, 2016, 12:43 a.m. UTC
From: Wanpeng Li <wanpeng.li@hotmail.com>

Introduce a new APIC macro to replace APIC_COMMON macro in 
hw/intc/apic.c in order to capture access LAPIC in qemu 
even if LAPIC is emulated in kvm.

Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
---
 hw/intc/apic.c                  | 20 ++++++++++----------
 include/hw/i386/apic_internal.h |  4 ++++
 2 files changed, 14 insertions(+), 10 deletions(-)

Comments

Michael S. Tsirkin Sept. 15, 2016, 1:33 a.m. UTC | #1
On Thu, Sep 15, 2016 at 08:43:33AM +0800, Wanpeng Li wrote:
> From: Wanpeng Li <wanpeng.li@hotmail.com>
> 
> Introduce a new APIC macro to replace APIC_COMMON macro in 
> hw/intc/apic.c in order to capture access LAPIC in qemu 
> even if LAPIC is emulated in kvm.
> 
> Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Radim Krčmář <rkrcmar@redhat.com>
> Cc: Michael S. Tsirkin <mst@redhat.com>
> Cc: Eduardo Habkost <ehabkost@redhat.com>
> Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>


Reviewed-by: Michael S. Tsirkin <mst@redhat.com>

> ---
>  hw/intc/apic.c                  | 20 ++++++++++----------
>  include/hw/i386/apic_internal.h |  4 ++++
>  2 files changed, 14 insertions(+), 10 deletions(-)
> 
> diff --git a/hw/intc/apic.c b/hw/intc/apic.c
> index 45887d9..577f095 100644
> --- a/hw/intc/apic.c
> +++ b/hw/intc/apic.c
> @@ -163,7 +163,7 @@ static void apic_local_deliver(APICCommonState *s, int vector)
>  
>  void apic_deliver_pic_intr(DeviceState *dev, int level)
>  {
> -    APICCommonState *s = APIC_COMMON(dev);
> +    APICCommonState *s = APIC(dev);
>  
>      if (level) {
>          apic_local_deliver(s, APIC_LVT_LINT0);
> @@ -373,7 +373,7 @@ static void apic_update_irq(APICCommonState *s)
>  
>  void apic_poll_irq(DeviceState *dev)
>  {
> -    APICCommonState *s = APIC_COMMON(dev);
> +    APICCommonState *s = APIC(dev);
>  
>      apic_sync_vapic(s, SYNC_FROM_VAPIC);
>      apic_update_irq(s);
> @@ -479,7 +479,7 @@ static void apic_startup(APICCommonState *s, int vector_num)
>  
>  void apic_sipi(DeviceState *dev)
>  {
> -    APICCommonState *s = APIC_COMMON(dev);
> +    APICCommonState *s = APIC(dev);
>  
>      cpu_reset_interrupt(CPU(s->cpu), CPU_INTERRUPT_SIPI);
>  
> @@ -493,7 +493,7 @@ static void apic_deliver(DeviceState *dev, uint8_t dest, uint8_t dest_mode,
>                           uint8_t delivery_mode, uint8_t vector_num,
>                           uint8_t trigger_mode)
>  {
> -    APICCommonState *s = APIC_COMMON(dev);
> +    APICCommonState *s = APIC(dev);
>      uint32_t deliver_bitmask[MAX_APIC_WORDS];
>      int dest_shorthand = (s->icr[0] >> 18) & 3;
>      APICCommonState *apic_iter;
> @@ -550,7 +550,7 @@ static bool apic_check_pic(APICCommonState *s)
>  
>  int apic_get_interrupt(DeviceState *dev)
>  {
> -    APICCommonState *s = APIC_COMMON(dev);
> +    APICCommonState *s = APIC(dev);
>      int intno;
>  
>      /* if the APIC is installed or enabled, we let the 8259 handle the
> @@ -584,7 +584,7 @@ int apic_get_interrupt(DeviceState *dev)
>  
>  int apic_accept_pic_intr(DeviceState *dev)
>  {
> -    APICCommonState *s = APIC_COMMON(dev);
> +    APICCommonState *s = APIC(dev);
>      uint32_t lvt0;
>  
>      if (!s)
> @@ -663,7 +663,7 @@ static uint32_t apic_mem_readl(void *opaque, hwaddr addr)
>      if (!dev) {
>          return 0;
>      }
> -    s = APIC_COMMON(dev);
> +    s = APIC(dev);
>  
>      index = (addr >> 4) & 0xff;
>      switch(index) {
> @@ -766,7 +766,7 @@ static void apic_mem_writel(void *opaque, hwaddr addr, uint32_t val)
>      if (!dev) {
>          return;
>      }
> -    s = APIC_COMMON(dev);
> +    s = APIC(dev);
>  
>      trace_apic_mem_writel(addr, val);
>  
> @@ -870,7 +870,7 @@ static const MemoryRegionOps apic_io_ops = {
>  
>  static void apic_realize(DeviceState *dev, Error **errp)
>  {
> -    APICCommonState *s = APIC_COMMON(dev);
> +    APICCommonState *s = APIC(dev);
>  
>      if (s->id >= MAX_APICS) {
>          error_setg(errp, "%s initialization failed. APIC ID %d is invalid",
> @@ -889,7 +889,7 @@ static void apic_realize(DeviceState *dev, Error **errp)
>  
>  static void apic_unrealize(DeviceState *dev, Error **errp)
>  {
> -    APICCommonState *s = APIC_COMMON(dev);
> +    APICCommonState *s = APIC(dev);
>  
>      timer_del(s->timer);
>      timer_free(s->timer);
> diff --git a/include/hw/i386/apic_internal.h b/include/hw/i386/apic_internal.h
> index 06c4e9f..5e36016 100644
> --- a/include/hw/i386/apic_internal.h
> +++ b/include/hw/i386/apic_internal.h
> @@ -131,6 +131,10 @@ typedef struct APICCommonState APICCommonState;
>  #define APIC_COMMON_GET_CLASS(obj) \
>       OBJECT_GET_CLASS(APICCommonClass, (obj), TYPE_APIC_COMMON)
>  
> +#define TYPE_APIC "apic"
> +#define APIC(obj) \
> +    OBJECT_CHECK(APICCommonState, (obj), TYPE_APIC)
> +
>  typedef struct APICCommonClass
>  {
>      DeviceClass parent_class;
> -- 
> 1.9.1
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Paolo Bonzini Sept. 15, 2016, 6:27 a.m. UTC | #2
On 15/09/2016 02:43, Wanpeng Li wrote:
> From: Wanpeng Li <wanpeng.li@hotmail.com>
> 
> Introduce a new APIC macro to replace APIC_COMMON macro in 
> hw/intc/apic.c in order to capture access LAPIC in qemu 
> even if LAPIC is emulated in kvm.
> 
> Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Radim Krčmář <rkrcmar@redhat.com>
> Cc: Michael S. Tsirkin <mst@redhat.com>
> Cc: Eduardo Habkost <ehabkost@redhat.com>
> Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
> ---
>  hw/intc/apic.c                  | 20 ++++++++++----------
>  include/hw/i386/apic_internal.h |  4 ++++
>  2 files changed, 14 insertions(+), 10 deletions(-)
> 
> diff --git a/hw/intc/apic.c b/hw/intc/apic.c
> index 45887d9..577f095 100644
> --- a/hw/intc/apic.c
> +++ b/hw/intc/apic.c
> @@ -163,7 +163,7 @@ static void apic_local_deliver(APICCommonState *s, int vector)
>  
>  void apic_deliver_pic_intr(DeviceState *dev, int level)
>  {
> -    APICCommonState *s = APIC_COMMON(dev);
> +    APICCommonState *s = APIC(dev);
>  
>      if (level) {
>          apic_local_deliver(s, APIC_LVT_LINT0);
> @@ -373,7 +373,7 @@ static void apic_update_irq(APICCommonState *s)
>  
>  void apic_poll_irq(DeviceState *dev)
>  {
> -    APICCommonState *s = APIC_COMMON(dev);
> +    APICCommonState *s = APIC(dev);
>  
>      apic_sync_vapic(s, SYNC_FROM_VAPIC);
>      apic_update_irq(s);
> @@ -479,7 +479,7 @@ static void apic_startup(APICCommonState *s, int vector_num)
>  
>  void apic_sipi(DeviceState *dev)
>  {
> -    APICCommonState *s = APIC_COMMON(dev);
> +    APICCommonState *s = APIC(dev);
>  
>      cpu_reset_interrupt(CPU(s->cpu), CPU_INTERRUPT_SIPI);
>  
> @@ -493,7 +493,7 @@ static void apic_deliver(DeviceState *dev, uint8_t dest, uint8_t dest_mode,
>                           uint8_t delivery_mode, uint8_t vector_num,
>                           uint8_t trigger_mode)
>  {
> -    APICCommonState *s = APIC_COMMON(dev);
> +    APICCommonState *s = APIC(dev);
>      uint32_t deliver_bitmask[MAX_APIC_WORDS];
>      int dest_shorthand = (s->icr[0] >> 18) & 3;
>      APICCommonState *apic_iter;
> @@ -550,7 +550,7 @@ static bool apic_check_pic(APICCommonState *s)
>  
>  int apic_get_interrupt(DeviceState *dev)
>  {
> -    APICCommonState *s = APIC_COMMON(dev);
> +    APICCommonState *s = APIC(dev);
>      int intno;
>  
>      /* if the APIC is installed or enabled, we let the 8259 handle the
> @@ -584,7 +584,7 @@ int apic_get_interrupt(DeviceState *dev)
>  
>  int apic_accept_pic_intr(DeviceState *dev)
>  {
> -    APICCommonState *s = APIC_COMMON(dev);
> +    APICCommonState *s = APIC(dev);
>      uint32_t lvt0;
>  
>      if (!s)
> @@ -663,7 +663,7 @@ static uint32_t apic_mem_readl(void *opaque, hwaddr addr)
>      if (!dev) {
>          return 0;
>      }
> -    s = APIC_COMMON(dev);
> +    s = APIC(dev);
>  
>      index = (addr >> 4) & 0xff;
>      switch(index) {
> @@ -766,7 +766,7 @@ static void apic_mem_writel(void *opaque, hwaddr addr, uint32_t val)
>      if (!dev) {
>          return;
>      }
> -    s = APIC_COMMON(dev);
> +    s = APIC(dev);
>  
>      trace_apic_mem_writel(addr, val);
>  
> @@ -870,7 +870,7 @@ static const MemoryRegionOps apic_io_ops = {
>  
>  static void apic_realize(DeviceState *dev, Error **errp)
>  {
> -    APICCommonState *s = APIC_COMMON(dev);
> +    APICCommonState *s = APIC(dev);
>  
>      if (s->id >= MAX_APICS) {
>          error_setg(errp, "%s initialization failed. APIC ID %d is invalid",
> @@ -889,7 +889,7 @@ static void apic_realize(DeviceState *dev, Error **errp)
>  
>  static void apic_unrealize(DeviceState *dev, Error **errp)
>  {
> -    APICCommonState *s = APIC_COMMON(dev);
> +    APICCommonState *s = APIC(dev);
>  
>      timer_del(s->timer);
>      timer_free(s->timer);
> diff --git a/include/hw/i386/apic_internal.h b/include/hw/i386/apic_internal.h
> index 06c4e9f..5e36016 100644
> --- a/include/hw/i386/apic_internal.h
> +++ b/include/hw/i386/apic_internal.h
> @@ -131,6 +131,10 @@ typedef struct APICCommonState APICCommonState;
>  #define APIC_COMMON_GET_CLASS(obj) \
>       OBJECT_GET_CLASS(APICCommonClass, (obj), TYPE_APIC_COMMON)
>  
> +#define TYPE_APIC "apic"
> +#define APIC(obj) \
> +    OBJECT_CHECK(APICCommonState, (obj), TYPE_APIC)

This should be in apic.c.  Also please replace the other occurrence of
"apic" in apic.c by TYPE_APIC.

Thanks,

Paolo

>  typedef struct APICCommonClass
>  {
>      DeviceClass parent_class;
> 
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wanpeng Li Sept. 15, 2016, 6:32 a.m. UTC | #3
2016-09-15 14:27 GMT+08:00 Paolo Bonzini <pbonzini@redhat.com>:
[...]
>> +#define TYPE_APIC "apic"
>> +#define APIC(obj) \
>> +    OBJECT_CHECK(APICCommonState, (obj), TYPE_APIC)
>
> This should be in apic.c.  Also please replace the other occurrence of
> "apic" in apic.c by TYPE_APIC.

Will do, thanks for your review.

Regards,
Wanpeng Li
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/hw/intc/apic.c b/hw/intc/apic.c
index 45887d9..577f095 100644
--- a/hw/intc/apic.c
+++ b/hw/intc/apic.c
@@ -163,7 +163,7 @@  static void apic_local_deliver(APICCommonState *s, int vector)
 
 void apic_deliver_pic_intr(DeviceState *dev, int level)
 {
-    APICCommonState *s = APIC_COMMON(dev);
+    APICCommonState *s = APIC(dev);
 
     if (level) {
         apic_local_deliver(s, APIC_LVT_LINT0);
@@ -373,7 +373,7 @@  static void apic_update_irq(APICCommonState *s)
 
 void apic_poll_irq(DeviceState *dev)
 {
-    APICCommonState *s = APIC_COMMON(dev);
+    APICCommonState *s = APIC(dev);
 
     apic_sync_vapic(s, SYNC_FROM_VAPIC);
     apic_update_irq(s);
@@ -479,7 +479,7 @@  static void apic_startup(APICCommonState *s, int vector_num)
 
 void apic_sipi(DeviceState *dev)
 {
-    APICCommonState *s = APIC_COMMON(dev);
+    APICCommonState *s = APIC(dev);
 
     cpu_reset_interrupt(CPU(s->cpu), CPU_INTERRUPT_SIPI);
 
@@ -493,7 +493,7 @@  static void apic_deliver(DeviceState *dev, uint8_t dest, uint8_t dest_mode,
                          uint8_t delivery_mode, uint8_t vector_num,
                          uint8_t trigger_mode)
 {
-    APICCommonState *s = APIC_COMMON(dev);
+    APICCommonState *s = APIC(dev);
     uint32_t deliver_bitmask[MAX_APIC_WORDS];
     int dest_shorthand = (s->icr[0] >> 18) & 3;
     APICCommonState *apic_iter;
@@ -550,7 +550,7 @@  static bool apic_check_pic(APICCommonState *s)
 
 int apic_get_interrupt(DeviceState *dev)
 {
-    APICCommonState *s = APIC_COMMON(dev);
+    APICCommonState *s = APIC(dev);
     int intno;
 
     /* if the APIC is installed or enabled, we let the 8259 handle the
@@ -584,7 +584,7 @@  int apic_get_interrupt(DeviceState *dev)
 
 int apic_accept_pic_intr(DeviceState *dev)
 {
-    APICCommonState *s = APIC_COMMON(dev);
+    APICCommonState *s = APIC(dev);
     uint32_t lvt0;
 
     if (!s)
@@ -663,7 +663,7 @@  static uint32_t apic_mem_readl(void *opaque, hwaddr addr)
     if (!dev) {
         return 0;
     }
-    s = APIC_COMMON(dev);
+    s = APIC(dev);
 
     index = (addr >> 4) & 0xff;
     switch(index) {
@@ -766,7 +766,7 @@  static void apic_mem_writel(void *opaque, hwaddr addr, uint32_t val)
     if (!dev) {
         return;
     }
-    s = APIC_COMMON(dev);
+    s = APIC(dev);
 
     trace_apic_mem_writel(addr, val);
 
@@ -870,7 +870,7 @@  static const MemoryRegionOps apic_io_ops = {
 
 static void apic_realize(DeviceState *dev, Error **errp)
 {
-    APICCommonState *s = APIC_COMMON(dev);
+    APICCommonState *s = APIC(dev);
 
     if (s->id >= MAX_APICS) {
         error_setg(errp, "%s initialization failed. APIC ID %d is invalid",
@@ -889,7 +889,7 @@  static void apic_realize(DeviceState *dev, Error **errp)
 
 static void apic_unrealize(DeviceState *dev, Error **errp)
 {
-    APICCommonState *s = APIC_COMMON(dev);
+    APICCommonState *s = APIC(dev);
 
     timer_del(s->timer);
     timer_free(s->timer);
diff --git a/include/hw/i386/apic_internal.h b/include/hw/i386/apic_internal.h
index 06c4e9f..5e36016 100644
--- a/include/hw/i386/apic_internal.h
+++ b/include/hw/i386/apic_internal.h
@@ -131,6 +131,10 @@  typedef struct APICCommonState APICCommonState;
 #define APIC_COMMON_GET_CLASS(obj) \
      OBJECT_GET_CLASS(APICCommonClass, (obj), TYPE_APIC_COMMON)
 
+#define TYPE_APIC "apic"
+#define APIC(obj) \
+    OBJECT_CHECK(APICCommonState, (obj), TYPE_APIC)
+
 typedef struct APICCommonClass
 {
     DeviceClass parent_class;