From patchwork Sat Nov 14 08:46:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grzegorz Jaszczyk X-Patchwork-Id: 324353 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:5ce:0:0:0:0 with SMTP id l14csp1850105ils; Sat, 14 Nov 2020 00:48:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJw6rl9hnCUM9xZVHR4YePMAdpurjcxwoXzgNZdkVNuu5kB27KxLEh/rPCNzeB+P7fF1RLbh X-Received: by 2002:a17:906:c08f:: with SMTP id f15mr5751323ejz.97.1605343694835; Sat, 14 Nov 2020 00:48:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605343694; cv=none; d=google.com; s=arc-20160816; b=eF1qptc+Sv/95Ho29IaCcjsTLh3rEXNM3AKd/f4KHh76a/GCWcFVzHRQpaw5alWB8D d/V5vuCdrYUBhCHbF3wodrAGBapl3cY8uJq0IO6iPN+Kbjrcz/alu9tKI2S5456jerf5 7wJuk9FattPe0vVeLTIJzhlODBkGnp7B4KPZnaGnsGI6FpIxfuttsY8GrtPQh2VIPNDi FnNYYfKc+od9Nx2jEq1PN2XCKgKj+gXOOLXae6uiVe+SzoP2HrUHwCiCQ1MYUmgyG31x 9wJTZqWr5bj1TG8fEu8t+hQPCxAMQ/ZRC/qymtb5Vjmb9/6B4Jt8Jhq7s/PrPDLCZK+K yGtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=a/nSWEsw3N6fSKKLuz4XMLcWzgg3KLh595YgOxVRdOs=; b=LtDttSpyqNNcV0e4ZJTwCazE7YM2SKOTFfzxhP72cgN28rZs799DMSHmMMKJhkVBj2 rUUexCyYt+hTZ4Ost1cH4DZYxF1RhVAxVZCzSlvj82Xn3SiWG2Ou8A/x7BcgZnHDMAJv K3fbaKlpFU3Bv3Nyv0iySZecQUcLWOZXvCiiqL6u96RU6dBeS+uJ2vbChfNEaHrwQaBS qTEcqciuCsauwgGbjxYYtGGdWeeh7qSjea8uSAkqsmPPHdZmkxjfOn9hqjLQGq/JXE4M 5JeOc3bIwCxRTw03AZxHPE0s4f0eZZLxxCdtZbBRxwSzivs8Y1PdDtytjm41cvtVdFve qJFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=N2JwHMrP; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m8si8307667edj.357.2020.11.14.00.48.14; Sat, 14 Nov 2020 00:48:14 -0800 (PST) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=N2JwHMrP; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726738AbgKNIqp (ORCPT + 6 others); Sat, 14 Nov 2020 03:46:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726734AbgKNIqo (ORCPT ); Sat, 14 Nov 2020 03:46:44 -0500 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E49B2C061A4B for ; Sat, 14 Nov 2020 00:46:42 -0800 (PST) Received: by mail-lf1-x135.google.com with SMTP id l11so5609528lfg.0 for ; Sat, 14 Nov 2020 00:46:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=a/nSWEsw3N6fSKKLuz4XMLcWzgg3KLh595YgOxVRdOs=; b=N2JwHMrPfSCZtpY3q2xbT+ib5L1HzYHliqPlmcYp9QsD2VBTyZKlDdbpGuiOFoJd1s 52+L9WETgaAeMww0c5i8OTnbug++dQoSJ0h7+K+lDnRpglJY3CEsa8su/PqZr0U1lKQg r5HAu3k15jf4yz3c+LI71v1m2P/mpF51p8O2ha8LsW/FM4q0Kj3gB3yLEjuUU22rhv7k nN5dl3awHgK8joTyqs975AkNlM1P0mZe8C+Hp9+azEMoonWwf2UHgxDo2IJ9dbo/z6LK IqMLpuPKn6xVz1/e1Q2og6dDca8UOCwyr22MKH2TxlEZLvf0sbZSqgBhr0amgtdkB3mi jhBQ== 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=a/nSWEsw3N6fSKKLuz4XMLcWzgg3KLh595YgOxVRdOs=; b=pBSpesmmlYop9bQcKAA9g2IW4HyruXcgRcPwDcTfg2/eLQFEpGOozrpFE5PVAVo/6G KIKWkGNovl0esY17MZpocqQvAcQbvsL7G5tshoBEWvztBiUK995/Aoo7WG6RUrgHYv9C 4O774mkarzLnSNHk5SQf7hOa5Pv5L4AOZK/IYAUlbE2/TQgz+14S0S5b7EzUrRmzbySe L3rIcP7OjkGl91xIcBqDFtPXMMBp33imOzj9kA+1ETXKzo0nB7CRbVu7WVJjUL6q94yP JvUvTgn+AsU3A2KsMJgo7llpKuh/19qF9bCC/qvJT8ccBSXDyAlnUfQgjSzzbgOaP892 dttQ== X-Gm-Message-State: AOAM5304xltVIc3/19GszUtvePEF9xpOwlRsyDyDU6ReKoWK2GCWoYA/ wcK+p7oR/zdL2YxWY8SEtaKqfA== X-Received: by 2002:a05:6512:368a:: with SMTP id d10mr2224684lfs.579.1605343601373; Sat, 14 Nov 2020 00:46:41 -0800 (PST) Received: from gilgamesh.semihalf.com (193-106-246-138.noc.fibertech.net.pl. [193.106.246.138]) by smtp.gmail.com with ESMTPSA id f62sm1870081lfd.144.2020.11.14.00.46.40 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 14 Nov 2020 00:46:40 -0800 (PST) From: Grzegorz Jaszczyk To: ohad@wizery.com, bjorn.andersson@linaro.org, mathieu.poirier@linaro.org, s-anna@ti.com Cc: grzegorz.jaszczyk@linaro.org, linux-remoteproc@vger.kernel.org, robh+dt@kernel.org, lee.jones@linaro.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org, praneeth@ti.com, rogerq@ti.com Subject: [PATCH 4/6] remoteproc/pru: Add pru-specific debugfs support Date: Sat, 14 Nov 2020 09:46:11 +0100 Message-Id: <20201114084613.13503-5-grzegorz.jaszczyk@linaro.org> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20201114084613.13503-1-grzegorz.jaszczyk@linaro.org> References: <20201114084613.13503-1-grzegorz.jaszczyk@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@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 Signed-off-by: Grzegorz Jaszczyk --- drivers/remoteproc/pru_rproc.c | 137 +++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) -- 2.29.0 diff --git a/drivers/remoteproc/pru_rproc.c b/drivers/remoteproc/pru_rproc.c index 825e9c7e081b..33806ddcbd5d 100644 --- a/drivers/remoteproc/pru_rproc.c +++ b/drivers/remoteproc/pru_rproc.c @@ -11,6 +11,7 @@ */ #include +#include #include #include #include @@ -25,6 +26,13 @@ /* PRU_ICSS_PRU_CTRL registers */ #define PRU_CTRL_CTRL 0x0000 #define PRU_CTRL_STS 0x0004 +#define PRU_CTRL_WAKEUP_EN 0x0008 +#define PRU_CTRL_CYCLE 0x000C +#define PRU_CTRL_STALL 0x0010 +#define PRU_CTRL_CTBIR0 0x0020 +#define PRU_CTRL_CTBIR1 0x0024 +#define PRU_CTRL_CTPPR0 0x0028 +#define PRU_CTRL_CTPPR1 0x002C /* CTRL register bit-fields */ #define CTRL_CTRL_SOFT_RST_N BIT(0) @@ -34,6 +42,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) + /* PRU Core IRAM address masks */ #define PRU0_IRAM_ADDR_MASK 0x34000 #define PRU1_IRAM_ADDR_MASK 0x38000 @@ -73,6 +85,8 @@ enum pru_iomem { * @pru_interrupt_map: pointer to interrupt mapping description (firmware) * @pru_interrupt_map_sz: pru_interrupt_map size * @evt_count: number of mapped events + * @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; @@ -85,6 +99,8 @@ struct pru_rproc { struct pru_irq_rsc *pru_interrupt_map; size_t pru_interrupt_map_sz; ssize_t evt_count; + u32 dbg_single_step; + u32 dbg_continuous; }; static inline u32 pru_control_read_reg(struct pru_rproc *pru, unsigned int reg) @@ -98,6 +114,125 @@ void pru_control_write_reg(struct pru_rproc *pru, unsigned int reg, u32 val) writel_relaxed(val, pru->mem_regions[PRU_IOMEM_CTRL].va + reg); } +static inline u32 pru_debug_read_reg(struct pru_rproc *pru, unsigned int reg) +{ + return readl_relaxed(pru->mem_regions[PRU_IOMEM_DEBUG].va + reg); +} + +static int regs_show(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; +} + +DEFINE_SHOW_ATTRIBUTE(regs); + +/* + * 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, ®s_fops); + debugfs_create_file("single_step", 0600, rproc->dbg_dir, + rproc, &pru_rproc_debug_ss_fops); +} + static void pru_dispose_irq_mapping(struct pru_rproc *pru) { while (--pru->evt_count >= 0) { @@ -575,6 +710,8 @@ static int pru_rproc_probe(struct platform_device *pdev) return ret; } + pru_rproc_create_debug_entries(rproc); + dev_dbg(dev, "PRU rproc node %pOF probed successfully\n", np); return 0; From patchwork Sat Nov 14 08:46:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grzegorz Jaszczyk X-Patchwork-Id: 324351 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:5ce:0:0:0:0 with SMTP id l14csp1850086ils; Sat, 14 Nov 2020 00:48:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJy+Yx93ISpLSkt5me9toIqEtb0+kOA1Os+UtaYkmEijRFgn6qnKvhX/ot5ll5lHKL3mtVpp X-Received: by 2002:aa7:d711:: with SMTP id t17mr6617241edq.83.1605343691505; Sat, 14 Nov 2020 00:48:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605343691; cv=none; d=google.com; s=arc-20160816; b=Z+xKTNZm/1wse9/HHrS5dQ3slkqu4wTP0MDXzKQ40lBeP7On8bQ0hjoojJHgpTPNFR 1Qp4EXg4qI/FGWdPeHiMdHTSb7DXlPVwdJ/IK0f+n5U7u3VZM1ZE9dnX4ccNT0kdqGLS 3Wivmd10c6cHW4XKaBolhgYxYBvQVfXr6S08rhHrwu5tvMrqw/qjPfW/9HSiTsvRN3eu mYOQKzUnrZNzz5b6yav3ZhQjHCvilM5E1gpmKHFYVMor9WHC/TY/nTo+zdKbCIelFbuW h0aZ2PXTKt5RjEEh8i/kNlx/z5CVOqih4EWoirW86KHUW/ViNWwNnWhmf1fV02ue4a1r s/kQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9BepB+xK4X+JiX+/PaV7AqLX9bv5aDwLpI3mPyJBUOw=; b=Uy9CUqyP9svgKobnqu01xWyEPlacDhYDpx4Ao2xYtir0TVl+HABQG65DFNX0iw2Tvf ujr2JHnQfuPWERQIg1PHJBRVXHYW52VzvqZavLTHDsll4QG7H1HK+rm4H2AlQ8Vp0l+q aobV4JVzI1ebFqRE+nVClUBH7X/Ykq+y5KAkMqMtlJ5d3gfJjh8h9w3hypcK3reZugTg 1KrlQreMfZbj2YVxLMSLpDpl6L/iBJ/wzBkMGB9DQLiWfIF4m3GmEdmk1YYdLZaTQZkP ZlfNxbDl3eiR/9H2AfnzeICXBVQpkE6gRhvfec7y8Nt0wR+k1FPgMqDtREmzKl7RaE5s dfug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OoSOUKAl; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m8si8307667edj.357.2020.11.14.00.48.11; Sat, 14 Nov 2020 00:48:11 -0800 (PST) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OoSOUKAl; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726754AbgKNIqq (ORCPT + 6 others); Sat, 14 Nov 2020 03:46:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726751AbgKNIqq (ORCPT ); Sat, 14 Nov 2020 03:46:46 -0500 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42AD1C0617A6 for ; Sat, 14 Nov 2020 00:46:44 -0800 (PST) Received: by mail-lj1-x241.google.com with SMTP id 142so218671ljj.10 for ; Sat, 14 Nov 2020 00:46:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9BepB+xK4X+JiX+/PaV7AqLX9bv5aDwLpI3mPyJBUOw=; b=OoSOUKAlc0wTwPnxpR1RV6imcpKiWTC/CrRPDOyUM3jDTevLSJQK+eGkBUlSnGzfOR j0Tj68FJSUcvh0F2wqAZCzE9mS2bUPjRtikENDBG8WQQHwnRnTKPI99fza6nK9rj9B9M MiIUHWQj92lSXzmDpULSLCrRwyXlQsU4D9Ef4ul/YFBjzKwgQ6K+fdi6aqxSTl03prLe BrH/9SwdSAzpW10lVmrpQgDp364uSNQ1RZjTHVCHadrTgINb9pY6uAjwInBKSiy0kWdu YBoxFUlW2LNPgh0+y67ah8dh1BO6l+DSPJChKWx1E8O3MLy8+Yr6x/5wBU5gw86XjwkR kUcg== 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=9BepB+xK4X+JiX+/PaV7AqLX9bv5aDwLpI3mPyJBUOw=; b=YAFdpuDBRPUuD9VWzPFPHHa2WjHhL2fp9BcF+B+Bf78MKtBj79Dn8ZipPeK9r0WzuK 53NknBqLTvuYPA03zLAebIyp6VLCYB/BszScMIbfqw8bre0nN42GH+jOoyNhNAeG9uQc euASq+gcttf3uzII2ZZpXm80wCCL7JPLXoCGQO4eGyiUP60p1dYXk+L5ob+JjJ7cqywN KXQU/XHWptHEVGJjaobxHdjyjxqjRPZjaFOcHYz0C49YfWN8jINaIgEYxlh3aO4RZPm7 RlZKPwws1UVJnw3AArrb7Bc51V9wcUSQogUtUeKIXfdi9lzMmq7Q9vXbD3OpM2IUokSY InIw== X-Gm-Message-State: AOAM532jlRZP+PpuM5nT8miSZFir8Kv/lOHXDvarHNLZ7/ndGP2oM+kF 0tV74770lHrlCd6LuwfYbbrvPQ== X-Received: by 2002:a05:651c:3d0:: with SMTP id f16mr2406212ljp.109.1605343602726; Sat, 14 Nov 2020 00:46:42 -0800 (PST) Received: from gilgamesh.semihalf.com (193-106-246-138.noc.fibertech.net.pl. [193.106.246.138]) by smtp.gmail.com with ESMTPSA id f62sm1870081lfd.144.2020.11.14.00.46.41 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 14 Nov 2020 00:46:42 -0800 (PST) From: Grzegorz Jaszczyk To: ohad@wizery.com, bjorn.andersson@linaro.org, mathieu.poirier@linaro.org, s-anna@ti.com Cc: grzegorz.jaszczyk@linaro.org, linux-remoteproc@vger.kernel.org, robh+dt@kernel.org, lee.jones@linaro.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org, praneeth@ti.com, rogerq@ti.com Subject: [PATCH 5/6] remoteproc/pru: Add support for various PRU cores on K3 AM65x SoCs Date: Sat, 14 Nov 2020 09:46:12 +0100 Message-Id: <20201114084613.13503-6-grzegorz.jaszczyk@linaro.org> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20201114084613.13503-1-grzegorz.jaszczyk@linaro.org> References: <20201114084613.13503-1-grzegorz.jaszczyk@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Suman Anna The K3 AM65x family of SoCs have the next generation of the PRU-ICSS processor subsystem, commonly referred to as ICSSG. Each ICSSG processor subsystem on AM65x SR1.0 contains two primary PRU cores and two new auxiliary PRU cores called RTUs. The AM65x SR2.0 SoCs have a revised ICSSG IP that is based off the subsequent IP revision used on J721E SoCs. This IP instance has two new custom auxiliary PRU cores called Transmit PRUs (Tx_PRUs) in addition to the existing PRUs and RTUs. Each RTU and Tx_PRU cores have their own dedicated IRAM (smaller than a PRU), Control and debug feature sets, but is different in terms of sub-modules integrated around it and does not have the full capabilities associated with a PRU core. The RTU core is typically used to aid a PRU core in accelerating data transfers, while the Tx_PRU cores is normally used to control the TX L2 FIFO if enabled in Ethernet applications. Both can also be used to run independent applications. The RTU and Tx_PRU cores though share the same Data RAMs as the PRU cores, so the memories have to be partitioned carefully between different applications. The new cores also support a new sub-module called Task Manager to support two different context thread executions. Enhance the existing PRU remoteproc driver to support these new PRU, RTU and Tx PRU cores by using specific compatibles. The initial names for the firmware images for each PRU core are retrieved from DT nodes, and can be adjusted through sysfs if required. The PRU remoteproc driver has to be specifically modified to use a custom memcpy function within its ELF loader implementation for these new cores in order to overcome a limitation with copying data into each of the core's IRAM memories. These memory ports support only 4-byte writes, and any sub-word order byte writes clear out the remaining bytes other than the bytes being written within the containing word. The default ARM64 memcpy also cannot be used as it throws an exception when the preferred 8-byte copy operation is attempted. This choice is made by using a state flag that is set only on K3 SoCs. Signed-off-by: Suman Anna Co-developed-by: Grzegorz Jaszczyk Signed-off-by: Grzegorz Jaszczyk --- drivers/remoteproc/pru_rproc.c | 141 ++++++++++++++++++++++++++++++--- 1 file changed, 132 insertions(+), 9 deletions(-) -- 2.29.0 diff --git a/drivers/remoteproc/pru_rproc.c b/drivers/remoteproc/pru_rproc.c index 33806ddcbd5d..04c9f07799e2 100644 --- a/drivers/remoteproc/pru_rproc.c +++ b/drivers/remoteproc/pru_rproc.c @@ -46,9 +46,13 @@ #define PRU_DEBUG_GPREG(x) (0x0000 + (x) * 4) #define PRU_DEBUG_CT_REG(x) (0x0080 + (x) * 4) -/* PRU Core IRAM address masks */ +/* PRU/RTU/Tx_PRU Core IRAM address masks */ #define PRU0_IRAM_ADDR_MASK 0x34000 #define PRU1_IRAM_ADDR_MASK 0x38000 +#define RTU0_IRAM_ADDR_MASK 0x4000 +#define RTU1_IRAM_ADDR_MASK 0x6000 +#define TX_PRU0_IRAM_ADDR_MASK 0xa000 +#define TX_PRU1_IRAM_ADDR_MASK 0xc000 /* PRU device addresses for various type of PRU RAMs */ #define PRU_IRAM_DA 0 /* Instruction RAM */ @@ -73,12 +77,38 @@ enum pru_iomem { PRU_IOMEM_MAX, }; +/** + * enum pru_type - PRU core type identifier + * + * @PRU_TYPE_PRU: Programmable Real-time Unit + * @PRU_TYPE_RTU: Auxiliary Programmable Real-Time Unit + * @PRU_TYPE_TX_PRU: Transmit Programmable Real-Time Unit + * @PRU_TYPE_MAX: just keep this one at the end + */ +enum pru_type { + PRU_TYPE_PRU = 0, + PRU_TYPE_RTU, + PRU_TYPE_TX_PRU, + PRU_TYPE_MAX, +}; + +/** + * struct pru_private_data - device data for a PRU core + * @type: type of the PRU core (PRU, RTU, Tx_PRU) + * @is_k3: flag used to identify the need for special load & event handling + */ +struct pru_private_data { + enum pru_type type; + unsigned int is_k3 : 1; +}; + /** * struct pru_rproc - PRU remoteproc structure * @id: id of the PRU core within the PRUSS * @dev: PRU core device pointer * @pruss: back-reference to parent PRUSS structure * @rproc: remoteproc pointer for this PRU core + * @data: PRU core specific data * @mem_regions: data for each of the PRU memory regions * @fw_name: name of firmware image used during loading * @mapped_irq: virtual interrupt numbers of created fw specific mapping @@ -93,6 +123,7 @@ struct pru_rproc { struct device *dev; struct pruss *pruss; struct rproc *rproc; + const struct pru_private_data *data; struct pruss_mem_region mem_regions[PRU_IOMEM_MAX]; const char *fw_name; int *mapped_irq; @@ -318,11 +349,12 @@ static int pru_rproc_start(struct rproc *rproc) { struct device *dev = &rproc->dev; struct pru_rproc *pru = rproc->priv; + const char *names[PRU_TYPE_MAX] = { "PRU", "RTU", "Tx_PRU" }; u32 val; int ret; - dev_dbg(dev, "starting PRU%d: entry-point = 0x%llx\n", - pru->id, (rproc->bootaddr >> 2)); + dev_dbg(dev, "starting %s%d: entry-point = 0x%llx\n", + names[pru->data->type], pru->id, (rproc->bootaddr >> 2)); ret = pru_handle_intrmap(rproc); /* @@ -344,9 +376,10 @@ static int pru_rproc_stop(struct rproc *rproc) { struct device *dev = &rproc->dev; struct pru_rproc *pru = rproc->priv; + const char *names[PRU_TYPE_MAX] = { "PRU", "RTU", "Tx_PRU" }; u32 val; - dev_dbg(dev, "stopping PRU%d\n", pru->id); + dev_dbg(dev, "stopping %s%d\n", names[pru->data->type], pru->id); val = pru_control_read_reg(pru, PRU_CTRL_CTRL); val &= ~CTRL_CTRL_EN; @@ -458,9 +491,53 @@ static struct rproc_ops pru_rproc_ops = { .da_to_va = pru_rproc_da_to_va, }; +/* + * Custom memory copy implementation for ICSSG PRU/RTU Cores + * + * The ICSSG PRU/RTU cores have a memory copying issue with IRAM memories, that + * is not seen on previous generation SoCs. The data is reflected properly in + * the IRAM memories only for integer (4-byte) copies. Any unaligned copies + * result in all the other pre-existing bytes zeroed out within that 4-byte + * boundary, thereby resulting in wrong text/code in the IRAMs. Also, the + * IRAM memory port interface does not allow any 8-byte copies (as commonly + * used by ARM64 memcpy implementation) and throws an exception. The DRAM + * memory ports do not show this behavior. Use this custom copying function + * to properly load the PRU/RTU firmware images on all memories for simplicity. + */ +static int pru_rproc_memcpy(void *dest, const void *src, size_t count) +{ + const int *s = src; + int *d = dest; + int size = count / 4; + int *tmp_src = NULL; + + /* + * TODO: relax limitation of 4-byte aligned dest addresses and copy + * sizes + */ + if ((long)dest % 4 || count % 4) + return -EINVAL; + + /* src offsets in ELF firmware image can be non-aligned */ + if ((long)src % 4) { + tmp_src = kmemdup(src, count, GFP_KERNEL); + if (!tmp_src) + return -ENOMEM; + s = tmp_src; + } + + while (size--) + *d++ = *s++; + + kfree(tmp_src); + + return 0; +} + static int pru_rproc_load_elf_segments(struct rproc *rproc, const struct firmware *fw) { + struct pru_rproc *pru = rproc->priv; struct device *dev = &rproc->dev; struct elf32_hdr *ehdr; struct elf32_phdr *phdr; @@ -512,7 +589,17 @@ pru_rproc_load_elf_segments(struct rproc *rproc, const struct firmware *fw) if (!phdr->p_filesz) continue; - memcpy(ptr, elf_data + phdr->p_offset, filesz); + if (pru->data->is_k3 && is_iram) { + ret = pru_rproc_memcpy(ptr, elf_data + phdr->p_offset, + filesz); + if (ret) { + dev_err(dev, "PRU memory copy failed for da 0x%x memsz 0x%x\n", + da, memsz); + break; + } + } else { + memcpy(ptr, elf_data + phdr->p_offset, filesz); + } } return ret; @@ -619,9 +706,17 @@ static int pru_rproc_set_id(struct pru_rproc *pru) int ret = 0; switch (pru->mem_regions[PRU_IOMEM_IRAM].pa & 0x3ffff) { + case TX_PRU0_IRAM_ADDR_MASK: + fallthrough; + case RTU0_IRAM_ADDR_MASK: + fallthrough; case PRU0_IRAM_ADDR_MASK: pru->id = 0; break; + case TX_PRU1_IRAM_ADDR_MASK: + fallthrough; + case RTU1_IRAM_ADDR_MASK: + fallthrough; case PRU1_IRAM_ADDR_MASK: pru->id = 1; break; @@ -642,8 +737,13 @@ static int pru_rproc_probe(struct platform_device *pdev) struct rproc *rproc = NULL; struct resource *res; int i, ret; + const struct pru_private_data *data; const char *mem_names[PRU_IOMEM_MAX] = { "iram", "control", "debug" }; + data = of_device_get_match_data(&pdev->dev); + if (!data) + return -ENODEV; + ret = of_property_read_string(np, "firmware-name", &fw_name); if (ret) { dev_err(dev, "unable to retrieve firmware-name %d\n", ret); @@ -676,6 +776,7 @@ static int pru_rproc_probe(struct platform_device *pdev) pru = rproc->priv; pru->dev = dev; + pru->data = data; pru->pruss = platform_get_drvdata(ppdev); pru->rproc = rproc; pru->fw_name = fw_name; @@ -727,11 +828,33 @@ static int pru_rproc_remove(struct platform_device *pdev) return 0; } +static const struct pru_private_data pru_data = { + .type = PRU_TYPE_PRU, +}; + +static const struct pru_private_data k3_pru_data = { + .type = PRU_TYPE_PRU, + .is_k3 = 1, +}; + +static const struct pru_private_data k3_rtu_data = { + .type = PRU_TYPE_RTU, + .is_k3 = 1, +}; + +static const struct pru_private_data k3_tx_pru_data = { + .type = PRU_TYPE_TX_PRU, + .is_k3 = 1, +}; + static const struct of_device_id pru_rproc_match[] = { - { .compatible = "ti,am3356-pru", }, - { .compatible = "ti,am4376-pru", }, - { .compatible = "ti,am5728-pru", }, - { .compatible = "ti,k2g-pru", }, + { .compatible = "ti,am3356-pru", .data = &pru_data }, + { .compatible = "ti,am4376-pru", .data = &pru_data }, + { .compatible = "ti,am5728-pru", .data = &pru_data }, + { .compatible = "ti,k2g-pru", .data = &pru_data }, + { .compatible = "ti,am654-pru", .data = &k3_pru_data }, + { .compatible = "ti,am654-rtu", .data = &k3_rtu_data }, + { .compatible = "ti,am654-tx-pru", .data = &k3_tx_pru_data }, {}, }; MODULE_DEVICE_TABLE(of, pru_rproc_match);