2016-08-31 00:04:28 +00:00
|
|
|
/*
|
|
|
|
* Based on work from:
|
|
|
|
* Andrew Andrianov <andrew@ncrmnt.org>
|
|
|
|
* Google
|
|
|
|
* The Linux Foundation
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_platform.h>
|
|
|
|
#include <linux/of_address.h>
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
|
|
|
#include <linux/cma.h>
|
|
|
|
#include <linux/dma-contiguous.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/of_reserved_mem.h>
|
|
|
|
#include "ion.h"
|
|
|
|
#include "ion_priv.h"
|
|
|
|
#include "ion_of.h"
|
|
|
|
|
2016-09-23 13:13:35 +00:00
|
|
|
static int ion_parse_dt_heap_common(struct device_node *heap_node,
|
|
|
|
struct ion_platform_heap *heap,
|
|
|
|
struct ion_of_heap *compatible)
|
2016-08-31 00:04:28 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2016-09-27 07:38:23 +00:00
|
|
|
for (i = 0; compatible[i].name; i++) {
|
2016-08-31 00:04:28 +00:00
|
|
|
if (of_device_is_compatible(heap_node, compatible[i].compat))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-09-27 07:38:23 +00:00
|
|
|
if (!compatible[i].name)
|
2016-08-31 00:04:28 +00:00
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
heap->id = compatible[i].heap_id;
|
|
|
|
heap->type = compatible[i].type;
|
|
|
|
heap->name = compatible[i].name;
|
|
|
|
heap->align = compatible[i].align;
|
|
|
|
|
|
|
|
/* Some kind of callback function pointer? */
|
|
|
|
|
|
|
|
pr_info("%s: id %d type %d name %s align %lx\n", __func__,
|
staging:android:ion: Fix alignment issues
This patch fixes the following whitespace issues:
CHECK: Alignment should match open parenthesis
+ pr_info("%s: id %d type %d name %s align %lx\n", __func__,
+ heap->id, heap->type, heap->name, heap->align);
CHECK: Alignment should match open parenthesis
+struct ion_platform_data *ion_parse_dt(struct platform_device *pdev,
+ struct ion_of_heap *compatible)
CHECK: Alignment should match open parenthesis
+ heaps = devm_kzalloc(&pdev->dev,
+ sizeof(struct ion_platform_heap)*num_heaps,
CHECK: Alignment should match open parenthesis
+ data = devm_kzalloc(&pdev->dev, sizeof(struct ion_platform_data),
+ GFP_KERNEL);
CHECK: Alignment should match open parenthesis
+ heap_pdev = of_platform_device_create(node, heaps[i].name,
+ &pdev->dev);
CHECK: Alignment should match open parenthesis
+ pr_debug("%s: heap %s base %pa size %pa dev %p\n", __func__,
+ heap->name, &rmem->base, &rmem->size, dev);
CHECK: Alignment should match open parenthesis
+static void rmem_ion_device_release(struct reserved_mem *rmem,
+ struct device *dev)
Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-09-27 07:38:24 +00:00
|
|
|
heap->id, heap->type, heap->name, heap->align);
|
2016-08-31 00:04:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-09-23 13:13:35 +00:00
|
|
|
static int ion_setup_heap_common(struct platform_device *parent,
|
|
|
|
struct device_node *heap_node,
|
|
|
|
struct ion_platform_heap *heap)
|
2016-08-31 00:04:28 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
switch (heap->type) {
|
2016-09-24 16:51:58 +00:00
|
|
|
case ION_HEAP_TYPE_CARVEOUT:
|
|
|
|
case ION_HEAP_TYPE_CHUNK:
|
|
|
|
if (heap->base && heap->size)
|
|
|
|
return 0;
|
2016-08-31 00:04:28 +00:00
|
|
|
|
2016-09-24 16:51:58 +00:00
|
|
|
ret = of_reserved_mem_device_init(heap->priv);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2016-08-31 00:04:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ion_platform_data *ion_parse_dt(struct platform_device *pdev,
|
staging:android:ion: Fix alignment issues
This patch fixes the following whitespace issues:
CHECK: Alignment should match open parenthesis
+ pr_info("%s: id %d type %d name %s align %lx\n", __func__,
+ heap->id, heap->type, heap->name, heap->align);
CHECK: Alignment should match open parenthesis
+struct ion_platform_data *ion_parse_dt(struct platform_device *pdev,
+ struct ion_of_heap *compatible)
CHECK: Alignment should match open parenthesis
+ heaps = devm_kzalloc(&pdev->dev,
+ sizeof(struct ion_platform_heap)*num_heaps,
CHECK: Alignment should match open parenthesis
+ data = devm_kzalloc(&pdev->dev, sizeof(struct ion_platform_data),
+ GFP_KERNEL);
CHECK: Alignment should match open parenthesis
+ heap_pdev = of_platform_device_create(node, heaps[i].name,
+ &pdev->dev);
CHECK: Alignment should match open parenthesis
+ pr_debug("%s: heap %s base %pa size %pa dev %p\n", __func__,
+ heap->name, &rmem->base, &rmem->size, dev);
CHECK: Alignment should match open parenthesis
+static void rmem_ion_device_release(struct reserved_mem *rmem,
+ struct device *dev)
Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-09-27 07:38:24 +00:00
|
|
|
struct ion_of_heap *compatible)
|
2016-08-31 00:04:28 +00:00
|
|
|
{
|
|
|
|
int num_heaps, ret;
|
|
|
|
const struct device_node *dt_node = pdev->dev.of_node;
|
|
|
|
struct device_node *node;
|
|
|
|
struct ion_platform_heap *heaps;
|
|
|
|
struct ion_platform_data *data;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
num_heaps = of_get_available_child_count(dt_node);
|
|
|
|
|
|
|
|
if (!num_heaps)
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
|
|
|
heaps = devm_kzalloc(&pdev->dev,
|
2016-09-27 07:38:26 +00:00
|
|
|
sizeof(struct ion_platform_heap) * num_heaps,
|
staging:android:ion: Fix alignment issues
This patch fixes the following whitespace issues:
CHECK: Alignment should match open parenthesis
+ pr_info("%s: id %d type %d name %s align %lx\n", __func__,
+ heap->id, heap->type, heap->name, heap->align);
CHECK: Alignment should match open parenthesis
+struct ion_platform_data *ion_parse_dt(struct platform_device *pdev,
+ struct ion_of_heap *compatible)
CHECK: Alignment should match open parenthesis
+ heaps = devm_kzalloc(&pdev->dev,
+ sizeof(struct ion_platform_heap)*num_heaps,
CHECK: Alignment should match open parenthesis
+ data = devm_kzalloc(&pdev->dev, sizeof(struct ion_platform_data),
+ GFP_KERNEL);
CHECK: Alignment should match open parenthesis
+ heap_pdev = of_platform_device_create(node, heaps[i].name,
+ &pdev->dev);
CHECK: Alignment should match open parenthesis
+ pr_debug("%s: heap %s base %pa size %pa dev %p\n", __func__,
+ heap->name, &rmem->base, &rmem->size, dev);
CHECK: Alignment should match open parenthesis
+static void rmem_ion_device_release(struct reserved_mem *rmem,
+ struct device *dev)
Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-09-27 07:38:24 +00:00
|
|
|
GFP_KERNEL);
|
2016-08-31 00:04:28 +00:00
|
|
|
if (!heaps)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
data = devm_kzalloc(&pdev->dev, sizeof(struct ion_platform_data),
|
staging:android:ion: Fix alignment issues
This patch fixes the following whitespace issues:
CHECK: Alignment should match open parenthesis
+ pr_info("%s: id %d type %d name %s align %lx\n", __func__,
+ heap->id, heap->type, heap->name, heap->align);
CHECK: Alignment should match open parenthesis
+struct ion_platform_data *ion_parse_dt(struct platform_device *pdev,
+ struct ion_of_heap *compatible)
CHECK: Alignment should match open parenthesis
+ heaps = devm_kzalloc(&pdev->dev,
+ sizeof(struct ion_platform_heap)*num_heaps,
CHECK: Alignment should match open parenthesis
+ data = devm_kzalloc(&pdev->dev, sizeof(struct ion_platform_data),
+ GFP_KERNEL);
CHECK: Alignment should match open parenthesis
+ heap_pdev = of_platform_device_create(node, heaps[i].name,
+ &pdev->dev);
CHECK: Alignment should match open parenthesis
+ pr_debug("%s: heap %s base %pa size %pa dev %p\n", __func__,
+ heap->name, &rmem->base, &rmem->size, dev);
CHECK: Alignment should match open parenthesis
+static void rmem_ion_device_release(struct reserved_mem *rmem,
+ struct device *dev)
Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-09-27 07:38:24 +00:00
|
|
|
GFP_KERNEL);
|
2016-08-31 00:04:28 +00:00
|
|
|
if (!data)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
for_each_available_child_of_node(dt_node, node) {
|
|
|
|
struct platform_device *heap_pdev;
|
|
|
|
|
|
|
|
ret = ion_parse_dt_heap_common(node, &heaps[i], compatible);
|
|
|
|
if (ret)
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
|
|
|
|
heap_pdev = of_platform_device_create(node, heaps[i].name,
|
staging:android:ion: Fix alignment issues
This patch fixes the following whitespace issues:
CHECK: Alignment should match open parenthesis
+ pr_info("%s: id %d type %d name %s align %lx\n", __func__,
+ heap->id, heap->type, heap->name, heap->align);
CHECK: Alignment should match open parenthesis
+struct ion_platform_data *ion_parse_dt(struct platform_device *pdev,
+ struct ion_of_heap *compatible)
CHECK: Alignment should match open parenthesis
+ heaps = devm_kzalloc(&pdev->dev,
+ sizeof(struct ion_platform_heap)*num_heaps,
CHECK: Alignment should match open parenthesis
+ data = devm_kzalloc(&pdev->dev, sizeof(struct ion_platform_data),
+ GFP_KERNEL);
CHECK: Alignment should match open parenthesis
+ heap_pdev = of_platform_device_create(node, heaps[i].name,
+ &pdev->dev);
CHECK: Alignment should match open parenthesis
+ pr_debug("%s: heap %s base %pa size %pa dev %p\n", __func__,
+ heap->name, &rmem->base, &rmem->size, dev);
CHECK: Alignment should match open parenthesis
+static void rmem_ion_device_release(struct reserved_mem *rmem,
+ struct device *dev)
Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-09-27 07:38:24 +00:00
|
|
|
&pdev->dev);
|
2016-08-31 00:04:28 +00:00
|
|
|
if (!pdev)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
heap_pdev->dev.platform_data = &heaps[i];
|
|
|
|
|
|
|
|
heaps[i].priv = &heap_pdev->dev;
|
|
|
|
|
|
|
|
ret = ion_setup_heap_common(pdev, node, &heaps[i]);
|
|
|
|
if (ret)
|
|
|
|
goto out_err;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->heaps = heaps;
|
|
|
|
data->nr = num_heaps;
|
|
|
|
return data;
|
|
|
|
|
|
|
|
out_err:
|
|
|
|
for ( ; i >= 0; i--)
|
|
|
|
if (heaps[i].priv)
|
|
|
|
of_device_unregister(to_platform_device(heaps[i].priv));
|
|
|
|
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ion_destroy_platform_data(struct ion_platform_data *data)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < data->nr; i++)
|
|
|
|
if (data->heaps[i].priv)
|
|
|
|
of_device_unregister(to_platform_device(
|
|
|
|
data->heaps[i].priv));
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_OF_RESERVED_MEM
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_fdt.h>
|
|
|
|
#include <linux/of_reserved_mem.h>
|
|
|
|
|
|
|
|
static int rmem_ion_device_init(struct reserved_mem *rmem, struct device *dev)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
|
|
struct ion_platform_heap *heap = pdev->dev.platform_data;
|
|
|
|
|
|
|
|
heap->base = rmem->base;
|
|
|
|
heap->base = rmem->size;
|
|
|
|
pr_debug("%s: heap %s base %pa size %pa dev %p\n", __func__,
|
staging:android:ion: Fix alignment issues
This patch fixes the following whitespace issues:
CHECK: Alignment should match open parenthesis
+ pr_info("%s: id %d type %d name %s align %lx\n", __func__,
+ heap->id, heap->type, heap->name, heap->align);
CHECK: Alignment should match open parenthesis
+struct ion_platform_data *ion_parse_dt(struct platform_device *pdev,
+ struct ion_of_heap *compatible)
CHECK: Alignment should match open parenthesis
+ heaps = devm_kzalloc(&pdev->dev,
+ sizeof(struct ion_platform_heap)*num_heaps,
CHECK: Alignment should match open parenthesis
+ data = devm_kzalloc(&pdev->dev, sizeof(struct ion_platform_data),
+ GFP_KERNEL);
CHECK: Alignment should match open parenthesis
+ heap_pdev = of_platform_device_create(node, heaps[i].name,
+ &pdev->dev);
CHECK: Alignment should match open parenthesis
+ pr_debug("%s: heap %s base %pa size %pa dev %p\n", __func__,
+ heap->name, &rmem->base, &rmem->size, dev);
CHECK: Alignment should match open parenthesis
+static void rmem_ion_device_release(struct reserved_mem *rmem,
+ struct device *dev)
Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-09-27 07:38:24 +00:00
|
|
|
heap->name, &rmem->base, &rmem->size, dev);
|
2016-08-31 00:04:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rmem_ion_device_release(struct reserved_mem *rmem,
|
staging:android:ion: Fix alignment issues
This patch fixes the following whitespace issues:
CHECK: Alignment should match open parenthesis
+ pr_info("%s: id %d type %d name %s align %lx\n", __func__,
+ heap->id, heap->type, heap->name, heap->align);
CHECK: Alignment should match open parenthesis
+struct ion_platform_data *ion_parse_dt(struct platform_device *pdev,
+ struct ion_of_heap *compatible)
CHECK: Alignment should match open parenthesis
+ heaps = devm_kzalloc(&pdev->dev,
+ sizeof(struct ion_platform_heap)*num_heaps,
CHECK: Alignment should match open parenthesis
+ data = devm_kzalloc(&pdev->dev, sizeof(struct ion_platform_data),
+ GFP_KERNEL);
CHECK: Alignment should match open parenthesis
+ heap_pdev = of_platform_device_create(node, heaps[i].name,
+ &pdev->dev);
CHECK: Alignment should match open parenthesis
+ pr_debug("%s: heap %s base %pa size %pa dev %p\n", __func__,
+ heap->name, &rmem->base, &rmem->size, dev);
CHECK: Alignment should match open parenthesis
+static void rmem_ion_device_release(struct reserved_mem *rmem,
+ struct device *dev)
Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-09-27 07:38:24 +00:00
|
|
|
struct device *dev)
|
2016-08-31 00:04:28 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct reserved_mem_ops rmem_dma_ops = {
|
|
|
|
.device_init = rmem_ion_device_init,
|
|
|
|
.device_release = rmem_ion_device_release,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init rmem_ion_setup(struct reserved_mem *rmem)
|
|
|
|
{
|
|
|
|
phys_addr_t size = rmem->size;
|
|
|
|
|
|
|
|
size = size / 1024;
|
|
|
|
|
|
|
|
pr_info("Ion memory setup at %pa size %pa MiB\n",
|
|
|
|
&rmem->base, &size);
|
|
|
|
rmem->ops = &rmem_dma_ops;
|
|
|
|
return 0;
|
|
|
|
}
|
2016-09-27 07:38:25 +00:00
|
|
|
|
2016-08-31 00:04:28 +00:00
|
|
|
RESERVEDMEM_OF_DECLARE(ion, "ion-region", rmem_ion_setup);
|
|
|
|
#endif
|