Skip to content

Commit

Permalink
Create util.h to rearrange define macro
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabrina Ni committed Aug 28, 2014
1 parent 4a429f5 commit a17acc4
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 33 deletions.
3 changes: 2 additions & 1 deletion core/arch/arm32/kernel/tee_ta_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include <tee_api_types.h>
#include <user_ta_header.h>
#include <kernel/util.h>
#include <kernel/tee_compat.h>
#include <tee/tee_svc.h>
#include <mm/tee_mmu.h>
Expand Down Expand Up @@ -500,7 +501,7 @@ static TEE_Result tee_ta_load_user_ta(struct tee_ta_ctx *ctx,
}

/* Ensure proper aligment of stack */
ctx->stack_size = TEE_ROUNDUP(sub_head->stack_size,
ctx->stack_size = ROUNDUP(sub_head->stack_size,
TEE_TA_STACK_ALIGNMENT);

*heap_size = sub_head->heap_size;
Expand Down
5 changes: 3 additions & 2 deletions core/arch/arm32/mm/tee_mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <assert.h>
#include <stdlib.h>

#include <kernel/util.h>
#include <kernel/tee_common.h>
#include <mm/tee_mmu.h>
#include <mm/tee_mmu_unpg.h>
Expand Down Expand Up @@ -676,8 +677,8 @@ TEE_Result tee_mmu_kmap_helper(tee_paddr_t pa, size_t len, void **va)
size_t n;
uint32_t *l1 = (uint32_t *)TEE_MMU_UL1_KERN_BASE;
uint32_t py_offset = (uint32_t) pa >> SECTION_SHIFT;
uint32_t pa_s = TEE_ROUNDDOWN(pa, SECTION_SIZE);
uint32_t pa_e = TEE_ROUNDUP(pa + len, SECTION_SIZE);
uint32_t pa_s = ROUNDDOWN(pa, SECTION_SIZE);
uint32_t pa_e = ROUNDUP(pa + len, SECTION_SIZE);
uint32_t flags;

mm = tee_mm_alloc(&tee_mmu_virt_kmap, pa_e - pa_s);
Expand Down
2 changes: 1 addition & 1 deletion core/arch/arm32/plat-cannes/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include <arm32.h>
#include <kernel/thread.h>
#include <kernel/panic.h>
#include <kernel/kernel.h>
#include <kernel/util.h>
#include <kernel/tee_core_trace.h>
#include <kernel/misc.h>
#include <mm/tee_pager_unpg.h>
Expand Down
2 changes: 1 addition & 1 deletion core/arch/arm32/plat-orly2/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include <arm32.h>
#include <kernel/thread.h>
#include <kernel/panic.h>
#include <kernel/kernel.h>
#include <kernel/util.h>
#include <kernel/tee_core_trace.h>
#include <kernel/misc.h>
#include <mm/tee_pager_unpg.h>
Expand Down
2 changes: 1 addition & 1 deletion core/arch/arm32/plat-vexpress/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include <sm/teesmc.h>
#include <sm/teesmc_st.h>

#include <kernel/kernel.h>
#include <kernel/util.h>
#include <kernel/arch_debug.h>

#include <arm32.h>
Expand Down
2 changes: 1 addition & 1 deletion core/arch/arm32/tee/arch_tee_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <kernel/tee_rpc_types.h>
#include <mm/core_mmu.h>
#include "tee_api_defines.h"
#include <kernel/tee_common_unpg.h>
#include <kernel/util.h>
#include <kernel/thread.h>
#include <sm/teesmc.h>

Expand Down
9 changes: 5 additions & 4 deletions core/arch/arm32/tee/tee_rpmb.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <stdlib.h>
#include <string.h>
#include <string_ext.h>
#include <kernel/util.h>
#include <kernel/tee_core_trace.h>
#include <tee_api_types.h>
#include <kernel/tee_common_otp.h>
Expand Down Expand Up @@ -327,8 +328,8 @@ static TEE_Result tee_rpmb_alloc(size_t req_size, size_t resp_size,
struct tee_rpmb_mem *mem, void **req, void **resp)
{
TEE_Result res = TEE_SUCCESS;
size_t req_s = TEE_ROUNDUP(req_size, sizeof(uint32_t));
size_t resp_s = TEE_ROUNDUP(resp_size, sizeof(uint32_t));
size_t req_s = ROUNDUP(req_size, sizeof(uint32_t));
size_t resp_s = ROUNDUP(resp_size, sizeof(uint32_t));

if (!mem)
return TEE_ERROR_BAD_PARAMETERS;
Expand Down Expand Up @@ -983,7 +984,7 @@ TEE_Result tee_rpmb_read(uint16_t dev_id,
byte_offset = addr % RPMB_DATA_SIZE;

blkcnt =
TEE_ROUNDUP(len + byte_offset, RPMB_DATA_SIZE) / RPMB_DATA_SIZE;
ROUNDUP(len + byte_offset, RPMB_DATA_SIZE) / RPMB_DATA_SIZE;

res = tee_rpmb_init(dev_id, false, true);
if (res != TEE_SUCCESS)
Expand Down Expand Up @@ -1166,7 +1167,7 @@ TEE_Result tee_rpmb_write(uint16_t dev_id,
byte_offset = addr % RPMB_DATA_SIZE;

blkcnt =
TEE_ROUNDUP(len + byte_offset, RPMB_DATA_SIZE) / RPMB_DATA_SIZE;
ROUNDUP(len + byte_offset, RPMB_DATA_SIZE) / RPMB_DATA_SIZE;

if (byte_offset == 0 && (len % RPMB_DATA_SIZE) == 0) {
res = tee_rpmb_write_blk(dev_id, blk_idx, data, blkcnt);
Expand Down
17 changes: 0 additions & 17 deletions core/include/kernel/tee_common_unpg.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,6 @@
#include <mm/tee_mm_def.h>
#include <kernel/tee_misc_unpg.h>

#ifndef MAX
#define MAX(a, b) \
(__extension__({ __typeof__(a) _a = (a); \
__typeof__(b) _b = (b); \
_a > _b ? _a : _b; }))

#define MIN(a, b) \
(__extension__({ __typeof__(a) _a = (a); \
__typeof__(b) _b = (b); \
_a < _b ? _a : _b; }))
#endif

#define TEE_MEMBER_SIZE(type, member) sizeof(((type *)0)->member)

#define TEE_ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
Expand All @@ -60,11 +48,6 @@ typedef uintptr_t tee_vaddr_t;
/* Virtual address valid in user mode */
typedef uintptr_t tee_uaddr_t;

/* Round up the even multiple of size, size has to be a multiple of 2 */
#define TEE_ROUNDUP(v, size) (((v) + (size - 1)) & ~(size - 1))

/* Round down the even multiple of size, size has to be a multiple of 2 */
#define TEE_ROUNDDOWN(v, size) ((v) & ~(size - 1))

#if (CFG_TEE_FW_DEBUG == 0)

Expand Down
18 changes: 15 additions & 3 deletions core/include/kernel/kernel.h → core/include/kernel/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,20 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef KERNEL_KERNEL_H
#define KERNEL_KERNEL_H
#ifndef KERNEL_UTIL_H
#define KERNEL_UTIL_H

#ifndef MAX
#define MAX(a, b) \
(__extension__({ __typeof__(a) _a = (a); \
__typeof__(b) _b = (b); \
_a > _b ? _a : _b; }))

#define MIN(a, b) \
(__extension__({ __typeof__(a) _a = (a); \
__typeof__(b) _b = (b); \
_a < _b ? _a : _b; }))
#endif

#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))

Expand All @@ -35,4 +47,4 @@
/* Round down the even multiple of size, size has to be a multiple of 2 */
#define ROUNDDOWN(v, size) ((v) & ~(size - 1))

#endif /*KERNEL_KERNEL_H*/
#endif /*KERNEL_UTIL_H*/
1 change: 1 addition & 0 deletions core/kernel/tee_ta_manager_unpg.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <string.h>
#include <user_ta_header.h>
#include <kernel/util.h>
#include <kernel/tee_ta_manager_unpg.h>
#include <tee/tee_hash.h>
#include <kernel/tee_core_trace.h>
Expand Down
5 changes: 3 additions & 2 deletions core/tee/tee_svc.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <kernel/util.h>
#include <kernel/tee_common_otp.h>
#include <kernel/tee_common.h>
#include <kernel/tee_compat.h>
Expand Down Expand Up @@ -286,7 +287,7 @@ static TEE_Result tee_svc_copy_param(struct tee_ta_session *sess,
(uintptr_t)param->params[n].memref.buffer,
param->params[n].memref.size)) {

s = TEE_ROUNDUP(param->params[n].memref.size,
s = ROUNDUP(param->params[n].memref.size,
sizeof(uint32_t));
/* Check overflow */
if (req_mem + s < req_mem)
Expand Down Expand Up @@ -338,7 +339,7 @@ static TEE_Result tee_svc_copy_param(struct tee_ta_session *sess,
if (ta_private_memref[n] == false)
continue;

s = TEE_ROUNDUP(param->params[n].memref.size, sizeof(uint32_t));
s = ROUNDUP(param->params[n].memref.size, sizeof(uint32_t));

switch (TEE_PARAM_TYPE_GET(param->types, n)) {
case TEE_PARAM_TYPE_MEMREF_INPUT:
Expand Down

0 comments on commit a17acc4

Please sign in to comment.