From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7B3CEC433F5 for ; Fri, 28 Jan 2022 15:19:24 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A1FF0837D2; Fri, 28 Jan 2022 16:19:11 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="o/5+ivEQ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 31E1A837C5; Fri, 28 Jan 2022 16:19:07 +0100 (CET) Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 83BEE837CF for ; Fri, 28 Jan 2022 16:19:02 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sunilvl@ventanamicro.com Received: by mail-pl1-x62c.google.com with SMTP id x11so6199398plg.6 for ; Fri, 28 Jan 2022 07:19:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XhYHkDkMWBZgd0+FZ0iOc8FXSVEDUNhiLZXOb3GrVcc=; b=o/5+ivEQ+BnuUmzc3zxXGPvvEEPgy0HQXohCc057nHMJ1jcO34aX7GTzzppSTx2teL ZZhy6n+/ePwiSuJfsUjljmEW14xfcOtx0SPa+5Ofxb8sx/86Dbz9a6NP4Vse3S9Xpw2i SX8Kl+hQx6k9oXGNgpBDkiNjgQA5LyccmVsC56HyzKEWgHGB8+DoXMjC2LphV4dee0KL v5pjWc7RPsznvpodPB6NkJt6mV7DK+KxJvp3EIYU5ZANw76YQpJvdwP3SsbRLphnXERD Lo8ROsXbHVKrm6kUsxs8sgvXilKnD4A4hzUDDfmj3VbmaVa3kw+fFyNQzdQF5Nv042ov WNYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XhYHkDkMWBZgd0+FZ0iOc8FXSVEDUNhiLZXOb3GrVcc=; b=b01V7sjvPuStwH1QcUcndCbjkkKmZAgNMlgbjK2DM+0qPLmYxoyYhLIcMGNMpdQM6w G3iWoD9vswxvvrbK5JIBFQrZw6BboUh+5jLNrqeuPzUtWIc1IZdlJovBZ5Jc75b3lbnu xtWWtSYYNp1b14WwN9wESAI9rjb9BwB36xlr66kNoCEIEuZ//OS2cBeRFL2cG/c3W1e8 WZ+XhuGydYPoHgQ3WZUewEyaLUSgkInL5v02Eluz8Xk+2OPHHHkSjP1ZQLsI9U2pI+Db MczxT0TRqDmrCFtO6dTzgXa+E4pz+YNOYa9s6cNbD00ECdZSdTKgkVkLaU7Ezty0Ne4q 4jHA== X-Gm-Message-State: AOAM530tFhX+HPZ85kolWpvkEtwM9ih0ekbUU6itGO8zjhlr9eSv2K9u dZCuBAHjGCMLruuE0ceDfHwgvYy7ldBakA== X-Google-Smtp-Source: ABdhPJzCQsxF0fBXFCgFh9QgR5/s5MjW1XpnQGy53Fq5ugLynajirjIEMqEgnLSSEiRBiCdy6L5GJQ== X-Received: by 2002:a17:902:8c84:: with SMTP id t4mr6483045plo.78.1643383140887; Fri, 28 Jan 2022 07:19:00 -0800 (PST) Received: from sunil-ThinkPad-T490.dc1.ventanamicro.com ([49.206.3.187]) by smtp.gmail.com with ESMTPSA id c7sm9192205pfo.131.2022.01.28.07.18.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jan 2022 07:19:00 -0800 (PST) From: Sunil V L To: Heinrich Schuchardt Cc: u-boot@lists.denx.de, Ard Biesheuvel , Anup Patel , Atish Patra , Abner Chang , Jessica Clarke , Sunil V L Subject: [RFC PATCH V2 2/2] efi_selftest: unit test for RISCV_EFI_BOOT_PROTOCOL Date: Fri, 28 Jan 2022 20:48:45 +0530 Message-Id: <20220128151845.114159-3-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220128151845.114159-1-sunilvl@ventanamicro.com> References: <20220128151845.114159-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.5 at phobos.denx.de X-Virus-Status: Clean Add a test for the RISCV_EFI_BOOT_PROTOCOL. Signed-off-by: Sunil V L --- lib/efi_selftest/Makefile | 1 + lib/efi_selftest/efi_selftest_riscv.c | 119 ++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 lib/efi_selftest/efi_selftest_riscv.c diff --git a/lib/efi_selftest/Makefile b/lib/efi_selftest/Makefile index 9ff6e1760c..0b05f8a591 100644 --- a/lib/efi_selftest/Makefile +++ b/lib/efi_selftest/Makefile @@ -64,6 +64,7 @@ obj-$(CONFIG_EFI_LOADER_HII) += efi_selftest_hii.o obj-$(CONFIG_EFI_RNG_PROTOCOL) += efi_selftest_rng.o obj-$(CONFIG_EFI_GET_TIME) += efi_selftest_rtc.o obj-$(CONFIG_EFI_TCG2_PROTOCOL) += efi_selftest_tcg2.o +obj-$(CONFIG_EFI_RISCV_BOOT_PROTOCOL) += efi_selftest_riscv.o ifeq ($(CONFIG_GENERATE_ACPI_TABLE),) obj-y += efi_selftest_fdt.o diff --git a/lib/efi_selftest/efi_selftest_riscv.c b/lib/efi_selftest/efi_selftest_riscv.c new file mode 100644 index 0000000000..9d2182e61f --- /dev/null +++ b/lib/efi_selftest/efi_selftest_riscv.c @@ -0,0 +1,119 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * efi_selftest_riscv + * + * Copyright (c) 2022 Ventana Micro Systems Inc + * + * Test the RISCV_EFI_BOOT_PROTOCOL. + * + * The following services are tested: + * get_boot_hartid + */ + +#include +#include +#include + +static const struct efi_system_table *systemtab; +static const struct efi_boot_services *boottime; +static const char *fdt; +static const efi_guid_t riscv_efi_boot_protocol_guid = RISCV_EFI_BOOT_PROTOCOL_GUID; +static const efi_guid_t fdt_guid = EFI_FDT_GUID; + +/** + * efi_st_get_config_table() - get configuration table + * + * @guid: GUID of the configuration table + * Return: pointer to configuration table or NULL + */ +static void *efi_st_get_config_table(const efi_guid_t *guid) +{ + size_t i; + + for (i = 0; i < systab.nr_tables; i++) { + if (!guidcmp(guid, &systemtab->tables[i].guid)) + return systemtab->tables[i].table; + } + return NULL; +} + +/* + * Setup unit test. + * + * @handle: handle of the loaded image + * @systable: system table + * @return: EFI_ST_SUCCESS for success + */ +static int setup(const efi_handle_t img_handle, + const struct efi_system_table *systable) +{ + systemtab = systable; + boottime = systable->boottime; + + fdt = efi_st_get_config_table(&fdt_guid); + + if (!fdt) { + efi_st_error("Missing device tree\n"); + return EFI_ST_FAILURE; + } + return EFI_ST_SUCCESS; +} + +/* + * Execute unit test. + * + * @return: EFI_ST_SUCCESS for success + */ +static int execute(void) +{ + efi_status_t ret; + struct riscv_efi_boot_protocol *prot; + efi_uintn_t efi_hartid, fdt_hartid; + int chosen_node, len; + const fdt32_t *prop; + + /* Get riscv boot protocol */ + ret = boottime->locate_protocol(&riscv_efi_boot_protocol_guid, NULL, + (void **)&prot); + if (ret != EFI_SUCCESS) { + efi_st_error("RISC-V Boot Protocol not available\n"); + return EFI_ST_FAILURE; + } + + /* Get Boot Hart ID from EFI protocol */ + ret = prot->get_boot_hartid(prot, &efi_hartid); + if (ret != EFI_SUCCESS) { + efi_st_error("Could not retrieve boot hart ID\n"); + return EFI_ST_FAILURE; + } + + /* Get Boot Hart ID from FDT */ + chosen_node = fdt_path_offset(fdt, "/chosen"); + if (chosen_node < 0) { + efi_st_error("/chosen node not found\n"); + return EFI_ST_FAILURE; + } + + prop = fdt_getprop((void *)fdt, chosen_node, "boot-hartid", &len); + if (!prop || len != sizeof(u32)) { + efi_st_error("boot-hartid not found\n"); + return EFI_ST_FAILURE; + } + + fdt_hartid = fdt32_to_cpu(*prop); + + /* Boot Hart ID should be same */ + if (efi_hartid != fdt_hartid) { + efi_st_error("boot-hartid is not same in EFI and FDT\n"); + return EFI_ST_FAILURE; + } + + return EFI_ST_SUCCESS; +} + +EFI_UNIT_TEST(riscv) = { + .name = "riscv", + .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT, + .setup = setup, + .execute = execute, +}; -- 2.25.1