diff mbox series

[v5,2/2] hw/arm/sbsa-ref: add SBSA watchdog device

Message ID 20201013151631.30678-3-shashi.mallela@linaro.org
State Superseded
Headers show
Series Add watchdog support for SbsaQemu | expand

Commit Message

Shashi Mallela Oct. 13, 2020, 3:16 p.m. UTC
Included the newly implemented SBSA generic watchdog device model into
SBSA platform

Signed-off-by: Shashi Mallela <shashi.mallela@linaro.org>
---
 hw/arm/sbsa-ref.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

Comments

Graeme Gregory Oct. 14, 2020, 9:31 a.m. UTC | #1
On Tue, Oct 13, 2020 at 11:16:31AM -0400, Shashi Mallela wrote:
> Included the newly implemented SBSA generic watchdog device model into
> SBSA platform
> 
> Signed-off-by: Shashi Mallela <shashi.mallela@linaro.org>
> ---
>  hw/arm/sbsa-ref.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 50 insertions(+)
> 
> diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c
> index 9c3a893bedfd..97ed41607119 100644
> --- a/hw/arm/sbsa-ref.c
> +++ b/hw/arm/sbsa-ref.c
> @@ -30,6 +30,7 @@
>  #include "exec/hwaddr.h"
>  #include "kvm_arm.h"
>  #include "hw/arm/boot.h"
> +#include "hw/arm/fdt.h"
>  #include "hw/block/flash.h"
>  #include "hw/boards.h"
>  #include "hw/ide/internal.h"
> @@ -40,6 +41,7 @@
>  #include "hw/qdev-properties.h"
>  #include "hw/usb.h"
>  #include "hw/char/pl011.h"
> +#include "hw/watchdog/wdt_sbsa_gwdt.h"
>  #include "net/net.h"
>  #include "qom/object.h"
>  
> @@ -64,6 +66,9 @@ enum {
>      SBSA_GIC_DIST,
>      SBSA_GIC_REDIST,
>      SBSA_SECURE_EC,
> +    SBSA_GWDT,
> +    SBSA_GWDT_REFRESH,
> +    SBSA_GWDT_CONTROL,
>      SBSA_SMMU,
>      SBSA_UART,
>      SBSA_RTC,
> @@ -104,6 +109,8 @@ static const MemMapEntry sbsa_ref_memmap[] = {
>      [SBSA_GIC_DIST] =           { 0x40060000, 0x00010000 },
>      [SBSA_GIC_REDIST] =         { 0x40080000, 0x04000000 },
>      [SBSA_SECURE_EC] =          { 0x50000000, 0x00001000 },
> +    [SBSA_GWDT_REFRESH] =       { 0x50010000, 0x00001000 },
> +    [SBSA_GWDT_CONTROL] =       { 0x50011000, 0x00001000 },
>      [SBSA_UART] =               { 0x60000000, 0x00001000 },
>      [SBSA_RTC] =                { 0x60010000, 0x00001000 },
>      [SBSA_GPIO] =               { 0x60020000, 0x00001000 },
> @@ -133,6 +140,8 @@ static const int sbsa_ref_irqmap[] = {
>      [SBSA_SECURE_UART_MM] = 9,
>      [SBSA_AHCI] = 10,
>      [SBSA_EHCI] = 11,
> +    [SBSA_SMMU] = 12, /* ... to 15 */
> +    [SBSA_GWDT] = 16,
>  };
>  
>  static uint64_t sbsa_ref_cpu_mp_affinity(SBSAMachineState *sms, int idx)
> @@ -141,6 +150,30 @@ static uint64_t sbsa_ref_cpu_mp_affinity(SBSAMachineState *sms, int idx)
>      return arm_cpu_mp_affinity(idx, clustersz);
>  }
>  
> +static void create_wdt_fdt(SBSAMachineState *sms)
> +{
> +    char *nodename;
> +    const char compat[] = "arm,sbsa-gwdt";
> +
> +    hwaddr rbase = sbsa_ref_memmap[SBSA_GWDT_REFRESH].base;
> +    hwaddr cbase = sbsa_ref_memmap[SBSA_GWDT_CONTROL].base;
> +    int irq = sbsa_ref_irqmap[SBSA_GWDT];
> +
> +    nodename = g_strdup_printf("/watchdog@%" PRIx64, rbase);
> +    qemu_fdt_add_subnode(sms->fdt, nodename);
> +
> +    qemu_fdt_setprop(sms->fdt, nodename, "compatible",
> +                             compat, sizeof(compat));
> +    qemu_fdt_setprop_sized_cells(sms->fdt, nodename, "reg",
> +                                 2, rbase, 2, SBSA_GWDT_RMMIO_SIZE,
> +                                 2, cbase, 2, SBSA_GWDT_CMMIO_SIZE);
> +    qemu_fdt_setprop_cells(sms->fdt, nodename, "interrupts",
> +                                GIC_FDT_IRQ_TYPE_PPI, irq,
> +                                GIC_FDT_IRQ_FLAGS_LEVEL_HI);
> +    qemu_fdt_setprop_cell(sms->fdt, nodename, "timeout-sec", 30);
> +    g_free(nodename);
> +}
> +

Is this actually used anywhere? I ask because SBSA-ref is not a FDT
booting machine and only uses FDT to transfer some dynamic info to
arm-tf/edk2 and is not a full description tree. Your ACPI patch in
edk2 certainly does not use this info.

Graeme


>  /*
>   * Firmware on this machine only uses ACPI table to load OS, these limited
>   * device tree nodes are just to let firmware know the info which varies from
> @@ -219,6 +252,7 @@ static void create_fdt(SBSAMachineState *sms)
>  
>          g_free(nodename);
>      }
> +    create_wdt_fdt(sms);
>  }
>  
>  #define SBSA_FLASH_SECTOR_SIZE (256 * KiB)
> @@ -447,6 +481,20 @@ static void create_rtc(const SBSAMachineState *sms)
>      sysbus_create_simple("pl031", base, qdev_get_gpio_in(sms->gic, irq));
>  }
>  
> +static void create_wdt(const SBSAMachineState *sms)
> +{
> +    hwaddr rbase = sbsa_ref_memmap[SBSA_GWDT_REFRESH].base;
> +    hwaddr cbase = sbsa_ref_memmap[SBSA_GWDT_CONTROL].base;
> +    DeviceState *dev = qdev_new(TYPE_WDT_SBSA_GWDT);
> +    SysBusDevice *s = SYS_BUS_DEVICE(dev);
> +    int irq = sbsa_ref_irqmap[SBSA_GWDT];
> +
> +    sysbus_realize_and_unref(s, &error_fatal);
> +    sysbus_mmio_map(s, 0, rbase);
> +    sysbus_mmio_map(s, 1, cbase);
> +    sysbus_connect_irq(s, 0, qdev_get_gpio_in(sms->gic, irq));
> +}
> +
>  static DeviceState *gpio_key_dev;
>  static void sbsa_ref_powerdown_req(Notifier *n, void *opaque)
>  {
> @@ -730,6 +778,8 @@ static void sbsa_ref_init(MachineState *machine)
>  
>      create_rtc(sms);
>  
> +    create_wdt(sms);
> +
>      create_gpio(sms);
>  
>      create_ahci(sms);
> -- 
> 2.18.4
> 
>
Shashi Mallela Oct. 14, 2020, 5:04 p.m. UTC | #2
This was added as a placeholder for the virt requirement suggested by Maxim
earlier.Agreed that this fdt otherwise has no significance for sbsa-ref
platform nor is being used by ACPI table created for wdt.

-Shashi

On Wed, 14 Oct 2020 at 05:31, Graeme Gregory <graeme@nuviainc.com> wrote:

> On Tue, Oct 13, 2020 at 11:16:31AM -0400, Shashi Mallela wrote:

> > Included the newly implemented SBSA generic watchdog device model into

> > SBSA platform

> >

> > Signed-off-by: Shashi Mallela <shashi.mallela@linaro.org>

> > ---

> >  hw/arm/sbsa-ref.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++

> >  1 file changed, 50 insertions(+)

> >

> > diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c

> > index 9c3a893bedfd..97ed41607119 100644

> > --- a/hw/arm/sbsa-ref.c

> > +++ b/hw/arm/sbsa-ref.c

> > @@ -30,6 +30,7 @@

> >  #include "exec/hwaddr.h"

> >  #include "kvm_arm.h"

> >  #include "hw/arm/boot.h"

> > +#include "hw/arm/fdt.h"

> >  #include "hw/block/flash.h"

> >  #include "hw/boards.h"

> >  #include "hw/ide/internal.h"

> > @@ -40,6 +41,7 @@

> >  #include "hw/qdev-properties.h"

> >  #include "hw/usb.h"

> >  #include "hw/char/pl011.h"

> > +#include "hw/watchdog/wdt_sbsa_gwdt.h"

> >  #include "net/net.h"

> >  #include "qom/object.h"

> >

> > @@ -64,6 +66,9 @@ enum {

> >      SBSA_GIC_DIST,

> >      SBSA_GIC_REDIST,

> >      SBSA_SECURE_EC,

> > +    SBSA_GWDT,

> > +    SBSA_GWDT_REFRESH,

> > +    SBSA_GWDT_CONTROL,

> >      SBSA_SMMU,

> >      SBSA_UART,

> >      SBSA_RTC,

> > @@ -104,6 +109,8 @@ static const MemMapEntry sbsa_ref_memmap[] = {

> >      [SBSA_GIC_DIST] =           { 0x40060000, 0x00010000 },

> >      [SBSA_GIC_REDIST] =         { 0x40080000, 0x04000000 },

> >      [SBSA_SECURE_EC] =          { 0x50000000, 0x00001000 },

> > +    [SBSA_GWDT_REFRESH] =       { 0x50010000, 0x00001000 },

> > +    [SBSA_GWDT_CONTROL] =       { 0x50011000, 0x00001000 },

> >      [SBSA_UART] =               { 0x60000000, 0x00001000 },

> >      [SBSA_RTC] =                { 0x60010000, 0x00001000 },

> >      [SBSA_GPIO] =               { 0x60020000, 0x00001000 },

> > @@ -133,6 +140,8 @@ static const int sbsa_ref_irqmap[] = {

> >      [SBSA_SECURE_UART_MM] = 9,

> >      [SBSA_AHCI] = 10,

> >      [SBSA_EHCI] = 11,

> > +    [SBSA_SMMU] = 12, /* ... to 15 */

> > +    [SBSA_GWDT] = 16,

> >  };

