diff mbox

[qom,v2,4/4] irq: Slim conversion of qemu_irq to QOM

Message ID f1fbc450e5f6a13e7bf3df1baa608820407ea294.1403061437.git.peter.crosthwaite@xilinx.com
State New
Headers show

Commit Message

Peter Crosthwaite June 18, 2014, 7:57 a.m. UTC
From: Andreas Färber <afaerber@suse.de>

As a prequel to any big Pin refactoring plans, do an in-place conversion
of qemu_irq to an Object, so that we can reference it in link<> properties.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Andreas Färber <afaerber@suse.de>
[ PC Changes:
 * Removed array-alloctor ref counting logic (limit changes just to
 * single IRQ allocator)
 * Removed WIP marking from subject line
]
Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
---

 hw/core/irq.c    | 22 ++++++++++++++++++++--
 include/hw/irq.h |  2 ++
 2 files changed, 22 insertions(+), 2 deletions(-)

Comments

Paolo Bonzini June 18, 2014, 2:40 p.m. UTC | #1
Il 18/06/2014 09:57, Peter Crosthwaite ha scritto:
> @@ -63,7 +68,7 @@ qemu_irq qemu_allocate_irq(qemu_irq_handler handler, void *opaque, int n)
>  {
>      struct IRQState *irq;
>
> -    irq = g_new(struct IRQState, 1);
> +    irq = IRQ(object_new(TYPE_IRQ));
>      irq->handler = handler;
>      irq->opaque = opaque;
>      irq->n = n;
> @@ -82,7 +87,7 @@ void qemu_free_irqs(qemu_irq *s, int n)
>
>  void qemu_free_irq(qemu_irq irq)
>  {
> -    g_free(irq);
> +    object_unref(OBJECT(irq));
>  }
>
>  static void qemu_notirq(void *opaque, int line, int level)

If the next step is to add an "owner" like the one in MemoryRegion, and 
change occurrences of qemu_free_irq to object_unparent, then

Acked-by: Paolo Bonzini <pbonzini@redhat.com>

Paolo
Peter Crosthwaite June 19, 2014, 4:57 a.m. UTC | #2
On Thu, Jun 19, 2014 at 12:40 AM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> Il 18/06/2014 09:57, Peter Crosthwaite ha scritto:
>
>> @@ -63,7 +68,7 @@ qemu_irq qemu_allocate_irq(qemu_irq_handler handler,
>> void *opaque, int n)
>>  {
>>      struct IRQState *irq;
>>
>> -    irq = g_new(struct IRQState, 1);
>> +    irq = IRQ(object_new(TYPE_IRQ));
>>      irq->handler = handler;
>>      irq->opaque = opaque;
>>      irq->n = n;
>> @@ -82,7 +87,7 @@ void qemu_free_irqs(qemu_irq *s, int n)
>>
>>  void qemu_free_irq(qemu_irq irq)
>>  {
>> -    g_free(irq);
>> +    object_unref(OBJECT(irq));
>>  }
>>
>>  static void qemu_notirq(void *opaque, int line, int level)
>
>
> If the next step is to add an "owner" like the one in MemoryRegion, and
> change occurrences of qemu_free_irq to object_unparent,

Sure, I guess its a tree wide much like the one for Memory API though.
Can we do it as follow up though and sneak this through for 2.1?

Regards,
Peter

> then
>
> Acked-by: Paolo Bonzini <pbonzini@redhat.com>
>
> Paolo
>
Paolo Bonzini June 19, 2014, 5:47 a.m. UTC | #3
Il 19/06/2014 06:57, Peter Crosthwaite ha scritto:
>> >
>> > If the next step is to add an "owner" like the one in MemoryRegion, and
>> > change occurrences of qemu_free_irq to object_unparent,
> Sure, I guess its a tree wide much like the one for Memory API though.
> Can we do it as follow up though and sneak this through for 2.1?

Sure.

Paolo
diff mbox

Patch

diff --git a/hw/core/irq.c b/hw/core/irq.c
index bc982a7..cffced0 100644
--- a/hw/core/irq.c
+++ b/hw/core/irq.c
@@ -23,8 +23,13 @@ 
  */
 #include "qemu-common.h"
 #include "hw/irq.h"
+#include "qom/object.h"
+
+#define IRQ(obj) OBJECT_CHECK(struct IRQState, (obj), TYPE_IRQ)
 
 struct IRQState {
+    Object parent_obj;
+
     qemu_irq_handler handler;
     void *opaque;
     int n;
@@ -63,7 +68,7 @@  qemu_irq qemu_allocate_irq(qemu_irq_handler handler, void *opaque, int n)
 {
     struct IRQState *irq;
 
-    irq = g_new(struct IRQState, 1);
+    irq = IRQ(object_new(TYPE_IRQ));
     irq->handler = handler;
     irq->opaque = opaque;
     irq->n = n;
@@ -82,7 +87,7 @@  void qemu_free_irqs(qemu_irq *s, int n)
 
 void qemu_free_irq(qemu_irq irq)
 {
-    g_free(irq);
+    object_unref(OBJECT(irq));
 }
 
 static void qemu_notirq(void *opaque, int line, int level)
@@ -144,3 +149,16 @@  void qemu_irq_intercept_out(qemu_irq **gpio_out, qemu_irq_handler handler, int n
     qemu_irq *old_irqs = *gpio_out;
     *gpio_out = qemu_allocate_irqs(handler, old_irqs, n);
 }
+
+static const TypeInfo irq_type_info = {
+   .name = TYPE_IRQ,
+   .parent = TYPE_OBJECT,
+   .instance_size = sizeof(struct IRQState),
+};
+
+static void irq_register_types(void)
+{
+    type_register_static(&irq_type_info);
+}
+
+type_init(irq_register_types)
diff --git a/include/hw/irq.h b/include/hw/irq.h
index 9f34c96..6f874f5 100644
--- a/include/hw/irq.h
+++ b/include/hw/irq.h
@@ -3,6 +3,8 @@ 
 
 /* Generic IRQ/GPIO pin infrastructure.  */
 
+#define TYPE_IRQ "irq"
+
 typedef struct IRQState *qemu_irq;
 
 typedef void (*qemu_irq_handler)(void *opaque, int n, int level);