1169caf69SPeng Fan // SPDX-License-Identifier: GPL-2.0+ 2169caf69SPeng Fan /* 3169caf69SPeng Fan * Copyright 2020 NXP 4169caf69SPeng Fan * 5169caf69SPeng Fan * File containing client-side RPC functions for the RM service. These 6169caf69SPeng Fan * function are ported to clients that communicate to the SC. 7169caf69SPeng Fan */ 8169caf69SPeng Fan 9169caf69SPeng Fan #include <linux/firmware/imx/svc/rm.h> 10169caf69SPeng Fan 11169caf69SPeng Fan struct imx_sc_msg_rm_rsrc_owned { 12169caf69SPeng Fan struct imx_sc_rpc_msg hdr; 13169caf69SPeng Fan u16 resource; 14169caf69SPeng Fan } __packed __aligned(4); 15169caf69SPeng Fan 16169caf69SPeng Fan /* 17169caf69SPeng Fan * This function check @resource is owned by current partition or not 18169caf69SPeng Fan * 19169caf69SPeng Fan * @param[in] ipc IPC handle 20169caf69SPeng Fan * @param[in] resource resource the control is associated with 21169caf69SPeng Fan * 22169caf69SPeng Fan * @return Returns 0 for not owned and 1 for owned. 23169caf69SPeng Fan */ 24169caf69SPeng Fan bool imx_sc_rm_is_resource_owned(struct imx_sc_ipc *ipc, u16 resource) 25169caf69SPeng Fan { 26169caf69SPeng Fan struct imx_sc_msg_rm_rsrc_owned msg; 27169caf69SPeng Fan struct imx_sc_rpc_msg *hdr = &msg.hdr; 28169caf69SPeng Fan 29169caf69SPeng Fan hdr->ver = IMX_SC_RPC_VERSION; 30169caf69SPeng Fan hdr->svc = IMX_SC_RPC_SVC_RM; 31169caf69SPeng Fan hdr->func = IMX_SC_RM_FUNC_IS_RESOURCE_OWNED; 32169caf69SPeng Fan hdr->size = 2; 33169caf69SPeng Fan 34169caf69SPeng Fan msg.resource = resource; 35169caf69SPeng Fan 36169caf69SPeng Fan /* 37169caf69SPeng Fan * SCU firmware only returns value 0 or 1 38169caf69SPeng Fan * for resource owned check which means not owned or owned. 39169caf69SPeng Fan * So it is always successful. 40169caf69SPeng Fan */ 41169caf69SPeng Fan imx_scu_call_rpc(ipc, &msg, true); 42169caf69SPeng Fan 43169caf69SPeng Fan return hdr->func; 44169caf69SPeng Fan } 45169caf69SPeng Fan EXPORT_SYMBOL(imx_sc_rm_is_resource_owned); 46*6d240170SPeng Fan 47*6d240170SPeng Fan struct imx_sc_msg_rm_get_resource_owner { 48*6d240170SPeng Fan struct imx_sc_rpc_msg hdr; 49*6d240170SPeng Fan union { 50*6d240170SPeng Fan struct { 51*6d240170SPeng Fan u16 resource; 52*6d240170SPeng Fan } req; 53*6d240170SPeng Fan struct { 54*6d240170SPeng Fan u8 val; 55*6d240170SPeng Fan } resp; 56*6d240170SPeng Fan } data; 57*6d240170SPeng Fan } __packed __aligned(4); 58*6d240170SPeng Fan 59*6d240170SPeng Fan /* 60*6d240170SPeng Fan * This function get @resource partition number 61*6d240170SPeng Fan * 62*6d240170SPeng Fan * @param[in] ipc IPC handle 63*6d240170SPeng Fan * @param[in] resource resource the control is associated with 64*6d240170SPeng Fan * @param[out] pt pointer to return the partition number 65*6d240170SPeng Fan * 66*6d240170SPeng Fan * @return Returns 0 for success and < 0 for errors. 67*6d240170SPeng Fan */ 68*6d240170SPeng Fan int imx_sc_rm_get_resource_owner(struct imx_sc_ipc *ipc, u16 resource, u8 *pt) 69*6d240170SPeng Fan { 70*6d240170SPeng Fan struct imx_sc_msg_rm_get_resource_owner msg; 71*6d240170SPeng Fan struct imx_sc_rpc_msg *hdr = &msg.hdr; 72*6d240170SPeng Fan int ret; 73*6d240170SPeng Fan 74*6d240170SPeng Fan hdr->ver = IMX_SC_RPC_VERSION; 75*6d240170SPeng Fan hdr->svc = IMX_SC_RPC_SVC_RM; 76*6d240170SPeng Fan hdr->func = IMX_SC_RM_FUNC_GET_RESOURCE_OWNER; 77*6d240170SPeng Fan hdr->size = 2; 78*6d240170SPeng Fan 79*6d240170SPeng Fan msg.data.req.resource = resource; 80*6d240170SPeng Fan 81*6d240170SPeng Fan ret = imx_scu_call_rpc(ipc, &msg, true); 82*6d240170SPeng Fan if (ret) 83*6d240170SPeng Fan return ret; 84*6d240170SPeng Fan 85*6d240170SPeng Fan if (pt) 86*6d240170SPeng Fan *pt = msg.data.resp.val; 87*6d240170SPeng Fan 88*6d240170SPeng Fan return 0; 89*6d240170SPeng Fan } 90*6d240170SPeng Fan EXPORT_SYMBOL(imx_sc_rm_get_resource_owner); 91