Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp794385imm; Fri, 27 Jul 2018 06:17:49 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcaNFAJlBQLbE4Zy/6jArpanG2hwdWIt0oToOXmOaJIn/3+djcTjTAUmlh+8OeuHFoHyu4j X-Received: by 2002:a17:902:381:: with SMTP id d1-v6mr6054099pld.309.1532697469266; Fri, 27 Jul 2018 06:17:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532697469; cv=none; d=google.com; s=arc-20160816; b=ftHWB3AXCKVRQRHWMUNnE6zMzGzB0YGcGJiP5MKhtuEVzCQ43CdzT7lytK7fUs1BLy UnO8PboKZhAdeDhr+e1OS5X0aiClVgzPg7b9CI2T8oN49adRD6E3VFYP6tSpFkWrywYI /UmO6HB9oXIU2kq31kxXPknKY1MXV3tGw7yVfxrztzF1TWxQ6nRsWvezISPWsl+AAJe/ 2/EDBS8RhRPpL/UuHuuc8fSs96kPUNFyEWevwFy0FbQMcqBWD1lGnoZUaKfYg/beyriN U3FOhRyhRjgdeUAXzkKIqEIyjvtjpgXtSCBUyqFzhaeE5RgrCc0XaPkIbXhHbwjtusjN PvgQ== 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=etiXzHOo9EfgiVfySm9CH2I3ht+bul2Bej4z4g2ADA0=; b=BlqyVSnu09pdOVvtWU43MtR+4w2mct1Uv9/xEb/dFyWbUhVHsBO7FoDFQwhIf7UoZE KwRFRP5vokQBgR/UjdvJVKyGCQuDs2t7+dnC49n3vlkyUagbmrFrev7OimNNhpsbQjSd HbC23ifK+hWGC/cLFCztReeipgC3HVLATDks45FxFHMyslYnvvx/256BzEfMWmxF/sdN 7rT3Gxwqyrg39zDBlOrImNOTJ1JSmmuPNEQOVhfWaZGtGklnndr5Avm7FYyMDnsGWPUy aDnLX2wTuv7P7I9S0YP8AP4xx/qccqgsMkKiDjlXTnXE4jlC11oe6gxxfcddpSn6r+jW uGCA== 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 m21-v6si3799578pgh.664.2018.07.27.06.17.34; Fri, 27 Jul 2018 06:17:49 -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 S2388902AbeG0OiM (ORCPT + 99 others); Fri, 27 Jul 2018 10:38:12 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:10721 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388585AbeG0OhZ (ORCPT ); Fri, 27 Jul 2018 10:37:25 -0400 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w6RDESkq024978; Fri, 27 Jul 2018 15:15:28 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2kg1up0nsm-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 27 Jul 2018 15:15:28 +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 EECF238; Fri, 27 Jul 2018 13:15:27 +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 D4B21577A; Fri, 27 Jul 2018 13:15:27 +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 Jul 2018 15:15:27 +0200 From: Loic Pallardy To: , CC: , , , , , Loic Pallardy Subject: [PATCH v4 10/17] remoteproc: add helper function to check carveout device address Date: Fri, 27 Jul 2018 15:14:45 +0200 Message-ID: <1532697292-14272-11-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> References: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.75.127.48] X-ClientProxiedBy: SFHDAG8NODE1.st.com (10.75.127.22) To SFHDAG7NODE2.st.com (10.75.127.20) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-07-27_06:,, 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 function to verify that a specified carveout is fitting request device address and associated length Signed-off-by: Loic Pallardy --- drivers/remoteproc/remoteproc_core.c | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 1e0fe3e..5dd5edf 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -259,6 +259,53 @@ struct rproc_mem_entry * return mem; } +/** + * rproc_check_carveout_da() - Check specified carveout da configuration + * @rproc: handle of a remote processor + * @mem: pointer on carveout to check + * @da: area device address + * @len: associated area size + * + * This function is a helper function to verify requested device area (couple + * da, len) is part of specified carevout. + * + * Return: 0 if carveout matchs request else -ENOMEM + */ +int rproc_check_carveout_da(struct rproc *rproc, struct rproc_mem_entry *mem, + u32 da, u32 len) +{ + struct device *dev = &rproc->dev; + int delta = 0; + + /* Check requested resource length */ + if (len > mem->len) { + dev_err(dev, "Registered carveout doesn't fit len request\n"); + return -ENOMEM; + } + + if (da != FW_RSC_ADDR_ANY && mem->da == FW_RSC_ADDR_ANY) { + /* Update existing carveout da */ + mem->da = da; + } else if (da != FW_RSC_ADDR_ANY && mem->da != FW_RSC_ADDR_ANY) { + delta = da - mem->da; + + /* Check requested resource belongs to registered carveout */ + if (delta < 0) { + dev_err(dev, + "Registered carveout doesn't fit da request\n"); + return -ENOMEM; + } + + if (delta + len > mem->len) { + dev_err(dev, + "Registered carveout doesn't fit len request\n"); + return -ENOMEM; + } + } + + return 0; +} + int rproc_alloc_vring(struct rproc_vdev *rvdev, int i) { struct rproc *rproc = rvdev->rproc; -- 1.9.1