1 /*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, 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
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25 #include <trusty/sysdeps.h>
26
27 #include <common.h>
28 #include <linux/string.h>
29 #include <malloc.h>
30
31 extern int trusty_encode_page_info(struct ns_mem_page_info* page_info,
32 void* vaddr);
33
trusty_lock(struct trusty_dev * dev)34 void trusty_lock(struct trusty_dev* dev) {}
trusty_unlock(struct trusty_dev * dev)35 void trusty_unlock(struct trusty_dev* dev) {}
36
trusty_local_irq_disable(unsigned long * state)37 void trusty_local_irq_disable(unsigned long* state) {
38 disable_interrupts();
39 }
40
trusty_local_irq_restore(unsigned long * state)41 void trusty_local_irq_restore(unsigned long* state) {
42 enable_interrupts();
43 }
44
trusty_idle(struct trusty_dev * dev,bool event_poll)45 void trusty_idle(struct trusty_dev* dev, bool event_poll) {
46 wfi();
47 }
48
trusty_abort(void)49 void trusty_abort(void) {
50 do_reset(NULL, 0, 0, NULL);
51 __builtin_unreachable();
52 }
53
trusty_printf(const char * format,...)54 void trusty_printf(const char* format, ...) {
55 va_list ap;
56
57 va_start(ap, format);
58 vprintf(format, ap);
59 va_end(ap);
60 }
61
trusty_memcpy(void * dest,const void * src,size_t n)62 void* trusty_memcpy(void* dest, const void* src, size_t n) {
63 return memcpy(dest, src, n);
64 }
65
trusty_memset(void * dest,const int c,size_t n)66 void* trusty_memset(void* dest, const int c, size_t n) {
67 return memset(dest, c, n);
68 }
69
trusty_strcpy(char * dest,const char * src)70 char* trusty_strcpy(char* dest, const char* src) {
71 return strcpy(dest, src);
72 }
73
trusty_strlen(const char * str)74 size_t trusty_strlen(const char* str) {
75 return strlen(str);
76 }
77
trusty_calloc(size_t n,size_t size)78 void* trusty_calloc(size_t n, size_t size) {
79 return calloc(n, size);
80 }
81
trusty_free(void * addr)82 void trusty_free(void* addr) {
83 if (addr)
84 free(addr);
85 }
86
trusty_alloc_pages(unsigned count)87 void* trusty_alloc_pages(unsigned count) {
88 return memalign(PAGE_SIZE, count * PAGE_SIZE);
89 }
90
trusty_free_pages(void * va,unsigned count)91 void trusty_free_pages(void* va, unsigned count) {
92 if (va)
93 free(va);
94 }
95