• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
3  * Licensed under the Mulan PSL v2.
4  * You can use this software according to the terms and conditions of the Mulan PSL v2.
5  * You may obtain a copy of Mulan PSL v2 at:
6  *     http://license.coscl.org.cn/MulanPSL2
7  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
8  * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
9  * PURPOSE.
10  * See the Mulan PSL v2 for more details.
11  */
12 
13 #pragma once
14 
15 #include <chcore/defs.h>
16 #include <chcore/type.h>
17 #include <stdio.h>
18 #include <chcore/memory.h>
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 void usys_putstr(vaddr_t buffer, size_t size);
25 char usys_getc(void);
26 
27 int usys_tee_push_rdr_update_addr(paddr_t addr, size_t size, bool is_cache_mem,
28                                   const char *chip_type_buff, size_t buff_len);
29 int usys_debug_rdr_logitem(char *str, size_t str_len);
30 
31 int usys_get_prio(cap_t thread_cap);
32 int usys_set_prio(cap_t thread_cap, int prio);
33 int usys_get_pmo_paddr(cap_t pmo_cap, unsigned long *buf);
34 cap_t usys_create_device_pmo(unsigned long paddr, unsigned long size);
35 cap_t usys_create_pmo(unsigned long size, unsigned long type);
36 int usys_map_pmo(cap_t cap_group_cap, cap_t pmo_cap, unsigned long addr,
37                  unsigned long perm);
38 int usys_unmap_pmo(cap_t cap_group_cap, cap_t pmo_cap, unsigned long addr);
39 int usys_write_pmo(cap_t pmo_cap, unsigned long offset, void *buf,
40                    unsigned long size);
41 int usys_read_pmo(cap_t cap, unsigned long offset, void *buf,
42                   unsigned long size);
43 int usys_get_phys_addr(void *vaddr, unsigned long *paddr);
44 
45 int usys_revoke_cap(cap_t obj_cap, bool revoke_copy);
46 int usys_transfer_caps(cap_t dest_group_cap, cap_t *src_caps, int nr_caps,
47                        cap_t *dst_caps);
48 
49 _Noreturn void usys_exit(unsigned long ret);
50 void usys_yield(void);
51 
52 cap_t usys_create_thread(unsigned long thread_args_p);
53 cap_t usys_create_cap_group(unsigned long cap_group_args_p);
54 int usys_kill_group(int proc_cap);
55 int usys_register_server(unsigned long ipc_handler, cap_t reigster_cb_cap,
56                          unsigned long destructor);
57 cap_t usys_register_client(cap_t server_cap, unsigned long vm_config_ptr);
58 int usys_ipc_call(cap_t conn_cap, unsigned long ipc_msg_ptr,
59                   unsigned int cap_num);
60 _Noreturn void usys_ipc_return(unsigned long ret, unsigned long cap_num);
61 void usys_ipc_register_cb_return(cap_t server_thread_cap,
62                                  unsigned long server_thread_exit_routine,
63                                  unsigned long server_shm_addr);
64 _Noreturn void usys_ipc_exit_routine_return(void);
65 void usys_debug_log(long arg);
66 int usys_set_affinity(cap_t thread_cap, s32 aff);
67 s32 usys_get_affinity(cap_t thread_cap);
68 
69 unsigned long usys_get_free_mem_size(void);
70 void usys_get_mem_usage_msg(void);
71 void usys_perf_start(void);
72 void usys_perf_end(void);
73 void usys_perf_null(void);
74 void usys_top(void);
75 
76 int usys_user_fault_register(cap_t notific_cap, vaddr_t msg_buffer);
77 int usys_user_fault_map(badge_t client_badge, vaddr_t fault_va,
78                         vaddr_t remap_va, bool copy, vmr_prop_t perm);
79 int usys_map_pmo_with_length(cap_t pmo_cap, vaddr_t addr, unsigned long perm,
80                              size_t length);
81 
82 cap_t usys_irq_register(int irq);
83 int usys_irq_wait(cap_t irq_cap, bool is_block);
84 int usys_irq_ack(cap_t irq_cap);
85 int usys_disable_irqno(int irq);
86 int usys_enable_irqno(int irq);
87 int usys_irq_op(int irq, int op, long val);
88 int usys_irq_stop(cap_t irq_cap);
89 cap_t usys_create_notifc(void);
90 int usys_wait(cap_t notifc_cap, bool is_block, void *timeout);
91 int usys_notify(cap_t notifc_cap);
92 void usys_cache_config(unsigned long option);
93 
94 #ifdef CHCORE_OH_TEE
95 cap_t usys_create_ns_pmo(cap_t cap_group, unsigned long paddr,
96                          unsigned long size);
97 int usys_destroy_ns_pmo(cap_t cap_group, cap_t pmo);
98 int usys_transfer_pmo_owner(cap_t pmo, cap_t cap_group);
99 cap_t usys_create_tee_shared_pmo(cap_t cap_group, void *uuid,
100                                  unsigned long size, cap_t *self_cap);
101 cap_t usys_get_thread_id(cap_t thread_cap);
102 int usys_terminate_thread(cap_t thread_cap);
103 cap_t usys_tee_msg_create_msg_hdl(void);
104 cap_t usys_tee_msg_create_channel(void);
105 int usys_tee_msg_stop_channel(cap_t channel_cap);
106 int usys_tee_msg_receive(cap_t channel_cap, void *recv_buf, size_t recv_len,
107                          cap_t msg_hdl_cap, void *info, int timeout);
108 int usys_tee_msg_call(cap_t channel_cap, void *send_buf, size_t send_len,
109                       void *recv_buf, size_t recv_len, void *timeout);
110 int usys_tee_msg_reply(cap_t msg_hdl_cap, void *reply_buf, size_t reply_len);
111 int usys_tee_msg_notify(cap_t channel_cap, void *send_buf, size_t send_len);
112 #endif /* CHCORE_OH_TEE */
113 
114 int usys_register_recycle_thread(cap_t cap, unsigned long buffer);
115 int usys_ipc_close_connection(cap_t cap);
116 
117 int usys_cache_flush(unsigned long start, unsigned long size, int op_type);
118 unsigned long usys_get_current_tick(void);
119 
120 void usys_get_pci_device(int dev_class, unsigned long uaddr);
121 
122 struct smc_registers {
123     unsigned long x0;
124     unsigned long x1;
125     unsigned long x2;
126     unsigned long x3;
127     unsigned long x4;
128 };
129 enum tz_switch_req {
130     TZ_SWITCH_REQ_ENTRY_DONE,
131     TZ_SWITCH_REQ_STD_REQUEST,
132     TZ_SWITCH_REQ_STD_RESPONSE,
133     TZ_SWITCH_REQ_NR
134 };
135 int usys_tee_wait_switch_req(struct smc_registers *regs);
136 int usys_tee_switch_req(struct smc_registers *regs);
137 int usys_tee_create_ns_pmo(unsigned long paddr, unsigned long size);
138 int usys_tee_pull_kernel_var(unsigned long cmd_buf_addr_buf);
139 void usys_disable_local_irq(void);
140 void usys_enable_local_irq(void);
141 void usys_poweroff(void);
142 
143 #ifdef __cplusplus
144 }
145 #endif
146