> >

> >  static uint64_t sbsa_ref_cpu_mp_affinity(SBSAMachineState *sms, int idx)

> > @@ -141,6 +150,30 @@ static uint64_t

> sbsa_ref_cpu_mp_affinity(SBSAMachineState *sms, int idx)

> >      return arm_cpu_mp_affinity(idx, clustersz);

> >  }

> >

> > +static void create_wdt_fdt(SBSAMachineState *sms)

> > +{

> > +    char *nodename;

> > +    const char compat[] = "arm,sbsa-gwdt";

> > +

> > +    hwaddr rbase = sbsa_ref_memmap[SBSA_GWDT_REFRESH].base;

> > +    hwaddr cbase = sbsa_ref_memmap[SBSA_GWDT_CONTROL].base;

> > +    int irq = sbsa_ref_irqmap[SBSA_GWDT];

> > +

> > +    nodename = g_strdup_printf("/watchdog@%" PRIx64, rbase);

> > +    qemu_fdt_add_subnode(sms->fdt, nodename);

> > +

> > +    qemu_fdt_setprop(sms->fdt, nodename, "compatible",

> > +                             compat, sizeof(compat));

> > +    qemu_fdt_setprop_sized_cells(sms->fdt, nodename, "reg",

> > +                                 2, rbase, 2, SBSA_GWDT_RMMIO_SIZE,

> > +                                 2, cbase, 2, SBSA_GWDT_CMMIO_SIZE);

> > +    qemu_fdt_setprop_cells(sms->fdt, nodename, "interrupts",

> > +                                GIC_FDT_IRQ_TYPE_PPI, irq,

> > +                                GIC_FDT_IRQ_FLAGS_LEVEL_HI);

> > +    qemu_fdt_setprop_cell(sms->fdt, nodename, "timeout-sec", 30);

> > +    g_free(nodename);

> > +}

> > +

>

> Is this actually used anywhere? I ask because SBSA-ref is not a FDT

> booting machine and only uses FDT to transfer some dynamic info to

> arm-tf/edk2 and is not a full description tree. Your ACPI patch in

> edk2 certainly does not use this info.

>

> Graeme

>

>

