<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<br>
<br>
<div class="moz-cite-prefix">Le 14/04/2023 à 16:04, Frederic Barrat
a écrit :<br>
</div>
<blockquote type="cite"
cite="mid:9c7ea0ec-ac8c-3854-7412-e42732cd78ed@linux.ibm.com">
<br>
<br>
On 29/04/2022 11:46, Christophe Lombard wrote:
<br>
<blockquote type="cite">This patch parses the "hb_lid_ids" string
from bios tables and complete
<br>
the global list of lid files. Each entry in the list contains
the name,
<br>
the id, the length of the lid file and the virtual address start
access.
<br>
This virtual address is used for for PNOR Resource Provider
operations.
<br>
16 MB of VMM address are reserved space per section.
<br>
<br>
Signed-off-by: Christophe Lombard
<a class="moz-txt-link-rfc2396E" href="mailto:clombard@linux.vnet.ibm.com"><clombard@linux.vnet.ibm.com></a>
<br>
---
<br>
core/pldm/Makefile.inc | 2 +-
<br>
core/pldm/pldm-lid-files.c | 170
+++++++++++++++++++++++++++++++++++++
<br>
include/pldm.h | 7 ++
<br>
3 files changed, 178 insertions(+), 1 deletion(-)
<br>
create mode 100644 core/pldm/pldm-lid-files.c
<br>
<br>
diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc
<br>
index d3affaa0..506bf5d7 100644
<br>
--- a/core/pldm/Makefile.inc
<br>
+++ b/core/pldm/Makefile.inc
<br>
@@ -13,7 +13,7 @@ CFLAGS_$(PLDM_DIR)/pldm-bios-requests.o =
-Wno-strict-prototypes
<br>
PLDM_OBJS = pldm-common.o pldm-responder.o pldm-requester.o
<br>
PLDM_OBJS += pldm-base-requests.o pldm-platform-requests.o
<br>
PLDM_OBJS += pldm-bios-requests.o pldm-fru-requests.o
<br>
-PLDM_OBJS += pldm-file-io-requests.o
<br>
+PLDM_OBJS += pldm-file-io-requests.o pldm-lid-files.o
<br>
PLDM = $(PLDM_DIR)/built-in.a
<br>
$(PLDM): $(PLDM_OBJS:%=$(PLDM_DIR)/%)
<br>
diff --git a/core/pldm/pldm-lid-files.c
b/core/pldm/pldm-lid-files.c
<br>
new file mode 100644
<br>
index 00000000..11e2f9e2
<br>
--- /dev/null
<br>
+++ b/core/pldm/pldm-lid-files.c
<br>
@@ -0,0 +1,170 @@
<br>
+// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
<br>
+// Copyright 2022 IBM Corp.
<br>
+
<br>
+#define pr_fmt(fmt) "PLDM: " fmt
<br>
+
<br>
+#include <endian.h>
<br>
+#include <lock.h>
<br>
+#include <opal-api.h>
<br>
+#include <libflash/errors.h>
<br>
+#include <libflash/ffs.h>
<br>
+#include "pldm.h"
<br>
+
<br>
+/*
<br>
+ * This struct is used to map a PNOR sections.
<br>
+ * The content is deriving from the hb_lid_ids PLDM BIOS
Attribute.
<br>
+ */
<br>
+struct pldm_lid {
<br>
+ struct list_node list;
<br>
+ uint32_t start;
<br>
+ uint32_t handle;
<br>
+ uint32_t length;
<br>
+ char name[PART_NAME_MAX + 1];
<br>
+ char id[PART_NAME_MAX + 1];
<br>
+};
<br>
+
<br>
+static LIST_HEAD(lid_files);
<br>
+
<br>
+#define MEGABYTE (1024*1024)
<br>
+
<br>
+/*
<br>
+ * When using PLDM for PNOR Resource Provider operations,
<br>
+ * reserve 16 MB of VMM address space per section.
<br>
+ * Note that all of this space may not actually be used by each
section.
<br>
+ */
<br>
+#define VMM_SIZE_RESERVED_PER_SECTION (16 * MEGABYTE)
<br>
+
<br>
+/*
<br>
+ * Print the attributes of lid files.
<br>
+ */
<br>
+static void print_lid_files_attr(void)
<br>
+{
<br>
+ struct pldm_lid *lid = NULL;
<br>
+
<br>
+ list_for_each(&lid_files, lid, list)
<br>
+ prlog(PR_NOTICE, "name: %s, id: %s, handle: %d, length:
0x%x, start: 0x%x\n",
<br>
+ lid->name, lid->id, lid->handle,
lid->length, lid->start);
<br>
+
<br>
+}
<br>
+
<br>
+/*
<br>
+ * Return the number of lid files.
<br>
+ */
<br>
+static uint32_t get_lids_count(void)
<br>
+{
<br>
+ struct pldm_lid *lid = NULL;
<br>
+ uint32_t count = 0;
<br>
+
<br>
+ list_for_each(&lid_files, lid, list)
<br>
+ count++;
<br>
+
<br>
+ return count;
<br>
+}
<br>
+
<br>
+/*
<br>
+ * parse the "hb_lid_ids" string
<br>
+ *
<ATTR_a>=<lid_id_1>,<ATTR_b>=<lid_id_2>
<br>
+ */
<br>
+static int parse_hb_lid_ids_string(char *str)
<br>
+{
<br>
+ struct pldm_lid *lid;
<br>
+ const char *pp = "=";
<br>
+ char *attr, *attr_end;
<br>
+ int rc, count = 1;
<br>
+ char *lid_id;
<br>
+
<br>
+ for (char *p = strtok(str, ","); p != NULL; p =
strtok(NULL, ",")) {
<br>
+ lid = zalloc(sizeof(struct pldm_lid));
<br>
+ if (!lid) {
<br>
+ prlog(PR_ERR, "Error allocating pldm_lid
structure\n");
<br>
+ rc = OPAL_RESOURCE;
<br>
+ goto err;
<br>
+ }
<br>
+
<br>
+ /* parse the string <attr>=<lid_id> */
<br>
+ attr = p;
<br>
+ while (*pp != *p)
<br>
+ p++;
<br>
</blockquote>
<br>
<br>
Same comment as in a previous patch: we should protect ourselves
against malformed expressions in case the string doesn't have a
"=" in it.
<br>
</blockquote>
<br>
<span class="HwtZe" lang="en"><span class="jCAhz ChMk0b"><span
class="ryNqvb">Normally it should never, but you never know.
Thanks.<br>
<br>
</span></span></span>
<blockquote type="cite"
cite="mid:9c7ea0ec-ac8c-3854-7412-e42732cd78ed@linux.ibm.com">
<br>
<br>
<blockquote type="cite">+
<br>
+ attr_end = p;
<br>
+ lid_id = ++p;
<br>
+ *attr_end = '\0';
<br>
+
<br>
+ strcpy(lid->name, attr);
<br>
+ strcpy(lid->id, lid_id);
<br>
+
<br>
+ /* reserve 16 MB of VMM address space per section */
<br>
+ lid->start = VMM_SIZE_RESERVED_PER_SECTION * count;
<br>
</blockquote>
<br>
<br>
I was wondering by we start with count = 1, i.e the very first
section address it not 0. I found the answer in the next patch (I
think :) ), as we want to emulate a flash rom and we reserve
address 0 for the header. A comment could be useful.
<br>
<br>
<br>
<blockquote type="cite">+
<br>
+ /* handle and length */
<br>
+ rc = pldm_find_file_handle_by_lid_id(lid->id,
<br>
+ &lid->handle,
<br>
+ &lid->length);
<br>
+ if ((rc) && (rc != OPAL_PARAMETER))
<br>
+ goto err;
<br>
</blockquote>
<br>
<br>
This is where I think it would make sense to check and err out if
the lid length is bigger than the VMM_SIZE_RESERVED_PER_SECTION
space we reserve.
<br>
</blockquote>
<br>
Correct.<br>
<br>
<blockquote type="cite"
cite="mid:9c7ea0ec-ac8c-3854-7412-e42732cd78ed@linux.ibm.com">
<br>
<br>
<blockquote type="cite">+
<br>
+ /* add new member in the global list */
<br>
+ list_add_tail(&lid_files, &lid->list);
<br>
+
<br>
+ count++;
<br>
+ }
<br>
+
<br>
+ return OPAL_SUCCESS;
<br>
+
<br>
+err:
<br>
+ /* free all lid entries */
<br>
+ list_for_each(&lid_files, lid, list)
<br>
+ free(lid);
<br>
+
<br>
+ return rc;
<br>
+}
<br>
+
<br>
+/*
<br>
+ * Parse the "hb_lid_ids" string from bios tables and complete
<br>
+ * the global list of lid files.
<br>
+ */
<br>
+static int lid_ids_to_vaddr_mapping(void)
<br>
+{
<br>
+ char *lid_ids_string;
<br>
</blockquote>
<br>
<br>
lid_ids_string must be initialized to NULL because of "goto out"
<br>
</blockquote>
<br>
Correct. Thanks.<br>
<br>
<blockquote type="cite"
cite="mid:9c7ea0ec-ac8c-3854-7412-e42732cd78ed@linux.ibm.com">
<br>
Fred
<br>
<br>
</blockquote>
<br>
</body>
</html>