diff mbox

[09/11] hdat: Parse hostboot memory reservations from HDAT

Message ID 1475064333-22504-10-git-send-email-hegdevasant@linux.vnet.ibm.com
State Superseded
Headers show

Commit Message

Vasant Hegde Sept. 28, 2016, 12:05 p.m. UTC
Hostboot reserves some memory and passes via HDAT. This patch
adds code to parse node reservation details and marks it as
REGION_HW_RESERVED. Later mem_region_add_dt_reserved() populates
DT entry.

Signed-off-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
---
 hdata/memory.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

Comments

Oliver O'Halloran Sept. 29, 2016, 2:28 a.m. UTC | #1
On Wed, Sep 28, 2016 at 10:05 PM, Vasant Hegde
<hegdevasant@linux.vnet.ibm.com> wrote:
> Hostboot reserves some memory and passes via HDAT. This patch
> adds code to parse node reservation details and marks it as
> REGION_HW_RESERVED. Later mem_region_add_dt_reserved() populates
> DT entry.
>
> Signed-off-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
> ---
>  hdata/memory.c | 31 +++++++++++++++++++++++++++++++
>  1 file changed, 31 insertions(+)
>
> diff --git a/hdata/memory.c b/hdata/memory.c
> index a8b9955..bb776fd 100644
> --- a/hdata/memory.c
> +++ b/hdata/memory.c
> @@ -19,6 +19,7 @@
>  #include <vpd.h>
>  #include <ccan/str/str.h>
>  #include <libfdt/libfdt.h>
> +#include <mem_region.h>
>  #include <types.h>
>
>  #include "spira.h"
> @@ -383,6 +384,34 @@ static void get_msareas(struct dt_node *root,
>         }
>  }
>
> +static void get_hb_reserved_mem(struct HDIF_common_hdr *ms_vpd)
> +{
> +       int count, i;
> +       const struct msvpd_hb_reserved_mem *hb_resv_mem;
> +
> +       if (proc_gen < proc_gen_p9)
> +               return;
> +
> +       count = HDIF_get_iarray_size(ms_vpd, MSVPD_IDATA_HB_RESERVED_MEM);
> +       if (count <= 0) {
> +               prerror("MS VPD: No hostboot reserved memory found\n");
> +               return;
> +       }
> +
> +       for (i = 0; i < count; i++) {
> +               hb_resv_mem = HDIF_get_iarray_item(ms_vpd,
> +                                                  MSVPD_IDATA_HB_RESERVED_MEM,
> +                                                  i, NULL);
> +               if (!CHECK_SPPTR(hb_resv_mem))
> +                       continue;
> +
> +#if !defined(TEST)
> +               mem_reserve_hw(hb_resv_mem->label, hb_resv_mem->start_addr,

I'm not sure it's safe to use hb_res_mem->label directly as a string.
The spec doesn't say it needs to be NUL terminated and expects you to
parse it based on the length field.

> +                              (hb_resv_mem->end_addr - hb_resv_mem->start_addr));

Most of the existing parsing code uses be*_to_cpu() rather than
reading the values directly. That said I don't think we have any plans
to make skiboot run little endian so I'm not sure I care...

> +#endif
> +       }
> +}
> +
>  static bool __memory_parse(struct dt_node *root)
>  {
>         struct HDIF_common_hdr *ms_vpd;
> @@ -431,6 +460,8 @@ static bool __memory_parse(struct dt_node *root)
>
>         get_msareas(root, ms_vpd);
>
> +       get_hb_reserved_mem(ms_vpd);
> +
>         prlog(PR_INFO, "MS VPD: Total MB of RAM: 0x%llx\n",
>                (long long)be64_to_cpu(tcms->total_in_mb));
>
> --
> 2.5.5
>
> _______________________________________________
> Skiboot mailing list
> Skiboot@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/skiboot
Vasant Hegde Sept. 29, 2016, 5:27 a.m. UTC | #2
On 09/29/2016 07:58 AM, Oliver O'Halloran wrote:
> On Wed, Sep 28, 2016 at 10:05 PM, Vasant Hegde
> <hegdevasant@linux.vnet.ibm.com> wrote:


.../...

>> +
>> +#if !defined(TEST)
>> +               mem_reserve_hw(hb_resv_mem->label, hb_resv_mem->start_addr,
>
> I'm not sure it's safe to use hb_res_mem->label directly as a string.
> The spec doesn't say it needs to be NUL terminated and expects you to
> parse it based on the length field.

Ah! I assumed it will terminate with NULL :-) I agree that its not safe to 
assume specially on someone else is passing data :-) Will fix in V2.



>
>> +                              (hb_resv_mem->end_addr - hb_resv_mem->start_addr));
>
> Most of the existing parsing code uses be*_to_cpu() rather than
> reading the values directly. That said I don't think we have any plans
> to make skiboot run little endian so I'm not sure I care...

Its always BE. So many a time we forget to use converters .. But its good to use.
will fix in v2.

-Vasant
diff mbox

Patch

diff --git a/hdata/memory.c b/hdata/memory.c
index a8b9955..bb776fd 100644
--- a/hdata/memory.c
+++ b/hdata/memory.c
@@ -19,6 +19,7 @@ 
 #include <vpd.h>
 #include <ccan/str/str.h>
 #include <libfdt/libfdt.h>
+#include <mem_region.h>
 #include <types.h>
 
 #include "spira.h"
@@ -383,6 +384,34 @@  static void get_msareas(struct dt_node *root,
 	}
 }
 
+static void get_hb_reserved_mem(struct HDIF_common_hdr *ms_vpd)
+{
+	int count, i;
+	const struct msvpd_hb_reserved_mem *hb_resv_mem;
+
+	if (proc_gen < proc_gen_p9)
+		return;
+
+	count = HDIF_get_iarray_size(ms_vpd, MSVPD_IDATA_HB_RESERVED_MEM);
+	if (count <= 0) {
+		prerror("MS VPD: No hostboot reserved memory found\n");
+		return;
+	}
+
+	for (i = 0; i < count; i++) {
+		hb_resv_mem = HDIF_get_iarray_item(ms_vpd,
+						   MSVPD_IDATA_HB_RESERVED_MEM,
+						   i, NULL);
+		if (!CHECK_SPPTR(hb_resv_mem))
+			continue;
+
+#if !defined(TEST)
+		mem_reserve_hw(hb_resv_mem->label, hb_resv_mem->start_addr,
+			       (hb_resv_mem->end_addr - hb_resv_mem->start_addr));
+#endif
+	}
+}
+
 static bool __memory_parse(struct dt_node *root)
 {
 	struct HDIF_common_hdr *ms_vpd;
@@ -431,6 +460,8 @@  static bool __memory_parse(struct dt_node *root)
 
 	get_msareas(root, ms_vpd);
 
+	get_hb_reserved_mem(ms_vpd);
+
 	prlog(PR_INFO, "MS VPD: Total MB of RAM: 0x%llx\n",
 	       (long long)be64_to_cpu(tcms->total_in_mb));