-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core: add support for (de)registering remote shmem
This patch utilizes new shared memory subsystem. Now we can: - map commands buffers that were not allocated in shm carveout - map data buffers allocated thru RPC - register and map data buffers provided by clients Signed-off-by: Volodymyr Babchuk <vlad.babchuk@gmail.com>
- Loading branch information
Showing
11 changed files
with
569 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
/* | ||
* Copyright (c) 2016, EPAM Systems | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include <kernel/misc.h> | ||
#include <kernel/panic.h> | ||
#include <mm/core_memprot.h> | ||
#include <mm/shmem.h> | ||
#include <optee_msg.h> | ||
#include <sm/optee_smc.h> | ||
#include <sm/sm.h> | ||
#include <trace.h> | ||
#include <util.h> | ||
|
||
/** | ||
* extract_pages_from_params() - extract list of pages from | ||
* OPTEE_MSG_ATTR_FRAGMENT parameters | ||
* | ||
* @params: pointer to parameters array | ||
* @pages: output array of page addresses | ||
* @num_params: number of parameters in array | ||
* | ||
* return: | ||
* page count on success | ||
* <0 on error | ||
*/ | ||
int extract_pages_from_params(struct optee_msg_param *params, paddr_t *pages, | ||
uint32_t num_params) | ||
{ | ||
uint32_t pages_cnt = 0; | ||
|
||
if (params[num_params-1].attr & OPTEE_MSG_ATTR_FRAGMENT) | ||
return -1; | ||
|
||
for (uint32_t i = 0; i < num_params; i++) { | ||
uint32_t attr = params[i].attr & OPTEE_MSG_ATTR_TYPE_MASK; | ||
|
||
switch (attr) { | ||
case OPTEE_MSG_ATTR_TYPE_NEXT_FRAGMENT: | ||
continue; | ||
case OPTEE_MSG_ATTR_TYPE_TMEM_INPUT: | ||
case OPTEE_MSG_ATTR_TYPE_TMEM_OUTPUT: | ||
if (pages_cnt >= num_params) | ||
return -1; | ||
if (!(params[i].attr & OPTEE_MSG_ATTR_FRAGMENT) && | ||
(i != num_params - 1)) | ||
return -1; | ||
pages[pages_cnt++] = params[i].u.tmem.buf_ptr | ||
& ~SMALL_PAGE_MASK; | ||
break; | ||
default: | ||
return -1; | ||
} | ||
} | ||
return pages_cnt; | ||
} | ||
|
||
/** | ||
* map_params_buffer() - map parameters buffer into OP-TEE VA space | ||
* @pa_params - physical pointer to parameters | ||
* @num_params - number of parameters | ||
* @map_offset - offset that should be deducted before mapping buffer | ||
* | ||
* return: | ||
* struct shmem_mapping of mapped buffer on success | ||
* NULL on error. | ||
*/ | ||
struct shmem_mapping *map_params_buffer(paddr_t pa_params, uint32_t num_params, | ||
paddr_t map_offset) | ||
{ | ||
struct shmem_mapping *shm_mapping = NULL; | ||
struct optee_msg_param *params; | ||
paddr_t *pages = NULL; | ||
uint32_t max_pages, pages_cnt; | ||
size_t args_size; | ||
|
||
if (shmem_map_page(pa_params, &shm_mapping)) | ||
return NULL; | ||
|
||
args_size = OPTEE_MSG_GET_ARG_SIZE(num_params); | ||
max_pages = args_size/SMALL_PAGE_SIZE + 1; | ||
pages = calloc(max_pages, sizeof(paddr_t)); | ||
if (!pages) | ||
goto err; | ||
|
||
params = (struct optee_msg_param *) shmem_pa2va(pa_params); | ||
pages[0] = pa_params & ~SMALL_PAGE_MASK; | ||
pages_cnt = 1; | ||
for (uint32_t i = 0; i < num_params; i++) { | ||
if ((params->attr & OPTEE_MSG_ATTR_TYPE_MASK) == | ||
OPTEE_MSG_ATTR_TYPE_NEXT_FRAGMENT) { | ||
if (pages_cnt >= max_pages) | ||
goto err; | ||
pages[pages_cnt] = params->u.tmem.buf_ptr; | ||
shmem_unmap_buffer(shm_mapping); | ||
shm_mapping = NULL; | ||
|
||
if (shmem_map_page(pages[pages_cnt], &shm_mapping)) | ||
goto err; | ||
|
||
pages_cnt++; | ||
params = (struct optee_msg_param *) | ||
shmem_get_va(shm_mapping); | ||
} else { | ||
params++; | ||
if (((vaddr_t)params & SMALL_PAGE_MASK) == 0) | ||
goto err; | ||
} | ||
} | ||
|
||
shmem_unmap_buffer(shm_mapping); | ||
shm_mapping = NULL; | ||
|
||
if (shmem_map_buffer(pa_params - map_offset, args_size, | ||
pages, pages_cnt, &shm_mapping)) | ||
goto err; | ||
|
||
goto out; | ||
err: | ||
if (shm_mapping) | ||
shmem_unmap_buffer(shm_mapping); | ||
shm_mapping = NULL; | ||
out: | ||
if (pages) | ||
free(pages); | ||
return shm_mapping; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.