Re: [PATCH v3 3/7] of: reserved_mem: add support for named reserved mem nodes
Hi Rob, On 2015-12-31 00:25, Rob Herring wrote: On Wed, Dec 16, 2015 at 9:37 AM, Marek Szyprowski wrote: 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 regreg-names clocks clock-names interrupts interrupt-names +memory-region memory-region-names The other cases of *-names should correspond to actual h/w names for a h/w block. memory-regions are not really h/w. So I'd prefer to not add memory-region-names. If you want a name for the region, put it in the region node. The name for each client node is not going to be different. There is a difference between a name in the region node and a name assigned in client node. Reserved memory region bindings already allows assigning given region to more than one device. In such case the name put in the region itself is not really useful. In my case (Exynos MFC device) the names are related to HW names. The memory regions are named in the hw documentation (referred as 'left memory bank' and 'right memory bank'). Using those names in the binding is also simply convenient (no need to remember which regions is at which index number). Those names might be also convenient for describing Android's ION related regions, although I didn't look deep into details of such use case. Best regards -- Marek Szyprowski, PhD Samsung R&D Institute Poland -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 3/7] of: reserved_mem: add support for named reserved mem nodes
On Wed, Dec 16, 2015 at 9:37 AM, Marek Szyprowski wrote: > 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 > regreg-names > clocks clock-names > interrupts interrupt-names > +memory-region memory-region-names The other cases of *-names should correspond to actual h/w names for a h/w block. memory-regions are not really h/w. So I'd prefer to not add memory-region-names. If you want a name for the region, put it in the region node. The name for each client node is not going to be different. Rob -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v3 3/7] of: reserved_mem: add support for named reserved mem nodes
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 regreg-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