From patchwork Fri Jun 7 18:52:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 802342 Delivered-To: patch@linaro.org Received: by 2002:adf:f147:0:b0:35b:5a80:51b4 with SMTP id y7csp950219wro; Fri, 7 Jun 2024 11:59:04 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVYPAD+XvXgR+S36bbKStg8g+CjFnvA51+3MHt+3ng3vIKmQ4LlLMBrHf2IWT2SXED4nT35foCNeR9j8QVxsDob X-Google-Smtp-Source: AGHT+IFBEU8NyIs6xr7DuwSJsKtUvfwlwLxooXNHtdoxHayOF3Mcxsl+P+nmg3XnZ/NbLJG7pU7j X-Received: by 2002:a50:999d:0:b0:57c:6ae2:abda with SMTP id 4fb4d7f45d1cf-57c6ae2ac5emr69768a12.5.1717786743950; Fri, 07 Jun 2024 11:59:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717786743; cv=none; d=google.com; s=arc-20160816; b=HDoyI2vR7pFjPnMKlGtqbVELXA/58PHkFQVQpxatsg9K8StHtHx5eEijL995iUIYde aWpkZYqw1Wq9MJ+3uhfHy/eYRGyTkAf698910qnaUQ1ytFuoEmp6EXza5OAlvcAgSQrN gENjftEgbvivTift/AXUZF9r95cE8XIWMomsZBUfnk+HpMmIRGpaXnaC2ZWJHpHPULMx CpgkOnCN0qpoQTppaeITNIBSMPb+lLPzSWmOZ+ibJK6gdtp/hWJlRcYG7m4ywEChLaHH TxZBec/Px4Qel8/exVsagq9yu5tyWpalL/gdR6OdYcCfcoqf3ofVGFZ8I60ivmJoMBUW mv3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=eiKfm5G0q66VZM6AgGNmyDnGiua2dRHR7ePPYao+36I=; fh=xLSOOz5Q0Mrmzd+lwBRTYS7D/8TpUWM8TEHgIjpMzow=; b=v11jzbuSW1UXTtBIBQl8uTaNYtPIjinhSggmvKk16YOMe9QCKhBXDR7lmRNBfySppJ 2C4HpiFSOR5Ae3p5of3Fs/zpRyjB12ypIBfsBoTdawDbgy0XZDzIajC5BJHYm/VV6ggZ 4AKABdTUOe54hqUonoZbbqvlkIOkmH1fEdhBSl587nz/A5SGTUjp0s+KES2LKi0/IK48 SZW9sBQ1ccMAI4RGFITwCrmvo3dufk7nx8PDtIu0LW8CNhUrOVlnkOPXF1rEH7A5+efN wlaw0RN6zEm11/13ca7Cbn1ET3qgkFVoSF7u7aUzIoX7IGm9tlyrtbmoX6qI3fOtJVxn wndA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57c61e0000fsi405867a12.214.2024.06.07.11.59.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 11:59:03 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C3E948855C; Fri, 7 Jun 2024 20:55:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 464A48857E; Fri, 7 Jun 2024 20:55:15 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, SPF_HELO_NONE,SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 1F8E588445 for ; Fri, 7 Jun 2024 20:55:13 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F348F1480; Fri, 7 Jun 2024 11:55:36 -0700 (PDT) Received: from a079122.blr.arm.com (a079122.arm.com [10.162.17.48]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D9C723F792; Fri, 7 Jun 2024 11:55:09 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Tom Rini , Ilias Apalodimas , Heinrich Schuchardt , Simon Glass , Marek Vasut , Mark Kettenis , Fabio Estevam , Sughosh Ganu Subject: [RFC PATCH 31/31] temp: cmd: efi: add a command to dump EFI memory map Date: Sat, 8 Jun 2024 00:22:40 +0530 Message-Id: <20240607185240.1892031-32-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240607185240.1892031-1-sughosh.ganu@linaro.org> References: <20240607185240.1892031-1-sughosh.ganu@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Add a command to dump the EFI memory map. Not for committing. Signed-off-by: Sughosh Ganu --- cmd/Makefile | 1 + cmd/efi_map_dump.c | 28 ++++++++++++++++++++++++++++ include/efi_loader.h | 2 ++ lib/efi_loader/efi_memory.c | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 cmd/efi_map_dump.c diff --git a/cmd/Makefile b/cmd/Makefile index 35fcc4af5a..315046def6 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -11,6 +11,7 @@ obj-y += help.o obj-y += panic.o obj-y += version.o obj-y += efi_memory.o +obj-y += efi_map_dump.o # command obj-$(CONFIG_CMD_ARMFFA) += armffa.o diff --git a/cmd/efi_map_dump.c b/cmd/efi_map_dump.c new file mode 100644 index 0000000000..f2a5932767 --- /dev/null +++ b/cmd/efi_map_dump.c @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Allocate and Free EFI memory + * + * Copyright (c) 2024 Linaro Limited + */ + +#include +#include + +static int do_efi_map_dump(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ +// printf("%s: argc => %d\n", __func__, argc); + + if (argc != 1) + return CMD_RET_USAGE; + + dump_efi_memory_map(); + + return CMD_RET_SUCCESS; +} + +U_BOOT_CMD( + efi_map_dump, 1, 0, do_efi_map_dump, + "Dump the EFI memory map", + "" +); diff --git a/include/efi_loader.h b/include/efi_loader.h index 9600941aa3..40f894f182 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -791,6 +791,8 @@ efi_status_t efi_get_memory_map(efi_uintn_t *memory_map_size, uint32_t *descriptor_version); /* Adds a range into the EFI memory map */ efi_status_t efi_add_memory_map(u64 start, u64 size, int memory_type); +/* Dump the contents of the EFI memory map */ +void dump_efi_memory_map(void); /* Adds a conventional range into the EFI memory map */ efi_status_t efi_add_conventional_memory_map(u64 ram_start, u64 ram_end, u64 ram_top); diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c index 93244161b0..7ab1b86140 100644 --- a/lib/efi_loader/efi_memory.c +++ b/lib/efi_loader/efi_memory.c @@ -47,6 +47,8 @@ static LIST_HEAD(efi_mem); void *efi_bounce_buffer; #endif +static uint64_t desc_get_end(struct efi_mem_desc *desc); + /** * struct efi_pool_allocation - memory block allocated from pool * @@ -118,6 +120,36 @@ static int lmb_mem_map_update_sync(void *ctx, struct event *event) EVENT_SPY_FULL(EVT_LMB_MAP_UPDATE, lmb_mem_map_update_sync); #endif /* MEM_MAP_UPDATE_NOTIFY */ +static void dump_efi_mem_desc(struct efi_mem_desc *desc) +{ + u64 end; + + end = desc_get_end(desc); + + printf("-----------------------------------\n"); + printf("Memory Range [0x%llx - 0x%llx]\n", + desc->physical_start, end); + printf("Num Pages [0x%llx]\n", desc->num_pages); + printf("Memory Type [0x%x]\n", desc->type); + printf("Attribute [0x%llx]\n", desc->attribute); + printf("-----------------------------------\n"); +} + +void dump_efi_memory_map(void) +{ + struct list_head *lhandle; + + list_for_each(lhandle, &efi_mem) { + struct efi_mem_list *lmem; + struct efi_mem_desc *desc; + + lmem = list_entry(lhandle, struct efi_mem_list, link); + desc = &lmem->desc; + + dump_efi_mem_desc(desc); + } +} + /** * checksum() - calculate checksum for memory allocated from pool *