Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7c0f1114 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge changes If87b8dee,Ia81ea76d into msm-next

* changes:
  Revert "ion: Revert upstream changes for now"
  Revert "ion: Snapshot for 4.12 kernel upgrade"
parents 8bc7bdcf 363288a9
Loading
Loading
Loading
Loading
+0 −72
Original line number Diff line number Diff line
ION Memory Manager (ION)

ION is a memory manager that allows for sharing of buffers between different
processes and between user space and kernel space. ION manages different
memory spaces by separating the memory spaces into "heaps". Depending on the
type of heap ION must reserve memory using the msm specific memory reservation
bindings (see Documentation/devicetree/bindings/arm/msm/memory-reserve.txt).

Required properties for Ion

- compatible: "qcom,msm-ion"


All child nodes of a qcom,msm-ion node are interpreted as Ion heap
configurations.

Required properties for Ion heaps

- reg: The ID of the ION heap.
- qcom,ion-heap-type: The heap type to use for this heap. Should be one of
  the following:
    - "SYSTEM"
    - "SYSTEM_CONTIG"
    - "CARVEOUT"
    - "CHUNK"
    - "CP"
    - "DMA"
    - "SECURE_DMA"

Optional properties for Ion heaps

- compatible: "qcom,msm-ion-reserve" This is required if memory is to be reserved
  as specified by qcom,memory-reservation-size below.
- qcom,heap-align: Alignment of start of the memory in the heap.
- qcom,heap-adjacent: ID of heap this heap needs to be adjacent to.
- qcom,memory-reservation-size: size of reserved memory for the ION heap.
- qcom,memory-reservation-type: type of memory to be reserved
(see memory-reserve.txt for information about memory reservations)
- qcom,default-prefetch-size: Base value to be used for prefetching
  optimizations. Ignored if the heap does not support prefetching.
  Will set to a reasonable default value (e.g. the maximum heap size)
  if this option is not set.

Example:
	qcom,ion {
                 compatible = "qcom,msm-ion";
                 #address-cells = <1>;
                 #size-cells = <0>;

                 qcom,ion-heap@25 {
                         reg = <25>;
                         qcom,ion-heap-type = "SYSTEM";
                 };

                 qcom,ion-heap@8 { /* CP_MM HEAP */
                         compatible = "qcom,msm-ion-reserve";
                         reg = <8>;
                         qcom,heap-align = <0x1000>;
                         linux,contiguous-region = <&secure_mem>;
                         qcom,ion-heap-type = "SECURE_DMA";
                 };

                 qcom,ion-heap@29 { /* FIRMWARE HEAP */
                         compatible = "qcom,msm-ion-reserve";
                         reg = <29>;
                         qcom,heap-align = <0x20000>;
                         qcom,heap-adjacent = <8>;
                         qcom,memory-reservation-type = "EBI1"; /* reserve EBI memory */
                         qcom,memory-reservation-size = <0xA00000>;
                         qcom,ion-heap-type = "CARVEOUT";
                 };
	};
+25 −48
Original line number Diff line number Diff line
menuconfig ION
	bool "Ion Memory Manager"
	depends on HAVE_MEMBLOCK && HAS_DMA && MMU && ION_MSM
	depends on HAVE_MEMBLOCK && HAS_DMA && MMU
	select GENERIC_ALLOCATOR
	select DMA_SHARED_BUFFER
	---help---
@@ -10,58 +10,35 @@ menuconfig ION
	  If you're not using Android its probably safe to
	  say N here.

config ION_TEST
	tristate "Ion Test Device"
config ION_SYSTEM_HEAP
	bool "Ion system heap"
	depends on ION
	help
	  Choose this option to create a device that can be used to test the
	  kernel and device side ION functions.
	  Choose this option to enable the Ion system heap. The system heap
	  is backed by pages from the buddy allocator. If in doubt, say Y.

config ION_DUMMY
	bool "Dummy Ion driver"
config ION_CARVEOUT_HEAP
	bool "Ion carveout heap support"
	depends on ION
	help
	  Provides a dummy ION driver that registers the
	  /dev/ion device and some basic heaps. This can
	  be used for testing the ION infrastructure if
	  one doesn't have access to hardware drivers that
	  use ION.
	  Choose this option to enable carveout heaps with Ion. Carveout heaps
	  are backed by memory reserved from the system. Allocation times are
	  typically faster at the cost of memory not being used. Unless you
	  know your system has these regions, you should say N here.

config ION_TEGRA
	tristate "Ion for Tegra"
	depends on ARCH_TEGRA && ION
	help
	  Choose this option if you wish to use ion on an nVidia Tegra.