> >  /*

> >   * Firmware on this machine only uses ACPI table to load OS, these

> limited

> >   * device tree nodes are just to let firmware know the info which

> varies from

> > @@ -219,6 +252,7 @@ static void create_fdt(SBSAMachineState *sms)

> >

> >          g_free(nodename);

> >      }

> > +    create_wdt_fdt(sms);

> >  }

> >

> >  #define SBSA_FLASH_SECTOR_SIZE (256 * KiB)

> > @@ -447,6 +481,20 @@ static void create_rtc(const SBSAMachineState *sms)

> >      sysbus_create_simple("pl031", base, qdev_get_gpio_in(sms->gic,

> irq));

> >  }

> >

> > +static void create_wdt(const SBSAMachineState *sms)

> > +{

> > +    hwaddr rbase = sbsa_ref_memmap[SBSA_GWDT_REFRESH].base;

> > +    hwaddr cbase = sbsa_ref_memmap[SBSA_GWDT_CONTROL].base;

> > +    DeviceState *dev = qdev_new(TYPE_WDT_SBSA_GWDT);

> > +    SysBusDevice *s = SYS_BUS_DEVICE(dev);

> > +    int irq = sbsa_ref_irqmap[SBSA_GWDT];

> > +

> > +    sysbus_realize_and_unref(s, &error_fatal);

> > +    sysbus_mmio_map(s, 0, rbase);

> > +    sysbus_mmio_map(s, 1, cbase);

> > +    sysbus_connect_irq(s, 0, qdev_get_gpio_in(sms->gic, irq));

> > +}

> > +

> >  static DeviceState *gpio_key_dev;

> >  static void sbsa_ref_powerdown_req(Notifier *n, void *opaque)

> >  {

> > @@ -730,6 +778,8 @@ static void sbsa_ref_init(MachineState *machine)

> >

> >      create_rtc(sms);

> >

> > +    create_wdt(sms);

> > +

> >      create_gpio(sms);

> >

> >      create_ahci(sms);

> > --

> > 2.18.4

> >

> >

>
<div dir="ltr"><div>This was added as a placeholder for the virt requirement suggested by 
Maxim earlier.Agreed that this fdt otherwise has no significance for 
sbsa-ref platform nor is being used by ACPI table created for wdt.</div><div><br></div><div>-Shashi<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 14 Oct 2020 at 05:31, Graeme Gregory &lt;<a href="mailto:graeme@nuviainc.com">graeme@nuviainc.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Tue, Oct 13, 2020 at 11:16:31AM -0400, Shashi Mallela wrote:<br>
&gt; Included the newly implemented SBSA generic watchdog device model into<br>
&gt; SBSA platform<br>
&gt; <br>
&gt; Signed-off-by: Shashi Mallela &lt;<a href="mailto:shashi.mallela@linaro.org" target="_blank">shashi.mallela@linaro.org</a>&gt;<br>
&gt; ---<br>
&gt;  hw/arm/sbsa-ref.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++<br>
&gt;  1 file changed, 50 insertions(+)<br>
&gt; <br>
&gt; diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c<br>
&gt; index 9c3a893bedfd..97ed41607119 100644<br>
&gt; --- a/hw/arm/sbsa-ref.c<br>
&gt; +++ b/hw/arm/sbsa-ref.c<br>
&gt; @@ -30,6 +30,7 @@<br>
&gt;  #include &quot;exec/hwaddr.h&quot;<br>
&gt;  #include &quot;kvm_arm.h&quot;<br>
&gt;  #include &quot;hw/arm/boot.h&quot;<br>
&gt; +#include &quot;hw/arm/fdt.h&quot;<br>
&gt;  #include &quot;hw/block/flash.h&quot;<br>
&gt;  #include &quot;hw/boards.h&quot;<br>
&gt;  #include &quot;hw/ide/internal.h&quot;<br>
&gt; @@ -40,6 +41,7 @@<br>
&gt;  #include &quot;hw/qdev-properties.h&quot;<br>
&gt;  #include &quot;hw/usb.h&quot;<br>
&gt;  #include &quot;hw/char/pl011.h&quot;<br>
&gt; +#include &quot;hw/watchdog/wdt_sbsa_gwdt.h&quot;<br>
&gt;  #include &quot;net/net.h&quot;<br>
&gt;  #include &quot;qom/object.h&quot;<br>
&gt;  <br>
&gt; @@ -64,6 +66,9 @@ enum {<br>
&gt;      SBSA_GIC_DIST,<br>
&gt;      SBSA_GIC_REDIST,<br>
&gt;      SBSA_SECURE_EC,<br>
&gt; +    SBSA_GWDT,<br>
&gt; +    SBSA_GWDT_REFRESH,<br>
&gt; +    SBSA_GWDT_CONTROL,<br>
&gt;      SBSA_SMMU,<br>
&gt;      SBSA_UART,<br>
&gt;      SBSA_RTC,<br>
&gt; @@ -104,6 +109,8 @@ static const MemMapEntry sbsa_ref_memmap[] = {<br>
&gt;      [SBSA_GIC_DIST] =           { 0x40060000, 0x00010000 },<br>
&gt;      [SBSA_GIC_REDIST] =         { 0x40080000, 0x04000000 },<br>
&gt;      [SBSA_SECURE_EC] =          { 0x50000000, 0x00001000 },<br>
&gt; +    [SBSA_GWDT_REFRESH] =       { 0x50010000, 0x00001000 },<br>
&gt; +    [SBSA_GWDT_CONTROL] =       { 0x50011000, 0x00001000 },<br>
&gt;      [SBSA_UART] =               { 0x60000000, 0x00001000 },<br>
&gt;      [SBSA_RTC] =                { 0x60010000, 0x00001000 },<br>
&gt;      [SBSA_GPIO] =               { 0x60020000, 0x00001000 },<br>
&gt; @@ -133,6 +140,8 @@ static const int sbsa_ref_irqmap[] = {<br>
&gt;      [SBSA_SECURE_UART_MM] = 9,<br>
&gt;      [SBSA_AHCI] = 10,<br>
&gt;      [SBSA_EHCI] = 11,<br>
&gt; +    [SBSA_SMMU] = 12, /* ... to 15 */<br>
&gt; +    [SBSA_GWDT] = 16,<br>
&gt;  };<br>
&gt;  <br>
&gt;  static uint64_t sbsa_ref_cpu_mp_affinity(SBSAMachineState *sms, int idx)<br>
&gt; @@ -141,6 +150,30 @@ static uint64_t sbsa_ref_cpu_mp_affinity(SBSAMachineState *sms, int idx)<br>
&gt;      return arm_cpu_mp_affinity(idx, clustersz);<br>
&gt;  }<br>
&gt;  <br>
&gt; +static void create_wdt_fdt(SBSAMachineState *sms)<br>
&gt; +{<br>
&gt; +    char *nodename;<br>
&gt; +    const char compat[] = &quot;arm,sbsa-gwdt&quot;;<br>
&gt; +<br>
&gt; +    hwaddr rbase = sbsa_ref_memmap[SBSA_GWDT_REFRESH].base;<br>
&gt; +    hwaddr cbase = sbsa_ref_memmap[SBSA_GWDT_CONTROL].base;<br>
&gt; +    int irq = sbsa_ref_irqmap[SBSA_GWDT];<br>
&gt; +<br>
&gt; +    nodename = g_strdup_printf(&quot;/watchdog@%&quot; PRIx64, rbase);<br>
&gt; +    qemu_fdt_add_subnode(sms-&gt;fdt, nodename);<br>
&gt; +<br>
&gt; +    qemu_fdt_setprop(sms-&gt;fdt, nodename, &quot;compatible&quot;,<br>
&gt; +                             compat, sizeof(compat));<br>
&gt; +    qemu_fdt_setprop_sized_cells(sms-&gt;fdt, nodename, &quot;reg&quot;,<br>
&gt; +                                 2, rbase, 2, SBSA_GWDT_RMMIO_SIZE,<br>
&gt; +                                 2, cbase, 2, SBSA_GWDT_CMMIO_SIZE);<br>
&gt; +    qemu_fdt_setprop_cells(sms-&gt;fdt, nodename, &quot;interrupts&quot;,<br>
&gt; +                                GIC_FDT_IRQ_TYPE_PPI, irq,<br>
&gt; +                                GIC_FDT_IRQ_FLAGS_LEVEL_HI);<br>
&gt; +    qemu_fdt_setprop_cell(sms-&gt;fdt, nodename, &quot;timeout-sec&quot;, 30);<br>
&gt; +    g_free(nodename);<br>
&gt; +}<br>
&gt; +<br>
<br>
Is this actually used anywhere? I ask because SBSA-ref is not a FDT<br>
booting machine and only uses FDT to transfer some dynamic info to<br>
arm-tf/edk2 and is not a full description tree. Your ACPI patch in<br>
edk2 certainly does not use this info.<br>
<br>
Graeme<br>
<br>
<br>
&gt;  /*<br>
&gt;   * Firmware on this machine only uses ACPI table to load OS, these limited<br>
&gt;   * device tree nodes are just to let firmware know the info which varies from<br>
&gt; @@ -219,6 +252,7 @@ static void create_fdt(SBSAMachineState *sms)<br>
&gt;  <br>
&gt;          g_free(nodename);<br>
&gt;      }<br>
&gt; +    create_wdt_fdt(sms);<br>
&gt;  }<br>
&gt;  <br>
&gt;  #define SBSA_FLASH_SECTOR_SIZE (256 * KiB)<br>
&gt; @@ -447,6 +481,20 @@ static void create_rtc(const SBSAMachineState *sms)<br>
&gt;      sysbus_create_simple(&quot;pl031&quot;, base, qdev_get_gpio_in(sms-&gt;gic, irq));<br>
&gt;  }<br>
&gt;  <br>
&gt; +static void create_wdt(const SBSAMachineState *sms)<br>
&gt; +{<br>
&gt; +    hwaddr rbase = sbsa_ref_memmap[SBSA_GWDT_REFRESH].base;<br>
&gt; +    hwaddr cbase = sbsa_ref_memmap[SBSA_GWDT_CONTROL].base;<br>
&gt; +    DeviceState *dev = qdev_new(TYPE_WDT_SBSA_GWDT);<br>
&gt; +    SysBusDevice *s = SYS_BUS_DEVICE(dev);<br>
&gt; +    int irq = sbsa_ref_irqmap[SBSA_GWDT];<br>
&gt; +<br>
&gt; +    sysbus_realize_and_unref(s, &amp;error_fatal);<br>
&gt; +    sysbus_mmio_map(s, 0, rbase);<br>
&gt; +    sysbus_mmio_map(s, 1, cbase);<br>
&gt; +    sysbus_connect_irq(s, 0, qdev_get_gpio_in(sms-&gt;gic, irq));<br>
&gt; +}<br>
&gt; +<br>
&gt;  static DeviceState *gpio_key_dev;<br>
&gt;  static void sbsa_ref_powerdown_req(Notifier *n, void *opaque)<br>
&gt;  {<br>
&gt; @@ -730,6 +778,8 @@ static void sbsa_ref_init(MachineState *machine)<br>
&gt;  <br>
&gt;      create_rtc(sms);<br>
&gt;  <br>
&gt; +    create_wdt(sms);<br>
&gt; +<br>
&gt;      create_gpio(sms);<br>
&gt;  <br>
&gt;      create_ahci(sms);<br>
&gt; -- <br>
&gt; 2.18.4<br>
&gt; <br>
&gt; <br>
</blockquote></div>
Graeme Gregory Oct. 15, 2020, 2:10 p.m. UTC | #3
On Wed, Oct 14, 2020 at 01:04:43PM -0400, Shashi Mallela wrote:
> This was added as a placeholder for the virt requirement suggested by Maxim

> earlier.Agreed that this fdt otherwise has no significance for sbsa-ref

> platform nor is being used by ACPI table created for wdt.

> 

> -Shashi

> 

> On Wed, 14 Oct 2020 at 05:31, Graeme Gregory <[1]graeme@nuviainc.com> wrote:

> 

>     On Tue, Oct 13, 2020 at 11:16:31AM -0400, Shashi Mallela wrote:

>     > Included the newly implemented SBSA generic watchdog device model into

>     > SBSA platform

>     >

>     > Signed-off-by: Shashi Mallela <[2]shashi.mallela@linaro.org>

>     > ---

>     >  hw/arm/sbsa-ref.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++

>     >  1 file changed, 50 insertions(+)

>     >

>     > diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c

>     > index 9c3a893bedfd..97ed41607119 100644

>     > --- a/hw/arm/sbsa-ref.c

>     > +++ b/hw/arm/sbsa-ref.c

>     > @@ -30,6 +30,7 @@

>     >  #include "exec/hwaddr.h"

>     >  #include "kvm_arm.h"

>     >  #include "hw/arm/boot.h"

>     > +#include "hw/arm/fdt.h"

>     >  #include "hw/block/flash.h"

>     >  #include "hw/boards.h"

>     >  #include "hw/ide/internal.h"

>     > @@ -40,6 +41,7 @@

>     >  #include "hw/qdev-properties.h"

>     >  #include "hw/usb.h"

>     >  #include "hw/char/pl011.h"

>     > +#include "hw/watchdog/wdt_sbsa_gwdt.h"

>     >  #include "net/net.h"

>     >  #include "qom/object.h"

>     > 

>     > @@ -64,6 +66,9 @@ enum {

>     >      SBSA_GIC_DIST,

>     >      SBSA_GIC_REDIST,

>     >      SBSA_SECURE_EC,

>     > +    SBSA_GWDT,

>     > +    SBSA_GWDT_REFRESH,

>     > +    SBSA_GWDT_CONTROL,

>     >      SBSA_SMMU,

>     >      SBSA_UART,

>     >      SBSA_RTC,

>     > @@ -104,6 +109,8 @@ static const MemMapEntry sbsa_ref_memmap[] = {

>     >      [SBSA_GIC_DIST] =           { 0x40060000, 0x00010000 },

>     >      [SBSA_GIC_REDIST] =         { 0x40080000, 0x04000000 },

>     >      [SBSA_SECURE_EC] =          { 0x50000000, 0x00001000 },

>     > +    [SBSA_GWDT_REFRESH] =       { 0x50010000, 0x00001000 },

>     > +    [SBSA_GWDT_CONTROL] =       { 0x50011000, 0x00001000 },

>     >      [SBSA_UART] =               { 0x60000000, 0x00001000 },

>     >      [SBSA_RTC] =                { 0x60010000, 0x00001000 },

>     >      [SBSA_GPIO] =               { 0x60020000, 0x00001000 },

>     > @@ -133,6 +140,8 @@ static const int sbsa_ref_irqmap[] = {

>     >      [SBSA_SECURE_UART_MM] = 9,

>     >      [SBSA_AHCI] = 10,

>     >      [SBSA_EHCI] = 11,

>     > +    [SBSA_SMMU] = 12, /* ... to 15 */

