/*
 * Copyright (c) 2014 - 2016 MediaTek Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files
 * (the "Software"), to deal in the Software without restriction,
 * including without limitation the rights to use, copy, modify, merge,
 * publish, distribute, sublicense, and/or sell copies of the Software,
 * and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#ifndef __H__MTK_GENERIC__
#define __H__MTK_GENERIC__

#include <stdio.h>
#include <tee_internal_api.h>
#include <unistd.h>
#include "base.h"
#include "mt_typedefs.h"
#include "bsp_common.h"

/**
 * buffer_map_to_va -map physical addr to virtual addr
 * phyaddr - physical address
 * size - physical buffer size
 * va - output virtual buffer address
 *
 * return 0 success, return -1 on failure.
 */
int buffer_map_to_va(uint32_t phyaddr, size_t size, void **va);

/**
 * buffer_unmap -unmap physical buffer
 * va - virtual buffer address
 * size - virtual buffer size
 *
 * return 0 success, return -1 on failure.
 */
int buffer_unmap(void *va, size_t size);


/**
 * irq_attach -register irq
 * intrNo - irq number
 *
 * return 0 success, return -1 on failure.
 */
int irq_attach(int intrNo,int mode);

/**
 * irq_detach -unregister irq
 * intrNo - irq number
 *
 * return 0 success, return -1 on failure.
 */
int irq_detach(int intrNo);

/**
 * irq_wait -wait hardware interupt
 * intrNo - irq number
 * timeoutMs - time for timeout in ms, -1 will be wait forever
 * pIntrRet - set to unll
 *
 * return 0 success, return -1 on failure.
 */
int irq_wait(int  intrNo, int  timeoutMs, int *pIntrRet);

/**
 * irq_trigger -softerware trigger irq
 * intrNo - irq number
 *
 * return 0 success, return -1 on failure.
 */
int irq_trigger(int intrNo);

#endif
