From patchwork Tue Sep 10 16:08:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 11139851 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C5C8E14ED for ; Tue, 10 Sep 2019 16:09:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A46DE206A1 for ; Tue, 10 Sep 2019 16:09:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="WgGiFGhC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436617AbfIJQJG (ORCPT ); Tue, 10 Sep 2019 12:09:06 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:38418 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436545AbfIJQJG (ORCPT ); Tue, 10 Sep 2019 12:09:06 -0400 Received: by mail-pg1-f195.google.com with SMTP id d10so9986241pgo.5 for ; Tue, 10 Sep 2019 09:09:06 -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=HUiGHkQMIXTru33NEpbepH3aRpqrcccJiliaWHN/NLg=; b=WgGiFGhC0+fEZ7JT0OjNHDyPLtBG3IXaHE9JpZEtRV2XqVoXUnKBH4yKD0ALDyd9ck 2OM4E+GQhSWHovAAda2EVwo5DBAambJGR6Ru/sygZR/+5MmXPszT57QDh4A2TkuPw88h HrfbDrERmKljT3OSSYd7McTkRH1e1rZdAj67s= 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=HUiGHkQMIXTru33NEpbepH3aRpqrcccJiliaWHN/NLg=; b=rTfV9ZyvtWnDJ9blpr6G5FMoecImTBMeGgQnj0FBH8OW6mhk0c+b7G3IMHseLk8AJv bfw0ot2nqDmmWSflMxYf2pqoeWJe06T8XPB+4H7SQTgT1kZR5orsf035NkzazWXaEHD+ ZOGfE28DNmxND0hhM8mekiDsoihd1+pyOgu3weEucsm/u0K1gtztMkb/7QDDX3FpDjSz OH4jxAz90HkuAaHrcfyzj1ZCX/5uyvvWWX+TATgSh47+RrfPy4sa5b3v+wnBr+rIYk9g xj+bmJLMqAEBIToewn+Mw5/5sKR3uxYnWRHEwcDzAXjl6aYVoE1w4rOPzbye47z7R0ft 6Yog== X-Gm-Message-State: APjAAAWmH3vyTf7GVBGuYin+SIsv9sqv2+PQclQ+ZS9N2YE0ULjQK6JT SoN5Zf6PKu2/vBs05Cxa/3KUCg== X-Google-Smtp-Source: APXvYqwEeEfNXla76FaGP5TGBYBOatyT898AHWyJZN2OgmIQpcAR1+y4Xp5qzzvgO8bXi6iPgi7SEA== X-Received: by 2002:a63:f04:: with SMTP id e4mr27801248pgl.38.1568131745594; Tue, 10 Sep 2019 09:09:05 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:202:1:fa53:7765:582b:82b9]) by smtp.gmail.com with ESMTPSA id em21sm106088pjb.31.2019.09.10.09.09.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 09:09:05 -0700 (PDT) From: Stephen Boyd To: Dan Williams Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, Evan Green , Rob Herring , Bjorn Andersson , Andy Gross , Will Deacon , Catalin Marinas , Rob Herring Subject: [PATCH v3 1/5] reserved_mem: Add a devm_memremap_reserved_mem() API Date: Tue, 10 Sep 2019 09:08:59 -0700 Message-Id: <20190910160903.65694-2-swboyd@chromium.org> X-Mailer: git-send-email 2.23.0.162.g0b9fbb3734-goog In-Reply-To: <20190910160903.65694-1-swboyd@chromium.org> References: <20190910160903.65694-1-swboyd@chromium.org> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.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 Reviewed-by: Bjorn Andersson Reviewed-by: Rob Herring 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 7989703b883c..b3899a2c74c4 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 @@ -410,3 +411,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 /**