Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp802005yba; Thu, 18 Apr 2019 09:45:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqz5bc47tNXLe5SA4uvj5u7YKJ+YtuKP9DDEfndkiETnJGBzLNmpXWhKI1M3MAVlTnthsQcT X-Received: by 2002:a63:fc5a:: with SMTP id r26mr85394185pgk.97.1555605955185; Thu, 18 Apr 2019 09:45:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555605955; cv=none; d=google.com; s=arc-20160816; b=eqXNHNr/xtI8n8jiBsVWYdOIEiV9NkFKtwaYhh5lifFQMjZZ07+fz3Z7WnzFsvZPli 6dGpVDmN1mvXIMrvye3+eMY3JYNwwHgQjOmMo2ym+ViDho4q0GSoNsyWrt4ZWWYqJ+EQ 9daTo8wqDS9sGVxUiQQaqo6V9moTO6QbOEjw91B/+RytNrr0nyV900kPXaD49YgAmRaE MPiySeuR7qXF5DQbNuEC5Xi+OHHfW/yuzlWZ8AEmYA8cA1z1XzeWp33Rpdk6SsPoPmN4 eXxh4Dm7H7ZmYFlTlZhQOyDaDVF2x1z08l+GYyHD4L/z8MWhg4r0baZKHFTHdbCC8EBp pCCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mptKACXQhQgDUMyPlZCGnxz/gjpJxP41cGsb1cPqYVU=; b=0VmPE9Z3KM97FpXZ02FJ6GniS8PUe2UFnRZJG1zSxCnk8/cce1kMcIDSHItH07Syjb w6mmqTS79Cj5Kp2eC1NELiDVw40+HIYjBazVN0LQ36uHluWhmYIyqQ3UFtBmGCLqb0ta Ls9wCeqRTxD5B/dOE0WgQ8Mb/ziep8OyInAT+Ej/847bOukakcPqTB1esNRluyh65aNB 9A35VOvlw1wqIzPMcr6mFjQZ5bYuFjg7/p1gQu1nxbM86FOp95xi0sKs5GBjDS0WG2tw GHJJFHF24JiKfOjEkcZ9Y/sW3Ss/iblRa6lp7WL7PjdO1ShOrBqlzrQOEszLmmuZQMNH We8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Jas9PT7h; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o2si2319134pgv.144.2019.04.18.09.45.40; Thu, 18 Apr 2019 09:45:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Jas9PT7h; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389714AbfDRQov (ORCPT + 99 others); Thu, 18 Apr 2019 12:44:51 -0400 Received: from mail-io1-f67.google.com ([209.85.166.67]:46475 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388388AbfDRQov (ORCPT ); Thu, 18 Apr 2019 12:44:51 -0400 Received: by mail-io1-f67.google.com with SMTP id p23so2382106iol.13 for ; Thu, 18 Apr 2019 09:44:50 -0700 (PDT) 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=mptKACXQhQgDUMyPlZCGnxz/gjpJxP41cGsb1cPqYVU=; b=Jas9PT7hRyxdXVOrAwhsvVbuZB04g9Z9xXlLTgglV+UCs12tYcgeTH6adJhAKAfCd2 lVPvCz3e7j0DEzqo5dDdlq4TuCtgbEHTqPhAtH080DR/kc8OfXuLI8seB45BFcqUdbOy oqBG/Fl+fXDnjPvrMFrgDxoJbdlxlYWBx6Pls= 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=mptKACXQhQgDUMyPlZCGnxz/gjpJxP41cGsb1cPqYVU=; b=D1gsFm8zaXLs62jo88kSf0akY48n8FhJQIEUJds6EyoUCfHmY7imMrU7R5kyiJM4Oz Wd3E5tbZ0bc9ywWH7Hjv7YfHVqKotNPv6jFDCU41T4+mJHQ5jOYfkvWurtZ2R9kHnv5M uLLE3SWtmKw19VHh3sqhRGZkbRPU/Ox8tF+epjwf/wklKQ9+S3OjANaJqPBp3flSlyk9 Q8LNqPwuGNRiNtm03MKOjo++Hq4VXEys39ha8GRqMvQBnTHb5j608oDVHiFnnEKRedDk 7SGfd3ma9I1qb2NNKlyjRWsZsSj70zLeNwqSo4J3s9JdklDCMS0elIbTydShzii6L/8F RYPw== X-Gm-Message-State: APjAAAWAeMa3IEZHC+gPV4mqQRVpzXMGraLJw6UCnzQ+PULqfc0ws7HA Y7VM2eFGTORGF5FYuMYZqOqbsw== X-Received: by 2002:a5d:9cd5:: with SMTP id w21mr5012126iow.298.1555605889928; Thu, 18 Apr 2019 09:44:49 -0700 (PDT) Received: from twawrzynczak.bld.corp.google.com ([2620:15c:183:200:3175:8c2d:44b6:cfea]) by smtp.gmail.com with ESMTPSA id u26sm851675iob.78.2019.04.18.09.44.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 18 Apr 2019 09:44:49 -0700 (PDT) From: Tim Wawrzynczak To: Tim Wawrzynczak Cc: EnricBalletboiSerraenric.balletbo@collabora.com, Benson Leung , Olof Johansson , linux-kernel@vger.kernel.org Subject: [PATCH v4] platform/chrome: mfd/cros_ec_debugfs: Add debugfs entry to retrieve EC uptime. Date: Thu, 18 Apr 2019 10:44:44 -0600 Message-Id: <20190418164444.258107-1-twawrzynczak@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190325170250.2547-1-twawrzynczak@chromium.org> References: <20190325170250.2547-1-twawrzynczak@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The new debugfs entry 'uptime' is being made available to userspace so that a userspace daemon can synchronize EC logs with host time. Signed-off-by: Tim Wawrzynczak --- Enric, AFAIK only the cros_ec supports the 'uptime' command for now. And yes, the file does need to be seekable; the userspace daemon that consumes the file keeps the file open and seeks back to the beginning to get the latest uptime value. Based on your second response to v3, I kept the separate 'create_uptime' function b/c of the logic for checking support for the uptime command. Let me know if you'd like me to move all of that logic into _probe. Changelist from v3: 1) Don't check return values of debugfs_* functions. 2) Only expose 'uptime' file if EC supports it. --- Documentation/ABI/testing/debugfs-cros-ec | 10 +++ drivers/platform/chrome/cros_ec_debugfs.c | 78 +++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 Documentation/ABI/testing/debugfs-cros-ec diff --git a/Documentation/ABI/testing/debugfs-cros-ec b/Documentation/ABI/testing/debugfs-cros-ec new file mode 100644 index 000000000000..24b781c67a4c --- /dev/null +++ b/Documentation/ABI/testing/debugfs-cros-ec @@ -0,0 +1,10 @@ +What: /sys/kernel/debug/cros_ec/uptime +Date: March 2019 +KernelVersion: 5.1 +Description: + Read-only. + Reads the EC's current uptime information + (using EC_CMD_GET_UPTIME_INFO) and prints + time_since_ec_boot_ms into the file. + This is used for synchronizing AP host time + with the cros_ec log. diff --git a/drivers/platform/chrome/cros_ec_debugfs.c b/drivers/platform/chrome/cros_ec_debugfs.c index 71308766e891..226545a2150b 100644 --- a/drivers/platform/chrome/cros_ec_debugfs.c +++ b/drivers/platform/chrome/cros_ec_debugfs.c @@ -201,6 +201,50 @@ static int cros_ec_console_log_release(struct inode *inode, struct file *file) return 0; } +static int cros_ec_get_uptime(struct cros_ec_device *ec_dev, u32 *uptime) +{ + struct { + struct cros_ec_command msg; + struct ec_response_uptime_info resp; + } __packed ec_buf; + struct ec_response_uptime_info *resp; + struct cros_ec_command *msg; + + msg = &ec_buf.msg; + resp = (struct ec_response_uptime_info *)msg->data; + + msg->command = EC_CMD_GET_UPTIME_INFO; + msg->version = 0; + msg->insize = sizeof(*resp); + msg->outsize = 0; + + ret = cros_ec_cmd_xfer_status(ec_dev, msg); + if (ret < 0) + return ret; + + *uptime = resp->time_since_ec_boot_ms; + return 0; +} + +static ssize_t cros_ec_uptime_read(struct file *file, + char __user *user_buf, + size_t count, + loff_t *ppos) +{ + struct cros_ec_debugfs *debug_info = file->private_data; + struct cros_ec_device *ec_dev = debug_info->ec->ec_dev; + char read_buf[32]; + int ret; + u32 uptime; + + ret = cros_ec_get_uptime(ec_dev, &uptime); + if (ret < 0) + return ret; + + ret = scnprintf(read_buf, sizeof(read_buf), "%u\n", uptime); + return simple_read_from_buffer(user_buf, count, ppos, read_buf, ret); +} + static ssize_t cros_ec_pdinfo_read(struct file *file, char __user *user_buf, size_t count, @@ -269,6 +313,13 @@ const struct file_operations cros_ec_pdinfo_fops = { .llseek = default_llseek, }; +const struct file_operations cros_ec_uptime_fops = { + .owner = THIS_MODULE, + .open = simple_open, + .read = cros_ec_uptime_read, + .llseek = default_llseek, +}; + static int ec_read_version_supported(struct cros_ec_dev *ec) { struct ec_params_get_cmd_versions_v1 *params; @@ -413,6 +464,29 @@ static int cros_ec_create_pdinfo(struct cros_ec_debugfs *debug_info) return 0; } +static int cros_ec_create_uptime(struct cros_ec_debugfs *debug_info) +{ + struct cros_ec_debugfs *debug_info = file->private_data; + struct cros_ec_device *ec_dev = debug_info->ec->ec_dev; + u32 uptime; + int ret; + + /* + * If the EC does not support the uptime command, which is + * indicated by xfer_status() returning -EINVAL, then no + * debugfs entry will be created. + */ + ret = cros_ec_get_uptime(ec_dev, &uptime); + + if (ret == -EINVAL) + return supported; + + debugfs_create_file("uptime", 0444, debug_info->dir, debug_info, + &cros_ec_uptime_fops); + + return 0; +} + static int cros_ec_debugfs_probe(struct platform_device *pd) { struct cros_ec_dev *ec = dev_get_drvdata(pd->dev.parent); @@ -442,6 +516,10 @@ static int cros_ec_debugfs_probe(struct platform_device *pd) if (ret) goto remove_log; + ret = cros_ec_create_uptime(debug_info); + if (ret) + goto remove_log; + ec->debug_info = debug_info; dev_set_drvdata(&pd->dev, ec); -- 2.20.1