>     > +    [SBSA_GWDT] = 16,

>     >  };


I guess your patch was not based on master here? You should make sure
you are rebased to the latest version before sending.

>     > 

>     >  static uint64_t sbsa_ref_cpu_mp_affinity(SBSAMachineState *sms, int idx)

>     > @@ -141,6 +150,30 @@ static uint64_t sbsa_ref_cpu_mp_affinity

>     (SBSAMachineState *sms, int idx)

>     >      return arm_cpu_mp_affinity(idx, clustersz);

>     >  }

>     > 

>     > +static void create_wdt_fdt(SBSAMachineState *sms)

>     > +{

>     > +    char *nodename;

>     > +    const char compat[] = "arm,sbsa-gwdt";

>     > +

>     > +    hwaddr rbase = sbsa_ref_memmap[SBSA_GWDT_REFRESH].base;

>     > +    hwaddr cbase = sbsa_ref_memmap[SBSA_GWDT_CONTROL].base;

>     > +    int irq = sbsa_ref_irqmap[SBSA_GWDT];

>     > +

>     > +    nodename = g_strdup_printf("/watchdog@%" PRIx64, rbase);

>     > +    qemu_fdt_add_subnode(sms->fdt, nodename);

>     > +

>     > +    qemu_fdt_setprop(sms->fdt, nodename, "compatible",

>     > +                             compat, sizeof(compat));

>     > +    qemu_fdt_setprop_sized_cells(sms->fdt, nodename, "reg",

>     > +                                 2, rbase, 2, SBSA_GWDT_RMMIO_SIZE,

>     > +                                 2, cbase, 2, SBSA_GWDT_CMMIO_SIZE);

>     > +    qemu_fdt_setprop_cells(sms->fdt, nodename, "interrupts",

>     > +                                GIC_FDT_IRQ_TYPE_PPI, irq,

>     > +                                GIC_FDT_IRQ_FLAGS_LEVEL_HI);

>     > +    qemu_fdt_setprop_cell(sms->fdt, nodename, "timeout-sec", 30);

>     > +    g_free(nodename);

>     > +}

