From patchwork Thu Sep 17 16:35:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 1366265 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (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 4BsjMg1ByFz9sRR for ; Fri, 18 Sep 2020 02:38:39 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=kaod.org Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4BsjMg0BJFzDqfK for ; Fri, 18 Sep 2020 02:38:39 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=kaod.org (client-ip=178.32.125.2; helo=smtpout1.mo529.mail-out.ovh.net; envelope-from=clg@kaod.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=kaod.org Received: from smtpout1.mo529.mail-out.ovh.net (smtpout1.mo529.mail-out.ovh.net [178.32.125.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4BsjJY1BdWzDqc9 for ; Fri, 18 Sep 2020 02:35:52 +1000 (AEST) Received: from mxplan5.mail.ovh.net (unknown [10.109.143.206]) by mo529.mail-out.ovh.net (Postfix) with ESMTPS id B77565C30D0A; Thu, 17 Sep 2020 18:35:48 +0200 (CEST) Received: from kaod.org (37.59.142.96) by DAG4EX1.mxp5.local (172.16.2.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2044.4; Thu, 17 Sep 2020 18:35:48 +0200 Authentication-Results: garm.ovh; auth=pass (GARM-96R001b2a3e9ca-3a2d-45fa-943d-c37db3333984, FF1720B74B3888C93CA5040C1F5ACCC945AC33B8) smtp.auth=clg@kaod.org From: =?utf-8?q?C=C3=A9dric_Le_Goater?= To: Date: Thu, 17 Sep 2020 18:35:44 +0200 Message-ID: <20200917163544.142593-8-clg@kaod.org> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200917163544.142593-1-clg@kaod.org> References: <20200917163544.142593-1-clg@kaod.org> MIME-Version: 1.0 X-Originating-IP: [37.59.142.96] X-ClientProxiedBy: DAG1EX1.mxp5.local (172.16.2.1) To DAG4EX1.mxp5.local (172.16.2.31) X-Ovh-Tracer-GUID: 3e3d51ea-5582-4d4e-9e2a-85a1b5464958 X-Ovh-Tracer-Id: 10404441042471848925 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedujedrtdeggddutdehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufffkffojghfgggtgfhisehtkeertdertdejnecuhfhrohhmpeevrogurhhitgcunfgvucfiohgrthgvrhcuoegtlhhgsehkrghougdrohhrgheqnecuggftrfgrthhtvghrnhepheehfeegjeeitdfffeetjeduveejueefuefgtdefueelueetveeliefhhffgtdelnecukfhppedtrddtrddtrddtpdefjedrheelrddugedvrdelieenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhhouggvpehsmhhtphdqohhuthdphhgvlhhopehmgihplhgrnhehrdhmrghilhdrohhvhhdrnhgvthdpihhnvghtpedtrddtrddtrddtpdhmrghilhhfrhhomheptghlgheskhgrohgurdhorhhgpdhrtghpthhtoheptghlgheskhgrohgurdhorhhg Subject: [Skiboot] [RFC PATCH linux] powerpc/powernv: Add support for OPAL_DEBUG_READ/WRITE X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Signed-off-by: Cédric Le Goater --- arch/powerpc/include/asm/opal-api.h | 4 +- arch/powerpc/include/asm/opal.h | 2 + arch/powerpc/platforms/powernv/opal-call.c | 2 + arch/powerpc/platforms/powernv/opal-debug.c | 124 ++++++++++++++++++++ arch/powerpc/platforms/powernv/opal.c | 2 + arch/powerpc/platforms/powernv/Makefile | 1 + 6 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 arch/powerpc/platforms/powernv/opal-debug.c diff --git a/arch/powerpc/include/asm/opal-api.h b/arch/powerpc/include/asm/opal-api.h index 1dffa3cb16ba..1a4ac8d1d944 100644 --- a/arch/powerpc/include/asm/opal-api.h +++ b/arch/powerpc/include/asm/opal-api.h @@ -214,7 +214,9 @@ #define OPAL_SECVAR_GET 176 #define OPAL_SECVAR_GET_NEXT 177 #define OPAL_SECVAR_ENQUEUE_UPDATE 178 -#define OPAL_LAST 178 +#define OPAL_DEBUG_READ 181 +#define OPAL_DEBUG_WRITE 182 +#define OPAL_LAST 182 #define QUIESCE_HOLD 1 /* Spin all calls at entry */ #define QUIESCE_REJECT 2 /* Fail all calls with OPAL_BUSY */ diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h index 9986ac34b8e2..97f236180abc 100644 --- a/arch/powerpc/include/asm/opal.h +++ b/arch/powerpc/include/asm/opal.h @@ -311,6 +311,8 @@ s64 opal_mpipl_query_tag(enum opal_mpipl_tags tag, u64 *addr); s64 opal_signal_system_reset(s32 cpu); s64 opal_quiesce(u64 shutdown_type, s32 cpu); +int64_t opal_debug_read(uint64_t id, uint64_t buf, uint64_t size); +int64_t opal_debug_write(uint64_t id, uint64_t buf, uint64_t size); /* Internal functions */ extern int early_init_dt_scan_opal(unsigned long node, const char *uname, diff --git a/arch/powerpc/platforms/powernv/opal-call.c b/arch/powerpc/platforms/powernv/opal-call.c index 5cd0f52d258f..c7e109220956 100644 --- a/arch/powerpc/platforms/powernv/opal-call.c +++ b/arch/powerpc/platforms/powernv/opal-call.c @@ -293,3 +293,5 @@ OPAL_CALL(opal_mpipl_query_tag, OPAL_MPIPL_QUERY_TAG); OPAL_CALL(opal_secvar_get, OPAL_SECVAR_GET); OPAL_CALL(opal_secvar_get_next, OPAL_SECVAR_GET_NEXT); OPAL_CALL(opal_secvar_enqueue_update, OPAL_SECVAR_ENQUEUE_UPDATE); +OPAL_CALL(opal_debug_read, OPAL_DEBUG_READ); +OPAL_CALL(opal_debug_write, OPAL_DEBUG_WRITE); diff --git a/arch/powerpc/platforms/powernv/opal-debug.c b/arch/powerpc/platforms/powernv/opal-debug.c new file mode 100644 index 000000000000..59fe9ea310a1 --- /dev/null +++ b/arch/powerpc/platforms/powernv/opal-debug.c @@ -0,0 +1,124 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * PowerNV OPAL debugfs interface + * + * Copyright 2020 IBM Corp. + */ + +#define pr_fmt(fmt) "opal-stat: " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int opal_debug_show(struct seq_file *m, void *p) +{ + u64 id = (u64) m->private; + int size = PAGE_SIZE; + char *buf; + int rc; + + buf = kzalloc(size, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + rc = opal_debug_read(id, __pa(buf), size); + if (rc < 0) { + rc = opal_error_code(rc); + } else { + seq_puts(m, buf); + rc = 0; + } + + kfree(buf); + return rc; +} + +static int opal_debug_open(struct inode *inode, struct file *file) +{ + return single_open(file, opal_debug_show, inode->i_private); +} + +static ssize_t opal_debug_do_write(struct file *file, const char __user *user_buf, + size_t count, loff_t *ppos) +{ + u64 id = (u64) file_inode(file)->i_private; + char buf[8] = { 0 }; + char *data; + size_t size; + int rc; + + size = min(sizeof(buf) - 1, count); + if (copy_from_user(buf, user_buf, size)) + return -EFAULT; + data = strim(buf); + + rc = opal_debug_write(id, __pa(data), size); + if (rc < 0) + return opal_error_code(rc); + + return count; +} + +static const struct file_operations opal_debug_ops = { + .open = opal_debug_open, + .write = opal_debug_do_write, + .read = seq_read, + .llseek = no_llseek, + .release = single_release, +}; + +static struct dentry *debug_dir; + +static int opal_debug_probe(struct platform_device *pdev) +{ + struct device_node *node = pdev->dev.of_node; + u32 reg; + const char *label; + const char *name; + u32 chip_id; + + if (of_property_read_u32(node, "reg", ®)) { + pr_warn("OPAL: 'reg' property not found\n"); + return -ENODEV; + } + + if (of_property_read_string(node, "label", &label)) + label = node->name; + + if (!of_property_read_u32(node, "ibm,chip-id", &chip_id)) + name = kasprintf(GFP_KERNEL, "%s-%x", label, chip_id); + else + name = kasprintf(GFP_KERNEL, "%s", label); + + if (!debug_dir) + debug_dir = debugfs_create_dir("opal-debug", + powerpc_debugfs_root); + + debugfs_create_file(name, 0644, debug_dir, (void *) (u64) reg, + &opal_debug_ops); + kfree(name); + return 0; +} + +static const struct of_device_id opal_debug_of_match[] = { + { .compatible = "ibm,opal-debug" }, + { } +}; + +static struct platform_driver opal_debug_driver = { + .probe = opal_debug_probe, + .driver = { + .name = "opal-debug", + .of_match_table = opal_debug_of_match, + }, +}; + +builtin_platform_driver(opal_debug_driver); diff --git a/arch/powerpc/platforms/powernv/opal.c b/arch/powerpc/platforms/powernv/opal.c index d95954ad4c0a..c883cf0db655 100644 --- a/arch/powerpc/platforms/powernv/opal.c +++ b/arch/powerpc/platforms/powernv/opal.c @@ -1093,6 +1093,8 @@ static int __init opal_init(void) /* Initialize OPAL secure variables */ opal_pdev_init("ibm,secvar-backend"); + opal_pdev_init("ibm,opal-debug"); + return 0; } machine_subsys_initcall(powernv, opal_init); diff --git a/arch/powerpc/platforms/powernv/Makefile b/arch/powerpc/platforms/powernv/Makefile index 2eb6ae150d1f..9cfd3942e0e8 100644 --- a/arch/powerpc/platforms/powernv/Makefile +++ b/arch/powerpc/platforms/powernv/Makefile @@ -5,6 +5,7 @@ obj-y += rng.o opal-elog.o opal-dump.o opal-sysparam.o opal-sensor.o obj-y += opal-msglog.o opal-hmi.o opal-power.o opal-irqchip.o obj-y += opal-kmsg.o opal-powercap.o opal-psr.o opal-sensor-groups.o obj-y += ultravisor.o +obj-y += opal-debug.o obj-$(CONFIG_SMP) += smp.o subcore.o subcore-asm.o obj-$(CONFIG_FA_DUMP) += opal-fadump.o