From patchwork Fri Oct 27 12:44:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 117311 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp727207qgn; Fri, 27 Oct 2017 05:44:43 -0700 (PDT) X-Google-Smtp-Source: ABhQp+S8BK3UKYWk+hcUL9kxfVh8c/eRbuq0KqLLNZBS8IenL3MEQVPRIoOWTRd6lAqJ8sunntOF X-Received: by 10.98.75.71 with SMTP id y68mr368366pfa.45.1509108283856; Fri, 27 Oct 2017 05:44:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509108283; cv=none; d=google.com; s=arc-20160816; b=AcOcqIwE7G/P4Nmdn7WB8n3ajmMifztIP3tEcg0YeO9qHWigHU+j1vYy/1XoHSX26n WgIirxi5+T5FWtW0nv3YVjB8Phte8ILN0YjC/ZrZOWoNGp/u0VwQ5XlzLyxua4FX1SDc uCo+5vpZFnJa79sPavpLo0ALc8t4Gkn/VhXpQ9BRM7QwSwt2SAK9Fl9DFhaZSLmiyMm/ AeuFCxjfjBbC+JtCVRzrOCSVzwQGNEzTWQpZDlknVk4UUk1rdWn1aUD+3LDBIrYHnPPh LZO1X9KMimKe1fEe0/VvDvRsOCl4pma9LT3XwRXVnqQczH62VMUi3ug6hNeLSb08+qdH rC1g== 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:arc-authentication-results; bh=+p0JMoaaR1fg2nzsQic4PHrvT7oTwU5+n6sJI8MvLpA=; b=k25LPEIhP1EnFXdLs7dUDf2uwVWcWnwcmC5qKMyHpB3Izk413WOneM5dgvamaYnRLt GuqtZEoZePkX8uExoGJZOC+cGhG+86HAw/HUhrz5ybzV+tHB/6Bxta9DfL4BwGcIKmk4 qE4h3uEqkztFzhlUwyOlS3KWSXRTQk2hbmf6/Jwx4sJ1bxwMzUzTxje9wx5HjLRrsK+D I91tEnRfF0lI+wao7H3UObX6zo7t4GGDPQJl//wcbLsMh5Lsxt3ldOD0yT8NxNj0QRlG 8uY4FeWRbTBLbdUWLzLoSbii2aONbxXFiYFgUG7jnBm+3Sqvj4YSBOc6BBhoabCvp+eG nNcw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m66si5333968pfb.72.2017.10.27.05.44.43; Fri, 27 Oct 2017 05:44:43 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752658AbdJ0Moj (ORCPT + 27 others); Fri, 27 Oct 2017 08:44:39 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:39695 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752459AbdJ0Mod (ORCPT ); Fri, 27 Oct 2017 08:44:33 -0400 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v9RCi214004814; Fri, 27 Oct 2017 14:44:31 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2dtg42ywk6-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 27 Oct 2017 14:44:31 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 27A983D; Fri, 27 Oct 2017 12:44:31 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag7node2.st.com [10.75.127.20]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 0A60626E0; Fri, 27 Oct 2017 12:44:31 +0000 (GMT) Received: from localhost (10.75.127.49) by SFHDAG7NODE2.st.com (10.75.127.20) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 27 Oct 2017 14:44:30 +0200 From: Loic Pallardy To: , CC: , , , , Loic Pallardy Subject: [PATCH 1/7] remoteproc: add rproc_va_to_pa function Date: Fri, 27 Oct 2017 14:44:08 +0200 Message-ID: <1509108254-22296-2-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1509108254-22296-1-git-send-email-loic.pallardy@st.com> References: <1509108254-22296-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.49] X-ClientProxiedBy: SFHDAG4NODE3.st.com (10.75.127.12) To SFHDAG7NODE2.st.com (10.75.127.20) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-10-27_07:, , signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This new function translates CPU virtual address in CPU physical one according to virtual address location. Signed-off-by: Loic Pallardy --- drivers/remoteproc/remoteproc_core.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) -- 1.9.1 diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index eab14b4..faa18a7 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -139,6 +139,17 @@ static void rproc_disable_iommu(struct rproc *rproc) iommu_domain_free(domain); } +static phys_addr_t rproc_va_to_pa(void *cpu_addr) +{ + if (is_vmalloc_addr(cpu_addr)) { + return page_to_phys(vmalloc_to_page(cpu_addr)) + + offset_in_page(cpu_addr); + } + + WARN_ON(!virt_addr_valid(cpu_addr)); + return virt_to_phys(cpu_addr); +} + /** * rproc_da_to_va() - lookup the kernel virtual address for a remoteproc address * @rproc: handle of a remote processor @@ -700,7 +711,7 @@ static int rproc_handle_carveout(struct rproc *rproc, * In this case, the device address and the physical address * are the same. */ - rsc->pa = dma; + rsc->pa = (u32)rproc_va_to_pa(va); carveout->va = va; carveout->len = rsc->len; From patchwork Fri Oct 27 12:44:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 117312 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp727242qgn; Fri, 27 Oct 2017 05:44:46 -0700 (PDT) X-Google-Smtp-Source: ABhQp+TDXDL8rtFSLqEeh9vehlrpcgikY78j1LpMF0hVrCYiv0hwTuqS9Opdjmofg8ay0jW8v3PL X-Received: by 10.98.16.149 with SMTP id 21mr390710pfq.182.1509108286207; Fri, 27 Oct 2017 05:44:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509108286; cv=none; d=google.com; s=arc-20160816; b=SO6sSTPXDEkrrOgOkN8CMEbrZhP4N0a34IzVLMAgyRsnjKwYgwvqNKRPgKf7zV46DR pe7ECj5xcqHPm05pS1Y6YH6PdD7gxGjJkYS/4rfVe+YZBAKLrNvMNnaDGduGX5IoJXQj NRc2js39lZsKFxD6OJBjhcLc9a39CiGUSK+k1QCTglPAcWW3ydckbtHWvalJV3tkd9xk 5eKfzYkoSOnWoLuxcp3bQssiHRekRNJsU2RI5yC+Ib34Wpv6YvytwAaVimRRB0zoRa5P Guhj2FBCXl9EN9hyjfv0k5ovKmYFikHcLapQWb668eFAB9dyHHXAoqvbRpbZaSAaIuse t9vA== 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:arc-authentication-results; bh=OkuJivHxzUISNOQmCOdTuRlfzn2S1thnoD8Aw4ookqA=; b=quS435V5H9VfepJRI4WzNul2j2e6UmBcENtL+cDYdWjkVYfZxdwPFCmAnZCCxH2AJe RHHaJM4DTR5d6DaEl6bq4Hl4jRD7qxpjPEhygIndETz6NbVISYs44Slrz8JI6v450K/J t2tm76WPOjxM6E63nbI6fjeYPgDtYltnspm0sEOTWlIVubA4DIELE9lAea8No+iT8UE8 h3s85uH4Civc3hQE/VPoYxWRgJrhpjWKXhuh/gbZ3/zQCokmdlzgdlstdegqIJXQCUWI n4zPUGigvcB22m9YniY+7o81iE//hfg4LRnzoLT0RiO1+5QKPGIH7wFjY1/4yLbzKMPE nRxw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m66si5333968pfb.72.2017.10.27.05.44.45; Fri, 27 Oct 2017 05:44:46 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752695AbdJ0Moo (ORCPT + 27 others); Fri, 27 Oct 2017 08:44:44 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:19591 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752544AbdJ0Moe (ORCPT ); Fri, 27 Oct 2017 08:44:34 -0400 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v9RCi2oO004813; Fri, 27 Oct 2017 14:44:32 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2dtg42ywk9-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 27 Oct 2017 14:44:32 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 09CDF31; Fri, 27 Oct 2017 12:44:32 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag7node2.st.com [10.75.127.20]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id D634C26E0; Fri, 27 Oct 2017 12:44:31 +0000 (GMT) Received: from localhost (10.75.127.48) by SFHDAG7NODE2.st.com (10.75.127.20) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 27 Oct 2017 14:44:31 +0200 From: Loic Pallardy To: , CC: , , , , Loic Pallardy Subject: [PATCH 2/7] remoteproc: add release ops in rproc_mem_entry struct Date: Fri, 27 Oct 2017 14:44:09 +0200 Message-ID: <1509108254-22296-3-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1509108254-22296-1-git-send-email-loic.pallardy@st.com> References: <1509108254-22296-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.48] X-ClientProxiedBy: SFHDAG7NODE2.st.com (10.75.127.20) To SFHDAG7NODE2.st.com (10.75.127.20) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-10-27_07:, , signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Memory entry could be allocated in different ways (ioremap, dma_alloc_coherent, internal RAM allocator...). This patch introduces a release ops in rproc_mem_entry structure to associate dedicated release mechanism to each memory entry descriptor in order to keep remoteproc core generic. Signed-off-by: Loic Pallardy --- drivers/remoteproc/remoteproc_core.c | 26 ++++++++++++++++++++++---- include/linux/remoteproc.h | 6 ++++-- 2 files changed, 26 insertions(+), 6 deletions(-) -- 1.9.1 diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index faa18a7..f23daf9 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -592,6 +592,25 @@ static int rproc_handle_devmem(struct rproc *rproc, struct fw_rsc_devmem *rsc, } /** + * rproc_release_carveout() - release acquired carveout + * @rproc: rproc handle + * @mem: the memory entry to release + * + * This function releases specified memory entry @mem allocated via + * dma_alloc_coherent() function by @rproc. + */ +static int rproc_release_carveout(struct rproc *rproc, struct rproc_mem_entry *mem) +{ + struct device *dev = &rproc->dev; + + /* clean up carveout allocations */ + dma_free_coherent(dev->parent, mem->len, mem->va, mem->dma); + list_del(&mem->node); + kfree(mem); + return 0; +} + +/** * rproc_handle_carveout() - handle phys contig memory allocation requests * @rproc: rproc handle * @rsc: the resource entry @@ -717,6 +736,7 @@ static int rproc_handle_carveout(struct rproc *rproc, carveout->len = rsc->len; carveout->dma = dma; carveout->da = rsc->da; + carveout->release = rproc_release_carveout; list_add_tail(&carveout->node, &rproc->carveouts); @@ -847,10 +867,8 @@ static void rproc_resource_cleanup(struct rproc *rproc) /* clean up carveout allocations */ list_for_each_entry_safe(entry, tmp, &rproc->carveouts, node) { - dma_free_coherent(dev->parent, entry->len, entry->va, - entry->dma); - list_del(&entry->node); - kfree(entry); + if (entry->release) + entry->release(rproc, entry); } /* clean up remote vdev entries */ diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 44e630e..8780f2e 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -305,12 +305,15 @@ struct fw_rsc_vdev { struct fw_rsc_vdev_vring vring[0]; } __packed; +struct rproc; + /** * struct rproc_mem_entry - memory entry descriptor * @va: virtual address * @dma: dma address * @len: length, in bytes * @da: device address + * @release: release associated memory * @priv: associated data * @node: list node */ @@ -319,12 +322,11 @@ struct rproc_mem_entry { dma_addr_t dma; int len; u32 da; + int (*release)(struct rproc *rproc, struct rproc_mem_entry *mem); void *priv; struct list_head node; }; -struct rproc; - /** * struct rproc_ops - platform-specific device handlers * @start: power on the device and boot it From patchwork Fri Oct 27 12:44:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 117318 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp728191qgn; Fri, 27 Oct 2017 05:45:48 -0700 (PDT) X-Google-Smtp-Source: ABhQp+R6ytYS6rfmIz5OI/kuT4CBIG7xqMEoaMGuXFCP1sfd4Tzh26VPcFt1t7fgu5MI4289iJsK X-Received: by 10.99.150.2 with SMTP id c2mr203595pge.386.1509108348074; Fri, 27 Oct 2017 05:45:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509108348; cv=none; d=google.com; s=arc-20160816; b=k7hXroZFQvfj8c4f80LpJk9D4y5e4mCApFABB2U+uwf/6QRG+2sl3nOKCMqxRZn+pI 2fTp1t8WEmDc9GobhLv6h3FYrEpJUyktCpaO1dJOYlG875MuGdvFC8z5TYTkvhkHuC1Q DLcysMUPZkAIgaGNb+66aIClgqgCC1jzqcXMhwp5tTEnvlNW/hte9UAMEHuIiHsF29H5 8IpU8MF6iqlScTDG9mNMJHs5v9GQUYJ432Bq8+1Bpi01dQII5rIV6ECNpXPbthTrYblQ nykpc4j7aOVBJAud0nmWrGl/KAhDDgHHJ612c0OjFme/GqDWzbsI48VD55KM5p9uR2NK FWng== 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:arc-authentication-results; bh=OGnuf/AzXk/2L6bJeDbKcupxE894ltzj74HbVsI9fig=; b=vA3i7ZEs2Dz9wt0MQ1WcUiKG6MPbrOb+i90VEdpY9h+afjRhQsHpV+tXdBQu0t19Ri TYGI1jfMWmb71ZDQ08WgJQk8Yb2YUlE+f3oUPjpK6YA8G82N3a/4/Sxuf26JP1lKfikk LNgzFalV11r7STLCb/hgpmAMcTMW2hOcRyyRW/Q7xLfsuUFiHmx4wGsXQIbOBiN85EUt FC7XygbU/zvt2BrczoTrq3SMYtTWGBE7WK9eKkavqM/QqYeGzXbDCbzHX54b7XHW9lMu wGGkRDOyy+2GFjEe26slUuWSimVp+4UT27cgEgBSpHqtJ6G0bRRE87K6J8bNFp6xyG0E G2JQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m3si4460994plt.232.2017.10.27.05.45.47; Fri, 27 Oct 2017 05:45:48 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752776AbdJ0Mpp (ORCPT + 27 others); Fri, 27 Oct 2017 08:45:45 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:33908 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752412AbdJ0Mof (ORCPT ); Fri, 27 Oct 2017 08:44:35 -0400 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v9RChee6000593; Fri, 27 Oct 2017 14:44:33 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2duapy8939-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 27 Oct 2017 14:44:33 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id AF57534; Fri, 27 Oct 2017 12:44:32 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag7node2.st.com [10.75.127.20]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 9795326E0; Fri, 27 Oct 2017 12:44:32 +0000 (GMT) Received: from localhost (10.75.127.46) by SFHDAG7NODE2.st.com (10.75.127.20) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 27 Oct 2017 14:44:32 +0200 From: Loic Pallardy To: , CC: , , , , Loic Pallardy Subject: [PATCH 3/7] remoteproc: introduce rproc_add_carveout function Date: Fri, 27 Oct 2017 14:44:10 +0200 Message-ID: <1509108254-22296-4-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1509108254-22296-1-git-send-email-loic.pallardy@st.com> References: <1509108254-22296-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.46] X-ClientProxiedBy: SFHDAG1NODE1.st.com (10.75.127.1) To SFHDAG7NODE2.st.com (10.75.127.20) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-10-27_07:, , signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch introduces a new API to allow platform driver to register platform specific carveout regions. Signed-off-by: Loic Pallardy --- drivers/remoteproc/remoteproc_core.c | 22 ++++++++++++++++++++++ drivers/remoteproc/remoteproc_internal.h | 7 +++++++ include/linux/remoteproc.h | 2 ++ 3 files changed, 31 insertions(+) -- 1.9.1 diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index f23daf9..279320a 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -737,6 +737,7 @@ static int rproc_handle_carveout(struct rproc *rproc, carveout->dma = dma; carveout->da = rsc->da; carveout->release = rproc_release_carveout; + carveout->priv = (void *)CARVEOUT_RSC_ALLOCATED; list_add_tail(&carveout->node, &rproc->carveouts); @@ -751,6 +752,27 @@ static int rproc_handle_carveout(struct rproc *rproc, return ret; } +/** + * rproc_add_carveout() - register an allocated carveout region + * @rproc: rproc handle + * @mem: memory entry to register + * + * This function registers specified memory entry in @rproc carveouts list. + * Specified carveout should have been allocated before registering. + */ +int rproc_add_carveout(struct rproc *rproc, struct rproc_mem_entry *mem) +{ + if (!rproc || !mem) + return -EINVAL; + + mem->priv = (void *)CARVEOUT_EXTERNAL; + + list_add_tail(&mem->node, &rproc->carveouts); + + return 0; +} +EXPORT_SYMBOL(rproc_add_carveout); + /* * A lookup table for resource handlers. The indices are defined in * enum fw_resource_type. diff --git a/drivers/remoteproc/remoteproc_internal.h b/drivers/remoteproc/remoteproc_internal.h index c1077be..69b22ac 100644 --- a/drivers/remoteproc/remoteproc_internal.h +++ b/drivers/remoteproc/remoteproc_internal.h @@ -23,6 +23,13 @@ #include #include +/* Indicate carveout origin */ +enum carveout_src { + CARVEOUT_RSC = 0, + CARVEOUT_RSC_ALLOCATED = 1, + CARVEOUT_EXTERNAL = 2, +}; + struct rproc; /** diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 8780f2e..5bd5175 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -522,6 +522,8 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, int rproc_del(struct rproc *rproc); void rproc_free(struct rproc *rproc); +int rproc_add_carveout(struct rproc *rproc, struct rproc_mem_entry *mem); + int rproc_boot(struct rproc *rproc); void rproc_shutdown(struct rproc *rproc); void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type); From patchwork Fri Oct 27 12:44:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 117317 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp728099qgn; Fri, 27 Oct 2017 05:45:43 -0700 (PDT) X-Google-Smtp-Source: ABhQp+SsCt98kaeIlOZ+tM/gAZM/mBpW34mqLqFGSvJMzpq4ze1N9Kqk44a+rFYiDxdHC/o7Z9wh X-Received: by 10.99.116.25 with SMTP id p25mr227222pgc.26.1509108342899; Fri, 27 Oct 2017 05:45:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509108342; cv=none; d=google.com; s=arc-20160816; b=cebUtAx4e7b1+nHAfLTpgPz88Fai5uZzBg5R5trOSaW/eGd86OaHZo/wc2ShR1CZh8 KPZNAjhbKjp0QrQdfrIY0R9615ONjz2ohJ+2H2NgTZBPxdIRFlPZs0DnLG0/sR1nggxK zEukgy6lmJt2uX6pYUtyny8FJeukVD3X9kYYsbxrFl3//5IVHryQbGLZmNPYlhhC9hXw /N9EmxvabxQrdEA4dpI4/XBFAAF0m25G8RwEBHVS9DaV7ko+AfmUJaTR7gJdEneFzFX5 obZ+3ZXyTVMYRBzgmB+jq3Ym7aylV1sdu+5YTxOmQvToUdgbGwIUYyrW4XOnnKIRKNpG 7qzA== 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:arc-authentication-results; bh=ouvP6P5WHynhrRXV45C5nh+umaspcEBsd9ktqVZcoeM=; b=Qpc2WBWag5fhGQV40c1K4FErns9y/HHm34e0W2BOBCAHHTEeBhRd4FYHgZcOJfcUUz MrucHHdHpxzYzWeNxo1Yr6GuYmgi2TeFQO1rcDVtLrpe9dfL1ttb3lTu1nQ6OgKny5QD JleJzkDrbdfUOEd4bYlCeAaLcVIscKQ2XT7Z3JZdSKSjIZZ5Hn8wwDhU0A/xj7obxnOW W684hT7sABx9KW+QB1n0ItxHcVwUUqqH+D/kf/MtyaKsRE83rn3hLB49fR9b9fiSf/1N FoOrwyGGt+89QQUXjtEKlF+85/iU7+xKdClMUZ6kKJAHC1lzaDXHGBJuud4Y1ddvZMe7 9OLQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i6si4336946plt.797.2017.10.27.05.45.42; Fri, 27 Oct 2017 05:45:42 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752757AbdJ0Mpl (ORCPT + 27 others); Fri, 27 Oct 2017 08:45:41 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:33914 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752473AbdJ0Mof (ORCPT ); Fri, 27 Oct 2017 08:44:35 -0400 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v9RChcgw000587; Fri, 27 Oct 2017 14:44:34 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2duapy893a-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 27 Oct 2017 14:44:34 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 78D3531; Fri, 27 Oct 2017 12:44:33 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag7node2.st.com [10.75.127.20]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 61EB726E0; Fri, 27 Oct 2017 12:44:33 +0000 (GMT) Received: from localhost (10.75.127.50) by SFHDAG7NODE2.st.com (10.75.127.20) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 27 Oct 2017 14:44:32 +0200 From: Loic Pallardy To: , CC: , , , , Loic Pallardy Subject: [PATCH 4/7] remoteproc: introduce rproc_find_carveout_by_da Date: Fri, 27 Oct 2017 14:44:11 +0200 Message-ID: <1509108254-22296-5-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1509108254-22296-1-git-send-email-loic.pallardy@st.com> References: <1509108254-22296-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.50] X-ClientProxiedBy: SFHDAG4NODE1.st.com (10.75.127.10) To SFHDAG7NODE2.st.com (10.75.127.20) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-10-27_07:, , signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch provides a new function to find a carveout according to a device address (da). If match found, this function returns CPU virtual address corresponding to specified da. Signed-off-by: Loic Pallardy --- drivers/remoteproc/remoteproc_core.c | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) -- 1.9.1 diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 279320a..78525d1 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -211,6 +211,48 @@ void *rproc_da_to_va(struct rproc *rproc, u64 da, int len) } EXPORT_SYMBOL(rproc_da_to_va); +/** + * rproc_find_carveout_by_da() - lookup the carveout region for a remoteproc address + * @rproc: handle of a remote processor + * @da: remoteproc device address to find + * @len: length of the memory region @da is pointing to + * + * Platform driver has the capability to register some pre-allacoted carveout + * (physically contiguous memory regions) before rproc firmware loading and + * associated resource table analysis. These regions may be dedicated memory + * regions internal to the coprocessor or specified DDR region with specific + * attributes + * + * This function is a helper function with which we can go over the + * allocated carveouts and translate specific device addresse to virtual + * addresse so we can fill firmware resource table. + * + * The function returns a valid virtual address on success or NULL on failure. + */ +void *rproc_find_carveout_by_da(struct rproc *rproc, u64 da, int len) +{ + struct rproc_mem_entry *carveout; + void *va = NULL; + + list_for_each_entry(carveout, &rproc->carveouts, node) { + int offset = da - carveout->da; + + /* try next carveout if da is too small */ + if (offset < 0) + continue; + + /* try next carveout if da is too large */ + if (offset + len > carveout->len) + continue; + + va = carveout->va + offset; + + break; + } + + return va; +} + int rproc_alloc_vring(struct rproc_vdev *rvdev, int i) { struct rproc *rproc = rvdev->rproc; From patchwork Fri Oct 27 12:44:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 117316 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp727681qgn; Fri, 27 Oct 2017 05:45:14 -0700 (PDT) X-Google-Smtp-Source: ABhQp+Th3cVf8vuVPGeTh9r4tm816f2TcTfcbTBzUwzFQQ/IIbUAsPLcXhmmeBRjRoRATGNHFJOH X-Received: by 10.84.234.199 with SMTP id i7mr293402plt.15.1509108313911; Fri, 27 Oct 2017 05:45:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509108313; cv=none; d=google.com; s=arc-20160816; b=jggD6gYZdjh+Q/BvVf6I9xodI0PZuLA+a+6C1vDKUBawVKxQrQxKdVr9IlvXQg6FDj j3cB1TwjRlYpbZm5oWYG5T6l7uf3zS7LjdCLmjFgT2PvtivEgiLH0nxCTdf9jssKaXoa KW7b8UlGHRAK4r/6wc+vmmI1wwauC83O8x4CI7+NTmsMPm6Bds8aqXkRU3STTi+k8lpb yJ23sJuhD2hPXU6yVNK+sYP6m6RPQiaayY3I4+EJrnsvg3ss3W14Q1BgThlE1EKK+TfC Ti5RLqIFMLfoviPT1QmRzYtrNocZxQb/TuNEfGYZ39O08+aYwCIKWGR9KeOQE2RtTSWM jG+w== 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:arc-authentication-results; bh=kfIybiZrRFmbLp69G04wDpzKWQ1RYst1WhIH+V4z+48=; b=ZHJD8Yx2p7Klj7uf6RJqlk88tgGWsND1O6As27GaefeRc8K7phKTrttfk+9I4Q8aWZ bgWXsX9YqCl1E9Fjvdm81adBhf/2wW0RW7iqfnkW7C+e3Wfh+ZuIHGqioO4VrVcAY3YM i7fDcMq25hr3vNqeOCl5caH6tmetrJRBQPrWtmnE0cfgfh2xAq/zPmY/EcJHKRuUmdRS zW0q27VJbuaqY9YU0mfoDvlCwJyS6k8KpSyiCoWIqn+GsZP0yMpB0gl4AhOL4IQ2S6UZ /e2L72gKdCag9X1r+Dva8MP/KzDQDIrl7tedcz/P0zemKR0XNKl7obobTBaP33OFF+l8 S4Cg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y23si5364448pfa.140.2017.10.27.05.45.13; Fri, 27 Oct 2017 05:45:13 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752695AbdJ0MpK (ORCPT + 27 others); Fri, 27 Oct 2017 08:45:10 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:38010 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752629AbdJ0Mog (ORCPT ); Fri, 27 Oct 2017 08:44:36 -0400 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v9RCi2oP004813; Fri, 27 Oct 2017 14:44:34 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2dtg42ywkf-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 27 Oct 2017 14:44:34 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 4C93234; Fri, 27 Oct 2017 12:44:34 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag7node2.st.com [10.75.127.20]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 3849E26E0; Fri, 27 Oct 2017 12:44:34 +0000 (GMT) Received: from localhost (10.75.127.48) by SFHDAG7NODE2.st.com (10.75.127.20) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 27 Oct 2017 14:44:33 +0200 From: Loic Pallardy To: , CC: , , , , Loic Pallardy Subject: [PATCH 5/7] remoteproc: modify rproc_handle_carveout to support preallocated region Date: Fri, 27 Oct 2017 14:44:12 +0200 Message-ID: <1509108254-22296-6-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1509108254-22296-1-git-send-email-loic.pallardy@st.com> References: <1509108254-22296-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.48] X-ClientProxiedBy: SFHDAG4NODE1.st.com (10.75.127.10) To SFHDAG7NODE2.st.com (10.75.127.20) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-10-27_07:, , signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In current version rproc_handle_carveout function support only dynamic region allocation. This patch extends rproc_handle_carveout function to support different carveout configurations: - fixed DA and fixed PA: check if already part of pre-registered carveouts (platform driver). If no, return error. - fixed DA and any PA: check if already part of pre-allocated carveouts (platform driver). If not found and rproc supports iommu, continue with dynamic allocation (DA will be used for iommu programming), else return error as no way to force DA. - any DA and any PA: use original dynamic allocation Signed-off-by: Loic Pallardy --- drivers/remoteproc/remoteproc_core.c | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) -- 1.9.1 diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 78525d1..515a17a 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -184,6 +184,10 @@ void *rproc_da_to_va(struct rproc *rproc, u64 da, int len) struct rproc_mem_entry *carveout; void *ptr = NULL; + /* + * da_to_va platform driver is deprecated. Driver should register + * carveout thanks to rproc_add_carveout function + */ if (rproc->ops->da_to_va) { ptr = rproc->ops->da_to_va(rproc, da, len); if (ptr) @@ -677,6 +681,7 @@ static int rproc_handle_carveout(struct rproc *rproc, struct rproc_mem_entry *carveout, *mapping; struct device *dev = &rproc->dev; dma_addr_t dma; + phys_addr_t pa; void *va; int ret; @@ -698,6 +703,41 @@ static int rproc_handle_carveout(struct rproc *rproc, if (!carveout) return -ENOMEM; + /* Check carveout rsc already part of a registered carveout */ + if (rsc->da != FW_RSC_ADDR_ANY) { + va = rproc_find_carveout_by_da(rproc, rsc->da, rsc->len); + + if (va) { + /* Registered region found */ + pa = rproc_va_to_pa(va); + if (rsc->pa != FW_RSC_ADDR_ANY && rsc->pa != (u32)pa) { + /* Carveout doesn't match request */ + dev_err(dev->parent, + "Failed to find carveout fitting da and pa\n"); + return -ENOMEM; + } + + /* Update rsc table with physical address */ + rsc->pa = (u32)pa; + + /* Update carveouts list */ + carveout->va = va; + carveout->len = rsc->len; + carveout->da = rsc->da; + carveout->priv = (void *)CARVEOUT_RSC; + + list_add_tail(&carveout->node, &rproc->carveouts); + + return 0; + } + + if (!rproc->domain) { + dev_err(dev->parent, + "Bad carveout rsc configuration\n"); + return -ENOMEM; + } + } + va = dma_alloc_coherent(dev->parent, rsc->len, &dma, GFP_KERNEL); if (!va) { dev_err(dev->parent, From patchwork Fri Oct 27 12:44:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 117314 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp727558qgn; Fri, 27 Oct 2017 05:45:07 -0700 (PDT) X-Google-Smtp-Source: ABhQp+S/BuxzlcQ/KiCHVYoRwUFchb8IuWRhWIjwl5iIUJgYcCPHsuMmUd3jnWOLObqoJUu6a1Gg X-Received: by 10.101.77.144 with SMTP id p16mr211117pgq.226.1509108307281; Fri, 27 Oct 2017 05:45:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509108307; cv=none; d=google.com; s=arc-20160816; b=CM2S3AvmS7l5XrH9tQLOEKlI7X+7moWKMhm0tAnEhuKHmHHlzuLWcwZmGIX0EUOSdB V2DfRqE1PYzghyEqOzHgRjnwBp34L4e9HIZL0/WtYhERjIq0b7QHN6P5kr8KfGYBePCx wEkXGkWG+p9KJmaYp4YA21K5B6VZH7TnNIBfzeLatySTVaLUAwak7j2PuKDo201KUOCt zCCErZUns3c1H7aQUqQhqzt0NHfu4CoP5eaMOEpDy9JEHOFgR5e2/OZuSJnNsvAMVMiO yxlfMBbKbDVJHtCQpA8FQVZKTIRBRx+/h6ZIZVDnMc3z1Gi/Fd0zIs8xd8IP5oJ0fFnv p9xA== 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:arc-authentication-results; bh=1Ni09qPXMYZKWbdfNAfB/2UC+YJ6j88a87f3FCoER78=; b=Gw7iSBQvq9mPfY3jI5jC1dlAtfP4E2tQBvPHGyhYKIT13PsVYIkig1d0Pt6BxT+gH8 GqQaQA3mmMjjM4OOdwWox/dSIbF6Bixees3FDmMwRhGofDSCmPH+t5wqEUybzxiAqwG/ 3Ef4bLJ5n63r810wyYTkSY5B4orRlyU176+xZxUKhcZAnzNXEPTv42hQGwGf3Wp+I11z IgMLYGkm5zDTANQQklgIOLvmHNJ55psyWoCzwYppBp9dh9QbHNj4GWHeyd+y7RgKx4LX MaulPhjcTk9Q3y19b5O4tXI2pJTm5eh/CRW37xVRKZ+MuMWljE04ym6VKjGYzQlKpqs6 0RiQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m18si5298857pfh.138.2017.10.27.05.45.06; Fri, 27 Oct 2017 05:45:07 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752739AbdJ0MpG (ORCPT + 27 others); Fri, 27 Oct 2017 08:45:06 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:38751 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752635AbdJ0Moh (ORCPT ); Fri, 27 Oct 2017 08:44:37 -0400 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v9RCi2oQ004813; Fri, 27 Oct 2017 14:44:35 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2dtg42ywkg-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 27 Oct 2017 14:44:35 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 1827331; Fri, 27 Oct 2017 12:44:35 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag7node2.st.com [10.75.127.20]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 007F726E0; Fri, 27 Oct 2017 12:44:34 +0000 (GMT) Received: from localhost (10.75.127.46) by SFHDAG7NODE2.st.com (10.75.127.20) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 27 Oct 2017 14:44:34 +0200 From: Loic Pallardy To: , CC: , , , , Loic Pallardy Subject: [PATCH 6/7] remoteproc: modify vring allocation to support preallocated region Date: Fri, 27 Oct 2017 14:44:13 +0200 Message-ID: <1509108254-22296-7-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1509108254-22296-1-git-send-email-loic.pallardy@st.com> References: <1509108254-22296-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.46] X-ClientProxiedBy: SFHDAG3NODE1.st.com (10.75.127.7) To SFHDAG7NODE2.st.com (10.75.127.20) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-10-27_07:, , signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Current version of rproc_alloc_vring function supports only dynamic vring allocation. This patch extends rproc_alloc_vring to verify if requested vring DA is already part or not of a registered carveout. If true, nothing to do, else just allocate vring as before. Signed-off-by: Loic Pallardy --- drivers/remoteproc/remoteproc_core.c | 50 +++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 18 deletions(-) -- 1.9.1 diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 515a17a..e1dbe65 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -263,21 +263,41 @@ int rproc_alloc_vring(struct rproc_vdev *rvdev, int i) struct device *dev = &rproc->dev; struct rproc_vring *rvring = &rvdev->vring[i]; struct fw_rsc_vdev *rsc; - dma_addr_t dma; + dma_addr_t dma = 0; void *va; int ret, size, notifyid; /* actual size of vring (in bytes) */ size = PAGE_ALIGN(vring_size(rvring->len, rvring->align)); - /* - * Allocate non-cacheable memory for the vring. In the future - * this call will also configure the IOMMU for us - */ - va = dma_alloc_coherent(dev->parent, size, &dma, GFP_KERNEL); - if (!va) { - dev_err(dev->parent, "dma_alloc_coherent failed\n"); - return -EINVAL; + /* get vring resource table pointer */ + rsc = (void *)rproc->table_ptr + rvdev->rsc_offset; + + if (rsc->vring[i].da != FW_RSC_ADDR_ANY) { + va = rproc_find_carveout_by_da(rproc, rsc->vring[i].da, size); + + if (!va) { + /* No region not found */ + dev_err(dev->parent, "Pre-allocated vring not found\n"); + return -ENOMEM; + } + } else { + /* + * Allocate non-cacheable memory for the vring. In the future + * this call will also configure the IOMMU for us + */ + va = dma_alloc_coherent(dev->parent, size, &dma, GFP_KERNEL); + if (!va) { + dev_err(dev->parent, "dma_alloc_coherent failed\n"); + return -EINVAL; + } + /* + * Let the rproc know the da of this vring. + * Not all platforms use dma_alloc_coherent to automatically + * set up the iommu. In this case the device address (da) will + * hold the physical address and not the device address. + */ + rsc->vring[i].da = dma; } /* @@ -304,14 +324,7 @@ int rproc_alloc_vring(struct rproc_vdev *rvdev, int i) rvring->dma = dma; rvring->notifyid = notifyid; - /* - * Let the rproc know the notifyid and da of this vring. - * Not all platforms use dma_alloc_coherent to automatically - * set up the iommu. In this case the device address (da) will - * hold the physical address and not the device address. - */ - rsc = (void *)rproc->table_ptr + rvdev->rsc_offset; - rsc->vring[i].da = dma; + /* Let the rproc know the notifyid of this vring. */ rsc->vring[i].notifyid = notifyid; return 0; } @@ -348,7 +361,8 @@ void rproc_free_vring(struct rproc_vring *rvring) int idx = rvring->rvdev->vring - rvring; struct fw_rsc_vdev *rsc; - dma_free_coherent(rproc->dev.parent, size, rvring->va, rvring->dma); + if (rvring->dma) + dma_free_coherent(rproc->dev.parent, size, rvring->va, rvring->dma); idr_remove(&rproc->notifyids, rvring->notifyid); /* reset resource entry info */ From patchwork Fri Oct 27 12:44:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 117313 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp727511qgn; Fri, 27 Oct 2017 05:45:04 -0700 (PDT) X-Google-Smtp-Source: ABhQp+ScQKybVAPuhQD6pit09D8DTlmt/F5CmDudWduW0h3uZopATXpYUgefXbg8m5PBni5rNtn6 X-Received: by 10.98.182.15 with SMTP id j15mr365408pff.47.1509108304202; Fri, 27 Oct 2017 05:45:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509108304; cv=none; d=google.com; s=arc-20160816; b=hR+RHJ8XI8UCENNlqpEKYLc2R/LoPrwONQrHYeIx3nZ7KiVGSWdqtmztTqFWTS5jht EndyXYeE9lh42yjFZRpgn3F57hYRLAr+PfEXoNA6txzBtjmOjx/kD5jSFmG9TvCsyTF7 tujPRDn37+QHTjXsQcyr9PO2UAQB43z7NWHgEBk1irPBVJe5Y7iL1xSRIHEestpGaFMr u+GaaDheDFvDAGpYvxLXlJjUnHJqBZ8bYRoSDFw9GxiiONo1DO64LF/44how+j+OPtif MJnpJgKxXxzTMkWzD9YKMTCK9gLUm0+qyJgw8gxgL7FustszUr4p1nEem6DXjpenTAdt 6Yow== 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:arc-authentication-results; bh=WJ/qcxZevF9kjlPWWVZ5naLNJjrDiVIIg9g6nGcsOhw=; b=gMYRljqhEkTM++MITEqTv9Q3zn99y1cvyuWGOnTHmbv+GmxBB81LUzd/5MFvpgLsTz cjvTETexTatKyvQDPjcL0VdtdnP5gu9+5I3sY81Mng3Vv1r1aLUv57ehabFhCnc/Fx26 Zg7mHrPFdjCi1gmORfnCYqlnib62j3EZ+/o2xHIFN0w3SlONyBrNYdtdFgH5N/H95G+l qKoSJGZfMVyeEWfLzS8HzU+9KurrxIs1c6GDdUkiGLaDtxdTiBTCXSSDGaRLUi6uAlcT xZZM32zG1NSGRo91tUBl+NBHgK+k6Q7w8D0EjswkLgWVxCkBSZt+2RWQFS6+0FfZN/eZ sZ+g== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m18si5298857pfh.138.2017.10.27.05.45.03; Fri, 27 Oct 2017 05:45:04 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752723AbdJ0MpB (ORCPT + 27 others); Fri, 27 Oct 2017 08:45:01 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:33921 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752649AbdJ0Moi (ORCPT ); Fri, 27 Oct 2017 08:44:38 -0400 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v9RChcWG000584; Fri, 27 Oct 2017 14:44:36 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2duapy893k-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 27 Oct 2017 14:44:36 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id E379C34; Fri, 27 Oct 2017 12:44:35 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag7node2.st.com [10.75.127.20]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id C76F226E0; Fri, 27 Oct 2017 12:44:35 +0000 (GMT) Received: from localhost (10.75.127.50) by SFHDAG7NODE2.st.com (10.75.127.20) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 27 Oct 2017 14:44:35 +0200 From: Loic Pallardy To: , CC: , , , , Loic Pallardy Subject: [PATCH 7/7] remoteproc: st: add reserved memory support Date: Fri, 27 Oct 2017 14:44:14 +0200 Message-ID: <1509108254-22296-8-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1509108254-22296-1-git-send-email-loic.pallardy@st.com> References: <1509108254-22296-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.50] X-ClientProxiedBy: SFHDAG3NODE2.st.com (10.75.127.8) To SFHDAG7NODE2.st.com (10.75.127.20) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-10-27_07:, , signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ST remote processor needs some specified memory regions for firmware and IPC. Memory regions are defined as reserved memory and should be registered in remoteproc core thanks to rproc_add_carveout function. Memory region release is handled by ST driver itself on remove operation. Signed-off-by: Loic Pallardy --- drivers/remoteproc/st_remoteproc.c | 43 +++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 8 deletions(-) -- 1.9.1 diff --git a/drivers/remoteproc/st_remoteproc.c b/drivers/remoteproc/st_remoteproc.c index aacef0e..1549ce8 100644 --- a/drivers/remoteproc/st_remoteproc.c +++ b/drivers/remoteproc/st_remoteproc.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -208,8 +209,10 @@ static int st_rproc_parse_dt(struct platform_device *pdev) struct device *dev = &pdev->dev; struct rproc *rproc = platform_get_drvdata(pdev); struct st_rproc *ddata = rproc->priv; - struct device_node *np = dev->of_node; - int err; + struct device_node *node, *np = dev->of_node; + struct resource res; + struct rproc_mem_entry *mem; + int err, count, i; if (ddata->config->sw_reset) { ddata->sw_reset = devm_reset_control_get_exclusive(dev, @@ -254,10 +257,36 @@ static int st_rproc_parse_dt(struct platform_device *pdev) return -EINVAL; } - err = of_reserved_mem_device_init(dev); - if (err) { - dev_err(dev, "Failed to obtain shared memory\n"); - return err; + count = of_count_phandle_with_args(np, "memory-region", NULL); + + for (i = 0; i < count; i++) { + node = of_parse_phandle(np, "memory-region", i); + if (!node) { + dev_err(dev, "No memory-region specified\n"); + return -EINVAL; + } + + err = of_address_to_resource(node, 0, &res); + if (err) { + dev_err(dev, "Bad memory-region definition\n"); + return err; + } + + mem = devm_kzalloc(dev, sizeof(*mem), GFP_KERNEL); + if (!mem) + return -ENOMEM; + + mem->dma = res.start; + mem->da = res.start; + mem->len = resource_size(&res); + mem->va = devm_ioremap_wc(dev, mem->dma, mem->len); + if (!mem->va) { + dev_err(dev, "Unable to map memory region: %pa+%zx\n", + &res.start, mem->len); + return -EBUSY; + } + + rproc_add_carveout(rproc, mem); } err = clk_prepare(ddata->clk); @@ -387,8 +416,6 @@ static int st_rproc_remove(struct platform_device *pdev) clk_disable_unprepare(ddata->clk); - of_reserved_mem_device_release(&pdev->dev); - for (i = 0; i < ST_RPROC_MAX_VRING * MBOX_MAX; i++) mbox_free_channel(ddata->mbox_chan[i]);