Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove core dependencies from generic part #11

Merged
1 commit merged into from
Aug 13, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/arch/arm32/include/kernel/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#ifndef KERNEL_THREAD_H
#define KERNEL_THREAD_H

#include <sys/types.h>
#include <types_ext.h>

#define THREAD_ID_0 0
#define THREAD_ABT_STACK 0xfffffffe
Expand Down
2 changes: 1 addition & 1 deletion core/arch/arm32/include/sm/sm.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#ifndef SM_SM_H
#define SM_SM_H

#include <sys/types.h>
#include <types_ext.h>

struct sm_nsec_ctx {
uint32_t usr_sp;
Expand Down
2 changes: 1 addition & 1 deletion core/arch/arm32/kernel/tee_ta_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/

#include <sys/types.h>
#include <types_ext.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
Expand Down
62 changes: 62 additions & 0 deletions core/arch/arm32/kernel/tee_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
#include <utee_defines.h>
#include <kernel/tee_time_unpg.h>
#include <kernel/tee_core_trace.h>
#include <kernel/thread.h>
#include <sm/teesmc.h>
#include <kernel/tee_rpc.h>
#include <mm/core_mmu.h>

#define TEE_TIME_SHIFT 5

Expand Down Expand Up @@ -192,3 +196,61 @@ void tee_wait_specific(uint32_t milliseconds_delay)
/* usleep to be implemented */
/* usleep(milliseconds_delay * 1000); */
}

/*
* tee_time_get_ree_time(): this function implements the GP Internal API
* function TEE_GetREETime()
* Goal is to get the time of the Rich Execution Environment
* This is why this time is provided through the supplicant
*/
TEE_Result tee_time_get_ree_time(TEE_Time *time)
{
TEE_Result res = TEE_ERROR_BAD_PARAMETERS;
struct teesmc32_arg *arg;
struct teesmc32_param *params;
paddr_t pharg = 0;
paddr_t phpayload = 0;
paddr_t cookie = 0;
TEE_Time *payload;

if (!time)
goto exit;

pharg = thread_rpc_alloc_arg(TEESMC32_GET_ARG_SIZE(1));
if (!pharg)
goto exit;
thread_st_rpc_alloc_payload(sizeof(TEE_Time), &phpayload, &cookie);
if (!phpayload)
goto exit;

if (!TEE_ALIGNMENT_IS_OK(pharg, struct teesmc32_arg) ||
!TEE_ALIGNMENT_IS_OK(phpayload, TEE_Time))
goto exit;

if (core_pa2va(pharg, (uint32_t *)&arg) ||
core_pa2va(phpayload, (uint32_t *)&payload))
goto exit;

arg->cmd = TEE_RPC_GET_TIME;
arg->ret = TEE_ERROR_GENERIC;
arg->num_params = 1;
params = TEESMC32_GET_PARAMS(arg);
params[0].attr = TEESMC_ATTR_TYPE_MEMREF_OUTPUT |
(TEESMC_ATTR_CACHE_I_WRITE_THR |
TEESMC_ATTR_CACHE_O_WRITE_THR) <<
TEESMC_ATTR_CACHE_SHIFT;
params[0].u.memref.buf_ptr = phpayload;
params[0].u.memref.size = sizeof(TEE_Time);

thread_rpc_cmd(pharg);
res = arg->ret;
if (res != TEE_SUCCESS)
goto exit;

*time = *payload;

exit:
thread_rpc_free_arg(pharg);
thread_st_rpc_free_payload(cookie);
return res;
}
102 changes: 102 additions & 0 deletions core/arch/arm32/tee/arch_tee_fs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright (c) 2014, STMicroelectronics International N.V.
* 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 <stdlib.h>
#include <string.h>
#include <tee/tee_fs.h>
#include <tee/tee_fs_defs.h>
#include <kernel/tee_rpc.h>
#include <kernel/tee_rpc_types.h>
#include <mm/core_mmu.h>
#include "tee_api_defines.h"
#include <kernel/tee_common_unpg.h>
#include <kernel/thread.h>
#include <sm/teesmc.h>

