From patchwork Mon Dec 7 12:08:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 57788 Delivered-To: patch@linaro.org Received: by 10.202.179.86 with SMTP id c83csp949554oif; Mon, 7 Dec 2015 04:10:27 -0800 (PST) X-Received: by 10.66.248.74 with SMTP id yk10mr42634165pac.17.1449490205966; Mon, 07 Dec 2015 04:10:05 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x16si849119pfa.116.2015.12.07.04.10.05; Mon, 07 Dec 2015 04:10:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-media-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-media-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-media-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755386AbbLGMJz (ORCPT + 4 others); Mon, 7 Dec 2015 07:09:55 -0500 Received: from mailout2.w1.samsung.com ([210.118.77.12]:24808 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755237AbbLGMJm (ORCPT ); Mon, 7 Dec 2015 07:09:42 -0500 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout2.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0NYZ00KM3LS1XLA0@mailout2.w1.samsung.com>; Mon, 07 Dec 2015 12:09:37 +0000 (GMT) X-AuditID: cbfec7f4-f79026d00000418a-58-566577010fbf Received: from eusync1.samsung.com ( [203.254.199.211]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 71.E9.16778.10775665; Mon, 7 Dec 2015 12:09:37 +0000 (GMT) Received: from amdc1339.digital.local ([106.116.147.30]) by eusync1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0NYZ00FEQLRTAS00@eusync1.samsung.com>; Mon, 07 Dec 2015 12:09:37 +0000 (GMT) From: Marek Szyprowski To: linux-media@vger.kernel.org, linux-samsung-soc@vger.kernel.org Cc: Marek Szyprowski , devicetree@vger.kernel.org, Sylwester Nawrocki , Kamil Debski , Laurent Pinchart , Andrzej Hajda , Kukjin Kim , Krzysztof Kozlowski , Bartlomiej Zolnierkiewicz , Rob Herring , Frank Rowand , Grant Likely Subject: [PATCH 3/7] of: reserved_mem: add support for named reserved mem nodes Date: Mon, 07 Dec 2015 13:08:58 +0100 Message-id: <1449490142-27502-4-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 In-reply-to: <1449490142-27502-1-git-send-email-m.szyprowski@samsung.com> References: <1449490142-27502-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrFLMWRmVeSWpSXmKPExsVy+t/xy7qM5alhBkc2S1rcWneO1WLjjPWs FvOPAFkz3/xnszjwZwejxY/XF9gsXr8wtOh//JrZonPiEnaLng1bWS1mnN/HZLH2yF12i9a9 R9gtDr9pZ3Xg89g56y67x+yOmawem1Z1snncubaHzaNvyypGj8+b5ALYorhsUlJzMstSi/Tt Ergy9jV2MhdM06l4+7+PsYFxuUoXIyeHhICJRN/RGSwQtpjEhXvr2UBsIYGljBK9X4y7GLmA 7CYmif1XljCBJNgEDCW63naBFYkIOEksnPWXHaSIWeAvs8TCrc+YQRLCAv4SS9YvZwexWQRU JWadamYFsXkFPCQOtt1nhNgmJ/H/5QqwoZwCnhIPf34HinMAbfOQeLwlYwIj7wJGhlWMoqml yQXFSem5hnrFibnFpXnpesn5uZsYISH6ZQfj4mNWhxgFOBiVeHgt0lPChFgTy4orcw8xSnAw K4nwymamhgnxpiRWVqUW5ccXleakFh9ilOZgURLnnbvrfYiQQHpiSWp2ampBahFMlomDU6qB scLz3PoZOWXJIq9zzF9HndY4au/7sXfG2yXLghc0TxbbZNn16nGJkXXQbf3mD2HuMZMuSR14 LRzwT4q9dFFW/vd2Fa4juXsUM9nf85/a+UloffytvgOpGybf5Kwp3tDRmiHtHhghtf2AhIFD 9cTdtz9OUF/REHtRuHuZefm5zdtuvGaK57M9qcRSnJFoqMVcVJwIANHHoD1NAgAA Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org This patch allows device drivers to use more than one reserved memory region assigned to given device. When NULL name is passed to of_reserved_mem_device_init(), the default (first) region is used. Signed-off-by: Marek Szyprowski --- drivers/of/of_reserved_mem.c | 101 +++++++++++++++++++++++++++++++--------- include/linux/of_reserved_mem.h | 6 ++- 2 files changed, 84 insertions(+), 23 deletions(-) -- 1.9.2 -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 1a3556a9e9ea..0a0b23b73004 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -21,6 +21,7 @@ #include #include #include +#include #define MAX_RESERVED_REGIONS 16 static struct reserved_mem reserved_mem[MAX_RESERVED_REGIONS]; @@ -287,31 +288,84 @@ static inline struct reserved_mem *__find_rmem(struct device_node *node) return NULL; } +static struct reserved_mem *__node_to_rmem(struct device_node *node, + const char *name) +{ + struct reserved_mem *rmem; + struct device_node *target; + int idx = 0; + + if (!node) + return NULL; + + if (name) { + idx = of_property_match_string(node, + "memory-region-names", name); + if (idx < 0) + return NULL; + } + + target = of_parse_phandle(node, "memory-region", idx); + if (!target) + return NULL; + rmem = __find_rmem(target); + of_node_put(target); + + return rmem; +} + +struct rmem_assigned_device { + struct device *dev; + struct reserved_mem *rmem; + struct list_head list; +}; + +static LIST_HEAD(of_rmem_assigned_device_list); +static DEFINE_MUTEX(of_rmem_assigned_device_mutex); + /** * of_reserved_mem_device_init() - assign reserved memory region to given device + * @dev: Pointer to the device to configure + * @np: Pointer to the device_node with 'reserved-memory' property + * @name: Optional name of the selected region (can be NULL) + * + * This function assigns respective DMA-mapping operations based on reserved + * memory regionspecified by 'memory-region' property in @np node, named @name + * to the @dev device. When NULL name is provided, the default (first) memory + * region is used. When driver needs to use more than one reserved memory + * region, it should allocate child devices and initialize regions by name for + * each of child device. * - * This function assign memory region pointed by "memory-region" device tree - * property to the given device. + * Returns error code or zero on success. */ -int of_reserved_mem_device_init(struct device *dev) +int of_reserved_mem_device_init(struct device *dev, struct device_node *np, + const char *name) { + struct rmem_assigned_device *rd; struct reserved_mem *rmem; - struct device_node *np; int ret; - np = of_parse_phandle(dev->of_node, "memory-region", 0); - if (!np) - return -ENODEV; - - rmem = __find_rmem(np); - of_node_put(np); - + rmem = __node_to_rmem(np, name); if (!rmem || !rmem->ops || !rmem->ops->device_init) return -EINVAL; + rd = kmalloc(sizeof(struct rmem_assigned_device), GFP_KERNEL); + if (!rd) + return -ENOMEM; + ret = rmem->ops->device_init(rmem, dev); - if (ret == 0) + if (ret == 0) { + rd->dev = dev; + rd->rmem = rmem; + + mutex_lock(&of_rmem_assigned_device_mutex); + list_add(&rd->list, &of_rmem_assigned_device_list); + mutex_unlock(&of_rmem_assigned_device_mutex); + dev_info(dev, "assigned reserved memory node %s\n", rmem->name); + } else { + kfree(rd); + } return ret; } @@ -319,21 +373,26 @@ EXPORT_SYMBOL_GPL(of_reserved_mem_device_init); /** * of_reserved_mem_device_release() - release reserved memory device structures + * @dev: Pointer to the device to deconfigure * * This function releases structures allocated for memory region handling for * the given device. */ void of_reserved_mem_device_release(struct device *dev) { - struct reserved_mem *rmem; - struct device_node *np; - - np = of_parse_phandle(dev->of_node, "memory-region", 0); - if (!np) - return; - - rmem = __find_rmem(np); - of_node_put(np); + struct rmem_assigned_device *rd; + struct reserved_mem *rmem = NULL; + + mutex_lock(&of_rmem_assigned_device_mutex); + list_for_each_entry(rd, &of_rmem_assigned_device_list, list) { + if (rd->dev == dev) { + rmem = rd->rmem; + list_del(&rd->list); + kfree(rd); + break; + } + } + mutex_unlock(&of_rmem_assigned_device_mutex); if (!rmem || !rmem->ops || !rmem->ops->device_release) return; diff --git a/include/linux/of_reserved_mem.h b/include/linux/of_reserved_mem.h index ad2f67054372..05dd38490657 100644 --- a/include/linux/of_reserved_mem.h +++ b/include/linux/of_reserved_mem.h @@ -28,14 +28,16 @@ typedef int (*reservedmem_of_init_fn)(struct reserved_mem *rmem); _OF_DECLARE(reservedmem, name, compat, init, reservedmem_of_init_fn) #ifdef CONFIG_OF_RESERVED_MEM -int of_reserved_mem_device_init(struct device *dev); +int of_reserved_mem_device_init(struct device *dev, struct device_node *np, + const char *name); void of_reserved_mem_device_release(struct device *dev); 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); #else -static inline int of_reserved_mem_device_init(struct device *dev) +static inline int of_reserved_mem_device_init(struct device *dev, + struct device_node *np, const char *name) { return -ENOSYS; }