From patchwork Wed Dec 16 16:52:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grzegorz Jaszczyk X-Patchwork-Id: 11978047 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 598A0C4361B for ; Wed, 16 Dec 2020 16:54:31 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 01B3B225A9 for ; Wed, 16 Dec 2020 16:54:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 01B3B225A9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=sYRsJeKWjWhjdNqLap6Ik+KSZpDsBSISAm54Zx1uSS8=; b=IbnI1DqulYXSiafBJyDtUObsC ux3sNgEkVhIadG/cUyvfsQB1vJc3K9/btKVlgcj7R6wKTww5D5s0pg6DgpUWZGaiwGaGsROUex/8x oJYOWWO7tgTYBRQFvUR5iWXFcHTdfqaYw0+atOu5p15G8DG8PiEGuQN2GaIF5l3+PiA9dcKa4WbSj 3DOFhDZ05RcxkYBFRdZcApK5oOiSUk2QN09P4HoyZPm/NMdbAwLmUTnSxYYMWczBaniK7ldpEh3gg 6mv+Bhf6VToWTwGFRlV6fU33Q+PG+Kh9aMHpNhEDPTn/h6hk5BTKF8D/qO9n8z05zIk8oyINKmV0W gZ9+TTWng==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kpa3A-0004Ep-VN; Wed, 16 Dec 2020 16:53:17 +0000 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kpa2t-0004A1-IS for linux-arm-kernel@lists.infradead.org; Wed, 16 Dec 2020 16:53:00 +0000 Received: by mail-lf1-x129.google.com with SMTP id a9so50045539lfh.2 for ; Wed, 16 Dec 2020 08:52:59 -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=P45j3wiFR9Tri3Ofzw18omORpyymmURP37wmkg2klyw=; b=TdD0moJ/izalkc+QkYizCyULJHTgkKxJXdM4rvie7LnZSFbXVrqnphFHAPrrZpsQL7 T3VK6npCnSgtGJ6lRKTKSDps/FccK7MjxyQaG+a6Ufxfd239tiLTnqeyACshBTWsPSkn b0g3RoRDb9PVPreKG0wDBepphnZu9myExIwyvhU5YEUb60ngOGkoSrK7/VV8GX6irHNF f7QA0/cbIOAUGMs4pemsUr+bjFLVW0SZH2+Q1tDBiMlCKVKqQQVyLg0iW3L6ClO0ZIP9 R+AyHbW2dNxhzibGtnsN7YVPHz+7nEAuFceBcVa7sjol6RPWP5VMWAlhoyq1oIdPEyZJ yT7Q== 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=P45j3wiFR9Tri3Ofzw18omORpyymmURP37wmkg2klyw=; b=fJJog55nJOy3IJ9YaybBxB/AH2Y4oXwQoAKUf7QYsAWVJUtVJX9wu7pTpggKN/t5pI 0e4Y6XoYpT4CSWeQFh/FrKMGemnnV/3NxVPa0Rq7nDBaLOLGfT5VD3ZMsgmAiW/Hntlg o4QcEKpFhA03T8f+zjEfOFZX8pIP+hbfkgzw6hL6iRaFMsMwDw64RmCUMdRqflXFgnvO 6zMPTSucSKDlYcdeW2t3wyoVrqpTQx/Fp6WUyq/5YkF9/XglQQTXC/hyDtRjKXcQq495 q+t+493vK2nnMJoe3X5PqStjTmJXyWFAPwFCd8CYD1txuNEMEOoXsIrWfQqi4jty/n9T 26aw== X-Gm-Message-State: AOAM532jvQiwLE7GxbQpBU8f5IZr4up9MwwXfb+N/yVli2AZvAoLSzAP F6sSzsUf+PtAy82l8FexcM+esA== X-Google-Smtp-Source: ABdhPJwyebGUSUDwL2LrMLfRUgP3yoqFG5LRbUXLW8SuJ+pKLDBR23n7/0VEsW4Eerftkva9jFqw6A== X-Received: by 2002:a19:418e:: with SMTP id o136mr13145940lfa.80.1608137577965; Wed, 16 Dec 2020 08:52:57 -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 t3sm281645lfe.263.2020.12.16.08.52.56 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Dec 2020 08:52:57 -0800 (PST) From: Grzegorz Jaszczyk To: ohad@wizery.com, bjorn.andersson@linaro.org, mathieu.poirier@linaro.org, robh+dt@kernel.org, s-anna@ti.com, ssantosh@kernel.org Subject: [PATCH v2 4/5] remoteproc: pru: Add pru_rproc_set_ctable() function Date: Wed, 16 Dec 2020 17:52:38 +0100 Message-Id: <20201216165239.2744-5-grzegorz.jaszczyk@linaro.org> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20201216165239.2744-1-grzegorz.jaszczyk@linaro.org> References: <20201216165239.2744-1-grzegorz.jaszczyk@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201216_115259_759250_7ADC7B93 X-CRM114-Status: GOOD ( 22.05 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, grzegorz.jaszczyk@linaro.org, praneeth@ti.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, t-kristo@ti.com, linux-omap@vger.kernel.org, lee.jones@linaro.org, linux-arm-kernel@lists.infradead.org, rogerq@ti.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Roger Quadros Some firmwares expect the OS drivers to configure the CTABLE entries publishing dynamically allocated memory regions. For example, the PRU Ethernet firmwares use the C28 and C30 entries for retrieving the Shared RAM and System SRAM (OCMC) areas allocated by the PRU Ethernet client driver. Provide a way for users to do that through a new API, pru_rproc_set_ctable(). The API returns 0 on success and a negative value on error. NOTE: The programmable CTABLE entries are typically re-programmed by the PRU firmwares when dealing with a certain block of memory during block processing. This API provides an interface to the PRU client drivers to publish a dynamically allocated memory block with the PRU firmware using a CTABLE entry instead of a negotiated address in shared memory. Additional synchronization may be needed between the PRU client drivers and firmwares if different addresses needs to be published at run-time reusing the same CTABLE entry. Co-developed-by: Andrew F. Davis Signed-off-by: Andrew F. Davis Co-developed-by: Suman Anna Signed-off-by: Suman Anna Signed-off-by: Roger Quadros Co-developed-by: Grzegorz Jaszczyk Signed-off-by: Grzegorz Jaszczyk --- drivers/remoteproc/pru_rproc.c | 59 ++++++++++++++++++++++++++++++++++ include/linux/pruss.h | 22 +++++++++++++ 2 files changed, 81 insertions(+) diff --git a/drivers/remoteproc/pru_rproc.c b/drivers/remoteproc/pru_rproc.c index 3ffd49f77cfc..a37c3f5838ea 100644 --- a/drivers/remoteproc/pru_rproc.c +++ b/drivers/remoteproc/pru_rproc.c @@ -118,6 +118,7 @@ struct pru_private_data { * @mapped_irq: virtual interrupt numbers of created fw specific mapping * @pru_interrupt_map: pointer to interrupt mapping description (firmware) * @pru_interrupt_map_sz: pru_interrupt_map size + * @rmw_lock: lock for read, modify, write operations on registers * @dbg_single_step: debug state variable to set PRU into single step mode * @dbg_continuous: debug state variable to restore PRU execution mode * @evt_count: number of mapped events @@ -135,6 +136,7 @@ struct pru_rproc { unsigned int *mapped_irq; struct pru_irq_rsc *pru_interrupt_map; size_t pru_interrupt_map_sz; + spinlock_t rmw_lock; /* register access lock */ u32 dbg_single_step; u32 dbg_continuous; u8 evt_count; @@ -151,6 +153,23 @@ 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 +void pru_control_set_reg(struct pru_rproc *pru, unsigned int reg, + u32 mask, u32 set) +{ + u32 val; + unsigned long flags; + + spin_lock_irqsave(&pru->rmw_lock, flags); + + val = pru_control_read_reg(pru, reg); + val &= ~mask; + val |= (set & mask); + pru_control_write_reg(pru, reg, val); + + spin_unlock_irqrestore(&pru->rmw_lock, flags); +} + static struct rproc *__pru_rproc_get(struct device_node *np, int index) { struct device_node *rproc_np = NULL; @@ -266,6 +285,45 @@ void pru_rproc_put(struct rproc *rproc) } EXPORT_SYMBOL_GPL(pru_rproc_put); +/** + * pru_rproc_set_ctable() - set the constant table index for the PRU + * @rproc: the rproc instance of the PRU + * @c: constant table index to set + * @addr: physical address to set it to + * + * Return: 0 on success, or errno in error case. + */ +int pru_rproc_set_ctable(struct rproc *rproc, enum pru_ctable_idx c, u32 addr) +{ + struct pru_rproc *pru = rproc->priv; + unsigned int reg; + u32 mask, set; + u16 idx; + u16 idx_mask; + + if (IS_ERR_OR_NULL(rproc)) + return -EINVAL; + + if (!rproc->dev.parent || !is_pru_rproc(rproc->dev.parent)) + return -ENODEV; + + /* pointer is 16 bit and index is 8-bit so mask out the rest */ + idx_mask = (c >= PRU_C28) ? 0xFFFF : 0xFF; + + /* ctable uses bit 8 and upwards only */ + idx = (addr >> 8) & idx_mask; + + /* configurable ctable (i.e. C24) starts at PRU_CTRL_CTBIR0 */ + reg = PRU_CTRL_CTBIR0 + 4 * (c >> 1); + mask = idx_mask << (16 * (c & 1)); + set = idx << (16 * (c & 1)); + + pru_control_set_reg(pru, reg, mask, set); + + return 0; +} +EXPORT_SYMBOL_GPL(pru_rproc_set_ctable); + 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); @@ -895,6 +953,7 @@ static int pru_rproc_probe(struct platform_device *pdev) pru->pruss = platform_get_drvdata(ppdev); pru->rproc = rproc; pru->fw_name = fw_name; + spin_lock_init(&pru->rmw_lock); mutex_init(&pru->lock); for (i = 0; i < ARRAY_SIZE(mem_names); i++) { diff --git a/include/linux/pruss.h b/include/linux/pruss.h index 43cb5c2eed08..903d0c0b75be 100644 --- a/include/linux/pruss.h +++ b/include/linux/pruss.h @@ -23,13 +23,29 @@ enum pruss_pru_id { PRUSS_NUM_PRUS, }; +/* + * enum pru_ctable_idx - Configurable Constant table index identifiers + */ +enum pru_ctable_idx { + PRU_C24 = 0, + PRU_C25, + PRU_C26, + PRU_C27, + PRU_C28, + PRU_C29, + PRU_C30, + PRU_C31, +}; + struct device_node; +struct rproc; #if IS_ENABLED(CONFIG_PRU_REMOTEPROC) struct rproc *pru_rproc_get(struct device_node *np, int index, enum pruss_pru_id *pru_id); void pru_rproc_put(struct rproc *rproc); +int pru_rproc_set_ctable(struct rproc *rproc, enum pru_ctable_idx c, u32 addr); #else @@ -41,6 +57,12 @@ pru_rproc_get(struct device_node *np, int index, enum pruss_pru_id *pru_id) static inline void pru_rproc_put(struct rproc *rproc) { } +static inline int pru_rproc_set_ctable(struct rproc *rproc, + enum pru_ctable_idx c, u32 addr) +{ + return -ENOTSUPP; +} + #endif /* CONFIG_PRU_REMOTEPROC */ static inline bool is_pru_rproc(struct device *dev)