blob: 61c8211b44364ffa3f9c7781a6ac670ddde1aaf0 [file] [log] [blame]
Peng Fan0c830d32018-10-18 14:28:07 +02001/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Copyright 2018 NXP
4 */
5
6#ifndef _SC_SCI_H
7#define _SC_SCI_H
8
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Peng Fan2e0644a2023-04-28 12:08:09 +080010#include <firmware/imx/sci/types.h>
11#include <firmware/imx/sci/svc/misc/api.h>
12#include <firmware/imx/sci/svc/pad/api.h>
13#include <firmware/imx/sci/svc/pm/api.h>
14#include <firmware/imx/sci/svc/rm/api.h>
15#include <firmware/imx/sci/svc/seco/api.h>
16#include <firmware/imx/sci/rpc.h>
Peng Fan0c830d32018-10-18 14:28:07 +020017#include <dt-bindings/soc/imx_rsrc.h>
18#include <linux/errno.h>
19
20static inline int sc_err_to_linux(sc_err_t err)
21{
22 int ret;
23
24 switch (err) {
25 case SC_ERR_NONE:
26 return 0;
27 case SC_ERR_VERSION:
28 case SC_ERR_CONFIG:
29 case SC_ERR_PARM:
30 ret = -EINVAL;
31 break;
32 case SC_ERR_NOACCESS:
33 case SC_ERR_LOCKED:
34 case SC_ERR_UNAVAILABLE:
35 ret = -EACCES;
36 break;
37 case SC_ERR_NOTFOUND:
38 case SC_ERR_NOPOWER:
39 ret = -ENODEV;
40 break;
41 case SC_ERR_IPC:
42 ret = -EIO;
43 break;
44 case SC_ERR_BUSY:
45 ret = -EBUSY;
46 break;
47 case SC_ERR_FAIL:
48 ret = -EIO;
49 break;
50 default:
51 ret = 0;
52 break;
53 }
54
55 debug("%s %d %d\n", __func__, err, ret);
56
57 return ret;
58}
59
Peng Fan9c621932023-04-28 12:08:10 +080060#if IS_ENABLED(CONFIG_IMX8)
Peng Fan55486382018-10-18 14:28:12 +020061/* PM API*/
62int sc_pm_set_resource_power_mode(sc_ipc_t ipc, sc_rsrc_t resource,
63 sc_pm_power_mode_t mode);
Peng Fand4191db2019-09-23 10:12:31 +000064int sc_pm_get_resource_power_mode(sc_ipc_t ipc, sc_rsrc_t resource,
65 sc_pm_power_mode_t *mode);
Peng Fan55486382018-10-18 14:28:12 +020066int sc_pm_set_clock_rate(sc_ipc_t ipc, sc_rsrc_t resource, sc_pm_clk_t clk,
67 sc_pm_clock_rate_t *rate);
68int sc_pm_get_clock_rate(sc_ipc_t ipc, sc_rsrc_t resource, sc_pm_clk_t clk,
69 sc_pm_clock_rate_t *rate);
Peng Fan55486382018-10-18 14:28:12 +020070int sc_pm_clock_enable(sc_ipc_t ipc, sc_rsrc_t resource, sc_pm_clk_t clk,
71 sc_bool_t enable, sc_bool_t autog);
Peng Fand4191db2019-09-23 10:12:31 +000072int sc_pm_set_clock_parent(sc_ipc_t ipc, sc_rsrc_t resource, sc_pm_clk_t clk,
73 sc_pm_clk_parent_t parent);
74int sc_pm_cpu_start(sc_ipc_t ipc, sc_rsrc_t resource, sc_bool_t enable,
75 sc_faddr_t address);
76sc_bool_t sc_pm_is_partition_started(sc_ipc_t ipc, sc_rm_pt_t pt);
Ye Li24b5dae2019-11-13 21:20:43 -080077int sc_pm_resource_reset(sc_ipc_t ipc, sc_rsrc_t resource);
Peng Fan55486382018-10-18 14:28:12 +020078
79/* MISC API */
Peng Fand4191db2019-09-23 10:12:31 +000080int sc_misc_set_control(sc_ipc_t ipc, sc_rsrc_t resource,
81 sc_ctrl_t ctrl, u32 val);
Peng Fan55486382018-10-18 14:28:12 +020082int sc_misc_get_control(sc_ipc_t ipc, sc_rsrc_t resource, sc_ctrl_t ctrl,
83 u32 *val);
84void sc_misc_get_boot_dev(sc_ipc_t ipc, sc_rsrc_t *boot_dev);
85void sc_misc_boot_status(sc_ipc_t ipc, sc_misc_boot_status_t status);
Ye Lic9c35a42020-06-09 03:34:42 -070086int sc_misc_get_boot_container(sc_ipc_t ipc, u8 *idx);
Peng Fan55486382018-10-18 14:28:12 +020087void sc_misc_build_info(sc_ipc_t ipc, u32 *build, u32 *commit);
88int sc_misc_otp_fuse_read(sc_ipc_t ipc, u32 word, u32 *val);
Peng Fanba44e012019-05-05 13:23:51 +000089int sc_misc_get_temp(sc_ipc_t ipc, sc_rsrc_t resource, sc_misc_temp_t temp,
90 s16 *celsius, s8 *tenths);
Peng Fan55486382018-10-18 14:28:12 +020091
92/* RM API */
93sc_bool_t sc_rm_is_memreg_owned(sc_ipc_t ipc, sc_rm_mr_t mr);
Peng Fand4191db2019-09-23 10:12:31 +000094int sc_rm_find_memreg(sc_ipc_t ipc, sc_rm_mr_t *mr, sc_faddr_t addr_start,
95 sc_faddr_t addr_end);
96int sc_rm_set_memreg_permissions(sc_ipc_t ipc, sc_rm_mr_t mr,
97 sc_rm_pt_t pt, sc_rm_perm_t perm);
Peng Fan55486382018-10-18 14:28:12 +020098int sc_rm_get_memreg_info(sc_ipc_t ipc, sc_rm_mr_t mr, sc_faddr_t *addr_start,
99 sc_faddr_t *addr_end);
100sc_bool_t sc_rm_is_resource_owned(sc_ipc_t ipc, sc_rsrc_t resource);
Peng Fand4191db2019-09-23 10:12:31 +0000101int sc_rm_partition_alloc(sc_ipc_t ipc, sc_rm_pt_t *pt, sc_bool_t secure,
102 sc_bool_t isolated, sc_bool_t restricted,
103 sc_bool_t grant, sc_bool_t coherent);
104int sc_rm_partition_free(sc_ipc_t ipc, sc_rm_pt_t pt);
105int sc_rm_get_partition(sc_ipc_t ipc, sc_rm_pt_t *pt);
106int sc_rm_set_parent(sc_ipc_t ipc, sc_rm_pt_t pt, sc_rm_pt_t pt_parent);
107int sc_rm_assign_resource(sc_ipc_t ipc, sc_rm_pt_t pt, sc_rsrc_t resource);
108int sc_rm_assign_pad(sc_ipc_t ipc, sc_rm_pt_t pt, sc_pad_t pad);
109sc_bool_t sc_rm_is_pad_owned(sc_ipc_t ipc, sc_pad_t pad);
110int sc_rm_get_resource_owner(sc_ipc_t ipc, sc_rsrc_t resource,
111 sc_rm_pt_t *pt);
Peng Fan55486382018-10-18 14:28:12 +0200112
113/* PAD API */
114int sc_pad_set(sc_ipc_t ipc, sc_pad_t pad, u32 val);
Franck LENORMANDd3b70ea2019-10-09 10:27:43 +0200115int sc_pad_get(sc_ipc_t ipc, sc_pad_t pad, uint32_t *val);
Peng Fand4191db2019-09-23 10:12:31 +0000116
117/* SMMU API */
118int sc_rm_set_master_sid(sc_ipc_t ipc, sc_rsrc_t resource, sc_rm_sid_t sid);
119
120/* SECO API */
121int sc_seco_authenticate(sc_ipc_t ipc, sc_seco_auth_cmd_t cmd,
122 sc_faddr_t addr);
123int sc_seco_forward_lifecycle(sc_ipc_t ipc, u32 change);
124int sc_seco_chip_info(sc_ipc_t ipc, u16 *lc, u16 *monotonic, u32 *uid_l,
125 u32 *uid_h);
126void sc_seco_build_info(sc_ipc_t ipc, u32 *version, u32 *commit);
127int sc_seco_get_event(sc_ipc_t ipc, u8 idx, u32 *event);
128int sc_seco_gen_key_blob(sc_ipc_t ipc, u32 id, sc_faddr_t load_addr,
129 sc_faddr_t export_addr, u16 max_size);
Breno Lima184c7e22019-10-16 18:10:54 -0300130int sc_seco_get_mp_key(sc_ipc_t ipc, sc_faddr_t dst_addr, u16 dst_size);
131int sc_seco_update_mpmr(sc_ipc_t ipc, sc_faddr_t addr, u8 size, u8 lock);
132int sc_seco_get_mp_sign(sc_ipc_t ipc, sc_faddr_t msg_addr,
133 u16 msg_size, sc_faddr_t dst_addr, u16 dst_size);
Ye Li24b5dae2019-11-13 21:20:43 -0800134int sc_seco_secvio_dgo_config(sc_ipc_t ipc, u8 id, u8 access, u32 *data);
Franck LENORMANDd3b70ea2019-10-09 10:27:43 +0200135int sc_seco_secvio_config(sc_ipc_t ipc, u8 id, u8 access,
136 u32 *data0, u32 *data1, u32 *data2, u32 *data3,
137 u32 *data4, u8 size);
Peng Fan9c621932023-04-28 12:08:10 +0800138#else
139/* PM API*/
140static inline int sc_pm_set_resource_power_mode(sc_ipc_t ipc, sc_rsrc_t resource,
141 sc_pm_power_mode_t mode)
142{
143 return -EOPNOTSUPP;
144}
145
146static inline int sc_pm_get_resource_power_mode(sc_ipc_t ipc, sc_rsrc_t resource,
147 sc_pm_power_mode_t *mode)
148{
149 return -EOPNOTSUPP;
150}
151
152static inline int sc_pm_set_clock_rate(sc_ipc_t ipc, sc_rsrc_t resource, sc_pm_clk_t clk,
153 sc_pm_clock_rate_t *rate)
154{
155 return -EOPNOTSUPP;
156}
157
158static inline int sc_pm_get_clock_rate(sc_ipc_t ipc, sc_rsrc_t resource, sc_pm_clk_t clk,
159 sc_pm_clock_rate_t *rate)
160{
161 return -EOPNOTSUPP;
162}
163
164static inline int sc_pm_clock_enable(sc_ipc_t ipc, sc_rsrc_t resource, sc_pm_clk_t clk,
165 sc_bool_t enable, sc_bool_t autog)
166{
167 return -EOPNOTSUPP;
168}
169
170static inline int sc_pm_set_clock_parent(sc_ipc_t ipc, sc_rsrc_t resource, sc_pm_clk_t clk,
171 sc_pm_clk_parent_t parent)
172{
173 return -EOPNOTSUPP;
174}
175
176static inline int sc_pm_cpu_start(sc_ipc_t ipc, sc_rsrc_t resource, sc_bool_t enable,
177 sc_faddr_t address)
178{
179 return -EOPNOTSUPP;
180}
181
182static inline sc_bool_t sc_pm_is_partition_started(sc_ipc_t ipc, sc_rm_pt_t pt)
183{
184 return false;
185}
186
187static inline int sc_pm_resource_reset(sc_ipc_t ipc, sc_rsrc_t resource)
188{
189 return -EOPNOTSUPP;
190}
191
192/* MISC API */
193static inline int sc_misc_set_control(sc_ipc_t ipc, sc_rsrc_t resource, sc_ctrl_t ctrl, u32 val)
194{
195 return -EOPNOTSUPP;
196}
197
198static inline int sc_misc_get_control(sc_ipc_t ipc, sc_rsrc_t resource, sc_ctrl_t ctrl, u32 *val)
199{
200 return -EOPNOTSUPP;
201}
202
203static inline void sc_misc_get_boot_dev(sc_ipc_t ipc, sc_rsrc_t *boot_dev)
204{
205}
206
207static inline void sc_misc_boot_status(sc_ipc_t ipc, sc_misc_boot_status_t status)
208{
209}
210
211static inline int sc_misc_get_boot_container(sc_ipc_t ipc, u8 *idx)
212{
213 return -EOPNOTSUPP;
214}
215
216static inline void sc_misc_build_info(sc_ipc_t ipc, u32 *build, u32 *commit)
217{
218}
219
220static inline int sc_misc_otp_fuse_read(sc_ipc_t ipc, u32 word, u32 *val)
221{
222 return -EOPNOTSUPP;
223}
224
225static inline int sc_misc_get_temp(sc_ipc_t ipc, sc_rsrc_t resource, sc_misc_temp_t temp,
226 s16 *celsius, s8 *tenths)
227{
228 return -EOPNOTSUPP;
229}
230
231/* RM API */
232static inline sc_bool_t sc_rm_is_memreg_owned(sc_ipc_t ipc, sc_rm_mr_t mr)
233{
234 return true;
235}
236
237static inline int sc_rm_find_memreg(sc_ipc_t ipc, sc_rm_mr_t *mr, sc_faddr_t addr_start,
238 sc_faddr_t addr_end)
239{
240 return -EOPNOTSUPP;
241}
242
243static inline int sc_rm_set_memreg_permissions(sc_ipc_t ipc, sc_rm_mr_t mr, sc_rm_pt_t pt,
244 sc_rm_perm_t perm)
245{
246 return -EOPNOTSUPP;
247}
248
249static inline int sc_rm_get_memreg_info(sc_ipc_t ipc, sc_rm_mr_t mr, sc_faddr_t *addr_start,
250 sc_faddr_t *addr_end)
251{
252 return -EOPNOTSUPP;
253}
254
255static inline sc_bool_t sc_rm_is_resource_owned(sc_ipc_t ipc, sc_rsrc_t resource)
256{
257 return true;
258}
259
260static inline int sc_rm_partition_alloc(sc_ipc_t ipc, sc_rm_pt_t *pt, sc_bool_t secure,
261 sc_bool_t isolated, sc_bool_t restricted,
262 sc_bool_t grant, sc_bool_t coherent)
263{
264 return -EOPNOTSUPP;
265}
266
267static inline int sc_rm_partition_free(sc_ipc_t ipc, sc_rm_pt_t pt)
268{
269 return -EOPNOTSUPP;
270}
271
272static inline int sc_rm_get_partition(sc_ipc_t ipc, sc_rm_pt_t *pt)
273{
274 return -EOPNOTSUPP;
275}
276
277static inline int sc_rm_set_parent(sc_ipc_t ipc, sc_rm_pt_t pt, sc_rm_pt_t pt_parent)
278{
279 return -EOPNOTSUPP;
280}
281
282static inline int sc_rm_assign_resource(sc_ipc_t ipc, sc_rm_pt_t pt, sc_rsrc_t resource)
283{
284 return -EOPNOTSUPP;
285}
286
287static inline int sc_rm_assign_pad(sc_ipc_t ipc, sc_rm_pt_t pt, sc_pad_t pad)
288{
289 return -EOPNOTSUPP;
290}
291
292static inline sc_bool_t sc_rm_is_pad_owned(sc_ipc_t ipc, sc_pad_t pad)
293{
294 return true;
295}
296
297static inline int sc_rm_get_resource_owner(sc_ipc_t ipc, sc_rsrc_t resource, sc_rm_pt_t *pt)
298{
299 return -EOPNOTSUPP;
300}
301
302/* PAD API */
303static inline int sc_pad_set(sc_ipc_t ipc, sc_pad_t pad, u32 val)
304{
305 return -EOPNOTSUPP;
306}
307
308static inline int sc_pad_get(sc_ipc_t ipc, sc_pad_t pad, uint32_t *val)
309{
310 return -EOPNOTSUPP;
311}
312
313/* SMMU API */
314static inline int sc_rm_set_master_sid(sc_ipc_t ipc, sc_rsrc_t resource, sc_rm_sid_t sid)
315{
316 return -EOPNOTSUPP;
317}
318
319/* SECO API */
320static inline int sc_seco_authenticate(sc_ipc_t ipc, sc_seco_auth_cmd_t cmd, sc_faddr_t addr)
321{
322 return -EOPNOTSUPP;
323}
324
325static inline int sc_seco_forward_lifecycle(sc_ipc_t ipc, u32 change)
326{
327 return -EOPNOTSUPP;
328}
329
330static inline int sc_seco_chip_info(sc_ipc_t ipc, u16 *lc, u16 *monotonic, u32 *uid_l, u32 *uid_h)
331{
332 return -EOPNOTSUPP;
333}
334
335void sc_seco_build_info(sc_ipc_t ipc, u32 *version, u32 *commit)
336{
337}
338
339static inline int sc_seco_get_event(sc_ipc_t ipc, u8 idx, u32 *event)
340{
341 return -EOPNOTSUPP;
342}
343
344static inline int sc_seco_gen_key_blob(sc_ipc_t ipc, u32 id, sc_faddr_t load_addr,
345 sc_faddr_t export_addr, u16 max_size)
346{
347 return -EOPNOTSUPP;
348}
349
350static inline int sc_seco_get_mp_key(sc_ipc_t ipc, sc_faddr_t dst_addr, u16 dst_size)
351{
352 return -EOPNOTSUPP;
353}
354
355static inline int sc_seco_update_mpmr(sc_ipc_t ipc, sc_faddr_t addr, u8 size, u8 lock)
356{
357 return -EOPNOTSUPP;
358}
359
360static inline int sc_seco_get_mp_sign(sc_ipc_t ipc, sc_faddr_t msg_addr, u16 msg_size,
361 sc_faddr_t dst_addr, u16 dst_size)
362{
363 return -EOPNOTSUPP;
364}
365
366static inline int sc_seco_secvio_dgo_config(sc_ipc_t ipc, u8 id, u8 access, u32 *data)
367{
368 return -EOPNOTSUPP;
369}
370
371static inline int sc_seco_secvio_config(sc_ipc_t ipc, u8 id, u8 access, u32 *data0, u32 *data1,
372 u32 *data2, u32 *data3, u32 *data4, u8 size)
373{
374 return -EOPNOTSUPP;
375}
376
377#endif
Peng Fand4191db2019-09-23 10:12:31 +0000378
Peng Fan0c830d32018-10-18 14:28:07 +0200379#endif