├── .gitignore ├── Makefile ├── README ├── cedrus.c ├── cedrus.h ├── cedrus_mem.h ├── cedrus_mem_ion.c ├── cedrus_mem_ump.c ├── cedrus_mem_ve.c ├── cedrus_regs.h └── kernel-headers ├── README ├── cedardev_api.h ├── ion.h └── ion_sunxi.h /.gitignore: -------------------------------------------------------------------------------- 1 | *.d 2 | *.o 3 | libcedrus.so.1 4 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | TARGET = libcedrus.so.1 2 | SRC = cedrus.c cedrus_mem_ve.c cedrus_mem_ion.c 3 | INC = cedrus.h cedrus_regs.h 4 | CFLAGS ?= -Wall -Wextra -O3 5 | LDFLAGS ?= 6 | LIBS = -lpthread 7 | CC ?= gcc 8 | 9 | prefix ?= /usr/local 10 | libdir ?= $(prefix)/lib 11 | includedir ?= $(prefix)/include 12 | 13 | ifeq ($(USE_UMP),1) 14 | SRC += cedrus_mem_ump.c 15 | CFLAGS += -DUSE_UMP 16 | LIBS += -lUMP 17 | endif 18 | 19 | DEP_CFLAGS = -MD -MP -MQ $@ 20 | LIB_CFLAGS = -fpic -fvisibility=hidden 21 | LIB_LDFLAGS = -shared -Wl,-soname,$(TARGET) 22 | 23 | OBJ = $(addsuffix .o,$(basename $(SRC))) 24 | DEP = $(addsuffix .d,$(basename $(SRC))) 25 | 26 | .PHONY: clean all install uninstall 27 | 28 | all: $(TARGET) 29 | $(TARGET): $(OBJ) 30 | $(CC) $(LIB_LDFLAGS) $(LDFLAGS) $(OBJ) $(LIBS) -o $@ 31 | 32 | clean: 33 | rm -f $(OBJ) 34 | rm -f $(DEP) 35 | rm -f $(TARGET) 36 | 37 | install: $(TARGET) $(INC) 38 | install -D $(TARGET) $(DESTDIR)/$(libdir)/$(TARGET) 39 | ln -sf $(TARGET) $(DESTDIR)/$(libdir)/$(basename $(TARGET)) 40 | install -D -t $(DESTDIR)/$(includedir)/cedrus/ $(INC) 41 | 42 | uninstall: 43 | rm -f $(DESTDIR)/$(libdir)/$(basename $(TARGET)) 44 | rm -f $(DESTDIR)/$(libdir)/$(TARGET) 45 | rm -rf $(DESTDIR)/$(includedir)/cedrus 46 | 47 | %.o: %.c 48 | $(CC) $(DEP_CFLAGS) $(LIB_CFLAGS) $(CFLAGS) -c $< -o $@ 49 | 50 | include $(wildcard $(DEP)) 51 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | libcedrus provides low-level access to the video engine of Allwinner sunxi SoCs. 2 | 3 | Installation: 4 | 5 | $ make 6 | $ make install 7 | -------------------------------------------------------------------------------- /cedrus.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2016 Jens Kuske 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include "cedrus.h" 30 | #include "cedrus_mem.h" 31 | #include "cedrus_regs.h" 32 | #include "kernel-headers/cedardev_api.h" 33 | 34 | #define DEVICE "/dev/cedar_dev" 35 | #define EXPORT __attribute__ ((visibility ("default"))) 36 | 37 | static struct cedrus 38 | { 39 | int fd; 40 | void *regs; 41 | int version; 42 | int ioctl_offset; 43 | struct cedrus_allocator *allocator; 44 | pthread_mutex_t device_lock; 45 | } ve = { .fd = -1, .device_lock = PTHREAD_MUTEX_INITIALIZER }; 46 | 47 | EXPORT struct cedrus *cedrus_open(void) 48 | { 49 | if (ve.fd != -1) 50 | return NULL; 51 | 52 | struct cedarv_env_infomation info; 53 | 54 | ve.fd = open(DEVICE, O_RDWR); 55 | if (ve.fd == -1) 56 | return NULL; 57 | 58 | if (ioctl(ve.fd, IOCTL_GET_ENV_INFO, (void *)(&info)) == -1) 59 | goto close; 60 | 61 | ve.regs = mmap(NULL, 0x800, PROT_READ | PROT_WRITE, MAP_SHARED, ve.fd, info.address_macc); 62 | if (ve.regs == MAP_FAILED) 63 | goto close; 64 | 65 | #ifdef USE_UMP 66 | ve.allocator = cedrus_allocator_ump_new(); 67 | if (!ve.allocator) 68 | #endif 69 | { 70 | ve.allocator = cedrus_allocator_ve_new(ve.fd, &info); 71 | if (!ve.allocator) 72 | { 73 | ve.allocator = cedrus_allocator_ion_new(); 74 | if (!ve.allocator) 75 | goto unmap; 76 | } 77 | } 78 | 79 | ioctl(ve.fd, IOCTL_ENGINE_REQ, 0); 80 | 81 | ve.version = readl(ve.regs + VE_VERSION) >> 16; 82 | 83 | if (ve.version >= 0x1639) 84 | ve.ioctl_offset = 1; 85 | 86 | ioctl(ve.fd, IOCTL_ENABLE_VE + ve.ioctl_offset, 0); 87 | ioctl(ve.fd, IOCTL_SET_VE_FREQ + ve.ioctl_offset, 320); 88 | ioctl(ve.fd, IOCTL_RESET_VE + ve.ioctl_offset, 0); 89 | 90 | writel(0x00130007, ve.regs + VE_CTRL); 91 | 92 | return &ve; 93 | 94 | unmap: 95 | munmap(ve.regs, 0x800); 96 | close: 97 | close(ve.fd); 98 | ve.fd = -1; 99 | return NULL; 100 | } 101 | 102 | EXPORT void cedrus_close(struct cedrus *dev) 103 | { 104 | if (dev->fd == -1) 105 | return; 106 | 107 | ioctl(dev->fd, IOCTL_DISABLE_VE + dev->ioctl_offset, 0); 108 | ioctl(dev->fd, IOCTL_ENGINE_REL, 0); 109 | 110 | munmap(dev->regs, 0x800); 111 | dev->regs = NULL; 112 | 113 | dev->allocator->free(dev->allocator); 114 | 115 | close(dev->fd); 116 | dev->fd = -1; 117 | } 118 | 119 | EXPORT int cedrus_get_ve_version(struct cedrus *dev) 120 | { 121 | if (!dev) 122 | return 0x0; 123 | 124 | return dev->version; 125 | } 126 | 127 | EXPORT int cedrus_ve_wait(struct cedrus *dev, int timeout) 128 | { 129 | if (!dev) 130 | return -1; 131 | 132 | return ioctl(dev->fd, IOCTL_WAIT_VE_DE, timeout); 133 | } 134 | 135 | EXPORT void *cedrus_ve_get(struct cedrus *dev, enum cedrus_engine engine, uint32_t flags) 136 | { 137 | if (!dev || pthread_mutex_lock(&dev->device_lock)) 138 | return NULL; 139 | 140 | writel(0x00130000 | (engine & 0xf) | (flags & ~0xf), dev->regs + VE_CTRL); 141 | 142 | return dev->regs; 143 | } 144 | 145 | EXPORT void cedrus_ve_put(struct cedrus *dev) 146 | { 147 | if (!dev) 148 | return; 149 | 150 | writel(0x00130007, dev->regs + VE_CTRL); 151 | pthread_mutex_unlock(&dev->device_lock); 152 | } 153 | 154 | EXPORT struct cedrus_mem *cedrus_mem_alloc(struct cedrus *dev, size_t size) 155 | { 156 | if (!dev || size == 0) 157 | return NULL; 158 | 159 | return dev->allocator->mem_alloc(dev->allocator, (size + 4096 - 1) & ~(4096 - 1)); 160 | } 161 | 162 | EXPORT void cedrus_mem_free(struct cedrus_mem *mem) 163 | { 164 | if (!mem) 165 | return; 166 | 167 | ve.allocator->mem_free(ve.allocator, mem); 168 | } 169 | 170 | EXPORT void cedrus_mem_flush_cache(struct cedrus_mem *mem) 171 | { 172 | if (!mem) 173 | return; 174 | 175 | ve.allocator->mem_flush(ve.allocator, mem); 176 | } 177 | 178 | EXPORT void *cedrus_mem_get_pointer(const struct cedrus_mem *mem) 179 | { 180 | if (!mem) 181 | return NULL; 182 | 183 | return mem->virt; 184 | } 185 | 186 | EXPORT uint32_t cedrus_mem_get_phys_addr(const struct cedrus_mem *mem) 187 | { 188 | if (!mem) 189 | return 0x0; 190 | 191 | return mem->phys; 192 | } 193 | 194 | uint32_t phys2bus(uint32_t phys) 195 | { 196 | if (ve.version == 0x1639) 197 | return phys - 0x20000000; 198 | else 199 | return phys - 0x40000000; 200 | } 201 | 202 | uint32_t bus2phys(uint32_t bus) 203 | { 204 | if (ve.version == 0x1639) 205 | return bus + 0x20000000; 206 | else 207 | return bus + 0x40000000; 208 | } 209 | 210 | EXPORT uint32_t cedrus_mem_get_bus_addr(const struct cedrus_mem *mem) 211 | { 212 | if (!mem) 213 | return 0x0; 214 | 215 | return phys2bus(mem->phys); 216 | } 217 | -------------------------------------------------------------------------------- /cedrus.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2016 Jens Kuske 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | #ifndef CEDRUS_H_ 21 | #define CEDRUS_H_ 22 | 23 | #include 24 | #include 25 | 26 | typedef struct cedrus cedrus_t; 27 | 28 | enum cedrus_engine { CEDRUS_ENGINE_MPEG = 0x0, CEDRUS_ENGINE_H264 = 0x1, CEDRUS_ENGINE_HEVC = 0x4 }; 29 | 30 | cedrus_t *cedrus_open(void); 31 | void cedrus_close(cedrus_t *dev); 32 | int cedrus_get_ve_version(cedrus_t *dev); 33 | int cedrus_ve_wait(cedrus_t *dev, int timeout); 34 | void *cedrus_ve_get(cedrus_t *dev, enum cedrus_engine engine, uint32_t flags); 35 | void cedrus_ve_put(cedrus_t *dev); 36 | 37 | typedef struct cedrus_mem cedrus_mem_t; 38 | 39 | cedrus_mem_t *cedrus_mem_alloc(cedrus_t *dev, size_t size); 40 | void cedrus_mem_free(cedrus_mem_t *mem); 41 | void cedrus_mem_flush_cache(cedrus_mem_t *mem); 42 | void *cedrus_mem_get_pointer(const cedrus_mem_t *mem); 43 | uint32_t cedrus_mem_get_phys_addr(const cedrus_mem_t *mem); 44 | uint32_t cedrus_mem_get_bus_addr(const cedrus_mem_t *mem); 45 | void *cedrus_mem_get_ump_handle(const cedrus_mem_t *mem); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /cedrus_mem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2016 Jens Kuske 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | #ifndef CEDRUS_MEM_H_ 21 | #define CEDRUS_MEM_H_ 22 | 23 | #include 24 | #include 25 | #include "kernel-headers/cedardev_api.h" 26 | 27 | struct cedrus_mem 28 | { 29 | void *virt; 30 | uint32_t phys; 31 | size_t size; 32 | }; 33 | 34 | struct cedrus_allocator 35 | { 36 | struct cedrus_mem *(*mem_alloc)(struct cedrus_allocator *allocator, size_t size); 37 | void (*mem_free)(struct cedrus_allocator *allocator, struct cedrus_mem *mem); 38 | void (*mem_flush)(struct cedrus_allocator *allocator, struct cedrus_mem *mem); 39 | 40 | void (*free)(struct cedrus_allocator *allocator); 41 | }; 42 | 43 | struct cedrus_allocator *cedrus_allocator_ve_new(int ve_fd, const struct cedarv_env_infomation *ve_info); 44 | struct cedrus_allocator *cedrus_allocator_ion_new(void); 45 | #ifdef USE_UMP 46 | struct cedrus_allocator *cedrus_allocator_ump_new(void); 47 | #endif 48 | 49 | uint32_t phys2bus(uint32_t phys); 50 | uint32_t bus2phys(uint32_t bus); 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /cedrus_mem_ion.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2016 Jens Kuske 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include "cedrus_mem.h" 27 | #include "kernel-headers/ion.h" 28 | #include "kernel-headers/ion_sunxi.h" 29 | 30 | struct ion_mem 31 | { 32 | struct cedrus_mem pub; 33 | 34 | ion_user_handle_t handle; 35 | int fd; 36 | }; 37 | 38 | struct ion_allocator 39 | { 40 | struct cedrus_allocator pub; 41 | 42 | int fd; 43 | }; 44 | 45 | static ion_user_handle_t ion_alloc(int ion_fd, size_t size) 46 | { 47 | struct ion_allocation_data allocation_data = { 48 | .len = size, 49 | .align = 4096, 50 | .heap_id_mask = ION_HEAP_TYPE_DMA_MASK, 51 | .flags = ION_FLAG_CACHED | ION_FLAG_CACHED_NEEDS_SYNC, 52 | }; 53 | 54 | if (ioctl(ion_fd, ION_IOC_ALLOC, &allocation_data)) 55 | return 0; 56 | 57 | return allocation_data.handle; 58 | } 59 | 60 | static int ion_map(int ion_fd, ion_user_handle_t ion_handle) 61 | { 62 | struct ion_fd_data fd_data = { 63 | .handle = ion_handle, 64 | }; 65 | 66 | if (ioctl(ion_fd, ION_IOC_MAP, &fd_data)) 67 | return -1; 68 | 69 | return fd_data.fd; 70 | } 71 | 72 | static uint32_t ion_get_phys_addr(int ion_fd, ion_user_handle_t ion_handle) 73 | { 74 | sunxi_phys_data phys_data = { 75 | .handle = ion_handle, 76 | }; 77 | 78 | struct ion_custom_data custom_data = { 79 | .cmd = ION_IOC_SUNXI_PHYS_ADDR, 80 | .arg = (unsigned long)(&phys_data), 81 | }; 82 | 83 | if (ioctl(ion_fd, ION_IOC_CUSTOM, &custom_data)) 84 | return 0x0; 85 | 86 | return phys_data.phys_addr; 87 | } 88 | 89 | static int ion_flush_cache(int ion_fd, void *addr, size_t size) 90 | { 91 | static int new_ioctl = 0; 92 | 93 | sunxi_cache_range cache_range = { 94 | .start = (long)addr, 95 | .end = (long)addr + size, 96 | }; 97 | 98 | struct ion_custom_data custom_data = { 99 | .cmd = ION_IOC_SUNXI_FLUSH_RANGE, 100 | .arg = (unsigned long)(&cache_range), 101 | }; 102 | 103 | if (new_ioctl || ioctl(ion_fd, ION_IOC_CUSTOM, &custom_data)) 104 | { 105 | if (ioctl(ion_fd, ION_IOC_SUNXI_FLUSH_RANGE, &cache_range)) 106 | return 0; 107 | else 108 | new_ioctl = 1; 109 | } 110 | 111 | return 1; 112 | } 113 | 114 | static int ion_free(int ion_fd, ion_user_handle_t ion_handle) 115 | { 116 | struct ion_handle_data handle_data = { 117 | .handle = ion_handle, 118 | }; 119 | 120 | if (ioctl(ion_fd, ION_IOC_FREE, &handle_data)) 121 | return 0; 122 | 123 | return 1; 124 | } 125 | 126 | static struct cedrus_mem *cedrus_allocator_ion_mem_alloc(struct cedrus_allocator *allocator_pub, size_t size) 127 | { 128 | struct ion_allocator *allocator = (struct ion_allocator *)allocator_pub; 129 | 130 | struct ion_mem *mem = calloc(1, sizeof(*mem)); 131 | if (!mem) 132 | return NULL; 133 | 134 | mem->pub.size = size; 135 | 136 | mem->handle = ion_alloc(allocator->fd, size); 137 | if (!mem->handle) 138 | goto err; 139 | 140 | mem->pub.phys = ion_get_phys_addr(allocator->fd, mem->handle); 141 | if (!mem->pub.phys) 142 | goto err_free; 143 | 144 | mem->fd = ion_map(allocator->fd, mem->handle); 145 | if (mem->fd < 0) 146 | goto err_free; 147 | 148 | mem->pub.virt = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, mem->fd, 0); 149 | if (mem->pub.virt == MAP_FAILED) 150 | goto err_close; 151 | 152 | return &mem->pub; 153 | 154 | err_close: 155 | close(mem->fd); 156 | err_free: 157 | ion_free(allocator->fd, mem->handle); 158 | err: 159 | free(mem); 160 | return NULL; 161 | } 162 | 163 | static void cedrus_allocator_ion_mem_free(struct cedrus_allocator *allocator_pub, struct cedrus_mem *mem_pub) 164 | { 165 | struct ion_allocator *allocator = (struct ion_allocator *)allocator_pub; 166 | struct ion_mem *mem = (struct ion_mem *)mem_pub; 167 | 168 | munmap(mem->pub.virt, mem->pub.size); 169 | close(mem->fd); 170 | ion_free(allocator->fd, mem->handle); 171 | 172 | free(mem); 173 | } 174 | 175 | static void cedrus_allocator_ion_mem_flush(struct cedrus_allocator *allocator_pub, struct cedrus_mem *mem_pub) 176 | { 177 | struct ion_allocator *allocator = (struct ion_allocator *)allocator_pub; 178 | struct ion_mem *mem = (struct ion_mem *)mem_pub; 179 | 180 | ion_flush_cache(allocator->fd, mem->pub.virt, mem->pub.size); 181 | } 182 | 183 | static void cedrus_allocator_ion_free(struct cedrus_allocator *allocator_pub) 184 | { 185 | struct ion_allocator *allocator = (struct ion_allocator *)allocator_pub; 186 | 187 | close(allocator->fd); 188 | free(allocator); 189 | } 190 | 191 | struct cedrus_allocator *cedrus_allocator_ion_new(void) 192 | { 193 | struct ion_allocator *allocator = calloc(1, sizeof(*allocator)); 194 | if (!allocator) 195 | return NULL; 196 | 197 | allocator->fd = open("/dev/ion", O_RDONLY); 198 | if (allocator->fd == -1) 199 | { 200 | free(allocator); 201 | return NULL; 202 | } 203 | 204 | allocator->pub.mem_alloc = cedrus_allocator_ion_mem_alloc; 205 | allocator->pub.mem_free = cedrus_allocator_ion_mem_free; 206 | allocator->pub.mem_flush = cedrus_allocator_ion_mem_flush; 207 | 208 | allocator->pub.free = cedrus_allocator_ion_free; 209 | 210 | return &allocator->pub; 211 | } 212 | -------------------------------------------------------------------------------- /cedrus_mem_ump.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Jens Kuske 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include "cedrus_mem.h" 29 | 30 | struct ump_mem 31 | { 32 | struct cedrus_mem pub; 33 | 34 | ump_handle handle; 35 | }; 36 | 37 | static struct cedrus_mem *cedrus_allocator_ump_mem_alloc(struct cedrus_allocator *allocator, size_t size) 38 | { 39 | (void)allocator; 40 | struct ump_mem *mem = calloc(1, sizeof(*mem)); 41 | if (!mem) 42 | return NULL; 43 | 44 | mem->pub.size = size; 45 | 46 | mem->handle = ump_ref_drv_allocate(size, UMP_REF_DRV_CONSTRAINT_PHYSICALLY_LINEAR); 47 | if (mem->handle == UMP_INVALID_MEMORY_HANDLE) 48 | goto err; 49 | 50 | mem->pub.virt = ump_mapped_pointer_get(mem->handle); 51 | if (!mem->pub.virt) 52 | goto err_release; 53 | 54 | mem->pub.phys = bus2phys((uint32_t)ump_phys_address_get(mem->handle)); 55 | if (!mem->pub.phys) 56 | goto err_release; 57 | 58 | return &mem->pub; 59 | 60 | err_release: 61 | ump_reference_release(mem->handle); 62 | err: 63 | free(mem); 64 | return NULL; 65 | } 66 | 67 | static void cedrus_allocator_ump_mem_free(struct cedrus_allocator *allocator, struct cedrus_mem *mem_pub) 68 | { 69 | (void)allocator; 70 | struct ump_mem *mem = (struct ump_mem *)mem_pub; 71 | 72 | ump_reference_release(mem->handle); 73 | 74 | free(mem); 75 | } 76 | 77 | static void cedrus_allocator_ump_mem_flush(struct cedrus_allocator *allocator, struct cedrus_mem *mem_pub) 78 | { 79 | (void)allocator; 80 | struct ump_mem *mem = (struct ump_mem *)mem_pub; 81 | 82 | ump_cpu_msync_now(mem->handle, UMP_MSYNC_CLEAN_AND_INVALIDATE, 0, mem->pub.size); 83 | } 84 | 85 | static void cedrus_allocator_ump_free(struct cedrus_allocator *allocator) 86 | { 87 | ump_close(); 88 | free(allocator); 89 | } 90 | 91 | struct cedrus_allocator *cedrus_allocator_ump_new(void) 92 | { 93 | struct cedrus_allocator *allocator = calloc(1, sizeof(*allocator)); 94 | if (!allocator) 95 | return NULL; 96 | 97 | if (ump_open() != UMP_OK) 98 | { 99 | free(allocator); 100 | return NULL; 101 | } 102 | 103 | allocator->mem_alloc = cedrus_allocator_ump_mem_alloc; 104 | allocator->mem_free = cedrus_allocator_ump_mem_free; 105 | allocator->mem_flush = cedrus_allocator_ump_mem_flush; 106 | 107 | allocator->free = cedrus_allocator_ump_free; 108 | 109 | return allocator; 110 | } 111 | 112 | __attribute__ ((visibility ("default"))) void *cedrus_mem_get_ump_handle(const struct cedrus_mem *mem_pub) 113 | { 114 | const struct ump_mem *mem = (const struct ump_mem *)mem_pub; 115 | 116 | if (!mem) 117 | return 0x0; 118 | 119 | return mem->handle; 120 | } 121 | -------------------------------------------------------------------------------- /cedrus_mem_ve.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2016 Jens Kuske 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "cedrus_mem.h" 25 | #include "kernel-headers/cedardev_api.h" 26 | 27 | #define PAGE_OFFSET (0xc0000000) // from kernel 28 | 29 | struct ve_mem 30 | { 31 | struct cedrus_mem pub; 32 | 33 | struct ve_mem *next; 34 | }; 35 | 36 | struct ve_allocator 37 | { 38 | struct cedrus_allocator pub; 39 | 40 | int fd; 41 | struct ve_mem first; 42 | pthread_mutex_t lock; 43 | }; 44 | 45 | static struct cedrus_mem *cedrus_allocator_ve_mem_alloc(struct cedrus_allocator *allocator_pub, size_t size) 46 | { 47 | struct ve_allocator *allocator = (struct ve_allocator *)allocator_pub; 48 | 49 | if (pthread_mutex_lock(&allocator->lock)) 50 | return NULL; 51 | 52 | void *addr = NULL; 53 | struct cedrus_mem *ret = NULL; 54 | 55 | struct ve_mem *c, *best_chunk = NULL; 56 | for (c = &allocator->first; c != NULL; c = c->next) 57 | { 58 | if(c->pub.virt == NULL && c->pub.size >= size) 59 | { 60 | if (best_chunk == NULL || c->pub.size < best_chunk->pub.size) 61 | best_chunk = c; 62 | 63 | if (c->pub.size == size) 64 | break; 65 | } 66 | } 67 | 68 | if (!best_chunk) 69 | goto out; 70 | 71 | int left_size = best_chunk->pub.size - size; 72 | 73 | addr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, allocator->fd, phys2bus(best_chunk->pub.phys) + PAGE_OFFSET); 74 | if (addr == MAP_FAILED) 75 | { 76 | ret = NULL; 77 | goto out; 78 | } 79 | 80 | best_chunk->pub.virt = addr; 81 | best_chunk->pub.size = size; 82 | 83 | ret = &best_chunk->pub; 84 | 85 | if (left_size > 0) 86 | { 87 | c = calloc(1, sizeof(*c)); 88 | if (!c) 89 | goto out; 90 | 91 | c->pub.phys = best_chunk->pub.phys + size; 92 | c->pub.size = left_size; 93 | c->pub.virt = NULL; 94 | c->next = best_chunk->next; 95 | best_chunk->next = c; 96 | } 97 | 98 | out: 99 | pthread_mutex_unlock(&allocator->lock); 100 | 101 | return ret; 102 | } 103 | 104 | static void cedrus_allocator_ve_mem_free(struct cedrus_allocator *allocator_pub, struct cedrus_mem *mem_pub) 105 | { 106 | struct ve_allocator *allocator = (struct ve_allocator *)allocator_pub; 107 | struct ve_mem *mem = (struct ve_mem *)mem_pub; 108 | 109 | if (pthread_mutex_lock(&allocator->lock)) 110 | return; 111 | 112 | struct ve_mem *c; 113 | for (c = &allocator->first; c != NULL; c = c->next) 114 | { 115 | if (&c->pub == &mem->pub) 116 | { 117 | munmap(c->pub.virt, c->pub.size); 118 | c->pub.virt = NULL; 119 | break; 120 | } 121 | } 122 | 123 | for (c = &allocator->first; c != NULL; c = c->next) 124 | { 125 | if (c->pub.virt == NULL) 126 | { 127 | while (c->next != NULL && c->next->pub.virt == NULL) 128 | { 129 | struct ve_mem *n = c->next; 130 | c->pub.size += n->pub.size; 131 | c->next = n->next; 132 | free(n); 133 | } 134 | } 135 | } 136 | 137 | pthread_mutex_unlock(&allocator->lock); 138 | } 139 | 140 | static void cedrus_allocator_ve_mem_flush(struct cedrus_allocator *allocator_pub, struct cedrus_mem *mem_pub) 141 | { 142 | struct ve_allocator *allocator = (struct ve_allocator *)allocator_pub; 143 | struct ve_mem *mem = (struct ve_mem *)mem_pub; 144 | 145 | struct cedarv_cache_range cache_range = { 146 | .start = (long)mem->pub.virt, 147 | .end = (long)mem->pub.virt + mem->pub.size 148 | }; 149 | 150 | ioctl(allocator->fd, IOCTL_FLUSH_CACHE, &cache_range); 151 | } 152 | 153 | static void cedrus_allocator_ve_free(struct cedrus_allocator *allocator_pub) 154 | { 155 | struct ve_allocator *allocator = (struct ve_allocator *)allocator_pub; 156 | 157 | free(allocator); 158 | } 159 | 160 | struct cedrus_allocator *cedrus_allocator_ve_new(int ve_fd, const struct cedarv_env_infomation *ve_info) 161 | { 162 | if (ve_info->phymem_total_size == 0) 163 | return NULL; 164 | 165 | struct ve_allocator *allocator = calloc(1, sizeof(*allocator)); 166 | if (!allocator) 167 | return NULL; 168 | 169 | allocator->fd = ve_fd; 170 | 171 | allocator->first.pub.phys = bus2phys(ve_info->phymem_start - PAGE_OFFSET); 172 | allocator->first.pub.size = ve_info->phymem_total_size; 173 | 174 | pthread_mutex_init(&allocator->lock, NULL); 175 | 176 | allocator->pub.mem_alloc = cedrus_allocator_ve_mem_alloc; 177 | allocator->pub.mem_free = cedrus_allocator_ve_mem_free; 178 | allocator->pub.mem_flush = cedrus_allocator_ve_mem_flush; 179 | 180 | allocator->pub.free = cedrus_allocator_ve_free; 181 | 182 | return &allocator->pub; 183 | } 184 | -------------------------------------------------------------------------------- /cedrus_regs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2016 Jens Kuske 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | #ifndef CEDRUS_REGS_H_ 21 | #define CEDRUS_REGS_H_ 22 | 23 | #include 24 | 25 | static inline void writel(uint32_t val, void *addr) 26 | { 27 | *((volatile uint32_t *)addr) = val; 28 | } 29 | 30 | static inline uint32_t readl(void *addr) 31 | { 32 | return *((volatile uint32_t *) addr); 33 | } 34 | 35 | #define VE_CTRL 0x000 36 | #define VE_EXTRA_OUT_FMT_OFFSET 0x0e8 37 | #define VE_VERSION 0x0f0 38 | 39 | #define VE_MPEG_PIC_HDR 0x100 40 | #define VE_MPEG_VOP_HDR 0x104 41 | #define VE_MPEG_SIZE 0x108 42 | #define VE_MPEG_FRAME_SIZE 0x10c 43 | #define VE_MPEG_MBA 0x110 44 | #define VE_MPEG_CTRL 0x114 45 | #define VE_MPEG_TRIGGER 0x118 46 | #define VE_MPEG_STATUS 0x11c 47 | #define VE_MPEG_TRBTRD_FIELD 0x120 48 | #define VE_MPEG_TRBTRD_FRAME 0x124 49 | #define VE_MPEG_VLD_ADDR 0x128 50 | #define VE_MPEG_VLD_OFFSET 0x12c 51 | #define VE_MPEG_VLD_LEN 0x130 52 | #define VE_MPEG_VLD_END 0x134 53 | #define VE_MPEG_MBH_ADDR 0x138 54 | #define VE_MPEG_DCAC_ADDR 0x13c 55 | #define VE_MPEG_NCF_ADDR 0x144 56 | #define VE_MPEG_REC_LUMA 0x148 57 | #define VE_MPEG_REC_CHROMA 0x14c 58 | #define VE_MPEG_FWD_LUMA 0x150 59 | #define VE_MPEG_FWD_CHROMA 0x154 60 | #define VE_MPEG_BACK_LUMA 0x158 61 | #define VE_MPEG_BACK_CHROMA 0x15c 62 | #define VE_MPEG_IQ_MIN_INPUT 0x180 63 | #define VE_MPEG_QP_INPUT 0x184 64 | 65 | #define VE_MPEG_ROT_LUMA 0x1cc 66 | #define VE_MPEG_ROT_CHROMA 0x1d0 67 | #define VE_MPEG_SDROT_CTRL 0x1d4 68 | 69 | #define VE_H264_FRAME_SIZE 0x200 70 | #define VE_H264_PIC_HDR 0x204 71 | #define VE_H264_SLICE_HDR 0x208 72 | #define VE_H264_SLICE_HDR2 0x20c 73 | #define VE_H264_PRED_WEIGHT 0x210 74 | #define VE_H264_QP_PARAM 0x21c 75 | #define VE_H264_CTRL 0x220 76 | #define VE_H264_TRIGGER 0x224 77 | #define VE_H264_STATUS 0x228 78 | #define VE_H264_CUR_MB_NUM 0x22c 79 | #define VE_H264_VLD_ADDR 0x230 80 | #define VE_H264_VLD_OFFSET 0x234 81 | #define VE_H264_VLD_LEN 0x238 82 | #define VE_H264_VLD_END 0x23c 83 | #define VE_H264_SDROT_CTRL 0x240 84 | #define VE_H264_SDROT_LUMA 0x244 85 | #define VE_H264_SDROT_CHROMA 0x248 86 | #define VE_H264_OUTPUT_FRAME_IDX 0x24c 87 | #define VE_H264_EXTRA_BUFFER1 0x250 88 | #define VE_H264_EXTRA_BUFFER2 0x254 89 | #define VE_H264_BASIC_BITS 0x2dc 90 | #define VE_H264_RAM_WRITE_PTR 0x2e0 91 | #define VE_H264_RAM_WRITE_DATA 0x2e4 92 | 93 | #define VE_SRAM_H264_PRED_WEIGHT_TABLE 0x000 94 | #define VE_SRAM_H264_FRAMEBUFFER_LIST 0x400 95 | #define VE_SRAM_H264_REF_LIST0 0x640 96 | #define VE_SRAM_H264_REF_LIST1 0x664 97 | #define VE_SRAM_H264_SCALING_LISTS 0x800 98 | 99 | #define VE_HEVC_NAL_HDR 0x500 100 | #define VE_HEVC_SPS 0x504 101 | #define VE_HEVC_PIC_SIZE 0x508 102 | #define VE_HEVC_PCM_HDR 0x50c 103 | #define VE_HEVC_PPS0 0x510 104 | #define VE_HEVC_PPS1 0x514 105 | #define VE_HEVC_SCALING_LIST_CTRL 0x518 106 | #define VE_HEVC_SLICE_HDR0 0x520 107 | #define VE_HEVC_SLICE_HDR1 0x524 108 | #define VE_HEVC_SLICE_HDR2 0x528 109 | #define VE_HEVC_CTB_ADDR 0x52c 110 | #define VE_HEVC_CTRL 0x530 111 | #define VE_HEVC_TRIG 0x534 112 | #define VE_HEVC_STATUS 0x538 113 | #define VE_HEVC_CTU_NUM 0x53c 114 | #define VE_HEVC_BITS_ADDR 0x540 115 | #define VE_HEVC_BITS_OFFSET 0x544 116 | #define VE_HEVC_BITS_LEN 0x548 117 | #define VE_HEVC_BITS_END_ADDR 0x54c 118 | #define VE_HEVC_REC_BUF_IDX 0x55c 119 | #define VE_HEVC_NEIGHBOR_INFO_ADDR 0x560 120 | #define VE_HEVC_TILE_LIST_ADDR 0x564 121 | #define VE_HEVC_TILE_START_CTB 0x568 122 | #define VE_HEVC_TILE_END_CTB 0x56c 123 | #define VE_HEVC_SCALING_LIST_DC_COEF0 0x578 124 | #define VE_HEVC_SCALING_LIST_DC_COEF1 0x57c 125 | #define VE_HEVC_BITS_DATA 0x5dc 126 | #define VE_HEVC_SRAM_ADDR 0x5e0 127 | #define VE_HEVC_SRAM_DATA 0x5e4 128 | 129 | #define VE_SRAM_HEVC_PRED_WEIGHT_LUMA_L0 0x000 130 | #define VE_SRAM_HEVC_PRED_WEIGHT_CHROMA_L0 0x020 131 | #define VE_SRAM_HEVC_PRED_WEIGHT_LUMA_L1 0x060 132 | #define VE_SRAM_HEVC_PRED_WEIGHT_CHROMA_L1 0x080 133 | #define VE_SRAM_HEVC_PIC_LIST 0x400 134 | #define VE_SRAM_HEVC_SCALING_LISTS 0x800 135 | #define VE_SRAM_HEVC_REF_PIC_LIST0 0xc00 136 | #define VE_SRAM_HEVC_REF_PIC_LIST1 0xc10 137 | 138 | #endif 139 | -------------------------------------------------------------------------------- /kernel-headers/README: -------------------------------------------------------------------------------- 1 | Various sunxi-specific kernel header files from sunxi kernel sources at 2 | https://github.com/linux-sunxi/linux-sunxi 3 | https://github.com/allwinner-zh/linux-3.4-sunxi 4 | -------------------------------------------------------------------------------- /kernel-headers/cedardev_api.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Cedarx framework. 3 | * Copyright (c) 2008-2015 Allwinner Technology Co. Ltd. 4 | * Copyright (c) 2014 BZ Chen 5 | * 6 | * This file is part of Cedarx. 7 | * 8 | * Cedarx is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 2.1 of the License, or (at your option) any later version. 12 | * 13 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any 14 | * kind, whether express or implied; without even the implied warranty 15 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | */ 18 | #ifndef __CEDARDEV_API_H__ 19 | #define __CEDARDEV_API_H__ 20 | 21 | enum IOCTL_CMD { 22 | IOCTL_UNKOWN = 0x100, 23 | IOCTL_GET_ENV_INFO, 24 | IOCTL_WAIT_VE_DE, //* changed from IOCTL_WAIT_VE to IOCTL_WAIT_VE_DE, it make code compliant. 25 | IOCTL_RESET_VE, 26 | IOCTL_ENABLE_VE, 27 | IOCTL_DISABLE_VE, 28 | IOCTL_SET_VE_FREQ, 29 | 30 | IOCTL_CONFIG_AVS2 = 0x200, 31 | IOCTL_GETVALUE_AVS2 , 32 | IOCTL_PAUSE_AVS2 , 33 | IOCTL_START_AVS2 , 34 | IOCTL_RESET_AVS2 , 35 | IOCTL_ADJUST_AVS2, 36 | IOCTL_ENGINE_REQ, 37 | IOCTL_ENGINE_REL, 38 | IOCTL_ENGINE_CHECK_DELAY, 39 | IOCTL_GET_IC_VER, 40 | IOCTL_ADJUST_AVS2_ABS, 41 | IOCTL_FLUSH_CACHE, 42 | IOCTL_SET_REFCOUNT, 43 | IOCTL_FLUSH_CACHE_ALL, 44 | IOCTL_TEST_VERSION, 45 | 46 | IOCTL_READ_REG = 0x300, 47 | IOCTL_WRITE_REG, 48 | }; 49 | 50 | #define IOCTL_WAIT_VE_EN IOCTL_WAIT_VE_DE //* decoder and encoder is together on 1651. 51 | 52 | struct cedarv_env_infomation 53 | { 54 | unsigned int phymem_start; 55 | int phymem_total_size; 56 | unsigned int address_macc; 57 | }; 58 | 59 | struct cedarv_cache_range 60 | { 61 | long start; 62 | long end; 63 | }; 64 | 65 | struct cedarv_regop 66 | { 67 | unsigned int addr; 68 | unsigned int value; 69 | }; 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /kernel-headers/ion.h: -------------------------------------------------------------------------------- 1 | /* 2 | * drivers/staging/android/uapi/ion.h 3 | * 4 | * Copyright (C) 2011 Google, Inc. 5 | * 6 | * This software is licensed under the terms of the GNU General Public 7 | * License version 2, as published by the Free Software Foundation, and 8 | * may be copied, distributed, and modified under those terms. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | */ 16 | 17 | #ifndef _UAPI_LINUX_ION_H 18 | #define _UAPI_LINUX_ION_H 19 | 20 | #include 21 | #include 22 | 23 | typedef int ion_user_handle_t; 24 | 25 | /** 26 | * enum ion_heap_types - list of all possible types of heaps 27 | * @ION_HEAP_TYPE_SYSTEM: memory allocated via vmalloc 28 | * @ION_HEAP_TYPE_SYSTEM_CONTIG: memory allocated via kmalloc 29 | * @ION_HEAP_TYPE_CARVEOUT: memory allocated from a prereserved 30 | * carveout heap, allocations are physically 31 | * contiguous 32 | * @ION_HEAP_TYPE_DMA: memory allocated via DMA API 33 | * @ION_NUM_HEAPS: helper for iterating over heaps, a bit mask 34 | * is used to identify the heaps, so only 32 35 | * total heap types are supported 36 | */ 37 | enum ion_heap_type { 38 | ION_HEAP_TYPE_SYSTEM, 39 | ION_HEAP_TYPE_SYSTEM_CONTIG, 40 | ION_HEAP_TYPE_CARVEOUT, 41 | ION_HEAP_TYPE_CHUNK, 42 | ION_HEAP_TYPE_DMA, 43 | ION_HEAP_TYPE_CUSTOM, /* must be last so device specific heaps always 44 | are at the end of this enum */ 45 | ION_NUM_HEAPS = 16, 46 | }; 47 | 48 | #define ION_HEAP_SYSTEM_MASK (1 << ION_HEAP_TYPE_SYSTEM) 49 | #define ION_HEAP_SYSTEM_CONTIG_MASK (1 << ION_HEAP_TYPE_SYSTEM_CONTIG) 50 | #define ION_HEAP_CARVEOUT_MASK (1 << ION_HEAP_TYPE_CARVEOUT) 51 | #define ION_HEAP_TYPE_DMA_MASK (1 << ION_HEAP_TYPE_DMA) 52 | 53 | #define ION_NUM_HEAP_IDS sizeof(unsigned int) * 8 54 | 55 | /** 56 | * allocation flags - the lower 16 bits are used by core ion, the upper 16 57 | * bits are reserved for use by the heaps themselves. 58 | */ 59 | #define ION_FLAG_CACHED 1 /* mappings of this buffer should be 60 | cached, ion will do cache 61 | maintenance when the buffer is 62 | mapped for dma */ 63 | #define ION_FLAG_CACHED_NEEDS_SYNC 2 /* mappings of this buffer will created 64 | at mmap time, if this is set 65 | caches must be managed manually */ 66 | 67 | /** 68 | * DOC: Ion Userspace API 69 | * 70 | * create a client by opening /dev/ion 71 | * most operations handled via following ioctls 72 | * 73 | */ 74 | 75 | /** 76 | * struct ion_allocation_data - metadata passed from userspace for allocations 77 | * @len: size of the allocation 78 | * @align: required alignment of the allocation 79 | * @heap_id_mask: mask of heap ids to allocate from 80 | * @flags: flags passed to heap 81 | * @handle: pointer that will be populated with a cookie to use to 82 | * refer to this allocation 83 | * 84 | * Provided by userspace as an argument to the ioctl 85 | */ 86 | struct ion_allocation_data { 87 | size_t len; 88 | size_t align; 89 | unsigned int heap_id_mask; 90 | unsigned int flags; 91 | ion_user_handle_t handle; 92 | }; 93 | 94 | /** 95 | * struct ion_fd_data - metadata passed to/from userspace for a handle/fd pair 96 | * @handle: a handle 97 | * @fd: a file descriptor representing that handle 98 | * 99 | * For ION_IOC_SHARE or ION_IOC_MAP userspace populates the handle field with 100 | * the handle returned from ion alloc, and the kernel returns the file 101 | * descriptor to share or map in the fd field. For ION_IOC_IMPORT, userspace 102 | * provides the file descriptor and the kernel returns the handle. 103 | */ 104 | struct ion_fd_data { 105 | ion_user_handle_t handle; 106 | int fd; 107 | }; 108 | 109 | /** 110 | * struct ion_handle_data - a handle passed to/from the kernel 111 | * @handle: a handle 112 | */ 113 | struct ion_handle_data { 114 | ion_user_handle_t handle; 115 | }; 116 | 117 | /** 118 | * struct ion_custom_data - metadata passed to/from userspace for a custom ioctl 119 | * @cmd: the custom ioctl function to call 120 | * @arg: additional data to pass to the custom ioctl, typically a user 121 | * pointer to a predefined structure 122 | * 123 | * This works just like the regular cmd and arg fields of an ioctl. 124 | */ 125 | struct ion_custom_data { 126 | unsigned int cmd; 127 | unsigned long arg; 128 | }; 129 | 130 | #define ION_IOC_MAGIC 'I' 131 | 132 | /** 133 | * DOC: ION_IOC_ALLOC - allocate memory 134 | * 135 | * Takes an ion_allocation_data struct and returns it with the handle field 136 | * populated with the opaque handle for the allocation. 137 | */ 138 | #define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \ 139 | struct ion_allocation_data) 140 | 141 | /** 142 | * DOC: ION_IOC_FREE - free memory 143 | * 144 | * Takes an ion_handle_data struct and frees the handle. 145 | */ 146 | #define ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data) 147 | 148 | /** 149 | * DOC: ION_IOC_MAP - get a file descriptor to mmap 150 | * 151 | * Takes an ion_fd_data struct with the handle field populated with a valid 152 | * opaque handle. Returns the struct with the fd field set to a file 153 | * descriptor open in the current address space. This file descriptor 154 | * can then be used as an argument to mmap. 155 | */ 156 | #define ION_IOC_MAP _IOWR(ION_IOC_MAGIC, 2, struct ion_fd_data) 157 | 158 | /** 159 | * DOC: ION_IOC_SHARE - creates a file descriptor to use to share an allocation 160 | * 161 | * Takes an ion_fd_data struct with the handle field populated with a valid 162 | * opaque handle. Returns the struct with the fd field set to a file 163 | * descriptor open in the current address space. This file descriptor 164 | * can then be passed to another process. The corresponding opaque handle can 165 | * be retrieved via ION_IOC_IMPORT. 166 | */ 167 | #define ION_IOC_SHARE _IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data) 168 | 169 | /** 170 | * DOC: ION_IOC_IMPORT - imports a shared file descriptor 171 | * 172 | * Takes an ion_fd_data struct with the fd field populated with a valid file 173 | * descriptor obtained from ION_IOC_SHARE and returns the struct with the handle 174 | * filed set to the corresponding opaque handle. 175 | */ 176 | #define ION_IOC_IMPORT _IOWR(ION_IOC_MAGIC, 5, struct ion_fd_data) 177 | 178 | /** 179 | * DOC: ION_IOC_SYNC - syncs a shared file descriptors to memory 180 | * 181 | * Deprecated in favor of using the dma_buf api's correctly (syncing 182 | * will happend automatically when the buffer is mapped to a device). 183 | * If necessary should be used after touching a cached buffer from the cpu, 184 | * this will make the buffer in memory coherent. 185 | */ 186 | #define ION_IOC_SYNC _IOWR(ION_IOC_MAGIC, 7, struct ion_fd_data) 187 | 188 | /** 189 | * DOC: ION_IOC_CUSTOM - call architecture specific ion ioctl 190 | * 191 | * Takes the argument of the architecture specific ioctl to call and 192 | * passes appropriate userdata for that ioctl 193 | */ 194 | #define ION_IOC_CUSTOM _IOWR(ION_IOC_MAGIC, 6, struct ion_custom_data) 195 | 196 | #endif /* _UAPI_LINUX_ION_H */ 197 | -------------------------------------------------------------------------------- /kernel-headers/ion_sunxi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * include/linux/ion_sunxi.h 3 | * 4 | * Copyright(c) 2013-2015 Allwinnertech Co., Ltd. 5 | * http://www.allwinnertech.com 6 | * 7 | * Author: liugang 8 | * 9 | * sunxi ion header file 10 | * 11 | * This program is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2 of the License, or 14 | * (at your option) any later version. 15 | */ 16 | 17 | #ifndef __ION_SUNXI_H 18 | #define __ION_SUNXI_H 19 | 20 | typedef struct { 21 | long start; 22 | long end; 23 | }sunxi_cache_range; 24 | 25 | typedef struct { 26 | ion_user_handle_t handle; 27 | unsigned int phys_addr; 28 | unsigned int size; 29 | }sunxi_phys_data; 30 | 31 | #define ION_IOC_SUNXI_FLUSH_RANGE 5 32 | #define ION_IOC_SUNXI_PHYS_ADDR 7 33 | 34 | 35 | 36 | 37 | #endif 38 | --------------------------------------------------------------------------------