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 53B54C4332F for ; Wed, 23 Nov 2022 17:51:00 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0EEA9855A5; Wed, 23 Nov 2022 18:50:42 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sancloud.com 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 73343855AA; Wed, 23 Nov 2022 18:50:38 +0100 (CET) Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01on2062b.outbound.protection.outlook.com [IPv6:2a01:111:f400:feab::62b]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 39DB38557D for ; Wed, 23 Nov 2022 18:50:35 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sancloud.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=paul.barker@sancloud.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oH+tRUaCc+9MseIfTZrH8+qWZjWIwlN5DE1g9XaLoOTqmNqpGvYWJr8ZBcF7InwSIfB4G3ozyfIsRxCvsz9OZjT/sYPXjhdonRaGtTKmHAoEQbgPpzUIt5vGA3yIyoPvn5uGkrSIozfuSHIZCepAEE3nR8CMnpMNxFTUP6EhxVQfCPW3dR0nY7kMCPuPvSMR6AxS07JN0ukOZDHAeoqdViacrIAYpkEmxhxw9ViYRbmvs7lEFzfh3XV1tilZUgbE2wQVUZ4YlnDrvyXB1e8aGtfPqAVS6xxIqkMqtNwJfBN+SiXC9Rk/DmXqsAZhy1mwINY7Dmy8WT3mAvzSaggjSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7Pdy2dTSDnzi3Lm3xGuGjgRx2hPl0tp7Qj0iGt12Km4=; b=XZ7vHyAiZi/w+cNzF16XBrxKCtHTUchrhUbTWcXKpag+cUQ/jko65lJlcJH2nC84BYcHPMT7cjKIwQ6S2eHpQbcDTAvyN+dDikEvXSgDVfLeJGTWGto+JXAa7Re399ieBV/GGfkIoUlK95n1AzTF4FY3hbf7b+OdN3sH3xlFlqkZylXKxLyoFGoaQxnW9pXmbsDMXUWif93fVxb+3MG/KiXspNUbMK7Oo5HOWsIso06WQVf9KYA7XUdkFmSLwwppimmalm3NkQ3bXqRhm6FShKoDkcIeM0BneCnUsUCmSRO5aX4W0g/kE94A0GMncCmSCbEsv2YXLzm2H2MGlNVKOA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=sancloud.com; dmarc=pass action=none header.from=sancloud.com; dkim=pass header.d=sancloud.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=sancloud.com; Received: from SEYPR06MB5064.apcprd06.prod.outlook.com (2603:1096:101:55::13) by TYZPR06MB4320.apcprd06.prod.outlook.com (2603:1096:400:65::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5834.15; Wed, 23 Nov 2022 17:50:31 +0000 Received: from SEYPR06MB5064.apcprd06.prod.outlook.com ([fe80::3343:e4e0:2fbb:3c9c]) by SEYPR06MB5064.apcprd06.prod.outlook.com ([fe80::3343:e4e0:2fbb:3c9c%5]) with mapi id 15.20.5834.015; Wed, 23 Nov 2022 17:50:31 +0000 From: Paul Barker To: u-boot@lists.denx.de, Simon Glass , Tom Rini , Heinrich Schuchardt , Ilias Apalodimas , Jagan Teki Cc: Paul Barker Subject: [PATCH v5 2/3] efi_selftest: Add tests for SPI protocol support Date: Wed, 23 Nov 2022 17:50:05 +0000 Message-Id: <20221123175006.4080122-3-paul.barker@sancloud.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221123175006.4080122-1-paul.barker@sancloud.com> References: <20221123175006.4080122-1-paul.barker@sancloud.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: LO4P123CA0101.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:191::16) To SEYPR06MB5064.apcprd06.prod.outlook.com (2603:1096:101:55::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEYPR06MB5064:EE_|TYZPR06MB4320:EE_ X-MS-Office365-Filtering-Correlation-Id: 23453d10-70bc-4560-8c35-08dacd7b3714 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kTMCeHFZj39WE5/loCrzmPNcDCP4l4JR4n3Lj/Mtm0wVHHGe/9BNBOO4vmO9MqnvVAEdVH+NgyeV6940j+FTruvP0kqbPj01Yl3LWGMAnklp2XrdbWFFYkQQj0j28QZMPvFGhDbQh7LHJcZqHn6dnD8E9byntLQwqo4GBHEJUhkmdFoshaqAlDqkzFb9yVZ7/km0zIkdWDH2dNSws+t+swvOFcClJoI82wVk1bMIpkjIlY4frjsZhgXTSOlygvfzDpZ02SUTwZ7hf0WMupO+o6juHMZD54MnZViaX6Wy+llUqczDfcsOZSY1ThbShsM587BtHJo9cg6ABJGGLaX3B9hQ73rOfkxnUkmoRqSYSuiZAuQdfg03YjAFivqAc/QwspZJePJ9OwoU434yqOrhQF8381HcQf5hIIq5BM5eWFjj9Nni/DW7PZw2cf50vzQ81EYTnKnpADsLTuGR5ORVNbZyjZ9OdNqTrNMBTQtWaEFWVwspAUyfq40Ax/dlRuv+tsVuINDfOluBlj0uCJ1Nlr7j1CEZRA99d6inVlOLuzlekpeC8rOVrOOzG5yqK6P/zOF0iAnPCX3v6laKbnpLnqjvtmg7pHP6rTrMiZMjAdauWTc3TdKfeyukClkUiFK2YXEduzqtYdjc6rP1SObTfTd1uzeQZcc7gcHfq0PqZRTNRuP0qZBaOp7dgfM6kW1un5o4H1d2RnFAXYOUGuO9EQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SEYPR06MB5064.apcprd06.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(346002)(396003)(39830400003)(376002)(366004)(136003)(451199015)(66476007)(83380400001)(86362001)(38350700002)(41300700001)(30864003)(2906002)(38100700002)(44832011)(478600001)(8936002)(41320700001)(6512007)(5660300002)(6506007)(1076003)(6666004)(107886003)(52116002)(2616005)(4326008)(186003)(8676002)(66556008)(316002)(66946007)(26005)(6486002)(110136005)(786003)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?sVI7LlqwakZHKltWI2ST4/tIgyv0sPCBvSMZPCOzkVRb8ktwCj+QUoMFkoZy?= =?us-ascii?Q?b0Hu8K4jQgWcm/hKG3v4I46bYp50UvPv27q/G3GVi3WiAsAKdqh/Vl1CT7c2?= =?us-ascii?Q?qCMxXZqrXQebzqH+E/ZyC3z3JR2V+3aFDUVdgFvokjOW6xW173n25QnqwWM3?= =?us-ascii?Q?6hXW3izWwaiYFaIpur0Dd3THnn8P5Rq1jdNCtk2Qr49MFhmVfIrwtb2s9jmZ?= =?us-ascii?Q?0tE9GrlMV2Chi3e+YIBKPw4J3XeD5bh4igVIrFthtjmzqFaaS42JmdSoZo2k?= =?us-ascii?Q?gDagtffD4DSFGHTgffjQZzbNRF9fwGJX9jfvGQ0lXxo+BvO2+louJDvPBt7N?= =?us-ascii?Q?GWH3g8hLAoKSfVhykJPlyEkdK+tKtIlFuYPikMLuxGdFwsRINKQoWgUQEY+c?= =?us-ascii?Q?GECWtAEQLWDi97YHo4rDc2VrqIvAM3V18sZgI5Vbp05Rm16bueZhVoFBmKRL?= =?us-ascii?Q?teVrK35NzltQjlVTvz8UinS15bkkJLCHqouTJHXuVKrroPCIXalROh7AYj7Z?= =?us-ascii?Q?VHBFTxlbB768ehlAGKSrTsrb+XW/20ACC8ryKdyWRJWwn4J5e36fg0Vi4K3G?= =?us-ascii?Q?7Qy74lbiBXWZ+r7kz+R28Zr168Fx9MutRido5xYBQ0nVJBi9qu+cfEjJ+dau?= =?us-ascii?Q?aF4+s4t99yrF+Rx0R3DELADOIVKCRT1vZrvqWw+yWo5zZ8SGVSY9HkH2l+Ig?= =?us-ascii?Q?Xet9QMmPbL6R2TMr99JTbi467UJmom5fgqCMqiZqjJ1Ts6D5oYf+UVvdgsbb?= =?us-ascii?Q?xkjZrHLp2StWDx7UWmyk+ZgzhioLpnA1ohV3KXh/pFBupy9mp83rqM0/zkBT?= =?us-ascii?Q?tSPGWxJhD+xA8FGlw5oiYFw9uz1c2kDjY+bsdfBm0/9xMo1iqLqGTkB/5oVE?= =?us-ascii?Q?DxEdWVSxs1Ll/N4zVxCDEs2yiUyut2u6uy3d9dJAOmJeq8HVNHHlPOLZEr8x?= =?us-ascii?Q?SxswWqlF+VyKHoAK56hDtRlLLjuZe0WXaYV5Foy84pSjxEfCREFNEc3SHKJy?= =?us-ascii?Q?71f+EDog8a1TA23982UG2DKtF3+dzTeAELTsOEEg2AeAcHG9E0PcW69ZXSid?= =?us-ascii?Q?HzO2gbLmIKEY0yJ/nZHgFVBap1Q03DPQrzD/F8opABUjvJuymCxtoig3xeZE?= =?us-ascii?Q?8mso1XoiOch7x07LgxrpWhiiLxeSrzuPLuSyLW+HVTAxBHGwsjBjjfynCx4v?= =?us-ascii?Q?fmH/UGgyOtl8w2+UAbrZ84qZQN+7nEPz9ECqeGRhAaL5jUsc+1uwt5vA+65S?= =?us-ascii?Q?7AeLSS7/xp5oLLdPQ7fsqcwUFvYSNks4r0QIv77cAKVNtGTox3GQ0qCJHTc8?= =?us-ascii?Q?cXJTFriVp1J0obXAWQDtpQGgoYgDfhOvUcuhFyQa4c3PCnSbI9hKOzNFNDpa?= =?us-ascii?Q?drqrXMHxLBbvHxK3nuihLF2oWfEMIqcy0v+GetB2wT5YSLKlf1A2tAOsCyOp?= =?us-ascii?Q?NWMJkVGx5fwXMbav34QsNjF6L+z/eKxjTB5jYAQ9zOy6gnXwLcZkExt4bvQN?= =?us-ascii?Q?xjA1j2rSlFudi7mZtQdaJDNuT+gGb/eXzIglkv6hodpEJZL9YHsbp97uNUDx?= =?us-ascii?Q?eXhdE2DT+XObppMWUx4f9eMslM0foNLapYURMC3GzqQgxTOU6mHK/E5U2c2G?= =?us-ascii?Q?Mw=3D=3D?= X-OriginatorOrg: sancloud.com X-MS-Exchange-CrossTenant-Network-Message-Id: 23453d10-70bc-4560-8c35-08dacd7b3714 X-MS-Exchange-CrossTenant-AuthSource: SEYPR06MB5064.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Nov 2022 17:50:31.6517 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3e0f949f-6a74-4378-baf2-0abfca8d5e06 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: VuwDj5HEx/gY3THRSnroA/iigKELUicVeHZaM/9Rr8md1VjM16XmIDaUxf2O6MKI9tiK9XRvGvXxHKm/43n+vglR17gIMSq9l8+3kGqN6jo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR06MB4320 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.6 at phobos.denx.de X-Virus-Status: Clean These tests ensure that the new UEFI SPI I/O protocol support works as expected. They intended to execute on the sandbox target. Signed-off-by: Paul Barker --- MAINTAINERS | 1 + arch/sandbox/dts/test.dts | 13 + lib/efi_selftest/Makefile | 1 + lib/efi_selftest/efi_selftest_spi_protocol.c | 284 +++++++++++++++++++ 4 files changed, 299 insertions(+) create mode 100644 lib/efi_selftest/efi_selftest_spi_protocol.c diff --git a/MAINTAINERS b/MAINTAINERS index 6a82cdbbb474..54742e759e4c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -931,6 +931,7 @@ M: Paul Barker S: Maintained F: include/efi_spi_protocol.h F: lib/efi_loader/efi_spi_protocol.c +F: lib/efi_selftest/efi_selftest_spi_protocol.c ENVIRONMENT M: Joe Hershberger diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index dffe10adbf47..003af61113a8 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -1253,6 +1253,13 @@ compatible = "spansion,m25p16", "jedec,spi-nor"; spi-max-frequency = <40000000>; sandbox,filename = "spi.bin"; + + u-boot,uefi-spi-vendor = "spansion"; + u-boot,uefi-spi-part-number = "mt25p16"; + + /* GUID in UEFI format: b881eb5d-ad92-4a48-8fdd-fa75a8e4c6b8 */ + u-boot,uefi-spi-io-guid = [5d eb 81 b8 92 ad 48 4a + 8f dd fa 75 a8 e4 c6 b8]; }; spi.bin@1 { reg = <1>; @@ -1261,6 +1268,12 @@ sandbox,filename = "spi.bin"; spi-cpol; spi-cpha; + + u-boot,uefi-spi-vendor = "spansion"; + u-boot,uefi-spi-part-number = "mt25p16"; + /* GUID in UEFI format: b6b39ecd-2b1f-a643-b8d7-3192d7cf7270 */ + u-boot,uefi-spi-io-guid = [cd 9e b3 b6 1f 2b 43 a6 + b8 d7 31 92 d7 cf 72 70]; }; }; diff --git a/lib/efi_selftest/Makefile b/lib/efi_selftest/Makefile index e4d75420bff6..e2c4fcd40795 100644 --- a/lib/efi_selftest/Makefile +++ b/lib/efi_selftest/Makefile @@ -63,6 +63,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_SPI_PROTOCOL) += efi_selftest_spi_protocol.o ifeq ($(CONFIG_GENERATE_ACPI_TABLE),) obj-y += efi_selftest_fdt.o diff --git a/lib/efi_selftest/efi_selftest_spi_protocol.c b/lib/efi_selftest/efi_selftest_spi_protocol.c new file mode 100644 index 000000000000..946d04dbb557 --- /dev/null +++ b/lib/efi_selftest/efi_selftest_spi_protocol.c @@ -0,0 +1,284 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2022 Micron Technology, Inc. + */ + +#include +#include + +static struct efi_boot_services *boottime; +static efi_guid_t efi_spi_configuration_guid = EFI_SPI_CONFIGURATION_GUID; + +static int setup(const efi_handle_t img_handle, + const struct efi_system_table *systable) +{ + boottime = systable->boottime; + return EFI_ST_SUCCESS; +} + +static int test_peripheral(struct efi_spi_peripheral *p, struct efi_spi_bus *bus) +{ + struct efi_spi_io_protocol *io_protocol; + u8 req[5], resp[5]; + efi_status_t ret; + + if (!p->friendly_name) { + efi_st_error("SPI peripheral lacks a friendly name\n"); + return EFI_ST_FAILURE; + } + + if (!p->spi_peripheral_driver_guid) { + efi_st_error("SPI peripheral lacks driver GUID\n"); + return EFI_ST_FAILURE; + } + + if (!p->spi_part) { + efi_st_error("SPI peripheral lacks SPI part definition\n"); + return EFI_ST_FAILURE; + } + + if (!p->max_clock_hz) { + efi_st_error("SPI peripheral has a max clock rate of zero\n"); + return EFI_ST_FAILURE; + } + + if (!p->spi_bus) { + efi_st_error("SPI peripheral lack pointer to SPI bus\n"); + return EFI_ST_FAILURE; + } + + if (p->spi_bus != bus) { + efi_st_error("SPI peripheral spi_bus pointer points to the wrong bus\n"); + return EFI_ST_FAILURE; + } + + if (!p->chip_select) { + efi_st_error("SPI peripheral lacks chip_select function\n"); + return EFI_ST_FAILURE; + } + + if (!p->spi_part->vendor) { + efi_st_error("SPI part lacks vendor string\n"); + return EFI_ST_FAILURE; + } + + if (!p->spi_part->part_number) { + efi_st_error("SPI part lacks part number string\n"); + return EFI_ST_FAILURE; + } + + if (p->spi_part->min_clock_hz > p->spi_part->max_clock_hz) { + efi_st_error("SPI part min clock rate is greater than max clock rate\n"); + return EFI_ST_FAILURE; + } + + if (p->spi_part->max_clock_hz != p->max_clock_hz) { + efi_st_error("SPI part max clock rate does not match peripheral max clock rate\n"); + return EFI_ST_FAILURE; + } + + ret = boottime->locate_protocol(p->spi_peripheral_driver_guid, + NULL, (void **)&io_protocol); + if (ret != EFI_SUCCESS) { + efi_st_error("SPI IO protocol not available\n"); + return EFI_ST_FAILURE; + } + + if (io_protocol->spi_peripheral != p) { + efi_st_error("SPI IO protocol spi_peripheral pointer points to the wrong peripheral\n"); + return EFI_ST_FAILURE; + } + + if (io_protocol->original_spi_peripheral != p) { + efi_st_error("SPI IO protocol original_spi_peripheral pointer points to the wrong peripheral\n"); + return EFI_ST_FAILURE; + } + + if (!io_protocol->maximum_transfer_bytes) { + efi_st_error("SPI IO protocol has zero maximum transfer size\n"); + return EFI_ST_FAILURE; + } + + if (!io_protocol->legacy_spi_protocol) { + efi_st_error("SPI IO protocol lacks legacy SPI protocol\n"); + return EFI_ST_FAILURE; + } + + if (!io_protocol->transaction) { + efi_st_error("SPI IO protocol lacks transaction function\n"); + return EFI_ST_FAILURE; + } + + if (!io_protocol->update_spi_peripheral) { + efi_st_error("SPI IO protocol lacks update_spi_peripheral function\n"); + return EFI_ST_FAILURE; + } + + if (!io_protocol->legacy_spi_protocol->erase_block_opcode) { + efi_st_error("SPI legacy controller protocol lacks erase_block_opcode function\n"); + return EFI_ST_FAILURE; + } + + if (io_protocol->legacy_spi_protocol->erase_block_opcode( + io_protocol->legacy_spi_protocol, + 0) != EFI_UNSUPPORTED) { + efi_st_error("Incorrect return value from SPI legacy controller protocol erase_block_opcode function\n"); + return EFI_ST_FAILURE; + } + + if (!io_protocol->legacy_spi_protocol->write_status_prefix) { + efi_st_error("SPI legacy controller protocol lacks write_status_prefix function\n"); + return EFI_ST_FAILURE; + } + + if (io_protocol->legacy_spi_protocol->write_status_prefix( + io_protocol->legacy_spi_protocol, + 0) != EFI_UNSUPPORTED) { + efi_st_error("Incorrect return value from SPI legacy controller protocol write_status_prefix function\n"); + return EFI_ST_FAILURE; + } + + if (!io_protocol->legacy_spi_protocol->bios_base_address) { + efi_st_error("SPI legacy controller protocol lacks bios_base_address function\n"); + return EFI_ST_FAILURE; + } + + if (io_protocol->legacy_spi_protocol->bios_base_address( + io_protocol->legacy_spi_protocol, + 0) != EFI_UNSUPPORTED) { + efi_st_error("Incorrect return value from SPI legacy controller protocol bios_base_address function\n"); + return EFI_ST_FAILURE; + } + + if (!io_protocol->legacy_spi_protocol->clear_spi_protect) { + efi_st_error("SPI legacy controller protocol lacks clear_spi_protect function\n"); + return EFI_ST_FAILURE; + } + + if (io_protocol->legacy_spi_protocol->clear_spi_protect( + io_protocol->legacy_spi_protocol) != EFI_UNSUPPORTED) { + efi_st_error("Incorrect return value from SPI legacy controller protocol clear_spi_protect function\n"); + return EFI_ST_FAILURE; + } + + if (!io_protocol->legacy_spi_protocol->is_range_protected) { + efi_st_error("SPI legacy controller protocol lacks is_range_protected function\n"); + return EFI_ST_FAILURE; + } + + if (io_protocol->legacy_spi_protocol->is_range_protected( + io_protocol->legacy_spi_protocol, + 0, 0)) { + efi_st_error("Incorrect return value from SPI legacy controller protocol is_range_protected function\n"); + return EFI_ST_FAILURE; + } + + if (!io_protocol->legacy_spi_protocol->protect_next_range) { + efi_st_error("SPI legacy controller protocol lacks protect_next_range function\n"); + return EFI_ST_FAILURE; + } + + if (io_protocol->legacy_spi_protocol->protect_next_range( + io_protocol->legacy_spi_protocol, + 0, 0) != EFI_UNSUPPORTED) { + efi_st_error("Incorrect return value from SPI legacy controller protocol protect_next_range function\n"); + return EFI_ST_FAILURE; + } + + if (!io_protocol->legacy_spi_protocol->lock_controller) { + efi_st_error("SPI legacy controller protocol lacks lock_controller function\n"); + return EFI_ST_FAILURE; + } + + if (io_protocol->legacy_spi_protocol->lock_controller( + io_protocol->legacy_spi_protocol) != EFI_UNSUPPORTED) { + efi_st_error("Incorrect return value from SPI legacy controller protocol lock_controller function\n"); + return EFI_ST_FAILURE; + } + + req[0] = 0x9f; + ret = io_protocol->transaction(io_protocol, + SPI_TRANSACTION_FULL_DUPLEX, + false, 0, 1, 8, + sizeof(req), req, + sizeof(resp), resp); + if (ret != EFI_SUCCESS) { + efi_st_error("SPI transaction failed\n"); + return EFI_ST_FAILURE; + } + + if ((resp[0] != 0xff) || (resp[1] != 0x20) || (resp[2] != 0x20) || (resp[3] != 0x15)) { + efi_st_error("Incorrect response from sandbox SPI flash emulator\n"); + return EFI_ST_FAILURE; + } + + return EFI_ST_SUCCESS; +} + +static int test_bus(struct efi_spi_bus *bus) +{ + struct efi_spi_peripheral *p; + int status; + + if (!bus->friendly_name) { + efi_st_error("SPI bus lacks a friendly name\n"); + return EFI_ST_FAILURE; + } + + if (!bus->peripheral_list) { + efi_st_error("SPI bus has zero peripherals\n"); + return EFI_ST_FAILURE; + } + + if (!bus->clock) { + efi_st_error("SPI bus lacks clock function\n"); + return EFI_ST_FAILURE; + } + + for (p = bus->peripheral_list; p; p = p->next_spi_peripheral) { + status = test_peripheral(p, bus); + if (status) { + efi_st_error("Failed testing SPI peripheral\n"); + return status; + } + } + + return EFI_ST_SUCCESS; +} + +static int execute(void) +{ + struct efi_spi_configuration_protocol *spi; + efi_status_t ret; + int status; + u32 i; + + ret = boottime->locate_protocol(&efi_spi_configuration_guid, + NULL, (void **)&spi); + if (ret != EFI_SUCCESS) { + efi_st_error("SPI configuration protocol not available\n"); + return EFI_ST_FAILURE; + } + + if (!spi->bus_count) { + efi_st_error("SPI configuration protocol has zero busses\n"); + return EFI_ST_FAILURE; + } + + for (i = 0; i < spi->bus_count; i++) { + status = test_bus(spi->bus_list[i]); + if (status) { + efi_st_error("Failed testing SPI bus %d\n", i); + return status; + } + } + + return EFI_ST_SUCCESS; +} + +EFI_UNIT_TEST(spi_protocol) = { + .name = "SPI protocol", + .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT, + .setup = setup, + .execute = execute, +}; -- 2.25.1