>     > +

> 

>     Is this actually used anywhere? I ask because SBSA-ref is not a FDT

>     booting machine and only uses FDT to transfer some dynamic info to

>     arm-tf/edk2 and is not a full description tree. Your ACPI patch in

>     edk2 certainly does not use this info.

> 


From your reply above I would propose this hunk and the call below are
removed. If its needed to virt thats a seperate discussion which I think
was already happening in another thread.

FOSS style is for inline replies not top posting FYI

Graeme

>     Graeme

> 

> 

>     >  /*

>     >   * Firmware on this machine only uses ACPI table to load OS, these

>     limited

>     >   * device tree nodes are just to let firmware know the info which varies

>     from

>     > @@ -219,6 +252,7 @@ static void create_fdt(SBSAMachineState *sms)

>     > 

>     >          g_free(nodename);

>     >      }

>     > +    create_wdt_fdt(sms);

>     >  }

>     > 

>     >  #define SBSA_FLASH_SECTOR_SIZE (256 * KiB)

>     > @@ -447,6 +481,20 @@ static void create_rtc(const SBSAMachineState *sms)

>     >      sysbus_create_simple("pl031", base, qdev_get_gpio_in(sms->gic,

>     irq));

>     >  }

>     > 

>     > +static void create_wdt(const SBSAMachineState *sms)

>     > +{

>     > +    hwaddr rbase = sbsa_ref_memmap[SBSA_GWDT_REFRESH].base;

>     > +    hwaddr cbase = sbsa_ref_memmap[SBSA_GWDT_CONTROL].base;

>     > +    DeviceState *dev = qdev_new(TYPE_WDT_SBSA_GWDT);

>     > +    SysBusDevice *s = SYS_BUS_DEVICE(dev);

>     > +    int irq = sbsa_ref_irqmap[SBSA_GWDT];

>     > +

>     > +    sysbus_realize_and_unref(s, &error_fatal);

>     > +    sysbus_mmio_map(s, 0, rbase);

>     > +    sysbus_mmio_map(s, 1, cbase);

>     > +    sysbus_connect_irq(s, 0, qdev_get_gpio_in(sms->gic, irq));

>     > +}

>     > +

>     >  static DeviceState *gpio_key_dev;

>     >  static void sbsa_ref_powerdown_req(Notifier *n, void *opaque)

>     >  {

>     > @@ -730,6 +778,8 @@ static void sbsa_ref_init(MachineState *machine)

>     > 

>     >      create_rtc(sms);

>     > 

>     > +    create_wdt(sms);

>     > +

>     >      create_gpio(sms);

>     > 

>     >      create_ahci(sms);

>     > --

>     > 2.18.4

>     >

>     >

> 

> 

> References:

> 

> [1] mailto:graeme@nuviainc.com

> [2] mailto:shashi.mallela@linaro.org
Maxim Uvarov Oct. 15, 2020, 3:21 p.m. UTC | #4
On Thu, 15 Oct 2020 at 17:12, Graeme Gregory <graeme@nuviainc.com> wrote:
>
> On Wed, Oct 14, 2020 at 01:04:43PM -0400, Shashi Mallela wrote:
> > This was added as a placeholder for the virt requirement suggested by Maxim
> > earlier.Agreed that this fdt otherwise has no significance for sbsa-ref
> > platform nor is being used by ACPI table created for wdt.
> >
> > -Shashi
> >
> > On Wed, 14 Oct 2020 at 05:31, Graeme Gregory <[1]graeme@nuviainc.com> wrote:
> >
> >     On Tue, Oct 13, 2020 at 11:16:31AM -0400, Shashi Mallela wrote:
> >     > Included the newly implemented SBSA generic watchdog device model into
> >     > SBSA platform
> >     >
> >     > Signed-off-by: Shashi Mallela <[2]shashi.mallela@linaro.org>
> >     > ---
> >     >  hw/arm/sbsa-ref.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++
> >     >  1 file changed, 50 insertions(+)
> >     >
> >     > diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c
> >     > index 9c3a893bedfd..97ed41607119 100644
> >     > --- a/hw/arm/sbsa-ref.c
> >     > +++ b/hw/arm/sbsa-ref.c
> >     > @@ -30,6 +30,7 @@
> >     >  #include "exec/hwaddr.h"
> >     >  #include "kvm_arm.h"
> >     >  #include "hw/arm/boot.h"
> >     > +#include "hw/arm/fdt.h"
> >     >  #include "hw/block/flash.h"
> >     >  #include "hw/boards.h"
> >     >  #include "hw/ide/internal.h"
> >     > @@ -40,6 +41,7 @@
> >     >  #include "hw/qdev-properties.h"
> >     >  #include "hw/usb.h"
> >     >  #include "hw/char/pl011.h"
> >     > +#include "hw/watchdog/wdt_sbsa_gwdt.h"
> >     >  #include "net/net.h"
> >     >  #include "qom/object.h"
> >     >
> >     > @@ -64,6 +66,9 @@ enum {
> >     >      SBSA_GIC_DIST,
> >     >      SBSA_GIC_REDIST,
> >     >      SBSA_SECURE_EC,
> >     > +    SBSA_GWDT,
> >     > +    SBSA_GWDT_REFRESH,
> >     > +    SBSA_GWDT_CONTROL,
> >     >      SBSA_SMMU,
> >     >      SBSA_UART,
> >     >      SBSA_RTC,
> >     > @@ -104,6 +109,8 @@ static const MemMapEntry sbsa_ref_memmap[] = {
> >     >      [SBSA_GIC_DIST] =           { 0x40060000, 0x00010000 },
> >     >      [SBSA_GIC_REDIST] =         { 0x40080000, 0x04000000 },
> >     >      [SBSA_SECURE_EC] =          { 0x50000000, 0x00001000 },
> >     > +    [SBSA_GWDT_REFRESH] =       { 0x50010000, 0x00001000 },
> >     > +    [SBSA_GWDT_CONTROL] =       { 0x50011000, 0x00001000 },
> >     >      [SBSA_UART] =               { 0x60000000, 0x00001000 },
> >     >      [SBSA_RTC] =                { 0x60010000, 0x00001000 },
> >     >      [SBSA_GPIO] =               { 0x60020000, 0x00001000 },
> >     > @@ -133,6 +140,8 @@ static const int sbsa_ref_irqmap[] = {
> >     >      [SBSA_SECURE_UART_MM] = 9,
> >     >      [SBSA_AHCI] = 10,
> >     >      [SBSA_EHCI] = 11,
> >     > +    [SBSA_SMMU] = 12, /* ... to 15 */
> >     > +    [SBSA_GWDT] = 16,
> >     >  };
>
> I guess your patch was not based on master here? You should make sure
> you are rebased to the latest version before sending.
>
> >     >
> >     >  static uint64_t sbsa_ref_cpu_mp_affinity(SBSAMachineState *sms, int idx)
> >     > @@ -141,6 +150,30 @@ static uint64_t sbsa_ref_cpu_mp_affinity
> >     (SBSAMachineState *sms, int idx)
> >     >      return arm_cpu_mp_affinity(idx, clustersz);
> >     >  }
> >     >
> >     > +static void create_wdt_fdt(SBSAMachineState *sms)
> >     > +{
> >     > +    char *nodename;
> >     > +    const char compat[] = "arm,sbsa-gwdt";
> >     > +
> >     > +    hwaddr rbase = sbsa_ref_memmap[SBSA_GWDT_REFRESH].base;
> >     > +    hwaddr cbase = sbsa_ref_memmap[SBSA_GWDT_CONTROL].base;
> >     > +    int irq = sbsa_ref_irqmap[SBSA_GWDT];
> >     > +
> >     > +    nodename = g_strdup_printf("/watchdog@%" PRIx64, rbase);
> >     > +    qemu_fdt_add_subnode(sms->fdt, nodename);
> >     > +
> >     > +    qemu_fdt_setprop(sms->fdt, nodename, "compatible",
> >     > +                             compat, sizeof(compat));
> >     > +    qemu_fdt_setprop_sized_cells(sms->fdt, nodename, "reg",
> >     > +                                 2, rbase, 2, SBSA_GWDT_RMMIO_SIZE,
> >     > +                                 2, cbase, 2, SBSA_GWDT_CMMIO_SIZE);
> >     > +    qemu_fdt_setprop_cells(sms->fdt, nodename, "interrupts",
> >     > +                                GIC_FDT_IRQ_TYPE_PPI, irq,
> >     > +                                GIC_FDT_IRQ_FLAGS_LEVEL_HI);
> >     > +    qemu_fdt_setprop_cell(sms->fdt, nodename, "timeout-sec", 30);
> >     > +    g_free(nodename);
> >     > +}
> >     > +
> >
> >     Is this actually used anywhere? I ask because SBSA-ref is not a FDT
> >     booting machine and only uses FDT to transfer some dynamic info to
> >     arm-tf/edk2 and is not a full description tree. Your ACPI patch in
> >     edk2 certainly does not use this info.
> >
>