config ION_HISI
	tristate "Ion for Hisilicon"
	depends on ARCH_HISI && ION
	help
	  Choose this option if you wish to use ion on Hisilicon Platform.

source "drivers/staging/android/ion/hisilicon/Kconfig"

config ION_POOL_CACHE_POLICY
	bool "Ion set page pool cache policy"
	depends on ION && X86
	default y if X86
	help
	  Choose this option if need to explicity set cache policy of the
	  pages in the page pool.

config ION_MSM
	tristate "Ion for MSM"
	depends on ARCH_QCOM && CMA
	select MSM_SECURE_BUFFER
config ION_CHUNK_HEAP
	bool "Ion chunk heap support"
	depends on ION
	help
	  Choose this option if you wish to use ion on an MSM target.
	  Features include allocating heaps from device tree, buffer
	  cache maintenance, and a custom ioctl/compat_ioctl. Enable
	  utility functions used by ion_system_heap.

config ALLOC_BUFFERS_IN_4K_CHUNKS
	bool "Turns off allocation optimization and allocate only 4K pages"
	depends on ARCH_QCOM && ION
          Choose this option to enable chunk heaps with Ion. This heap is
	  similar in function the carveout heap but memory is broken down
	  into smaller chunk sizes, typically corresponding to a TLB size.
	  Unless you know your system has these regions, you should say N here.

config ION_CMA_HEAP
	bool "Ion CMA heap support"
	depends on ION && CMA
	help
          Choose this option if you want ION to allocate buffers in
          only 4KB chunks.
	  Choose this option to enable CMA heaps with Ion. This heap is backed
	  by the Contiguous Memory Allocator (CMA). If your system has these
	  regions, you should say Y here.
+5 −12
Original line number Diff line number Diff line
obj-$(CONFIG_ION) +=	ion.o ion_heap.o ion_page_pool.o ion_system_heap.o \
			ion_carveout_heap.o ion_chunk_heap.o ion_cma_heap.o \
			ion_system_secure_heap.o
obj-$(CONFIG_ION_TEST) += ion_test.o
ifdef CONFIG_COMPAT
obj-$(CONFIG_ION) += compat_ion.o
endif
obj-$(CONFIG_ION_DUMMY) += ion_dummy_driver.o
obj-$(CONFIG_ION_TEGRA) += tegra/
obj-$(CONFIG_ION_HISI) += hisilicon/

obj-$(CONFIG_ION_MSM) += msm/
obj-$(CONFIG_ION) +=	ion.o ion-ioctl.o ion_heap.o
obj-$(CONFIG_ION_SYSTEM_HEAP) += ion_system_heap.o ion_page_pool.o
obj-$(CONFIG_ION_CARVEOUT_HEAP) += ion_carveout_heap.o
obj-$(CONFIG_ION_CHUNK_HEAP) += ion_chunk_heap.o
obj-$(CONFIG_ION_CMA_HEAP) += ion_cma_heap.o
+0 −195
Original line number Diff line number Diff line
/*
 * drivers/staging/android/ion/compat_ion.c
 *
 * Copyright (C) 2013 Google, Inc.
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * 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.
 *
 */

#include <linux/compat.h>
#include <linux/fs.h>
#include <linux/uaccess.h>

#include "ion.h"
#include "compat_ion.h"

/* See drivers/staging/android/uapi/ion.h for the definition of these structs */
struct compat_ion_allocation_data {
	compat_size_t len;
	compat_size_t align;
	compat_uint_t heap_id_mask;
	compat_uint_t flags;
	compat_int_t handle;
};

struct compat_ion_custom_data {
	compat_uint_t cmd;
	compat_ulong_t arg;
};

struct compat_ion_handle_data {
	compat_int_t handle;
};

#define COMPAT_ION_IOC_ALLOC	_IOWR(ION_IOC_MAGIC, 0, \
				      struct compat_ion_allocation_data)
#define COMPAT_ION_IOC_FREE	_IOWR(ION_IOC_MAGIC, 1, \
				      struct compat_ion_handle_data)
#define COMPAT_ION_IOC_CUSTOM	_IOWR(ION_IOC_MAGIC, 6, \
				      struct compat_ion_custom_data)

static int compat_get_ion_allocation_data(
			struct compat_ion_allocation_data __user *data32,
			struct ion_allocation_data __user *data)
{
	compat_size_t s;
	compat_uint_t u;
	compat_int_t i;
	int err;

