mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-17 09:14:19 +08:00
9c92ab6191
Based on 1 normalized pattern(s): 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 extracted by the scancode license scanner the SPDX license identifier GPL-2.0-only has been chosen to replace the boilerplate/reference in 285 file(s). Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Alexios Zavras <alexios.zavras@intel.com> Reviewed-by: Allison Randal <allison@lohutok.net> Cc: linux-spdx@vger.kernel.org Link: https://lkml.kernel.org/r/20190529141900.642774971@linutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
67 lines
1.5 KiB
C
67 lines
1.5 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Copyright (c) 2015, Linaro Limited
|
|
* Copyright (c) 2017, EPAM Systems
|
|
*/
|
|
#include <linux/device.h>
|
|
#include <linux/dma-buf.h>
|
|
#include <linux/genalloc.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/tee_drv.h>
|
|
#include "optee_private.h"
|
|
#include "optee_smc.h"
|
|
#include "shm_pool.h"
|
|
|
|
static int pool_op_alloc(struct tee_shm_pool_mgr *poolm,
|
|
struct tee_shm *shm, size_t size)
|
|
{
|
|
unsigned int order = get_order(size);
|
|
struct page *page;
|
|
|
|
page = alloc_pages(GFP_KERNEL | __GFP_ZERO, order);
|
|
if (!page)
|
|
return -ENOMEM;
|
|
|
|
shm->kaddr = page_address(page);
|
|
shm->paddr = page_to_phys(page);
|
|
shm->size = PAGE_SIZE << order;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void pool_op_free(struct tee_shm_pool_mgr *poolm,
|
|
struct tee_shm *shm)
|
|
{
|
|
free_pages((unsigned long)shm->kaddr, get_order(shm->size));
|
|
shm->kaddr = NULL;
|
|
}
|
|
|
|
static void pool_op_destroy_poolmgr(struct tee_shm_pool_mgr *poolm)
|
|
{
|
|
kfree(poolm);
|
|
}
|
|
|
|
static const struct tee_shm_pool_mgr_ops pool_ops = {
|
|
.alloc = pool_op_alloc,
|
|
.free = pool_op_free,
|
|
.destroy_poolmgr = pool_op_destroy_poolmgr,
|
|
};
|
|
|
|
/**
|
|
* optee_shm_pool_alloc_pages() - create page-based allocator pool
|
|
*
|
|
* This pool is used when OP-TEE supports dymanic SHM. In this case
|
|
* command buffers and such are allocated from kernel's own memory.
|
|
*/
|
|
struct tee_shm_pool_mgr *optee_shm_pool_alloc_pages(void)
|
|
{
|
|
struct tee_shm_pool_mgr *mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
|
|
|
|
if (!mgr)
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
mgr->ops = &pool_ops;
|
|
|
|
return mgr;
|
|
}
|