From patchwork Mon Nov 26 07:52:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 151986 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp5329252ljp; Sun, 25 Nov 2018 23:54:01 -0800 (PST) X-Google-Smtp-Source: AFSGD/XRpX4URZZDx6kJNf0moEsdztMXBoEtcU32wXauLGMd5pHaqxTe9/lcjxe2a1+ig5UIEK+k X-Received: by 2002:a63:1157:: with SMTP id 23mr23950757pgr.245.1543218841365; Sun, 25 Nov 2018 23:54:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543218841; cv=none; d=google.com; s=arc-20160816; b=Df49NJ1a8eFXmj10mFvkalYOwHEFPlbIvDLvQ/Q1Fq4fxYlNsvuNT29lQZASWDPNVv JcFX5/9ecrco4Gyw7Lkw5fRPYX7QgxGbREU8MZNoim/rd/gfj1xfs9D6UMAkz99ALgHV 9vU7rkOw3duq1qMU/chqlIbKqDCbWGNehtmwnEXwjkkdzZDXkp6CV/o3dtKuP7B+1x9D 4Pq4QN2XwzU+AYmXiyoG1UBTrWJ+BH8y3/1b0NKMldI2MpCM1xBsMqZdewKbfq9WLF42 jsJnJNbw96ThfT0oEADsERmNa7dslff2dNafZCcaIZ0ByShxXEwIdYtDi5Z0zhHbjmkv nDlw== 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; bh=BrMkc1KybtAC28p8Ajc9LZ6lW5Gyw/fQJLxaqaSXIGY=; b=R+v4Trops8b6GAOslLGiJHenW2VvVv9BpZ6A5RWF1qiTWYPDIvVFxuv0dr7MYUs5nV Ng8gA+dZaEf/ftoRJhAx998GoU23hoh96FWkNl+GAMAPB+lgf6mvdlMsBp4PIdMqM49a htBoamE7ThwehG80z6p3ZPTm/Bgad5mjQ+zzQm7mq3tUxZNmIcyh61gKf2UGeVCYijgh v9+tkYHkuOWDc+9f/1NQeJUXAec7dytT4IcJJ7BG3sEDh5xTBwa89MfapIFKLPxd3l+K LKUQl+K3/5FznrFuAX4K4MePhK7We1X9+iT4bCObNBpr8Lwljvk/JWazJRtmkeVCyi+T LWpg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=NONE dis=QUARANTINE) 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 e1-v6si65161954plk.4.2018.11.25.23.54.01; Sun, 25 Nov 2018 23:54:01 -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; 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=fail (p=QUARANTINE sp=NONE dis=QUARANTINE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726820AbeKZSrP (ORCPT + 32 others); Mon, 26 Nov 2018 13:47:15 -0500 Received: from fllv0016.ext.ti.com ([198.47.19.142]:36600 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726287AbeKZSrO (ORCPT ); Mon, 26 Nov 2018 13:47:14 -0500 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id wAQ7rtaN102596; Mon, 26 Nov 2018 01:53:55 -0600 Received: from DLEE115.ent.ti.com (dlee115.ent.ti.com [157.170.170.26]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id wAQ7rt8F038728 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 26 Nov 2018 01:53:55 -0600 Received: from DLEE107.ent.ti.com (157.170.170.37) by DLEE115.ent.ti.com (157.170.170.26) 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:55 -0600 Received: from dflp33.itg.ti.com (10.64.6.16) by DLEE107.ent.ti.com (157.170.170.37) 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:55 -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 wAQ7rtmx009392; Mon, 26 Nov 2018 01:53:55 -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 wAQ7qn1T024490; Mon, 26 Nov 2018 01:53:51 -0600 From: Roger Quadros To: , CC: , , , , , , , , , , , , , , , Subject: [PATCH 15/16] remoteproc/pru: add support for parsing pru interrupt mapping from DT Date: Mon, 26 Nov 2018 09:52:48 +0200 Message-ID: <1543218769-5507-16-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: Tero Kristo PRU interrupt mapping can now be parsed from devicetree also, from ti,pru-interrupt-map property. This is an alternative configuration method in addition to the legacy resource table config. If both are provided, the config in DT takes precedence. Signed-off-by: Tero Kristo [s-anna@ti.com: various fixes and cleanups] Signed-off-by: Suman Anna Signed-off-by: Roger Quadros --- drivers/remoteproc/pru_rproc.c | 109 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 106 insertions(+), 3 deletions(-) -- 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 84f006b..540cce3 100644 --- a/drivers/remoteproc/pru_rproc.c +++ b/drivers/remoteproc/pru_rproc.c @@ -63,6 +63,7 @@ enum pru_mem { * @irq_ring: IRQ number to use for processing vring buffers * @irq_kick: IRQ number to use to perform virtio kick * @mem_regions: data for each of the PRU memory regions + * @intc_config: PRU INTC configuration data * @dram0: PRUSS DRAM0 region * @dram1: PRUSS DRAM1 region * @shrdram: PRUSS SHARED RAM region @@ -73,6 +74,7 @@ enum pru_mem { * @shrdram_da: device address of shared Data RAM * @fw_name: name of firmware image used during loading * @gpmux_save: saved value for gpmux config + * @dt_irqs: number of irqs configured from DT * @lock: mutex to protect client usage * @dbg_single_step: debug state variable to set PRU into single step mode * @dbg_continuous: debug state variable to restore PRU execution mode @@ -87,6 +89,7 @@ struct pru_rproc { int irq_vring; int irq_kick; struct pruss_mem_region mem_regions[PRU_MEM_MAX]; + struct pruss_intc_config intc_config; struct pruss_mem_region dram0; struct pruss_mem_region dram1; struct pruss_mem_region shrdram; @@ -97,6 +100,7 @@ struct pru_rproc { u32 shrdram_da; const char *fw_name; u8 gpmux_save; + int dt_irqs; struct mutex lock; /* client access lock */ u32 dbg_single_step; u32 dbg_continuous; @@ -180,6 +184,87 @@ static struct rproc *__pru_rproc_get(struct device_node *np, int index) return rproc; } +static int pru_get_intc_dt_config(struct device *dev, const char *propname, + int index, + struct pruss_intc_config *intc_config) +{ + struct device_node *np = dev->of_node; + struct property *prop; + int ret = 0, entries, i; + int dt_irqs = 0; + u32 *arr; + int max_system_events, max_pru_channels, max_pru_host_ints; + + max_system_events = MAX_PRU_SYS_EVENTS; + max_pru_channels = MAX_PRU_CHANNELS; + max_pru_host_ints = MAX_PRU_CHANNELS; + + prop = of_find_property(np, propname, NULL); + if (!prop) + return 0; + + entries = of_property_count_u32_elems(np, propname); + if (entries <= 0 || entries % 4) + return -EINVAL; + + arr = kmalloc_array(entries, sizeof(u32), GFP_KERNEL); + if (!arr) + return -ENOMEM; + + ret = of_property_read_u32_array(np, propname, arr, entries); + if (ret) + return -EINVAL; + + for (i = 0; i < ARRAY_SIZE(intc_config->sysev_to_ch); i++) + intc_config->sysev_to_ch[i] = -1; + + for (i = 0; i < ARRAY_SIZE(intc_config->ch_to_host); i++) + intc_config->ch_to_host[i] = -1; + + for (i = 0; i < entries; i += 4) { + if (arr[i] != index) + continue; + + if (arr[i + 1] < 0 || + arr[i + 1] >= max_system_events) { + dev_dbg(dev, "bad sys event %d\n", arr[i + 1]); + ret = -EINVAL; + goto err; + } + + if (arr[i + 2] < 0 || + arr[i + 2] >= max_pru_channels) { + dev_dbg(dev, "bad channel %d\n", arr[i + 2]); + ret = -EINVAL; + goto err; + } + + if (arr[i + 3] < 0 || + arr[i + 3] >= max_pru_host_ints) { + dev_dbg(dev, "bad irq %d\n", arr[i + 3]); + ret = -EINVAL; + goto err; + } + + intc_config->sysev_to_ch[arr[i + 1]] = arr[i + 2]; + dev_dbg(dev, "sysevt-to-ch[%d] -> %d\n", arr[i + 1], + arr[i + 2]); + + intc_config->ch_to_host[arr[i + 2]] = arr[i + 3]; + dev_dbg(dev, "chnl-to-host[%d] -> %d\n", arr[i + 2], + arr[i + 3]); + + dt_irqs++; + } + + kfree(arr); + return dt_irqs; + +err: + kfree(arr); + return ret; +} + /** * pru_rproc_get() - get the PRU rproc instance from a device node * @np: the user/client device node @@ -251,6 +336,15 @@ struct rproc *pru_rproc_get(struct device_node *np, int index) } } + ret = pru_get_intc_dt_config(dev, "ti,pru-interrupt-map", + index, &pru->intc_config); + if (ret < 0) { + dev_err(dev, "error getting DT interrupt map: %d\n", ret); + goto err; + } + + pru->dt_irqs = ret; + return rproc; err: @@ -568,7 +662,13 @@ static int pru_rproc_start(struct rproc *rproc) dev_dbg(dev, "starting PRU%d: entry-point = 0x%x\n", pru->id, (rproc->bootaddr >> 2)); - /* TODO: INTC setup */ + if (pru->dt_irqs) { + ret = pruss_intc_configure(pru->pruss, &pru->intc_config); + if (ret) { + dev_err(dev, "failed to configure intc %d\n", ret); + return ret; + } + } if (!list_empty(&pru->rproc->rvdevs)) { if (!pru->mbox && (pru->irq_vring <= 0 || pru->irq_kick <= 0)) { @@ -596,7 +696,8 @@ static int pru_rproc_start(struct rproc *rproc) return 0; fail: - /* TODO: INTC cleanup */ + if (pru->dt_irqs) + pruss_intc_unconfigure(pru->pruss, &pru->intc_config); return ret; } @@ -618,7 +719,9 @@ static int pru_rproc_stop(struct rproc *rproc) !pru->mbox && pru->irq_vring > 0) free_irq(pru->irq_vring, pru); - /* TODO: INTC cleanup */ + /* undo INTC config */ + if (pru->dt_irqs) + pruss_intc_unconfigure(pru->pruss, &pru->intc_config); return 0; }