Greame, if sbsa-ref does not support non edk2 boot, i.e.
arm-tf/optee/uboot-uefi, then it's better to remove here and we can
add later for the virt machine.

> From your reply above I would propose this hunk and the call below are
> removed. If its needed to virt thats a seperate discussion which I think
> was already happening in another thread.
>
Yep, agree.

Maxim.

> FOSS style is for inline replies not top posting FYI
>
> Graeme
>
> >     Graeme
> >
> >
> >     >  /*
> >     >   * Firmware on this machine only uses ACPI table to load OS, these
> >     limited
> >     >   * device tree nodes are just to let firmware know the info which varies
> >     from
> >     > @@ -219,6 +252,7 @@ static void create_fdt(SBSAMachineState *sms)
> >     >
> >     >          g_free(nodename);
> >     >      }
> >     > +    create_wdt_fdt(sms);
> >     >  }
> >     >
> >     >  #define SBSA_FLASH_SECTOR_SIZE (256 * KiB)
> >     > @@ -447,6 +481,20 @@ static void create_rtc(const SBSAMachineState *sms)
> >     >      sysbus_create_simple("pl031", base, qdev_get_gpio_in(sms->gic,
> >     irq));
> >     >  }
> >     >
> >     > +static void create_wdt(const SBSAMachineState *sms)
> >     > +{
> >     > +    hwaddr rbase = sbsa_ref_memmap[SBSA_GWDT_REFRESH].base;
> >     > +    hwaddr cbase = sbsa_ref_memmap[SBSA_GWDT_CONTROL].base;
> >     > +    DeviceState *dev = qdev_new(TYPE_WDT_SBSA_GWDT);
> >     > +    SysBusDevice *s = SYS_BUS_DEVICE(dev);
> >     > +    int irq = sbsa_ref_irqmap[SBSA_GWDT];
> >     > +
> >     > +    sysbus_realize_and_unref(s, &error_fatal);
> >     > +    sysbus_mmio_map(s, 0, rbase);
> >     > +    sysbus_mmio_map(s, 1, cbase);
> >     > +    sysbus_connect_irq(s, 0, qdev_get_gpio_in(sms->gic, irq));
> >     > +}
> >     > +
> >     >  static DeviceState *gpio_key_dev;
> >     >  static void sbsa_ref_powerdown_req(Notifier *n, void *opaque)
> >     >  {
> >     > @@ -730,6 +778,8 @@ static void sbsa_ref_init(MachineState *machine)
> >     >
> >     >      create_rtc(sms);
> >     >
> >     > +    create_wdt(sms);
> >     > +
> >     >      create_gpio(sms);
> >     >
> >     >      create_ahci(sms);
> >     > --
> >     > 2.18.4
> >     >
> >     >
> >
> >
> > References:
> >
> > [1] mailto:graeme@nuviainc.com
> > [2] mailto:shashi.mallela@linaro.org
>
Graeme Gregory Oct. 16, 2020, 8:37 a.m. UTC | #5
On Thu, Oct 15, 2020 at 06:21:09PM +0300, Maxim Uvarov wrote:
> On Thu, 15 Oct 2020 at 17:12, Graeme Gregory <graeme@nuviainc.com> wrote:
> >
> > On Wed, Oct 14, 2020 at 01:04:43PM -0400, Shashi Mallela wrote:
> > > This was added as a placeholder for the virt requirement suggested by Maxim
> > > earlier.Agreed that this fdt otherwise has no significance for sbsa-ref
> > > platform nor is being used by ACPI table created for wdt.
> > >
> > > -Shashi
> > >
> > > On Wed, 14 Oct 2020 at 05:31, Graeme Gregory <[1]graeme@nuviainc.com> wrote:
> > >
> > >     On Tue, Oct 13, 2020 at 11:16:31AM -0400, Shashi Mallela wrote:
> > >     > Included the newly implemented SBSA generic watchdog device model into
> > >     > SBSA platform
> > >     >
> > >     > Signed-off-by: Shashi Mallela <[2]shashi.mallela@linaro.org>
> > >     > ---
> > >     >  hw/arm/sbsa-ref.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++
> > >     >  1 file changed, 50 insertions(+)
> > >     >
> > >     > diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c
> > >     > index 9c3a893bedfd..97ed41607119 100644
> > >     > --- a/hw/arm/sbsa-ref.c
> > >     > +++ b/hw/arm/sbsa-ref.c
> > >     > @@ -30,6 +30,7 @@
> > >     >  #include "exec/hwaddr.h"
> > >     >  #include "kvm_arm.h"
> > >     >  #include "hw/arm/boot.h"
> > >     > +#include "hw/arm/fdt.h"
> > >     >  #include "hw/block/flash.h"
> > >     >  #include "hw/boards.h"
> > >     >  #include "hw/ide/internal.h"
> > >     > @@ -40,6 +41,7 @@
> > >     >  #include "hw/qdev-properties.h"
> > >     >  #include "hw/usb.h"
> > >     >  #include "hw/char/pl011.h"
> > >     > +#include "hw/watchdog/wdt_sbsa_gwdt.h"
> > >     >  #include "net/net.h"
> > >     >  #include "qom/object.h"
> > >     >
> > >     > @@ -64,6 +66,9 @@ enum {
> > >     >      SBSA_GIC_DIST,
> > >     >      SBSA_GIC_REDIST,
> > >     >      SBSA_SECURE_EC,
> > >     > +    SBSA_GWDT,
> > >     > +    SBSA_GWDT_REFRESH,
> > >     > +    SBSA_GWDT_CONTROL,
> > >     >      SBSA_SMMU,
> > >     >      SBSA_UART,
> > >     >      SBSA_RTC,
> > >     > @@ -104,6 +109,8 @@ static const MemMapEntry sbsa_ref_memmap[] = {
> > >     >      [SBSA_GIC_DIST] =           { 0x40060000, 0x00010000 },
> > >     >      [SBSA_GIC_REDIST] =         { 0x40080000, 0x04000000 },
> > >     >      [SBSA_SECURE_EC] =          { 0x50000000, 0x00001000 },
> > >     > +    [SBSA_GWDT_REFRESH] =       { 0x50010000, 0x00001000 },
> > >     > +    [SBSA_GWDT_CONTROL] =       { 0x50011000, 0x00001000 },
> > >     >      [SBSA_UART] =               { 0x60000000, 0x00001000 },
> > >     >      [SBSA_RTC] =                { 0x60010000, 0x00001000 },
> > >     >      [SBSA_GPIO] =               { 0x60020000, 0x00001000 },
> > >     > @@ -133,6 +140,8 @@ static const int sbsa_ref_irqmap[] = {
> > >     >      [SBSA_SECURE_UART_MM] = 9,
> > >     >      [SBSA_AHCI] = 10,
> > >     >      [SBSA_EHCI] = 11,
> > >     > +    [SBSA_SMMU] = 12, /* ... to 15 */
> > >     > +    [SBSA_GWDT] = 16,
> > >     >  };
> >
> > I guess your patch was not based on master here? You should make sure
> > you are rebased to the latest version before sending.
> >
> > >     >
> > >     >  static uint64_t sbsa_ref_cpu_mp_affinity(SBSAMachineState *sms, int idx)
> > >     > @@ -141,6 +150,30 @@ static uint64_t sbsa_ref_cpu_mp_affinity
> > >     (SBSAMachineState *sms, int idx)
> > >     >      return arm_cpu_mp_affinity(idx, clustersz);
> > >     >  }
> > >     >
> > >     > +static void create_wdt_fdt(SBSAMachineState *sms)
> > >     > +{
> > >     > +    char *nodename;
> > >     > +    const char compat[] = "arm,sbsa-gwdt";
> > >     > +
> > >     > +    hwaddr rbase = sbsa_ref_memmap[SBSA_GWDT_REFRESH].base;
> > >     > +    hwaddr cbase = sbsa_ref_memmap[SBSA_GWDT_CONTROL].base;
> > >     > +    int irq = sbsa_ref_irqmap[SBSA_GWDT];
> > >     > +
> > >     > +    nodename = g_strdup_printf("/watchdog@%" PRIx64, rbase);
> > >     > +    qemu_fdt_add_subnode(sms->fdt, nodename);
> > >     > +
> > >     > +    qemu_fdt_setprop(sms->fdt, nodename, "compatible",
> > >     > +                             compat, sizeof(compat));
> > >     > +    qemu_fdt_setprop_sized_cells(sms->fdt, nodename, "reg",
> > >     > +                                 2, rbase, 2, SBSA_GWDT_RMMIO_SIZE,
> > >     > +                                 2, cbase, 2, SBSA_GWDT_CMMIO_SIZE);
> > >     > +    qemu_fdt_setprop_cells(sms->fdt, nodename, "interrupts",
> > >     > +                                GIC_FDT_IRQ_TYPE_PPI, irq,
> > >     > +                                GIC_FDT_IRQ_FLAGS_LEVEL_HI);
> > >     > +    qemu_fdt_setprop_cell(sms->fdt, nodename, "timeout-sec", 30);
> > >     > +    g_free(nodename);
> > >     > +}
> > >     > +
> > >
> > >     Is this actually used anywhere? I ask because SBSA-ref is not a FDT
> > >     booting machine and only uses FDT to transfer some dynamic info to
> > >     arm-tf/edk2 and is not a full description tree. Your ACPI patch in
> > >     edk2 certainly does not use this info.
> > >
> >
> 
> Greame, if sbsa-ref does not support non edk2 boot, i.e.
> arm-tf/optee/uboot-uefi, then it's better to remove here and we can
> add later for the virt machine.
> 
It is not that it does not support it, it is as real hardware you will
need to build the hardware knowledge into your firmware.