int tee_fs_send_cmd(struct tee_fs_rpc *bf_cmd, void *data, uint32_t len,
uint32_t mode)
{
struct teesmc32_arg *arg;
struct teesmc32_param *params;
const size_t num_params = 1;
paddr_t pharg = 0;
paddr_t phpayload = 0;
paddr_t cookie = 0;
struct tee_fs_rpc *bf;
int res = -1;

pharg = thread_rpc_alloc_arg(TEESMC32_GET_ARG_SIZE(num_params));
thread_st_rpc_alloc_payload(sizeof(struct tee_fs_rpc) + len,
&phpayload, &cookie);
if (!pharg || !phpayload)
goto exit;

if (!TEE_ALIGNMENT_IS_OK(pharg, struct teesmc32_arg) ||
!TEE_ALIGNMENT_IS_OK(phpayload, struct tee_fs_rpc))
goto exit;

if (core_pa2va(pharg, (uint32_t *)&arg) ||
core_pa2va(phpayload, (uint32_t *)&bf))
goto exit;

arg->cmd = TEE_RPC_FS;
arg->ret = TEE_ERROR_GENERIC;
arg->num_params = num_params;
params = TEESMC32_GET_PARAMS(arg);
params[0].attr = TEESMC_ATTR_TYPE_MEMREF_INOUT |
(TEESMC_ATTR_CACHE_I_WRITE_THR |
TEESMC_ATTR_CACHE_O_WRITE_THR) <<
TEESMC_ATTR_CACHE_SHIFT;

params[0].u.memref.buf_ptr = phpayload;
params[0].u.memref.size = sizeof(struct tee_fs_rpc) + len;

/* fill in parameters */
*bf = *bf_cmd;

if (mode & TEE_FS_MODE_IN)
memcpy((void *)(bf + 1), data, len);

thread_rpc_cmd(pharg);
/* update result */
*bf_cmd = *bf;
if (arg->ret != TEE_SUCCESS)
goto exit;

if (mode & TEE_FS_MODE_OUT) {
uint32_t olen = MIN(len, bf->len);

memcpy(data, (void *)(bf + 1), olen);
}

res = 0;

exit:
thread_rpc_free_arg(pharg);
thread_st_rpc_free_payload(cookie);
return res;
}
3 changes: 3 additions & 0 deletions core/arch/arm32/tee/sub.mk
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
srcs-y += arch_tee_fs.c
srcs-y += tee_rpmb.c
cflags-tee_rpmb.c-y += -Wno-unused-parameter
srcs-y += tee_svc_asm.S
srcs-y += entry.c
srcs-y += init.c
Expand Down
2 changes: 1 addition & 1 deletion core/tee/tee_rpmb.c → core/arch/arm32/tee/tee_rpmb.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/types.h>
#include <types_ext.h>
#include <stdlib.h>
#include <string.h>
#include <string_ext.h>
Expand Down
2 changes: 1 addition & 1 deletion core/include/drivers/gic.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#ifndef GIC_H
#define GIC_H
#include <sys/types.h>
#include <types_ext.h>

void gic_init(paddr_t gicc_base, paddr_t gicd_base);

Expand Down
2 changes: 1 addition & 1 deletion core/include/drivers/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#ifndef UART_H
#define UART_H

#include <sys/types.h>
#include <types_ext.h>

void uart_init(vaddr_t base);

Expand Down
2 changes: 1 addition & 1 deletion core/include/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#define IO_H

#include <stdint.h>
#include <sys/types.h>
#include <types_ext.h>

/*
* IO access macro, please avoid using this macro, since it's going to be
Expand Down
2 changes: 1 addition & 1 deletion core/include/kernel/tee_ta_manager_unpg.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#ifndef TEE_TA_MANAGER_UNPG_H
#define TEE_TA_MANAGER_UNPG_H

#include <sys/types.h>
#include <types_ext.h>
#include <kernel/tee_common_unpg.h>

#include <kernel/tee_ta.h>
Expand Down
11 changes: 11 additions & 0 deletions core/include/tee/tee_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,15 @@ int tee_fs_rmdir(const char *pathname);

int tee_fs_access(const char *name, int mode);

struct tee_fs_rpc {
int op;
int flags;
int arg;
int fd;
uint32_t len;
int res;
};
int tee_fs_send_cmd(struct tee_fs_rpc *bf_cmd, void *data, uint32_t len,
uint32_t mode);

#endif
4 changes: 4 additions & 0 deletions core/include/tee/tee_fs_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,8 @@
#define TEE_FS_W_OK 0x2
#define TEE_FS_F_OK 0x4

#define TEE_FS_MODE_NONE 0
#define TEE_FS_MODE_IN 1
#define TEE_FS_MODE_OUT 2

#endif
3 changes: 0 additions & 3 deletions core/tee/sub.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ cflags-tee_authenc.c-y += -Wno-unused-parameter
srcs-y += tee_mac.c
cflags-tee_mac.c-y += -Wno-unused-parameter

srcs-y += tee_rpmb.c
cflags-tee_rpmb.c-y += -Wno-unused-parameter

srcs-y += tee_cipher.c
srcs-y += tee_fs.c
srcs-y += tee_hash.c
Expand Down
Loading