diff mbox

[v2,11/16] qdev: Define qdev_get_gpio_out

Message ID 081cdaf70459a467622cdebd83e30c72ae16f251.1453237258.git.alistair.francis@xilinx.com (mailing list archive)
State New, archived
Headers show

Commit Message

Alistair Francis Jan. 19, 2016, 10:35 p.m. UTC
From: Peter Crosthwaite <peter.crosthwaite@xilinx.com>

An API similar to the existing qdev_get_gpio_in() except gets outputs.
Useful for:

1: Implementing lightweight devices that don't want to keep pointers
to their own GPIOs. They can get their GPIO pointers at runtime from
QOM using this API.

2: testing or debugging code which may wish to override the
hardware generated value of of a GPIO with a user specified value
(E.G. interrupt injection).

Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
---

 hw/core/qdev.c         | 12 ++++++++++++
 include/hw/qdev-core.h |  2 ++
 2 files changed, 14 insertions(+)

Comments

KONRAD Frédéric Jan. 28, 2016, 3:44 p.m. UTC | #1
On 19/01/2016 23:35, Alistair Francis wrote:
> From: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
>
> An API similar to the existing qdev_get_gpio_in() except gets outputs.
> Useful for:
>
> 1: Implementing lightweight devices that don't want to keep pointers
> to their own GPIOs. They can get their GPIO pointers at runtime from
> QOM using this API.
>
> 2: testing or debugging code which may wish to override the
> hardware generated value of of a GPIO with a user specified value
> (E.G. interrupt injection).
>
> Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
> Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
> ---
>
>  hw/core/qdev.c         | 12 ++++++++++++
>  include/hw/qdev-core.h |  2 ++
>  2 files changed, 14 insertions(+)
>
> diff --git a/hw/core/qdev.c b/hw/core/qdev.c
> index 2c7101d..308e4a1 100644
> --- a/hw/core/qdev.c
> +++ b/hw/core/qdev.c
> @@ -489,6 +489,18 @@ qemu_irq qdev_get_gpio_in(DeviceState *dev, int n)
>      return qdev_get_gpio_in_named(dev, NULL, n);
>  }
>  
> +qemu_irq qdev_get_gpio_out_named(DeviceState *dev, const char *name, int n)
> +{
> +    char *propname = g_strdup_printf("%s[%d]",
> +                                     name ? name : "unnamed-gpio-out", n);
> +    return (qemu_irq)object_property_get_link(OBJECT(dev), propname, NULL);
> +}

Why don't we have the same implementation than qdev_get_gpio_in_named ?

qemu_irq qdev_get_gpio_in_named(DeviceState *dev, const char *name, int n)
{
    NamedGPIOList *gpio_list = qdev_get_named_gpio_list(dev, name);

    assert(n >= 0 && n < gpio_list->num_in);
    return gpio_list->in[n];
}

Thanks,
Fred
> +
> +qemu_irq qdev_get_gpio_out(DeviceState *dev, int n)
> +{
> +    return qdev_get_gpio_out_named(dev, NULL, n);
> +}
> +
>  void qdev_connect_gpio_out_named(DeviceState *dev, const char *name, int n,
>                                   qemu_irq pin)
>  {
> diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
> index abcdee8..0a09b8a 100644
> --- a/include/hw/qdev-core.h
> +++ b/include/hw/qdev-core.h
> @@ -287,6 +287,8 @@ bool qdev_machine_modified(void);
>  
>  qemu_irq qdev_get_gpio_in(DeviceState *dev, int n);
>  qemu_irq qdev_get_gpio_in_named(DeviceState *dev, const char *name, int n);
> +qemu_irq qdev_get_gpio_out(DeviceState *dev, int n);
> +qemu_irq qdev_get_gpio_out_named(DeviceState *dev, const char *name, int n);
>  
>  void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin);
>  void qdev_connect_gpio_out_named(DeviceState *dev, const char *name, int n,
Alistair Francis Jan. 30, 2016, 12:23 a.m. UTC | #2
On Thu, Jan 28, 2016 at 7:44 AM, Frederic Konrad
<fred.konrad@greensocs.com> wrote:
> On 19/01/2016 23:35, Alistair Francis wrote:
>> From: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
>>
>> An API similar to the existing qdev_get_gpio_in() except gets outputs.
>> Useful for:
>>
>> 1: Implementing lightweight devices that don't want to keep pointers
>> to their own GPIOs. They can get their GPIO pointers at runtime from
>> QOM using this API.
>>
>> 2: testing or debugging code which may wish to override the
>> hardware generated value of of a GPIO with a user specified value
>> (E.G. interrupt injection).
>>
>> Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
>> Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
>> ---
>>
>>  hw/core/qdev.c         | 12 ++++++++++++
>>  include/hw/qdev-core.h |  2 ++
>>  2 files changed, 14 insertions(+)
>>
>> diff --git a/hw/core/qdev.c b/hw/core/qdev.c
>> index 2c7101d..308e4a1 100644
>> --- a/hw/core/qdev.c
>> +++ b/hw/core/qdev.c
>> @@ -489,6 +489,18 @@ qemu_irq qdev_get_gpio_in(DeviceState *dev, int n)
>>      return qdev_get_gpio_in_named(dev, NULL, n);
>>  }
>>
>> +qemu_irq qdev_get_gpio_out_named(DeviceState *dev, const char *name, int n)
>> +{
>> +    char *propname = g_strdup_printf("%s[%d]",
>> +                                     name ? name : "unnamed-gpio-out", n);
>> +    return (qemu_irq)object_property_get_link(OBJECT(dev), propname, NULL);
>> +}
>
> Why don't we have the same implementation than qdev_get_gpio_in_named ?

