From patchwork Wed Dec 16 15:37:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 7863251 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 42B5E9F6FA for ; Wed, 16 Dec 2015 15:38:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1827F203A5 for ; Wed, 16 Dec 2015 15:38:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A7351203A4 for ; Wed, 16 Dec 2015 15:38:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965722AbbLPPiP (ORCPT ); Wed, 16 Dec 2015 10:38:15 -0500 Received: from mailout4.w1.samsung.com ([210.118.77.14]:17324 "EHLO mailout4.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933822AbbLPPhl (ORCPT ); Wed, 16 Dec 2015 10:37:41 -0500 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout4.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0NZG00353JEOSP10@mailout4.w1.samsung.com>; Wed, 16 Dec 2015 15:37:36 +0000 (GMT) X-AuditID: cbfec7f4-f79026d00000418a-c4-567185403dd8 Received: from eusync3.samsung.com ( [203.254.199.213]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 4B.78.16778.04581765; Wed, 16 Dec 2015 15:37:36 +0000 (GMT) Received: from amdc1339.digital.local ([106.116.147.30]) by eusync3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0NZG0019WJEJLV00@eusync3.samsung.com>; Wed, 16 Dec 2015 15:37:36 +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 v3 3/7] of: reserved_mem: add support for named reserved mem nodes Date: Wed, 16 Dec 2015 16:37:25 +0100 Message-id: <1450280249-24681-4-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 In-reply-to: <1450280249-24681-1-git-send-email-m.szyprowski@samsung.com> References: <1450280249-24681-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrFLMWRmVeSWpSXmKPExsVy+t/xq7oOrYVhBifWi1vcWneO1WLjjPWs FvOPAFkz3/xnszjwZwejxY/XF9gsXr8wtOh//JrZonPiEnaLng1bWS1mnN/HZLH2yF12i9a9 R9gtDr9pZ3Xg89g56y67x+yOmawem1Z1snncubaHzaNvyypGj8+b5ALYorhsUlJzMstSi/Tt ErgyFq6fz1Twxqmi59EilgbGjeZdjJwcEgImEnsuXGWCsMUkLtxbz9bFyMUhJLCUUWJ50zoW CKeJSWL50V0sIFVsAoYSXW+72EBsEQEniYWz/rKDFDEL/GWWWLj1GXMXIweHsECIxImNDiA1 LAKqEruX/QTr5RXwkPg6+QsrxDY5if8vV4Bt5hTwlPi2fxILSKsQUM3jlrIJjLwLGBlWMYqm liYXFCel5xrqFSfmFpfmpesl5+duYoSE6JcdjIuPWR1iFOBgVOLhvRBZECbEmlhWXJl7iFGC g1lJhPehXGGYEG9KYmVValF+fFFpTmrxIUZpDhYlcd65u96HCAmkJ5akZqemFqQWwWSZODil GhgN5WofLnl9aNLfmhMHvVbtbuud3H/7yZ2lrHWrV32LWLoj2ahTIW3PTZ9z7V8OtupP/ul+ rC3wfLHdneIylwu9EgovJ9b9K61etU338flpvgYZqa+1naLEf5V/Xb7558biHR9YNp101mE6 8udtqO80KR2TGTOvFW9cX5yVX7Kry+vPhl/3Oyq3KrEUZyQaajEXFScCAC9jaDlNAgAA Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch allows device drivers to initialize more than one reserved memory region assigned to given device. When driver needs to use more than one reserved memory region, it should allocate child devices and initialize regions by index or name for each of its child devices. Signed-off-by: Marek Szyprowski --- .../bindings/reserved-memory/reserved-memory.txt | 2 + .../devicetree/bindings/resource-names.txt | 1 + drivers/of/of_reserved_mem.c | 104 +++++++++++++++++---- include/linux/of_reserved_mem.h | 31 +++++- 4 files changed, 115 insertions(+), 23 deletions(-) diff --git a/Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt b/Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt index 3da0ebdba8d9..43a14957fd64 100644 --- a/Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt +++ b/Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt @@ -74,6 +74,8 @@ Regions in the /reserved-memory node may be referenced by other device nodes by adding a memory-region property to the device node. memory-region (optional) - phandle, specifier pairs to children of /reserved-memory +memory-region-names (optional) - supplemental names property, provide array of + names to identify memory regions Example ------- diff --git a/Documentation/devicetree/bindings/resource-names.txt b/Documentation/devicetree/bindings/resource-names.txt index e280fef6f265..51823e99b983 100644 --- a/Documentation/devicetree/bindings/resource-names.txt +++ b/Documentation/devicetree/bindings/resource-names.txt @@ -12,6 +12,7 @@ Resource Property Supplemental Names Property reg reg-names clocks clock-names interrupts interrupt-names +memory-region memory-region-names Usage: diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 1a3556a9e9ea..c58b362aaa63 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,53 +288,116 @@ static inline struct reserved_mem *__find_rmem(struct device_node *node) return NULL; } +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 + * @idx: Index of selected region + * + * This function assigns respective DMA-mapping operations based on reserved + * memory region specified by 'memory-region' property in @np node to the @dev + * device. 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_init(struct device *dev, struct device_node *np, int idx) { + struct rmem_assigned_device *rd; + struct device_node *target; struct reserved_mem *rmem; - struct device_node *np; int ret; - np = of_parse_phandle(dev->of_node, "memory-region", 0); - if (!np) - return -ENODEV; + if (!np || !dev) + return -EINVAL; + + target = of_parse_phandle(np, "memory-region", idx); + if (!target) + return -EINVAL; - rmem = __find_rmem(np); - of_node_put(np); + rmem = __find_rmem(target); + of_node_put(target); 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; } -EXPORT_SYMBOL_GPL(of_reserved_mem_device_init); +EXPORT_SYMBOL_GPL(of_reserved_mem_init); + +/** + * 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: Name of the selected region + * + * This function assigns respective DMA-mapping operations based on reserved + * memory region specified by 'memory-region' property in @np node, named @name + * to the @dev device. + * + * Returns error code or zero on success. + */ +int of_reserved_mem_init_by_name(struct device *dev, struct device_node *np, + const char *name) +{ + int idx = of_property_match_string(np, "memory-region-names", name); + + if (idx < 0) + return -EINVAL; + return of_reserved_mem_init(dev, np, idx); +} +EXPORT_SYMBOL_GPL(of_reserved_mem_init_by_name); /** * 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..0b928ad1ed93 100644 --- a/include/linux/of_reserved_mem.h +++ b/include/linux/of_reserved_mem.h @@ -1,7 +1,8 @@ #ifndef __OF_RESERVED_MEM_H #define __OF_RESERVED_MEM_H -struct device; +#include + struct of_phandle_args; struct reserved_mem_ops; @@ -28,14 +29,23 @@ 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_init(struct device *dev, struct device_node *np, int idx); +int of_reserved_mem_init_by_name(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_init(struct device *dev, + struct device_node *np, int idx) +{ + return -ENOSYS; +} +static inline int of_reserved_mem_init_by_name(struct device *dev, + struct device_node *np, const char *name) { return -ENOSYS; } @@ -46,4 +56,19 @@ static inline void fdt_reserved_mem_save_node(unsigned long node, const char *uname, phys_addr_t base, phys_addr_t size) { } #endif +/** + * of_reserved_mem_device_init() - assign reserved memory region to given device + * @dev: Pointer to the device to configure + * + * This function assigns respective DMA-mapping operations based on the first + * reserved memory region specified by 'memory-region' property in device tree + * node of the given device. + * + * Returns error code or zero on success. + */ +static inline int of_reserved_mem_device_init(struct device *dev) +{ + return of_reserved_mem_init(dev, dev->of_node, 0); +} + #endif /* __OF_RESERVED_MEM_H */