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 #ifndef __VM_ZONE_H__ 33 #define __VM_ZONE_H__ 34 35 #include "target_config.h" 36 37 #ifdef __cplusplus 38 #if __cplusplus 39 extern "C" { 40 #endif /* __cplusplus */ 41 #endif /* __cplusplus */ 42 43 #ifdef LOSCFG_KERNEL_MMU 44 #ifdef LOSCFG_TEE_ENABLE 45 #define KERNEL_VADDR_BASE 0x41000000 46 #else 47 #define KERNEL_VADDR_BASE 0x40000000 48 #endif 49 #else 50 #define KERNEL_VADDR_BASE DDR_MEM_ADDR 51 #endif 52 #define KERNEL_VADDR_SIZE DDR_MEM_SIZE 53 54 #define SYS_MEM_BASE DDR_MEM_ADDR 55 #define SYS_MEM_END (SYS_MEM_BASE + SYS_MEM_SIZE_DEFAULT) 56 57 #define _U32_C(X) X##U 58 #define U32_C(X) _U32_C(X) 59 60 #define KERNEL_VMM_BASE U32_C(KERNEL_VADDR_BASE) 61 #define KERNEL_VMM_SIZE U32_C(KERNEL_VADDR_SIZE) 62 63 #define KERNEL_ASPACE_BASE KERNEL_VMM_BASE 64 #define KERNEL_ASPACE_SIZE KERNEL_VMM_SIZE 65 66 /* Uncached vmm aspace */ 67 #define UNCACHED_VMM_BASE (KERNEL_VMM_BASE + KERNEL_VMM_SIZE) 68 #define UNCACHED_VMM_SIZE DDR_MEM_SIZE 69 70 #define VMALLOC_START (UNCACHED_VMM_BASE + UNCACHED_VMM_SIZE) 71 #define VMALLOC_SIZE 0x08000000 72 73 #ifdef LOSCFG_KERNEL_MMU 74 #define PERIPH_DEVICE_BASE (VMALLOC_START + VMALLOC_SIZE) 75 #define PERIPH_DEVICE_SIZE U32_C(PERIPH_PMM_SIZE) 76 #define PERIPH_CACHED_BASE (PERIPH_DEVICE_BASE + PERIPH_DEVICE_SIZE) 77 #define PERIPH_CACHED_SIZE U32_C(PERIPH_PMM_SIZE) 78 #define PERIPH_UNCACHED_BASE (PERIPH_CACHED_BASE + PERIPH_CACHED_SIZE) 79 #define PERIPH_UNCACHED_SIZE U32_C(PERIPH_PMM_SIZE) 80 #else 81 #define PERIPH_DEVICE_BASE PERIPH_PMM_BASE 82 #define PERIPH_DEVICE_SIZE U32_C(PERIPH_PMM_SIZE) 83 #define PERIPH_CACHED_BASE PERIPH_PMM_BASE 84 #define PERIPH_CACHED_SIZE U32_C(PERIPH_PMM_SIZE) 85 #define PERIPH_UNCACHED_BASE PERIPH_PMM_BASE 86 #define PERIPH_UNCACHED_SIZE U32_C(PERIPH_PMM_SIZE) 87 #endif 88 89 #define IO_DEVICE_ADDR(paddr) ((paddr) - PERIPH_PMM_BASE + PERIPH_DEVICE_BASE) 90 #define IO_CACHED_ADDR(paddr) ((paddr) - PERIPH_PMM_BASE + PERIPH_CACHED_BASE) 91 #define IO_UNCACHED_ADDR(paddr) ((paddr) - PERIPH_PMM_BASE + PERIPH_UNCACHED_BASE) 92 93 #define MEM_CACHED_ADDR(paddr) ((paddr) - DDR_MEM_ADDR + KERNEL_VMM_BASE) 94 #define MEM_UNCACHED_ADDR(paddr) ((paddr) - DDR_MEM_ADDR + UNCACHED_VMM_BASE) 95 96 #define VMM_TO_UNCACHED_ADDR(vaddr) ((vaddr) - KERNEL_VMM_BASE + UNCACHED_VMM_BASE) 97 #define UNCACHED_TO_VMM_ADDR(vaddr) ((vaddr) - UNCACHED_VMM_BASE + KERNEL_VMM_BASE) 98 99 #define VMM_TO_DMA_ADDR(vaddr) ((vaddr) - KERNEL_VMM_BASE + SYS_MEM_BASE) 100 #define DMA_TO_VMM_ADDR(vaddr) ((vaddr) - SYS_MEM_BASE + KERNEL_VMM_BASE) 101 102 #if (PERIPH_UNCACHED_BASE >= (0xFFFFFFFFU - PERIPH_UNCACHED_SIZE)) 103 #error "Kernel virtual memory space has overflowed!" 104 #endif 105 106 #ifdef __cplusplus 107 #if __cplusplus 108 } 109 #endif /* __cplusplus */ 110 #endif /* __cplusplus */ 111 112 #endif 113