Peter knows the QOM functions better then me, but from the looks of
things the in and out GPIOs are created differently. The out named
GPIOs are object properties, so without changing the way the out GPIOs
are created this looks like the best option.

Thanks,

Alistair

>
> qemu_irq qdev_get_gpio_in_named(DeviceState *dev, const char *name, int n)
> {
>     NamedGPIOList *gpio_list = qdev_get_named_gpio_list(dev, name);
>
>     assert(n >= 0 && n < gpio_list->num_in);
>     return gpio_list->in[n];
> }
>
> Thanks,
> Fred
>> +
>> +qemu_irq qdev_get_gpio_out(DeviceState *dev, int n)
>> +{
>> +    return qdev_get_gpio_out_named(dev, NULL, n);
>> +}
>> +
>>  void qdev_connect_gpio_out_named(DeviceState *dev, const char *name, int n,
>>                                   qemu_irq pin)
>>  {
>> diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
>> index abcdee8..0a09b8a 100644
>> --- a/include/hw/qdev-core.h
>> +++ b/include/hw/qdev-core.h
>> @@ -287,6 +287,8 @@ bool qdev_machine_modified(void);
>>
>>  qemu_irq qdev_get_gpio_in(DeviceState *dev, int n);
>>  qemu_irq qdev_get_gpio_in_named(DeviceState *dev, const char *name, int n);
>> +qemu_irq qdev_get_gpio_out(DeviceState *dev, int n);
>> +qemu_irq qdev_get_gpio_out_named(DeviceState *dev, const char *name, int n);
>>
>>  void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin);
>>  void qdev_connect_gpio_out_named(DeviceState *dev, const char *name, int n,
>
>
diff mbox

Patch

diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 2c7101d..308e4a1 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -489,6 +489,18 @@  qemu_irq qdev_get_gpio_in(DeviceState *dev, int n)
     return qdev_get_gpio_in_named(dev, NULL, n);
 }
 
+qemu_irq qdev_get_gpio_out_named(DeviceState *dev, const char *name, int n)
+{
+    char *propname = g_strdup_printf("%s[%d]",
+                                     name ? name : "unnamed-gpio-out", n);
+    return (qemu_irq)object_property_get_link(OBJECT(dev), propname, NULL);
+}
+
+qemu_irq qdev_get_gpio_out(DeviceState *dev, int n)
+{
+    return qdev_get_gpio_out_named(dev, NULL, n);
+}
+
 void qdev_connect_gpio_out_named(DeviceState *dev, const char *name, int n,
                                  qemu_irq pin)
 {
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index abcdee8..0a09b8a 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -287,6 +287,8 @@  bool qdev_machine_modified(void);
 
 qemu_irq qdev_get_gpio_in(DeviceState *dev, int n);
 qemu_irq qdev_get_gpio_in_named(DeviceState *dev, const char *name, int n);
+qemu_irq qdev_get_gpio_out(DeviceState *dev, int n);
+qemu_irq qdev_get_gpio_out_named(DeviceState *dev, const char *name, int n);
 
 void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin);
 void qdev_connect_gpio_out_named(DeviceState *dev, const char *name, int n,