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 X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 18087C6379F for ; Thu, 19 Nov 2020 13:10:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 986C52222A for ; Thu, 19 Nov 2020 13:10:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="xAFB8AUm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727694AbgKSNKS (ORCPT ); Thu, 19 Nov 2020 08:10:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727685AbgKSNKR (ORCPT ); Thu, 19 Nov 2020 08:10:17 -0500 Received: from mail-qt1-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D61DAC0617A7 for ; Thu, 19 Nov 2020 05:10:16 -0800 (PST) Received: by mail-qt1-x844.google.com with SMTP id i12so4255238qtj.0 for ; Thu, 19 Nov 2020 05:10:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zIfUjW+aiBjmdX+tAUjwYQ92NbJPj9lCHZuwkcM8Nkg=; b=xAFB8AUmc5Tj6IGxBYzeEcQQm9BpKWwt31skGR6lZBqLH0uXhkfqWEfVWILyg3hzWm D67SShsYQSUYRO62MT9yHS7TOSEJjA9LG7wmDYnGcNPbYlK4gwS7QydEeA9tp2TFQVKW U9uo/ecI6qWjq/hu6qF23mDm0SO52xwz5xeisfeYS0FnWrKcO/yu40UMCTE5Z7A5OKoj bhF99kvMKxIur8Od/wK8m93CZqnPkau+MHz2OsLv1+IPkM1gLfATIPDRog9gxPUgeV0b trDSiiuJL0Sc4QzBzqqlT3+8oasgwP9xrOj6XWci7iymIPWiABVwG/RAbXbwSVQTFazJ fK1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zIfUjW+aiBjmdX+tAUjwYQ92NbJPj9lCHZuwkcM8Nkg=; b=OHwAjt7kvayT5auREkoDB5WcF0VFL9nGs4hs2zGyh8pEJ/y2wZ9DfxU5TxMr/dFols QJYYU0xgJBCgeifp8PZWbV0qp5hKOLlWqHnedBfM6o3JYJecx9TIOra6REn+8tev1IIa L0NozBNbYeBW8XzGPckGoSa9ydISusRQXnRau+2GNnRyYg534FBHynDAKJAnp1oAno3B GJv0NZ8zb8ptoD/uxiB84pOqUnwiMu1DRvr/eGIPuqS899/DbM4TUGbTd01UlI7pi5Yp QN4nRRFKSYtVlqMotn8VxLfKAathJCmSv8qOJWLd382xCGP4getfw1DS1DSzmVze+Fqi /F3A== X-Gm-Message-State: AOAM53371kIK2FVXqHXT7sE3MvrGE4UEMVVNZAzX9OL5eKmUjFR8FXJa kCg4QZ5SqxAwYC1N8n/SkTF2udpzWhjnUjfQBj9a0cqgM5E= X-Google-Smtp-Source: ABdhPJwSYUcsSwolzI8rzaoxCuKLO4/2H4yip/wvOaPYuDhkLJtTlRWGJvHPEGhboRgzOqxAPZGzt7wNOI0ruoKEWOE= X-Received: by 2002:ac8:5a8c:: with SMTP id c12mr9651445qtc.97.1605791415741; Thu, 19 Nov 2020 05:10:15 -0800 (PST) MIME-Version: 1.0 References: <20201114084613.13503-1-grzegorz.jaszczyk@linaro.org> <20201114084613.13503-4-grzegorz.jaszczyk@linaro.org> <5e92947a-febf-90d0-b40e-499fe2144737@ti.com> In-Reply-To: From: Grzegorz Jaszczyk Date: Thu, 19 Nov 2020 14:10:04 +0100 Message-ID: Subject: Re: [PATCH 3/6] remoteproc/pru: Add support for PRU specific interrupt configuration To: Suman Anna Cc: Ohad Ben Cohen , Bjorn Andersson , Mathieu Poirier , linux-remoteproc@vger.kernel.org, Rob Herring , Lee Jones , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org, "Bajjuri, Praneeth" , Roger Quadros Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Hi Suman, On Thu, 19 Nov 2020 at 00:04, Suman Anna wrote: > > Hi Greg, > > On 11/18/20 9:27 AM, Grzegorz Jaszczyk wrote: > > Hi Suman, > > > > On Tue, 17 Nov 2020 at 21:40, Suman Anna wrote: > >> > >> Hi Greg, > >> > >> On 11/14/20 2:46 AM, Grzegorz Jaszczyk wrote: > >>> The firmware blob can contain optional ELF sections: .resource_table > >>> section and .pru_irq_map one. The second one contains the PRUSS > >>> interrupt mapping description, which needs to be setup before powering > >>> on the PRU core. To avoid RAM wastage this ELF section is not mapped to > >>> any ELF segment (by the firmware linker) and therefore is not loaded to > >>> PRU memory. > >>> > >>> The PRU interrupt configuration is handled within the PRUSS INTC irqchip > >>> driver and leverages the system events to interrupt channels and host > >>> interrupts mapping configuration. Relevant irq routing information is > >>> passed through a special .pru_irq_map ELF section (for interrupts routed > >>> to and used by PRU cores) or via the PRU application's device tree node > >>> (for interrupts routed to and used by the main CPU). The mappings are > >>> currently programmed during the booting/shutdown of the PRU. > >>> > >>> The interrupt configuration passed through .pru_irq_map ELF section is > >>> optional. It varies on specific firmware functionality and therefore > >>> have to be unwinded during PRU stop and performed again during > >>> PRU start. > >>> > >>> Co-developed-by: Suman Anna > >>> Signed-off-by: Suman Anna > >>> Signed-off-by: Grzegorz Jaszczyk > >>> --- > >>> drivers/remoteproc/pru_rproc.c | 191 ++++++++++++++++++++++++++++++++- > >>> drivers/remoteproc/pru_rproc.h | 46 ++++++++ > >>> 2 files changed, 236 insertions(+), 1 deletion(-) > >>> create mode 100644 drivers/remoteproc/pru_rproc.h > >>> > >>> diff --git a/drivers/remoteproc/pru_rproc.c b/drivers/remoteproc/pru_rproc.c > >>> index c94c8e965c21..825e9c7e081b 100644 > >>> --- a/drivers/remoteproc/pru_rproc.c > >>> +++ b/drivers/remoteproc/pru_rproc.c > >>> @@ -11,13 +11,16 @@ > >>> */ > >>> > >>> #include > >>> +#include > >>> #include > >>> #include > >>> +#include > >>> #include > >>> #include > >>> > >>> #include "remoteproc_internal.h" > >>> #include "remoteproc_elf_helpers.h" > >>> +#include "pru_rproc.h" > >>> > >>> /* PRU_ICSS_PRU_CTRL registers */ > >>> #define PRU_CTRL_CTRL 0x0000 > >>> @@ -41,6 +44,8 @@ > >>> #define PRU_SDRAM_DA 0x2000 /* Secondary Data RAM */ > >>> #define PRU_SHRDRAM_DA 0x10000 /* Shared Data RAM */ > >>> > >>> +#define MAX_PRU_SYS_EVENTS 160 > >>> + > >>> /** > >>> * enum pru_iomem - PRU core memory/register range identifiers > >>> * > >>> @@ -64,6 +69,10 @@ enum pru_iomem { > >>> * @rproc: remoteproc pointer for this PRU core > >>> * @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 > >>> + * @pru_interrupt_map: pointer to interrupt mapping description (firmware) > >>> + * @pru_interrupt_map_sz: pru_interrupt_map size > >>> + * @evt_count: number of mapped events > >>> */ > >>> struct pru_rproc { > >>> int id; > >>> @@ -72,6 +81,10 @@ struct pru_rproc { > >>> struct rproc *rproc; > >>> struct pruss_mem_region mem_regions[PRU_IOMEM_MAX]; > >>> const char *fw_name; > >>> + int *mapped_irq; > >>> + struct pru_irq_rsc *pru_interrupt_map; > >>> + size_t pru_interrupt_map_sz; > >>> + ssize_t evt_count; > >> > >> Do you really need this to be ssize_t type? > > > > You are right, it is not needed. I will use size_t type instead and > > modify relevant while loop. > > Hmm, size_t is ok, but perhaps the same type you used struct pru_irq_rsc is better. Ok. > > > > >> > >>> }; > >>> > >>> static inline u32 pru_control_read_reg(struct pru_rproc *pru, unsigned int reg) > >>> @@ -85,15 +98,107 @@ 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 void pru_dispose_irq_mapping(struct pru_rproc *pru) > >>> +{ > >>> + while (--pru->evt_count >= 0) { > >>> + if (pru->mapped_irq[pru->evt_count] > 0) > >>> + irq_dispose_mapping(pru->mapped_irq[pru->evt_count]); > >>> + } > >>> + > >>> + kfree(pru->mapped_irq); > >>> +} > >>> + > >>> +/* > >>> + * Parse the custom PRU interrupt map resource and configure the INTC > >>> + * appropriately. > >>> + */ > >>> +static int pru_handle_intrmap(struct rproc *rproc) > >>> +{ > >>> + struct device *dev = rproc->dev.parent; > >>> + struct pru_rproc *pru = rproc->priv; > >>> + struct pru_irq_rsc *rsc = pru->pru_interrupt_map; > >>> + struct irq_fwspec fwspec; > >>> + struct device_node *irq_parent; > >>> + int i, ret = 0; > >>> + > >>> + /* not having pru_interrupt_map is not an error */ > >>> + if (!rsc) > >>> + return 0; > >>> + > >>> + /* currently supporting only type 0 */ > >>> + if (rsc->type != 0) { > >>> + dev_err(dev, "unsupported rsc type: %d\n", rsc->type); > >>> + return -EINVAL; > >>> + } > >>> + > >>> + if (rsc->num_evts < 0 || rsc->num_evts > MAX_PRU_SYS_EVENTS) > >>> + return -EINVAL; > >>> + > >>> + if (sizeof(*rsc) + rsc->num_evts * sizeof(struct pruss_int_map) != > >>> + pru->pru_interrupt_map_sz) > >>> + return -EINVAL; > >>> + > >>> + pru->evt_count = rsc->num_evts; > >>> + pru->mapped_irq = kcalloc(pru->evt_count, sizeof(int), GFP_KERNEL); > >>> + if (!pru->mapped_irq) > >>> + return -ENOMEM; > >>> + > >>> + /* > >>> + * parse and fill in system event to interrupt channel and > >>> + * channel-to-host mapping > >>> + */ > >>> + irq_parent = of_irq_find_parent(pru->dev->of_node); > >>> + if (!irq_parent) { > >>> + kfree(pru->mapped_irq); > >>> + return -ENODEV; > >>> + } > >>> + > >>> + fwspec.fwnode = of_node_to_fwnode(irq_parent); > >>> + fwspec.param_count = 3; > >>> + for (i = 0; i < pru->evt_count; i++) { > >>> + fwspec.param[0] = rsc->pru_intc_map[i].event; > >>> + fwspec.param[1] = rsc->pru_intc_map[i].chnl; > >>> + fwspec.param[2] = rsc->pru_intc_map[i].host; > >>> + > >>> + dev_dbg(dev, "mapping%d: event %d, chnl %d, host %d\n", > >>> + i, fwspec.param[0], fwspec.param[1], fwspec.param[2]); > >>> + > >>> + pru->mapped_irq[i] = irq_create_fwspec_mapping(&fwspec); > >>> + if (pru->mapped_irq[i] < 0) { > >>> + dev_err(dev, "failed to get virq\n"); > >>> + ret = pru->mapped_irq[i]; > >>> + goto map_fail; > >>> + } > >>> + } > >>> + > >>> + return ret; > >>> + > >>> +map_fail: > >>> + pru_dispose_irq_mapping(pru); > >>> + > >>> + return ret; > >>> +} > >>> + > >>> static int pru_rproc_start(struct rproc *rproc) > >>> { > >>> struct device *dev = &rproc->dev; > >>> struct pru_rproc *pru = rproc->priv; > >>> u32 val; > >>> + int ret; > >>> > >>> dev_dbg(dev, "starting PRU%d: entry-point = 0x%llx\n", > >>> pru->id, (rproc->bootaddr >> 2)); > >>> > >>> + ret = pru_handle_intrmap(rproc); > >>> + /* > >>> + * reset references to pru interrupt map - they will stop being valid > >>> + * after rproc_start returns > >>> + */ > >>> + pru->pru_interrupt_map = NULL; > >>> + pru->pru_interrupt_map_sz = 0; > >>> + if (ret) > >>> + return ret; > >>> + > >>> val = CTRL_CTRL_EN | ((rproc->bootaddr >> 2) << 16); > >>> pru_control_write_reg(pru, PRU_CTRL_CTRL, val); > >>> > >>> @@ -112,6 +217,10 @@ static int pru_rproc_stop(struct rproc *rproc) > >>> val &= ~CTRL_CTRL_EN; > >>> pru_control_write_reg(pru, PRU_CTRL_CTRL, val); > >>> > >>> + /* dispose irq mapping - new firmware can provide new mapping */ > >>> + if (pru->mapped_irq) > >>> + pru_dispose_irq_mapping(pru); > >>> + > >>> return 0; > >>> } > >>> > >>> @@ -274,16 +383,96 @@ pru_rproc_load_elf_segments(struct rproc *rproc, const struct firmware *fw) > >>> return ret; > >>> } > >>> > >>> +static const void * > >>> +pru_rproc_find_interrupt_map(struct device *dev, const struct firmware *fw) > >>> +{ > >>> + const void *shdr, *name_table_shdr; > >>> + const char *name_table; > >>> + const u8 *elf_data = (void *)fw->data; > >>> + u8 class = fw_elf_get_class(fw); > >>> + size_t fw_size = fw->size; > >>> + const void *ehdr = elf_data; > >>> + u16 shnum = elf_hdr_get_e_shnum(class, ehdr); > >>> + u32 elf_shdr_get_size = elf_size_of_shdr(class); > >>> + u16 shstrndx = elf_hdr_get_e_shstrndx(class, ehdr); > >>> + int i; > >>> + > >>> + /* first, get the section header according to the elf class */ > >>> + shdr = elf_data + elf_hdr_get_e_shoff(class, ehdr); > >>> + /* compute name table section header entry in shdr array */ > >>> + name_table_shdr = shdr + (shstrndx * elf_shdr_get_size); > >>> + /* finally, compute the name table section address in elf */ > >>> + name_table = elf_data + elf_shdr_get_sh_offset(class, name_table_shdr); > >> > >> I see you used the style influenced by the remoteproc_elf_loader code. PRUs are > >> all 32-bit, so we need not use this strictly. I am ok with this style, but > >> prefer consistent usage style between this function and > >> pru_rproc_load_elf_segments(). > > > > Ok. I will get rid of generic elf helpers macros usage and will stick > > with elf32_* related structs instead. This will make it similar to > > pru_rproc_load_elf_segments() in terms of style. > > Yeah, ok with me. > > > > >> > >>> + > >>> + for (i = 0; i < shnum; i++, shdr += elf_shdr_get_size) { > >>> + u64 size = elf_shdr_get_sh_size(class, shdr); > >>> + u64 offset = elf_shdr_get_sh_offset(class, shdr); > >>> + u32 name = elf_shdr_get_sh_name(class, shdr); > >>> + > >>> + if (strcmp(name_table + name, ".pru_irq_map")) > >>> + continue; > >>> + > >>> + /* make sure we have the entire table */ > >>> + if (offset + size > fw_size || offset + size < size) { > >>> + dev_err(dev, "interrupt map sec truncated\n"); > >> > >> sec can confuse developers, suggest rephrasing this trace, something like > >> ".pru_irq_map section truncated" > > > > Ok. I will also update the comment to: "make sure we have the entire irq map" > > Please don't use "we" in debug traces, and just the summary of the error trace. I think you've misunderstood my answer: I agreed with your suggestion to rephrase this trace to ".pru_irq_map section truncated" but additionally I wanted to say that I will also update the comment (not the dev_err trace) which is located two lines above. > > > > >> > >>> + return ERR_PTR(-EINVAL); > >>> + } > >>> + > >>> + /* make sure table has at least the header */ > >>> + if (sizeof(struct pru_irq_rsc) > size) { > >>> + dev_err(dev, "header-less interrupt map sec\n"); > >> > >> same comment as above > > > > Sure, I will use "header-less .pru_irq_map section\n" and update the > > comment above to: "make sure irq map has at least the header" > > similar to above The same as above :) > > > > >> > >>> + return ERR_PTR(-EINVAL); > >>> + } > >>> + > >>> + return shdr; > >>> + } > >>> + > >>> + dev_dbg(dev, "no .pru_irq_map section found for this fw\n"); > >>> + > >>> + return NULL; > >>> +} > >>> + > >>> +/* > >>> + * Usa a custom parse_fw callback function for dealing with standard > >>> + * resource table and a PRU-specific custom ELF section. > >>> + * > >>> + * The firmware blob can contain optional ELF sections: .resource_table section > >>> + * and .pru_irq_map one. The second one contains the PRUSS interrupt mapping > >>> + * description, which needs to be setup before powering on the PRU core. To > >>> + * avoid RAM wastage this ELF section is not mapped to any ELF segment (by the > >>> + * firmware linker) and therefore is not loaded to PRU memory. > >> > >> Some of this description can move to Patch 2 as well. > > > > I thought about it before posting but IMO this function without > > .pru_irq_map handling is kind of self explaining. Especially when > > taking into account comment and deb_dbg message from the function body > > of previous patch. Nevertheless I can add: > > /* > > * Usa a custom parse_fw callback function for dealing with optional resource > > * table. > > */ > > Or you can keep the first two lines generic, "... dealing with PRU firmware > specific sections", and only add the details in the second paragraph in this > patch. The commit in code above resource table + these two links should suffice > for patch 2. Ok. Thank you, Grzegorz 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 X-Spam-Level: X-Spam-Status: No, score=-13.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 autolearn=unavailable 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 1EA36C2D0E4 for ; Thu, 19 Nov 2020 13:12:23 +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 727762222A for ; Thu, 19 Nov 2020 13:12:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ejb311UM"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="xAFB8AUm" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 727762222A 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:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=dsk9A7Z1TN/4Aa7uZ1/CUpKWvvIXuno7kJIcCV4wQ3A=; b=ejb311UMkZpaQc8z+GMB+Lfh8 /1Yh1tgYwxuWHIaL5bgbHLC6mGJqWMe+xdKNJAxusJL5ZCcyRRbrzyKSswIHZd7gcKmPnGVlAT4Il DLrZA09WtTduHxZAXIdLV9C/38AUwdMBdWZsULMn2AEjB5RhCBNC1bM2AXrSlH/3dVcqbgIZrGsDr unQvqWwGXwE5gFG9RAPvPP09RpFO+hmRmGMZQHiAVYr+Ne78LjyMVNYD24zjYFcZUuoL9ichoSe5m Q/brz8u4P9sEyPyfFzhq/GFDKrdNJAzQbeDBCSLAn9VmoMFDGOJ0YjG3KCXWvhro48DGtdd5GfRUP cRga/7jZA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfjhy-0004E9-6q; Thu, 19 Nov 2020 13:10:42 +0000 Received: from mail-qt1-x841.google.com ([2607:f8b0:4864:20::841]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfjhZ-00047V-Rx for linux-arm-kernel@lists.infradead.org; Thu, 19 Nov 2020 13:10:21 +0000 Received: by mail-qt1-x841.google.com with SMTP id z3so4193935qtw.9 for ; Thu, 19 Nov 2020 05:10:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zIfUjW+aiBjmdX+tAUjwYQ92NbJPj9lCHZuwkcM8Nkg=; b=xAFB8AUmc5Tj6IGxBYzeEcQQm9BpKWwt31skGR6lZBqLH0uXhkfqWEfVWILyg3hzWm D67SShsYQSUYRO62MT9yHS7TOSEJjA9LG7wmDYnGcNPbYlK4gwS7QydEeA9tp2TFQVKW U9uo/ecI6qWjq/hu6qF23mDm0SO52xwz5xeisfeYS0FnWrKcO/yu40UMCTE5Z7A5OKoj bhF99kvMKxIur8Od/wK8m93CZqnPkau+MHz2OsLv1+IPkM1gLfATIPDRog9gxPUgeV0b trDSiiuJL0Sc4QzBzqqlT3+8oasgwP9xrOj6XWci7iymIPWiABVwG/RAbXbwSVQTFazJ fK1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zIfUjW+aiBjmdX+tAUjwYQ92NbJPj9lCHZuwkcM8Nkg=; b=RbWBr6mMPYp9xAMNMUz3Qqe+8IV8iTSRIdHEyv04M/cL2mwzNFKUpUasqJU9wFlkv3 UoSxEi/ZuB2RocA7q+xTgdffrflhqfeDXjXRjOFrJ1DwDD1OgEBJY1iHx6gm0dVxSnYJ rr/FzlOFZ4gPel9U98SvpSjiEaVX+kvE0Ydb/plujD9B0zSYgTfg0xgE2azuXkFRmwM4 r+PpSoDTFSmgozssGei8mX0fGu8fj2D0A+VQahe3LUlNrg0rNFv2BlNk6l3RncYkc0FP IE9vw+SbUyFy3KiLEGXEvcM12ncOAA62/7otEwEx4RgngrrlWM9DLDFSFUfX0Urnzd3W w04A== X-Gm-Message-State: AOAM530pFsKwbFYx9fTntkQlH859PN+CIl+IZr/+BWhzBrp54UA6Qq0d HKLk9gUp9D98ZsFBOw1fxGGnHuACc/SwUVJ/8AEaEA== X-Google-Smtp-Source: ABdhPJwSYUcsSwolzI8rzaoxCuKLO4/2H4yip/wvOaPYuDhkLJtTlRWGJvHPEGhboRgzOqxAPZGzt7wNOI0ruoKEWOE= X-Received: by 2002:ac8:5a8c:: with SMTP id c12mr9651445qtc.97.1605791415741; Thu, 19 Nov 2020 05:10:15 -0800 (PST) MIME-Version: 1.0 References: <20201114084613.13503-1-grzegorz.jaszczyk@linaro.org> <20201114084613.13503-4-grzegorz.jaszczyk@linaro.org> <5e92947a-febf-90d0-b40e-499fe2144737@ti.com> In-Reply-To: From: Grzegorz Jaszczyk Date: Thu, 19 Nov 2020 14:10:04 +0100 Message-ID: Subject: Re: [PATCH 3/6] remoteproc/pru: Add support for PRU specific interrupt configuration To: Suman Anna X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201119_081020_018536_3F698967 X-CRM114-Status: GOOD ( 46.23 ) 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: Ohad Ben Cohen , devicetree@vger.kernel.org, Mathieu Poirier , "Bajjuri, Praneeth" , linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, Bjorn Andersson , Rob Herring , linux-omap@vger.kernel.org, Lee Jones , linux-arm-kernel@lists.infradead.org, Roger Quadros 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 Suman, On Thu, 19 Nov 2020 at 00:04, Suman Anna wrote: > > Hi Greg, > > On 11/18/20 9:27 AM, Grzegorz Jaszczyk wrote: > > Hi Suman, > > > > On Tue, 17 Nov 2020 at 21:40, Suman Anna wrote: > >> > >> Hi Greg, > >> > >> On 11/14/20 2:46 AM, Grzegorz Jaszczyk wrote: > >>> The firmware blob can contain optional ELF sections: .resource_table > >>> section and .pru_irq_map one. The second one contains the PRUSS > >>> interrupt mapping description, which needs to be setup before powering > >>> on the PRU core. To avoid RAM wastage this ELF section is not mapped to > >>> any ELF segment (by the firmware linker) and therefore is not loaded to > >>> PRU memory. > >>> > >>> The PRU interrupt configuration is handled within the PRUSS INTC irqchip > >>> driver and leverages the system events to interrupt channels and host > >>> interrupts mapping configuration. Relevant irq routing information is > >>> passed through a special .pru_irq_map ELF section (for interrupts routed > >>> to and used by PRU cores) or via the PRU application's device tree node > >>> (for interrupts routed to and used by the main CPU). The mappings are > >>> currently programmed during the booting/shutdown of the PRU. > >>> > >>> The interrupt configuration passed through .pru_irq_map ELF section is > >>> optional. It varies on specific firmware functionality and therefore > >>> have to be unwinded during PRU stop and performed again during > >>> PRU start. > >>> > >>> Co-developed-by: Suman Anna > >>> Signed-off-by: Suman Anna > >>> Signed-off-by: Grzegorz Jaszczyk > >>> --- > >>> drivers/remoteproc/pru_rproc.c | 191 ++++++++++++++++++++++++++++++++- > >>> drivers/remoteproc/pru_rproc.h | 46 ++++++++ > >>> 2 files changed, 236 insertions(+), 1 deletion(-) > >>> create mode 100644 drivers/remoteproc/pru_rproc.h > >>> > >>> diff --git a/drivers/remoteproc/pru_rproc.c b/drivers/remoteproc/pru_rproc.c > >>> index c94c8e965c21..825e9c7e081b 100644 > >>> --- a/drivers/remoteproc/pru_rproc.c > >>> +++ b/drivers/remoteproc/pru_rproc.c > >>> @@ -11,13 +11,16 @@ > >>> */ > >>> > >>> #include > >>> +#include > >>> #include > >>> #include > >>> +#include > >>> #include > >>> #include > >>> > >>> #include "remoteproc_internal.h" > >>> #include "remoteproc_elf_helpers.h" > >>> +#include "pru_rproc.h" > >>> > >>> /* PRU_ICSS_PRU_CTRL registers */ > >>> #define PRU_CTRL_CTRL 0x0000 > >>> @@ -41,6 +44,8 @@ > >>> #define PRU_SDRAM_DA 0x2000 /* Secondary Data RAM */ > >>> #define PRU_SHRDRAM_DA 0x10000 /* Shared Data RAM */ > >>> > >>> +#define MAX_PRU_SYS_EVENTS 160 > >>> + > >>> /** > >>> * enum pru_iomem - PRU core memory/register range identifiers > >>> * > >>> @@ -64,6 +69,10 @@ enum pru_iomem { > >>> * @rproc: remoteproc pointer for this PRU core > >>> * @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 > >>> + * @pru_interrupt_map: pointer to interrupt mapping description (firmware) > >>> + * @pru_interrupt_map_sz: pru_interrupt_map size > >>> + * @evt_count: number of mapped events > >>> */ > >>> struct pru_rproc { > >>> int id; > >>> @@ -72,6 +81,10 @@ struct pru_rproc { > >>> struct rproc *rproc; > >>> struct pruss_mem_region mem_regions[PRU_IOMEM_MAX]; > >>> const char *fw_name; > >>> + int *mapped_irq; > >>> + struct pru_irq_rsc *pru_interrupt_map; > >>> + size_t pru_interrupt_map_sz; > >>> + ssize_t evt_count; > >> > >> Do you really need this to be ssize_t type? > > > > You are right, it is not needed. I will use size_t type instead and > > modify relevant while loop. > > Hmm, size_t is ok, but perhaps the same type you used struct pru_irq_rsc is better. Ok. > > > > >> > >>> }; > >>> > >>> static inline u32 pru_control_read_reg(struct pru_rproc *pru, unsigned int reg) > >>> @@ -85,15 +98,107 @@ 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 void pru_dispose_irq_mapping(struct pru_rproc *pru) > >>> +{ > >>> + while (--pru->evt_count >= 0) { > >>> + if (pru->mapped_irq[pru->evt_count] > 0) > >>> + irq_dispose_mapping(pru->mapped_irq[pru->evt_count]); > >>> + } > >>> + > >>> + kfree(pru->mapped_irq); > >>> +} > >>> + > >>> +/* > >>> + * Parse the custom PRU interrupt map resource and configure the INTC > >>> + * appropriately. > >>> + */ > >>> +static int pru_handle_intrmap(struct rproc *rproc) > >>> +{ > >>> + struct device *dev = rproc->dev.parent; > >>> + struct pru_rproc *pru = rproc->priv; > >>> + struct pru_irq_rsc *rsc = pru->pru_interrupt_map; > >>> + struct irq_fwspec fwspec; > >>> + struct device_node *irq_parent; > >>> + int i, ret = 0; > >>> + > >>> + /* not having pru_interrupt_map is not an error */ > >>> + if (!rsc) > >>> + return 0; > >>> + > >>> + /* currently supporting only type 0 */ > >>> + if (rsc->type != 0) { > >>> + dev_err(dev, "unsupported rsc type: %d\n", rsc->type); > >>> + return -EINVAL; > >>> + } > >>> + > >>> + if (rsc->num_evts < 0 || rsc->num_evts > MAX_PRU_SYS_EVENTS) > >>> + return -EINVAL; > >>> + > >>> + if (sizeof(*rsc) + rsc->num_evts * sizeof(struct pruss_int_map) != > >>> + pru->pru_interrupt_map_sz) > >>> + return -EINVAL; > >>> + > >>> + pru->evt_count = rsc->num_evts; > >>> + pru->mapped_irq = kcalloc(pru->evt_count, sizeof(int), GFP_KERNEL); > >>> + if (!pru->mapped_irq) > >>> + return -ENOMEM; > >>> + > >>> + /* > >>> + * parse and fill in system event to interrupt channel and > >>> + * channel-to-host mapping > >>> + */ > >>> + irq_parent = of_irq_find_parent(pru->dev->of_node); > >>> + if (!irq_parent) { > >>> + kfree(pru->mapped_irq); > >>> + return -ENODEV; > >>> + } > >>> + > >>> + fwspec.fwnode = of_node_to_fwnode(irq_parent); > >>> + fwspec.param_count = 3; > >>> + for (i = 0; i < pru->evt_count; i++) { > >>> + fwspec.param[0] = rsc->pru_intc_map[i].event; > >>> + fwspec.param[1] = rsc->pru_intc_map[i].chnl; > >>> + fwspec.param[2] = rsc->pru_intc_map[i].host; > >>> + > >>> + dev_dbg(dev, "mapping%d: event %d, chnl %d, host %d\n", > >>> + i, fwspec.param[0], fwspec.param[1], fwspec.param[2]); > >>> + > >>> + pru->mapped_irq[i] = irq_create_fwspec_mapping(&fwspec); > >>> + if (pru->mapped_irq[i] < 0) { > >>> + dev_err(dev, "failed to get virq\n"); > >>> + ret = pru->mapped_irq[i]; > >>> + goto map_fail; > >>> + } > >>> + } > >>> + > >>> + return ret; > >>> + > >>> +map_fail: > >>> + pru_dispose_irq_mapping(pru); > >>> + > >>> + return ret; > >>> +} > >>> + > >>> static int pru_rproc_start(struct rproc *rproc) > >>> { > >>> struct device *dev = &rproc->dev; > >>> struct pru_rproc *pru = rproc->priv; > >>> u32 val; > >>> + int ret; > >>> > >>> dev_dbg(dev, "starting PRU%d: entry-point = 0x%llx\n", > >>> pru->id, (rproc->bootaddr >> 2)); > >>> > >>> + ret = pru_handle_intrmap(rproc); > >>> + /* > >>> + * reset references to pru interrupt map - they will stop being valid > >>> + * after rproc_start returns > >>> + */ > >>> + pru->pru_interrupt_map = NULL; > >>> + pru->pru_interrupt_map_sz = 0; > >>> + if (ret) > >>> + return ret; > >>> + > >>> val = CTRL_CTRL_EN | ((rproc->bootaddr >> 2) << 16); > >>> pru_control_write_reg(pru, PRU_CTRL_CTRL, val); > >>> > >>> @@ -112,6 +217,10 @@ static int pru_rproc_stop(struct rproc *rproc) > >>> val &= ~CTRL_CTRL_EN; > >>> pru_control_write_reg(pru, PRU_CTRL_CTRL, val); > >>> > >>> + /* dispose irq mapping - new firmware can provide new mapping */ > >>> + if (pru->mapped_irq) > >>> + pru_dispose_irq_mapping(pru); > >>> + > >>> return 0; > >>> } > >>> > >>> @@ -274,16 +383,96 @@ pru_rproc_load_elf_segments(struct rproc *rproc, const struct firmware *fw) > >>> return ret; > >>> } > >>> > >>> +static const void * > >>> +pru_rproc_find_interrupt_map(struct device *dev, const struct firmware *fw) > >>> +{ > >>> + const void *shdr, *name_table_shdr; > >>> + const char *name_table; > >>> + const u8 *elf_data = (void *)fw->data; > >>> + u8 class = fw_elf_get_class(fw); > >>> + size_t fw_size = fw->size; > >>> + const void *ehdr = elf_data; > >>> + u16 shnum = elf_hdr_get_e_shnum(class, ehdr); > >>> + u32 elf_shdr_get_size = elf_size_of_shdr(class); > >>> + u16 shstrndx = elf_hdr_get_e_shstrndx(class, ehdr); > >>> + int i; > >>> + > >>> + /* first, get the section header according to the elf class */ > >>> + shdr = elf_data + elf_hdr_get_e_shoff(class, ehdr); > >>> + /* compute name table section header entry in shdr array */ > >>> + name_table_shdr = shdr + (shstrndx * elf_shdr_get_size); > >>> + /* finally, compute the name table section address in elf */ > >>> + name_table = elf_data + elf_shdr_get_sh_offset(class, name_table_shdr); > >> > >> I see you used the style influenced by the remoteproc_elf_loader code. PRUs are > >> all 32-bit, so we need not use this strictly. I am ok with this style, but > >> prefer consistent usage style between this function and > >> pru_rproc_load_elf_segments(). > > > > Ok. I will get rid of generic elf helpers macros usage and will stick > > with elf32_* related structs instead. This will make it similar to > > pru_rproc_load_elf_segments() in terms of style. > > Yeah, ok with me. > > > > >> > >>> + > >>> + for (i = 0; i < shnum; i++, shdr += elf_shdr_get_size) { > >>> + u64 size = elf_shdr_get_sh_size(class, shdr); > >>> + u64 offset = elf_shdr_get_sh_offset(class, shdr); > >>> + u32 name = elf_shdr_get_sh_name(class, shdr); > >>> + > >>> + if (strcmp(name_table + name, ".pru_irq_map")) > >>> + continue; > >>> + > >>> + /* make sure we have the entire table */ > >>> + if (offset + size > fw_size || offset + size < size) { > >>> + dev_err(dev, "interrupt map sec truncated\n"); > >> > >> sec can confuse developers, suggest rephrasing this trace, something like > >> ".pru_irq_map section truncated" > > > > Ok. I will also update the comment to: "make sure we have the entire irq map" > > Please don't use "we" in debug traces, and just the summary of the error trace. I think you've misunderstood my answer: I agreed with your suggestion to rephrase this trace to ".pru_irq_map section truncated" but additionally I wanted to say that I will also update the comment (not the dev_err trace) which is located two lines above. > > > > >> > >>> + return ERR_PTR(-EINVAL); > >>> + } > >>> + > >>> + /* make sure table has at least the header */ > >>> + if (sizeof(struct pru_irq_rsc) > size) { > >>> + dev_err(dev, "header-less interrupt map sec\n"); > >> > >> same comment as above > > > > Sure, I will use "header-less .pru_irq_map section\n" and update the > > comment above to: "make sure irq map has at least the header" > > similar to above The same as above :) > > > > >> > >>> + return ERR_PTR(-EINVAL); > >>> + } > >>> + > >>> + return shdr; > >>> + } > >>> + > >>> + dev_dbg(dev, "no .pru_irq_map section found for this fw\n"); > >>> + > >>> + return NULL; > >>> +} > >>> + > >>> +/* > >>> + * Usa a custom parse_fw callback function for dealing with standard > >>> + * resource table and a PRU-specific custom ELF section. > >>> + * > >>> + * The firmware blob can contain optional ELF sections: .resource_table section > >>> + * and .pru_irq_map one. The second one contains the PRUSS interrupt mapping > >>> + * description, which needs to be setup before powering on the PRU core. To > >>> + * avoid RAM wastage this ELF section is not mapped to any ELF segment (by the > >>> + * firmware linker) and therefore is not loaded to PRU memory. > >> > >> Some of this description can move to Patch 2 as well. > > > > I thought about it before posting but IMO this function without > > .pru_irq_map handling is kind of self explaining. Especially when > > taking into account comment and deb_dbg message from the function body > > of previous patch. Nevertheless I can add: > > /* > > * Usa a custom parse_fw callback function for dealing with optional resource > > * table. > > */ > > Or you can keep the first two lines generic, "... dealing with PRU firmware > specific sections", and only add the details in the second paragraph in this > patch. The commit in code above resource table + these two links should suffice > for patch 2. Ok. Thank you, Grzegorz _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel