Peng Fan | bf494d7 | 2018-10-18 14:28:07 +0200 | [diff] [blame] | 1 | /* 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 Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Peng Fan | 99ac6c7 | 2023-04-28 12:08:09 +0800 | [diff] [blame] | 10 | #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 Fan | bf494d7 | 2018-10-18 14:28:07 +0200 | [diff] [blame] | 17 | #include <dt-bindings/soc/imx_rsrc.h> |
| 18 | #include <linux/errno.h> |
| 19 | |
| 20 | static 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 Fan | f991e98 | 2023-04-28 12:08:10 +0800 | [diff] [blame^] | 60 | #if IS_ENABLED(CONFIG_IMX8) |
Peng Fan | ad9d40a | 2018-10-18 14:28:12 +0200 | [diff] [blame] | 61 | /* PM API*/ |
| 62 | int sc_pm_set_resource_power_mode(sc_ipc_t ipc, sc_rsrc_t resource, |
| 63 | sc_pm_power_mode_t mode); |
Peng Fan | 4d81755 | 2019-09-23 10:12:31 +0000 | [diff] [blame] | 64 | int sc_pm_get_resource_power_mode(sc_ipc_t ipc, sc_rsrc_t resource, |
| 65 | sc_pm_power_mode_t *mode); |
Peng Fan | ad9d40a | 2018-10-18 14:28:12 +0200 | [diff] [blame] | 66 | int 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); |
| 68 | int 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 Fan | ad9d40a | 2018-10-18 14:28:12 +0200 | [diff] [blame] | 70 | int 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 Fan | 4d81755 | 2019-09-23 10:12:31 +0000 | [diff] [blame] | 72 | int 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); |
| 74 | int sc_pm_cpu_start(sc_ipc_t ipc, sc_rsrc_t resource, sc_bool_t enable, |
| 75 | sc_faddr_t address); |
| 76 | sc_bool_t sc_pm_is_partition_started(sc_ipc_t ipc, sc_rm_pt_t pt); |
Ye Li | 73d769d | 2019-11-13 21:20:43 -0800 | [diff] [blame] | 77 | int sc_pm_resource_reset(sc_ipc_t ipc, sc_rsrc_t resource); |
Peng Fan | ad9d40a | 2018-10-18 14:28:12 +0200 | [diff] [blame] | 78 | |
| 79 | /* MISC API */ |
Peng Fan | 4d81755 | 2019-09-23 10:12:31 +0000 | [diff] [blame] | 80 | int sc_misc_set_control(sc_ipc_t ipc, sc_rsrc_t resource, |
| 81 | sc_ctrl_t ctrl, u32 val); |
Peng Fan | ad9d40a | 2018-10-18 14:28:12 +0200 | [diff] [blame] | 82 | int sc_misc_get_control(sc_ipc_t ipc, sc_rsrc_t resource, sc_ctrl_t ctrl, |
| 83 | u32 *val); |
| 84 | void sc_misc_get_boot_dev(sc_ipc_t ipc, sc_rsrc_t *boot_dev); |
| 85 | void sc_misc_boot_status(sc_ipc_t ipc, sc_misc_boot_status_t status); |
Ye Li | dfbdaa6 | 2020-06-09 03:34:42 -0700 | [diff] [blame] | 86 | int sc_misc_get_boot_container(sc_ipc_t ipc, u8 *idx); |
Peng Fan | ad9d40a | 2018-10-18 14:28:12 +0200 | [diff] [blame] | 87 | void sc_misc_build_info(sc_ipc_t ipc, u32 *build, u32 *commit); |
| 88 | int sc_misc_otp_fuse_read(sc_ipc_t ipc, u32 word, u32 *val); |
Peng Fan | 7752a0f | 2019-05-05 13:23:51 +0000 | [diff] [blame] | 89 | int sc_misc_get_temp(sc_ipc_t ipc, sc_rsrc_t resource, sc_misc_temp_t temp, |
| 90 | s16 *celsius, s8 *tenths); |
Peng Fan | ad9d40a | 2018-10-18 14:28:12 +0200 | [diff] [blame] | 91 | |
| 92 | /* RM API */ |
| 93 | sc_bool_t sc_rm_is_memreg_owned(sc_ipc_t ipc, sc_rm_mr_t mr); |
Peng Fan | 4d81755 | 2019-09-23 10:12:31 +0000 | [diff] [blame] | 94 | int sc_rm_find_memreg(sc_ipc_t ipc, sc_rm_mr_t *mr, sc_faddr_t addr_start, |
| 95 | sc_faddr_t addr_end); |
| 96 | int 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 Fan | ad9d40a | 2018-10-18 14:28:12 +0200 | [diff] [blame] | 98 | int 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); |
| 100 | sc_bool_t sc_rm_is_resource_owned(sc_ipc_t ipc, sc_rsrc_t resource); |
Peng Fan | 4d81755 | 2019-09-23 10:12:31 +0000 | [diff] [blame] | 101 | int 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); |
| 104 | int sc_rm_partition_free(sc_ipc_t ipc, sc_rm_pt_t pt); |
| 105 | int sc_rm_get_partition(sc_ipc_t ipc, sc_rm_pt_t *pt); |
| 106 | int sc_rm_set_parent(sc_ipc_t ipc, sc_rm_pt_t pt, sc_rm_pt_t pt_parent); |
| 107 | int sc_rm_assign_resource(sc_ipc_t ipc, sc_rm_pt_t pt, sc_rsrc_t resource); |
| 108 | int sc_rm_assign_pad(sc_ipc_t ipc, sc_rm_pt_t pt, sc_pad_t pad); |
| 109 | sc_bool_t sc_rm_is_pad_owned(sc_ipc_t ipc, sc_pad_t pad); |
| 110 | int sc_rm_get_resource_owner(sc_ipc_t ipc, sc_rsrc_t resource, |
| 111 | sc_rm_pt_t *pt); |
Peng Fan | ad9d40a | 2018-10-18 14:28:12 +0200 | [diff] [blame] | 112 | |
| 113 | /* PAD API */ |
| 114 | int sc_pad_set(sc_ipc_t ipc, sc_pad_t pad, u32 val); |
Franck LENORMAND | 242d1cd | 2019-10-09 10:27:43 +0200 | [diff] [blame] | 115 | int sc_pad_get(sc_ipc_t ipc, sc_pad_t pad, uint32_t *val); |
Peng Fan | 4d81755 | 2019-09-23 10:12:31 +0000 | [diff] [blame] | 116 | |
| 117 | /* SMMU API */ |
| 118 | int sc_rm_set_master_sid(sc_ipc_t ipc, sc_rsrc_t resource, sc_rm_sid_t sid); |
| 119 | |
| 120 | /* SECO API */ |
| 121 | int sc_seco_authenticate(sc_ipc_t ipc, sc_seco_auth_cmd_t cmd, |
| 122 | sc_faddr_t addr); |
| 123 | int sc_seco_forward_lifecycle(sc_ipc_t ipc, u32 change); |
| 124 | int sc_seco_chip_info(sc_ipc_t ipc, u16 *lc, u16 *monotonic, u32 *uid_l, |
| 125 | u32 *uid_h); |
| 126 | void sc_seco_build_info(sc_ipc_t ipc, u32 *version, u32 *commit); |
| 127 | int sc_seco_get_event(sc_ipc_t ipc, u8 idx, u32 *event); |
| 128 | int 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 Lima | f959594 | 2019-10-16 18:10:54 -0300 | [diff] [blame] | 130 | int sc_seco_get_mp_key(sc_ipc_t ipc, sc_faddr_t dst_addr, u16 dst_size); |
| 131 | int sc_seco_update_mpmr(sc_ipc_t ipc, sc_faddr_t addr, u8 size, u8 lock); |
| 132 | int 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 Li | 73d769d | 2019-11-13 21:20:43 -0800 | [diff] [blame] | 134 | int sc_seco_secvio_dgo_config(sc_ipc_t ipc, u8 id, u8 access, u32 *data); |
Franck LENORMAND | 242d1cd | 2019-10-09 10:27:43 +0200 | [diff] [blame] | 135 | int 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 Fan | f991e98 | 2023-04-28 12:08:10 +0800 | [diff] [blame^] | 138 | #else |
| 139 | /* PM API*/ |
| 140 | static 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 | |
| 146 | static 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 | |
| 152 | static 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 | |
| 158 | static 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 | |
| 164 | static 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 | |
| 170 | static 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 | |
| 176 | static 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 | |
| 182 | static inline sc_bool_t sc_pm_is_partition_started(sc_ipc_t ipc, sc_rm_pt_t pt) |
| 183 | { |
| 184 | return false; |
| 185 | } |
| 186 | |
| 187 | static inline int sc_pm_resource_reset(sc_ipc_t ipc, sc_rsrc_t resource) |
| 188 | { |
| 189 | return -EOPNOTSUPP; |
| 190 | } |
| 191 | |
| 192 | /* MISC API */ |
| 193 | static 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 | |
| 198 | static 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 | |
| 203 | static inline void sc_misc_get_boot_dev(sc_ipc_t ipc, sc_rsrc_t *boot_dev) |
| 204 | { |
| 205 | } |
| 206 | |
| 207 | static inline void sc_misc_boot_status(sc_ipc_t ipc, sc_misc_boot_status_t status) |
| 208 | { |
| 209 | } |
| 210 | |
| 211 | static inline int sc_misc_get_boot_container(sc_ipc_t ipc, u8 *idx) |
| 212 | { |
| 213 | return -EOPNOTSUPP; |
| 214 | } |
| 215 | |
| 216 | static inline void sc_misc_build_info(sc_ipc_t ipc, u32 *build, u32 *commit) |
| 217 | { |
| 218 | } |
| 219 | |
| 220 | static inline int sc_misc_otp_fuse_read(sc_ipc_t ipc, u32 word, u32 *val) |
| 221 | { |
| 222 | return -EOPNOTSUPP; |
| 223 | } |
| 224 | |
| 225 | static 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 */ |
| 232 | static inline sc_bool_t sc_rm_is_memreg_owned(sc_ipc_t ipc, sc_rm_mr_t mr) |
| 233 | { |
| 234 | return true; |
| 235 | } |
| 236 | |
| 237 | static 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 | |
| 243 | static 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 | |
| 249 | static 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 | |
| 255 | static inline sc_bool_t sc_rm_is_resource_owned(sc_ipc_t ipc, sc_rsrc_t resource) |
| 256 | { |
| 257 | return true; |
| 258 | } |
| 259 | |
| 260 | static 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 | |
| 267 | static inline int sc_rm_partition_free(sc_ipc_t ipc, sc_rm_pt_t pt) |
| 268 | { |
| 269 | return -EOPNOTSUPP; |
| 270 | } |
| 271 | |
| 272 | static inline int sc_rm_get_partition(sc_ipc_t ipc, sc_rm_pt_t *pt) |
| 273 | { |
| 274 | return -EOPNOTSUPP; |
| 275 | } |
| 276 | |
| 277 | static 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 | |
| 282 | static 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 | |
| 287 | static 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 | |
| 292 | static inline sc_bool_t sc_rm_is_pad_owned(sc_ipc_t ipc, sc_pad_t pad) |
| 293 | { |
| 294 | return true; |
| 295 | } |
| 296 | |
| 297 | static 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 */ |
| 303 | static inline int sc_pad_set(sc_ipc_t ipc, sc_pad_t pad, u32 val) |
| 304 | { |
| 305 | return -EOPNOTSUPP; |
| 306 | } |
| 307 | |
| 308 | static 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 */ |
| 314 | static 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 */ |
| 320 | static 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 | |
| 325 | static inline int sc_seco_forward_lifecycle(sc_ipc_t ipc, u32 change) |
| 326 | { |
| 327 | return -EOPNOTSUPP; |
| 328 | } |
| 329 | |
| 330 | static 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 | |
| 335 | void sc_seco_build_info(sc_ipc_t ipc, u32 *version, u32 *commit) |
| 336 | { |
| 337 | } |
| 338 | |
| 339 | static inline int sc_seco_get_event(sc_ipc_t ipc, u8 idx, u32 *event) |
| 340 | { |
| 341 | return -EOPNOTSUPP; |
| 342 | } |
| 343 | |
| 344 | static 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 | |
| 350 | static 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 | |
| 355 | static inline int sc_seco_update_mpmr(sc_ipc_t ipc, sc_faddr_t addr, u8 size, u8 lock) |
| 356 | { |
| 357 | return -EOPNOTSUPP; |
| 358 | } |
| 359 | |
| 360 | static 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 | |
| 366 | static inline int sc_seco_secvio_dgo_config(sc_ipc_t ipc, u8 id, u8 access, u32 *data) |
| 367 | { |
| 368 | return -EOPNOTSUPP; |
| 369 | } |
| 370 | |
| 371 | static 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 Fan | 4d81755 | 2019-09-23 10:12:31 +0000 | [diff] [blame] | 378 | |
Peng Fan | bf494d7 | 2018-10-18 14:28:07 +0200 | [diff] [blame] | 379 | #endif |