From a2e9363f069768597687ecd3436d331fc3c1ceb1 Mon Sep 17 00:00:00 2001 From: Laura Abbott Date: Fri, 19 Aug 2011 13:36:32 -0700 Subject: [PATCH] gpu: ion: Add support for carveout heaps on msm targets Add infrastructure for supporting ion carveout heaps. The memory type should be specified in the board file using mach/ion.h. The ion platform driver will be responsible for allocating the correct memory. Signed-off-by: Laura Abbott --- arch/arm/mach-msm/devices.h | 2 ++ arch/arm/mach-msm/include/mach/ion.h | 23 +++++++++++++++++++++ drivers/gpu/ion/msm/msm_ion.c | 30 ++++++++++++++++++++++++++++ include/linux/ion.h | 21 +++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 arch/arm/mach-msm/include/mach/ion.h diff --git a/arch/arm/mach-msm/devices.h b/arch/arm/mach-msm/devices.h index 6297505d6b1..012ba27e474 100644 --- a/arch/arm/mach-msm/devices.h +++ b/arch/arm/mach-msm/devices.h @@ -165,4 +165,6 @@ extern struct platform_device msm_device_touchscreen; extern struct pil_device peripheral_dsps; extern struct platform_device led_pdev; + +extern struct platform_device ion_dev; #endif diff --git a/arch/arm/mach-msm/include/mach/ion.h b/arch/arm/mach-msm/include/mach/ion.h new file mode 100644 index 00000000000..4d12249d567 --- /dev/null +++ b/arch/arm/mach-msm/include/mach/ion.h @@ -0,0 +1,23 @@ +/** + * + * Copyright (c) 2011, Code Aurora Forum. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef __MACH_ION_H_ +#define __MACH_ION_H_ + +enum ion_memory_types { + ION_EBI_TYPE, + ION_SMI_TYPE, +}; + +#endif diff --git a/drivers/gpu/ion/msm/msm_ion.c b/drivers/gpu/ion/msm/msm_ion.c index 35a6063a402..6b1a59a646c 100644 --- a/drivers/gpu/ion/msm/msm_ion.c +++ b/drivers/gpu/ion/msm/msm_ion.c @@ -14,6 +14,9 @@ #include #include #include +#include +#include +#include #include "../ion_priv.h" struct ion_device *idev; @@ -25,6 +28,22 @@ struct ion_client *msm_ion_client_create(unsigned int heap_mask, { return ion_client_create(idev, heap_mask, name); } +EXPORT_SYMBOL(msm_ion_client_create); + +static unsigned long msm_ion_get_base(unsigned long size, int memory_type) +{ + switch (memory_type) { + case ION_EBI_TYPE: + return allocate_contiguous_ebi_nomap(size, PAGE_SIZE); + break; + case ION_SMI_TYPE: + return allocate_contiguous_memory_nomap(size, MEMTYPE_SMI, + PAGE_SIZE); + break; + default: + return 0; + } +} static int msm_ion_probe(struct platform_device *pdev) { @@ -51,6 +70,17 @@ static int msm_ion_probe(struct platform_device *pdev) for (i = 0; i < num_heaps; i++) { struct ion_platform_heap *heap_data = &pdata->heaps[i]; + if (heap_data->type == ION_HEAP_TYPE_CARVEOUT) { + heap_data->base = msm_ion_get_base(heap_data->size, + heap_data->memory_type); + if (!heap_data->base) { + pr_err("%s: could not get memory for heap %s" + " (id %x)\n", __func__, heap_data->name, + heap_data->id); + continue; + } + } + heaps[i] = ion_heap_create(heap_data); if (IS_ERR_OR_NULL(heaps[i])) { err = PTR_ERR(heaps[i]); diff --git a/include/linux/ion.h b/include/linux/ion.h index 5a855e977fc..d6dcf3803f4 100644 --- a/include/linux/ion.h +++ b/include/linux/ion.h @@ -18,6 +18,7 @@ #define _LINUX_ION_H #include +#include struct ion_handle; /** @@ -42,6 +43,25 @@ enum ion_heap_type { #define ION_HEAP_SYSTEM_CONTIG_MASK (1 << ION_HEAP_TYPE_SYSTEM_CONTIG) #define ION_HEAP_CARVEOUT_MASK (1 << ION_HEAP_TYPE_CARVEOUT) + +/** + * These are the only ids that should be used for Ion heap ids. + * The ids listed are the order in which allocation will be attempted + * if specified. Don't swap the order of heap ids unless you know what + * you are doing! + */ + +enum ion_heap_ids { + ION_HEAP_SYSTEM_ID, + ION_HEAP_SYSTEM_CONTIG_ID, + ION_HEAP_EBI_ID, + ION_HEAP_SMI_ID, +}; + +#define ION_KMALLOC_HEAP_NAME "kmalloc" +#define ION_VMALLOC_HEAP_NAME "vmalloc" +#define ION_EBI1_HEAP_NAME "EBI1" + #ifdef __KERNEL__ struct ion_device; struct ion_heap; @@ -72,6 +92,7 @@ struct ion_platform_heap { const char *name; ion_phys_addr_t base; size_t size; + enum ion_memory_types memory_type; }; /**