| /* | 
 |  * Copyright (C) 2016 The Android Open Source Project | 
 |  * | 
 |  * Permission is hereby granted, free of charge, to any person | 
 |  * obtaining a copy of this software and associated documentation | 
 |  * files (the "Software"), to deal in the Software without | 
 |  * restriction, including without limitation the rights to use, copy, | 
 |  * modify, merge, publish, distribute, sublicense, and/or sell copies | 
 |  * of the Software, and to permit persons to whom the Software is | 
 |  * furnished to do so, subject to the following conditions: | 
 |  * | 
 |  * The above copyright notice and this permission notice shall be | 
 |  * included in all copies or substantial portions of the Software. | 
 |  * | 
 |  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | 
 |  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | 
 |  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | 
 |  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | 
 |  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | 
 |  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | 
 |  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | 
 |  * SOFTWARE. | 
 |  */ | 
 |  | 
 | #include <trusty/sysdeps.h> | 
 |  | 
 | #include <common.h> | 
 | #include <linux/string.h> | 
 | #include <malloc.h> | 
 |  | 
 | extern int trusty_encode_page_info(struct ns_mem_page_info *page_info, | 
 |                                    void *vaddr); | 
 |  | 
 | void trusty_lock(struct trusty_dev *dev) | 
 | { | 
 | } | 
 | void trusty_unlock(struct trusty_dev *dev) | 
 | { | 
 | } | 
 |  | 
 | void trusty_local_irq_disable(unsigned long *state) | 
 | { | 
 |     disable_interrupts(); | 
 | } | 
 |  | 
 | void trusty_local_irq_restore(unsigned long *state) | 
 | { | 
 |     enable_interrupts(); | 
 | } | 
 |  | 
 | void trusty_idle(struct trusty_dev *dev) | 
 | { | 
 |     wfi(); | 
 | } | 
 |  | 
 | void trusty_abort(void) | 
 | { | 
 |     do_reset(NULL, 0, 0, NULL); | 
 |     __builtin_unreachable(); | 
 | } | 
 |  | 
 | void trusty_printv(const char *message, ...) | 
 | { | 
 |     va_list ap; | 
 |  | 
 |     va_start(ap, message); | 
 |     vprintf(message, ap); | 
 |     va_end(ap); | 
 | } | 
 |  | 
 | void *trusty_memcpy(void *dest, const void *src, size_t n) | 
 | { | 
 |     return memcpy(dest, src, n); | 
 | } | 
 |  | 
 | void *trusty_memset(void *dest, const int c, size_t n) | 
 | { | 
 |     return memset(dest, c, n); | 
 | } | 
 |  | 
 | char *trusty_strcpy(char *dest, const char *src) | 
 | { | 
 |     return strcpy(dest, src); | 
 | } | 
 |  | 
 | size_t trusty_strlen(const char *str) | 
 | { | 
 |     return strlen(str); | 
 | } | 
 |  | 
 | void *trusty_calloc(size_t n, size_t size) | 
 | { | 
 |     return calloc(n, size); | 
 | } | 
 |  | 
 | void trusty_free(void *addr) | 
 | { | 
 |     if (addr) | 
 |         free(addr); | 
 | } | 
 |  | 
 | void *trusty_membuf_alloc(struct ns_mem_page_info *page_info, size_t size) | 
 | { | 
 |     void *va = NULL; | 
 |     int res; | 
 |  | 
 |     va = memalign(4096, size); | 
 |     if (!va) | 
 |         return NULL; | 
 |  | 
 |     /* get memory attibutes */ | 
 |     res = trusty_encode_page_info(page_info, va); | 
 |     if (res) { | 
 |         trusty_membuf_free(va); | 
 |         return NULL; | 
 |     } | 
 |     return va; | 
 | } | 
 |  | 
 | void trusty_membuf_free(void *va) | 
 | { | 
 |     if (va) | 
 |         free(va); | 
 | } |