Skip to content
This repository has been archived by the owner on Oct 5, 2018. It is now read-only.

Commit

Permalink
Merge branch 'working-hikey960-upstream-ion' into working-hikey960-up…
Browse files Browse the repository at this point in the history
…stream-rebase-v4.14-rc7-2017-11-03-18-10-36

* working-hikey960-upstream-ion:
  HACK: ion: Revert ION to 4.11 era code to avoid ABI break
  • Loading branch information
docularxu committed Nov 3, 2017
2 parents 772e60d + dd5cb1f commit ed16484
Show file tree
Hide file tree
Showing 27 changed files with 3,295 additions and 564 deletions.
21 changes: 17 additions & 4 deletions drivers/staging/android/TODO
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,23 @@ TODO:


ion/
- Add dt-bindings for remaining heaps (chunk and carveout heaps). This would
involve putting appropriate bindings in a memory node for Ion to find.
- Split /dev/ion up into multiple nodes (e.g. /dev/ion/heap0)
- Better test framework (integration with VGEM was suggested)
- Remove ION_IOC_SYNC: Flushing for devices should be purely a kernel internal
interface on top of dma-buf. flush_for_device needs to be added to dma-buf
first.
- Remove ION_IOC_CUSTOM: Atm used for cache flushing for cpu access in some
vendor trees. Should be replaced with an ioctl on the dma-buf to expose the
begin/end_cpu_access hooks to userspace.
- Clarify the tricks ion plays with explicitly managing coherency behind the
dma api's back (this is absolutely needed for high-perf gpu drivers): Add an
explicit coherency management mode to flush_for_device to be used by drivers
which want to manage caches themselves and which indicates whether cpu caches
need flushing.
- With those removed there's probably no use for ION_IOC_IMPORT anymore either
since ion would just be the central allocator for shared buffers.
- Add dt-binding to expose cma regions as ion heaps, with the rule that any
such cma regions must already be used by some device for dma. I.e. ion only
exposes existing cma regions and doesn't reserve unecessarily memory when
booting a system which doesn't use ion.

Please send patches to Greg Kroah-Hartman <[email protected]> and Cc:
Arve Hjønnevåg <[email protected]> and Riley Andrews <[email protected]>
56 changes: 33 additions & 23 deletions drivers/staging/android/ion/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,45 @@ menuconfig ION
If you're not using Android its probably safe to
say N here.

config ION_SYSTEM_HEAP
bool "Ion system heap"
config ION_TEST
tristate "Ion Test Device"
depends on ION
help
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.
Choose this option to create a device that can be used to test the
kernel and device side ION functions.

config ION_CARVEOUT_HEAP
bool "Ion carveout heap support"
config ION_DUMMY
bool "Dummy Ion driver"
depends on ION
help
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.
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.

config ION_CHUNK_HEAP
bool "Ion chunk heap support"
depends on ION
config ION_TEGRA
tristate "Ion for Tegra"
depends on ARCH_TEGRA && ION
help
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.
Choose this option if you wish to use ion on an nVidia Tegra.

config ION_CMA_HEAP
bool "Ion CMA heap support"
depends on ION && CMA
config ION_HISI
tristate "Ion for Hisilicon"
depends on ARCH_HISI && ION
select ION_OF
help
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.
Choose this option if you wish to use ion on Hisilicon Platform.

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

config ION_OF
bool "Devicetree support for Ion"
depends on ION && OF_ADDRESS
help
Provides base support for defining Ion heaps in devicetree
and setting them up. Also includes functions for platforms
to parse the devicetree and expand for their own custom
extensions

If using Ion and devicetree, you should say Y here
18 changes: 13 additions & 5 deletions drivers/staging/android/ion/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
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
obj-$(CONFIG_ION) += ion.o ion-ioctl.o ion_heap.o \
ion_page_pool.o ion_system_heap.o \
ion_carveout_heap.o ion_chunk_heap.o ion_cma_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_OF) += ion_of.o

195 changes: 195 additions & 0 deletions drivers/staging/android/ion/compat_ion.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
/*
* 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;
}
}
29 changes: 29 additions & 0 deletions drivers/staging/android/ion/compat_ion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* drivers/staging/android/ion/compat_ion.h
*
* 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.
*
*/

#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);

#else

#define compat_ion_ioctl NULL

#endif /* CONFIG_COMPAT */
#endif /* _LINUX_COMPAT_ION_H */
51 changes: 51 additions & 0 deletions drivers/staging/android/ion/devicetree.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Ion Memory Manager

Ion is a memory manager that allows for sharing of buffers via dma-buf.
Ion allows for different types of allocation via an abstraction called
a 'heap'. A heap represents a specific type of memory. Each heap has
a different type. There can be multiple instances of the same heap
type.

Specific heap instances are tied to heap IDs. Heap IDs are not to be specified
in the devicetree.

Required properties for Ion

- compatible: "linux,ion" PLUS a compatible property for the device

All child nodes of a linux,ion node are interpreted as heaps

required properties for heaps

- compatible: compatible string for a heap type PLUS a compatible property
for the specific instance of the heap. Current heap types
-- linux,ion-heap-system
-- linux,ion-heap-system-contig
-- linux,ion-heap-carveout
-- linux,ion-heap-chunk
-- linux,ion-heap-dma
-- linux,ion-heap-custom

Optional properties
- memory-region: A phandle to a memory region. Required for DMA heap type
(see reserved-memory.txt for details on the reservation)

Example:

ion {
compatbile = "hisilicon,ion", "linux,ion";

ion-system-heap {
compatbile = "hisilicon,system-heap", "linux,ion-heap-system"
};

ion-camera-region {
compatible = "hisilicon,camera-heap", "linux,ion-heap-dma"
memory-region = <&camera_region>;
};

ion-fb-region {
compatbile = "hisilicon,fb-heap", "linux,ion-heap-dma"
memory-region = <&fb_region>;
};
}
5 changes: 5 additions & 0 deletions drivers/staging/android/ion/hisilicon/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
config HI6220_ION
bool "Hi6220 ION Driver"
depends on ARCH_HISI && ION
help
Build the Hisilicon Hi6220 ion driver.
Loading

0 comments on commit ed16484

Please sign in to comment.