From patchwork Sat Jan 16 21:52:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1427603 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=GgSqHPib; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 ozlabs.org (Postfix) with ESMTPS id 4DJBf85gJLz9s24 for ; Sun, 17 Jan 2021 08:54:24 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B20C382998; Sat, 16 Jan 2021 22:52:45 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="GgSqHPib"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AFEBE829DB; Sat, 16 Jan 2021 22:52:40 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) (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 2F587829C6 for ; Sat, 16 Jan 2021 22:52:37 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd2d.google.com with SMTP id n2so8235833iom.7 for ; Sat, 16 Jan 2021 13:52:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=R5VsOTnHQTIUisH6pxB1jkjNZX5ZexRHqyqhCmTNOZQ=; b=GgSqHPibZDER6H7/054i6CsY85wLgKmZL3I3LKCzWPEiHdInpi7rsNI390nB/CDwdJ sf6VpHHdIw/31sEXUBWTBeVjdwSvrJjXXhQW4EKqkYxBlXuUD5ShY/YekgLubqfvx+EF zKv/2nYVXaP2ywmxsIF1ZIwI33kmCcY5fDFGc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=R5VsOTnHQTIUisH6pxB1jkjNZX5ZexRHqyqhCmTNOZQ=; b=QukaBjGRtt83lZ/ucxXy9QmchOgTx//UaY5AfuVOomgY00NNHSs+nYUA2cH8gnsaVc 6nbZdUz16yKDUgqbVFJzj857l42PlkTYSXyoDMjyxY5U7yh2aCgnQVuT+R9000iK9Siv tIr832Bn48bNFIGBXAyg5uvgSHm6vOnPVuxYV3LbsZYOvaOPL+jYoWEleoftzI2AMV6o hlFn4eMzMAYjmrTTeKaDOMdeMiv/biCkpoTda4Zg4zZoDgi7xZfRteGQnZMsJallAh5E 0Xk7NZf8/UAdg2d65dE6gg3qRMIzrdSApZaJCso/5UrRTUQcR16ImnManLJv04mMf66I s2pg== X-Gm-Message-State: AOAM531pGA0v2+zk9jIxvdXKSnRL1fHxPwVL7fMUxccB4F+u02hpbHvU nj1Im2YeTHbbhdcYpTPrLBSydiRqoL1xf7HA X-Google-Smtp-Source: ABdhPJwzo8S+tuqX419EWwLsBp+bNsy/aODant61JPt8BuSMENV/Q0j4EBB1j+YTHxoVT5qWi6PaOA== X-Received: by 2002:a02:6a50:: with SMTP id m16mr14976708jaf.129.1610833955772; Sat, 16 Jan 2021 13:52:35 -0800 (PST) Received: from localhost.localdomain (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id r1sm3356359iot.8.2021.01.16.13.52.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Jan 2021 13:52:35 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Alper Nebi Yasak , Andy Shevchenko , Bin Meng , Heinrich Schuchardt , Ovidiu Panait , Pratyush Yadav , Walter Lozano Subject: [PATCH 01/10] cros_ec: Add a function for the hello message Date: Sat, 16 Jan 2021 14:52:22 -0700 Message-Id: <20210116145217.1.Ibb6b54274e623fe7c1b49a67775a5ebf297b4052@changeid> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog In-Reply-To: <20210116215231.1220196-1-sjg@chromium.org> References: <20210116215231.1220196-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean This is used several times in this file. Put it in a function to avoid code duplication. Also add a test for this function. There are no cros_ec tests at present, so it is time to update the code. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- arch/sandbox/include/asm/test.h | 14 ++++++++++ drivers/misc/cros_ec.c | 46 ++++++++++++++++++++++----------- drivers/misc/cros_ec_sandbox.c | 12 +++++++++ include/cros_ec.h | 11 ++++++++ test/dm/Makefile | 1 + test/dm/cros_ec.c | 32 +++++++++++++++++++++++ 6 files changed, 101 insertions(+), 15 deletions(-) create mode 100644 test/dm/cros_ec.c diff --git a/arch/sandbox/include/asm/test.h b/arch/sandbox/include/asm/test.h index 05f66f700ca..8363ca73195 100644 --- a/arch/sandbox/include/asm/test.h +++ b/arch/sandbox/include/asm/test.h @@ -57,6 +57,12 @@ enum { SYSCON_COUNT }; +/** + */ +enum cros_ec_test_t { + CROSECT_BREAK_HELLO = BIT(1), +}; + /** * sandbox_i2c_set_test_mode() - set test mode for running unit tests * @@ -260,4 +266,12 @@ uint sandbox_pci_read_bar(u32 barval, int type, uint size); */ void sandbox_set_enable_memio(bool enable); +/** + * sandbox_cros_ec_set_test_flags() - Set behaviour for testing purposes + * + * @dev: Device to check + * @flags: Flags to control behaviour (CROSECT_...) + */ +void sandbox_cros_ec_set_test_flags(struct udevice *dev, uint flags); + #endif diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c index f03b7d55d64..013c67e0464 100644 --- a/drivers/misc/cros_ec.c +++ b/drivers/misc/cros_ec.c @@ -591,6 +591,25 @@ static int cros_ec_invalidate_hash(struct udevice *dev) return 0; } +int cros_ec_hello(struct udevice *dev, uint *handshakep) +{ + struct ec_params_hello req; + struct ec_response_hello *resp; + + req.in_data = 0x12345678; + if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req), + (uint8_t **)&resp, sizeof(*resp)) < 0) + return -EIO; + if (resp->out_data != req.in_data + 0x01020304) { + printf("Received invalid handshake %x\n", resp->out_data); + if (handshakep) + *handshakep = req.in_data; + return -ENOTSYNC; + } + + return 0; +} + int cros_ec_reboot(struct udevice *dev, enum ec_reboot_cmd cmd, uint8_t flags) { struct ec_params_reboot_ec p; @@ -738,7 +757,6 @@ static int cros_ec_check_version(struct udevice *dev) { struct cros_ec_dev *cdev = dev_get_uclass_priv(dev); struct ec_params_hello req; - struct ec_response_hello *resp; struct dm_cros_ec_ops *ops; int ret; @@ -767,14 +785,14 @@ static int cros_ec_check_version(struct udevice *dev) /* Try sending a version 3 packet */ cdev->protocol_version = 3; req.in_data = 0; - if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req), - (uint8_t **)&resp, sizeof(*resp)) > 0) + ret = cros_ec_hello(dev, NULL); + if (!ret || ret == -ENOTSYNC) return 0; /* Try sending a version 2 packet */ cdev->protocol_version = 2; - if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req), - (uint8_t **)&resp, sizeof(*resp)) > 0) + ret = cros_ec_hello(dev, NULL); + if (!ret || ret == -ENOTSYNC) return 0; /* @@ -790,18 +808,16 @@ static int cros_ec_check_version(struct udevice *dev) int cros_ec_test(struct udevice *dev) { - struct ec_params_hello req; - struct ec_response_hello *resp; + uint out_data; + int ret; - req.in_data = 0x12345678; - if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req), - (uint8_t **)&resp, sizeof(*resp)) < sizeof(*resp)) { + ret = cros_ec_hello(dev, &out_data); + if (ret == -ENOTSYNC) { + printf("Received invalid handshake %x\n", out_data); + return ret; + } else if (ret) { printf("ec_command_inptr() returned error\n"); - return -1; - } - if (resp->out_data != req.in_data + 0x01020304) { - printf("Received invalid handshake %x\n", resp->out_data); - return -1; + return ret; } return 0; diff --git a/drivers/misc/cros_ec_sandbox.c b/drivers/misc/cros_ec_sandbox.c index 9fd6cc2086c..1922a9c1b96 100644 --- a/drivers/misc/cros_ec_sandbox.c +++ b/drivers/misc/cros_ec_sandbox.c @@ -18,6 +18,7 @@ #include #include #include +#include #include /* @@ -73,6 +74,7 @@ struct ec_keymatrix_entry { * @matrix: Information about keyboard matrix * @keyscan: Current keyscan information (bit set for each row/column pressed) * @recovery_req: Keyboard recovery requested + * @test_flags: Flags that control behaviour for tests */ struct ec_state { u8 vbnv_context[EC_VBNV_BLOCK_SIZE_V2]; @@ -84,6 +86,7 @@ struct ec_state { struct ec_keymatrix_entry *matrix; /* the key matrix info */ uint8_t keyscan[KEYBOARD_COLS]; bool recovery_req; + uint test_flags; } s_state, *g_state; /** @@ -295,6 +298,8 @@ static int process_cmd(struct ec_state *ec, struct ec_response_hello *resp = resp_data; resp->out_data = req->in_data + 0x01020304; + if (ec->test_flags & CROSECT_BREAK_HELLO) + resp->out_data++; len = sizeof(*resp); break; } @@ -518,6 +523,13 @@ void cros_ec_check_keyboard(struct udevice *dev) } } +void sandbox_cros_ec_set_test_flags(struct udevice *dev, uint flags) +{ + struct ec_state *ec = dev_get_priv(dev); + + ec->test_flags = flags; +} + int cros_ec_probe(struct udevice *dev) { struct ec_state *ec = dev_get_priv(dev); diff --git a/include/cros_ec.h b/include/cros_ec.h index f187bd0d4b5..f57e0cc4501 100644 --- a/include/cros_ec.h +++ b/include/cros_ec.h @@ -497,4 +497,15 @@ int cros_ec_get_lid_shutdown_mask(struct udevice *dev); */ int cros_ec_set_lid_shutdown_mask(struct udevice *dev, int enable); +/** + * cros_ec_hello() - Send a hello message + * + * Sends a message with a fixed input value and checks that the expected output + * value is received + * + * @dev: CROS-EC device + * @handshakep: If non-NULL, returns received handshake value on error + * @return 0 if OK, -ve on error + */ +int cros_ec_hello(struct udevice *dev, uint *handshakep); #endif diff --git a/test/dm/Makefile b/test/dm/Makefile index 46e076ed099..afcabfacc1b 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -24,6 +24,7 @@ obj-$(CONFIG_BLK) += blk.o obj-$(CONFIG_BUTTON) += button.o obj-$(CONFIG_DM_BOOTCOUNT) += bootcount.o obj-$(CONFIG_CLK) += clk.o clk_ccf.o +obj-$(CONFIG_CROS_EC) += cros_ec.o obj-$(CONFIG_DEVRES) += devres.o obj-$(CONFIG_VIDEO_MIPI_DSI) += dsi_host.o obj-$(CONFIG_DM_ETH) += eth.o diff --git a/test/dm/cros_ec.c b/test/dm/cros_ec.c new file mode 100644 index 00000000000..823245ca70b --- /dev/null +++ b/test/dm/cros_ec.c @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright 2021 Google LLC + */ + +#include +#include +#include +#include +#include +#include + +static int dm_test_cros_ec_hello(struct unit_test_state *uts) +{ + struct udevice *dev; + uint val; + + ut_assertok(uclass_first_device_err(UCLASS_CROS_EC, &dev)); + + ut_assertok(cros_ec_hello(dev, NULL)); + + val = 0xdead1357; + ut_assertok(cros_ec_hello(dev, &val)); + ut_asserteq(0xdead1357, val); + + sandbox_cros_ec_set_test_flags(dev, CROSECT_BREAK_HELLO); + ut_asserteq(-ENOTSYNC, cros_ec_hello(dev, &val)); + ut_asserteq(0x12345678, val); + + return 0; +} +DM_TEST(dm_test_cros_ec_hello, UT_TESTF_SCAN_FDT); From patchwork Sat Jan 16 21:52:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1427605 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=blpW1V8m; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 ozlabs.org (Postfix) with ESMTPS id 4DJBfM5Yjnz9s24 for ; Sun, 17 Jan 2021 08:54:35 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2C1E0829D0; Sat, 16 Jan 2021 22:52:48 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="blpW1V8m"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A4D63829E2; Sat, 16 Jan 2021 22:52:42 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) (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 1576482986 for ; Sat, 16 Jan 2021 22:52:38 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd32.google.com with SMTP id d81so10245747iof.3 for ; Sat, 16 Jan 2021 13:52:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KE7+81twOD2jreR/YiAnMQznP4ggMDjojpnKekn5kd0=; b=blpW1V8mTo/uxYJCwwSl0EJUunPpCPj9MuGXsd2SM6EJlN1S8jDt1TIXDyQjVK4DoC RKH2QAJwUwVDJrwQ3M1tFZvbiSlOv/5oFHnx8EFcu5jRlHCFFYP+25xSEwFQ2Y3yywnV 89dKn5zxWbS5ZLhFuNhZ0Wi/se7w7f0jLkanQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KE7+81twOD2jreR/YiAnMQznP4ggMDjojpnKekn5kd0=; b=lpNoHPwuOnl2burRLSMRQ4m54CYWdFTWxAL/jI2tZPP6SGKuZZGA9LP8XL2jkJ9mTD Vtq0XQiEBXV/thiLlaZXTutEMwgyOrbr/37YnmZHaUV1B6ixZbpu7strlsce9s1QV2hL orNKTSai2Y4iemj50y5kiOQRctyImYxuIFoLLA1vREvP1xG0M0jNSBgW+BVAp6so5ycX 0JmJwHbg8E7+FieSspDSP+mTJxqPx8wX4SOYxYfJaUgJedbp2WNdmgUI/h3CgP9rKh6M UjNwQFmN6nP6lAH6O8EizOpLw+OSaZIcmJO2/iIDqCcWzS04uHTp0QS5PNh9IIsIFW8d bfPQ== X-Gm-Message-State: AOAM531KJ6RmZpN9X3jfftevTB2nN8jdSz7WSNowpY+4lnJBjkpWyqmb 8YimBHdPpFNxSdjQineYaikWqfSPbFbvBBFD X-Google-Smtp-Source: ABdhPJwWa4rflNbLnEbIOrZThuX537mxupCEnqWGl/rp3XZYoKFem5/U19uWGNBaD+44X+Sjb3vyfg== X-Received: by 2002:a05:6602:152:: with SMTP id v18mr12900663iot.187.1610833956715; Sat, 16 Jan 2021 13:52:36 -0800 (PST) Received: from localhost.localdomain (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id r1sm3356359iot.8.2021.01.16.13.52.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Jan 2021 13:52:36 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Alper Nebi Yasak Subject: [PATCH 02/10] cros_ec: Tidy up a few delays Date: Sat, 16 Jan 2021 14:52:23 -0700 Message-Id: <20210116145217.2.I74e07d56e163990e9a8ea6fad47efc0cb77ea6f8@changeid> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog In-Reply-To: <20210116215231.1220196-1-sjg@chromium.org> References: <20210116215231.1220196-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean Allow a longer time for the EC to reboot. Also use a constant for the hash delay time, so it is clear what it is for. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- drivers/misc/cros_ec.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c index 013c67e0464..ce5fa5bee35 100644 --- a/drivers/misc/cros_ec.c +++ b/drivers/misc/cros_ec.c @@ -44,6 +44,10 @@ enum { CROS_EC_CMD_TIMEOUT_MS = 5000, /* Timeout waiting for a synchronous hash to be recomputed */ CROS_EC_CMD_HASH_TIMEOUT_MS = 2000, + + /* Wait 10 ms between attempts to check if EC's hash is ready */ + CROS_EC_HASH_CHECK_DELAY_MS = 10, + }; #define INVALID_HCMD 0xFF @@ -502,9 +506,10 @@ static int cros_ec_wait_on_hash_done(struct udevice *dev, start = get_timer(0); while (hash->status == EC_VBOOT_HASH_STATUS_BUSY) { - mdelay(50); /* Insert some reasonable delay */ + mdelay(CROS_EC_HASH_CHECK_DELAY_MS); p->cmd = EC_VBOOT_HASH_GET; + if (ec_command(dev, EC_CMD_VBOOT_HASH, 0, p, sizeof(*p), hash, sizeof(*hash)) < 0) return -1; @@ -622,18 +627,23 @@ int cros_ec_reboot(struct udevice *dev, enum ec_reboot_cmd cmd, uint8_t flags) return -1; if (!(flags & EC_REBOOT_FLAG_ON_AP_SHUTDOWN)) { + ulong start; + /* * EC reboot will take place immediately so delay to allow it * to complete. Note that some reboot types (EC_REBOOT_COLD) * will reboot the AP as well, in which case we won't actually * get to this point. */ - /* - * TODO(rspangler@chromium.org): Would be nice if we had a - * better way to determine when the reboot is complete. Could - * we poll a memory-mapped LPC value? - */ - udelay(50000); + mdelay(50); + start = get_timer(0); + while (cros_ec_hello(dev, NULL)) { + if (get_timer(start) > 3000) { + log_err("EC did not return from reboot\n"); + return -ETIMEDOUT; + } + mdelay(5); + } } return 0; From patchwork Sat Jan 16 21:52:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1427606 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=mATfnIcM; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 ozlabs.org (Postfix) with ESMTPS id 4DJBfb7039z9s24 for ; Sun, 17 Jan 2021 08:54:47 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3A6FD829E6; Sat, 16 Jan 2021 22:52:51 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="mATfnIcM"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 78D9F829E6; Sat, 16 Jan 2021 22:52:43 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) (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 E871F829D0 for ; Sat, 16 Jan 2021 22:52:38 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd31.google.com with SMTP id d13so22162910ioy.4 for ; Sat, 16 Jan 2021 13:52:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=feEkezYd5ZEV9+lqZfRHiSvShLGKbJ7B1whLuOOsdDU=; b=mATfnIcMPscUDdvp1JZCAKf75VTuBjwoL6SxcTNivTKAaSzjoKD0SjoHOiAKFibyVy oTS6NiB5KnH8/biUncU3xVcNzzRsNu4XzS9FmqKDycSX/rFbBW1i+kkTxJyJNh6LB89r /bwK0PbnCCQBDljZBtQ0iAZIe0DnoDfqRe+Gw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=feEkezYd5ZEV9+lqZfRHiSvShLGKbJ7B1whLuOOsdDU=; b=p0/py9J/hCFY5iIvmLbSI9PA+Os53XdhLUAqHWOX4AJMZIkxJoGs1NsvxfNQ11sFop kwmSKq62rqOS0z/zO9oGXGKWfAGCY6MnyofQfm7dJwyQ7H8aWadrtNXmHa5NGn4UWO1U O3ya9jb/RZigVqL6e63Hh3EUVJyowVI8ue+Tv1lfVm85HXctMhf8HxlJb2hXINWD8z3x rijeSg5lskPpcDRF6ZoD+kdKJ7FaxLN0yW1K8krlt45qScbdLjDjmviH2tTKHExUrhQz WrLXqE9z1l7yATCKACwFfUcoEBR0rpyle6ZE9avrWyJEr/8zWSCnp8pIRndeFkKmzN1x JnFg== X-Gm-Message-State: AOAM533b3I9uA9mK8fgz4Q6/eHj7Hmp1cbdMystbyBa9EXY/sAnhsly7 8qRoBsqVY6ZnXzki6S1I/n7Hxdh+m5OWagS2 X-Google-Smtp-Source: ABdhPJwFuVMo59eufwQqoHVXLkAb8dZSxmSIG8VFq9DKFKp+IHZm+DBCQjqRK0JaMYHdPNCZsgLInQ== X-Received: by 2002:a92:a010:: with SMTP id e16mr3440856ili.38.1610833957623; Sat, 16 Jan 2021 13:52:37 -0800 (PST) Received: from localhost.localdomain (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id r1sm3356359iot.8.2021.01.16.13.52.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Jan 2021 13:52:37 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Alper Nebi Yasak Subject: [PATCH 03/10] cros_ec: Add run-time check for input buffer overflow Date: Sat, 16 Jan 2021 14:52:24 -0700 Message-Id: <20210116145217.3.I964a093c91639ceefb1a21142f52b7c2ba404343@changeid> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog In-Reply-To: <20210116215231.1220196-1-sjg@chromium.org> References: <20210116215231.1220196-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean This should not happen in normal operation, but the EC might have a bug, so add a run-time check just in case. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- drivers/misc/cros_ec.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c index ce5fa5bee35..e51ac874098 100644 --- a/drivers/misc/cros_ec.c +++ b/drivers/misc/cros_ec.c @@ -404,6 +404,8 @@ static int ec_command(struct udevice *dev, uint cmd, int cmd_version, */ if (din && in_buffer) { assert(len <= din_len); + if (len > din_len) + return -ENOSPC; memmove(din, in_buffer, len); } } From patchwork Sat Jan 16 21:52:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1427607 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=jM60Bwik; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 ozlabs.org (Postfix) with ESMTPS id 4DJBfr231bz9s24 for ; Sun, 17 Jan 2021 08:55:00 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C97A5829E9; Sat, 16 Jan 2021 22:52:53 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="jM60Bwik"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C909F829DD; Sat, 16 Jan 2021 22:52:43 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) (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 E69608295D for ; Sat, 16 Jan 2021 22:52:39 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd35.google.com with SMTP id y19so25409280iov.2 for ; Sat, 16 Jan 2021 13:52:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kcFCUZmfNngjoQZM77wZXPstEkL6gkXZ7EETbPVUUU0=; b=jM60Bwik9O4qUR1tZegMJpDlLBPkk2KaLRhwrCTIFx/G9X6cLss2GA47ooPzw45Inl ODPgWT9SOimhLr9ztV8CUyMSHbeRb9iGefNSPcBJ+f5WRfts9enhzHIz5Ao7I1mDePGz Amp9JavjBKuFb+f18Q1tTp80A3aTVlqn7rMdI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kcFCUZmfNngjoQZM77wZXPstEkL6gkXZ7EETbPVUUU0=; b=gDhZXPMraGT7Y69Um1h4bO/TRX14wAPIEEQHmxr5rbGRDZM06EWTZhKJ9fA3bOasQQ OJ6fQ0uG7KPKAytt8bG7WfR5gTr+lDIFI9K3tdfWY7WrqY2Qklcj79SB0g870Th7UWlr 0lxrMnP+kajhAUyBKjOtVlfQ5tGgSsfYAnlva/kgmhvCGMiaJQIc3GyqpHI7jWzTmfY0 a8LfxTlOkB14HvMoaxL4Ysb46PckxKz0gPnmXiEYEyUAZG9I19KCIZCn8/uBmhoCtLHl 7upRzmN8NgEpk3j5X0vqE8LJOsol7jPrFpj3njTrg0Gh6wcS3vM363WQid2tGYiIiCr8 i8ww== X-Gm-Message-State: AOAM531FGthxpE1o5QNGFPCKkKKs/bbyWoDW1S2wvgi3xEt+tTPVnBcK 5zZ8E0/SBC+V9J+Xd3FZ9FtelmKa52rz4Uap X-Google-Smtp-Source: ABdhPJzeN6TrevemDucnacibsRd9HT5Ar9Lz70q2J40RsC4GL6I+hoRLQoybK2wqbZt/rnCdi5e2+g== X-Received: by 2002:a5d:9588:: with SMTP id a8mr8364756ioo.34.1610833958557; Sat, 16 Jan 2021 13:52:38 -0800 (PST) Received: from localhost.localdomain (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id r1sm3356359iot.8.2021.01.16.13.52.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Jan 2021 13:52:38 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Alper Nebi Yasak , Heinrich Schuchardt , Pratyush Yadav , Walter Lozano Subject: [PATCH 04/10] cros_ec: Add support for reading the SKU ID Date: Sat, 16 Jan 2021 14:52:25 -0700 Message-Id: <20210116145217.4.I2b8d2365905f99d1010b92cad25300f5fe81b4d8@changeid> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog In-Reply-To: <20210116215231.1220196-1-sjg@chromium.org> References: <20210116215231.1220196-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean This allows reading strapping pins attached to the EC. Add an implementation for this. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- cmd/cros_ec.c | 10 ++++++++++ drivers/misc/cros_ec.c | 13 +++++++++++++ drivers/misc/cros_ec_sandbox.c | 7 +++++++ include/cros_ec.h | 8 ++++++++ test/dm/cros_ec.c | 17 +++++++++++++++++ 5 files changed, 55 insertions(+) diff --git a/cmd/cros_ec.c b/cmd/cros_ec.c index ce1f59a740c..4e85e184fee 100644 --- a/cmd/cros_ec.c +++ b/cmd/cros_ec.c @@ -352,6 +352,15 @@ static int do_cros_ec(struct cmd_tbl *cmdtp, int flag, int argc, debug("%s: Could not access LDO%d\n", __func__, index); return ret; } + } else if (!strcmp("sku", cmd)) { + ret = cros_ec_get_sku_id(dev); + + if (ret >= 0) { + printf("%d\n", ret); + ret = 0; + } else { + printf("Error: %d\n", ret); + } } else { return CMD_RET_USAGE; } @@ -382,6 +391,7 @@ U_BOOT_CMD( "crosec write [] Write EC image\n" "crosec vbnvcontext [hexstring] Read [write] VbNvContext from EC\n" "crosec ldo [] Switch/Read LDO state\n" + "crosec sku Read board SKU ID\n" "crosec test run tests on cros_ec\n" "crosec version Read CROS-EC version" ); diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c index e51ac874098..80709be2f15 100644 --- a/drivers/misc/cros_ec.c +++ b/drivers/misc/cros_ec.c @@ -1105,6 +1105,19 @@ int cros_ec_flash_update_rw(struct udevice *dev, const uint8_t *image, return 0; } +int cros_ec_get_sku_id(struct udevice *dev) +{ + struct ec_sku_id_info *r; + int ret; + + ret = ec_command_inptr(dev, EC_CMD_GET_SKU_ID, 0, NULL, 0, + (uint8_t **)&r, sizeof(*r)); + if (ret != sizeof(*r)) + return -ret; + + return r->sku_id; +} + int cros_ec_read_nvdata(struct udevice *dev, uint8_t *block, int size) { struct ec_params_vbnvcontext p; diff --git a/drivers/misc/cros_ec_sandbox.c b/drivers/misc/cros_ec_sandbox.c index 1922a9c1b96..93243847048 100644 --- a/drivers/misc/cros_ec_sandbox.c +++ b/drivers/misc/cros_ec_sandbox.c @@ -473,6 +473,13 @@ static int process_cmd(struct ec_state *ec, len = sizeof(*resp); break; } + case EC_CMD_GET_SKU_ID: { + struct ec_sku_id_info *resp = resp_data; + + resp->sku_id = 1234; + len = sizeof(*resp); + break; + } default: printf(" ** Unknown EC command %#02x\n", req_hdr->command); return -1; diff --git a/include/cros_ec.h b/include/cros_ec.h index f57e0cc4501..1154cdc52b8 100644 --- a/include/cros_ec.h +++ b/include/cros_ec.h @@ -329,6 +329,14 @@ int cros_ec_flash_write(struct udevice *dev, const uint8_t *data, int cros_ec_flash_offset(struct udevice *dev, enum ec_flash_region region, uint32_t *offset, uint32_t *size); +/** + * cros_ec_get_sku_id() - Read the SKU ID + * + * @dev: CROS-EC device + * return SKU ID, or -ve on error + */ +int cros_ec_get_sku_id(struct udevice *dev); + /** * Read/write non-volatile data from/to a CROS-EC device. * diff --git a/test/dm/cros_ec.c b/test/dm/cros_ec.c index 823245ca70b..3d0e5dc08d3 100644 --- a/test/dm/cros_ec.c +++ b/test/dm/cros_ec.c @@ -30,3 +30,20 @@ static int dm_test_cros_ec_hello(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_cros_ec_hello, UT_TESTF_SCAN_FDT); + +static int dm_test_cros_ec_sku_id(struct unit_test_state *uts) +{ + struct udevice *dev; + + ut_assertok(uclass_first_device_err(UCLASS_CROS_EC, &dev)); + ut_asserteq(1234, cros_ec_get_sku_id(dev)); + + /* try the command */ + console_record_reset(); + ut_assertok(run_command("crosec sku", 0)); + ut_assert_nextline("1234"); + ut_assert_console_end(); + + return 0; +} +DM_TEST(dm_test_cros_ec_sku_id, UT_TESTF_SCAN_FDT); From patchwork Sat Jan 16 21:52:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1427608 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=Vr1e7L5j; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 ozlabs.org (Postfix) with ESMTPS id 4DJBg33F33z9s24 for ; Sun, 17 Jan 2021 08:55:11 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4F0B1829ED; Sat, 16 Jan 2021 22:52:59 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Vr1e7L5j"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E859F829E8; Sat, 16 Jan 2021 22:52:45 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) (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 24BCA829C6 for ; Sat, 16 Jan 2021 22:52:41 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd29.google.com with SMTP id y19so25409320iov.2 for ; Sat, 16 Jan 2021 13:52:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pacA4RWT5A86zV114EfAbVw9piWW67FVvi5//YGisfM=; b=Vr1e7L5jWup24/Un4Q3yn3PyzcCO3yPnNJ8L0o2TM5x/u8QZzmgGsXKsUXKyx5HDkX ekbu1e4M3odBkevNeak9j2Za8H6SjN9MxKyl474AJrsRvw8yFD8R6s//kqpPwuiafCEw bqzN8o6gMEb9loX2bZ7xY6frOfzfOW+2i4nvU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pacA4RWT5A86zV114EfAbVw9piWW67FVvi5//YGisfM=; b=WbOyfEJqg6FQ/2239DVyTbHjafwveLiIy6eNkM6QTNMnsbvN/gKxXPd42IOO56IDZ/ GOCyH1B6rIvkc2UcjU1KjeFAMpYSpoOON1NOgtRN2UBl3xcgvoxl80rWsm/k7QOjBqRI w91TfrcieN5jsM/0tla8t/6nk9h77FRF+azgEDofkivUsd7nEk0YAjfUBe1+55q1guZ3 23Arut1iVifY6SrLSQCEnjwcWaGT3oqYLCO7q1p7Mk3EzDDNGZyLt8J65C4xyjrSVVxB YzT5v4580je+3lzR/fFRbrJKUOyienT3eEZ1U3q2N4yJPm2QbQlgd9/VzH5q58wGUDub ZdbA== X-Gm-Message-State: AOAM533kindV+deItq9OwtLDL78pKFmh01wv0NpJcuXmUddeki5reqUo I5MSeUF+yXr1Lcbc6tfifX7UagT/9KPXf3sh X-Google-Smtp-Source: ABdhPJykD5EujUAzyXAJ18Y3irE8Md2FQFde0PxnQPsdPh+zZUcpetgiKj56K/PzEQWZMy7t4AHbuQ== X-Received: by 2002:a92:c7c6:: with SMTP id g6mr856842ilk.248.1610833959610; Sat, 16 Jan 2021 13:52:39 -0800 (PST) Received: from localhost.localdomain (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id r1sm3356359iot.8.2021.01.16.13.52.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Jan 2021 13:52:39 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Alper Nebi Yasak , Andy Shevchenko , Heinrich Schuchardt , Pratyush Yadav , Walter Lozano Subject: [PATCH 05/10] cros_ec: Support reading EC features Date: Sat, 16 Jan 2021 14:52:26 -0700 Message-Id: <20210116145217.5.Ia423a771b966fba7f1d8a7d46164e1da71ec793d@changeid> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog In-Reply-To: <20210116215231.1220196-1-sjg@chromium.org> References: <20210116215231.1220196-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean The EC can support a variety of features and provides a way to find out what is available. Add support for this. Also update the feature list to the lastest available while we are here. This is at: https://chromium.googlesource.com/chromiumos/platform/ec/+/refs/heads/master/include/ec_commands.h Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- cmd/cros_ec.c | 74 ++++++++++++++++++++++++++++++++++ drivers/misc/cros_ec.c | 26 +++++++++--- drivers/misc/cros_ec_sandbox.c | 11 +++++ include/cros_ec.h | 21 ++++++++++ include/ec_commands.h | 45 +++++++++++++++++++-- test/dm/cros_ec.c | 28 +++++++++++++ 6 files changed, 195 insertions(+), 10 deletions(-) diff --git a/cmd/cros_ec.c b/cmd/cros_ec.c index 4e85e184fee..77656a2308c 100644 --- a/cmd/cros_ec.c +++ b/cmd/cros_ec.c @@ -94,6 +94,74 @@ static int do_read_write(struct udevice *dev, int is_write, int argc, return 0; } +static const char *const feat_name[64] = { + "limited", + "flash", + "pwm_fan", + "pwm_keyb", + "lightbar", + "led", + "motion_sense", + "keyb", + "pstore", + "port80", + "thermal", + "bklight_switch", + "wifi_switch", + "host_events", + "gpio", + "i2c", + "charger", + "battery", + "smart_battery", + "hang_detect", + "pmu", + "sub_mcu", + "usb_pd", + "usb_mux", + "motion_sense_fifo", + "vstore", + "usbc_ss_mux_virtual", + "rtc", + "fingerprint", + "touchpad", + "rwsig", + "device_event", + "unified_wake_masks", + "host_event64", + "exec_in_ram", + "cec", + "motion_sense_tight_timestamps", + "refined_tablet_mode_hysteresis", + "efs2", + "scp", + "ish", + "typec_cmd", + "typec_require_ap_mode_entry", + "typec_mux_require_ap_ack", +}; + +static int do_show_features(struct udevice *dev) +{ + u64 feat; + int ret; + uint i; + + ret = cros_ec_get_features(dev, &feat); + if (ret) + return ret; + for (i = 0; i < ARRAY_SIZE(feat_name); i++) { + if (feat & (1ULL << i)) { + if (feat_name[i]) + printf("%s\n", feat_name[i]); + else + printf("unknown %d\n", i); + } + } + + return 0; +} + static int do_cros_ec(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { @@ -140,6 +208,11 @@ static int do_cros_ec(struct cmd_tbl *cmdtp, int flag, int argc, } printf("rows = %u\n", info.rows); printf("cols = %u\n", info.cols); + } else if (!strcmp("features", cmd)) { + ret = do_show_features(dev); + + if (ret) + printf("Error: %d\n", ret); } else if (0 == strcmp("curimage", cmd)) { enum ec_current_image image; @@ -379,6 +452,7 @@ U_BOOT_CMD( "init Re-init CROS-EC (done on startup automatically)\n" "crosec id Read CROS-EC ID\n" "crosec info Read CROS-EC info\n" + "crosec features Read CROS-EC features\n" "crosec curimage Read CROS-EC current image\n" "crosec hash Read CROS-EC hash\n" "crosec reboot [rw | ro | cold] Reboot CROS-EC\n" diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c index 80709be2f15..fd2f2abd7e8 100644 --- a/drivers/misc/cros_ec.c +++ b/drivers/misc/cros_ec.c @@ -1344,19 +1344,33 @@ int cros_ec_i2c_tunnel(struct udevice *dev, int port, struct i2c_msg *in, return 0; } -int cros_ec_check_feature(struct udevice *dev, int feature) +int cros_ec_get_features(struct udevice *dev, u64 *featuresp) { struct ec_response_get_features r; int rv; - rv = ec_command(dev, EC_CMD_GET_FEATURES, 0, &r, sizeof(r), NULL, 0); - if (rv) - return rv; + rv = ec_command(dev, EC_CMD_GET_FEATURES, 0, NULL, 0, &r, sizeof(r)); + if (rv != sizeof(r)) + return -EIO; + *featuresp = r.flags[0] | (u64)r.flags[1] << 32; + + return 0; +} + +int cros_ec_check_feature(struct udevice *dev, uint feature) +{ + struct ec_response_get_features r; + int rv; + + rv = ec_command(dev, EC_CMD_GET_FEATURES, 0, NULL, 0, &r, sizeof(r)); + if (rv != sizeof(r)) + return -EIO; if (feature >= 8 * sizeof(r.flags)) - return -1; + return -EINVAL; - return r.flags[feature / 32] & EC_FEATURE_MASK_0(feature); + return r.flags[feature / 32] & EC_FEATURE_MASK_0(feature) ? true : + false; } /* diff --git a/drivers/misc/cros_ec_sandbox.c b/drivers/misc/cros_ec_sandbox.c index 93243847048..7213313c1ac 100644 --- a/drivers/misc/cros_ec_sandbox.c +++ b/drivers/misc/cros_ec_sandbox.c @@ -480,6 +480,17 @@ static int process_cmd(struct ec_state *ec, len = sizeof(*resp); break; } + case EC_CMD_GET_FEATURES: { + struct ec_response_get_features *resp = resp_data; + + resp->flags[0] = EC_FEATURE_MASK_0(EC_FEATURE_FLASH) | + EC_FEATURE_MASK_0(EC_FEATURE_I2C); + resp->flags[1] = + EC_FEATURE_MASK_1(EC_FEATURE_UNIFIED_WAKE_MASKS) | + EC_FEATURE_MASK_1(EC_FEATURE_ISH); + len = sizeof(*resp); + break; + } default: printf(" ** Unknown EC command %#02x\n", req_hdr->command); return -1; diff --git a/include/cros_ec.h b/include/cros_ec.h index 1154cdc52b8..338878c3bed 100644 --- a/include/cros_ec.h +++ b/include/cros_ec.h @@ -516,4 +516,25 @@ int cros_ec_set_lid_shutdown_mask(struct udevice *dev, int enable); * @return 0 if OK, -ve on error */ int cros_ec_hello(struct udevice *dev, uint *handshakep); + +/** + * cros_ec_get_features() - Get the set of features provided by the EC + * + * See enum ec_feature_code for the list of available features + * + * @dev: CROS-EC device + * @featuresp: Returns a bitmask of supported features + * @return 0 if OK, -ve on error + */ +int cros_ec_get_features(struct udevice *dev, u64 *featuresp); + +/** + * cros_ec_check_feature() - Check if a feature is supported + * + * @dev: CROS-EC device + * @feature: Feature number to check (enum ec_feature_code) + * @return true if supported, false if not, -ve on error + */ +int cros_ec_check_feature(struct udevice *dev, uint feature); + #endif diff --git a/include/ec_commands.h b/include/ec_commands.h index 444ba61e591..36f4a02f936 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -1101,13 +1101,50 @@ enum ec_feature_code { EC_FEATURE_DEVICE_EVENT = 31, /* EC supports the unified wake masks for LPC/eSPI systems */ EC_FEATURE_UNIFIED_WAKE_MASKS = 32, + /* EC supports 64-bit host events */ + EC_FEATURE_HOST_EVENT64 = 33, + /* EC runs code in RAM (not in place, a.k.a. XIP) */ + EC_FEATURE_EXEC_IN_RAM = 34, + /* EC supports CEC commands */ + EC_FEATURE_CEC = 35, + /* EC supports tight sensor timestamping. */ + EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36, + /* + * EC supports tablet mode detection aligned to Chrome and allows + * setting of threshold by host command using + * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. + */ + EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37, + /* + * Early Firmware Selection ver.2. Enabled by CONFIG_VBOOT_EFS2. + * Note this is a RO feature. So, a query (EC_CMD_GET_FEATURES) should + * be sent to RO to be precise. + */ + EC_FEATURE_EFS2 = 38, + /* The MCU is a System Companion Processor (SCP). */ + EC_FEATURE_SCP = 39, + /* The MCU is an Integrated Sensor Hub */ + EC_FEATURE_ISH = 40, + /* New TCPMv2 TYPEC_ prefaced commands supported */ + EC_FEATURE_TYPEC_CMD = 41, + /* + * The EC will wait for direction from the AP to enter Type-C alternate + * modes or USB4. + */ + EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY = 42, + /* + * The EC will wait for an acknowledge from the AP after setting the + * mux. + */ + EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK = 43, }; -#define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32)) -#define EC_FEATURE_MASK_1(event_code) (1UL << (event_code - 32)) -struct __ec_align4 ec_response_get_features { +#define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32) +#define EC_FEATURE_MASK_1(event_code) BIT(event_code - 32) + +struct ec_response_get_features { uint32_t flags[2]; -}; +} __ec_align4; /*****************************************************************************/ /* Get the board's SKU ID from EC */ diff --git a/test/dm/cros_ec.c b/test/dm/cros_ec.c index 3d0e5dc08d3..a1ec9fccf3a 100644 --- a/test/dm/cros_ec.c +++ b/test/dm/cros_ec.c @@ -47,3 +47,31 @@ static int dm_test_cros_ec_sku_id(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_cros_ec_sku_id, UT_TESTF_SCAN_FDT); + +static int dm_test_cros_ec_features(struct unit_test_state *uts) +{ + struct udevice *dev; + u64 feat; + + ut_assertok(uclass_first_device_err(UCLASS_CROS_EC, &dev)); + ut_assertok(cros_ec_get_features(dev, &feat)); + ut_asserteq_64(1U << EC_FEATURE_FLASH | 1U << EC_FEATURE_I2C | + 1ULL << EC_FEATURE_UNIFIED_WAKE_MASKS | 1ULL << EC_FEATURE_ISH, + feat); + + ut_asserteq(true, cros_ec_check_feature(dev, EC_FEATURE_I2C)); + ut_asserteq(false, cros_ec_check_feature(dev, EC_FEATURE_MOTION_SENSE)); + ut_asserteq(true, cros_ec_check_feature(dev, EC_FEATURE_ISH)); + + /* try the command */ + console_record_reset(); + ut_assertok(run_command("crosec features", 0)); + ut_assert_nextline("flash"); + ut_assert_nextline("i2c"); + ut_assert_nextline("unified_wake_masks"); + ut_assert_nextline("ish"); + ut_assert_console_end(); + + return 0; +} +DM_TEST(dm_test_cros_ec_features, UT_TESTF_SCAN_FDT); From patchwork Sat Jan 16 21:52:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1427609 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=EPH1krX/; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 ozlabs.org (Postfix) with ESMTPS id 4DJBgJ4h1Tz9s24 for ; Sun, 17 Jan 2021 08:55:24 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DF39E829F3; Sat, 16 Jan 2021 22:53:01 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="EPH1krX/"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E2D46829EC; Sat, 16 Jan 2021 22:52:46 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) (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 18EEA829E4 for ; Sat, 16 Jan 2021 22:52:42 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd2a.google.com with SMTP id y19so25409358iov.2 for ; Sat, 16 Jan 2021 13:52:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Qd/OqDxy3na0kMPTPDIxgbiRvIt9tYXAC6Fc7pcbX8E=; b=EPH1krX/Hn1cHA0N+1xhjutRMEChtZBVnU/ZCbw+s2A+Dz6h/1BPK8umse1uudZ40D /KJsmOz7tw6dI14MnCjl80rrTAWva8qYaOgOBcZxxYMQWKnUe5/0c690by1SO5Z+tTUI UqV1qz4Q+yVZEhfEOFL3xbZJ+AwvCL+HaVMWs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Qd/OqDxy3na0kMPTPDIxgbiRvIt9tYXAC6Fc7pcbX8E=; b=oRMoITqDs6zievAiTkcRVrcKqW/maNu0JBZG0LJTg94h5UjCQJqK+cd3B79hA7hJGL 9zKKVzJ6mPp+Syb8F12bYkcP21PTXYVvLpULCpgf0WRbRAUV+5XWREtcz7bYOx5ysQK5 r5xMydsQFS/otUocYSL9MXEyhJpnfiEheDGKEXY3mDO8K0Y5buu6vwoRdB22koiWed14 B1J4f3pdO+aWlEsOFYy7Kawsjm51moPVCmhRFWLEoGzA/8iKl9PE1koFAZg6LgsMqKDG uX836Q7K4dfyMsLFTjuwfCz56sFk5SgIabMfTOBoluyZyWbbvsJl82zWhKI/jwbJvXSJ 7VgQ== X-Gm-Message-State: AOAM533nS8HH9AylTiv9guWeQnRpt8elZsBUwwE8ARhDlEWPXe8dj8Nr 6ZZR142MUNSgNrIzces+VAy9mQ+YlGU3FfsA X-Google-Smtp-Source: ABdhPJxYzMEi/dGQ3M6SiTHmOt9TXICsJ19OTfpqhbD/fMG6AyQwRirvyHLyPmSkq/vVGhDTt5rvxA== X-Received: by 2002:a5e:840d:: with SMTP id h13mr13072311ioj.23.1610833960720; Sat, 16 Jan 2021 13:52:40 -0800 (PST) Received: from localhost.localdomain (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id r1sm3356359iot.8.2021.01.16.13.52.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Jan 2021 13:52:40 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Alper Nebi Yasak Subject: [PATCH 06/10] cros_ec: Add documentation for cros_ec driver operations Date: Sat, 16 Jan 2021 14:52:27 -0700 Message-Id: <20210116145217.6.I412e5d05d279e8f763eb90b2c4b3d54310f47578@changeid> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog In-Reply-To: <20210116215231.1220196-1-sjg@chromium.org> References: <20210116215231.1220196-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean Add comments to these methods so it is documented in this central place, not just in each driver. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- include/cros_ec.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/include/cros_ec.h b/include/cros_ec.h index 338878c3bed..26e3f3ba0cb 100644 --- a/include/cros_ec.h +++ b/include/cros_ec.h @@ -234,10 +234,50 @@ int cros_ec_flash_update_rw(struct udevice *dev, const uint8_t *image, struct udevice *board_get_cros_ec_dev(void); struct dm_cros_ec_ops { + /** + * check_version() - Check the protocol version being used (optional) + * + * If provided, this function should check that the EC can be supported + * by the driver. If not provided, HELLO messages will be sent to try + * to determine the protocol version. + * + * @dev: Device to check + * @return 0 if the protocol is valid, -ve if not supported + */ int (*check_version)(struct udevice *dev); + + /** + * command() - Old-style command interface + * + * This sends a command and receives a response (deprecated, use + * packet()) + * + * @dev: Device to use + * @cmd: Command to send (only supports 0-0xff) + * @cmd_version: Version of command to send (often 0) + * @dout: Output data (may be NULL If dout_len=0) + * @dout_len: Length of output data excluding 4-byte header + * @dinp: On input, set to point to input data, often struct + * cros_ec_dev->din - typically this is left alone but may be + * updated by the driver + * @din_len: Maximum length of response + * @return number of bytes in response, or -ve on error + */ int (*command)(struct udevice *dev, uint8_t cmd, int cmd_version, const uint8_t *dout, int dout_len, uint8_t **dinp, int din_len); + + /** + * packet() - New-style command interface + * + * This interface is preferred over command(), since it is typically + * easier to implement. + * + * @dev: Device to use + * @out_bytes: Number of bytes to send (from struct cros_ec_dev->dout) + * @in_bytes: Maximum number of bytes to expect in response + * @return number of bytes in response, or -ve on error + */ int (*packet)(struct udevice *dev, int out_bytes, int in_bytes); }; From patchwork Sat Jan 16 21:52:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1427610 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=dwouJ3i7; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 ozlabs.org (Postfix) with ESMTPS id 4DJBgY6TTdz9s24 for ; Sun, 17 Jan 2021 08:55:37 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AC7CD829F8; Sat, 16 Jan 2021 22:53:04 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="dwouJ3i7"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3023E829B1; Sat, 16 Jan 2021 22:52:49 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) (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 4BC96829E2 for ; Sat, 16 Jan 2021 22:52:43 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd32.google.com with SMTP id e22so25375655iom.5 for ; Sat, 16 Jan 2021 13:52:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fQNAnq3zfqRSs9BpfVXbT6+cQ++qVNQuhWIg6mTtyJU=; b=dwouJ3i7bxf2xZGQluZcMrj5eJPmrcWcmTOb6UpmAEC7dBSxK52NTDlm3rypz1KlQ0 1+w6H/aqKRUVSFTznW/yHDwVSBVUjiMGUf4AsCX0lAkCNZB9h4qeYbrFFdx5JUxT3yFt OezHL5C28IHjzg4y9f85yxgmev9LhPVnoPibs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fQNAnq3zfqRSs9BpfVXbT6+cQ++qVNQuhWIg6mTtyJU=; b=BFgyFv24IIj4rp6lHqkTG+rCek9c7fEXqVdy5jIWz3aCpdddbI77cIhCKi3R2Tu/IZ YyOaZGezgvEkk/jK3XTqPnZWRmbGouF7oUIRJ8vOjtDod0XDtKOxluh2vMcjd9Zb9Ahe NcNdOBRnGm43xPZJo7Kt/lNyo2h53pow5QW9BGlTiaKQR98fbOtyjrXGODaC3TdtMLEb 3EeaksbCjL8cYge2ok1ln3JPnZBSsQTGlS5jWQ05kj95yVrf6K2U1EBgsfAsZq80slGd prVvDOSM/vkgxa794f9yQW34AFPG6LPuBNYzfnQqaczkkdwtB2uHz/UttuHFbVzedi7J iMgw== X-Gm-Message-State: AOAM531MSKPa4UwPXsfzgKR8TBiCY4ahWOtolpF1Gp0G8mA5JLHYqrLv 9W3c9Hc+B37qIn2A+iSHN9H7EioZN02/2pdF X-Google-Smtp-Source: ABdhPJznOuvOSiqlW0w4Od9PSU9Daqh2R9kgv5UToZ7PEvul8qGPGbzPR6oDNsrVajktVeeqt7OstQ== X-Received: by 2002:a05:6e02:1c2a:: with SMTP id m10mr16535641ilh.17.1610833961778; Sat, 16 Jan 2021 13:52:41 -0800 (PST) Received: from localhost.localdomain (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id r1sm3356359iot.8.2021.01.16.13.52.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Jan 2021 13:52:41 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Alper Nebi Yasak , Andy Shevchenko , Bin Meng , Heinrich Schuchardt , Ovidiu Panait , Pratyush Yadav , Walter Lozano Subject: [PATCH 07/10] cros_ec: Add support for switches Date: Sat, 16 Jan 2021 14:52:28 -0700 Message-Id: <20210116145217.7.I39bf1e6dafa91da8c42ca29d6bc5e4199509cf9b@changeid> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog In-Reply-To: <20210116215231.1220196-1-sjg@chromium.org> References: <20210116215231.1220196-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean On x86 platforms the EC provides a way to read 'switches', which are on/off values determined by the EC. Add a new driver method for this and implement it for LPC. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- arch/sandbox/include/asm/test.h | 1 + cmd/cros_ec.c | 41 +++++++++++++++++++++++++++++++++ drivers/misc/cros_ec.c | 16 +++++++++++++ drivers/misc/cros_ec_lpc.c | 7 ++++++ drivers/misc/cros_ec_sandbox.c | 10 ++++++++ include/cros_ec.h | 19 +++++++++++++++ test/dm/cros_ec.c | 26 +++++++++++++++++++++ 7 files changed, 120 insertions(+) diff --git a/arch/sandbox/include/asm/test.h b/arch/sandbox/include/asm/test.h index 8363ca73195..1cb960ac240 100644 --- a/arch/sandbox/include/asm/test.h +++ b/arch/sandbox/include/asm/test.h @@ -61,6 +61,7 @@ enum { */ enum cros_ec_test_t { CROSECT_BREAK_HELLO = BIT(1), + CROSECT_LID_OPEN = BIT(2), }; /** diff --git a/cmd/cros_ec.c b/cmd/cros_ec.c index 77656a2308c..a222c75c17c 100644 --- a/cmd/cros_ec.c +++ b/cmd/cros_ec.c @@ -162,6 +162,41 @@ static int do_show_features(struct udevice *dev) return 0; } +static const char *const switch_name[8] = { + "lid open", + "power button pressed", + "write-protect disabled", + NULL, + "dedicated recovery", + NULL, + NULL, + NULL, +}; + +static int do_show_switches(struct udevice *dev) +{ + uint switches; + int ret; + uint i; + + ret = cros_ec_get_switches(dev); + if (ret < 0) + return log_msg_ret("get", ret); + switches = ret; + for (i = 0; i < ARRAY_SIZE(switch_name); i++) { + uint mask = 1 << i; + + if (switches & mask) { + if (switch_name[i]) + printf("%s\n", switch_name[i]); + else + printf("unknown %02x\n", mask); + } + } + + return 0; +} + static int do_cros_ec(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { @@ -211,6 +246,11 @@ static int do_cros_ec(struct cmd_tbl *cmdtp, int flag, int argc, } else if (!strcmp("features", cmd)) { ret = do_show_features(dev); + if (ret) + printf("Error: %d\n", ret); + } else if (!strcmp("switches", cmd)) { + ret = do_show_switches(dev); + if (ret) printf("Error: %d\n", ret); } else if (0 == strcmp("curimage", cmd)) { @@ -453,6 +493,7 @@ U_BOOT_CMD( "crosec id Read CROS-EC ID\n" "crosec info Read CROS-EC info\n" "crosec features Read CROS-EC features\n" + "crosec switches Read CROS-EC switches\n" "crosec curimage Read CROS-EC current image\n" "crosec hash Read CROS-EC hash\n" "crosec reboot [rw | ro | cold] Reboot CROS-EC\n" diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c index fd2f2abd7e8..0bc28e882c9 100644 --- a/drivers/misc/cros_ec.c +++ b/drivers/misc/cros_ec.c @@ -1557,6 +1557,22 @@ int cros_ec_set_lid_shutdown_mask(struct udevice *dev, int enable) return 0; } +int cros_ec_get_switches(struct udevice *dev) +{ + struct dm_cros_ec_ops *ops; + int ret; + + ops = dm_cros_ec_get_ops(dev); + if (!ops->get_switches) + return -ENOSYS; + + ret = ops->get_switches(dev); + if (ret < 0) + return log_msg_ret("get", ret); + + return ret; +} + UCLASS_DRIVER(cros_ec) = { .id = UCLASS_CROS_EC, .name = "cros-ec", diff --git a/drivers/misc/cros_ec_lpc.c b/drivers/misc/cros_ec_lpc.c index e0002b9753f..f40375978dd 100644 --- a/drivers/misc/cros_ec_lpc.c +++ b/drivers/misc/cros_ec_lpc.c @@ -207,6 +207,12 @@ int cros_ec_lpc_init(struct cros_ec_dev *dev, const void *blob) return 0; } +/* Return the byte of EC switch states */ +static int cros_ec_lpc_get_switches(struct udevice *dev) +{ + return inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SWITCHES); +} + /* * Test if LPC command args are supported. * @@ -239,6 +245,7 @@ static struct dm_cros_ec_ops cros_ec_ops = { .packet = cros_ec_lpc_packet, .command = cros_ec_lpc_command, .check_version = cros_ec_lpc_check_version, + .get_switches = cros_ec_lpc_get_switches, }; static const struct udevice_id cros_ec_ids[] = { diff --git a/drivers/misc/cros_ec_sandbox.c b/drivers/misc/cros_ec_sandbox.c index 7213313c1ac..38a2614a993 100644 --- a/drivers/misc/cros_ec_sandbox.c +++ b/drivers/misc/cros_ec_sandbox.c @@ -75,6 +75,7 @@ struct ec_keymatrix_entry { * @keyscan: Current keyscan information (bit set for each row/column pressed) * @recovery_req: Keyboard recovery requested * @test_flags: Flags that control behaviour for tests + * @switches: Current switches value (EC_SWITCH_) */ struct ec_state { u8 vbnv_context[EC_VBNV_BLOCK_SIZE_V2]; @@ -541,6 +542,14 @@ void cros_ec_check_keyboard(struct udevice *dev) } } +/* Return the byte of EC switch states */ +static int cros_ec_sandbox_get_switches(struct udevice *dev) +{ + struct ec_state *ec = dev_get_priv(dev); + + return ec->test_flags & CROSECT_LID_OPEN ? EC_SWITCH_LID_OPEN : 0; +} + void sandbox_cros_ec_set_test_flags(struct udevice *dev, uint flags) { struct ec_state *ec = dev_get_priv(dev); @@ -603,6 +612,7 @@ int cros_ec_probe(struct udevice *dev) struct dm_cros_ec_ops cros_ec_ops = { .packet = cros_ec_sandbox_packet, + .get_switches = cros_ec_sandbox_get_switches, }; static const struct udevice_id cros_ec_ids[] = { diff --git a/include/cros_ec.h b/include/cros_ec.h index 26e3f3ba0cb..cb91343e3d8 100644 --- a/include/cros_ec.h +++ b/include/cros_ec.h @@ -279,6 +279,16 @@ struct dm_cros_ec_ops { * @return number of bytes in response, or -ve on error */ int (*packet)(struct udevice *dev, int out_bytes, int in_bytes); + + /** + * get_switches() - Get value of EC switches + * + * This is currently supported on the LPC EC. + * + * @dev: Device to use + * @return current switches value, or -ENOSYS if not supported + */ + int (*get_switches)(struct udevice *dev); }; #define dm_cros_ec_get_ops(dev) \ @@ -577,4 +587,13 @@ int cros_ec_get_features(struct udevice *dev, u64 *featuresp); */ int cros_ec_check_feature(struct udevice *dev, uint feature); +/** + * cros_ec_get_switches() - Get switches value + * + * @dev: CROS-EC device + * @return switches value, or -ENOSYS if not supported, or other -ve value on + * other error + */ +int cros_ec_get_switches(struct udevice *dev); + #endif diff --git a/test/dm/cros_ec.c b/test/dm/cros_ec.c index a1ec9fccf3a..43774400a1e 100644 --- a/test/dm/cros_ec.c +++ b/test/dm/cros_ec.c @@ -75,3 +75,29 @@ static int dm_test_cros_ec_features(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_cros_ec_features, UT_TESTF_SCAN_FDT); + +static int dm_test_cros_ec_switches(struct unit_test_state *uts) +{ + struct udevice *dev; + + ut_assertok(uclass_first_device_err(UCLASS_CROS_EC, &dev)); + ut_asserteq(0, cros_ec_get_switches(dev)); + + /* try the command */ + console_record_reset(); + ut_assertok(run_command("crosec switches", 0)); + ut_assert_console_end(); + + /* Open the lid and check the switch changes */ + sandbox_cros_ec_set_test_flags(dev, CROSECT_LID_OPEN); + ut_asserteq(EC_SWITCH_LID_OPEN, cros_ec_get_switches(dev)); + + /* try the command */ + console_record_reset(); + ut_assertok(run_command("crosec switches", 0)); + ut_assert_nextline("lid open"); + ut_assert_console_end(); + + return 0; +} +DM_TEST(dm_test_cros_ec_switches, UT_TESTF_SCAN_FDT); From patchwork Sat Jan 16 21:52:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1427611 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=imuApW0A; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 ozlabs.org (Postfix) with ESMTPS id 4DJBgm6G00z9sWF for ; Sun, 17 Jan 2021 08:55:48 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8427582A0A; Sat, 16 Jan 2021 22:53:06 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="imuApW0A"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 842B5829E2; Sat, 16 Jan 2021 22:52:50 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd34.google.com (mail-io1-xd34.google.com [IPv6:2607:f8b0:4864:20::d34]) (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 40F13829E6 for ; Sat, 16 Jan 2021 22:52:44 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd34.google.com with SMTP id e22so25375690iom.5 for ; Sat, 16 Jan 2021 13:52:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wv/OGkoZJDuUGXTx2YDhmZdb5iXJmhIH8aTQ1ZWXZec=; b=imuApW0AV803cohohyOdog7wUSH21Q0yQISmbiZLRp0+Kkmp6zw3ydDTI2JhpG7pF+ 0zpZleOUJM697CnF9svRhLQe37Iv0lAi++l2pfg0lITgoeNV28TU9wjvRiUem/es+tW6 WG17R0vf2RNHdWVW1eg7nsi5tmNzly7N1LlJo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wv/OGkoZJDuUGXTx2YDhmZdb5iXJmhIH8aTQ1ZWXZec=; b=TdEvjk54WcutdfApI9cm1I1jDFDhPnLtc150gViDH0Jis+UTeHcUZFO0w8rRB2HpPl PgJ/q9CIgBq4cU90zskUnpaU7WlMNzBp3GNsWcfOab7Bq/ni47/eKVbJpEeykRJNUn+U Z1R5zVInPGTf9njdvUv7GOywaOc8VVIM+Vge1ndglafcg6LuGLAu2ZUuWGYryW6Q49z2 bAcPQz4u+HSpE4UomhJ5W9mOIMLI20DCcBpIkfJa+ziGeyVhPBs8SKvEdS21An5VEgde epZRxPe7BdeBj3E7TTF55aTbYyfUAnBQhNkw354IcehtHFwHagXT5U4DBjzZla2oKEnO hONw== X-Gm-Message-State: AOAM531Pfm6yC84eclbpVJWJlJHUSPW6FmyHSNd78t9b64uBnndDY0nS FckbUXWSwvgbsvmoX2akNHTZZ3qa4fzJWh3M X-Google-Smtp-Source: ABdhPJwHiYPRNhtEKuWWLbGNTXtVuAAO+w/3LjXNUu2GxNDLnuKcxomsGHEqOmzi4+I0flqPFlAaBw== X-Received: by 2002:a6b:c981:: with SMTP id z123mr8314453iof.206.1610833962849; Sat, 16 Jan 2021 13:52:42 -0800 (PST) Received: from localhost.localdomain (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id r1sm3356359iot.8.2021.01.16.13.52.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Jan 2021 13:52:42 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Alper Nebi Yasak , Andy Shevchenko , Heinrich Schuchardt , Pratyush Yadav , Walter Lozano Subject: [PATCH 08/10] cros_ec: Show events in human-readable form Date: Sat, 16 Jan 2021 14:52:29 -0700 Message-Id: <20210116145217.8.Icf77de451c8f0083adb05631e088f5fca3fc51fe@changeid> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog In-Reply-To: <20210116215231.1220196-1-sjg@chromium.org> References: <20210116215231.1220196-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean Add a command to show the current events as a list of names. This is easier to decipher than a bit mask. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- cmd/cros_ec.c | 70 +++++++++++++++++++++++++++++++--- drivers/misc/cros_ec_sandbox.c | 12 +++++- test/dm/cros_ec.c | 37 ++++++++++++++++++ 3 files changed, 112 insertions(+), 7 deletions(-) diff --git a/cmd/cros_ec.c b/cmd/cros_ec.c index a222c75c17c..eb5053d6424 100644 --- a/cmd/cros_ec.c +++ b/cmd/cros_ec.c @@ -197,6 +197,66 @@ static int do_show_switches(struct udevice *dev) return 0; } +static const char *const event_name[] = { + "lid_closed", + "lid_open", + "power_button", + "ac_connected", + "ac_disconnected", + "battery_low", + "battery_critical", + "battery", + "thermal_threshold", + "device", + "thermal", + "usb_charger", + "key_pressed", + "interface_ready", + "keyboard_recovery", + "thermal_shutdown", + "battery_shutdown", + "throttle_start", + "throttle_stop", + "hang_detect", + "hang_reboot", + "pd_mcu", + "battery_status", + "panic", + "keyboard_fastboot", + "rtc", + "mkbp", + "usb_mux", + "mode_change", + "keyboard_recovery_hw_reinit", + "extended", + "invalid", +}; + +static int do_show_events(struct udevice *dev) +{ + u32 events; + int ret; + uint i; + + ret = cros_ec_get_host_events(dev, &events); + if (ret) + return ret; + printf("%08x\n", events); + for (i = 0; i < ARRAY_SIZE(event_name); i++) { + enum host_event_code code = i + 1; + u64 mask = EC_HOST_EVENT_MASK(code); + + if (events & mask) { + if (event_name[i]) + printf("%s\n", event_name[i]); + else + printf("unknown code %#x\n", code); + } + } + + return 0; +} + static int do_cros_ec(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { @@ -303,13 +363,10 @@ static int do_cros_ec(struct cmd_tbl *cmdtp, int flag, int argc, return 1; } } else if (0 == strcmp("events", cmd)) { - uint32_t events; + ret = do_show_events(dev); - if (cros_ec_get_host_events(dev, &events)) { - debug("%s: Could not read host events\n", __func__); - return 1; - } - printf("0x%08x\n", events); + if (ret) + printf("Error: %d\n", ret); } else if (0 == strcmp("clrevents", cmd)) { uint32_t events = 0x7fffffff; @@ -498,6 +555,7 @@ U_BOOT_CMD( "crosec hash Read CROS-EC hash\n" "crosec reboot [rw | ro | cold] Reboot CROS-EC\n" "crosec events Read CROS-EC host events\n" + "crosec eventsb Read CROS-EC host events_b\n" "crosec clrevents [mask] Clear CROS-EC host events\n" "crosec regioninfo Read image info\n" "crosec flashinfo Read flash info\n" diff --git a/drivers/misc/cros_ec_sandbox.c b/drivers/misc/cros_ec_sandbox.c index 38a2614a993..845876cfb0c 100644 --- a/drivers/misc/cros_ec_sandbox.c +++ b/drivers/misc/cros_ec_sandbox.c @@ -364,10 +364,20 @@ static int process_cmd(struct ec_state *ec, resp->mask |= EC_HOST_EVENT_MASK( EC_HOST_EVENT_KEYBOARD_RECOVERY); } - + if (ec->test_flags & CROSECT_LID_OPEN) + resp->mask |= + EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN); len = sizeof(*resp); break; } + case EC_CMD_HOST_EVENT_CLEAR_B: { + const struct ec_params_host_event_mask *req = req_data; + + if (req->mask & EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN)) + ec->test_flags &= ~CROSECT_LID_OPEN; + len = 0; + break; + } case EC_CMD_VBOOT_HASH: { const struct ec_params_vboot_hash *req = req_data; struct ec_response_vboot_hash *resp = resp_data; diff --git a/test/dm/cros_ec.c b/test/dm/cros_ec.c index 43774400a1e..0da7548fd24 100644 --- a/test/dm/cros_ec.c +++ b/test/dm/cros_ec.c @@ -101,3 +101,40 @@ static int dm_test_cros_ec_switches(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_cros_ec_switches, UT_TESTF_SCAN_FDT); + +static int dm_test_cros_ec_events(struct unit_test_state *uts) +{ + struct udevice *dev; + u32 events; + + ut_assertok(uclass_first_device_err(UCLASS_CROS_EC, &dev)); + ut_assertok(cros_ec_get_host_events(dev, &events)); + ut_asserteq(0, events); + + /* try the command */ + console_record_reset(); + ut_assertok(run_command("crosec events", 0)); + ut_assert_nextline("00000000"); + ut_assert_console_end(); + + /* Open the lid and check the event appears */ + sandbox_cros_ec_set_test_flags(dev, CROSECT_LID_OPEN); + ut_assertok(cros_ec_get_host_events(dev, &events)); + ut_asserteq(EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN), events); + + /* try the command */ + console_record_reset(); + ut_assertok(run_command("crosec events", 0)); + ut_assert_nextline("00000002"); + ut_assert_nextline("lid_open"); + ut_assert_console_end(); + + /* Clear the event */ + ut_assertok(cros_ec_clear_host_events(dev, + EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN))); + ut_assertok(cros_ec_get_host_events(dev, &events)); + ut_asserteq(0, events); + + return 0; +} +DM_TEST(dm_test_cros_ec_events, UT_TESTF_SCAN_FDT); From patchwork Sat Jan 16 21:52:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1427614 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=NCYDjxsn; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 ozlabs.org (Postfix) with ESMTPS id 4DJBgz2TXvz9s24 for ; Sun, 17 Jan 2021 08:55:59 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6AE6F82A0E; Sat, 16 Jan 2021 22:53:08 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="NCYDjxsn"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 03CC7829E7; Sat, 16 Jan 2021 22:52:50 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd2e.google.com (mail-io1-xd2e.google.com [IPv6:2607:f8b0:4864:20::d2e]) (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 1551D82986 for ; Sat, 16 Jan 2021 22:52:45 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd2e.google.com with SMTP id w18so25429775iot.0 for ; Sat, 16 Jan 2021 13:52:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=u16cUqha1n+/9x43w1/Feq7B+VXe+4NxDa3BcBohvzc=; b=NCYDjxsnYJdfHWRYVi7RpF+rEhnCy2IWkazm+DKbdH/k2QKFjz5glKSckfUwfJou0O 6CCxB1ILk7Ew3jUHwmGVnMiGFIAmxQ8TGGmPKyCSBrAg2NoEV4ajeINAVPiFeaOrx62F yjbjrvyGJ3yqR4iq9mxjJop4XggspEKk+G+8g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=u16cUqha1n+/9x43w1/Feq7B+VXe+4NxDa3BcBohvzc=; b=R/qQwKexTCGW6qsBD2wSFRyKCxQezkcCNaSX1wrfpJcVIllV0+zBFSoRJvS0AJrDxi nlBceq4Xn/IbYy11PpwkD/YS00I+RqNUs1mVWp7/E8MngY54aF73buAJ+ox7ofEaMK1l E1AgzjHpBoPdLOz259FGmA9ohH8ocw89kddRamoAGsIAg25bIocRXoOV61HW915wfmiA 7ZRwidtIG/VKihpVvOfIT9YovYHdzBRudn4ps63bLn4Da4uablchVRzlAtgzVsa+cBhZ UdPR5yt4MVkTn1U/lEanln/Y7Z0Ymx6mlLPxuEFJsiLmdAzolpPrwe4sIW0f8mGZPuyp 8QWA== X-Gm-Message-State: AOAM532txsJUxrC2FYdYrMhazaSK3H55bHhaJHEPrTSFJstB4cKJlWmk ASP4+1SOh8SoI5AydJEEbwddPRrAc5PFaY/n X-Google-Smtp-Source: ABdhPJxjjknqHGZov3/gXwztbNGwmxRyL0DmdU24GXX/6RPTEXZ/Mii8RSEV7G1iTyYaKCqqsNTX9w== X-Received: by 2002:a92:c102:: with SMTP id p2mr15667573ile.254.1610833963797; Sat, 16 Jan 2021 13:52:43 -0800 (PST) Received: from localhost.localdomain (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id r1sm3356359iot.8.2021.01.16.13.52.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Jan 2021 13:52:43 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Alper Nebi Yasak Subject: [PATCH 09/10] cros_ec: Allow use with of-platdata Date: Sat, 16 Jan 2021 14:52:30 -0700 Message-Id: <20210116145217.9.I9f0f824e3c0d73f0242af00523cbc18874855c95@changeid> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog In-Reply-To: <20210116215231.1220196-1-sjg@chromium.org> References: <20210116215231.1220196-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean Avoid reading the device tree when of-platdata is in use. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- drivers/misc/cros_ec.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c index 0bc28e882c9..c22bb4b5b50 100644 --- a/drivers/misc/cros_ec.c +++ b/drivers/misc/cros_ec.c @@ -1577,6 +1577,8 @@ UCLASS_DRIVER(cros_ec) = { .id = UCLASS_CROS_EC, .name = "cros-ec", .per_device_auto = sizeof(struct cros_ec_dev), +#if !CONFIG_IS_ENABLED(OF_PLATDATA) .post_bind = dm_scan_fdt_dev, +#endif .flags = DM_UC_FLAG_ALLOC_PRIV_DMA, }; From patchwork Sat Jan 16 21:52:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1427615 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=gALKN6bC; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 ozlabs.org (Postfix) with ESMTPS id 4DJBhC1w5fz9s24 for ; Sun, 17 Jan 2021 08:56:11 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EE08282A14; Sat, 16 Jan 2021 22:53:09 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="gALKN6bC"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5532B829E2; Sat, 16 Jan 2021 22:52:51 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) (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 41665829E9 for ; Sat, 16 Jan 2021 22:52:46 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd36.google.com with SMTP id e22so25375769iom.5 for ; Sat, 16 Jan 2021 13:52:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1PFsnM7baNcZu16RQwWaKRmEQVy2uyhZSSc/P9pyq9E=; b=gALKN6bC/x9rwOBst+BUGeIXispNnpEtWzZJ+1nBHDzBYlClH9EQQ8EfTxzZIdZDBp g+BbBV1iZdPzvhjQFjGA5VaZxUuYIyl+wIqGSbJO17QIizHpFcMwtaeFquD0cGPipBQD q7AESCaUxsJ4aQPplwSdYKY38BBBQ+9YuwUUM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1PFsnM7baNcZu16RQwWaKRmEQVy2uyhZSSc/P9pyq9E=; b=FQyaYs7l4+PKeuqeDPF/WsR0u+4ECnyU3HBBqoy6nDo+31uYRuQ4GxvqrkuscRbua7 KwX1MYjBkg9x+pCdL0tDyhGzaE5C/94gYm6lBuHnHtce4lfwxK6L1hnEF9Nr9prDrrnU R8jo+4CYrFDWVtsA4BWHZ2ffeA9FUj1p8oPhYYyN0ZlOa79dJP9XoyTHGp2yK6NHlUNT NmIr4PQWn1tbdaq26BXhubCPNhi7hb1Fg9m+RdyurXHKucXjFCpp4F60+glQiAVUKpcP mKO/5wXEH1mLJ+q/QDMb6EVt82iRWH1tSBEpZX/lXYrU2+RXXiP267B1BCC+/lh4vVPj VBXg== X-Gm-Message-State: AOAM530Q+NtjOOO06w37nsSrQ7axWATJQeNLc37tZKnw5WkYrpS9EyHi bqOI5NmeoL1Rcb7M2qbpesLE9rJ2kTTOU98c X-Google-Smtp-Source: ABdhPJx+9E/9YN+AmQREstjB0xwIJ2emgs8PN5B5xS9G3qfuI3y9BbiaQPioaYFke+7GyAXbwuSjVA== X-Received: by 2002:a6b:7704:: with SMTP id n4mr12821690iom.159.1610833964804; Sat, 16 Jan 2021 13:52:44 -0800 (PST) Received: from localhost.localdomain (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id r1sm3356359iot.8.2021.01.16.13.52.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Jan 2021 13:52:44 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Alper Nebi Yasak , Andy Shevchenko , Heinrich Schuchardt , Walter Lozano Subject: [PATCH 10/10] cros_ec: Add vstore support Date: Sat, 16 Jan 2021 14:52:31 -0700 Message-Id: <20210116145217.10.I3acf20d585d8985e7f8d8aa579429b21d7d452aa@changeid> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog In-Reply-To: <20210116215231.1220196-1-sjg@chromium.org> References: <20210116215231.1220196-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean The EC can store small amounts of data for the benefit of the verified boot process. Since the EC is seldom reset, this can allow the AP to store data that survives a reboot or a suspend/resume cycle. Add support for this. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- drivers/misc/cros_ec.c | 71 ++++++++++++++++++++++++++++++++++ drivers/misc/cros_ec_sandbox.c | 52 ++++++++++++++++++++++++- include/cros_ec.h | 43 ++++++++++++++++++++ test/dm/cros_ec.c | 38 ++++++++++++++++++ 4 files changed, 202 insertions(+), 2 deletions(-) diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c index c22bb4b5b50..ebfa7c41c25 100644 --- a/drivers/misc/cros_ec.c +++ b/drivers/misc/cros_ec.c @@ -1557,6 +1557,77 @@ int cros_ec_set_lid_shutdown_mask(struct udevice *dev, int enable) return 0; } +int cros_ec_vstore_supported(struct udevice *dev) +{ + return cros_ec_check_feature(dev, EC_FEATURE_VSTORE); +} + +int cros_ec_vstore_info(struct udevice *dev, u32 *lockedp) +{ + struct ec_response_vstore_info *resp; + + if (ec_command_inptr(dev, EC_CMD_VSTORE_INFO, 0, NULL, 0, + (uint8_t **)&resp, sizeof(*resp)) != sizeof(*resp)) + return -EIO; + + if (lockedp) + *lockedp = resp->slot_locked; + + return resp->slot_count; +} + +/* + * cros_ec_vstore_read - Read data from EC vstore slot + * + * @slot: vstore slot to read from + * @data: buffer to store read data, must be EC_VSTORE_SLOT_SIZE bytes + */ +int cros_ec_vstore_read(struct udevice *dev, int slot, uint8_t *data) +{ + struct ec_params_vstore_read req; + struct ec_response_vstore_read *resp; + + req.slot = slot; + if (ec_command_inptr(dev, EC_CMD_VSTORE_READ, 0, &req, sizeof(req), + (uint8_t **)&resp, sizeof(*resp)) != sizeof(*resp)) + return -EIO; + + if (!data || req.slot >= EC_VSTORE_SLOT_MAX) + return -EINVAL; + + memcpy(data, resp->data, sizeof(resp->data)); + + return 0; +} + +/* + * cros_ec_vstore_write - Save data into EC vstore slot + * + * @slot: vstore slot to write into + * @data: data to write + * @size: size of data in bytes + * + * Maximum size of data is EC_VSTORE_SLOT_SIZE. It is the callers + * responsibility to check the number of implemented slots by + * querying the vstore info. + */ +int cros_ec_vstore_write(struct udevice *dev, int slot, const uint8_t *data, + size_t size) +{ + struct ec_params_vstore_write req; + + if (slot >= EC_VSTORE_SLOT_MAX || size > EC_VSTORE_SLOT_SIZE) + return -EINVAL; + + req.slot = slot; + memcpy(req.data, data, size); + + if (ec_command(dev, EC_CMD_VSTORE_WRITE, 0, &req, sizeof(req), NULL, 0)) + return -EIO; + + return 0; +} + int cros_ec_get_switches(struct udevice *dev) { struct dm_cros_ec_ops *ops; diff --git a/drivers/misc/cros_ec_sandbox.c b/drivers/misc/cros_ec_sandbox.c index 845876cfb0c..cb8adc4495a 100644 --- a/drivers/misc/cros_ec_sandbox.c +++ b/drivers/misc/cros_ec_sandbox.c @@ -62,6 +62,15 @@ struct ec_keymatrix_entry { int keycode; /* corresponding linux key code */ }; +enum { + VSTORE_SLOT_COUNT = 4, +}; + +struct vstore_slot { + bool locked; + u8 data[EC_VSTORE_SLOT_SIZE]; +}; + /** * struct ec_state - Information about the EC state * @@ -75,7 +84,7 @@ struct ec_keymatrix_entry { * @keyscan: Current keyscan information (bit set for each row/column pressed) * @recovery_req: Keyboard recovery requested * @test_flags: Flags that control behaviour for tests - * @switches: Current switches value (EC_SWITCH_) + * @slot_locked: Locked vstore slots (mask) */ struct ec_state { u8 vbnv_context[EC_VBNV_BLOCK_SIZE_V2]; @@ -88,6 +97,7 @@ struct ec_state { uint8_t keyscan[KEYBOARD_COLS]; bool recovery_req; uint test_flags; + struct vstore_slot slot[VSTORE_SLOT_COUNT]; } s_state, *g_state; /** @@ -495,13 +505,51 @@ static int process_cmd(struct ec_state *ec, struct ec_response_get_features *resp = resp_data; resp->flags[0] = EC_FEATURE_MASK_0(EC_FEATURE_FLASH) | - EC_FEATURE_MASK_0(EC_FEATURE_I2C); + EC_FEATURE_MASK_0(EC_FEATURE_I2C) | + EC_FEATURE_MASK_0(EC_FEATURE_VSTORE); resp->flags[1] = EC_FEATURE_MASK_1(EC_FEATURE_UNIFIED_WAKE_MASKS) | EC_FEATURE_MASK_1(EC_FEATURE_ISH); len = sizeof(*resp); break; } + case EC_CMD_VSTORE_INFO: { + struct ec_response_vstore_info *resp = resp_data; + int i; + + resp->slot_count = VSTORE_SLOT_COUNT; + resp->slot_locked = 0; + for (i = 0; i < VSTORE_SLOT_COUNT; i++) { + if (ec->slot[i].locked) + resp->slot_locked |= 1 << i; + } + len = sizeof(*resp); + break; + }; + case EC_CMD_VSTORE_WRITE: { + const struct ec_params_vstore_write *req = req_data; + struct vstore_slot *slot; + + if (req->slot >= EC_VSTORE_SLOT_MAX) + return -EINVAL; + slot = &ec->slot[req->slot]; + slot->locked = true; + memcpy(slot->data, req->data, EC_VSTORE_SLOT_SIZE); + len = 0; + break; + } + case EC_CMD_VSTORE_READ: { + const struct ec_params_vstore_read *req = req_data; + struct ec_response_vstore_read *resp = resp_data; + struct vstore_slot *slot; + + if (req->slot >= EC_VSTORE_SLOT_MAX) + return -EINVAL; + slot = &ec->slot[req->slot]; + memcpy(resp->data, slot->data, EC_VSTORE_SLOT_SIZE); + len = sizeof(*resp); + break; + } default: printf(" ** Unknown EC command %#02x\n", req_hdr->command); return -1; diff --git a/include/cros_ec.h b/include/cros_ec.h index cb91343e3d8..eddc23d48f8 100644 --- a/include/cros_ec.h +++ b/include/cros_ec.h @@ -596,4 +596,47 @@ int cros_ec_check_feature(struct udevice *dev, uint feature); */ int cros_ec_get_switches(struct udevice *dev); +/** + * cros_ec_vstore_supported() - Check if vstore is supported + * + * @dev: CROS-EC device + * @return false if not supported, true if supported, -ve on error + */ +int cros_ec_vstore_supported(struct udevice *dev); + +/** + * cros_ec_vstore_info() - Get vstore information + * + * @dev: CROS-EC device + * @lockedp: mask of locked slots + * @return number of vstore slots supported by the EC,, -ve on error + */ +int cros_ec_vstore_info(struct udevice *dev, u32 *lockedp); + +/** + * cros_ec_vstore_read() - Read data from EC vstore slot + * + * @dev: CROS-EC device + * @slot: vstore slot to read from + * @data: buffer to store read data, must be EC_VSTORE_SLOT_SIZE bytes + * @return 0 if OK, -ve on error + */ +int cros_ec_vstore_read(struct udevice *dev, int slot, uint8_t *data); + +/** + * cros_ec_vstore_write() - Save data into EC vstore slot + * + * The maximum size of data is EC_VSTORE_SLOT_SIZE. It is the caller's + * responsibility to check the number of implemented slots by querying the + * vstore info. + * + * @dev: CROS-EC device + * @slot: vstore slot to write into + * @data: data to write + * @size: size of data in bytes + * @return 0 if OK, -ve on error + */ +int cros_ec_vstore_write(struct udevice *dev, int slot, const uint8_t *data, + size_t size); + #endif diff --git a/test/dm/cros_ec.c b/test/dm/cros_ec.c index 0da7548fd24..30cb70e0882 100644 --- a/test/dm/cros_ec.c +++ b/test/dm/cros_ec.c @@ -56,6 +56,7 @@ static int dm_test_cros_ec_features(struct unit_test_state *uts) ut_assertok(uclass_first_device_err(UCLASS_CROS_EC, &dev)); ut_assertok(cros_ec_get_features(dev, &feat)); ut_asserteq_64(1U << EC_FEATURE_FLASH | 1U << EC_FEATURE_I2C | + 1u << EC_FEATURE_VSTORE | 1ULL << EC_FEATURE_UNIFIED_WAKE_MASKS | 1ULL << EC_FEATURE_ISH, feat); @@ -68,6 +69,7 @@ static int dm_test_cros_ec_features(struct unit_test_state *uts) ut_assertok(run_command("crosec features", 0)); ut_assert_nextline("flash"); ut_assert_nextline("i2c"); + ut_assert_nextline("vstore"); ut_assert_nextline("unified_wake_masks"); ut_assert_nextline("ish"); ut_assert_console_end(); @@ -138,3 +140,39 @@ static int dm_test_cros_ec_events(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_cros_ec_events, UT_TESTF_SCAN_FDT); + +static int dm_test_cros_ec_vstore(struct unit_test_state *uts) +{ + const int size = EC_VSTORE_SLOT_SIZE; + u8 test_data[size], data[size]; + struct udevice *dev; + u32 locked; + int i; + + ut_assertok(uclass_first_device_err(UCLASS_CROS_EC, &dev)); + ut_asserteq(true, cros_ec_vstore_supported(dev)); + + ut_asserteq(4, cros_ec_vstore_info(dev, &locked)); + ut_asserteq(0, locked); + + /* Write some data */ + for (i = 0; i < size; i++) + test_data[i] = ' ' + i; + ut_assertok(cros_ec_vstore_write(dev, 2, test_data, size)); + + /* Check it is locked */ + ut_asserteq(4, cros_ec_vstore_info(dev, &locked)); + ut_asserteq(1 << 2, locked); + + /* Read it back and compare */ + ut_assertok(cros_ec_vstore_read(dev, 2, data)); + ut_asserteq_mem(test_data, data, size); + + /* Try another slot to make sure it is empty */ + ut_assertok(cros_ec_vstore_read(dev, 0, data)); + for (i = 0; i < size; i++) + ut_asserteq(0, data[i]); + + return 0; +} +DM_TEST(dm_test_cros_ec_vstore, UT_TESTF_SCAN_FDT);