	err = get_user(s, &data32->len);
	err |= put_user(s, &data->len);
	err |= get_user(s, &data32->align);
	err |= put_user(s, &data->align);
	err |= get_user(u, &data32->heap_id_mask);
	err |= put_user(u, &data->heap_id_mask);
	err |= get_user(u, &data32->flags);
	err |= put_user(u, &data->flags);
	err |= get_user(i, &data32->handle);
	err |= put_user(i, &data->handle);

	return err;
}

static int compat_get_ion_handle_data(
			struct compat_ion_handle_data __user *data32,
			struct ion_handle_data __user *data)
{
	compat_int_t i;
	int err;

	err = get_user(i, &data32->handle);
	err |= put_user(i, &data->handle);

	return err;
}

static int compat_put_ion_allocation_data(
			struct compat_ion_allocation_data __user *data32,
			struct ion_allocation_data __user *data)
{
	compat_size_t s;
	compat_uint_t u;
	compat_int_t i;
	int err;

	err = get_user(s, &data->len);
	err |= put_user(s, &data32->len);
	err |= get_user(s, &data->align);
	err |= put_user(s, &data32->align);
	err |= get_user(u, &data->heap_id_mask);
	err |= put_user(u, &data32->heap_id_mask);
	err |= get_user(u, &data->flags);
	err |= put_user(u, &data32->flags);
	err |= get_user(i, &data->handle);
	err |= put_user(i, &data32->handle);

	return err;
}

static int compat_get_ion_custom_data(
			struct compat_ion_custom_data __user *data32,
			struct ion_custom_data __user *data)
{
	compat_uint_t cmd;
	compat_ulong_t arg;
	int err;

	err = get_user(cmd, &data32->cmd);
	err |= put_user(cmd, &data->cmd);
	err |= get_user(arg, &data32->arg);
	err |= put_user(arg, &data->arg);

	return err;
};

long compat_ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
	long ret;

	if (!filp->f_op->unlocked_ioctl)
		return -ENOTTY;

	switch (cmd) {
	case COMPAT_ION_IOC_ALLOC:
	{
		struct compat_ion_allocation_data __user *data32;
		struct ion_allocation_data __user *data;
		int err;

		data32 = compat_ptr(arg);
		data = compat_alloc_user_space(sizeof(*data));
		if (!data)
			return -EFAULT;

		err = compat_get_ion_allocation_data(data32, data);
		if (err)
			return err;
		ret = filp->f_op->unlocked_ioctl(filp, ION_IOC_ALLOC,
							(unsigned long)data);
		err = compat_put_ion_allocation_data(data32, data);
		return ret ? ret : err;
	}
	case COMPAT_ION_IOC_FREE:
	{
		struct compat_ion_handle_data __user *data32;
		struct ion_handle_data __user *data;
		int err;

		data32 = compat_ptr(arg);
		data = compat_alloc_user_space(sizeof(*data));
		if (!data)
			return -EFAULT;

		err = compat_get_ion_handle_data(data32, data);
		if (err)
			return err;

		return filp->f_op->unlocked_ioctl(filp, ION_IOC_FREE,
							(unsigned long)data);
	}
	case COMPAT_ION_IOC_CUSTOM: {
		struct compat_ion_custom_data __user *data32;
		struct ion_custom_data __user *data;
		int err;

		data32 = compat_ptr(arg);
		data = compat_alloc_user_space(sizeof(*data));
		if (!data)
			return -EFAULT;

		err = compat_get_ion_custom_data(data32, data);
		if (err)
			return err;

		return filp->f_op->unlocked_ioctl(filp, ION_IOC_CUSTOM,
							(unsigned long)data);
	}
	case ION_IOC_SHARE:
	case ION_IOC_MAP:
	case ION_IOC_IMPORT:
	case ION_IOC_SYNC:
		return filp->f_op->unlocked_ioctl(filp, cmd,
						(unsigned long)compat_ptr(arg));
	default:
		return -ENOIOCTLCMD;
	}
}
+0 −32
Original line number Diff line number Diff line
/*
 * drivers/staging/android/ion/compat_ion.h
 *
 * Copyright (C) 2013 Google, Inc.
 * Copyright (c) 2016, The Linux Foundation. All rights reserved.
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * 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 _LINUX_COMPAT_ION_H
#define _LINUX_COMPAT_ION_H

#if IS_ENABLED(CONFIG_COMPAT)

long compat_ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);

#define compat_ion_user_handle_t compat_int_t

#else

#define compat_ion_ioctl  NULL

#endif /* CONFIG_COMPAT */
#endif /* _LINUX_COMPAT_ION_H */
Loading