From: Ye Li Date: Wed, 17 Apr 2019 08:53:36 +0000 (-0700) Subject: MLK-21831-4 sci_api: Update SCFW API for ahab X-Git-Tag: rel_imx_4.19.35_1.1.0~748 X-Git-Url: https://git.somdevices.com/?a=commitdiff_plain;h=4d2c578bc56149d8f268c4854eba537f7e5b6527;p=u-boot.git MLK-21831-4 sci_api: Update SCFW API for ahab Add relevants SCFW APIs used in AHAB implementation Signed-off-by: Ye Li --- diff --git a/arch/arm/include/asm/arch-imx8/sci/sci.h b/arch/arm/include/asm/arch-imx8/sci/sci.h index 30f7bf8ac6..be058b8312 100644 --- a/arch/arm/include/asm/arch-imx8/sci/sci.h +++ b/arch/arm/include/asm/arch-imx8/sci/sci.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -89,6 +90,10 @@ int sc_misc_get_temp(sc_ipc_t ipc, sc_rsrc_t resource, sc_misc_temp_t temp, /* RM API */ sc_bool_t sc_rm_is_memreg_owned(sc_ipc_t ipc, sc_rm_mr_t mr); +int sc_rm_find_memreg(sc_ipc_t ipc, sc_rm_mr_t *mr, + sc_faddr_t addr_start, sc_faddr_t addr_end); +int sc_rm_set_memreg_permissions(sc_ipc_t ipc, sc_rm_mr_t mr, + sc_rm_pt_t pt, sc_rm_perm_t perm); int sc_rm_get_memreg_info(sc_ipc_t ipc, sc_rm_mr_t mr, sc_faddr_t *addr_start, sc_faddr_t *addr_end); sc_bool_t sc_rm_is_resource_owned(sc_ipc_t ipc, sc_rsrc_t resource); @@ -101,7 +106,14 @@ int sc_rm_set_master_sid(sc_ipc_t ipc, sc_rsrc_t resource, sc_rm_sid_t sid); /* SECO API */ +int sc_seco_authenticate(sc_ipc_t ipc, + sc_seco_auth_cmd_t cmd, sc_faddr_t addr); +int sc_seco_forward_lifecycle(sc_ipc_t ipc, uint32_t change); +int sc_seco_chip_info(sc_ipc_t ipc, uint16_t *lc, + uint16_t *monotonic, uint32_t *uid_l, uint32_t *uid_h); void sc_seco_build_info(sc_ipc_t ipc, uint32_t *version, uint32_t *commit); +int sc_seco_get_event(sc_ipc_t ipc, uint8_t idx, + uint32_t *event); #endif diff --git a/arch/arm/include/asm/arch-imx8/sci/svc/seco/api.h b/arch/arm/include/asm/arch-imx8/sci/svc/seco/api.h new file mode 100644 index 0000000000..6ad266fd93 --- /dev/null +++ b/arch/arm/include/asm/arch-imx8/sci/svc/seco/api.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2018 NXP + */ + +#ifndef SC_SECO_API_H +#define SC_SECO_API_H + +/* Includes */ + +#include + +/* Defines */ +#define SC_SECO_AUTH_CONTAINER 0U /* Authenticate container */ +#define SC_SECO_VERIFY_IMAGE 1U /* Verify image */ +#define SC_SECO_REL_CONTAINER 2U /* Release container */ +#define SC_SECO_AUTH_SECO_FW 3U /* SECO Firmware */ +#define SC_SECO_AUTH_HDMI_TX_FW 4U /* HDMI TX Firmware */ +#define SC_SECO_AUTH_HDMI_RX_FW 5U /* HDMI RX Firmware */ + +#define SC_SECO_RNG_STAT_UNAVAILABLE 0U /* Unable to initialize the RNG */ +#define SC_SECO_RNG_STAT_INPROGRESS 1U /* Initialization is on-going */ +#define SC_SECO_RNG_STAT_READY 2U /* Initialized */ + +/* Types */ + +/*! + * This type is used to issue SECO authenticate commands. + */ +typedef uint8_t sc_seco_auth_cmd_t; + +/*! + * This type is used to return the RNG initialization status. + */ +typedef uint32_t sc_seco_rng_stat_t; + +#endif /* SC_SECO_API_H */ diff --git a/drivers/misc/imx8/scu_api.c b/drivers/misc/imx8/scu_api.c index 1ce11c99df..ff59626ab8 100644 --- a/drivers/misc/imx8/scu_api.c +++ b/drivers/misc/imx8/scu_api.c @@ -389,6 +389,66 @@ sc_bool_t sc_rm_is_memreg_owned(sc_ipc_t ipc, sc_rm_mr_t mr) return (sc_bool_t)result; } +int sc_rm_find_memreg(sc_ipc_t ipc, sc_rm_mr_t *mr, + sc_faddr_t addr_start, sc_faddr_t addr_end) +{ + struct udevice *dev = gd->arch.scu_dev; + int size = sizeof(struct sc_rpc_msg_s); + struct sc_rpc_msg_s msg; + int ret; + + if (!dev) + hang(); + + RPC_VER(&msg) = SC_RPC_VERSION; + RPC_SVC(&msg) = (u8)(SC_RPC_SVC_RM); + RPC_FUNC(&msg) = (u8)(RM_FUNC_FIND_MEMREG); + RPC_U32(&msg, 0U) = (u32)(addr_start >> 32ULL); + RPC_U32(&msg, 4U) = (u32)(addr_start); + RPC_U32(&msg, 8U) = (u32)(addr_end >> 32ULL); + RPC_U32(&msg, 12U) = (u32)(addr_end); + RPC_SIZE(&msg) = 5U; + + ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size); + if (ret) + printf("%s: start:0x%llx, end:0x%llx res:%d\n", __func__, addr_start, addr_end, RPC_R8(&msg)); + + if (mr != NULL) + { + *mr = RPC_U8(&msg, 0U); + } + + return ret; +} + +int sc_rm_set_memreg_permissions(sc_ipc_t ipc, sc_rm_mr_t mr, + sc_rm_pt_t pt, sc_rm_perm_t perm) +{ + struct udevice *dev = gd->arch.scu_dev; + int size = sizeof(struct sc_rpc_msg_s); + struct sc_rpc_msg_s msg; + int ret; + + if (!dev) + hang(); + + + RPC_VER(&msg) = SC_RPC_VERSION; + RPC_SVC(&msg) = (u8)(SC_RPC_SVC_RM); + RPC_FUNC(&msg) = (u8)(RM_FUNC_SET_MEMREG_PERMISSIONS); + RPC_U8(&msg, 0U) = (u8)(mr); + RPC_U8(&msg, 1U) = (u8)(pt); + RPC_U8(&msg, 2U) = (u8)(perm); + RPC_SIZE(&msg) = 2U; + + ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size); + if (ret) + printf("%s: mr:%u, pt:%u, perm:%u, res:%d\n", __func__, + mr, pt, perm, RPC_R8(&msg)); + + return ret; +} + int sc_rm_get_memreg_info(sc_ipc_t ipc, sc_rm_mr_t mr, sc_faddr_t *addr_start, sc_faddr_t *addr_end) { @@ -526,6 +586,89 @@ int sc_pm_get_resource_power_mode(sc_ipc_t ipc, sc_rsrc_t resource, return ret; } +int sc_seco_authenticate(sc_ipc_t ipc, + sc_seco_auth_cmd_t cmd, sc_faddr_t addr) +{ + struct udevice *dev = gd->arch.scu_dev; + struct sc_rpc_msg_s msg; + int size = sizeof(struct sc_rpc_msg_s); + int ret; + + RPC_VER(&msg) = SC_RPC_VERSION; + RPC_SVC(&msg) = (u8)(SC_RPC_SVC_SECO); + RPC_FUNC(&msg) = (u8)(SECO_FUNC_AUTHENTICATE); + RPC_U32(&msg, 0U) = (u32)(addr >> 32ULL); + RPC_U32(&msg, 4U) = (u32)(addr); + RPC_U8(&msg, 8U) = (u8)(cmd); + RPC_SIZE(&msg) = 4U; + + ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size); + if (ret) + printf("%s: res:%d\n", __func__, RPC_R8(&msg)); + + return ret; +} + +int sc_seco_forward_lifecycle(sc_ipc_t ipc, uint32_t change) +{ + struct udevice *dev = gd->arch.scu_dev; + struct sc_rpc_msg_s msg; + int size = sizeof(struct sc_rpc_msg_s); + int ret; + + RPC_VER(&msg) = SC_RPC_VERSION; + RPC_SVC(&msg) = (u8)(SC_RPC_SVC_SECO); + RPC_FUNC(&msg) = (u8)(SECO_FUNC_FORWARD_LIFECYCLE); + RPC_U32(&msg, 0U) = (u32)(change); + RPC_SIZE(&msg) = 2U; + + ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size); + if (ret) + printf("%s: change:%u, res:%d\n", __func__, change, RPC_R8(&msg)); + + return ret; +} + +int sc_seco_chip_info(sc_ipc_t ipc, uint16_t *lc, + uint16_t *monotonic, uint32_t *uid_l, uint32_t *uid_h) +{ + struct udevice *dev = gd->arch.scu_dev; + struct sc_rpc_msg_s msg; + int size = sizeof(struct sc_rpc_msg_s); + int ret; + + RPC_VER(&msg) = SC_RPC_VERSION; + RPC_SVC(&msg) = (u8)(SC_RPC_SVC_SECO); + RPC_FUNC(&msg) = (u8)(SECO_FUNC_CHIP_INFO); + RPC_SIZE(&msg) = 1U; + + ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size); + if (ret) + printf("%s: res:%d\n", __func__, RPC_R8(&msg)); + + if (uid_l != NULL) + { + *uid_l = RPC_U32(&msg, 0U); + } + + if (uid_h != NULL) + { + *uid_h = RPC_U32(&msg, 4U); + } + + if (lc != NULL) + { + *lc = RPC_U16(&msg, 8U); + } + + if (monotonic != NULL) + { + *monotonic = RPC_U16(&msg, 10U); + } + + return ret; +} + void sc_seco_build_info(sc_ipc_t ipc, uint32_t *version, uint32_t *commit) { @@ -552,3 +695,29 @@ void sc_seco_build_info(sc_ipc_t ipc, uint32_t *version, return; } + +int sc_seco_get_event(sc_ipc_t ipc, uint8_t idx, + uint32_t *event) +{ + struct udevice *dev = gd->arch.scu_dev; + struct sc_rpc_msg_s msg; + int size = sizeof(struct sc_rpc_msg_s); + int ret; + + RPC_VER(&msg) = SC_RPC_VERSION; + RPC_SVC(&msg) = (u8)(SC_RPC_SVC_SECO); + RPC_FUNC(&msg) = (u8)(SECO_FUNC_GET_EVENT); + RPC_U8(&msg, 0U) = (u8)(idx); + RPC_SIZE(&msg) = 2U; + + ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size); + if (ret) + printf("%s: idx: %u, res:%d\n", __func__, idx, RPC_R8(&msg)); + + if (event != NULL) + { + *event = RPC_U32(&msg, 0U); + } + + return ret; +}