Graeme

> > From your reply above I would propose this hunk and the call below are
> > removed. If its needed to virt thats a seperate discussion which I think
> > was already happening in another thread.
> >
> Yep, agree.
> 
> Maxim.
> 
> > FOSS style is for inline replies not top posting FYI
> >
> > Graeme
> >
> > >     Graeme
> > >
> > >
> > >     >  /*
> > >     >   * Firmware on this machine only uses ACPI table to load OS, these
> > >     limited
> > >     >   * device tree nodes are just to let firmware know the info which varies
> > >     from
> > >     > @@ -219,6 +252,7 @@ static void create_fdt(SBSAMachineState *sms)
> > >     >
> > >     >          g_free(nodename);
> > >     >      }
> > >     > +    create_wdt_fdt(sms);
> > >     >  }
> > >     >
> > >     >  #define SBSA_FLASH_SECTOR_SIZE (256 * KiB)
> > >     > @@ -447,6 +481,20 @@ static void create_rtc(const SBSAMachineState *sms)
> > >     >      sysbus_create_simple("pl031", base, qdev_get_gpio_in(sms->gic,
> > >     irq));
> > >     >  }
> > >     >
> > >     > +static void create_wdt(const SBSAMachineState *sms)
> > >     > +{
> > >     > +    hwaddr rbase = sbsa_ref_memmap[SBSA_GWDT_REFRESH].base;
> > >     > +    hwaddr cbase = sbsa_ref_memmap[SBSA_GWDT_CONTROL].base;
> > >     > +    DeviceState *dev = qdev_new(TYPE_WDT_SBSA_GWDT);
> > >     > +    SysBusDevice *s = SYS_BUS_DEVICE(dev);
> > >     > +    int irq = sbsa_ref_irqmap[SBSA_GWDT];
> > >     > +
> > >     > +    sysbus_realize_and_unref(s, &error_fatal);
> > >     > +    sysbus_mmio_map(s, 0, rbase);
> > >     > +    sysbus_mmio_map(s, 1, cbase);
> > >     > +    sysbus_connect_irq(s, 0, qdev_get_gpio_in(sms->gic, irq));
> > >     > +}
> > >     > +
> > >     >  static DeviceState *gpio_key_dev;
> > >     >  static void sbsa_ref_powerdown_req(Notifier *n, void *opaque)
> > >     >  {
> > >     > @@ -730,6 +778,8 @@ static void sbsa_ref_init(MachineState *machine)
> > >     >
> > >     >      create_rtc(sms);
> > >     >
> > >     > +    create_wdt(sms);
> > >     > +
> > >     >      create_gpio(sms);
> > >     >
> > >     >      create_ahci(sms);
> > >     > --
> > >     > 2.18.4
> > >     >
> > >     >
> > >
> > >
> > > References:
> > >
> > > [1] mailto:graeme@nuviainc.com
> > > [2] mailto:shashi.mallela@linaro.org
> >
diff mbox series

Patch

diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c
index 9c3a893bedfd..97ed41607119 100644
--- a/hw/arm/sbsa-ref.c
+++ b/hw/arm/sbsa-ref.c
@@ -30,6 +30,7 @@ 
 #include "exec/hwaddr.h"
 #include "kvm_arm.h"
 #include "hw/arm/boot.h"
+#include "hw/arm/fdt.h"
 #include "hw/block/flash.h"
 #include "hw/boards.h"
 #include "hw/ide/internal.h"
@@ -40,6 +41,7 @@ 
 #include "hw/qdev-properties.h"
 #include "hw/usb.h"
 #include "hw/char/pl011.h"
+#include "hw/watchdog/wdt_sbsa_gwdt.h"
 #include "net/net.h"
 #include "qom/object.h"
 
@@ -64,6 +66,9 @@  enum {
     SBSA_GIC_DIST,
     SBSA_GIC_REDIST,
     SBSA_SECURE_EC,
+    SBSA_GWDT,
+    SBSA_GWDT_REFRESH,
+    SBSA_GWDT_CONTROL,
     SBSA_SMMU,
     SBSA_UART,
     SBSA_RTC,
@@ -104,6 +109,8 @@  static const MemMapEntry sbsa_ref_memmap[] = {
     [SBSA_GIC_DIST] =           { 0x40060000, 0x00010000 },
     [SBSA_GIC_REDIST] =         { 0x40080000, 0x04000000 },
     [SBSA_SECURE_EC] =          { 0x50000000, 0x00001000 },
+    [SBSA_GWDT_REFRESH] =       { 0x50010000, 0x00001000 },
+    [SBSA_GWDT_CONTROL] =       { 0x50011000, 0x00001000 },
     [SBSA_UART] =               { 0x60000000, 0x00001000 },
     [SBSA_RTC] =                { 0x60010000, 0x00001000 },
     [SBSA_GPIO] =               { 0x60020000, 0x00001000 },
@@ -133,6 +140,8 @@  static const int sbsa_ref_irqmap[] = {
     [SBSA_SECURE_UART_MM] = 9,
     [SBSA_AHCI] = 10,
     [SBSA_EHCI] = 11,
+    [SBSA_SMMU] = 12, /* ... to 15 */
+    [SBSA_GWDT] = 16,
 };
 
 static uint64_t sbsa_ref_cpu_mp_affinity(SBSAMachineState *sms, int idx)
