diff mbox series

[4/5] hw/arm/boot: Expose the pmem nodes in the DT

Message ID 20191004155302.4632-5-shameerali.kolothum.thodi@huawei.com
State New
Headers show
Series ARM virt: Add NVDIMM support | expand

Commit Message

Shameerali Kolothum Thodi Oct. 4, 2019, 3:53 p.m. UTC
From: Eric Auger <eric.auger@redhat.com>


In case of NV-DIMM slots, let's add /pmem DT nodes.

Signed-off-by: Eric Auger <eric.auger@redhat.com>

Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>

---
 hw/arm/boot.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

-- 
2.17.1

Comments

Igor Mammedov Nov. 11, 2019, 2:46 p.m. UTC | #1
On Fri, 4 Oct 2019 16:53:01 +0100
Shameer Kolothum <shameerali.kolothum.thodi@huawei.com> wrote:

> From: Eric Auger <eric.auger@redhat.com>

> 

> In case of NV-DIMM slots, let's add /pmem DT nodes

Why should we do it for NVDIMM but not for PC-DIMM?

> 

> Signed-off-by: Eric Auger <eric.auger@redhat.com>

> Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>

> ---

>  hw/arm/boot.c | 45 +++++++++++++++++++++++++++++++++++++++++++++

>  1 file changed, 45 insertions(+)

> 

> diff --git a/hw/arm/boot.c b/hw/arm/boot.c

> index c264864c11..bd6d72b33e 100644

> --- a/hw/arm/boot.c

> +++ b/hw/arm/boot.c

> @@ -20,6 +20,7 @@

>  #include "hw/boards.h"

>  #include "sysemu/reset.h"

>  #include "hw/loader.h"

> +#include "hw/mem/memory-device.h"

>  #include "elf.h"

>  #include "sysemu/device_tree.h"

>  #include "qemu/config-file.h"

> @@ -523,6 +524,44 @@ static void fdt_add_psci_node(void *fdt)

>      qemu_fdt_setprop_cell(fdt, "/psci", "migrate", migrate_fn);

>  }

>  

> +static int fdt_add_pmem_node(void *fdt, uint32_t acells, uint32_t scells)

> +{

> +    MemoryDeviceInfoList *info, *info_list = qmp_memory_device_list();

> +    MemoryDeviceInfo *mi;

> +    int ret;

> +

> +    for (info = info_list; info != NULL; info = info->next) {

> +        mi = info->value;

> +

> +        if (mi->type == MEMORY_DEVICE_INFO_KIND_NVDIMM) {

> +            PCDIMMDeviceInfo *di = mi->u.nvdimm.data;

> +            char *nodename;

> +

> +            nodename = g_strdup_printf("/pmem@%" PRIx64, di->addr);

> +            qemu_fdt_add_subnode(fdt, nodename);

> +            qemu_fdt_setprop_string(fdt, nodename, "compatible", "pmem-region");

> +            ret = qemu_fdt_setprop_sized_cells(fdt, nodename, "reg", acells,

> +                                               di->addr, scells, di->size);

> +            /* only set the NUMA ID if it is specified */

> +            if (!ret && di->node >= 0) {

> +                ret = qemu_fdt_setprop_cell(fdt, nodename, "numa-node-id",

> +                                            di->node);

> +            }

> +

> +            g_free(nodename);

> +

> +            if (ret < 0) {

> +                fprintf(stderr, "couldn't add NVDIMM /memory@%"PRIx64" node\n",

shouldn't it be s:/memory:/pmem:

and maybe move error printing outside like it's done in fdt_add_memory_node()
to be consistent with current code.

> +                        di->addr);

> +                goto out;

> +            }

> +        }

> +    }

> +out:

> +    qapi_free_MemoryDeviceInfoList(info_list);

> +    return ret;

> +}

> +

>  int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo,

>                   hwaddr addr_limit, AddressSpace *as, MachineState *ms)

>  {

> @@ -622,6 +661,12 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo,

>          }

>      }

>  

> +    rc = fdt_add_pmem_node(fdt, acells, scells);

> +    if (rc < 0) {

> +        fprintf(stderr, "couldn't add pmem memory nodes\n");

> +        goto fail;

> +    }

> +

>      rc = fdt_path_offset(fdt, "/chosen");

>      if (rc < 0) {

>          qemu_fdt_add_subnode(fdt, "/chosen");
diff mbox series

Patch

diff --git a/hw/arm/boot.c b/hw/arm/boot.c
index c264864c11..bd6d72b33e 100644
--- a/hw/arm/boot.c
+++ b/hw/arm/boot.c
@@ -20,6 +20,7 @@ 
 #include "hw/boards.h"
 #include "sysemu/reset.h"
 #include "hw/loader.h"
+#include "hw/mem/memory-device.h"
 #include "elf.h"
 #include "sysemu/device_tree.h"
 #include "qemu/config-file.h"
@@ -523,6 +524,44 @@  static void fdt_add_psci_node(void *fdt)
     qemu_fdt_setprop_cell(fdt, "/psci", "migrate", migrate_fn);
 }
 
+static int fdt_add_pmem_node(void *fdt, uint32_t acells, uint32_t scells)
+{
+    MemoryDeviceInfoList *info, *info_list = qmp_memory_device_list();
+    MemoryDeviceInfo *mi;
+    int ret;
+
+    for (info = info_list; info != NULL; info = info->next) {
+        mi = info->value;
+
+        if (mi->type == MEMORY_DEVICE_INFO_KIND_NVDIMM) {
+            PCDIMMDeviceInfo *di = mi->u.nvdimm.data;
+            char *nodename;
+
+            nodename = g_strdup_printf("/pmem@%" PRIx64, di->addr);
+            qemu_fdt_add_subnode(fdt, nodename);
+            qemu_fdt_setprop_string(fdt, nodename, "compatible", "pmem-region");
+            ret = qemu_fdt_setprop_sized_cells(fdt, nodename, "reg", acells,
+                                               di->addr, scells, di->size);
+            /* only set the NUMA ID if it is specified */
+            if (!ret && di->node >= 0) {
+                ret = qemu_fdt_setprop_cell(fdt, nodename, "numa-node-id",
+                                            di->node);
+            }
+
+            g_free(nodename);
+
+            if (ret < 0) {
+                fprintf(stderr, "couldn't add NVDIMM /memory@%"PRIx64" node\n",
+                        di->addr);
+                goto out;
+            }
+        }
+    }
+out:
+    qapi_free_MemoryDeviceInfoList(info_list);
+    return ret;
+}
+
 int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
                  hwaddr addr_limit, AddressSpace *as, MachineState *ms)
 {
@@ -622,6 +661,12 @@  int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
         }
     }
 
+    rc = fdt_add_pmem_node(fdt, acells, scells);
+    if (rc < 0) {
+        fprintf(stderr, "couldn't add pmem memory nodes\n");
+        goto fail;
+    }
+
     rc = fdt_path_offset(fdt, "/chosen");
     if (rc < 0) {
         qemu_fdt_add_subnode(fdt, "/chosen");