From patchwork Mon Nov 26 07:52:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 151976 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp5328745ljp; Sun, 25 Nov 2018 23:53:22 -0800 (PST) X-Google-Smtp-Source: AFSGD/WnDCZu+fPc7FCjicsLaSoGXBqh9A32ngjh5mXThfACLXQk8FWFMQL+e2kULQbsvBIytT4c X-Received: by 2002:a17:902:7107:: with SMTP id a7mr26323278pll.290.1543218801899; Sun, 25 Nov 2018 23:53:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543218801; cv=none; d=google.com; s=arc-20160816; b=wEMGLeYgQ2KVU9+gN7G4zitWe6+IFBxS/jKM1R/FfnfXoGSN2ZtbTT3rcRdsLFAKHs KFlvIk7eAvhNpjhuZMiCl4Zh6yldTqsZXUJGlTYIWHUSJBAi1/VQyJsGF/6zNG7/Yb/X 0IsfTJUzWCdW7fOnIT7Dd5uPmXNczw40882y4OQSDeQpNsgR3lKwRMnWFK0loDHf70wL ZgyT4+TEkkzNVQaYW4aIklKod7fbNK3afLYT0pXR5JKqSQD6awxVb+XruqUSrry39vfP npWOzPo1s6SjVi5AMzrFXttRg37JF1tSB6YuCoN9PMC40KWUg4RqERqa8uwLPGnyU/I6 0vyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=trY+rKRaXzr+XXemQYYt3LpgzdzpAoqCZiJ8oFvAQXQ=; b=dqs2K5QYqROcPfNO9/a5Y6W3HDO5Cy3vr8RUghgFpHDIGhJdVHzd/T6Xk9sPNYqQBX WwRKU2RoFw/GMFpLq3XqprGz1z6z9HzdWtYnloXDZvYpwarVHgnPjhnj30K8+ywr8Dsk mN2Uj6bx5IceHrm2E2y9Ni+Gq30XpqcL4ZS5ep3zdeohY6s3vK020x5vC9wzvy6HAt0C 3n0rnNFyORLx3SPFwnHeXk7ht92cAavcIPLGTmscqb4FahrGywbou7Dwb66o2F56MDc1 TNG8A/gAYZwnR0boLzMecWvKJ1H+375WPvq5D5CURqafw60tGmxC01q+Ke95TGN51AWL FOLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=f3NDklOB; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q5si49966640pgb.245.2018.11.25.23.53.21; Sun, 25 Nov 2018 23:53:21 -0800 (PST) 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=@ti.com header.s=ti-com-17Q1 header.b=f3NDklOB; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726543AbeKZSqe (ORCPT + 32 others); Mon, 26 Nov 2018 13:46:34 -0500 Received: from fllv0015.ext.ti.com ([198.47.19.141]:40938 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726485AbeKZSqe (ORCPT ); Mon, 26 Nov 2018 13:46:34 -0500 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id wAQ7rFIx043460; Mon, 26 Nov 2018 01:53:15 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1543218795; bh=trY+rKRaXzr+XXemQYYt3LpgzdzpAoqCZiJ8oFvAQXQ=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=f3NDklOBg2fMf88DLBiTgUNrD2EU7OCrcO/I3rTXVn3VnaNm7p0khGfRQG9ER/Lfb OyuOBL7NECMKL6nIRfvNiilvGLNIjVs1mjFYjDv+0uNUdKkgJcm2ZN/c53WfaiyIzd 3mJqHWmsnC4wXS+yblbKzThBZROyONWFh4rGHUCg= Received: from DFLE100.ent.ti.com (dfle100.ent.ti.com [10.64.6.21]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id wAQ7rFwH059381 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 26 Nov 2018 01:53:15 -0600 Received: from DFLE114.ent.ti.com (10.64.6.35) by DFLE100.ent.ti.com (10.64.6.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Mon, 26 Nov 2018 01:53:14 -0600 Received: from dflp33.itg.ti.com (10.64.6.16) by DFLE114.ent.ti.com (10.64.6.35) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1591.10 via Frontend Transport; Mon, 26 Nov 2018 01:53:14 -0600 Received: from dlelxv97.itg.ti.com (dlelxv97.itg.ti.com [172.17.2.193]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id wAQ7rE0K008903; Mon, 26 Nov 2018 01:53:14 -0600 Received: from localhost.localdomain (vboxa0400828d.dhcp.ti.com [172.22.237.3]) by dlelxv97.itg.ti.com (8.14.3/8.13.8) with ESMTP id wAQ7qn1J024490; Mon, 26 Nov 2018 01:53:11 -0600 From: Roger Quadros To: , CC: , , , , , , , , , , , , , , , Subject: [PATCH 05/16] remoteproc/pru: Add pru-specific debugfs support Date: Mon, 26 Nov 2018 09:52:38 +0200 Message-ID: <1543218769-5507-6-git-send-email-rogerq@ti.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1543218769-5507-1-git-send-email-rogerq@ti.com> References: <1543218769-5507-1-git-send-email-rogerq@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Suman Anna The remoteproc core creates certain standard debugfs entries, that does not give a whole lot of useful information for the PRUs. The PRU remoteproc driver is enhanced to add additional debugfs entries for PRU. These will be auto-cleaned up when the parent rproc debug directory is removed. The enhanced debugfs support adds two new entries: 'regs' and 'single_step'. The 'regs' dumps out the useful CTRL sub-module registers as well as each of the 32 GPREGs and CT_REGs registers. The GPREGs and CT_REGs though are printed only when the PRU is halted and accessible as per the IP design. The 'single_step' utilizes the single-step execution of the PRU cores. Writing a non-zero value performs a single step, and a zero value restores the PRU to execute in the same mode as the mode before the first single step. (note: if the PRU is halted because of a halt instruction, then no change occurs). Logic for setting the PC and jumping over a halt instruction shall be added in the future. Signed-off-by: Suman Anna --- drivers/remoteproc/pru_rproc.c | 135 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) -- Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki diff --git a/drivers/remoteproc/pru_rproc.c b/drivers/remoteproc/pru_rproc.c index c35f432..73a7f13 100644 --- a/drivers/remoteproc/pru_rproc.c +++ b/drivers/remoteproc/pru_rproc.c @@ -8,6 +8,7 @@ */ #include +#include #include #include #include @@ -36,6 +37,10 @@ #define CTRL_CTRL_SINGLE_STEP BIT(8) #define CTRL_CTRL_RUNSTATE BIT(15) +/* PRU_ICSS_PRU_DEBUG registers */ +#define PRU_DEBUG_GPREG(x) (0x0000 + (x) * 4) +#define PRU_DEBUG_CT_REG(x) (0x0080 + (x) * 4) + /** * enum pru_mem - PRU core memory range identifiers */ @@ -60,6 +65,8 @@ enum pru_mem { * @sdram_da: device address of secondary Data RAM for this PRU * @shrdram_da: device address of shared Data RAM * @fw_name: name of firmware image used during loading + * @dbg_single_step: debug state variable to set PRU into single step mode + * @dbg_continuous: debug state variable to restore PRU execution mode */ struct pru_rproc { int id; @@ -74,6 +81,8 @@ struct pru_rproc { u32 sdram_da; u32 shrdram_da; const char *fw_name; + u32 dbg_single_step; + u32 dbg_continuous; }; static void *pru_d_da_to_va(struct pru_rproc *pru, u32 da, int len); @@ -100,6 +109,130 @@ void pru_debug_write_reg(struct pru_rproc *pru, unsigned int reg, u32 val) writel_relaxed(val, pru->mem_regions[PRU_MEM_DEBUG].va + reg); } +static int pru_rproc_debug_read_regs(struct seq_file *s, void *data) +{ + struct rproc *rproc = s->private; + struct pru_rproc *pru = rproc->priv; + int i, nregs = 32; + u32 pru_sts; + int pru_is_running; + + seq_puts(s, "============== Control Registers ==============\n"); + seq_printf(s, "CTRL := 0x%08x\n", + pru_control_read_reg(pru, PRU_CTRL_CTRL)); + pru_sts = pru_control_read_reg(pru, PRU_CTRL_STS); + seq_printf(s, "STS (PC) := 0x%08x (0x%08x)\n", pru_sts, pru_sts << 2); + seq_printf(s, "WAKEUP_EN := 0x%08x\n", + pru_control_read_reg(pru, PRU_CTRL_WAKEUP_EN)); + seq_printf(s, "CYCLE := 0x%08x\n", + pru_control_read_reg(pru, PRU_CTRL_CYCLE)); + seq_printf(s, "STALL := 0x%08x\n", + pru_control_read_reg(pru, PRU_CTRL_STALL)); + seq_printf(s, "CTBIR0 := 0x%08x\n", + pru_control_read_reg(pru, PRU_CTRL_CTBIR0)); + seq_printf(s, "CTBIR1 := 0x%08x\n", + pru_control_read_reg(pru, PRU_CTRL_CTBIR1)); + seq_printf(s, "CTPPR0 := 0x%08x\n", + pru_control_read_reg(pru, PRU_CTRL_CTPPR0)); + seq_printf(s, "CTPPR1 := 0x%08x\n", + pru_control_read_reg(pru, PRU_CTRL_CTPPR1)); + + seq_puts(s, "=============== Debug Registers ===============\n"); + pru_is_running = pru_control_read_reg(pru, PRU_CTRL_CTRL) & + CTRL_CTRL_RUNSTATE; + if (pru_is_running) { + seq_puts(s, "PRU is executing, cannot print/access debug registers.\n"); + return 0; + } + + for (i = 0; i < nregs; i++) { + seq_printf(s, "GPREG%-2d := 0x%08x\tCT_REG%-2d := 0x%08x\n", + i, pru_debug_read_reg(pru, PRU_DEBUG_GPREG(i)), + i, pru_debug_read_reg(pru, PRU_DEBUG_CT_REG(i))); + } + + return 0; +} + +static int pru_rproc_debug_regs_open(struct inode *inode, struct file *file) +{ + return single_open(file, pru_rproc_debug_read_regs, inode->i_private); +} + +static const struct file_operations pru_rproc_debug_regs_ops = { + .open = pru_rproc_debug_regs_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +/* + * Control PRU single-step mode + * + * This is a debug helper function used for controlling the single-step + * mode of the PRU. The PRU Debug registers are not accessible when the + * PRU is in RUNNING state. + * + * Writing a non-zero value sets the PRU into single-step mode irrespective + * of its previous state. The PRU mode is saved only on the first set into + * a single-step mode. Writing a zero value will restore the PRU into its + * original mode. + */ +static int pru_rproc_debug_ss_set(void *data, u64 val) +{ + struct rproc *rproc = data; + struct pru_rproc *pru = rproc->priv; + u32 reg_val; + + val = val ? 1 : 0; + if (!val && !pru->dbg_single_step) + return 0; + + reg_val = pru_control_read_reg(pru, PRU_CTRL_CTRL); + + if (val && !pru->dbg_single_step) + pru->dbg_continuous = reg_val; + + if (val) + reg_val |= CTRL_CTRL_SINGLE_STEP | CTRL_CTRL_EN; + else + reg_val = pru->dbg_continuous; + + pru->dbg_single_step = val; + pru_control_write_reg(pru, PRU_CTRL_CTRL, reg_val); + + return 0; +} + +static int pru_rproc_debug_ss_get(void *data, u64 *val) +{ + struct rproc *rproc = data; + struct pru_rproc *pru = rproc->priv; + + *val = pru->dbg_single_step; + + return 0; +} +DEFINE_SIMPLE_ATTRIBUTE(pru_rproc_debug_ss_fops, pru_rproc_debug_ss_get, + pru_rproc_debug_ss_set, "%llu\n"); + +/* + * Create PRU-specific debugfs entries + * + * The entries are created only if the parent remoteproc debugfs directory + * exists, and will be cleaned up by the remoteproc core. + */ +static void pru_rproc_create_debug_entries(struct rproc *rproc) +{ + if (!rproc->dbg_dir) + return; + + debugfs_create_file("regs", 0400, rproc->dbg_dir, + rproc, &pru_rproc_debug_regs_ops); + debugfs_create_file("single_step", 0600, rproc->dbg_dir, + rproc, &pru_rproc_debug_ss_fops); +} + /* start a PRU core */ static int pru_rproc_start(struct rproc *rproc) { @@ -348,6 +481,8 @@ static int pru_rproc_probe(struct platform_device *pdev) goto free_rproc; } + pru_rproc_create_debug_entries(rproc); + dev_info(dev, "PRU rproc node %s probed successfully\n", np->full_name); return 0;