diff mbox series

[34/50] ps2: add gpio for output IRQ and optionally use it in ps2_raise_irq() and ps2_lower_irq()

Message ID 20220522181836.864-35-mark.cave-ayland@ilande.co.uk
State New
Headers show
Series PS2 device QOMification - part 1 | expand

Commit Message

Mark Cave-Ayland May 22, 2022, 6:18 p.m. UTC
Define the gpio for the PS2 output IRQ in ps2_init() and add logic to optionally
use it in ps2_raise_irq() and ps2_lower_irq() if the gpio is connected. If the
gpio is not connected then call the legacy update_irq() function as before.

This allows the incremental conversion of devices from the legacy update_irq()
function to use gpios instead.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/input/ps2.c         | 21 +++++++++++++++++++--
 include/hw/input/ps2.h |  4 ++++
 2 files changed, 23 insertions(+), 2 deletions(-)

Comments

Peter Maydell June 9, 2022, 11:05 a.m. UTC | #1
On Sun, 22 May 2022 at 19:20, Mark Cave-Ayland
<mark.cave-ayland@ilande.co.uk> wrote:
>
> Define the gpio for the PS2 output IRQ in ps2_init() and add logic to optionally
> use it in ps2_raise_irq() and ps2_lower_irq() if the gpio is connected. If the
> gpio is not connected then call the legacy update_irq() function as before.
>
> This allows the incremental conversion of devices from the legacy update_irq()
> function to use gpios instead.
>
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> ---
>  hw/input/ps2.c         | 21 +++++++++++++++++++--
>  include/hw/input/ps2.h |  4 ++++
>  2 files changed, 23 insertions(+), 2 deletions(-)
>
> diff --git a/hw/input/ps2.c b/hw/input/ps2.c
> index 214dda60bf..891eb7181c 100644
> --- a/hw/input/ps2.c
> +++ b/hw/input/ps2.c
> @@ -24,6 +24,7 @@
>
>  #include "qemu/osdep.h"
>  #include "qemu/log.h"
> +#include "hw/irq.h"
>  #include "hw/sysbus.h"
>  #include "hw/input/ps2.h"
>  #include "migration/vmstate.h"
> @@ -174,12 +175,20 @@ void ps2_queue_noirq(PS2State *s, int b)
>
>  static void ps2_raise_irq(PS2State *s)
>  {
> -    s->update_irq(s->update_arg, 1);
> +    if (s->irq) {

I know this code is going to go away in patch 50, but cleaner to write
 if (qemu_irq_is_connected(s->irq))
rather than directly testing for NULL.

> +        qemu_set_irq(s->irq, 1);
> +    } else {
> +        s->update_irq(s->update_arg, 1);
> +    }
>  }

Otherwise
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM
Mark Cave-Ayland June 10, 2022, 7:09 a.m. UTC | #2
On 09/06/2022 12:05, Peter Maydell wrote:

> On Sun, 22 May 2022 at 19:20, Mark Cave-Ayland
> <mark.cave-ayland@ilande.co.uk> wrote:
>>
>> Define the gpio for the PS2 output IRQ in ps2_init() and add logic to optionally
>> use it in ps2_raise_irq() and ps2_lower_irq() if the gpio is connected. If the
>> gpio is not connected then call the legacy update_irq() function as before.
>>
>> This allows the incremental conversion of devices from the legacy update_irq()
>> function to use gpios instead.
>>
>> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
>> ---
>>   hw/input/ps2.c         | 21 +++++++++++++++++++--
>>   include/hw/input/ps2.h |  4 ++++
>>   2 files changed, 23 insertions(+), 2 deletions(-)
>>
>> diff --git a/hw/input/ps2.c b/hw/input/ps2.c
>> index 214dda60bf..891eb7181c 100644
>> --- a/hw/input/ps2.c
>> +++ b/hw/input/ps2.c
>> @@ -24,6 +24,7 @@
>>
>>   #include "qemu/osdep.h"
>>   #include "qemu/log.h"
>> +#include "hw/irq.h"
>>   #include "hw/sysbus.h"
>>   #include "hw/input/ps2.h"
>>   #include "migration/vmstate.h"
>> @@ -174,12 +175,20 @@ void ps2_queue_noirq(PS2State *s, int b)
>>
>>   static void ps2_raise_irq(PS2State *s)
>>   {
>> -    s->update_irq(s->update_arg, 1);
>> +    if (s->irq) {
> 
> I know this code is going to go away in patch 50, but cleaner to write
>   if (qemu_irq_is_connected(s->irq))
> rather than directly testing for NULL.

Thanks, I wasn't aware of that function. I'll update it for v2.

>> +        qemu_set_irq(s->irq, 1);
>> +    } else {
>> +        s->update_irq(s->update_arg, 1);
>> +    }
>>   }
> 
> Otherwise
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
> 
> thanks
> -- PMM


ATB,

Mark.
diff mbox series

Patch

diff --git a/hw/input/ps2.c b/hw/input/ps2.c
index 214dda60bf..891eb7181c 100644
--- a/hw/input/ps2.c
+++ b/hw/input/ps2.c
@@ -24,6 +24,7 @@ 
 
 #include "qemu/osdep.h"
 #include "qemu/log.h"
+#include "hw/irq.h"
 #include "hw/sysbus.h"
 #include "hw/input/ps2.h"
 #include "migration/vmstate.h"
@@ -174,12 +175,20 @@  void ps2_queue_noirq(PS2State *s, int b)
 
 static void ps2_raise_irq(PS2State *s)
 {
-    s->update_irq(s->update_arg, 1);
+    if (s->irq) {
+        qemu_set_irq(s->irq, 1);
+    } else {
+        s->update_irq(s->update_arg, 1);
+    }
 }
 
 static void ps2_lower_irq(PS2State *s)
 {
-    s->update_irq(s->update_arg, 0);
+    if (s->irq) {
+        qemu_set_irq(s->irq, 0);
+    } else {
+        s->update_irq(s->update_arg, 0);
+    }
 }
 
 void ps2_queue(PS2State *s, int b)
@@ -1305,6 +1314,13 @@  static const TypeInfo ps2_mouse_info = {
     .class_init    = ps2_mouse_class_init
 };
 
+static void ps2_init(Object *obj)
+{
+    PS2State *s = PS2_DEVICE(obj);
+
+    qdev_init_gpio_out(DEVICE(obj), &s->irq, 1);
+}
+
 static void ps2_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -1316,6 +1332,7 @@  static void ps2_class_init(ObjectClass *klass, void *data)
 static const TypeInfo ps2_info = {
     .name          = TYPE_PS2_DEVICE,
     .parent        = TYPE_SYS_BUS_DEVICE,
+    .instance_init = ps2_init,
     .instance_size = sizeof(PS2State),
     .class_init    = ps2_class_init,
     .abstract      = true
diff --git a/include/hw/input/ps2.h b/include/hw/input/ps2.h
index d04d291287..6e5c404cb5 100644
--- a/include/hw/input/ps2.h
+++ b/include/hw/input/ps2.h
@@ -50,11 +50,15 @@  typedef struct {
     int rptr, wptr, cwptr, count;
 } PS2Queue;
 
+/* Output IRQ */
+#define PS2_DEVICE_IRQ      0
+
 struct PS2State {
     SysBusDevice parent_obj;
 
     PS2Queue queue;
     int32_t write_cmd;
+    qemu_irq irq;
     void (*update_irq)(void *, int);
     void *update_arg;
 };