From patchwork Fri Mar 4 14:30:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1601116 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=EIEcHCAF; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4K99JG54ggz9sG7 for ; Sat, 5 Mar 2022 01:30:54 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4K99JF4lqZz30JX for ; Sat, 5 Mar 2022 01:30:53 +1100 (AEDT) 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=EIEcHCAF; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.vnet.ibm.com; receiver=) 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=EIEcHCAF; dkim-atps=neutral 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 4K99J85y47z30Dv for ; Sat, 5 Mar 2022 01:30:48 +1100 (AEDT) Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 224CeTs7014892 for ; Fri, 4 Mar 2022 14:30:46 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=zjUgq+V4NogVuSfn/buufO1HGFP3oKr0llz+4U8Fjpw=; b=EIEcHCAFw92oDmLkKuak/KeCcZdt/rClcciz0j0v8krJwzhILRO7BJ+AtryoYSX1tnm3 R+q1tBrgmuDQ743JlWVcYRl4HPI+PVqZijlX1wO0d75Pz++Io9OdaCGYJ/km1NyLF9k4 dKF6rGTZYuvw2tyKQGGkfCC+aeavmXs1K3LUvCGbXaBSsBP8QEpndmjWF5hqSqq5DqA8 8ZoPtgz72bLprBF4dAbnnEQJlOxtVUpTrcRwEvo3IksxsIHCZHntLzSKhsg/uarDUz/B fJI27Nbio80eOOR2Khyt9fW3ivMEbqN4jfT+w5EOEf5T4XDeH/217Aji41KQ5ovdDifT MA== Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 3ekdcq8hwj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 04 Mar 2022 14:30:46 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 224EJJHG007688 for ; Fri, 4 Mar 2022 14:30:44 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma03ams.nl.ibm.com with ESMTP id 3ek4k41y36-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 04 Mar 2022 14:30:44 +0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 224EUgad58589618 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 4 Mar 2022 14:30:42 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4B2054203F for ; Fri, 4 Mar 2022 14:30:42 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0FBA742041 for ; Fri, 4 Mar 2022 14:30:42 +0000 (GMT) Received: from li-ed209401-43e8-11cb-8043-c0c0b85d70f7.ibm.com.com (unknown [9.171.29.80]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Fri, 4 Mar 2022 14:30:41 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Fri, 4 Mar 2022 15:30:40 +0100 Message-Id: <20220304143041.76128-2-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220304143041.76128-1-clombard@linux.vnet.ibm.com> References: <20220304143041.76128-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: czYaFINOzvV3yXHopQwYDe2ky4GUXlG3 X-Proofpoint-GUID: czYaFINOzvV3yXHopQwYDe2ky4GUXlG3 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-03-04_06,2022-03-04_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 adultscore=0 impostorscore=0 bulkscore=0 mlxlogscore=999 spamscore=0 lowpriorityscore=0 priorityscore=1501 suspectscore=0 malwarescore=0 phishscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203040077 Subject: [Skiboot] [PATCH 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 | 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 +#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[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 + * =,= + */ +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 = 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 + /** * 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 */