From patchwork Tue Jun 20 15:00:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1797411 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=UuEoNjB4; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QlqgP4BkNz20Wk for ; Wed, 21 Jun 2023 01:05:05 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=UuEoNjB4; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QlqgP33zSz3cmW for ; Wed, 21 Jun 2023 01:05:05 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=UuEoNjB4; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QlqbM4NvKz3c60 for ; Wed, 21 Jun 2023 01:01:35 +1000 (AEST) Received: from pps.filterd (m0353726.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35KEnr5x030025 for ; Tue, 20 Jun 2023 15:01:33 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=4hh7jrPJFyalPz6EsJ7CeCg37k3wmiIqGFfYGYwIyNI=; b=UuEoNjB4KWHuNnpSxeYvUvZ2at7ISmFHP+25DDxnquiv7P3oK/ySdHdrejzI0QQSv8C4 mZTeZN39epdAvZNJi7yvBIkiFFVWJSBcOMGNFR8Vvf3dKczisur9QYzvjJEHGten4yPU o6nehbT681Ust+HXnWK3/X7x1BB9SuURyI8OV7IhmOWdHONZuvew7yGCYtVZSGvri3Pw LAnD1jOsakWXFa/I8AhJYLGTatwjKuuPL4PBg7qb0UWKQfXl52p+hsUY13UnQNmEvDzo 6SSd8aT7DM5DjIGlyNU0tVZKOPsMgZ3iFEbD3qHbjpfr3kPz9uA4TCCLJ200m5d1qvV6 fw== Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rbe7bg91v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:01:26 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35K2dV6c006831 for ; Tue, 20 Jun 2023 15:00:47 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma03ams.nl.ibm.com (PPS) with ESMTPS id 3r94f524rh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:46 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35KF0iRw63111528 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 20 Jun 2023 15:00:44 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6C58F20043 for ; Tue, 20 Jun 2023 15:00:44 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4E06C20063 for ; Tue, 20 Jun 2023 15:00:44 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.biot.fr.ibm.com (unknown [9.144.62.191]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 20 Jun 2023 15:00:44 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 20 Jun 2023 17:00:42 +0200 Message-ID: <20230620150043.88727-2-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620150043.88727-1-clombard@linux.ibm.com> References: <20230620150043.88727-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: ofJHFiXz6dQ_y3wRtjQEXOvJJ_pOfyNd X-Proofpoint-ORIG-GUID: ofJHFiXz6dQ_y3wRtjQEXOvJJ_pOfyNd X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-20_10,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 suspectscore=0 bulkscore=0 mlxscore=0 spamscore=0 lowpriorityscore=0 mlxlogscore=999 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306200135 Subject: [Skiboot] [PATCH V4 1/2] core/pldm: Lid ids string parsing X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" 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 --- core/pldm/Makefile.inc | 2 +- core/pldm/pldm-lid-files.c | 186 +++++++++++++++++++++++++++++++++++++ include/pldm.h | 7 ++ 3 files changed, 194 insertions(+), 1 deletion(-) create mode 100644 core/pldm/pldm-lid-files.c diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc index d89e4c2f..87952dbf 100644 --- a/core/pldm/Makefile.inc +++ b/core/pldm/Makefile.inc @@ -10,7 +10,7 @@ CPPFLAGS += -I$(SRC)/pldm/include/libpldm/oem/ibm/ PLDM_OBJS = pldm-mctp.o pldm-responder.o pldm-requester.o PLDM_OBJS += pldm-base-requests.o pldm-platform-requests.o PLDM_OBJS += pldm-bios-requests.o pldm-fru-requests.o -PLDM_OBJS += pldm-file-io-requests.o +PLDM_OBJS += pldm-file-io-requests.o 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..a46a7316 --- /dev/null +++ b/core/pldm/pldm-lid-files.c @@ -0,0 +1,186 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later +// Copyright 2022 IBM Corp. + +#define pr_fmt(fmt) "PLDM: " fmt + +#include +#include +#include +#include +#include +#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[FFS_PART_NAME_MAX + 1]; + char id[FFS_PART_NAME_MAX + 1]; +}; + +static LIST_HEAD(lid_files); + +#define MEGABYTE (1024*1024) + +/* + * When using PLDM for PNOR Resource Provider operations, + * reserve 32 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 (32 * 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 + * =,= + */ +static int parse_hb_lid_ids_string(char *str) +{ + struct pldm_lid *lid, *tmp; + 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_NO_MEM; + goto err; + } + + /* parse the string = */ + attr = p; + while ((*pp != *p) && (*p != '\0')) + p++; + + attr_end = p; + lid_id = ++p; + *attr_end = '\0'; + + strcpy(lid->name, attr); + strcpy(lid->id, lid_id); + + /* reserve 32 MB of VMM address space per section. + * Address 0x0 -> 0x2000000: 'fake' header flash + * Address 0x2000000 -> 0x4000000: lid id 1 + * Address 0x4000000 -> 0x6000000: lid id 2 + * .... + */ + 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); + /* OPAL_PARAMETER means that lid_id is present in hb_lid_ids, + * but we don't have any file attribute information in the + * file table, so continue on the next item. + */ + if ((rc) && (rc != OPAL_PARAMETER)) + goto err; + + if (lid->length > VMM_SIZE_RESERVED_PER_SECTION) { + prlog(PR_ERR, "file length (0x%x) > virtual size reserved per " + "section (0x%x)\n", + lid->length, VMM_SIZE_RESERVED_PER_SECTION); + rc = OPAL_RESOURCE; + 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_safe(&lid_files, lid, tmp, 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 = NULL; + 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 3c23dc97..9c5369ed 100644 --- a/include/pldm.h +++ b/include/pldm.h @@ -5,6 +5,8 @@ #ifndef __PLDM_H__ #define __PLDM_H__ +#include + /** * Handle PLDM messages received from MCTP */ @@ -36,4 +38,9 @@ int pldm_platform_restart(void); */ int pldm_fru_dt_add_bmc_version(void); +/** + * Convert lid ids data to pnor structure + */ +int pldm_lid_files_init(struct blocklevel_device **bl); + #endif /* __PLDM_H__ */