Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 /*
0003  * Copyright 2020 NXP
0004  *
0005  * File containing client-side RPC functions for the RM service. These
0006  * function are ported to clients that communicate to the SC.
0007  */
0008 
0009 #include <linux/firmware/imx/svc/rm.h>
0010 
0011 struct imx_sc_msg_rm_rsrc_owned {
0012     struct imx_sc_rpc_msg hdr;
0013     u16 resource;
0014 } __packed __aligned(4);
0015 
0016 /*
0017  * This function check @resource is owned by current partition or not
0018  *
0019  * @param[in]     ipc         IPC handle
0020  * @param[in]     resource    resource the control is associated with
0021  *
0022  * @return Returns 0 for not owned and 1 for owned.
0023  */
0024 bool imx_sc_rm_is_resource_owned(struct imx_sc_ipc *ipc, u16 resource)
0025 {
0026     struct imx_sc_msg_rm_rsrc_owned msg;
0027     struct imx_sc_rpc_msg *hdr = &msg.hdr;
0028 
0029     hdr->ver = IMX_SC_RPC_VERSION;
0030     hdr->svc = IMX_SC_RPC_SVC_RM;
0031     hdr->func = IMX_SC_RM_FUNC_IS_RESOURCE_OWNED;
0032     hdr->size = 2;
0033 
0034     msg.resource = resource;
0035 
0036     /*
0037      * SCU firmware only returns value 0 or 1
0038      * for resource owned check which means not owned or owned.
0039      * So it is always successful.
0040      */
0041     imx_scu_call_rpc(ipc, &msg, true);
0042 
0043     return hdr->func;
0044 }
0045 EXPORT_SYMBOL(imx_sc_rm_is_resource_owned);
0046 
0047 struct imx_sc_msg_rm_get_resource_owner {
0048     struct imx_sc_rpc_msg hdr;
0049     union {
0050         struct {
0051             u16 resource;
0052         } req;
0053         struct {
0054             u8 val;
0055         } resp;
0056     } data;
0057 } __packed __aligned(4);
0058 
0059 /*
0060  * This function get @resource partition number
0061  *
0062  * @param[in]     ipc         IPC handle
0063  * @param[in]     resource    resource the control is associated with
0064  * @param[out]    pt          pointer to return the partition number
0065  *
0066  * @return Returns 0 for success and < 0 for errors.
0067  */
0068 int imx_sc_rm_get_resource_owner(struct imx_sc_ipc *ipc, u16 resource, u8 *pt)
0069 {
0070     struct imx_sc_msg_rm_get_resource_owner msg;
0071     struct imx_sc_rpc_msg *hdr = &msg.hdr;
0072     int ret;
0073 
0074     hdr->ver = IMX_SC_RPC_VERSION;
0075     hdr->svc = IMX_SC_RPC_SVC_RM;
0076     hdr->func = IMX_SC_RM_FUNC_GET_RESOURCE_OWNER;
0077     hdr->size = 2;
0078 
0079     msg.data.req.resource = resource;
0080 
0081     ret = imx_scu_call_rpc(ipc, &msg, true);
0082     if (ret)
0083         return ret;
0084 
0085     if (pt)
0086         *pt = msg.data.resp.val;
0087 
0088     return 0;
0089 }
0090 EXPORT_SYMBOL(imx_sc_rm_get_resource_owner);