blob: f832982b3de26c9ef4504f604ce93eb5ef503637 [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>
Peng Fane89a3912023-06-15 18:09:04 +080016#include <firmware/imx/sci/svc/timer/api.h>
Peng Fan2e0644a2023-04-28 12:08:09 +080017#include <firmware/imx/sci/rpc.h>
Peng Fan0c830d32018-10-18 14:28:07 +020018#include <dt-bindings/soc/imx_rsrc.h>
19#include <linux/errno.h>
20
21static inline int sc_err_to_linux(sc_err_t err)
22{
23 int ret;
24
25 switch (err) {
26 case SC_ERR_NONE:
27 return 0;
28 case SC_ERR_VERSION:
29 case SC_ERR_CONFIG:
30 case SC_ERR_PARM:
31 ret = -EINVAL;
32 break;
33 case SC_ERR_NOACCESS:
34 case SC_ERR_LOCKED:
35 case SC_ERR_UNAVAILABLE:
36 ret = -EACCES;
37 break;
38 case SC_ERR_NOTFOUND:
39 case SC_ERR_NOPOWER:
40 ret = -ENODEV;
41 break;
42 case SC_ERR_IPC:
43 ret = -EIO;
44 break;
45 case SC_ERR_BUSY:
46 ret = -EBUSY;
47 break;
48 case SC_ERR_FAIL:
49 ret = -EIO;
50 break;
51 default:
52 ret = 0;
53 break;
54 }
55
56 debug("%s %d %d\n", __func__, err, ret);
57
58 return ret;
59}
60
Peng Fan9c621932023-04-28 12:08:10 +080061#if IS_ENABLED(CONFIG_IMX8)
Peng Fan55486382018-10-18 14:28:12 +020062/* PM API*/
63int sc_pm_set_resource_power_mode(sc_ipc_t ipc, sc_rsrc_t resource,
64 sc_pm_power_mode_t mode);
Peng Fand4191db2019-09-23 10:12:31 +000065int sc_pm_get_resource_power_mode(sc_ipc_t ipc, sc_rsrc_t resource,
66 sc_pm_power_mode_t *mode);
Peng Fan55486382018-10-18 14:28:12 +020067int sc_pm_set_clock_rate(sc_ipc_t ipc, sc_rsrc_t resource, sc_pm_clk_t clk,
68 sc_pm_clock_rate_t *rate);
69int sc_pm_get_clock_rate(sc_ipc_t ipc, sc_rsrc_t resource, sc_pm_clk_t clk,
70 sc_pm_clock_rate_t *rate);
Peng Fan55486382018-10-18 14:28:12 +020071int sc_pm_clock_enable(sc_ipc_t ipc, sc_rsrc_t resource, sc_pm_clk_t clk,
72 sc_bool_t enable, sc_bool_t autog);
Peng Fand4191db2019-09-23 10:12:31 +000073int sc_pm_set_clock_parent(sc_ipc_t ipc, sc_rsrc_t resource, sc_pm_clk_t clk,
74 sc_pm_clk_parent_t parent);
75int sc_pm_cpu_start(sc_ipc_t ipc, sc_rsrc_t resource, sc_bool_t enable,
76 sc_faddr_t address);
Peng Fane89a3912023-06-15 18:09:04 +080077void sc_pm_reboot(sc_ipc_t ipc, sc_pm_reset_type_t type);
Peng Fand4191db2019-09-23 10:12:31 +000078sc_bool_t sc_pm_is_partition_started(sc_ipc_t ipc, sc_rm_pt_t pt);
Ye Li24b5dae2019-11-13 21:20:43 -080079int sc_pm_resource_reset(sc_ipc_t ipc, sc_rsrc_t resource);
Peng Fan55486382018-10-18 14:28:12 +020080
81/* MISC API */
Peng Fand4191db2019-09-23 10:12:31 +000082int sc_misc_set_control(sc_ipc_t ipc, sc_rsrc_t resource,
83 sc_ctrl_t ctrl, u32 val);
Peng Fan55486382018-10-18 14:28:12 +020084int sc_misc_get_control(sc_ipc_t ipc, sc_rsrc_t resource, sc_ctrl_t ctrl,
85 u32 *val);
86void sc_misc_get_boot_dev(sc_ipc_t ipc, sc_rsrc_t *boot_dev);
87void sc_misc_boot_status(sc_ipc_t ipc, sc_misc_boot_status_t status);
Ye Lic9c35a42020-06-09 03:34:42 -070088int sc_misc_get_boot_container(sc_ipc_t ipc, u8 *idx);
Peng Fan55486382018-10-18 14:28:12 +020089void sc_misc_build_info(sc_ipc_t ipc, u32 *build, u32 *commit);
90int sc_misc_otp_fuse_read(sc_ipc_t ipc, u32 word, u32 *val);
Peng Fanba44e012019-05-05 13:23:51 +000091int sc_misc_get_temp(sc_ipc_t ipc, sc_rsrc_t resource, sc_misc_temp_t temp,
92 s16 *celsius, s8 *tenths);
Peng Fane89a3912023-06-15 18:09:04 +080093void sc_misc_get_button_status(sc_ipc_t ipc, sc_bool_t *status);
Peng Fan55486382018-10-18 14:28:12 +020094
95/* RM API */
96sc_bool_t sc_rm_is_memreg_owned(sc_ipc_t ipc, sc_rm_mr_t mr);
Peng Fand4191db2019-09-23 10:12:31 +000097int sc_rm_find_memreg(sc_ipc_t ipc, sc_rm_mr_t *mr, sc_faddr_t addr_start,
98 sc_faddr_t addr_end);
99int sc_rm_set_memreg_permissions(sc_ipc_t ipc, sc_rm_mr_t mr,
100 sc_rm_pt_t pt, sc_rm_perm_t perm);
Peng Fan55486382018-10-18 14:28:12 +0200101int sc_rm_get_memreg_info(sc_ipc_t ipc, sc_rm_mr_t mr, sc_faddr_t *addr_start,
102 sc_faddr_t *addr_end);
103sc_bool_t sc_rm_is_resource_owned(sc_ipc_t ipc, sc_rsrc_t resource);
Peng Fand4191db2019-09-23 10:12:31 +0000104int sc_rm_partition_alloc(sc_ipc_t ipc, sc_rm_pt_t *pt, sc_bool_t secure,
105 sc_bool_t isolated, sc_bool_t restricted,
106 sc_bool_t grant, sc_bool_t coherent);
107int sc_rm_partition_free(sc_ipc_t ipc, sc_rm_pt_t pt);
108int sc_rm_get_partition(sc_ipc_t ipc, sc_rm_pt_t *pt);
109int sc_rm_set_parent(sc_ipc_t ipc, sc_rm_pt_t pt, sc_rm_pt_t pt_parent);
110int sc_rm_assign_resource(sc_ipc_t ipc, sc_rm_pt_t pt, sc_rsrc_t resource);
111int sc_rm_assign_pad(sc_ipc_t ipc, sc_rm_pt_t pt, sc_pad_t pad);
112sc_bool_t sc_rm_is_pad_owned(sc_ipc_t ipc, sc_pad_t pad);
113int sc_rm_get_resource_owner(sc_ipc_t ipc, sc_rsrc_t resource,
114 sc_rm_pt_t *pt);
Peng Fan55486382018-10-18 14:28:12 +0200115
116/* PAD API */
117int sc_pad_set(sc_ipc_t ipc, sc_pad_t pad, u32 val);
Franck LENORMANDd3b70ea2019-10-09 10:27:43 +0200118int sc_pad_get(sc_ipc_t ipc, sc_pad_t pad, uint32_t *val);
Peng Fand4191db2019-09-23 10:12:31 +0000119
120/* SMMU API */
121int sc_rm_set_master_sid(sc_ipc_t ipc, sc_rsrc_t resource, sc_rm_sid_t sid);
122
Peng Fane89a3912023-06-15 18:09:04 +0800123/* Timer API */
124int sc_timer_set_wdog_window(sc_ipc_t ipc, sc_timer_wdog_time_t window);
125
Peng Fand4191db2019-09-23 10:12:31 +0000126/* SECO API */
127int sc_seco_authenticate(sc_ipc_t ipc, sc_seco_auth_cmd_t cmd,
128 sc_faddr_t addr);
129int sc_seco_forward_lifecycle(sc_ipc_t ipc, u32 change);
130int sc_seco_chip_info(sc_ipc_t ipc, u16 *lc, u16 *monotonic, u32 *uid_l,
131 u32 *uid_h);
132void sc_seco_build_info(sc_ipc_t ipc, u32 *version, u32 *commit);
Peng Fane89a3912023-06-15 18:09:04 +0800133int sc_seco_v2x_build_info(sc_ipc_t ipc, u32 *version, u32 *commit);
Peng Fand4191db2019-09-23 10:12:31 +0000134int sc_seco_get_event(sc_ipc_t ipc, u8 idx, u32 *event);
135int sc_seco_gen_key_blob(sc_ipc_t ipc, u32 id, sc_faddr_t load_addr,
136 sc_faddr_t export_addr, u16 max_size);
Breno Lima184c7e22019-10-16 18:10:54 -0300137int sc_seco_get_mp_key(sc_ipc_t ipc, sc_faddr_t dst_addr, u16 dst_size);
138int sc_seco_update_mpmr(sc_ipc_t ipc, sc_faddr_t addr, u8 size, u8 lock);
139int sc_seco_get_mp_sign(sc_ipc_t ipc, sc_faddr_t msg_addr,
140 u16 msg_size, sc_faddr_t dst_addr, u16 dst_size);
Ye Li24b5dae2019-11-13 21:20:43 -0800141int sc_seco_secvio_dgo_config(sc_ipc_t ipc, u8 id, u8 access, u32 *data);
Franck LENORMANDd3b70ea2019-10-09 10:27:43 +0200142int sc_seco_secvio_config(sc_ipc_t ipc, u8 id, u8 access,
143 u32 *data0, u32 *data1, u32 *data2, u32 *data3,
144 u32 *data4, u8 size);
Peng Fan9c621932023-04-28 12:08:10 +0800145#else
146/* PM API*/
147static inline int sc_pm_set_resource_power_mode(sc_ipc_t ipc, sc_rsrc_t resource,
148 sc_pm_power_mode_t mode)
149{
150 return -EOPNOTSUPP;
151}
152
153static inline int sc_pm_get_resource_power_mode(sc_ipc_t ipc, sc_rsrc_t resource,
154 sc_pm_power_mode_t *mode)
155{
156 return -EOPNOTSUPP;
157}
158
159static inline int sc_pm_set_clock_rate(sc_ipc_t ipc, sc_rsrc_t resource, sc_pm_clk_t clk,
160 sc_pm_clock_rate_t *rate)
161{
162 return -EOPNOTSUPP;
163}
164
165static inline int sc_pm_get_clock_rate(sc_ipc_t ipc, sc_rsrc_t resource, sc_pm_clk_t clk,
166 sc_pm_clock_rate_t *rate)
167{
168 return -EOPNOTSUPP;
169}
170
171static inline int sc_pm_clock_enable(sc_ipc_t ipc, sc_rsrc_t resource, sc_pm_clk_t clk,
172 sc_bool_t enable, sc_bool_t autog)
173{
174 return -EOPNOTSUPP;
175}
176
177static inline int sc_pm_set_clock_parent(sc_ipc_t ipc, sc_rsrc_t resource, sc_pm_clk_t clk,
178 sc_pm_clk_parent_t parent)
179{
180 return -EOPNOTSUPP;
181}
182
183static inline int sc_pm_cpu_start(sc_ipc_t ipc, sc_rsrc_t resource, sc_bool_t enable,
184 sc_faddr_t address)
185{
186 return -EOPNOTSUPP;
187}
188
189static inline sc_bool_t sc_pm_is_partition_started(sc_ipc_t ipc, sc_rm_pt_t pt)
190{
191 return false;
192}
193
194static inline int sc_pm_resource_reset(sc_ipc_t ipc, sc_rsrc_t resource)
195{
196 return -EOPNOTSUPP;
197}
198
199/* MISC API */
200static inline int sc_misc_set_control(sc_ipc_t ipc, sc_rsrc_t resource, sc_ctrl_t ctrl, u32 val)
201{
202 return -EOPNOTSUPP;
203}
204
205static inline int sc_misc_get_control(sc_ipc_t ipc, sc_rsrc_t resource, sc_ctrl_t ctrl, u32 *val)
206{
207 return -EOPNOTSUPP;
208}
209
210static inline void sc_misc_get_boot_dev(sc_ipc_t ipc, sc_rsrc_t *boot_dev)
211{
212}
213
214static inline void sc_misc_boot_status(sc_ipc_t ipc, sc_misc_boot_status_t status)
215{
216}
217
218static inline int sc_misc_get_boot_container(sc_ipc_t ipc, u8 *idx)
219{
220 return -EOPNOTSUPP;
221}
222
223static inline void sc_misc_build_info(sc_ipc_t ipc, u32 *build, u32 *commit)
224{
225}
226
227static inline int sc_misc_otp_fuse_read(sc_ipc_t ipc, u32 word, u32 *val)
228{
229 return -EOPNOTSUPP;
230}
231
232static inline int sc_misc_get_temp(sc_ipc_t ipc, sc_rsrc_t resource, sc_misc_temp_t temp,
233 s16 *celsius, s8 *tenths)
234{
235 return -EOPNOTSUPP;
236}
237
238/* RM API */
239static inline sc_bool_t sc_rm_is_memreg_owned(sc_ipc_t ipc, sc_rm_mr_t mr)
240{
241 return true;
242}
243
244static inline int sc_rm_find_memreg(sc_ipc_t ipc, sc_rm_mr_t *mr, sc_faddr_t addr_start,
245 sc_faddr_t addr_end)
246{
247 return -EOPNOTSUPP;
248}
249
250static inline int sc_rm_set_memreg_permissions(sc_ipc_t ipc, sc_rm_mr_t mr, sc_rm_pt_t pt,
251 sc_rm_perm_t perm)
252{
253 return -EOPNOTSUPP;
254}
255
256static inline int sc_rm_get_memreg_info(sc_ipc_t ipc, sc_rm_mr_t mr, sc_faddr_t *addr_start,
257 sc_faddr_t *addr_end)
258{
259 return -EOPNOTSUPP;
260}
261
262static inline sc_bool_t sc_rm_is_resource_owned(sc_ipc_t ipc, sc_rsrc_t resource)
263{
264 return true;
265}
266
267static inline int sc_rm_partition_alloc(sc_ipc_t ipc, sc_rm_pt_t *pt, sc_bool_t secure,
268 sc_bool_t isolated, sc_bool_t restricted,
269 sc_bool_t grant, sc_bool_t coherent)
270{
271 return -EOPNOTSUPP;
272}
273
274static inline int sc_rm_partition_free(sc_ipc_t ipc, sc_rm_pt_t pt)
275{
276 return -EOPNOTSUPP;
277}
278
279static inline int sc_rm_get_partition(sc_ipc_t ipc, sc_rm_pt_t *pt)
280{
281 return -EOPNOTSUPP;
282}
283
284static inline int sc_rm_set_parent(sc_ipc_t ipc, sc_rm_pt_t pt, sc_rm_pt_t pt_parent)
285{
286 return -EOPNOTSUPP;
287}
288
289static inline int sc_rm_assign_resource(sc_ipc_t ipc, sc_rm_pt_t pt, sc_rsrc_t resource)
290{
291 return -EOPNOTSUPP;
292}
293
294static inline int sc_rm_assign_pad(sc_ipc_t ipc, sc_rm_pt_t pt, sc_pad_t pad)
295{
296 return -EOPNOTSUPP;
297}
298
299static inline sc_bool_t sc_rm_is_pad_owned(sc_ipc_t ipc, sc_pad_t pad)
300{
301 return true;
302}
303
304static inline int sc_rm_get_resource_owner(sc_ipc_t ipc, sc_rsrc_t resource, sc_rm_pt_t *pt)
305{
306 return -EOPNOTSUPP;
307}
308
309/* PAD API */
310static inline int sc_pad_set(sc_ipc_t ipc, sc_pad_t pad, u32 val)
311{
312 return -EOPNOTSUPP;
313}
314
315static inline int sc_pad_get(sc_ipc_t ipc, sc_pad_t pad, uint32_t *val)
316{
317 return -EOPNOTSUPP;
318}
319
320/* SMMU API */
321static inline int sc_rm_set_master_sid(sc_ipc_t ipc, sc_rsrc_t resource, sc_rm_sid_t sid)
322{
323 return -EOPNOTSUPP;
324}
325
326/* SECO API */
327static inline int sc_seco_authenticate(sc_ipc_t ipc, sc_seco_auth_cmd_t cmd, sc_faddr_t addr)
328{
329 return -EOPNOTSUPP;
330}
331
332static inline int sc_seco_forward_lifecycle(sc_ipc_t ipc, u32 change)
333{
334 return -EOPNOTSUPP;
335}
336
337static inline int sc_seco_chip_info(sc_ipc_t ipc, u16 *lc, u16 *monotonic, u32 *uid_l, u32 *uid_h)
338{
339 return -EOPNOTSUPP;
340}
341
342void sc_seco_build_info(sc_ipc_t ipc, u32 *version, u32 *commit)
343{
344}
345
346static inline int sc_seco_get_event(sc_ipc_t ipc, u8 idx, u32 *event)
347{
348 return -EOPNOTSUPP;
349}
350
351static inline int sc_seco_gen_key_blob(sc_ipc_t ipc, u32 id, sc_faddr_t load_addr,
352 sc_faddr_t export_addr, u16 max_size)
353{
354 return -EOPNOTSUPP;
355}
356
357static inline int sc_seco_get_mp_key(sc_ipc_t ipc, sc_faddr_t dst_addr, u16 dst_size)
358{
359 return -EOPNOTSUPP;
360}
361
362static inline int sc_seco_update_mpmr(sc_ipc_t ipc, sc_faddr_t addr, u8 size, u8 lock)
363{
364 return -EOPNOTSUPP;
365}
366
367static inline int sc_seco_get_mp_sign(sc_ipc_t ipc, sc_faddr_t msg_addr, u16 msg_size,
368 sc_faddr_t dst_addr, u16 dst_size)
369{
370 return -EOPNOTSUPP;
371}
372
373static inline int sc_seco_secvio_dgo_config(sc_ipc_t ipc, u8 id, u8 access, u32 *data)
374{
375 return -EOPNOTSUPP;
376}
377
378static inline int sc_seco_secvio_config(sc_ipc_t ipc, u8 id, u8 access, u32 *data0, u32 *data1,
379 u32 *data2, u32 *data3, u32 *data4, u8 size)
380{
381 return -EOPNOTSUPP;
382}
383
Peng Fane89a3912023-06-15 18:09:04 +0800384static inline void sc_pm_reboot(sc_ipc_t ipc, sc_pm_reset_type_t type)
385{
386}
387
388static inline int sc_seco_v2x_build_info(sc_ipc_t ipc, u32 *version, u32 *commit)
389{
390 return -EOPNOTSUPP;
391}
392
393static inline void sc_misc_get_button_status(sc_ipc_t ipc, sc_bool_t *status)
394{
395}
396
397static inline int sc_timer_set_wdog_window(sc_ipc_t ipc, sc_timer_wdog_time_t window)
398{
399 return -EOPNOTSUPP;
400}
Peng Fan9c621932023-04-28 12:08:10 +0800401#endif
Peng Fand4191db2019-09-23 10:12:31 +0000402
Peng Fan0c830d32018-10-18 14:28:07 +0200403#endif