/*
 *
 * Copyright (C) 2012-2019, Samsung Electronics Co., Ltd.
 *
 * Common helper functions
 */

#include <errno.h>
#include <stdlib.h>
#include <tee_internal_api.h>

#include "bsp_common.h"

void udelay(int timeout)
{
    volatile int t = timeout*500;
    while(t) { --t; }
}

void mdelay(int timeout)
{
    volatile int t = timeout*1000;
    while(t) {
        udelay(1);
        --t;
    }
}

int copy_from_user(void *dest, void *src, unsigned int size)
{
    if (!dest || !src || !size) {
        return -EINVAL;
    }

    if (*(uint32_t *)src == size) {
        TEE_MemMove(dest, src, size);
    } else {
        return -EINVAL;
    }

    return 0;
}

int copy_to_user(void *dest, void *src, unsigned int size)
{
    if (!dest || !src || !size) {
        return -EINVAL;
    }

    if (*(uint32_t *)dest == size) {
        TEE_MemMove(dest, src, size);
    } else {
        return -EINVAL;
    }

    return 0;
}
