Skip to content

Commit 169caf6

Browse files
MrVanShawn Guo
authored andcommitted
firmware: imx: add resource management api
Add resource management API, when we have multiple partition running together, resources not owned to current partition should not be used. Reviewed-by: Leonard Crestez <[email protected]> Reviewed-by: Dong Aisheng <[email protected]> Signed-off-by: Peng Fan <[email protected]> Signed-off-by: Shawn Guo <[email protected]>
1 parent a8dfca1 commit 169caf6

File tree

4 files changed

+116
-1
lines changed

4 files changed

+116
-1
lines changed

drivers/firmware/imx/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# SPDX-License-Identifier: GPL-2.0
22
obj-$(CONFIG_IMX_DSP) += imx-dsp.o
3-
obj-$(CONFIG_IMX_SCU) += imx-scu.o misc.o imx-scu-irq.o
3+
obj-$(CONFIG_IMX_SCU) += imx-scu.o misc.o imx-scu-irq.o rm.o
44
obj-$(CONFIG_IMX_SCU_PD) += scu-pd.o

drivers/firmware/imx/rm.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
/*
3+
* Copyright 2020 NXP
4+
*
5+
* File containing client-side RPC functions for the RM service. These
6+
* function are ported to clients that communicate to the SC.
7+
*/
8+
9+
#include <linux/firmware/imx/svc/rm.h>
10+
11+
struct imx_sc_msg_rm_rsrc_owned {
12+
struct imx_sc_rpc_msg hdr;
13+
u16 resource;
14+
} __packed __aligned(4);
15+
16+
/*
17+
* This function check @resource is owned by current partition or not
18+
*
19+
* @param[in] ipc IPC handle
20+
* @param[in] resource resource the control is associated with
21+
*
22+
* @return Returns 0 for not owned and 1 for owned.
23+
*/
24+
bool imx_sc_rm_is_resource_owned(struct imx_sc_ipc *ipc, u16 resource)
25+
{
26+
struct imx_sc_msg_rm_rsrc_owned msg;
27+
struct imx_sc_rpc_msg *hdr = &msg.hdr;
28+
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;
33+
34+
msg.resource = resource;
35+
36+
/*
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.
40+
*/
41+
imx_scu_call_rpc(ipc, &msg, true);
42+
43+
return hdr->func;
44+
}
45+
EXPORT_SYMBOL(imx_sc_rm_is_resource_owned);

include/linux/firmware/imx/sci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include <linux/firmware/imx/svc/misc.h>
1616
#include <linux/firmware/imx/svc/pm.h>
17+
#include <linux/firmware/imx/svc/rm.h>
1718

1819
int imx_scu_enable_general_irq_channel(struct device *dev);
1920
int imx_scu_irq_register_notifier(struct notifier_block *nb);

include/linux/firmware/imx/svc/rm.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/* SPDX-License-Identifier: GPL-2.0+ */
2+
/*
3+
* Copyright (C) 2016 Freescale Semiconductor, Inc.
4+
* Copyright 2017-2020 NXP
5+
*
6+
* Header file containing the public API for the System Controller (SC)
7+
* Resource Management (RM) function. This includes functions for
8+
* partitioning resources, pads, and memory regions.
9+
*
10+
* RM_SVC (SVC) Resource Management Service
11+
*
12+
* Module for the Resource Management (RM) service.
13+
*/
14+
15+
#ifndef _SC_RM_API_H
16+
#define _SC_RM_API_H
17+
18+
#include <linux/firmware/imx/sci.h>
19+
20+
/*
21+
* This type is used to indicate RPC RM function calls.
22+
*/
23+
enum imx_sc_rm_func {
24+
IMX_SC_RM_FUNC_UNKNOWN = 0,
25+
IMX_SC_RM_FUNC_PARTITION_ALLOC = 1,
26+
IMX_SC_RM_FUNC_SET_CONFIDENTIAL = 31,
27+
IMX_SC_RM_FUNC_PARTITION_FREE = 2,
28+
IMX_SC_RM_FUNC_GET_DID = 26,
29+
IMX_SC_RM_FUNC_PARTITION_STATIC = 3,
30+
IMX_SC_RM_FUNC_PARTITION_LOCK = 4,
31+
IMX_SC_RM_FUNC_GET_PARTITION = 5,
32+
IMX_SC_RM_FUNC_SET_PARENT = 6,
33+
IMX_SC_RM_FUNC_MOVE_ALL = 7,
34+
IMX_SC_RM_FUNC_ASSIGN_RESOURCE = 8,
35+
IMX_SC_RM_FUNC_SET_RESOURCE_MOVABLE = 9,
36+
IMX_SC_RM_FUNC_SET_SUBSYS_RSRC_MOVABLE = 28,
37+
IMX_SC_RM_FUNC_SET_MASTER_ATTRIBUTES = 10,
38+
IMX_SC_RM_FUNC_SET_MASTER_SID = 11,
39+
IMX_SC_RM_FUNC_SET_PERIPHERAL_PERMISSIONS = 12,
40+
IMX_SC_RM_FUNC_IS_RESOURCE_OWNED = 13,
41+
IMX_SC_RM_FUNC_GET_RESOURCE_OWNER = 33,
42+
IMX_SC_RM_FUNC_IS_RESOURCE_MASTER = 14,
43+
IMX_SC_RM_FUNC_IS_RESOURCE_PERIPHERAL = 15,
44+
IMX_SC_RM_FUNC_GET_RESOURCE_INFO = 16,
45+
IMX_SC_RM_FUNC_MEMREG_ALLOC = 17,
46+
IMX_SC_RM_FUNC_MEMREG_SPLIT = 29,
47+
IMX_SC_RM_FUNC_MEMREG_FRAG = 32,
48+
IMX_SC_RM_FUNC_MEMREG_FREE = 18,
49+
IMX_SC_RM_FUNC_FIND_MEMREG = 30,
50+
IMX_SC_RM_FUNC_ASSIGN_MEMREG = 19,
51+
IMX_SC_RM_FUNC_SET_MEMREG_PERMISSIONS = 20,
52+
IMX_SC_RM_FUNC_IS_MEMREG_OWNED = 21,
53+
IMX_SC_RM_FUNC_GET_MEMREG_INFO = 22,
54+
IMX_SC_RM_FUNC_ASSIGN_PAD = 23,
55+
IMX_SC_RM_FUNC_SET_PAD_MOVABLE = 24,
56+
IMX_SC_RM_FUNC_IS_PAD_OWNED = 25,
57+
IMX_SC_RM_FUNC_DUMP = 27,
58+
};
59+
60+
#if IS_ENABLED(CONFIG_IMX_SCU)
61+
bool imx_sc_rm_is_resource_owned(struct imx_sc_ipc *ipc, u16 resource);
62+
#else
63+
static inline bool
64+
imx_sc_rm_is_resource_owned(struct imx_sc_ipc *ipc, u16 resource)
65+
{
66+
return true;
67+
}
68+
#endif
69+
#endif

0 commit comments

Comments
 (0)