From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4897FC4332F for ; Fri, 23 Dec 2022 13:23:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To: Subject:MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=P3qjKQD7AL9MjCOmBEDcgQVMa+xbluzYS7HOtrAnLCE=; b=ePu5P4PusKOgoE P5CpDARkeVc3lRGTpo76tDfiJfsWtrqVP5y1JTzVzHW3pBPu1mbgLyisVxLR648ARKniAhRrUbr+C ye1VUJytrd6PHfS9EJPUqUR2zQs3/efzPoIUBn3DBtVhBLvDvOlpkFRvrQXeCAV37+47VFP5fKcLW iUZt/vNNtUwtD2DnFaQft58t2o2niuuoSBNIiB/udmkh/wWvWVt69twaaGHDxBEAJyaQMdNLv+5uN 7zyJ3e7PpEurHcypmfvSQtsMo/5nk9d/fkhPgJjsJruhJK/N4N6I4/5GfPl3kM1c/KlBd6qPlIZEA ldnKDrIiEzw/ws9xvABw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p8i05-008M8D-Hs; Fri, 23 Dec 2022 13:22:13 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1p8hzz-008M5H-Tw for linux-arm-kernel@lists.infradead.org; Fri, 23 Dec 2022 13:22:10 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 28A1860D38; Fri, 23 Dec 2022 13:22:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77D30C433D2; Fri, 23 Dec 2022 13:22:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671801725; bh=/bkLWGL7GWvujKVMX2lIDGVEMUmN/vqQnpwsZq8vxTk=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=ekAU446s8t4ownogb+ZXqJQ5p5EoM7/e+NMIRUNPNw0C8JBX4Lf2CnyKrewEQh6n/ btGVZ+4WCJ21VkQcWUj9xOwPwXC4ulYcZ4JgFdKaNariQ4YfymecmJ7CtrJQ6KBPdt c7//4tia1Fy+IPo46y6Kh0/WJ4JZ1UapTOc2fTbpdluObmY1yzqJdQz1TmqSxRwxDr cGuR5tY17BNfg/VR2/xR7JYtf5bKd19pzQPM2qCEEHfqPd3OyMku7V9xzkb51IECfh xl4MaCp81rJSY/BWEWEngTT2eBrAQrBGdveD6s7w0zytrUBZEvvfAVMw6SJQxL0WOf aYOyW2oXQtJZA== Message-ID: Date: Fri, 23 Dec 2022 15:22:00 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH v12 5/6] remoteproc: pru: Add pru_rproc_set_ctable() function Content-Language: en-US To: Md Danish Anwar , MD Danish Anwar , Mathieu Poirier , Krzysztof Kozlowski , Rob Herring Cc: Suman Anna , "Andrew F . Davis" , nm@ti.com, vigneshr@ti.com, srk@ti.com, linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org References: <20221216053313.2974826-1-danishanwar@ti.com> <20221216053313.2974826-6-danishanwar@ti.com> <73577808-b133-62d4-2c16-670d6a49b067@ti.com> From: Roger Quadros In-Reply-To: <73577808-b133-62d4-2c16-670d6a49b067@ti.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221223_052208_317502_9D842A8B X-CRM114-Status: GOOD ( 31.54 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Danish, On 23/12/2022 12:58, Md Danish Anwar wrote: > Hi Roger, > > Can you please review this patch. I am the author of that patch so my review tag will be kind or worthless. ;) cheers, -roger > > Thanks, > Danish. > > On 16/12/22 11:03, MD Danish Anwar wrote: >> 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. >> >> CTABLE for stands for "constant table". >> Each CTable entry just holds the upper address bits so PRU can >> reference to external memory with larger address bits. >> >> For use case please see >> prueth_sw_emac_config() in "drivers/net/ethernet/ti/prueth_switch.c" >> >> /* Set in constant table C28 of PRUn to ICSS Shared memory */ >> pru_rproc_set_ctable(prueth->pru0, PRU_C28, sharedramaddr); >> pru_rproc_set_ctable(prueth->pru1, PRU_C28, sharedramaddr); >> >> /* Set in constant table C30 of PRUn to OCMC memory */ >> pru_rproc_set_ctable(prueth->pru0, PRU_C30, ocmcaddr); >> pru_rproc_set_ctable(prueth->pru1, PRU_C30, ocmcaddr); >> >> Signed-off-by: Andrew F. Davis >> Signed-off-by: Suman Anna >> Signed-off-by: Roger Quadros >> Signed-off-by: Grzegorz Jaszczyk >> Signed-off-by: MD Danish Anwar >> --- >> 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 8e2fbe392ef3..176186882acf 100644 >> --- a/drivers/remoteproc/pru_rproc.c >> +++ b/drivers/remoteproc/pru_rproc.c >> @@ -120,6 +120,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 >> @@ -137,6 +138,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; >> u32 dbg_single_step; >> u32 dbg_continuous; >> u8 evt_count; >> @@ -153,6 +155,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 rproc *rproc; >> @@ -269,6 +288,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); >> @@ -940,6 +998,7 @@ static int pru_rproc_probe(struct platform_device *pdev) >> pru->rproc = rproc; >> pru->fw_name = fw_name; >> pru->client_np = NULL; >> + 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 6ea737e995e9..a6bc3df92fee 100644 >> --- a/include/linux/pruss.h >> +++ b/include/linux/pruss.h >> @@ -28,13 +28,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 >> >> @@ -46,6 +62,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 -EOPNOTSUPP; >> +} >> + >> #endif /* CONFIG_PRU_REMOTEPROC */ >> >> static inline bool is_pru_rproc(struct device *dev) _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel