1 /*
2  * Copyright (c) 2013-2016 Google Inc. All rights reserved
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining
5  * a copy of this software and associated documentation files
6  * (the "Software"), to deal in the Software without restriction,
7  * including without limitation the rights to use, copy, modify, merge,
8  * publish, distribute, sublicense, and/or sell copies of the Software,
9  * and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 #ifndef __SM_H
24 #define __SM_H
25 
26 #include <lib/extmem/extmem.h>
27 #include <lib/sm/smcall.h>
28 #include <stdbool.h>
29 #include <stddef.h>
30 #include <sys/types.h>
31 
32 #define PRIxNS_ADDR PRIx64
33 
34 typedef uint64_t ns_addr_t;
35 typedef uint32_t ns_size_t;
36 
37 struct ns_page_info {
38     uint64_t attr;
39 };
40 
41 struct smc32_args {
42     uint32_t smc_nr;
43     uint32_t params[SMC_NUM_PARAMS];
44     ext_mem_obj_id_t client_id;
45 };
46 
47 #define SMC32_ARGS_INITIAL_VALUE(args) \
48     { 0, {0}, 0 }
49 
50 typedef long (*smc32_handler_t)(struct smc32_args* args);
51 
52 struct smc32_entity {
53     smc32_handler_t fastcall_handler;
54     smc32_handler_t nopcall_handler;
55     smc32_handler_t stdcall_handler;
56 };
57 
58 /* Get selected api version. */
59 uint32_t sm_get_api_version(void);
60 
61 /**
62  * sm_check_and_lock_api_version - Check and lock api version
63  * @api_version_wanted: Version wanted.
64  *
65  * Check if the currently selected api version is greater or equal to
66  * @api_version_wanted and prevent changing the selected api version to a
67  * a version that would change that answer.
68  *
69  * Return: true if currently connected client support @api_version_wanted.
70  */
71 bool sm_check_and_lock_api_version(uint32_t api_version_wanted);
72 
73 /* Schedule Secure OS */
74 long sm_sched_secure(struct smc32_args* args);
75 
76 /* Schedule Non-secure OS */
77 void sm_sched_nonsecure(long retval, struct smc32_args* args);
78 
79 /* Handle an interrupt */
80 enum handler_return sm_handle_irq(void);
81 void sm_handle_fiq(void);
82 
83 /* Version */
84 long smc_sm_api_version(struct smc32_args* args);
85 
86 /* SMP mode */
87 long smc_get_smp_max_cpus(struct smc32_args* args);
88 
89 /* Interrupt controller irq/fiq support */
90 long smc_intc_get_next_irq(struct smc32_args* args);
91 /* return 0 to enter ns-fiq handler, return non-0 to return */
92 status_t sm_intc_fiq_enter(void);
93 void sm_intc_enable_interrupts(void);
94 
95 /* Get the argument block passed in by the bootloader */
96 status_t sm_get_boot_args(void** boot_argsp, size_t* args_sizep);
97 
98 /* Release bootloader arg block */
99 void sm_put_boot_args(void);
100 
101 /* Register handler(s) for an entity */
102 status_t sm_register_entity(uint entity_nr, struct smc32_entity* entity);
103 
104 status_t sm_decode_ns_memory_attr(struct ns_page_info* pinf,
105                                   ns_addr_t* ppa,
106                                   uint* pmmu);
107 
108 #endif /* __SM_H */
109