123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506 |
- /*
- * Copyright (C) 2016 Freescale Semiconductor, Inc.
- * Copyright 2017-2018 NXP
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
- /*!
- * File containing client-side RPC functions for the MISC service. These
- * functions are ported to clients that communicate to the SC.
- *
- * @addtogroup MISC_SVC
- * @{
- */
- /* Includes */
- #include <sci/sci_types.h>
- #include <sci/svc/rm/sci_rm_api.h>
- #include <sci/svc/misc/sci_misc_api.h>
- #include <sci/sci_rpc.h>
- #include <stdlib.h>
- #include "sci_misc_rpc.h"
- /* Local Defines */
- /* Local Types */
- /* Local Functions */
- sc_err_t sc_misc_set_control(sc_ipc_t ipc, sc_rsrc_t resource,
- sc_ctrl_t ctrl, uint32_t val)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
- RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_SET_CONTROL;
- RPC_U32(&msg, 0U) = (uint32_t)ctrl;
- RPC_U32(&msg, 4U) = (uint32_t)val;
- RPC_U16(&msg, 8U) = (uint16_t)resource;
- RPC_SIZE(&msg) = 4U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- sc_err_t sc_misc_get_control(sc_ipc_t ipc, sc_rsrc_t resource,
- sc_ctrl_t ctrl, uint32_t *val)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
- RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_GET_CONTROL;
- RPC_U32(&msg, 0U) = (uint32_t)ctrl;
- RPC_U16(&msg, 4U) = (uint16_t)resource;
- RPC_SIZE(&msg) = 3U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- if (val != NULL)
- *val = RPC_U32(&msg, 0U);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- sc_err_t sc_misc_set_max_dma_group(sc_ipc_t ipc, sc_rm_pt_t pt,
- sc_misc_dma_group_t max)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
- RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_SET_MAX_DMA_GROUP;
- RPC_U8(&msg, 0U) = (uint8_t)pt;
- RPC_U8(&msg, 1U) = (uint8_t)max;
- RPC_SIZE(&msg) = 2U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- sc_err_t sc_misc_set_dma_group(sc_ipc_t ipc, sc_rsrc_t resource,
- sc_misc_dma_group_t group)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
- RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_SET_DMA_GROUP;
- RPC_U16(&msg, 0U) = (uint16_t)resource;
- RPC_U8(&msg, 2U) = (uint8_t)group;
- RPC_SIZE(&msg) = 2U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- sc_err_t sc_misc_seco_image_load(sc_ipc_t ipc, sc_faddr_t addr_src,
- sc_faddr_t addr_dst, uint32_t len,
- sc_bool_t fw)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
- RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_SECO_IMAGE_LOAD;
- RPC_U32(&msg, 0U) = (uint32_t)(addr_src >> 32U);
- RPC_U32(&msg, 4U) = (uint32_t)addr_src;
- RPC_U32(&msg, 8U) = (uint32_t)(addr_dst >> 32U);
- RPC_U32(&msg, 12U) = (uint32_t)addr_dst;
- RPC_U32(&msg, 16U) = (uint32_t)len;
- RPC_U8(&msg, 20U) = (uint8_t)fw;
- RPC_SIZE(&msg) = 7U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- sc_err_t sc_misc_seco_authenticate(sc_ipc_t ipc,
- sc_misc_seco_auth_cmd_t cmd, sc_faddr_t addr)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
- RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_SECO_AUTHENTICATE;
- RPC_U32(&msg, 0U) = (uint32_t)(addr >> 32U);
- RPC_U32(&msg, 4U) = (uint32_t)addr;
- RPC_U8(&msg, 8U) = (uint8_t)cmd;
- RPC_SIZE(&msg) = 4U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- sc_err_t sc_misc_seco_fuse_write(sc_ipc_t ipc, sc_faddr_t addr)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
- RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_SECO_FUSE_WRITE;
- RPC_U32(&msg, 0U) = (uint32_t)(addr >> 32U);
- RPC_U32(&msg, 4U) = (uint32_t)addr;
- RPC_SIZE(&msg) = 3U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- sc_err_t sc_misc_seco_enable_debug(sc_ipc_t ipc, sc_faddr_t addr)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
- RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_SECO_ENABLE_DEBUG;
- RPC_U32(&msg, 0U) = (uint32_t)(addr >> 32U);
- RPC_U32(&msg, 4U) = (uint32_t)addr;
- RPC_SIZE(&msg) = 3U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- sc_err_t sc_misc_seco_forward_lifecycle(sc_ipc_t ipc, uint32_t lifecycle)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
- RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_SECO_FORWARD_LIFECYCLE;
- RPC_U32(&msg, 0U) = (uint32_t)lifecycle;
- RPC_SIZE(&msg) = 2U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- sc_err_t sc_misc_seco_return_lifecycle(sc_ipc_t ipc, sc_faddr_t addr)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
- RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_SECO_RETURN_LIFECYCLE;
- RPC_U32(&msg, 0U) = (uint32_t)(addr >> 32U);
- RPC_U32(&msg, 4U) = (uint32_t)addr;
- RPC_SIZE(&msg) = 3U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- void sc_misc_seco_build_info(sc_ipc_t ipc, uint32_t *version, uint32_t *commit)
- {
- sc_rpc_msg_t msg;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
- RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_SECO_BUILD_INFO;
- RPC_SIZE(&msg) = 1U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- if (version != NULL)
- *version = RPC_U32(&msg, 0U);
- if (commit != NULL)
- *commit = RPC_U32(&msg, 4U);
- }
- sc_err_t sc_misc_seco_chip_info(sc_ipc_t ipc, uint16_t *lc,
- uint16_t *monotonic, uint32_t *uid_l,
- uint32_t *uid_h)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
- RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_SECO_CHIP_INFO;
- RPC_SIZE(&msg) = 1U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- 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);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- void sc_misc_debug_out(sc_ipc_t ipc, uint8_t ch)
- {
- sc_rpc_msg_t msg;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
- RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_DEBUG_OUT;
- RPC_U8(&msg, 0U) = (uint8_t)ch;
- RPC_SIZE(&msg) = 2U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- }
- sc_err_t sc_misc_waveform_capture(sc_ipc_t ipc, sc_bool_t enable)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
- RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_WAVEFORM_CAPTURE;
- RPC_U8(&msg, 0U) = (uint8_t)enable;
- RPC_SIZE(&msg) = 2U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- void sc_misc_build_info(sc_ipc_t ipc, uint32_t *build, uint32_t *commit)
- {
- sc_rpc_msg_t msg;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
- RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_BUILD_INFO;
- RPC_SIZE(&msg) = 1U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- if (build != NULL)
- *build = RPC_U32(&msg, 0U);
- if (commit != NULL)
- *commit = RPC_U32(&msg, 4U);
- }
- void sc_misc_unique_id(sc_ipc_t ipc, uint32_t *id_l, uint32_t *id_h)
- {
- sc_rpc_msg_t msg;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
- RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_UNIQUE_ID;
- RPC_SIZE(&msg) = 1U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- if (id_l != NULL)
- *id_l = RPC_U32(&msg, 0U);
- if (id_h != NULL)
- *id_h = RPC_U32(&msg, 4U);
- }
- sc_err_t sc_misc_set_ari(sc_ipc_t ipc, sc_rsrc_t resource,
- sc_rsrc_t resource_mst, uint16_t ari, sc_bool_t enable)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
- RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_SET_ARI;
- RPC_U16(&msg, 0U) = (uint16_t)resource;
- RPC_U16(&msg, 2U) = (uint16_t)resource_mst;
- RPC_U16(&msg, 4U) = (uint16_t)ari;
- RPC_U8(&msg, 6U) = (uint8_t)enable;
- RPC_SIZE(&msg) = 3U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- void sc_misc_boot_status(sc_ipc_t ipc, sc_misc_boot_status_t status)
- {
- sc_rpc_msg_t msg;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
- RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_BOOT_STATUS;
- RPC_U8(&msg, 0U) = (uint8_t)status;
- RPC_SIZE(&msg) = 2U;
- sc_call_rpc(ipc, &msg, SC_TRUE);
- }
- sc_err_t sc_misc_boot_done(sc_ipc_t ipc, sc_rsrc_t cpu)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
- RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_BOOT_DONE;
- RPC_U16(&msg, 0U) = (uint16_t)cpu;
- RPC_SIZE(&msg) = 2U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- sc_err_t sc_misc_otp_fuse_read(sc_ipc_t ipc, uint32_t word, uint32_t *val)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
- RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_OTP_FUSE_READ;
- RPC_U32(&msg, 0U) = (uint32_t)word;
- RPC_SIZE(&msg) = 2U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- if (val != NULL)
- *val = RPC_U32(&msg, 0U);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- sc_err_t sc_misc_otp_fuse_write(sc_ipc_t ipc, uint32_t word, uint32_t val)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
- RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_OTP_FUSE_WRITE;
- RPC_U32(&msg, 0U) = (uint32_t)word;
- RPC_U32(&msg, 4U) = (uint32_t)val;
- RPC_SIZE(&msg) = 3U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- sc_err_t sc_misc_set_temp(sc_ipc_t ipc, sc_rsrc_t resource,
- sc_misc_temp_t temp, int16_t celsius, int8_t tenths)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
- RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_SET_TEMP;
- RPC_U16(&msg, 0U) = (uint16_t)resource;
- RPC_I16(&msg, 2U) = (int16_t) celsius;
- RPC_U8(&msg, 4U) = (uint8_t)temp;
- RPC_I8(&msg, 5U) = (int8_t) tenths;
- RPC_SIZE(&msg) = 3U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- sc_err_t sc_misc_get_temp(sc_ipc_t ipc, sc_rsrc_t resource,
- sc_misc_temp_t temp, int16_t *celsius,
- int8_t *tenths)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
- RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_GET_TEMP;
- RPC_U16(&msg, 0U) = (uint16_t)resource;
- RPC_U8(&msg, 2U) = (uint8_t)temp;
- RPC_SIZE(&msg) = 2U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- if (celsius != NULL)
- *celsius = RPC_I16(&msg, 0U);
- result = RPC_R8(&msg);
- if (tenths != NULL)
- *tenths = RPC_I8(&msg, 2U);
- return (sc_err_t)result;
- }
- void sc_misc_get_boot_dev(sc_ipc_t ipc, sc_rsrc_t *dev)
- {
- sc_rpc_msg_t msg;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
- RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_GET_BOOT_DEV;
- RPC_SIZE(&msg) = 1U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- if (dev != NULL)
- *dev = RPC_U16(&msg, 0U);
- }
- void sc_misc_get_button_status(sc_ipc_t ipc, sc_bool_t *status)
- {
- sc_rpc_msg_t msg;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
- RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_GET_BUTTON_STATUS;
- RPC_SIZE(&msg) = 1U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- if (status != NULL)
- *status = RPC_U8(&msg, 0U);
- }
- /**@}*/
|