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=-9.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 41D54C16A69 for ; Fri, 17 May 2019 16:48:14 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 12E1021726 for ; Fri, 17 May 2019 16:48:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="LoMzt/vW"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="ELBsaFN8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 12E1021726 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-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=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=olXecpYJ/EPlXB+Ri0BX7GeyugvGOs6b9faje5GouP8=; b=LoMzt/vWOKGPhL Y8u87bTKKnk0i+AtqLkfZSPKWFLh7yYChnEiVvvwBR2y7K1igaxGSc3KIT6Ggyn/Jme5PyLH3xSeS k7LYJdF0DwOY8BheBzWdsWXSbQhOMCcl80A9d3ym6rPdHFIBqgAC7Q7AzRFTmR1vTTQkumSZ6pLlb OKH+KCCeHtQ/b7FsvaewlxC9HBzEdvFOK5V1tRhreeFoDvwHf64KC01oY9Abt0pbWQcr+WnLS1zLl 2j7WoGg1SpueRrJwbz5zFOnvl320IS58RKBKA4fSNEIhBQ4kY7d+gGJd4R1HZlqDhn1F8+vHypgeX OLGjNAAUerauNz/sdJaw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hRg1c-0007ep-D9; Fri, 17 May 2019 16:48:04 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hRg1Q-0007SG-Fp for linux-arm-kernel@lists.infradead.org; Fri, 17 May 2019 16:47:53 +0000 Received: by mail-pf1-x441.google.com with SMTP id v80so3956736pfa.3 for ; Fri, 17 May 2019 09:47:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Dt/r9hghbvHRpM950rNfaqeDb6HHc3YxElzsbgb3628=; b=ELBsaFN8oBFo7zIK4AKnzx6dpfch/T8r5+SNxrpXpOQYdh4vleaWEpO9Y1yd1e7YpH v5v4iv3CmptHKW7CSR/OFrjxedmV7UdZYU0CuLLH0aHxSUHeot3mJ5kN7M5W10+7ssYv QR2zQxpcFQzfE91l4uLKK9N05oRfi2ZTVG+yw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Dt/r9hghbvHRpM950rNfaqeDb6HHc3YxElzsbgb3628=; b=kbVYFO5Q7ulcDp4PynX/Rn4rJGs6EYHAiWVfPvTWr4D9RU66PHJodC/d8Zw+wrhVvf 7tt/594vBkGw463cVbA5u8s9Zg5TDBocXWxXfSbHcZBAfKZAeYdgyV95gRtaz5zKkD7D YOwElp2zyVF3AaiwcR3tU8QiGwdIos77z4pnIVuDSNr3Fyu3MLVt8gZEOEbDfb0US8n9 dDi82G+WmnmTsGZVRTWWne4P6fObwC7iT+fnqREo4f+pj1tQa4blR+x4+l+9C+tLW68s r0g51tOpZ1pcwKztoPwi/y05gWVjlxartMNfb0UUKZ5dmmnxxfCO0d5Ygv5Mqkc+uv+5 la2w== X-Gm-Message-State: APjAAAUeECJsfKrBotbvD2F09h8tfU4+GXtLI3MswwXVy8RTx/gIYPbk ekxFwabJVp8IJRg7eCugg3Bpyw== X-Google-Smtp-Source: APXvYqxUOQ607cIWfGf9dbtUWQEfdBIaBbRL7/bhUOO2Fqka7KMkLhJ2lePdV2L8GZHvT7d0TjZSDg== X-Received: by 2002:a63:4147:: with SMTP id o68mr55522959pga.76.1558111671899; Fri, 17 May 2019 09:47:51 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:202:1:fa53:7765:582b:82b9]) by smtp.gmail.com with ESMTPSA id l141sm12229810pfd.24.2019.05.17.09.47.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 May 2019 09:47:51 -0700 (PDT) From: Stephen Boyd To: linux-kernel@vger.kernel.org Subject: [RFC/PATCH 1/5] reserved_mem: Add a devm_memremap_reserved_mem() API Date: Fri, 17 May 2019 09:47:42 -0700 Message-Id: <20190517164746.110786-2-swboyd@chromium.org> X-Mailer: git-send-email 2.21.0.1020.gf2820cf01a-goog In-Reply-To: <20190517164746.110786-1-swboyd@chromium.org> References: <20190517164746.110786-1-swboyd@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190517_094752_522934_0012C8DE X-CRM114-Status: GOOD ( 15.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org, Will Deacon , Andy Gross , Evan Green , Bjorn Andersson , Rob Herring , Catalin Marinas , Dan Williams , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org We have a few drivers that need to get a reserved memory region, request the region, and map the reserved memory with memremap(). Add an API to do this all in one function call. Cc: Evan Green Cc: Rob Herring Cc: Bjorn Andersson Cc: Andy Gross Cc: Will Deacon Cc: Catalin Marinas Cc: Dan Williams Signed-off-by: Stephen Boyd --- drivers/of/of_reserved_mem.c | 45 +++++++++++++++++++++++++++++++++ include/linux/of_reserved_mem.h | 6 +++++ 2 files changed, 51 insertions(+) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 6a36bc0b3d64..39ab2bfd40d7 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -12,6 +12,7 @@ #define pr_fmt(fmt) "OF: reserved mem: " fmt #include +#include #include #include #include @@ -395,3 +396,47 @@ struct reserved_mem *of_reserved_mem_lookup(struct device_node *np) return NULL; } EXPORT_SYMBOL_GPL(of_reserved_mem_lookup); + +/** + * devm_memremap_reserved_mem() - acquire reserved_mem from a device node, + * request and memremap it + * @dev: device with node pointer of the desired reserved-memory region + * @flags: flags to pass to memremap() + * + * This function allows drivers to acquire a reference to the reserved_mem + * struct based on the device's device_node handle, request it and then + * memremap() it. + * + * Returns: A remapped reserved memory region, or an error pointer on failure. + */ +void *devm_memremap_reserved_mem(struct device *dev, unsigned long flags) +{ + void *dest_ptr; + struct reserved_mem *rmem; + struct resource *res; + const char *name; + + rmem = of_reserved_mem_lookup(dev->of_node); + if (!rmem) { + dev_err(dev, "failed to acquire memory region\n"); + return ERR_PTR(-ENODEV); + } + + name = rmem->name ? : dev_name(dev); + + res = devm_request_mem_region(dev, rmem->base, rmem->size, name); + if (!res) { + dev_err(dev, "can't request region for reserved memory\n"); + return ERR_PTR(-EBUSY); + } + + dest_ptr = devm_memremap(dev, rmem->base, rmem->size, flags); + if (!dest_ptr) { + dev_err(dev, "memremap failed for reserved memory\n"); + devm_release_mem_region(dev, rmem->base, rmem->size); + dest_ptr = ERR_PTR(-ENOMEM); + } + + return dest_ptr; +} +EXPORT_SYMBOL_GPL(devm_memremap_reserved_mem); diff --git a/include/linux/of_reserved_mem.h b/include/linux/of_reserved_mem.h index 60f541912ccf..a36be60ef67c 100644 --- a/include/linux/of_reserved_mem.h +++ b/include/linux/of_reserved_mem.h @@ -39,6 +39,7 @@ void fdt_init_reserved_mem(void); void fdt_reserved_mem_save_node(unsigned long node, const char *uname, phys_addr_t base, phys_addr_t size); struct reserved_mem *of_reserved_mem_lookup(struct device_node *np); +void *devm_memremap_reserved_mem(struct device *dev, unsigned long flags); #else static inline int of_reserved_mem_device_init_by_idx(struct device *dev, struct device_node *np, int idx) @@ -54,6 +55,11 @@ static inline struct reserved_mem *of_reserved_mem_lookup(struct device_node *np { return NULL; } +static inline void *devm_memremap_reserved_mem(struct device *dev, + unsigned long flags) +{ + return NULL; +} #endif /** -- Sent by a computer through tubes _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel