From patchwork Tue Aug 29 09:23:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1827181 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=SlgiOur4; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RZhsK11xcz1yZs for ; Tue, 29 Aug 2023 19:27:17 +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=SlgiOur4; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4RZhsJ73sFz3c26 for ; Tue, 29 Aug 2023 19:27:16 +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=SlgiOur4; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 4RZhnX61Qdz3bTt for ; Tue, 29 Aug 2023 19:24:00 +1000 (AEST) Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37T9AVaQ004910 for ; Tue, 29 Aug 2023 09:23:58 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=IVKxIUS2a5K81qLOBeFTPGzPBu/m6JMNgsnZqUTqJj8=; b=SlgiOur4KxXwF2qzHyMsewSk2xEwyAqoLu+Z92QAapf/bwXwh6CAF7W0NnK52giGhSSg XNQegnUQgBm94KsFsGOu4ox3jbIjLusgh5XIbDJuA4VTrdPbMDilWEXg521GsqHAy+R2 mYTc1rU2+UMUdDywp6EdkQn57dwzYiRMrLDzY3Bg4ZXpjMJYNdz0vKl3L4CDhTFAIGsk Rui85PvabqnaJhzbWdr7uiFW70J3oRHq259+wSABxhpe0EExZ50IgD9q7Z+GbkqyTBep RN0Nvxc4bLxJqXS8WrhlkzZumdix3LrwwGAYloZ9w2AwU6UlaSA9Mj/WCWj8gRnbDePi 9w== Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3sr9j35wuj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:23:58 +0000 Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 37T96FdY004891 for ; Tue, 29 Aug 2023 09:23:57 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3squqsjk6f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:23:57 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 37T9Nt7Z13304388 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 29 Aug 2023 09:23:56 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CD9DE2004D for ; Tue, 29 Aug 2023 09:23:55 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8F8B020040 for ; Tue, 29 Aug 2023 09:23:55 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.171.88.232]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 29 Aug 2023 09:23:55 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 29 Aug 2023 11:23:53 +0200 Message-ID: <20230829092354.75836-2-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230829092354.75836-1-clombard@linux.ibm.com> References: <20230829092354.75836-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: MvUHvAZqibPyHz91WJq_-mXu77PknM8c X-Proofpoint-ORIG-GUID: MvUHvAZqibPyHz91WJq_-mXu77PknM8c X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_06,2023-08-28_04,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 bulkscore=0 malwarescore=0 adultscore=0 suspectscore=0 mlxlogscore=999 lowpriorityscore=0 mlxscore=0 spamscore=0 clxscore=1015 phishscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290078 Subject: [Skiboot] [PATCH V5 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 d89e4c2fc..87952dbfe 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 000000000..a46a73164 --- /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 3c23dc97a..9c5369edb 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__ */