[Skiboot] [PATCH 1/2] core/pldm: Lid ids string parsing
Christophe Lombard
clombard at linux.vnet.ibm.com
Sat Mar 5 01:30:40 AEDT 2022
This patch parses the "hb_lid_ids" string from bios tables and complete
the global list of lid files. Each entry in the list contains the name,
the id, the length of the lid file and the virtual address start access.
This virtual address is used for for PNOR Resource Provider operations.
16 MB of VMM address are reserved space per section.
Signed-off-by: Christophe Lombard <clombard at linux.vnet.ibm.com>
---
core/pldm/Makefile.inc | 1 +
core/pldm/pldm-lid-files.c | 171 +++++++++++++++++++++++++++++++++++++
include/pldm.h | 7 ++
3 files changed, 179 insertions(+)
create mode 100644 core/pldm/pldm-lid-files.c
diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc
index 06a784ea..258838ac 100644
--- a/core/pldm/Makefile.inc
+++ b/core/pldm/Makefile.inc
@@ -13,6 +13,7 @@ CFLAGS_$(PLDM_DIR)/pldm-bios-requests.o = -Wno-strict-prototypes
PLDM_OBJS = pldm-common.o pldm-responder.o pldm-requester.o
PLDM_OBJS += pldm-platform-requests.o pldm-bios-requests.o
PLDM_OBJS += pldm-fru-requests.o pldm-file-io-requests.o
+PLDM_OBJS += pldm-lid-files.o
PLDM = $(PLDM_DIR)/built-in.a
$(PLDM): $(PLDM_OBJS:%=$(PLDM_DIR)/%)
diff --git a/core/pldm/pldm-lid-files.c b/core/pldm/pldm-lid-files.c
new file mode 100644
index 00000000..bdadb2bf
--- /dev/null
+++ b/core/pldm/pldm-lid-files.c
@@ -0,0 +1,171 @@
+// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+// Copyright 2022 IBM Corp.
+
+#define pr_fmt(fmt) "PLDM: " fmt
+
+#include <endian.h>
+#include <lock.h>
+#include <opal-api.h>
+#include <libflash/errors.h>
+#include <libflash/ffs.h>
+#include "pldm.h"
+
+/*
+ * This struct is used to map a PNOR sections.
+ * The content is deriving from the hb_lid_ids PLDM BIOS Attribute.
+ */
+struct pldm_lid {
+ struct list_node list;
+ uint32_t start;
+ uint32_t handle;
+ uint32_t length;
+ char name[PART_NAME_MAX + 1];
+ char id[PART_NAME_MAX + 1];
+};
+
+static LIST_HEAD(lid_files);
+
+#define MEGABYTE 1024*1024
+
+/*
+ * When using PLDM for PNOR Resource Provider operations,
+ * reserve 16 MB of VMM address space per section.
+ * Note that all of this space may not actually be used by each section.
+ */
+#define VMM_SIZE_RESERVED_PER_SECTION (16 * MEGABYTE)
+
+/*
+ * Print the attributes of lid files.
+ */
+static void print_lid_files_attr(void)
+{
+ struct pldm_lid *lid = NULL;
+
+ list_for_each(&lid_files, lid, list)
+ prlog(PR_NOTICE, "name: %s, id: %s, handle: %d, length: 0x%x, start: 0x%x\n",
+ lid->name, lid->id, lid->handle, lid->length, lid->start);
+
+}
+
+/*
+ * Return the number of lid files.
+ */
+static uint32_t get_lids_count(void)
+{
+ struct pldm_lid *lid = NULL;
+ uint32_t count = 0;
+
+ list_for_each(&lid_files, lid, list)
+ count++;
+
+ return count;
+}
+
+/*
+ * parse the "hb_lid_ids" string
+ * <ATTR_a>=<lid_id_1>,<ATTR_b>=<lid_id_2>
+ */
+static int parse_hb_lid_ids_string(char *str)
+{
+ struct pldm_lid *lid;
+ const char *pp = "=";
+ char *attr, *attr_end;
+ int rc, count = 1;
+ char *lid_id;
+
+ for (char *p = strtok(str,","); p != NULL; p = strtok(NULL, ","))
+ {
+ lid = zalloc(sizeof(struct pldm_lid));
+ if (!lid) {
+ prlog(PR_ERR, "Error allocating pldm_lid structure\n");
+ rc = OPAL_RESOURCE;
+ goto err;
+ }
+
+ /* parse the string <attr>=<lid_id> */
+ attr = p;
+ while (*pp != *p)
+ p++;
+
+ attr_end = p;
+ lid_id = ++p;
+ *attr_end = '\0';
+
+ strcpy(lid->name, attr);
+ strcpy(lid->id, lid_id);
+
+ /* reserve 16 MB of VMM address space per section */
+ lid->start = VMM_SIZE_RESERVED_PER_SECTION * count;
+
+ /* handle and length */
+ rc = pldm_find_file_handle_by_lid_id(lid->id,
+ &lid->handle,
+ &lid->length);
+ if ((rc) && (rc != OPAL_PARAMETER))
+ goto err;
+
+ /* add new member in the global list */
+ list_add_tail(&lid_files, &lid->list);
+
+ count++;
+ }
+
+ return OPAL_SUCCESS;
+
+err:
+ /* free all lid entries */
+ list_for_each(&lid_files, lid, list)
+ free(lid);
+
+ return rc;
+}
+
+/*
+ * Parse the "hb_lid_ids" string from bios tables and complete
+ * the global list of lid files.
+ */
+static int lid_ids_to_vaddr_mapping(void)
+{
+ char *lid_ids_string;
+ int rc;
+
+ /* get lid ids string from bios tables */
+ rc = pldm_bios_get_lids_id(&lid_ids_string);
+ if (rc)
+ goto out;
+
+ /* parse the "hb_lid_ids" string */
+ rc = parse_hb_lid_ids_string(lid_ids_string);
+
+out:
+ if (lid_ids_string)
+ free(lid_ids_string);
+
+ return rc;
+}
+
+int pldm_lid_files_init(struct blocklevel_device **bl)
+{
+ uint32_t lid_files_count;
+ int rc;
+
+ if (!bl)
+ return FLASH_ERR_PARM_ERROR;
+
+ *bl = NULL;
+
+ /* convert lid ids data to pnor structure */
+ rc = lid_ids_to_vaddr_mapping();
+ if (rc)
+ goto err;
+
+ lid_files_count = get_lids_count();
+
+ prlog(PR_NOTICE, "Number of lid files: %d\n", lid_files_count);
+ print_lid_files_attr();
+
+ return OPAL_SUCCESS;
+
+err:
+ return rc;
+}
diff --git a/include/pldm.h b/include/pldm.h
index aa7ea9c4..568f7cf2 100644
--- a/include/pldm.h
+++ b/include/pldm.h
@@ -5,11 +5,18 @@
#ifndef __PLDM_H__
#define __PLDM_H__
+#include <skiboot.h>
+
/**
* PLDM over MCTP initialization
*/
int pldm_mctp_init(void);
+/**
+ * Enable PLDM over MCTP
+ */
+int pldm_lid_files_init(struct blocklevel_device **bl);
+
/**
* Send a system chassis Off-Soft Graceful request
*/
--
2.35.1
More information about the Skiboot
mailing list