@@ -141,6 +150,30 @@  static uint64_t sbsa_ref_cpu_mp_affinity(SBSAMachineState *sms, int idx)
     return arm_cpu_mp_affinity(idx, clustersz);
 }
 
+static void create_wdt_fdt(SBSAMachineState *sms)
+{
+    char *nodename;
+    const char compat[] = "arm,sbsa-gwdt";
+
+    hwaddr rbase = sbsa_ref_memmap[SBSA_GWDT_REFRESH].base;
+    hwaddr cbase = sbsa_ref_memmap[SBSA_GWDT_CONTROL].base;
+    int irq = sbsa_ref_irqmap[SBSA_GWDT];
+
+    nodename = g_strdup_printf("/watchdog@%" PRIx64, rbase);
+    qemu_fdt_add_subnode(sms->fdt, nodename);
+
+    qemu_fdt_setprop(sms->fdt, nodename, "compatible",
+                             compat, sizeof(compat));
+    qemu_fdt_setprop_sized_cells(sms->fdt, nodename, "reg",
+                                 2, rbase, 2, SBSA_GWDT_RMMIO_SIZE,
+                                 2, cbase, 2, SBSA_GWDT_CMMIO_SIZE);
+    qemu_fdt_setprop_cells(sms->fdt, nodename, "interrupts",
+                                GIC_FDT_IRQ_TYPE_PPI, irq,
+                                GIC_FDT_IRQ_FLAGS_LEVEL_HI);
+    qemu_fdt_setprop_cell(sms->fdt, nodename, "timeout-sec", 30);
+    g_free(nodename);
+}
+
 /*
  * Firmware on this machine only uses ACPI table to load OS, these limited
  * device tree nodes are just to let firmware know the info which varies from
@@ -219,6 +252,7 @@  static void create_fdt(SBSAMachineState *sms)
 
         g_free(nodename);
     }
+    create_wdt_fdt(sms);
 }
 
 #define SBSA_FLASH_SECTOR_SIZE (256 * KiB)
@@ -447,6 +481,20 @@  static void create_rtc(const SBSAMachineState *sms)
     sysbus_create_simple("pl031", base, qdev_get_gpio_in(sms->gic, irq));
 }
 
+static void create_wdt(const SBSAMachineState *sms)
+{
+    hwaddr rbase = sbsa_ref_memmap[SBSA_GWDT_REFRESH].base;
+    hwaddr cbase = sbsa_ref_memmap[SBSA_GWDT_CONTROL].base;
+    DeviceState *dev = qdev_new(TYPE_WDT_SBSA_GWDT);
+    SysBusDevice *s = SYS_BUS_DEVICE(dev);
+    int irq = sbsa_ref_irqmap[SBSA_GWDT];
+
+    sysbus_realize_and_unref(s, &error_fatal);
+    sysbus_mmio_map(s, 0, rbase);
+    sysbus_mmio_map(s, 1, cbase);
+    sysbus_connect_irq(s, 0, qdev_get_gpio_in(sms->gic, irq));
+}
+
 static DeviceState *gpio_key_dev;
 static void sbsa_ref_powerdown_req(Notifier *n, void *opaque)
 {
@@ -730,6 +778,8 @@  static void sbsa_ref_init(MachineState *machine)
 
     create_rtc(sms);
 
+    create_wdt(sms);
+
     create_gpio(sms);
 
     create_ahci(sms);