Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / firmware / imx / rm.c
blobd492b99e1c6ccb9e475fb640df10b877bd5c9a47
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright 2020 NXP
5 * File containing client-side RPC functions for the RM service. These
6 * function are ported to clients that communicate to the SC.
7 */
9 #include <linux/firmware/imx/svc/rm.h>
11 struct imx_sc_msg_rm_rsrc_owned {
12 struct imx_sc_rpc_msg hdr;
13 u16 resource;
14 } __packed __aligned(4);
17 * This function check @resource is owned by current partition or not
19 * @param[in] ipc IPC handle
20 * @param[in] resource resource the control is associated with
22 * @return Returns 0 for not owned and 1 for owned.
24 bool imx_sc_rm_is_resource_owned(struct imx_sc_ipc *ipc, u16 resource)
26 struct imx_sc_msg_rm_rsrc_owned msg;
27 struct imx_sc_rpc_msg *hdr = &msg.hdr;
29 hdr->ver = IMX_SC_RPC_VERSION;
30 hdr->svc = IMX_SC_RPC_SVC_RM;
31 hdr->func = IMX_SC_RM_FUNC_IS_RESOURCE_OWNED;
32 hdr->size = 2;
34 msg.resource = resource;
37 * SCU firmware only returns value 0 or 1
38 * for resource owned check which means not owned or owned.
39 * So it is always successful.
41 imx_scu_call_rpc(ipc, &msg, true);
43 return hdr->func;
45 EXPORT_SYMBOL(imx_sc_rm_is_resource_owned);
47 struct imx_sc_msg_rm_get_resource_owner {
48 struct imx_sc_rpc_msg hdr;
49 union {
50 struct {
51 u16 resource;
52 } req;
53 struct {
54 u8 val;
55 } resp;
56 } data;
57 } __packed __aligned(4);
60 * This function get @resource partition number
62 * @param[in] ipc IPC handle
63 * @param[in] resource resource the control is associated with
64 * @param[out] pt pointer to return the partition number
66 * @return Returns 0 for success and < 0 for errors.
68 int imx_sc_rm_get_resource_owner(struct imx_sc_ipc *ipc, u16 resource, u8 *pt)
70 struct imx_sc_msg_rm_get_resource_owner msg;
71 struct imx_sc_rpc_msg *hdr = &msg.hdr;
72 int ret;
74 hdr->ver = IMX_SC_RPC_VERSION;
75 hdr->svc = IMX_SC_RPC_SVC_RM;
76 hdr->func = IMX_SC_RM_FUNC_GET_RESOURCE_OWNER;
77 hdr->size = 2;
79 msg.data.req.resource = resource;
81 ret = imx_scu_call_rpc(ipc, &msg, true);
82 if (ret)
83 return ret;
85 if (pt)
86 *pt = msg.data.resp.val;
88 return 0;
90 EXPORT_SYMBOL(imx_sc_rm_get_resource_owner);