Commit f61119240922ad13fd573f16c02361d7228fbd67
1 parent
29625003b8
Exists in
smarc-imx_v2017.03_o8.1.0_1.3.0_8m
and in
1 other branch
MLK-17842 imx8: introduce partition cmd
Add partition API cmd support. Signed-off-by: Peng Fan <peng.fan@nxp.com>
Showing 2 changed files with 199 additions and 0 deletions Side-by-side Diff
arch/arm/cpu/armv8/imx8/Makefile
arch/arm/cpu/armv8/imx8/partition.c
1 | +/* | |
2 | + * Copyright 2018 NXP. | |
3 | + * | |
4 | + * SPDX-License-Identifier: GPL-2.0+ | |
5 | + */ | |
6 | +#include <common.h> | |
7 | +#include <linux/errno.h> | |
8 | +#include <asm/io.h> | |
9 | +#include <asm/imx-common/sci/sci.h> | |
10 | +#include <asm/imx-common/boot_mode.h> | |
11 | +#include <malloc.h> | |
12 | +#include <command.h> | |
13 | +#include <asm/arch-imx/cpu.h> | |
14 | +#include <asm/arch/sys_proto.h> | |
15 | + | |
16 | +DECLARE_GLOBAL_DATA_PTR; | |
17 | + | |
18 | +#define SC_MAX_PARTS 32 | |
19 | + | |
20 | +struct scu_rm_part_data { | |
21 | + bool used; | |
22 | + bool isolated; | |
23 | + bool restricted; | |
24 | + bool grant; | |
25 | + sc_rm_did_t did; | |
26 | + sc_rm_pt_t self; | |
27 | + sc_rm_pt_t parent; | |
28 | + char *name; | |
29 | +}; | |
30 | + | |
31 | +static struct scu_rm_part_data rm_part_data[SC_MAX_PARTS]; | |
32 | + | |
33 | +static int do_part_alloc(int argc, char * const argv[]) | |
34 | +{ | |
35 | + sc_rm_pt_t parent_part, os_part; | |
36 | + sc_ipc_t ipc_handle; | |
37 | + sc_err_t err; | |
38 | + int i; | |
39 | + bool restricted = false, isolated = false, grant = false; | |
40 | + | |
41 | + for (i = 0; i < SC_MAX_PARTS; i++) { | |
42 | + if (!rm_part_data[i].used) | |
43 | + break; | |
44 | + } | |
45 | + | |
46 | + if (i == SC_MAX_PARTS) { | |
47 | + puts("No empty slots\n"); | |
48 | + return CMD_RET_FAILURE; | |
49 | + } | |
50 | + | |
51 | + ipc_handle = gd->arch.ipc_channel_handle; | |
52 | + | |
53 | + err = sc_rm_get_partition(ipc_handle, &parent_part); | |
54 | + if (err != SC_ERR_NONE) { | |
55 | + puts("sc_rm_get_partition failure\n"); | |
56 | + return CMD_RET_FAILURE; | |
57 | + } | |
58 | + | |
59 | + isolated = simple_strtoul(argv[0], NULL, 10); | |
60 | + restricted = simple_strtoul(argv[1], NULL, 10); | |
61 | + grant = simple_strtoul(argv[2], NULL, 10); | |
62 | + /* Refine here */ | |
63 | + err = sc_rm_partition_alloc(ipc_handle, &os_part, false, isolated, | |
64 | + restricted, grant, false); | |
65 | + if (err != SC_ERR_NONE) { | |
66 | + printf("sc_rm_partition_alloc failure %d\n", err); | |
67 | + return CMD_RET_FAILURE; | |
68 | + } | |
69 | + | |
70 | + err = sc_rm_set_parent(ipc_handle, os_part, parent_part); | |
71 | + if (err != SC_ERR_NONE) { | |
72 | + sc_rm_partition_free(ipc_handle, os_part); | |
73 | + return CMD_RET_FAILURE; | |
74 | + } | |
75 | + | |
76 | + | |
77 | + rm_part_data[i].self = os_part; | |
78 | + rm_part_data[i].parent = parent_part; | |
79 | + rm_part_data[i].used = true; | |
80 | + rm_part_data[i].restricted = restricted; | |
81 | + rm_part_data[i].isolated = isolated; | |
82 | + rm_part_data[i].grant = grant; | |
83 | + | |
84 | + printf("%s: os_part, %d: parent_part, %d\n", __func__, os_part, | |
85 | + parent_part); | |
86 | + | |
87 | + return CMD_RET_SUCCESS; | |
88 | +} | |
89 | + | |
90 | +static int do_part_free(int argc, char * const argv[]) | |
91 | +{ | |
92 | + sc_rm_pt_t os_part; | |
93 | + sc_ipc_t ipc_handle; | |
94 | + sc_err_t err; | |
95 | + ipc_handle = gd->arch.ipc_channel_handle; | |
96 | + | |
97 | + if (argc == 0) | |
98 | + return CMD_RET_FAILURE; | |
99 | + | |
100 | + os_part = simple_strtoul(argv[0], NULL, 10); | |
101 | + | |
102 | + err = sc_rm_partition_free(ipc_handle, os_part); | |
103 | + if (err != SC_ERR_NONE) { | |
104 | + printf("free partiiton %d err %d\n", os_part, err); | |
105 | + return CMD_RET_FAILURE; | |
106 | + } | |
107 | + | |
108 | + rm_part_data[os_part].used = false; | |
109 | + | |
110 | + return CMD_RET_SUCCESS; | |
111 | +} | |
112 | + | |
113 | +static int do_resource_assign(int argc, char * const argv[]) | |
114 | +{ | |
115 | + sc_rm_pt_t os_part; | |
116 | + sc_ipc_t ipc_handle; | |
117 | + sc_err_t err; | |
118 | + sc_rsrc_t resource; | |
119 | + sc_pad_t pad; | |
120 | + int i, flag; | |
121 | + | |
122 | + ipc_handle = gd->arch.ipc_channel_handle; | |
123 | + | |
124 | + if (argc < 3) | |
125 | + return CMD_RET_FAILURE; | |
126 | + | |
127 | + os_part = simple_strtoul(argv[0], NULL, 10); | |
128 | + flag = simple_strtoul(argv[1], NULL, 10); | |
129 | + if (flag) | |
130 | + pad = simple_strtoul(argv[2], NULL, 10); | |
131 | + else | |
132 | + resource = simple_strtoul(argv[2], NULL, 10); | |
133 | + | |
134 | + for (i = 0; i < SC_MAX_PARTS; i++) { | |
135 | + if ((rm_part_data[i].self == os_part) && rm_part_data[i].used) | |
136 | + break; | |
137 | + } | |
138 | + | |
139 | + if (i == SC_MAX_PARTS) { | |
140 | + puts("Not valid partition\n"); | |
141 | + return CMD_RET_FAILURE; | |
142 | + } | |
143 | + | |
144 | + if (flag) | |
145 | + err = sc_rm_assign_pad(ipc_handle, os_part, pad); | |
146 | + else | |
147 | + err = sc_rm_assign_resource(ipc_handle, os_part, resource); | |
148 | + if (err != SC_ERR_NONE) { | |
149 | + printf("assign resource/pad error %d\n", err); | |
150 | + return CMD_RET_FAILURE; | |
151 | + } | |
152 | + | |
153 | + printf("%s: os_part, %d, %d\n", __func__, os_part, | |
154 | + flag ? pad : resource); | |
155 | + | |
156 | + return CMD_RET_SUCCESS; | |
157 | +} | |
158 | + | |
159 | +static int do_part_list(int argc, char * const argv[]) | |
160 | +{ | |
161 | + int i; | |
162 | + | |
163 | + for (i = 0; i < SC_MAX_PARTS; i++) { | |
164 | + if (rm_part_data[i].used) | |
165 | + printf("part id: %d %d\n", rm_part_data[i].self, | |
166 | + rm_part_data[i].parent); | |
167 | + } | |
168 | + | |
169 | + return CMD_RET_SUCCESS; | |
170 | +} | |
171 | + | |
172 | +static int do_scu_rm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) | |
173 | +{ | |
174 | + if (argc < 2) | |
175 | + return CMD_RET_USAGE; | |
176 | + | |
177 | + if (!strcmp(argv[1], "alloc")) | |
178 | + return do_part_alloc(argc - 2, argv + 2); | |
179 | + if (!strcmp(argv[1], "free")) | |
180 | + return do_part_free(argc - 2, argv + 2); | |
181 | + else if (!strcmp(argv[1], "assign")) | |
182 | + return do_resource_assign(argc - 2, argv + 2); | |
183 | + else if (!strcmp(argv[1], "print")) | |
184 | + return do_part_list(argc - 2, argv + 2); | |
185 | + | |
186 | + return CMD_RET_USAGE; | |
187 | +} | |
188 | + | |
189 | +U_BOOT_CMD( | |
190 | + scu_rm, CONFIG_SYS_MAXARGS, 1, do_scu_rm, | |
191 | + "scu partition function", | |
192 | + "\n" | |
193 | + "scu_rm alloc [isolated] [restricted] [grant]\n" | |
194 | + "scu_rm free pt\n" | |
195 | + "scu_rm assign pt 0 resource\n" | |
196 | + "scu_rm assign pt 1 pad\n" | |
197 | + "scu_rm print\n" | |
198 | +); |
-
mentioned in commit ef488a
-
mentioned in commit ef488a
-
mentioned in commit ef488a
-
mentioned in commit ef488a
-
mentioned in commit ef488a
-
mentioned in commit 9689d9
-
mentioned in commit ef488a
-
mentioned in commit 9689d9
-
mentioned in commit 4b0e79
-
mentioned in commit 4b0e79
-
mentioned in commit 4b0e79
-
mentioned in commit 4b0e79
-
mentioned in commit 6c4b85
-
mentioned in commit 6c4b85
-
mentioned in commit 4b0e79
-
mentioned in commit 6c4b85
-
mentioned in commit 6c4b85
-
mentioned in commit 6c4b85
-
mentioned in commit 6c4b85
-
mentioned in commit 163638