2 * Copyright (c) 2015, Linaro Limited
3 * Copyright (c) 2017, EPAM Systems
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
9 * This program 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
12 * GNU General Public License for more details.
15 #include <linux/device.h>
16 #include <linux/dma-buf.h>
17 #include <linux/genalloc.h>
18 #include <linux/slab.h>
19 #include <linux/tee_drv.h>
20 #include "optee_private.h"
21 #include "optee_smc.h"
24 static int pool_op_alloc(struct tee_shm_pool_mgr *poolm,
25 struct tee_shm *shm, size_t size)
27 unsigned int order = get_order(size);
30 page = alloc_pages(GFP_KERNEL | __GFP_ZERO, order);
34 shm->kaddr = page_address(page);
35 shm->paddr = page_to_phys(page);
36 shm->size = PAGE_SIZE << order;
41 static void pool_op_free(struct tee_shm_pool_mgr *poolm,
44 free_pages((unsigned long)shm->kaddr, get_order(shm->size));
48 static void pool_op_destroy_poolmgr(struct tee_shm_pool_mgr *poolm)
53 static const struct tee_shm_pool_mgr_ops pool_ops = {
54 .alloc = pool_op_alloc,
56 .destroy_poolmgr = pool_op_destroy_poolmgr,
60 * optee_shm_pool_alloc_pages() - create page-based allocator pool
62 * This pool is used when OP-TEE supports dymanic SHM. In this case
63 * command buffers and such are allocated from kernel's own memory.
65 struct tee_shm_pool_mgr *optee_shm_pool_alloc_pages(void)
67 struct tee_shm_pool_mgr *mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
70 return ERR_PTR(-ENOMEM);