rockchip: smccc: add more interfaces support

These interfaces are moved from kernel 4.4:
./drivers/firmware/rockchip_sip.c

Only those maybe used in U-Boot are moved.

Change-Id: I5896606c992056199f116692cca3c6d9530fd2f9
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
This commit is contained in:
Joseph Chen 2018-02-21 17:40:57 +08:00 committed by Kever Yang
parent eb2a5055ad
commit 5f048e57a3
2 changed files with 106 additions and 2 deletions

View File

@ -7,10 +7,65 @@
#ifndef __ROCKCHIP_SMCCC_H__
#define __ROCKCHIP_SMCCC_H__
/* Rockchip platform SiP call ID */
#define SIP_ATF_VERSION 0x82000001
#define SIP_ACCESS_REG 0x82000002
#define SIP_SUSPEND_MODE 0x82000003
#define SIP_PENDING_CPUS 0x82000004
#define SIP_UARTDBG_CFG 0x82000005
#define SIP_UARTDBG_CFG64 0xc2000005
#define SIP_MCU_EL3FIQ_CFG 0x82000006
#define SIP_ACCESS_CHIP_STATE64 0xc2000006
#define SIP_SECURE_MEM_CONFIG 0x82000007
#define SIP_ACCESS_CHIP_EXTRA_STATE64 0xc2000007
#define SIP_DRAM_CONFIG 0x82000008
#define SIP_SHARE_MEM 0x82000009
#define SIP_SIP_VERSION 0x8200000a
#define SIP_REMOTECTL_CFG 0x8200000b
#define PSCI_SIP_VPU_RESET 0x8200000c
/* Rockchip Sip version */
#define SIP_IMPLEMENT_V1 (1)
#define SIP_IMPLEMENT_V2 (2)
/* Error return code */
#define IS_SIP_ERROR(x) (!!(x))
#define SIP_RET_SUCCESS 0
#define SIP_RET_SMC_UNKNOWN -1
#define SIP_RET_NOT_SUPPORTED -2
#define SIP_RET_INVALID_PARAMS -3
#define SIP_RET_INVALID_ADDRESS -4
#define SIP_RET_DENIED -5
/* SIP_ACCESS_REG: read or write */
#define SECURE_REG_RD 0x0
#define SECURE_REG_WR 0x1
/* Share mem page types */
typedef enum {
SHARE_PAGE_TYPE_INVALID = 0,
SHARE_PAGE_TYPE_UARTDBG,
SHARE_PAGE_TYPE_DDR,
SHARE_PAGE_TYPE_MAX,
} share_page_type_t;
/* Stand PSCI system suspend */
int psci_system_suspend(unsigned long unused);
/* Rockchip SMC Calls */
int sip_smc_set_suspend_mode(unsigned long ctrl,
unsigned long config1,
unsigned long config2);
struct arm_smccc_res sip_smc_dram(unsigned long arg0,
unsigned long arg1,
unsigned long arg2);
struct arm_smccc_res sip_smc_request_share_mem(unsigned long page_num,
share_page_type_t page_type);
int sip_smc_set_sip_version(unsigned long version);
struct arm_smccc_res sip_smc_get_sip_version(void);
#endif

View File

@ -9,6 +9,7 @@
#include <asm/psci.h>
#include <asm/suspend.h>
#include <linux/arm-smccc.h>
#include <linux/io.h>
#ifdef CONFIG_ARM64
#define ARM_PSCI_1_0_SYSTEM_SUSPEND ARM_PSCI_1_0_FN64_SYSTEM_SUSPEND
@ -16,8 +17,7 @@
#define ARM_PSCI_1_0_SYSTEM_SUSPEND ARM_PSCI_1_0_FN_SYSTEM_SUSPEND
#endif
/* Rockchip platform SiP call ID */
#define SIP_SUSPEND_MODE 0x82000003
#define SIZE_PAGE(n) ((n) << 12)
static struct arm_smccc_res __invoke_sip_fn_smc(unsigned long function_id,
unsigned long arg0,
@ -48,3 +48,52 @@ int sip_smc_set_suspend_mode(unsigned long ctrl,
res = __invoke_sip_fn_smc(SIP_SUSPEND_MODE, ctrl, config1, config2);
return res.a0;
}
struct arm_smccc_res sip_smc_dram(unsigned long arg0,
unsigned long arg1,
unsigned long arg2)
{
return __invoke_sip_fn_smc(SIP_DRAM_CONFIG, arg0, arg1, arg2);
}
struct arm_smccc_res sip_smc_request_share_mem(unsigned long page_num,
share_page_type_t page_type)
{
struct arm_smccc_res res;
unsigned long share_mem_phy;
res = __invoke_sip_fn_smc(SIP_SHARE_MEM, page_num, page_type, 0);
if (IS_SIP_ERROR(res.a0))
goto error;
share_mem_phy = res.a1;
res.a1 = (unsigned long)ioremap(share_mem_phy, SIZE_PAGE(page_num));
error:
return res;
}
struct arm_smccc_res sip_smc_get_sip_version(void)
{
return __invoke_sip_fn_smc(SIP_SIP_VERSION, 0, 0, 0);
}
/*
* OP-TEE works both for kernel 3.10 and 4.4, and these two kernels have
* different sip implement that 3.10 uses SIP_IMPLEMENT_V1 and 4.4 uses
* SIP_IMPLEMENT_V2. So we should tell OP-TEE the current rockchip sip
* version(default SIP_IMPLEMENT_V1) before use.
*/
int sip_smc_set_sip_version(unsigned long version)
{
struct arm_smccc_res res;
res = __invoke_sip_fn_smc(SIP_SIP_VERSION, version, SECURE_REG_WR, 0);
if (IS_SIP_ERROR(res.a0)) {
printf("%s: set rockchip sip version v%ld failed\n",
__func__, version);
return res.a0;
}
return 0;
}