1 /* 2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. 3 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without modification, 6 * are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this list of 9 * conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 * of conditions and the following disclaimer in the documentation and/or other materials 13 * provided with the distribution. 14 * 15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 16 * to endorse or promote products derived from this software without specific prior written 17 * permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 /** 33 * @defgroup los_vm_map vm common definition 34 * @ingroup kernel 35 */ 36 37 #ifndef __LOS_VM_COMMON_H__ 38 #define __LOS_VM_COMMON_H__ 39 40 #ifdef __cplusplus 41 #if __cplusplus 42 extern "C" { 43 #endif /* __cplusplus */ 44 #endif /* __cplusplus */ 45 46 /* user address space, defaults to below kernel space with a 16MB guard gap on either side */ 47 #ifndef USER_ASPACE_BASE 48 #define USER_ASPACE_BASE ((vaddr_t)0x01000000UL) 49 #endif 50 #ifndef USER_ASPACE_SIZE 51 #define USER_ASPACE_SIZE ((vaddr_t)KERNEL_ASPACE_BASE - USER_ASPACE_BASE - 0x01000000UL) 52 #endif 53 54 #define USER_ASPACE_TOP_MAX ((vaddr_t)(USER_ASPACE_BASE + USER_ASPACE_SIZE)) 55 #define USER_HEAP_BASE ((vaddr_t)(USER_ASPACE_TOP_MAX >> 2)) 56 #define USER_MAP_BASE ((vaddr_t)(USER_ASPACE_TOP_MAX >> 1)) 57 #define USER_MAP_SIZE ((vaddr_t)(USER_ASPACE_SIZE >> 3)) 58 59 #ifndef PAGE_SIZE 60 #define PAGE_SIZE (0x1000U) 61 #endif 62 #define PAGE_MASK (~(PAGE_SIZE - 1)) 63 #define PAGE_SHIFT (12) 64 65 #define KB (1024UL) 66 #define MB (1024UL * 1024UL) 67 #define GB (1024UL * 1024UL * 1024UL) 68 69 #define ROUNDUP(a, b) (((a) + ((b) - 1)) & ~((b) - 1)) 70 #define ROUNDDOWN(a, b) ((a) & ~((b) - 1)) 71 #define ROUNDOFFSET(a, b) ((a) & ((b) - 1)) 72 #define MIN2(a, b) (((a) < (b)) ? (a) : (b)) 73 74 #define IS_ALIGNED(a, b) (!(((UINTPTR)(a)) & (((UINTPTR)(b)) - 1))) 75 #define IS_PAGE_ALIGNED(x) IS_ALIGNED(x, PAGE_SIZE) 76 #define IS_SECTION_ALIGNED(x) IS_ALIGNED(x, SECTION_SIZE) 77 78 #define LOS_ERRNO_VM_NO_ERROR (0) 79 #define LOS_ERRNO_VM_GENERIC (-1) 80 #define LOS_ERRNO_VM_NOT_FOUND (-2) 81 #define LOS_ERRNO_VM_NOT_READY (-3) 82 #define LOS_ERRNO_VM_NO_MSG (-4) 83 #define LOS_ERRNO_VM_NO_MEMORY (-5) 84 #define LOS_ERRNO_VM_ALREADY_STARTED (-6) 85 #define LOS_ERRNO_VM_NOT_VALID (-7) 86 #define LOS_ERRNO_VM_INVALID_ARGS (-8) 87 #define LOS_ERRNO_VM_NOT_ENOUGH_BUFFER (-9) 88 #define LOS_ERRNO_VM_NOT_SUSPENDED (-10) 89 #define LOS_ERRNO_VM_OBJECT_DESTROYED (-11) 90 #define LOS_ERRNO_VM_NOT_BLOCKED (-12) 91 #define LOS_ERRNO_VM_TIMED_OUT (-13) 92 #define LOS_ERRNO_VM_ALREADY_EXISTS (-14) 93 #define LOS_ERRNO_VM_CHANNEL_CLOSED (-15) 94 #define LOS_ERRNO_VM_OFFLINE (-16) 95 #define LOS_ERRNO_VM_NOT_ALLOWED (-17) 96 #define LOS_ERRNO_VM_BAD_PATH (-18) 97 #define LOS_ERRNO_VM_ALREADY_MOUNTED (-19) 98 #define LOS_ERRNO_VM_IO (-20) 99 #define LOS_ERRNO_VM_NOT_DIR (-21) 100 #define LOS_ERRNO_VM_NOT_FILE (-22) 101 #define LOS_ERRNO_VM_RECURSE_TOO_DEEP (-23) 102 #define LOS_ERRNO_VM_NOT_SUPPORTED (-24) 103 #define LOS_ERRNO_VM_TOO_BIG (-25) 104 #define LOS_ERRNO_VM_CANCELLED (-26) 105 #define LOS_ERRNO_VM_NOT_IMPLEMENTED (-27) 106 #define LOS_ERRNO_VM_CHECKSUM_FAIL (-28) 107 #define LOS_ERRNO_VM_CRC_FAIL (-29) 108 #define LOS_ERRNO_VM_CMD_UNKNOWN (-30) 109 #define LOS_ERRNO_VM_BAD_STATE (-31) 110 #define LOS_ERRNO_VM_BAD_LEN (-32) 111 #define LOS_ERRNO_VM_BUSY (-33) 112 #define LOS_ERRNO_VM_THREAD_DETACHED (-34) 113 #define LOS_ERRNO_VM_I2C_NACK (-35) 114 #define LOS_ERRNO_VM_ALREADY_EXPIRED (-36) 115 #define LOS_ERRNO_VM_OUT_OF_RANGE (-37) 116 #define LOS_ERRNO_VM_NOT_CONFIGURED (-38) 117 #define LOS_ERRNO_VM_NOT_MOUNTED (-39) 118 #define LOS_ERRNO_VM_FAULT (-40) 119 #define LOS_ERRNO_VM_NO_RESOURCES (-41) 120 #define LOS_ERRNO_VM_BAD_HANDLE (-42) 121 #define LOS_ERRNO_VM_ACCESS_DENIED (-43) 122 #define LOS_ERRNO_VM_PARTIAL_WRITE (-44) 123 #define LOS_ERRNO_VM_LOCK (-45) 124 #define LOS_ERRNO_VM_MAP_FAILED (-46) 125 126 #define VM_ERR(args...) do { \ 127 PRINT_ERR("%s %d ", __FUNCTION__, __LINE__); \ 128 if (PRINT_LEVEL == LOS_DEBUG_LEVEL) { \ 129 PRINTK(args); \ 130 } \ 131 PRINTK("\n"); \ 132 } while (0) 133 134 #ifdef __cplusplus 135 #if __cplusplus 136 } 137 #endif /* __cplusplus */ 138 #endif /* __cplusplus */ 139 140 #endif /* __LOS_VM_COMMON_H__ */ 141